summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-06-17 16:07:36 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2009-06-17 16:08:33 +0200
commita29864ef012d98ad6773ba4690704b731c79c7da (patch)
treee29ce5a361a603a9cd3af0c1eb0f3ea0c06ffa2b
parent609f4a437b746671f30fd091662e125c56d54979 (diff)
downloadqt-creator-a29864ef012d98ad6773ba4690704b731c79c7da.tar.gz
New generators for ASTVisit.cpp and ASTClone.cpp
-rw-r--r--tests/manual/cplusplus/main.cpp49
1 files changed, 44 insertions, 5 deletions
diff --git a/tests/manual/cplusplus/main.cpp b/tests/manual/cplusplus/main.cpp
index 10415d82ce..e704400ed6 100644
--- a/tests/manual/cplusplus/main.cpp
+++ b/tests/manual/cplusplus/main.cpp
@@ -196,8 +196,8 @@ protected:
if (ast->lbrace_token)
insertTextAfter(ast->lbrace_token, " Q_OBJECT\n");
- for (DeclarationAST *it = ast->member_specifiers; it; it = it->next) {
- accept(it);
+ for (DeclarationListAST *it = ast->member_specifiers; it; it = it->next) {
+ accept(it->declaration);
}
return false;
@@ -342,8 +342,40 @@ protected:
}
};
+class SearchListNodes: protected ASTVisitor
+{
+ QList<QByteArray> _listNodes;
+
+public:
+ SearchListNodes(Control *control)
+ : ASTVisitor(control)
+ { }
+
+ QList<QByteArray> operator()(AST *ast)
+ {
+ _listNodes.clear();
+ accept(ast);
+ return _listNodes;
+ }
+
+protected:
+ virtual bool visit(ClassSpecifierAST *ast)
+ {
+ for (unsigned i = 0; i < ast->symbol->memberCount(); ++i) {
+ Symbol *member = ast->symbol->memberAt(i);
+ if (! qstrcmp("next", member->name()->identifier()->chars())) {
+ _listNodes.append(ast->symbol->name()->identifier()->chars());
+ break;
+ }
+ }
+ return true;
+ }
+};
+
class VisitCG: protected ASTVisitor
{
+ QList<QByteArray> _listNodes;
+
public:
VisitCG(Control *control)
: ASTVisitor(control)
@@ -385,6 +417,9 @@ public:
"\n"
"CPLUSPLUS_BEGIN_NAMESPACE\n" << std::endl;
+ SearchListNodes listNodes(control());
+ _listNodes = listNodes(ast);
+
accept(ast);
std::cout << "CPLUSPLUS_END_NAMESPACE" << std::endl;
@@ -423,7 +458,11 @@ protected:
} else if (PointerType *ptrTy = member->type()->asPointerType()) {
if (NamedType *namedTy = ptrTy->elementType()->asNamedType()) {
QByteArray typeName = namedTy->name()->identifier()->chars();
- if (typeName.endsWith("AST")) {
+ if (_listNodes.contains(typeName) && memberName != "next") {
+ std::cout
+ << " for (" << typeName.constData() << " *it = " << memberName.constData() << "; it; it = it->next)" << std::endl
+ << " accept(it, visitor);" << std::endl;
+ } else if (typeName.endsWith("AST") && memberName != "next") {
std::cout << " accept(" << memberName.constData() << ", visitor);" << std::endl;
}
}
@@ -515,8 +554,8 @@ int main(int argc, char *argv[])
Scope globalScope;
Semantic sem(&control);
- for (DeclarationAST *decl = ast->declarations; decl; decl = decl->next) {
- sem.check(decl, &globalScope);
+ for (DeclarationListAST *decl = ast->declarations; decl; decl = decl->next) {
+ sem.check(decl->declaration, &globalScope);
}
// test the rewriter