diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-02 14:48:22 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-05 14:59:26 +0200 |
commit | 7200da29a888567313fa67ea20bbdb82714ae218 (patch) | |
tree | 5f13e35dad127b0b8100a6fd28fb984f3f4560f1 /src/qmlcompiler | |
parent | 6bb5a51a9d70347f50c89919613a958c1a524ab5 (diff) |
QmlCompiler: Move ScopeType and JavaScriptIdentifier into QQmlJSScope
They don't begin with 'Q' and they are not very useful outside of
QQmlJSScope.
Change-Id: I3363ac4d29be7a9cb5c9f7f3af1727c99e886825
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r-- | src/qmlcompiler/qqmljsscope.cpp | 25 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsscope_p.h | 43 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljstypereader.cpp | 6 |
3 files changed, 38 insertions, 36 deletions
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp index 8087880f66..b2b9443fc6 100644 --- a/src/qmlcompiler/qqmljsscope.cpp +++ b/src/qmlcompiler/qqmljsscope.cpp @@ -42,9 +42,9 @@ QQmlJSScope::Ptr QQmlJSScope::create(ScopeType type, const QQmlJSScope::Ptr &par { QQmlJSScope::Ptr childScope(new QQmlJSScope{type, parentScope}); if (parentScope) { - Q_ASSERT(type != ScopeType::QMLScope + Q_ASSERT(type != QQmlJSScope::QMLScope || !parentScope->m_parentScope - || parentScope->parentScope()->m_scopeType == ScopeType::QMLScope + || parentScope->parentScope()->m_scopeType == QQmlJSScope::QMLScope || parentScope->parentScope()->m_internalName == QLatin1String("global")); parentScope->m_childScopes.push_back(childScope); } @@ -53,14 +53,14 @@ QQmlJSScope::Ptr QQmlJSScope::create(ScopeType type, const QQmlJSScope::Ptr &par void QQmlJSScope::insertJSIdentifier(const QString &name, const JavaScriptIdentifier &identifier) { - Q_ASSERT(m_scopeType != ScopeType::QMLScope); + Q_ASSERT(m_scopeType != QQmlJSScope::QMLScope); if (identifier.kind == JavaScriptIdentifier::LexicalScoped || identifier.kind == JavaScriptIdentifier::Injected - || m_scopeType == ScopeType::JSFunctionScope) { + || m_scopeType == QQmlJSScope::JSFunctionScope) { m_jsIdentifiers.insert(name, identifier); } else { auto targetScope = parentScope(); - while (targetScope->m_scopeType != ScopeType::JSFunctionScope) + while (targetScope->m_scopeType != QQmlJSScope::JSFunctionScope) targetScope = targetScope->parentScope(); targetScope->m_jsIdentifiers.insert(name, identifier); } @@ -80,7 +80,7 @@ bool QQmlJSScope::isIdInCurrentScope(const QString &id) const bool QQmlJSScope::isIdInCurrentQMlScopes(const QString &id) const { - if (m_scopeType == ScopeType::QMLScope) + if (m_scopeType == QQmlJSScope::QMLScope) return m_properties.contains(id) || m_methods.contains(id) || m_enums.contains(id); const auto qmlScope = findCurrentQMLScope(parentScope()); @@ -91,11 +91,11 @@ bool QQmlJSScope::isIdInCurrentQMlScopes(const QString &id) const bool QQmlJSScope::isIdInCurrentJSScopes(const QString &id) const { - if (m_scopeType != ScopeType::QMLScope && m_jsIdentifiers.contains(id)) + if (m_scopeType != QQmlJSScope::QMLScope && m_jsIdentifiers.contains(id)) return true; for (auto jsScope = parentScope(); jsScope; jsScope = jsScope->parentScope()) { - if (jsScope->m_scopeType != ScopeType::QMLScope && jsScope->m_jsIdentifiers.contains(id)) + if (jsScope->m_scopeType != QQmlJSScope::QMLScope && jsScope->m_jsIdentifiers.contains(id)) return true; } @@ -108,11 +108,12 @@ bool QQmlJSScope::isIdInjectedFromSignal(const QString &id) const return found.has_value() && found->kind == JavaScriptIdentifier::Injected; } -std::optional<JavaScriptIdentifier> QQmlJSScope::findJSIdentifier(const QString &id) const +std::optional<QQmlJSScope::JavaScriptIdentifier> +QQmlJSScope::findJSIdentifier(const QString &id) const { for (const auto *scope = this; scope; scope = scope->parentScope().data()) { - if (scope->m_scopeType == ScopeType::JSFunctionScope - || scope->m_scopeType == ScopeType::JSLexicalScope) { + if (scope->m_scopeType == QQmlJSScope::JSFunctionScope + || scope->m_scopeType == QQmlJSScope::JSLexicalScope) { auto it = scope->m_jsIdentifiers.find(id); if (it != scope->m_jsIdentifiers.end()) return *it; @@ -153,7 +154,7 @@ void QQmlJSScope::resolveTypes(const QHash<QString, QQmlJSScope::ConstPtr> &cont QQmlJSScope::ConstPtr QQmlJSScope::findCurrentQMLScope(const QQmlJSScope::ConstPtr &scope) { auto qmlScope = scope; - while (qmlScope && qmlScope->m_scopeType != ScopeType::QMLScope) + while (qmlScope && qmlScope->m_scopeType != QQmlJSScope::QMLScope) qmlScope = qmlScope->parentScope(); return qmlScope; } diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h index 9e0cfcd079..0de0a58401 100644 --- a/src/qmlcompiler/qqmljsscope_p.h +++ b/src/qmlcompiler/qqmljsscope_p.h @@ -52,25 +52,6 @@ QT_BEGIN_NAMESPACE -enum class ScopeType -{ - JSFunctionScope, - JSLexicalScope, - QMLScope -}; - -struct JavaScriptIdentifier -{ - enum Kind { - Parameter, - FunctionScoped, - LexicalScoped, - Injected - }; - - Kind kind = FunctionScoped; - QQmlJS::SourceLocation location; -}; class QQmlJSScope { @@ -81,6 +62,13 @@ public: using ConstPtr = QSharedPointer<const QQmlJSScope>; using WeakConstPtr = QWeakPointer<const QQmlJSScope>; + enum ScopeType + { + JSFunctionScope, + JSLexicalScope, + QMLScope + }; + enum class AccessSemantics { Reference, Value, @@ -119,7 +107,20 @@ public: int m_metaObjectRevision = 0; }; - static QQmlJSScope::Ptr create(ScopeType type = ScopeType::QMLScope, + struct JavaScriptIdentifier + { + enum Kind { + Parameter, + FunctionScoped, + LexicalScoped, + Injected + }; + + Kind kind = FunctionScoped; + QQmlJS::SourceLocation location; + }; + + static QQmlJSScope::Ptr create(ScopeType type = QQmlJSScope::QMLScope, const QQmlJSScope::Ptr &parentScope = QQmlJSScope::Ptr()); static QQmlJSScope::ConstPtr findCurrentQMLScope(const QQmlJSScope::ConstPtr &scope); @@ -209,7 +210,7 @@ private: QString m_baseTypeName; QQmlJSScope::WeakConstPtr m_baseType; - ScopeType m_scopeType = ScopeType::QMLScope; + ScopeType m_scopeType = QMLScope; QList<Export> m_exports; QString m_defaultPropertyName; diff --git a/src/qmlcompiler/qqmljstypereader.cpp b/src/qmlcompiler/qqmljstypereader.cpp index 0974e16050..90293e3e5f 100644 --- a/src/qmlcompiler/qqmljstypereader.cpp +++ b/src/qmlcompiler/qqmljstypereader.cpp @@ -71,7 +71,7 @@ static QList<QQmlJSTypeReader::Import> parseHeaders(QQmlJS::AST::UiHeaderItemLis static QQmlJSScope::Ptr parseProgram(QQmlJS::AST::Program *program, const QString &name) { using namespace QQmlJS::AST; - QQmlJSScope::Ptr result = QQmlJSScope::create(ScopeType::JSLexicalScope); + QQmlJSScope::Ptr result = QQmlJSScope::create(QQmlJSScope::JSLexicalScope); result->setInternalName(name); for (auto *statement = program->statements; statement; statement = statement->next) { if (auto *function = cast<FunctionDeclaration *>(statement->statement)) { @@ -103,7 +103,7 @@ QQmlJSScope::Ptr QQmlJSTypeReader::operator()() QFile file(m_file); if (!file.open(QFile::ReadOnly)) { QQmlJSScope::Ptr result = QQmlJSScope::create( - isJavaScript ? ScopeType::JSLexicalScope : ScopeType::QMLScope); + isJavaScript ? QQmlJSScope::JSLexicalScope : QQmlJSScope::QMLScope); result->setInternalName(scopeName); return result; } @@ -119,7 +119,7 @@ QQmlJSScope::Ptr QQmlJSTypeReader::operator()() : parser.parse(); if (!success) { QQmlJSScope::Ptr result = QQmlJSScope::create( - isJavaScript ? ScopeType::JSLexicalScope : ScopeType::QMLScope); + isJavaScript ? QQmlJSScope::JSLexicalScope : QQmlJSScope::QMLScope); result->setInternalName(scopeName); return result; } |