From 77e7899e7ca3c4f426f53a2cd89e6924fd2d1646 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Tue, 10 Nov 2009 11:27:56 +0100
Subject: [PATCH] Removed StatementListAST

Done with Erik Verbruggen
---
 src/shared/cplusplus/AST.cpp            | 18 +-----------------
 src/shared/cplusplus/AST.h              | 16 ----------------
 src/shared/cplusplus/ASTVisit.cpp       |  8 --------
 src/shared/cplusplus/ASTVisitor.h       |  2 --
 src/shared/cplusplus/ASTfwd.h           |  2 +-
 src/shared/cplusplus/CheckStatement.cpp |  2 +-
 src/shared/cplusplus/Parser.cpp         |  2 +-
 tests/auto/cplusplus/ast/tst_ast.cpp    | 20 ++++++++++----------
 8 files changed, 14 insertions(+), 56 deletions(-)

diff --git a/src/shared/cplusplus/AST.cpp b/src/shared/cplusplus/AST.cpp
index 9cb2d1f7425..44d2b978ff9 100644
--- a/src/shared/cplusplus/AST.cpp
+++ b/src/shared/cplusplus/AST.cpp
@@ -401,22 +401,6 @@ unsigned ClassSpecifierAST::lastToken() const
     return classkey_token + 1;
 }
 
-
-unsigned StatementListAST::firstToken() const
-{
-    return statement->firstToken();
-}
-
-unsigned StatementListAST::lastToken() const
-{
-    for (const StatementListAST *it = this; it; it = it->next) {
-        if (! it->next)
-            return it->statement->lastToken();
-    }
-
-    return 0;
-}
-
 unsigned CompoundStatementAST::firstToken() const
 {
     return lbrace_token;
@@ -429,7 +413,7 @@ unsigned CompoundStatementAST::lastToken() const
 
     for (StatementListAST *it = statements; it; it = it->next) {
         if (! it->next)
-            return it->statement->lastToken();
+            return it->value->lastToken();
     }
 
     return lbrace_token + 1;
diff --git a/src/shared/cplusplus/AST.h b/src/shared/cplusplus/AST.h
index 3bc6f8e1746..a3686849b4e 100644
--- a/src/shared/cplusplus/AST.h
+++ b/src/shared/cplusplus/AST.h
@@ -607,22 +607,6 @@ protected:
     virtual void accept0(ASTVisitor *visitor);
 };
 
-class CPLUSPLUS_EXPORT StatementListAST: public AST
-{
-public:
-    StatementAST *statement;
-    StatementListAST *next;
-
-public:
-    virtual StatementListAST *asStatementList() { return this; }
-
-    virtual unsigned firstToken() const;
-    virtual unsigned lastToken() const;
-
-protected:
-    virtual void accept0(ASTVisitor *visitor);
-};
-
 class CPLUSPLUS_EXPORT CompoundStatementAST: public StatementAST
 {
 public:
diff --git a/src/shared/cplusplus/ASTVisit.cpp b/src/shared/cplusplus/ASTVisit.cpp
index 23578a006bb..f3239d356a8 100644
--- a/src/shared/cplusplus/ASTVisit.cpp
+++ b/src/shared/cplusplus/ASTVisit.cpp
@@ -180,14 +180,6 @@ void CaseStatementAST::accept0(ASTVisitor *visitor)
     visitor->endVisit(this);
 }
 
-void StatementListAST::accept0(ASTVisitor *visitor)
-{
-    if (visitor->visit(this)) {
-        accept(statement, visitor);
-    }
-    visitor->endVisit(this);
-}
-
 void CompoundStatementAST::accept0(ASTVisitor *visitor)
 {
     if (visitor->visit(this)) {
diff --git a/src/shared/cplusplus/ASTVisitor.h b/src/shared/cplusplus/ASTVisitor.h
index 8ad6d640aa2..41fcc38151a 100644
--- a/src/shared/cplusplus/ASTVisitor.h
+++ b/src/shared/cplusplus/ASTVisitor.h
@@ -171,7 +171,6 @@ public:
     virtual bool visit(SimpleNameAST *) { return true; }
     virtual bool visit(SimpleSpecifierAST *) { return true; }
     virtual bool visit(SizeofExpressionAST *) { return true; }
-    virtual bool visit(StatementListAST *) { return true; }
     virtual bool visit(StringLiteralAST *) { return true; }
     virtual bool visit(SwitchStatementAST *) { return true; }
     virtual bool visit(TemplateArgumentListAST *) { return true; }
@@ -305,7 +304,6 @@ public:
     virtual void endVisit(SimpleNameAST *) { }
     virtual void endVisit(SimpleSpecifierAST *) { }
     virtual void endVisit(SizeofExpressionAST *) { }
-    virtual void endVisit(StatementListAST *) { }
     virtual void endVisit(StringLiteralAST *) { }
     virtual void endVisit(SwitchStatementAST *) { }
     virtual void endVisit(TemplateArgumentListAST *) { }
diff --git a/src/shared/cplusplus/ASTfwd.h b/src/shared/cplusplus/ASTfwd.h
index ccc08845c31..61d7cc1aac7 100644
--- a/src/shared/cplusplus/ASTfwd.h
+++ b/src/shared/cplusplus/ASTfwd.h
@@ -178,7 +178,6 @@ class SimpleSpecifierAST;
 class SizeofExpressionAST;
 class SpecifierAST;
 class StatementAST;
-class StatementListAST;
 class StringLiteralAST;
 class SwitchStatementAST;
 class TemplateArgumentListAST;
@@ -202,6 +201,7 @@ class WhileStatementAST;
 
 typedef List<ExpressionAST *> ExpressionListAST;
 typedef List<DeclarationAST *> DeclarationListAST;
+typedef List<StatementAST *> StatementListAST;
 
 } // end of namespace CPlusPlus
 
diff --git a/src/shared/cplusplus/CheckStatement.cpp b/src/shared/cplusplus/CheckStatement.cpp
index 79a4e2e33d7..f2edeae338a 100644
--- a/src/shared/cplusplus/CheckStatement.cpp
+++ b/src/shared/cplusplus/CheckStatement.cpp
@@ -105,7 +105,7 @@ bool CheckStatement::visit(CompoundStatementAST *ast)
     _scope->enterSymbol(block);
     Scope *previousScope = switchScope(block->members());
     for (StatementListAST *it = ast->statements; it; it = it->next) {
-        semantic()->check(it->statement, _scope);
+        semantic()->check(it->value, _scope);
     }
     (void) switchScope(previousScope);
     return false;
diff --git a/src/shared/cplusplus/Parser.cpp b/src/shared/cplusplus/Parser.cpp
index 76c374d93f5..1f121631a93 100644
--- a/src/shared/cplusplus/Parser.cpp
+++ b/src/shared/cplusplus/Parser.cpp
@@ -2439,7 +2439,7 @@ bool Parser::parseCompoundStatement(StatementAST *&node)
                 skipUntilStatement();
             } else {
                 *statement_ptr = new (_pool) StatementListAST;
-                (*statement_ptr)->statement = statement;
+                (*statement_ptr)->value = statement;
                 statement_ptr = &(*statement_ptr)->next;
             }
         }
diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp
index ea6d196889a..43b2cb409f7 100644
--- a/tests/auto/cplusplus/ast/tst_ast.cpp
+++ b/tests/auto/cplusplus/ast/tst_ast.cpp
@@ -557,8 +557,8 @@ void tst_AST::normal_array_access()
     QVERIFY(bodyStatements);
     QVERIFY(bodyStatements->next);
     QVERIFY(bodyStatements->next->next);
-    QVERIFY(bodyStatements->next->next->statement);
-    ExpressionAST *expr = bodyStatements->next->next->statement->asReturnStatement()->expression;
+    QVERIFY(bodyStatements->next->next->value);
+    ExpressionAST *expr = bodyStatements->next->next->value->asReturnStatement()->expression;
     QVERIFY(expr);
 
     PostfixExpressionAST *postfixExpr = expr->asPostfixExpression();
@@ -598,8 +598,8 @@ void tst_AST::array_access_with_nested_expression()
     QVERIFY(func);
 
     StatementListAST *bodyStatements = func->function_body->asCompoundStatement()->statements;
-    QVERIFY(bodyStatements && bodyStatements->next && bodyStatements->next->next && bodyStatements->next->next->statement);
-    ExpressionAST *expr = bodyStatements->next->next->statement->asReturnStatement()->expression;
+    QVERIFY(bodyStatements && bodyStatements->next && bodyStatements->next->next && bodyStatements->next->next->value);
+    ExpressionAST *expr = bodyStatements->next->next->value->asReturnStatement()->expression;
     QVERIFY(expr);
 
     CastExpressionAST *castExpr = expr->asCastExpression();
@@ -643,10 +643,10 @@ void tst_AST::objc_msg_send_expression()
     QVERIFY(func);
 
     StatementListAST *bodyStatements = func->function_body->asCompoundStatement()->statements;
-    QVERIFY(bodyStatements && bodyStatements->next && !bodyStatements->next->next && bodyStatements->next->statement);
+    QVERIFY(bodyStatements && bodyStatements->next && !bodyStatements->next->next && bodyStatements->next->value);
 
     {// check the NSObject declaration
-        DeclarationStatementAST *firstStatement = bodyStatements->statement->asDeclarationStatement();
+        DeclarationStatementAST *firstStatement = bodyStatements->value->asDeclarationStatement();
         QVERIFY(firstStatement);
         DeclarationAST *objDecl = firstStatement->declaration;
         QVERIFY(objDecl);
@@ -692,7 +692,7 @@ void tst_AST::objc_msg_send_expression()
     }
 
     {// check the return statement
-        ExpressionAST *expr = bodyStatements->next->statement->asReturnStatement()->expression;
+        ExpressionAST *expr = bodyStatements->next->value->asReturnStatement()->expression;
         QVERIFY(expr);
 
         ObjCMessageExpressionAST *msgExpr = expr->asObjCMessageExpression();
@@ -729,9 +729,9 @@ void tst_AST::objc_msg_send_expression_without_selector()
 
     StatementListAST *bodyStatements = func->function_body->asCompoundStatement()->statements;
     QVERIFY(bodyStatements && bodyStatements->next);
-    QVERIFY(bodyStatements->next->statement);
-    QVERIFY(bodyStatements->next->statement->asReturnStatement());
-    QVERIFY(!bodyStatements->next->statement->asReturnStatement()->expression);
+    QVERIFY(bodyStatements->next->value);
+    QVERIFY(bodyStatements->next->value->asReturnStatement());
+    QVERIFY(!bodyStatements->next->value->asReturnStatement()->expression);
 }
 
 QTEST_APPLESS_MAIN(tst_AST)
-- 
GitLab