1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "qmljs_global.h" 29 #include "qmljsdocument.h" 30 #include "qmljscontext.h" 31 32 #include <QList> 33 #include <QSharedPointer> 34 35 namespace QmlJS { 36 37 class ObjectValue; 38 class TypeScope; 39 class JSImportScope; 40 class Context; 41 class Value; 42 43 class QMLJS_EXPORT QmlComponentChain 44 { 45 Q_DISABLE_COPY(QmlComponentChain) 46 public: 47 QmlComponentChain(const Document::Ptr &document); 48 ~QmlComponentChain(); 49 50 Document::Ptr document() const; 51 QList<const QmlComponentChain *> instantiatingComponents() const; 52 53 const ObjectValue *idScope() const; 54 const ObjectValue *rootObjectScope() const; 55 56 // takes ownership 57 void addInstantiatingComponent(const QmlComponentChain *component); 58 59 private: 60 QList<const QmlComponentChain *> m_instantiatingComponents; 61 Document::Ptr m_document; 62 }; 63 64 // scope chains are copyable 65 // constructing a new scope chain is currently too expensive: 66 // building the instantiating component chain needs to be sped up 67 class QMLJS_EXPORT ScopeChain 68 { 69 public: 70 explicit ScopeChain(const Document::Ptr &document, const ContextPtr &context); 71 72 Document::Ptr document() const; 73 const ContextPtr &context() const; 74 75 const Value *lookup(const QString &name, const ObjectValue **foundInScope = nullptr) const; 76 const Value *evaluate(AST::Node *node) const; 77 78 const ObjectValue *globalScope() const; 79 void setGlobalScope(const ObjectValue *globalScope); 80 81 const ObjectValue *cppContextProperties() const; 82 void setCppContextProperties(const ObjectValue *cppContextProperties); 83 84 QSharedPointer<const QmlComponentChain> qmlComponentChain() const; 85 void setQmlComponentChain(const QSharedPointer<const QmlComponentChain> &qmlComponentChain); 86 87 QList<const ObjectValue *> qmlScopeObjects() const; 88 void setQmlScopeObjects(const QList<const ObjectValue *> &qmlScopeObjects); 89 90 const TypeScope *qmlTypes() const; 91 void setQmlTypes(const TypeScope *qmlTypes); 92 93 const JSImportScope *jsImports() const; 94 void setJsImports(const JSImportScope *jsImports); 95 96 QList<const ObjectValue *> jsScopes() const; 97 void setJsScopes(const QList<const ObjectValue *> &jsScopes); 98 void appendJsScope(const ObjectValue *scope); 99 100 QList<const ObjectValue *> all() const; 101 102 private: 103 void update() const; 104 void initializeRootScope(); 105 void makeComponentChain(QmlComponentChain *target, const Snapshot &snapshot, 106 QHash<const Document *, QmlComponentChain *> *components); 107 108 109 Document::Ptr m_document; 110 ContextPtr m_context; 111 112 const ObjectValue *m_globalScope; 113 const ObjectValue *m_cppContextProperties; 114 QSharedPointer<const QmlComponentChain> m_qmlComponentScope; 115 QList<const ObjectValue *> m_qmlScopeObjects; 116 const TypeScope *m_qmlTypes; 117 const JSImportScope *m_jsImports; 118 QList<const ObjectValue *> m_jsScopes; 119 120 mutable bool m_modified; 121 mutable QList<const ObjectValue *> m_all; 122 }; 123 124 } // namespace QmlJS 125