diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2020-02-27 10:49:14 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2020-03-02 10:35:50 +0100 |
commit | 8ab237edf170f5b0482dccf5169868e5c7c47771 (patch) | |
tree | cca2d3faa0a8553a452d9139ac7442c3da25c0f8 /tools | |
parent | d8f6f41c334d14c4712b1dc16554f80bb1290e24 (diff) |
Restore offset/length in QQmlJS::DiagnosticMessage
This is needed in a few places outside of declarative, so this change
restores the loc member in DiagnosticMessage and moves
QQmlJS::AST::SourceLocation into common's QQmlJS namespace/directory.
QQmlError is unaffected and retains only line/column.
Amends d4d197d06279f9257647628f7e1ccc9ec763a6bb
Change-Id: Ifb9d344228e3c6e9e26fc4fe112686f9336ea2b2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.cpp | 6 | ||||
-rw-r--r-- | tools/qmlformat/commentastvisitor.h | 1 | ||||
-rw-r--r-- | tools/qmlformat/dumpastvisitor.h | 1 | ||||
-rw-r--r-- | tools/qmlformat/main.cpp | 4 | ||||
-rw-r--r-- | tools/qmlimportscanner/main.cpp | 2 | ||||
-rw-r--r-- | tools/qmllint/main.cpp | 2 | ||||
-rw-r--r-- | tools/qmllint/scopetree.cpp | 12 | ||||
-rw-r--r-- | tools/qmllint/scopetree.h | 16 | ||||
-rw-r--r-- | tools/qmllint/typedescriptionreader.h | 4 |
9 files changed, 25 insertions, 23 deletions
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index b1670c940d..bc74e7b08e 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -84,9 +84,9 @@ Error Error::augment(const QString &contextErrorMessage) const QString diagnosticErrorMessage(const QString &fileName, const QQmlJS::DiagnosticMessage &m) { QString message; - message = fileName + QLatin1Char(':') + QString::number(m.line) + QLatin1Char(':'); - if (m.column > 0) - message += QString::number(m.column) + QLatin1Char(':'); + message = fileName + QLatin1Char(':') + QString::number(m.loc.startLine) + QLatin1Char(':'); + if (m.loc.startColumn > 0) + message += QString::number(m.loc.startColumn) + QLatin1Char(':'); if (m.isError()) message += QLatin1String(" error: "); diff --git a/tools/qmlformat/commentastvisitor.h b/tools/qmlformat/commentastvisitor.h index c756c4f820..d3de0a9b9d 100644 --- a/tools/qmlformat/commentastvisitor.h +++ b/tools/qmlformat/commentastvisitor.h @@ -38,6 +38,7 @@ #include <QVector> using namespace QQmlJS::AST; +using namespace QQmlJS; struct Comment { diff --git a/tools/qmlformat/dumpastvisitor.h b/tools/qmlformat/dumpastvisitor.h index 1e25bd9190..faf067d400 100644 --- a/tools/qmlformat/dumpastvisitor.h +++ b/tools/qmlformat/dumpastvisitor.h @@ -38,6 +38,7 @@ #include "commentastvisitor.h" using namespace QQmlJS::AST; +using namespace QQmlJS; class DumpAstVisitor : protected Visitor { diff --git a/tools/qmlformat/main.cpp b/tools/qmlformat/main.cpp index 915389e3d2..da58ffd5d0 100644 --- a/tools/qmlformat/main.cpp +++ b/tools/qmlformat/main.cpp @@ -67,7 +67,7 @@ bool parseFile(const QString& filename, bool inplace, bool verbose, bool sortImp const auto diagnosticMessages = parser.diagnosticMessages(); for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { qWarning().noquote() << QString::fromLatin1("%1:%2 : %3") - .arg(filename).arg(m.line).arg(m.message); + .arg(filename).arg(m.loc.startLine).arg(m.message); } qWarning().noquote() << "Failed to parse" << filename; @@ -112,7 +112,7 @@ bool parseFile(const QString& filename, bool inplace, bool verbose, bool sortImp const auto diagnosticMessages = parser.diagnosticMessages(); for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { qWarning().noquote() << QString::fromLatin1("<formatted>:%2 : %3") - .arg(m.line).arg(m.message); + .arg(m.loc.startLine).arg(m.message); } } diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp index b563d7df95..e5d43a8e89 100644 --- a/tools/qmlimportscanner/main.cpp +++ b/tools/qmlimportscanner/main.cpp @@ -277,7 +277,7 @@ QVariantList findQmlImportsInQmlCode(const QString &filePath, const QString &cod const auto diagnosticMessages = parser.diagnosticMessages(); for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { std::cerr << QDir::toNativeSeparators(filePath).toStdString() << ':' - << m.line << ':' << m.message.toStdString() << std::endl; + << m.loc.startLine << ':' << m.message.toStdString() << std::endl; } return QVariantList(); } diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index 0a0e669e94..fa601986b2 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -78,7 +78,7 @@ static bool lint_file(const QString &filename, const bool silent, const bool war const auto diagnosticMessages = parser.diagnosticMessages(); for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { qWarning().noquote() << QString::fromLatin1("%1:%2 : %3") - .arg(filename).arg(m.line).arg(m.message); + .arg(filename).arg(m.loc.startLine).arg(m.message); } } diff --git a/tools/qmllint/scopetree.cpp b/tools/qmllint/scopetree.cpp index 2ca3ed9a67..e7e0113f35 100644 --- a/tools/qmllint/scopetree.cpp +++ b/tools/qmllint/scopetree.cpp @@ -62,7 +62,7 @@ void ScopeTree::insertJSIdentifier(const QString &id, QQmlJS::AST::VariableScope } void ScopeTree::insertSignalIdentifier(const QString &id, const MetaMethod &method, - const QQmlJS::AST::SourceLocation &loc, + const QQmlJS::SourceLocation &loc, bool hasMultilineHandlerBody) { Q_ASSERT(m_scopeType == ScopeType::QMLScope); @@ -77,7 +77,7 @@ void ScopeTree::insertPropertyIdentifier(const MetaProperty &property) } void ScopeTree::addUnmatchedSignalHandler(const QString &handler, - const QQmlJS::AST::SourceLocation &location) + const QQmlJS::SourceLocation &location) { m_unmatchedSignalHandlers.append(qMakePair(handler, location)); } @@ -87,13 +87,13 @@ bool ScopeTree::isIdInCurrentScope(const QString &id) const return isIdInCurrentQMlScopes(id) || isIdInCurrentJSScopes(id); } -void ScopeTree::addIdToAccessed(const QString &id, const QQmlJS::AST::SourceLocation &location) { +void ScopeTree::addIdToAccessed(const QString &id, const QQmlJS::SourceLocation &location) { m_currentFieldMember = new FieldMemberList {id, QString(), location, {}}; m_accessedIdentifiers.push_back(std::unique_ptr<FieldMemberList>(m_currentFieldMember)); } void ScopeTree::accessMember(const QString &name, const QString &parentType, - const QQmlJS::AST::SourceLocation &location) + const QQmlJS::SourceLocation &location) { Q_ASSERT(m_currentFieldMember); auto *fieldMember = new FieldMemberList {name, parentType, location, {}}; @@ -115,7 +115,7 @@ bool ScopeTree::isVisualRootScope() const class IssueLocationWithContext { public: - IssueLocationWithContext(const QString &code, const QQmlJS::AST::SourceLocation &location) { + IssueLocationWithContext(const QString &code, const QQmlJS::SourceLocation &location) { int before = std::max(0,code.lastIndexOf('\n', location.offset)); m_beforeText = code.midRef(before + 1, int(location.offset - (before + 1))); m_issueText = code.midRef(location.offset, location.length); @@ -440,7 +440,7 @@ const ScopeTree *ScopeTree::currentQMLScope() const } void ScopeTree::printContext(ColorOutput &colorOut, const QString &code, - const QQmlJS::AST::SourceLocation &location) const + const QQmlJS::SourceLocation &location) const { IssueLocationWithContext issueLocationWithContext {code, location}; colorOut.write(issueLocationWithContext.beforeText().toString(), Normal); diff --git a/tools/qmllint/scopetree.h b/tools/qmllint/scopetree.h index f5d1155a49..63f4310bf8 100644 --- a/tools/qmllint/scopetree.h +++ b/tools/qmllint/scopetree.h @@ -68,7 +68,7 @@ enum class ScopeType struct MethodUsage { MetaMethod method; - QQmlJS::AST::SourceLocation loc; + QQmlJS::SourceLocation loc; bool hasMultilineHandlerBody; }; @@ -112,16 +112,16 @@ public: void insertJSIdentifier(const QString &id, QQmlJS::AST::VariableScope scope); void insertSignalIdentifier(const QString &id, const MetaMethod &method, - const QQmlJS::AST::SourceLocation &loc, bool hasMultilineHandlerBody); + const QQmlJS::SourceLocation &loc, bool hasMultilineHandlerBody); // inserts property as qml identifier as well as the corresponding void insertPropertyIdentifier(const MetaProperty &prop); void addUnmatchedSignalHandler(const QString &handler, - const QQmlJS::AST::SourceLocation &location); + const QQmlJS::SourceLocation &location); bool isIdInCurrentScope(const QString &id) const; - void addIdToAccessed(const QString &id, const QQmlJS::AST::SourceLocation &location); + void addIdToAccessed(const QString &id, const QQmlJS::SourceLocation &location); void accessMember(const QString &name, const QString &parentType, - const QQmlJS::AST::SourceLocation &location); + const QQmlJS::SourceLocation &location); void resetMemberScope(); bool isVisualRootScope() const; @@ -174,7 +174,7 @@ private: { QString m_name; QString m_parentType; - QQmlJS::AST::SourceLocation m_location; + QQmlJS::SourceLocation m_location; std::unique_ptr<FieldMemberList> m_child; }; @@ -188,7 +188,7 @@ private: std::vector<std::unique_ptr<FieldMemberList>> m_accessedIdentifiers; FieldMemberList *m_currentFieldMember = nullptr; - QVector<QPair<QString, QQmlJS::AST::SourceLocation>> m_unmatchedSignalHandlers; + QVector<QPair<QString, QQmlJS::SourceLocation>> m_unmatchedSignalHandlers; QVector<ScopeTree::Ptr> m_childScopes; ScopeTree *m_parentScope; @@ -211,7 +211,7 @@ private: bool isIdInjectedFromSignal(const QString &id) const; const ScopeTree *currentQMLScope() const; void printContext(ColorOutput &colorOut, const QString &code, - const QQmlJS::AST::SourceLocation &location) const; + const QQmlJS::SourceLocation &location) const; bool checkMemberAccess( const QString &code, FieldMemberList *members, diff --git a/tools/qmllint/typedescriptionreader.h b/tools/qmllint/typedescriptionreader.h index 5fcbe3abc9..48c33bee3c 100644 --- a/tools/qmllint/typedescriptionreader.h +++ b/tools/qmllint/typedescriptionreader.h @@ -90,8 +90,8 @@ private: void readMetaObjectRevisions(QQmlJS::AST::UiScriptBinding *ast, const ScopeTree::Ptr &scope); void readEnumValues(QQmlJS::AST::UiScriptBinding *ast, MetaEnum *metaEnum); - void addError(const QQmlJS::AST::SourceLocation &loc, const QString &message); - void addWarning(const QQmlJS::AST::SourceLocation &loc, const QString &message); + void addError(const QQmlJS::SourceLocation &loc, const QString &message); + void addWarning(const QQmlJS::SourceLocation &loc, const QString &message); QString m_fileName; QString m_source; |