diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2009-06-16 16:18:58 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-06-16 16:18:59 (GMT) |
commit | d612b4789f7ec891ada16afbbbf1c13ab0f0e575 (patch) | |
tree | 0e25f0dd66abbe087220c3de9c258bc6215db639 /src/script/visitors | |
parent | 94e39aff7dd02d4a631d5c40c6f5a5f6fa424035 (diff) | |
download | Qt-d612b4789f7ec891ada16afbbbf1c13ab0f0e575.zip Qt-d612b4789f7ec891ada16afbbbf1c13ab0f0e575.tar.gz Qt-d612b4789f7ec891ada16afbbbf1c13ab0f0e575.tar.bz2 |
Import JSC-based Qt Script from Kent's tree.
Diffstat (limited to 'src/script/visitors')
-rw-r--r-- | src/script/visitors/qscriptprettypretty.cpp | 1316 | ||||
-rw-r--r-- | src/script/visitors/qscriptprettypretty_p.h | 299 | ||||
-rw-r--r-- | src/script/visitors/qscriptxmlgenerator.cpp | 1084 | ||||
-rw-r--r-- | src/script/visitors/qscriptxmlgenerator_p.h | 300 |
4 files changed, 2999 insertions, 0 deletions
diff --git a/src/script/visitors/qscriptprettypretty.cpp b/src/script/visitors/qscriptprettypretty.cpp new file mode 100644 index 0000000..06faac9 --- /dev/null +++ b/src/script/visitors/qscriptprettypretty.cpp @@ -0,0 +1,1316 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include "qscriptprettypretty_p.h" + +#ifndef QT_NO_SCRIPT + +#include "../parser/qscriptast_p.h" + +#include <QtCore/QString> +#include <QtCore/QTextStream> +#include <QtCore/QtDebug> + +QT_BEGIN_NAMESPACE + +typedef double qsreal; // ### + +namespace QScript { +QString numberToString(qsreal value); +} + +using namespace QScript; + +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) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << QScriptEnginePrivate::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) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + QString lit = QString(); // QScriptEnginePrivate::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) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << QScript::numberToString(node->value); + return true; +} + +void PrettyPretty::endVisit(AST::NumericLiteral *node) +{ + Q_UNUSED(node); +} + +bool PrettyPretty::visit(AST::RegExpLiteral *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << "/" << QScriptEnginePrivate::toString(node->pattern) << "/"; +// if (node->flags) +// out << QScript::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) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << QScriptEnginePrivate::toString(node->id); + return false; +} + +void PrettyPretty::endVisit(AST::IdentifierPropertyName *node) +{ + Q_UNUSED(node); +} + +bool PrettyPretty::visit(AST::StringLiteralPropertyName *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// QString lit = QScriptEnginePrivate::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); + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << "." << QScriptEnginePrivate::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) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << QScriptEnginePrivate::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) { + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << " " << QScriptEnginePrivate::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) { + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << " " << QScriptEnginePrivate::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) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << QScriptEnginePrivate::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) { + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// out << " catch (" << QScriptEnginePrivate::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"; + + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// if (node->name) +// out << " " << QScriptEnginePrivate::toString(node->name); + + // the arguments + out << '('; + for (AST::FormalParameterList *it = node->formals; it; it = it->next) { + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); +// if (it->name) +// out << QScriptEnginePrivate::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) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + out << "function"; + +// if (node->name) +// out << " " << QScriptEnginePrivate::toString(node->name); + + // the arguments + out << '('; + for (AST::FormalParameterList *it = node->formals; it; it = it->next) { +// if (it->name) +// out << QScriptEnginePrivate::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 + +#endif // QT_NO_SCRIPT diff --git a/src/script/visitors/qscriptprettypretty_p.h b/src/script/visitors/qscriptprettypretty_p.h new file mode 100644 index 0000000..eaa73cb --- /dev/null +++ b/src/script/visitors/qscriptprettypretty_p.h @@ -0,0 +1,299 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTPRETTYPRETTY_P_H +#define QSCRIPTPRETTYPRETTY_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 "../parser/qscriptastvisitor_p.h" + +QT_BEGIN_NAMESPACE + +class QTextStream; + +namespace QScript { + +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 QScript + +QT_END_NAMESPACE + +#endif diff --git a/src/script/visitors/qscriptxmlgenerator.cpp b/src/script/visitors/qscriptxmlgenerator.cpp new file mode 100644 index 0000000..c530d48 --- /dev/null +++ b/src/script/visitors/qscriptxmlgenerator.cpp @@ -0,0 +1,1084 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include "qscriptxmlgenerator_p.h" + +#ifndef QT_NO_SCRIPT + +#include "../parser/qscriptast_p.h" + +#include <QtCore/qstring.h> +#include <QtCore/qtextstream.h> + +QT_BEGIN_NAMESPACE + +typedef double qsreal; // ### + +namespace QScript { + +extern QString numberToString(qsreal value); + +// copy of Qt::escape() (it's in QtGui :-( ) + +static QString escape(const QString& plain) +{ + QString rich; + rich.reserve(int(plain.length() * 1.1)); + for (int i = 0; i < plain.length(); ++i) { + if (plain.at(i) == QLatin1Char('<')) + rich += QLatin1String("<"); + else if (plain.at(i) == QLatin1Char('>')) + rich += QLatin1String(">"); + else if (plain.at(i) == QLatin1Char('&')) + rich += QLatin1String("&"); + else + rich += plain.at(i); + } + return rich; +} + +XmlGenerator::XmlGenerator(QTextStream &o): + out(o), m_indentLevel(-1), m_formatOutput(false) +{ +} + +XmlGenerator::~XmlGenerator() +{ +} + +QTextStream &XmlGenerator::operator()(const QString &program, int lineNumber) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + return out; +} + +QTextStream &XmlGenerator::newlineAndIndent() +{ + enum { IND = 2 }; + if (m_formatOutput) + out << endl << QString().fill(QLatin1Char(' '), m_indentLevel * IND); + return out; +} + +QTextStream &XmlGenerator::startTag(const QString &name, AST::Node *locationNode) +{ + pushIndentLevel(); + newlineAndIndent(); + out << QLatin1Char('<') << name; + if (locationNode) + out << QLatin1String(" line=\"") << locationNode->startLine << QLatin1Char('\"'); + out << QLatin1Char('>'); + return out; +} + +QTextStream &XmlGenerator::endTag(const QString &name) +{ + newlineAndIndent(); + popIndentLevel(); + out << QLatin1String("</") << escape(name) << QLatin1Char('>'); + return out; +} + +void XmlGenerator::accept(AST::Node *node) +{ + AST::Node::acceptChild(node, this); +} + +bool XmlGenerator::visit(AST::ThisExpression *) +{ + pushIndentLevel(); + newlineAndIndent(); + out << QLatin1String("<this/>"); + popIndentLevel(); + return true; +} + +void XmlGenerator::endVisit(AST::ThisExpression *) +{ +} + +bool XmlGenerator::visit(AST::IdentifierExpression *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("identifier")); +// out << escape(QScriptEnginePrivate::toString(node->name)); + out << QLatin1String("</identifier>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::IdentifierExpression *) +{ +} + +bool XmlGenerator::visit(AST::NullExpression *) +{ + pushIndentLevel(); + newlineAndIndent(); + out << QLatin1String("<null/>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::NullExpression *) +{ +} + +bool XmlGenerator::visit(AST::TrueLiteral *) +{ + pushIndentLevel(); + newlineAndIndent(); + out << QLatin1String("<true/>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::TrueLiteral *) +{ +} + +bool XmlGenerator::visit(AST::FalseLiteral *) +{ + pushIndentLevel(); + newlineAndIndent(); + out << QLatin1String("<false/>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::FalseLiteral *) +{ +} + +bool XmlGenerator::visit(AST::StringLiteral *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("string")); +// out << escape(QScriptEnginePrivate::toString(node->value)) << QLatin1String("</string>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::StringLiteral *) +{ +} + +bool XmlGenerator::visit(AST::NumericLiteral *node) +{ + startTag(QLatin1String("number")); + out << QString::number(node->value) << QLatin1String("</number>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::NumericLiteral *) +{ +} + +bool XmlGenerator::visit(AST::RegExpLiteral *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("regexp")); +// out << QLatin1String("/") << escape(QScriptEnginePrivate::toString(node->pattern)) << QLatin1String("/"); +// if (node->flags) +// out << QScript::Ecma::RegExp::flagsToString(node->flags); + out << QLatin1String("</regexp>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::RegExpLiteral *) +{ +} + +bool XmlGenerator::visit(AST::ArrayLiteral *) +{ + startTag(QLatin1String("array-literal")); + return true; +} + +void XmlGenerator::endVisit(AST::ArrayLiteral *) +{ + endTag(QLatin1String("array-literal")); +} + +bool XmlGenerator::visit(AST::ObjectLiteral *) +{ + startTag(QLatin1String("object-literal")); + return true; +} + +void XmlGenerator::endVisit(AST::ObjectLiteral *) +{ + endTag(QLatin1String("object-literal")); +} + +bool XmlGenerator::visit(AST::ElementList *) +{ + startTag(QLatin1String("element-list")); + return true; +} + +void XmlGenerator::endVisit(AST::ElementList *) +{ + endTag(QLatin1String("element-list")); +} + +bool XmlGenerator::visit(AST::Elision *) +{ + startTag(QLatin1String("elision")); // ### count + return true; +} + +void XmlGenerator::endVisit(AST::Elision *) +{ + endTag(QLatin1String("elision")); +} + +bool XmlGenerator::visit(AST::PropertyNameAndValueList *) +{ + startTag(QLatin1String("property-name-and-value-list")); + return true; +} + +void XmlGenerator::endVisit(AST::PropertyNameAndValueList *) +{ + endTag(QLatin1String("property-name-and-value-list")); +} + +bool XmlGenerator::visit(AST::IdentifierPropertyName *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("identifier")); +// out << escape(QScriptEnginePrivate::toString(node->id)) << QLatin1String("</identifier>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::IdentifierPropertyName *) +{ +} + +bool XmlGenerator::visit(AST::StringLiteralPropertyName *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("string")); +// out << escape(QScriptEnginePrivate::toString(node->id)) << QLatin1String("</string>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::StringLiteralPropertyName *) +{ +} + +bool XmlGenerator::visit(AST::NumericLiteralPropertyName *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("number")); +// out << escape(QScript::numberToString(node->id)) << QLatin1String("</number>"); + popIndentLevel(); + return false; +} + +void XmlGenerator::endVisit(AST::NumericLiteralPropertyName *) +{ +} + +bool XmlGenerator::visit(AST::ArrayMemberExpression *) +{ + startTag(QLatin1String("array-member-expression")); + return true; +} + +void XmlGenerator::endVisit(AST::ArrayMemberExpression *) +{ + endTag(QLatin1String("array-member-expression")); +} + +bool XmlGenerator::visit(AST::FieldMemberExpression *) +{ + startTag(QLatin1String("field-member-expression")); + return true; +} + +void XmlGenerator::endVisit(AST::FieldMemberExpression *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("identifier")); +// out << escape(QScriptEnginePrivate::toString(node->name)); + out << QLatin1String("</identifier>"); + popIndentLevel(); + endTag(QLatin1String("field-member-expression")); +} + +bool XmlGenerator::visit(AST::NewMemberExpression *) +{ + startTag(QLatin1String("new-member-expression")); + return true; +} + +void XmlGenerator::endVisit(AST::NewMemberExpression *) +{ + endTag(QLatin1String("new-member-expression")); +} + +bool XmlGenerator::visit(AST::NewExpression *) +{ + startTag(QLatin1String("new")); + return true; +} + +void XmlGenerator::endVisit(AST::NewExpression *) +{ + endTag(QLatin1String("new")); +} + +bool XmlGenerator::visit(AST::CallExpression *) +{ + startTag(QLatin1String("call")); + return true; +} + +void XmlGenerator::endVisit(AST::CallExpression *) +{ + endTag(QLatin1String("call")); +} + +bool XmlGenerator::visit(AST::ArgumentList *) +{ + startTag(QLatin1String("argument-list")); + return true; +} + +void XmlGenerator::endVisit(AST::ArgumentList *) +{ + endTag(QLatin1String("argument-list")); +} + +bool XmlGenerator::visit(AST::PostIncrementExpression *) +{ + startTag(QLatin1String("post-increment")); + return true; +} + +void XmlGenerator::endVisit(AST::PostIncrementExpression *) +{ + endTag(QLatin1String("post-increment")); +} + +bool XmlGenerator::visit(AST::PostDecrementExpression *) +{ + startTag(QLatin1String("post-decrement")); + return true; +} + +void XmlGenerator::endVisit(AST::PostDecrementExpression *) +{ + endTag(QLatin1String("post-decrement")); +} + +bool XmlGenerator::visit(AST::DeleteExpression *) +{ + startTag(QLatin1String("delete")); + return true; +} + +void XmlGenerator::endVisit(AST::DeleteExpression *) +{ + endTag(QLatin1String("delete")); +} + +bool XmlGenerator::visit(AST::VoidExpression *) +{ + startTag(QLatin1String("void")); + return true; +} + +void XmlGenerator::endVisit(AST::VoidExpression *) +{ + endTag(QLatin1String("void")); +} + +bool XmlGenerator::visit(AST::TypeOfExpression *) +{ + startTag(QLatin1String("typeof")); + return true; +} + +void XmlGenerator::endVisit(AST::TypeOfExpression *) +{ + endTag(QLatin1String("typeof")); +} + +bool XmlGenerator::visit(AST::PreIncrementExpression *) +{ + startTag(QLatin1String("pre-increment")); + return true; +} + +void XmlGenerator::endVisit(AST::PreIncrementExpression *) +{ + endTag(QLatin1String("pre-increment")); +} + +bool XmlGenerator::visit(AST::PreDecrementExpression *) +{ + startTag(QLatin1String("pre-decrement")); + return true; +} + +void XmlGenerator::endVisit(AST::PreDecrementExpression *) +{ + endTag(QLatin1String("pre-decrement")); +} + +bool XmlGenerator::visit(AST::UnaryPlusExpression *) +{ + startTag(QLatin1String("unary-plus")); + return true; +} + +void XmlGenerator::endVisit(AST::UnaryPlusExpression *) +{ + endTag(QLatin1String("unary-plus")); +} + +bool XmlGenerator::visit(AST::UnaryMinusExpression *) +{ + startTag(QLatin1String("unary-minus")); + return true; +} + +void XmlGenerator::endVisit(AST::UnaryMinusExpression *) +{ + endTag(QLatin1String("unary-minus")); +} + +bool XmlGenerator::visit(AST::TildeExpression *) +{ + startTag(QLatin1String("bitwise-not")); + return true; +} + +void XmlGenerator::endVisit(AST::TildeExpression *) +{ + endTag(QLatin1String("bitwise-not")); +} + +bool XmlGenerator::visit(AST::NotExpression *) +{ + startTag(QLatin1String("logical-not")); + return true; +} + +void XmlGenerator::endVisit(AST::NotExpression *) +{ + endTag(QLatin1String("logical-not")); +} + +bool XmlGenerator::visit(AST::BinaryExpression *node) +{ + 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); + } + pushIndentLevel(); + newlineAndIndent(); + out << QLatin1String("<binary-expression op=\"") << s << QLatin1String("\">"); + return true; +} + +void XmlGenerator::endVisit(AST::BinaryExpression *) +{ + endTag(QLatin1String("binary-expression")); +} + +bool XmlGenerator::visit(AST::ConditionalExpression *) +{ + startTag(QLatin1String("conditional")); + return true; +} + +void XmlGenerator::endVisit(AST::ConditionalExpression *) +{ + endTag(QLatin1String("conditional")); +} + +bool XmlGenerator::visit(AST::Expression *) +{ + startTag(QLatin1String("comma-expression")); + return true; +} + +void XmlGenerator::endVisit(AST::Expression *) +{ + endTag(QLatin1String("comma-expression")); +} + +bool XmlGenerator::visit(AST::Block *) +{ + startTag(QLatin1String("block")); + return true; +} + +void XmlGenerator::endVisit(AST::Block *) +{ + endTag(QLatin1String("block")); +} + +bool XmlGenerator::visit(AST::StatementList *) +{ + startTag(QLatin1String("statement-list")); + return true; +} + +void XmlGenerator::endVisit(AST::StatementList *) +{ + endTag(QLatin1String("statement-list")); +} + +bool XmlGenerator::visit(AST::VariableDeclarationList *) +{ + startTag(QLatin1String("variable-declaration-list")); + return true; +} + +void XmlGenerator::endVisit(AST::VariableDeclarationList *) +{ + endTag(QLatin1String("variable-declaration-list")); +} + +bool XmlGenerator::visit(AST::VariableStatement *node) +{ + startTag(QLatin1String("variable-statement"), node); + return true; +} + +void XmlGenerator::endVisit(AST::VariableStatement *) +{ + endTag(QLatin1String("variable-statement")); +} + +bool XmlGenerator::visit(AST::VariableDeclaration *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("variable-declaration"), node); + startTag(QLatin1String("name")); +// out << escape(QScriptEnginePrivate::toString(node->name)); + out << QLatin1String("</name>"); + popIndentLevel(); + return true; +} + +void XmlGenerator::endVisit(AST::VariableDeclaration *) +{ + endTag(QLatin1String("variable-declaration")); +} + +bool XmlGenerator::visit(AST::EmptyStatement *node) +{ + startTag(QLatin1String("empty-statement"), node); + return true; +} + +void XmlGenerator::endVisit(AST::EmptyStatement *) +{ + endTag(QLatin1String("empty-statement")); +} + +bool XmlGenerator::visit(AST::ExpressionStatement *node) +{ + startTag(QLatin1String("expression-statement"), node); + return true; +} + +void XmlGenerator::endVisit(AST::ExpressionStatement *) +{ + endTag(QLatin1String("expression-statement")); +} + +bool XmlGenerator::visit(AST::IfStatement *node) +{ + startTag(QLatin1String("if"), node); + return true; +} + +void XmlGenerator::endVisit(AST::IfStatement *) +{ + endTag(QLatin1String("if")); +} + +bool XmlGenerator::visit(AST::DoWhileStatement *node) +{ + startTag(QLatin1String("do-while"), node); + return true; +} + +void XmlGenerator::endVisit(AST::DoWhileStatement *) +{ + endTag(QLatin1String("do-while")); +} + +bool XmlGenerator::visit(AST::WhileStatement *node) +{ + startTag(QLatin1String("while"), node); + return true; +} + +void XmlGenerator::endVisit(AST::WhileStatement *) +{ + endTag(QLatin1String("while")); +} + +bool XmlGenerator::visit(AST::ForStatement *node) +{ + startTag(QLatin1String("for"), node); + return true; +} + +void XmlGenerator::endVisit(AST::ForStatement *) +{ + endTag(QLatin1String("for")); +} + +bool XmlGenerator::visit(AST::LocalForStatement *node) +{ + startTag(QLatin1String("for"), node); + return true; +} + +void XmlGenerator::endVisit(AST::LocalForStatement *) +{ + endTag(QLatin1String("for")); +} + +bool XmlGenerator::visit(AST::ForEachStatement *node) +{ + startTag(QLatin1String("for-in"), node); + return false; +} + +void XmlGenerator::endVisit(AST::ForEachStatement *) +{ + endTag(QLatin1String("for-in")); +} + +bool XmlGenerator::visit(AST::LocalForEachStatement *node) +{ + startTag(QLatin1String("for-in"), node); + return true; +} + +void XmlGenerator::endVisit(AST::LocalForEachStatement *) +{ + endTag(QLatin1String("for-in")); +} + +bool XmlGenerator::visit(AST::ContinueStatement *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("continue"), node); + if (node->label) { + startTag(QLatin1String("label")); +// out << escape(QScriptEnginePrivate::toString(node->label)); + out << QLatin1String("</label>"); + popIndentLevel(); + } + return true; +} + +void XmlGenerator::endVisit(AST::ContinueStatement *) +{ + endTag(QLatin1String("continue")); +} + +bool XmlGenerator::visit(AST::BreakStatement *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("break"), node); + if (node->label) { + startTag(QLatin1String("label")); +// out << escape(QScriptEnginePrivate::toString(node->label)); + out << QLatin1String("</label>"); + popIndentLevel(); + } + return true; +} + +void XmlGenerator::endVisit(AST::BreakStatement *) +{ + endTag(QLatin1String("break")); +} + +bool XmlGenerator::visit(AST::ReturnStatement *node) +{ + startTag(QLatin1String("return"), node); + return true; +} + +void XmlGenerator::endVisit(AST::ReturnStatement *) +{ + endTag(QLatin1String("return")); +} + +bool XmlGenerator::visit(AST::WithStatement *node) +{ + startTag(QLatin1String("with"), node); + return true; +} + +void XmlGenerator::endVisit(AST::WithStatement *) +{ + endTag(QLatin1String("with")); +} + +bool XmlGenerator::visit(AST::SwitchStatement *node) +{ + startTag(QLatin1String("switch"), node); + return true; +} + +void XmlGenerator::endVisit(AST::SwitchStatement *) +{ + endTag(QLatin1String("switch")); +} + +bool XmlGenerator::visit(AST::CaseBlock *) +{ + startTag(QLatin1String("case-block")); + return true; +} + +void XmlGenerator::endVisit(AST::CaseBlock *) +{ + endTag(QLatin1String("case-block")); +} + +bool XmlGenerator::visit(AST::CaseClauses *) +{ + startTag(QLatin1String("case-clauses")); + return true; +} + +void XmlGenerator::endVisit(AST::CaseClauses *) +{ + endTag(QLatin1String("case-clauses")); +} + +bool XmlGenerator::visit(AST::CaseClause *) +{ + startTag(QLatin1String("case-clause")); + return true; +} + +void XmlGenerator::endVisit(AST::CaseClause *) +{ + endTag(QLatin1String("case-clause")); +} + +bool XmlGenerator::visit(AST::DefaultClause *) +{ + startTag(QLatin1String("default-clause")); + return true; +} + +void XmlGenerator::endVisit(AST::DefaultClause *) +{ + endTag(QLatin1String("default-clause")); +} + +bool XmlGenerator::visit(AST::LabelledStatement *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("labelled-statement"), node); + startTag(QLatin1String("label")); +// out << escape(QScriptEnginePrivate::toString(node->label)); + out << QLatin1String("</label>"); + popIndentLevel(); + return true; +} + +void XmlGenerator::endVisit(AST::LabelledStatement *) +{ + endTag(QLatin1String("labelled-statement")); +} + +bool XmlGenerator::visit(AST::ThrowStatement *node) +{ + startTag(QLatin1String("throw"), node); + return true; +} + +void XmlGenerator::endVisit(AST::ThrowStatement *) +{ + endTag(QLatin1String("throw")); +} + +bool XmlGenerator::visit(AST::TryStatement *node) +{ + startTag(QLatin1String("try"), node); + return true; +} + +void XmlGenerator::endVisit(AST::TryStatement *) +{ + endTag(QLatin1String("try")); +} + +bool XmlGenerator::visit(AST::Catch *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("catch")); + startTag(QLatin1String("identifier")); +// out << escape(QScriptEnginePrivate::toString(node->name)); + out << QLatin1String("</identifier>"); + popIndentLevel(); + return true; +} + +void XmlGenerator::endVisit(AST::Catch *) +{ + endTag(QLatin1String("catch")); +} + +bool XmlGenerator::visit(AST::Finally *) +{ + startTag(QLatin1String("finally")); + return true; +} + +void XmlGenerator::endVisit(AST::Finally *) +{ + endTag(QLatin1String("finally")); +} + +bool XmlGenerator::visit(AST::FunctionDeclaration *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("function-declaration"), node); + startTag(QLatin1String("name")); +// if (node->name) +// out << escape(QScriptEnginePrivate::toString(node->name)); + out << QLatin1String("</name>"); + popIndentLevel(); + if (!node->formals) { + startTag(QLatin1String("formal-parameter-list")); + endTag(QLatin1String("formal-parameter-list")); + } + if (!node->body) { + startTag(QLatin1String("function-body")); + endTag(QLatin1String("function-body")); + } + return true; +} + +void XmlGenerator::endVisit(AST::FunctionDeclaration *) +{ + endTag(QLatin1String("function-declaration")); +} + +bool XmlGenerator::visit(AST::FunctionExpression *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + startTag(QLatin1String("function-expression"), node); + startTag(QLatin1String("name")); +// if (node->name) +// out << escape(QScriptEnginePrivate::toString(node->name)); + out << QLatin1String("</name>"); + if (!node->formals) { + startTag(QLatin1String("formal-parameter-list")); + endTag(QLatin1String("formal-parameter-list")); + } + if (!node->body) { + startTag(QLatin1String("function-body")); + endTag(QLatin1String("function-body")); + } + return true; +} + +void XmlGenerator::endVisit(AST::FunctionExpression *) +{ + endTag(QLatin1String("function-expression")); +} + +bool XmlGenerator::visit(AST::FormalParameterList *node) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + Q_UNUSED(node); + startTag(QLatin1String("formal-parameter-list")); + for (AST::FormalParameterList *it = node; it; it = it->next) { + startTag(QLatin1String("identifier")); +// out << escape(QScriptEnginePrivate::toString(it->name)); + out << QLatin1String("</identifier>"); + popIndentLevel(); + } + return true; +} + +void XmlGenerator::endVisit(AST::FormalParameterList *) +{ + endTag(QLatin1String("formal-parameter-list")); +} + +bool XmlGenerator::visit(AST::FunctionBody *) +{ + startTag(QLatin1String("function-body")); + return true; +} + +void XmlGenerator::endVisit(AST::FunctionBody *) +{ + endTag(QLatin1String("function-body")); +} + +bool XmlGenerator::visit(AST::Program *) +{ + startTag(QLatin1String("program")); + return true; +} + +void XmlGenerator::endVisit(AST::Program *) +{ + endTag(QLatin1String("program")); +} + +bool XmlGenerator::visit(AST::SourceElements *) +{ + startTag(QLatin1String("source-elements")); + return true; +} + +void XmlGenerator::endVisit(AST::SourceElements *) +{ + endTag(QLatin1String("source-elements")); +} + +bool XmlGenerator::visit(AST::FunctionSourceElement *) +{ + return true; +} + +void XmlGenerator::endVisit(AST::FunctionSourceElement *) +{ +} + +bool XmlGenerator::visit(AST::StatementSourceElement *) +{ + return true; +} + +void XmlGenerator::endVisit(AST::StatementSourceElement *) +{ +} + +bool XmlGenerator::visit(AST::DebuggerStatement *node) +{ + startTag(QLatin1String("debugger-statement"), node); + return true; +} + +void XmlGenerator::endVisit(AST::DebuggerStatement *) +{ + endTag(QLatin1String("debugger-statement")); +} + +bool XmlGenerator::preVisit(AST::Node *) +{ + return true; +} + +} // namespace QScript + +Q_SCRIPT_EXPORT QString qt_scriptToXml(const QString &program, int lineNumber = 1) +{ + QString result; + QTextStream out(&result, QIODevice::WriteOnly); + QScript::XmlGenerator gen(out); + gen(program, lineNumber); + out.flush(); + return result; +} + +QT_END_NAMESPACE + +#endif // QT_NO_SCRIPT diff --git a/src/script/visitors/qscriptxmlgenerator_p.h b/src/script/visitors/qscriptxmlgenerator_p.h new file mode 100644 index 0000000..cb6c0f5 --- /dev/null +++ b/src/script/visitors/qscriptxmlgenerator_p.h @@ -0,0 +1,300 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTXMLGENERATOR_P_H +#define QSCRIPTXMLGENERATOR_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/qobjectdefs.h> + +#ifndef QT_NO_SCRIPT + +#include "../parser/qscriptastvisitor_p.h" + +QT_BEGIN_NAMESPACE + +class QTextStream; + +namespace QScript { + +class XmlGenerator: protected AST::Visitor +{ +public: + XmlGenerator(QTextStream &out); + virtual ~XmlGenerator(); + + QTextStream &operator()(const QString &program, int lineNumber = 1); + +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); + +private: + int indentLevel(int level) + { + int was = m_indentLevel; + m_indentLevel = level; + return was; + } + + void pushIndentLevel() + { ++m_indentLevel; } + + void popIndentLevel() + { --m_indentLevel; } + + QTextStream &newlineAndIndent(); + QTextStream &startTag(const QString &name, AST::Node *locationNode = 0); + QTextStream &endTag(const QString &name); + +private: + QTextStream &out; + int m_indentLevel; + bool m_formatOutput; +}; + +} // namespace QScript + +#endif // QT_NO_SCRIPT + +QT_END_NAMESPACE + +#endif |