summaryrefslogtreecommitdiff
path: root/tests/manual/cplusplus/main.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-11-16 14:46:07 +0100
committerRoberto Raggi <roberto.raggi@nokia.com>2009-11-16 14:54:45 +0100
commitbc96850dedc605367a6d6e5cb730cee2f4491727 (patch)
treefc46eb8c0961958d1d937198fa8b23e8995bd205 /tests/manual/cplusplus/main.cpp
parentbef4ed8917ad7e9a762672841befa01e56752285 (diff)
downloadqt-creator-bc96850dedc605367a6d6e5cb730cee2f4491727.tar.gz
Introduced ASTPatternBuilder
Diffstat (limited to 'tests/manual/cplusplus/main.cpp')
-rw-r--r--tests/manual/cplusplus/main.cpp64
1 files changed, 6 insertions, 58 deletions
diff --git a/tests/manual/cplusplus/main.cpp b/tests/manual/cplusplus/main.cpp
index 7c5cc07533..ef4af02ab1 100644
--- a/tests/manual/cplusplus/main.cpp
+++ b/tests/manual/cplusplus/main.cpp
@@ -29,6 +29,7 @@
#include <AST.h>
#include <ASTVisitor.h>
+#include <ASTPatternBuilder.h>
#include <ASTMatcher.h>
#include <Control.h>
#include <Scope.h>
@@ -54,61 +55,6 @@
using namespace CPlusPlus;
-class PatternBuilder
-{
-public:
- PatternBuilder()
- : pool(new MemoryPool()) {}
-
- ~PatternBuilder()
- { delete pool; }
-
- UnaryExpressionAST *CreateUnaryExpression(ExpressionAST *expr = 0)
- {
- UnaryExpressionAST *ast = new (pool) UnaryExpressionAST;
- ast->expression = expr;
- return ast;
- }
-
- BinaryExpressionAST *CreateBinaryExpression(ExpressionAST *left = 0, ExpressionAST *right = 0)
- {
- BinaryExpressionAST *ast = new (pool) BinaryExpressionAST;
- ast->left_expression = left;
- ast->right_expression = right;
- return ast;
- }
-
- NumericLiteralAST *NumericLiteral()
- {
- NumericLiteralAST *ast = new (pool) NumericLiteralAST;
- return ast;
- }
-
- SimpleNameAST *SimpleName()
- {
- SimpleNameAST *ast = new (pool) SimpleNameAST;
- return ast;
- }
-
- IfStatementAST *IfStatement(ExpressionAST *cond = 0, StatementAST *iftrue = 0, StatementAST *iffalse = 0)
- {
- IfStatementAST *ast = new (pool) IfStatementAST;
- ast->condition = cond;
- ast->statement = iftrue;
- ast->else_statement = iffalse;
- return ast;
- }
-
- CompoundStatementAST *CompoundStatement()
- {
- CompoundStatementAST *ast = new (pool) CompoundStatementAST;
- return ast;
- }
-
-private:
- MemoryPool *pool;
-};
-
class ForEachNode: protected ASTVisitor
{
Document::Ptr doc;
@@ -126,10 +72,10 @@ protected:
virtual bool preVisit(AST *ast)
{
- PatternBuilder ir;
- //IfStatementAST *pattern = ir.IfStatement(ir.SimpleName());
+ ir.reset();
+ IfStatementAST *pattern = ir.IfStatement(ir.SimpleName());
- CompoundStatementAST *pattern = ir.CompoundStatement();
+ //CompoundStatementAST *pattern = ir.CompoundStatement();
if (ast->match(ast, pattern, &matcher))
translationUnit()->warning(ast->firstToken(), "matched");
@@ -137,6 +83,8 @@ protected:
return true;
}
+
+ ASTPatternBuilder ir;
ASTMatcher matcher;
};