aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPrzemyslaw Gorszkowski <[email protected]>2013-04-07 09:05:22 +0200
committerErik Verbruggen <[email protected]>2013-04-10 14:58:48 +0200
commitbde666724083126808507e46bc840eb601631a13 (patch)
tree4812ae8056a8cd231c99e47bb5f33f0aae1593cf /src
parent9c2a352027711519fb7dcc579f520717cd7ed115 (diff)
C++: name of function of class problem
It fixes: * highlighing * find usage * follow symbol when function of class has the same name as: * local variable * template parameter * other struct/union/class/enum * function argument in function scope. Task-number: QTCREATORBUG-8902 Change-Id: Iddc0f764af689babb40d39460d174bac7b919b31 Reviewed-by: Orgad Shaneh <[email protected]> Reviewed-by: Sergey Shambir <[email protected]> Reviewed-by: Erik Verbruggen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/libs/cplusplus/LookupContext.cpp30
-rw-r--r--src/plugins/cpptools/cppchecksymbols.cpp14
-rw-r--r--src/plugins/cpptools/cppchecksymbols.h2
3 files changed, 40 insertions, 6 deletions
diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp
index 12ee4933c33..08340671445 100644
--- a/src/libs/cplusplus/LookupContext.cpp
+++ b/src/libs/cplusplus/LookupContext.cpp
@@ -335,8 +335,14 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
if (name->identifier() != 0 && scope->isBlock()) {
bindings()->lookupInScope(name, scope, &candidates, /*templateId = */ 0, /*binding=*/ 0);
- if (! candidates.isEmpty())
- break; // it's a local.
+ if (! candidates.isEmpty()) {
+ // it's a local.
+ //for qualified it can be outside of the local scope
+ if (name->isQualifiedNameId())
+ continue;
+ else
+ break;
+ }
for (unsigned i = 0; i < scope->memberCount(); ++i) {
if (UsingNamespaceDirective *u = scope->memberAt(i)->asUsingNamespaceDirective()) {
@@ -352,8 +358,14 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
} else if (Function *fun = scope->asFunction()) {
bindings()->lookupInScope(name, fun, &candidates, /*templateId = */ 0, /*binding=*/ 0);
- if (! candidates.isEmpty())
- break; // it's an argument or a template parameter.
+ if (! candidates.isEmpty()) {
+ // it's an argument or a template parameter.
+ //for qualified it can be outside of the local scope
+ if (name->isQualifiedNameId())
+ continue;
+ else
+ break;
+ }
if (fun->name() && fun->name()->isQualifiedNameId()) {
if (ClassOrNamespace *binding = bindings()->lookupType(fun)) {
@@ -379,8 +391,14 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
} else if (Template *templ = scope->asTemplate()) {
bindings()->lookupInScope(name, templ, &candidates, /*templateId = */ 0, /*binding=*/ 0);
- if (! candidates.isEmpty())
- return candidates; // it's a template parameter.
+ if (! candidates.isEmpty()) {
+ // it's a template parameter.
+ //for qualified it can be outside of the local scope
+ if (name->isQualifiedNameId())
+ continue;
+ else
+ break;
+ }
} else if (scope->asNamespace()
|| scope->asClass()
diff --git a/src/plugins/cpptools/cppchecksymbols.cpp b/src/plugins/cpptools/cppchecksymbols.cpp
index fbf27666060..6ac5843c11e 100644
--- a/src/plugins/cpptools/cppchecksymbols.cpp
+++ b/src/plugins/cpptools/cppchecksymbols.cpp
@@ -1240,6 +1240,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
{
unsigned startToken = ast->firstToken();
bool isDestructor = false;
+ bool isConstructor = false;
if (DestructorNameAST *dtor = ast->asDestructorName()) {
isDestructor = true;
if (dtor->unqualified_name)
@@ -1264,6 +1265,8 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
if (isDestructor != c->name()->isDestructorNameId())
continue;
+ isConstructor = isConstructorDeclaration(c);
+
Function *funTy = c->type()->asFunctionType();
if (! funTy) {
//Try to find a template function
@@ -1296,7 +1299,9 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
}
if (matchType != Match_None) {
+ // decide how constructor and destructor should be highlighted
if (highlightCtorDtorAsType
+ && (isConstructor || isDestructor)
&& maybeType(ast->name)
&& kind == SemanticInfo::FunctionUse) {
return false;
@@ -1399,3 +1404,12 @@ void CheckSymbols::flush()
_usages.clear();
_usages.reserve(cap);
}
+
+bool CheckSymbols::isConstructorDeclaration(Symbol *declaration)
+{
+ Class *clazz = declaration->enclosingClass();
+ if (clazz && clazz->name())
+ return declaration->name()->isEqualTo(clazz->name());
+
+ return false;
+}
diff --git a/src/plugins/cpptools/cppchecksymbols.h b/src/plugins/cpptools/cppchecksymbols.h
index 2b69e000815..51c032bb9c3 100644
--- a/src/plugins/cpptools/cppchecksymbols.h
+++ b/src/plugins/cpptools/cppchecksymbols.h
@@ -165,6 +165,8 @@ protected:
void flush();
private:
+ bool isConstructorDeclaration(Symbol *declaration);
+
Document::Ptr _doc;
LookupContext _context;
TypeOfExpression typeOfExpression;