summaryrefslogtreecommitdiff
path: root/src/shared/cplusplus
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-08-11 12:26:02 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2010-08-11 15:25:18 +0200
commit354b9712e4655040930a9f18de4e6b4c71dc42d9 (patch)
tree474bab43aa8a84893f38b8a0552f8071404e6a12 /src/shared/cplusplus
parent5accc9664ea247a5b9e1fa6097a04252fb57f01b (diff)
downloadqt-creator-354b9712e4655040930a9f18de4e6b4c71dc42d9.tar.gz
Merged ScopedSymbol and Scope.
Diffstat (limited to 'src/shared/cplusplus')
-rw-r--r--src/shared/cplusplus/CPlusPlusForwardDeclarations.h4
-rw-r--r--src/shared/cplusplus/CheckDeclaration.cpp75
-rw-r--r--src/shared/cplusplus/CheckDeclarator.cpp4
-rw-r--r--src/shared/cplusplus/CheckExpression.cpp11
-rw-r--r--src/shared/cplusplus/CheckName.cpp2
-rw-r--r--src/shared/cplusplus/CheckSpecifier.cpp14
-rw-r--r--src/shared/cplusplus/CheckStatement.cpp60
-rw-r--r--src/shared/cplusplus/Scope.cpp252
-rw-r--r--src/shared/cplusplus/Scope.h101
-rw-r--r--src/shared/cplusplus/Semantic.cpp2
-rw-r--r--src/shared/cplusplus/Symbol.cpp80
-rw-r--r--src/shared/cplusplus/Symbol.h22
-rw-r--r--src/shared/cplusplus/Symbols.cpp160
-rw-r--r--src/shared/cplusplus/Symbols.h96
14 files changed, 300 insertions, 583 deletions
diff --git a/src/shared/cplusplus/CPlusPlusForwardDeclarations.h b/src/shared/cplusplus/CPlusPlusForwardDeclarations.h
index 5dc0609670..9b8f7a1976 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 94b7b845b9..f431ca9db5 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 d9d51b356e..41b4ea1b3a 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 27e05390c0..544dc95cea 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 1161a8e0e0..4fccbcd759 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 8e8debdcfc..6bb4879246 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 aa145e804c..b61ba97a9e 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 a38dce4840..0d8f75eeb2 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 b98435100a..c3a1cb23e7 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 91cb68513f..91376d3a25 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 e5a99bcb66..bb63cd96da 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 b83f676601..bcd0e7e695 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 62d068063d..5ad7d815db 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 4017b367a0..a52b7cb373 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