diff options
-rw-r--r-- | src/core/model/Syntax.cpp | 16 | ||||
-rw-r--r-- | src/core/model/Syntax.hpp | 23 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/core/model/Syntax.cpp b/src/core/model/Syntax.cpp index a97acf7..0e92ef5 100644 --- a/src/core/model/Syntax.cpp +++ b/src/core/model/Syntax.cpp @@ -32,6 +32,22 @@ bool TokenDescriptor::isValid() const /* Class SyntaxDescriptor */ +bool operator==(const SyntaxDescriptor &o1, const SyntaxDescriptor &o2) +{ + return (o1.depth == o2.depth) && (o1.open == o2.open) && + (o1.close == o2.close) && (o1.shortForm == o2.shortForm) && + (o1.descriptor == o2.descriptor); +} + +bool operator<(const SyntaxDescriptor &o1, const SyntaxDescriptor &o2) +{ + return (o1.depth < o2.depth) || + (o1.isFieldDescriptor() && !o2.isFieldDescriptor()) || + (o1.open < o2.open) || (o1.close < o2.close) || + (o1.shortForm < o2.shortForm) || + (o1.descriptor.get() < o2.descriptor.get()); +} + bool SyntaxDescriptor::isAnnotation() const { return descriptor->isa(&RttiTypes::AnnotationClass); diff --git a/src/core/model/Syntax.hpp b/src/core/model/Syntax.hpp index 97a2995..91b2226 100644 --- a/src/core/model/Syntax.hpp +++ b/src/core/model/Syntax.hpp @@ -158,6 +158,29 @@ struct SyntaxDescriptor { } /** + * Equality operator, returns true if the two SyntaxDescriptor instances + * are exactly equal. + * + * @param o1 is the first syntax descriptor for the comparison. + * @param o2 is the second syntax descriptor for the comparison. + * @return true if the two syntax descriptors equal, false otherwise. + */ + friend bool operator==(const SyntaxDescriptor &o1, + const SyntaxDescriptor &o2); + + /** + * Orders two SyntaxDescriptor instances by their depth, open, close and + * shortForm TokenId and the descriptor pointer. Additionally, + * SyntaxDescriptors belonging to FieldDescriptors are prefered. + * + * @param o1 is the first syntax descriptor for the comparison. + * @param o2 is the second syntax descriptor for the comparison. + * @return true if o1 is should be ordered before o2. + */ + friend bool operator<(const SyntaxDescriptor &o1, + const SyntaxDescriptor &o2); + + /** * Inserts all tokens referenced in this SyntaxDescriptor into the * given TokenSet. Skips token ids set to Tokens::Empty. * |