1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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>
60 #include <private/qhashedstring_p.h>
64 namespace QQmlRewrite {
65 using namespace QQmlJS;
67 class SharedBindingTester : protected AST::Visitor
72 SharedBindingTester();
74 bool isSharable() const { return _sharable; }
75 bool isSafe() const { return isSharable() && _safe; }
77 void parse(const QString &code);
78 void parse(AST::Node *Node);
80 virtual bool visit(AST::FunctionDeclaration *);
81 virtual bool visit(AST::FunctionExpression *);
82 virtual bool visit(AST::IdentifierExpression *);
83 virtual bool visit(AST::CallExpression *);
84 virtual bool visit(AST::PostDecrementExpression *);
85 virtual bool visit(AST::PostIncrementExpression *);
86 virtual bool visit(AST::PreDecrementExpression *);
87 virtual bool visit(AST::PreIncrementExpression *);
88 virtual bool visit(AST::BinaryExpression *);
91 class RewriteBinding: protected AST::Visitor
99 QString operator()(const QString &code, bool *ok = 0, bool *sharable = 0, bool *safe = 0);
100 QString operator()(QQmlJS::AST::Node *node, const QString &code, bool *sharable = 0, bool *safe = 0);
102 //name of the function: used for the debugger
103 void setName(const QString &name) { _name = name; }
106 using AST::Visitor::visit;
108 void accept(AST::Node *node);
109 QString rewrite(QString code, unsigned position, AST::Statement *node);
110 void rewriteCaseStatements(AST::StatementList *statements, bool rewriteTheLastStatement);
112 virtual bool visit(AST::StringLiteral *ast);
113 virtual bool visit(AST::Block *ast);
114 virtual bool visit(AST::ExpressionStatement *ast);
116 virtual bool visit(AST::DoWhileStatement *ast);
117 virtual void endVisit(AST::DoWhileStatement *ast);
119 virtual bool visit(AST::WhileStatement *ast);
120 virtual void endVisit(AST::WhileStatement *ast);
122 virtual bool visit(AST::ForStatement *ast);
123 virtual void endVisit(AST::ForStatement *ast);
125 virtual bool visit(AST::LocalForStatement *ast);
126 virtual void endVisit(AST::LocalForStatement *ast);
128 virtual bool visit(AST::ForEachStatement *ast);
129 virtual void endVisit(AST::ForEachStatement *ast);
131 virtual bool visit(AST::LocalForEachStatement *ast);
132 virtual void endVisit(AST::LocalForEachStatement *ast);
134 virtual bool visit(AST::CaseBlock *ast);
136 virtual bool visit(AST::FunctionExpression *ast);
137 virtual bool visit(AST::FunctionDeclaration *ast);
143 class RewriteSignalHandler: protected AST::Visitor
146 RewriteSignalHandler();
147 QString operator()(QQmlJS::AST::Node *node, const QString &code, const QString &name,
148 const QString ¶meterString = QString(),
149 const QList<QByteArray> ¶meterNameList = QList<QByteArray>(),
150 const QStringHash<bool> &illegalNames = QStringHash<bool>());
151 QString operator()(const QString &code, const QString &name, bool *ok = 0,
152 const QList<QByteArray> ¶meterNameList = QList<QByteArray>(),
153 const QStringHash<bool> &illegalNames = QStringHash<bool>());
155 enum ParameterAccess {
157 ParametersUnaccessed,
161 //returns the first n signal parameters that are used in the expression
162 int parameterCountForJS() const { return _parameterCountForJS; }
163 ParameterAccess parameterAccess() const { return _parameterAccess; }
164 QString createParameterString(const QList<QByteArray> ¶meterNameList,
165 const QStringHash<bool> &illegalNames);
167 bool hasParameterError() { return !_error.isEmpty(); }
168 QString parameterError() const { return _error; }
171 void rewriteMultilineStrings(QString &code);
173 using AST::Visitor::visit;
174 void accept(AST::Node *node);
175 virtual bool visit(AST::StringLiteral *ast);
176 virtual bool visit(AST::IdentifierExpression *);
179 QString createParameterString(const QList<QHashedString> ¶meterNameList,
180 const QStringHash<bool> &illegalNames);
183 const QString *_code;
185 QStringHash<int> _parameterNames;
186 QList<QHashedString> _parameterNameList;
187 ParameterAccess _parameterAccess;
188 int _parameterCountForJS;
192 } // namespace QQmlRewrite
196 #endif // QQMLREWRITE_P_H