diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-08-29 10:38:36 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-09-30 08:24:30 +0000 |
commit | b5b1367b0b37133c9666a5d20c95d53e5e6d6a43 (patch) | |
tree | 7ec23b1e40957f3dec907ff21548c571689540f2 /src/libs/qmljs/qmljstypedescriptionreader.cpp | |
parent | 1bf23a6c74c18b1f89d17cbc9bfc2f93056020bc (diff) |
Accept arrays as enum descriptions in qmltypes files
We don't use the values at all and they are hard to determine
statically. Qt >= 5.15 will generated arrays instead of objects.
Change-Id: I3b3bbd427c49e649ca3f9cef51c89b32e830eb66
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src/libs/qmljs/qmljstypedescriptionreader.cpp')
-rw-r--r-- | src/libs/qmljs/qmljstypedescriptionreader.cpp | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/libs/qmljs/qmljstypedescriptionreader.cpp b/src/libs/qmljs/qmljstypedescriptionreader.cpp index 895922a1eb8..152432ca7be 100644 --- a/src/libs/qmljs/qmljstypedescriptionreader.cpp +++ b/src/libs/qmljs/qmljstypedescriptionreader.cpp @@ -649,39 +649,34 @@ void TypeDescriptionReader::readEnumValues(AST::UiScriptBinding *ast, LanguageUt return; } - ExpressionStatement *expStmt = AST::cast<ExpressionStatement *>(ast->statement); + auto *expStmt = AST::cast<ExpressionStatement *>(ast->statement); if (!expStmt) { - addError(ast->statement->firstSourceLocation(), tr("Expected object literal after colon.")); - return; - } - - ObjectPattern *objectLit = AST::cast<ObjectPattern *>(expStmt->expression); - if (!objectLit) { - addError(expStmt->firstSourceLocation(), tr("Expected object literal after colon.")); + addError(ast->statement->firstSourceLocation(), tr("Expected expression after colon.")); return; } - for (PatternPropertyList *it = objectLit->properties; it; it = it->next) { - PatternProperty *assignement = AST::cast<PatternProperty *>(it->property); - if (assignement) { - StringLiteralPropertyName *propName = AST::cast<StringLiteralPropertyName *>(assignement->name); - NumericLiteral *value = AST::cast<NumericLiteral *>(assignement->initializer); - UnaryMinusExpression *minus = AST::cast<UnaryMinusExpression *>(assignement->initializer); - if (minus) - value = AST::cast<NumericLiteral *>(minus->expression); - if (!propName || !value) { - addError(objectLit->firstSourceLocation(), tr("Expected object literal to contain only 'string: number' elements.")); - continue; + if (auto *objectLit = AST::cast<ObjectPattern *>(expStmt->expression)) { + for (PatternPropertyList *it = objectLit->properties; it; it = it->next) { + if (PatternProperty *assignement = it->property) { + if (auto *name = AST::cast<StringLiteralPropertyName *>(assignement->name)) { + fme->addKey(name->id.toString()); + continue; + } } - - double v = value->value; - if (minus) - v = -v; - fme->addKey(propName->id.toString(), v); - continue; + addError(it->firstSourceLocation(), tr("Expected strings as enum keys.")); + } + } else if (auto *arrayLit = AST::cast<ArrayPattern *>(expStmt->expression)) { + for (PatternElementList *it = arrayLit->elements; it; it = it->next) { + if (PatternElement *element = it->element) { + if (auto *name = AST::cast<StringLiteral *>(element->initializer)) { + fme->addKey(name->value.toString()); + continue; + } + } + addError(it->firstSourceLocation(), tr("Expected strings as enum keys.")); } - PatternPropertyList *getterSetter = AST::cast<PatternPropertyList *>(it->next); - if (getterSetter) - addError(objectLit->firstSourceLocation(), tr("Enum should not contain getter and setters, but only 'string: number' elements.")); + } else { + addError(ast->statement->firstSourceLocation(), + tr("Expected either array or object literal as enum definition.")); } } |