forked from qt-creator/qt-creator
qmljs: update Qml parser to parser of Qt 6.2
this is needed (among other things) for * null coalescing * shebang support Change-Id: I1b37fd86593f143de8b39c0daf433831a8785568 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
@@ -4,6 +4,7 @@ add_qtc_library(QmlJS
|
||||
SOURCES
|
||||
jsoncheck.cpp jsoncheck.h
|
||||
parser/qmldirparser.cpp parser/qmldirparser_p.h
|
||||
parser/qmlimportresolver.cpp parser/qmlimportresolver_p.h
|
||||
parser/qmljsast.cpp parser/qmljsast_p.h
|
||||
parser/qmljsastfwd_p.h
|
||||
parser/qmljsastvisitor.cpp parser/qmljsastvisitor_p.h
|
||||
|
@@ -3,6 +3,7 @@ HEADERS += \
|
||||
$$PWD/qmljsastfwd_p.h \
|
||||
$$PWD/qmljsastvisitor_p.h \
|
||||
$$PWD/qmljsengine_p.h \
|
||||
$$PWD/qmlimportresolver_p.h \
|
||||
$$PWD/qmljslexer_p.h \
|
||||
$$PWD/qmljsglobal_p.h \
|
||||
$$PWD/qmljssourcelocation_p.h \
|
||||
@@ -16,6 +17,7 @@ SOURCES += \
|
||||
$$PWD/qmljsast.cpp \
|
||||
$$PWD/qmljsastvisitor.cpp \
|
||||
$$PWD/qmljsengine_p.cpp \
|
||||
$$PWD/qmlimportresolver.cpp \
|
||||
$$PWD/qmljslexer.cpp \
|
||||
$$PWD/qmldirparser.cpp \
|
||||
$$PWD/qmljsgrammar.cpp \
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -102,7 +102,7 @@ void QmlDirParser::clear()
|
||||
_plugins.clear();
|
||||
_designerSupported = false;
|
||||
_typeInfos.clear();
|
||||
_className.clear();
|
||||
_classNames.clear();
|
||||
}
|
||||
|
||||
inline static void scanSpace(const QChar *&ch) {
|
||||
@@ -258,7 +258,6 @@ bool QmlDirParser::parse(const QString &source)
|
||||
"not %1.").arg(sections[1]));
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if (sections[0] == QLatin1String("classname")) {
|
||||
if (sectionCount < 2) {
|
||||
reportError(lineNumber, 0,
|
||||
@@ -267,7 +266,7 @@ bool QmlDirParser::parse(const QString &source)
|
||||
continue;
|
||||
}
|
||||
|
||||
_className = sections[1];
|
||||
_classNames.append(sections[1]);
|
||||
|
||||
} else if (sections[0] == QLatin1String("internal")) {
|
||||
if (sectionCount != 3) {
|
||||
@@ -308,19 +307,38 @@ bool QmlDirParser::parse(const QString &source)
|
||||
QStringLiteral("typeinfo requires 1 argument, but %1 were provided").arg(sectionCount - 1));
|
||||
continue;
|
||||
}
|
||||
#ifdef QT_CREATOR
|
||||
TypeInfo typeInfo(sections[1]);
|
||||
_typeInfos.append(typeInfo);
|
||||
#endif
|
||||
|
||||
_typeInfos.append(sections[1]);
|
||||
} else if (sections[0] == QLatin1String("designersupported")) {
|
||||
if (sectionCount != 1)
|
||||
reportError(lineNumber, 0, QStringLiteral("designersupported does not expect any argument"));
|
||||
else
|
||||
_designerSupported = true;
|
||||
} else if (sections[0] == QLatin1String("depends") || sections[0] == QLatin1String("import")) {
|
||||
} else if (sections[0] == QLatin1String("import")
|
||||
|| sections[0] == QLatin1String("depends")) {
|
||||
if (!readImport(sections, sectionCount, Import::Default))
|
||||
continue;
|
||||
} else if (sections[0] == QLatin1String("prefer")) {
|
||||
if (sectionCount < 2) {
|
||||
reportError(lineNumber, 0,
|
||||
QStringLiteral("prefer directive requires one argument, "
|
||||
"but %1 were provided").arg(sectionCount - 1));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_preferredPath.isEmpty()) {
|
||||
reportError(lineNumber, 0, QStringLiteral(
|
||||
"only one prefer directive may be defined in a qmldir file"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!sections[1].endsWith(u'/')) {
|
||||
// Yes. People should realize it's a directory.
|
||||
reportError(lineNumber, 0, QStringLiteral(
|
||||
"the preferred directory has to end with a '/'"));
|
||||
continue;
|
||||
}
|
||||
|
||||
_preferredPath = sections[1];
|
||||
} else if (sectionCount == 2) {
|
||||
// No version specified (should only be used for relative qmldir files)
|
||||
const Component entry(sections[0], sections[1], -1, -1);
|
||||
@@ -361,14 +379,6 @@ void QmlDirParser::reportError(quint16 line, quint16 column, const QString &desc
|
||||
_errors.append(error);
|
||||
}
|
||||
|
||||
bool QmlDirParser::hasError() const
|
||||
{
|
||||
if (! _errors.isEmpty())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void QmlDirParser::setError(const QmlJS::DiagnosticMessage &e)
|
||||
{
|
||||
_errors.clear();
|
||||
@@ -388,56 +398,6 @@ QList<QmlJS::DiagnosticMessage> QmlDirParser::errors(const QString &uri) const
|
||||
return errors;
|
||||
}
|
||||
|
||||
QString QmlDirParser::typeNamespace() const
|
||||
{
|
||||
return _typeNamespace;
|
||||
}
|
||||
|
||||
void QmlDirParser::setTypeNamespace(const QString &s)
|
||||
{
|
||||
_typeNamespace = s;
|
||||
}
|
||||
|
||||
QList<QmlDirParser::Plugin> QmlDirParser::plugins() const
|
||||
{
|
||||
return _plugins;
|
||||
}
|
||||
|
||||
QMultiHash<QString, QmlDirParser::Component> QmlDirParser::components() const
|
||||
{
|
||||
return _components;
|
||||
}
|
||||
|
||||
QList<QmlDirParser::Import> QmlDirParser::dependencies() const
|
||||
{
|
||||
return _dependencies;
|
||||
}
|
||||
|
||||
QList<QmlDirParser::Import> QmlDirParser::imports() const
|
||||
{
|
||||
return _imports;
|
||||
}
|
||||
|
||||
QList<QmlDirParser::Script> QmlDirParser::scripts() const
|
||||
{
|
||||
return _scripts;
|
||||
}
|
||||
|
||||
QList<QmlDirParser::TypeInfo> QmlDirParser::typeInfos() const
|
||||
{
|
||||
return _typeInfos;
|
||||
}
|
||||
|
||||
bool QmlDirParser::designerSupported() const
|
||||
{
|
||||
return _designerSupported;
|
||||
}
|
||||
|
||||
QString QmlDirParser::className() const
|
||||
{
|
||||
return _className;
|
||||
}
|
||||
|
||||
QDebug &operator<< (QDebug &debug, const QmlDirParser::Component &component)
|
||||
{
|
||||
const QString output = QStringLiteral("{%1 %2.%3}").
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -55,12 +55,12 @@ public:
|
||||
void clear();
|
||||
bool parse(const QString &source);
|
||||
|
||||
bool hasError() const;
|
||||
bool hasError() const { return !_errors.isEmpty(); }
|
||||
void setError(const QmlJS::DiagnosticMessage &);
|
||||
QList<QmlJS::DiagnosticMessage> errors(const QString &uri) const;
|
||||
|
||||
QString typeNamespace() const;
|
||||
void setTypeNamespace(const QString &s);
|
||||
QString typeNamespace() const { return _typeNamespace; }
|
||||
void setTypeNamespace(const QString &s) { _typeNamespace = s; }
|
||||
|
||||
static void checkNonRelative(const char *item, const QString &typeName, const QString &fileName)
|
||||
{
|
||||
@@ -141,25 +141,16 @@ public:
|
||||
Flags flags;
|
||||
};
|
||||
|
||||
QMultiHash<QString,Component> components() const;
|
||||
QList<Import> dependencies() const;
|
||||
QList<Import> imports() const;
|
||||
QList<Script> scripts() const;
|
||||
QList<Plugin> plugins() const;
|
||||
bool designerSupported() const;
|
||||
QMultiHash<QString,Component> components() const { return _components; }
|
||||
QList<Import> dependencies() const { return _dependencies; }
|
||||
QList<Import> imports() const { return _imports; }
|
||||
QList<Script> scripts() const { return _scripts; }
|
||||
QList<Plugin> plugins() const { return _plugins; }
|
||||
bool designerSupported() const { return _designerSupported; }
|
||||
|
||||
struct TypeInfo
|
||||
{
|
||||
TypeInfo() = default;
|
||||
TypeInfo(const QString &fileName)
|
||||
: fileName(fileName) {}
|
||||
|
||||
QString fileName;
|
||||
};
|
||||
|
||||
QList<TypeInfo> typeInfos() const;
|
||||
|
||||
QString className() const;
|
||||
QStringList typeInfos() const { return _typeInfos; }
|
||||
QStringList classNames() const { return _classNames; }
|
||||
QString preferredPath() const { return _preferredPath; }
|
||||
|
||||
private:
|
||||
bool maybeAddComponent(const QString &typeName, const QString &fileName, const QString &version, QHash<QString,Component> &hash, int lineNumber = -1, bool multi = true);
|
||||
@@ -168,19 +159,21 @@ private:
|
||||
private:
|
||||
QList<QmlJS::DiagnosticMessage> _errors;
|
||||
QString _typeNamespace;
|
||||
QString _preferredPath;
|
||||
QMultiHash<QString,Component> _components;
|
||||
QList<Import> _dependencies;
|
||||
QList<Import> _imports;
|
||||
QList<Script> _scripts;
|
||||
QList<Plugin> _plugins;
|
||||
bool _designerSupported = false;
|
||||
QList<TypeInfo> _typeInfos;
|
||||
QString _className;
|
||||
QStringList _typeInfos;
|
||||
QStringList _classNames;
|
||||
};
|
||||
|
||||
using QmlDirComponents = QMultiHash<QString,QmlDirParser::Component>;
|
||||
using QmlDirScripts = QList<QmlDirParser::Script>;
|
||||
using QmlDirPlugins = QList<QmlDirParser::Plugin>;
|
||||
using QmlDirImports = QList<QmlDirParser::Import>;
|
||||
|
||||
QDebug &operator<< (QDebug &, const QmlDirParser::Component &);
|
||||
QDebug &operator<< (QDebug &, const QmlDirParser::Script &);
|
||||
|
108
src/libs/qmljs/parser/qmlimportresolver.cpp
Normal file
108
src/libs/qmljs/parser/qmlimportresolver.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmlimportresolver_p.h"
|
||||
|
||||
QT_QML_BEGIN_NAMESPACE
|
||||
|
||||
enum ImportVersion { FullyVersioned, PartiallyVersioned, Unversioned };
|
||||
|
||||
/*!
|
||||
Forms complete paths to a module, from a list of base paths,
|
||||
a module URI and version specification.
|
||||
|
||||
For example, QtQml.Models 2.0:
|
||||
- base/QtQml/Models.2.0
|
||||
- base/QtQml.2.0/Models
|
||||
- base/QtQml/Models.2
|
||||
- base/QtQml.2/Models
|
||||
- base/QtQml/Models
|
||||
*/
|
||||
QStringList qQmlResolveImportPaths(QStringView uri, const QStringList &basePaths,
|
||||
LanguageUtils::ComponentVersion version)
|
||||
{
|
||||
static const QLatin1Char Slash('/');
|
||||
static const QLatin1Char Backslash('\\');
|
||||
|
||||
const QList<QStringView> parts = uri.split(u'.', Qt::SkipEmptyParts);
|
||||
|
||||
QStringList importPaths;
|
||||
// fully & partially versioned parts + 1 unversioned for each base path
|
||||
importPaths.reserve(2 * parts.count() + 1);
|
||||
|
||||
auto versionString = [](LanguageUtils::ComponentVersion version, ImportVersion mode)
|
||||
{
|
||||
if (mode == FullyVersioned) {
|
||||
// extension with fully encoded version number (eg. MyModule.3.2)
|
||||
return QString::fromLatin1(".%1.%2").arg(version.majorVersion())
|
||||
.arg(version.minorVersion());
|
||||
}
|
||||
if (mode == PartiallyVersioned) {
|
||||
// extension with encoded version major (eg. MyModule.3)
|
||||
return QString::fromLatin1(".%1").arg(version.majorVersion());
|
||||
}
|
||||
// else extension without version number (eg. MyModule)
|
||||
return QString();
|
||||
};
|
||||
|
||||
auto joinStringRefs = [](const QList<QStringView> &refs, const QChar &sep) {
|
||||
QString str;
|
||||
for (auto it = refs.cbegin(); it != refs.cend(); ++it) {
|
||||
if (it != refs.cbegin())
|
||||
str += sep;
|
||||
str += *it;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const ImportVersion initial = ((version.minorVersion() >= 0)
|
||||
? FullyVersioned
|
||||
: ((version.majorVersion() >= 0) ? PartiallyVersioned : Unversioned));
|
||||
for (int mode = initial; mode <= Unversioned; ++mode) {
|
||||
const QString ver = versionString(version, ImportVersion(mode));
|
||||
|
||||
for (const QString &path : basePaths) {
|
||||
QString dir = path;
|
||||
if (!dir.endsWith(Slash) && !dir.endsWith(Backslash))
|
||||
dir += Slash;
|
||||
|
||||
// append to the end
|
||||
importPaths += dir + joinStringRefs(parts, Slash) + ver;
|
||||
|
||||
if (mode != Unversioned) {
|
||||
// insert in the middle
|
||||
for (int index = parts.count() - 2; index >= 0; --index) {
|
||||
importPaths += dir + joinStringRefs(parts.mid(0, index + 1), Slash)
|
||||
+ ver + Slash
|
||||
+ joinStringRefs(parts.mid(index + 1), Slash);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return importPaths;
|
||||
}
|
||||
|
||||
QT_QML_END_NAMESPACE
|
50
src/libs/qmljs/parser/qmlimportresolver_p.h
Normal file
50
src/libs/qmljs/parser/qmlimportresolver_p.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qmljs/parser/qmljsglobal_p.h"
|
||||
|
||||
#include "qmljsglobal_p.h"
|
||||
#include <QtCore/qstring.h>
|
||||
#include <languageutils/componentversion.h>
|
||||
|
||||
QT_QML_BEGIN_NAMESPACE
|
||||
|
||||
QML_PARSER_EXPORT QStringList qQmlResolveImportPaths(QStringView uri, const QStringList &basePaths,
|
||||
LanguageUtils::ComponentVersion version);
|
||||
|
||||
QT_QML_END_NAMESPACE
|
@@ -81,6 +81,7 @@
|
||||
%token T_COMPATIBILITY_SEMICOLON
|
||||
%token T_ARROW "=>"
|
||||
%token T_QUESTION_QUESTION "??"
|
||||
%token T_QUESTION_DOT "?."
|
||||
%token T_ENUM "enum"
|
||||
%token T_ELLIPSIS "..."
|
||||
%token T_YIELD "yield"
|
||||
@@ -835,18 +836,32 @@ UiImport: UiImportHead Semicolon;
|
||||
UiVersionSpecifier: T_VERSION_NUMBER T_DOT T_VERSION_NUMBER;
|
||||
/.
|
||||
case $rule_number: {
|
||||
auto version = new (pool) AST::UiVersionSpecifier(sym(1).dval, sym(3).dval);
|
||||
const int major = sym(1).dval;
|
||||
const int minor = sym(3).dval;
|
||||
if (major < 0 || major >= 255 || minor < 0 || minor >= 255) {
|
||||
diagnostic_messages.append(
|
||||
compileError(loc(1),
|
||||
QLatin1String("Invalid version. Version numbers must be >= 0 and < 255.")));
|
||||
return false;
|
||||
}
|
||||
auto version = new (pool) AST::UiVersionSpecifier(major, minor);
|
||||
version->majorToken = loc(1);
|
||||
version->minorToken = loc(3);
|
||||
sym(1).UiVersionSpecifier = version;
|
||||
} break;
|
||||
./
|
||||
|
||||
|
||||
UiVersionSpecifier: T_VERSION_NUMBER;
|
||||
/.
|
||||
case $rule_number: {
|
||||
auto version = new (pool) AST::UiVersionSpecifier(sym(1).dval, 0);
|
||||
const int major = sym(1).dval;
|
||||
if (major < 0 || major >= 255) {
|
||||
diagnostic_messages.append(
|
||||
compileError(loc(1),
|
||||
QLatin1String("Invalid major version. Version numbers must be >= 0 and < 255.")));
|
||||
return false;
|
||||
}
|
||||
auto version = new (pool) AST::UiVersionSpecifier(sym(1).dval);
|
||||
version->majorToken = loc(1);
|
||||
sym(1).UiVersionSpecifier = version;
|
||||
} break;
|
||||
@@ -1320,6 +1335,7 @@ UiObjectMember: T_DEFAULT UiObjectMemberPropertyNoInitialiser;
|
||||
} break;
|
||||
./
|
||||
|
||||
|
||||
UiObjectMember: T_REQUIRED UiObjectMemberListPropertyNoInitialiser;
|
||||
/.
|
||||
case $rule_number: {
|
||||
@@ -2277,7 +2293,16 @@ MemberExpression: MemberExpression T_LBRACKET Expression_In T_RBRACKET;
|
||||
sym(1).Node = node;
|
||||
} break;
|
||||
./
|
||||
|
||||
MemberExpression: MemberExpression T_QUESTION_DOT T_LBRACKET Expression_In T_RBRACKET;
|
||||
/.
|
||||
case $rule_number: {
|
||||
AST::ArrayMemberExpression *node = new (pool) AST::ArrayMemberExpression(sym(1).Expression, sym(4).Expression);
|
||||
node->lbracketToken = loc(3);
|
||||
node->rbracketToken = loc(5);
|
||||
node->isOptional = true;
|
||||
sym(1).Node = node;
|
||||
} break;
|
||||
./
|
||||
|
||||
-- the identifier has to be "target", catched at codegen time
|
||||
NewTarget: T_NEW T_DOT T_IDENTIFIER;
|
||||
@@ -2300,6 +2325,17 @@ MemberExpression: MemberExpression T_DOT IdentifierName;
|
||||
} break;
|
||||
./
|
||||
|
||||
MemberExpression: MemberExpression T_QUESTION_DOT IdentifierName;
|
||||
/.
|
||||
case $rule_number: {
|
||||
AST::FieldMemberExpression *node = new (pool) AST::FieldMemberExpression(sym(1).Expression, stringRef(3));
|
||||
node->dotToken = loc(2);
|
||||
node->identifierToken = loc(3);
|
||||
node->isOptional = true;
|
||||
sym(1).Node = node;
|
||||
} break;
|
||||
./
|
||||
|
||||
MemberExpression: MetaProperty;
|
||||
|
||||
MemberExpression: T_NEW MemberExpression T_LPAREN Arguments T_RPAREN;
|
||||
@@ -2348,6 +2384,17 @@ CallExpression: MemberExpression T_LPAREN Arguments T_RPAREN;
|
||||
} break;
|
||||
./
|
||||
|
||||
CallExpression: MemberExpression T_QUESTION_DOT T_LPAREN Arguments T_RPAREN;
|
||||
/.
|
||||
case $rule_number: {
|
||||
AST::CallExpression *node = new (pool) AST::CallExpression(sym(1).Expression, sym(4).ArgumentList);
|
||||
node->lparenToken = loc(3);
|
||||
node->rparenToken = loc(5);
|
||||
node->isOptional = true;
|
||||
sym(1).Node = node;
|
||||
} break;
|
||||
./
|
||||
|
||||
CallExpression: Super T_LPAREN Arguments T_RPAREN;
|
||||
/. case $rule_number: Q_FALLTHROUGH(); ./
|
||||
CallExpression: CallExpression T_LPAREN Arguments T_RPAREN;
|
||||
@@ -2360,6 +2407,18 @@ CallExpression: CallExpression T_LPAREN Arguments T_RPAREN;
|
||||
} break;
|
||||
./
|
||||
|
||||
CallExpression: CallExpression T_QUESTION_DOT T_LPAREN Arguments T_RPAREN;
|
||||
/.
|
||||
case $rule_number: {
|
||||
AST::CallExpression *node = new (pool) AST::CallExpression(sym(1).Expression, sym(4).ArgumentList);
|
||||
node->lparenToken = loc(3);
|
||||
node->rparenToken = loc(5);
|
||||
node->isOptional = true;
|
||||
sym(1).Node = node;
|
||||
} break;
|
||||
./
|
||||
|
||||
|
||||
CallExpression: CallExpression T_LBRACKET Expression_In T_RBRACKET;
|
||||
/.
|
||||
case $rule_number: {
|
||||
@@ -2370,6 +2429,17 @@ CallExpression: CallExpression T_LBRACKET Expression_In T_RBRACKET;
|
||||
} break;
|
||||
./
|
||||
|
||||
CallExpression: CallExpression T_QUESTION_DOT T_LBRACKET Expression_In T_RBRACKET;
|
||||
/.
|
||||
case $rule_number: {
|
||||
AST::ArrayMemberExpression *node = new (pool) AST::ArrayMemberExpression(sym(1).Expression, sym(4).Expression);
|
||||
node->lbracketToken = loc(3);
|
||||
node->rbracketToken = loc(5);
|
||||
node->isOptional = true;
|
||||
sym(1).Node = node;
|
||||
} break;
|
||||
./
|
||||
|
||||
CallExpression: CallExpression T_DOT IdentifierName;
|
||||
/.
|
||||
case $rule_number: {
|
||||
@@ -2380,6 +2450,17 @@ CallExpression: CallExpression T_DOT IdentifierName;
|
||||
} break;
|
||||
./
|
||||
|
||||
CallExpression: CallExpression T_QUESTION_DOT IdentifierName;
|
||||
/.
|
||||
case $rule_number: {
|
||||
AST::FieldMemberExpression *node = new (pool) AST::FieldMemberExpression(sym(1).Expression, stringRef(3));
|
||||
node->dotToken = loc(2);
|
||||
node->identifierToken = loc(3);
|
||||
node->isOptional = true;
|
||||
sym(1).Node = node;
|
||||
} break;
|
||||
./
|
||||
|
||||
Arguments: ;
|
||||
/.
|
||||
case $rule_number: {
|
||||
@@ -2673,6 +2754,12 @@ RelationalOperator: T_INSTANCEOF;
|
||||
sym(1).ival = QSOperator::InstanceOf;
|
||||
} break;
|
||||
./
|
||||
RelationalOperator: T_AS;
|
||||
/.
|
||||
case $rule_number: {
|
||||
sym(1).ival = QSOperator::As;
|
||||
} break;
|
||||
./
|
||||
|
||||
RelationalExpression_In: RelationalExpression_In T_IN ShiftExpression;
|
||||
/.
|
||||
@@ -2683,20 +2770,6 @@ RelationalExpression_In: RelationalExpression_In T_IN ShiftExpression;
|
||||
} break;
|
||||
./
|
||||
|
||||
TypeAssertExpression_In: RelationalExpression_In T_AS Type;
|
||||
/. case $rule_number: Q_FALLTHROUGH(); ./
|
||||
TypeAssertExpression: RelationalExpression T_AS Type;
|
||||
/.
|
||||
case $rule_number: {
|
||||
AST::BinaryExpression *node = new (pool) AST::BinaryExpression(sym(1).Expression, QSOperator::As, sym(3).Expression);
|
||||
node->operatorToken = loc(2);
|
||||
sym(1).Node = node;
|
||||
} break;
|
||||
./
|
||||
|
||||
RelationalExpression_In: TypeAssertExpression_In;
|
||||
RelationalExpression: TypeAssertExpression;
|
||||
|
||||
EqualityExpression_In: RelationalExpression_In;
|
||||
EqualityExpression: RelationalExpression;
|
||||
|
||||
@@ -2873,6 +2946,9 @@ AssignmentExpression: LeftHandSideExpression T_EQ AssignmentExpression;
|
||||
AssignmentExpression_In: LeftHandSideExpression T_EQ AssignmentExpression_In;
|
||||
/.
|
||||
case $rule_number: {
|
||||
if (sym(1).Expression->containsOptionalChain()) {
|
||||
syntaxError(loc(1), QStringLiteral("Optional chains are not permitted on the left-hand-side in assignments"));
|
||||
}
|
||||
// need to convert the LHS to an AssignmentPattern if it was an Array/ObjectLiteral
|
||||
if (AST::Pattern *p = sym(1).Expression->patternCast()) {
|
||||
SourceLocation errorLoc;
|
||||
@@ -2903,6 +2979,9 @@ AssignmentExpression: LeftHandSideExpression AssignmentOperator AssignmentExpres
|
||||
AssignmentExpression_In: LeftHandSideExpression AssignmentOperator AssignmentExpression_In;
|
||||
/.
|
||||
case $rule_number: {
|
||||
if (sym(1).Expression->containsOptionalChain()) {
|
||||
syntaxError(loc(1), QStringLiteral("Optional chains are not permitted on the left-hand-side in assignments"));
|
||||
}
|
||||
AST::BinaryExpression *node = new (pool) AST::BinaryExpression(sym(1).Expression, sym(2).ival, sym(3).Expression);
|
||||
node->operatorToken = loc(2);
|
||||
sym(1).Node = node;
|
||||
@@ -4019,15 +4098,14 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead AssignmentExpress
|
||||
/.
|
||||
case $rule_number: {
|
||||
AST::ReturnStatement *ret = new (pool) AST::ReturnStatement(sym(4).Expression);
|
||||
ret->returnToken = sym(4).Node->firstSourceLocation().zeroLength();
|
||||
ret->semicolonToken = sym(4).Node->lastSourceLocation().zeroLengthEnd(driver->code());
|
||||
ret->returnToken = sym(4).Node->firstSourceLocation().startZeroLengthLocation();
|
||||
ret->semicolonToken = sym(4).Node->lastSourceLocation().endZeroLengthLocation(driver->code());
|
||||
AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish();
|
||||
AST::FunctionExpression *f = new (pool)
|
||||
AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements);
|
||||
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements);
|
||||
f->isArrowFunction = true;
|
||||
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation().zeroLength() : loc(1).zeroLength();
|
||||
f->lbraceToken = sym(4).Node->firstSourceLocation().zeroLength();
|
||||
f->rbraceToken = sym(4).Node->lastSourceLocation().zeroLengthEnd(driver->code());
|
||||
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation().startZeroLengthLocation() : loc(1).startZeroLengthLocation();
|
||||
f->lbraceToken = sym(4).Node->firstSourceLocation().startZeroLengthLocation();
|
||||
f->rbraceToken = sym(4).Node->lastSourceLocation().endZeroLengthLocation(driver->code());
|
||||
sym(1).Node = f;
|
||||
} break;
|
||||
./
|
||||
@@ -4039,8 +4117,8 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK Fun
|
||||
case $rule_number: {
|
||||
AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, sym(6).StatementList);
|
||||
f->isArrowFunction = true;
|
||||
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation().zeroLength() : loc(1).zeroLength();
|
||||
f->lbraceToken = loc(5);
|
||||
f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation().startZeroLengthLocation() : loc(1).startZeroLengthLocation();
|
||||
f->lbraceToken = loc(6);
|
||||
f->rbraceToken = loc(7);
|
||||
sym(1).Node = f;
|
||||
} break;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -23,11 +23,11 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QLocale>
|
||||
#include "qmljsast_p.h"
|
||||
|
||||
#include "qmljsastvisitor_p.h"
|
||||
|
||||
#include <QLocale>
|
||||
#include <qlocale.h>
|
||||
|
||||
QT_QML_BEGIN_NAMESPACE
|
||||
|
||||
@@ -104,6 +104,44 @@ ExpressionNode *ExpressionNode::expressionCast()
|
||||
return this;
|
||||
}
|
||||
|
||||
bool ExpressionNode::containsOptionalChain() const
|
||||
{
|
||||
for (const Node *node = this;;) {
|
||||
switch (node->kind) {
|
||||
case Kind_FieldMemberExpression: {
|
||||
const auto *fme = AST::cast<const FieldMemberExpression*>(node);
|
||||
if (fme->isOptional)
|
||||
return true;
|
||||
node = fme->base;
|
||||
break;
|
||||
}
|
||||
case Kind_ArrayMemberExpression: {
|
||||
const auto *ame = AST::cast<const ArrayMemberExpression*>(node);
|
||||
if (ame->isOptional)
|
||||
return true;
|
||||
node = ame->base;
|
||||
break;
|
||||
}
|
||||
case Kind_CallExpression: {
|
||||
const auto *ce = AST::cast<const CallExpression*>(node);
|
||||
if (ce->isOptional)
|
||||
return true;
|
||||
node = ce->base;
|
||||
break;
|
||||
}
|
||||
case Kind_NestedExpression: {
|
||||
const auto *ne = AST::cast<const NestedExpression*>(node);
|
||||
node = ne->expression;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// These unhandled nodes lead to invalid lvalues anyway, so they do not need to be handled here.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FormalParameterList *ExpressionNode::reparseAsFormalParameterList(MemoryPool *pool)
|
||||
{
|
||||
AST::ExpressionNode *expr = this;
|
||||
@@ -145,6 +183,12 @@ BinaryExpression *BinaryExpression::binaryExpressionCast()
|
||||
return this;
|
||||
}
|
||||
|
||||
void TypeExpression::accept0(BaseVisitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
visitor->endVisit(this);
|
||||
}
|
||||
|
||||
Statement *Statement::statementCast()
|
||||
{
|
||||
return this;
|
||||
@@ -989,7 +1033,13 @@ BoundNames FormalParameterList::formals() const
|
||||
// change the name of the earlier argument to enforce the lookup semantics from the spec
|
||||
formals[duplicateIndex].id += QLatin1String("#") + QString::number(i);
|
||||
}
|
||||
formals += {name, it->element->typeAnnotation};
|
||||
formals += {
|
||||
name,
|
||||
it->element->typeAnnotation,
|
||||
it->element->isInjectedSignalParameter
|
||||
? BoundName::Injected
|
||||
: BoundName::Declared
|
||||
};
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@@ -1392,7 +1442,8 @@ void PatternElement::boundNames(BoundNames *names)
|
||||
else if (PatternPropertyList *p = propertyList())
|
||||
p->boundNames(names);
|
||||
} else {
|
||||
names->append({bindingIdentifier.toString(), typeAnnotation});
|
||||
names->append({bindingIdentifier.toString(), typeAnnotation,
|
||||
isInjectedSignalParameter ? BoundName::Injected : BoundName::Declared});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1531,7 +1582,7 @@ QString Type::toString() const
|
||||
void Type::toString(QString *out) const
|
||||
{
|
||||
for (QmlJS::AST::UiQualifiedId *it = typeId; it; it = it->next) {
|
||||
out->append(it->name.toString());
|
||||
out->append(it->name);
|
||||
|
||||
if (it->next)
|
||||
out->append(QLatin1Char('.'));
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "qmljs/parser/qmljsmemorypool_p.h"
|
||||
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qversionnumber.h>
|
||||
|
||||
QT_QML_BEGIN_NAMESPACE
|
||||
|
||||
@@ -201,6 +202,7 @@ public:
|
||||
Kind_SwitchStatement,
|
||||
Kind_TemplateLiteral,
|
||||
Kind_TaggedTemplate,
|
||||
Kind_TypeExpression,
|
||||
Kind_ThisExpression,
|
||||
Kind_ThrowStatement,
|
||||
Kind_TildeExpression,
|
||||
@@ -319,8 +321,7 @@ public:
|
||||
QMLJS_DECLARE_AST_NODE(UiQualifiedId)
|
||||
|
||||
UiQualifiedId(QStringView name)
|
||||
: next(this)
|
||||
, name(name)
|
||||
: next(this), name(name)
|
||||
{ kind = K; }
|
||||
|
||||
UiQualifiedId(UiQualifiedId *previous, QStringView name)
|
||||
@@ -444,6 +445,7 @@ public:
|
||||
ExpressionNode() {}
|
||||
|
||||
ExpressionNode *expressionCast() override;
|
||||
bool containsOptionalChain() const;
|
||||
|
||||
AST::FormalParameterList *reparseAsFormalParameterList(MemoryPool *pool);
|
||||
|
||||
@@ -489,6 +491,26 @@ public:
|
||||
SourceLocation rparenToken;
|
||||
};
|
||||
|
||||
|
||||
class QML_PARSER_EXPORT TypeExpression : public ExpressionNode
|
||||
{
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(TypeExpression)
|
||||
TypeExpression(Type *t) : m_type(t) { kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
SourceLocation firstSourceLocation() const override {
|
||||
return m_type->firstSourceLocation();
|
||||
}
|
||||
|
||||
SourceLocation lastSourceLocation() const override {
|
||||
return m_type->lastSourceLocation();
|
||||
}
|
||||
|
||||
Type *m_type;
|
||||
};
|
||||
|
||||
class QML_PARSER_EXPORT ThisExpression: public LeftHandSideExpression
|
||||
{
|
||||
public:
|
||||
@@ -513,11 +535,8 @@ class QML_PARSER_EXPORT IdentifierExpression: public LeftHandSideExpression
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(IdentifierExpression)
|
||||
|
||||
IdentifierExpression(QStringView n)
|
||||
: name(n)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
IdentifierExpression(QStringView n):
|
||||
name (n) { kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -635,7 +654,15 @@ class QML_PARSER_EXPORT UiVersionSpecifier : public Node
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(UiVersionSpecifier)
|
||||
|
||||
UiVersionSpecifier(int majorum, int minorum) : majorVersion(majorum), minorVersion(minorum) { kind = K; }
|
||||
UiVersionSpecifier(int majorum) : majorVersion(majorum)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
|
||||
UiVersionSpecifier(int majorum, int minorum) : majorVersion(majorum), minorVersion(minorum)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -647,8 +674,8 @@ public:
|
||||
}
|
||||
|
||||
// attributes:
|
||||
int majorVersion;
|
||||
int minorVersion;
|
||||
int majorVersion = -1;
|
||||
int minorVersion = -1;
|
||||
SourceLocation majorToken;
|
||||
SourceLocation minorToken;
|
||||
};
|
||||
@@ -658,11 +685,8 @@ class QML_PARSER_EXPORT StringLiteral : public LeftHandSideExpression
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(StringLiteral)
|
||||
|
||||
StringLiteral(QStringView v)
|
||||
: value(v)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
StringLiteral(QStringView v):
|
||||
value (v) { kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -683,10 +707,7 @@ public:
|
||||
QMLJS_DECLARE_AST_NODE(TemplateLiteral)
|
||||
|
||||
TemplateLiteral(QStringView str, QStringView raw, ExpressionNode *e)
|
||||
: value(str)
|
||||
, rawValue(raw)
|
||||
, expression(e)
|
||||
, next(nullptr)
|
||||
: value(str), rawValue(raw), expression(e), next(nullptr)
|
||||
{ kind = K; }
|
||||
|
||||
SourceLocation firstSourceLocation() const override
|
||||
@@ -712,12 +733,8 @@ class QML_PARSER_EXPORT RegExpLiteral: public LeftHandSideExpression
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(RegExpLiteral)
|
||||
|
||||
RegExpLiteral(QStringView p, int f)
|
||||
: pattern(p)
|
||||
, flags(f)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
RegExpLiteral(QStringView p, int f):
|
||||
pattern (p), flags (f) { kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -857,13 +874,20 @@ public:
|
||||
|
||||
struct QML_PARSER_EXPORT BoundName
|
||||
{
|
||||
enum Type {
|
||||
Declared,
|
||||
Injected,
|
||||
};
|
||||
|
||||
QString id;
|
||||
TypeAnnotation *typeAnnotation = nullptr;
|
||||
BoundName(const QString &id, TypeAnnotation *typeAnnotation)
|
||||
: id(id), typeAnnotation(typeAnnotation)
|
||||
Type typeAnnotationType;
|
||||
TypeAnnotation *typeAnnotation;
|
||||
BoundName(const QString &id, TypeAnnotation *typeAnnotation, Type type = Declared)
|
||||
: id(id), typeAnnotation(typeAnnotation), typeAnnotationType(type)
|
||||
{}
|
||||
BoundName() = default;
|
||||
QString typeName() const { return typeAnnotation ? typeAnnotation->type->toString() : QString(); }
|
||||
bool isInjected() const { return typeAnnotation && typeAnnotationType == Injected; }
|
||||
};
|
||||
|
||||
struct BoundNames : public QVector<BoundName>
|
||||
@@ -907,13 +931,8 @@ public:
|
||||
: initializer(i), type(t)
|
||||
{ kind = K; }
|
||||
|
||||
PatternElement(QStringView n,
|
||||
TypeAnnotation *typeAnnotation = nullptr,
|
||||
ExpressionNode *i = nullptr,
|
||||
Type t = Binding)
|
||||
: bindingIdentifier(n)
|
||||
, initializer(i)
|
||||
, type(t)
|
||||
PatternElement(QStringView n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding)
|
||||
: bindingIdentifier(n), initializer(i), type(t)
|
||||
, typeAnnotation(typeAnnotation)
|
||||
{
|
||||
Q_ASSERT(t >= RestElement);
|
||||
@@ -956,6 +975,7 @@ public:
|
||||
// when used in a VariableDeclarationList
|
||||
VariableScope scope = VariableScope::NoScope;
|
||||
bool isForDeclaration = false;
|
||||
bool isInjectedSignalParameter = false;
|
||||
};
|
||||
|
||||
class QML_PARSER_EXPORT PatternElementList : public Node
|
||||
@@ -1008,8 +1028,7 @@ public:
|
||||
{ kind = K; }
|
||||
|
||||
PatternProperty(PropertyName *name, QStringView n, ExpressionNode *i = nullptr)
|
||||
: PatternElement(n, /*type annotation*/ nullptr, i)
|
||||
, name(name)
|
||||
: PatternElement(n, /*type annotation*/nullptr, i), name(name)
|
||||
{ kind = K; }
|
||||
|
||||
PatternProperty(PropertyName *name, Pattern *pattern, ExpressionNode *i = nullptr)
|
||||
@@ -1078,11 +1097,8 @@ class QML_PARSER_EXPORT IdentifierPropertyName: public PropertyName
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(IdentifierPropertyName)
|
||||
|
||||
IdentifierPropertyName(QStringView n)
|
||||
: id(n)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
IdentifierPropertyName(QStringView n):
|
||||
id (n) { kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -1097,11 +1113,8 @@ class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(StringLiteralPropertyName)
|
||||
|
||||
StringLiteralPropertyName(QStringView n)
|
||||
: id(n)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
StringLiteralPropertyName(QStringView n):
|
||||
id (n) { kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -1173,6 +1186,7 @@ public:
|
||||
ExpressionNode *expression;
|
||||
SourceLocation lbracketToken;
|
||||
SourceLocation rbracketToken;
|
||||
bool isOptional = false;
|
||||
};
|
||||
|
||||
class QML_PARSER_EXPORT FieldMemberExpression: public LeftHandSideExpression
|
||||
@@ -1180,11 +1194,9 @@ class QML_PARSER_EXPORT FieldMemberExpression: public LeftHandSideExpression
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(FieldMemberExpression)
|
||||
|
||||
FieldMemberExpression(ExpressionNode *b, QStringView n)
|
||||
: base(b)
|
||||
, name(n)
|
||||
{
|
||||
kind = K; }
|
||||
FieldMemberExpression(ExpressionNode *b, QStringView n):
|
||||
base (b), name (n)
|
||||
{ kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -1199,6 +1211,7 @@ public:
|
||||
QStringView name;
|
||||
SourceLocation dotToken;
|
||||
SourceLocation identifierToken;
|
||||
bool isOptional = false;
|
||||
};
|
||||
|
||||
class QML_PARSER_EXPORT TaggedTemplate : public LeftHandSideExpression
|
||||
@@ -1291,6 +1304,7 @@ public:
|
||||
ArgumentList *arguments;
|
||||
SourceLocation lparenToken;
|
||||
SourceLocation rparenToken;
|
||||
bool isOptional = false;
|
||||
};
|
||||
|
||||
class QML_PARSER_EXPORT ArgumentList: public Node
|
||||
@@ -1972,11 +1986,8 @@ class QML_PARSER_EXPORT ContinueStatement: public Statement
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(ContinueStatement)
|
||||
|
||||
ContinueStatement(QStringView l = QStringView())
|
||||
: label(l)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
ContinueStatement(QStringView l = QStringView()):
|
||||
label (l) { kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -1998,11 +2009,8 @@ class QML_PARSER_EXPORT BreakStatement: public Statement
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(BreakStatement)
|
||||
|
||||
BreakStatement(QStringView l)
|
||||
: label(l)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
BreakStatement(QStringView l):
|
||||
label (l) { kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -2229,11 +2237,9 @@ class QML_PARSER_EXPORT LabelledStatement: public Statement
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(LabelledStatement)
|
||||
|
||||
LabelledStatement(QStringView l, Statement *stmt)
|
||||
: label(l)
|
||||
, statement(stmt)
|
||||
{
|
||||
kind = K; }
|
||||
LabelledStatement(QStringView l, Statement *stmt):
|
||||
label (l), statement (stmt)
|
||||
{ kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -2364,16 +2370,10 @@ class QML_PARSER_EXPORT FunctionExpression: public ExpressionNode
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(FunctionExpression)
|
||||
|
||||
FunctionExpression(QStringView n,
|
||||
FormalParameterList *f,
|
||||
StatementList *b,
|
||||
TypeAnnotation *typeAnnotation = nullptr)
|
||||
: name(n)
|
||||
, formals(f)
|
||||
, body(b)
|
||||
, typeAnnotation(typeAnnotation)
|
||||
{
|
||||
kind = K; }
|
||||
FunctionExpression(QStringView n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
|
||||
name (n), formals (f), body (b),
|
||||
typeAnnotation(typeAnnotation)
|
||||
{ kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -2405,13 +2405,9 @@ class QML_PARSER_EXPORT FunctionDeclaration: public FunctionExpression
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(FunctionDeclaration)
|
||||
|
||||
FunctionDeclaration(QStringView n,
|
||||
FormalParameterList *f,
|
||||
StatementList *b,
|
||||
TypeAnnotation *typeAnnotation = nullptr)
|
||||
: FunctionExpression(n, f, b, typeAnnotation)
|
||||
{
|
||||
kind = K; }
|
||||
FunctionDeclaration(QStringView n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr):
|
||||
FunctionExpression(n, f, b, typeAnnotation)
|
||||
{ kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
};
|
||||
@@ -2507,11 +2503,8 @@ public:
|
||||
QMLJS_DECLARE_AST_NODE(ClassExpression)
|
||||
|
||||
ClassExpression(QStringView n, ExpressionNode *heritage, ClassElementList *elements)
|
||||
: name(n)
|
||||
, heritage(heritage)
|
||||
, elements(elements)
|
||||
{
|
||||
kind = K; }
|
||||
: name(n), heritage(heritage), elements(elements)
|
||||
{ kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
@@ -2540,8 +2533,7 @@ public:
|
||||
|
||||
ClassDeclaration(QStringView n, ExpressionNode *heritage, ClassElementList *elements)
|
||||
: ClassExpression(n, heritage, elements)
|
||||
{
|
||||
kind = K; }
|
||||
{ kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
};
|
||||
@@ -2617,8 +2609,7 @@ public:
|
||||
}
|
||||
|
||||
ImportSpecifier(QStringView identifier, QStringView importedBinding)
|
||||
: identifier(identifier)
|
||||
, importedBinding(importedBinding)
|
||||
: identifier(identifier), importedBinding(importedBinding)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
@@ -2852,15 +2843,13 @@ public:
|
||||
QMLJS_DECLARE_AST_NODE(ExportSpecifier)
|
||||
|
||||
ExportSpecifier(QStringView identifier)
|
||||
: identifier(identifier)
|
||||
, exportedIdentifier(identifier)
|
||||
: identifier(identifier), exportedIdentifier(identifier)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
|
||||
ExportSpecifier(QStringView identifier, QStringView exportedIdentifier)
|
||||
: identifier(identifier)
|
||||
, exportedIdentifier(exportedIdentifier)
|
||||
: identifier(identifier), exportedIdentifier(exportedIdentifier)
|
||||
{
|
||||
kind = K;
|
||||
}
|
||||
@@ -2959,7 +2948,6 @@ public:
|
||||
ExportDeclaration(FromClause *fromClause)
|
||||
: fromClause(fromClause)
|
||||
{
|
||||
exportAll = true;
|
||||
kind = K;
|
||||
}
|
||||
|
||||
@@ -2982,6 +2970,11 @@ public:
|
||||
kind = K;
|
||||
}
|
||||
|
||||
bool exportsAll() const
|
||||
{
|
||||
return fromClause && !exportClause;
|
||||
}
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
SourceLocation firstSourceLocation() const override
|
||||
@@ -2991,7 +2984,6 @@ public:
|
||||
|
||||
// attributes
|
||||
SourceLocation exportToken;
|
||||
bool exportAll = false;
|
||||
ExportClause *exportClause = nullptr;
|
||||
FromClause *fromClause = nullptr;
|
||||
Node *variableStatementOrDeclaration = nullptr;
|
||||
@@ -3048,8 +3040,7 @@ public:
|
||||
QMLJS_DECLARE_AST_NODE(UiImport)
|
||||
|
||||
UiImport(QStringView fileName)
|
||||
: fileName(fileName)
|
||||
, importUri(nullptr)
|
||||
: fileName(fileName), importUri(nullptr)
|
||||
{ kind = K; }
|
||||
|
||||
UiImport(UiQualifiedId *uri)
|
||||
@@ -3154,7 +3145,7 @@ public:
|
||||
QMLJS_DECLARE_AST_NODE(UiRequired)
|
||||
|
||||
UiRequired(QStringView name)
|
||||
: name(name)
|
||||
:name(name)
|
||||
{ kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
@@ -3319,16 +3310,12 @@ class QML_PARSER_EXPORT UiParameterList: public Node
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(UiParameterList)
|
||||
|
||||
UiParameterList(UiQualifiedId *t, QStringView n)
|
||||
: type(t)
|
||||
, name(n)
|
||||
, next(this)
|
||||
{
|
||||
kind = K; }
|
||||
UiParameterList(UiQualifiedId *t, QStringView n):
|
||||
type (t), name (n), next (this)
|
||||
{ kind = K; }
|
||||
|
||||
UiParameterList(UiParameterList *previous, UiQualifiedId *t, QStringView n)
|
||||
: type(t)
|
||||
, name(n)
|
||||
UiParameterList(UiParameterList *previous, UiQualifiedId *t, QStringView n):
|
||||
type (t), name (n)
|
||||
{
|
||||
kind = K;
|
||||
next = previous->next;
|
||||
@@ -3368,43 +3355,29 @@ class QML_PARSER_EXPORT UiPublicMember: public UiObjectMember
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(UiPublicMember)
|
||||
|
||||
UiPublicMember(UiQualifiedId *memberType, QStringView name)
|
||||
: type(Property)
|
||||
, memberType(memberType)
|
||||
, name(name)
|
||||
, statement(nullptr)
|
||||
, binding(nullptr)
|
||||
, isDefaultMember(false)
|
||||
, isReadonlyMember(false)
|
||||
, parameters(nullptr)
|
||||
UiPublicMember(UiQualifiedId *memberType,
|
||||
QStringView name)
|
||||
: type(Property), memberType(memberType), name(name), statement(nullptr), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr)
|
||||
{ kind = K; }
|
||||
|
||||
UiPublicMember(UiQualifiedId *memberType, QStringView name, Statement *statement)
|
||||
: type(Property)
|
||||
, memberType(memberType)
|
||||
, name(name)
|
||||
, statement(statement)
|
||||
, binding(nullptr)
|
||||
, isDefaultMember(false)
|
||||
, isReadonlyMember(false)
|
||||
, parameters(nullptr)
|
||||
UiPublicMember(UiQualifiedId *memberType,
|
||||
QStringView name,
|
||||
Statement *statement)
|
||||
: type(Property), memberType(memberType), name(name), statement(statement), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr)
|
||||
{ kind = K; }
|
||||
|
||||
void accept0(BaseVisitor *visitor) override;
|
||||
|
||||
SourceLocation firstSourceLocation() const override
|
||||
{
|
||||
if (requiredToken.isValid()) {
|
||||
if (defaultToken.isValid() && defaultToken.offset < requiredToken.offset)
|
||||
return defaultToken;
|
||||
return requiredToken;
|
||||
}
|
||||
if (defaultToken.isValid())
|
||||
return defaultToken;
|
||||
if (readonlyToken.isValid())
|
||||
return readonlyToken;
|
||||
if (defaultToken.isValid())
|
||||
return defaultToken;
|
||||
else if (readonlyToken.isValid())
|
||||
return readonlyToken;
|
||||
else if (requiredToken.isValid())
|
||||
return requiredToken;
|
||||
|
||||
return propertyToken;
|
||||
return propertyToken;
|
||||
}
|
||||
|
||||
SourceLocation lastSourceLocation() const override
|
||||
@@ -3468,9 +3441,8 @@ class QML_PARSER_EXPORT UiInlineComponent: public UiObjectMember
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(UiInlineComponent)
|
||||
|
||||
UiInlineComponent(QStringView inlineComponentName, UiObjectDefinition *inlineComponent)
|
||||
: name(inlineComponentName)
|
||||
, component(inlineComponent)
|
||||
UiInlineComponent(QStringView inlineComponentName, UiObjectDefinition* inlineComponent)
|
||||
: name(inlineComponentName), component(inlineComponent)
|
||||
{ kind = K; }
|
||||
|
||||
SourceLocation lastSourceLocation() const override
|
||||
@@ -3596,7 +3568,7 @@ public:
|
||||
{ kind = K; }
|
||||
|
||||
SourceLocation firstSourceLocation() const override
|
||||
{ return qualifiedId->identifierToken; }
|
||||
{ Q_ASSERT(qualifiedId); return qualifiedId->identifierToken; }
|
||||
|
||||
SourceLocation lastSourceLocation() const override
|
||||
{ return rbracketToken; }
|
||||
@@ -3616,9 +3588,7 @@ class QML_PARSER_EXPORT UiEnumMemberList: public Node
|
||||
QMLJS_DECLARE_AST_NODE(UiEnumMemberList)
|
||||
public:
|
||||
UiEnumMemberList(QStringView member, double v = 0.0)
|
||||
: next(this)
|
||||
, member(member)
|
||||
, value(v)
|
||||
: next(this), member(member), value(v)
|
||||
{ kind = K; }
|
||||
|
||||
UiEnumMemberList(UiEnumMemberList *previous, QStringView member)
|
||||
@@ -3631,8 +3601,7 @@ public:
|
||||
}
|
||||
|
||||
UiEnumMemberList(UiEnumMemberList *previous, QStringView member, double v)
|
||||
: member(member)
|
||||
, value(v)
|
||||
: member(member), value(v)
|
||||
{
|
||||
kind = K;
|
||||
next = previous->next;
|
||||
@@ -3670,7 +3639,8 @@ class QML_PARSER_EXPORT UiEnumDeclaration: public UiObjectMember
|
||||
public:
|
||||
QMLJS_DECLARE_AST_NODE(UiEnumDeclaration)
|
||||
|
||||
UiEnumDeclaration(QStringView name, UiEnumMemberList *members)
|
||||
UiEnumDeclaration(QStringView name,
|
||||
UiEnumMemberList *members)
|
||||
: name(name)
|
||||
, members(members)
|
||||
{ kind = K; }
|
||||
@@ -3754,4 +3724,3 @@ public:
|
||||
|
||||
|
||||
QT_QML_END_NAMESPACE
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -50,6 +50,7 @@ class Visitor;
|
||||
class Node;
|
||||
class ExpressionNode;
|
||||
class Statement;
|
||||
class TypeExpression;
|
||||
class ThisExpression;
|
||||
class IdentifierExpression;
|
||||
class NullExpression;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -126,6 +126,9 @@ public:
|
||||
virtual void endVisit(UiRequired *) = 0;
|
||||
|
||||
// QmlJS
|
||||
virtual bool visit(TypeExpression *) = 0;
|
||||
virtual void endVisit(TypeExpression *) = 0;
|
||||
|
||||
virtual bool visit(ThisExpression *) = 0;
|
||||
virtual void endVisit(ThisExpression *) = 0;
|
||||
|
||||
@@ -467,6 +470,9 @@ public:
|
||||
void endVisit(UiRequired *) override {}
|
||||
|
||||
// QmlJS
|
||||
bool visit(TypeExpression *) override { return true; }
|
||||
void endVisit(TypeExpression *) override {}
|
||||
|
||||
bool visit(ThisExpression *) override { return true; }
|
||||
void endVisit(ThisExpression *) override {}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -26,11 +26,9 @@
|
||||
#include "qmljsengine_p.h"
|
||||
#include "qmljsglobal_p.h"
|
||||
|
||||
#include <utils/porting.h>
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qnumeric.h>
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
QT_QML_BEGIN_NAMESPACE
|
||||
|
||||
@@ -138,9 +136,7 @@ QStringView Engine::newStringRef(const QString &text)
|
||||
}
|
||||
|
||||
QStringView Engine::newStringRef(const QChar *chars, int size)
|
||||
{
|
||||
return newStringRef(QString(chars, size));
|
||||
}
|
||||
{ return newStringRef(QString(chars, size)); }
|
||||
|
||||
} // end of namespace QmlJS
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -37,16 +37,14 @@
|
||||
//
|
||||
|
||||
#include "qmljsglobal_p.h"
|
||||
#include "qmljs/parser/qmljssourcelocation_p.h"
|
||||
|
||||
#include "qmljs/parser/qmljsmemorypool_p.h"
|
||||
#include "qmljs/parser/qmljssourcelocation_p.h"
|
||||
#include <qmljs/qmljsconstants.h>
|
||||
|
||||
#include <utils/porting.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QSet>
|
||||
|
||||
#include <qmljs/qmljsconstants.h>
|
||||
QT_QML_BEGIN_NAMESPACE
|
||||
|
||||
namespace QmlJS {
|
||||
@@ -107,10 +105,7 @@ public:
|
||||
|
||||
MemoryPool *pool();
|
||||
|
||||
inline QStringView midRef(int position, int size)
|
||||
{
|
||||
return Utils::midView(_code, position, size);
|
||||
}
|
||||
inline QStringView midRef(int position, int size) { return QStringView{_code}.mid(position, size); }
|
||||
|
||||
QStringView newStringRef(const QString &s);
|
||||
QStringView newStringRef(const QChar *chars, int size);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -32,23 +32,23 @@ class QML_PARSER_EXPORT QmlJSGrammar
|
||||
public:
|
||||
enum VariousConstants {
|
||||
EOF_SYMBOL = 0,
|
||||
REDUCE_HERE = 131,
|
||||
REDUCE_HERE = 132,
|
||||
T_AND = 1,
|
||||
T_AND_AND = 2,
|
||||
T_AND_EQ = 3,
|
||||
T_ARROW = 96,
|
||||
T_AS = 116,
|
||||
T_AS = 117,
|
||||
T_AT = 90,
|
||||
T_AUTOMATIC_SEMICOLON = 64,
|
||||
T_BREAK = 4,
|
||||
T_CASE = 5,
|
||||
T_CATCH = 6,
|
||||
T_CLASS = 102,
|
||||
T_CLASS = 103,
|
||||
T_COLON = 7,
|
||||
T_COMMA = 8,
|
||||
T_COMMENT = 94,
|
||||
T_COMPATIBILITY_SEMICOLON = 95,
|
||||
T_COMPONENT = 108,
|
||||
T_COMPONENT = 109,
|
||||
T_CONST = 88,
|
||||
T_CONTINUE = 9,
|
||||
T_DEBUGGER = 91,
|
||||
@@ -58,32 +58,32 @@ public:
|
||||
T_DIVIDE_EQ = 13,
|
||||
T_DO = 14,
|
||||
T_DOT = 15,
|
||||
T_ELLIPSIS = 99,
|
||||
T_ELLIPSIS = 100,
|
||||
T_ELSE = 16,
|
||||
T_ENUM = 98,
|
||||
T_ENUM = 99,
|
||||
T_EQ = 17,
|
||||
T_EQ_EQ = 18,
|
||||
T_EQ_EQ_EQ = 19,
|
||||
T_ERROR = 120,
|
||||
T_EXPORT = 105,
|
||||
T_EXTENDS = 103,
|
||||
T_ERROR = 121,
|
||||
T_EXPORT = 106,
|
||||
T_EXTENDS = 104,
|
||||
T_FALSE = 87,
|
||||
T_FEED_JS_EXPRESSION = 124,
|
||||
T_FEED_JS_MODULE = 126,
|
||||
T_FEED_JS_SCRIPT = 125,
|
||||
T_FEED_JS_STATEMENT = 123,
|
||||
T_FEED_UI_OBJECT_MEMBER = 122,
|
||||
T_FEED_UI_PROGRAM = 121,
|
||||
T_FEED_JS_EXPRESSION = 125,
|
||||
T_FEED_JS_MODULE = 127,
|
||||
T_FEED_JS_SCRIPT = 126,
|
||||
T_FEED_JS_STATEMENT = 124,
|
||||
T_FEED_UI_OBJECT_MEMBER = 123,
|
||||
T_FEED_UI_PROGRAM = 122,
|
||||
T_FINALLY = 20,
|
||||
T_FOR = 21,
|
||||
T_FORCE_BLOCK = 128,
|
||||
T_FORCE_DECLARATION = 127,
|
||||
T_FOR_LOOKAHEAD_OK = 129,
|
||||
T_FROM = 106,
|
||||
T_FORCE_BLOCK = 129,
|
||||
T_FORCE_DECLARATION = 128,
|
||||
T_FOR_LOOKAHEAD_OK = 130,
|
||||
T_FROM = 107,
|
||||
T_FUNCTION = 23,
|
||||
T_FUNCTION_STAR = 22,
|
||||
T_GE = 24,
|
||||
T_GET = 118,
|
||||
T_GET = 119,
|
||||
T_GT = 25,
|
||||
T_GT_GT = 26,
|
||||
T_GT_GT_EQ = 27,
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
T_GT_GT_GT_EQ = 29,
|
||||
T_IDENTIFIER = 30,
|
||||
T_IF = 31,
|
||||
T_IMPORT = 114,
|
||||
T_IMPORT = 115,
|
||||
T_IN = 32,
|
||||
T_INSTANCEOF = 33,
|
||||
T_LBRACE = 34,
|
||||
@@ -110,46 +110,47 @@ public:
|
||||
T_NOT = 45,
|
||||
T_NOT_EQ = 46,
|
||||
T_NOT_EQ_EQ = 47,
|
||||
T_NO_SUBSTITUTION_TEMPLATE = 109,
|
||||
T_NO_SUBSTITUTION_TEMPLATE = 110,
|
||||
T_NULL = 85,
|
||||
T_NUMERIC_LITERAL = 48,
|
||||
T_OF = 117,
|
||||
T_ON = 130,
|
||||
T_OF = 118,
|
||||
T_ON = 131,
|
||||
T_OR = 49,
|
||||
T_OR_EQ = 51,
|
||||
T_OR_OR = 52,
|
||||
T_PLUS = 53,
|
||||
T_PLUS_EQ = 54,
|
||||
T_PLUS_PLUS = 55,
|
||||
T_PRAGMA = 115,
|
||||
T_PRAGMA = 116,
|
||||
T_PROPERTY = 70,
|
||||
T_PUBLIC = 113,
|
||||
T_PUBLIC = 114,
|
||||
T_QUESTION = 56,
|
||||
T_QUESTION_DOT = 98,
|
||||
T_QUESTION_QUESTION = 97,
|
||||
T_RBRACE = 57,
|
||||
T_RBRACKET = 58,
|
||||
T_READONLY = 72,
|
||||
T_REMAINDER = 59,
|
||||
T_REMAINDER_EQ = 60,
|
||||
T_REQUIRED = 107,
|
||||
T_REQUIRED = 108,
|
||||
T_RESERVED_WORD = 92,
|
||||
T_RETURN = 61,
|
||||
T_RPAREN = 62,
|
||||
T_SEMICOLON = 63,
|
||||
T_SET = 119,
|
||||
T_SET = 120,
|
||||
T_SIGNAL = 71,
|
||||
T_STAR = 65,
|
||||
T_STAR_EQ = 68,
|
||||
T_STAR_STAR = 66,
|
||||
T_STAR_STAR_EQ = 67,
|
||||
T_STATIC = 104,
|
||||
T_STATIC = 105,
|
||||
T_STRING_LITERAL = 69,
|
||||
T_SUPER = 101,
|
||||
T_SUPER = 102,
|
||||
T_SWITCH = 73,
|
||||
T_TEMPLATE_HEAD = 110,
|
||||
T_TEMPLATE_MIDDLE = 111,
|
||||
T_TEMPLATE_TAIL = 112,
|
||||
T_THEN = 132,
|
||||
T_TEMPLATE_HEAD = 111,
|
||||
T_TEMPLATE_MIDDLE = 112,
|
||||
T_TEMPLATE_TAIL = 113,
|
||||
T_THEN = 133,
|
||||
T_THIS = 74,
|
||||
T_THROW = 75,
|
||||
T_TILDE = 76,
|
||||
@@ -161,20 +162,20 @@ public:
|
||||
T_VOID = 80,
|
||||
T_WHILE = 81,
|
||||
T_WITH = 82,
|
||||
T_WITHOUTAS = 133,
|
||||
T_WITHOUTAS = 134,
|
||||
T_XOR = 83,
|
||||
T_XOR_EQ = 84,
|
||||
T_YIELD = 100,
|
||||
T_YIELD = 101,
|
||||
|
||||
ACCEPT_STATE = 1102,
|
||||
RULE_COUNT = 619,
|
||||
STATE_COUNT = 1103,
|
||||
TERMINAL_COUNT = 134,
|
||||
NON_TERMINAL_COUNT = 238,
|
||||
ACCEPT_STATE = 1114,
|
||||
RULE_COUNT = 622,
|
||||
STATE_COUNT = 1115,
|
||||
TERMINAL_COUNT = 135,
|
||||
NON_TERMINAL_COUNT = 236,
|
||||
|
||||
GOTO_INDEX_OFFSET = 1103,
|
||||
GOTO_INFO_OFFSET = 6857,
|
||||
GOTO_CHECK_OFFSET = 6857
|
||||
GOTO_INDEX_OFFSET = 1115,
|
||||
GOTO_INFO_OFFSET = 7121,
|
||||
GOTO_CHECK_OFFSET = 7121
|
||||
};
|
||||
|
||||
static const char *const spell[];
|
||||
@@ -214,4 +215,3 @@ public:
|
||||
|
||||
|
||||
#endif // QMLJSGRAMMAR_P_H
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -176,6 +176,7 @@ protected:
|
||||
|
||||
private:
|
||||
inline void scanChar();
|
||||
inline QChar peekChar();
|
||||
int scanToken();
|
||||
int scanNumber(QChar ch);
|
||||
int scanVersionNumber(QChar ch);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -90,8 +90,7 @@ public:
|
||||
template <typename Tp, typename... Ta> Tp *New(Ta... args)
|
||||
{ return new (this->allocate(sizeof(Tp))) Tp(args...); }
|
||||
|
||||
QStringView newString(const QString &string)
|
||||
{
|
||||
QStringView newString(const QString &string) {
|
||||
strings.append(new QString(string));
|
||||
return QStringView(*strings.last());
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,6 @@
|
||||
|
||||
#line 185 "qmljs.g"
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -292,27 +290,27 @@ protected:
|
||||
|
||||
|
||||
|
||||
#line 1862 "qmljs.g"
|
||||
#line 1878 "qmljs.g"
|
||||
|
||||
#define J_SCRIPT_REGEXPLITERAL_RULE1 164
|
||||
|
||||
#line 1874 "qmljs.g"
|
||||
#line 1890 "qmljs.g"
|
||||
|
||||
#define J_SCRIPT_REGEXPLITERAL_RULE2 165
|
||||
|
||||
#line 3423 "qmljs.g"
|
||||
#line 3502 "qmljs.g"
|
||||
|
||||
#define J_SCRIPT_EXPRESSIONSTATEMENTLOOKAHEAD_RULE 463
|
||||
#define J_SCRIPT_EXPRESSIONSTATEMENTLOOKAHEAD_RULE 466
|
||||
|
||||
#line 4076 "qmljs.g"
|
||||
#line 4154 "qmljs.g"
|
||||
|
||||
#define J_SCRIPT_CONCISEBODYLOOKAHEAD_RULE 533
|
||||
#define J_SCRIPT_CONCISEBODYLOOKAHEAD_RULE 536
|
||||
|
||||
#line 4618 "qmljs.g"
|
||||
#line 4696 "qmljs.g"
|
||||
|
||||
#define J_SCRIPT_EXPORTDECLARATIONLOOKAHEAD_RULE 602
|
||||
#define J_SCRIPT_EXPORTDECLARATIONLOOKAHEAD_RULE 605
|
||||
|
||||
#line 4902 "qmljs.g"
|
||||
#line 4980 "qmljs.g"
|
||||
|
||||
QT_QML_END_NAMESPACE
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -26,8 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "qmljsglobal_p.h"
|
||||
|
||||
#include <QtCore/QStringView>
|
||||
#include <QtCore/qhashfunctions.h>
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -52,13 +51,19 @@ public:
|
||||
startLine(line), startColumn(column)
|
||||
{ }
|
||||
|
||||
bool isValid() const { return length != 0; }
|
||||
bool isValid() const { return *this != SourceLocation(); }
|
||||
|
||||
quint32 begin() const { return offset; }
|
||||
quint32 end() const { return offset + length; }
|
||||
|
||||
SourceLocation zeroLength() const { return SourceLocation(offset, 0, startLine, startColumn); }
|
||||
SourceLocation zeroLengthEnd(QStringView text) const {
|
||||
// Returns a zero length location at the start of the current one.
|
||||
SourceLocation startZeroLengthLocation() const
|
||||
{
|
||||
return SourceLocation(offset, 0, startLine, startColumn);
|
||||
}
|
||||
// Returns a zero length location at the end of the current one.
|
||||
SourceLocation endZeroLengthLocation(QStringView text) const
|
||||
{
|
||||
quint32 i = offset;
|
||||
quint32 endLine = startLine;
|
||||
quint32 endColumn = startColumn;
|
||||
@@ -71,7 +76,7 @@ public:
|
||||
Q_FALLTHROUGH();
|
||||
case '\r':
|
||||
++endLine;
|
||||
++endColumn;
|
||||
endColumn = 1;
|
||||
break;
|
||||
default:
|
||||
++endColumn;
|
||||
@@ -87,6 +92,33 @@ public:
|
||||
quint32 length;
|
||||
quint32 startLine;
|
||||
quint32 startColumn;
|
||||
|
||||
friend size_t qHash(const SourceLocation &location, size_t seed = 0)
|
||||
{
|
||||
return (seed ^ (size_t(location.offset) << 8) ^ size_t(location.length)
|
||||
^ (size_t(location.startLine) << 16) ^ (size_t(location.startColumn) << 24));
|
||||
}
|
||||
|
||||
friend bool operator==(const SourceLocation &a, const SourceLocation &b)
|
||||
{
|
||||
return a.offset == b.offset && a.length == b.length && a.startLine == b.startLine
|
||||
&& a.startColumn == b.startColumn;
|
||||
}
|
||||
|
||||
friend bool operator!=(const SourceLocation &a, const SourceLocation &b) { return !(a == b); }
|
||||
|
||||
// Returns a source location starting at the beginning of l1, l2 and ending at the end of them.
|
||||
// Ignores invalid source locations.
|
||||
friend SourceLocation combine(const SourceLocation &l1, const SourceLocation &l2) {
|
||||
quint32 e = qMax(l1.end(), l2.end());
|
||||
SourceLocation res;
|
||||
if (l1.offset <= l2.offset)
|
||||
res = (l1.isValid() ? l1 : l2);
|
||||
else
|
||||
res = (l2.isValid() ? l2 : l1);
|
||||
res.length = e - res.offset;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace QmlJS
|
||||
|
@@ -60,6 +60,7 @@ Project {
|
||||
prefix: "parser/"
|
||||
files: [
|
||||
"qmldirparser.cpp", "qmldirparser_p.h",
|
||||
"qmlimportresolver.cpp", "qmlimportresolver_p.h",
|
||||
"qmljsast.cpp", "qmljsast_p.h",
|
||||
"qmljsastfwd_p.h",
|
||||
"qmljsastvisitor.cpp", "qmljsastvisitor_p.h",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
|
@@ -370,7 +370,7 @@ LibraryInfo::LibraryInfo(Status status)
|
||||
updateFingerprint();
|
||||
}
|
||||
|
||||
LibraryInfo::LibraryInfo(const QmlDirParser::TypeInfo &typeInfo)
|
||||
LibraryInfo::LibraryInfo(const QString &typeInfo)
|
||||
: _status(Found)
|
||||
{
|
||||
_typeinfos.append(typeInfo);
|
||||
@@ -421,10 +421,10 @@ QByteArray LibraryInfo::calculateFingerprint() const
|
||||
}
|
||||
len = _typeinfos.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
foreach (const QmlDirParser::TypeInfo &typeinfo, _typeinfos) {
|
||||
len = typeinfo.fileName.size();
|
||||
foreach (const QString &typeinfo, _typeinfos) {
|
||||
len = typeinfo.size();
|
||||
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
|
||||
hash.addData(reinterpret_cast<const char *>(typeinfo.fileName.constData()),
|
||||
hash.addData(reinterpret_cast<const char *>(typeinfo.constData()),
|
||||
len * sizeofQChar);
|
||||
}
|
||||
len = _metaObjects.size();
|
||||
|
@@ -153,7 +153,7 @@ private:
|
||||
Status _status = NotScanned;
|
||||
QList<QmlDirParser::Component> _components;
|
||||
QList<QmlDirParser::Plugin> _plugins;
|
||||
QList<QmlDirParser::TypeInfo> _typeinfos;
|
||||
QStringList _typeinfos;
|
||||
typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
|
||||
FakeMetaObjectList _metaObjects;
|
||||
QList<ModuleApiInfo> _moduleApis;
|
||||
@@ -167,7 +167,7 @@ private:
|
||||
public:
|
||||
LibraryInfo();
|
||||
explicit LibraryInfo(Status status);
|
||||
explicit LibraryInfo(const QmlDirParser::TypeInfo &typeInfo);
|
||||
explicit LibraryInfo(const QString &typeInfo);
|
||||
explicit LibraryInfo(const QmlDirParser &parser, const QByteArray &fingerprint = QByteArray());
|
||||
~LibraryInfo() = default;
|
||||
LibraryInfo(const LibraryInfo &other) = default;
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
QList<QmlDirParser::Plugin> plugins() const
|
||||
{ return _plugins; }
|
||||
|
||||
QList<QmlDirParser::TypeInfo> typeInfos() const
|
||||
QStringList typeInfos() const
|
||||
{ return _typeinfos; }
|
||||
|
||||
FakeMetaObjectList metaObjects() const
|
||||
|
@@ -811,7 +811,7 @@ static bool findNewQmlApplicationInPath(const QString &path,
|
||||
|
||||
qmltypesFile = it.next();
|
||||
|
||||
LibraryInfo libraryInfo = LibraryInfo(QmlDirParser::TypeInfo(qmltypesFile));
|
||||
LibraryInfo libraryInfo = LibraryInfo(qmltypesFile);
|
||||
const QString libraryPath = dir.absolutePath();
|
||||
newLibraries->insert(libraryPath);
|
||||
modelManager->updateLibraryInfo(path, libraryInfo);
|
||||
|
@@ -154,8 +154,8 @@ void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &
|
||||
}
|
||||
|
||||
// add typeinfo files listed in qmldir
|
||||
foreach (const QmlDirParser::TypeInfo &typeInfo, libraryInfo.typeInfos()) {
|
||||
QString pathNow = makeAbsolute(typeInfo.fileName, canonicalLibraryPath);
|
||||
foreach (const QString &typeInfo, libraryInfo.typeInfos()) {
|
||||
QString pathNow = makeAbsolute(typeInfo, canonicalLibraryPath);
|
||||
if (!plugin.typeInfoPaths.contains(pathNow) && QFile::exists(pathNow))
|
||||
plugin.typeInfoPaths += pathNow;
|
||||
}
|
||||
|
@@ -209,7 +209,7 @@ const QString undefinedVersion = QLatin1String("-1.-1");
|
||||
* undefined version (-1.-1) or if it is empty. False otherwise.
|
||||
*/
|
||||
bool QmlJS::maybeModuleVersion(const QString &version) {
|
||||
QRegularExpression re(QLatin1String("^\\d+\\.\\d+$"));
|
||||
QRegularExpression re(QLatin1String("^\\d+\\.-?\\d+$"));
|
||||
return version.isEmpty() || version == undefinedVersion || re.match(version).hasMatch();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user