aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorRoberto Raggi <[email protected]>2010-08-11 12:26:02 +0200
committerRoberto Raggi <[email protected]>2010-08-11 15:25:18 +0200
commit354b9712e4655040930a9f18de4e6b4c71dc42d9 (patch)
tree474bab43aa8a84893f38b8a0552f8071404e6a12 /src/libs
parent5accc9664ea247a5b9e1fa6097a04252fb57f01b (diff)
Merged ScopedSymbol and Scope.
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/cplusplus/CppDocument.cpp30
-rw-r--r--src/libs/cplusplus/CppDocument.h1
-rw-r--r--src/libs/cplusplus/DeprecatedGenTemplateInstance.cpp2
-rw-r--r--src/libs/cplusplus/FindUsages.cpp29
-rw-r--r--src/libs/cplusplus/FindUsages.h3
-rw-r--r--src/libs/cplusplus/Icons.cpp2
-rw-r--r--src/libs/cplusplus/LookupContext.cpp50
-rw-r--r--src/libs/cplusplus/OverviewModel.cpp29
-rw-r--r--src/libs/cplusplus/ResolveExpression.cpp19
9 files changed, 67 insertions, 98 deletions
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp
index 1e677f85c04..e6197884d2a 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 cc1f9c2ff8c..b30efc2716c 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 175477e88dc..8bba41c07ac 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 c42c125b90e..a381bb91b21 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 bf9e86bfd83..64e854df9bd 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 a3bb5a38ef3..51a7bea017c 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 cdc1018e2de..e56ffcbc074 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 c3953a29e8d..2174735c118 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 6cb276d81b0..55c4c3ac42a 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;