summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-02-28 13:57:16 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-03-02 11:02:35 +0100
commit281a2dc91e96ffc833f85faf05c73eddc5bac645 (patch)
treece88cb69bdc68072e9b4375f12cf62577cbcb89e
parentfaf3ced146b50e3eb8b20a3d02711c29f9484106 (diff)
Prepare for internal QML Parser API change
With the internal API version 8, the SourceLocation will move from QQmlJS::AST to the QQmlJS namespace, and it will get its loc.startLine/loc.startColumn members back. Change-Id: I70ba5a7f7b6eca60298a7b4982bf2cf099110089 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/linguist/lupdate/qdeclarative.cpp17
-rw-r--r--src/qdoc/jscodemarker.cpp4
-rw-r--r--src/qdoc/qmlcodemarker.cpp8
-rw-r--r--src/qdoc/qmlcodemarker.h11
-rw-r--r--src/qdoc/qmlcodeparser.cpp2
-rw-r--r--src/qdoc/qmlmarkupvisitor.cpp12
-rw-r--r--src/qdoc/qmlmarkupvisitor.h20
-rw-r--r--src/qdoc/qmlvisitor.cpp12
-rw-r--r--src/qdoc/qmlvisitor.h15
9 files changed, 67 insertions, 34 deletions
diff --git a/src/linguist/lupdate/qdeclarative.cpp b/src/linguist/lupdate/qdeclarative.cpp
index 7a453aa32..7d995ae86 100644
--- a/src/linguist/lupdate/qdeclarative.cpp
+++ b/src/linguist/lupdate/qdeclarative.cpp
@@ -39,6 +39,7 @@
#include <private/qqmljslexer_p.h>
#include <private/qqmljsastvisitor_p.h>
#include <private/qqmljsast_p.h>
+#include <private/qqmlapiversion_p.h>
#include <QCoreApplication>
#include <QFile>
@@ -52,6 +53,12 @@
QT_BEGIN_NAMESPACE
+#if Q_QML_PRIVATE_API_VERSION < 8
+namespace QQmlJS {
+ using SourceLocation = AST::SourceLocation;
+}
+#endif
+
using namespace QQmlJS;
static QString MagicComment(QLatin1String("TRANSLATOR"));
@@ -229,7 +236,7 @@ private:
void processComments(quint32 offset, bool flush = false);
- void processComment(const AST::SourceLocation &loc);
+ void processComment(const SourceLocation &loc);
void consumeComment();
bool createString(AST::ExpressionNode *ast, QString *out)
@@ -259,7 +266,7 @@ private:
TranslatorMessage::ExtraData extra;
QString sourcetext;
QString trcontext;
- QList<AST::SourceLocation> m_todo;
+ QList<SourceLocation> m_todo;
};
QString createErrorString(const QString &filename, const QString &code, Parser &parser)
@@ -274,7 +281,7 @@ QString createErrorString(const QString &filename, const QString &code, Parser &
if (m.isWarning())
continue;
-#if Q_QML_PRIVATE_API_VERSION < 5
+#if Q_QML_PRIVATE_API_VERSION >= 8
const int line = m.loc.startLine;
const int column = m.loc.startColumn;
#else
@@ -315,7 +322,7 @@ void FindTrCalls::postVisit(AST::Node *node)
void FindTrCalls::processComments(quint32 offset, bool flush)
{
for (; !m_todo.isEmpty(); m_todo.removeFirst()) {
- AST::SourceLocation loc = m_todo.first();
+ SourceLocation loc = m_todo.first();
if (! flush && (loc.begin() >= offset))
break;
@@ -332,7 +339,7 @@ void FindTrCalls::consumeComment()
sourcetext.clear();
}
-void FindTrCalls::processComment(const AST::SourceLocation &loc)
+void FindTrCalls::processComment(const SourceLocation &loc)
{
if (!loc.length)
return;
diff --git a/src/qdoc/jscodemarker.cpp b/src/qdoc/jscodemarker.cpp
index d9ac99d6d..b3c675d5b 100644
--- a/src/qdoc/jscodemarker.cpp
+++ b/src/qdoc/jscodemarker.cpp
@@ -63,7 +63,7 @@ bool JsCodeMarker::recognizeCode(const QString &code)
QQmlJS::Parser parser(&engine);
QString newCode = code;
- QVector<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
+ QVector<QQmlJS::SourceLocation> pragmas = extractPragmas(newCode);
lexer.setCode(newCode, 1);
return parser.parseProgram();
@@ -112,7 +112,7 @@ QString JsCodeMarker::addMarkUp(const QString &code, const Node * /* relative */
QQmlJS::Lexer lexer(&engine);
QString newCode = code;
- QVector<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
+ QVector<QQmlJS::SourceLocation> pragmas = extractPragmas(newCode);
lexer.setCode(newCode, 1);
QQmlJS::Parser parser(&engine);
diff --git a/src/qdoc/qmlcodemarker.cpp b/src/qdoc/qmlcodemarker.cpp
index 4ecfb6475..08c9b11ed 100644
--- a/src/qdoc/qmlcodemarker.cpp
+++ b/src/qdoc/qmlcodemarker.cpp
@@ -164,7 +164,7 @@ QString QmlCodeMarker::addMarkUp(const QString &code, const Node * /* relative *
QQmlJS::Lexer lexer(&engine);
QString newCode = code;
- QVector<QQmlJS::AST::SourceLocation> pragmas = extractPragmas(newCode);
+ QVector<QQmlJS::SourceLocation> pragmas = extractPragmas(newCode);
lexer.setCode(newCode, 1);
QQmlJS::Parser parser(&engine);
@@ -217,11 +217,11 @@ static void replaceWithSpace(QString &str, int idx, int n)
Searches for ".pragma <value>" or ".import <stuff>" declarations
in \a script. Currently supported pragmas are: library
*/
-QVector<QQmlJS::AST::SourceLocation> QmlCodeMarker::extractPragmas(QString &script)
+QVector<QQmlJS::SourceLocation> QmlCodeMarker::extractPragmas(QString &script)
{
const QString pragma(QLatin1String("pragma"));
const QString library(QLatin1String("library"));
- QVector<QQmlJS::AST::SourceLocation> removed;
+ QVector<QQmlJS::SourceLocation> removed;
QQmlJS::Lexer l(nullptr);
l.setCode(script, 0);
@@ -246,7 +246,7 @@ QVector<QQmlJS::AST::SourceLocation> QmlCodeMarker::extractPragmas(QString &scri
token = l.lex();
}
replaceWithSpace(script, startOffset, endOffset - startOffset);
- removed.append(QQmlJS::AST::SourceLocation(startOffset, endOffset - startOffset, startLine,
+ removed.append(QQmlJS::SourceLocation(startOffset, endOffset - startOffset, startLine,
startColumn));
}
return removed;
diff --git a/src/qdoc/qmlcodemarker.h b/src/qdoc/qmlcodemarker.h
index c3435e840..67b1a9be7 100644
--- a/src/qdoc/qmlcodemarker.h
+++ b/src/qdoc/qmlcodemarker.h
@@ -41,6 +41,15 @@
QT_BEGIN_NAMESPACE
+#ifndef QT_NO_DECLARATIVE
+# include <private/qqmlapiversion_p.h>
+# if Q_QML_PRIVATE_API_VERSION < 8
+namespace QQmlJS {
+ using SourceLocation = AST::SourceLocation;
+}
+# endif
+#endif
+
class QmlCodeMarker : public CppCodeMarker
{
Q_DECLARE_TR_FUNCTIONS(QDoc::QmlCodeMarker)
@@ -64,7 +73,7 @@ public:
/* Copied from src/declarative/qml/qdeclarativescriptparser.cpp */
#ifndef QT_NO_DECLARATIVE
- QVector<QQmlJS::AST::SourceLocation> extractPragmas(QString &script);
+ QVector<QQmlJS::SourceLocation> extractPragmas(QString &script);
#endif
private:
diff --git a/src/qdoc/qmlcodeparser.cpp b/src/qdoc/qmlcodeparser.cpp
index e161b9cfc..a0a6bc5f0 100644
--- a/src/qdoc/qmlcodeparser.cpp
+++ b/src/qdoc/qmlcodeparser.cpp
@@ -141,7 +141,7 @@ void QmlCodeParser::parseSourceFile(const Location &location, const QString &fil
const auto &messages = parser->diagnosticMessages();
for (const auto &msg : messages) {
qDebug().nospace() << qPrintable(filePath) << ':'
-# if Q_QML_PRIVATE_API_VERSION < 5
+# if Q_QML_PRIVATE_API_VERSION >= 8
<< msg.loc.startLine << ": QML syntax error at col "
<< msg.loc.startColumn
# else
diff --git a/src/qdoc/qmlmarkupvisitor.cpp b/src/qdoc/qmlmarkupvisitor.cpp
index d7b95fae7..78f48753a 100644
--- a/src/qdoc/qmlmarkupvisitor.cpp
+++ b/src/qdoc/qmlmarkupvisitor.cpp
@@ -41,7 +41,7 @@ QT_BEGIN_NAMESPACE
#ifndef QT_NO_DECLARATIVE
QmlMarkupVisitor::QmlMarkupVisitor(const QString &source,
- const QVector<QQmlJS::AST::SourceLocation> &pragmas,
+ const QVector<QQmlJS::SourceLocation> &pragmas,
QQmlJS::Engine *engine)
{
this->source = source;
@@ -53,7 +53,7 @@ QmlMarkupVisitor::QmlMarkupVisitor(const QString &source,
// Merge the lists of locations of pragmas and comments in the source code.
int i = 0;
int j = 0;
- const QList<QQmlJS::AST::SourceLocation> comments = engine->comments();
+ const QList<QQmlJS::SourceLocation> comments = engine->comments();
while (i < comments.size() && j < pragmas.length()) {
if (comments[i].offset < pragmas[j].offset) {
extraTypes.append(Comment);
@@ -186,7 +186,7 @@ void QmlMarkupVisitor::addExtra(quint32 start, quint32 finish)
cursor = finish;
}
-void QmlMarkupVisitor::addMarkedUpToken(QQmlJS::AST::SourceLocation &location,
+void QmlMarkupVisitor::addMarkedUpToken(QQmlJS::SourceLocation &location,
const QString &tagName,
const QHash<QString, QString> &attributes)
{
@@ -205,13 +205,13 @@ void QmlMarkupVisitor::addMarkedUpToken(QQmlJS::AST::SourceLocation &location,
cursor += location.length;
}
-QString QmlMarkupVisitor::sourceText(QQmlJS::AST::SourceLocation &location)
+QString QmlMarkupVisitor::sourceText(QQmlJS::SourceLocation &location)
{
return source.mid(location.offset, location.length);
}
-void QmlMarkupVisitor::addVerbatim(QQmlJS::AST::SourceLocation first,
- QQmlJS::AST::SourceLocation last)
+void QmlMarkupVisitor::addVerbatim(QQmlJS::SourceLocation first,
+ QQmlJS::SourceLocation last)
{
if (!first.isValid())
return;
diff --git a/src/qdoc/qmlmarkupvisitor.h b/src/qdoc/qmlmarkupvisitor.h
index c9a012ae8..53d6b4ed9 100644
--- a/src/qdoc/qmlmarkupvisitor.h
+++ b/src/qdoc/qmlmarkupvisitor.h
@@ -42,12 +42,20 @@
QT_BEGIN_NAMESPACE
#ifndef QT_NO_DECLARATIVE
+# include <private/qqmlapiversion_p.h>
+# if Q_QML_PRIVATE_API_VERSION < 8
+namespace QQmlJS {
+ using SourceLocation = AST::SourceLocation;
+}
+# endif
+
+
class QmlMarkupVisitor : public QQmlJS::AST::Visitor
{
public:
enum ExtraType { Comment, Pragma };
- QmlMarkupVisitor(const QString &code, const QVector<QQmlJS::AST::SourceLocation> &pragmas,
+ QmlMarkupVisitor(const QString &code, const QVector<QQmlJS::SourceLocation> &pragmas,
QQmlJS::Engine *engine);
virtual ~QmlMarkupVisitor();
@@ -144,16 +152,16 @@ protected:
private:
typedef QHash<QString, QString> StringHash;
void addExtra(quint32 start, quint32 finish);
- void addMarkedUpToken(QQmlJS::AST::SourceLocation &location, const QString &text,
+ void addMarkedUpToken(QQmlJS::SourceLocation &location, const QString &text,
const StringHash &attributes = StringHash());
- void addVerbatim(QQmlJS::AST::SourceLocation first,
- QQmlJS::AST::SourceLocation last = QQmlJS::AST::SourceLocation());
- QString sourceText(QQmlJS::AST::SourceLocation &location);
+ void addVerbatim(QQmlJS::SourceLocation first,
+ QQmlJS::SourceLocation last = QQmlJS::SourceLocation());
+ QString sourceText(QQmlJS::SourceLocation &location);
void throwRecursionDepthError() final;
QQmlJS::Engine *engine;
QVector<ExtraType> extraTypes;
- QVector<QQmlJS::AST::SourceLocation> extraLocations;
+ QVector<QQmlJS::SourceLocation> extraLocations;
QString source;
QString output;
quint32 cursor;
diff --git a/src/qdoc/qmlvisitor.cpp b/src/qdoc/qmlvisitor.cpp
index 2ee362d77..aac45dd43 100644
--- a/src/qdoc/qmlvisitor.cpp
+++ b/src/qdoc/qmlvisitor.cpp
@@ -76,11 +76,11 @@ QmlDocVisitor::~QmlDocVisitor()
/*!
Returns the location of the nearest comment above the \a offset.
*/
-QQmlJS::AST::SourceLocation QmlDocVisitor::precedingComment(quint32 offset) const
+QQmlJS::SourceLocation QmlDocVisitor::precedingComment(quint32 offset) const
{
const auto comments = engine->comments();
for (auto it = comments.rbegin(); it != comments.rend(); ++it) {
- QQmlJS::AST::SourceLocation loc = *it;
+ QQmlJS::SourceLocation loc = *it;
if (loc.begin() <= lastEndOffset) {
// Return if we reach the end of the preceding structure.
@@ -99,7 +99,7 @@ QQmlJS::AST::SourceLocation QmlDocVisitor::precedingComment(quint32 offset) cons
}
}
- return QQmlJS::AST::SourceLocation();
+ return QQmlJS::SourceLocation();
}
class QmlSignatureParser
@@ -134,9 +134,9 @@ private:
If a qdoc comment is found for \a location, true is returned.
If a comment is not found there, false is returned.
*/
-bool QmlDocVisitor::applyDocumentation(QQmlJS::AST::SourceLocation location, Node *node)
+bool QmlDocVisitor::applyDocumentation(QQmlJS::SourceLocation location, Node *node)
{
- QQmlJS::AST::SourceLocation loc = precedingComment(location.begin());
+ QQmlJS::SourceLocation loc = precedingComment(location.begin());
if (loc.isValid()) {
QString source = document.mid(loc.offset, loc.length);
@@ -419,7 +419,7 @@ bool QmlDocVisitor::splitQmlPropertyArg(const Doc &doc, const QString &arg, QmlP
/*!
Applies the metacommands found in the comment.
*/
-void QmlDocVisitor::applyMetacommands(QQmlJS::AST::SourceLocation, Node *node, Doc &doc)
+void QmlDocVisitor::applyMetacommands(QQmlJS::SourceLocation, Node *node, Doc &doc)
{
QDocDatabase *qdb = QDocDatabase::qdocDB();
QSet<QString> metacommands = doc.metaCommandsUsed();
diff --git a/src/qdoc/qmlvisitor.h b/src/qdoc/qmlvisitor.h
index 6c10c5258..c0fe51251 100644
--- a/src/qdoc/qmlvisitor.h
+++ b/src/qdoc/qmlvisitor.h
@@ -40,6 +40,15 @@
QT_BEGIN_NAMESPACE
+#ifndef QT_NO_DECLARATIVE
+# include <private/qqmlapiversion_p.h>
+# if Q_QML_PRIVATE_API_VERSION < 8
+namespace QQmlJS {
+ using SourceLocation = AST::SourceLocation;
+}
+# endif
+#endif
+
struct QmlPropArgs
{
QString type_;
@@ -96,9 +105,9 @@ public:
private:
QString getFullyQualifiedId(QQmlJS::AST::UiQualifiedId *id);
- QQmlJS::AST::SourceLocation precedingComment(quint32 offset) const;
- bool applyDocumentation(QQmlJS::AST::SourceLocation location, Node *node);
- void applyMetacommands(QQmlJS::AST::SourceLocation location, Node *node, Doc &doc);
+ QQmlJS::SourceLocation precedingComment(quint32 offset) const;
+ bool applyDocumentation(QQmlJS::SourceLocation location, Node *node);
+ void applyMetacommands(QQmlJS::SourceLocation location, Node *node, Doc &doc);
bool splitQmlPropertyArg(const Doc &doc, const QString &arg, QmlPropArgs &qpa);
QQmlJS::Engine *engine;