diff options
Diffstat (limited to 'src/shared/cplusplus/CheckSpecifier.cpp')
-rw-r--r-- | src/shared/cplusplus/CheckSpecifier.cpp | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/src/shared/cplusplus/CheckSpecifier.cpp b/src/shared/cplusplus/CheckSpecifier.cpp index 6baef4682e..5b32762c69 100644 --- a/src/shared/cplusplus/CheckSpecifier.cpp +++ b/src/shared/cplusplus/CheckSpecifier.cpp @@ -69,11 +69,11 @@ CheckSpecifier::CheckSpecifier(Semantic *semantic) CheckSpecifier::~CheckSpecifier() { } -FullySpecifiedType CheckSpecifier::check(SpecifierAST *specifier, Scope *scope) +FullySpecifiedType CheckSpecifier::check(SpecifierListAST *specifier, Scope *scope) { FullySpecifiedType previousType = switchFullySpecifiedType(FullySpecifiedType()); Scope *previousScope = switchScope(scope); - SpecifierAST *previousSpecifier = switchSpecifier(specifier); + SpecifierListAST *previousSpecifier = switchSpecifier(specifier); accept(specifier); (void) switchSpecifier(previousSpecifier); (void) switchScope(previousScope); @@ -91,14 +91,14 @@ FullySpecifiedType CheckSpecifier::check(ObjCTypeNameAST *typeName, Scope *scope return switchFullySpecifiedType(previousType); } -SpecifierAST *CheckSpecifier::switchSpecifier(SpecifierAST *specifier) +SpecifierListAST *CheckSpecifier::switchSpecifier(SpecifierListAST *specifier) { - SpecifierAST *previousSpecifier = _specifier; + SpecifierListAST *previousSpecifier = _specifier; _specifier = specifier; return previousSpecifier; } -FullySpecifiedType CheckSpecifier::switchFullySpecifiedType(FullySpecifiedType type) +FullySpecifiedType CheckSpecifier::switchFullySpecifiedType(const FullySpecifiedType &type) { FullySpecifiedType previousType = _fullySpecifiedType; _fullySpecifiedType = type; @@ -301,7 +301,7 @@ bool CheckSpecifier::visit(SimpleSpecifierAST *ast) default: break; } // switch - accept(ast->next); + return false; } @@ -312,7 +312,7 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast) if (ast->name) sourceLocation = ast->name->firstToken(); - Name *className = semantic()->check(ast->name, _scope); + const Name *className = semantic()->check(ast->name, _scope); Class *klass = control()->newClass(sourceLocation, className); klass->setStartOffset(tokenAt(ast->firstToken()).offset); klass->setEndOffset(tokenAt(ast->lastToken()).offset); @@ -328,8 +328,9 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast) _scope->enterSymbol(klass); _fullySpecifiedType.setType(klass); - for (BaseSpecifierAST *base = ast->base_clause; base; base = base->next) { - Name *baseClassName = semantic()->check(base->name, _scope); + for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) { + BaseSpecifierAST *base = it->value; + const Name *baseClassName = semantic()->check(base->name, _scope); BaseClass *baseClass = control()->newBaseClass(ast->firstToken(), baseClassName); base->symbol = baseClass; if (base->virtual_token) @@ -346,30 +347,36 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast) int previousVisibility = semantic()->switchVisibility(visibility); int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod); - for (DeclarationListAST *member = ast->member_specifiers; member; member = member->next) { - semantic()->check(member->declaration, klass->members()); + DeclarationAST *previousDeclaration = 0; + for (DeclarationListAST *it = ast->member_specifier_list; it; it = it->next) { + DeclarationAST *declaration = it->value; + semantic()->check(declaration, klass->members()); + + if (previousDeclaration && declaration && + declaration->asEmptyDeclaration() != 0 && + previousDeclaration->asFunctionDefinition() != 0) + translationUnit()->warning(declaration->firstToken(), "unnecessary semicolon after function body"); + + previousDeclaration = declaration; } (void) semantic()->switchMethodKey(previousMethodKey); (void) semantic()->switchVisibility(previousVisibility); - accept(ast->next); return false; } bool CheckSpecifier::visit(NamedTypeSpecifierAST *ast) { - Name *name = semantic()->check(ast->name, _scope); + const Name *name = semantic()->check(ast->name, _scope); _fullySpecifiedType.setType(control()->namedType(name)); - accept(ast->next); return false; } bool CheckSpecifier::visit(ElaboratedTypeSpecifierAST *ast) { - Name *name = semantic()->check(ast->name, _scope); + const Name *name = semantic()->check(ast->name, _scope); _fullySpecifiedType.setType(control()->namedType(name)); - accept(ast->next); return false; } @@ -379,37 +386,34 @@ bool CheckSpecifier::visit(EnumSpecifierAST *ast) if (ast->name) sourceLocation = ast->name->firstToken(); - Name *name = semantic()->check(ast->name, _scope); + const Name *name = semantic()->check(ast->name, _scope); Enum *e = control()->newEnum(sourceLocation, name); e->setStartOffset(tokenAt(ast->firstToken()).offset); e->setEndOffset(tokenAt(ast->lastToken()).offset); e->setVisibility(semantic()->currentVisibility()); _scope->enterSymbol(e); _fullySpecifiedType.setType(e); - for (EnumeratorAST *enumerator = ast->enumerators; enumerator; - enumerator = enumerator->next) { - Identifier *id = identifier(enumerator->identifier_token); + for (EnumeratorListAST *it = ast->enumerator_list; it; it = it->next) { + EnumeratorAST *enumerator = it->value; + const Identifier *id = identifier(enumerator->identifier_token); if (! id) continue; - NameId *enumeratorName = control()->nameId(id); + const NameId *enumeratorName = control()->nameId(id); Declaration *decl = control()->newDeclaration(enumerator->firstToken(), enumeratorName); e->addMember(decl); } - accept(ast->next); return false; } bool CheckSpecifier::visit(TypeofSpecifierAST *ast) { semantic()->check(ast->expression, _scope); - accept(ast->next); return false; } -bool CheckSpecifier::visit(AttributeSpecifierAST *ast) +bool CheckSpecifier::visit(AttributeSpecifierAST * /*ast*/) { - accept(ast->next); return false; } |