Commit 88fe5a50 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Added semantic checks for stray semicolons and topldevel empty declarations.

parent 476dda1b
......@@ -70,7 +70,7 @@ QList<CppQuickFixOperation::Ptr> InsertQtPropertyMembers::match(const CppQuickFi
QString getterName;
QString setterName;
QString signalName;
int generateFlags;
int generateFlags = 0;
for (QtPropertyDeclarationItemListAST *it = qtPropertyDeclaration->property_declaration_item_list;
it; it = it->next) {
const QString tokenString = file.tokenAt(it->value->item_name_token).spell();
......
......@@ -1107,6 +1107,8 @@ unsigned EnumSpecifierAST::firstToken() const
if (enumerator_list)
if (unsigned candidate = enumerator_list->firstToken())
return candidate;
if (stray_comma_token)
return stray_comma_token;
if (rbrace_token)
return rbrace_token;
return 0;
......@@ -1117,6 +1119,8 @@ unsigned EnumSpecifierAST::lastToken() const
{
if (rbrace_token)
return rbrace_token + 1;
if (stray_comma_token)
return stray_comma_token + 1;
if (enumerator_list)
if (unsigned candidate = enumerator_list->lastToken())
return candidate;
......
......@@ -1621,6 +1621,7 @@ public:
NameAST *name;
unsigned lbrace_token;
EnumeratorListAST *enumerator_list;
unsigned stray_comma_token;
unsigned rbrace_token;
public: // annotations
......@@ -1632,6 +1633,7 @@ public:
, name(0)
, lbrace_token(0)
, enumerator_list(0)
, stray_comma_token(0)
, rbrace_token(0)
, symbol(0)
{}
......
......@@ -557,6 +557,7 @@ EnumSpecifierAST *EnumSpecifierAST::clone(MemoryPool *pool) const
for (EnumeratorListAST *iter = enumerator_list, **ast_iter = &ast->enumerator_list;
iter; iter = iter->next, ast_iter = &(*ast_iter)->next)
*ast_iter = new (pool) EnumeratorListAST((iter->value) ? iter->value->clone(pool) : 0);
ast->stray_comma_token = stray_comma_token;
ast->rbrace_token = rbrace_token;
return ast;
}
......
......@@ -926,6 +926,8 @@ bool ASTMatcher::match(EnumSpecifierAST *node, EnumSpecifierAST *pattern)
else if (! AST::match(node->enumerator_list, pattern->enumerator_list, this))
return false;
pattern->stray_comma_token = node->stray_comma_token;
pattern->rbrace_token = node->rbrace_token;
return true;
......
......@@ -1796,7 +1796,13 @@ bool Bind::visit(SimpleDeclarationAST *ast)
bool Bind::visit(EmptyDeclarationAST *ast)
{
(void) ast;
// unsigned semicolon_token = ast->semicolon_token;
unsigned semicolon_token = ast->semicolon_token;
if (_scope && (_scope->isClass() || _scope->isNamespace())) {
const Token &tk = tokenAt(semicolon_token);
if (! tk.generated())
translationUnit()->warning(semicolon_token, "extra `;'");
}
return false;
}
......@@ -2770,6 +2776,14 @@ bool Bind::visit(EnumSpecifierAST *ast)
for (EnumeratorListAST *it = ast->enumerator_list; it; it = it->next) {
this->enumerator(it->value, e);
}
if (ast->stray_comma_token /* && ! translationUnit()->cxx0xEnabled()*/) {
const Token &tk = tokenAt(ast->stray_comma_token);
if (! tk.generated())
translationUnit()->warning(ast->stray_comma_token,
"commas at the end of enumerator lists are a C++0x-specific feature");
}
(void) switchScope(previousScope);
return false;
}
......
......@@ -1546,6 +1546,9 @@ bool Parser::parseEnumSpecifier(SpecifierListAST *&node)
enumerator_ptr = &(*enumerator_ptr)->next;
}
if (LA() == T_COMMA && LA(2) == T_RBRACE)
ast->stray_comma_token = consumeToken();
if (LA() != T_RBRACE)
match(T_COMMA, &comma_token);
}
......
......@@ -543,6 +543,8 @@ virtual bool visit(EnumSpecifierAST *ast)
terminal(ast->lbrace_token, ast);
for (EnumeratorListAST *iter = ast->enumerator_list; iter; iter = iter->next)
nonterminal(iter->value);
if (ast->stray_comma_token)
terminal(ast->stray_comma_token, ast);
if (ast->rbrace_token)
terminal(ast->rbrace_token, ast);
return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment