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 QtDeclarative 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 QDECLARATIVEREWRITE_P_H
43 #define QDECLARATIVEREWRITE_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/qdeclarativejslexer_p.h>
58 #include <private/qdeclarativejsparser_p.h>
59 #include <private/qdeclarativejsmemorypool_p.h>
63 namespace QDeclarativeRewrite {
64 using namespace QDeclarativeJS;
66 class SharedBindingTester : protected AST::Visitor
70 bool isSharable(const QString &code);
71 bool isSharable(AST::Node *Node);
73 virtual bool visit(AST::FunctionDeclaration *) { _sharable = false; return false; }
74 virtual bool visit(AST::FunctionExpression *) { _sharable = false; return false; }
75 virtual bool visit(AST::CallExpression *) { _sharable = false; return false; }
78 class RewriteBinding: protected AST::Visitor
86 QString operator()(const QString &code, bool *ok = 0, bool *sharable = 0);
87 QString operator()(QDeclarativeJS::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);
127 class RewriteSignalHandler: protected AST::Visitor
129 QList<int> _strStarts;
134 QString operator()(QDeclarativeJS::AST::Node *node, const QString &code, const QString &name);
137 void rewriteMultilineStrings(QString &code);
139 using AST::Visitor::visit;
140 void accept(AST::Node *node);
141 virtual bool visit(AST::StringLiteral *ast);
144 } // namespace QDeclarativeRewrite
148 #endif // QDECLARATIVEREWRITE_P_H