Update qmljs parser to Qt 5.15 parser

* parser side support for annotations, inline components, new UiVersion
  and all the things included in QT 5.15 parser
* SourceLocation moved from QmlJS:AST to QmlJS
* Visitors now need to handle throwRecursionDepthError
* BaseVisitor for visitors that want to override all visit

Task-number: QTCREATORBUG-23591
Change-Id: I682a30d0b08b6c929739fd0e339ef6fbde3eb630
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Fawzi Mohamed
2020-02-28 17:51:32 +01:00
parent a24dead5f6
commit b09a48599e
88 changed files with 5290 additions and 4350 deletions

View File

@@ -1,157 +1,83 @@
diff --git a/src/libs/qmljs/parser/qmlerror.cpp b/src/libs/qmljs/parser/qmlerror.cpp
index d090a19..5ec311d 100644
--- a/src/libs/qmljs/parser/qmlerror.cpp
+++ b/src/libs/qmljs/parser/qmlerror.cpp
@@ -65,6 +65,12 @@ QT_BEGIN_NAMESPACE
diff -u parser-genOut/qmljsgrammar.cpp parser/qmljsgrammar.cpp
--- parser-genOut/qmljsgrammar.cpp 2020-03-02 13:53:50.000000000 +0100
+++ parser/qmljsgrammar.cpp 2020-03-02 14:16:26.000000000 +0100
@@ -21,7 +21,8 @@
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
-***************************************************************************// This file was generated by qlalr - DO NOT EDIT!
+***************************************************************************/
+// This file was generated by qlalr - DO NOT EDIT!
#include "qmljsgrammar_p.h"
\sa QQuickView::errors(), QmlComponent::errors()
*/
+
+static quint16 qmlSourceCoordinate(int n)
+{
+ return (n > 0 && n <= static_cast<int>(USHRT_MAX)) ? static_cast<quint16>(n) : 0;
+}
+
class QmlErrorPrivate
const char *const QmlJSGrammar::spell [] = {
diff -u parser-genOut/qmljsgrammar_p.h parser/qmljsgrammar_p.h
--- parser/qmljsgrammar_p.h 2020-03-03 13:51:43.000000000 +0100
+++ parser-fixed2/qmljsgrammar_p.h 2020-03-02 17:20:56.000000000 +0100
@@ -21,11 +21,13 @@
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
-***************************************************************************// This file was generated by qlalr - DO NOT EDIT!
+***************************************************************************/
+// This file was generated by qlalr - DO NOT EDIT!
#ifndef QMLJSGRAMMAR_P_H
#define QMLJSGRAMMAR_P_H
+#include "qmljsglobal_p.h"
-class QmlJSGrammar
+class QML_PARSER_EXPORT QmlJSGrammar
{
public:
diff --git a/src/libs/qmljs/parser/qmljsengine_p.cpp b/src/libs/qmljs/parser/qmljsengine_p.cpp
index 1e22fa5..10fc3d1 100644
--- a/src/libs/qmljs/parser/qmljsengine_p.cpp
+++ b/src/libs/qmljs/parser/qmljsengine_p.cpp
@@ -110,7 +110,7 @@ double integerFromString(const QString &str, int radix)
Engine::Engine()
- : _lexer(0)
+ : _lexer(0), _directives(0)
{ }
Engine::~Engine()
@@ -131,6 +131,12 @@ Lexer *Engine::lexer() const
void Engine::setLexer(Lexer *lexer)
{ _lexer = lexer; }
+void Engine::setDirectives(Directives *directives)
+{ _directives = directives; }
+
+Directives *Engine::directives() const
+{ return _directives; }
+
MemoryPool *Engine::pool()
{ return &_pool; }
diff --git a/src/libs/qmljs/parser/qmljsengine_p.h b/src/libs/qmljs/parser/qmljsengine_p.h
index b1f7e1a..29b69d1 100644
--- a/src/libs/qmljs/parser/qmljsengine_p.h
+++ b/src/libs/qmljs/parser/qmljsengine_p.h
@@ -44,36 +44,35 @@
#include "qmljsglobal_p.h"
#include "qmljsastfwd_p.h"
#include "qmljsmemorypool_p.h"
+#include <qmljs/qmljsconstants.h>
#include <QString>
#include <QSet>
-#include <qmljs/qmljsconstants.h>
QT_QML_BEGIN_NAMESPACE
enum VariousConstants {
diff -u parser-genOut/qmljslexer_p.h parser/qmljslexer_p.h
--- parser-genOut/qmljslexer_p.h 2020-03-02 13:53:50.000000000 +0100
+++ parser/qmljslexer_p.h 2020-03-02 13:55:13.000000000 +0100
@@ -47,7 +47,7 @@
namespace QmlJS {
class Lexer;
+class Directives;
class MemoryPool;
class Engine;
-struct DiagnosticMessage;
+class DiagnosticMessage;
class Directives;
class QML_PARSER_EXPORT DiagnosticMessage
{
public:
- enum Kind { Warning, Error };
-
DiagnosticMessage()
- : kind(Error) {}
+ : kind(Severity::Error) {}
class QML_PARSER_EXPORT Lexer: public QmlJSGrammar
diff -u parser-genOut/qmljsparser.cpp parser/qmljsparser.cpp
--- parser-genOut/qmljsparser.cpp 2020-03-02 13:53:50.000000000 +0100
+++ parser/qmljsparser.cpp 2020-03-02 14:16:01.000000000 +0100
@@ -22,5 +22,6 @@
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
+#line 172 "qmljs.g"
- DiagnosticMessage(Kind kind, const AST::SourceLocation &loc, const QString &message)
+ DiagnosticMessage(Severity::Enum kind, const AST::SourceLocation &loc, const QString &message)
: kind(kind), loc(loc), message(message) {}
#include "qmljs/parser/qmljsengine_p.h"
diff -u parser-genOut/qmljsparser_p.h parser/qmljsparser_p.h
--- parser-genOut/qmljsparser_p.h 2020-03-02 13:53:50.000000000 +0100
+++ parser/qmljsparser_p.h 2020-03-02 14:13:25.000000000 +0100
@@ -22,6 +22,7 @@
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
+#line 223 "qmljs.g"
bool isWarning() const
- { return kind == Warning; }
+ { return kind == Severity::Warning; }
bool isError() const
- { return kind == Error; }
+ { return kind == Severity::Error; }
//
diff -u parser-genOut/parser.pri parser/parser.pri
--- parser-genOut/parser.pri 2020-03-02 15:40:09.000000000 +0100
+++ parser/parser.pri 2020-03-02 15:41:11.000000000 +0100
@@ -22,10 +22,10 @@
$$PWD/qmljsparser.cpp \
- Kind kind;
+ Severity::Enum kind;
AST::SourceLocation loc;
QString message;
};
@@ -81,6 +80,7 @@ public:
class QML_PARSER_EXPORT Engine
{
Lexer *_lexer;
+ Directives *_directives;
MemoryPool _pool;
QList<AST::SourceLocation> _comments;
QString _extraCode;
@@ -99,6 +99,9 @@ public:
Lexer *lexer() const;
void setLexer(Lexer *lexer);
-CONFIG += qlalr
+#CONFIG += qlalr
QLALRSOURCES = $$PWD/qmljs.g
-QMAKE_QLALRFLAGS = --no-debug --qt
+#QMAKE_QLALRFLAGS = --no-debug --qt
+ void setDirectives(Directives *directives);
+ Directives *directives() const;
+
MemoryPool *pool();
OTHER_FILES += $$QLALRSOURCES
inline QStringRef midRef(int position, int size) { return _code.midRef(position, size); }
diff --git a/src/libs/qmljs/parser/qmljslexer.cpp b/src/libs/qmljs/parser/qmljslexer.cpp
index 9698e9d..036be75 100644
--- a/src/libs/qmljs/parser/qmljslexer.cpp
+++ b/src/libs/qmljs/parser/qmljslexer.cpp
@@ -345,7 +345,7 @@ static inline bool isIdentifierStart(QChar ch)
// fast path for ascii
if ((ch.unicode() >= 'a' && ch.unicode() <= 'z') ||
(ch.unicode() >= 'A' && ch.unicode() <= 'Z') ||
- ch == '$' || ch == '_')
+ ch == QLatin1Char('$') || ch == QLatin1Char('_'))
return true;
switch (ch.category()) {
@@ -368,7 +368,7 @@ static bool isIdentifierPart(QChar ch)
if ((ch.unicode() >= 'a' && ch.unicode() <= 'z') ||
(ch.unicode() >= 'A' && ch.unicode() <= 'Z') ||
(ch.unicode() >= '0' && ch.unicode() <= '9') ||
- ch == '$' || ch == '_' ||
+ ch == QLatin1Char('$') || ch == QLatin1Char('_') ||
ch.unicode() == 0x200c /* ZWNJ */ || ch.unicode() == 0x200d /* ZWJ */)
return true;
diff --git a/src/libs/qmljs/parser/qmljsparser.cpp b/src/libs/qmljs/parser/qmljsparser.cpp
index 6e61637..e016b91 100644
--- a/src/libs/qmljs/parser/qmljsparser.cpp
+++ b/src/libs/qmljs/parser/qmljsparser.cpp
@@ -157,7 +157,20 @@ bool Parser::parse(int startToken)
token_buffer[0].token = startToken;
first_token = &token_buffer[0];
- last_token = &token_buffer[1];
+ if (startToken == T_FEED_JS_PROGRAM) {
+ Directives ignoreDirectives;
+ Directives *directives = driver->directives();
+ if (!directives)
+ directives = &ignoreDirectives;
+ lexer->scanDirectives(directives);
+ token_buffer[1].token = lexer->tokenKind();
+ token_buffer[1].dval = lexer->tokenValue();
+ token_buffer[1].loc = location(lexer);
+ token_buffer[1].spell = lexer->tokenSpell();
+ last_token = &token_buffer[2];
+ } else {
+ last_token = &token_buffer[1];
+ }
tos = -1;
program = 0;
# make sure we install the headers generated by qlalr
-private_headers.CONFIG += no_check_exist
+#private_headers.CONFIG += no_check_exist