2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-18 16:15:23 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2010-01-18 16:15:23 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-18 16:15:23 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-01-18 16:15:23 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-18 16:15:23 +01:00
|
|
|
|
2013-03-12 12:09:22 +01:00
|
|
|
#ifndef QMLJSEVALUATE_H
|
|
|
|
|
#define QMLJSEVALUATE_H
|
2010-01-18 16:15:23 +01:00
|
|
|
|
|
|
|
|
#include "parser/qmljsastvisitor_p.h"
|
|
|
|
|
#include "qmljsdocument.h"
|
2011-07-12 14:55:27 +02:00
|
|
|
#include "qmljsscopechain.h"
|
2010-01-18 16:15:23 +01:00
|
|
|
|
2014-02-05 13:07:46 +01:00
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
namespace QmlJS {
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
class ValueOwner;
|
|
|
|
|
class Context;
|
|
|
|
|
class Value;
|
|
|
|
|
class ObjectValue;
|
|
|
|
|
class FunctionValue;
|
2010-01-26 14:53:11 +01:00
|
|
|
|
2010-02-15 11:52:39 +01:00
|
|
|
class QMLJS_EXPORT Evaluate: protected AST::Visitor
|
2010-01-18 16:15:23 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2011-09-12 11:48:33 +02:00
|
|
|
Evaluate(const ScopeChain *scopeChain, ReferenceContext *referenceContext = 0);
|
2014-02-07 09:01:53 +01:00
|
|
|
~Evaluate();
|
2010-01-18 16:15:23 +01:00
|
|
|
|
2011-08-08 10:54:48 +02:00
|
|
|
// same as value()
|
2011-08-08 12:47:49 +02:00
|
|
|
const Value *operator()(AST::Node *ast);
|
2011-05-04 11:12:45 +02:00
|
|
|
|
2011-08-08 10:54:48 +02:00
|
|
|
// evaluate ast in the given context, resolving references
|
2011-08-08 12:47:49 +02:00
|
|
|
const Value *value(AST::Node *ast);
|
2011-08-08 10:54:48 +02:00
|
|
|
|
2011-05-04 11:12:45 +02:00
|
|
|
// evaluate, but stop when encountering a Reference
|
2011-08-08 12:47:49 +02:00
|
|
|
const Value *reference(AST::Node *ast);
|
2010-01-18 16:15:23 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void accept(AST::Node *node);
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
const Value *switchResult(const Value *result);
|
2010-01-26 14:53:11 +01:00
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
// Ui
|
2014-09-24 12:49:32 +02:00
|
|
|
bool visit(AST::UiProgram *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiHeaderItemList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiQualifiedPragmaId *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiPragma *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiImport *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiPublicMember *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiSourceElement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiObjectDefinition *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiObjectInitializer *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiObjectBinding *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiScriptBinding *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiArrayBinding *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiObjectMemberList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiArrayMemberList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UiQualifiedId *ast) Q_DECL_OVERRIDE;
|
2010-01-18 16:15:23 +01:00
|
|
|
|
|
|
|
|
// QmlJS
|
2014-09-24 12:49:32 +02:00
|
|
|
bool visit(AST::ThisExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::IdentifierExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::NullExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::TrueLiteral *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::FalseLiteral *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::StringLiteral *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::NumericLiteral *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::RegExpLiteral *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ArrayLiteral *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ObjectLiteral *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ElementList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::Elision *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::PropertyAssignmentList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::PropertyGetterSetter *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::PropertyNameAndValue *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::NestedExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::IdentifierPropertyName *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::StringLiteralPropertyName *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::NumericLiteralPropertyName *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ArrayMemberExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::FieldMemberExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::NewMemberExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::NewExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::CallExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ArgumentList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::PostIncrementExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::PostDecrementExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::DeleteExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::VoidExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::TypeOfExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::PreIncrementExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::PreDecrementExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UnaryPlusExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::UnaryMinusExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::TildeExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::NotExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::BinaryExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ConditionalExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::Expression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::Block *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::StatementList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::VariableStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::VariableDeclarationList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::VariableDeclaration *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::EmptyStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ExpressionStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::IfStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::DoWhileStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::WhileStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ForStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::LocalForStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ForEachStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::LocalForEachStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ContinueStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::BreakStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ReturnStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::WithStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::SwitchStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::CaseBlock *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::CaseClauses *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::CaseClause *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::DefaultClause *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::LabelledStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::ThrowStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::TryStatement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::Catch *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::Finally *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::FunctionDeclaration *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::FunctionExpression *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::FormalParameterList *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::FunctionBody *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::Program *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::SourceElements *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::FunctionSourceElement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::StatementSourceElement *ast) Q_DECL_OVERRIDE;
|
|
|
|
|
bool visit(AST::DebuggerStatement *ast) Q_DECL_OVERRIDE;
|
2010-01-18 16:15:23 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QmlJS::Document::Ptr _doc;
|
2011-08-08 12:47:49 +02:00
|
|
|
ValueOwner *_valueOwner;
|
|
|
|
|
ContextPtr _context;
|
2011-09-12 11:48:33 +02:00
|
|
|
ReferenceContext *_referenceContext;
|
2011-08-08 12:47:49 +02:00
|
|
|
const ScopeChain *_scopeChain;
|
|
|
|
|
const Value *_result;
|
2010-01-18 16:15:23 +01:00
|
|
|
};
|
|
|
|
|
|
2011-02-04 09:52:39 +01:00
|
|
|
} // namespace Qml
|
2010-01-18 16:15:23 +01:00
|
|
|
|
2013-03-12 12:09:22 +01:00
|
|
|
#endif // QMLJSEVALUATE_H
|