diff options
author | Przemyslaw Gorszkowski <pgorszkowski@gmail.com> | 2013-02-01 21:43:38 +0100 |
---|---|---|
committer | Przemyslaw Gorszkowski <pgorszkowski@gmail.com> | 2013-02-11 10:27:47 +0100 |
commit | 4c800b1b5af28ad6011187ea6f9c7abf6be986ae (patch) | |
tree | 04b49ef1a4afade1bb5af772ee85a9210366a088 /src/libs/cplusplus/ResolveExpression.cpp | |
parent | 432aaf005b2bc21206629fb48f6aac8157eab1fd (diff) | |
download | qt-creator-4c800b1b5af28ad6011187ea6f9c7abf6be986ae.tar.gz |
C++: fix code completion for typedef of pointer
Fix code completion and highlighting member of typedefed pointers.
It works when typedef is inside or outside of the function.
Task-number: QTCREATORBUG-8671
Task-number: QTCREATORBUG-8672
Change-Id: I9cc87080bf443f7ffa6a90ef5ba582b87700f2db
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/libs/cplusplus/ResolveExpression.cpp')
-rw-r--r-- | src/libs/cplusplus/ResolveExpression.cpp | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/src/libs/cplusplus/ResolveExpression.cpp b/src/libs/cplusplus/ResolveExpression.cpp index 452aa88aa4..23c9b201b8 100644 --- a/src/libs/cplusplus/ResolveExpression.cpp +++ b/src/libs/cplusplus/ResolveExpression.cpp @@ -848,7 +848,7 @@ public: } private: - NamedType *getNamedType(FullySpecifiedType& type) + NamedType *getNamedType(FullySpecifiedType& type) const { NamedType *namedTy = type->asNamedType(); if (! namedTy) { @@ -858,19 +858,57 @@ private: return namedTy; } - QList<LookupItem> getNamedTypeItems(const Name *name, Scope *scope, ClassOrNamespace *binding) + QList<LookupItem> getNamedTypeItems(const Name *name, Scope *scope, + ClassOrNamespace *binding) const { - QList<LookupItem> namedTypeItems; - if (binding) - namedTypeItems = binding->lookup(name); - if (ClassOrNamespace *scopeCon = _context.lookupType(scope)) - namedTypeItems += scopeCon->lookup(name); + QList<LookupItem> namedTypeItems = typedefsFromScopeUpToFunctionScope(name, scope); + if (namedTypeItems.isEmpty()) { + if (binding) + namedTypeItems = binding->lookup(name); + if (ClassOrNamespace *scopeCon = _context.lookupType(scope)) + namedTypeItems += scopeCon->lookup(name); + } return namedTypeItems; } + /// Return all typedefs with given name from given scope up to function scope. + static QList<LookupItem> typedefsFromScopeUpToFunctionScope(const Name *name, Scope *scope) + { + QList<LookupItem> results; + Scope *enclosingBlockScope = 0; + for (Block *block = scope->asBlock(); block; + block = enclosingBlockScope ? enclosingBlockScope->asBlock() : 0) { + const unsigned memberCount = block->memberCount(); + for (unsigned i = 0; i < memberCount; ++i) { + Symbol *symbol = block->memberAt(i); + if (Declaration *declaration = symbol->asDeclaration()) { + if (isTypedefWithName(declaration, name)) { + LookupItem item; + item.setDeclaration(declaration); + item.setScope(block); + item.setType(declaration->type()); + results.append(item); + } + } + } + enclosingBlockScope = block->enclosingScope(); + } + return results; + } + + static bool isTypedefWithName(const Declaration *declaration, const Name *name) + { + if (declaration->isTypedef()) { + const Identifier *identifier = declaration->name()->identifier(); + if (name->identifier()->isEqualTo(identifier)) + return true; + } + return false; + } + bool findTypedef(const QList<LookupItem>& namedTypeItems, FullySpecifiedType *type, - Scope **scope, QSet<Symbol *>& visited) + Scope **scope, QSet<Symbol *>& visited) const { bool foundTypedef = false; foreach (const LookupItem &it, namedTypeItems) { @@ -931,6 +969,11 @@ ClassOrNamespace *ResolveExpression::baseExpression(const QList<LookupItem> &bas if (ClassOrNamespace *binding = findClass(type, scope)) return binding; + } else if (PointerType *ptrTy = ty->asPointerType()) { + FullySpecifiedType type = ptrTy->elementType(); + if (ClassOrNamespace *binding = findClass(type, scope)) + return binding; + } else if (ClassOrNamespace *binding = findClass(ty, scope)) { // lookup for overloads of operator-> |