aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmllint
diff options
context:
space:
mode:
Diffstat (limited to 'tools/qmllint')
-rw-r--r--tools/qmllint/componentversion.cpp18
-rw-r--r--tools/qmllint/componentversion.h14
-rw-r--r--tools/qmllint/findunqualified.cpp46
-rw-r--r--tools/qmllint/findunqualified.h2
-rw-r--r--tools/qmllint/main.cpp2
-rw-r--r--tools/qmllint/scopetree.cpp12
-rw-r--r--tools/qmllint/scopetree.h16
-rw-r--r--tools/qmllint/typedescriptionreader.cpp2
-rw-r--r--tools/qmllint/typedescriptionreader.h4
9 files changed, 56 insertions, 60 deletions
diff --git a/tools/qmllint/componentversion.cpp b/tools/qmllint/componentversion.cpp
index e5047b8302..95403ec15f 100644
--- a/tools/qmllint/componentversion.cpp
+++ b/tools/qmllint/componentversion.cpp
@@ -41,21 +41,21 @@ ComponentVersion::ComponentVersion(const QString &versionString)
const int maybeMinor = versionString.midRef(dotIdx + 1).toInt(&ok);
if (!ok)
return;
- m_major = maybeMajor;
- m_minor = maybeMinor;
+ m_version = QTypeRevision::fromVersion(maybeMajor, maybeMinor);
}
bool operator<(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
- return lhs.majorVersion() < rhs.majorVersion()
- || (lhs.majorVersion() == rhs.majorVersion() && lhs.minorVersion() < rhs.minorVersion());
+ return lhs.version().majorVersion() < rhs.version().majorVersion()
+ || (lhs.version().majorVersion() == rhs.version().majorVersion()
+ && lhs.version().minorVersion() < rhs.version().minorVersion());
}
bool operator<=(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
- return lhs.majorVersion() < rhs.majorVersion()
- || (lhs.majorVersion() == rhs.majorVersion()
- && lhs.minorVersion() <= rhs.minorVersion());
+ return lhs.version().majorVersion() < rhs.version().majorVersion()
+ || (lhs.version().majorVersion() == rhs.version().majorVersion()
+ && lhs.version().minorVersion() <= rhs.version().minorVersion());
}
bool operator>(const ComponentVersion &lhs, const ComponentVersion &rhs)
@@ -70,8 +70,8 @@ bool operator>=(const ComponentVersion &lhs, const ComponentVersion &rhs)
bool operator==(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
- return lhs.majorVersion() == rhs.majorVersion()
- && lhs.minorVersion() == rhs.minorVersion();
+ return lhs.version().majorVersion() == rhs.version().majorVersion()
+ && lhs.version().minorVersion() == rhs.version().minorVersion();
}
bool operator!=(const ComponentVersion &lhs, const ComponentVersion &rhs)
diff --git a/tools/qmllint/componentversion.h b/tools/qmllint/componentversion.h
index 9c4604b9a3..bbb039fc40 100644
--- a/tools/qmllint/componentversion.h
+++ b/tools/qmllint/componentversion.h
@@ -40,24 +40,20 @@
// We mean it.
#include <QtCore/qglobal.h>
+#include <QtCore/qversionnumber.h>
class ComponentVersion
{
public:
- static const int NoVersion = -1;
-
ComponentVersion() = default;
- ComponentVersion(int major, int minor) : m_major(major), m_minor(minor) {}
+ ComponentVersion(QTypeRevision version) : m_version(version) {}
explicit ComponentVersion(const QString &versionString);
- int majorVersion() const { return m_major; }
- int minorVersion() const { return m_minor; }
-
- bool isValid() const { return m_major >= 0 && m_minor >= 0; }
+ QTypeRevision version() const { return m_version; }
+ bool isValid() const { return m_version.hasMajorVersion() && m_version.hasMinorVersion(); }
private:
- int m_major = NoVersion;
- int m_minor = NoVersion;
+ QTypeRevision m_version;
};
bool operator<(const ComponentVersion &lhs, const ComponentVersion &rhs);
diff --git a/tools/qmllint/findunqualified.cpp b/tools/qmllint/findunqualified.cpp
index 807110c3c1..6155ea4637 100644
--- a/tools/qmllint/findunqualified.cpp
+++ b/tools/qmllint/findunqualified.cpp
@@ -92,8 +92,7 @@ void FindUnqualifiedIDVisitor::parseHeaders(QQmlJS::AST::UiHeaderItemList *heade
if (import->asToken.isValid()) {
prefix += import->importId + QLatin1Char('.');
}
- importHelper(path, prefix, import->version->majorVersion,
- import->version->minorVersion);
+ importHelper(path, prefix, import->version->version);
}
}
header = header->next;
@@ -119,26 +118,27 @@ ScopeTree *FindUnqualifiedIDVisitor::parseProgram(QQmlJS::AST::Program *program,
enum ImportVersion { FullyVersioned, PartiallyVersioned, Unversioned, BasePath };
-QStringList completeImportPaths(const QString &uri, const QString &basePath, int vmaj, int vmin)
+QStringList completeImportPaths(const QString &uri, const QString &basePath, QTypeRevision version)
{
static const QLatin1Char Slash('/');
static const QLatin1Char Backslash('\\');
- const QVector<QStringRef> parts = uri.splitRef(QLatin1Char('.'), QString::SkipEmptyParts);
+ const QVector<QStringRef> parts = uri.splitRef(QLatin1Char('.'), Qt::SkipEmptyParts);
QStringList qmlDirPathsPaths;
// fully & partially versioned parts + 1 unversioned for each base path
qmlDirPathsPaths.reserve(2 * parts.count() + 1);
- auto versionString = [](int vmaj, int vmin, ImportVersion version)
+ auto versionString = [](QTypeRevision version, ImportVersion mode)
{
- if (version == FullyVersioned) {
+ if (mode == FullyVersioned) {
// extension with fully encoded version number (eg. MyModule.3.2)
- return QString::fromLatin1(".%1.%2").arg(vmaj).arg(vmin);
+ return QString::fromLatin1(".%1.%2").arg(version.majorVersion())
+ .arg(version.minorVersion());
}
- if (version == PartiallyVersioned) {
+ if (mode == PartiallyVersioned) {
// extension with encoded version major (eg. MyModule.3)
- return QString::fromLatin1(".%1").arg(vmaj);
+ return QString::fromLatin1(".%1").arg(version.majorVersion());
}
// else extension without version number (eg. MyModule)
return QString();
@@ -153,24 +153,24 @@ QStringList completeImportPaths(const QString &uri, const QString &basePath, int
return str;
};
- const ImportVersion initial = (vmin >= 0)
+ const ImportVersion initial = (version.hasMinorVersion())
? FullyVersioned
- : (vmaj >= 0 ? PartiallyVersioned : Unversioned);
- for (int version = initial; version <= BasePath; ++version) {
- const QString ver = versionString(vmaj, vmin, static_cast<ImportVersion>(version));
+ : (version.hasMajorVersion() ? PartiallyVersioned : Unversioned);
+ for (int mode = initial; mode <= BasePath; ++mode) {
+ const QString ver = versionString(version, ImportVersion(mode));
QString dir = basePath;
if (!dir.endsWith(Slash) && !dir.endsWith(Backslash))
dir += Slash;
- if (version == BasePath) {
+ if (mode == BasePath) {
qmlDirPathsPaths += dir;
} else {
// append to the end
qmlDirPathsPaths += dir + joinStringRefs(parts, Slash) + ver;
}
- if (version < Unversioned) {
+ if (mode < Unversioned) {
// insert in the middle
for (int index = parts.count() - 2; index >= 0; --index) {
qmlDirPathsPaths += dir + joinStringRefs(parts.mid(0, index + 1), Slash)
@@ -222,7 +222,7 @@ FindUnqualifiedIDVisitor::Import FindUnqualifiedIDVisitor::readQmldir(const QStr
(*mo)->addExport(
it.key(), reader.typeNamespace(),
- ComponentVersion(it->majorVersion, it->minorVersion));
+ ComponentVersion(it->version));
}
for (auto it = qmlComponents.begin(), end = qmlComponents.end(); it != end; ++it)
result.objects.insert( it.key(), ScopeTree::ConstPtr(it.value()));
@@ -240,11 +240,11 @@ void FindUnqualifiedIDVisitor::processImport(const QString &prefix, const FindUn
auto const &id = split.at(0);
if (split.length() > 1) {
const auto version = split.at(1).split('.');
- importHelper(id, QString(),
- version.at(0).toInt(),
- version.length() > 1 ? version.at(1).toInt() : -1);
+ importHelper(id, QString(), QTypeRevision::fromVersion(
+ version.at(0).toInt(),
+ version.length() > 1 ? version.at(1).toInt() : -1));
} else {
- importHelper(id, QString(), -1, -1);
+ importHelper(id, QString(), QTypeRevision());
}
@@ -267,7 +267,7 @@ void FindUnqualifiedIDVisitor::processImport(const QString &prefix, const FindUn
}
void FindUnqualifiedIDVisitor::importHelper(const QString &module, const QString &prefix,
- int major, int minor)
+ QTypeRevision version)
{
const QString id = QString(module).replace(QLatin1Char('/'), QLatin1Char('.'));
QPair<QString, QString> importId { id, prefix };
@@ -276,7 +276,7 @@ void FindUnqualifiedIDVisitor::importHelper(const QString &module, const QString
m_alreadySeenImports.insert(importId);
for (const QString &qmltypeDir : m_qmltypeDirs) {
- auto qmltypesPaths = completeImportPaths(id, qmltypeDir, major, minor);
+ auto qmltypesPaths = completeImportPaths(id, qmltypeDir, version);
for (auto const &qmltypesPath : qmltypesPaths) {
if (QFile::exists(qmltypesPath + SlashQmldir)) {
@@ -764,7 +764,7 @@ bool FindUnqualifiedIDVisitor::visit(QQmlJS::AST::UiImport *import)
}
path.chop(1);
- importHelper(path, prefix, import->version->majorVersion, import->version->minorVersion);
+ importHelper(path, prefix, import->version->version);
}
return true;
}
diff --git a/tools/qmllint/findunqualified.h b/tools/qmllint/findunqualified.h
index 6668b53b08..1c351e4fd9 100644
--- a/tools/qmllint/findunqualified.h
+++ b/tools/qmllint/findunqualified.h
@@ -91,7 +91,7 @@ private:
void enterEnvironment(ScopeType type, const QString &name);
void leaveEnvironment();
void importHelper(const QString &module, const QString &prefix = QString(),
- int major = -1, int minor = -1);
+ QTypeRevision version = QTypeRevision());
void readQmltypes(const QString &filename, Import &result);
Import readQmldir(const QString &dirname);
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.cpp b/tools/qmllint/typedescriptionreader.cpp
index 3dc87ffc8d..8734f349d5 100644
--- a/tools/qmllint/typedescriptionreader.cpp
+++ b/tools/qmllint/typedescriptionreader.cpp
@@ -102,7 +102,7 @@ void TypeDescriptionReader::readDocument(UiProgram *ast)
return;
}
- if (import->version->majorVersion != 1) {
+ if (import->version->version.majorVersion() != 1) {
addError(import->version->firstSourceLocation(),
tr("Major version different from 1 not supported."));
return;
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;