/// Return all typedefs with given name from given scope up to function scope. QList<LookupItem> TypeResolver::typedefsFromScopeUpToFunctionScope(const Name *name, Scope *scope) { QList<LookupItem> results; if (!scope) return 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(); if (enclosingBlockScope) { // For lambda, step beyond the function to its enclosing block if (Function *enclosingFunction = enclosingBlockScope->asFunction()) { if (!enclosingFunction->name()) enclosingBlockScope = enclosingBlockScope->enclosingScope(); } } } return results; }
Function *Symbol::enclosingFunction() const { for (Scope *s = _enclosingScope; s; s = s->enclosingScope()) { if (Function *fun = s->asFunction()) return fun; } return 0; }