From 5bee5dea132d755f903c73434ba17cdacb0578e3 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 13 Oct 2009 12:20:21 +0200 Subject: [PATCH] Check the scope of class and fwd-class declarations --- src/plugins/cpptools/cppfindreferences.cpp | 24 ++++++++++++++++++++-- src/shared/cplusplus/Symbol.cpp | 8 ++++++++ src/shared/cplusplus/Symbol.h | 2 ++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index 06bc4affa87..a60d8be4136 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -166,6 +166,26 @@ protected: return false; } + bool checkScope(Symbol *symbol, Symbol *otherSymbol) const + { + if (! (symbol && otherSymbol)) + return false; + + else if (symbol->scope() == otherSymbol->scope()) + return true; + + else if (symbol->name() && otherSymbol->name()) { + + if (! symbol->name()->isEqualTo(otherSymbol->name())) + return false; + + } else if (symbol->name() != otherSymbol->name()) { + return false; + } + + return checkScope(symbol->enclosingSymbol(), otherSymbol->enclosingSymbol()); + } + bool isDeclSymbol(Symbol *symbol) const { if (! symbol) @@ -180,11 +200,11 @@ protected: } else if (symbol->isForwardClassDeclaration() && (_declSymbol->isClass() || _declSymbol->isForwardClassDeclaration())) { - return true; + return checkScope(symbol, _declSymbol); } else if (_declSymbol->isForwardClassDeclaration() && (symbol->isClass() || symbol->isForwardClassDeclaration())) { - return true; + return checkScope(symbol, _declSymbol); } return false; diff --git a/src/shared/cplusplus/Symbol.cpp b/src/shared/cplusplus/Symbol.cpp index 3d3f3c78744..dc80add92b2 100644 --- a/src/shared/cplusplus/Symbol.cpp +++ b/src/shared/cplusplus/Symbol.cpp @@ -314,6 +314,14 @@ void Symbol::setScope(Scope *scope) _scope = scope; } +Symbol *Symbol::enclosingSymbol() const +{ + if (! _scope) + return 0; + + return _scope->owner(); +} + Scope *Symbol::enclosingNamespaceScope() const { if (! _scope) diff --git a/src/shared/cplusplus/Symbol.h b/src/shared/cplusplus/Symbol.h index 511e14c9f21..0857673d3f4 100644 --- a/src/shared/cplusplus/Symbol.h +++ b/src/shared/cplusplus/Symbol.h @@ -281,6 +281,8 @@ public: bool isGenerated() const; + Symbol *enclosingSymbol() const; + /// Returns the eclosing namespace scope. Scope *enclosingNamespaceScope() const;