diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-07-30 01:16:09 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-07-30 01:16:09 (GMT) |
commit | 580d706fc6db98ebdbd065d244c739d6b72e4a0f (patch) | |
tree | 9e8d9d2ea7c0229a2b53c069e44dcbefe6ae4f2a /src | |
parent | 674291cc996a10210321b64ea80cf20d0cc678d4 (diff) | |
parent | 8b168b8f969c1eafaeb0276a3c81b58a388f93d2 (diff) | |
download | Qt-580d706fc6db98ebdbd065d244c739d6b72e4a0f.zip Qt-580d706fc6db98ebdbd065d244c739d6b72e4a0f.tar.gz Qt-580d706fc6db98ebdbd065d244c739d6b72e4a0f.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/parser/parser.pri | 4 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljsast.cpp | 281 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljsast_p.h | 16 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljsprettypretty.cpp | 1334 | ||||
-rw-r--r-- | src/declarative/qml/parser/qmljsprettypretty_p.h | 329 |
5 files changed, 143 insertions, 1821 deletions
diff --git a/src/declarative/qml/parser/parser.pri b/src/declarative/qml/parser/parser.pri index 1ea249a..1f553f6 100644 --- a/src/declarative/qml/parser/parser.pri +++ b/src/declarative/qml/parser/parser.pri @@ -10,14 +10,12 @@ HEADERS += $$PWD/qmljsast_p.h \ $$PWD/qmljslexer_p.h \ $$PWD/qmljsmemorypool_p.h \ $$PWD/qmljsnodepool_p.h \ - $$PWD/qmljsparser_p.h \ - $$PWD/qmljsprettypretty_p.h + $$PWD/qmljsparser_p.h SOURCES += $$PWD/qmljsast.cpp \ $$PWD/qmljsastvisitor.cpp \ $$PWD/qmljsengine_p.cpp \ $$PWD/qmljsgrammar.cpp \ $$PWD/qmljslexer.cpp \ - $$PWD/qmljsprettypretty.cpp \ $$PWD/qmljsparser.cpp diff --git a/src/declarative/qml/parser/qmljsast.cpp b/src/declarative/qml/parser/qmljsast.cpp index 1d7f09e..caf81e5 100644 --- a/src/declarative/qml/parser/qmljsast.cpp +++ b/src/declarative/qml/parser/qmljsast.cpp @@ -40,15 +40,26 @@ ****************************************************************************/ #include "qmljsast_p.h" - - - #include "qmljsastvisitor_p.h" QT_BEGIN_NAMESPACE namespace QmlJS { namespace AST { +void Node::accept(Visitor *visitor) +{ + if (visitor->preVisit(this)) { + accept0(visitor); + } + visitor->postVisit(this); +} + +void Node::accept(Node *node, Visitor *visitor) +{ + if (node) + node->accept(visitor); +} + ExpressionNode *Node::expressionCast() { return 0; @@ -82,7 +93,7 @@ Statement *Statement::statementCast() void NestedExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); } @@ -154,8 +165,8 @@ void RegExpLiteral::accept0(Visitor *visitor) void ArrayLiteral::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(elements, visitor); - acceptChild(elision, visitor); + accept(elements, visitor); + accept(elision, visitor); } visitor->endVisit(this); @@ -164,7 +175,7 @@ void ArrayLiteral::accept0(Visitor *visitor) void ObjectLiteral::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(properties, visitor); + accept(properties, visitor); } visitor->endVisit(this); @@ -173,12 +184,10 @@ void ObjectLiteral::accept0(Visitor *visitor) void ElementList::accept0(Visitor *visitor) { if (visitor->visit(this)) { - ElementList *it = this; - do { - acceptChild(it->elision, visitor); - acceptChild(it->expression, visitor); - it = it->next; - } while (it); + for (ElementList *it = this; it; it = it->next) { + accept(it->elision, visitor); + accept(it->expression, visitor); + } } visitor->endVisit(this); @@ -196,12 +205,10 @@ void Elision::accept0(Visitor *visitor) void PropertyNameAndValueList::accept0(Visitor *visitor) { if (visitor->visit(this)) { - PropertyNameAndValueList *it = this; - do { - acceptChild(it->name, visitor); - acceptChild(it->value, visitor); - it = it->next; - } while (it); + for (PropertyNameAndValueList *it = this; it; it = it->next) { + accept(it->name, visitor); + accept(it->value, visitor); + } } visitor->endVisit(this); @@ -234,8 +241,8 @@ void NumericLiteralPropertyName::accept0(Visitor *visitor) void ArrayMemberExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(base, visitor); - acceptChild(expression, visitor); + accept(base, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -244,7 +251,7 @@ void ArrayMemberExpression::accept0(Visitor *visitor) void FieldMemberExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(base, visitor); + accept(base, visitor); } visitor->endVisit(this); @@ -253,8 +260,8 @@ void FieldMemberExpression::accept0(Visitor *visitor) void NewMemberExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(base, visitor); - acceptChild(arguments, visitor); + accept(base, visitor); + accept(arguments, visitor); } visitor->endVisit(this); @@ -263,7 +270,7 @@ void NewMemberExpression::accept0(Visitor *visitor) void NewExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -272,8 +279,8 @@ void NewExpression::accept0(Visitor *visitor) void CallExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(base, visitor); - acceptChild(arguments, visitor); + accept(base, visitor); + accept(arguments, visitor); } visitor->endVisit(this); @@ -282,11 +289,9 @@ void CallExpression::accept0(Visitor *visitor) void ArgumentList::accept0(Visitor *visitor) { if (visitor->visit(this)) { - ArgumentList *it = this; - do { - acceptChild(it->expression, visitor); - it = it->next; - } while (it); + for (ArgumentList *it = this; it; it = it->next) { + accept(it->expression, visitor); + } } visitor->endVisit(this); @@ -295,7 +300,7 @@ void ArgumentList::accept0(Visitor *visitor) void PostIncrementExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(base, visitor); + accept(base, visitor); } visitor->endVisit(this); @@ -304,7 +309,7 @@ void PostIncrementExpression::accept0(Visitor *visitor) void PostDecrementExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(base, visitor); + accept(base, visitor); } visitor->endVisit(this); @@ -313,7 +318,7 @@ void PostDecrementExpression::accept0(Visitor *visitor) void DeleteExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -322,7 +327,7 @@ void DeleteExpression::accept0(Visitor *visitor) void VoidExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -331,7 +336,7 @@ void VoidExpression::accept0(Visitor *visitor) void TypeOfExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -340,7 +345,7 @@ void TypeOfExpression::accept0(Visitor *visitor) void PreIncrementExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -349,7 +354,7 @@ void PreIncrementExpression::accept0(Visitor *visitor) void PreDecrementExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -358,7 +363,7 @@ void PreDecrementExpression::accept0(Visitor *visitor) void UnaryPlusExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -367,7 +372,7 @@ void UnaryPlusExpression::accept0(Visitor *visitor) void UnaryMinusExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -376,7 +381,7 @@ void UnaryMinusExpression::accept0(Visitor *visitor) void TildeExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -385,7 +390,7 @@ void TildeExpression::accept0(Visitor *visitor) void NotExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -394,8 +399,8 @@ void NotExpression::accept0(Visitor *visitor) void BinaryExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(left, visitor); - acceptChild(right, visitor); + accept(left, visitor); + accept(right, visitor); } visitor->endVisit(this); @@ -404,9 +409,9 @@ void BinaryExpression::accept0(Visitor *visitor) void ConditionalExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); - acceptChild(ok, visitor); - acceptChild(ko, visitor); + accept(expression, visitor); + accept(ok, visitor); + accept(ko, visitor); } visitor->endVisit(this); @@ -415,8 +420,8 @@ void ConditionalExpression::accept0(Visitor *visitor) void Expression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(left, visitor); - acceptChild(right, visitor); + accept(left, visitor); + accept(right, visitor); } visitor->endVisit(this); @@ -425,7 +430,7 @@ void Expression::accept0(Visitor *visitor) void Block::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(statements, visitor); + accept(statements, visitor); } visitor->endVisit(this); @@ -434,11 +439,9 @@ void Block::accept0(Visitor *visitor) void StatementList::accept0(Visitor *visitor) { if (visitor->visit(this)) { - StatementList *it = this; - do { - acceptChild(it->statement, visitor); - it = it->next; - } while (it); + for (StatementList *it = this; it; it = it->next) { + accept(it->statement, visitor); + } } visitor->endVisit(this); @@ -447,7 +450,7 @@ void StatementList::accept0(Visitor *visitor) void VariableStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(declarations, visitor); + accept(declarations, visitor); } visitor->endVisit(this); @@ -456,11 +459,9 @@ void VariableStatement::accept0(Visitor *visitor) void VariableDeclarationList::accept0(Visitor *visitor) { if (visitor->visit(this)) { - VariableDeclarationList *it = this; - do { - acceptChild(it->declaration, visitor); - it = it->next; - } while (it); + for (VariableDeclarationList *it = this; it; it = it->next) { + accept(it->declaration, visitor); + } } visitor->endVisit(this); @@ -469,7 +470,7 @@ void VariableDeclarationList::accept0(Visitor *visitor) void VariableDeclaration::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -486,7 +487,7 @@ void EmptyStatement::accept0(Visitor *visitor) void ExpressionStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -495,9 +496,9 @@ void ExpressionStatement::accept0(Visitor *visitor) void IfStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); - acceptChild(ok, visitor); - acceptChild(ko, visitor); + accept(expression, visitor); + accept(ok, visitor); + accept(ko, visitor); } visitor->endVisit(this); @@ -506,8 +507,8 @@ void IfStatement::accept0(Visitor *visitor) void DoWhileStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(statement, visitor); - acceptChild(expression, visitor); + accept(statement, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -516,8 +517,8 @@ void DoWhileStatement::accept0(Visitor *visitor) void WhileStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); - acceptChild(statement, visitor); + accept(expression, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -526,10 +527,10 @@ void WhileStatement::accept0(Visitor *visitor) void ForStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(initialiser, visitor); - acceptChild(condition, visitor); - acceptChild(expression, visitor); - acceptChild(statement, visitor); + accept(initialiser, visitor); + accept(condition, visitor); + accept(expression, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -538,10 +539,10 @@ void ForStatement::accept0(Visitor *visitor) void LocalForStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(declarations, visitor); - acceptChild(condition, visitor); - acceptChild(expression, visitor); - acceptChild(statement, visitor); + accept(declarations, visitor); + accept(condition, visitor); + accept(expression, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -550,9 +551,9 @@ void LocalForStatement::accept0(Visitor *visitor) void ForEachStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(initialiser, visitor); - acceptChild(expression, visitor); - acceptChild(statement, visitor); + accept(initialiser, visitor); + accept(expression, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -561,9 +562,9 @@ void ForEachStatement::accept0(Visitor *visitor) void LocalForEachStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(declaration, visitor); - acceptChild(expression, visitor); - acceptChild(statement, visitor); + accept(declaration, visitor); + accept(expression, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -588,7 +589,7 @@ void BreakStatement::accept0(Visitor *visitor) void ReturnStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -597,8 +598,8 @@ void ReturnStatement::accept0(Visitor *visitor) void WithStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); - acceptChild(statement, visitor); + accept(expression, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -607,8 +608,8 @@ void WithStatement::accept0(Visitor *visitor) void SwitchStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); - acceptChild(block, visitor); + accept(expression, visitor); + accept(block, visitor); } visitor->endVisit(this); @@ -617,9 +618,9 @@ void SwitchStatement::accept0(Visitor *visitor) void CaseBlock::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(clauses, visitor); - acceptChild(defaultClause, visitor); - acceptChild(moreClauses, visitor); + accept(clauses, visitor); + accept(defaultClause, visitor); + accept(moreClauses, visitor); } visitor->endVisit(this); @@ -628,11 +629,9 @@ void CaseBlock::accept0(Visitor *visitor) void CaseClauses::accept0(Visitor *visitor) { if (visitor->visit(this)) { - CaseClauses *it = this; - do { - acceptChild(it->clause, visitor); - it = it->next; - } while (it); + for (CaseClauses *it = this; it; it = it->next) { + accept(it->clause, visitor); + } } visitor->endVisit(this); @@ -641,8 +640,8 @@ void CaseClauses::accept0(Visitor *visitor) void CaseClause::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); - acceptChild(statements, visitor); + accept(expression, visitor); + accept(statements, visitor); } visitor->endVisit(this); @@ -651,7 +650,7 @@ void CaseClause::accept0(Visitor *visitor) void DefaultClause::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(statements, visitor); + accept(statements, visitor); } visitor->endVisit(this); @@ -660,7 +659,7 @@ void DefaultClause::accept0(Visitor *visitor) void LabelledStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(statement, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -669,7 +668,7 @@ void LabelledStatement::accept0(Visitor *visitor) void ThrowStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -678,9 +677,9 @@ void ThrowStatement::accept0(Visitor *visitor) void TryStatement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(statement, visitor); - acceptChild(catchExpression, visitor); - acceptChild(finallyExpression, visitor); + accept(statement, visitor); + accept(catchExpression, visitor); + accept(finallyExpression, visitor); } visitor->endVisit(this); @@ -689,7 +688,7 @@ void TryStatement::accept0(Visitor *visitor) void Catch::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(statement, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -698,7 +697,7 @@ void Catch::accept0(Visitor *visitor) void Finally::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(statement, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -707,8 +706,8 @@ void Finally::accept0(Visitor *visitor) void FunctionDeclaration::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(formals, visitor); - acceptChild(body, visitor); + accept(formals, visitor); + accept(body, visitor); } visitor->endVisit(this); @@ -717,8 +716,8 @@ void FunctionDeclaration::accept0(Visitor *visitor) void FunctionExpression::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(formals, visitor); - acceptChild(body, visitor); + accept(formals, visitor); + accept(body, visitor); } visitor->endVisit(this); @@ -736,7 +735,7 @@ void FormalParameterList::accept0(Visitor *visitor) void FunctionBody::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(elements, visitor); + accept(elements, visitor); } visitor->endVisit(this); @@ -745,7 +744,7 @@ void FunctionBody::accept0(Visitor *visitor) void Program::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(elements, visitor); + accept(elements, visitor); } visitor->endVisit(this); @@ -754,11 +753,9 @@ void Program::accept0(Visitor *visitor) void SourceElements::accept0(Visitor *visitor) { if (visitor->visit(this)) { - SourceElements *it = this; - do { - acceptChild(it->element, visitor); - it = it->next; - } while (it); + for (SourceElements *it = this; it; it = it->next) { + accept(it->element, visitor); + } } visitor->endVisit(this); @@ -767,7 +764,7 @@ void SourceElements::accept0(Visitor *visitor) void FunctionSourceElement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(declaration, visitor); + accept(declaration, visitor); } visitor->endVisit(this); @@ -776,7 +773,7 @@ void FunctionSourceElement::accept0(Visitor *visitor) void StatementSourceElement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(statement, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -794,8 +791,7 @@ void DebuggerStatement::accept0(Visitor *visitor) void UiProgram::accept0(Visitor *visitor) { if (visitor->visit(this)) { - for (UiObjectMemberList *it = members; it; it = it->next) - acceptChild(it->member, visitor); + accept(imports, visitor); } visitor->endVisit(this); @@ -804,7 +800,7 @@ void UiProgram::accept0(Visitor *visitor) void UiSignature::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(formals, visitor); + accept(formals, visitor); } visitor->endVisit(this); } @@ -813,7 +809,7 @@ void UiFormalList::accept0(Visitor *visitor) { if (visitor->visit(this)) { for (UiFormalList *it = this; it; it = it->next) { - acceptChild(it->formal, visitor); + accept(it->formal, visitor); } } visitor->endVisit(this); @@ -829,7 +825,7 @@ void UiFormal::accept0(Visitor *visitor) void UiPublicMember::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(expression, visitor); + accept(expression, visitor); } visitor->endVisit(this); @@ -838,8 +834,8 @@ void UiPublicMember::accept0(Visitor *visitor) void UiObjectDefinition::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(qualifiedTypeNameId, visitor); - acceptChild(initializer, visitor); + accept(qualifiedTypeNameId, visitor); + accept(initializer, visitor); } visitor->endVisit(this); @@ -848,8 +844,7 @@ void UiObjectDefinition::accept0(Visitor *visitor) void UiObjectInitializer::accept0(Visitor *visitor) { if (visitor->visit(this)) { - for (UiObjectMemberList *it = members; it; it = it->next) - acceptChild(it->member, visitor); + accept(members, visitor); } visitor->endVisit(this); @@ -858,9 +853,9 @@ void UiObjectInitializer::accept0(Visitor *visitor) void UiObjectBinding::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(qualifiedId, visitor); - acceptChild(qualifiedTypeNameId, visitor); - acceptChild(initializer, visitor); + accept(qualifiedId, visitor); + accept(qualifiedTypeNameId, visitor); + accept(initializer, visitor); } visitor->endVisit(this); @@ -869,8 +864,8 @@ void UiObjectBinding::accept0(Visitor *visitor) void UiScriptBinding::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(qualifiedId, visitor); - acceptChild(statement, visitor); + accept(qualifiedId, visitor); + accept(statement, visitor); } visitor->endVisit(this); @@ -879,9 +874,8 @@ void UiScriptBinding::accept0(Visitor *visitor) void UiArrayBinding::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(qualifiedId, visitor); - for (UiArrayMemberList *it = members; it; it = it->next) - acceptChild(it->member, visitor); + accept(qualifiedId, visitor); + accept(members, visitor); } visitor->endVisit(this); @@ -891,7 +885,7 @@ void UiObjectMemberList::accept0(Visitor *visitor) { if (visitor->visit(this)) { for (UiObjectMemberList *it = this; it; it = it->next) - acceptChild(it->member, visitor); + accept(it->member, visitor); } visitor->endVisit(this); @@ -901,7 +895,7 @@ void UiArrayMemberList::accept0(Visitor *visitor) { if (visitor->visit(this)) { for (UiArrayMemberList *it = this; it; it = it->next) - acceptChild(it->member, visitor); + accept(it->member, visitor); } visitor->endVisit(this); @@ -918,6 +912,7 @@ void UiQualifiedId::accept0(Visitor *visitor) void UiImport::accept0(Visitor *visitor) { if (visitor->visit(this)) { + accept(importUri, visitor); } visitor->endVisit(this); @@ -926,8 +921,8 @@ void UiImport::accept0(Visitor *visitor) void UiImportList::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(import, visitor); - acceptChild(next, visitor); + accept(import, visitor); + accept(next, visitor); } visitor->endVisit(this); @@ -936,7 +931,7 @@ void UiImportList::accept0(Visitor *visitor) void UiSourceElement::accept0(Visitor *visitor) { if (visitor->visit(this)) { - acceptChild(sourceElement, visitor); + accept(sourceElement, visitor); } visitor->endVisit(this); diff --git a/src/declarative/qml/parser/qmljsast_p.h b/src/declarative/qml/parser/qmljsast_p.h index ee2f472..3967742 100644 --- a/src/declarative/qml/parser/qmljsast_p.h +++ b/src/declarative/qml/parser/qmljsast_p.h @@ -228,19 +228,11 @@ public: virtual BinaryExpression *binaryExpressionCast(); virtual Statement *statementCast(); - inline void accept(Visitor *visitor) - { - if (visitor->preVisit(this)) { - accept0(visitor); - visitor->postVisit(this); - } - } + void accept(Visitor *visitor); + static void accept(Node *node, Visitor *visitor); - static void acceptChild(Node *node, Visitor *visitor) - { - if (node) - node->accept(visitor); - } + inline static void acceptChild(Node *node, Visitor *visitor) + { return accept(node, visitor); } // ### remove virtual void accept0(Visitor *visitor) = 0; diff --git a/src/declarative/qml/parser/qmljsprettypretty.cpp b/src/declarative/qml/parser/qmljsprettypretty.cpp deleted file mode 100644 index b6733e5..0000000 --- a/src/declarative/qml/parser/qmljsprettypretty.cpp +++ /dev/null @@ -1,1334 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmljsprettypretty_p.h" - - - -#include "qmljsengine_p.h" - - - - -#include "qmljsast_p.h" - -#include <QtCore/QString> -#include <QtCore/QTextStream> -#include <QtCore/QtDebug> - -QT_BEGIN_NAMESPACE - -namespace QmlJS { -QString numberToString(double value); -} - -using namespace QmlJS; - -PrettyPretty::PrettyPretty(QTextStream &o): - out(o), m_indentLevel(0) -{ -} - -PrettyPretty::~PrettyPretty() -{ -} - -void PrettyPretty::acceptAsBlock(AST::Node *node) -{ - out << "{"; - pushIndentLevel(); - newlineAndIndent(); - accept(node); - popIndentLevel(); - newlineAndIndent(); - out << "}"; -} - -int PrettyPretty::operatorPrecedenceLevel(int op) -{ - switch (op) { - case QSOperator::Div: - case QSOperator::Mod: - case QSOperator::Mul: - return 5; - case QSOperator::Add: - case QSOperator::Sub: - return 6; - case QSOperator::LShift: - case QSOperator::RShift: - case QSOperator::URShift: - return 7; - case QSOperator::Ge: - case QSOperator::Gt: - case QSOperator::In: - case QSOperator::InstanceOf: - case QSOperator::Le: - case QSOperator::Lt: - return 8; - case QSOperator::Equal: - case QSOperator::NotEqual: - case QSOperator::StrictEqual: - case QSOperator::StrictNotEqual: - return 9; - case QSOperator::BitAnd: - return 10; - case QSOperator::BitXor: - return 11; - case QSOperator::BitOr: - return 12; - case QSOperator::And: - return 13; - case QSOperator::Or: - return 14; - case QSOperator::InplaceAnd: - case QSOperator::InplaceSub: - case QSOperator::InplaceDiv: - case QSOperator::InplaceAdd: - case QSOperator::InplaceLeftShift: - case QSOperator::InplaceMod: - case QSOperator::InplaceMul: - case QSOperator::InplaceOr: - case QSOperator::InplaceRightShift: - case QSOperator::InplaceURightShift: - case QSOperator::InplaceXor: - case QSOperator::Assign: - return 16; - default: - Q_ASSERT_X(false, "PrettyPretty::operatorPrecedenceLevel()", "bad operator"); - } - return 0; -} - -int PrettyPretty::compareOperatorPrecedence(int op1, int op2) -{ - int prec1 = operatorPrecedenceLevel(op1); - int prec2 = operatorPrecedenceLevel(op2); - if (prec1 == prec2) - return 0; - if (prec1 > prec2) - return -1; - return 1; -} - -QTextStream &PrettyPretty::operator () (AST::Node *node, int level) -{ - int was = indentLevel(level); - accept(node); - indentLevel(was); - return out; -} - -QTextStream &PrettyPretty::newlineAndIndent() -{ - enum { IND = 4 }; - out << endl << QString().fill(QLatin1Char(' '), m_indentLevel * IND); - return out; -} - -void PrettyPretty::accept(AST::Node *node) -{ - AST::Node::acceptChild(node, this); -} - -bool PrettyPretty::visit(AST::ThisExpression *node) -{ - Q_UNUSED(node); - out << "this"; - return true; -} - -void PrettyPretty::endVisit(AST::ThisExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::IdentifierExpression *node) -{ - out << Engine::toString(node->name); - return true; -} - -void PrettyPretty::endVisit(AST::IdentifierExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::NullExpression *node) -{ - Q_UNUSED(node); - out << "null"; - return false; -} - -void PrettyPretty::endVisit(AST::NullExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::TrueLiteral *node) -{ - Q_UNUSED(node); - out << "true"; - return false; -} - -void PrettyPretty::endVisit(AST::TrueLiteral *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::FalseLiteral *node) -{ - Q_UNUSED(node); - out << "false"; - return false; -} - -void PrettyPretty::endVisit(AST::FalseLiteral *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::StringLiteral *node) -{ - QString lit = Engine::toString(node->value); - lit.replace(QLatin1String("\\"), QLatin1String("\\\\")); - out << "\"" << lit << "\""; - return false; -} - -void PrettyPretty::endVisit(AST::StringLiteral *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::NumericLiteral *node) -{ - out << QmlJS::numberToString(node->value); - return true; -} - -void PrettyPretty::endVisit(AST::NumericLiteral *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::RegExpLiteral *node) -{ - out << "/" << Engine::toString(node->pattern) << "/"; - if (node->flags) - out << QmlJS::Ecma::RegExp::flagsToString(node->flags); - - return true; -} - -void PrettyPretty::endVisit(AST::RegExpLiteral *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ArrayLiteral *node) -{ - out << "["; - accept(node->elements); - accept(node->elision); - out << "]"; - return false; -} - -void PrettyPretty::endVisit(AST::ArrayLiteral *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ObjectLiteral *node) -{ - out << "{"; - if (node->properties) { - pushIndentLevel(); - AST::PropertyNameAndValueList *prop; - for (prop = node->properties; prop != 0; prop = prop->next) { - newlineAndIndent(); - accept(prop); - if (prop->next) - out << ","; - } - popIndentLevel(); - newlineAndIndent(); - } - out << "}"; - return false; -} - -void PrettyPretty::endVisit(AST::ObjectLiteral *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ElementList *node) -{ - accept(node->elision); - accept(node->expression); - for (node = node->next; node != 0; node = node->next) { - out << ", "; - accept(node->elision); - accept(node->expression); - } - return false; -} - -void PrettyPretty::endVisit(AST::ElementList *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::Elision *node) -{ - out << ", "; - for (AST::Elision *eit = node->next; eit != 0; eit = eit->next) - out << ", "; - return false; -} - -void PrettyPretty::endVisit(AST::Elision *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::PropertyNameAndValueList *node) -{ - accept(node->name); - out << ": "; - accept(node->value); - return false; -} - -void PrettyPretty::endVisit(AST::PropertyNameAndValueList *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::IdentifierPropertyName *node) -{ - out << Engine::toString(node->id); - return false; -} - -void PrettyPretty::endVisit(AST::IdentifierPropertyName *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::StringLiteralPropertyName *node) -{ - QString lit = Engine::toString(node->id); - lit.replace(QLatin1String("\\"), QLatin1String("\\\\")); - out << lit; - return false; -} - -void PrettyPretty::endVisit(AST::StringLiteralPropertyName *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::NumericLiteralPropertyName *node) -{ - out << node->id; - return false; -} - -void PrettyPretty::endVisit(AST::NumericLiteralPropertyName *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ArrayMemberExpression *node) -{ - accept(node->base); - out << "["; - accept(node->expression); - out << "]"; - return false; -} - -void PrettyPretty::endVisit(AST::ArrayMemberExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::FieldMemberExpression *node) -{ - accept(node->base); - out << "." << Engine::toString(node->name); - return false; -} - -void PrettyPretty::endVisit(AST::FieldMemberExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::NewMemberExpression *node) -{ - out << "new "; - accept(node->base); - out << "("; - accept(node->arguments); - out << ")"; - return false; -} - -void PrettyPretty::endVisit(AST::NewMemberExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::NewExpression *node) -{ - Q_UNUSED(node); - out << "new "; - return true; -} - -void PrettyPretty::endVisit(AST::NewExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::CallExpression *node) -{ - accept(node->base); - out << "("; - accept(node->arguments); - out << ")"; - return false; -} - -void PrettyPretty::endVisit(AST::CallExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ArgumentList *node) -{ - accept(node->expression); - for (node = node->next; node != 0; node = node->next) { - out << ", "; - accept(node->expression); - } - return false; -} - -void PrettyPretty::endVisit(AST::ArgumentList *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::PostIncrementExpression *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::PostIncrementExpression *node) -{ - Q_UNUSED(node); - out << "++"; -} - -bool PrettyPretty::visit(AST::PostDecrementExpression *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::PostDecrementExpression *node) -{ - Q_UNUSED(node); - out << "--"; -} - -bool PrettyPretty::visit(AST::DeleteExpression *node) -{ - Q_UNUSED(node); - out << "delete "; - return true; -} - -void PrettyPretty::endVisit(AST::DeleteExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::VoidExpression *node) -{ - Q_UNUSED(node); - out << "void "; - return true; -} - -void PrettyPretty::endVisit(AST::VoidExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::TypeOfExpression *node) -{ - Q_UNUSED(node); - out << "typeof "; - return true; -} - -void PrettyPretty::endVisit(AST::TypeOfExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::PreIncrementExpression *node) -{ - Q_UNUSED(node); - out << "++"; - return true; -} - -void PrettyPretty::endVisit(AST::PreIncrementExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::PreDecrementExpression *node) -{ - Q_UNUSED(node); - out << "--"; - return true; -} - -void PrettyPretty::endVisit(AST::PreDecrementExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::UnaryPlusExpression *node) -{ - out << "+"; - bool needParens = (node->expression->binaryExpressionCast() != 0); - if (needParens) - out << "("; - accept(node->expression); - if (needParens) - out << ")"; - return false; -} - -void PrettyPretty::endVisit(AST::UnaryPlusExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::UnaryMinusExpression *node) -{ - out << "-"; - bool needParens = (node->expression->binaryExpressionCast() != 0); - if (needParens) - out << "("; - accept(node->expression); - if (needParens) - out << ")"; - return false; -} - -void PrettyPretty::endVisit(AST::UnaryMinusExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::TildeExpression *node) -{ - out << "~"; - bool needParens = (node->expression->binaryExpressionCast() != 0); - if (needParens) - out << "("; - accept(node->expression); - if (needParens) - out << ")"; - return false; -} - -void PrettyPretty::endVisit(AST::TildeExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::NotExpression *node) -{ - out << "!"; - bool needParens = (node->expression->binaryExpressionCast() != 0); - if (needParens) - out << "("; - accept(node->expression); - if (needParens) - out << ")"; - return false; -} - -void PrettyPretty::endVisit(AST::NotExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::BinaryExpression *node) -{ - bool needParens = node->left->binaryExpressionCast() - && (compareOperatorPrecedence(node->left->binaryExpressionCast()->op, node->op) < 0); - if (needParens) - out << "("; - accept(node->left); - if (needParens) - out << ")"; - QString s; - switch (node->op) { - case QSOperator::Add: - s = QLatin1String("+"); break; - case QSOperator::And: - s = QLatin1String("&&"); break; - case QSOperator::InplaceAnd: - s = QLatin1String("&="); break; - case QSOperator::Assign: - s = QLatin1String("="); break; - case QSOperator::BitAnd: - s = QLatin1String("&"); break; - case QSOperator::BitOr: - s = QLatin1String("|"); break; - case QSOperator::BitXor: - s = QLatin1String("^"); break; - case QSOperator::InplaceSub: - s = QLatin1String("-="); break; - case QSOperator::Div: - s = QLatin1String("/"); break; - case QSOperator::InplaceDiv: - s = QLatin1String("/="); break; - case QSOperator::Equal: - s = QLatin1String("=="); break; - case QSOperator::Ge: - s = QLatin1String(">="); break; - case QSOperator::Gt: - s = QLatin1String(">"); break; - case QSOperator::In: - s = QLatin1String("in"); break; - case QSOperator::InplaceAdd: - s = QLatin1String("+="); break; - case QSOperator::InstanceOf: - s = QLatin1String("instanceof"); break; - case QSOperator::Le: - s = QLatin1String("<="); break; - case QSOperator::LShift: - s = QLatin1String("<<"); break; - case QSOperator::InplaceLeftShift: - s = QLatin1String("<<="); break; - case QSOperator::Lt: - s = QLatin1String("<"); break; - case QSOperator::Mod: - s = QLatin1String("%"); break; - case QSOperator::InplaceMod: - s = QLatin1String("%="); break; - case QSOperator::Mul: - s = QLatin1String("*"); break; - case QSOperator::InplaceMul: - s = QLatin1String("*="); break; - case QSOperator::NotEqual: - s = QLatin1String("!="); break; - case QSOperator::Or: - s = QLatin1String("||"); break; - case QSOperator::InplaceOr: - s = QLatin1String("|="); break; - case QSOperator::RShift: - s = QLatin1String(">>"); break; - case QSOperator::InplaceRightShift: - s = QLatin1String(">>="); break; - case QSOperator::StrictEqual: - s = QLatin1String("==="); break; - case QSOperator::StrictNotEqual: - s = QLatin1String("!=="); break; - case QSOperator::Sub: - s = QLatin1String("-"); break; - case QSOperator::URShift: - s = QLatin1String(">>>"); break; - case QSOperator::InplaceURightShift: - s = QLatin1String(">>>="); break; - case QSOperator::InplaceXor: - s = QLatin1String("^="); break; - default: - Q_ASSERT (0); - } - out << " " << s << " "; - needParens = node->right->binaryExpressionCast() - && (compareOperatorPrecedence(node->right->binaryExpressionCast()->op, node->op) <= 0); - if (needParens) - out << "("; - accept(node->right); - if (needParens) - out << ")"; - return false; -} - -void PrettyPretty::endVisit(AST::BinaryExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ConditionalExpression *node) -{ - accept(node->expression); - out << " ? "; - accept(node->ok); - out << " : "; - accept(node->ko); - return false; -} - -void PrettyPretty::endVisit(AST::ConditionalExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::Expression *node) -{ - accept(node->left); - out << ", "; - accept(node->right); - return false; -} - -void PrettyPretty::endVisit(AST::Expression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::Block *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::Block *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::StatementList *node) -{ - accept(node->statement); - for (node = node->next; node != 0; node = node->next) { - newlineAndIndent(); - accept(node->statement); - } - return false; -} - -void PrettyPretty::endVisit(AST::StatementList *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::VariableDeclarationList *node) -{ - AST::VariableDeclarationList *it = node; - - do { - it->declaration->accept(this); - it = it->next; - if (it) - out << ", "; - } while (it); - - return false; -} - -void PrettyPretty::endVisit(AST::VariableDeclarationList *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::VariableStatement *node) -{ - out << "var "; - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::VariableStatement *node) -{ - Q_UNUSED(node); - out << ";"; -} - -bool PrettyPretty::visit(AST::VariableDeclaration *node) -{ - out << Engine::toString(node->name); - if (node->expression) { - out << " = "; - accept(node->expression); - } - return false; -} - -void PrettyPretty::endVisit(AST::VariableDeclaration *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::EmptyStatement *node) -{ - Q_UNUSED(node); - out << ";"; - return true; -} - -void PrettyPretty::endVisit(AST::EmptyStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ExpressionStatement *node) -{ - accept(node->expression); - out << ";"; - return false; -} - -void PrettyPretty::endVisit(AST::ExpressionStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::IfStatement *node) -{ - out << "if ("; - accept(node->expression); - out << ") "; - acceptAsBlock(node->ok); - if (node->ko) { - out << " else "; - acceptAsBlock(node->ko); - } - return false; -} - -void PrettyPretty::endVisit(AST::IfStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::DoWhileStatement *node) -{ - out << "do "; - acceptAsBlock(node->statement); - out << " while ("; - accept(node->expression); - out << ");"; - return false; -} - -void PrettyPretty::endVisit(AST::DoWhileStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::WhileStatement *node) -{ - out << "while ("; - accept(node->expression); - out << ") "; - acceptAsBlock(node->statement); - return false; -} - -void PrettyPretty::endVisit(AST::WhileStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ForStatement *node) -{ - out << "for ("; - accept(node->initialiser); - out << "; "; - accept(node->condition); - out << "; "; - accept(node->expression); - out << ") "; - acceptAsBlock(node->statement); - return false; -} - -void PrettyPretty::endVisit(AST::ForStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::LocalForStatement *node) -{ - out << "for (var "; - accept(node->declarations); - out << "; "; - accept(node->condition); - out << "; "; - accept(node->expression); - out << ") "; - acceptAsBlock(node->statement); - return false; -} - -void PrettyPretty::endVisit(AST::LocalForStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ForEachStatement *node) -{ - out << "for ("; - accept(node->initialiser); - out << " in "; - accept(node->expression); - out << ") "; - acceptAsBlock(node->statement); - return false; -} - -void PrettyPretty::endVisit(AST::ForEachStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::LocalForEachStatement *node) -{ - out << "for (var "; - accept(node->declaration); - out << " in "; - accept(node->expression); - out << ") "; - acceptAsBlock(node->statement); - return false; -} - -void PrettyPretty::endVisit(AST::LocalForEachStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ContinueStatement *node) -{ - out << "continue"; - if (node->label) { - out << " " << Engine::toString(node->label); - } - out << ";"; - return false; -} - -void PrettyPretty::endVisit(AST::ContinueStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::BreakStatement *node) -{ - out << "break"; - if (node->label) { - out << " " << Engine::toString(node->label); - } - out << ";"; - return false; -} - -void PrettyPretty::endVisit(AST::BreakStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ReturnStatement *node) -{ - out << "return"; - if (node->expression) { - out << " "; - accept(node->expression); - } - out << ";"; - return false; -} - -void PrettyPretty::endVisit(AST::ReturnStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::WithStatement *node) -{ - out << "with ("; - accept(node->expression); - out << ") "; - acceptAsBlock(node->statement); - return false; -} - -void PrettyPretty::endVisit(AST::WithStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::SwitchStatement *node) -{ - out << "switch ("; - accept(node->expression); - out << ") "; - acceptAsBlock(node->block); - return false; -} - -void PrettyPretty::endVisit(AST::SwitchStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::CaseBlock *node) -{ - accept(node->clauses); - if (node->defaultClause) { - newlineAndIndent(); - accept(node->defaultClause); - } - if (node->moreClauses) { - newlineAndIndent(); - accept(node->moreClauses); - } - return false; -} - -void PrettyPretty::endVisit(AST::CaseBlock *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::CaseClauses *node) -{ - accept(node->clause); - for (node = node->next; node != 0; node = node->next) { - newlineAndIndent(); - accept(node->clause); - } - return false; -} - -void PrettyPretty::endVisit(AST::CaseClauses *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::CaseClause *node) -{ - out << "case "; - accept(node->expression); - out << ":"; - if (node->statements) { - newlineAndIndent(); - accept(node->statements); - } - return false; -} - -void PrettyPretty::endVisit(AST::CaseClause *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::DefaultClause *node) -{ - Q_UNUSED(node); - out << "default:"; - newlineAndIndent(); - return true; -} - -void PrettyPretty::endVisit(AST::DefaultClause *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::LabelledStatement *node) -{ - out << Engine::toString(node->label) << ": "; - return true; -} - -void PrettyPretty::endVisit(AST::LabelledStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::ThrowStatement *node) -{ - Q_UNUSED(node); - out << "throw "; - accept(node->expression); - out << ";"; - return false; -} - -void PrettyPretty::endVisit(AST::ThrowStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::TryStatement *node) -{ - out << "try "; - acceptAsBlock(node->statement); - if (node->catchExpression) { - out << " catch (" << Engine::toString(node->catchExpression->name) << ") "; - acceptAsBlock(node->catchExpression->statement); - } - if (node->finallyExpression) { - out << " finally "; - acceptAsBlock(node->finallyExpression->statement); - } - return false; -} - -void PrettyPretty::endVisit(AST::TryStatement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::Catch *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::Catch *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::Finally *node) -{ - Q_UNUSED(node); - out << "finally "; - return true; -} - -void PrettyPretty::endVisit(AST::Finally *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::FunctionDeclaration *node) -{ - out << "function"; - - if (node->name) - out << " " << Engine::toString(node->name); - - // the arguments - out << "("; - for (AST::FormalParameterList *it = node->formals; it; it = it->next) { - if (it->name) - out << Engine::toString(it->name); - - if (it->next) - out << ", "; - } - out << ")"; - - // the function body - out << " {"; - - if (node->body) { - pushIndentLevel(); - newlineAndIndent(); - accept(node->body); - popIndentLevel(); - newlineAndIndent(); - } - - out << "}"; - - return false; -} - -void PrettyPretty::endVisit(AST::FunctionDeclaration *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::FunctionExpression *node) -{ - out << "function"; - - if (node->name) - out << " " << Engine::toString(node->name); - - // the arguments - out << "("; - for (AST::FormalParameterList *it = node->formals; it; it = it->next) { - if (it->name) - out << Engine::toString(it->name); - - if (it->next) - out << ", "; - } - out << ")"; - - // the function body - out << " {"; - - if (node->body) { - pushIndentLevel(); - newlineAndIndent(); - accept(node->body); - popIndentLevel(); - newlineAndIndent(); - } - - out << "}"; - - return false; -} - -void PrettyPretty::endVisit(AST::FunctionExpression *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::FormalParameterList *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::FormalParameterList *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::FunctionBody *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::FunctionBody *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::Program *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::Program *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::SourceElements *node) -{ - Q_UNUSED(node); - accept(node->element); - for (node = node->next; node != 0; node = node->next) { - newlineAndIndent(); - accept(node->element); - } - return false; -} - -void PrettyPretty::endVisit(AST::SourceElements *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::FunctionSourceElement *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::FunctionSourceElement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::StatementSourceElement *node) -{ - Q_UNUSED(node); - return true; -} - -void PrettyPretty::endVisit(AST::StatementSourceElement *node) -{ - Q_UNUSED(node); -} - -bool PrettyPretty::visit(AST::DebuggerStatement *node) -{ - Q_UNUSED(node); - out << "debugger"; - return true; -} - -void PrettyPretty::endVisit(AST::DebuggerStatement *node) -{ - Q_UNUSED(node); - out << ";"; -} - -bool PrettyPretty::preVisit(AST::Node *node) -{ - Q_UNUSED(node); - return true; -} - -QT_END_NAMESPACE - - diff --git a/src/declarative/qml/parser/qmljsprettypretty_p.h b/src/declarative/qml/parser/qmljsprettypretty_p.h deleted file mode 100644 index 3227e7d..0000000 --- a/src/declarative/qml/parser/qmljsprettypretty_p.h +++ /dev/null @@ -1,329 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLJSPRETTYPRETTY_P_H -#define QMLJSPRETTYPRETTY_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qglobal.h> - -#include "qmljsastvisitor_p.h" - -QT_BEGIN_NAMESPACE - -class QTextStream; - -namespace QmlJS { - -class PrettyPretty: protected AST::Visitor -{ -public: - PrettyPretty(QTextStream &out); - virtual ~PrettyPretty(); - - QTextStream &operator () (AST::Node *node, int level = 0); - -protected: - void accept(AST::Node *node); - - virtual bool preVisit(AST::Node *node); - - virtual bool visit(AST::ThisExpression *node); - virtual void endVisit(AST::ThisExpression *node); - - virtual bool visit(AST::IdentifierExpression *node); - virtual void endVisit(AST::IdentifierExpression *node); - - virtual bool visit(AST::NullExpression *node); - virtual void endVisit(AST::NullExpression *node); - - virtual bool visit(AST::TrueLiteral *node); - virtual void endVisit(AST::TrueLiteral *node); - - virtual bool visit(AST::FalseLiteral *node); - virtual void endVisit(AST::FalseLiteral *node); - - virtual bool visit(AST::StringLiteral *node); - virtual void endVisit(AST::StringLiteral *node); - - virtual bool visit(AST::NumericLiteral *node); - virtual void endVisit(AST::NumericLiteral *node); - - virtual bool visit(AST::RegExpLiteral *node); - virtual void endVisit(AST::RegExpLiteral *node); - - virtual bool visit(AST::ArrayLiteral *node); - virtual void endVisit(AST::ArrayLiteral *node); - - virtual bool visit(AST::ObjectLiteral *node); - virtual void endVisit(AST::ObjectLiteral *node); - - virtual bool visit(AST::ElementList *node); - virtual void endVisit(AST::ElementList *node); - - virtual bool visit(AST::Elision *node); - virtual void endVisit(AST::Elision *node); - - virtual bool visit(AST::PropertyNameAndValueList *node); - virtual void endVisit(AST::PropertyNameAndValueList *node); - - virtual bool visit(AST::IdentifierPropertyName *node); - virtual void endVisit(AST::IdentifierPropertyName *node); - - virtual bool visit(AST::StringLiteralPropertyName *node); - virtual void endVisit(AST::StringLiteralPropertyName *node); - - virtual bool visit(AST::NumericLiteralPropertyName *node); - virtual void endVisit(AST::NumericLiteralPropertyName *node); - - virtual bool visit(AST::ArrayMemberExpression *node); - virtual void endVisit(AST::ArrayMemberExpression *node); - - virtual bool visit(AST::FieldMemberExpression *node); - virtual void endVisit(AST::FieldMemberExpression *node); - - virtual bool visit(AST::NewMemberExpression *node); - virtual void endVisit(AST::NewMemberExpression *node); - - virtual bool visit(AST::NewExpression *node); - virtual void endVisit(AST::NewExpression *node); - - virtual bool visit(AST::CallExpression *node); - virtual void endVisit(AST::CallExpression *node); - - virtual bool visit(AST::ArgumentList *node); - virtual void endVisit(AST::ArgumentList *node); - - virtual bool visit(AST::PostIncrementExpression *node); - virtual void endVisit(AST::PostIncrementExpression *node); - - virtual bool visit(AST::PostDecrementExpression *node); - virtual void endVisit(AST::PostDecrementExpression *node); - - virtual bool visit(AST::DeleteExpression *node); - virtual void endVisit(AST::DeleteExpression *node); - - virtual bool visit(AST::VoidExpression *node); - virtual void endVisit(AST::VoidExpression *node); - - virtual bool visit(AST::TypeOfExpression *node); - virtual void endVisit(AST::TypeOfExpression *node); - - virtual bool visit(AST::PreIncrementExpression *node); - virtual void endVisit(AST::PreIncrementExpression *node); - - virtual bool visit(AST::PreDecrementExpression *node); - virtual void endVisit(AST::PreDecrementExpression *node); - - virtual bool visit(AST::UnaryPlusExpression *node); - virtual void endVisit(AST::UnaryPlusExpression *node); - - virtual bool visit(AST::UnaryMinusExpression *node); - virtual void endVisit(AST::UnaryMinusExpression *node); - - virtual bool visit(AST::TildeExpression *node); - virtual void endVisit(AST::TildeExpression *node); - - virtual bool visit(AST::NotExpression *node); - virtual void endVisit(AST::NotExpression *node); - - virtual bool visit(AST::BinaryExpression *node); - virtual void endVisit(AST::BinaryExpression *node); - - virtual bool visit(AST::ConditionalExpression *node); - virtual void endVisit(AST::ConditionalExpression *node); - - virtual bool visit(AST::Expression *node); - virtual void endVisit(AST::Expression *node); - - virtual bool visit(AST::Block *node); - virtual void endVisit(AST::Block *node); - - virtual bool visit(AST::StatementList *node); - virtual void endVisit(AST::StatementList *node); - - virtual bool visit(AST::VariableStatement *node); - virtual void endVisit(AST::VariableStatement *node); - - virtual bool visit(AST::VariableDeclarationList *node); - virtual void endVisit(AST::VariableDeclarationList *node); - - virtual bool visit(AST::VariableDeclaration *node); - virtual void endVisit(AST::VariableDeclaration *node); - - virtual bool visit(AST::EmptyStatement *node); - virtual void endVisit(AST::EmptyStatement *node); - - virtual bool visit(AST::ExpressionStatement *node); - virtual void endVisit(AST::ExpressionStatement *node); - - virtual bool visit(AST::IfStatement *node); - virtual void endVisit(AST::IfStatement *node); - - virtual bool visit(AST::DoWhileStatement *node); - virtual void endVisit(AST::DoWhileStatement *node); - - virtual bool visit(AST::WhileStatement *node); - virtual void endVisit(AST::WhileStatement *node); - - virtual bool visit(AST::ForStatement *node); - virtual void endVisit(AST::ForStatement *node); - - virtual bool visit(AST::LocalForStatement *node); - virtual void endVisit(AST::LocalForStatement *node); - - virtual bool visit(AST::ForEachStatement *node); - virtual void endVisit(AST::ForEachStatement *node); - - virtual bool visit(AST::LocalForEachStatement *node); - virtual void endVisit(AST::LocalForEachStatement *node); - - virtual bool visit(AST::ContinueStatement *node); - virtual void endVisit(AST::ContinueStatement *node); - - virtual bool visit(AST::BreakStatement *node); - virtual void endVisit(AST::BreakStatement *node); - - virtual bool visit(AST::ReturnStatement *node); - virtual void endVisit(AST::ReturnStatement *node); - - virtual bool visit(AST::WithStatement *node); - virtual void endVisit(AST::WithStatement *node); - - virtual bool visit(AST::SwitchStatement *node); - virtual void endVisit(AST::SwitchStatement *node); - - virtual bool visit(AST::CaseBlock *node); - virtual void endVisit(AST::CaseBlock *node); - - virtual bool visit(AST::CaseClauses *node); - virtual void endVisit(AST::CaseClauses *node); - - virtual bool visit(AST::CaseClause *node); - virtual void endVisit(AST::CaseClause *node); - - virtual bool visit(AST::DefaultClause *node); - virtual void endVisit(AST::DefaultClause *node); - - virtual bool visit(AST::LabelledStatement *node); - virtual void endVisit(AST::LabelledStatement *node); - - virtual bool visit(AST::ThrowStatement *node); - virtual void endVisit(AST::ThrowStatement *node); - - virtual bool visit(AST::TryStatement *node); - virtual void endVisit(AST::TryStatement *node); - - virtual bool visit(AST::Catch *node); - virtual void endVisit(AST::Catch *node); - - virtual bool visit(AST::Finally *node); - virtual void endVisit(AST::Finally *node); - - virtual bool visit(AST::FunctionDeclaration *node); - virtual void endVisit(AST::FunctionDeclaration *node); - - virtual bool visit(AST::FunctionExpression *node); - virtual void endVisit(AST::FunctionExpression *node); - - virtual bool visit(AST::FormalParameterList *node); - virtual void endVisit(AST::FormalParameterList *node); - - virtual bool visit(AST::FunctionBody *node); - virtual void endVisit(AST::FunctionBody *node); - - virtual bool visit(AST::Program *node); - virtual void endVisit(AST::Program *node); - - virtual bool visit(AST::SourceElements *node); - virtual void endVisit(AST::SourceElements *node); - - virtual bool visit(AST::FunctionSourceElement *node); - virtual void endVisit(AST::FunctionSourceElement *node); - - virtual bool visit(AST::StatementSourceElement *node); - virtual void endVisit(AST::StatementSourceElement *node); - - virtual bool visit(AST::DebuggerStatement *node); - virtual void endVisit(AST::DebuggerStatement *node); - - int indentLevel(int level) - { - int was = m_indentLevel; - m_indentLevel = level; - return was; - } - - void pushIndentLevel() - { ++m_indentLevel; } - - void popIndentLevel() - { --m_indentLevel; } - - QTextStream &newlineAndIndent(); - - void acceptAsBlock(AST::Node *node); - - static int operatorPrecedenceLevel(int op); - static int compareOperatorPrecedence(int op1, int op2); - -private: - QTextStream &out; - int m_indentLevel; - - Q_DISABLE_COPY(PrettyPretty) -}; - -} // namespace QmlJS - -QT_END_NAMESPACE - -#endif |