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)
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;
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 readInterfaces(script, scope);
207 metaObjectRevisions = script;
223 const QString semantics = readStringBinding(script);
233 addWarning(script->firstSourceLocation(),
234 tr(
"Unknown access semantics \"%1\".").
arg(semantics));
241 readDeferredNames(script, scope);
243 readImmediateNames(script, scope);
245 addWarning(script->firstSourceLocation(),
246 tr(
"Expected only name, prototype, defaultProperty, attachedType, "
247 "valueType, exports, interfaces, isSingleton, isCreatable, "
248 "isStructured, isComposite, hasCustomParser, "
249 "exportMetaObjectRevisions, deferredNames, and immediateNames "
250 "in script bindings, not \"%1\".")
255 tr(
"Expected only script bindings and object definitions."));
264 if (metaObjectRevisions)
265 checkMetaObjectRevisions(metaObjectRevisions, &exports);
266 m_objects->append({scope, exports});
269void QQmlJSTypeDescriptionReader::readSignalOrMethod(
281 auto *
component = cast<UiObjectDefinition *>(member);
282 auto *script = cast<UiScriptBinding *>(member);
288 addWarning(
component->firstSourceLocation(),
289 tr(
"Expected only Parameter in object definitions."));
319 addWarning(script->firstSourceLocation(),
320 tr(
"Expected only name, type, revision, isPointer, isList, "
321 "isCloned, isConstructor, and "
322 "isJavaScriptFunction in script bindings."));
326 tr(
"Expected only script bindings and object definitions."));
332 tr(
"Method or signal is missing a name script binding."));
342 property.setIsWritable(
true);
343 bool isRequired =
false;
347 auto *script = cast<UiScriptBinding *>(member);
355 property.setPropertyName(readStringBinding(script));
357 property.setTypeName(readStringBinding(script));
359 property.setIsPointer(readBoolBinding(script));
361 property.setIsWritable(!readBoolBinding(script));
363 isRequired = readBoolBinding(script);
365 property.setIsList(readBoolBinding(script));
367 property.setIsFinal(readBoolBinding(script));
369 property.setIsConstant(readBoolBinding(script));
371 property.setRevision(readIntBinding(script));
373 property.setBindable(readStringBinding(script));
375 property.setRead(readStringBinding(script));
377 property.setWrite(readStringBinding(script));
379 property.setReset(readStringBinding(script));
381 property.setNotify(readStringBinding(script));
383 property.setIndex(readIntBinding(script));
385 property.setPrivateClass(readStringBinding(script));
387 addWarning(script->firstSourceLocation(),
388 tr(
"Expected only type, name, revision, isPointer, isReadonly, isRequired, "
389 "isFinal, isList, bindable, read, write, reset, notify, index, and "
390 "privateClass and script bindings."));
394 if (
property.propertyName().isEmpty()) {
396 tr(
"Property object is missing a name script binding."));
411 auto *script = cast<UiScriptBinding *>(member);
419 metaEnum.
setName(readStringBinding(script));
421 metaEnum.
setAlias(readStringBinding(script));
423 metaEnum.
setIsFlag(readBoolBinding(script));
425 readEnumValues(script, &metaEnum);
427 metaEnum.
setScoped(readBoolBinding(script));
431 addWarning(script->firstSourceLocation(),
432 tr(
"Expected only name, alias, isFlag, values, scoped, or type."));
443 bool isConstant =
false;
444 bool isPointer =
false;
449 auto *script = cast<UiScriptBinding *>(member);
457 name = readStringBinding(script);
459 type = readStringBinding(script);
461 isPointer = readBoolBinding(script);
463 isConstant = readBoolBinding(script);
467 isList = readBoolBinding(script);
469 addWarning(script->firstSourceLocation(),
470 tr(
"Expected only name, type, isPointer, isConstant, isReadonly, "
471 "or IsList script bindings."));
477 p.setIsPointer(isPointer);
487 addError(ast->
colonToken,
tr(
"Expected string after colon."));
491 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
497 auto *stringLit = cast<StringLiteral *>(expStmt->expression);
499 addError(expStmt->firstSourceLocation(),
tr(
"Expected string after colon."));
503 return stringLit->value.toString();
511 addError(ast->
colonToken,
tr(
"Expected boolean after colon."));
515 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
521 auto *trueLit = cast<TrueLiteral *>(expStmt->expression);
522 auto *falseLit = cast<FalseLiteral *>(expStmt->expression);
523 if (!trueLit && !falseLit) {
524 addError(expStmt->firstSourceLocation(),
tr(
"Expected true or false after colon."));
531double QQmlJSTypeDescriptionReader::readNumericBinding(
UiScriptBinding *ast)
536 addError(ast->
colonToken,
tr(
"Expected numeric literal after colon."));
540 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
543 tr(
"Expected numeric literal after colon."));
547 auto *numericLit = cast<NumericLiteral *>(expStmt->expression);
549 addError(expStmt->firstSourceLocation(),
tr(
"Expected numeric literal after colon."));
553 return numericLit->value;
577 tr(
"Expected numeric literal after colon."));
578 return invalidVersion;
581 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
584 tr(
"Expected numeric literal after colon."));
585 return invalidVersion;
588 auto *numericLit = cast<NumericLiteral *>(expStmt->expression);
590 addError(expStmt->firstSourceLocation(),
tr(
"Expected numeric literal after colon."));
591 return invalidVersion;
595 numericLit->literalToken.length));
600 double v = readNumericBinding(ast);
601 int i =
static_cast<int>(
v);
616 addError(ast->
colonToken,
tr(
"Expected array of strings after colon."));
620 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
623 tr(
"Expected array of strings after colon."));
627 auto *arrayLit = cast<ArrayPattern *>(expStmt->expression);
629 addError(expStmt->firstSourceLocation(),
tr(
"Expected array of strings after colon."));
639 auto *arrayLit = getArray(ast);
645 auto *stringLit = cast<StringLiteral *>(
it->element->initializer);
648 addError(arrayLit->firstSourceLocation(),
649 tr(
"Expected array literal with only string literal members."));
653 QString exp = stringLit->value.toString();
658 if (spaceIdx == -1 || !version.
isValid()) {
659 addError(stringLit->firstSourceLocation(),
660 tr(
"Expected string literal to contain 'Package/Name major.minor' "
661 "or 'Name major.minor'."));
666 package = exp.left(slashIdx);
678 auto *arrayLit = getArray(ast);
686 auto *stringLit = cast<StringLiteral *>(
it->element->initializer);
688 addError(arrayLit->firstSourceLocation(),
689 tr(
"Expected array literal with only string literal members."));
699void QQmlJSTypeDescriptionReader::checkMetaObjectRevisions(
705 addError(ast->
colonToken,
tr(
"Expected array of numbers after colon."));
709 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
712 tr(
"Expected array of numbers after colon."));
716 auto *arrayLit = cast<ArrayPattern *>(expStmt->expression);
718 addError(expStmt->firstSourceLocation(),
tr(
"Expected array of numbers after colon."));
723 const int exportCount = exports->
size();
725 auto *numberLit = cast<NumericLiteral *>(
it->element->initializer);
727 addError(arrayLit->firstSourceLocation(),
728 tr(
"Expected array literal with only number literal members."));
732 if (exportIndex >= exportCount) {
733 addError(numberLit->firstSourceLocation(),
734 tr(
"Meta object revision without matching export."));
738 const double v = numberLit->value;
739 const int metaObjectRevision =
static_cast<int>(
v);
740 if (metaObjectRevision !=
v) {
741 addError(numberLit->firstSourceLocation(),
tr(
"Expected integer."));
749 if (metaObjectVersion != exportVersion) {
750 addWarning(numberLit->firstSourceLocation(),
751 tr(
"Meta object revision and export version differ.\n"
752 "Revision %1 corresponds to version %2.%3; it should be %4.%5.")
753 .
arg(metaObjectRevision)
757 exportVersion, metaObjectVersion);
764 auto *arrayLit = getArray(ast);
771 auto *stringLit = cast<StringLiteral *>(
it->element->initializer);
773 addError(arrayLit->firstSourceLocation(),
774 tr(
"Expected array literal with only string literal members."));
784void QQmlJSTypeDescriptionReader::readDeferredNames(
UiScriptBinding *ast,
790void QQmlJSTypeDescriptionReader::readImmediateNames(
UiScriptBinding *ast,
801 addError(ast->
colonToken,
tr(
"Expected object literal after colon."));
805 auto *expStmt = cast<ExpressionStatement *>(ast->
statement);
811 if (
auto *objectLit = cast<ObjectPattern *>(expStmt->expression)) {
815 if (
auto *
name = cast<StringLiteralPropertyName *>(assignement->name)) {
818 if (
auto *
value = AST::cast<NumericLiteral *>(assignement->initializer)) {
820 }
else if (
auto *minus = AST::cast<UnaryMinusExpression *>(
821 assignement->initializer)) {
822 if (
auto *
value = AST::cast<NumericLiteral *>(minus->expression))
834 addError(
it->firstSourceLocation(),
tr(
"Expected strings as enum keys."));
836 }
else if (
auto *arrayLit = cast<ArrayPattern *>(expStmt->expression)) {
839 if (
auto *
name = cast<StringLiteral *>(element->initializer)) {
844 addError(
it->firstSourceLocation(),
tr(
"Expected strings as enum keys."));
848 tr(
"Expected either array or object literal as enum definition."));
void parse(QIODevice &input, const QString &name)
static QString toNativeSeparators(const QString &pathName)
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
void append(parameter_type t)
void setIsComposite(bool v)
void setOwnDeferredNames(const QStringList &names)
void setExtensionTypeName(const QString &name)
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 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
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 arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
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...
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
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...
static constexpr QTypeRevision fromEncodedVersion(Integer value)
Produces a QTypeRevision from the given value.
constexpr quint8 minorVersion() const
Returns the minor version encoded in the revision.
constexpr bool isValid() const
Returns true if the major version or the minor version is known, otherwise false.
constexpr quint8 majorVersion() const
Returns the major version encoded in the revision.
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