aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljstypedescriptionreader.cpp
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-11-20 13:20:52 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2020-11-23 10:06:41 +0100
commit588d624837ae0174139f8db930ad20612463b1dd (patch)
tree13ef2dba7f6cc9ec4f22fe517c2c16f01db3ad06 /src/qmlcompiler/qqmljstypedescriptionreader.cpp
parent87533900738d65ad278722b292852c998e987c10 (diff)
qmltyperegistrar: Expose interface information
Change-Id: Ica3f5c6696542921bc8d399cd46d901ba06f6d83 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljstypedescriptionreader.cpp')
-rw-r--r--src/qmlcompiler/qqmljstypedescriptionreader.cpp47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/qmlcompiler/qqmljstypedescriptionreader.cpp b/src/qmlcompiler/qqmljstypedescriptionreader.cpp
index 8bdfd89370..6f474bbe10 100644
--- a/src/qmlcompiler/qqmljstypedescriptionreader.cpp
+++ b/src/qmlcompiler/qqmljstypedescriptionreader.cpp
@@ -220,6 +220,8 @@ void QQmlJSTypeDescriptionReader::readComponent(UiObjectDefinition *ast)
scope->setDefaultPropertyName(readStringBinding(script));
} else if (name == QLatin1String("exports")) {
readExports(script, scope);
+ } else if (name == QLatin1String("interfaces")) {
+ readInterfaces(script, scope);
} else if (name == QLatin1String("exportMetaObjectRevisions")) {
readMetaObjectRevisions(script, scope);
} else if (name == QLatin1String("attachedType")) {
@@ -249,7 +251,7 @@ void QQmlJSTypeDescriptionReader::readComponent(UiObjectDefinition *ast)
} else {
addWarning(script->firstSourceLocation(),
tr("Expected only name, prototype, defaultProperty, attachedType, "
- "valueType, exports, isSingleton, isCreatable, isComposite and "
+ "valueType, exports, interfaces, isSingleton, isCreatable, isComposite and "
"exportMetaObjectRevisions script bindings, not \"%1\".").arg(name));
}
} else {
@@ -551,35 +553,47 @@ int QQmlJSTypeDescriptionReader::readIntBinding(UiScriptBinding *ast)
return i;
}
-void QQmlJSTypeDescriptionReader::readExports(UiScriptBinding *ast, const QQmlJSScope::Ptr &scope)
+ArrayPattern* QQmlJSTypeDescriptionReader::getArray(UiScriptBinding *ast)
{
Q_ASSERT(ast);
if (!ast->statement) {
addError(ast->colonToken, tr("Expected array of strings after colon."));
- return;
+ return nullptr;
}
auto *expStmt = cast<ExpressionStatement *>(ast->statement);
if (!expStmt) {
addError(ast->statement->firstSourceLocation(),
tr("Expected array of strings after colon."));
- return;
+ return nullptr;
}
auto *arrayLit = cast<ArrayPattern *>(expStmt->expression);
if (!arrayLit) {
addError(expStmt->firstSourceLocation(), tr("Expected array of strings after colon."));
- return;
+ return nullptr;
}
+ return arrayLit;
+}
+
+void QQmlJSTypeDescriptionReader::readExports(UiScriptBinding *ast, const QQmlJSScope::Ptr &scope)
+{
+ auto *arrayLit = getArray(ast);
+
+ if (!arrayLit)
+ return;
+
for (PatternElementList *it = arrayLit->elements; it; it = it->next) {
auto *stringLit = cast<StringLiteral *>(it->element->initializer);
+
if (!stringLit) {
addError(arrayLit->firstSourceLocation(),
tr("Expected array literal with only string literal members."));
return;
}
+
QString exp = stringLit->value.toString();
int slashIdx = exp.indexOf(QLatin1Char('/'));
int spaceIdx = exp.indexOf(QLatin1Char(' '));
@@ -601,6 +615,29 @@ void QQmlJSTypeDescriptionReader::readExports(UiScriptBinding *ast, const QQmlJS
}
}
+void QQmlJSTypeDescriptionReader::readInterfaces(UiScriptBinding *ast, const QQmlJSScope::Ptr &scope)
+{
+ auto *arrayLit = getArray(ast);
+
+ if (!arrayLit)
+ return;
+
+ QStringList list;
+
+ for (PatternElementList *it = arrayLit->elements; it; it = it->next) {
+ auto *stringLit = cast<StringLiteral *>(it->element->initializer);
+ if (!stringLit) {
+ addError(arrayLit->firstSourceLocation(),
+ tr("Expected array literal with only string literal members."));
+ return;
+ }
+
+ list << stringLit->value.toString();
+ }
+
+ scope->setInterfaceNames(list);
+}
+
void QQmlJSTypeDescriptionReader::readMetaObjectRevisions(UiScriptBinding *ast,
const QQmlJSScope::Ptr &scope)
{