Commit f0e4df58 authored by Fawzi Mohamed's avatar Fawzi Mohamed Committed by Erik Verbruggen
Browse files

qmljs/parser: update to latest qt5 parser



fix error semicolon insertion of loops, strict mode
Change-Id: I311733ffb34269d1cee7e576d05af78893b2bcbb
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 11187259
diff --git a/src/libs/qmljs/parser/qmljs.g b/src/libs/qmljs/parser/qmljs.g
index 069be3c..9cbdc23 100644
--- a/src/libs/qmljs/parser/qmljs.g
+++ b/src/libs/qmljs/parser/qmljs.g
@@ -111,7 +111,7 @@ double integerFromString(const QString &str, int radix)
diff --git a/src/libs/qmljs/parser/qmljsengine_p.cpp b/src/libs/qmljs/parser/qmljsengine_p.cpp
index 73850bb..d7d2189 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)
+ : _lexer(0), directives(0)
{ }
Engine::~Engine()
@@ -132,6 +132,12 @@ Lexer *Engine::lexer() const
@@ -131,6 +131,12 @@ Lexer *Engine::lexer() const
void Engine::setLexer(Lexer *lexer)
{ _lexer = lexer; }
......@@ -24,11 +24,11 @@ index 069be3c..9cbdc23 100644
MemoryPool *Engine::pool()
{ return &_pool; }
diff --git b/src/libs/qmljs/parser/qmljsengine_p.h a/src/libs/qmljs/parser/qmljsengine_p.h
index 5057ea0..487619e 100644
--- b/src/libs/qmljs/parser/qmljsengine_p.h
+++ a/src/libs/qmljs/parser/qmljsengine_p.h
@@ -54,6 +54,7 @@ QT_QML_BEGIN_NAMESPACE
diff --git a/src/libs/qmljs/parser/qmljsengine_p.h b/src/libs/qmljs/parser/qmljsengine_p.h
index d4ed4b37..4908e02 100644
--- a/src/libs/qmljs/parser/qmljsengine_p.h
+++ b/src/libs/qmljs/parser/qmljsengine_p.h
@@ -53,6 +53,7 @@ QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
class Lexer;
......@@ -36,7 +36,7 @@ index 5057ea0..487619e 100644
class MemoryPool;
class QML_PARSER_EXPORT DiagnosticMessage
@@ -81,6 +82,7 @@ public:
@@ -80,6 +81,7 @@ public:
class QML_PARSER_EXPORT Engine
{
Lexer *_lexer;
......@@ -44,7 +44,7 @@ index 5057ea0..487619e 100644
MemoryPool _pool;
QList<AST::SourceLocation> _comments;
QString _extraCode;
@@ -98,6 +100,9 @@ public:
@@ -97,6 +99,9 @@ public:
Lexer *lexer() const;
void setLexer(Lexer *lexer);
......@@ -54,11 +54,11 @@ index 5057ea0..487619e 100644
MemoryPool *pool();
inline QStringRef midRef(int position, int size) { return _code.midRef(position, size); }
diff --git b/src/libs/qmljs/parser/qmljsparser.cpp a/src/libs/qmljs/parser/qmljsparser.cpp
index a731c1a..e986534 100644
--- b/src/libs/qmljs/parser/qmljsparser.cpp
+++ a/src/libs/qmljs/parser/qmljsparser.cpp
@@ -137,7 +137,20 @@ bool Parser::parse(int startToken)
diff --git a/src/libs/qmljs/parser/qmljsparser.cpp b/src/libs/qmljs/parser/qmljsparser.cpp
index d53960b..71e994f 100644
--- a/src/libs/qmljs/parser/qmljsparser.cpp
+++ b/src/libs/qmljs/parser/qmljsparser.cpp
@@ -143,7 +143,20 @@ bool Parser::parse(int startToken)
token_buffer[0].token = startToken;
first_token = &token_buffer[0];
......
......@@ -21,3 +21,6 @@ SOURCES += \
$$PWD/qmljsparser.cpp \
$$PWD/qmldirparser.cpp \
$$PWD/qmlerror.cpp \
OTHER_FILES += \
$$PWD/qmljs.g
......@@ -32,7 +32,7 @@
#include <QtCore/QDebug>
#include <QtCore/QtDebug>
QT_BEGIN_NAMESPACE
......@@ -86,7 +86,7 @@ bool QmlDirParser::parse(const QString &source)
_components.clear();
_scripts.clear();
int lineNumber = 0;
quint16 lineNumber = 0;
bool firstLine = true;
const QChar *ch = source.constData();
......@@ -129,7 +129,7 @@ bool QmlDirParser::parse(const QString &source)
++ch;
if (invalidLine) {
reportError(lineNumber, -1,
reportError(lineNumber, 0,
QString::fromUtf8("invalid qmldir directive contains too many tokens"));
continue;
} else if (sectionCount == 0) {
......@@ -137,18 +137,18 @@ bool QmlDirParser::parse(const QString &source)
} else if (sections[0] == QLatin1String("module")) {
if (sectionCount != 2) {
reportError(lineNumber, -1,
QString::fromUtf8("module directive requires one argument, but %1 were provided").arg(sectionCount - 1));
reportError(lineNumber, 0,
QString::fromUtf8("module identifier directive requires one argument, but %1 were provided").arg(sectionCount - 1));
continue;
}
if (!_typeNamespace.isEmpty()) {
reportError(lineNumber, -1,
QString::fromUtf8("only one module directive may be defined in a qmldir file"));
reportError(lineNumber, 0,
QString::fromUtf8("only one module identifier directive may be defined in a qmldir file"));
continue;
}
if (!firstLine) {
reportError(lineNumber, -1,
QString::fromUtf8("module directive must be the first directive in a qmldir file"));
reportError(lineNumber, 0,
QString::fromUtf8("module identifier directive must be the first command in a qmldir file"));
continue;
}
......@@ -156,7 +156,7 @@ bool QmlDirParser::parse(const QString &source)
} else if (sections[0] == QLatin1String("plugin")) {
if (sectionCount < 2) {
reportError(lineNumber, -1,
reportError(lineNumber, 0,
QString::fromUtf8("plugin directive requires one or two arguments, but %1 were provided").arg(sectionCount - 1));
continue;
......@@ -168,7 +168,7 @@ bool QmlDirParser::parse(const QString &source)
} else if (sections[0] == QLatin1String("internal")) {
if (sectionCount != 3) {
reportError(lineNumber, -1,
reportError(lineNumber, 0,
QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount - 1));
continue;
}
......@@ -177,7 +177,7 @@ bool QmlDirParser::parse(const QString &source)
_components.insertMulti(entry.typeName, entry);
} else if (sections[0] == QLatin1String("typeinfo")) {
if (sectionCount != 2) {
reportError(lineNumber, -1,
reportError(lineNumber, 0,
QString::fromUtf8("typeinfo requires 1 argument, but %1 were provided").arg(sectionCount - 1));
continue;
}
......@@ -195,9 +195,9 @@ bool QmlDirParser::parse(const QString &source)
const int dotIndex = version.indexOf(QLatin1Char('.'));
if (dotIndex == -1) {
reportError(lineNumber, -1, QLatin1String("expected '.'"));
reportError(lineNumber, 0, QLatin1String("expected '.'"));
} else if (version.indexOf(QLatin1Char('.'), dotIndex + 1) != -1) {
reportError(lineNumber, -1, QLatin1String("unexpected '.'"));
reportError(lineNumber, 0, QLatin1String("unexpected '.'"));
} else {
bool validVersionNumber = false;
const int majorVersion = parseInt(QStringRef(&version, 0, dotIndex), &validVersionNumber);
......@@ -220,7 +220,7 @@ bool QmlDirParser::parse(const QString &source)
}
}
} else {
reportError(lineNumber, -1,
reportError(lineNumber, 0,
QString::fromUtf8("a component declaration requires two or three arguments, but %1 were provided").arg(sectionCount));
}
......@@ -230,7 +230,7 @@ bool QmlDirParser::parse(const QString &source)
return hasError();
}
void QmlDirParser::reportError(int line, int column, const QString &description)
void QmlDirParser::reportError(quint16 line, quint16 column, const QString &description)
{
QmlError error;
error.setLine(line);
......
......@@ -128,7 +128,7 @@ public:
#endif
private:
void reportError(int line, int column, const QString &message);
void reportError(quint16 line, quint16 column, const QString &message);
private:
QList<QmlError> _errors;
......
......@@ -28,6 +28,7 @@
****************************************************************************/
#include "qmlerror.h"
#include "qmlglobal_p.h"
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
......@@ -69,12 +70,12 @@ public:
QUrl url;
QString description;
int line;
int column;
quint16 line;
quint16 column;
};
QmlErrorPrivate::QmlErrorPrivate()
: line(-1), column(-1)
: line(0), column(0)
{
}
......@@ -114,7 +115,7 @@ QmlError &QmlError::operator=(const QmlError &other)
}
/*!
\internal
\internal
*/
QmlError::~QmlError()
{
......@@ -170,7 +171,7 @@ void QmlError::setDescription(const QString &description)
*/
int QmlError::line() const
{
if (d) return d->line;
if (d) return qmlSourceCoordinate(d->line);
else return -1;
}
......@@ -180,7 +181,7 @@ int QmlError::line() const
void QmlError::setLine(int line)
{
if (!d) d = new QmlErrorPrivate;
d->line = line;
d->line = qmlSourceCoordinate(line);
}
/*!
......@@ -188,7 +189,7 @@ void QmlError::setLine(int line)
*/
int QmlError::column() const
{
if (d) return d->column;
if (d) return qmlSourceCoordinate(d->column);
else return -1;
}
......@@ -198,7 +199,7 @@ int QmlError::column() const
void QmlError::setColumn(int column)
{
if (!d) d = new QmlErrorPrivate;
d->column = column;
d->column = qmlSourceCoordinate(column);
}
/*!
......@@ -207,14 +208,20 @@ void QmlError::setColumn(int column)
QString QmlError::toString() const
{
QString rv;
if (url().isEmpty()) {
QUrl u(url());
int l(line());
if (u.isEmpty()) {
rv = QLatin1String("<Unknown File>");
} else if (line() != -1) {
rv = url().toString() + QLatin1Char(':') + QString::number(line());
if (column() != -1)
rv += QLatin1Char(':') + QString::number(column());
} else if (l != -1) {
rv = u.toString() + QLatin1Char(':') + QString::number(l);
int c(column());
if (c != -1)
rv += QLatin1Char(':') + QString::number(c);
} else {
rv = url().toString();
rv = u.toString();
}
rv += QLatin1String(": ") + description();
......@@ -251,9 +258,9 @@ QDebug operator<<(QDebug debug, const QmlError &error)
const QString &line = lines.at(error.line() - 1);
debug << "\n " << qPrintable(line);
if (error.column() > 0) {
if(error.column() > 0) {
int column = qMax(0, error.column() - 1);
column = qMin(column, line.length());
column = qMin(column, line.length());
QByteArray ind;
ind.reserve(column);
......
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
--
-- Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
-- Contact: http://www.qt-project.org/legal
--
-- 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 Digia. For licensing terms and
-- conditions see http://qt.digia.com/licensing. For further information
-- use the contact form at http://qt.digia.com/contact-us.
-- This file is part of the QtQml module of the Qt Toolkit.
--
-- $QT_BEGIN_LICENSE:LGPL-ONLY$
-- GNU Lesser General Public License Usage
-- Alternatively, this file may be used under the terms of the GNU Lesser
-- This file may be used under the terms of the GNU Lesser
-- General Public License version 2.1 as published by the Free Software
-- Foundation and appearing in the file LICENSE.LGPL included in the
-- packaging of this file. Please review the following information to
-- ensure the GNU Lesser General Public License version 2.1 requirements
-- will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
--
-- In addition, as a special exception, Digia gives you certain additional
-- rights. These rights are described in the Digia Qt LGPL Exception
-- version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-- If you have questions regarding the use of this file, please contact
-- us via http://www.qt-project.org/.
--
-----------------------------------------------------------------------------
-- $QT_END_LICENSE$
--
----------------------------------------------------------------------------
%parser QmlJSGrammar
%decl qmljsparser_p.h
%impl qdeclarativejsparser.cpp
%impl qmljsparser.cpp
%expect 2
%expect-rr 2
......@@ -68,6 +60,7 @@
%token T_RESERVED_WORD "reserved word"
%token T_MULTILINE_STRING_LITERAL "multiline string literal"
%token T_COMMENT "comment"
%token T_COMPATIBILITY_SEMICOLON
--- context keywords.
%token T_PUBLIC "public"
......@@ -96,8 +89,9 @@
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
** This file is part of the QtQml module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
......@@ -118,10 +112,20 @@
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtCore/QDebug>
#include <QtCore/QtDebug>
#include <QtCore/QCoreApplication>
#include <string.h>
......@@ -138,8 +142,9 @@
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
** This file is part of the QtQml module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
......@@ -160,10 +165,20 @@
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
......@@ -175,9 +190,16 @@
// We mean it.
//
//
// W A R N I N G
// -------------
//
// This file is automatically generated from qmljs.g.
// Changes will be lost.
// Changes should be made to that file, not here. Any change to this file will
// be lost!
//
// To regenerate this file, run:
// qlalr --no-debug --no-lines --qt qmljs.g
//
#ifndef QMLJSPARSER_P_H
......@@ -368,9 +390,16 @@ protected:
#include "qmljsparser_p.h"
#include <QVarLengthArray>
//
// W A R N I N G
// -------------
//
// This file is automatically generated from qmljs.g.
// Changes will be lost.
// Changes should be made to that file, not here. Any change to this file will
// be lost!
//
// To regenerate this file, run:
// qlalr --no-debug --no-lines --qt qmljs.g
//
using namespace QmlJS;
......@@ -2411,6 +2440,7 @@ case $rule_number: {
IterationStatement: T_DO Statement T_WHILE T_LPAREN Expression T_RPAREN T_AUTOMATIC_SEMICOLON ; -- automatic semicolon
IterationStatement: T_DO Statement T_WHILE T_LPAREN Expression T_RPAREN T_COMPATIBILITY_SEMICOLON ; -- for JSC/V8 compatibility
IterationStatement: T_DO Statement T_WHILE T_LPAREN Expression T_RPAREN T_SEMICOLON ;
/.
case $rule_number: {
......@@ -2875,7 +2905,8 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
const int errorState = state_stack[tos];
// automatic insertion of `;'
if (yytoken != -1 && t_action(errorState, T_AUTOMATIC_SEMICOLON) && lexer->canInsertAutomaticSemicolon(yytoken)) {
if (yytoken != -1 && ((t_action(errorState, T_AUTOMATIC_SEMICOLON) && lexer->canInsertAutomaticSemicolon(yytoken))
|| t_action(errorState, T_COMPATIBILITY_SEMICOLON))) {
SavedToken &tk = token_buffer[0];
tk.token = yytoken;
tk.dval = yylval;
......@@ -2887,7 +2918,7 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
yylloc.startColumn += yylloc.length;
yylloc.length = 0;
//const QString msg = qApp->translate("QQmlParser", "Missing `;'");
//const QString msg = qApp->translate("QmlParser", "Missing `;'");
//diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, yylloc, msg));
first_token = &token_buffer[0];
......@@ -2917,9 +2948,9 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
QString msg;
int token = token_buffer[0].token;
if (token < 0 || token >= TERMINAL_COUNT)
msg = qApp->translate("QQmlParser", "Syntax error");
msg = qApp->translate("QmlParser", "Syntax error");
else
msg = qApp->translate("QQmlParser", "Unexpected token `%1'").arg(QLatin1String(spell[token]));
msg = qApp->translate("QmlParser", "Unexpected token `%1'").arg(QLatin1String(spell[token]));
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg));
action = errorState;
......@@ -2947,7 +2978,7 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
for (int *tk = tokens; *tk != EOF_SYMBOL; ++tk) {
int a = t_action(errorState, *tk);
if (a > 0 && t_action(a, yytoken)) {
const QString msg = qApp->translate("QQmlParser", "Expected token `%1'").arg(QLatin1String(spell[*tk]));
const QString msg = qApp->translate("QmlParser", "Expected token `%1'").arg(QLatin1String(spell[*tk]));
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg));
yytoken = *tk;
......@@ -2971,7 +3002,7 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
int a = t_action(errorState, tk);
if (a > 0 && t_action(a, yytoken)) {
const QString msg = qApp->translate("QQmlParser", "Expected token `%1'").arg(QLatin1String(spell[tk]));
const QString msg = qApp->translate("QmlParser", "Expected token `%1'").arg(QLatin1String(spell[tk]));
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg));
yytoken = tk;
......@@ -2984,7 +3015,7 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
}
}
const QString msg = qApp->translate("QQmlParser", "Syntax error");
const QString msg = qApp->translate("QmlParser", "Syntax error");
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, token_buffer[0].loc, msg));
}
......
......@@ -110,7 +110,7 @@ double integerFromString(const QString &str, int radix)
Engine::Engine()
: _lexer(0), _directives(0)
: _lexer(0), directives(0)
{ }
Engine::~Engine()
......
This diff is collapsed.
......@@ -52,12 +52,12 @@ class QML_PARSER_EXPORT QmlJSGrammar
public:
enum VariousConstants {
EOF_SYMBOL = 0,
REDUCE_HERE = 101,
SHIFT_THERE = 100,
REDUCE_HERE = 102,
SHIFT_THERE = 101,
T_AND = 1,
T_AND_AND = 2,
T_AND_EQ = 3,
T_AS = 91,
T_AS = 92,
T_AUTOMATIC_SEMICOLON = 62,
T_BREAK = 4,
T_CASE = 5,
......@@ -65,6 +65,7 @@ public:
T_COLON = 7,
T_COMMA = 8,
T_COMMENT = 88,
T_COMPATIBILITY_SEMICOLON = 89,
T_CONST = 84,
T_CONTINUE = 9,
T_DEBUGGER = 85,
......@@ -78,14 +79,14 @@ public:
T_EQ = 17,
T_EQ_EQ = 18,
T_EQ_EQ_EQ = 19,
T_ERROR = 93,
T_ERROR = 94,
T_FALSE = 83,
T_FEED_JS_EXPRESSION = 97,
T_FEED_JS_PROGRAM = 99,
T_FEED_JS_SOURCE_ELEMENT = 98,
T_FEED_JS_STATEMENT = 96,
T_FEED_UI_OBJECT_MEMBER = 95,
T_FEED_UI_PROGRAM = 94,
T_FEED_JS_EXPRESSION = 98,
T_FEED_JS_PROGRAM = 100,
T_FEED_JS_SOURCE_ELEMENT = 99,
T_FEED_JS_STATEMENT = 97,
T_FEED_UI_OBJECT_MEMBER = 96,
T_FEED_UI_PROGRAM = 95,
T_FINALLY = 20,
T_FOR = 21,
T_FUNCTION = 22,
......@@ -97,7 +98,7 @@ public:
T_GT_GT_GT_EQ = 28,
T_IDENTIFIER = 29,
T_IF = 30,
T_IMPORT = 90,
T_IMPORT = 91,
T_IN = 31,
T_INSTANCEOF = 32,
T_LBRACE = 33,
......@@ -117,7 +118,7 @@ public:
T_NOT_EQ_EQ = 46,
T_NULL = 81,
T_NUMERIC_LITERAL = 47,
T_ON = 92,
T_ON = 93,
T_OR = 48,
T_OR_EQ = 49,
T_OR_OR = 50,
......@@ -125,7 +126,7 @@ public:
T_PLUS_EQ = 52,
T_PLUS_PLUS = 53,
T_PROPERTY = 66,
T_PUBLIC = 89,
T_PUBLIC = 90,
T_QUESTION = 54,
T_RBRACE = 55,
T_RBRACKET = 56,
......@@ -154,15 +155,15 @@ public:
T_XOR = 79,
T_XOR_EQ = 80,
ACCEPT_STATE = 644,
RULE_COUNT = 349,
STATE_COUNT = 645,
TERMINAL_COUNT = 102,
ACCEPT_STATE = 645,
RULE_COUNT = 350,
STATE_COUNT = 646,
TERMINAL_COUNT = 103,
NON_TERMINAL_COUNT = 107,
GOTO_INDEX_OFFSET = 645,
GOTO_INFO_OFFSET = 2807,
GOTO_CHECK_OFFSET = 2807
GOTO_INDEX_OFFSET = 646,
GOTO_INFO_OFFSET = 3019,
GOTO_CHECK_OFFSET = 3019
};
static const char *const spell [];
......
......@@ -44,7 +44,7 @@
static inline int classify2(const QChar *s, bool qmlMode) {
if (s[0].unicode() == 'a') {