6#include <QtQml/private/qqmljsparser_p.h>
7#include <QtQml/private/qqmljslexer_p.h>
8#include <QtQml/private/qqmljsengine_p.h>
10#include <QtCore/qdir.h>
11#include <QtCore/qstring.h>
24 if (
iter != qualifiedId)
34 QList<QQmlJSExportedScope> *objects,
QStringList *dependencies)
41 lexer.
setCode(m_source, 1,
true);
43 if (!parser.
parse()) {
47 parser.errorMessage());
52 m_dependencies = dependencies;
53 readDocument(parser.ast());
55 return m_errorMessage.
isEmpty();
58void QQmlJSTypeDescriptionReader::readDocument(
UiProgram *ast)
72 addError(import->importToken,
tr(
"Expected import of QtQuick.tooling."));
76 if (!import->version) {
77 addError(import->firstSourceLocation(),
tr(
"Import statement without version."));
81 if (import->version->version.majorVersion() != 1) {
82 addError(import->version->firstSourceLocation(),
83 tr(
"Major version different from 1 not supported."));
88 addError(
SourceLocation(),
tr(
"Expected document to contain a single object definition."));
92 auto *
module = cast<UiObjectDefinition *>(ast->members->member);
94 addError(
SourceLocation(),
tr(
"Expected document to contain a single object definition."));
99 addError(
SourceLocation(),
tr(
"Expected document to contain a Module {} member."));
110 auto *
component = cast<UiObjectDefinition *>(member);
112 auto *script = cast<UiScriptBinding *>(member);
114 readDependencies(script);
149void QQmlJSTypeDescriptionReader::readDependencies(
UiScriptBinding *ast)
151 auto *stmt = cast<ExpressionStatement*>(ast->
statement);
156 auto *exp = cast<ArrayPattern *>(stmt->expression);
158 addError(stmt->expression->firstSourceLocation(),
tr(
"Expected dependency definitions"));
162 auto *
str = cast<StringLiteral *>(l->element->initializer);
163 *m_dependencies <<
str->value.toString();
169 m_currentCtorIndex = 0;
171 QList<QQmlJSScope::Export> exports;
176 auto *
component = cast<UiObjectDefinition *>(member);
177 auto *script = cast<UiScriptBinding *>(member);
187 addWarning(
component->firstSourceLocation(),
188 tr(
"Expected only Property, Method, Signal and Enum object definitions, "
203 exports = readExports(script);
205 readAliases(script, scope);
207 readInterfaces(script, scope);
209 metaObjectRevisions = script;
225 const QString semantics = readStringBinding(script);
235 addWarning(script->firstSourceLocation(),
236 tr(
"Unknown access semantics \"%1\".").
arg(semantics));
245 readDeferredNames(script, scope);
247 readImmediateNames(script, scope);
249 addWarning(script->firstSourceLocation(),
250 tr(
"Expected only name, prototype, defaultProperty, attachedType, "
251 "valueType, exports, interfaces, isSingleton, isCreatable, "
252 "isStructured, isComposite, hasCustomParser, aliases, "
253 "exportMetaObjectRevisions, deferredNames, and immediateNames "
254 "in script bindings, not \"%1\".")
259 tr(
"Expected only script bindings and object definitions."));
268 if (metaObjectRevisions)
269 checkMetaObjectRevisions(metaObjectRevisions, &exports);
270 m_objects->append({scope, exports});
273void QQmlJSTypeDescriptionReader::readSignalOrMethod(
285 auto *
component = cast<UiObjectDefinition *>(member);
286 auto *script = cast<UiScriptBinding *>(member);
292 addWarning(
component->firstSourceLocation(),
293 tr(
"Expected only Parameter in object definitions."));
309 if (readBoolBinding(script)) {
318 metaReturnType.
setIsList(readBoolBinding(script));
334 addWarning(script->firstSourceLocation(),
335 tr(
"Expected only name, type, revision, isPointer, isConstant, "
336 "isList, isCloned, isConstructor, and isJavaScriptFunction "
337 "in script bindings."));
341 tr(
"Expected only script bindings and object definitions."));
347 tr(
"Method or signal is missing a name script binding."));
357 property.setIsWritable(
true);
358 bool isRequired =
false;
362 auto *script = cast<UiScriptBinding *>(member);
370 property.setPropertyName(readStringBinding(script));
372 property.setTypeName(readStringBinding(script));
374 property.setIsPointer(readBoolBinding(script));
376 property.setIsWritable(!readBoolBinding(script));
378 isRequired = readBoolBinding(script);
380 property.setIsList(readBoolBinding(script));
382 property.setIsFinal(readBoolBinding(script));
384 property.setIsConstant(readBoolBinding(script));
386 property.setRevision(readIntBinding(script));
388 property.setBindable(readStringBinding(script));
390 property.setRead(readStringBinding(script));
392 property.setWrite(readStringBinding(script));
394 property.setReset(readStringBinding(script));
396 property.setNotify(readStringBinding(script));
398 property.setIndex(readIntBinding(script));
400 property.setPrivateClass(readStringBinding(script));
402 addWarning(script->firstSourceLocation(),
403 tr(
"Expected only type, name, revision, isPointer, isReadonly, isRequired, "
404 "isFinal, isList, bindable, read, write, reset, notify, index, and "
405 "privateClass and script bindings."));
409 if (
property.propertyName().isEmpty()) {
411 tr(
"Property object is missing a name script binding."));
426 auto *script = cast<UiScriptBinding *>(member);
434 metaEnum.setName(readStringBinding(script));
436 metaEnum.setAlias(readStringBinding(script));
438 metaEnum.setIsFlag(readBoolBinding(script));
440 readEnumValues(script, &metaEnum);
442 metaEnum.setIsScoped(readBoolBinding(script));
444 metaEnum.setTypeName(readStringBinding(script));
446 addWarning(script->firstSourceLocation(),
447 tr(
"Expected only name, alias, isFlag, values, isScoped, or type."));
458 bool isConstant =
false;
459 bool isPointer =
false;
464 auto *script = cast<UiScriptBinding *>(member);
472 name = readStringBinding(script);
474 type = readStringBinding(script);
476 isPointer = readBoolBinding(script);
478 isConstant = readBoolBinding(script);
482 isList = readBoolBinding(script);
484 addWarning(script->firstSourceLocation(),
485 tr(
"Expected only name, type, isPointer, isConstant, isReadonly, "
486 "or IsList script bindings."));
492 p.setIsPointer(isPointer);
502 addError(ast->
colonToken,
tr(
"Expected string after colon."));
506 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
512 auto *stringLit = cast<StringLiteral *>(expStmt->expression);
514 addError(expStmt->firstSourceLocation(),
tr(
"Expected string after colon."));
518 return stringLit->value.toString();
526 addError(ast->
colonToken,
tr(
"Expected boolean after colon."));
530 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
536 auto *trueLit = cast<TrueLiteral *>(expStmt->expression);
537 auto *falseLit = cast<FalseLiteral *>(expStmt->expression);
538 if (!trueLit && !falseLit) {
539 addError(expStmt->firstSourceLocation(),
tr(
"Expected true or false after colon."));
546double QQmlJSTypeDescriptionReader::readNumericBinding(
UiScriptBinding *ast)
551 addError(ast->
colonToken,
tr(
"Expected numeric literal after colon."));
555 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
558 tr(
"Expected numeric literal after colon."));
562 auto *numericLit = cast<NumericLiteral *>(expStmt->expression);
564 addError(expStmt->firstSourceLocation(),
tr(
"Expected numeric literal after colon."));
568 return numericLit->value;
592 tr(
"Expected numeric literal after colon."));
593 return invalidVersion;
596 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
599 tr(
"Expected numeric literal after colon."));
600 return invalidVersion;
603 auto *numericLit = cast<NumericLiteral *>(expStmt->expression);
605 addError(expStmt->firstSourceLocation(),
tr(
"Expected numeric literal after colon."));
606 return invalidVersion;
610 numericLit->literalToken.length));
615 double v = readNumericBinding(ast);
616 int i =
static_cast<int>(
v);
631 addError(ast->
colonToken,
tr(
"Expected array of strings after colon."));
635 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
638 tr(
"Expected array of strings after colon."));
642 auto *arrayLit = cast<ArrayPattern *>(expStmt->expression);
644 addError(expStmt->firstSourceLocation(),
tr(
"Expected array of strings after colon."));
651QList<QQmlJSScope::Export> QQmlJSTypeDescriptionReader::readExports(
UiScriptBinding *ast)
653 QList<QQmlJSScope::Export> exports;
654 auto *arrayLit = getArray(ast);
660 auto *stringLit = cast<StringLiteral *>(
it->element->initializer);
663 addError(arrayLit->firstSourceLocation(),
664 tr(
"Expected array literal with only string literal members."));
668 QString exp = stringLit->value.toString();
673 if (spaceIdx == -1 || !version.
isValid()) {
674 addError(stringLit->firstSourceLocation(),
675 tr(
"Expected string literal to contain 'Package/Name major.minor' "
676 "or 'Name major.minor'."));
681 package = exp.left(slashIdx);
691void QQmlJSTypeDescriptionReader::readAliases(
699 auto *arrayLit = getArray(ast);
707 auto *stringLit = cast<StringLiteral *>(
it->element->initializer);
709 addError(arrayLit->firstSourceLocation(),
710 tr(
"Expected array literal with only string literal members."));
720void QQmlJSTypeDescriptionReader::checkMetaObjectRevisions(
726 addError(ast->
colonToken,
tr(
"Expected array of numbers after colon."));
730 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
733 tr(
"Expected array of numbers after colon."));
737 auto *arrayLit = cast<ArrayPattern *>(expStmt->expression);
739 addError(expStmt->firstSourceLocation(),
tr(
"Expected array of numbers after colon."));
744 const int exportCount = exports->size();
746 auto *numberLit = cast<NumericLiteral *>(
it->element->initializer);
748 addError(arrayLit->firstSourceLocation(),
749 tr(
"Expected array literal with only number literal members."));
753 if (exportIndex >= exportCount) {
754 addError(numberLit->firstSourceLocation(),
755 tr(
"Meta object revision without matching export."));
759 const double v = numberLit->value;
760 const int metaObjectRevision =
static_cast<int>(
v);
761 if (metaObjectRevision !=
v) {
762 addError(numberLit->firstSourceLocation(),
tr(
"Expected integer."));
770 if (metaObjectVersion != exportVersion) {
771 addWarning(numberLit->firstSourceLocation(),
772 tr(
"Meta object revision and export version differ.\n"
773 "Revision %1 corresponds to version %2.%3; it should be %4.%5.")
774 .
arg(metaObjectRevision)
775 .
arg(metaObjectVersion.majorVersion()).arg(metaObjectVersion.minorVersion())
776 .arg(exportVersion.majorVersion()).arg(exportVersion.minorVersion()));
778 exportVersion, metaObjectVersion);
785 auto *arrayLit = getArray(ast);
792 auto *stringLit = cast<StringLiteral *>(
it->element->initializer);
794 addError(arrayLit->firstSourceLocation(),
795 tr(
"Expected array literal with only string literal members."));
805void QQmlJSTypeDescriptionReader::readDeferredNames(
UiScriptBinding *ast,
811void QQmlJSTypeDescriptionReader::readImmediateNames(
UiScriptBinding *ast,
822 addError(ast->
colonToken,
tr(
"Expected object literal after colon."));
826 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
832 if (
auto *objectLit = cast<ObjectPattern *>(expStmt->expression)) {
836 if (
auto *
name = cast<StringLiteralPropertyName *>(assignement->name)) {
837 metaEnum->addKey(
name->id.toString());
839 if (
auto *
value = AST::cast<NumericLiteral *>(assignement->initializer)) {
841 }
else if (
auto *minus = AST::cast<UnaryMinusExpression *>(
842 assignement->initializer)) {
843 if (
auto *
value = AST::cast<NumericLiteral *>(minus->expression))
855 addError(
it->firstSourceLocation(),
tr(
"Expected strings as enum keys."));
857 }
else if (
auto *arrayLit = cast<ArrayPattern *>(expStmt->expression)) {
860 if (
auto *
name = cast<StringLiteral *>(element->initializer)) {
861 metaEnum->addKey(
name->value.toString());
865 addError(
it->firstSourceLocation(),
tr(
"Expected strings as enum keys."));
869 tr(
"Expected either array or object literal as enum definition."));
void parse(QIODevice &input, const QString &name)
static QString toNativeSeparators(const QString &pathName)
T value(qsizetype i) const
void setIsComposite(bool v)
void setOwnDeferredNames(const QStringList &names)
void setExtensionTypeName(const QString &name)
void setExtensionIsJavaScript(bool v)
void setInterfaceNames(const QStringList &interfaces)
static QQmlJSScope::Ptr create()
void setStructuredFlag(bool v)
void setAccessSemantics(AccessSemantics semantics)
void setOwnParentPropertyName(const QString &name)
void setOwnAttachedTypeName(const QString &name)
void setInternalName(const QString &internalName)
QString internalName() const
void setHasCustomParser(bool v)
void setIsSingleton(bool v)
void addOwnProperty(const QQmlJSMetaProperty &prop)
void setExtensionIsNamespace(bool v)
void setAliases(const QStringList &aliases)
void setBaseTypeName(const QString &baseTypeName)
void setValueTypeName(const QString &name)
void setOwnImmediateNames(const QStringList &names)
void addOwnEnumeration(const QQmlJSMetaEnum &enumeration)
void addOwnMethod(const QQmlJSMetaMethod &method)
void setCreatableFlag(bool v)
void setOwnDefaultPropertyName(const QString &name)
void setFilePath(const QString &file)
void setPropertyLocallyRequired(const QString &name, bool isRequired)
bool operator()(QList< QQmlJSExportedScope > *objects, QStringList *dependencies)
virtual SourceLocation firstSourceLocation() const =0
SourceLocation firstSourceLocation() const override
UiObjectInitializer * initializer
UiObjectMemberList * members
UiObjectMemberList * next
SourceLocation firstSourceLocation() const override=0
UiHeaderItemList * headers
UiObjectMemberList * members
SourceLocation firstSourceLocation() const override
SourceLocation colonToken
void setCode(const QString &code, int lineno, bool qmlMode=true, CodeContinuation codeContinuation=CodeContinuation::Reset)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString left(qsizetype n) const &
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString mid(qsizetype position, qsizetype n=-1) const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static constexpr QTypeRevision fromVersion(Major majorVersion, Minor minorVersion)
Produces a QTypeRevision from the given majorVersion and minorVersion, both of which need to be a val...
constexpr bool isValid() const
Returns true if the major version or the minor version is known, otherwise false.
static constexpr QTypeRevision fromEncodedVersion(Integer value)
Produces a QTypeRevision from the given value.
QSet< QString >::iterator it
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter * iter
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
GLuint GLsizei const GLchar * message
static qreal component(const QPointF &point, unsigned int i)
static QTypeRevision parseVersion(const QString &str)
static QTypeRevision parseVersion(const QString &versionString)
QString toString(const UiQualifiedId *qualifiedId, QChar delimiter=QLatin1Char('.'))
QLatin1StringView QLatin1String
#define QStringLiteral(str)
char * toString(const MyType &t)
[31]
\inmodule QtCore \reentrant