diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index cd85bff3dc6e78bbafb06534426a5f1740e503bf..42f16aa47be98bd96082f66af421d74fcb36fd7b 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -366,8 +366,8 @@ protected: { 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); diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp index 825c7506b995f3838ccd5b1be0b5443087802fed..45292dcc4a4731112d93e2999efa0675c70306fb 100644 --- a/src/shared/cplusplus/AST.cpp +++ b/src/shared/cplusplus/AST.cpp @@ -100,16 +100,13 @@ unsigned AttributeAST::lastToken() const if (rparen_token) return rparen_token + 1; - for (ExpressionListAST *it = expression_list; it->value && it->next; it = it->next) { - if (! it->next && it->value) { - return it->value->lastToken(); - } - } + else if (expression_list) + return expression_list->lastToken(); - if (tag_token) + else if (tag_token) return tag_token + 1; - if (lparen_token) + else if (lparen_token) return lparen_token + 1; return identifier_token + 1; @@ -172,10 +169,8 @@ unsigned ArrayInitializerAST::lastToken() const if (rbrace_token) return rbrace_token + 1; - for (ExpressionListAST *it = expression_list; it; it = it->next) { - if (! it->next && it->value) - return it->value->lastToken(); - } + else if (expression_list) + return expression_list->lastToken(); return lbrace_token + 1; } @@ -302,10 +297,10 @@ unsigned CallAST::lastToken() const { if (rparen_token) return rparen_token + 1; - for (ExpressionListAST *it = expression_list; it; it = it->next) { - if (! it->next && it->value) - return it->value->lastToken(); - } + + else if (expression_list) + return expression_list->lastToken(); + return lparen_token + 1; } @@ -374,12 +369,10 @@ unsigned ClassSpecifierAST::lastToken() const if (rbrace_token) return rbrace_token + 1; - for (DeclarationListAST *it = member_specifiers; it; it = it->next) { - if (! it->next) - return it->lastToken(); - } + else if (member_specifiers) + return member_specifiers->lastToken(); - if (lbrace_token) + else if (lbrace_token) return lbrace_token + 1; else if (base_clause_list) @@ -416,8 +409,8 @@ unsigned CompoundStatementAST::lastToken() const unsigned ConditionAST::firstToken() const { - if (type_specifier) - return type_specifier->firstToken(); + if (type_specifiers) + return type_specifiers->firstToken(); return declarator->firstToken(); } @@ -427,8 +420,8 @@ unsigned ConditionAST::lastToken() const if (declarator) return declarator->lastToken(); - else if (type_specifier) - return type_specifier->lastToken(); + else if (type_specifiers) + return type_specifiers->lastToken(); // ### assert? return 0; @@ -738,13 +731,12 @@ unsigned ExceptionSpecificationAST::lastToken() const if (rparen_token) return rparen_token + 1; - for (ExpressionListAST *it = type_ids; it; it = it->next) { - if (! it->next && it->value) - return it->value->lastToken(); - } + else if (type_ids) + return type_ids->lastToken(); - if (dot_dot_dot_token) + else if (dot_dot_dot_token) return dot_dot_dot_token + 1; + else if (lparen_token) return lparen_token + 1; @@ -942,10 +934,8 @@ unsigned LinkageBodyAST::lastToken() const if (rbrace_token) return rbrace_token + 1; - for (DeclarationListAST *it = declarations; it; it = it->next) { - if (! it->next) - return it->lastToken(); - } + else if (declarations) + return declarations->lastToken(); return lbrace_token + 1; } @@ -1457,12 +1447,16 @@ unsigned SwitchStatementAST::lastToken() const { if (statement) return statement->lastToken(); + else if (rparen_token) return rparen_token + 1; + else if (condition) return condition->lastToken(); + else if (lparen_token) return lparen_token + 1; + return switch_token + 1; } @@ -1470,6 +1464,7 @@ unsigned TemplateDeclarationAST::firstToken() const { if (export_token) return export_token; + return template_token; } @@ -1477,21 +1472,23 @@ unsigned TemplateDeclarationAST::lastToken() const { if (declaration) return declaration->lastToken(); + else if (greater_token) return greater_token + 1; - for (DeclarationListAST *it = template_parameters; it; it = it->next) { - if (! it->next) - return it->lastToken(); - } + else if (template_parameters) + return template_parameters->lastToken(); - if (less_token) + else if (less_token) return less_token + 1; + else if (template_token) return template_token + 1; + else if (export_token) return export_token + 1; + // ### assert(0); return 0; } @@ -1506,12 +1503,10 @@ unsigned TemplateIdAST::lastToken() const if (greater_token) return greater_token + 1; - for (TemplateArgumentListAST *it = template_arguments; it; it = it->next) { - if (! it->next && it->value) - return it->value->lastToken(); - } + else if (template_arguments) + return template_arguments->lastToken(); - if (less_token) + else if (less_token) return less_token + 1; return identifier_token + 1; @@ -1527,21 +1522,23 @@ unsigned TemplateTypeParameterAST::lastToken() const { if (type_id) return type_id->lastToken(); + else if (equal_token) return equal_token + 1; + else if (name) return name->lastToken(); + else if (class_token) return class_token + 1; + else if (greater_token) return greater_token + 1; - for (DeclarationListAST *it = template_parameters; it; it = it->next) { - if (! it->next) - return it->value->lastToken(); - } + else if (template_parameters) + return template_parameters->lastToken(); - if (less_token) + else if (less_token) return less_token + 1; return template_token + 1; @@ -1571,7 +1568,6 @@ unsigned ThrowExpressionAST::lastToken() const return throw_token + 1; } - unsigned TranslationUnitAST::firstToken() const { return declarations->firstToken(); @@ -1579,14 +1575,13 @@ unsigned TranslationUnitAST::firstToken() const unsigned TranslationUnitAST::lastToken() const { - for (DeclarationListAST *it = declarations; it; it = it->next) { - if (! it->next) - return it->lastToken(); - } + if (declarations) + return declarations->lastToken(); + + // ### assert(0); return 0; } - unsigned TryBlockStatementAST::firstToken() const { return try_token; @@ -1674,13 +1669,12 @@ unsigned TypenameCallExpressionAST::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 (name) return name->lastToken(); @@ -1761,12 +1755,16 @@ unsigned WhileStatementAST::lastToken() const { if (statement) return statement->lastToken(); + else if (rparen_token) return rparen_token + 1; + else if (condition) return condition->lastToken(); + else if (lparen_token) return lparen_token + 1; + return while_token + 1; } @@ -1775,6 +1773,7 @@ unsigned ObjCClassForwardDeclarationAST::firstToken() const { if (attributes) return attributes->firstToken(); + return class_token; } @@ -1783,10 +1782,8 @@ unsigned ObjCClassForwardDeclarationAST::lastToken() const if (semicolon_token) return semicolon_token + 1; - for (ObjCIdentifierListAST *it = identifier_list; it; it = it->next) { - if (! it->next && it->value) - return it->value->lastToken(); - } + else if (identifier_list) + return identifier_list->lastToken(); return class_token + 1; } @@ -1795,6 +1792,7 @@ unsigned ObjCProtocolForwardDeclarationAST::firstToken() const { if (attributes) return attributes->firstToken(); + return protocol_token; } @@ -1803,10 +1801,8 @@ unsigned ObjCProtocolForwardDeclarationAST::lastToken() const if (semicolon_token) return semicolon_token + 1; - for (ObjCIdentifierListAST *it = identifier_list; it; it = it->next) { - if (! it->next && it->value) - return it->value->lastToken(); - } + else if (identifier_list) + return identifier_list->lastToken(); return protocol_token + 1; } @@ -1880,12 +1876,11 @@ unsigned ObjCProtocolRefsAST::firstToken() const unsigned ObjCProtocolRefsAST::lastToken() const { - if (greater_token) return greater_token + 1; + if (greater_token) + return greater_token + 1; - for (ObjCIdentifierListAST *it = identifier_list; it; it = it->next) { - if (! it->next && it->value) - return it->value->lastToken(); - } + else if (identifier_list) + return identifier_list->lastToken(); return less_token + 1; } diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h index c8cb6694af229a02a9d8dacea1c0c9e215b244c3..46718574d60257086c9f0c7406d04e11cdf8147f 100644 --- a/src/shared/cplusplus/AST.h +++ b/src/shared/cplusplus/AST.h @@ -81,15 +81,18 @@ public: unsigned lastToken() const { - unsigned token = 0; + _Tp lastValue = 0; for (const List *it = this; it; it = it->next) { if (it->value) - token = it->value->lastToken(); + lastValue = it->value; } - // assert(token != 0); - return token; + if (lastValue) + return lastValue->lastToken(); + + // ### assert(0); + return 0; } _Tp value; @@ -616,7 +619,7 @@ protected: class CPLUSPLUS_EXPORT ConditionAST: public ExpressionAST { public: - SpecifierListAST *type_specifier; + SpecifierListAST *type_specifiers; DeclaratorAST *declarator; public: diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp index 4e4ee1ffcaf9c5af32c85c2127474a592684fd51..c939a654f90c66e29c0909dc11d41a6bcb3151ac 100644 --- a/src/shared/cplusplus/ASTVisit.cpp +++ b/src/shared/cplusplus/ASTVisit.cpp @@ -50,8 +50,7 @@ void AttributeSpecifierAST::accept0(ASTVisitor *visitor) void AttributeAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (ExpressionListAST *it = expression_list; it; it = it->next) - accept(it, visitor); + accept(expression_list, visitor); } visitor->endVisit(this); } @@ -173,8 +172,7 @@ void CaseStatementAST::accept0(ASTVisitor *visitor) void CompoundStatementAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (StatementListAST *it = statements; it; it = it->next) - accept(it, visitor); + accept(statements, visitor); } visitor->endVisit(this); } @@ -182,7 +180,7 @@ void CompoundStatementAST::accept0(ASTVisitor *visitor) void ConditionAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - accept(type_specifier, visitor); + accept(type_specifiers, visitor); accept(declarator, visitor); } visitor->endVisit(this); @@ -320,8 +318,7 @@ void ExceptionDeclarationAST::accept0(ASTVisitor *visitor) void ExceptionSpecificationAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (ExpressionListAST *it = type_ids; it; it = it->next) - accept(it, visitor); + accept(type_ids, visitor); } visitor->endVisit(this); } @@ -390,8 +387,7 @@ void IfStatementAST::accept0(ASTVisitor *visitor) void ArrayInitializerAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (ExpressionListAST *it = expression_list; it; it = it->next) - accept(it, visitor); + accept(expression_list, visitor); } visitor->endVisit(this); } @@ -407,8 +403,7 @@ void LabeledStatementAST::accept0(ASTVisitor *visitor) void LinkageBodyAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (DeclarationListAST *it = declarations; it; it = it->next) - accept(it, visitor); + accept(declarations, visitor); } visitor->endVisit(this); } @@ -481,8 +476,7 @@ void DestructorNameAST::accept0(ASTVisitor *visitor) void TemplateIdAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (TemplateArgumentListAST *it = template_arguments; it; it = it->next) - accept(it, visitor); + accept(template_arguments, visitor); } visitor->endVisit(this); } @@ -507,8 +501,7 @@ void NamespaceAliasDefinitionAST::accept0(ASTVisitor *visitor) void NewPlacementAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (ExpressionListAST *it = expression_list; it; it = it->next) - accept(it, visitor); + accept(expression_list, visitor); } visitor->endVisit(this); } @@ -570,8 +563,7 @@ void ParameterDeclarationAST::accept0(ASTVisitor *visitor) void ParameterDeclarationClauseAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (DeclarationListAST *it = parameter_declarations; it; it = it->next) - accept(it, visitor); + accept(parameter_declarations, visitor); } visitor->endVisit(this); } @@ -579,8 +571,7 @@ void ParameterDeclarationClauseAST::accept0(ASTVisitor *visitor) void CallAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (ExpressionListAST *it = expression_list; it; it = it->next) - accept(it, visitor); + accept(expression_list, visitor); } visitor->endVisit(this); } @@ -620,8 +611,7 @@ void TypenameCallExpressionAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { accept(name, visitor); - for (ExpressionListAST *it = expression_list; it; it = it->next) - accept(it, visitor); + accept(expression_list, visitor); } visitor->endVisit(this); } @@ -753,8 +743,7 @@ void SwitchStatementAST::accept0(ASTVisitor *visitor) void TemplateDeclarationAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (DeclarationListAST *it = template_parameters; it; it = it->next) - accept(it, visitor); + accept(template_parameters, visitor); accept(declaration, visitor); } visitor->endVisit(this); @@ -771,8 +760,7 @@ void ThrowExpressionAST::accept0(ASTVisitor *visitor) void TranslationUnitAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (DeclarationListAST *it = declarations; it; it = it->next) - accept(it, visitor); + accept(declarations, visitor); } visitor->endVisit(this); } @@ -816,8 +804,7 @@ void TypenameTypeParameterAST::accept0(ASTVisitor *visitor) void TemplateTypeParameterAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (DeclarationListAST *it = template_parameters; it; it = it->next) - accept(it, visitor); + accept(template_parameters, visitor); accept(name, visitor); accept(type_id, visitor); } @@ -921,8 +908,7 @@ void ObjCMessageExpressionAST::accept0(ASTVisitor *visitor) if (visitor->visit(this)) { accept(receiver_expression, visitor); accept(selector, visitor); - for (ObjCMessageArgumentListAST *it = argument_list; it; it = it->next) - accept(it, visitor); + accept(argument_list, visitor); } visitor->endVisit(this); } @@ -967,8 +953,7 @@ void ObjCSelectorArgumentAST::accept0(ASTVisitor *visitor) void ObjCSelectorWithArgumentsAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (ObjCSelectorArgumentListAST *it = selector_arguments; it; it = it->next) - accept(it, visitor); + accept(selector_arguments, visitor); } visitor->endVisit(this); } @@ -984,8 +969,7 @@ void ObjCSelectorExpressionAST::accept0(ASTVisitor *visitor) void ObjCInstanceVariablesDeclarationAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (DeclarationListAST *it = instance_variables; it; it = it->next) - accept(it, visitor); + accept(instance_variables, visitor); } visitor->endVisit(this); } @@ -1054,8 +1038,7 @@ void ObjCSynthesizedPropertyAST::accept0(ASTVisitor *visitor) void ObjCSynthesizedPropertiesDeclarationAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (ObjCSynthesizedPropertyListAST *it = property_identifiers; it; it = it->next) - accept(it, visitor); + accept(property_identifiers, visitor); } visitor->endVisit(this); } @@ -1063,8 +1046,7 @@ void ObjCSynthesizedPropertiesDeclarationAST::accept0(ASTVisitor *visitor) void ObjCDynamicPropertiesDeclarationAST::accept0(ASTVisitor *visitor) { if (visitor->visit(this)) { - for (ObjCIdentifierListAST *it = property_identifiers; it; it = it->next) - accept(it, visitor); + accept(property_identifiers, visitor); } visitor->endVisit(this); } diff --git a/src/shared/cplusplus/CheckExpression.cpp b/src/shared/cplusplus/CheckExpression.cpp index 25de7e62c6dab21a7ab4da691675d141eca4fc1c..0e6fb0dfd63d03e8d55a2038d8229c3f011fb7c9 100644 --- a/src/shared/cplusplus/CheckExpression.cpp +++ b/src/shared/cplusplus/CheckExpression.cpp @@ -119,7 +119,7 @@ bool CheckExpression::visit(CastExpressionAST *ast) bool CheckExpression::visit(ConditionAST *ast) { - FullySpecifiedType typeSpecTy = semantic()->check(ast->type_specifier, _scope); + FullySpecifiedType typeSpecTy = semantic()->check(ast->type_specifiers, _scope); Name *name = 0; FullySpecifiedType declTy = semantic()->check(ast->declarator, typeSpecTy.qualifiedType(), _scope, &name); diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp index 5af2ae9a1c6112229efffd50a6d24d3e86c8cd76..7052567d0d4b7f8285ddf398bb256105ddc43bef 100644 --- a/src/shared/cplusplus/Parser.cpp +++ b/src/shared/cplusplus/Parser.cpp @@ -2274,7 +2274,7 @@ bool Parser::parseCondition(ExpressionAST *&node) if (parseInitDeclarator(declarator, /*acceptStructDeclarator=*/false)) { if (declarator->initializer) { ConditionAST *ast = new (_pool) ConditionAST; - ast->type_specifier = type_specifier; + ast->type_specifiers = type_specifier; ast->declarator = declarator; node = ast; blockErrors(blocked); diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp index b2e583a3d8059396e7269e9c3d156da4a18f9584..d5056d875f73b23092ad64c52382b3d151c9cc4b 100644 --- a/tests/auto/cplusplus/ast/tst_ast.cpp +++ b/tests/auto/cplusplus/ast/tst_ast.cpp @@ -396,10 +396,10 @@ void tst_AST::while_condition_statement() // check condition ConditionAST *condition = stmt->condition->asCondition(); QVERIFY(condition != 0); - QVERIFY(condition->type_specifier != 0); - QVERIFY(condition->type_specifier->value->asSimpleSpecifier() != 0); - QCOMPARE(condition->type_specifier->value->asSimpleSpecifier()->specifier_token, 3U); - QVERIFY(condition->type_specifier->next == 0); + QVERIFY(condition->type_specifiers != 0); + QVERIFY(condition->type_specifiers->value->asSimpleSpecifier() != 0); + QCOMPARE(condition->type_specifiers->value->asSimpleSpecifier()->specifier_token, 3U); + QVERIFY(condition->type_specifiers->next == 0); QVERIFY(condition->declarator != 0); QVERIFY(condition->declarator->core_declarator != 0); QVERIFY(condition->declarator->core_declarator->asDeclaratorId() != 0); diff --git a/tests/manual/cplusplus/main.cpp b/tests/manual/cplusplus/main.cpp index 63efc8b985bdcc51a14172339ed788dd890af84a..adc3c0c918bb6b9bbc4cec0d6342cc8c2aaa50ee 100644 --- a/tests/manual/cplusplus/main.cpp +++ b/tests/manual/cplusplus/main.cpp @@ -377,8 +377,9 @@ int main(int argc, char *argv[]) Namespace *globalNamespace = control.newNamespace(0, 0); Semantic sem(&control); - for (DeclarationListAST *decl = ast->declarations; decl; decl = decl->next) { - sem.check(decl->declaration, globalNamespace->members()); + for (DeclarationListAST *it = ast->declarations; it; it = it->next) { + DeclarationAST *declaration = it->value; + sem.check(declaration, globalNamespace->members()); } return EXIT_SUCCESS;