Commit ea5ca799 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Add ComponentVersion class to simplify dealing with versions.

parent 0d5d6344
......@@ -20,7 +20,8 @@ HEADERS += \
$$PWD/qmljscheck.h \
$$PWD/qmljsscopebuilder.h \
$$PWD/qmljslineinfo.h \
$$PWD/qmljscompletioncontextfinder.h
$$PWD/qmljscompletioncontextfinder.h \
$$PWD/qmljscomponentversion.h
SOURCES += \
$$PWD/qmljsbind.cpp \
......@@ -32,7 +33,8 @@ SOURCES += \
$$PWD/qmljscheck.cpp \
$$PWD/qmljsscopebuilder.cpp \
$$PWD/qmljslineinfo.cpp \
$$PWD/qmljscompletioncontextfinder.cpp
$$PWD/qmljscompletioncontextfinder.cpp \
$$PWD/qmljscomponentversion.cpp
OTHER_FILES += \
$$PWD/parser/qmljs.g
......
......@@ -187,15 +187,12 @@ bool Bind::visit(UiImport *ast)
{
ImportInfo info;
info.majorVersion = QmlObjectValue::NoVersion;
info.minorVersion = QmlObjectValue::NoVersion;
if (ast->versionToken.isValid()) {
const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length);
const int dotIdx = versionString.indexOf(QLatin1Char('.'));
if (dotIdx != -1) {
info.majorVersion = versionString.left(dotIdx).toInt();
info.minorVersion = versionString.mid(dotIdx + 1).toInt();
info.version = ComponentVersion(versionString.left(dotIdx).toInt(),
versionString.mid(dotIdx + 1).toInt());
}
}
......
......@@ -32,6 +32,7 @@
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/qmljsinterpreter.h>
#include <qmljs/qmljscomponentversion.h>
#include <QtCore/QHash>
#include <QtCore/QStringList>
......@@ -52,8 +53,7 @@ public:
struct ImportInfo {
QString name;
int majorVersion;
int minorVersion;
ComponentVersion version;
};
QList<ImportInfo> fileImports() const;
......
#include "qmljscomponentversion.h"
using namespace QmlJS;
const int ComponentVersion::NoVersion = -1;
ComponentVersion::ComponentVersion()
: _major(NoVersion), _minor(NoVersion)
{
}
ComponentVersion::ComponentVersion(int major, int minor)
: _major(major), _minor(minor)
{
}
ComponentVersion::~ComponentVersion()
{
}
bool ComponentVersion::isValid() const
{
return _major >= 0 && _minor >= 0;
}
namespace QmlJS {
bool operator<(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
return lhs.major() < rhs.major()
|| (lhs.major() == rhs.major() && lhs.minor() < rhs.minor());
}
bool operator<=(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
return lhs.major() < rhs.major()
|| (lhs.major() == rhs.major() && lhs.minor() <= rhs.minor());
}
bool operator==(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
return lhs.major() == rhs.major() && lhs.minor() == rhs.minor();
}
bool operator!=(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
return !(lhs == rhs);
}
}
#ifndef QMLJSCOMPONENTVERSION_H
#define QMLJSCOMPONENTVERSION_H
#include "qmljs_global.h"
namespace QmlJS {
class QMLJS_EXPORT ComponentVersion
{
int _major;
int _minor;
public:
static const int NoVersion;
ComponentVersion();
ComponentVersion(int major, int minor);
~ComponentVersion();
int major() const
{ return _major; }
int minor() const
{ return _minor; }
bool isValid() const;
};
bool operator<(const ComponentVersion &lhs, const ComponentVersion &rhs);
bool operator<=(const ComponentVersion &lhs, const ComponentVersion &rhs);
bool operator==(const ComponentVersion &lhs, const ComponentVersion &rhs);
bool operator!=(const ComponentVersion &lhs, const ComponentVersion &rhs);
} // namespace QmlJS
#endif // QMLJSCOMPONENTVERSION_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment