diff options
Diffstat (limited to 'src/libs/3rdparty/cplusplus/Names.cpp')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Names.cpp | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/src/libs/3rdparty/cplusplus/Names.cpp b/src/libs/3rdparty/cplusplus/Names.cpp index 6bcc988f37..d240ac536b 100644 --- a/src/libs/3rdparty/cplusplus/Names.cpp +++ b/src/libs/3rdparty/cplusplus/Names.cpp @@ -24,6 +24,7 @@ #include "Literals.h" #include <algorithm> #include <cstring> +#include <string_view> using namespace CPlusPlus; @@ -93,44 +94,61 @@ bool TemplateNameId::match0(const Name *otherName, Matcher *matcher) const const Identifier *TemplateNameId::identifier() const { return _identifier; } +bool TemplateArgument::match(const TemplateArgument &otherTy, Matcher *matcher) const +{ + if (_numericLiteral != otherTy._numericLiteral) + return false; + return type().match(otherTy.type(), matcher); +} + int TemplateNameId::templateArgumentCount() const { return int(_templateArguments.size()); } -const FullySpecifiedType &TemplateNameId::templateArgumentAt(int index) const +const TemplateArgument &TemplateNameId::templateArgumentAt(int index) const { return _templateArguments[index]; } -bool TemplateNameId::Compare::operator()(const TemplateNameId *name, - const TemplateNameId *other) const +bool TemplateNameId::Equals::operator()(const TemplateNameId *name, + const TemplateNameId *other) const { - if (name == nullptr) - return other != nullptr; - if (other == nullptr) - return false; if (name == other) + return true; + if (name == nullptr || other == nullptr) return false; const Identifier *id = name->identifier(); const Identifier *otherId = other->identifier(); - if (id == nullptr) - return otherId != nullptr; - if (otherId == nullptr) + if (!id != !otherId) // mimic logical xor (id == nullptr ^^ otherId == nullptr) return false; - const int c = std::strcmp(id->chars(), otherId->chars()); + const int c = id ? std::strcmp(id->chars(), otherId->chars()) : 0; // 0 if both are nullptr if (c == 0) { // we have to differentiate TemplateNameId with respect to specialization or instantiation if (name->isSpecialization() == other->isSpecialization()) { - return std::lexicographical_compare(name->firstTemplateArgument(), - name->lastTemplateArgument(), - other->firstTemplateArgument(), - other->lastTemplateArgument()); - } else { - return name->isSpecialization(); + return std::equal(name->firstTemplateArgument(), + name->lastTemplateArgument(), + other->firstTemplateArgument(), + other->lastTemplateArgument()); } } + return false; +} - return c < 0; +size_t TemplateNameId::Hash::operator()(const TemplateNameId *name) const +{ + if (name == nullptr) + return 0; + + const Identifier *id = name->identifier(); + + size_t hash = id ? std::hash<std::string_view>()(std::string_view(id->chars())) : 0; + hash ^= name->isSpecialization() ? 0x1 : 0x0; + std::for_each(name->firstTemplateArgument(), + name->lastTemplateArgument(), + [&hash](const TemplateArgument &ta) { + hash ^= ta.hash(); + }); + return hash; } OperatorNameId::OperatorNameId(Kind kind) @@ -153,9 +171,6 @@ bool OperatorNameId::match0(const Name *otherName, Matcher *matcher) const OperatorNameId::Kind OperatorNameId::kind() const { return _kind; } -const Identifier *OperatorNameId::identifier() const -{ return nullptr; } - ConversionNameId::ConversionNameId(const FullySpecifiedType &type) : _type(type) { } @@ -173,11 +188,7 @@ bool ConversionNameId::match0(const Name *otherName, Matcher *matcher) const return false; } -FullySpecifiedType ConversionNameId::type() const -{ return _type; } -const Identifier *ConversionNameId::identifier() const -{ return nullptr; } SelectorNameId::~SelectorNameId() { } @@ -231,5 +242,4 @@ bool AnonymousNameId::match0(const Name *otherName, Matcher *matcher) const return false; } -const Identifier *AnonymousNameId::identifier() const -{ return nullptr; } + |