diff options
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 4 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsmetatypes_p.h | 8 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljstypedescriptionreader.cpp | 15 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index b81f7b59a7..41e8b4da88 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -281,8 +281,10 @@ void QQmlJSImportVisitor::endVisit(UiScriptBinding *scriptBinding) bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiEnumDeclaration *uied) { QQmlJSMetaEnum qmlEnum(uied->name.toString()); - for (const auto *member = uied->members; member; member = member->next) + for (const auto *member = uied->members; member; member = member->next) { qmlEnum.addKey(member->member.toString()); + qmlEnum.addValue(int(member->value)); + } m_currentScope->addEnumeration(qmlEnum); return true; } diff --git a/src/qmlcompiler/qqmljsmetatypes_p.h b/src/qmlcompiler/qqmljsmetatypes_p.h index dcb388abfb..86a49c89c7 100644 --- a/src/qmlcompiler/qqmljsmetatypes_p.h +++ b/src/qmlcompiler/qqmljsmetatypes_p.h @@ -59,6 +59,7 @@ class QQmlJSScope; class QQmlJSMetaEnum { QStringList m_keys; + QList<int> m_values; // empty if values unknown. QString m_name; QString m_alias; bool m_isFlag = false; @@ -80,6 +81,13 @@ public: void addKey(const QString &key) { m_keys.append(key); } QStringList keys() const { return m_keys; } + + void addValue(int value) { m_values.append(value); } + QList<int> values() const { return m_values; } + + bool hasValues() const { return !m_values.isEmpty(); } + int value(const QString &key) const { return m_values.value(m_keys.indexOf(key)); } + bool hasKey(const QString &key) const { return m_keys.indexOf(key) != -1; } }; class QQmlJSMetaMethod diff --git a/src/qmlcompiler/qqmljstypedescriptionreader.cpp b/src/qmlcompiler/qqmljstypedescriptionreader.cpp index 0a5c97c3db..8bdfd89370 100644 --- a/src/qmlcompiler/qqmljstypedescriptionreader.cpp +++ b/src/qmlcompiler/qqmljstypedescriptionreader.cpp @@ -677,10 +677,25 @@ void QQmlJSTypeDescriptionReader::readEnumValues(UiScriptBinding *ast, QQmlJSMet } if (auto *objectLit = cast<ObjectPattern *>(expStmt->expression)) { + int currentValue = -1; for (PatternPropertyList *it = objectLit->properties; it; it = it->next) { if (PatternProperty *assignement = it->property) { if (auto *name = cast<StringLiteralPropertyName *>(assignement->name)) { metaEnum->addKey(name->id.toString()); + + if (auto *value = AST::cast<NumericLiteral *>(assignement->initializer)) { + currentValue = int(value->value); + } else if (auto *minus = AST::cast<UnaryMinusExpression *>( + assignement->initializer)) { + if (auto *value = AST::cast<NumericLiteral *>(minus->expression)) + currentValue = -int(value->value); + else + ++currentValue; + } else { + ++currentValue; + } + + metaEnum->addValue(currentValue); continue; } } |