Commit cdb14432 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Cleanup specifiers.

parent 4fc2ccf0
......@@ -244,9 +244,8 @@ void CheckUndefinedSymbols::endVisit(FunctionDeclaratorAST *)
_functionDeclaratorStack.removeLast();
}
bool CheckUndefinedSymbols::visit(TypeofSpecifierAST *ast)
bool CheckUndefinedSymbols::visit(TypeofSpecifierAST *)
{
accept(ast->next);
return false;
}
......@@ -425,9 +424,9 @@ bool CheckUndefinedSymbols::visit(CastExpressionAST *ast)
{
if (ast->lparen_token && ast->type_id && ast->rparen_token && ast->expression) {
if (TypeIdAST *cast_type_id = ast->type_id->asTypeId()) {
SpecifierAST *type_specifier = cast_type_id->type_specifier;
SpecifierListAST *type_specifier = cast_type_id->type_specifier;
if (! cast_type_id->declarator && type_specifier && ! type_specifier->next &&
type_specifier->asNamedTypeSpecifier() && ast->expression &&
type_specifier->value->asNamedTypeSpecifier() && ast->expression &&
ast->expression->asUnaryExpression()) {
// this ast node is ambigious, e.g.
// (a) + b
......@@ -448,9 +447,9 @@ bool CheckUndefinedSymbols::visit(SizeofExpressionAST *ast)
{
if (ast->lparen_token && ast->expression && ast->rparen_token) {
if (TypeIdAST *type_id = ast->expression->asTypeId()) {
SpecifierAST *type_specifier = type_id->type_specifier;
SpecifierListAST *type_specifier = type_id->type_specifier;
if (! type_id->declarator && type_specifier && ! type_specifier->next &&
type_specifier->asNamedTypeSpecifier()) {
type_specifier->value->asNamedTypeSpecifier()) {
// this sizeof expression is ambiguos, e.g.
// sizeof (a)
// `a' can be a typeid or a nested-expression.
......
......@@ -402,16 +402,15 @@ bool FindUsages::visit(TemplateIdAST *ast)
bool FindUsages::visit(ParameterDeclarationAST *ast)
{
for (SpecifierAST *spec = ast->type_specifier; spec; spec = spec->next)
accept(spec);
for (SpecifierListAST *it = ast->type_specifier; it; it = it->next)
accept(it->value);
if (DeclaratorAST *declarator = ast->declarator) {
for (SpecifierAST *attr = declarator->attributes; attr; attr = attr->next)
accept(attr);
for (SpecifierListAST *it = declarator->attributes; it; it = it->next)
accept(it->value);
for (PtrOperatorListAST *it = declarator->ptr_operators; it; it = it->next) {
for (PtrOperatorListAST *it = declarator->ptr_operators; it; it = it->next)
accept(it->value);
}
if (! _inSimpleDeclaration) // visit the core declarator only if we are not in simple-declaration.
accept(declarator->core_declarator);
......@@ -419,8 +418,8 @@ bool FindUsages::visit(ParameterDeclarationAST *ast)
for (PostfixDeclaratorListAST *it = declarator->postfix_declarators; it; it = it->next)
accept(it->value);
for (SpecifierAST *spec = declarator->post_attributes; spec; spec = spec->next)
accept(spec);
for (SpecifierListAST *it = declarator->post_attributes; it; it = it->next)
accept(it->value);
accept(declarator->initializer);
}
......@@ -439,8 +438,8 @@ bool FindUsages::visit(FunctionDeclaratorAST *ast)
{
accept(ast->parameters);
for (SpecifierAST *spec = ast->cv_qualifier_seq; spec; spec = spec->next)
accept(spec);
for (SpecifierListAST *it = ast->cv_qualifier_seq; it; it = it->next)
accept(it->value);
accept(ast->exception_specification);
......
......@@ -391,10 +391,8 @@ unsigned ClassSpecifierAST::lastToken() const
else if (name)
return name->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (attributes)
return attributes->lastToken();
return classkey_token + 1;
}
......@@ -409,10 +407,8 @@ unsigned CompoundStatementAST::lastToken() const
if (rbrace_token)
return rbrace_token + 1;
for (StatementListAST *it = statements; it; it = it->next) {
if (! it->next)
return it->value->lastToken();
}
else if (statements)
return statements->lastToken();
return lbrace_token + 1;
}
......@@ -431,10 +427,8 @@ unsigned ConditionAST::lastToken() const
if (declarator)
return declarator->lastToken();
for (SpecifierAST *it = type_specifier; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (type_specifier)
return type_specifier->lastToken();
// ### assert?
return 0;
......@@ -486,10 +480,8 @@ unsigned ConversionFunctionIdAST::lastToken() const
if (ptr_operators)
return ptr_operators->lastToken();
for (SpecifierAST *it = type_specifier; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (type_specifier)
return type_specifier->lastToken();
return operator_token + 1;
}
......@@ -553,24 +545,20 @@ unsigned DeclaratorAST::lastToken() const
if (initializer)
return initializer->lastToken();
for (SpecifierAST *it = post_attributes; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (post_attributes)
return post_attributes->lastToken();
if (postfix_declarators)
else if (postfix_declarators)
return postfix_declarators->lastToken();
if (core_declarator)
else if (core_declarator)
return core_declarator->lastToken();
if (ptr_operators)
else if (ptr_operators)
return ptr_operators->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (attributes)
return attributes->lastToken();
// ### assert?
return 0;
......@@ -729,12 +717,13 @@ unsigned ExceptionDeclarationAST::lastToken() const
{
if (dot_dot_dot_token)
return dot_dot_dot_token + 1;
else if (declarator)
return declarator->lastToken();
for (SpecifierAST *it = type_specifier; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (type_specifier)
return type_specifier->lastToken();
return 0;
}
......@@ -845,13 +834,12 @@ unsigned FunctionDeclaratorAST::lastToken() const
if (exception_specification)
return exception_specification->lastToken();
for (SpecifierAST *it = cv_qualifier_seq; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (cv_qualifier_seq)
return cv_qualifier_seq->lastToken();
if (rparen_token)
else if (rparen_token)
return rparen_token + 1;
else if (parameters)
return parameters->lastToken();
......@@ -874,15 +862,15 @@ unsigned FunctionDefinitionAST::lastToken() const
{
if (function_body)
return function_body->lastToken();
else if (ctor_initializer)
return ctor_initializer->lastToken();
if (declarator)
else if (declarator)
return declarator->lastToken();
for (SpecifierAST *it = decl_specifier_seq; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (decl_specifier_seq)
return decl_specifier_seq->lastToken();
// ### assert
return 0;
......@@ -1032,12 +1020,10 @@ unsigned NamespaceAST::lastToken() const
if (linkage_body)
return linkage_body->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (attributes)
return attributes->lastToken();
if (identifier_token)
else if (identifier_token)
return identifier_token + 1;
return namespace_token + 1;
......@@ -1231,14 +1217,16 @@ unsigned ParameterDeclarationAST::lastToken() const
{
if (expression)
return expression->lastToken();
else if (equal_token)
return equal_token + 1;
else if (declarator)
return declarator->lastToken();
for (SpecifierAST *it = type_specifier; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (type_specifier)
return type_specifier->lastToken();
// ### assert?
return 0;
}
......@@ -1266,10 +1254,9 @@ unsigned PointerAST::firstToken() const
unsigned PointerAST::lastToken() const
{
for (SpecifierAST *it = cv_qualifier_seq; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
if (cv_qualifier_seq)
return cv_qualifier_seq->lastToken();
return star_token + 1;
}
......@@ -1285,12 +1272,10 @@ unsigned PointerToMemberAST::firstToken() const
unsigned PointerToMemberAST::lastToken() const
{
for (SpecifierAST *it = cv_qualifier_seq; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
if (cv_qualifier_seq)
return cv_qualifier_seq->lastToken();
if (star_token)
else if (star_token)
return star_token + 1;
else if (nested_name_specifier)
......@@ -1299,6 +1284,7 @@ unsigned PointerToMemberAST::lastToken() const
else if (global_scope_token)
return global_scope_token + 1;
// ### assert(0);
return 0;
}
......@@ -1391,18 +1377,16 @@ unsigned SimpleDeclarationAST::lastToken() const
if (semicolon_token)
return semicolon_token + 1;
if (declarators)
else if (declarators)
return declarators->lastToken();
for (SpecifierAST *it = decl_specifier_seq; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (decl_specifier_seq)
return decl_specifier_seq->lastToken();
// ### assert(0);
return 0;
}
unsigned SimpleNameAST::firstToken() const
{
return identifier_token;
......@@ -1630,20 +1614,16 @@ unsigned TypeConstructorCallAST::lastToken() const
if (rparen_token)
return rparen_token + 1;
for (ExpressionListAST *it = expression_list; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (expression_list)
return expression_list->lastToken();
if (lparen_token)
else if (lparen_token)
return lparen_token + 1;
else if (type_specifier)
return type_specifier->lastToken();
for (SpecifierAST *it = type_specifier; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
// ### assert(0);
return 0;
}
......@@ -1658,11 +1638,10 @@ unsigned TypeIdAST::lastToken() const
if (declarator)
return declarator->lastToken();
for (SpecifierAST *it = type_specifier; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (type_specifier)
return type_specifier->lastToken();
// ### assert(0);
return 0;
}
......@@ -1879,19 +1858,17 @@ unsigned ObjCProtocolDeclarationAST::lastToken() const
if (end_token)
return end_token + 1;
if (member_declarations)
else if (member_declarations)
return member_declarations->lastToken();
if (protocol_refs)
else if (protocol_refs)
return protocol_refs->lastToken();
if (name)
else if (name)
return name->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
else if (attributes)
return attributes->lastToken();
return protocol_token + 1;
}
......
......@@ -258,9 +258,6 @@ protected:
class CPLUSPLUS_EXPORT SpecifierAST: public AST
{
public:
SpecifierAST *next;
public:
virtual SpecifierAST *asSpecifier() { return this; }
};
......@@ -370,11 +367,11 @@ public:
class CPLUSPLUS_EXPORT DeclaratorAST: public AST
{
public:
SpecifierAST *attributes;
SpecifierListAST *attributes;
PtrOperatorListAST *ptr_operators;
CoreDeclaratorAST *core_declarator;
PostfixDeclaratorListAST *postfix_declarators;
SpecifierAST *post_attributes;
SpecifierListAST *post_attributes;
unsigned equals_token;
ExpressionAST *initializer;
......@@ -392,7 +389,7 @@ class CPLUSPLUS_EXPORT SimpleDeclarationAST: public DeclarationAST
{
public:
unsigned qt_invokable_token;
SpecifierAST *decl_specifier_seq;
SpecifierListAST *decl_specifier_seq;
DeclaratorListAST *declarators;
unsigned semicolon_token;
......@@ -557,7 +554,7 @@ class CPLUSPLUS_EXPORT ClassSpecifierAST: public SpecifierAST
{
public:
unsigned classkey_token;
SpecifierAST *attributes;
SpecifierListAST *attributes;
NameAST *name;
unsigned colon_token;
BaseSpecifierListAST *base_clause_list;
......@@ -619,7 +616,7 @@ protected:
class CPLUSPLUS_EXPORT ConditionAST: public ExpressionAST
{
public:
SpecifierAST *type_specifier;
SpecifierListAST *type_specifier;
DeclaratorAST *declarator;
public:
......@@ -741,7 +738,7 @@ public:
unsigned lparen_token;
ParameterDeclarationClauseAST *parameters;
unsigned rparen_token;
SpecifierAST *cv_qualifier_seq;
SpecifierListAST *cv_qualifier_seq;
ExceptionSpecificationAST *exception_specification;
ExpressionAST *as_cpp_initializer;
......@@ -885,7 +882,7 @@ protected:
class CPLUSPLUS_EXPORT ExceptionDeclarationAST: public DeclarationAST
{
public:
SpecifierAST *type_specifier;
SpecifierListAST *type_specifier;
DeclaratorAST *declarator;
unsigned dot_dot_dot_token;
......@@ -954,7 +951,7 @@ class CPLUSPLUS_EXPORT FunctionDefinitionAST: public DeclarationAST
{
public:
unsigned qt_invokable_token;
SpecifierAST *decl_specifier_seq;
SpecifierListAST *decl_specifier_seq;
DeclaratorAST *declarator;
CtorInitializerAST *ctor_initializer;
StatementAST *function_body;
......@@ -978,7 +975,7 @@ public:
unsigned foreach_token;
unsigned lparen_token;
// declaration
SpecifierAST *type_specifiers;
SpecifierListAST *type_specifiers;
DeclaratorAST *declarator;
// or an expression
ExpressionAST *initializer;
......@@ -1197,7 +1194,7 @@ class CPLUSPLUS_EXPORT ConversionFunctionIdAST: public NameAST
{
public:
unsigned operator_token;
SpecifierAST *type_specifier;
SpecifierListAST *type_specifier;
PtrOperatorListAST *ptr_operators;
public:
......@@ -1264,7 +1261,7 @@ class CPLUSPLUS_EXPORT NamespaceAST: public DeclarationAST
public:
unsigned namespace_token;
unsigned identifier_token;
SpecifierAST *attributes;
SpecifierListAST *attributes;
DeclarationAST *linkage_body;
public: // annotations
......@@ -1378,7 +1375,7 @@ protected:
class CPLUSPLUS_EXPORT NewTypeIdAST: public AST
{
public:
SpecifierAST *type_specifier;
SpecifierListAST *type_specifier;
PtrOperatorListAST *ptr_operators;
NewArrayDeclaratorListAST *new_array_declarators;
......@@ -1412,7 +1409,7 @@ protected:
class CPLUSPLUS_EXPORT ParameterDeclarationAST: public DeclarationAST
{
public:
SpecifierAST *type_specifier;
SpecifierListAST *type_specifier;
DeclaratorAST *declarator;
unsigned equal_token;
ExpressionAST *expression;
......@@ -1558,7 +1555,7 @@ protected:
class CPLUSPLUS_EXPORT TypeConstructorCallAST: public ExpressionAST
{
public:
SpecifierAST *type_specifier;
SpecifierListAST *type_specifier;
unsigned lparen_token;
ExpressionListAST *expression_list;
unsigned rparen_token;
......@@ -1601,7 +1598,7 @@ public:
unsigned global_scope_token;
NestedNameSpecifierListAST *nested_name_specifier;
unsigned star_token;
SpecifierAST *cv_qualifier_seq;
SpecifierListAST *cv_qualifier_seq;
public:
virtual PointerToMemberAST *asPointerToMember() { return this; }
......@@ -1617,7 +1614,7 @@ class CPLUSPLUS_EXPORT PointerAST: public PtrOperatorAST
{
public:
unsigned star_token;
SpecifierAST *cv_qualifier_seq;
SpecifierListAST *cv_qualifier_seq;
public:
virtual PointerAST *asPointer() { return this; }
......@@ -1921,7 +1918,7 @@ protected:
class CPLUSPLUS_EXPORT TypeIdAST: public ExpressionAST
{
public:
SpecifierAST *type_specifier;
SpecifierListAST *type_specifier;
DeclaratorAST *declarator;
public:
......@@ -2063,7 +2060,7 @@ protected:
class CPLUSPLUS_EXPORT ObjCClassForwardDeclarationAST: public DeclarationAST
{
public:
SpecifierAST *attributes;
SpecifierListAST *attributes;
unsigned class_token;
ObjCIdentifierListAST *identifier_list;
unsigned semicolon_token;
......@@ -2084,7 +2081,7 @@ protected:
class CPLUSPLUS_EXPORT ObjCClassDeclarationAST: public DeclarationAST
{
public:
SpecifierAST *attributes;
SpecifierListAST *attributes;
unsigned interface_token;
unsigned implementation_token;
NameAST *class_name;
......@@ -2114,7 +2111,7 @@ protected:
class CPLUSPLUS_EXPORT ObjCProtocolForwardDeclarationAST: public DeclarationAST
{
public:
SpecifierAST *attributes;
SpecifierListAST *attributes;
unsigned protocol_token;
ObjCIdentifierListAST *identifier_list;
unsigned semicolon_token;
......@@ -2135,7 +2132,7 @@ protected:
class CPLUSPLUS_EXPORT ObjCProtocolDeclarationAST: public DeclarationAST
{
public:
SpecifierAST *attributes;
SpecifierListAST *attributes;
unsigned protocol_token;
NameAST *name;
ObjCProtocolRefsAST *protocol_refs;
......@@ -2384,7 +2381,7 @@ protected:
class CPLUSPLUS_EXPORT ObjCPropertyDeclarationAST: public DeclarationAST
{
public:
SpecifierAST *attributes;
SpecifierListAST *attributes;
unsigned property_token;
unsigned lparen_token;
ObjCPropertyAttributeListAST *property_attributes;
......@@ -2405,7 +2402,7 @@ class CPLUSPLUS_EXPORT ObjCMessageArgumentDeclarationAST: public NameAST
{
public:
ObjCTypeNameAST* type_name;
SpecifierAST *attributes;
SpecifierListAST *attributes;
unsigned param_name_token;
public: // annotations
......@@ -2429,7 +2426,7 @@ public:
ObjCSelectorAST *selector;
ObjCMessageArgumentDeclarationListAST *arguments;
unsigned dot_dot_dot_token;
SpecifierAST *attributes;
SpecifierListAST *attributes;
public: // annotations
ObjCMethod *symbol;
......@@ -2519,7 +2516,7 @@ public:
unsigned lparen_token;
// declaration
SpecifierAST *type_specifiers;
SpecifierListAST *type_specifiers;
DeclaratorAST *declarator;
// or an expression
ExpressionAST *initializer;
......
......@@ -67,13 +67,11 @@ void TypeofSpecifierAST::accept0(ASTVisitor *visitor)
void DeclaratorAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
for (SpecifierAST *it = attributes; it; it = it->next)
accept(it, visitor);
accept(attributes, visitor);
accept(ptr_operators, visitor);
accept(core_declarator, visitor);
accept(postfix_declarators, visitor);
for (SpecifierAST *it = post_attributes; it; it = it->next)
accept(it, visitor);
accept(post_attributes, visitor);
accept(initializer, visitor);
}
visitor->endVisit(this);
......@@ -82,10 +80,8 @@ void DeclaratorAST::accept0(ASTVisitor *visitor)
void SimpleDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
for (SpecifierAST *it = decl_specifier_seq; it; it = it->next)