Skip to content

Commit

Permalink
Added maximum depth option in JSON object model reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
dc42 committed Jan 23, 2020
1 parent e8a73d3 commit 6a2a98f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 41 deletions.
14 changes: 7 additions & 7 deletions .cproject
Expand Up @@ -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&quot;${workspace_loc:/${CoreName}/variants/RADDS/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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&quot;${workspace_loc:/${CoreName}/variants/RADDS/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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)"/>
Expand Down Expand Up @@ -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&quot;${workspace_loc:/${CoreName}/variants/duetNG/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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&quot;${workspace_loc:/${CoreName}/variants/duetNG/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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)"/>
Expand Down Expand Up @@ -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&quot;${workspace_loc:/${CoreName}/variants/sam4s/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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&quot;${workspace_loc:/${CoreName}/variants/sam4s/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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)"/>
Expand Down Expand Up @@ -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&quot;${workspace_loc:/${CoreName}/variants/sam4s/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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&quot;${workspace_loc:/${CoreName}/variants/sam4s/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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)"/>
Expand Down Expand Up @@ -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&quot;${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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&quot;${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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)"/>
Expand Down Expand Up @@ -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&quot;${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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&quot;${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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)"/>
Expand Down Expand Up @@ -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&quot;${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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&quot;${workspace_loc:/${CoreName}/variants/same70/linker_scripts/gcc/flash.ld}&quot; -Wl,-Map,&quot;${workspace_loc:/${ProjName}/${ConfigName}}/${BuildArtifactFileBaseName}.map&quot;" 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)"/>
Expand Down
14 changes: 7 additions & 7 deletions src/GCodes/GCodeBuffer/StringParser.cpp
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -2121,7 +2121,7 @@ void StringParser::EnsureNumeric(ExpressionValue& val, bool evaluate)
{
throw ConstructParseException("expected numeric operand");
}
val.Set(0);
val.Set((int32_t)0);
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"))
Expand Down
69 changes: 45 additions & 24 deletions src/ObjectModel/ObjectModel.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 6 additions & 2 deletions src/ObjectModel/ObjectModel.h
Expand Up @@ -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; }

Expand Down Expand Up @@ -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;
Expand All @@ -146,6 +148,8 @@ class ObjectExplorationContext
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];
Expand Down
2 changes: 1 addition & 1 deletion src/Version.h
Expand Up @@ -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"
Expand Down

0 comments on commit 6a2a98f

Please sign in to comment.