From 36a0ea2bcbe306ef845549defb894f479b47a9a1 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Tue, 10 Nov 2009 11:23:35 +0100
Subject: [PATCH] Removed DeclarationListAST node.

Done with Erik Verbruggen
---
 src/libs/cplusplus/CheckUndefinedSymbols.cpp  |  2 +-
 src/libs/cplusplus/CppDocument.cpp            |  2 +-
 src/shared/cplusplus/AST.cpp                  | 17 +------------
 src/shared/cplusplus/AST.h                    | 16 -------------
 src/shared/cplusplus/ASTVisit.cpp             |  8 -------
 src/shared/cplusplus/ASTVisitor.h             |  3 ---
 src/shared/cplusplus/ASTfwd.h                 |  3 +--
 src/shared/cplusplus/CheckDeclaration.cpp     | 10 ++++----
 src/shared/cplusplus/CheckDeclarator.cpp      |  2 +-
 src/shared/cplusplus/CheckSpecifier.cpp       |  2 +-
 src/shared/cplusplus/Parser.cpp               | 24 +++++++++----------
 tests/auto/cplusplus/ast/tst_ast.cpp          |  6 ++---
 .../auto/cplusplus/semantic/tst_semantic.cpp  |  2 +-
 13 files changed, 27 insertions(+), 70 deletions(-)

diff --git a/src/libs/cplusplus/CheckUndefinedSymbols.cpp b/src/libs/cplusplus/CheckUndefinedSymbols.cpp
index 6262dcebaac..30a08ea884f 100644
--- a/src/libs/cplusplus/CheckUndefinedSymbols.cpp
+++ b/src/libs/cplusplus/CheckUndefinedSymbols.cpp
@@ -104,7 +104,7 @@ bool CheckUndefinedSymbols::isType(const QByteArray &name) const
         TemplateDeclarationAST *templateDeclaration = _templateDeclarationStack.at(i);
 
         for (DeclarationListAST *it = templateDeclaration->template_parameters; it; it = it->next) {
-            DeclarationAST *templateParameter = it->declaration;
+            DeclarationAST *templateParameter = it->value;
 
             if (templateParameterName(templateParameter) == name)
                 return true;
diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp
index b05525b8547..0a6b1f16355 100644
--- a/src/libs/cplusplus/CppDocument.cpp
+++ b/src/libs/cplusplus/CppDocument.cpp
@@ -414,7 +414,7 @@ void Document::check(CheckMode mode)
 
     if (TranslationUnitAST *ast = _translationUnit->ast()->asTranslationUnit()) {
         for (DeclarationListAST *decl = ast->declarations; decl; decl = decl->next) {
-            semantic.check(decl->declaration, globals);
+            semantic.check(decl->value, globals);
         }
     } else if (ExpressionAST *ast = _translationUnit->ast()->asExpression()) {
         semantic.check(ast, globals);
diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp
index 18357aee9d6..9cb2d1f7425 100644
--- a/src/shared/cplusplus/AST.cpp
+++ b/src/shared/cplusplus/AST.cpp
@@ -552,21 +552,6 @@ unsigned CtorInitializerAST::lastToken() const
     return colon_token + 1;
 }
 
-unsigned DeclarationListAST::firstToken() const
-{
-    return declaration->firstToken();
-}
-
-unsigned DeclarationListAST::lastToken() const
-{
-    for (const DeclarationListAST *it = this; it; it = it->next) {
-        if (! it->next)
-            return it->declaration->lastToken();
-    }
-
-    return 0;
-}
-
 unsigned DeclaratorAST::firstToken() const
 {
     if (attributes)
@@ -1642,7 +1627,7 @@ unsigned TemplateTypeParameterAST::lastToken() const
 
     for (DeclarationListAST *it = template_parameters; it; it = it->next) {
         if (! it->next)
-            return it->declaration->lastToken();
+            return it->value->lastToken();
     }
 
     if (less_token)
diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h
index e10ce1b57ae..3bc6f8e1746 100644
--- a/src/shared/cplusplus/AST.h
+++ b/src/shared/cplusplus/AST.h
@@ -362,22 +362,6 @@ public:
     virtual DeclarationAST *asDeclaration() { return this; }
 };
 
-class CPLUSPLUS_EXPORT DeclarationListAST: public AST
-{
-public:
-    DeclarationAST *declaration;
-    DeclarationListAST *next;
-
-public:
-    virtual DeclarationListAST *asDeclarationList() { return this; }
-
-    virtual unsigned firstToken() const;
-    virtual unsigned lastToken() const;
-
-protected:
-    virtual void accept0(ASTVisitor *visitor);
-};
-
 class CPLUSPLUS_EXPORT CoreDeclaratorAST: public AST
 {
 public:
diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp
index 7a9f9164d23..23578a006bb 100644
--- a/src/shared/cplusplus/ASTVisit.cpp
+++ b/src/shared/cplusplus/ASTVisit.cpp
@@ -65,14 +65,6 @@ void TypeofSpecifierAST::accept0(ASTVisitor *visitor)
     visitor->endVisit(this);
 }
 
-void DeclarationListAST::accept0(ASTVisitor *visitor)
-{
-    if (visitor->visit(this)) {
-        accept(declaration, visitor);
-    }
-    visitor->endVisit(this);
-}
-
 void DeclaratorAST::accept0(ASTVisitor *visitor)
 {
     if (visitor->visit(this)) {
diff --git a/src/shared/cplusplus/ASTVisitor.h b/src/shared/cplusplus/ASTVisitor.h
index a5281cb50d3..8ad6d640aa2 100644
--- a/src/shared/cplusplus/ASTVisitor.h
+++ b/src/shared/cplusplus/ASTVisitor.h
@@ -228,9 +228,6 @@ public:
     virtual bool visit(ObjCFastEnumerationAST *) { return true; }
     virtual bool visit(ObjCSynchronizedStatementAST *) { return true; }
 
-    virtual bool visit(DeclarationListAST *) { return true; }
-    virtual void endVisit(DeclarationListAST *) { }
-
     virtual void endVisit(AccessDeclarationAST *) { }
     virtual void endVisit(ArrayAccessAST *) { }
     virtual void endVisit(ArrayDeclaratorAST *) { }
diff --git a/src/shared/cplusplus/ASTfwd.h b/src/shared/cplusplus/ASTfwd.h
index 1e0cf11ae36..ccc08845c31 100644
--- a/src/shared/cplusplus/ASTfwd.h
+++ b/src/shared/cplusplus/ASTfwd.h
@@ -84,7 +84,6 @@ class CoreDeclaratorAST;
 class CppCastExpressionAST;
 class CtorInitializerAST;
 class DeclarationAST;
-class DeclarationListAST;
 class DeclarationStatementAST;
 class DeclaratorAST;
 class DeclaratorIdAST;
@@ -202,7 +201,7 @@ class UsingDirectiveAST;
 class WhileStatementAST;
 
 typedef List<ExpressionAST *> ExpressionListAST;
-
+typedef List<DeclarationAST *> DeclarationListAST;
 
 } // end of namespace CPlusPlus
 
diff --git a/src/shared/cplusplus/CheckDeclaration.cpp b/src/shared/cplusplus/CheckDeclaration.cpp
index 1e7afdd166d..eb82e6331f5 100644
--- a/src/shared/cplusplus/CheckDeclaration.cpp
+++ b/src/shared/cplusplus/CheckDeclaration.cpp
@@ -363,7 +363,7 @@ bool CheckDeclaration::visit(MemInitializerAST *ast)
 bool CheckDeclaration::visit(LinkageBodyAST *ast)
 {
     for (DeclarationListAST *decl = ast->declarations; decl; decl = decl->next) {
-       semantic()->check(decl->declaration, _scope);
+       semantic()->check(decl->value, _scope);
     }
     return false;
 }
@@ -428,7 +428,7 @@ bool CheckDeclaration::visit(TemplateDeclarationAST *ast)
     Scope *scope = new Scope(_scope->owner());
 
     for (DeclarationListAST *param = ast->template_parameters; param; param = param->next) {
-       semantic()->check(param->declaration, scope);
+       semantic()->check(param->value, scope);
     }
 
     semantic()->check(ast->declaration, _scope,
@@ -547,7 +547,7 @@ bool CheckDeclaration::visit(ObjCProtocolDeclarationAST *ast)
 
     int previousObjCVisibility = semantic()->switchObjCVisibility(Function::Public);
     for (DeclarationListAST *it = ast->member_declarations; it; it = it->next) {
-        semantic()->check(it->declaration, protocol->members());
+        semantic()->check(it->value, protocol->members());
     }
     (void) semantic()->switchObjCVisibility(previousObjCVisibility);
 
@@ -626,14 +626,14 @@ bool CheckDeclaration::visit(ObjCClassDeclarationAST *ast)
 
     if (ast->inst_vars_decl) {
         for (DeclarationListAST *it = ast->inst_vars_decl->instance_variables; it; it = it->next) {
-            semantic()->check(it->declaration, klass->members());
+            semantic()->check(it->value, klass->members());
         }
     }
 
     (void) semantic()->switchObjCVisibility(Function::Public);
 
     for (DeclarationListAST *it = ast->member_declarations; it; it = it->next) {
-        semantic()->check(it->declaration, klass->members());
+        semantic()->check(it->value, klass->members());
     }
 
     (void) semantic()->switchObjCVisibility(previousObjCVisibility);
diff --git a/src/shared/cplusplus/CheckDeclarator.cpp b/src/shared/cplusplus/CheckDeclarator.cpp
index b44c90f955c..6fd92458752 100644
--- a/src/shared/cplusplus/CheckDeclarator.cpp
+++ b/src/shared/cplusplus/CheckDeclarator.cpp
@@ -174,7 +174,7 @@ bool CheckDeclarator::visit(FunctionDeclaratorAST *ast)
     if (ast->parameters) {
         DeclarationListAST *parameter_declarations = ast->parameters->parameter_declarations;
         for (DeclarationListAST *decl = parameter_declarations; decl; decl = decl->next) {
-            semantic()->check(decl->declaration, fun->arguments());
+            semantic()->check(decl->value, fun->arguments());
         }
 
         if (ast->parameters->dot_dot_dot_token)
diff --git a/src/shared/cplusplus/CheckSpecifier.cpp b/src/shared/cplusplus/CheckSpecifier.cpp
index 6baef4682ed..8c70f153d52 100644
--- a/src/shared/cplusplus/CheckSpecifier.cpp
+++ b/src/shared/cplusplus/CheckSpecifier.cpp
@@ -347,7 +347,7 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast)
     int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod);
 
     for (DeclarationListAST *member = ast->member_specifiers; member; member = member->next) {
-        semantic()->check(member->declaration, klass->members());
+        semantic()->check(member->value, klass->members());
     }
 
     (void) semantic()->switchMethodKey(previousMethodKey);
diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index f86ee1a976d..76c374d93f5 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -435,7 +435,7 @@ bool Parser::parseTranslationUnit(TranslationUnitAST *&node)
 
         if (parseDeclaration(declaration)) {
             *decl = new (_pool) DeclarationListAST;
-            (*decl)->declaration = declaration;
+            (*decl)->value = declaration;
             decl = &(*decl)->next;
         } else {
             rewind(start_declaration + 1);
@@ -562,7 +562,7 @@ bool Parser::parseLinkageBody(DeclarationAST *&node)
             DeclarationAST *declaration = 0;
             if (parseDeclaration(declaration)) {
                 *declaration_ptr = new (_pool) DeclarationListAST;
-                (*declaration_ptr)->declaration = declaration;
+                (*declaration_ptr)->value = declaration;
                 declaration_ptr = &(*declaration_ptr)->next;
             } else {
                 rewind(start_declaration + 1);
@@ -1340,7 +1340,7 @@ bool Parser::parseTemplateParameterList(DeclarationListAST *&node)
     DeclarationAST *declaration = 0;
     if (parseTemplateParameter(declaration)) {
         *template_parameter_ptr = new (_pool) DeclarationListAST;
-        (*template_parameter_ptr)->declaration = declaration;
+        (*template_parameter_ptr)->value = declaration;
         template_parameter_ptr = &(*template_parameter_ptr)->next;
 
         while (LA() == T_COMMA) {
@@ -1349,7 +1349,7 @@ bool Parser::parseTemplateParameterList(DeclarationListAST *&node)
             declaration = 0;
             if (parseTemplateParameter(declaration)) {
                 *template_parameter_ptr = new (_pool) DeclarationListAST;
-                (*template_parameter_ptr)->declaration = declaration;
+                (*template_parameter_ptr)->value = declaration;
                 template_parameter_ptr = &(*template_parameter_ptr)->next;
             }
         }
@@ -1480,7 +1480,7 @@ bool Parser::parseParameterDeclarationList(DeclarationListAST *&node)
     DeclarationAST *declaration = 0;
     if (parseParameterDeclaration(declaration)) {
         *parameter_declaration_ptr = new (_pool) DeclarationListAST;
-        (*parameter_declaration_ptr)->declaration = declaration;
+        (*parameter_declaration_ptr)->value = declaration;
         parameter_declaration_ptr = &(*parameter_declaration_ptr)->next;
         while (LA() == T_COMMA) {
             consumeToken();
@@ -1491,7 +1491,7 @@ bool Parser::parseParameterDeclarationList(DeclarationListAST *&node)
             declaration = 0;
             if (parseParameterDeclaration(declaration)) {
                 *parameter_declaration_ptr = new (_pool) DeclarationListAST;
-                (*parameter_declaration_ptr)->declaration = declaration;
+                (*parameter_declaration_ptr)->value = declaration;
                 parameter_declaration_ptr = &(*parameter_declaration_ptr)->next;
             }
         }
@@ -1587,7 +1587,7 @@ bool Parser::parseClassSpecifier(SpecifierAST *&node)
             DeclarationAST *declaration = 0;
             if (parseMemberSpecification(declaration)) {
                 *declaration_ptr = new (_pool) DeclarationListAST;
-                (*declaration_ptr)->declaration = declaration;
+                (*declaration_ptr)->value = declaration;
                 declaration_ptr = &(*declaration_ptr)->next;
             } else {
                 rewind(start_declaration + 1);
@@ -4380,7 +4380,7 @@ bool Parser::parseObjCInterface(DeclarationAST *&node,
         DeclarationAST *declaration = 0;
         while (parseObjCInterfaceMemberDeclaration(declaration)) {
             *nextMembers = new (_pool) DeclarationListAST;
-            (*nextMembers)->declaration = declaration;
+            (*nextMembers)->value = declaration;
             nextMembers = &((*nextMembers)->next);
         }
 
@@ -4411,7 +4411,7 @@ bool Parser::parseObjCInterface(DeclarationAST *&node,
         DeclarationAST *declaration = 0;
         while (parseObjCInterfaceMemberDeclaration(declaration)) {
             *nextMembers = new (_pool) DeclarationListAST;
-            (*nextMembers)->declaration = declaration;
+            (*nextMembers)->value = declaration;
             nextMembers = &((*nextMembers)->next);
         }
 
@@ -4482,7 +4482,7 @@ bool Parser::parseObjCProtocol(DeclarationAST *&node,
         DeclarationAST *declaration = 0;
         while (parseObjCInterfaceMemberDeclaration(declaration)) {
             *nextMembers = new (_pool) DeclarationListAST;
-            (*nextMembers)->declaration = declaration;
+            (*nextMembers)->value = declaration;
             nextMembers = &((*nextMembers)->next);
         }
 
@@ -4650,7 +4650,7 @@ bool Parser::parseObjCMethodDefinitionList(DeclarationListAST *&node)
 
         if (declaration) {
             *next = new (_pool) DeclarationListAST;
-            (*next)->declaration = declaration;
+            (*next)->value = declaration;
             next = &((*next)->next);
         }
     }
@@ -4738,7 +4738,7 @@ bool Parser::parseObjClassInstanceVariables(ObjCInstanceVariablesDeclarationAST
         const unsigned start = cursor();
 
         *next = new (_pool) DeclarationListAST;
-        parseObjCInstanceVariableDeclaration((*next)->declaration);
+        parseObjCInstanceVariableDeclaration((*next)->value);
 
         if (start == cursor()) {
             // skip stray token.
diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp
index 24fbe7865fa..ea6d196889a 100644
--- a/tests/auto/cplusplus/ast/tst_ast.cpp
+++ b/tests/auto/cplusplus/ast/tst_ast.cpp
@@ -497,12 +497,12 @@ void tst_AST::cpp_initializer_or_function_declaration()
     QCOMPARE(param_clause->dot_dot_dot_token, 0U);
 
     // check the parameter
-    DeclarationListAST *declarations = param_clause->parameter_declarations->asDeclarationList();
+    DeclarationListAST *declarations = param_clause->parameter_declarations;
     QVERIFY(declarations);
-    QVERIFY(declarations->declaration);
+    QVERIFY(declarations->value);
     QVERIFY(! declarations->next);
 
-    ParameterDeclarationAST *param = declarations->declaration->asParameterDeclaration();
+    ParameterDeclarationAST *param = declarations->value->asParameterDeclaration();
     QVERIFY(param);
     QVERIFY(param->type_specifier != 0);
     QVERIFY(param->type_specifier->next == 0);
diff --git a/tests/auto/cplusplus/semantic/tst_semantic.cpp b/tests/auto/cplusplus/semantic/tst_semantic.cpp
index 6da954ae92f..3cacddb7952 100644
--- a/tests/auto/cplusplus/semantic/tst_semantic.cpp
+++ b/tests/auto/cplusplus/semantic/tst_semantic.cpp
@@ -59,7 +59,7 @@ public:
             TranslationUnitAST *ast = unit->ast()->asTranslationUnit();
             QVERIFY(ast);
             for (DeclarationListAST *decl = ast->declarations; decl; decl = decl->next) {
-                sem.check(decl->declaration, globals);
+                sem.check(decl->value, globals);
             }
         }
 
-- 
GitLab