summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher/expression.h')
-rw-r--r--src/mongo/db/matcher/expression.h66
1 files changed, 16 insertions, 50 deletions
diff --git a/src/mongo/db/matcher/expression.h b/src/mongo/db/matcher/expression.h
index b6a2701702f..2c99218bdf7 100644
--- a/src/mongo/db/matcher/expression.h
+++ b/src/mongo/db/matcher/expression.h
@@ -150,57 +150,19 @@ public:
return StringData();
}
- /**
- * Notes on structure:
- * isLogical, isArray, and isLeaf define three partitions of all possible operators.
- *
- * isLogical can have children and its children can be arbitrary operators.
- *
- * isArray can have children and its children are predicates over one field.
- *
- * isLeaf is a predicate over one field.
- */
-
- /**
- * Returns true if this match expression node operates logically on its children.
- * For example, the AND node is logical in that it returns true only if all of its
- * children return true.
- */
- bool isLogical() const {
- switch (_matchType) {
- case AND:
- case OR:
- case NOT:
- case NOR:
- case INTERNAL_SCHEMA_XOR:
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Is this node an array operator? Array operators have multiple clauses but operate on one
- * field.
- *
- * ELEM_MATCH_VALUE, ELEM_MATCH_OBJECT, SIZE (ArrayMatchingMatchExpression)
- */
- bool isArray() const {
- return SIZE == _matchType || ELEM_MATCH_VALUE == _matchType ||
- ELEM_MATCH_OBJECT == _matchType;
- }
+ enum class MatchCategory {
+ // Expressions that are leaves on the AST, these do not have any children.
+ kLeaf,
+ // Logical Expressions such as $and, $or, etc. that do not have a path and may have
+ // one or more children.
+ kLogical,
+ // Expressions that operate on arrays only.
+ kArrayMatching,
+ // Expressions that don't fall into any particular bucket.
+ kOther,
+ };
- /**
- * Not-internal nodes, predicates over one field. Almost all of these inherit from
- * LeafMatchExpression.
- *
- * Exceptions: WHERE, which doesn't have a field.
- * TYPE_OPERATOR, which inherits from MatchExpression due to unique array
- * semantics.
- */
- bool isLeaf() const {
- return !isArray() && !isLogical();
- }
+ virtual MatchCategory getCategory() const = 0;
// XXX: document
virtual std::unique_ptr<MatchExpression> shallowClone() const = 0;
@@ -320,6 +282,10 @@ public:
return other->matchType() == ALWAYS_FALSE;
}
+ MatchCategory getCategory() const final {
+ return MatchCategory::kOther;
+ }
+
private:
StringData _path;
};