qmljs: update parser

Update the qtcreator qmljs parser to the
one of Qt 5.12. It supports EcmaScript 7.

Task-number: QTCREATORBUG-20341
Change-Id: I0d1cff71402ba17e22cde6b46c65614e162280de
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
This commit is contained in:
Marco Benelli
2018-10-16 15:32:58 +02:00
parent fe8a372773
commit 4646acad0d
46 changed files with 10604 additions and 5872 deletions

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,7 +20,13 @@ SOURCES += \
$$PWD/qmljslexer.cpp \
$$PWD/qmljsparser.cpp \
$$PWD/qmldirparser.cpp \
$$PWD/qmlerror.cpp \
$$PWD/qmlerror.cpp
DISTFILES += \
$$PWD/qmljs.g
#CONFIG += qlalr
QLALRSOURCES = $$PWD/qmljs.g
#QMAKE_QLALRFLAGS = --no-debug --qt
DISTFILES += $$QLALRSOURCES
# make sure we install the headers generated by qlalr
#private_headers.CONFIG += no_check_exist

View File

@@ -93,6 +93,7 @@ bool QmlDirParser::parse(const QString &source)
_components.clear();
_scripts.clear();
_designerSupported = false;
_className.clear();
quint16 lineNumber = 0;
bool firstLine = true;
@@ -182,7 +183,8 @@ bool QmlDirParser::parse(const QString &source)
continue;
}
// Ignore these. qmlimportscanner uses them.
_className = sections[1];
} else if (sections[0] == QLatin1String("internal")) {
if (sectionCount != 3) {
reportError(lineNumber, 0,
@@ -256,7 +258,7 @@ bool QmlDirParser::parse(const QString &source)
if (parseVersion(sections[1], &major, &minor)) {
const QString &fileName = sections[2];
if (fileName.endsWith(QLatin1String(".js"))) {
if (fileName.endsWith(QLatin1String(".js")) || fileName.endsWith(QLatin1String(".mjs"))) {
// A 'js' extension indicates a namespaced script import
const Script entry(sections[0], fileName, major, minor);
_scripts.append(entry);
@@ -363,6 +365,11 @@ 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}").

View File

@@ -39,8 +39,8 @@
#include <QtCore/QUrl>
#include <QtCore/QHash>
#include <QtCore/QDebug>
#include "qmljsengine_p.h"
#include "qmljsglobal_p.h"
QT_BEGIN_NAMESPACE
@@ -48,8 +48,6 @@ class QmlError;
class QmlEngine;
class QML_PARSER_EXPORT QmlDirParser
{
Q_DISABLE_COPY(QmlDirParser)
public:
QmlDirParser();
~QmlDirParser();
@@ -76,8 +74,7 @@ public:
struct Component
{
Component()
: majorVersion(0), minorVersion(0), internal(false), singleton(false) {}
Component() {}
Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion)
: typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion),
@@ -85,24 +82,23 @@ public:
QString typeName;
QString fileName;
int majorVersion;
int minorVersion;
bool internal;
bool singleton;
int majorVersion = 0;
int minorVersion = 0;
bool internal = false;
bool singleton = false;
};
struct Script
{
Script()
: majorVersion(0), minorVersion(0) {}
Script() {}
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;
int majorVersion = 0;
int minorVersion = 0;
};
QHash<QString,Component> components() const;
@@ -124,6 +120,8 @@ public:
QList<TypeInfo> typeInfos() const;
#endif
QString className() const;
private:
bool maybeAddComponent(const QString &typeName, const QString &fileName, const QString &version, QHash<QString,Component> &hash, int lineNumber = -1, bool multi = true);
void reportError(quint16 line, quint16 column, const QString &message);
@@ -139,6 +137,7 @@ private:
#ifdef QT_CREATOR
QList<TypeInfo> _typeInfos;
#endif
QString _className;
};
typedef QHash<QString,QmlDirParser::Component> QmlDirComponents;

View File

@@ -91,7 +91,7 @@ QmlErrorPrivate::QmlErrorPrivate()
Creates an empty error object.
*/
QmlError::QmlError()
: d(0)
: d(nullptr)
{
}
@@ -99,7 +99,7 @@ QmlError::QmlError()
Creates a copy of \a other.
*/
QmlError::QmlError(const QmlError &other)
: d(0)
: d(nullptr)
{
*this = other;
}
@@ -111,7 +111,7 @@ QmlError &QmlError::operator=(const QmlError &other)
{
if (!other.d) {
delete d;
d = 0;
d = nullptr;
} else {
if (!d)
d = new QmlErrorPrivate;
@@ -130,7 +130,7 @@ QmlError &QmlError::operator=(const QmlError &other)
*/
QmlError::~QmlError()
{
delete d; d = 0;
delete d; d = nullptr;
}
/*!
@@ -138,7 +138,7 @@ QmlError::~QmlError()
*/
bool QmlError::isValid() const
{
return d != 0;
return d != nullptr;
}
/*!
@@ -231,7 +231,7 @@ QObject *QmlError::object() const
{
if (d)
return d->object;
return 0;
return nullptr;
}
/*!
@@ -260,7 +260,7 @@ QtMsgType QmlError::messageType() const
\since 5.9
Sets the \a messageType for this message. The message type determines which
QDebug handlers are responsible for recieving the message.
QDebug handlers are responsible for receiving the message.
*/
void QmlError::setMessageType(QtMsgType messageType)
{

File diff suppressed because it is too large Load Diff

View File

@@ -31,6 +31,27 @@ QT_QML_BEGIN_NAMESPACE
namespace QmlJS { namespace AST {
FunctionExpression *asAnonymousFunctionDefinition(Node *n)
{
if (!n)
return nullptr;
FunctionExpression *f = n->asFunctionDefinition();
if (!f || !f->name.isNull())
return nullptr;
return f;
}
ClassExpression *asAnonymousClassDefinition(Node *n)
{
if (!n)
return nullptr;
ClassExpression *c = n->asClassDefinition();
if (!c || !c->name.isNull())
return nullptr;
return c;
}
void Node::accept(Visitor *visitor)
{
if (visitor->preVisit(this)) {
@@ -47,22 +68,42 @@ void Node::accept(Node *node, Visitor *visitor)
ExpressionNode *Node::expressionCast()
{
return 0;
return nullptr;
}
BinaryExpression *Node::binaryExpressionCast()
{
return 0;
return nullptr;
}
Statement *Node::statementCast()
{
return 0;
return nullptr;
}
UiObjectMember *Node::uiObjectMemberCast()
{
return 0;
return nullptr;
}
LeftHandSideExpression *Node::leftHandSideExpressionCast()
{
return nullptr;
}
Pattern *Node::patternCast()
{
return nullptr;
}
FunctionExpression *Node::asFunctionDefinition()
{
return nullptr;
}
ClassExpression *Node::asClassDefinition()
{
return nullptr;
}
ExpressionNode *ExpressionNode::expressionCast()
@@ -70,6 +111,42 @@ ExpressionNode *ExpressionNode::expressionCast()
return this;
}
FormalParameterList *ExpressionNode::reparseAsFormalParameterList(MemoryPool *pool)
{
AST::ExpressionNode *expr = this;
AST::FormalParameterList *f = nullptr;
if (AST::Expression *commaExpr = AST::cast<AST::Expression *>(expr)) {
f = commaExpr->left->reparseAsFormalParameterList(pool);
if (!f)
return nullptr;
expr = commaExpr->right;
}
AST::ExpressionNode *rhs = nullptr;
if (AST::BinaryExpression *assign = AST::cast<AST::BinaryExpression *>(expr)) {
if (assign->op != QSOperator::Assign)
return nullptr;
expr = assign->left;
rhs = assign->right;
}
AST::PatternElement *binding = nullptr;
if (AST::IdentifierExpression *idExpr = AST::cast<AST::IdentifierExpression *>(expr)) {
binding = new (pool) AST::PatternElement(idExpr->name, rhs);
binding->identifierToken = idExpr->identifierToken;
} else if (AST::Pattern *p = expr->patternCast()) {
SourceLocation loc;
QString s;
if (!p->convertLiteralToAssignmentPattern(pool, &loc, &s))
return nullptr;
binding = new (pool) AST::PatternElement(p, rhs);
binding->identifierToken = p->firstSourceLocation();
}
if (!binding)
return nullptr;
return new (pool) AST::FormalParameterList(f, binding);
}
BinaryExpression *BinaryExpression::binaryExpressionCast()
{
return this;
@@ -93,6 +170,16 @@ void NestedExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
FunctionExpression *NestedExpression::asFunctionDefinition()
{
return expression->asFunctionDefinition();
}
ClassExpression *NestedExpression::asClassDefinition()
{
return expression->asClassDefinition();
}
void ThisExpression::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -133,6 +220,15 @@ void FalseLiteral::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void SuperLiteral::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void StringLiteral::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -141,6 +237,16 @@ void StringLiteral::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void TemplateLiteral::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
if (next)
accept(next, visitor);
}
visitor->endVisit(this);
}
void NumericLiteral::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -157,17 +263,27 @@ void RegExpLiteral::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void ArrayLiteral::accept0(Visitor *visitor)
void ArrayPattern::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
if (visitor->visit(this))
accept(elements, visitor);
accept(elision, visitor);
}
visitor->endVisit(this);
}
void ObjectLiteral::accept0(Visitor *visitor)
bool ArrayPattern::isValidArrayLiteral(SourceLocation *errorLocation) const {
for (PatternElementList *it = elements; it != nullptr; it = it->next) {
PatternElement *e = it->element;
if (e && e->bindingTarget != nullptr) {
if (errorLocation)
*errorLocation = e->firstSourceLocation();
return false;
}
}
return true;
}
void ObjectPattern::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(properties, visitor);
@@ -176,18 +292,170 @@ void ObjectLiteral::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void ElementList::accept0(Visitor *visitor)
/*
This is the grammar for AssignmentPattern that we need to convert the literal to:
AssignmentPattern:
ObjectAssignmentPattern
ArrayAssignmentPattern
ArrayAssignmentPattern:
[ ElisionOpt AssignmentRestElementOpt ]
[ AssignmentElementList ]
[ AssignmentElementList , ElisionOpt AssignmentRestElementOpt ]
AssignmentElementList:
AssignmentElisionElement
AssignmentElementList , AssignmentElisionElement
AssignmentElisionElement:
ElisionOpt AssignmentElement
AssignmentRestElement:
... DestructuringAssignmentTarget
ObjectAssignmentPattern:
{}
{ AssignmentPropertyList }
{ AssignmentPropertyList, }
AssignmentPropertyList:
AssignmentProperty
AssignmentPropertyList , AssignmentProperty
AssignmentProperty:
IdentifierReference InitializerOpt_In
PropertyName:
AssignmentElement
AssignmentElement:
DestructuringAssignmentTarget InitializerOpt_In
DestructuringAssignmentTarget:
LeftHandSideExpression
It was originally parsed with the following grammar:
ArrayLiteral:
[ ElisionOpt ]
[ ElementList ]
[ ElementList , ElisionOpt ]
ElementList:
ElisionOpt AssignmentExpression_In
ElisionOpt SpreadElement
ElementList , ElisionOpt AssignmentExpression_In
ElementList , Elisionopt SpreadElement
SpreadElement:
... AssignmentExpression_In
ObjectLiteral:
{}
{ PropertyDefinitionList }
{ PropertyDefinitionList , }
PropertyDefinitionList:
PropertyDefinition
PropertyDefinitionList , PropertyDefinition
PropertyDefinition:
IdentifierReference
CoverInitializedName
PropertyName : AssignmentExpression_In
MethodDefinition
PropertyName:
LiteralPropertyName
ComputedPropertyName
*/
bool ArrayPattern::convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage)
{
if (visitor->visit(this)) {
for (ElementList *it = this; it; it = it->next) {
accept(it->elision, visitor);
accept(it->expression, visitor);
if (parseMode == Binding)
return true;
for (auto *it = elements; it; it = it->next) {
if (!it->element)
continue;
if (it->element->type == PatternElement::SpreadElement && it->next) {
*errorLocation = it->element->firstSourceLocation();
*errorMessage = QString::fromLatin1("'...' can only appear as last element in a destructuring list.");
return false;
}
if (!it->element->convertLiteralToAssignmentPattern(pool, errorLocation, errorMessage))
return false;
}
parseMode = Binding;
return true;
}
bool ObjectPattern::convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage)
{
if (parseMode == Binding)
return true;
for (auto *it = properties; it; it = it->next) {
if (!it->property->convertLiteralToAssignmentPattern(pool, errorLocation, errorMessage))
return false;
}
parseMode = Binding;
return true;
}
bool PatternElement::convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage)
{
Q_ASSERT(type == Literal || type == SpreadElement);
Q_ASSERT(bindingIdentifier.isNull());
Q_ASSERT(bindingTarget == nullptr);
Q_ASSERT(bindingTarget == nullptr);
Q_ASSERT(initializer);
ExpressionNode *init = initializer;
initializer = nullptr;
LeftHandSideExpression *lhs = init->leftHandSideExpressionCast();
if (type == SpreadElement) {
if (!lhs) {
*errorLocation = init->firstSourceLocation();
*errorMessage = QString::fromLatin1("Invalid lhs expression after '...' in destructuring expression.");
return false;
}
} else {
type = PatternElement::Binding;
if (BinaryExpression *b = init->binaryExpressionCast()) {
if (b->op != QSOperator::Assign) {
*errorLocation = b->operatorToken;
*errorMessage = QString::fromLatin1("Invalid assignment operation in destructuring expression");
return false;
}
lhs = b->left->leftHandSideExpressionCast();
initializer = b->right;
Q_ASSERT(lhs);
} else {
lhs = init->leftHandSideExpressionCast();
}
if (!lhs) {
*errorLocation = init->firstSourceLocation();
*errorMessage = QString::fromLatin1("Destructuring target is not a left hand side expression.");
return false;
}
}
visitor->endVisit(this);
if (auto *i = cast<IdentifierExpression *>(lhs)) {
bindingIdentifier = i->name;
identifierToken = i->identifierToken;
return true;
}
bindingTarget = lhs;
if (auto *p = lhs->patternCast()) {
if (!p->convertLiteralToAssignmentPattern(pool, errorLocation, errorMessage))
return false;
}
return true;
}
bool PatternProperty::convertLiteralToAssignmentPattern(MemoryPool *pool, SourceLocation *errorLocation, QString *errorMessage)
{
Q_ASSERT(type != SpreadElement);
if (type == Binding)
return true;
if (type == Getter || type == Setter) {
*errorLocation = firstSourceLocation();
*errorMessage = QString::fromLatin1("Invalid getter/setter in destructuring expression.");
return false;
}
Q_ASSERT(type == Literal);
return PatternElement::convertLiteralToAssignmentPattern(pool, errorLocation, errorMessage);
}
void Elision::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -197,38 +465,6 @@ void Elision::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void PropertyNameAndValue::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(name, visitor);
accept(value, visitor);
}
visitor->endVisit(this);
}
void PropertyGetterSetter::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(name, visitor);
accept(formals, visitor);
accept(functionBody, visitor);
}
visitor->endVisit(this);
}
void PropertyAssignmentList::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
for (PropertyAssignmentList *it = this; it; it = it->next) {
accept(it->assignment, visitor);
}
}
visitor->endVisit(this);
}
void IdentifierPropertyName::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -253,6 +489,28 @@ void NumericLiteralPropertyName::accept0(Visitor *visitor)
visitor->endVisit(this);
}
namespace {
struct LocaleWithoutZeroPadding : public QLocale
{
LocaleWithoutZeroPadding()
: QLocale(QLocale::C)
{
setNumberOptions(QLocale::OmitLeadingZeroInExponent | QLocale::OmitGroupSeparator);
}
};
}
QString NumericLiteralPropertyName::asString()const
{
// Can't use QString::number here anymore as it does zero padding by default now.
// In C++11 this initialization is thread-safe (6.7 [stmt.dcl] p4)
static LocaleWithoutZeroPadding locale;
// Because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562 we can't use thread_local
// for the locale variable and therefore rely on toString(double) to be thread-safe.
return locale.toString(id, 'g', 16);
}
void ArrayMemberExpression::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -482,15 +740,6 @@ void VariableDeclarationList::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void VariableDeclaration::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(expression, visitor);
}
visitor->endVisit(this);
}
void EmptyStatement::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -543,17 +792,6 @@ void ForStatement::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(initialiser, visitor);
accept(condition, visitor);
accept(expression, visitor);
accept(statement, visitor);
}
visitor->endVisit(this);
}
void LocalForStatement::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(declarations, visitor);
accept(condition, visitor);
accept(expression, visitor);
@@ -566,18 +804,7 @@ void LocalForStatement::accept0(Visitor *visitor)
void ForEachStatement::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(initialiser, visitor);
accept(expression, visitor);
accept(statement, visitor);
}
visitor->endVisit(this);
}
void LocalForEachStatement::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(declaration, visitor);
accept(lhs, visitor);
accept(expression, visitor);
accept(statement, visitor);
}
@@ -610,6 +837,16 @@ void ReturnStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void YieldExpression::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(expression, visitor);
}
visitor->endVisit(this);
}
void WithStatement::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -703,6 +940,7 @@ void TryStatement::accept0(Visitor *visitor)
void Catch::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(patternElement, visitor);
accept(statement, visitor);
}
@@ -738,57 +976,182 @@ void FunctionExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
FunctionExpression *FunctionExpression::asFunctionDefinition()
{
return this;
}
QStringList FormalParameterList::formals() const
{
QStringList formals;
int i = 0;
for (const FormalParameterList *it = this; it; it = it->next) {
if (it->element) {
QString name = it->element->bindingIdentifier.toString();
int duplicateIndex = formals.indexOf(name);
if (duplicateIndex >= 0) {
// change the name of the earlier argument to enforce the lookup semantics from the spec
formals[duplicateIndex] += QLatin1String("#") + QString::number(i);
}
formals += name;
}
++i;
}
return formals;
}
QStringList FormalParameterList::boundNames() const
{
QStringList names;
for (const FormalParameterList *it = this; it; it = it->next) {
if (it->element)
it->element->boundNames(&names);
}
return names;
}
void FormalParameterList::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
// ###
accept(element, visitor);
if (next)
accept(next, visitor);
}
visitor->endVisit(this);
}
void FunctionBody::accept0(Visitor *visitor)
FormalParameterList *FormalParameterList::finish(QmlJS::MemoryPool *pool)
{
if (visitor->visit(this)) {
accept(elements, visitor);
}
FormalParameterList *front = next;
next = nullptr;
visitor->endVisit(this);
int i = 0;
for (const FormalParameterList *it = this; it; it = it->next) {
if (it->element && it->element->bindingIdentifier.isEmpty())
it->element->bindingIdentifier = pool->newString(QLatin1String("arg#") + QString::number(i));
++i;
}
return front;
}
void Program::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(elements, visitor);
accept(statements, visitor);
}
visitor->endVisit(this);
}
void SourceElements::accept0(Visitor *visitor)
void ImportSpecifier::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
for (SourceElements *it = this; it; it = it->next) {
accept(it->element, visitor);
}
visitor->endVisit(this);
}
void ImportsList::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
for (ImportsList *it = this; it; it = it->next) {
accept(it->importSpecifier, visitor);
}
}
visitor->endVisit(this);
}
void FunctionSourceElement::accept0(Visitor *visitor)
void NamedImports::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(declaration, visitor);
accept(importsList, visitor);
}
visitor->endVisit(this);
}
void StatementSourceElement::accept0(Visitor *visitor)
void FromClause::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(statement, visitor);
}
visitor->endVisit(this);
}
void NameSpaceImport::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void ImportClause::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(nameSpaceImport, visitor);
accept(namedImports, visitor);
}
visitor->endVisit(this);
}
void ImportDeclaration::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(importClause, visitor);
accept(fromClause, visitor);
}
visitor->endVisit(this);
}
void ExportSpecifier::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void ExportsList::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
for (ExportsList *it = this; it; it = it->next) {
accept(it->exportSpecifier, visitor);
}
}
visitor->endVisit(this);
}
void ExportClause::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(exportsList, visitor);
}
visitor->endVisit(this);
}
void ExportDeclaration::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(fromClause, visitor);
accept(exportClause, visitor);
accept(variableStatementOrDeclaration, visitor);
}
visitor->endVisit(this);
}
void ESModule::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(body, visitor);
}
visitor->endVisit(this);
@@ -916,18 +1279,9 @@ void UiImport::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void UiQualifiedPragmaId::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
}
visitor->endVisit(this);
}
void UiPragma::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(pragmaType, visitor);
}
visitor->endVisit(this);
@@ -970,6 +1324,153 @@ void UiEnumMemberList::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void TaggedTemplate::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(base, visitor);
accept(templateLiteral, visitor);
}
visitor->endVisit(this);
}
void PatternElement::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(bindingTarget, visitor);
accept(initializer, visitor);
}
visitor->endVisit(this);
}
void PatternElement::boundNames(QStringList *names)
{
if (bindingTarget) {
if (PatternElementList *e = elementList())
e->boundNames(names);
else if (PatternPropertyList *p = propertyList())
p->boundNames(names);
} else {
names->append(bindingIdentifier.toString());
}
}
void PatternElementList::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(elision, visitor);
accept(element, visitor);
if (next)
accept(next, visitor);
}
visitor->endVisit(this);
}
void PatternElementList::boundNames(QStringList *names)
{
for (PatternElementList *it = this; it; it = it->next) {
if (it->element)
it->element->boundNames(names);
}
}
void PatternProperty::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(name, visitor);
accept(bindingTarget, visitor);
accept(initializer, visitor);
}
visitor->endVisit(this);
}
void PatternProperty::boundNames(QStringList *names)
{
PatternElement::boundNames(names);
}
void PatternPropertyList::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(property, visitor);
if (next)
accept(next, visitor);
}
visitor->endVisit(this);
}
void PatternPropertyList::boundNames(QStringList *names)
{
for (PatternPropertyList *it = this; it; it = it->next)
it->property->boundNames(names);
}
void ComputedPropertyName::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(expression, visitor);
}
visitor->endVisit(this);
}
void ClassExpression::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(heritage, visitor);
accept(elements, visitor);
}
visitor->endVisit(this);
}
ClassExpression *ClassExpression::asClassDefinition()
{
return this;
}
void ClassDeclaration::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(heritage, visitor);
accept(elements, visitor);
}
visitor->endVisit(this);
}
void ClassElementList::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(property, visitor);
if (next)
accept(next, visitor);
}
visitor->endVisit(this);
}
ClassElementList *ClassElementList::finish()
{
ClassElementList *front = next;
next = nullptr;
return front;
}
Pattern *Pattern::patternCast()
{
return this;
}
LeftHandSideExpression *LeftHandSideExpression::leftHandSideExpressionCast()
{
return this;
}
} } // namespace QmlJS::AST
QT_QML_END_NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@@ -74,22 +74,27 @@ class IdentifierExpression;
class NullExpression;
class TrueLiteral;
class FalseLiteral;
class SuperLiteral;
class NumericLiteral;
class StringLiteral;
class TemplateLiteral;
class RegExpLiteral;
class ArrayLiteral;
class ObjectLiteral;
class ElementList;
class Pattern;
class ArrayPattern;
class ObjectPattern;
class PatternElement;
class PatternElementList;
class PatternProperty;
class PatternPropertyList;
class Elision;
class PropertyAssignmentList;
class PropertyGetterSetter;
class PropertyNameAndValue;
class PropertyName;
class IdentifierPropertyName;
class StringLiteralPropertyName;
class NumericLiteralPropertyName;
class ComputedPropertyName;
class ArrayMemberExpression;
class FieldMemberExpression;
class TaggedTemplate;
class NewMemberExpression;
class NewExpression;
class CallExpression;
@@ -108,20 +113,19 @@ class NotExpression;
class BinaryExpression;
class ConditionalExpression;
class Expression; // ### rename
class YieldExpression;
class Block;
class LeftHandSideExpression;
class StatementList;
class VariableStatement;
class VariableDeclarationList;
class VariableDeclaration;
class EmptyStatement;
class ExpressionStatement;
class IfStatement;
class DoWhileStatement;
class WhileStatement;
class ForStatement;
class LocalForStatement;
class ForEachStatement;
class LocalForEachStatement;
class ContinueStatement;
class BreakStatement;
class ReturnStatement;
@@ -139,14 +143,26 @@ class Finally;
class FunctionDeclaration;
class FunctionExpression;
class FormalParameterList;
class FunctionBody;
class ExportSpecifier;
class ExportsList;
class ExportClause;
class ExportDeclaration;
class Program;
class SourceElements;
class SourceElement;
class FunctionSourceElement;
class StatementSourceElement;
class ImportSpecifier;
class ImportsList;
class NamedImports;
class NameSpaceImport;
class NamedImport;
class ImportClause;
class FromClause;
class ImportDeclaration;
class ModuleItem;
class ESModule;
class DebuggerStatement;
class NestedExpression;
class ClassExpression;
class ClassDeclaration;
class ClassElementList;
// ui elements
class UiProgram;
@@ -164,7 +180,6 @@ class UiObjectMember;
class UiObjectMemberList;
class UiArrayMemberList;
class UiQualifiedId;
class UiQualifiedPragmaId;
class UiHeaderItemList;
class UiEnumDeclaration;
class UiEnumMemberList;

View File

@@ -68,7 +68,6 @@ public:
virtual bool visit(UiObjectMemberList *) { return true; }
virtual bool visit(UiArrayMemberList *) { return true; }
virtual bool visit(UiQualifiedId *) { return true; }
virtual bool visit(UiQualifiedPragmaId *) { return true; }
virtual bool visit(UiEnumDeclaration *) { return true; }
virtual bool visit(UiEnumMemberList *) { return true; }
@@ -87,7 +86,6 @@ public:
virtual void endVisit(UiObjectMemberList *) {}
virtual void endVisit(UiArrayMemberList *) {}
virtual void endVisit(UiQualifiedId *) {}
virtual void endVisit(UiQualifiedPragmaId *) {}
virtual void endVisit(UiEnumDeclaration *) {}
virtual void endVisit(UiEnumMemberList *) { }
@@ -107,36 +105,42 @@ public:
virtual bool visit(FalseLiteral *) { return true; }
virtual void endVisit(FalseLiteral *) {}
virtual bool visit(SuperLiteral *) { return true; }
virtual void endVisit(SuperLiteral *) {}
virtual bool visit(StringLiteral *) { return true; }
virtual void endVisit(StringLiteral *) {}
virtual bool visit(TemplateLiteral *) { return true; }
virtual void endVisit(TemplateLiteral *) {}
virtual bool visit(NumericLiteral *) { return true; }
virtual void endVisit(NumericLiteral *) {}
virtual bool visit(RegExpLiteral *) { return true; }
virtual void endVisit(RegExpLiteral *) {}
virtual bool visit(ArrayLiteral *) { return true; }
virtual void endVisit(ArrayLiteral *) {}
virtual bool visit(ArrayPattern *) { return true; }
virtual void endVisit(ArrayPattern *) {}
virtual bool visit(ObjectLiteral *) { return true; }
virtual void endVisit(ObjectLiteral *) {}
virtual bool visit(ObjectPattern *) { return true; }
virtual void endVisit(ObjectPattern *) {}
virtual bool visit(ElementList *) { return true; }
virtual void endVisit(ElementList *) {}
virtual bool visit(PatternElementList *) { return true; }
virtual void endVisit(PatternElementList *) {}
virtual bool visit(PatternPropertyList *) { return true; }
virtual void endVisit(PatternPropertyList *) {}
virtual bool visit(PatternElement *) { return true; }
virtual void endVisit(PatternElement *) {}
virtual bool visit(PatternProperty *) { return true; }
virtual void endVisit(PatternProperty *) {}
virtual bool visit(Elision *) { return true; }
virtual void endVisit(Elision *) {}
virtual bool visit(PropertyAssignmentList *) { return true; }
virtual void endVisit(PropertyAssignmentList *) {}
virtual bool visit(PropertyNameAndValue *) { return true; }
virtual void endVisit(PropertyNameAndValue *) {}
virtual bool visit(PropertyGetterSetter *) { return true; }
virtual void endVisit(PropertyGetterSetter *) {}
virtual bool visit(NestedExpression *) { return true; }
virtual void endVisit(NestedExpression *) {}
@@ -149,12 +153,18 @@ public:
virtual bool visit(NumericLiteralPropertyName *) { return true; }
virtual void endVisit(NumericLiteralPropertyName *) {}
virtual bool visit(ComputedPropertyName *) { return true; }
virtual void endVisit(ComputedPropertyName *) {}
virtual bool visit(ArrayMemberExpression *) { return true; }
virtual void endVisit(ArrayMemberExpression *) {}
virtual bool visit(FieldMemberExpression *) { return true; }
virtual void endVisit(FieldMemberExpression *) {}
virtual bool visit(TaggedTemplate *) { return true; }
virtual void endVisit(TaggedTemplate *) {}
virtual bool visit(NewMemberExpression *) { return true; }
virtual void endVisit(NewMemberExpression *) {}
@@ -221,9 +231,6 @@ public:
virtual bool visit(VariableDeclarationList *) { return true; }
virtual void endVisit(VariableDeclarationList *) {}
virtual bool visit(VariableDeclaration *) { return true; }
virtual void endVisit(VariableDeclaration *) {}
virtual bool visit(EmptyStatement *) { return true; }
virtual void endVisit(EmptyStatement *) {}
@@ -242,15 +249,9 @@ public:
virtual bool visit(ForStatement *) { return true; }
virtual void endVisit(ForStatement *) {}
virtual bool visit(LocalForStatement *) { return true; }
virtual void endVisit(LocalForStatement *) {}
virtual bool visit(ForEachStatement *) { return true; }
virtual void endVisit(ForEachStatement *) {}
virtual bool visit(LocalForEachStatement *) { return true; }
virtual void endVisit(LocalForEachStatement *) {}
virtual bool visit(ContinueStatement *) { return true; }
virtual void endVisit(ContinueStatement *) {}
@@ -260,6 +261,9 @@ public:
virtual bool visit(ReturnStatement *) { return true; }
virtual void endVisit(ReturnStatement *) {}
virtual bool visit(YieldExpression *) { return true; }
virtual void endVisit(YieldExpression *) {}
virtual bool visit(WithStatement *) { return true; }
virtual void endVisit(WithStatement *) {}
@@ -302,20 +306,56 @@ public:
virtual bool visit(FormalParameterList *) { return true; }
virtual void endVisit(FormalParameterList *) {}
virtual bool visit(FunctionBody *) { return true; }
virtual void endVisit(FunctionBody *) {}
virtual bool visit(ClassExpression *) { return true; }
virtual void endVisit(ClassExpression *) {}
virtual bool visit(ClassDeclaration *) { return true; }
virtual void endVisit(ClassDeclaration *) {}
virtual bool visit(ClassElementList *) { return true; }
virtual void endVisit(ClassElementList *) {}
virtual bool visit(Program *) { return true; }
virtual void endVisit(Program *) {}
virtual bool visit(SourceElements *) { return true; }
virtual void endVisit(SourceElements *) {}
virtual bool visit(NameSpaceImport *) { return true; }
virtual void endVisit(NameSpaceImport *) {}
virtual bool visit(FunctionSourceElement *) { return true; }
virtual void endVisit(FunctionSourceElement *) {}
virtual bool visit(ImportSpecifier *) { return true; }
virtual void endVisit(ImportSpecifier *) {}
virtual bool visit(StatementSourceElement *) { return true; }
virtual void endVisit(StatementSourceElement *) {}
virtual bool visit(ImportsList *) { return true; }
virtual void endVisit(ImportsList *) {}
virtual bool visit(NamedImports *) { return true; }
virtual void endVisit(NamedImports *) {}
virtual bool visit(FromClause *) { return true; }
virtual void endVisit(FromClause *) {}
virtual bool visit(ImportClause *) { return true; }
virtual void endVisit(ImportClause *) {}
virtual bool visit(ImportDeclaration *) { return true; }
virtual void endVisit(ImportDeclaration *) {}
virtual bool visit(ExportSpecifier *) { return true; }
virtual void endVisit(ExportSpecifier *) {}
virtual bool visit(ExportsList *) { return true; }
virtual void endVisit(ExportsList *) {}
virtual bool visit(ExportClause *) { return true; }
virtual void endVisit(ExportClause *) {}
virtual bool visit(ExportDeclaration *) { return true; }
virtual void endVisit(ExportDeclaration *) {}
virtual bool visit(ModuleItem *) { return true; }
virtual void endVisit(ModuleItem *) {}
virtual bool visit(ESModule *) { return true; }
virtual void endVisit(ESModule *) {}
virtual bool visit(DebuggerStatement *) { return true; }
virtual void endVisit(DebuggerStatement *) {}

View File

@@ -98,15 +98,8 @@ double integerFromString(const char *buf, int size, int radix)
return result;
}
double integerFromString(const QString &str, int radix)
{
QByteArray ba = QStringRef(&str).trimmed().toLatin1();
return integerFromString(ba.constData(), ba.size(), radix);
}
Engine::Engine()
: _lexer(0), _directives(0)
: _lexer(nullptr), _directives(nullptr)
{ }
Engine::~Engine()

View File

@@ -49,14 +49,40 @@ QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
class Lexer;
class Directives;
class MemoryPool;
class QML_PARSER_EXPORT Directives {
public:
virtual ~Directives() {}
virtual void pragmaLibrary()
{
}
virtual void importFile(const QString &jsfile, const QString &module, int line, int column)
{
Q_UNUSED(jsfile);
Q_UNUSED(module);
Q_UNUSED(line);
Q_UNUSED(column);
}
virtual void importModule(const QString &uri, const QString &version, const QString &module, int line, int column)
{
Q_UNUSED(uri);
Q_UNUSED(version);
Q_UNUSED(module);
Q_UNUSED(line);
Q_UNUSED(column);
}
};
class QML_PARSER_EXPORT DiagnosticMessage
{
public:
DiagnosticMessage()
: kind(Severity::Error) {}
DiagnosticMessage() {}
DiagnosticMessage(Severity::Enum kind, const AST::SourceLocation &loc, const QString &message)
: kind(kind), loc(loc), message(message) {}
@@ -67,7 +93,7 @@ public:
bool isError() const
{ return kind == Severity::Error; }
Severity::Enum kind;
Severity::Enum kind = Severity::Error;
AST::SourceLocation loc;
QString message;
};

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,9 @@
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
@@ -21,6 +22,8 @@
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
@@ -39,7 +42,6 @@
#define QMLJSGRAMMAR_P_H
#include "qmljsglobal_p.h"
#include <QtCore/qglobal.h>
QT_BEGIN_NAMESPACE
@@ -48,47 +50,55 @@ class QML_PARSER_EXPORT QmlJSGrammar
public:
enum VariousConstants {
EOF_SYMBOL = 0,
REDUCE_HERE = 107,
SHIFT_THERE = 106,
REDUCE_HERE = 125,
T_AND = 1,
T_AND_AND = 2,
T_AND_EQ = 3,
T_AS = 95,
T_ARROW = 93,
T_AS = 110,
T_AUTOMATIC_SEMICOLON = 62,
T_BREAK = 4,
T_CASE = 5,
T_CATCH = 6,
T_CLASS = 98,
T_COLON = 7,
T_COMMA = 8,
T_COMMENT = 89,
T_COMPATIBILITY_SEMICOLON = 90,
T_CONST = 84,
T_COMMENT = 91,
T_COMPATIBILITY_SEMICOLON = 92,
T_CONST = 86,
T_CONTINUE = 9,
T_DEBUGGER = 86,
T_DEBUGGER = 88,
T_DEFAULT = 10,
T_DELETE = 11,
T_DIVIDE_ = 12,
T_DIVIDE_EQ = 13,
T_DO = 14,
T_DOT = 15,
T_ELLIPSIS = 95,
T_ELSE = 16,
T_ENUM = 91,
T_ENUM = 94,
T_EQ = 17,
T_EQ_EQ = 18,
T_EQ_EQ_EQ = 19,
T_ERROR = 99,
T_FALSE = 83,
T_FEED_JS_EXPRESSION = 103,
T_FEED_JS_PROGRAM = 105,
T_FEED_JS_SOURCE_ELEMENT = 104,
T_FEED_JS_STATEMENT = 102,
T_FEED_UI_OBJECT_MEMBER = 101,
T_FEED_UI_PROGRAM = 100,
T_ERROR = 114,
T_EXPORT = 101,
T_EXTENDS = 99,
T_FALSE = 85,
T_FEED_JS_EXPRESSION = 118,
T_FEED_JS_MODULE = 120,
T_FEED_JS_SCRIPT = 119,
T_FEED_JS_STATEMENT = 117,
T_FEED_UI_OBJECT_MEMBER = 116,
T_FEED_UI_PROGRAM = 115,
T_FINALLY = 20,
T_FOR = 21,
T_FORCE_BLOCK = 122,
T_FORCE_DECLARATION = 121,
T_FOR_LOOKAHEAD_OK = 123,
T_FROM = 102,
T_FUNCTION = 22,
T_GE = 23,
T_GET = 97,
T_GET = 112,
T_GT = 24,
T_GT_GT = 25,
T_GT_GT_EQ = 26,
@@ -96,13 +106,13 @@ public:
T_GT_GT_GT_EQ = 28,
T_IDENTIFIER = 29,
T_IF = 30,
T_IMPORT = 93,
T_IMPORT = 108,
T_IN = 31,
T_INSTANCEOF = 32,
T_LBRACE = 33,
T_LBRACKET = 34,
T_LE = 35,
T_LET = 85,
T_LET = 87,
T_LPAREN = 36,
T_LT = 37,
T_LT_LT = 38,
@@ -110,66 +120,82 @@ public:
T_MINUS = 40,
T_MINUS_EQ = 41,
T_MINUS_MINUS = 42,
T_MULTILINE_STRING_LITERAL = 88,
T_MULTILINE_STRING_LITERAL = 90,
T_NEW = 43,
T_NOT = 44,
T_NOT_EQ = 45,
T_NOT_EQ_EQ = 46,
T_NULL = 81,
T_NO_SUBSTITUTION_TEMPLATE = 103,
T_NULL = 83,
T_NUMERIC_LITERAL = 47,
T_ON = 96,
T_OF = 111,
T_ON = 124,
T_OR = 48,
T_OR_EQ = 49,
T_OR_OR = 50,
T_PLUS = 51,
T_PLUS_EQ = 52,
T_PLUS_PLUS = 53,
T_PRAGMA = 94,
T_PROPERTY = 66,
T_PUBLIC = 92,
T_PRAGMA = 109,
T_PROPERTY = 68,
T_PUBLIC = 107,
T_QUESTION = 54,
T_RBRACE = 55,
T_RBRACKET = 56,
T_READONLY = 68,
T_READONLY = 70,
T_REMAINDER = 57,
T_REMAINDER_EQ = 58,
T_RESERVED_WORD = 87,
T_RESERVED_WORD = 89,
T_RETURN = 59,
T_RPAREN = 60,
T_SEMICOLON = 61,
T_SET = 98,
T_SIGNAL = 67,
T_SET = 113,
T_SIGNAL = 69,
T_STAR = 63,
T_STAR_EQ = 64,
T_STRING_LITERAL = 65,
T_SWITCH = 69,
T_THIS = 70,
T_THROW = 71,
T_TILDE = 72,
T_TRUE = 82,
T_TRY = 73,
T_TYPEOF = 74,
T_VAR = 75,
T_VOID = 76,
T_WHILE = 77,
T_WITH = 78,
T_XOR = 79,
T_XOR_EQ = 80,
T_STAR_EQ = 66,
T_STAR_STAR = 64,
T_STAR_STAR_EQ = 65,
T_STATIC = 100,
T_STRING_LITERAL = 67,
T_SUPER = 97,
T_SWITCH = 71,
T_TEMPLATE_HEAD = 104,
T_TEMPLATE_MIDDLE = 105,
T_TEMPLATE_TAIL = 106,
T_THIS = 72,
T_THROW = 73,
T_TILDE = 74,
T_TRUE = 84,
T_TRY = 75,
T_TYPEOF = 76,
T_VAR = 77,
T_VOID = 78,
T_WHILE = 79,
T_WITH = 80,
T_XOR = 81,
T_XOR_EQ = 82,
T_YIELD = 96,
ACCEPT_STATE = 691,
RULE_COUNT = 369,
STATE_COUNT = 692,
TERMINAL_COUNT = 108,
NON_TERMINAL_COUNT = 112,
ACCEPT_STATE = 1008,
RULE_COUNT = 586,
STATE_COUNT = 1009,
TERMINAL_COUNT = 126,
NON_TERMINAL_COUNT = 213,
GOTO_INDEX_OFFSET = 692,
GOTO_INFO_OFFSET = 3357,
GOTO_CHECK_OFFSET = 3357
GOTO_INDEX_OFFSET = 1009,
GOTO_INFO_OFFSET = 5937,
GOTO_CHECK_OFFSET = 5937
};
static const char *const spell[];
static const short lhs[];
static const short rhs[];
#ifndef QLALR_NO_QMLJSGRAMMAR_DEBUG_INFO
static const int rule_index[];
static const int rule_info[];
#endif // QLALR_NO_QMLJSGRAMMAR_DEBUG_INFO
static const short goto_default[];
static const short action_default[];
static const short action_index[];

View File

@@ -42,10 +42,10 @@ QT_QML_BEGIN_NAMESPACE
namespace QmlJS {
static inline int classify2(const QChar *s, bool qmlMode) {
static inline int classify2(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'a') {
if (s[1].unicode() == 's') {
return qmlMode ? Lexer::T_AS : Lexer::T_IDENTIFIER;
return Lexer::T_AS;
}
}
else if (s[0].unicode() == 'd') {
@@ -61,15 +61,18 @@ static inline int classify2(const QChar *s, bool qmlMode) {
return Lexer::T_IN;
}
}
else if (qmlMode && s[0].unicode() == 'o') {
else if (s[0].unicode() == 'o') {
if (s[1].unicode() == 'n') {
return qmlMode ? Lexer::T_ON : Lexer::T_IDENTIFIER;
return (parseModeFlags & Lexer::QmlMode) ? Lexer::T_ON : Lexer::T_IDENTIFIER;
}
else if (s[1].unicode() == 'f') {
return Lexer::T_OF;
}
}
return Lexer::T_IDENTIFIER;
}
static inline int classify3(const QChar *s, bool qmlMode) {
static inline int classify3(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'f') {
if (s[1].unicode() == 'o') {
if (s[2].unicode() == 'r') {
@@ -87,7 +90,7 @@ static inline int classify3(const QChar *s, bool qmlMode) {
else if (s[0].unicode() == 'i') {
if (s[1].unicode() == 'n') {
if (s[2].unicode() == 't') {
return qmlMode ? int(Lexer::T_INT) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_INT) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -129,12 +132,12 @@ static inline int classify3(const QChar *s, bool qmlMode) {
return Lexer::T_IDENTIFIER;
}
static inline int classify4(const QChar *s, bool qmlMode) {
static inline int classify4(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'b') {
if (s[1].unicode() == 'y') {
if (s[2].unicode() == 't') {
if (s[3].unicode() == 'e') {
return qmlMode ? int(Lexer::T_BYTE) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_BYTE) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -150,7 +153,7 @@ static inline int classify4(const QChar *s, bool qmlMode) {
else if (s[1].unicode() == 'h') {
if (s[2].unicode() == 'a') {
if (s[3].unicode() == 'r') {
return qmlMode ? int(Lexer::T_CHAR) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_CHAR) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -166,7 +169,16 @@ static inline int classify4(const QChar *s, bool qmlMode) {
else if (s[1].unicode() == 'n') {
if (s[2].unicode() == 'u') {
if (s[3].unicode() == 'm') {
return qmlMode ? int(Lexer::T_ENUM) : int(Lexer::T_RESERVED_WORD);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_ENUM) : int(Lexer::T_RESERVED_WORD);
}
}
}
}
else if (s[0].unicode() == 'f') {
if (s[1].unicode() == 'r') {
if (s[2].unicode() == 'o') {
if (s[3].unicode() == 'm') {
return int(Lexer::T_FROM);
}
}
}
@@ -175,7 +187,7 @@ static inline int classify4(const QChar *s, bool qmlMode) {
if (s[1].unicode() == 'o') {
if (s[2].unicode() == 't') {
if (s[3].unicode() == 'o') {
return qmlMode ? int(Lexer::T_GOTO) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_GOTO) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -184,7 +196,7 @@ static inline int classify4(const QChar *s, bool qmlMode) {
if (s[1].unicode() == 'o') {
if (s[2].unicode() == 'n') {
if (s[3].unicode() == 'g') {
return qmlMode ? int(Lexer::T_LONG) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_LONG) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -235,7 +247,7 @@ static inline int classify4(const QChar *s, bool qmlMode) {
return Lexer::T_IDENTIFIER;
}
static inline int classify5(const QChar *s, bool qmlMode) {
static inline int classify5(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'b') {
if (s[1].unicode() == 'r') {
if (s[2].unicode() == 'e') {
@@ -290,7 +302,7 @@ static inline int classify5(const QChar *s, bool qmlMode) {
if (s[2].unicode() == 'n') {
if (s[3].unicode() == 'a') {
if (s[4].unicode() == 'l') {
return qmlMode ? int(Lexer::T_FINAL) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_FINAL) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -299,7 +311,7 @@ static inline int classify5(const QChar *s, bool qmlMode) {
if (s[2].unicode() == 'o') {
if (s[3].unicode() == 'a') {
if (s[4].unicode() == 't') {
return qmlMode ? int(Lexer::T_FLOAT) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_FLOAT) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -310,7 +322,7 @@ static inline int classify5(const QChar *s, bool qmlMode) {
if (s[2].unicode() == 'o') {
if (s[3].unicode() == 'r') {
if (s[4].unicode() == 't') {
return qmlMode ? int(Lexer::T_SHORT) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_SHORT) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -319,7 +331,7 @@ static inline int classify5(const QChar *s, bool qmlMode) {
if (s[2].unicode() == 'p') {
if (s[3].unicode() == 'e') {
if (s[4].unicode() == 'r') {
return qmlMode ? int(Lexer::T_SUPER) : int(Lexer::T_RESERVED_WORD);
return int(Lexer::T_SUPER);
}
}
}
@@ -347,10 +359,21 @@ static inline int classify5(const QChar *s, bool qmlMode) {
}
}
}
else if (s[0].unicode() == 'y') {
if (s[1].unicode() == 'i') {
if (s[2].unicode() == 'e') {
if (s[3].unicode() == 'l') {
if (s[4].unicode() == 'd') {
return (parseModeFlags & Lexer::YieldIsKeyword) ? Lexer::T_YIELD : Lexer::T_IDENTIFIER;
}
}
}
}
}
return Lexer::T_IDENTIFIER;
}
static inline int classify6(const QChar *s, bool qmlMode) {
static inline int classify6(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'd') {
if (s[1].unicode() == 'e') {
if (s[2].unicode() == 'l') {
@@ -368,7 +391,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
if (s[3].unicode() == 'b') {
if (s[4].unicode() == 'l') {
if (s[5].unicode() == 'e') {
return qmlMode ? int(Lexer::T_DOUBLE) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_DOUBLE) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -394,7 +417,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
if (s[3].unicode() == 'o') {
if (s[4].unicode() == 'r') {
if (s[5].unicode() == 't') {
return qmlMode ? int(Lexer::T_IMPORT) : int(Lexer::T_RESERVED_WORD);
return Lexer::T_IMPORT;
}
}
}
@@ -407,7 +430,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
if (s[3].unicode() == 'i') {
if (s[4].unicode() == 'v') {
if (s[5].unicode() == 'e') {
return qmlMode ? int(Lexer::T_NATIVE) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_NATIVE) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -420,7 +443,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
if (s[3].unicode() == 'l') {
if (s[4].unicode() == 'i') {
if (s[5].unicode() == 'c') {
return qmlMode ? Lexer::T_PUBLIC : Lexer::T_IDENTIFIER;
return (parseModeFlags & Lexer::QmlMode) ? Lexer::T_PUBLIC : Lexer::T_IDENTIFIER;
}
}
}
@@ -431,7 +454,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
if (s[3].unicode() == 'g') {
if (s[4].unicode() == 'm') {
if (s[5].unicode() == 'a') {
return qmlMode ? Lexer::T_PRAGMA : Lexer::T_IDENTIFIER;
return (parseModeFlags & Lexer::QmlMode) ? Lexer::T_PRAGMA : Lexer::T_IDENTIFIER;
}
}
}
@@ -452,7 +475,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
}
}
else if (s[0].unicode() == 's') {
if (qmlMode && s[1].unicode() == 'i') {
if ((parseModeFlags & Lexer::QmlMode) && s[1].unicode() == 'i') {
if (s[2].unicode() == 'g') {
if (s[3].unicode() == 'n') {
if (s[4].unicode() == 'a') {
@@ -468,7 +491,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
if (s[3].unicode() == 't') {
if (s[4].unicode() == 'i') {
if (s[5].unicode() == 'c') {
return qmlMode ? int(Lexer::T_STATIC) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::StaticIsKeyword) ? int(Lexer::T_STATIC) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -492,7 +515,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
if (s[3].unicode() == 'o') {
if (s[4].unicode() == 'w') {
if (s[5].unicode() == 's') {
return qmlMode ? int(Lexer::T_THROWS) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_THROWS) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -513,7 +536,7 @@ static inline int classify6(const QChar *s, bool qmlMode) {
return Lexer::T_IDENTIFIER;
}
static inline int classify7(const QChar *s, bool qmlMode) {
static inline int classify7(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'b') {
if (s[1].unicode() == 'o') {
if (s[2].unicode() == 'o') {
@@ -521,7 +544,7 @@ static inline int classify7(const QChar *s, bool qmlMode) {
if (s[4].unicode() == 'e') {
if (s[5].unicode() == 'a') {
if (s[6].unicode() == 'n') {
return qmlMode ? int(Lexer::T_BOOLEAN) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_BOOLEAN) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -581,7 +604,7 @@ static inline int classify7(const QChar *s, bool qmlMode) {
if (s[4].unicode() == 'a') {
if (s[5].unicode() == 'g') {
if (s[6].unicode() == 'e') {
return qmlMode ? int(Lexer::T_PACKAGE) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_PACKAGE) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -594,7 +617,7 @@ static inline int classify7(const QChar *s, bool qmlMode) {
if (s[4].unicode() == 'a') {
if (s[5].unicode() == 't') {
if (s[6].unicode() == 'e') {
return qmlMode ? int(Lexer::T_PRIVATE) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_PRIVATE) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -605,7 +628,7 @@ static inline int classify7(const QChar *s, bool qmlMode) {
return Lexer::T_IDENTIFIER;
}
static inline int classify8(const QChar *s, bool qmlMode) {
static inline int classify8(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'a') {
if (s[1].unicode() == 'b') {
if (s[2].unicode() == 's') {
@@ -614,7 +637,7 @@ static inline int classify8(const QChar *s, bool qmlMode) {
if (s[5].unicode() == 'a') {
if (s[6].unicode() == 'c') {
if (s[7].unicode() == 't') {
return qmlMode ? int(Lexer::T_ABSTRACT) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_ABSTRACT) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -674,7 +697,7 @@ static inline int classify8(const QChar *s, bool qmlMode) {
}
}
}
else if (qmlMode && s[0].unicode() == 'p') {
else if ((parseModeFlags & Lexer::QmlMode) && s[0].unicode() == 'p') {
if (s[1].unicode() == 'r') {
if (s[2].unicode() == 'o') {
if (s[3].unicode() == 'p') {
@@ -691,7 +714,7 @@ static inline int classify8(const QChar *s, bool qmlMode) {
}
}
}
else if (qmlMode && s[0].unicode() == 'r') {
else if ((parseModeFlags & Lexer::QmlMode) && s[0].unicode() == 'r') {
if (s[1].unicode() == 'e') {
if (s[2].unicode() == 'a') {
if (s[3].unicode() == 'd') {
@@ -716,7 +739,7 @@ static inline int classify8(const QChar *s, bool qmlMode) {
if (s[5].unicode() == 'i') {
if (s[6].unicode() == 'l') {
if (s[7].unicode() == 'e') {
return qmlMode ? int(Lexer::T_VOLATILE) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_VOLATILE) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -728,7 +751,7 @@ static inline int classify8(const QChar *s, bool qmlMode) {
return Lexer::T_IDENTIFIER;
}
static inline int classify9(const QChar *s, bool qmlMode) {
static inline int classify9(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'i') {
if (s[1].unicode() == 'n') {
if (s[2].unicode() == 't') {
@@ -738,7 +761,7 @@ static inline int classify9(const QChar *s, bool qmlMode) {
if (s[6].unicode() == 'a') {
if (s[7].unicode() == 'c') {
if (s[8].unicode() == 'e') {
return qmlMode ? int(Lexer::T_INTERFACE) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_INTERFACE) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -757,7 +780,7 @@ static inline int classify9(const QChar *s, bool qmlMode) {
if (s[6].unicode() == 't') {
if (s[7].unicode() == 'e') {
if (s[8].unicode() == 'd') {
return qmlMode ? int(Lexer::T_PROTECTED) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_PROTECTED) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -776,7 +799,7 @@ static inline int classify9(const QChar *s, bool qmlMode) {
if (s[6].unicode() == 'e') {
if (s[7].unicode() == 'n') {
if (s[8].unicode() == 't') {
return qmlMode ? int(Lexer::T_TRANSIENT) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_TRANSIENT) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -789,7 +812,7 @@ static inline int classify9(const QChar *s, bool qmlMode) {
return Lexer::T_IDENTIFIER;
}
static inline int classify10(const QChar *s, bool qmlMode) {
static inline int classify10(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 'i') {
if (s[1].unicode() == 'm') {
if (s[2].unicode() == 'p') {
@@ -800,7 +823,7 @@ static inline int classify10(const QChar *s, bool qmlMode) {
if (s[7].unicode() == 'n') {
if (s[8].unicode() == 't') {
if (s[9].unicode() == 's') {
return qmlMode ? int(Lexer::T_IMPLEMENTS) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_IMPLEMENTS) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -833,7 +856,7 @@ static inline int classify10(const QChar *s, bool qmlMode) {
return Lexer::T_IDENTIFIER;
}
static inline int classify12(const QChar *s, bool qmlMode) {
static inline int classify12(const QChar *s, int parseModeFlags) {
if (s[0].unicode() == 's') {
if (s[1].unicode() == 'y') {
if (s[2].unicode() == 'n') {
@@ -846,7 +869,7 @@ static inline int classify12(const QChar *s, bool qmlMode) {
if (s[9].unicode() == 'z') {
if (s[10].unicode() == 'e') {
if (s[11].unicode() == 'd') {
return qmlMode ? int(Lexer::T_SYNCHRONIZED) : int(Lexer::T_IDENTIFIER);
return (parseModeFlags & Lexer::QmlMode) ? int(Lexer::T_SYNCHRONIZED) : int(Lexer::T_IDENTIFIER);
}
}
}
@@ -862,18 +885,18 @@ static inline int classify12(const QChar *s, bool qmlMode) {
return Lexer::T_IDENTIFIER;
}
int Lexer::classify(const QChar *s, int n, bool qmlMode) {
int Lexer::classify(const QChar *s, int n, int parseModeFlags) {
switch (n) {
case 2: return classify2(s, qmlMode);
case 3: return classify3(s, qmlMode);
case 4: return classify4(s, qmlMode);
case 5: return classify5(s, qmlMode);
case 6: return classify6(s, qmlMode);
case 7: return classify7(s, qmlMode);
case 8: return classify8(s, qmlMode);
case 9: return classify9(s, qmlMode);
case 10: return classify10(s, qmlMode);
case 12: return classify12(s, qmlMode);
case 2: return classify2(s, parseModeFlags);
case 3: return classify3(s, parseModeFlags);
case 4: return classify4(s, parseModeFlags);
case 5: return classify5(s, parseModeFlags);
case 6: return classify6(s, parseModeFlags);
case 7: return classify7(s, parseModeFlags);
case 8: return classify8(s, parseModeFlags);
case 9: return classify9(s, parseModeFlags);
case 10: return classify10(s, parseModeFlags);
case 12: return classify12(s, parseModeFlags);
default: return Lexer::T_IDENTIFIER;
} // switch
}

File diff suppressed because it is too large Load Diff

View File

@@ -40,6 +40,7 @@
#include "qmljsgrammar_p.h"
#include <QtCore/qstring.h>
#include <QtCore/qstack.h>
QT_QML_BEGIN_NAMESPACE
@@ -47,35 +48,7 @@ namespace QmlJS {
class Engine;
class DiagnosticMessage;
class QML_PARSER_EXPORT Directives {
public:
virtual ~Directives() {}
virtual void pragmaLibrary(int line, int column)
{
Q_UNUSED(line);
Q_UNUSED(column);
}
virtual void importFile(const QString &jsfile, const QString &module, int line, int column)
{
Q_UNUSED(jsfile);
Q_UNUSED(module);
Q_UNUSED(line);
Q_UNUSED(column);
}
virtual void importModule(const QString &uri, const QString &version, const QString &module, int line, int column)
{
Q_UNUSED(uri);
Q_UNUSED(version);
Q_UNUSED(module);
Q_UNUSED(line);
Q_UNUSED(column);
}
};
class Directives;
class QML_PARSER_EXPORT Lexer: public QmlJSGrammar
{
@@ -85,10 +58,7 @@ public:
T_BOOLEAN = T_RESERVED_WORD,
T_BYTE = T_RESERVED_WORD,
T_CHAR = T_RESERVED_WORD,
T_CLASS = T_RESERVED_WORD,
T_DOUBLE = T_RESERVED_WORD,
T_EXPORT = T_RESERVED_WORD,
T_EXTENDS = T_RESERVED_WORD,
T_FINAL = T_RESERVED_WORD,
T_FLOAT = T_RESERVED_WORD,
T_GOTO = T_RESERVED_WORD,
@@ -101,8 +71,6 @@ public:
T_PRIVATE = T_RESERVED_WORD,
T_PROTECTED = T_RESERVED_WORD,
T_SHORT = T_RESERVED_WORD,
T_STATIC = T_RESERVED_WORD,
T_SUPER = T_RESERVED_WORD,
T_SYNCHRONIZED = T_RESERVED_WORD,
T_THROWS = T_RESERVED_WORD,
T_TRANSIENT = T_RESERVED_WORD,
@@ -112,7 +80,7 @@ public:
enum Error {
NoError,
IllegalCharacter,
IllegalHexNumber,
IllegalNumber,
UnclosedStringLiteral,
IllegalEscapeSequence,
IllegalUnicodeEscapeSequence,
@@ -130,13 +98,34 @@ public:
enum RegExpFlag {
RegExp_Global = 0x01,
RegExp_IgnoreCase = 0x02,
RegExp_Multiline = 0x04
RegExp_Multiline = 0x04,
RegExp_Unicode = 0x08,
RegExp_Sticky = 0x10
};
enum ParseModeFlags {
QmlMode = 0x1,
YieldIsKeyword = 0x2,
StaticIsKeyword = 0x4
};
public:
Lexer(Engine *engine);
int parseModeFlags() const {
int flags = 0;
if (qmlMode())
flags |= QmlMode|StaticIsKeyword;
if (yieldIsKeyWord())
flags |= YieldIsKeyword;
if (_staticIsKeyword)
flags |= StaticIsKeyword;
return flags;
}
bool qmlMode() const;
bool yieldIsKeyWord() const { return _generatorLevel != 0; }
void setStaticIsKeyword(bool b) { _staticIsKeyword = b; }
QString code() const;
void setCode(const QString &code, int lineno, bool qmlMode = true);
@@ -154,10 +143,7 @@ public:
int tokenLength() const { return _tokenLength; }
int tokenStartLine() const { return _tokenLine; }
int tokenStartColumn() const { return _tokenStartPtr - _tokenLinePtr + 1; }
int tokenEndLine() const;
int tokenEndColumn() const;
int tokenStartColumn() const { return _tokenColumn; }
inline QStringRef tokenSpell() const { return _tokenSpell; }
double tokenValue() const { return _tokenValue; }
@@ -176,13 +162,23 @@ public:
BalancedParentheses
};
void enterGeneratorBody() { ++_generatorLevel; }
void leaveGeneratorBody() { --_generatorLevel; }
protected:
int classify(const QChar *s, int n, bool qmlMode);
static int classify(const QChar *s, int n, int parseModeFlags);
private:
inline void scanChar();
int scanToken();
int scanNumber(QChar ch);
enum ScanStringMode {
SingleQuote = '\'',
DoubleQuote = '"',
TemplateHead = '`',
TemplateContinuation = 0
};
int scanString(ScanStringMode mode);
bool isLineTerminator() const;
unsigned isLineTerminatorSequence() const;
@@ -190,10 +186,9 @@ private:
static bool isDecimalDigit(ushort c);
static bool isHexDigit(QChar c);
static bool isOctalDigit(ushort c);
static bool isUnicodeEscapeSequence(const QChar *chars);
void syncProhibitAutomaticSemicolon();
QChar decodeUnicodeEscapeCharacter(bool *ok);
uint decodeUnicodeEscapeCharacter(bool *ok);
QChar decodeHexEscapeCharacter(bool *ok);
private:
@@ -206,26 +201,30 @@ private:
const QChar *_codePtr;
const QChar *_endPtr;
const QChar *_lastLinePtr;
const QChar *_tokenLinePtr;
const QChar *_tokenStartPtr;
QChar _char;
Error _errorCode;
int _currentLineNumber;
int _currentColumnNumber;
double _tokenValue;
// parentheses state
ParenthesesState _parenthesesState;
int _parenthesesCount;
// template string stack
QStack<int> _outerTemplateBraceCount;
int _bracesCount = -1;
int _stackToken;
int _patternFlags;
int _tokenKind;
int _tokenLength;
int _tokenLine;
int _tokenColumn;
bool _validTokenText;
bool _prohibitAutomaticSemicolon;
@@ -234,6 +233,8 @@ private:
bool _followsClosingBrace;
bool _delimited;
bool _qmlMode;
int _generatorLevel = 0;
bool _staticIsKeyword = false;
};
} // end of namespace QmlJS

View File

@@ -56,13 +56,7 @@ class QML_PARSER_EXPORT MemoryPool : public QSharedData
void operator =(const MemoryPool &other);
public:
MemoryPool()
: _blocks(0),
_allocatedBlocks(0),
_blockCount(-1),
_ptr(0),
_end(0)
{ }
MemoryPool() {}
~MemoryPool()
{
@@ -74,6 +68,7 @@ public:
free(_blocks);
}
qDeleteAll(strings);
}
inline void *allocate(size_t size)
@@ -90,11 +85,16 @@ public:
void reset()
{
_blockCount = -1;
_ptr = _end = 0;
_ptr = _end = nullptr;
}
template <typename Tp> Tp *New() { return new (this->allocate(sizeof(Tp))) Tp(); }
QStringRef newString(const QString &string) {
strings.append(new QString(string));
return QStringRef(strings.last());
}
private:
Q_NEVER_INLINE void *allocate_helper(size_t size)
{
@@ -110,7 +110,7 @@ private:
Q_CHECK_PTR(_blocks);
for (int index = _blockCount; index < _allocatedBlocks; ++index)
_blocks[index] = 0;
_blocks[index] = nullptr;
}
char *&block = _blocks[_blockCount];
@@ -129,11 +129,12 @@ private:
}
private:
char **_blocks;
int _allocatedBlocks;
int _blockCount;
char *_ptr;
char *_end;
char **_blocks = nullptr;
int _allocatedBlocks = 0;
int _blockCount = -1;
char *_ptr = nullptr;
char *_end = nullptr;
QVector<QString*> strings;
enum
{
@@ -144,12 +145,10 @@ private:
class QML_PARSER_EXPORT Managed
{
Managed(const Managed &other);
void operator = (const Managed &other);
Q_DISABLE_COPY(Managed)
public:
Managed() {}
~Managed() {}
Managed() = default;
~Managed() = default;
void *operator new(size_t size, MemoryPool *pool) { return pool->allocate(size); }
void operator delete(void *) {}

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,13 @@
#line 178 "qmljs.g"
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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
@@ -13,13 +16,26 @@
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** 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
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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.
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -70,30 +86,42 @@ public:
union Value {
int ival;
double dval;
AST::VariableScope scope;
AST::ForEachType forEachType;
AST::ArgumentList *ArgumentList;
AST::CaseBlock *CaseBlock;
AST::CaseClause *CaseClause;
AST::CaseClauses *CaseClauses;
AST::Catch *Catch;
AST::DefaultClause *DefaultClause;
AST::ElementList *ElementList;
AST::Elision *Elision;
AST::ExpressionNode *Expression;
AST::TemplateLiteral *Template;
AST::Finally *Finally;
AST::FormalParameterList *FormalParameterList;
AST::FunctionBody *FunctionBody;
AST::FunctionDeclaration *FunctionDeclaration;
AST::Node *Node;
AST::PropertyName *PropertyName;
AST::PropertyAssignment *PropertyAssignment;
AST::PropertyAssignmentList *PropertyAssignmentList;
AST::SourceElement *SourceElement;
AST::SourceElements *SourceElements;
AST::Statement *Statement;
AST::StatementList *StatementList;
AST::Block *Block;
AST::VariableDeclaration *VariableDeclaration;
AST::VariableDeclarationList *VariableDeclarationList;
AST::Pattern *Pattern;
AST::PatternElement *PatternElement;
AST::PatternElementList *PatternElementList;
AST::PatternProperty *PatternProperty;
AST::PatternPropertyList *PatternPropertyList;
AST::ClassElementList *ClassElementList;
AST::ImportClause *ImportClause;
AST::FromClause *FromClause;
AST::NameSpaceImport *NameSpaceImport;
AST::ImportsList *ImportsList;
AST::NamedImports *NamedImports;
AST::ImportSpecifier *ImportSpecifier;
AST::ExportSpecifier *ExportSpecifier;
AST::ExportsList *ExportsList;
AST::ExportClause *ExportClause;
AST::ExportDeclaration *ExportDeclaration;
AST::UiProgram *UiProgram;
AST::UiHeaderItemList *UiHeaderItemList;
@@ -110,7 +138,6 @@ public:
AST::UiObjectMemberList *UiObjectMemberList;
AST::UiArrayMemberList *UiArrayMemberList;
AST::UiQualifiedId *UiQualifiedId;
AST::UiQualifiedPragmaId *UiQualifiedPragmaId;
AST::UiEnumMemberList *UiEnumMemberList;
};
@@ -119,12 +146,13 @@ public:
~Parser();
// parse a UI program
bool parse() { return parse(T_FEED_UI_PROGRAM); }
bool parse() { ++functionNestingLevel; bool r = parse(T_FEED_UI_PROGRAM); --functionNestingLevel; return r; }
bool parseStatement() { return parse(T_FEED_JS_STATEMENT); }
bool parseExpression() { return parse(T_FEED_JS_EXPRESSION); }
bool parseSourceElement() { return parse(T_FEED_JS_SOURCE_ELEMENT); }
bool parseUiObjectMember() { return parse(T_FEED_UI_OBJECT_MEMBER); }
bool parseProgram() { return parse(T_FEED_JS_PROGRAM); }
bool parseUiObjectMember() { ++functionNestingLevel; bool r = parse(T_FEED_UI_OBJECT_MEMBER); --functionNestingLevel; return r; }
bool parseProgram() { return parse(T_FEED_JS_SCRIPT); }
bool parseScript() { return parse(T_FEED_JS_SCRIPT); }
bool parseModule() { return parse(T_FEED_JS_MODULE); }
AST::UiProgram *ast() const
{ return AST::cast<AST::UiProgram *>(program); }
@@ -193,22 +221,31 @@ protected:
{ return location_stack [tos + index - 1]; }
AST::UiQualifiedId *reparseAsQualifiedId(AST::ExpressionNode *expr);
AST::UiQualifiedPragmaId *reparseAsQualifiedPragmaId(AST::ExpressionNode *expr);
void pushToken(int token);
int lookaheadToken(Lexer *lexer);
void syntaxError(const AST::SourceLocation &location, const char *message) {
diagnostic_messages.append(DiagnosticMessage(Severity::Error, location, QLatin1String(message)));
}
void syntaxError(const AST::SourceLocation &location, const QString &message) {
diagnostic_messages.append(DiagnosticMessage(Severity::Error, location, message));
}
protected:
Engine *driver;
MemoryPool *pool;
int tos;
int stack_size;
Value *sym_stack;
int *state_stack;
AST::SourceLocation *location_stack;
QStringRef *string_stack;
int tos = 0;
int stack_size = 0;
Value *sym_stack = nullptr;
int *state_stack = nullptr;
AST::SourceLocation *location_stack = nullptr;
QVector<QStringRef> string_stack;
AST::Node *program;
AST::Node *program = nullptr;
// error recovery
enum { TOKEN_BUFFER_SIZE = 3 };
// error recovery and lookahead handling
enum { TOKEN_BUFFER_SIZE = 5 };
struct SavedToken {
int token;
@@ -217,14 +254,25 @@ protected:
QStringRef spell;
};
double yylval;
int yytoken = -1;
double yylval = 0.;
QStringRef yytokenspell;
AST::SourceLocation yylloc;
AST::SourceLocation yyprevlloc;
SavedToken token_buffer[TOKEN_BUFFER_SIZE];
SavedToken *first_token;
SavedToken *last_token;
SavedToken *first_token = nullptr;
SavedToken *last_token = nullptr;
int functionNestingLevel = 0;
enum CoverExpressionType {
CE_Invalid,
CE_ParenthesizedExpression,
CE_FormalParameterList
};
AST::SourceLocation coverExpressionErrorLocation;
CoverExpressionType coverExpressionType = CE_Invalid;
QList<DiagnosticMessage> diagnostic_messages;
};
@@ -233,9 +281,27 @@ protected:
#define J_SCRIPT_REGEXPLITERAL_RULE1 96
#line 1511 "qmljs.g"
#define J_SCRIPT_REGEXPLITERAL_RULE2 97
#define J_SCRIPT_REGEXPLITERAL_RULE1 128
#line 1523 "qmljs.g"
#define J_SCRIPT_REGEXPLITERAL_RULE2 129
#line 3022 "qmljs.g"
#define J_SCRIPT_EXPRESSIONSTATEMENTLOOKAHEAD_RULE 421
#line 3653 "qmljs.g"
#define J_SCRIPT_CONCISEBODYLOOKAHEAD_RULE 499
#line 4181 "qmljs.g"
#define J_SCRIPT_EXPORTDECLARATIONLOOKAHEAD_RULE 569
#line 4469 "qmljs.g"
QT_QML_END_NAMESPACE