Commit 187ae1e9 authored by Christian Kamm's avatar Christian Kamm

QmlJS: Rework FakeMetaObjects to no longer contain pointers.

Having a duplicate prototype chain - once in FakeMetaObjects and once
in QmlObjectValues was unnecessary. Now FMOs don't contain references
which may allow other simplifications.
parent 13f91358
......@@ -121,7 +121,6 @@ bool FakeMetaProperty::isPointer() const
FakeMetaObject::FakeMetaObject()
: m_super(0)
{
}
......@@ -143,17 +142,20 @@ void FakeMetaObject::addExport(const QString &name, const QString &package, Comp
}
QList<FakeMetaObject::Export> FakeMetaObject::exports() const
{ return m_exports; }
FakeMetaObject::Export FakeMetaObject::exportInPackage(const QString &package) const
{
foreach (const Export &exp, m_exports) {
if (exp.package == package)
return exp;
}
return Export();
}
void FakeMetaObject::setSuperclassName(const QString &superclass)
{ m_superName = superclass; }
QString FakeMetaObject::superclassName() const
{ return m_superName; }
void FakeMetaObject::setSuperclass(ConstPtr superClass)
{ m_super = superClass; }
FakeMetaObject::ConstPtr FakeMetaObject::superClass() const
{ return m_super; }
void FakeMetaObject::addEnum(const FakeMetaEnum &fakeEnum)
{ m_enumNameToIndex.insert(fakeEnum.name(), m_enums.size()); m_enums.append(fakeEnum); }
int FakeMetaObject::enumeratorCount() const
......
......@@ -135,12 +135,13 @@ public:
QString type;
ComponentVersion version;
QString packageNameVersion;
bool isValid() const;
};
private:
QString m_className;
QList<Export> m_exports;
ConstPtr m_super;
QString m_superName;
QList<FakeMetaEnum> m_enums;
QHash<QString, int> m_enumNameToIndex;
......@@ -158,11 +159,10 @@ public:
void addExport(const QString &name, const QString &package, ComponentVersion version);
QList<Export> exports() const;
Export exportInPackage(const QString &package) const;
void setSuperclassName(const QString &superclass);
QString superclassName() const;
void setSuperclass(ConstPtr superClass);
ConstPtr superClass() const;
void addEnum(const FakeMetaEnum &fakeEnum);
int enumeratorCount() const;
......
This diff is collapsed.
......@@ -420,9 +420,11 @@ private:
private:
Engine *_engine;
const Value *_prototype;
QHash<QString, const Value *> _members;
QString _className;
protected:
const Value *_prototype;
};
class QMLJS_EXPORT PrototypeIterator
......@@ -443,6 +445,8 @@ private:
const Context *m_context;
};
// A ObjectValue based on a FakeMetaObject.
// May only have other QmlObjectValues as ancestors.
class QMLJS_EXPORT QmlObjectValue: public ObjectValue
{
public:
......@@ -454,10 +458,14 @@ public:
virtual void processMembers(MemberProcessor *processor) const;
const Value *propertyValue(const LanguageUtils::FakeMetaProperty &prop) const;
using ObjectValue::prototype;
const QmlObjectValue *prototype() const;
LanguageUtils::FakeMetaObject::ConstPtr metaObject() const;
QString packageName() const;
QString nameInPackage(const QString &packageName) const;
QString fullyQualifiedNameInPackage(const QString &packageName) const;
LanguageUtils::ComponentVersion version() const;
QString defaultPropertyName() const;
QString propertyType(const QString &propertyName) const;
bool isListProperty(const QString &name) const;
......@@ -591,9 +599,7 @@ public:
// parses the xml string and fills the newObjects map
static QString parseQmlTypeDescriptions(const QByteArray &xml,
QHash<QString, LanguageUtils::FakeMetaObject::Ptr> *newObjects);
private:
static void setSuperClasses(QHash<QString, LanguageUtils::FakeMetaObject::Ptr> *newObjects);
QHash<QString, LanguageUtils::FakeMetaObject::ConstPtr> *newObjects);
};
class QMLJS_EXPORT CppQmlTypes
......@@ -621,16 +627,11 @@ public:
LanguageUtils::ComponentVersion version) const;
private:
void makeObject(Engine *engine,
LanguageUtils::FakeMetaObject::ConstPtr metaObject,
const LanguageUtils::FakeMetaObject::Export &exp,
QList<LanguageUtils::FakeMetaObject::ConstPtr> *newObjects);
void setPrototypes(Engine *engine,
LanguageUtils::FakeMetaObject::ConstPtr metaObject,
const LanguageUtils::FakeMetaObject::Export &exp);
QmlObjectValue *getOrCreate(const QString &package, const QString &cppName,
LanguageUtils::FakeMetaObject::ConstPtr metaObject,
Engine *engine, bool *created);
QmlObjectValue *makeObject(Engine *engine,
LanguageUtils::FakeMetaObject::ConstPtr metaObject,
const LanguageUtils::FakeMetaObject::Export &exp);
void setPrototypes(QmlObjectValue *object);
QmlObjectValue *getOrCreate(const QString &package, const QString &cppName);
QHash<QString, QList<QmlObjectValue *> > _typesByPackage;
......
......@@ -27,7 +27,7 @@ TypeDescriptionReader::~TypeDescriptionReader()
{
}
bool TypeDescriptionReader::operator()(QHash<QString, FakeMetaObject::Ptr> *objects)
bool TypeDescriptionReader::operator()(QHash<QString, FakeMetaObject::ConstPtr> *objects)
{
QString fileName("typeDescription");
Engine engine;
......
......@@ -30,7 +30,7 @@ public:
explicit TypeDescriptionReader(const QString &data);
~TypeDescriptionReader();
bool operator()(QHash<QString, LanguageUtils::FakeMetaObject::Ptr> *objects);
bool operator()(QHash<QString, LanguageUtils::FakeMetaObject::ConstPtr> *objects);
QString errorMessage() const;
private:
......@@ -50,7 +50,7 @@ private:
QString _source;
QString _errorMessage;
QHash<QString, LanguageUtils::FakeMetaObject::Ptr> *_objects;
QHash<QString, LanguageUtils::FakeMetaObject::ConstPtr> *_objects;
};
} // namespace QmlJS
......
......@@ -1551,7 +1551,6 @@ static void populate(LanguageUtils::FakeMetaObject::Ptr fmo, Class *klass,
baseFmo = FakeMetaObject::Ptr(new FakeMetaObject);
populate(baseFmo, baseClass, classes, typeOf);
}
fmo->setSuperclass(baseFmo);
}
}
......
......@@ -52,6 +52,7 @@
#include <qmljs/qmljsinterpreter.h>
#include <qmljs/qmljsbind.h>
#include <qmljs/parser/qmljsast_p.h>
#include <languageutils/fakemetaobject.h>
#include <private/qdeclarativemetatype_p.h>
#include <private/qdeclarativestringconverters_p.h>
......@@ -658,7 +659,9 @@ bool NodeMetaInfoPrivate::cleverCheckType(const QString &otherType) const
if (packageName() == package)
return QString(package + "/" + typeName) == qualfiedTypeName();
const QString convertedName = getQmlObjectValue()->nameInPackage(package);
const LanguageUtils::FakeMetaObject::Export exp =
getQmlObjectValue()->metaObject()->exportInPackage(package);
const QString convertedName = exp.type;
return QString(package + "/" + typeName) == QString(package + "/" + convertedName);
}
......
......@@ -139,16 +139,11 @@ static QString qmldumpFailedMessage(const QString &error)
static QList<FakeMetaObject::ConstPtr> parseHelper(const QByteArray &qmlTypeDescriptions, QString *error)
{
QList<FakeMetaObject::ConstPtr> ret;
QHash<QString, FakeMetaObject::Ptr> newObjects;
QHash<QString, FakeMetaObject::ConstPtr> newObjects;
*error = Interpreter::CppQmlTypesLoader::parseQmlTypeDescriptions(qmlTypeDescriptions, &newObjects);
if (error->isEmpty()) {
// convert from QList<T *> to QList<const T *>
QHashIterator<QString, FakeMetaObject::Ptr> it(newObjects);
while (it.hasNext()) {
it.next();
ret.append(it.value());
}
ret = newObjects.values();
}
return ret;
}
......
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