1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQMLREWRITE_P_H
43 #define QQMLREWRITE_P_H
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.
56 #include <private/textwriter_p.h>
57 #include <private/qqmljslexer_p.h>
58 #include <private/qqmljsparser_p.h>
59 #include <private/qqmljsmemorypool_p.h>
63 namespace QQmlRewrite {
64 using namespace QQmlJS;
66 class SharedBindingTester : protected AST::Visitor
70 bool isSharable(const QString &code);
71 bool isSharable(AST::Node *Node);
73 inline virtual bool visit(AST::FunctionDeclaration *);
74 inline virtual bool visit(AST::FunctionExpression *);
75 inline virtual bool visit(AST::IdentifierExpression *);
78 class RewriteBinding: protected AST::Visitor
86 QString operator()(const QString &code, bool *ok = 0, bool *sharable = 0);
87 QString operator()(QQmlJS::AST::Node *node, const QString &code, bool *sharable = 0);
89 //name of the function: used for the debugger
90 void setName(const QString &name) { _name = name; }
93 using AST::Visitor::visit;
95 void accept(AST::Node *node);
96 QString rewrite(QString code, unsigned position, AST::Statement *node);
97 void rewriteCaseStatements(AST::StatementList *statements, bool rewriteTheLastStatement);
99 virtual bool visit(AST::StringLiteral *ast);
100 virtual bool visit(AST::Block *ast);
101 virtual bool visit(AST::ExpressionStatement *ast);
103 virtual bool visit(AST::DoWhileStatement *ast);
104 virtual void endVisit(AST::DoWhileStatement *ast);
106 virtual bool visit(AST::WhileStatement *ast);
107 virtual void endVisit(AST::WhileStatement *ast);
109 virtual bool visit(AST::ForStatement *ast);
110 virtual void endVisit(AST::ForStatement *ast);
112 virtual bool visit(AST::LocalForStatement *ast);
113 virtual void endVisit(AST::LocalForStatement *ast);
115 virtual bool visit(AST::ForEachStatement *ast);
116 virtual void endVisit(AST::ForEachStatement *ast);
118 virtual bool visit(AST::LocalForEachStatement *ast);
119 virtual void endVisit(AST::LocalForEachStatement *ast);
121 virtual bool visit(AST::CaseBlock *ast);
123 virtual bool visit(AST::FunctionExpression *ast);
124 virtual bool visit(AST::FunctionDeclaration *ast);
130 class RewriteSignalHandler: protected AST::Visitor
133 const QString *_code;
137 RewriteSignalHandler();
138 QString operator()(QQmlJS::AST::Node *node, const QString &code, const QString &name);
139 QString operator()(const QString &code, const QString &name, bool *ok = 0);
142 void rewriteMultilineStrings(QString &code);
144 using AST::Visitor::visit;
145 void accept(AST::Node *node);
146 virtual bool visit(AST::StringLiteral *ast);
149 bool SharedBindingTester::visit(AST::FunctionDeclaration *)
155 bool SharedBindingTester::visit(AST::FunctionExpression *)
161 bool SharedBindingTester::visit(AST::IdentifierExpression *e)
163 static const QString evalString = QStringLiteral("eval");
164 if (e->name == evalString)
167 return false; // IdentifierExpression is a leaf node anyway
170 } // namespace QQmlRewrite
174 #endif // QQMLREWRITE_P_H