Merged ScopedSymbol and Scope.

This commit is contained in:
Roberto Raggi
2010-08-11 12:26:02 +02:00
parent 5accc9664e
commit 354b9712e4
33 changed files with 500 additions and 818 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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)

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -55,18 +55,77 @@
using namespace CPlusPlus;
Scope::Scope(ScopedSymbol *owner)
class CPlusPlus::SymbolTable
{
SymbolTable(const SymbolTable &other);
void operator =(const SymbolTable &other);
public:
typedef Symbol **iterator;
public:
/// Constructs an empty Scope.
SymbolTable(Scope *owner = 0);
/// Destroy this scope.
~SymbolTable();
/// Returns this scope's owner Symbol.
Scope *owner() const;
/// Sets this scope's owner Symbol.
void setOwner(Scope *owner); // ### remove me
/// 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;
/// 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;
private:
/// Returns the hash value for the given Symbol.
unsigned hashValue(Symbol *symbol) const;
/// Updates the hash table.
void rehash();
private:
enum { DefaultInitialSize = 11 };
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),
_startOffset(0),
_endOffset(0)
_hashSize(0)
{ }
Scope::~Scope()
SymbolTable::~SymbolTable()
{
if (_symbols)
free(_symbols);
@@ -74,128 +133,7 @@ Scope::~Scope()
free(_hash);
}
ScopedSymbol *Scope::owner() const
{ return _owner; }
void Scope::setOwner(ScopedSymbol *owner)
{ _owner = owner; }
Scope *Scope::enclosingScope() const
{
if (! _owner)
return 0;
return _owner->scope();
}
Scope *Scope::enclosingNamespaceScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isNamespace())
break;
}
return scope;
}
Scope *Scope::enclosingClassScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isClass())
break;
}
return scope;
}
Scope *Scope::enclosingEnumScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isEnum())
break;
}
return scope;
}
Scope *Scope::enclosingPrototypeScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isFunction())
break;
}
return scope;
}
Scope *Scope::enclosingBlockScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isBlock())
break;
}
return scope;
}
bool Scope::isNamespaceScope() const
{
if (_owner)
return _owner->isNamespace();
return false;
}
bool Scope::isClassScope() const
{
if (_owner)
return _owner->isClass();
return false;
}
bool Scope::isEnumScope() const
{
if (_owner)
return _owner->isEnum();
return false;
}
bool Scope::isBlockScope() const
{
if (_owner)
return _owner->isBlock();
return false;
}
bool Scope::isObjCClassScope() const
{
if (_owner)
return _owner->isObjCClass();
return false;
}
bool Scope::isObjCProtocolScope() const
{
if (_owner)
return _owner->isObjCProtocol();
return false;
}
bool Scope::isPrototypeScope() const
{
if (_owner)
return _owner->isFunction();
return false;
}
bool Scope::isObjCMethodScope() const
{
ObjCMethod *m = 0;
if (_owner && 0 != (m = _owner->asObjCMethod()))
return m->arguments() != this;
return false;
}
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; }

View File

@@ -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;
};

View File

@@ -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);

View File

@@ -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();
for (Scope *s = _scope; s; s = s->scope()) {
if (Namespace *ns = s->asNamespace())
return ns;
}
return 0;
}
Scope *Symbol::enclosingNamespaceScope() const
Class *Symbol::enclosingClass() const
{
if (! _scope)
return 0;
else if (_scope->isNamespaceScope())
return _scope;
return _scope->enclosingNamespaceScope();
for (Scope *s = _scope; s; s = s->scope()) {
if (Class *klass = s->asClass())
return klass;
}
return 0;
}
Scope *Symbol::enclosingClassScope() const
Enum *Symbol::enclosingEnum() const
{
if (! _scope)
return 0;
else if (_scope->isClassScope())
return _scope;
return _scope->enclosingClassScope();
for (Scope *s = _scope; s; s = s->scope()) {
if (Enum *e = s->asEnum())
return e;
}
return 0;
}
Scope *Symbol::enclosingEnumScope() const
Function *Symbol::enclosingFunction() const
{
if (! _scope)
return 0;
else if (_scope->isEnumScope())
return _scope;
return _scope->enclosingEnumScope();
for (Scope *s = _scope; s; s = s->scope()) {
if (Function *fun = s->asFunction())
return fun;
}
return 0;
}
Scope *Symbol::enclosingPrototypeScope() const
Block *Symbol::enclosingBlock() const
{
if (! _scope)
return 0;
else if (_scope->isPrototypeScope())
return _scope;
return _scope->enclosingPrototypeScope();
}
Scope *Symbol::enclosingBlockScope() 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; }

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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