| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtScript module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QSCRIPTPRETTYPRETTY_P_H
|
|---|
| 43 | #define QSCRIPTPRETTYPRETTY_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists purely as an
|
|---|
| 50 | // implementation detail. This header file may change from version to
|
|---|
| 51 | // version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include <QtCore/qglobal.h>
|
|---|
| 57 |
|
|---|
| 58 | #include "qscriptastvisitor_p.h"
|
|---|
| 59 |
|
|---|
| 60 | QT_BEGIN_NAMESPACE
|
|---|
| 61 |
|
|---|
| 62 | class QTextStream;
|
|---|
| 63 |
|
|---|
| 64 | namespace QScript {
|
|---|
| 65 |
|
|---|
| 66 | class PrettyPretty: protected AST::Visitor
|
|---|
| 67 | {
|
|---|
| 68 | public:
|
|---|
| 69 | PrettyPretty(QTextStream &out);
|
|---|
| 70 | virtual ~PrettyPretty();
|
|---|
| 71 |
|
|---|
| 72 | QTextStream &operator () (AST::Node *node, int level = 0);
|
|---|
| 73 |
|
|---|
| 74 | protected:
|
|---|
| 75 | void accept(AST::Node *node);
|
|---|
| 76 |
|
|---|
| 77 | virtual bool preVisit(AST::Node *node);
|
|---|
| 78 |
|
|---|
| 79 | virtual bool visit(AST::ThisExpression *node);
|
|---|
| 80 | virtual void endVisit(AST::ThisExpression *node);
|
|---|
| 81 |
|
|---|
| 82 | virtual bool visit(AST::IdentifierExpression *node);
|
|---|
| 83 | virtual void endVisit(AST::IdentifierExpression *node);
|
|---|
| 84 |
|
|---|
| 85 | virtual bool visit(AST::NullExpression *node);
|
|---|
| 86 | virtual void endVisit(AST::NullExpression *node);
|
|---|
| 87 |
|
|---|
| 88 | virtual bool visit(AST::TrueLiteral *node);
|
|---|
| 89 | virtual void endVisit(AST::TrueLiteral *node);
|
|---|
| 90 |
|
|---|
| 91 | virtual bool visit(AST::FalseLiteral *node);
|
|---|
| 92 | virtual void endVisit(AST::FalseLiteral *node);
|
|---|
| 93 |
|
|---|
| 94 | virtual bool visit(AST::StringLiteral *node);
|
|---|
| 95 | virtual void endVisit(AST::StringLiteral *node);
|
|---|
| 96 |
|
|---|
| 97 | virtual bool visit(AST::NumericLiteral *node);
|
|---|
| 98 | virtual void endVisit(AST::NumericLiteral *node);
|
|---|
| 99 |
|
|---|
| 100 | virtual bool visit(AST::RegExpLiteral *node);
|
|---|
| 101 | virtual void endVisit(AST::RegExpLiteral *node);
|
|---|
| 102 |
|
|---|
| 103 | virtual bool visit(AST::ArrayLiteral *node);
|
|---|
| 104 | virtual void endVisit(AST::ArrayLiteral *node);
|
|---|
| 105 |
|
|---|
| 106 | virtual bool visit(AST::ObjectLiteral *node);
|
|---|
| 107 | virtual void endVisit(AST::ObjectLiteral *node);
|
|---|
| 108 |
|
|---|
| 109 | virtual bool visit(AST::ElementList *node);
|
|---|
| 110 | virtual void endVisit(AST::ElementList *node);
|
|---|
| 111 |
|
|---|
| 112 | virtual bool visit(AST::Elision *node);
|
|---|
| 113 | virtual void endVisit(AST::Elision *node);
|
|---|
| 114 |
|
|---|
| 115 | virtual bool visit(AST::PropertyNameAndValueList *node);
|
|---|
| 116 | virtual void endVisit(AST::PropertyNameAndValueList *node);
|
|---|
| 117 |
|
|---|
| 118 | virtual bool visit(AST::IdentifierPropertyName *node);
|
|---|
| 119 | virtual void endVisit(AST::IdentifierPropertyName *node);
|
|---|
| 120 |
|
|---|
| 121 | virtual bool visit(AST::StringLiteralPropertyName *node);
|
|---|
| 122 | virtual void endVisit(AST::StringLiteralPropertyName *node);
|
|---|
| 123 |
|
|---|
| 124 | virtual bool visit(AST::NumericLiteralPropertyName *node);
|
|---|
| 125 | virtual void endVisit(AST::NumericLiteralPropertyName *node);
|
|---|
| 126 |
|
|---|
| 127 | virtual bool visit(AST::ArrayMemberExpression *node);
|
|---|
| 128 | virtual void endVisit(AST::ArrayMemberExpression *node);
|
|---|
| 129 |
|
|---|
| 130 | virtual bool visit(AST::FieldMemberExpression *node);
|
|---|
| 131 | virtual void endVisit(AST::FieldMemberExpression *node);
|
|---|
| 132 |
|
|---|
| 133 | virtual bool visit(AST::NewMemberExpression *node);
|
|---|
| 134 | virtual void endVisit(AST::NewMemberExpression *node);
|
|---|
| 135 |
|
|---|
| 136 | virtual bool visit(AST::NewExpression *node);
|
|---|
| 137 | virtual void endVisit(AST::NewExpression *node);
|
|---|
| 138 |
|
|---|
| 139 | virtual bool visit(AST::CallExpression *node);
|
|---|
| 140 | virtual void endVisit(AST::CallExpression *node);
|
|---|
| 141 |
|
|---|
| 142 | virtual bool visit(AST::ArgumentList *node);
|
|---|
| 143 | virtual void endVisit(AST::ArgumentList *node);
|
|---|
| 144 |
|
|---|
| 145 | virtual bool visit(AST::PostIncrementExpression *node);
|
|---|
| 146 | virtual void endVisit(AST::PostIncrementExpression *node);
|
|---|
| 147 |
|
|---|
| 148 | virtual bool visit(AST::PostDecrementExpression *node);
|
|---|
| 149 | virtual void endVisit(AST::PostDecrementExpression *node);
|
|---|
| 150 |
|
|---|
| 151 | virtual bool visit(AST::DeleteExpression *node);
|
|---|
| 152 | virtual void endVisit(AST::DeleteExpression *node);
|
|---|
| 153 |
|
|---|
| 154 | virtual bool visit(AST::VoidExpression *node);
|
|---|
| 155 | virtual void endVisit(AST::VoidExpression *node);
|
|---|
| 156 |
|
|---|
| 157 | virtual bool visit(AST::TypeOfExpression *node);
|
|---|
| 158 | virtual void endVisit(AST::TypeOfExpression *node);
|
|---|
| 159 |
|
|---|
| 160 | virtual bool visit(AST::PreIncrementExpression *node);
|
|---|
| 161 | virtual void endVisit(AST::PreIncrementExpression *node);
|
|---|
| 162 |
|
|---|
| 163 | virtual bool visit(AST::PreDecrementExpression *node);
|
|---|
| 164 | virtual void endVisit(AST::PreDecrementExpression *node);
|
|---|
| 165 |
|
|---|
| 166 | virtual bool visit(AST::UnaryPlusExpression *node);
|
|---|
| 167 | virtual void endVisit(AST::UnaryPlusExpression *node);
|
|---|
| 168 |
|
|---|
| 169 | virtual bool visit(AST::UnaryMinusExpression *node);
|
|---|
| 170 | virtual void endVisit(AST::UnaryMinusExpression *node);
|
|---|
| 171 |
|
|---|
| 172 | virtual bool visit(AST::TildeExpression *node);
|
|---|
| 173 | virtual void endVisit(AST::TildeExpression *node);
|
|---|
| 174 |
|
|---|
| 175 | virtual bool visit(AST::NotExpression *node);
|
|---|
| 176 | virtual void endVisit(AST::NotExpression *node);
|
|---|
| 177 |
|
|---|
| 178 | virtual bool visit(AST::BinaryExpression *node);
|
|---|
| 179 | virtual void endVisit(AST::BinaryExpression *node);
|
|---|
| 180 |
|
|---|
| 181 | virtual bool visit(AST::ConditionalExpression *node);
|
|---|
| 182 | virtual void endVisit(AST::ConditionalExpression *node);
|
|---|
| 183 |
|
|---|
| 184 | virtual bool visit(AST::Expression *node);
|
|---|
| 185 | virtual void endVisit(AST::Expression *node);
|
|---|
| 186 |
|
|---|
| 187 | virtual bool visit(AST::Block *node);
|
|---|
| 188 | virtual void endVisit(AST::Block *node);
|
|---|
| 189 |
|
|---|
| 190 | virtual bool visit(AST::StatementList *node);
|
|---|
| 191 | virtual void endVisit(AST::StatementList *node);
|
|---|
| 192 |
|
|---|
| 193 | virtual bool visit(AST::VariableStatement *node);
|
|---|
| 194 | virtual void endVisit(AST::VariableStatement *node);
|
|---|
| 195 |
|
|---|
| 196 | virtual bool visit(AST::VariableDeclarationList *node);
|
|---|
| 197 | virtual void endVisit(AST::VariableDeclarationList *node);
|
|---|
| 198 |
|
|---|
| 199 | virtual bool visit(AST::VariableDeclaration *node);
|
|---|
| 200 | virtual void endVisit(AST::VariableDeclaration *node);
|
|---|
| 201 |
|
|---|
| 202 | virtual bool visit(AST::EmptyStatement *node);
|
|---|
| 203 | virtual void endVisit(AST::EmptyStatement *node);
|
|---|
| 204 |
|
|---|
| 205 | virtual bool visit(AST::ExpressionStatement *node);
|
|---|
| 206 | virtual void endVisit(AST::ExpressionStatement *node);
|
|---|
| 207 |
|
|---|
| 208 | virtual bool visit(AST::IfStatement *node);
|
|---|
| 209 | virtual void endVisit(AST::IfStatement *node);
|
|---|
| 210 |
|
|---|
| 211 | virtual bool visit(AST::DoWhileStatement *node);
|
|---|
| 212 | virtual void endVisit(AST::DoWhileStatement *node);
|
|---|
| 213 |
|
|---|
| 214 | virtual bool visit(AST::WhileStatement *node);
|
|---|
| 215 | virtual void endVisit(AST::WhileStatement *node);
|
|---|
| 216 |
|
|---|
| 217 | virtual bool visit(AST::ForStatement *node);
|
|---|
| 218 | virtual void endVisit(AST::ForStatement *node);
|
|---|
| 219 |
|
|---|
| 220 | virtual bool visit(AST::LocalForStatement *node);
|
|---|
| 221 | virtual void endVisit(AST::LocalForStatement *node);
|
|---|
| 222 |
|
|---|
| 223 | virtual bool visit(AST::ForEachStatement *node);
|
|---|
| 224 | virtual void endVisit(AST::ForEachStatement *node);
|
|---|
| 225 |
|
|---|
| 226 | virtual bool visit(AST::LocalForEachStatement *node);
|
|---|
| 227 | virtual void endVisit(AST::LocalForEachStatement *node);
|
|---|
| 228 |
|
|---|
| 229 | virtual bool visit(AST::ContinueStatement *node);
|
|---|
| 230 | virtual void endVisit(AST::ContinueStatement *node);
|
|---|
| 231 |
|
|---|
| 232 | virtual bool visit(AST::BreakStatement *node);
|
|---|
| 233 | virtual void endVisit(AST::BreakStatement *node);
|
|---|
| 234 |
|
|---|
| 235 | virtual bool visit(AST::ReturnStatement *node);
|
|---|
| 236 | virtual void endVisit(AST::ReturnStatement *node);
|
|---|
| 237 |
|
|---|
| 238 | virtual bool visit(AST::WithStatement *node);
|
|---|
| 239 | virtual void endVisit(AST::WithStatement *node);
|
|---|
| 240 |
|
|---|
| 241 | virtual bool visit(AST::SwitchStatement *node);
|
|---|
| 242 | virtual void endVisit(AST::SwitchStatement *node);
|
|---|
| 243 |
|
|---|
| 244 | virtual bool visit(AST::CaseBlock *node);
|
|---|
| 245 | virtual void endVisit(AST::CaseBlock *node);
|
|---|
| 246 |
|
|---|
| 247 | virtual bool visit(AST::CaseClauses *node);
|
|---|
| 248 | virtual void endVisit(AST::CaseClauses *node);
|
|---|
| 249 |
|
|---|
| 250 | virtual bool visit(AST::CaseClause *node);
|
|---|
| 251 | virtual void endVisit(AST::CaseClause *node);
|
|---|
| 252 |
|
|---|
| 253 | virtual bool visit(AST::DefaultClause *node);
|
|---|
| 254 | virtual void endVisit(AST::DefaultClause *node);
|
|---|
| 255 |
|
|---|
| 256 | virtual bool visit(AST::LabelledStatement *node);
|
|---|
| 257 | virtual void endVisit(AST::LabelledStatement *node);
|
|---|
| 258 |
|
|---|
| 259 | virtual bool visit(AST::ThrowStatement *node);
|
|---|
| 260 | virtual void endVisit(AST::ThrowStatement *node);
|
|---|
| 261 |
|
|---|
| 262 | virtual bool visit(AST::TryStatement *node);
|
|---|
| 263 | virtual void endVisit(AST::TryStatement *node);
|
|---|
| 264 |
|
|---|
| 265 | virtual bool visit(AST::Catch *node);
|
|---|
| 266 | virtual void endVisit(AST::Catch *node);
|
|---|
| 267 |
|
|---|
| 268 | virtual bool visit(AST::Finally *node);
|
|---|
| 269 | virtual void endVisit(AST::Finally *node);
|
|---|
| 270 |
|
|---|
| 271 | virtual bool visit(AST::FunctionDeclaration *node);
|
|---|
| 272 | virtual void endVisit(AST::FunctionDeclaration *node);
|
|---|
| 273 |
|
|---|
| 274 | virtual bool visit(AST::FunctionExpression *node);
|
|---|
| 275 | virtual void endVisit(AST::FunctionExpression *node);
|
|---|
| 276 |
|
|---|
| 277 | virtual bool visit(AST::FormalParameterList *node);
|
|---|
| 278 | virtual void endVisit(AST::FormalParameterList *node);
|
|---|
| 279 |
|
|---|
| 280 | virtual bool visit(AST::FunctionBody *node);
|
|---|
| 281 | virtual void endVisit(AST::FunctionBody *node);
|
|---|
| 282 |
|
|---|
| 283 | virtual bool visit(AST::Program *node);
|
|---|
| 284 | virtual void endVisit(AST::Program *node);
|
|---|
| 285 |
|
|---|
| 286 | virtual bool visit(AST::SourceElements *node);
|
|---|
| 287 | virtual void endVisit(AST::SourceElements *node);
|
|---|
| 288 |
|
|---|
| 289 | virtual bool visit(AST::FunctionSourceElement *node);
|
|---|
| 290 | virtual void endVisit(AST::FunctionSourceElement *node);
|
|---|
| 291 |
|
|---|
| 292 | virtual bool visit(AST::StatementSourceElement *node);
|
|---|
| 293 | virtual void endVisit(AST::StatementSourceElement *node);
|
|---|
| 294 |
|
|---|
| 295 | virtual bool visit(AST::DebuggerStatement *node);
|
|---|
| 296 | virtual void endVisit(AST::DebuggerStatement *node);
|
|---|
| 297 |
|
|---|
| 298 | int indentLevel(int level)
|
|---|
| 299 | {
|
|---|
| 300 | int was = m_indentLevel;
|
|---|
| 301 | m_indentLevel = level;
|
|---|
| 302 | return was;
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | void pushIndentLevel()
|
|---|
| 306 | { ++m_indentLevel; }
|
|---|
| 307 |
|
|---|
| 308 | void popIndentLevel()
|
|---|
| 309 | { --m_indentLevel; }
|
|---|
| 310 |
|
|---|
| 311 | QTextStream &newlineAndIndent();
|
|---|
| 312 |
|
|---|
| 313 | void acceptAsBlock(AST::Node *node);
|
|---|
| 314 |
|
|---|
| 315 | static int operatorPrecedenceLevel(int op);
|
|---|
| 316 | static int compareOperatorPrecedence(int op1, int op2);
|
|---|
| 317 |
|
|---|
| 318 | private:
|
|---|
| 319 | QTextStream &out;
|
|---|
| 320 | int m_indentLevel;
|
|---|
| 321 |
|
|---|
| 322 | Q_DISABLE_COPY(PrettyPretty)
|
|---|
| 323 | };
|
|---|
| 324 |
|
|---|
| 325 | } // namespace QScript
|
|---|
| 326 |
|
|---|
| 327 | QT_END_NAMESPACE
|
|---|
| 328 |
|
|---|
| 329 | #endif
|
|---|