aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-11-12 10:00:41 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-11-12 11:55:49 +0100
commitc6452857a96d24325906ebd5529cfdda916a68fc (patch)
tree46486b757347707029ed6a53cf362f3a13ca8cb7 /src
parentf8f0eff273ba832f8b8ae8b27d4d3cf7a2d2efb7 (diff)
QmlCompiler: Store values QQmlJSMetaEnum when available
When parsing QML files, we need to keep the enum values around as this is the only place where we can find them (without parsing the same file again, that is). With C++ types we don't strictly need them as they are also available from the C++ header, but if the qmltypes file is nice enough to provide them, we can use them. (Which will be for types that are not actually C++ types, but rather types produced by registering a QML file with qmlRegisterType()). Change-Id: Ibcc93b30e523a00e1eeb80029943c48b83d0e1b5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp4
-rw-r--r--src/qmlcompiler/qqmljsmetatypes_p.h8
-rw-r--r--src/qmlcompiler/qqmljstypedescriptionreader.cpp15
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;
}
}