diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-12 10:00:41 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-12 11:55:49 +0100 |
commit | c6452857a96d24325906ebd5529cfdda916a68fc (patch) | |
tree | 46486b757347707029ed6a53cf362f3a13ca8cb7 /src/qmlcompiler/qqmljstypedescriptionreader.cpp | |
parent | f8f0eff273ba832f8b8ae8b27d4d3cf7a2d2efb7 (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/qmlcompiler/qqmljstypedescriptionreader.cpp')
-rw-r--r-- | src/qmlcompiler/qqmljstypedescriptionreader.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
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; } } |