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

QmlJS: Use ComponentVersion everywhere.

parent 822520c3
......@@ -31,6 +31,7 @@
#include "qmljsevaluate.h"
#include "qmljslink.h"
#include "qmljsscopebuilder.h"
#include "qmljscomponentversion.h"
#include "parser/qmljsast_p.h"
#include <QtCore/QFile>
......@@ -204,8 +205,7 @@ class FakeMetaObject {
QString m_name;
QString m_package;
int m_major;
int m_minor;
ComponentVersion m_version;
const FakeMetaObject *m_super;
QString m_superName;
QList<FakeMetaEnum> m_enums;
......@@ -216,8 +216,8 @@ class FakeMetaObject {
QString m_defaultPropertyName;
public:
FakeMetaObject(const QString &name, const QString &package, int majorVersion, int minorVersion)
: m_name(name), m_package(package), m_major(majorVersion), m_minor(minorVersion), m_super(0)
FakeMetaObject(const QString &name, const QString &package, ComponentVersion version)
: m_name(name), m_package(package), m_version(version), m_super(0)
{}
void setSuperclassName(const QString &superclass)
......@@ -265,10 +265,8 @@ public:
FakeMetaMethod method(int index) const
{ return m_methods.at(index); }
int majorVersion() const
{ return m_major; }
int minorVersion() const
{ return m_minor; }
ComponentVersion version() const
{ return m_version; }
QString defaultPropertyName() const
{ return m_defaultPropertyName; }
......@@ -398,7 +396,7 @@ private:
bool doInsert = true;
QString name, defaultPropertyName;
int major = -1, minor = -1;
QmlJS::ComponentVersion version;
QString extends;
foreach (const QXmlStreamAttribute &attr, _xml.attributes()) {
if (attr.name() == QLatin1String("name")) {
......@@ -408,28 +406,29 @@ private:
return;
}
} else if (attr.name() == QLatin1String("version")) {
QString version = attr.value().toString();
int dotIdx = version.indexOf('.');
QString versionStr = attr.value().toString();
int dotIdx = versionStr.indexOf('.');
if (dotIdx == -1) {
bool ok = false;
major = version.toInt(&ok);
const int major = versionStr.toInt(&ok);
if (!ok) {
invalidAttr(version, QLatin1String("version"), tag);
invalidAttr(versionStr, QLatin1String("version"), tag);
return;
}
minor = -1;
version = QmlJS::ComponentVersion(major, QmlJS::ComponentVersion::NoVersion);
} else {
bool ok = false;
major = version.left(dotIdx).toInt(&ok);
const int major = versionStr.left(dotIdx).toInt(&ok);
if (!ok) {
invalidAttr(version, QLatin1String("version"), tag);
invalidAttr(versionStr, QLatin1String("version"), tag);
return;
}
minor = version.mid(dotIdx + 1).toInt(&ok);
const int minor = versionStr.mid(dotIdx + 1).toInt(&ok);
if (!ok) {
invalidAttr(version, QLatin1String("version"), tag);
invalidAttr(versionStr, QLatin1String("version"), tag);
return;
}
version = QmlJS::ComponentVersion(major, minor);
}
} else if (attr.name() == QLatin1String("defaultProperty")) {
defaultPropertyName = attr.value().toString();
......@@ -448,8 +447,7 @@ private:
QString className, packageName;
split(name, &packageName, &className);
FakeMetaObject *metaObject = new FakeMetaObject(className, packageName,
major, minor);
FakeMetaObject *metaObject = new FakeMetaObject(className, packageName, version);
if (! extends.isEmpty())
metaObject->setSuperclassName(extends);
if (! defaultPropertyName.isEmpty())
......@@ -708,8 +706,6 @@ private:
} // end of anonymous namespace
const int QmlObjectValue::NoVersion = -1;
QmlObjectValue::QmlObjectValue(const FakeMetaObject *metaObject, Engine *engine)
: ObjectValue(engine),
_metaObject(metaObject)
......@@ -870,11 +866,8 @@ const Value *QmlObjectValue::propertyValue(const FakeMetaProperty &prop) const
QString QmlObjectValue::packageName() const
{ return _metaObject->packageName(); }
int QmlObjectValue::majorVersion() const
{ return _metaObject->majorVersion(); }
int QmlObjectValue::minorVersion() const
{ return _metaObject->minorVersion(); }
QmlJS::ComponentVersion QmlObjectValue::version() const
{ return _metaObject->version(); }
QString QmlObjectValue::defaultPropertyName() const
{ return _metaObject->defaultPropertyName(); }
......@@ -2036,20 +2029,18 @@ void CppQmlTypes::reload(Engine *interpreter)
}
}
QList<QmlObjectValue *> CppQmlTypes::typesForImport(const QString &packageName, int majorVersion, int minorVersion) const
QList<QmlObjectValue *> CppQmlTypes::typesForImport(const QString &packageName, ComponentVersion version) const
{
QMap<QString, QmlObjectValue *> objectValuesByName;
foreach (QmlObjectValue *qmlObjectValue, _importedTypes.value(packageName)) {
if (qmlObjectValue->majorVersion() < majorVersion ||
(qmlObjectValue->majorVersion() == majorVersion && qmlObjectValue->minorVersion() <= minorVersion)) {
if (qmlObjectValue->version() <= version) {
// we got a candidate.
const QString typeName = qmlObjectValue->className();
QmlObjectValue *previousCandidate = objectValuesByName.value(typeName, 0);
if (previousCandidate) {
// check if our new candidate is newer than the one we found previously
if (qmlObjectValue->majorVersion() > previousCandidate->majorVersion() ||
(qmlObjectValue->majorVersion() == previousCandidate->majorVersion() && qmlObjectValue->minorVersion() > previousCandidate->minorVersion())) {
if (previousCandidate->version() < qmlObjectValue->version()) {
// the new candidate has a higher version no. than the one we found previously, so replace it
objectValuesByName.insert(typeName, qmlObjectValue);
}
......@@ -2080,8 +2071,7 @@ QmlObjectValue *CppQmlTypes::typeForImport(const QString &qualifiedName) const
if (previousCandidate) {
// check if our new candidate is newer than the one we found previously
if (qmlObjectValue->majorVersion() > previousCandidate->majorVersion() ||
(qmlObjectValue->majorVersion() == previousCandidate->majorVersion() && qmlObjectValue->minorVersion() > previousCandidate->minorVersion())) {
if (previousCandidate->version() < qmlObjectValue->version()) {
// the new candidate has a higher version no. than the one we found previously, so replace it
previousCandidate = qmlObjectValue;
}
......
......@@ -32,6 +32,7 @@
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljs_global.h>
#include <qmljs/qmljscomponentversion.h>
#include <qmljs/parser/qmljsastfwd_p.h>
#include <QtCore/QFileInfoList>
......@@ -386,9 +387,6 @@ private:
class QMLJS_EXPORT QmlObjectValue: public ObjectValue
{
public:
static const int NoVersion;
public:
QmlObjectValue(const FakeMetaObject *metaObject, Engine *engine);
virtual ~QmlObjectValue();
......@@ -397,8 +395,7 @@ public:
const Value *propertyValue(const FakeMetaProperty &prop) const;
QString packageName() const;
int majorVersion() const;
int minorVersion() const;
ComponentVersion version() const;
QString defaultPropertyName() const;
QString propertyType(const QString &propertyName) const;
bool isListProperty(const QString &name) const;
......@@ -540,7 +537,7 @@ class QMLJS_EXPORT CppQmlTypes
public:
void reload(Interpreter::Engine *interpreter);
QList<Interpreter::QmlObjectValue *> typesForImport(const QString &prefix, int majorVersion, int minorVersion) const;
QList<Interpreter::QmlObjectValue *> typesForImport(const QString &prefix, ComponentVersion version) const;
Interpreter::QmlObjectValue *typeForImport(const QString &qualifiedName) const;
bool hasPackage(const QString &package) const;
......
......@@ -249,8 +249,7 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
}
const QString packageName = Bind::toString(import->importUri, '.');
int majorVersion = QmlObjectValue::NoVersion;
int minorVersion = QmlObjectValue::NoVersion;
ComponentVersion version;
if (import->versionToken.isValid()) {
const QString versionString = doc->source().mid(import->versionToken.offset, import->versionToken.length);
......@@ -260,8 +259,9 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
tr("expected two numbers separated by a dot"));
return;
} else {
majorVersion = versionString.left(dotIdx).toInt();
minorVersion = versionString.mid(dotIdx + 1).toInt();
const int majorVersion = versionString.left(dotIdx).toInt();
const int minorVersion = versionString.mid(dotIdx + 1).toInt();
version = ComponentVersion(majorVersion, minorVersion);
}
} else {
error(doc, locationFromRange(import->firstSourceLocation(), import->lastSourceLocation()),
......@@ -271,7 +271,7 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
// if the package is in the meta type system, use it
if (engine()->cppQmlTypes().hasPackage(packageName)) {
foreach (QmlObjectValue *object, engine()->cppQmlTypes().typesForImport(packageName, majorVersion, minorVersion)) {
foreach (QmlObjectValue *object, engine()->cppQmlTypes().typesForImport(packageName, version)) {
namespaceObject->setProperty(object->className(), object);
}
return;
......@@ -295,9 +295,8 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
if (importedTypes.contains(component.typeName))
continue;
if (component.majorVersion > majorVersion
|| (component.majorVersion == majorVersion
&& component.minorVersion > minorVersion))
ComponentVersion componentVersion(component.majorVersion, component.minorVersion);
if (version < componentVersion)
continue;
importedTypes.insert(component.typeName);
......
......@@ -215,14 +215,14 @@ public:
const Interpreter::QmlObjectValue * qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(value);
if (qmlValue) {
typeName = qmlValue->packageName() + QLatin1String("/") + qmlValue->className();
majorVersion = qmlValue->majorVersion();
minorVersion = qmlValue->minorVersion();
majorVersion = qmlValue->version().major();
minorVersion = qmlValue->version().minor();
} else if (value) {
for (UiQualifiedId *iter = astTypeNode; iter; iter = iter->next)
if (!iter->next && iter->name)
typeName = iter->name->asString();
majorVersion = Interpreter::QmlObjectValue::NoVersion;
minorVersion = Interpreter::QmlObjectValue::NoVersion;
majorVersion = ComponentVersion::NoVersion;
minorVersion = ComponentVersion::NoVersion;
}
}
......
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