Commit b5312090 authored by Christian Kamm's avatar Christian Kamm

QmlJS: Merge parser updates from Qt5.

Change-Id: Ibed38abca8f7e7bae7d424751a18c83f4c9e9bc5
Reviewed-on: http://codereview.qt-project.org/4732Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent c0c93124
......@@ -7,6 +7,7 @@ s/Q_DECLARATIVE_EXPORT //g
# adjust pri file
s/ \$\$PWD\/qmljsglobal_p.h/ $$PWD\/qmljsglobal_p.h \\\
$$PWD\/qmldirparser_p.h \\\
$$PWD\/qmlutils_p.h \\\
$$PWD\/qmlerror.h/
s/ \$\$PWD\/qmljsparser.cpp/ $$PWD\/qmljsparser.cpp \\\
$$PWD\/qmldirparser.cpp \\\
......
......@@ -10,8 +10,14 @@ for i in $QTDIR/src/declarative/qml/qdeclarative{error.{h,cpp},dirparser{_p.h,.c
sed -f $me/cmd.sed $i > $me/$(echo $(basename $i) | sed s/qdeclarative/qml/)
done
for i in $QTDIR/src/declarative/qml/ftw/qdeclarativeutils_p.h; do
sed -f $me/cmd.sed $i > $me/$(echo $(basename $i) | sed s/qdeclarative/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
# 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
./changeLicense.py $me/../qmljs_global.h qml*.{cpp,h}
......
......@@ -8,11 +8,12 @@ HEADERS += \
$$PWD/qmljsgrammar_p.h \
$$PWD/qmljslexer_p.h \
$$PWD/qmljsmemorypool_p.h \
$$PWD/qmljsnodepool_p.h \
$$PWD/qmljsparser_p.h \
$$PWD/qmljsglobal_p.h \
$$PWD/qmldirparser_p.h \
$$PWD/qmlerror.h
$$PWD/qmlutils_p.h \
$$PWD/qmlerror.h \
$$PWD/qmljskeywords_p.h
SOURCES += \
$$PWD/qmljsast.cpp \
......
......@@ -32,8 +32,11 @@
#include "qmldirparser_p.h"
#include "qmlerror.h"
bool Qml_isFileCaseCorrect(const QString &) { return true; }
#include <qmlutils_p.h>
#include <QtCore/QTextStream>
#include <QtCore/QFile>
#include <QtCore/QtDebug>
QT_BEGIN_NAMESPACE
......@@ -57,6 +60,16 @@ void QmlDirParser::setUrl(const QUrl &url)
_url = url;
}
QString QmlDirParser::fileSource() const
{
return _filePathSouce;
}
void QmlDirParser::setFileSource(const QString &filePath)
{
_filePathSouce = filePath;
}
QString QmlDirParser::source() const
{
return _source;
......@@ -83,6 +96,23 @@ bool QmlDirParser::parse()
_plugins.clear();
_components.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;
......@@ -102,9 +132,9 @@ bool QmlDirParser::parse()
while (index != length) {
const QChar ch = line.at(index);
if (ch.isSpace()) {
if (QmlUtils::isSpace(ch)) {
do { ++index; }
while (index != length && line.at(index).isSpace());
while (index != length && QmlUtils::isSpace(line.at(index)));
} else if (ch == QLatin1Char('#')) {
// recognized a comment
......@@ -114,7 +144,7 @@ bool QmlDirParser::parse()
const int start = index;
do { ++index; }
while (index != length && !line.at(index).isSpace());
while (index != length && !QmlUtils::isSpace(line.at(index)));
const QString lexeme = line.mid(start, index - start);
......@@ -148,7 +178,7 @@ bool QmlDirParser::parse()
QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount - 1));
continue;
}
Component entry(sections[1], sections[2], -1, -1);
Component entry(sections[1].toUtf8(), sections[2], -1, -1);
entry.internal = true;
_components.append(entry);
} else if (sections[0] == QLatin1String("typeinfo")) {
......@@ -164,7 +194,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);
const Component entry(sections[0].toUtf8(), sections[1], -1, -1);
_components.append(entry);
} else if (sectionCount == 3) {
const QString &version = sections[1];
......@@ -182,7 +212,7 @@ bool QmlDirParser::parse()
const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber);
if (validVersionNumber) {
const Component entry(sections[0], sections[2], majorVersion, minorVersion);
const Component entry(sections[0].toUtf8(), sections[2], majorVersion, minorVersion);
_components.append(entry);
}
......@@ -215,9 +245,16 @@ bool QmlDirParser::hasError() const
return false;
}
QList<QmlError> QmlDirParser::errors() const
QList<QmlError> QmlDirParser::errors(const QString &uri) const
{
return _errors;
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);
}
return errors;
}
QList<QmlDirParser::Plugin> QmlDirParser::plugins() const
......
......@@ -63,6 +63,9 @@ public:
QUrl url() const;
void setUrl(const QUrl &url);
QString fileSource() const;
void setFileSource(const QString &filePath);
QString source() const;
void setSource(const QString &source);
......@@ -70,7 +73,7 @@ public:
bool parse();
bool hasError() const;
QList<QmlError> errors() const;
QList<QmlError> errors(const QString &uri) const;
struct Plugin
{
......@@ -88,11 +91,11 @@ public:
Component()
: majorVersion(0), minorVersion(0), internal(false) {}
Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion)
Component(const QByteArray &typeName, const QString &fileName, int majorVersion, int minorVersion)
: typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion),
internal(false) {}
QString typeName;
QByteArray typeName;
QString fileName;
int majorVersion;
int minorVersion;
......@@ -122,6 +125,7 @@ private:
QList<QmlError> _errors;
QUrl _url;
QString _source;
QString _filePathSouce;
QList<Component> _components;
QList<Plugin> _plugins;
#ifdef QT_CREATOR
......
This diff is collapsed.
......@@ -46,6 +46,7 @@
#include "qmljsastvisitor_p.h"
#include "qmljsglobal_p.h"
#include "qmljsmemorypool_p.h"
#include <QtCore/QString>
......@@ -98,7 +99,7 @@ enum Op {
} // namespace QSOperator
namespace QmlJS {
class NameId;
namespace AST {
template <typename _T1, typename _T2>
......@@ -110,7 +111,7 @@ _T1 cast(_T2 *ast)
return 0;
}
class QML_PARSER_EXPORT Node
class QML_PARSER_EXPORT Node: public Managed
{
public:
enum Kind {
......@@ -264,7 +265,7 @@ class QML_PARSER_EXPORT UiFormal: public Node
public:
QMLJS_DECLARE_AST_NODE(UiFormal)
UiFormal(NameId *name, NameId *alias = 0)
UiFormal(const QStringRef &name, const QStringRef &alias)
: name(name), alias(alias)
{ }
......@@ -277,8 +278,8 @@ public:
virtual void accept0(Visitor *visitor);
// attributes
NameId *name;
NameId *alias;
QStringRef name;
QStringRef alias;
SourceLocation identifierToken;
SourceLocation asToken;
SourceLocation aliasToken;
......@@ -389,7 +390,7 @@ class QML_PARSER_EXPORT IdentifierExpression: public ExpressionNode
public:
QMLJS_DECLARE_AST_NODE(IdentifierExpression)
IdentifierExpression(NameId *n):
IdentifierExpression(const QStringRef &n):
name (n) { kind = K; }
virtual void accept0(Visitor *visitor);
......@@ -401,7 +402,7 @@ public:
{ return identifierToken; }
// attributes
NameId *name;
QStringRef name;
SourceLocation identifierToken;
};
......@@ -488,7 +489,7 @@ class QML_PARSER_EXPORT StringLiteral: public ExpressionNode
public:
QMLJS_DECLARE_AST_NODE(StringLiteral)
StringLiteral(NameId *v):
StringLiteral(const QStringRef &v):
value (v) { kind = K; }
virtual void accept0(Visitor *visitor);
......@@ -500,7 +501,7 @@ public:
{ return literalToken; }
// attributes:
NameId *value;
QStringRef value;
SourceLocation literalToken;
};
......@@ -509,7 +510,7 @@ class QML_PARSER_EXPORT RegExpLiteral: public ExpressionNode
public:
QMLJS_DECLARE_AST_NODE(RegExpLiteral)
RegExpLiteral(NameId *p, int f):
RegExpLiteral(const QStringRef &p, int f):
pattern (p), flags (f) { kind = K; }
virtual void accept0(Visitor *visitor);
......@@ -521,7 +522,7 @@ public:
{ return literalToken; }
// attributes:
NameId *pattern;
QStringRef pattern;
int flags;
SourceLocation literalToken;
};
......@@ -696,13 +697,13 @@ class QML_PARSER_EXPORT IdentifierPropertyName: public PropertyName
public:
QMLJS_DECLARE_AST_NODE(IdentifierPropertyName)
IdentifierPropertyName(NameId *n):
IdentifierPropertyName(const QStringRef &n):
id (n) { kind = K; }
virtual void accept0(Visitor *visitor);
// attributes
NameId *id;
QStringRef id;
};
class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName
......@@ -710,13 +711,13 @@ class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName
public:
QMLJS_DECLARE_AST_NODE(StringLiteralPropertyName)
StringLiteralPropertyName(NameId *n):
StringLiteralPropertyName(const QStringRef &n):
id (n) { kind = K; }
virtual void accept0(Visitor *visitor);
// attributes
NameId *id;
QStringRef id;
};
class QML_PARSER_EXPORT NumericLiteralPropertyName: public PropertyName
......@@ -762,7 +763,7 @@ class QML_PARSER_EXPORT FieldMemberExpression: public ExpressionNode
public:
QMLJS_DECLARE_AST_NODE(FieldMemberExpression)
FieldMemberExpression(ExpressionNode *b, NameId *n):
FieldMemberExpression(ExpressionNode *b, const QStringRef &n):
base (b), name (n)
{ kind = K; }
......@@ -776,7 +777,7 @@ public:
// attributes
ExpressionNode *base;
NameId *name;
QStringRef name;
SourceLocation dotToken;
SourceLocation identifierToken;
};
......@@ -1268,14 +1269,14 @@ class QML_PARSER_EXPORT VariableDeclaration: public Node
public:
QMLJS_DECLARE_AST_NODE(VariableDeclaration)
VariableDeclaration(NameId *n, ExpressionNode *e):
VariableDeclaration(const QStringRef &n, ExpressionNode *e):
name (n), expression (e), readOnly(false)
{ kind = K; }
virtual void accept0(Visitor *visitor);
// attributes
NameId *name;
QStringRef name;
ExpressionNode *expression;
bool readOnly;
SourceLocation identifierToken;
......@@ -1561,7 +1562,7 @@ class QML_PARSER_EXPORT ContinueStatement: public Statement
public:
QMLJS_DECLARE_AST_NODE(ContinueStatement)
ContinueStatement(NameId *l = 0):
ContinueStatement(const QStringRef &l = QStringRef()):
label (l) { kind = K; }
virtual void accept0(Visitor *visitor);
......@@ -1573,7 +1574,7 @@ public:
{ return semicolonToken; }
// attributes
NameId *label;
QStringRef label;
SourceLocation continueToken;
SourceLocation identifierToken;
SourceLocation semicolonToken;
......@@ -1584,7 +1585,7 @@ class QML_PARSER_EXPORT BreakStatement: public Statement
public:
QMLJS_DECLARE_AST_NODE(BreakStatement)
BreakStatement(NameId *l = 0):
BreakStatement(const QStringRef &l):
label (l) { kind = K; }
virtual void accept0(Visitor *visitor);
......@@ -1596,7 +1597,7 @@ public:
{ return semicolonToken; }
// attributes
NameId *label;
QStringRef label;
SourceLocation breakToken;
SourceLocation identifierToken;
SourceLocation semicolonToken;
......@@ -1764,7 +1765,7 @@ class QML_PARSER_EXPORT LabelledStatement: public Statement
public:
QMLJS_DECLARE_AST_NODE(LabelledStatement)
LabelledStatement(NameId *l, Statement *stmt):
LabelledStatement(const QStringRef &l, Statement *stmt):
label (l), statement (stmt)
{ kind = K; }
......@@ -1777,7 +1778,7 @@ public:
{ return statement->lastSourceLocation(); }
// attributes
NameId *label;
QStringRef label;
Statement *statement;
SourceLocation identifierToken;
SourceLocation colonToken;
......@@ -1810,14 +1811,14 @@ class QML_PARSER_EXPORT Catch: public Node
public:
QMLJS_DECLARE_AST_NODE(Catch)
Catch(NameId *n, Block *stmt):
Catch(const QStringRef &n, Block *stmt):
name (n), statement (stmt)
{ kind = K; }
virtual void accept0(Visitor *visitor);
// attributes
NameId *name;
QStringRef name;
Block *statement;
SourceLocation catchToken;
SourceLocation lparenToken;
......@@ -1885,7 +1886,7 @@ class QML_PARSER_EXPORT FunctionExpression: public ExpressionNode
public:
QMLJS_DECLARE_AST_NODE(FunctionExpression)
FunctionExpression(NameId *n, FormalParameterList *f, FunctionBody *b):
FunctionExpression(const QStringRef &n, FormalParameterList *f, FunctionBody *b):
name (n), formals (f), body (b)
{ kind = K; }
......@@ -1898,7 +1899,7 @@ public:
{ return rbraceToken; }
// attributes
NameId *name;
QStringRef name;
FormalParameterList *formals;
FunctionBody *body;
SourceLocation functionToken;
......@@ -1914,7 +1915,7 @@ class QML_PARSER_EXPORT FunctionDeclaration: public FunctionExpression
public:
QMLJS_DECLARE_AST_NODE(FunctionDeclaration)
FunctionDeclaration(NameId *n, FormalParameterList *f, FunctionBody *b):
FunctionDeclaration(const QStringRef &n, FormalParameterList *f, FunctionBody *b):
FunctionExpression(n, f, b)
{ kind = K; }
......@@ -1926,11 +1927,11 @@ class QML_PARSER_EXPORT FormalParameterList: public Node
public:
QMLJS_DECLARE_AST_NODE(FormalParameterList)
FormalParameterList(NameId *n):
FormalParameterList(const QStringRef &n):
name (n), next (this)
{ kind = K; }
FormalParameterList(FormalParameterList *previous, NameId *n):
FormalParameterList(FormalParameterList *previous, const QStringRef &n):
name (n)
{
kind = K;
......@@ -1948,7 +1949,7 @@ public:
}
// attributes
NameId *name;
QStringRef name;
FormalParameterList *next;
SourceLocation commaToken;
SourceLocation identifierToken;
......@@ -2096,11 +2097,11 @@ class QML_PARSER_EXPORT UiQualifiedId: public Node
public:
QMLJS_DECLARE_AST_NODE(UiQualifiedId)
UiQualifiedId(NameId *name)
UiQualifiedId(const QStringRef &name)
: next(this), name(name)
{ kind = K; }
UiQualifiedId(UiQualifiedId *previous, NameId *name)
UiQualifiedId(UiQualifiedId *previous, const QStringRef &name)
: name(name)
{
kind = K;
......@@ -2119,7 +2120,7 @@ public:
// attributes
UiQualifiedId *next;
NameId *name;
QStringRef name;
SourceLocation identifierToken;
};
......@@ -2128,12 +2129,12 @@ class QML_PARSER_EXPORT UiImport: public Node
public:
QMLJS_DECLARE_AST_NODE(UiImport)
UiImport(NameId *fileName)
: fileName(fileName), importUri(0), importId(0)
UiImport(const QStringRef &fileName)
: fileName(fileName), importUri(0)
{ kind = K; }
UiImport(UiQualifiedId *uri)
: fileName(0), importUri(uri), importId(0)
: importUri(uri)
{ kind = K; }
virtual SourceLocation firstSourceLocation() const
......@@ -2145,9 +2146,9 @@ public:
virtual void accept0(Visitor *visitor);
// attributes
NameId *fileName;
QStringRef fileName;
UiQualifiedId *importUri;
NameId *importId;
QStringRef importId;
SourceLocation importToken;
SourceLocation fileNameToken;
SourceLocation versionToken;
......@@ -2297,11 +2298,11 @@ class QML_PARSER_EXPORT UiParameterList: public Node
public:
QMLJS_DECLARE_AST_NODE(UiParameterList)
UiParameterList(NameId *t, NameId *n):
UiParameterList(const QStringRef &t, const QStringRef &n):
type (t), name (n), next (this)
{ kind = K; }
UiParameterList(UiParameterList *previous, NameId *t, NameId *n):
UiParameterList(UiParameterList *previous, const QStringRef &t, const QStringRef &n):
type (t), name (n)
{
kind = K;
......@@ -2319,8 +2320,8 @@ public:
}
// attributes
NameId *type;
NameId *name;
QStringRef type;
QStringRef name;
UiParameterList *next;
SourceLocation commaToken;
SourceLocation identifierToken;
......@@ -2331,15 +2332,15 @@ class QML_PARSER_EXPORT UiPublicMember: public UiObjectMember
public:
QMLJS_DECLARE_AST_NODE(UiPublicMember)
UiPublicMember(NameId *memberType,
NameId *name)
: type(Property), typeModifier(0), memberType(memberType), name(name), statement(0), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
UiPublicMember(const QStringRef &memberType,
const QStringRef &name)
: type(Property), memberType(memberType), name(name), statement(0), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
{ kind = K; }
UiPublicMember(NameId *memberType,
NameId *name,
UiPublicMember(const QStringRef &memberType,
const QStringRef &name,
Statement *statement)
: type(Property), typeModifier(0), memberType(memberType), name(name), statement(statement), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
: type(Property), memberType(memberType), name(name), statement(statement), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
{ kind = K; }
virtual SourceLocation firstSourceLocation() const
......@@ -2366,9 +2367,9 @@ public:
// attributes
enum { Signal, Property } type;
NameId *typeModifier;
NameId *memberType;
NameId *name;
QStringRef typeModifier;
QStringRef memberType;
QStringRef name;
Statement *statement; // initialized with a JS expression
UiObjectMember *binding; // initialized with a QML object or array.
bool isDefaultMember;
......
......@@ -31,66 +31,16 @@
**************************************************************************/
#include "qmljsengine_p.h"
#include "qmljsglobal_p.h"
#include "qmljsnodepool_p.h"
#include <qnumeric.h>
#include <QHash>
#include <QDebug>
QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
uint qHash(const QmlJS::NameId &id)
{ return qHash(id.asString()); }
QString numberToString(double value)
{ return QString::number(value); }
int Ecma::RegExp::flagFromChar(const QChar &ch)
{
static QHash<QChar, int> flagsHash;
if (flagsHash.isEmpty()) {
flagsHash[QLatin1Char('g')] = Global;
flagsHash[QLatin1Char('i')] = IgnoreCase;