QmlJS: Update to latest QmlJS parser from Qt 5.

Using qtdeclarative revision c9b7582a2e7ad9fcd03dd999c3b7a16b72803238

Change-Id: I9c942fa04c3fab5ef57b38e13471d0a4e2e8a2bf
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
Christian Kamm
2012-07-31 10:12:26 +02:00
parent 26bd1860d1
commit a14ed0793c
20 changed files with 422 additions and 360 deletions

View File

@@ -1,8 +1,9 @@
s/private\/qdeclarative/qml/g
s/qdeclarative/qml/g
s/qqml/qml/g
s/QDECLARATIVE/QML/g
s/QDeclarative/Qml/g
s/Q_DECLARATIVE_EXPORT //g
s/QQml/Qml/g
s/QQMLJS/QMLJS/g
s/Q_QML_EXPORT //g
# adjust pri file
s/ \$\$PWD\/qmljsglobal_p.h/ $$PWD\/qmljsglobal_p.h \\\

View File

@@ -2,20 +2,29 @@
me=$(dirname $0)
for i in $QTDIR/src/declarative/qml/parser/*.{g,h,cpp,pri}; do
sed -f $me/cmd.sed $i > $me/$(echo $(basename $i) | sed s/qdeclarativejs/qmljs/)
for i in $QTDIR/src/qml/qml/parser/*.{g,h,cpp,pri}; do
sed -f $me/cmd.sed $i > $me/$(echo $(basename $i) | sed s/qqmljs/qmljs/)
done
for i in $QTDIR/src/declarative/qml/qdeclarative{error.{h,cpp},dirparser{_p.h,.cpp}}; do
sed -f $me/cmd.sed $i > $me/$(echo $(basename $i) | sed s/qdeclarative/qml/)
for i in $QTDIR/src/qml/qml/qqml{error.{h,cpp},dirparser{_p.h,.cpp}}; do
sed -f $me/cmd.sed $i > $me/$(echo $(basename $i) | sed s/qqml/qml/)
done
# export QmlDirParser
perl -p -0777 -i -e 's/QT_BEGIN_NAMESPACE\n\nclass QmlError;\nclass QmlDirParser/#include "qmljsglobal_p.h"\n\nQT_BEGIN_NAMESPACE\n\nclass QmlError;\nclass QML_PARSER_EXPORT QmlDirParser/' qmldirparser_p.h
# export QmlJSGrammar
perl -p -0777 -i -e 's/#include <QtCore\/qglobal.h>\n\nQT_BEGIN_NAMESPACE\n\nclass QmlJSGrammar\n/#include "qmljsglobal_p.h"\n#include <QtCore\/qglobal.h>\n\nQT_BEGIN_NAMESPACE\n\nclass QML_PARSER_EXPORT QmlJSGrammar\n/' qmljsgrammar_p.h
# replace qmlglobal_p.h include with needed declaration
perl -p -0777 -i -e 's/#include \"qmlglobal_p.h\"/bool Qml_isFileCaseCorrect(const QString &) { return true; }/' qmldirparser.cpp
# remove qmlglobal_p.h include
perl -p -0777 -i -e 's/#include \"qmlglobal_p.h\"//' qmldirparser.cpp
# remove qmlglobal_p.h include
perl -p -0777 -i -e 's/#include \<QtQml\/qmlfile.h\>//' qmldirparser.cpp
# remove QtQml/qtqmlglobal.h include
perl -p -0777 -i -e 's/#include \<QtQml\/qtqmlglobal.h\>//' qmlerror.h
# replace private/qhashedstring_p.h include and QHashedStringRef
perl -p -0777 -i -e 's/#include \<private\/qhashedstring_p.h\>//' qmldirparser_p.h
perl -p -0777 -i -e 's/QHashedStringRef/QString/g' qmldirparser_p.h qmldirparser.cpp
# don't use the new QVarLengthArray::length()
sed -i -e 's/chars.length()/chars.size()/' $me/qmljslexer.cpp
./changeLicense.py $me/../qmljs_global.h qml*.{cpp,h}

View File

@@ -1,19 +1,18 @@
diff --git b/src/libs/qmljs/parser/qmljs.g a/src/libs/qmljs/parser/qmljs.g
index 6888b65..784e47f 100644
--- b/src/libs/qmljs/parser/qmljs.g
+++ a/src/libs/qmljs/parser/qmljs.g
@@ -1,23 +1,32 @@
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
@@ -1,23 +1,30 @@
----------------------------------------------------------------------------
--
--- Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
--- All rights reserved.
+-- This file is part of Qt Creator
+--
+-- Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
+--
-- Contact: http://www.qt-project.org/
--
--- This file is part of the QtDeclarative module of the Qt Toolkit.
--- This file is part of the QtQml module of the Qt Toolkit.
--
--- $QT_BEGIN_LICENSE:LGPL-ONLY$
-- GNU Lesser General Public License Usage
@@ -23,7 +22,9 @@ index 6888b65..784e47f 100644
--- 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.
+--
--
--- If you have questions regarding the use of this file, please contact
--- us via http://www.qt-project.org/.
+-- 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.
@@ -44,7 +45,7 @@ index 6888b65..784e47f 100644
--
----------------------------------------------------------------------------
@@ -83,46 +92,37 @@
@@ -83,46 +90,36 @@
%start TopLevel
@@ -56,10 +57,9 @@ index 6888b65..784e47f 100644
+** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
** Contact: http://www.qt-project.org/
**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
-** This file is part of the QtQml module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
@@ -95,14 +95,16 @@ index 6888b65..784e47f 100644
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+**************************************************************************/
+
#include <QtCore/QtDebug>
#include <QtCore/QCoreApplication>
@@ -136,46 +136,37 @@
@@ -136,46 +133,36 @@
./
@@ -114,10 +116,9 @@ index 6888b65..784e47f 100644
+** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
** Contact: http://www.qt-project.org/
**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
-** This file is part of the QtQml module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
@@ -153,10 +154,12 @@ index 6888b65..784e47f 100644
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+**************************************************************************/
+
//
@@ -164,7 +167,7 @@ diff --git b/src/libs/qmljs/parser/qmljsengine_p.cpp a/src/libs/qmljs/parser/qml
index 5b204c9..10e39ab 100644
--- b/src/libs/qmljs/parser/qmljsengine_p.cpp
+++ a/src/libs/qmljs/parser/qmljsengine_p.cpp
@@ -113,7 +113,7 @@ double integerFromString(const QString &str, int radix)
@@ -111,7 +111,7 @@ double integerFromString(const QString &str, int radix)
Engine::Engine()
@@ -173,7 +176,7 @@ index 5b204c9..10e39ab 100644
{ }
Engine::~Engine()
@@ -134,6 +134,12 @@ Lexer *Engine::lexer() const
@@ -132,6 +132,12 @@ Lexer *Engine::lexer() const
void Engine::setLexer(Lexer *lexer)
{ _lexer = lexer; }
@@ -190,7 +193,7 @@ diff --git b/src/libs/qmljs/parser/qmljsengine_p.h a/src/libs/qmljs/parser/qmljs
index 5057ea0..487619e 100644
--- b/src/libs/qmljs/parser/qmljsengine_p.h
+++ a/src/libs/qmljs/parser/qmljsengine_p.h
@@ -56,6 +56,7 @@ QT_QML_BEGIN_NAMESPACE
@@ -54,6 +54,7 @@ QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
class Lexer;
@@ -198,7 +201,7 @@ index 5057ea0..487619e 100644
class MemoryPool;
class QML_PARSER_EXPORT DiagnosticMessage
@@ -83,6 +84,7 @@ public:
@@ -81,6 +82,7 @@ public:
class QML_PARSER_EXPORT Engine
{
Lexer *_lexer;
@@ -206,7 +209,7 @@ index 5057ea0..487619e 100644
MemoryPool _pool;
QList<AST::SourceLocation> _comments;
QString _extraCode;
@@ -100,6 +102,9 @@ public:
@@ -98,6 +100,9 @@ public:
Lexer *lexer() const;
void setLexer(Lexer *lexer);
@@ -220,7 +223,7 @@ diff --git b/src/libs/qmljs/parser/qmljsparser.cpp a/src/libs/qmljs/parser/qmljs
index a731c1a..e986534 100644
--- b/src/libs/qmljs/parser/qmljsparser.cpp
+++ a/src/libs/qmljs/parser/qmljsparser.cpp
@@ -138,7 +138,20 @@ bool Parser::parse(int startToken)
@@ -137,7 +137,20 @@ bool Parser::parse(int startToken)
token_buffer[0].token = startToken;
first_token = &token_buffer[0];

View File

@@ -10,7 +10,7 @@ HEADERS += \
$$PWD/qmljsglobal_p.h \
$$PWD/qmldirparser_p.h \
$$PWD/qmlerror.h \
$$PWD/qmljskeywords_p.h
$$PWD/qmljskeywords_p.h \
SOURCES += \
$$PWD/qmljsast.cpp \
@@ -20,4 +20,4 @@ SOURCES += \
$$PWD/qmljslexer.cpp \
$$PWD/qmljsparser.cpp \
$$PWD/qmldirparser.cpp \
$$PWD/qmlerror.cpp
$$PWD/qmlerror.cpp \

View File

@@ -30,16 +30,31 @@
#include "qmldirparser_p.h"
#include "qmlerror.h"
bool Qml_isFileCaseCorrect(const QString &) { return true; }
#include <QTextStream>
#include <QFile>
#include <QtDebug>
#include <QtCore/QtDebug>
QT_BEGIN_NAMESPACE
static int parseInt(const QStringRef &str, bool *ok)
{
int pos = 0;
int number = 0;
while (pos < str.length() && str.at(pos).isDigit()) {
if (pos != 0)
number *= 10;
number += str.at(pos).unicode() - '0';
++pos;
}
if (pos != str.length())
*ok = false;
else
*ok = true;
return number;
}
QmlDirParser::QmlDirParser()
: _isParsed(false)
{
}
@@ -47,116 +62,99 @@ QmlDirParser::~QmlDirParser()
{
}
QUrl QmlDirParser::url() const
{
return _url;
inline static void scanSpace(const QChar *&ch) {
while (ch->isSpace() && !ch->isNull() && *ch != QLatin1Char('\n'))
++ch;
}
void QmlDirParser::setUrl(const QUrl &url)
{
_url = url;
inline static void scanToEnd(const QChar *&ch) {
while (*ch != QLatin1Char('\n') && !ch->isNull())
++ch;
}
QString QmlDirParser::fileSource() const
{
return _filePathSouce;
inline static void scanWord(const QChar *&ch) {
while (!ch->isSpace() && !ch->isNull())
++ch;
}
void QmlDirParser::setFileSource(const QString &filePath)
/*!
\a url is used for generating errors.
*/
bool QmlDirParser::parse(const QString &source)
{
_filePathSouce = filePath;
}
QString QmlDirParser::source() const
{
return _source;
}
void QmlDirParser::setSource(const QString &source)
{
_isParsed = false;
_source = source;
}
bool QmlDirParser::isParsed() const
{
return _isParsed;
}
bool QmlDirParser::parse()
{
if (_isParsed)
return true;
_isParsed = true;
_errors.clear();
_plugins.clear();
_components.clear();
_scripts.clear();
if (_source.isEmpty() && !_filePathSouce.isEmpty()) {
QFile file(_filePathSouce);
if (!Qml_isFileCaseCorrect(_filePathSouce)) {
QmlError error;
error.setDescription(QString::fromUtf8("cannot load module \"$$URI$$\": File name case mismatch for \"%1\"").arg(_filePathSouce));
_errors.prepend(error);
return false;
} else if (file.open(QFile::ReadOnly)) {
_source = QString::fromUtf8(file.readAll());
} else {
QmlError error;
error.setDescription(QString::fromUtf8("module \"$$URI$$\" definition \"%1\" not readable").arg(_filePathSouce));
_errors.prepend(error);
return false;
}
}
QTextStream stream(&_source);
int lineNumber = 0;
bool firstLine = true;
forever {
const QChar *ch = source.constData();
while (!ch->isNull()) {
++lineNumber;
const QString line = stream.readLine();
if (line.isNull())
bool invalidLine = false;
const QChar *lineStart = ch;
scanSpace(ch);
if (*ch == QLatin1Char('\n')) {
++ch;
continue;
}
if (ch->isNull())
break;
QString sections[3];
int sectionCount = 0;
int index = 0;
const int length = line.length();
while (index != length) {
const QChar ch = line.at(index);
if (ch.isSpace()) {
do { ++index; }
while (index != length && line.at(index).isSpace());
} else if (ch == QLatin1Char('#')) {
// recognized a comment
do {
if (*ch == QLatin1Char('#')) {
scanToEnd(ch);
break;
}
const QChar *start = ch;
scanWord(ch);
if (sectionCount < 3) {
sections[sectionCount++] = source.mid(start-source.constData(), ch-start);
} else {
const int start = index;
do { ++index; }
while (index != length && !line.at(index).isSpace());
const QString lexeme = line.mid(start, index - start);
if (sectionCount >= 3) {
reportError(lineNumber, start, QLatin1String("unexpected token"));
} else {
sections[sectionCount++] = lexeme;
}
}
reportError(lineNumber, start-lineStart, QLatin1String("unexpected token"));
scanToEnd(ch);
invalidLine = true;
break;
}
scanSpace(ch);
} while (*ch != QLatin1Char('\n') && !ch->isNull());
if (sectionCount == 0) {
if (!ch->isNull())
++ch;
if (invalidLine) {
reportError(lineNumber, -1,
QString::fromUtf8("invalid qmldir directive contains too many tokens"));
continue;
} else if (sectionCount == 0) {
continue; // no sections, no party.
} 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));
continue;
}
if (!_typeNamespace.isEmpty()) {
reportError(lineNumber, -1,
QString::fromUtf8("only one module 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"));
continue;
}
_typeNamespace = sections[1];
} else if (sections[0] == QLatin1String("plugin")) {
if (sectionCount < 2) {
reportError(lineNumber, -1,
@@ -177,7 +175,7 @@ bool QmlDirParser::parse()
}
Component entry(sections[1], sections[2], -1, -1);
entry.internal = true;
_components.append(entry);
_components.insertMulti(entry.typeName, entry);
} else if (sections[0] == QLatin1String("typeinfo")) {
if (sectionCount != 2) {
reportError(lineNumber, -1,
@@ -192,7 +190,7 @@ bool QmlDirParser::parse()
} else if (sectionCount == 2) {
// No version specified (should only be used for relative qmldir files)
const Component entry(sections[0], sections[1], -1, -1);
_components.append(entry);
_components.insertMulti(entry.typeName, entry);
} else if (sectionCount == 3) {
const QString &version = sections[1];
const int dotIndex = version.indexOf(QLatin1Char('.'));
@@ -203,15 +201,22 @@ bool QmlDirParser::parse()
reportError(lineNumber, -1, QLatin1String("unexpected '.'"));
} else {
bool validVersionNumber = false;
const int majorVersion = version.left(dotIndex).toInt(&validVersionNumber);
const int majorVersion = parseInt(QStringRef(&version, 0, dotIndex), &validVersionNumber);
if (validVersionNumber) {
const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber);
const int minorVersion = parseInt(QStringRef(&version, dotIndex+1, version.length()-dotIndex-1), &validVersionNumber);
if (validVersionNumber) {
const Component entry(sections[0], sections[2], majorVersion, minorVersion);
const QString &fileName = sections[2];
_components.append(entry);
if (fileName.endsWith(QLatin1String(".js"))) {
// A 'js' extension indicates a namespaced script import
const Script entry(sections[0], fileName, majorVersion, minorVersion);
_scripts.append(entry);
} else {
const Component entry(sections[0], fileName, majorVersion, minorVersion);
_components.insertMulti(entry.typeName, entry);
}
}
}
}
@@ -219,6 +224,8 @@ bool QmlDirParser::parse()
reportError(lineNumber, -1,
QString::fromUtf8("a component declaration requires two or three arguments, but %1 were provided").arg(sectionCount));
}
firstLine = false;
}
return hasError();
@@ -227,7 +234,6 @@ bool QmlDirParser::parse()
void QmlDirParser::reportError(int line, int column, const QString &description)
{
QmlError error;
error.setUrl(_url);
error.setLine(line);
error.setColumn(column);
error.setDescription(description);
@@ -242,28 +248,51 @@ bool QmlDirParser::hasError() const
return false;
}
void QmlDirParser::setError(const QmlError &e)
{
_errors.clear();
_errors.append(e);
}
QList<QmlError> QmlDirParser::errors(const QString &uri) const
{
QUrl url(uri);
QList<QmlError> errors = _errors;
for (int i = 0; i < errors.size(); ++i) {
QmlError &e = errors[i];
QString description = e.description();
description.replace(QLatin1String("$$URI$$"), uri);
e.setDescription(description);
e.setUrl(url);
}
return errors;
}
QString QmlDirParser::typeNamespace() const
{
return _typeNamespace;
}
void QmlDirParser::setTypeNamespace(const QString &s)
{
_typeNamespace = s;
}
QList<QmlDirParser::Plugin> QmlDirParser::plugins() const
{
return _plugins;
}
QList<QmlDirParser::Component> QmlDirParser::components() const
QHash<QString,QmlDirParser::Component> QmlDirParser::components() const
{
return _components;
}
QList<QmlDirParser::Script> QmlDirParser::scripts() const
{
return _scripts;
}
#ifdef QT_CREATOR
QList<QmlDirParser::TypeInfo> QmlDirParser::typeInfos() const
{
@@ -271,4 +300,18 @@ QList<QmlDirParser::TypeInfo> QmlDirParser::typeInfos() const
}
#endif
QDebug &operator<< (QDebug &debug, const QmlDirParser::Component &component)
{
const QString output = QString::fromLatin1("{%1 %2.%3}").
arg(component.typeName).arg(component.majorVersion).arg(component.minorVersion);
return debug << qPrintable(output);
}
QDebug &operator<< (QDebug &debug, const QmlDirParser::Script &script)
{
const QString output = QString::fromLatin1("{%1 %2.%3}").
arg(script.nameSpace).arg(script.majorVersion).arg(script.minorVersion);
return debug << qPrintable(output);
}
QT_END_NAMESPACE

View File

@@ -28,8 +28,8 @@
**
**************************************************************************/
#ifndef QMLDIRPARSER_P_H
#define QMLDIRPARSER_P_H
#ifndef QQMLDIRPARSER_P_H
#define QQMLDIRPARSER_P_H
//
// W A R N I N G
@@ -42,15 +42,16 @@
// We mean it.
//
#include <QUrl>
#include <QHash>
#include <QtCore/QUrl>
#include <QtCore/QHash>
#include <QtCore/QDebug>
#include "qmljsglobal_p.h"
QT_BEGIN_NAMESPACE
class QmlError;
class QML_PARSER_EXPORT QmlDirParser
class QmlEngine;
class Q_AUTOTEST_EXPORT QmlDirParser
{
Q_DISABLE_COPY(QmlDirParser)
@@ -58,21 +59,15 @@ public:
QmlDirParser();
~QmlDirParser();
QUrl url() const;
void setUrl(const QUrl &url);
QString fileSource() const;
void setFileSource(const QString &filePath);
QString source() const;
void setSource(const QString &source);
bool isParsed() const;
bool parse();
bool parse(const QString &source);
bool hasError() const;
void setError(const QmlError &);
QList<QmlError> errors(const QString &uri) const;
QString typeNamespace() const;
void setTypeNamespace(const QString &s);
struct Plugin
{
Plugin() {}
@@ -100,7 +95,22 @@ public:
bool internal;
};
QList<Component> components() const;
struct Script
{
Script()
: majorVersion(0), minorVersion(0) {}
Script(const QString &nameSpace, const QString &fileName, int majorVersion, int minorVersion)
: nameSpace(nameSpace), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion) {}
QString nameSpace;
QString fileName;
int majorVersion;
int minorVersion;
};
QHash<QString,Component> components() const;
QList<Script> scripts() const;
QList<Plugin> plugins() const;
#ifdef QT_CREATOR
@@ -121,20 +131,22 @@ private:
private:
QList<QmlError> _errors;
QUrl _url;
QString _source;
QString _filePathSouce;
QList<Component> _components;
QString _typeNamespace;
QHash<QString,Component> _components; // multi hash
QList<Script> _scripts;
QList<Plugin> _plugins;
#ifdef QT_CREATOR
QList<TypeInfo> _typeInfos;
#endif
unsigned _isParsed: 1;
};
typedef QList<QmlDirParser::Component> QmlDirComponents;
typedef QHash<QString,QmlDirParser::Component> QmlDirComponents;
typedef QList<QmlDirParser::Script> QmlDirScripts;
typedef QList<QmlDirParser::Plugin> QmlDirPlugins;
QDebug &operator<< (QDebug &, const QmlDirParser::Component &);
QDebug &operator<< (QDebug &, const QmlDirParser::Script &);
QT_END_NAMESPACE
#endif // QMLDIRPARSER_P_H
#endif // QQMLDIRPARSER_P_H

View File

@@ -30,15 +30,16 @@
#include "qmlerror.h"
#include <qdebug.h>
#include <qfile.h>
#include <qstringlist.h>
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
#include <QtCore/qstringlist.h>
QT_BEGIN_NAMESPACE
/*!
\class QmlError
\since 4.7
\since 5.0
\inmodule QtQml
\brief The QmlError class encapsulates a QML error.
QmlError includes a textual description of the error, as well
@@ -58,7 +59,9 @@ QT_BEGIN_NAMESPACE
^
\endcode
\sa QmlView::errors(), QmlComponent::errors()
Note that the QtQuick 1 version is named QDeclarativeError
\sa QQuickView::errors(), QmlComponent::errors()
*/
class QmlErrorPrivate
{

View File

@@ -28,17 +28,18 @@
**
**************************************************************************/
#ifndef QMLERROR_H
#define QMLERROR_H
#ifndef QQMLERROR_H
#define QQMLERROR_H
#include <qurl.h>
#include <qstring.h>
#include <QtCore/qurl.h>
#include <QtCore/qstring.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDebug;
class QmlErrorPrivate;
@@ -68,8 +69,10 @@ private:
QDebug operator<<(QDebug debug, const QmlError &error);
Q_DECLARE_TYPEINFO(QmlError, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
QT_END_HEADER
#endif // QMLERROR_H
#endif // QQMLERROR_H

View File

@@ -30,7 +30,7 @@
%parser QmlJSGrammar
%decl qmljsparser_p.h
%impl qmljsparser.cpp
%impl qdeclarativejsparser.cpp
%expect 2
%expect-rr 2
@@ -120,6 +120,7 @@
**
**************************************************************************/
#include <QtCore/QtDebug>
#include <QtCore/QCoreApplication>
@@ -163,6 +164,7 @@
**************************************************************************/
//
// W A R N I N G
// -------------
@@ -383,10 +385,10 @@ void Parser::reallocateStack()
else
stack_size <<= 1;
sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value)));
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<AST::SourceLocation*> (qRealloc(location_stack, stack_size * sizeof(AST::SourceLocation)));
string_stack = reinterpret_cast<QStringRef*> (qRealloc(string_stack, stack_size * sizeof(QStringRef)));
sym_stack = reinterpret_cast<Value*> (realloc(sym_stack, stack_size * sizeof(Value)));
state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<AST::SourceLocation*> (realloc(location_stack, stack_size * sizeof(AST::SourceLocation)));
string_stack = reinterpret_cast<QStringRef*> (realloc(string_stack, stack_size * sizeof(QStringRef)));
}
Parser::Parser(Engine *engine):
@@ -406,10 +408,10 @@ Parser::Parser(Engine *engine):
Parser::~Parser()
{
if (stack_size) {
qFree(sym_stack);
qFree(state_stack);
qFree(location_stack);
qFree(string_stack);
free(sym_stack);
free(state_stack);
free(location_stack);
free(string_stack);
}
}

View File

@@ -46,7 +46,7 @@
#include "qmljsglobal_p.h"
#include "qmljsmemorypool_p.h"
#include <QString>
#include <QtCore/QString>
QT_QML_BEGIN_NAMESPACE

View File

@@ -33,7 +33,7 @@
#include "qmljsglobal_p.h"
#include <qglobal.h>
#include <QtCore/qglobal.h>
//
// W A R N I N G

View File

@@ -30,7 +30,7 @@
#ifndef QMLJSGLOBAL_P_H
#define QMLJSGLOBAL_P_H
#include <qglobal.h>
#include <QtCore/qglobal.h>
#ifdef QT_CREATOR
# define QT_QML_BEGIN_NAMESPACE

View File

@@ -44,7 +44,7 @@
#define QMLJSGRAMMAR_P_H
#include "qmljsglobal_p.h"
#include <qglobal.h>
#include <QtCore/qglobal.h>
QT_BEGIN_NAMESPACE

View File

@@ -32,9 +32,9 @@
#include "qmljsengine_p.h"
#include "qmljsmemorypool_p.h"
#include <QCoreApplication>
#include <QVarLengthArray>
#include <QDebug>
#include <QtCore/QCoreApplication>
#include <QtCore/QVarLengthArray>
#include <QtCore/QDebug>
QT_BEGIN_NAMESPACE
Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok);
@@ -660,6 +660,17 @@ again:
_errorMessage = QCoreApplication::translate("QmlParser", "Unclosed string at end of line");
return T_ERROR;
}
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return scanNumber(ch);
default:
if (ch.isLetter() || ch == QLatin1Char('$') || ch == QLatin1Char('_') || (ch == QLatin1Char('\\') && _char == QLatin1Char('u'))) {
@@ -716,7 +727,16 @@ again:
return kind;
}
}
} else if (ch.isDigit()) {
}
break;
}
return T_ERROR;
}
int Lexer::scanNumber(QChar ch)
{
if (ch != QLatin1Char('0')) {
double integer = ch.unicode() - '0';
@@ -807,6 +827,12 @@ again:
}
}
if (chars.size() == 1) {
// if we ended up with a single digit, then it was a '0'
_tokenValue = 0;
return T_NUMERIC_LITERAL;
}
chars.append('\0');
const char *begin = chars.constData();
@@ -822,12 +848,6 @@ again:
}
return T_NUMERIC_LITERAL;
}
break;
}
return T_ERROR;
}
bool Lexer::scanRegExp(RegExpBodyPrefix prefix)
@@ -959,31 +979,6 @@ bool Lexer::isOctalDigit(ushort c)
return (c >= '0' && c <= '7');
}
int Lexer::tokenKind() const
{
return _tokenKind;
}
int Lexer::tokenOffset() const
{
return _tokenStartPtr - _code.unicode();
}
int Lexer::tokenLength() const
{
return _tokenLength;
}
int Lexer::tokenStartLine() const
{
return _tokenLine;
}
int Lexer::tokenStartColumn() const
{
return _tokenStartPtr - _tokenLinePtr + 1;
}
int Lexer::tokenEndLine() const
{
return _currentLineNumber;
@@ -994,16 +989,6 @@ int Lexer::tokenEndColumn() const
return _codePtr - _lastLinePtr;
}
QStringRef Lexer::tokenSpell() const
{
return _tokenSpell;
}
double Lexer::tokenValue() const
{
return _tokenValue;
}
QString Lexer::tokenText() const
{
if (_validTokenText)

View File

@@ -44,7 +44,7 @@
#include "qmljsglobal_p.h"
#include "qmljsgrammar_p.h"
#include <QString>
#include <QtCore/QString>
QT_QML_BEGIN_NAMESPACE
@@ -147,18 +147,18 @@ public:
int regExpFlags() const { return _patternFlags; }
QString regExpPattern() const { return _tokenText; }
int tokenKind() const;
int tokenOffset() const;
int tokenLength() const;
int tokenKind() const { return _tokenKind; }
int tokenOffset() const { return _tokenStartPtr - _code.unicode(); }
int tokenLength() const { return _tokenLength; }
int tokenStartLine() const;
int tokenStartColumn() const;
int tokenStartLine() const { return _tokenLine; }
int tokenStartColumn() const { return _tokenStartPtr - _tokenLinePtr + 1; }
int tokenEndLine() const;
int tokenEndColumn() const;
QStringRef tokenSpell() const;
double tokenValue() const;
inline QStringRef tokenSpell() const { return _tokenSpell; }
double tokenValue() const { return _tokenValue; }
QString tokenText() const;
Error errorCode() const;
@@ -180,6 +180,7 @@ protected:
private:
inline void scanChar();
int scanToken();
int scanNumber(QChar ch);
bool isLineTerminator() const;
static bool isIdentLetter(QChar c);

View File

@@ -44,9 +44,9 @@
#include "qmljsglobal_p.h"
#include <qglobal.h>
#include <qshareddata.h>
#include <qdebug.h>
#include <QtCore/qglobal.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qdebug.h>
#include <cstring>
@@ -73,10 +73,10 @@ public:
if (_blocks) {
for (int i = 0; i < _allocatedBlocks; ++i) {
if (char *b = _blocks[i])
qFree(b);
free(b);
}
qFree(_blocks);
free(_blocks);
}
}
@@ -108,7 +108,7 @@ private:
else
_allocatedBlocks *= 2;
_blocks = (char **) qRealloc(_blocks, sizeof(char *) * _allocatedBlocks);
_blocks = (char **) realloc(_blocks, sizeof(char *) * _allocatedBlocks);
for (int index = _blockCount; index < _allocatedBlocks; ++index)
_blocks[index] = 0;
@@ -117,7 +117,7 @@ private:
char *&block = _blocks[_blockCount];
if (! block)
block = (char *) qMalloc(BLOCK_SIZE);
block = (char *) malloc(BLOCK_SIZE);
_ptr = block;
_end = _ptr + BLOCK_SIZE;

View File

@@ -28,8 +28,8 @@
**
**************************************************************************/
#include <QtDebug>
#include <QCoreApplication>
#include <QtCore/QtDebug>
#include <QtCore/QCoreApplication>
#include <string.h>
@@ -59,10 +59,10 @@ void Parser::reallocateStack()
else
stack_size <<= 1;
sym_stack = reinterpret_cast<Value*> (qRealloc(sym_stack, stack_size * sizeof(Value)));
state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<AST::SourceLocation*> (qRealloc(location_stack, stack_size * sizeof(AST::SourceLocation)));
string_stack = reinterpret_cast<QStringRef*> (qRealloc(string_stack, stack_size * sizeof(QStringRef)));
sym_stack = reinterpret_cast<Value*> (realloc(sym_stack, stack_size * sizeof(Value)));
state_stack = reinterpret_cast<int*> (realloc(state_stack, stack_size * sizeof(int)));
location_stack = reinterpret_cast<AST::SourceLocation*> (realloc(location_stack, stack_size * sizeof(AST::SourceLocation)));
string_stack = reinterpret_cast<QStringRef*> (realloc(string_stack, stack_size * sizeof(QStringRef)));
}
Parser::Parser(Engine *engine):
@@ -74,6 +74,7 @@ Parser::Parser(Engine *engine):
state_stack(0),
location_stack(0),
string_stack(0),
program(0),
first_token(0),
last_token(0)
{
@@ -82,10 +83,10 @@ Parser::Parser(Engine *engine):
Parser::~Parser()
{
if (stack_size) {
qFree(sym_stack);
qFree(state_stack);
qFree(location_stack);
qFree(string_stack);
free(sym_stack);
free(state_stack);
free(location_stack);
free(string_stack);
}
}

View File

@@ -53,8 +53,8 @@
#include "qmljsast_p.h"
#include "qmljsengine_p.h"
#include <QList>
#include <QString>
#include <QtCore/QList>
#include <QtCore/QString>
QT_QML_BEGIN_NAMESPACE

View File

@@ -323,7 +323,7 @@ LibraryInfo::LibraryInfo(Status status)
LibraryInfo::LibraryInfo(const QmlDirParser &parser)
: _status(Found)
, _components(parser.components())
, _components(parser.components().values())
, _plugins(parser.plugins())
, _typeinfos(parser.typeInfos())
, _dumpStatus(NoTypeInfo)

View File

@@ -474,8 +474,7 @@ static bool findNewQmlLibraryInPath(const QString &path,
QString qmldirData = QString::fromUtf8(qmldirFile.readAll());
QmlDirParser qmldirParser;
qmldirParser.setSource(qmldirData);
qmldirParser.parse();
qmldirParser.parse(qmldirData);
const QString libraryPath = QFileInfo(qmldirFile).absolutePath();
newLibraries->insert(libraryPath);