From 1a7855af220156f00bdbb38a5cd53f11c6f9a0fb Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Fri, 13 Nov 2009 15:17:27 +0100 Subject: [PATCH] Match the value of the literals. --- src/shared/cplusplus/ASTMatcher.cpp | 3 +++ src/shared/cplusplus/Literals.cpp | 27 +++++++++++++-------------- src/shared/cplusplus/Literals.h | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/shared/cplusplus/ASTMatcher.cpp b/src/shared/cplusplus/ASTMatcher.cpp index 47dac58232a..5d137e9e9c1 100644 --- a/src/shared/cplusplus/ASTMatcher.cpp +++ b/src/shared/cplusplus/ASTMatcher.cpp @@ -57,6 +57,9 @@ bool ASTMatcher::matchToken(unsigned tokenIndex, unsigned patternTokenIndex) con else if (token.is(T_IDENTIFIER)) { if (! token.identifier->isEqualTo(otherToken.identifier)) return false; + } else if (token.isLiteral()) { + if (! token.literal->isEqualTo(otherToken.literal)) + return false; } return true; } diff --git a/src/shared/cplusplus/Literals.cpp b/src/shared/cplusplus/Literals.cpp index 40042eb66e4..078c0702705 100644 --- a/src/shared/cplusplus/Literals.cpp +++ b/src/shared/cplusplus/Literals.cpp @@ -72,6 +72,19 @@ Literal::Literal(const char *chars, unsigned size) Literal::~Literal() { delete[] _chars; } +bool Literal::isEqualTo(const Literal *other) const +{ + if (! other) + return false; + else if (this == other) + return true; + else if (hashCode() != other->hashCode()) + return false; + else if (size() != other->size()) + return false; + return ! strcmp(chars(), other->chars()); +} + Literal::iterator Literal::begin() const { return _chars; } @@ -214,17 +227,3 @@ Identifier::Identifier(const char *chars, unsigned size) Identifier::~Identifier() { } -bool Identifier::isEqualTo(const Identifier *other) const -{ - if (! other) - return false; - else if (this == other) - return true; - else if (hashCode() != other->hashCode()) - return false; - else if (size() != other->size()) - return false; - return ! strcmp(chars(), other->chars()); -} - - diff --git a/src/shared/cplusplus/Literals.h b/src/shared/cplusplus/Literals.h index 2a11cdada73..7f380ed0862 100644 --- a/src/shared/cplusplus/Literals.h +++ b/src/shared/cplusplus/Literals.h @@ -78,6 +78,8 @@ public: unsigned hashCode() const; static unsigned hashCode(const char *chars, unsigned size); + bool isEqualTo(const Literal *other) const; + private: char *_chars; unsigned _size; @@ -131,8 +133,6 @@ class CPLUSPLUS_EXPORT Identifier: public Literal public: Identifier(const char *chars, unsigned size); virtual ~Identifier(); - - bool isEqualTo(const Identifier *other) const; }; } // end of namespace CPlusPlus -- GitLab