diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-03-31 17:00:06 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-03-31 17:00:06 +0300 |
commit | a7226bfdd57e82e76f4943433dd8764a4705eb08 (patch) | |
tree | 111ac1e0667511ea8a7819b7ff4d1a33c73fa4c0 /src/ObjectModel | |
parent | c09da95d03cd3769173aa5e3af3e73aae8ae2be4 (diff) |
Implemented 'exists(object_model_path)' in expression evaluater
Diffstat (limited to 'src/ObjectModel')
-rw-r--r-- | src/ObjectModel/ObjectModel.cpp | 32 | ||||
-rw-r--r-- | src/ObjectModel/ObjectModel.h | 6 |
2 files changed, 33 insertions, 5 deletions
diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp index 6959ccd6..ecdb7009 100644 --- a/src/ObjectModel/ObjectModel.cpp +++ b/src/ObjectModel/ObjectModel.cpp @@ -269,7 +269,7 @@ ObjectModel::ObjectModel() noexcept ObjectExplorationContext::ObjectExplorationContext(bool wal, const char *reportFlags, unsigned int initialMaxDepth) noexcept : startMillis(millis()), maxDepth(initialMaxDepth), currentDepth(0), numIndicesProvided(0), numIndicesCounted(0), line(-1), column(-1), - shortForm(false), onlyLive(false), includeVerbose(false), wantArrayLength(wal), includeNulls(false), includeObsolete(false), obsoleteFieldQueried(false) + shortForm(false), onlyLive(false), includeVerbose(false), wantArrayLength(wal), includeNulls(false), includeObsolete(false), obsoleteFieldQueried(false), wantExists(false) { while (true) { @@ -311,10 +311,10 @@ ObjectExplorationContext::ObjectExplorationContext(bool wal, const char *reportF } // Constructor when evaluating expressions -ObjectExplorationContext::ObjectExplorationContext(bool wal, int p_line, int p_col) noexcept +ObjectExplorationContext::ObjectExplorationContext(bool wal, bool wex, int p_line, int p_col) noexcept : startMillis(millis()), maxDepth(99), currentDepth(0), numIndicesProvided(0), numIndicesCounted(0), line(p_line), column(p_col), - shortForm(false), onlyLive(false), includeVerbose(true), wantArrayLength(wal), includeNulls(false), includeObsolete(true), obsoleteFieldQueried(false) + shortForm(false), onlyLive(false), includeVerbose(true), wantArrayLength(wal), includeNulls(false), includeObsolete(true), obsoleteFieldQueried(false), wantExists(wex) { } @@ -852,11 +852,21 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, c classDescriptor = classDescriptor->parent; // search parent class object model too } + if (context.WantExists()) + { + return ExpressionValue(false); + } + throw context.ConstructParseException("unknown value '%s'", idString); } ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, const ObjectModelClassDescriptor *classDescriptor, const ExpressionValue& val, const char *idString) const { + if (*idString == 0 && context.WantExists() && val.GetType() != TypeCode::None) + { + return ExpressionValue(true); + } + switch (val.GetType()) { case TypeCode::Array: @@ -880,6 +890,10 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, c if (context.GetLastIndex() < 0 || (size_t)context.GetLastIndex() >= val.omadVal->GetNumElements(this, context)) { + if (context.WantExists()) + { + return ExpressionValue(false); + } throw context.ConstructParseException("array index out of bounds"); } @@ -902,6 +916,10 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, c break; case TypeCode::None: + if (context.WantExists()) + { + return ExpressionValue(false); + } if (*idString == 0) { return val; // a null value can be compared to null @@ -926,6 +944,10 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, c { break; } + if (context.WantExists()) + { + return ExpressionValue(true); + } const auto bm = Bitmap<uint32_t>::MakeFromRaw(val.uVal); return ExpressionValue((int32_t)bm.GetSetBitNumber(context.GetLastIndex())); } @@ -956,6 +978,10 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, c { break; } + if (context.WantExists()) + { + return ExpressionValue(true); + } const auto bm = Bitmap<uint64_t>::MakeFromRaw(val.Get56BitValue()); return ExpressionValue((int32_t)bm.GetSetBitNumber(context.GetLastIndex())); } diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h index 09e58332..99404ca3 100644 --- a/src/ObjectModel/ObjectModel.h +++ b/src/ObjectModel/ObjectModel.h @@ -191,7 +191,7 @@ public: ObjectExplorationContext(bool wal, const char *reportFlags, unsigned int initialMaxDepth) noexcept; // Constructor used when evaluating expressions - ObjectExplorationContext(bool wal, int p_line, int p_col) noexcept; + ObjectExplorationContext(bool wal, bool wex, int p_line, int p_col) noexcept; void SetMaxDepth(unsigned int d) noexcept { maxDepth = d; } bool IncreaseDepth() noexcept { if (currentDepth < maxDepth) { ++currentDepth; return true; } return false; } @@ -206,6 +206,7 @@ public: bool ShortFormReport() const noexcept { return shortForm; } bool ShouldReport(const ObjectModelEntryFlags f) const noexcept; bool WantArrayLength() const noexcept { return wantArrayLength; } + bool WantExists() const noexcept { return wantExists; } bool ShouldIncludeNulls() const noexcept { return includeNulls; } uint64_t GetStartMillis() const { return startMillis; } @@ -232,7 +233,8 @@ private: wantArrayLength : 1, includeNulls : 1, includeObsolete : 1, - obsoleteFieldQueried : 1; + obsoleteFieldQueried : 1, + wantExists : 1; }; // Entry to describe an array of objects or values. These must be brace-initializable into flash memory. |