diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp index 1e677f85c04e3fb2ca08a754cc5371addfcc979f..e6197884d2a4c08ae3f9facbfd5cec5bda8a18e1 100644 --- a/src/libs/cplusplus/CppDocument.cpp +++ b/src/libs/cplusplus/CppDocument.cpp @@ -76,13 +76,13 @@ public: } protected: - bool process(ScopedSymbol *symbol) + bool process(Scope *symbol) { if (! _scope) { - Scope *scope = symbol->members(); + Scope *scope = symbol; - for (unsigned i = 0; i < scope->symbolCount(); ++i) { - accept(scope->symbolAt(i)); + for (unsigned i = 0; i < scope->memberCount(); ++i) { + accept(scope->memberAt(i)); if (_scope) return false; @@ -388,14 +388,6 @@ Symbol *Document::globalSymbolAt(unsigned index) const return _globalNamespace->memberAt(index); } -Scope *Document::globalSymbols() const -{ - if (! _globalNamespace) - return 0; - - return _globalNamespace->members(); -} - Namespace *Document::globalNamespace() const { return _globalNamespace; @@ -411,20 +403,20 @@ Scope *Document::scopeAt(unsigned line, unsigned column) FindScopeAt findScopeAt(_translationUnit, line, column); if (Scope *scope = findScopeAt(_globalNamespace)) return scope; - return globalSymbols(); + return globalNamespace(); } Symbol *Document::lastVisibleSymbolAt(unsigned line, unsigned column) const { - return lastVisibleSymbolAt(line, column, globalSymbols()); + return lastVisibleSymbolAt(line, column, globalNamespace()); } Symbol *Document::lastVisibleSymbolAt(unsigned line, unsigned column, Scope *scope) const { Symbol *previousSymbol = 0; - for (unsigned i = 0; i < scope->symbolCount(); ++i) { - Symbol *symbol = scope->symbolAt(i); + for (unsigned i = 0; i < scope->memberCount(); ++i) { + Symbol *symbol = scope->memberAt(i); if (symbol->line() > line) break; @@ -432,8 +424,8 @@ Symbol *Document::lastVisibleSymbolAt(unsigned line, unsigned column, Scope *sco } if (previousSymbol) { - if (ScopedSymbol *scoped = previousSymbol->asScopedSymbol()) { - if (Symbol *member = lastVisibleSymbolAt(line, column, scoped->members())) + if (Scope *scope = previousSymbol->asScope()) { + if (Symbol *member = lastVisibleSymbolAt(line, column, scope)) return member; } } @@ -558,7 +550,7 @@ void Document::check(CheckMode mode) semantic.setSkipFunctionBodies(true); _globalNamespace = _control->newNamespace(0); - Scope *globals = _globalNamespace->members(); + Scope *globals = _globalNamespace; if (! _translationUnit->ast()) return; // nothing to do. diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h index cc1f9c2ff8c6ce62d739c0934ca010632439eb6f..b30efc2716c4e29b68f5960eb10e0800f7ffdbd2 100644 --- a/src/libs/cplusplus/CppDocument.h +++ b/src/libs/cplusplus/CppDocument.h @@ -84,7 +84,6 @@ public: unsigned globalSymbolCount() const; Symbol *globalSymbolAt(unsigned index) const; - Scope *globalSymbols() const; // ### deprecate? Namespace *globalNamespace() const; void setGlobalNamespace(Namespace *globalNamespace); // ### internal diff --git a/src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp b/src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp index 175477e88dc2870e35d1128c03fc136514dfbcb3..8bba41c07acd76d1388fd336b524a65683f8f0ec 100644 --- a/src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp +++ b/src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp @@ -401,7 +401,7 @@ FullySpecifiedType DeprecatedGenTemplateInstance::instantiate(const Name *classN { if (className) { if (const TemplateNameId *templId = className->asTemplateNameId()) { - if (Class *klass = candidate->enclosingSymbol()->asClass()) { + if (Class *klass = candidate->scope()->asClass()) { DeprecatedGenTemplateInstance::Substitution subst; for (unsigned i = 0; i < templId->templateArgumentCount(); ++i) { diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index c42c125b90e66785999dd8b880011b651f70e621..a381bb91b21f35f22b00a5989dd96beefbeb1753 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -209,7 +209,7 @@ bool FindUsages::checkCandidates(const QList<LookupItem> &candidates) const const LookupItem &r = candidates.at(i); if (Symbol *s = r.declaration()) { - if (_declSymbol->scope() && (_declSymbol->scope()->isPrototypeScope() || _declSymbol->scope()->isBlockScope())) { + if (_declSymbol->scope() && (_declSymbol->scope()->isFunction() || _declSymbol->scope()->isBlock())) { if (s->scope() != _declSymbol->scope()) return false; @@ -240,19 +240,12 @@ void FindUsages::checkExpression(unsigned startToken, unsigned endToken, Scope * reportResult(endToken, results); } -Scope *FindUsages::switchScope(ScopedSymbol *symbol) -{ - if (! symbol) - return _currentScope; // ### assert? - - return switchScope(symbol->members()); -} - Scope *FindUsages::switchScope(Scope *scope) { - Scope *previousScope = _currentScope; - _currentScope = scope; - return previousScope; + if (! scope) + return _currentScope; + + return switchScope(scope); } void FindUsages::statement(StatementAST *ast) @@ -345,7 +338,7 @@ bool FindUsages::visit(DeclaratorAST *ast) return false; } -void FindUsages::declarator(DeclaratorAST *ast, ScopedSymbol *symbol) +void FindUsages::declarator(DeclaratorAST *ast, Scope *symbol) { if (! ast) return; @@ -493,13 +486,13 @@ void FindUsages::memInitializer(MemInitializerAST *ast) if (! ast) return; - if (_currentScope->isPrototypeScope()) { - Scope *classScope = _currentScope->enclosingClassScope(); + if (_currentScope->isFunction()) { + Class *classScope = _currentScope->enclosingClass(); if (! classScope) { - if (ClassOrNamespace *binding = _context.lookupType(_currentScope->owner())) { + if (ClassOrNamespace *binding = _context.lookupType(_currentScope)) { foreach (Symbol *s, binding->symbols()) { if (Class *k = s->asClass()) { - classScope = k->members(); + classScope = k; break; } } @@ -658,7 +651,7 @@ void FindUsages::translationUnit(TranslationUnitAST *ast) if (! ast) return; - Scope *previousScope = switchScope(_doc->globalSymbols()); + Scope *previousScope = switchScope(_doc->globalNamespace()); for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) { this->declaration(it->value); } diff --git a/src/libs/cplusplus/FindUsages.h b/src/libs/cplusplus/FindUsages.h index bf9e86bfd83b9984c09464ef1ab172ba4ad4903e..64e854df9bd6afe32bcc4b1395ee1783bfa93623 100644 --- a/src/libs/cplusplus/FindUsages.h +++ b/src/libs/cplusplus/FindUsages.h @@ -71,7 +71,6 @@ protected: using ASTVisitor::translationUnit; Scope *switchScope(Scope *scope); - Scope *switchScope(ScopedSymbol *symbol); QString matchingLine(const Token &tk) const; @@ -97,7 +96,7 @@ protected: void objCSelectorArgument(ObjCSelectorArgumentAST *ast); void attribute(AttributeAST *ast); - void declarator(DeclaratorAST *ast, ScopedSymbol *symbol = 0); + void declarator(DeclaratorAST *ast, Scope *symbol = 0); void qtPropertyDeclarationItem(QtPropertyDeclarationItemAST *ast); void qtInterfaceName(QtInterfaceNameAST *ast); void baseSpecifier(BaseSpecifierAST *ast); diff --git a/src/libs/cplusplus/Icons.cpp b/src/libs/cplusplus/Icons.cpp index a3bb5a38ef3514579bbe920ca228307fcfd94ff1..51a7bea017caca4f94d4ffae37d17c1881fa5f34 100644 --- a/src/libs/cplusplus/Icons.cpp +++ b/src/libs/cplusplus/Icons.cpp @@ -99,7 +99,7 @@ Icons::IconType Icons::iconTypeForSymbol(const Symbol *symbol) } else if (symbol->isPrivate()) { return FuncPrivateIconType; } - } else if (symbol->scope() && symbol->scope()->isEnumScope()) { + } else if (symbol->scope() && symbol->scope()->isEnum()) { return EnumeratorIconType; } else if (symbol->isDeclaration() || symbol->isArgument()) { if (symbol->isPublic()) { diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index cdc1018e2de398da455385ad29bc62194502219e..e56ffcbc074502dc83eca7988b848a6d0aabf35c 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -68,7 +68,7 @@ static void path_helper(Symbol *symbol, QList<const Name *> *names) if (! symbol) return; - path_helper(symbol->enclosingSymbol(), names); + path_helper(symbol->scope(), names); if (symbol->name()) { if (symbol->isClass() || symbol->isNamespace()) { @@ -142,7 +142,7 @@ LookupContext &LookupContext::operator = (const LookupContext &other) QList<const Name *> LookupContext::fullyQualifiedName(Symbol *symbol) { - QList<const Name *> qualifiedName = path(symbol->enclosingSymbol()); + QList<const Name *> qualifiedName = path(symbol->scope()); addNames(symbol->name(), &qualifiedName, /*add all names*/ true); return qualifiedName; } @@ -238,7 +238,7 @@ ClassOrNamespace *LookupContext::globalNamespace() const ClassOrNamespace *LookupContext::lookupType(const Name *name, Scope *scope) const { - if (ClassOrNamespace *b = bindings()->lookupType(scope->owner())) + if (ClassOrNamespace *b = bindings()->lookupType(scope)) return b->lookupType(name); return 0; @@ -256,18 +256,18 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const if (! name) return candidates; - for (; scope; scope = scope->enclosingScope()) { - if ((name->isNameId() || name->isTemplateNameId()) && scope->isBlockScope()) { + for (; scope; scope = scope->scope()) { + if ((name->isNameId() || name->isTemplateNameId()) && scope->isBlock()) { bindings()->lookupInScope(name, scope, &candidates, /*templateId = */ 0, /*binding=*/ 0); if (! candidates.isEmpty()) break; // it's a local. - for (unsigned index = 0; index < scope->symbolCount(); ++index) { - Symbol *member = scope->symbolAt(index); + for (unsigned index = 0; index < scope->memberCount(); ++index) { + Symbol *member = scope->memberAt(index); if (UsingNamespaceDirective *u = member->asUsingNamespaceDirective()) { - if (Namespace *enclosingNamespace = u->enclosingNamespaceScope()->owner()->asNamespace()) { + if (Namespace *enclosingNamespace = u->enclosingNamespace()->asNamespace()) { if (ClassOrNamespace *b = bindings()->lookupType(enclosingNamespace)) { if (ClassOrNamespace *uu = b->lookupType(u->name())) { candidates = uu->find(name); @@ -280,9 +280,8 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const } } - } else if (scope->isPrototypeScope()) { - Function *fun = scope->owner()->asFunction(); - bindings()->lookupInScope(name, fun->members(), &candidates, /*templateId = */ 0, /*binding=*/ 0); + } else if (Function *fun = scope->asFunction()) { + bindings()->lookupInScope(name, fun, &candidates, /*templateId = */ 0, /*binding=*/ 0); for (TemplateParameters *it = fun->templateParameters(); it && candidates.isEmpty(); it = it->previous()) bindings()->lookupInScope(name, it->scope(), &candidates, /* templateId = */ 0, /*binding=*/ 0); @@ -301,16 +300,13 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const // contunue, and look at the enclosing scope. - } else if (scope->isObjCMethodScope()) { - ObjCMethod *method = scope->owner()->asObjCMethod(); - bindings()->lookupInScope(name, method->arguments(), &candidates, /*templateId = */ 0, /*binding=*/ 0); + } else if (ObjCMethod *method = scope->asObjCMethod()) { + bindings()->lookupInScope(name, method, &candidates, /*templateId = */ 0, /*binding=*/ 0); if (! candidates.isEmpty()) break; // it's a formal argument. - } else if (scope->isClassScope()) { - Class *klass = scope->owner()->asClass(); - + } else if (Class *klass = scope->asClass()) { for (TemplateParameters *it = klass->templateParameters(); it && candidates.isEmpty(); it = it->previous()) bindings()->lookupInScope(name, it->scope(), &candidates, /* templateId = */ 0, /*binding=*/ 0); @@ -324,15 +320,15 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const return candidates; } - } else if (scope->isNamespaceScope()) { - if (ClassOrNamespace *binding = bindings()->lookupType(scope->owner())) + } else if (Namespace *ns = scope->asNamespace()) { + if (ClassOrNamespace *binding = bindings()->lookupType(ns)) candidates = binding->find(name); if (! candidates.isEmpty()) return candidates; - } else if (scope->isObjCClassScope() || scope->isObjCProtocolScope()) { - if (ClassOrNamespace *binding = bindings()->lookupType(scope->owner())) + } else if (scope->isObjCClass() || scope->isObjCProtocol()) { + if (ClassOrNamespace *binding = bindings()->lookupType(scope)) candidates = binding->find(name); if (! candidates.isEmpty()) @@ -456,8 +452,8 @@ void ClassOrNamespace::lookup_helper(const Name *name, ClassOrNamespace *binding if (s->isFriend()) continue; - if (ScopedSymbol *scoped = s->asScopedSymbol()) { - if (Class *klass = scoped->asClass()) { + if (Scope *scope = s->asScope()) { + if (Class *klass = scope->asClass()) { if (const Identifier *id = klass->identifier()) { if (nameId && nameId->isEqualTo(id)) { LookupItem item; @@ -467,12 +463,12 @@ void ClassOrNamespace::lookup_helper(const Name *name, ClassOrNamespace *binding } } } - _factory->lookupInScope(name, scoped->members(), result, templateId, binding); + _factory->lookupInScope(name, scope, result, templateId, binding); } } foreach (Enum *e, binding->enums()) - _factory->lookupInScope(name, e->members(), result, templateId, binding); + _factory->lookupInScope(name, e, result, templateId, binding); foreach (ClassOrNamespace *u, binding->usings()) lookup_helper(name, u, result, processed, binding->_templateId); @@ -490,7 +486,7 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope, return; } else if (const OperatorNameId *op = name->asOperatorNameId()) { - for (Symbol *s = scope->lookat(op->kind()); s; s = s->next()) { + for (Symbol *s = scope->find(op->kind()); s; s = s->next()) { if (! s->name()) continue; else if (s->isFriend()) @@ -505,7 +501,7 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope, } } else if (const Identifier *id = name->identifier()) { - for (Symbol *s = scope->lookat(id); s; s = s->next()) { + for (Symbol *s = scope->find(id); s; s = s->next()) { if (s->isFriend()) continue; // skip friends else if (! id->isEqualTo(s->identifier())) diff --git a/src/libs/cplusplus/OverviewModel.cpp b/src/libs/cplusplus/OverviewModel.cpp index c3953a29e8d74b372242b6463200b58cdde80fb5..2174735c1185aaebd73e2a6c02e3aa1fd217d821 100644 --- a/src/libs/cplusplus/OverviewModel.cpp +++ b/src/libs/cplusplus/OverviewModel.cpp @@ -79,13 +79,9 @@ QModelIndex OverviewModel::index(int row, int column, const QModelIndex &parent) Symbol *parentSymbol = static_cast<Symbol *>(parent.internalPointer()); Q_ASSERT(parentSymbol); - ScopedSymbol *scopedSymbol = parentSymbol->asScopedSymbol(); - Q_ASSERT(scopedSymbol); - - Scope *scope = scopedSymbol->members(); - Q_ASSERT(scope); - - return createIndex(row, 0, scope->symbolAt(row)); + Scope *scope = parentSymbol->asScope(); + Q_ASSERT(scope != 0); + return createIndex(row, 0, scope->memberAt(row)); } } @@ -96,14 +92,12 @@ QModelIndex OverviewModel::parent(const QModelIndex &child) const return QModelIndex(); if (Scope *scope = symbol->scope()) { - Symbol *parentSymbol = scope->owner(); - if (parentSymbol && parentSymbol->scope()) { + if (scope->scope()) { QModelIndex index; - if (parentSymbol->scope() && parentSymbol->scope()->owner() - && parentSymbol->scope()->owner()->scope()) // the parent doesn't have a parent - index = createIndex(parentSymbol->index(), 0, parentSymbol); + if (scope->scope() && scope->scope()->scope()) // the parent doesn't have a parent + index = createIndex(scope->index(), 0, scope); else //+1 to account for no symbol item - index = createIndex(parentSymbol->index() + 1, 0, parentSymbol); + index = createIndex(scope->index() + 1, 0, scope); return index; } } @@ -122,12 +116,9 @@ int OverviewModel::rowCount(const QModelIndex &parent) const Symbol *parentSymbol = static_cast<Symbol *>(parent.internalPointer()); Q_ASSERT(parentSymbol); - if (ScopedSymbol *scopedSymbol = parentSymbol->asScopedSymbol()) { - if (!scopedSymbol->isFunction() && !scopedSymbol->isObjCMethod()) { - Scope *parentScope = scopedSymbol->members(); - Q_ASSERT(parentScope); - - return parentScope->symbolCount(); + if (Scope *parentScope = parentSymbol->asScope()) { + if (!parentScope->isFunction() && !parentScope->isObjCMethod()) { + return parentScope->memberCount(); } } return 0; diff --git a/src/libs/cplusplus/ResolveExpression.cpp b/src/libs/cplusplus/ResolveExpression.cpp index 6cb276d81b0a55904deabc061e52526085920f02..55c4c3ac42acd4a260e09932a263b0f00ccfa93a 100644 --- a/src/libs/cplusplus/ResolveExpression.cpp +++ b/src/libs/cplusplus/ResolveExpression.cpp @@ -88,7 +88,8 @@ QList<LookupItem> ResolveExpression::operator()(ExpressionAST *ast, Scope *scope QList<LookupItem> ResolveExpression::resolve(ExpressionAST *ast, Scope *scope) { - Q_ASSERT(scope != 0); + if (! scope) + return QList<LookupItem>(); Scope *previousVisibleSymbol = _scope; _scope = scope; @@ -174,7 +175,7 @@ bool ResolveExpression::visit(BinaryExpressionAST *ast) bool ResolveExpression::visit(CastExpressionAST *ast) { - Scope *dummyScope = _context.expressionDocument()->globalSymbols(); + Scope *dummyScope = _context.expressionDocument()->globalNamespace(); FullySpecifiedType ty = sem.check(ast->type_id, dummyScope); addResult(ty, _scope); return false; @@ -199,7 +200,7 @@ bool ResolveExpression::visit(ConditionalExpressionAST *ast) bool ResolveExpression::visit(CppCastExpressionAST *ast) { - Scope *dummyScope = _context.expressionDocument()->globalSymbols(); + Scope *dummyScope = _context.expressionDocument()->globalNamespace(); FullySpecifiedType ty = sem.check(ast->type_id, dummyScope); addResult(ty, _scope); return false; @@ -221,7 +222,7 @@ bool ResolveExpression::visit(ArrayInitializerAST *) bool ResolveExpression::visit(NewExpressionAST *ast) { if (ast->new_type_id) { - Scope *dummyScope = _context.expressionDocument()->globalSymbols(); + Scope *dummyScope = _context.expressionDocument()->globalNamespace(); FullySpecifiedType ty = sem.check(ast->new_type_id->type_specifier_list, dummyScope); ty = sem.check(ast->new_type_id->ptr_operator_list, ty, dummyScope); FullySpecifiedType ptrTy(control()->pointerType(ty)); @@ -315,11 +316,9 @@ bool ResolveExpression::visit(ThisExpressionAST *) void ResolveExpression::thisObject() { Scope *scope = _scope; - for (; scope; scope = scope->enclosingScope()) { - if (scope->isPrototypeScope()) { - Function *fun = scope->owner()->asFunction(); - if (Scope *cscope = scope->enclosingClassScope()) { - Class *klass = cscope->owner()->asClass(); + for (; scope; scope = scope->scope()) { + if (Function *fun = scope->asFunction()) { + if (Class *klass = scope->enclosingClass()) { FullySpecifiedType classTy(control()->namedType(klass->name())); FullySpecifiedType ptrTy(control()->pointerType(classTy)); addResult(ptrTy, fun->scope()); @@ -562,7 +561,7 @@ QList<LookupItem> ResolveExpression::getMembers(ClassOrNamespace *binding, const Symbol *decl = m.declaration(); - if (Class *klass = decl->enclosingSymbol()->asClass()) { + if (Class *klass = decl->scope()->asClass()) { if (klass->templateParameters() != 0) { SubstitutionMap map; diff --git a/src/plugins/classview/classviewparser.cpp b/src/plugins/classview/classviewparser.cpp index 32c55040699276300d92cb73bb271e525acd7239..42d9f3cc00ed41f1fefdc9b3fbe1c52892f68a21 100644 --- a/src/plugins/classview/classviewparser.cpp +++ b/src/plugins/classview/classviewparser.cpp @@ -289,7 +289,7 @@ void Parser::addSymbol(const ParserTreeItem::Ptr &item, const CPlusPlus::Symbol return; // skip static local functions -// if ((!symbol->scope() || symbol->scope()->owner()->isClass()) +// if ((!symbol->scope() || symbol->scope()->isClass()) // && symbol->isStatic() && symbol->isFunction()) // return; @@ -320,22 +320,19 @@ void Parser::addSymbol(const ParserTreeItem::Ptr &item, const CPlusPlus::Symbol // prevent showing a content of the functions if (!symbol->isFunction()) { - const CPlusPlus::ScopedSymbol *scopedSymbol = symbol->asScopedSymbol(); - if (scopedSymbol) { - CPlusPlus::Scope *scope = scopedSymbol->members(); - if (scope) { - CPlusPlus::Scope::iterator cur = scope->firstSymbol(); - while (cur != scope->lastSymbol()) { - const CPlusPlus::Symbol *curSymbol = *cur; - ++cur; - if (!curSymbol) - continue; - - // if (!symbol->isClass() && curSymbol->isStatic() && curSymbol->isFunction()) - // return; - - addSymbol(itemAdd, curSymbol); - } + const CPlusPlus::Scope *scope = symbol->asScope(); + if (scope) { + CPlusPlus::Scope::iterator cur = scope->firstMember(); + while (cur != scope->lastMember()) { + const CPlusPlus::Symbol *curSymbol = *cur; + ++cur; + if (!curSymbol) + continue; + + // if (!symbol->isClass() && curSymbol->isStatic() && curSymbol->isFunction()) + // return; + + addSymbol(itemAdd, curSymbol); } } } diff --git a/src/plugins/cppeditor/cppchecksymbols.cpp b/src/plugins/cppeditor/cppchecksymbols.cpp index 29390852540e6753608001539cd29f27b29ccf29..83aa5bca0a893c08039e503c43c592473d895e62 100644 --- a/src/plugins/cppeditor/cppchecksymbols.cpp +++ b/src/plugins/cppeditor/cppchecksymbols.cpp @@ -181,8 +181,8 @@ protected: for (TemplateParameters *p = symbol->templateParameters(); p; p = p->previous()) { Scope *scope = p->scope(); - for (unsigned i = 0; i < scope->symbolCount(); ++i) - accept(scope->symbolAt(i)); + for (unsigned i = 0; i < scope->memberCount(); ++i) + accept(scope->memberAt(i)); } return true; @@ -201,7 +201,7 @@ protected: virtual bool visit(Declaration *symbol) { - if (symbol->enclosingEnumScope() != 0) + if (symbol->enclosingEnum() != 0) addStatic(symbol->name()); if (Function *funTy = symbol->type()->asFunctionType()) { @@ -211,7 +211,7 @@ protected: if (symbol->isTypedef()) addType(symbol->name()); - else if (! symbol->type()->isFunctionType() && symbol->enclosingSymbol()->isClass()) + else if (! symbol->type()->isFunctionType() && symbol->scope()->isClass()) addMember(symbol->name()); return true; @@ -239,8 +239,8 @@ protected: { for (TemplateParameters *p = symbol->templateParameters(); p; p = p->previous()) { Scope *scope = p->scope(); - for (unsigned i = 0; i < scope->symbolCount(); ++i) - accept(scope->symbolAt(i)); + for (unsigned i = 0; i < scope->memberCount(); ++i) + accept(scope->memberAt(i)); } addType(symbol->name()); @@ -251,8 +251,8 @@ protected: { for (TemplateParameters *p = symbol->templateParameters(); p; p = p->previous()) { Scope *scope = p->scope(); - for (unsigned i = 0; i < scope->symbolCount(); ++i) - accept(scope->symbolAt(i)); + for (unsigned i = 0; i < scope->memberCount(); ++i) + accept(scope->memberAt(i)); } addType(symbol->name()); @@ -383,48 +383,48 @@ Scope *CheckSymbols::enclosingScope() const if (NamespaceAST *ns = ast->asNamespace()) { if (ns->symbol) - return ns->symbol->members(); + return ns->symbol; } else if (ClassSpecifierAST *classSpec = ast->asClassSpecifier()) { if (classSpec->symbol) - return classSpec->symbol->members(); + return classSpec->symbol; } else if (FunctionDefinitionAST *funDef = ast->asFunctionDefinition()) { if (funDef->symbol) - return funDef->symbol->members(); + return funDef->symbol; } else if (CompoundStatementAST *blockStmt = ast->asCompoundStatement()) { if (blockStmt->symbol) - return blockStmt->symbol->members(); + return blockStmt->symbol; } else if (IfStatementAST *ifStmt = ast->asIfStatement()) { if (ifStmt->symbol) - return ifStmt->symbol->members(); + return ifStmt->symbol; } else if (WhileStatementAST *whileStmt = ast->asWhileStatement()) { if (whileStmt->symbol) - return whileStmt->symbol->members(); + return whileStmt->symbol; } else if (ForStatementAST *forStmt = ast->asForStatement()) { if (forStmt->symbol) - return forStmt->symbol->members(); + return forStmt->symbol; } else if (ForeachStatementAST *foreachStmt = ast->asForeachStatement()) { if (foreachStmt->symbol) - return foreachStmt->symbol->members(); + return foreachStmt->symbol; } else if (SwitchStatementAST *switchStmt = ast->asSwitchStatement()) { if (switchStmt->symbol) - return switchStmt->symbol->members(); + return switchStmt->symbol; } else if (CatchClauseAST *catchClause = ast->asCatchClause()) { if (catchClause->symbol) - return catchClause->symbol->members(); + return catchClause->symbol; } } - return _doc->globalSymbols(); + return _doc->globalNamespace(); } bool CheckSymbols::preVisit(AST *ast) @@ -596,7 +596,7 @@ bool CheckSymbols::hasVirtualDestructor(Class *klass) const const Identifier *id = klass->identifier(); if (! id) return false; - for (Symbol *s = klass->members()->lookat(id); s; s = s->next()) { + for (Symbol *s = klass->find(id); s; s = s->next()) { if (! s->name()) continue; else if (s->name()->isDestructorNameId()) { @@ -639,8 +639,8 @@ void CheckSymbols::checkName(NameAST *ast, Scope *scope) if (! scope) scope = enclosingScope(); - if (ast->asDestructorName() != 0 && scope->isClassScope()) { - Class *klass = scope->owner()->asClass(); + if (ast->asDestructorName() != 0 && scope->isClass()) { + Class *klass = scope->asClass(); if (hasVirtualDestructor(_context.lookupType(klass))) addUse(ast, Use::VirtualMethod); } else if (maybeType(ast->name) || maybeStatic(ast->name)) { @@ -735,7 +735,7 @@ bool CheckSymbols::visit(MemInitializerAST *ast) if (ClassOrNamespace *binding = _context.lookupType(enclosingFunction->symbol)) { foreach (Symbol *s, binding->symbols()) { if (Class *klass = s->asClass()){ - checkName(ast->name, klass->members()); + checkName(ast->name, klass); break; } } @@ -876,7 +876,7 @@ void CheckSymbols::addTypeOrStatic(const QList<LookupItem> &candidates, NameAST continue; else if (c->isTypedef() || c->isNamespace() || c->isClass() || c->isEnum() || - c->isForwardClassDeclaration() || c->isTypenameArgument() || c->enclosingEnumScope() != 0) { + c->isForwardClassDeclaration() || c->isTypenameArgument() || c->enclosingEnum() != 0) { unsigned line, column; getTokenStartPosition(startToken, &line, &column); @@ -884,7 +884,7 @@ void CheckSymbols::addTypeOrStatic(const QList<LookupItem> &candidates, NameAST Use::Kind kind = Use::Type; - if (c->enclosingEnumScope() != 0) + if (c->enclosingEnum() != 0) kind = Use::Static; const Use use(line, column, length, kind); @@ -911,7 +911,7 @@ void CheckSymbols::addClassMember(const QList<LookupItem> &candidates, NameAST * continue; else if (! c->isDeclaration()) return; - else if (! (c->enclosingSymbol() && c->enclosingSymbol()->isClass())) + else if (! (c->scope() && c->scope()->isClass())) return; // shadowed else if (c->isTypedef() || c->type()->isFunctionType()) return; // shadowed @@ -940,7 +940,7 @@ void CheckSymbols::addStatic(const QList<LookupItem> &candidates, NameAST *ast) Symbol *c = r.declaration(); if (! c) return; - if (c->scope()->isEnumScope()) { + if (c->scope()->isEnum()) { unsigned line, column; getTokenStartPosition(startToken, &line, &column); const unsigned length = tok.length(); diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index e067cb37b0869744c4ce8f866b1e28cf31f185c8..775b2ee48833e413ca69e887350e9e412ba7899b 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -246,8 +246,8 @@ public: _declarationName = declarationName; _functions = functions; - for (unsigned i = 0; i < globals->symbolCount(); ++i) { - accept(globals->symbolAt(i)); + for (unsigned i = 0; i < globals->memberCount(); ++i) { + accept(globals->memberAt(i)); } } @@ -350,7 +350,7 @@ struct CanonicalSymbol break; else if (! r.declaration()->scope()) break; - else if (! r.declaration()->scope()->isClassScope()) + else if (! r.declaration()->scope()->isClass()) break; if (Function *funTy = r.declaration()->type()->asFunctionType()) @@ -1079,20 +1079,20 @@ void CPPEditor::switchDeclarationDefinition() Symbol *lastVisibleSymbol = thisDocument->lastVisibleSymbolAt(line, column); Scope *functionScope = 0; - if (scope->isPrototypeScope()) + if (scope->isFunction()) functionScope = scope; else - functionScope = scope->enclosingPrototypeScope(); + functionScope = scope->enclosingFunction(); if (! functionScope && lastVisibleSymbol) { if (Function *def = lastVisibleSymbol->asFunction()) - functionScope = def->members(); + functionScope = def; } if (functionScope) { LookupContext context(thisDocument, snapshot); - Function *functionDefinition = functionScope->owner()->asFunction(); + Function *functionDefinition = functionScope->asFunction(); const QList<LookupItem> declarations = context.lookup(functionDefinition->name(), functionDefinition->scope()); foreach (const LookupItem &r, declarations) { Symbol *decl = r.declaration(); diff --git a/src/plugins/cppeditor/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp index d90162e6088f5b7ca88339c6218be6382a75eb2d..0d4d24241b7a65f562c12d3e92e0040fe11b9a54 100644 --- a/src/plugins/cppeditor/cpphoverhandler.cpp +++ b/src/plugins/cppeditor/cpphoverhandler.cpp @@ -249,9 +249,9 @@ void CppHoverHandler::handleLookupItemMatch(const LookupItem &lookupItem, setToolTip(overview.prettyType(matchingType, QString())); } else { QString name; - if (matchingDeclaration->enclosingSymbol()->isClass() || - matchingDeclaration->enclosingSymbol()->isNamespace() || - matchingDeclaration->enclosingSymbol()->isEnum()) { + if (matchingDeclaration->scope()->isClass() || + matchingDeclaration->scope()->isNamespace() || + matchingDeclaration->scope()->isEnum()) { name.append(overview.prettyName( LookupContext::fullyQualifiedName(matchingDeclaration))); @@ -280,7 +280,7 @@ void CppHoverHandler::handleLookupItemMatch(const LookupItem &lookupItem, matchingDeclaration->isForwardClassDeclaration()) { helpCategory = HelpCandidate::ClassOrNamespace; } else if (matchingDeclaration->isEnum() || - matchingDeclaration->enclosingSymbol()->isEnum()) { + matchingDeclaration->scope()->isEnum()) { helpCategory = HelpCandidate::Enum; } else if (matchingDeclaration->isTypedef()) { helpCategory = HelpCandidate::Typedef; @@ -327,8 +327,8 @@ void CppHoverHandler::handleLookupItemMatch(const LookupItem &lookupItem, overview.setShowFunctionSignatures(false); const QString &functionName = overview.prettyName(matchingDeclaration->name()); addHelpCandidate(HelpCandidate(functionName, docMark, helpCategory)); - } else if (matchingDeclaration->enclosingSymbol()->isEnum()) { - Symbol *enumSymbol = matchingDeclaration->enclosingSymbol()->asEnum(); + } else if (matchingDeclaration->scope()->isEnum()) { + Symbol *enumSymbol = matchingDeclaration->scope()->asEnum(); docMark = overview.prettyName(enumSymbol->name()); } diff --git a/src/plugins/cppeditor/cpplocalsymbols.cpp b/src/plugins/cppeditor/cpplocalsymbols.cpp index 34122c2bcbfafbdd62bf6883dea7387614604b23..0404c084e61c7c32004e30b1aeafb0d13dbb3eb9 100644 --- a/src/plugins/cppeditor/cpplocalsymbols.cpp +++ b/src/plugins/cppeditor/cpplocalsymbols.cpp @@ -68,12 +68,12 @@ public: if (FunctionDefinitionAST *def = ast->asFunctionDefinition()) { if (def->symbol) { - _functionScope = def->symbol->members(); + _functionScope = def->symbol; accept(ast); } } else if (ObjCMethodDeclarationAST *decl = ast->asObjCMethodDeclaration()) { if (decl->method_prototype->symbol) { - _functionScope = decl->method_prototype->symbol->members(); + _functionScope = decl->method_prototype->symbol; accept(ast); } } @@ -87,8 +87,8 @@ protected: { _scopeStack.append(scope); - for (unsigned i = 0; i < scope->symbolCount(); ++i) { - if (Symbol *member = scope->symbolAt(i)) { + for (unsigned i = 0; i < scope->memberCount(); ++i) { + if (Symbol *member = scope->memberAt(i)) { if (! member->isGenerated() && (member->isDeclaration() || member->isArgument())) { if (member->name() && member->name()->isNameId()) { const Identifier *id = member->identifier(); @@ -106,8 +106,8 @@ protected: if (SimpleNameAST *simpleName = ast->name->asSimpleName()) { const Identifier *id = identifier(simpleName->identifier_token); for (int i = _scopeStack.size() - 1; i != -1; --i) { - if (Symbol *member = _scopeStack.at(i)->lookat(id)) { - if (!member->isGenerated() && (member->sourceLocation() < ast->firstToken() || member->scope()->isPrototypeScope())) { + if (Symbol *member = _scopeStack.at(i)->find(id)) { + if (!member->isGenerated() && (member->sourceLocation() < ast->firstToken() || member->scope()->isFunction())) { unsigned line, column; getTokenStartPosition(simpleName->identifier_token, &line, &column); localUses[member].append(SemanticInfo::Use(line, column, id->size(), SemanticInfo::Use::Local)); @@ -133,7 +133,7 @@ protected: virtual bool visit(FunctionDefinitionAST *ast) { if (ast->symbol) - enterScope(ast->symbol->members()); + enterScope(ast->symbol); return true; } @@ -146,7 +146,7 @@ protected: virtual bool visit(CompoundStatementAST *ast) { if (ast->symbol) - enterScope(ast->symbol->members()); + enterScope(ast->symbol); return true; } @@ -159,7 +159,7 @@ protected: virtual bool visit(IfStatementAST *ast) { if (ast->symbol) - enterScope(ast->symbol->members()); + enterScope(ast->symbol); return true; } @@ -172,7 +172,7 @@ protected: virtual bool visit(WhileStatementAST *ast) { if (ast->symbol) - enterScope(ast->symbol->members()); + enterScope(ast->symbol); return true; } @@ -185,7 +185,7 @@ protected: virtual bool visit(ForStatementAST *ast) { if (ast->symbol) - enterScope(ast->symbol->members()); + enterScope(ast->symbol); return true; } @@ -198,7 +198,7 @@ protected: virtual bool visit(ForeachStatementAST *ast) { if (ast->symbol) - enterScope(ast->symbol->members()); + enterScope(ast->symbol); return true; } @@ -211,7 +211,7 @@ protected: virtual bool visit(SwitchStatementAST *ast) { if (ast->symbol) - enterScope(ast->symbol->members()); + enterScope(ast->symbol); return true; } @@ -224,7 +224,7 @@ protected: virtual bool visit(CatchClauseAST *ast) { if (ast->symbol) - enterScope(ast->symbol->members()); + enterScope(ast->symbol); return true; } diff --git a/src/plugins/cpptools/abstracteditorsupport.cpp b/src/plugins/cpptools/abstracteditorsupport.cpp index d1edabf72d90b35a86e8370d71ddde068c2f99a3..938e23c0ede0bdc9fd054e7e7d7a5d0eb02ba3d6 100644 --- a/src/plugins/cpptools/abstracteditorsupport.cpp +++ b/src/plugins/cpptools/abstracteditorsupport.cpp @@ -68,15 +68,14 @@ QString AbstractEditorSupport::functionAt(const CppModelManagerInterface *modelM return QString(); if (const CPlusPlus::Symbol *symbol = document->lastVisibleSymbolAt(line, column)) if (const CPlusPlus::Scope *scope = symbol->scope()) - if (const CPlusPlus::Scope *functionScope = scope->enclosingPrototypeScope()) - if (const CPlusPlus::Symbol *function = functionScope->owner()) { + if (const CPlusPlus::Scope *functionScope = scope->enclosingFunction()) + if (const CPlusPlus::Symbol *function = functionScope) { const CPlusPlus::Overview o; QString rc = o.prettyName(function->name()); // Prepend namespace "Foo::Foo::foo()" up to empty root namespace for (const CPlusPlus::Symbol *owner = function; ; ) { - if (const CPlusPlus::Scope *nameSpace = owner->enclosingNamespaceScope()) { - owner = nameSpace->owner(); - const QString name = o.prettyName(owner->name()); + if (const CPlusPlus::Scope *nameSpace = owner->enclosingNamespace()) { + const QString name = o.prettyName(nameSpace->name()); if (name.isEmpty()) { break; } else { diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index 946e0719042eb0e1b586a934cf268034e26ca0f5..178c7e84b55f11fd6d724572c3d61c81bcb8a216 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -709,12 +709,12 @@ void CppCodeCompletion::completeObjCMsgSend(ClassOrNamespace *binding, QList<Scope*> memberScopes; foreach (Symbol *s, binding->symbols()) { if (ObjCClass *c = s->asObjCClass()) - memberScopes.append(c->members()); + memberScopes.append(c); } foreach (Scope *scope, memberScopes) { - for (unsigned i = 0; i < scope->symbolCount(); ++i) { - Symbol *symbol = scope->symbolAt(i); + for (unsigned i = 0; i < scope->memberCount(); ++i) { + Symbol *symbol = scope->memberAt(i); if (ObjCMethod *method = symbol->type()->asObjCMethodType()) { if (method->isStatic() == staticClassAccess) { @@ -1055,11 +1055,11 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope) QList<ClassOrNamespace *> usingBindings; ClassOrNamespace *currentBinding = 0; - for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) { - if (scope->isBlockScope()) { - if (ClassOrNamespace *binding = context.lookupType(scope->owner())) { - for (unsigned i = 0; i < scope->symbolCount(); ++i) { - Symbol *member = scope->symbolAt(i); + for (Scope *scope = currentScope; scope; scope = scope->scope()) { + if (scope->isBlock()) { + if (ClassOrNamespace *binding = context.lookupType(scope)) { + for (unsigned i = 0; i < scope->memberCount(); ++i) { + Symbol *member = scope->memberAt(i); if (! member->name()) continue; else if (UsingNamespaceDirective *u = member->asUsingNamespaceDirective()) { @@ -1068,19 +1068,19 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope) } } } - } else if (scope->isPrototypeScope() || scope->isClassScope() || scope->isNamespaceScope()) { - currentBinding = context.lookupType(scope->owner()); + } else if (scope->isFunction() || scope->isClass() || scope->isNamespace()) { + currentBinding = context.lookupType(scope); break; } } - for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) { - if (scope->isBlockScope()) { - for (unsigned i = 0; i < scope->symbolCount(); ++i) { - addCompletionItem(scope->symbolAt(i)); + for (Scope *scope = currentScope; scope; scope = scope->scope()) { + if (scope->isBlock()) { + for (unsigned i = 0; i < scope->memberCount(); ++i) { + addCompletionItem(scope->memberAt(i)); } - } else if (scope->isPrototypeScope()) { - Function *fun = scope->owner()->asFunction(); + } else if (scope->isFunction()) { + Function *fun = scope->asFunction(); for (unsigned i = 0; i < fun->argumentCount(); ++i) { addCompletionItem(fun->argumentAt(i)); } @@ -1216,7 +1216,7 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &r Scope *sc = context.thisDocument()->scopeAt(line, column); - if (sc && (sc->isClassScope() || sc->isNamespaceScope())) { + if (sc && (sc->isClass() || sc->isNamespace())) { // It may still be a function call. If the whole line parses as a function // declaration, we should be certain that it isn't. bool autocompleteSignature = false; @@ -1528,11 +1528,11 @@ void CppCodeCompletion::completeNamespace(ClassOrNamespace *b) foreach (Symbol *bb, binding->symbols()) { if (Namespace *ns = bb->asNamespace()) - scopesToVisit.append(ns->members()); + scopesToVisit.append(ns); } foreach (Enum *e, binding->enums()) { - scopesToVisit.append(e->members()); + scopesToVisit.append(e); } while (! scopesToVisit.isEmpty()) { @@ -1542,7 +1542,7 @@ void CppCodeCompletion::completeNamespace(ClassOrNamespace *b) scopesVisited.insert(scope); - for (Scope::iterator it = scope->firstSymbol(); it != scope->lastSymbol(); ++it) { + for (Scope::iterator it = scope->firstMember(); it != scope->lastMember(); ++it) { Symbol *member = *it; addCompletionItem(member); } @@ -1569,11 +1569,11 @@ void CppCodeCompletion::completeClass(ClassOrNamespace *b, bool staticLookup) foreach (Symbol *bb, binding->symbols()) { if (Class *k = bb->asClass()) - scopesToVisit.append(k->members()); + scopesToVisit.append(k); } foreach (Enum *e, binding->enums()) - scopesToVisit.append(e->members()); + scopesToVisit.append(e); while (! scopesToVisit.isEmpty()) { Scope *scope = scopesToVisit.takeFirst(); @@ -1582,9 +1582,9 @@ void CppCodeCompletion::completeClass(ClassOrNamespace *b, bool staticLookup) scopesVisited.insert(scope); - addCompletionItem(scope->owner()); // add a completion item for the injected class name. + addCompletionItem(scope); // add a completion item for the injected class name. - for (Scope::iterator it = scope->firstSymbol(); it != scope->lastSymbol(); ++it) { + for (Scope::iterator it = scope->firstMember(); it != scope->lastMember(); ++it) { Symbol *member = *it; if (member->isFriend()) continue; @@ -1641,18 +1641,18 @@ bool CppCodeCompletion::completeQtMethod(const QList<LookupItem> &results, foreach (Symbol *s, binding->symbols()) if (Class *clazz = s->asClass()) - scopes.append(clazz->members()); + scopes.append(clazz); todo.append(binding->usings()); } } foreach (Scope *scope, scopes) { - if (! scope->isClassScope()) + if (! scope->isClass()) continue; - for (unsigned i = 0; i < scope->symbolCount(); ++i) { - Symbol *member = scope->symbolAt(i); + for (unsigned i = 0; i < scope->memberCount(); ++i) { + Symbol *member = scope->memberAt(i); Function *fun = member->type()->asFunctionType(); if (! fun) continue; diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index 87254f03047719ee0665b9771d1a60465a677701..4d33e04f7276e706695b1399f2e50bd5cf92607e 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -191,7 +191,7 @@ static void find_helper(QFutureInterface<Usage> &future, QStringList files(sourceFile); if (symbol->isClass() || symbol->isForwardClassDeclaration() || (symbol->scope() && ! symbol->isStatic() && - symbol->scope()->isNamespaceScope())) { + symbol->scope()->isNamespace())) { foreach (const Document::Ptr &doc, context.snapshot()) { if (doc->fileName() == sourceFile) continue; diff --git a/src/plugins/cpptools/searchsymbols.cpp b/src/plugins/cpptools/searchsymbols.cpp index 70cd1452bd07475c70bc924e71de79da21d01c6c..d0e031d772923f0d0055c0b99d4cc29a854020fd 100644 --- a/src/plugins/cpptools/searchsymbols.cpp +++ b/src/plugins/cpptools/searchsymbols.cpp @@ -88,9 +88,8 @@ bool SearchSymbols::visit(Enum *symbol) appendItem(separateScope ? name : scopedName, separateScope ? previousScope : QString(), ModelItemInfo::Enum, symbol); - Scope *members = symbol->members(); - for (unsigned i = 0; i < members->symbolCount(); ++i) { - accept(members->symbolAt(i)); + for (unsigned i = 0; i < symbol->memberCount(); ++i) { + accept(symbol->memberAt(i)); } (void) switchScope(previousScope); return false; @@ -126,9 +125,8 @@ bool SearchSymbols::visit(Namespace *symbol) { QString name = findOrInsert(scopedSymbolName(symbol)); QString previousScope = switchScope(name); - Scope *members = symbol->members(); - for (unsigned i = 0; i < members->symbolCount(); ++i) { - accept(members->symbolAt(i)); + for (unsigned i = 0; i < symbol->memberCount(); ++i) { + accept(symbol->memberAt(i)); } (void) switchScope(previousScope); return false; @@ -159,9 +157,8 @@ bool SearchSymbols::visit(Class *symbol) separateScope ? previousScope : QString(), ModelItemInfo::Class, symbol); } - Scope *members = symbol->members(); - for (unsigned i = 0; i < members->symbolCount(); ++i) { - accept(members->symbolAt(i)); + for (unsigned i = 0; i < symbol->memberCount(); ++i) { + accept(symbol->memberAt(i)); } (void) switchScope(previousScope); return false; diff --git a/src/plugins/debugger/watchutils.cpp b/src/plugins/debugger/watchutils.cpp index 96797fbec925f12eabf5d4edeee92ccafacf4d03..f81d0a8eb02b3ea828ecd48d628366e60b649c57 100644 --- a/src/plugins/debugger/watchutils.cpp +++ b/src/plugins/debugger/watchutils.cpp @@ -85,7 +85,7 @@ static void debugCppSymbolRecursion(QTextStream &str, const Overview &o, if (s.isBlock()) str << " block"; if (doRecurse && s.isScopedSymbol()) { - const ScopedSymbol *scoped = s.asScopedSymbol(); + const Scope *scoped = s.asScope(); const int size = scoped->memberCount(); str << " scoped symbol of " << size << '\n'; for (int m = 0; m < size; m++) @@ -110,28 +110,31 @@ QDebug operator<<(QDebug d, const Scope &scope) QString output; Overview o; QTextStream str(&output); - const int size = scope.symbolCount(); + const int size = scope.memberCount(); str << "Scope of " << size; - if (scope.isNamespaceScope()) + if (scope.isNamespace()) str << " namespace"; - if (scope.isClassScope()) + if (scope.isClass()) str << " class"; - if (scope.isEnumScope()) + if (scope.isEnum()) str << " enum"; - if (scope.isBlockScope()) + if (scope.isBlock()) str << " block"; - if (scope.isPrototypeScope()) + if (scope.isFunction()) str << " function"; - if (scope.isPrototypeScope()) + if (scope.isFunction()) str << " prototype"; - if (const Symbol *owner = scope.owner()) { +#warning robe fix me +#if 0 + if (const Symbol *owner = &scope) { str << " owner: "; debugCppSymbolRecursion(str, o, *owner, false, 0); } else { str << " 0-owner\n"; } +#endif for (int s = 0; s < size; s++) - debugCppSymbolRecursion(str, o, *scope.symbolAt(s), true, 2); + debugCppSymbolRecursion(str, o, *scope.memberAt(s), true, 2); d.nospace() << output; return d; } @@ -319,9 +322,9 @@ static void blockRecursion(const CPlusPlus::Overview &overview, SeenHash *seenHash, int level = 0) { - const int size = scope->symbolCount(); + const int size = scope->memberCount(); for (int s = 0; s < size; s++){ - const CPlusPlus::Symbol *symbol = scope->symbolAt(s); + const CPlusPlus::Symbol *symbol = scope->memberAt(s); if (symbol->isDeclaration()) { // Find out about shadowed symbols by bookkeeping // the already seen occurrences in a hash. @@ -339,7 +342,7 @@ static void blockRecursion(const CPlusPlus::Overview &overview, } } // Next block scope. - if (const CPlusPlus::Scope *enclosingScope = scope->enclosingBlockScope()) + if (const CPlusPlus::Scope *enclosingScope = scope->enclosingBlock()) blockRecursion(overview, enclosingScope, line, uninitializedVariables, seenHash, level + 1); } @@ -372,13 +375,13 @@ int getUninitializedVariablesI(const CPlusPlus::Snapshot &snapshot, function = symbolAtLine->asFunction(); if (function->memberCount() == 1) // Skip over function block if (CPlusPlus::Block *block = function->memberAt(0)->asBlock()) - innerMostScope = block->members(); + innerMostScope = block; } else { - if (const CPlusPlus::Scope *functionScope = symbolAtLine->enclosingPrototypeScope()) { - function = functionScope->owner()->asFunction(); + if (const CPlusPlus::Scope *functionScope = symbolAtLine->enclosingFunction()) { + function = functionScope->asFunction(); innerMostScope = symbolAtLine->isBlock() ? - symbolAtLine->asBlock()->members() : - symbolAtLine->enclosingBlockScope(); + symbolAtLine->asBlock() : + symbolAtLine->enclosingBlock(); } } if (!function || !innerMostScope) diff --git a/src/shared/cplusplus/CPlusPlusForwardDeclarations.h b/src/shared/cplusplus/CPlusPlusForwardDeclarations.h index 5dc0609670ab582f9e562538ac1bc0429196fada..9b8f7a19765c16c1c5b8e19ddd2ee4d081460a34 100644 --- a/src/shared/cplusplus/CPlusPlusForwardDeclarations.h +++ b/src/shared/cplusplus/CPlusPlusForwardDeclarations.h @@ -79,7 +79,7 @@ class Literal; class StringLiteral; class NumericLiteral; -class Scope; +class SymbolTable; class TemplateParameters; // names @@ -111,7 +111,7 @@ class NamedType; // symbols class SymbolVisitor; class Symbol; -class ScopedSymbol; +class Scope; class UsingNamespaceDirective; class UsingDeclaration; class Declaration; diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp index 94b7b845b9744638fc7b89bfadbd5ed1a18d5565..f431ca9db5de05ad1368c5a6b8bb29b32f3d9933 100644 --- a/src/shared/cplusplus/CheckDeclaration.cpp +++ b/src/shared/cplusplus/CheckDeclaration.cpp @@ -154,7 +154,7 @@ void CheckDeclaration::checkFunctionArguments(Function *fun) if (! _checkAnonymousArguments) return; - if (_scope->isClassScope() && fun->isPublic()) { + if (_scope->isClass() && fun->isPublic()) { for (unsigned argc = 0; argc < fun->argumentCount(); ++argc) { Argument *arg = fun->argumentAt(argc)->asArgument(); assert(arg != 0); @@ -201,7 +201,7 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast) setDeclSpecifiers(symbol, declSpecifiers); - _scope->enterSymbol(symbol); + _scope->addMember(symbol); return false; } } @@ -262,7 +262,7 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast) (*decl_it)->value = symbol; decl_it = &(*decl_it)->next; - _scope->enterSymbol(symbol); + _scope->addMember(symbol); } return false; } @@ -310,7 +310,7 @@ bool CheckDeclaration::visit(ExceptionDeclarationAST *ast) Declaration *symbol = control()->newDeclaration(location, name); symbol->setType(declTy); - _scope->enterSymbol(symbol); + _scope->addMember(symbol); return false; } @@ -322,7 +322,7 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast) const Name *name = 0; FullySpecifiedType funTy = semantic()->check(ast->declarator, qualTy, _scope, &name); - if (! (funTy && funTy->isFunctionType())) { + if (! funTy->isFunctionType()) { translationUnit()->error(ast->firstToken(), "expected a function prototype"); return false; @@ -336,8 +336,8 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast) Function *fun = funTy->asFunctionType(); setDeclSpecifiers(fun, ty); - fun->members()->setStartOffset(funStartOffset); - fun->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + fun->setStartOffset(funStartOffset); + fun->setEndOffset(tokenAt(ast->lastToken() - 1).end()); if (ast->declarator) { unsigned loc = semantic()->location(ast->declarator); if (! loc) @@ -363,7 +363,7 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast) checkFunctionArguments(fun); ast->symbol = fun; - _scope->enterSymbol(fun); + _scope->addMember(fun); if (! semantic()->skipFunctionBodies()) semantic()->checkFunctionDefinition(ast); @@ -408,11 +408,11 @@ bool CheckDeclaration::visit(NamespaceAST *ast) scopeStart = tokenAt(ast->linkage_body->firstToken()).offset; Namespace *ns = control()->newNamespace(sourceLocation, namespaceName); - ns->members()->setStartOffset(scopeStart); - ns->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + ns->setStartOffset(scopeStart); + ns->setEndOffset(tokenAt(ast->lastToken() - 1).end()); ast->symbol = ns; - _scope->enterSymbol(ns); - semantic()->check(ast->linkage_body, ns->members()); // ### we'll do the merge later. + _scope->addMember(ns); + semantic()->check(ast->linkage_body, ns); // ### we'll do the merge later. return false; } @@ -434,7 +434,7 @@ bool CheckDeclaration::visit(NamespaceAliasDefinitionAST *ast) NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name); namespaceAlias->setNamespaceName(namespaceName); //ast->symbol = namespaceAlias; - _scope->enterSymbol(namespaceAlias); + _scope->addMember(namespaceAlias); return false; } @@ -470,12 +470,14 @@ bool CheckDeclaration::visit(ParameterDeclarationAST *ast) arg->setInitializer(initializer); } arg->setType(argTy); - _scope->enterSymbol(arg); + _scope->addMember(arg); return false; } bool CheckDeclaration::visit(TemplateDeclarationAST *ast) { +#warning robe process template arguments +#if 0 Scope *scope = new Scope(_scope->owner()); for (DeclarationListAST *param = ast->template_parameter_list; param; param = param->next) { @@ -484,6 +486,9 @@ bool CheckDeclaration::visit(TemplateDeclarationAST *ast) semantic()->check(ast->declaration, _scope, new TemplateParameters(_templateParameters, scope)); +#else + semantic()->check(ast->declaration, _scope); +#endif return false; } @@ -499,7 +504,7 @@ bool CheckDeclaration::visit(TypenameTypeParameterAST *ast) FullySpecifiedType ty = semantic()->check(ast->type_id, _scope); arg->setType(ty); ast->symbol = arg; - _scope->enterSymbol(arg); + _scope->addMember(arg); return false; } @@ -514,7 +519,7 @@ bool CheckDeclaration::visit(TemplateTypeParameterAST *ast) FullySpecifiedType ty = semantic()->check(ast->type_id, _scope); arg->setType(ty); ast->symbol = arg; - _scope->enterSymbol(arg); + _scope->addMember(arg); return false; } @@ -528,7 +533,7 @@ bool CheckDeclaration::visit(UsingAST *ast) UsingDeclaration *u = control()->newUsingDeclaration(sourceLocation, name); ast->symbol = u; - _scope->enterSymbol(u); + _scope->addMember(u); return false; } @@ -542,9 +547,9 @@ bool CheckDeclaration::visit(UsingDirectiveAST *ast) UsingNamespaceDirective *u = control()->newUsingNamespaceDirective(sourceLocation, name); ast->symbol = u; - _scope->enterSymbol(u); + _scope->addMember(u); - if (! (_scope->isBlockScope() || _scope->isNamespaceScope())) + if (! (_scope->isBlock() || _scope->isNamespace())) translationUnit()->error(ast->firstToken(), "using-directive not within namespace or block scope"); @@ -566,7 +571,7 @@ bool CheckDeclaration::visit(ObjCProtocolForwardDeclarationAST *ast) const Name *protocolName = semantic()->check(it->value, _scope); ObjCForwardProtocolDeclaration *fwdProtocol = control()->newObjCForwardProtocolDeclaration(sourceLocation, protocolName); - _scope->enterSymbol(fwdProtocol); + _scope->addMember(fwdProtocol); *symbolIter = new (translationUnit()->memoryPool()) List<ObjCForwardProtocolDeclaration *>(); (*symbolIter)->value = fwdProtocol; @@ -598,8 +603,8 @@ bool CheckDeclaration::visit(ObjCProtocolDeclarationAST *ast) const Name *protocolName = semantic()->check(ast->name, _scope); ObjCProtocol *protocol = control()->newObjCProtocol(sourceLocation, protocolName); - protocol->members()->setStartOffset(calculateScopeStart(ast)); - protocol->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + protocol->setStartOffset(calculateScopeStart(ast)); + protocol->setEndOffset(tokenAt(ast->lastToken() - 1).end()); if (ast->protocol_refs && ast->protocol_refs->identifier_list) { for (NameListAST *iter = ast->protocol_refs->identifier_list; iter; iter = iter->next) { @@ -612,12 +617,12 @@ bool CheckDeclaration::visit(ObjCProtocolDeclarationAST *ast) int previousObjCVisibility = semantic()->switchObjCVisibility(Function::Public); for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) { - semantic()->check(it->value, protocol->members()); + semantic()->check(it->value, protocol); } (void) semantic()->switchObjCVisibility(previousObjCVisibility); ast->symbol = protocol; - _scope->enterSymbol(protocol); + _scope->addMember(protocol); return false; } @@ -637,7 +642,7 @@ bool CheckDeclaration::visit(ObjCClassForwardDeclarationAST *ast) const Name *className = semantic()->check(it->value, _scope); ObjCForwardClassDeclaration *fwdClass = control()->newObjCForwardClassDeclaration(sourceLocation, className); - _scope->enterSymbol(fwdClass); + _scope->addMember(fwdClass); *symbolIter = new (translationUnit()->memoryPool()) List<ObjCForwardClassDeclaration *>(); (*symbolIter)->value = fwdClass; @@ -691,8 +696,8 @@ bool CheckDeclaration::visit(ObjCClassDeclarationAST *ast) const Name *className = semantic()->check(ast->class_name, _scope); ObjCClass *klass = control()->newObjCClass(sourceLocation, className); - klass->members()->setStartOffset(calculateScopeStart(ast)); - klass->members()->setEndOffset(tokenAt(ast->lastToken() - 1).offset); + klass->setStartOffset(calculateScopeStart(ast)); + klass->setEndOffset(tokenAt(ast->lastToken() - 1).offset); ast->symbol = klass; klass->setInterface(ast->interface_token != 0); @@ -717,20 +722,20 @@ bool CheckDeclaration::visit(ObjCClassDeclarationAST *ast) } } - _scope->enterSymbol(klass); + _scope->addMember(klass); int previousObjCVisibility = semantic()->switchObjCVisibility(Function::Protected); if (ast->inst_vars_decl) { for (DeclarationListAST *it = ast->inst_vars_decl->instance_variable_list; it; it = it->next) { - semantic()->check(it->value, klass->members()); + semantic()->check(it->value, klass); } } (void) semantic()->switchObjCVisibility(Function::Public); for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) { - semantic()->check(it->value, klass->members()); + semantic()->check(it->value, klass); } (void) semantic()->switchObjCVisibility(previousObjCVisibility); @@ -755,8 +760,8 @@ bool CheckDeclaration::visit(ObjCMethodDeclarationAST *ast) Symbol *symbol; if (ast->function_body) { symbol = methodTy; - methodTy->members()->setStartOffset(tokenAt(ast->function_body->firstToken()).offset); - methodTy->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + methodTy->setStartOffset(tokenAt(ast->function_body->firstToken()).offset); + methodTy->setEndOffset(tokenAt(ast->lastToken() - 1).end()); } else { Declaration *decl = control()->newDeclaration(selector->firstToken(), methodTy->name()); decl->setType(methodTy); @@ -770,10 +775,10 @@ bool CheckDeclaration::visit(ObjCMethodDeclarationAST *ast) if (ty.isUnavailable()) symbol->setUnavailable(true); - _scope->enterSymbol(symbol); + _scope->addMember(symbol); if (ast->function_body && !semantic()->skipFunctionBodies()) { - semantic()->check(ast->function_body, methodTy->members()); + semantic()->check(ast->function_body, methodTy); } return false; @@ -868,7 +873,7 @@ bool CheckDeclaration::visit(ObjCPropertyDeclarationAST *ast) propDecl->setAttributes(propAttrs); propDecl->setGetterName(getterName); propDecl->setSetterName(setterName); - _scope->enterSymbol(propDecl); + _scope->addMember(propDecl); *lastSymbols = new (translationUnit()->memoryPool()) List<ObjCPropertyDeclaration *>(); (*lastSymbols)->value = propDecl; diff --git a/src/shared/cplusplus/CheckDeclarator.cpp b/src/shared/cplusplus/CheckDeclarator.cpp index d9d51b356e10bac294cc8f6d5f7b4e1158e0d0ef..41b4ea1b3a1f95569afb3a7203f861fdee7138d2 100644 --- a/src/shared/cplusplus/CheckDeclarator.cpp +++ b/src/shared/cplusplus/CheckDeclarator.cpp @@ -172,7 +172,7 @@ bool CheckDeclarator::visit(FunctionDeclaratorAST *ast) if (ast->parameters) { DeclarationListAST *parameter_declarations = ast->parameters->parameter_declaration_list; for (DeclarationListAST *decl = parameter_declarations; decl; decl = decl->next) { - semantic()->check(decl->value, fun->members()); + semantic()->check(decl->value, fun); } if (ast->parameters->dot_dot_dot_token) @@ -276,7 +276,7 @@ bool CheckDeclarator::visit(ObjCMethodPrototypeAST *ast) for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) { ObjCMessageArgumentDeclarationAST *argDecl = it->value; - semantic()->check(argDecl, method->arguments()); + semantic()->check(argDecl, method); } if (ast->dot_dot_dot_token) diff --git a/src/shared/cplusplus/CheckExpression.cpp b/src/shared/cplusplus/CheckExpression.cpp index 27e05390c0a179f577a3b99dd1c724fa59fab540..544dc95ceadc82288c53fa54f7ae2f5496013d2e 100644 --- a/src/shared/cplusplus/CheckExpression.cpp +++ b/src/shared/cplusplus/CheckExpression.cpp @@ -125,7 +125,7 @@ bool CheckExpression::visit(ConditionAST *ast) _scope, &name); Declaration *decl = control()->newDeclaration(semantic()->location(ast->declarator), name); decl->setType(declTy); - _scope->enterSymbol(decl); + _scope->addMember(decl); return false; } @@ -313,9 +313,10 @@ bool CheckExpression::visit(UnaryExpressionAST *ast) bool CheckExpression::visit(QtMethodAST *ast) { const Name *name = 0; - Scope dummy; +#warning robe set a valid scope + Scope *dummy = 0; FullySpecifiedType methTy = semantic()->check(ast->declarator, FullySpecifiedType(), - &dummy, &name); + dummy, &name); Function *fty = methTy->asFunctionType(); if (! fty) translationUnit()->warning(ast->firstToken(), "expected a function declarator"); @@ -384,7 +385,7 @@ bool CheckExpression::visit(ObjCEncodeExpressionAST * /*ast*/) bool CheckExpression::visit(ObjCSelectorExpressionAST *ast) { - if (_scope->isPrototypeScope()) + if (_scope->isFunction()) return false; (void) semantic()->check(ast->selector, _scope); @@ -393,7 +394,7 @@ bool CheckExpression::visit(ObjCSelectorExpressionAST *ast) bool CheckExpression::visit(LambdaExpressionAST *ast) { - if (_scope->isPrototypeScope()) + if (_scope->isFunction()) return false; (void) semantic()->check(ast->statement, _scope); diff --git a/src/shared/cplusplus/CheckName.cpp b/src/shared/cplusplus/CheckName.cpp index 1161a8e0e0ecdc6ca0e1e3b8c73de8751fdc41a4..4fccbcd759acc41dbe0c4af9022e44faf138a3a3 100644 --- a/src/shared/cplusplus/CheckName.cpp +++ b/src/shared/cplusplus/CheckName.cpp @@ -412,7 +412,7 @@ bool CheckName::visit(ObjCMessageArgumentDeclarationAST *ast) ast->argument = arg; arg->setType(type); arg->setInitializer(0); - _scope->enterSymbol(arg); + _scope->addMember(arg); } return false; diff --git a/src/shared/cplusplus/CheckSpecifier.cpp b/src/shared/cplusplus/CheckSpecifier.cpp index 8e8debdcfc0dcd8b74a85a91a9f1bea5f4d69447..6bb48792464b6a38ada001592e8cb132b0def9fb 100644 --- a/src/shared/cplusplus/CheckSpecifier.cpp +++ b/src/shared/cplusplus/CheckSpecifier.cpp @@ -316,8 +316,8 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast) const Name *className = semantic()->check(ast->name, _scope); Class *klass = control()->newClass(sourceLocation, className); - klass->members()->setStartOffset(classScopeStart); - klass->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + klass->setStartOffset(classScopeStart); + klass->setEndOffset(tokenAt(ast->lastToken() - 1).end()); ast->symbol = klass; unsigned classKey = tokenKind(ast->classkey_token); if (classKey == T_CLASS) @@ -327,7 +327,7 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast) else if (classKey == T_UNION) klass->setClassKey(Class::UnionKey); klass->setVisibility(semantic()->currentVisibility()); - _scope->enterSymbol(klass); + _scope->addMember(klass); ClassSpecifierAST *previousClassSpecifier = semantic()->switchDeclaringClass(ast); @@ -362,7 +362,7 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast) DeclarationAST *previousDeclaration = 0; for (DeclarationListAST *it = ast->member_specifier_list; it; it = it->next) { DeclarationAST *declaration = it->value; - semantic()->check(declaration, klass->members()); + semantic()->check(declaration, klass); if (previousDeclaration && declaration && declaration->asEmptyDeclaration() != 0 && @@ -408,10 +408,10 @@ bool CheckSpecifier::visit(EnumSpecifierAST *ast) const Name *name = semantic()->check(ast->name, _scope); Enum *e = control()->newEnum(sourceLocation, name); ast->symbol = e; - e->members()->setStartOffset(scopeStart); - e->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + e->setStartOffset(scopeStart); + e->setEndOffset(tokenAt(ast->lastToken() - 1).end()); e->setVisibility(semantic()->currentVisibility()); - _scope->enterSymbol(e); + _scope->addMember(e); _fullySpecifiedType.setType(e); for (EnumeratorListAST *it = ast->enumerator_list; it; it = it->next) { EnumeratorAST *enumerator = it->value; diff --git a/src/shared/cplusplus/CheckStatement.cpp b/src/shared/cplusplus/CheckStatement.cpp index aa145e804c4ae2250a72632de065403d236b4647..b61ba97a9eab9a863289ccc681962059e902fc8b 100644 --- a/src/shared/cplusplus/CheckStatement.cpp +++ b/src/shared/cplusplus/CheckStatement.cpp @@ -111,11 +111,11 @@ bool CheckStatement::visit(CaseStatementAST *ast) bool CheckStatement::visit(CompoundStatementAST *ast) { Block *block = control()->newBlock(ast->lbrace_token); - block->members()->setStartOffset(tokenAt(ast->firstToken()).end()); - block->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + block->setStartOffset(tokenAt(ast->firstToken()).end()); + block->setEndOffset(tokenAt(ast->lastToken() - 1).end()); ast->symbol = block; - _scope->enterSymbol(block); - Scope *previousScope = switchScope(block->members()); + _scope->addMember(block); + Scope *previousScope = switchScope(block); StatementAST *previousStatement = 0; for (StatementListAST *it = ast->statement_list; it; it = it->next) { StatementAST *statement = it->value; @@ -181,11 +181,11 @@ bool CheckStatement::forEachFastEnum(unsigned firstToken, scopeStart = tokenAt(lparen).end(); Block *block = control()->newBlock(firstToken); - block->members()->setStartOffset(scopeStart); - block->members()->setEndOffset(tokenAt(lastToken - 1).end()); + block->setStartOffset(scopeStart); + block->setEndOffset(tokenAt(lastToken - 1).end()); symbol = block; - _scope->enterSymbol(block); - Scope *previousScope = switchScope(block->members()); + _scope->addMember(block); + Scope *previousScope = switchScope(block); if (type_specifier_list && declarator) { FullySpecifiedType ty = semantic()->check(type_specifier_list, _scope); const Name *name = 0; @@ -195,7 +195,7 @@ bool CheckStatement::forEachFastEnum(unsigned firstToken, location = core_declarator->firstToken(); Declaration *decl = control()->newDeclaration(location, name); decl->setType(ty); - _scope->enterSymbol(decl); + _scope->addMember(decl); } else { (void) semantic()->check(initializer, _scope); } @@ -240,11 +240,11 @@ bool CheckStatement::visit(ForStatementAST *ast) scopeStart = tokenAt(ast->lparen_token).end(); Block *block = control()->newBlock(ast->for_token); - block->members()->setStartOffset(scopeStart); - block->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + block->setStartOffset(scopeStart); + block->setEndOffset(tokenAt(ast->lastToken() - 1).end()); ast->symbol = block; - _scope->enterSymbol(block); - Scope *previousScope = switchScope(block->members()); + _scope->addMember(block); + Scope *previousScope = switchScope(block); semantic()->check(ast->initializer, _scope); FullySpecifiedType condTy = semantic()->check(ast->condition, _scope); FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope); @@ -261,11 +261,11 @@ bool CheckStatement::visit(IfStatementAST *ast) scopeStart = tokenAt(ast->lparen_token).end(); Block *block = control()->newBlock(ast->if_token); - block->members()->setStartOffset(scopeStart); - block->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + block->setStartOffset(scopeStart); + block->setEndOffset(tokenAt(ast->lastToken() - 1).end()); ast->symbol = block; - _scope->enterSymbol(block); - Scope *previousScope = switchScope(block->members()); + _scope->addMember(block); + Scope *previousScope = switchScope(block); FullySpecifiedType exprTy = semantic()->check(ast->condition, _scope); semantic()->check(ast->statement, _scope); semantic()->check(ast->else_statement, _scope); @@ -312,11 +312,11 @@ bool CheckStatement::visit(SwitchStatementAST *ast) scopeStart = tokenAt(ast->lparen_token).offset; Block *block = control()->newBlock(ast->switch_token); - block->members()->setStartOffset(scopeStart); - block->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + block->setStartOffset(scopeStart); + block->setEndOffset(tokenAt(ast->lastToken() - 1).end()); ast->symbol = block; - _scope->enterSymbol(block); - Scope *previousScope = switchScope(block->members()); + _scope->addMember(block); + Scope *previousScope = switchScope(block); FullySpecifiedType condTy = semantic()->check(ast->condition, _scope); semantic()->check(ast->statement, _scope); (void) switchScope(previousScope); @@ -341,11 +341,11 @@ bool CheckStatement::visit(CatchClauseAST *ast) scopeStart = tokenAt(ast->lparen_token).end(); Block *block = control()->newBlock(ast->catch_token); - block->members()->setStartOffset(scopeStart); - block->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + block->setStartOffset(scopeStart); + block->setEndOffset(tokenAt(ast->lastToken() - 1).end()); ast->symbol = block; - _scope->enterSymbol(block); - Scope *previousScope = switchScope(block->members()); + _scope->addMember(block); + Scope *previousScope = switchScope(block); semantic()->check(ast->exception_declaration, _scope); semantic()->check(ast->statement, _scope); (void) switchScope(previousScope); @@ -360,11 +360,11 @@ bool CheckStatement::visit(WhileStatementAST *ast) scopeStart = tokenAt(ast->lparen_token).end(); Block *block = control()->newBlock(ast->while_token); - block->members()->setStartOffset(scopeStart); - block->members()->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + block->setStartOffset(scopeStart); + block->setEndOffset(tokenAt(ast->lastToken() - 1).end()); ast->symbol = block; - _scope->enterSymbol(block); - Scope *previousScope = switchScope(block->members()); + _scope->addMember(block); + Scope *previousScope = switchScope(block); FullySpecifiedType condTy = semantic()->check(ast->condition, _scope); semantic()->check(ast->statement, _scope); (void) switchScope(previousScope); @@ -400,7 +400,7 @@ bool CheckStatement::visit(QtMemberDeclarationAST *ast) Declaration *symbol = control()->newDeclaration(/*generated*/ 0, name); symbol->setType(control()->pointerType(declTy)); - _scope->enterSymbol(symbol); + _scope->addMember(symbol); _exprType = FullySpecifiedType(); return false; } diff --git a/src/shared/cplusplus/Scope.cpp b/src/shared/cplusplus/Scope.cpp index a38dce4840166a11a1309ae551fb2e18208321ea..0d8f75eeb2f5a717719df4ee35e93854daf128fe 100644 --- a/src/shared/cplusplus/Scope.cpp +++ b/src/shared/cplusplus/Scope.cpp @@ -55,147 +55,85 @@ using namespace CPlusPlus; -Scope::Scope(ScopedSymbol *owner) - : _owner(owner), - _symbols(0), - _hash(0), - _allocatedSymbols(0), - _symbolCount(-1), - _hashSize(0), - _startOffset(0), - _endOffset(0) -{ } - -Scope::~Scope() +class CPlusPlus::SymbolTable { - if (_symbols) - free(_symbols); - if (_hash) - free(_hash); -} + SymbolTable(const SymbolTable &other); + void operator =(const SymbolTable &other); -ScopedSymbol *Scope::owner() const -{ return _owner; } +public: + typedef Symbol **iterator; -void Scope::setOwner(ScopedSymbol *owner) -{ _owner = owner; } +public: + /// Constructs an empty Scope. + SymbolTable(Scope *owner = 0); -Scope *Scope::enclosingScope() const -{ - if (! _owner) - return 0; + /// Destroy this scope. + ~SymbolTable(); - return _owner->scope(); -} + /// Returns this scope's owner Symbol. + Scope *owner() const; -Scope *Scope::enclosingNamespaceScope() const -{ - Scope *scope = enclosingScope(); - for (; scope; scope = scope->enclosingScope()) { - if (scope->owner()->isNamespace()) - break; - } - return scope; -} + /// Sets this scope's owner Symbol. + void setOwner(Scope *owner); // ### remove me -Scope *Scope::enclosingClassScope() const -{ - Scope *scope = enclosingScope(); - for (; scope; scope = scope->enclosingScope()) { - if (scope->owner()->isClass()) - break; - } - return scope; -} + /// Adds a Symbol to this Scope. + void enterSymbol(Symbol *symbol); -Scope *Scope::enclosingEnumScope() const -{ - Scope *scope = enclosingScope(); - for (; scope; scope = scope->enclosingScope()) { - if (scope->owner()->isEnum()) - break; - } - return scope; -} + /// Returns true if this Scope is empty; otherwise returns false. + bool isEmpty() const; -Scope *Scope::enclosingPrototypeScope() const -{ - Scope *scope = enclosingScope(); - for (; scope; scope = scope->enclosingScope()) { - if (scope->owner()->isFunction()) - break; - } - return scope; -} + /// Returns the number of symbols is in the scope. + unsigned symbolCount() const; -Scope *Scope::enclosingBlockScope() const -{ - Scope *scope = enclosingScope(); - for (; scope; scope = scope->enclosingScope()) { - if (scope->owner()->isBlock()) - break; - } - return scope; -} + /// Returns the Symbol at the given position. + Symbol *symbolAt(unsigned index) const; -bool Scope::isNamespaceScope() const -{ - if (_owner) - return _owner->isNamespace(); - return false; -} + /// Returns the first Symbol in the scope. + iterator firstSymbol() const; -bool Scope::isClassScope() const -{ - if (_owner) - return _owner->isClass(); - return false; -} + /// Returns the last Symbol in the scope. + iterator lastSymbol() const; -bool Scope::isEnumScope() const -{ - if (_owner) - return _owner->isEnum(); - return false; -} + Symbol *lookat(const Name *name) const; + Symbol *lookat(const Identifier *id) const; + Symbol *lookat(int operatorId) const; -bool Scope::isBlockScope() const -{ - if (_owner) - return _owner->isBlock(); - return false; -} +private: + /// Returns the hash value for the given Symbol. + unsigned hashValue(Symbol *symbol) const; -bool Scope::isObjCClassScope() const -{ - if (_owner) - return _owner->isObjCClass(); - return false; -} + /// Updates the hash table. + void rehash(); -bool Scope::isObjCProtocolScope() const -{ - if (_owner) - return _owner->isObjCProtocol(); - return false; -} +private: + enum { DefaultInitialSize = 11 }; -bool Scope::isPrototypeScope() const -{ - if (_owner) - return _owner->isFunction(); - return false; -} + Scope *_owner; + Symbol **_symbols; + Symbol **_hash; + int _allocatedSymbols; + int _symbolCount; + int _hashSize; +}; + +SymbolTable::SymbolTable(Scope *owner) + : _owner(owner), + _symbols(0), + _hash(0), + _allocatedSymbols(0), + _symbolCount(-1), + _hashSize(0) +{ } -bool Scope::isObjCMethodScope() const +SymbolTable::~SymbolTable() { - ObjCMethod *m = 0; - if (_owner && 0 != (m = _owner->asObjCMethod())) - return m->arguments() != this; - return false; + if (_symbols) + free(_symbols); + if (_hash) + free(_hash); } -void Scope::enterSymbol(Symbol *symbol) +void SymbolTable::enterSymbol(Symbol *symbol) { if (++_symbolCount == _allocatedSymbols) { _allocatedSymbols <<= 1; @@ -207,7 +145,7 @@ void Scope::enterSymbol(Symbol *symbol) assert(! symbol->_scope || symbol->scope() == this); symbol->_index = _symbolCount; - symbol->_scope = this; + symbol->_scope = _owner; _symbols[_symbolCount] = symbol; if (_symbolCount >= _hashSize * 0.6) @@ -219,7 +157,7 @@ void Scope::enterSymbol(Symbol *symbol) } } -Symbol *Scope::lookat(const Name *name) const +Symbol *SymbolTable::lookat(const Name *name) const { if (! name) return 0; @@ -234,7 +172,7 @@ Symbol *Scope::lookat(const Name *name) const return 0; } -Symbol *Scope::lookat(const Identifier *id) const +Symbol *SymbolTable::lookat(const Identifier *id) const { if (! _hash || ! id) return 0; @@ -264,7 +202,7 @@ Symbol *Scope::lookat(const Identifier *id) const return symbol; } -Symbol *Scope::lookat(int operatorId) const +Symbol *SymbolTable::lookat(int operatorId) const { if (! _hash) return 0; @@ -281,7 +219,7 @@ Symbol *Scope::lookat(int operatorId) const return symbol; } -void Scope::rehash() +void SymbolTable::rehash() { _hashSize <<= 1; @@ -299,7 +237,7 @@ void Scope::rehash() } } -unsigned Scope::hashValue(Symbol *symbol) const +unsigned SymbolTable::hashValue(Symbol *symbol) const { if (! symbol) return 0; @@ -307,35 +245,83 @@ unsigned Scope::hashValue(Symbol *symbol) const return symbol->hashCode() % _hashSize; } -bool Scope::isEmpty() const +bool SymbolTable::isEmpty() const { return _symbolCount == -1; } -unsigned Scope::symbolCount() const +unsigned SymbolTable::symbolCount() const { return _symbolCount + 1; } -Symbol *Scope::symbolAt(unsigned index) const +Symbol *SymbolTable::symbolAt(unsigned index) const { if (! _symbols) return 0; return _symbols[index]; } -Scope::iterator Scope::firstSymbol() const +SymbolTable::iterator SymbolTable::firstSymbol() const { return _symbols; } -Scope::iterator Scope::lastSymbol() const +SymbolTable::iterator SymbolTable::lastSymbol() const { return _symbols + _symbolCount + 1; } +Scope::Scope(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) + : Symbol(translationUnit, sourceLocation, name), + _members(0), + _startOffset(0), + _endOffset(0) +{ } + +Scope::~Scope() +{ delete _members; } + +/// Adds a Symbol to this Scope. +void Scope::addMember(Symbol *symbol) +{ + if (! _members) + _members = new SymbolTable(this); + + _members->enterSymbol(symbol); +} + +/// Returns true if this Scope is empty; otherwise returns false. +bool Scope::isEmpty() const +{ return _members ? _members->isEmpty() : true; } + +/// Returns the number of symbols is in the scope. +unsigned Scope::memberCount() const +{ return _members ? _members->symbolCount() : 0; } + +/// Returns the Symbol at the given position. +Symbol *Scope::memberAt(unsigned index) const +{ return _members ? _members->symbolAt(index) : 0; } + +/// Returns the first Symbol in the scope. +Scope::iterator Scope::firstMember() const +{ return _members ? _members->firstSymbol() : 0; } + +/// Returns the last Symbol in the scope. +Scope::iterator Scope::lastMember() const +{ return _members ? _members->lastSymbol() : 0; } + +Symbol *Scope::find(const Name *name) const +{ return _members ? _members->lookat(name) : 0; } + +Symbol *Scope::find(const Identifier *id) const +{ return _members ? _members->lookat(id) : 0; } + +Symbol *Scope::find(int operatorId) const +{ return _members ? _members->lookat(operatorId) : 0; } + +/// Set the start offset of the scope unsigned Scope::startOffset() const { return _startOffset; } void Scope::setStartOffset(unsigned offset) { _startOffset = offset; } +/// Set the end offset of the scope unsigned Scope::endOffset() const { return _endOffset; } void Scope::setEndOffset(unsigned offset) { _endOffset = offset; } - - diff --git a/src/shared/cplusplus/Scope.h b/src/shared/cplusplus/Scope.h index b98435100a592bb62f4b7efae03219f88504f0b1..c3a1cb23e7e0dee7259597ea03ccd0d4b4823bc9 100644 --- a/src/shared/cplusplus/Scope.h +++ b/src/shared/cplusplus/Scope.h @@ -50,94 +50,39 @@ #define CPLUSPLUS_SCOPE_H #include "CPlusPlusForwardDeclarations.h" - +#include "Symbol.h" namespace CPlusPlus { -class CPLUSPLUS_EXPORT Scope +class CPLUSPLUS_EXPORT Scope: public Symbol { - Scope(const Scope &other); - void operator =(const Scope &other); - public: - typedef Symbol **iterator; - -public: - /// Constructs an empty Scope. - Scope(ScopedSymbol *owner = 0); - - /// Destroy this scope. - ~Scope(); - - /// Returns this scope's owner Symbol. - ScopedSymbol *owner() const; - - /// Sets this scope's owner Symbol. - void setOwner(ScopedSymbol *owner); // ### remove me - - /// Returns the enclosing scope. - Scope *enclosingScope() const; - - /// Returns the eclosing namespace scope. - Scope *enclosingNamespaceScope() const; - - /// Returns the enclosing class scope. - Scope *enclosingClassScope() const; - - /// Returns the enclosing enum scope. - Scope *enclosingEnumScope() const; - - /// Rerturns the enclosing prototype scope. - Scope *enclosingPrototypeScope() const; - - /// Rerturns the enclosing Block scope. - Scope *enclosingBlockScope() const; - - /// Returns true if this scope's owner is a Namespace Symbol. - bool isNamespaceScope() const; - - /// Returns true if this scope's owner is a Class Symbol. - bool isClassScope() const; - - /// Returns true if this scope's owner is an Enum Symbol. - bool isEnumScope() const; - - /// Returns true if this scope's owner is a Block Symbol. - bool isBlockScope() const; - - /// Returns true if this scope's owner is a Prototype Symbol. - bool isPrototypeScope() const; - - /// Returns true if this scope's owner is an ObjCClass Symbol. - bool isObjCClassScope() const; - - /// Returns true if this scope's owner is an ObjCProtocol Symbol. - bool isObjCProtocolScope() const; - - /// Returns true if this scope's owner is an ObjCMethod symbol. - bool isObjCMethodScope() const; + Scope(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name); + virtual ~Scope(); /// Adds a Symbol to this Scope. - void enterSymbol(Symbol *symbol); + void addMember(Symbol *symbol); /// Returns true if this Scope is empty; otherwise returns false. bool isEmpty() const; /// Returns the number of symbols is in the scope. - unsigned symbolCount() const; + unsigned memberCount() const; /// Returns the Symbol at the given position. - Symbol *symbolAt(unsigned index) const; + Symbol *memberAt(unsigned index) const; + + typedef Symbol **iterator; /// Returns the first Symbol in the scope. - iterator firstSymbol() const; + iterator firstMember() const; /// Returns the last Symbol in the scope. - iterator lastSymbol() const; + iterator lastMember() const; - Symbol *lookat(const Name *name) const; - Symbol *lookat(const Identifier *id) const; - Symbol *lookat(int operatorId) const; + Symbol *find(const Name *name) const; + Symbol *find(const Identifier *id) const; + Symbol *find(int operatorId) const; /// Set the start offset of the scope unsigned startOffset() const; @@ -147,22 +92,14 @@ public: unsigned endOffset() const; void setEndOffset(unsigned offset); -private: - /// Returns the hash value for the given Symbol. - unsigned hashValue(Symbol *symbol) const; + virtual const Scope *asScope() const + { return this; } - /// Updates the hash table. - void rehash(); + virtual Scope *asScope() + { return this; } private: - enum { DefaultInitialSize = 11 }; - - ScopedSymbol *_owner; - Symbol **_symbols; - Symbol **_hash; - int _allocatedSymbols; - int _symbolCount; - int _hashSize; + SymbolTable *_members; unsigned _startOffset; unsigned _endOffset; }; diff --git a/src/shared/cplusplus/Semantic.cpp b/src/shared/cplusplus/Semantic.cpp index 91cb68513f3f86a13db28a9fda85f104dc3dccaf..91376d3a255a8af7a9b26dcafc2aa6155024c69e 100644 --- a/src/shared/cplusplus/Semantic.cpp +++ b/src/shared/cplusplus/Semantic.cpp @@ -201,7 +201,7 @@ void Semantic::finishFunctionDefinition(FunctionDefinitionAST *ast) d->checkDeclaration->check(ast->ctor_initializer, fun->scope()); if (ast->function_body) { - check(ast->function_body, fun->members()); + check(ast->function_body, fun); if (CompoundStatementAST *c = ast->function_body->asCompoundStatement()) fun->setBlock(c->symbol); diff --git a/src/shared/cplusplus/Symbol.cpp b/src/shared/cplusplus/Symbol.cpp index e5a99bcb66f26a390d1b3d4c1fbe1841e4302c58..bb63cd96dab7f6e4ff1b73ca62f8e9d94fae227e 100644 --- a/src/shared/cplusplus/Symbol.cpp +++ b/src/shared/cplusplus/Symbol.cpp @@ -242,67 +242,49 @@ void Symbol::setScope(Scope *scope) _scope = scope; } -ScopedSymbol *Symbol::enclosingSymbol() const +Namespace *Symbol::enclosingNamespace() const { - if (! _scope) - return 0; - - return _scope->owner(); -} - -Scope *Symbol::enclosingNamespaceScope() const -{ - if (! _scope) - return 0; - - else if (_scope->isNamespaceScope()) - return _scope; - - return _scope->enclosingNamespaceScope(); + for (Scope *s = _scope; s; s = s->scope()) { + if (Namespace *ns = s->asNamespace()) + return ns; + } + return 0; } -Scope *Symbol::enclosingClassScope() const +Class *Symbol::enclosingClass() const { - if (! _scope) - return 0; - - else if (_scope->isClassScope()) - return _scope; - - return _scope->enclosingClassScope(); + for (Scope *s = _scope; s; s = s->scope()) { + if (Class *klass = s->asClass()) + return klass; + } + return 0; } -Scope *Symbol::enclosingEnumScope() const +Enum *Symbol::enclosingEnum() const { - if (! _scope) - return 0; - - else if (_scope->isEnumScope()) - return _scope; - - return _scope->enclosingEnumScope(); + for (Scope *s = _scope; s; s = s->scope()) { + if (Enum *e = s->asEnum()) + return e; + } + return 0; } -Scope *Symbol::enclosingPrototypeScope() const +Function *Symbol::enclosingFunction() const { - if (! _scope) - return 0; - - else if (_scope->isPrototypeScope()) - return _scope; - - return _scope->enclosingPrototypeScope(); + for (Scope *s = _scope; s; s = s->scope()) { + if (Function *fun = s->asFunction()) + return fun; + } + return 0; } -Scope *Symbol::enclosingBlockScope() const +Block *Symbol::enclosingBlock() const { - if (! _scope) - return 0; - - else if (_scope->isBlockScope()) - return _scope; - - return _scope->enclosingBlockScope(); + for (Scope *s = _scope; s; s = s->scope()) { + if (Block *block = s->asBlock()) + return block; + } + return 0; } unsigned Symbol::index() const @@ -354,7 +336,7 @@ bool Symbol::isPrivate() const { return _visibility == Private; } bool Symbol::isScopedSymbol() const -{ return asScopedSymbol() != 0; } +{ return asScope() != 0; } bool Symbol::isEnum() const { return asEnum() != 0; } diff --git a/src/shared/cplusplus/Symbol.h b/src/shared/cplusplus/Symbol.h index b83f67660172dfb478f82a172141cc88f493310b..bcd0e7e6953b9357c841c008bd2b750924121c0d 100644 --- a/src/shared/cplusplus/Symbol.h +++ b/src/shared/cplusplus/Symbol.h @@ -126,9 +126,6 @@ public: /// Sets this Symbol's visibility. void setVisibility(int visibility); - /// Returns this Symbol's scope. - Scope *scope() const; - /// Returns the next chained Symbol. Symbol *next() const; @@ -219,7 +216,7 @@ public: /// Returns true if this Symbol is an Objective-C @property declaration. bool isObjCPropertyDeclaration() const; - virtual const ScopedSymbol *asScopedSymbol() const { return 0; } + virtual const Scope *asScope() const { return 0; } virtual const Enum *asEnum() const { return 0; } virtual const Function *asFunction() const { return 0; } virtual const Namespace *asNamespace() const { return 0; } @@ -242,7 +239,7 @@ public: virtual const ObjCMethod *asObjCMethod() const { return 0; } virtual const ObjCPropertyDeclaration *asObjCPropertyDeclaration() const { return 0; } - virtual ScopedSymbol *asScopedSymbol() { return 0; } + virtual Scope *asScope() { return 0; } virtual Enum *asEnum() { return 0; } virtual Function *asFunction() { return 0; } virtual Namespace *asNamespace() { return 0; } @@ -284,22 +281,23 @@ public: bool isUnavailable() const; void setUnavailable(bool isUnavailable); - ScopedSymbol *enclosingSymbol() const; + /// Returns this Symbol's eclosing scope. + Scope *scope() const; /// Returns the eclosing namespace scope. - Scope *enclosingNamespaceScope() const; + Namespace *enclosingNamespace() const; /// Returns the enclosing class scope. - Scope *enclosingClassScope() const; + Class *enclosingClass() const; /// Returns the enclosing enum scope. - Scope *enclosingEnumScope() const; + Enum *enclosingEnum() const; /// Returns the enclosing prototype scope. - Scope *enclosingPrototypeScope() const; + Function *enclosingFunction() const; /// Returns the enclosing Block scope. - Scope *enclosingBlockScope() const; + Block *enclosingBlock() const; void setScope(Scope *scope); // ### make me private void setSourceLocation(unsigned sourceLocation, TranslationUnit *translationUnit); // ### make me private @@ -331,7 +329,7 @@ private: class HashCode; - friend class Scope; + friend class SymbolTable; }; } // end of namespace CPlusPlus diff --git a/src/shared/cplusplus/Symbols.cpp b/src/shared/cplusplus/Symbols.cpp index 62d068063d32f6711844dea7db26f8852969df75..5ad7d815db8de1d8815cce7ccb35b092afb544fd 100644 --- a/src/shared/cplusplus/Symbols.cpp +++ b/src/shared/cplusplus/Symbols.cpp @@ -190,7 +190,7 @@ void TypenameArgument::visitSymbol0(SymbolVisitor *visitor) { visitor->visit(this); } Function::Function(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) - : ScopedSymbol(translationUnit, sourceLocation, name), + : Scope(translationUnit, sourceLocation, name), _templateParameters(0), _block(0), _flags(0) @@ -230,11 +230,11 @@ unsigned Function::templateParameterCount() const if (! _templateParameters) return 0; - return _templateParameters->scope()->symbolCount(); + return _templateParameters->scope()->memberCount(); } Symbol *Function::templateParameterAt(unsigned index) const -{ return _templateParameters->scope()->symbolAt(index); } +{ return _templateParameters->scope()->memberAt(index); } TemplateParameters *Function::templateParameters() const { return _templateParameters; } @@ -414,114 +414,8 @@ void Function::visitSymbol0(SymbolVisitor *visitor) } } -ScopedSymbol::ScopedSymbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) - : Symbol(translationUnit, sourceLocation, name) -{ _members = new Scope(this); } - -ScopedSymbol::~ScopedSymbol() -{ delete _members; } - -unsigned ScopedSymbol::memberCount() const -{ - if (! _members) - return 0; - return _members->symbolCount(); -} - -Symbol *ScopedSymbol::memberAt(unsigned index) const -{ - if (! _members) - return 0; - return _members->symbolAt(index); -} - -Scope *ScopedSymbol::members() const -{ return _members; } - -void ScopedSymbol::addMember(Symbol *member) -{ _members->enterSymbol(member); } - -/// Returns true if this scope's owner is a Namespace Symbol. -bool ScopedSymbol::isNamespaceScope() const -{ return _members->isNamespaceScope(); } - -/// Returns true if this scope's owner is a Class Symbol. -bool ScopedSymbol::isClassScope() const -{ return _members->isClassScope(); } - -/// Returns true if this scope's owner is an Enum Symbol. -bool ScopedSymbol::isEnumScope() const -{ return _members->isEnumScope(); } - -/// Returns true if this scope's owner is a Block Symbol. -bool ScopedSymbol::isBlockScope() const -{ return _members->isBlockScope(); } - -/// Returns true if this scope's owner is a Prototype Symbol. -bool ScopedSymbol::isPrototypeScope() const -{ return _members->isPrototypeScope(); } - -/// Returns true if this scope's owner is an ObjCClass Symbol. -bool ScopedSymbol::isObjCClassScope() const -{ return _members->isObjCClassScope(); } - -/// Returns true if this scope's owner is an ObjCProtocol Symbol. -bool ScopedSymbol::isObjCProtocolScope() const -{ return _members->isObjCProtocolScope(); } - -/// Returns true if this scope's owner is an ObjCMethod symbol. -bool ScopedSymbol::isObjCMethodScope() const -{ return _members->isObjCMethodScope(); } - -/// Adds a Symbol to this Scope. -void ScopedSymbol::enterSymbol(Symbol *symbol) -{ _members->enterSymbol(symbol); } - -/// Returns true if this Scope is empty; otherwise returns false. -bool ScopedSymbol::isEmpty() const -{ return _members->isEmpty(); } - -/// Returns the number of symbols is in the scope. -unsigned ScopedSymbol::symbolCount() const -{ return _members->symbolCount(); } - -/// Returns the Symbol at the given position. -Symbol *ScopedSymbol::symbolAt(unsigned index) const -{ return _members->symbolAt(index); } - -/// Returns the first Symbol in the scope. -ScopedSymbol::iterator ScopedSymbol::firstSymbol() const -{ return _members->firstSymbol(); } - -/// Returns the last Symbol in the scope. -Scope::iterator ScopedSymbol::lastSymbol() const -{ return _members->lastSymbol(); } - -Symbol *ScopedSymbol::lookat(const Name *name) const -{ return _members->lookat(name); } - -Symbol *ScopedSymbol::lookat(const Identifier *id) const -{ return _members->lookat(id); } - -Symbol *ScopedSymbol::lookat(int operatorId) const -{ return _members->lookat(operatorId); } - -/// Set the start offset of the scope -unsigned ScopedSymbol::startOffset() const -{ return _members->startOffset(); } - -void ScopedSymbol::setStartOffset(unsigned offset) -{ _members->setStartOffset(offset); } - -/// Set the end offset of the scope -unsigned ScopedSymbol::endOffset() const -{ return _members->endOffset(); } - -void ScopedSymbol::setEndOffset(unsigned offset) -{ _members->setEndOffset(offset); } - Block::Block(TranslationUnit *translationUnit, unsigned sourceLocation) - : ScopedSymbol(translationUnit, sourceLocation, /*name = */ 0) + : Scope(translationUnit, sourceLocation, /*name = */ 0) { } Block::~Block() @@ -540,7 +434,7 @@ void Block::visitSymbol0(SymbolVisitor *visitor) } Enum::Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) - : ScopedSymbol(translationUnit, sourceLocation, name) + : Scope(translationUnit, sourceLocation, name) { } Enum::~Enum() @@ -584,7 +478,7 @@ void Enum::visitSymbol0(SymbolVisitor *visitor) } Namespace::Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) - : ScopedSymbol(translationUnit, sourceLocation, name) + : Scope(translationUnit, sourceLocation, name) { } Namespace::~Namespace() @@ -694,7 +588,7 @@ bool ForwardClassDeclaration::matchType0(const Type *otherType, TypeMatcher *mat } Class::Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) - : ScopedSymbol(translationUnit, sourceLocation, name), + : Scope(translationUnit, sourceLocation, name), _key(ClassKey), _templateParameters(0) { } @@ -722,11 +616,11 @@ unsigned Class::templateParameterCount() const if (! _templateParameters) return 0; - return _templateParameters->scope()->symbolCount(); + return _templateParameters->scope()->memberCount(); } Symbol *Class::templateParameterAt(unsigned index) const -{ return _templateParameters->scope()->symbolAt(index); } +{ return _templateParameters->scope()->memberAt(index); } TemplateParameters *Class::templateParameters() const { return _templateParameters; } @@ -809,7 +703,7 @@ void ObjCBaseProtocol::visitSymbol0(SymbolVisitor *visitor) { visitor->visit(this); } ObjCClass::ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name): - ScopedSymbol(translationUnit, sourceLocation, name), + Scope(translationUnit, sourceLocation, name), _isInterface(false), _categoryName(0), _baseClass(0) @@ -892,7 +786,7 @@ bool ObjCClass::matchType0(const Type *otherType, TypeMatcher *matcher) const } ObjCProtocol::ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name): - ScopedSymbol(translationUnit, sourceLocation, name) + Scope(translationUnit, sourceLocation, name) { } @@ -1025,14 +919,12 @@ bool ObjCForwardProtocolDeclaration::matchType0(const Type *otherType, TypeMatch } ObjCMethod::ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name) - : ScopedSymbol(translationUnit, sourceLocation, name), + : Scope(translationUnit, sourceLocation, name), _flags(0) -{ _arguments = new Scope(this); } +{ } ObjCMethod::~ObjCMethod() -{ - delete _arguments; -} +{ } bool ObjCMethod::isEqualTo(const Type *other) const { @@ -1043,13 +935,13 @@ bool ObjCMethod::isEqualTo(const Type *other) const const Name *l = identity(); const Name *r = o->identity(); if (l == r || (l && l->isEqualTo(r))) { - if (_arguments->symbolCount() != o->_arguments->symbolCount()) + if (argumentCount() != o->argumentCount()) return false; else if (! _returnType.isEqualTo(o->_returnType)) return false; - for (unsigned i = 0; i < _arguments->symbolCount(); ++i) { - Symbol *l = _arguments->symbolAt(i); - Symbol *r = o->_arguments->symbolAt(i); + for (unsigned i = 0; i < argumentCount(); ++i) { + Symbol *l = argumentAt(i); + Symbol *r = o->argumentAt(i); if (! l->type().isEqualTo(r->type())) return false; } @@ -1086,17 +978,14 @@ bool ObjCMethod::hasReturnType() const unsigned ObjCMethod::argumentCount() const { - if (! _arguments) - return 0; - - return _arguments->symbolCount(); +#warning robe implement me + return memberCount(); } Symbol *ObjCMethod::argumentAt(unsigned index) const -{ return _arguments->symbolAt(index); } - -Scope *ObjCMethod::arguments() const -{ return _arguments; } +{ + return memberAt(index); +} bool ObjCMethod::hasArguments() const { @@ -1113,9 +1002,6 @@ void ObjCMethod::setVariadic(bool isVariadic) void ObjCMethod::visitSymbol0(SymbolVisitor *visitor) { if (visitor->visit(this)) { - for (unsigned i = 0; i < _arguments->symbolCount(); ++i) { - visitSymbol(_arguments->symbolAt(i), visitor); - } for (unsigned i = 0; i < memberCount(); ++i) { visitSymbol(memberAt(i), visitor); } diff --git a/src/shared/cplusplus/Symbols.h b/src/shared/cplusplus/Symbols.h index 4017b367a042de8d37c8e4b0ffa58980e54ae322..a52b7cb373a7d10c668a1ba84c165404725ff6d1 100644 --- a/src/shared/cplusplus/Symbols.h +++ b/src/shared/cplusplus/Symbols.h @@ -53,6 +53,7 @@ #include "Symbol.h" #include "Type.h" #include "FullySpecifiedType.h" +#include "Scope.h" #include <vector> namespace CPlusPlus { @@ -217,84 +218,7 @@ private: FullySpecifiedType _type; }; -class CPLUSPLUS_EXPORT ScopedSymbol: public Symbol -{ -public: - ScopedSymbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name); - virtual ~ScopedSymbol(); - - unsigned memberCount() const; - Symbol *memberAt(unsigned index) const; - Scope *members() const; - void addMember(Symbol *member); - - /// Returns true if this scope's owner is a Namespace Symbol. - bool isNamespaceScope() const; - - /// Returns true if this scope's owner is a Class Symbol. - bool isClassScope() const; - - /// Returns true if this scope's owner is an Enum Symbol. - bool isEnumScope() const; - - /// Returns true if this scope's owner is a Block Symbol. - bool isBlockScope() const; - - /// Returns true if this scope's owner is a Prototype Symbol. - bool isPrototypeScope() const; - - /// Returns true if this scope's owner is an ObjCClass Symbol. - bool isObjCClassScope() const; - - /// Returns true if this scope's owner is an ObjCProtocol Symbol. - bool isObjCProtocolScope() const; - - /// Returns true if this scope's owner is an ObjCMethod symbol. - bool isObjCMethodScope() const; - - /// Adds a Symbol to this Scope. - void enterSymbol(Symbol *symbol); - - /// Returns true if this Scope is empty; otherwise returns false. - bool isEmpty() const; - - /// Returns the number of symbols is in the scope. - unsigned symbolCount() const; - - /// Returns the Symbol at the given position. - Symbol *symbolAt(unsigned index) const; - - typedef Symbol **iterator; - - /// Returns the first Symbol in the scope. - iterator firstSymbol() const; - - /// Returns the last Symbol in the scope. - iterator lastSymbol() const; - - Symbol *lookat(const Name *name) const; - Symbol *lookat(const Identifier *id) const; - Symbol *lookat(int operatorId) const; - - /// Set the start offset of the scope - unsigned startOffset() const; - void setStartOffset(unsigned offset); - - /// Set the end offset of the scope - unsigned endOffset() const; - void setEndOffset(unsigned offset); - - virtual const ScopedSymbol *asScopedSymbol() const - { return this; } - - virtual ScopedSymbol *asScopedSymbol() - { return this; } - -private: - Scope *_members; -}; - -class CPLUSPLUS_EXPORT Block: public ScopedSymbol +class CPLUSPLUS_EXPORT Block: public Scope { public: Block(TranslationUnit *translationUnit, unsigned sourceLocation); @@ -347,7 +271,7 @@ private: TemplateParameters *_templateParameters; }; -class CPLUSPLUS_EXPORT Enum: public ScopedSymbol, public Type +class CPLUSPLUS_EXPORT Enum: public Scope, public Type { public: Enum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name); @@ -377,7 +301,7 @@ protected: virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; }; -class CPLUSPLUS_EXPORT Function: public ScopedSymbol, public Type +class CPLUSPLUS_EXPORT Function: public Scope, public Type { public: enum MethodKey { @@ -484,7 +408,7 @@ private: }; }; -class CPLUSPLUS_EXPORT Namespace: public ScopedSymbol, public Type +class CPLUSPLUS_EXPORT Namespace: public Scope, public Type { public: Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name); @@ -541,7 +465,7 @@ private: FullySpecifiedType _type; }; -class CPLUSPLUS_EXPORT Class: public ScopedSymbol, public Type +class CPLUSPLUS_EXPORT Class: public Scope, public Type { public: Class(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name); @@ -668,7 +592,7 @@ protected: virtual bool matchType0(const Type *otherType, TypeMatcher *matcher) const; }; -class CPLUSPLUS_EXPORT ObjCProtocol: public ScopedSymbol, public Type +class CPLUSPLUS_EXPORT ObjCProtocol: public Scope, public Type { public: ObjCProtocol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name); @@ -735,7 +659,7 @@ protected: private: }; -class CPLUSPLUS_EXPORT ObjCClass: public ScopedSymbol, public Type +class CPLUSPLUS_EXPORT ObjCClass: public Scope, public Type { public: ObjCClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name); @@ -785,7 +709,7 @@ private: std::vector<ObjCBaseProtocol *> _protocols; }; -class CPLUSPLUS_EXPORT ObjCMethod: public ScopedSymbol, public Type +class CPLUSPLUS_EXPORT ObjCMethod: public Scope, public Type { public: ObjCMethod(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name); @@ -799,7 +723,6 @@ public: unsigned argumentCount() const; Symbol *argumentAt(unsigned index) const; - Scope *arguments() const; /** Convenience function that returns whether the function receives any arguments. */ bool hasArguments() const; @@ -839,7 +762,6 @@ private: unsigned _flags; Flags f; }; - Scope *_arguments; }; class CPLUSPLUS_EXPORT ObjCPropertyDeclaration: public Symbol