Cleanup base base specifiers.

This commit is contained in:
Roberto Raggi
2009-11-10 14:03:40 +01:00
parent 86a8812beb
commit 1dbdbbefe7
9 changed files with 36 additions and 33 deletions

View File

@@ -382,15 +382,13 @@ unsigned ClassSpecifierAST::lastToken() const
if (lbrace_token)
return lbrace_token + 1;
for (BaseSpecifierAST *it = base_clause; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (base_clause_list)
return base_clause_list->lastToken();
if (colon_token)
else if (colon_token)
return colon_token + 1;
if (name)
else if (name)
return name->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {

View File

@@ -478,7 +478,6 @@ public:
unsigned virtual_token;
unsigned access_specifier_token;
NameAST *name;
BaseSpecifierAST *next;
public: // annotations
BaseClass *symbol;
@@ -571,7 +570,7 @@ public:
SpecifierAST *attributes;
NameAST *name;
unsigned colon_token;
BaseSpecifierAST *base_clause;
BaseSpecifierListAST *base_clause_list;
unsigned lbrace_token;
DeclarationListAST *member_specifiers;
unsigned rbrace_token;

View File

@@ -163,8 +163,7 @@ void ClassSpecifierAST::accept0(ASTVisitor *visitor)
for (SpecifierAST *it = attributes; it; it = it->next)
accept(it, visitor);
accept(name, visitor);
for (BaseSpecifierAST *it = base_clause; it; it = it->next)
accept(it, visitor);
accept(base_clause_list, visitor);
for (DeclarationListAST *it = member_specifiers; it; it = it->next)
accept(it, visitor);
}

View File

@@ -195,6 +195,8 @@ typedef List<ExpressionAST *> ExpressionListAST;
typedef List<DeclarationAST *> DeclarationListAST;
typedef List<StatementAST *> StatementListAST;
typedef List<DeclaratorAST *> DeclaratorListAST;
typedef List<BaseSpecifierAST *> BaseSpecifierListAST;
typedef List<NameAST *> ObjCIdentifierListAST;
typedef List<ObjCMessageArgumentAST *> ObjCMessageArgumentListAST;
typedef List<ObjCSelectorArgumentAST *> ObjCSelectorArgumentListAST;

View File

@@ -328,7 +328,8 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast)
_scope->enterSymbol(klass);
_fullySpecifiedType.setType(klass);
for (BaseSpecifierAST *base = ast->base_clause; base; base = base->next) {
for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) {
BaseSpecifierAST *base = it->value;
Name *baseClassName = semantic()->check(base->name, _scope);
BaseClass *baseClass = control()->newBaseClass(ast->firstToken(), baseClassName);
base->symbol = baseClass;

View File

@@ -1550,17 +1550,23 @@ bool Parser::parseClassSpecifier(SpecifierAST *&node)
unsigned colon_token = 0;
if (LA() == T_COLON || LA() == T_LBRACE) {
BaseSpecifierAST *base_clause = 0;
BaseSpecifierListAST *base_clause_list = 0;
if (LA() == T_COLON) {
colon_token = cursor();
parseBaseClause(base_clause);
parseBaseClause(base_clause_list);
if (LA() != T_LBRACE) {
_translationUnit->error(cursor(), "expected `{' before `%s'", tok().spell());
unsigned saved = cursor();
const unsigned saved = cursor();
for (int n = 0; n < 3 && LA() != T_EOF_SYMBOL; ++n, consumeToken()) {
if (LA() == T_LBRACE)
break;
}
if (LA() != T_LBRACE)
rewind(saved);
}
@@ -1571,7 +1577,7 @@ bool Parser::parseClassSpecifier(SpecifierAST *&node)
ast->attributes = attributes;
ast->name = name;
ast->colon_token = colon_token;
ast->base_clause = base_clause;
ast->base_clause_list = base_clause_list;
if (LA() == T_LBRACE)
ast->lbrace_token = consumeToken();
@@ -1778,13 +1784,14 @@ bool Parser::parseInitDeclarator(DeclaratorAST *&node,
return true;
}
bool Parser::parseBaseClause(BaseSpecifierAST *&node)
bool Parser::parseBaseClause(BaseSpecifierListAST *&node)
{
DEBUG_THIS_RULE();
if (LA() == T_COLON) {
consumeToken();
BaseSpecifierAST **ast = &node;
if (LA() == T_COLON) {
consumeToken(); // ### remove me
BaseSpecifierListAST **ast = &node;
if (parseBaseSpecifier(*ast)) {
ast = &(*ast)->next;
@@ -1895,7 +1902,7 @@ bool Parser::parseExpressionList(ExpressionListAST *&node)
return false;
}
bool Parser::parseBaseSpecifier(BaseSpecifierAST *&node)
bool Parser::parseBaseSpecifier(BaseSpecifierListAST *&node)
{
DEBUG_THIS_RULE();
BaseSpecifierAST *ast = new (_pool) BaseSpecifierAST;
@@ -1918,7 +1925,9 @@ bool Parser::parseBaseSpecifier(BaseSpecifierAST *&node)
parseName(ast->name);
if (! ast->name)
_translationUnit->error(cursor(), "expected class-name");
node = ast;
node = new (_pool) BaseSpecifierListAST;
node->value = ast;
return true;
}

View File

@@ -84,8 +84,8 @@ public:
bool parseAsmOperand();
bool parseAsmClobberList();
bool parseAssignmentExpression(ExpressionAST *&node);
bool parseBaseClause(BaseSpecifierAST *&node);
bool parseBaseSpecifier(BaseSpecifierAST *&node);
bool parseBaseClause(BaseSpecifierListAST *&node);
bool parseBaseSpecifier(BaseSpecifierListAST *&node);
bool parseBlockDeclaration(DeclarationAST *&node);
bool parseCppCastExpression(ExpressionAST *&node);
bool parseCastExpression(ExpressionAST *&node);