diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-03-01 14:49:13 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-03-01 14:49:13 +0300 |
commit | 92978f1d6f2ab91e1d2356369f7174a0f2c4a999 (patch) | |
tree | 8fd3528a43de4013c27a4ef1c1833b8f7a2af0df /src/ObjectModel | |
parent | 70ec453ff68c992ec7edf3c196d21f50fa5dbc3f (diff) |
Bug fixes to conditional GCode
Fixed premature termination of a loop when there were not commands in
the file after the loop body
Fixed crash when you tried to access a missong element of a sparse
object array
Handle stringising of null and object values (but objects are
represented as "{object}" for now)
Diffstat (limited to 'src/ObjectModel')
-rw-r--r-- | src/ObjectModel/ObjectModel.cpp | 27 | ||||
-rw-r--r-- | src/ObjectModel/ObjectModel.h | 4 |
2 files changed, 18 insertions, 13 deletions
diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp index ba581ddd..0b05f749 100644 --- a/src/ObjectModel/ObjectModel.cpp +++ b/src/ObjectModel/ObjectModel.cpp @@ -293,16 +293,11 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& break; case TYPE_OF(const ObjectModel*): - if (val.omVal != nullptr) + if (*filter == '.') { - if (*filter == '.') - { - ++filter; - } - return val.omVal->ReportAsJson(buf, context, val.param, filter); + ++filter; } - buf->cat("null"); - break; + return val.omVal->ReportAsJson(buf, context, val.param, filter); case TYPE_OF(float): if (val.fVal == 0.0) @@ -653,15 +648,25 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, E } case TYPE_OF(const ObjectModel*): - if (*idString == '.') + switch (*idString) { + case 0: + return val; + case '.': return val.omVal->GetObjectValue(context, idString + 1, val.param); + case '^': + throw context.ConstructParseException("object is not an array"); + default: + throw context.ConstructParseException("syntax error in object model path"); } + break; + + case NoType: if (*idString == 0) { - return val; // an object value can be compared to null + return val; // a null value can be compared to null } - throw context.ConstructParseException((*idString == '[') ? "object is not an array" : "syntax error in object model path"); + throw context.ConstructParseException("reached null object before end of selector string"); case TYPE_OF(Bitmap<uint16_t>): case TYPE_OF(Bitmap<uint32_t>): diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h index 0b60ef33..ed5270c2 100644 --- a/src/ObjectModel/ObjectModel.h +++ b/src/ObjectModel/ObjectModel.h @@ -103,8 +103,8 @@ struct ExpressionValue explicit constexpr ExpressionValue(float f) noexcept : type(TYPE_OF(float)), param(MaxFloatDigitsDisplayedAfterPoint), fVal(f) { } constexpr ExpressionValue(float f, uint8_t numDecimalPlaces) noexcept : type(TYPE_OF(float)), param(numDecimalPlaces), fVal(f) { } explicit constexpr ExpressionValue(int32_t i) noexcept : type(TYPE_OF(int32_t)), param(0), iVal(i) { } - explicit constexpr ExpressionValue(const ObjectModel *om) noexcept : type(TYPE_OF(const ObjectModel*)), param(0), omVal(om) { } - constexpr ExpressionValue(const ObjectModel *om, uint8_t tableNumber) noexcept : type(TYPE_OF(const ObjectModel*)), param(tableNumber), omVal(om) { } + explicit constexpr ExpressionValue(const ObjectModel *om) noexcept : type((om == nullptr) ? NoType : TYPE_OF(const ObjectModel*)), param(0), omVal(om) { } + constexpr ExpressionValue(const ObjectModel *om, uint8_t tableNumber) noexcept : type((om == nullptr) ? NoType : TYPE_OF(const ObjectModel*)), param(tableNumber), omVal(om) { } explicit constexpr ExpressionValue(const char *s) noexcept : type(TYPE_OF(const char*)), param(0), sVal(s) { } explicit constexpr ExpressionValue(const ObjectModelArrayDescriptor *omad) noexcept : type(TYPE_OF(const ObjectModelArrayDescriptor*)), param(0), omadVal(omad) { } explicit constexpr ExpressionValue(IPAddress ip) noexcept : type(TYPE_OF(IPAddress)), param(0), uVal(ip.GetV4LittleEndian()) { } |