From 30971fa4ffaeb4c2a3a1267cca73311fb9834241 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 4 Jun 2009 15:35:22 +0200 Subject: Added offsets of automatically inserted semicolons to the DOM and the QML script parser. --- src/declarative/qml/qmldom.cpp | 10 ++++++++++ src/declarative/qml/qmldom.h | 3 +++ src/declarative/qml/qmldom_p.h | 1 + src/declarative/qml/qmlscriptparser.cpp | 11 +++++++++++ src/declarative/qml/qmlscriptparser_p.h | 4 ++++ 5 files changed, 29 insertions(+) diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp index 0ebbbfb..e06afb5 100644 --- a/src/declarative/qml/qmldom.cpp +++ b/src/declarative/qml/qmldom.cpp @@ -194,6 +194,8 @@ bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl d->imports += QUrl(td->data.imports().at(i).uri); } + d->automaticSemicolonOffsets = td->data.automaticSemicolonOffsets(); + if (td->data.tree()) { if (compilerDump()) { qWarning() << "-AST------------------------------------------------------------------------------"; @@ -251,6 +253,14 @@ QmlDomObject QmlDomDocument::rootObject() const return rv; } +QList QmlDomDocument::automaticSemicolonOffsets() const +{ + if (d) + return d->automaticSemicolonOffsets; + else + return QList(); +} + QmlDomPropertyPrivate::QmlDomPropertyPrivate() : property(0) { diff --git a/src/declarative/qml/qmldom.h b/src/declarative/qml/qmldom.h index 86eaecb..442a4fc 100644 --- a/src/declarative/qml/qmldom.h +++ b/src/declarative/qml/qmldom.h @@ -78,6 +78,9 @@ public: QByteArray save() const; QmlDomObject rootObject() const; + + QList automaticSemicolonOffsets() const; + private: QSharedDataPointer d; }; diff --git a/src/declarative/qml/qmldom_p.h b/src/declarative/qml/qmldom_p.h index 74edd47..441269c 100644 --- a/src/declarative/qml/qmldom_p.h +++ b/src/declarative/qml/qmldom_p.h @@ -62,6 +62,7 @@ public: QList errors; QList imports; QmlParser::Object *root; + QList automaticSemicolonOffsets; }; class QmlDomObjectPrivate : public QSharedData diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 31a20be..5207292 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -178,6 +178,8 @@ protected: virtual bool visit(AST::UiArrayBinding *node); virtual bool visit(AST::UiSourceElement *node); + virtual bool visit(AST::ExpressionStatement *node); + void accept(AST::Node *node); QString asString(AST::UiQualifiedId *node) const; @@ -638,6 +640,14 @@ bool ProcessAST::visit(AST::UiScriptBinding *node) return true; } +bool ProcessAST::visit(AST::ExpressionStatement *node) +{ + if (!node->semicolonToken.isValid()) + _parser->addAutomaticSemicolonOffset(node->semicolonToken.offset); + + return true; +} + // UiObjectMember: UiQualifiedId T_COLON T_LBRACKET UiObjectMemberList T_RBRACKET ; bool ProcessAST::visit(AST::UiArrayBinding *node) { @@ -825,6 +835,7 @@ void QmlScriptParser::clear() _nameSpacePaths.clear(); _typeNames.clear(); _errors.clear(); + _automaticSemicolonOffsets.clear(); if (data) { delete data; diff --git a/src/declarative/qml/qmlscriptparser_p.h b/src/declarative/qml/qmlscriptparser_p.h index 3993194..b057e2b 100644 --- a/src/declarative/qml/qmlscriptparser_p.h +++ b/src/declarative/qml/qmlscriptparser_p.h @@ -82,6 +82,9 @@ public: QList errors() const; + QList automaticSemicolonOffsets() const { return _automaticSemicolonOffsets; } + void addAutomaticSemicolonOffset(int offset) { _automaticSemicolonOffsets.append(offset); } + // ### private: int findOrCreateTypeId(const QString &name); void setTree(QmlParser::Object *tree); @@ -100,6 +103,7 @@ public: QStringList _typeNames; QString _scriptFile; QmlScriptParserJsASTData *data; + QList _automaticSemicolonOffsets; }; QT_END_NAMESPACE -- cgit v0.12