diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-01-23 15:43:23 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-01-23 15:43:23 +0300 |
commit | 6a2a98ff7d8013eba9bf5bdc504c55ff2cec6e18 (patch) | |
tree | 17698fa23711bbc89551e0eb24dba059c5383124 | |
parent | e8a73d3af0f79d58576ae87eb470d15345d791f6 (diff) |
Added maximum depth option in JSON object model reporting
-rw-r--r-- | .cproject | 14 | ||||
-rw-r--r-- | src/GCodes/GCodeBuffer/StringParser.cpp | 14 | ||||
-rw-r--r-- | src/ObjectModel/ObjectModel.cpp | 69 | ||||
-rw-r--r-- | src/ObjectModel/ObjectModel.h | 8 | ||||
-rw-r--r-- | src/Version.h | 2 |
5 files changed, 66 insertions, 41 deletions
@@ -78,7 +78,7 @@ <listOptionValue builtIn="false" value="FreeRTOS"/> <listOptionValue builtIn="false" value="RRFLibraries"/> </option> - <option id="gnu.cpp.link.option.flags.827167716" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m3 -T"${workspace_loc:/${CoreName}/variants/RADDS/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> + <option id="gnu.cpp.link.option.flags.827167716" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="--specs=nosys.specs -Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m3 -T"${workspace_loc:/${CoreName}/variants/RADDS/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.99895855" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinput" paths="$(LIBS)"/> @@ -232,7 +232,7 @@ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="CoreNG"/> <listOptionValue builtIn="false" value="supc++"/> </option> - <option id="gnu.cpp.link.option.flags.161856294" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -T"${workspace_loc:/${CoreName}/variants/duetNG/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> + <option id="gnu.cpp.link.option.flags.161856294" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="--specs=nosys.specs -Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -T"${workspace_loc:/${CoreName}/variants/duetNG/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1270956612" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinput" paths="$(LIBS)"/> @@ -391,7 +391,7 @@ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="CoreNG"/> <listOptionValue builtIn="false" value="supc++"/> </option> - <option id="gnu.cpp.link.option.flags.1077151865" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m4 -T"${workspace_loc:/${CoreName}/variants/sam4s/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> + <option id="gnu.cpp.link.option.flags.1077151865" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="--specs=nosys.specs -Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m4 -T"${workspace_loc:/${CoreName}/variants/sam4s/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.480654714" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinput" paths="$(LIBS)"/> @@ -551,7 +551,7 @@ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="CoreNG"/> <listOptionValue builtIn="false" value="supc++"/> </option> - <option id="gnu.cpp.link.option.flags.1542629928" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m4 -T"${workspace_loc:/${CoreName}/variants/sam4s/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> + <option id="gnu.cpp.link.option.flags.1542629928" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="--specs=nosys.specs -Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m4 -T"${workspace_loc:/${CoreName}/variants/sam4s/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1255607760" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinput" paths="$(LIBS)"/> @@ -722,7 +722,7 @@ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="CANlib"/> <listOptionValue builtIn="false" value="supc++"/> </option> - <option id="gnu.cpp.link.option.flags.951069241" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -T"${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> + <option id="gnu.cpp.link.option.flags.951069241" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="--specs=nosys.specs -Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -T"${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.180655060" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinput" paths="$(LIBS)"/> @@ -906,7 +906,7 @@ <listOptionValue builtIn="false" value="RRFLibraries"/> <listOptionValue builtIn="false" value="CANlib"/> </option> - <option id="gnu.cpp.link.option.flags.610459151" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -T"${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> + <option id="gnu.cpp.link.option.flags.610459151" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="--specs=nosys.specs -Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -T"${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1597480314" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinput" paths="$(LIBS)"/> @@ -1087,7 +1087,7 @@ <listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="CANlib"/> <listOptionValue builtIn="false" value="supc++"/> </option> - <option id="gnu.cpp.link.option.flags.735756251" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -T"${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> + <option id="gnu.cpp.link.option.flags.735756251" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="--specs=nosys.specs -Os -Wl,--gc-sections -Wl,--fatal-warnings -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -T"${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}" -Wl,-Map,"${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map"" valueType="string"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.683755401" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinput" paths="$(LIBS)"/> diff --git a/src/GCodes/GCodeBuffer/StringParser.cpp b/src/GCodes/GCodeBuffer/StringParser.cpp index 4036b4be..a85e96de 100644 --- a/src/GCodes/GCodeBuffer/StringParser.cpp +++ b/src/GCodes/GCodeBuffer/StringParser.cpp @@ -2077,8 +2077,8 @@ void StringParser::BalanceNumericTypes(ExpressionValue& val1, ExpressionValue& v { throw ConstructParseException("expected numeric operands"); } - val1.Set(0); - val2.Set(0); + val1.Set((int32_t)0); + val2.Set((int32_t)0); } } @@ -2098,8 +2098,8 @@ void StringParser::BalanceTypes(ExpressionValue& val1, ExpressionValue& val2, bo { throw ConstructParseException("cannot convert operands to same type"); } - val1.Set(0); - val2.Set(0); + val1.Set((int32_t)0); + val2.Set((int32_t)0); } } @@ -2121,7 +2121,7 @@ void StringParser::EnsureNumeric(ExpressionValue& val, bool evaluate) { throw ConstructParseException("expected numeric operand"); } - val.Set(0); + val.Set((int32_t)0); } } @@ -2303,7 +2303,7 @@ ExpressionValue StringParser::ParseIdentifierExpression(StringBuffer& stringBuff } String<MaxVariableNameLength> id; - ObjectExplorationContext context("v", applyLengthOperator); + ObjectExplorationContext context("v", 99, applyLengthOperator); // Loop parsing identifiers and index expressions // When we come across an index expression, evaluate it, add it to the context, and place a marker in the identifier string. @@ -2410,7 +2410,7 @@ ExpressionValue StringParser::ParseIdentifierExpression(StringBuffer& stringBuff { throw ConstructParseException("expected numeric operand"); } - rslt.Set(0); + rslt.Set((int32_t)0); } } else if (id.Equals("sin")) diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp index fc9a096a..7628ed0a 100644 --- a/src/ObjectModel/ObjectModel.cpp +++ b/src/ObjectModel/ObjectModel.cpp @@ -59,12 +59,24 @@ ObjectModel::ObjectModel() noexcept // ObjectExplorationContext members -ObjectExplorationContext::ObjectExplorationContext(const char *reportFlags, bool wal) noexcept - : numIndicesProvided(0), numIndicesCounted(0), shortForm(false), onlyLive(false), includeVerbose(false), wantArrayLength(wal), includeNulls(false) +ObjectExplorationContext::ObjectExplorationContext(const char *reportFlags, unsigned int initialMaxDepth, bool wal) noexcept + : maxDepth(initialMaxDepth), currentDepth(0), numIndicesProvided(0), numIndicesCounted(0), + shortForm(false), onlyLive(false), includeVerbose(false), wantArrayLength(wal), includeNulls(false) { while (true) { - switch(*reportFlags) + if (isdigit(*reportFlags)) + { + maxDepth = *reportFlags - '0'; + ++reportFlags; + while (isdigit(*reportFlags)) + { + maxDepth = (10 * maxDepth) + (*reportFlags - '0'); + ++reportFlags; + } + } + + switch (*reportFlags) { case '\0': return; @@ -114,45 +126,54 @@ bool ObjectExplorationContext::ShouldReport(const ObjectModelEntryFlags f) const // Report this object void ObjectModel::ReportAsJson(OutputBuffer* buf, ObjectExplorationContext& context, uint8_t tableNumber, const char* filter) const { - bool added = false; - const uint8_t *descriptor; - const ObjectModelTableEntry *tbl = GetObjectModelTable(descriptor); - if (tableNumber < descriptor[0]) + if (context.IncreaseDepth()) { - size_t numEntries = descriptor[tableNumber + 1]; - while (tableNumber != 0) + bool added = false; + const uint8_t *descriptor; + const ObjectModelTableEntry *tbl = GetObjectModelTable(descriptor); + if (tableNumber < descriptor[0]) { - --tableNumber; - tbl += descriptor[tableNumber + 1]; - } + size_t numEntries = descriptor[tableNumber + 1]; + while (tableNumber != 0) + { + --tableNumber; + tbl += descriptor[tableNumber + 1]; + } - while (numEntries != 0) - { - if (tbl->Matches(filter, context)) + while (numEntries != 0) { - if (tbl->ReportAsJson(buf, context, this, filter, !added)) + if (tbl->Matches(filter, context)) { - added = true; + if (tbl->ReportAsJson(buf, context, this, filter, !added)) + { + added = true; + } } + --numEntries; + ++tbl; + } + if (added && *filter == 0) + { + buf->cat('}'); } - --numEntries; - ++tbl; } - if (added && *filter == 0) + if (!added) { - buf->cat('}'); + buf->cat("null"); } + context.DecreaseDepth(); } - if (!added) + else { - buf->cat("null"); + buf->cat("{}"); } } // Construct a JSON representation of those parts of the object model requested by the user. This version is called on the root of the tree. void ObjectModel::ReportAsJson(OutputBuffer *buf, const char *filter, const char *reportFlags, bool wantArrayLength) const { - ObjectExplorationContext context(reportFlags, wantArrayLength); + const unsigned int defaultMaxDepth = (wantArrayLength) ? 99 : (filter[0] == 0) ? 1 : 99; + ObjectExplorationContext context(reportFlags, defaultMaxDepth, wantArrayLength); ReportAsJson(buf, context, 0, filter); } diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h index ad404be4..9a18ffe6 100644 --- a/src/ObjectModel/ObjectModel.h +++ b/src/ObjectModel/ObjectModel.h @@ -101,7 +101,6 @@ struct ExpressionValue void Set(bool b) noexcept { type = TYPE_OF(bool); bVal = b; } void Set(char c) noexcept { type = TYPE_OF(char); cVal = c; } void Set(int32_t i) noexcept { type = TYPE_OF(int32_t); iVal = i; } - void Set(int i) noexcept { type = TYPE_OF(int32_t); iVal = i; } void Set(float f) noexcept { type = TYPE_OF(float); fVal = f; param = 1; } void Set(const char *s) noexcept { type = TYPE_OF(const char*); sVal = s; } @@ -129,8 +128,11 @@ enum class ObjectModelEntryFlags : uint8_t class ObjectExplorationContext { public: - ObjectExplorationContext(const char *reportFlags, bool wal) noexcept; + ObjectExplorationContext(const char *reportFlags, unsigned int initialMaxDepth, bool wal) noexcept; + void SetMaxDepth(unsigned int d) noexcept { maxDepth = d; } + bool IncreaseDepth() noexcept { if (currentDepth < maxDepth) { ++currentDepth; return true; } return false; } + void DecreaseDepth() noexcept { --currentDepth; } void AddIndex(int32_t index) THROWS_GCODE_EXCEPTION; void AddIndex() THROWS_GCODE_EXCEPTION; void RemoveIndex() THROWS_GCODE_EXCEPTION; @@ -146,6 +148,8 @@ public: private: static constexpr size_t MaxIndices = 4; // max depth of array nesting + unsigned int maxDepth; + unsigned int currentDepth; size_t numIndicesProvided; // the number of indices provided, when we are doing a value lookup size_t numIndicesCounted; // the number of indices passed in the search string int32_t indices[MaxIndices]; diff --git a/src/Version.h b/src/Version.h index 3ac41602..451cf6a3 100644 --- a/src/Version.h +++ b/src/Version.h @@ -20,7 +20,7 @@ #endif #ifndef DATE -# define DATE "2020-01-22b2" +# define DATE "2020-01-23b1" #endif #define AUTHORS "reprappro, dc42, chrishamm, t3p3, dnewman, printm3d" |