forked from qt-creator/qt-creator
QmlJS: Add refcounting to FakeMetaObjects.
Previously they were leaked when a qmldump or the C++ exported QML type list updated. Just deleting the previous FakeMetaObjects is not an option, as they might still be used in a QmlObjectValue owned by an Engine. Reviewed-by: Erik Verbruggen
This commit is contained in:
@@ -147,7 +147,7 @@ public:
|
|||||||
|
|
||||||
virtual void findMacroUsages(const CPlusPlus::Macro ¯o) = 0;
|
virtual void findMacroUsages(const CPlusPlus::Macro ¯o) = 0;
|
||||||
|
|
||||||
virtual QList<LanguageUtils::FakeMetaObject *> exportedQmlObjects() const = 0;
|
virtual QList<LanguageUtils::FakeMetaObject::ConstPtr> exportedQmlObjects() const = 0;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void documentUpdated(CPlusPlus::Document::Ptr doc);
|
void documentUpdated(CPlusPlus::Document::Ptr doc);
|
||||||
|
@@ -128,9 +128,9 @@ void FakeMetaObject::setSuperclassName(const QString &superclass)
|
|||||||
QString FakeMetaObject::superclassName() const
|
QString FakeMetaObject::superclassName() const
|
||||||
{ return m_superName; }
|
{ return m_superName; }
|
||||||
|
|
||||||
void FakeMetaObject::setSuperclass(FakeMetaObject *superClass)
|
void FakeMetaObject::setSuperclass(ConstPtr superClass)
|
||||||
{ m_super = superClass; }
|
{ m_super = superClass; }
|
||||||
const FakeMetaObject *FakeMetaObject::superClass() const
|
FakeMetaObject::ConstPtr FakeMetaObject::superClass() const
|
||||||
{ return m_super; }
|
{ return m_super; }
|
||||||
|
|
||||||
void FakeMetaObject::addEnum(const FakeMetaEnum &fakeEnum)
|
void FakeMetaObject::addEnum(const FakeMetaEnum &fakeEnum)
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtCore/QHash>
|
#include <QtCore/QHash>
|
||||||
|
#include <QtCore/QSharedPointer>
|
||||||
|
|
||||||
namespace LanguageUtils {
|
namespace LanguageUtils {
|
||||||
|
|
||||||
@@ -118,6 +119,9 @@ class LANGUAGEUTILS_EXPORT FakeMetaObject {
|
|||||||
Q_DISABLE_COPY(FakeMetaObject);
|
Q_DISABLE_COPY(FakeMetaObject);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef QSharedPointer<FakeMetaObject> Ptr;
|
||||||
|
typedef QSharedPointer<const FakeMetaObject> ConstPtr;
|
||||||
|
|
||||||
class Export {
|
class Export {
|
||||||
public:
|
public:
|
||||||
QString package;
|
QString package;
|
||||||
@@ -128,7 +132,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Export> m_exports;
|
QList<Export> m_exports;
|
||||||
const FakeMetaObject *m_super;
|
ConstPtr m_super;
|
||||||
QString m_superName;
|
QString m_superName;
|
||||||
QList<FakeMetaEnum> m_enums;
|
QList<FakeMetaEnum> m_enums;
|
||||||
QHash<QString, int> m_enumNameToIndex;
|
QHash<QString, int> m_enumNameToIndex;
|
||||||
@@ -145,8 +149,8 @@ public:
|
|||||||
|
|
||||||
void setSuperclassName(const QString &superclass);
|
void setSuperclassName(const QString &superclass);
|
||||||
QString superclassName() const;
|
QString superclassName() const;
|
||||||
void setSuperclass(FakeMetaObject *superClass);
|
void setSuperclass(ConstPtr superClass);
|
||||||
const FakeMetaObject *superClass() const;
|
ConstPtr superClass() const;
|
||||||
|
|
||||||
void addEnum(const FakeMetaEnum &fakeEnum);
|
void addEnum(const FakeMetaEnum &fakeEnum);
|
||||||
int enumeratorCount() const;
|
int enumeratorCount() const;
|
||||||
|
@@ -39,16 +39,14 @@
|
|||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
|
|
||||||
|
#include <languageutils/fakemetaobject.h>
|
||||||
|
|
||||||
#include "parser/qmldirparser_p.h"
|
#include "parser/qmldirparser_p.h"
|
||||||
#include "parser/qmljsengine_p.h"
|
#include "parser/qmljsengine_p.h"
|
||||||
#include "qmljs_global.h"
|
#include "qmljs_global.h"
|
||||||
|
|
||||||
QT_QML_BEGIN_NAMESPACE
|
QT_QML_BEGIN_NAMESPACE
|
||||||
|
|
||||||
namespace LanguageUtils {
|
|
||||||
class FakeMetaObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace QmlJS {
|
namespace QmlJS {
|
||||||
|
|
||||||
class Bind;
|
class Bind;
|
||||||
@@ -134,7 +132,7 @@ private:
|
|||||||
bool _valid;
|
bool _valid;
|
||||||
QList<QmlDirParser::Component> _components;
|
QList<QmlDirParser::Component> _components;
|
||||||
QList<QmlDirParser::Plugin> _plugins;
|
QList<QmlDirParser::Plugin> _plugins;
|
||||||
typedef QList<const LanguageUtils::FakeMetaObject *> FakeMetaObjectList;
|
typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
|
||||||
FakeMetaObjectList _metaObjects;
|
FakeMetaObjectList _metaObjects;
|
||||||
|
|
||||||
DumpStatus _dumpStatus;
|
DumpStatus _dumpStatus;
|
||||||
|
@@ -164,7 +164,7 @@ public:
|
|||||||
: _xml(data)
|
: _xml(data)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool operator()(QMap<QString, FakeMetaObject *> *objects) {
|
bool operator()(QMap<QString, FakeMetaObject::Ptr> *objects) {
|
||||||
Q_ASSERT(objects);
|
Q_ASSERT(objects);
|
||||||
_objects = objects;
|
_objects = objects;
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeMetaObject *metaObject = new FakeMetaObject;
|
FakeMetaObject::Ptr metaObject = FakeMetaObject::Ptr(new FakeMetaObject);
|
||||||
if (! extends.isEmpty())
|
if (! extends.isEmpty())
|
||||||
metaObject->setSuperclassName(extends);
|
metaObject->setSuperclassName(extends);
|
||||||
if (! defaultPropertyName.isEmpty())
|
if (! defaultPropertyName.isEmpty())
|
||||||
@@ -270,11 +270,8 @@ private:
|
|||||||
|
|
||||||
metaObject->addExport(id, QString(), ComponentVersion());
|
metaObject->addExport(id, QString(), ComponentVersion());
|
||||||
|
|
||||||
if (doInsert) {
|
if (doInsert)
|
||||||
_objects->insert(id, metaObject);
|
_objects->insert(id, metaObject);
|
||||||
} else {
|
|
||||||
delete metaObject;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool split(const QString &name, QString *packageName, QString *className) {
|
bool split(const QString &name, QString *packageName, QString *className) {
|
||||||
@@ -294,7 +291,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readProperty(FakeMetaObject *metaObject)
|
void readProperty(FakeMetaObject::Ptr metaObject)
|
||||||
{
|
{
|
||||||
const QLatin1String tag("property");
|
const QLatin1String tag("property");
|
||||||
Q_ASSERT(_xml.isStartElement() && _xml.name() == tag);
|
Q_ASSERT(_xml.isStartElement() && _xml.name() == tag);
|
||||||
@@ -352,14 +349,14 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void createProperty(FakeMetaObject *metaObject, const QString &name,
|
void createProperty(FakeMetaObject::Ptr metaObject, const QString &name,
|
||||||
const QString &type, bool isList, bool isWritable, bool isPointer) {
|
const QString &type, bool isList, bool isWritable, bool isPointer) {
|
||||||
Q_ASSERT(metaObject);
|
Q_ASSERT(metaObject);
|
||||||
|
|
||||||
metaObject->addProperty(FakeMetaProperty(name, type, isList, isWritable, isPointer));
|
metaObject->addProperty(FakeMetaProperty(name, type, isList, isWritable, isPointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void readEnum(FakeMetaObject *metaObject)
|
void readEnum(FakeMetaObject::Ptr metaObject)
|
||||||
{
|
{
|
||||||
Q_ASSERT(metaObject);
|
Q_ASSERT(metaObject);
|
||||||
|
|
||||||
@@ -426,7 +423,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readSignal(FakeMetaObject *metaObject)
|
void readSignal(FakeMetaObject::Ptr metaObject)
|
||||||
{
|
{
|
||||||
Q_ASSERT(metaObject);
|
Q_ASSERT(metaObject);
|
||||||
QLatin1String tag("signal");
|
QLatin1String tag("signal");
|
||||||
@@ -489,7 +486,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readMethod(FakeMetaObject *metaObject)
|
void readMethod(FakeMetaObject::Ptr metaObject)
|
||||||
{
|
{
|
||||||
Q_ASSERT(metaObject);
|
Q_ASSERT(metaObject);
|
||||||
QLatin1String tag("method");
|
QLatin1String tag("method");
|
||||||
@@ -526,7 +523,7 @@ private:
|
|||||||
metaObject->addMethod(method);
|
metaObject->addMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
void readExports(FakeMetaObject *metaObject)
|
void readExports(FakeMetaObject::Ptr metaObject)
|
||||||
{
|
{
|
||||||
Q_ASSERT(metaObject);
|
Q_ASSERT(metaObject);
|
||||||
QLatin1String tag("exports");
|
QLatin1String tag("exports");
|
||||||
@@ -582,12 +579,12 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QXmlStreamReader _xml;
|
QXmlStreamReader _xml;
|
||||||
QMap<QString, FakeMetaObject *> *_objects;
|
QMap<QString, FakeMetaObject::Ptr> *_objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
|
||||||
QmlObjectValue::QmlObjectValue(const FakeMetaObject *metaObject, const QString &className,
|
QmlObjectValue::QmlObjectValue(FakeMetaObject::ConstPtr metaObject, const QString &className,
|
||||||
const QString &packageName, const ComponentVersion version, Engine *engine)
|
const QString &packageName, const ComponentVersion version, Engine *engine)
|
||||||
: ObjectValue(engine),
|
: ObjectValue(engine),
|
||||||
_metaObject(metaObject),
|
_metaObject(metaObject),
|
||||||
@@ -734,7 +731,7 @@ QString QmlObjectValue::defaultPropertyName() const
|
|||||||
|
|
||||||
QString QmlObjectValue::propertyType(const QString &propertyName) const
|
QString QmlObjectValue::propertyType(const QString &propertyName) const
|
||||||
{
|
{
|
||||||
for (const FakeMetaObject *iter = _metaObject; iter; iter = iter->superClass()) {
|
for (FakeMetaObject::ConstPtr iter = _metaObject; iter; iter = iter->superClass()) {
|
||||||
int propIdx = iter->propertyIndex(propertyName);
|
int propIdx = iter->propertyIndex(propertyName);
|
||||||
if (propIdx != -1) {
|
if (propIdx != -1) {
|
||||||
return iter->property(propIdx).typeName();
|
return iter->property(propIdx).typeName();
|
||||||
@@ -745,7 +742,7 @@ QString QmlObjectValue::propertyType(const QString &propertyName) const
|
|||||||
|
|
||||||
bool QmlObjectValue::isListProperty(const QString &propertyName) const
|
bool QmlObjectValue::isListProperty(const QString &propertyName) const
|
||||||
{
|
{
|
||||||
for (const FakeMetaObject *iter = _metaObject; iter; iter = iter->superClass()) {
|
for (FakeMetaObject::ConstPtr iter = _metaObject; iter; iter = iter->superClass()) {
|
||||||
int propIdx = iter->propertyIndex(propertyName);
|
int propIdx = iter->propertyIndex(propertyName);
|
||||||
if (propIdx != -1) {
|
if (propIdx != -1) {
|
||||||
return iter->property(propIdx).isList();
|
return iter->property(propIdx).isList();
|
||||||
@@ -761,7 +758,7 @@ bool QmlObjectValue::isEnum(const QString &typeName) const
|
|||||||
|
|
||||||
bool QmlObjectValue::isWritable(const QString &propertyName) const
|
bool QmlObjectValue::isWritable(const QString &propertyName) const
|
||||||
{
|
{
|
||||||
for (const FakeMetaObject *iter = _metaObject; iter; iter = iter->superClass()) {
|
for (FakeMetaObject::ConstPtr iter = _metaObject; iter; iter = iter->superClass()) {
|
||||||
int propIdx = iter->propertyIndex(propertyName);
|
int propIdx = iter->propertyIndex(propertyName);
|
||||||
if (propIdx != -1) {
|
if (propIdx != -1) {
|
||||||
return iter->property(propIdx).isWritable();
|
return iter->property(propIdx).isWritable();
|
||||||
@@ -772,7 +769,7 @@ bool QmlObjectValue::isWritable(const QString &propertyName) const
|
|||||||
|
|
||||||
bool QmlObjectValue::isPointer(const QString &propertyName) const
|
bool QmlObjectValue::isPointer(const QString &propertyName) const
|
||||||
{
|
{
|
||||||
for (const FakeMetaObject *iter = _metaObject; iter; iter = iter->superClass()) {
|
for (FakeMetaObject::ConstPtr iter = _metaObject; iter; iter = iter->superClass()) {
|
||||||
int propIdx = iter->propertyIndex(propertyName);
|
int propIdx = iter->propertyIndex(propertyName);
|
||||||
if (propIdx != -1) {
|
if (propIdx != -1) {
|
||||||
return iter->property(propIdx).isPointer();
|
return iter->property(propIdx).isPointer();
|
||||||
@@ -791,7 +788,7 @@ bool QmlObjectValue::hasLocalProperty(const QString &typeName) const
|
|||||||
|
|
||||||
bool QmlObjectValue::hasProperty(const QString &propertyName) const
|
bool QmlObjectValue::hasProperty(const QString &propertyName) const
|
||||||
{
|
{
|
||||||
for (const FakeMetaObject *iter = _metaObject; iter; iter = iter->superClass()) {
|
for (FakeMetaObject::ConstPtr iter = _metaObject; iter; iter = iter->superClass()) {
|
||||||
int propIdx = iter->propertyIndex(propertyName);
|
int propIdx = iter->propertyIndex(propertyName);
|
||||||
if (propIdx != -1) {
|
if (propIdx != -1) {
|
||||||
return true;
|
return true;
|
||||||
@@ -831,11 +828,11 @@ bool QmlObjectValue::hasChildInPackage() const
|
|||||||
QHashIterator<QString, QmlObjectValue *> it(engine()->cppQmlTypes().types());
|
QHashIterator<QString, QmlObjectValue *> it(engine()->cppQmlTypes().types());
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
const FakeMetaObject *other = it.value()->_metaObject;
|
FakeMetaObject::ConstPtr other = it.value()->_metaObject;
|
||||||
// if it has only the default no-package export, it is not really exported
|
// if it has only the default no-package export, it is not really exported
|
||||||
if (other->exports().size() <= 1)
|
if (other->exports().size() <= 1)
|
||||||
continue;
|
continue;
|
||||||
for (const FakeMetaObject *iter = other; iter; iter = iter->superClass()) {
|
for (FakeMetaObject::ConstPtr iter = other; iter; iter = iter->superClass()) {
|
||||||
if (iter == _metaObject) // this object is a parent of other
|
if (iter == _metaObject) // this object is a parent of other
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -843,9 +840,9 @@ bool QmlObjectValue::hasChildInPackage() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlObjectValue::isDerivedFrom(const FakeMetaObject *base) const
|
bool QmlObjectValue::isDerivedFrom(FakeMetaObject::ConstPtr base) const
|
||||||
{
|
{
|
||||||
for (const FakeMetaObject *iter = _metaObject; iter; iter = iter->superClass()) {
|
for (FakeMetaObject::ConstPtr iter = _metaObject; iter; iter = iter->superClass()) {
|
||||||
if (iter == base)
|
if (iter == base)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1946,12 +1943,12 @@ const Value *Function::invoke(const Activation *activation) const
|
|||||||
// typing environment
|
// typing environment
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
QList<const FakeMetaObject *> CppQmlTypesLoader::builtinObjects;
|
QList<FakeMetaObject::ConstPtr> CppQmlTypesLoader::builtinObjects;
|
||||||
QList<const FakeMetaObject *> CppQmlTypesLoader::cppObjects;
|
QList<FakeMetaObject::ConstPtr> CppQmlTypesLoader::cppObjects;
|
||||||
|
|
||||||
QStringList CppQmlTypesLoader::load(const QFileInfoList &xmlFiles)
|
QStringList CppQmlTypesLoader::load(const QFileInfoList &xmlFiles)
|
||||||
{
|
{
|
||||||
QMap<QString, FakeMetaObject *> newObjects;
|
QMap<QString, FakeMetaObject::Ptr> newObjects;
|
||||||
QStringList errorMsgs;
|
QStringList errorMsgs;
|
||||||
|
|
||||||
foreach (const QFileInfo &xmlFile, xmlFiles) {
|
foreach (const QFileInfo &xmlFile, xmlFiles) {
|
||||||
@@ -1973,7 +1970,7 @@ QStringList CppQmlTypesLoader::load(const QFileInfoList &xmlFiles)
|
|||||||
|
|
||||||
// we need to go from QList<T *> of newObjects.values() to QList<const T *>
|
// we need to go from QList<T *> of newObjects.values() to QList<const T *>
|
||||||
// and there seems to be no better way
|
// and there seems to be no better way
|
||||||
QMapIterator<QString, FakeMetaObject *> it(newObjects);
|
QMapIterator<QString, FakeMetaObject::Ptr> it(newObjects);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
builtinObjects.append(it.value());
|
builtinObjects.append(it.value());
|
||||||
@@ -1983,7 +1980,7 @@ QStringList CppQmlTypesLoader::load(const QFileInfoList &xmlFiles)
|
|||||||
return errorMsgs;
|
return errorMsgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CppQmlTypesLoader::parseQmlTypeXml(const QByteArray &xml, QMap<QString, FakeMetaObject *> *newObjects)
|
QString CppQmlTypesLoader::parseQmlTypeXml(const QByteArray &xml, QMap<QString, FakeMetaObject::Ptr> *newObjects)
|
||||||
{
|
{
|
||||||
QmlXmlReader reader(xml);
|
QmlXmlReader reader(xml);
|
||||||
if (!reader(newObjects)) {
|
if (!reader(newObjects)) {
|
||||||
@@ -1995,16 +1992,16 @@ QString CppQmlTypesLoader::parseQmlTypeXml(const QByteArray &xml, QMap<QString,
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppQmlTypesLoader::setSuperClasses(QMap<QString, FakeMetaObject *> *newObjects)
|
void CppQmlTypesLoader::setSuperClasses(QMap<QString, FakeMetaObject::Ptr> *newObjects)
|
||||||
{
|
{
|
||||||
QMapIterator<QString, FakeMetaObject *> it(*newObjects);
|
QMapIterator<QString, FakeMetaObject::Ptr> it(*newObjects);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
FakeMetaObject *obj = it.value();
|
FakeMetaObject::Ptr obj = it.value();
|
||||||
|
|
||||||
const QString superName = obj->superclassName();
|
const QString superName = obj->superclassName();
|
||||||
if (! superName.isEmpty()) {
|
if (! superName.isEmpty()) {
|
||||||
FakeMetaObject *superClass = newObjects->value(superName);
|
FakeMetaObject::Ptr superClass = newObjects->value(superName);
|
||||||
if (superClass)
|
if (superClass)
|
||||||
obj->setSuperclass(superClass);
|
obj->setSuperclass(superClass);
|
||||||
else
|
else
|
||||||
@@ -2013,10 +2010,10 @@ void CppQmlTypesLoader::setSuperClasses(QMap<QString, FakeMetaObject *> *newObje
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppQmlTypes::load(Engine *engine, const QList<const FakeMetaObject *> &objects)
|
void CppQmlTypes::load(Engine *engine, const QList<FakeMetaObject::ConstPtr> &objects)
|
||||||
{
|
{
|
||||||
// load
|
// load
|
||||||
foreach (const FakeMetaObject *metaObject, objects) {
|
foreach (FakeMetaObject::ConstPtr metaObject, objects) {
|
||||||
for (int i = 0; i < metaObject->exports().size(); ++i) {
|
for (int i = 0; i < metaObject->exports().size(); ++i) {
|
||||||
const FakeMetaObject::Export &exp = metaObject->exports().at(i);
|
const FakeMetaObject::Export &exp = metaObject->exports().at(i);
|
||||||
// make sure we're not loading duplicate objects
|
// make sure we're not loading duplicate objects
|
||||||
@@ -2031,7 +2028,7 @@ void CppQmlTypes::load(Engine *engine, const QList<const FakeMetaObject *> &obje
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set prototypes
|
// set prototypes
|
||||||
foreach (const FakeMetaObject *metaObject, objects) {
|
foreach (FakeMetaObject::ConstPtr metaObject, objects) {
|
||||||
foreach (const FakeMetaObject::Export &exp, metaObject->exports()) {
|
foreach (const FakeMetaObject::Export &exp, metaObject->exports()) {
|
||||||
QmlObjectValue *objectValue = _typesByFullyQualifiedName.value(exp.packageNameVersion);
|
QmlObjectValue *objectValue = _typesByFullyQualifiedName.value(exp.packageNameVersion);
|
||||||
if (!objectValue || !metaObject->superClass())
|
if (!objectValue || !metaObject->superClass())
|
||||||
@@ -2043,7 +2040,7 @@ void CppQmlTypes::load(Engine *engine, const QList<const FakeMetaObject *> &obje
|
|||||||
// needs to create Positioner (Qt) and Positioner (QtQuick)
|
// needs to create Positioner (Qt) and Positioner (QtQuick)
|
||||||
bool created = true;
|
bool created = true;
|
||||||
QmlObjectValue *v = objectValue;
|
QmlObjectValue *v = objectValue;
|
||||||
const FakeMetaObject *fmo = metaObject;
|
FakeMetaObject::ConstPtr fmo = metaObject;
|
||||||
while (created && fmo->superClass()) {
|
while (created && fmo->superClass()) {
|
||||||
QmlObjectValue *superValue = getOrCreate(exp.package, fmo->superclassName(),
|
QmlObjectValue *superValue = getOrCreate(exp.package, fmo->superclassName(),
|
||||||
fmo->superClass(), engine, &created);
|
fmo->superClass(), engine, &created);
|
||||||
@@ -2136,7 +2133,7 @@ QmlObjectValue *CppQmlTypes::typeByQualifiedName(const QString &package, const Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
QmlObjectValue *CppQmlTypes::getOrCreate(const QString &package, const QString &cppName,
|
QmlObjectValue *CppQmlTypes::getOrCreate(const QString &package, const QString &cppName,
|
||||||
const FakeMetaObject *metaObject, Engine *engine, bool *created)
|
FakeMetaObject::ConstPtr metaObject, Engine *engine, bool *created)
|
||||||
{
|
{
|
||||||
QString typeName = cppName;
|
QString typeName = cppName;
|
||||||
ComponentVersion version;
|
ComponentVersion version;
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#define QMLJS_INTERPRETER_H
|
#define QMLJS_INTERPRETER_H
|
||||||
|
|
||||||
#include <languageutils/componentversion.h>
|
#include <languageutils/componentversion.h>
|
||||||
|
#include <languageutils/fakemetaobject.h>
|
||||||
#include <qmljs/qmljsdocument.h>
|
#include <qmljs/qmljsdocument.h>
|
||||||
#include <qmljs/qmljs_global.h>
|
#include <qmljs/qmljs_global.h>
|
||||||
#include <qmljs/parser/qmljsastfwd_p.h>
|
#include <qmljs/parser/qmljsastfwd_p.h>
|
||||||
@@ -46,13 +47,6 @@
|
|||||||
#include <QtCore/QSet>
|
#include <QtCore/QSet>
|
||||||
#include <QtCore/QMutex>
|
#include <QtCore/QMutex>
|
||||||
|
|
||||||
namespace LanguageUtils {
|
|
||||||
class FakeMetaObject;
|
|
||||||
class FakeMetaMethod;
|
|
||||||
class FakeMetaProperty;
|
|
||||||
class FakeMetaEnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace QmlJS {
|
namespace QmlJS {
|
||||||
|
|
||||||
class NameId;
|
class NameId;
|
||||||
@@ -452,7 +446,7 @@ private:
|
|||||||
class QMLJS_EXPORT QmlObjectValue: public ObjectValue
|
class QMLJS_EXPORT QmlObjectValue: public ObjectValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QmlObjectValue(const LanguageUtils::FakeMetaObject *metaObject, const QString &className,
|
QmlObjectValue(LanguageUtils::FakeMetaObject::ConstPtr metaObject, const QString &className,
|
||||||
const QString &packageName, const LanguageUtils::ComponentVersion version,
|
const QString &packageName, const LanguageUtils::ComponentVersion version,
|
||||||
Engine *engine);
|
Engine *engine);
|
||||||
virtual ~QmlObjectValue();
|
virtual ~QmlObjectValue();
|
||||||
@@ -478,10 +472,10 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
const Value *findOrCreateSignature(int index, const LanguageUtils::FakeMetaMethod &method,
|
const Value *findOrCreateSignature(int index, const LanguageUtils::FakeMetaMethod &method,
|
||||||
QString *methodName) const;
|
QString *methodName) const;
|
||||||
bool isDerivedFrom(const LanguageUtils::FakeMetaObject *base) const;
|
bool isDerivedFrom(LanguageUtils::FakeMetaObject::ConstPtr base) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const LanguageUtils::FakeMetaObject *_metaObject;
|
LanguageUtils::FakeMetaObject::ConstPtr _metaObject;
|
||||||
const QString _packageName;
|
const QString _packageName;
|
||||||
const LanguageUtils::ComponentVersion _componentVersion;
|
const LanguageUtils::ComponentVersion _componentVersion;
|
||||||
mutable QHash<int, const Value *> _metaSignature;
|
mutable QHash<int, const Value *> _metaSignature;
|
||||||
@@ -592,20 +586,20 @@ class QMLJS_EXPORT CppQmlTypesLoader
|
|||||||
public:
|
public:
|
||||||
/** \return an empty list when successful, error messages otherwise. */
|
/** \return an empty list when successful, error messages otherwise. */
|
||||||
static QStringList load(const QFileInfoList &xmlFiles);
|
static QStringList load(const QFileInfoList &xmlFiles);
|
||||||
static QList<const LanguageUtils::FakeMetaObject *> builtinObjects;
|
static QList<LanguageUtils::FakeMetaObject::ConstPtr> builtinObjects;
|
||||||
static QList<const LanguageUtils::FakeMetaObject *> cppObjects;
|
static QList<LanguageUtils::FakeMetaObject::ConstPtr> cppObjects;
|
||||||
|
|
||||||
// parses the xml string and fills the newObjects map
|
// parses the xml string and fills the newObjects map
|
||||||
static QString parseQmlTypeXml(const QByteArray &xml,
|
static QString parseQmlTypeXml(const QByteArray &xml,
|
||||||
QMap<QString, LanguageUtils::FakeMetaObject *> *newObjects);
|
QMap<QString, LanguageUtils::FakeMetaObject::Ptr> *newObjects);
|
||||||
private:
|
private:
|
||||||
static void setSuperClasses(QMap<QString, LanguageUtils::FakeMetaObject *> *newObjects);
|
static void setSuperClasses(QMap<QString, LanguageUtils::FakeMetaObject::Ptr> *newObjects);
|
||||||
};
|
};
|
||||||
|
|
||||||
class QMLJS_EXPORT CppQmlTypes
|
class QMLJS_EXPORT CppQmlTypes
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void load(Interpreter::Engine *interpreter, const QList<const LanguageUtils::FakeMetaObject *> &objects);
|
void load(Interpreter::Engine *interpreter, const QList<LanguageUtils::FakeMetaObject::ConstPtr> &objects);
|
||||||
|
|
||||||
QList<Interpreter::QmlObjectValue *> typesForImport(const QString &prefix, LanguageUtils::ComponentVersion version) const;
|
QList<Interpreter::QmlObjectValue *> typesForImport(const QString &prefix, LanguageUtils::ComponentVersion version) const;
|
||||||
Interpreter::QmlObjectValue *typeForImport(const QString &qualifiedName,
|
Interpreter::QmlObjectValue *typeForImport(const QString &qualifiedName,
|
||||||
@@ -623,7 +617,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QmlObjectValue *getOrCreate(const QString &package, const QString &cppName,
|
QmlObjectValue *getOrCreate(const QString &package, const QString &cppName,
|
||||||
const LanguageUtils::FakeMetaObject *metaObject,
|
LanguageUtils::FakeMetaObject::ConstPtr metaObject,
|
||||||
Engine *engine, bool *created);
|
Engine *engine, bool *created);
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1459,8 +1459,8 @@ static Class *lookupClass(const QString &expression, Scope *scope, TypeOfExpress
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void populate(LanguageUtils::FakeMetaObject *fmo, Class *klass,
|
static void populate(LanguageUtils::FakeMetaObject::Ptr fmo, Class *klass,
|
||||||
QHash<Class *, LanguageUtils::FakeMetaObject *> *classes,
|
QHash<Class *, LanguageUtils::FakeMetaObject::Ptr> *classes,
|
||||||
TypeOfExpression &typeOf)
|
TypeOfExpression &typeOf)
|
||||||
{
|
{
|
||||||
using namespace LanguageUtils;
|
using namespace LanguageUtils;
|
||||||
@@ -1539,27 +1539,27 @@ static void populate(LanguageUtils::FakeMetaObject *fmo, Class *klass,
|
|||||||
if (!baseClass)
|
if (!baseClass)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FakeMetaObject *baseFmo = classes->value(baseClass);
|
FakeMetaObject::Ptr baseFmo = classes->value(baseClass);
|
||||||
if (!baseFmo) {
|
if (!baseFmo) {
|
||||||
baseFmo = new FakeMetaObject;
|
baseFmo = FakeMetaObject::Ptr(new FakeMetaObject);
|
||||||
populate(baseFmo, baseClass, classes, typeOf);
|
populate(baseFmo, baseClass, classes, typeOf);
|
||||||
}
|
}
|
||||||
fmo->setSuperclass(baseFmo);
|
fmo->setSuperclass(baseFmo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<LanguageUtils::FakeMetaObject *> CppModelManager::exportedQmlObjects() const
|
QList<LanguageUtils::FakeMetaObject::ConstPtr> CppModelManager::exportedQmlObjects() const
|
||||||
{
|
{
|
||||||
using namespace LanguageUtils;
|
using namespace LanguageUtils;
|
||||||
QList<FakeMetaObject *> exportedObjects;
|
QList<FakeMetaObject::ConstPtr> exportedObjects;
|
||||||
QHash<Class *, FakeMetaObject *> classes;
|
QHash<Class *, FakeMetaObject::Ptr> classes;
|
||||||
|
|
||||||
const Snapshot currentSnapshot = snapshot();
|
const Snapshot currentSnapshot = snapshot();
|
||||||
foreach (Document::Ptr doc, currentSnapshot) {
|
foreach (Document::Ptr doc, currentSnapshot) {
|
||||||
TypeOfExpression typeOf;
|
TypeOfExpression typeOf;
|
||||||
typeOf.init(doc, currentSnapshot);
|
typeOf.init(doc, currentSnapshot);
|
||||||
foreach (const Document::ExportedQmlType &exportedType, doc->exportedQmlTypes()) {
|
foreach (const Document::ExportedQmlType &exportedType, doc->exportedQmlTypes()) {
|
||||||
FakeMetaObject *fmo = new FakeMetaObject;
|
FakeMetaObject::Ptr fmo(new FakeMetaObject);
|
||||||
fmo->addExport(exportedType.typeName, exportedType.packageName,
|
fmo->addExport(exportedType.typeName, exportedType.packageName,
|
||||||
ComponentVersion(exportedType.majorVersion, exportedType.minorVersion));
|
ComponentVersion(exportedType.majorVersion, exportedType.minorVersion));
|
||||||
exportedObjects += fmo;
|
exportedObjects += fmo;
|
||||||
|
@@ -131,7 +131,7 @@ public:
|
|||||||
|
|
||||||
virtual void findMacroUsages(const CPlusPlus::Macro ¯o);
|
virtual void findMacroUsages(const CPlusPlus::Macro ¯o);
|
||||||
|
|
||||||
virtual QList<LanguageUtils::FakeMetaObject *> exportedQmlObjects() const;
|
virtual QList<LanguageUtils::FakeMetaObject::ConstPtr> exportedQmlObjects() const;
|
||||||
|
|
||||||
void setHeaderSuffixes(const QStringList &suffixes)
|
void setHeaderSuffixes(const QStringList &suffixes)
|
||||||
{ m_headerSuffixes = suffixes; }
|
{ m_headerSuffixes = suffixes; }
|
||||||
|
@@ -562,8 +562,5 @@ void ModelManager::updateCppQmlTypes()
|
|||||||
if (!cppModelManager)
|
if (!cppModelManager)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QList<const LanguageUtils::FakeMetaObject *> constFMOs;
|
Interpreter::CppQmlTypesLoader::cppObjects = cppModelManager->exportedQmlObjects();
|
||||||
foreach (LanguageUtils::FakeMetaObject *fmo, cppModelManager->exportedQmlObjects())
|
|
||||||
constFMOs.append(fmo);
|
|
||||||
Interpreter::CppQmlTypesLoader::cppObjects = constFMOs;
|
|
||||||
}
|
}
|
||||||
|
@@ -126,15 +126,15 @@ static QString qmldumpFailedMessage()
|
|||||||
return PluginDumper::tr("Type dump of C++ plugin failed.\nCheck 'General Messages' output pane for details.");
|
return PluginDumper::tr("Type dump of C++ plugin failed.\nCheck 'General Messages' output pane for details.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static QList<const FakeMetaObject *> parseHelper(const QByteArray &xml, QString *error)
|
static QList<FakeMetaObject::ConstPtr> parseHelper(const QByteArray &xml, QString *error)
|
||||||
{
|
{
|
||||||
QList<const FakeMetaObject *> ret;
|
QList<FakeMetaObject::ConstPtr> ret;
|
||||||
QMap<QString, FakeMetaObject *> newObjects;
|
QMap<QString, FakeMetaObject::Ptr> newObjects;
|
||||||
*error = Interpreter::CppQmlTypesLoader::parseQmlTypeXml(xml, &newObjects);
|
*error = Interpreter::CppQmlTypesLoader::parseQmlTypeXml(xml, &newObjects);
|
||||||
|
|
||||||
if (error->isEmpty()) {
|
if (error->isEmpty()) {
|
||||||
// convert from QList<T *> to QList<const T *>
|
// convert from QList<T *> to QList<const T *>
|
||||||
QMapIterator<QString, FakeMetaObject *> it(newObjects);
|
QMapIterator<QString, FakeMetaObject::Ptr> it(newObjects);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
ret.append(it.value());
|
ret.append(it.value());
|
||||||
@@ -162,7 +162,7 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode)
|
|||||||
|
|
||||||
const QByteArray output = process->readAllStandardOutput();
|
const QByteArray output = process->readAllStandardOutput();
|
||||||
QString error;
|
QString error;
|
||||||
QList<const FakeMetaObject *> objectsList = parseHelper(output, &error);
|
QList<FakeMetaObject::ConstPtr> objectsList = parseHelper(output, &error);
|
||||||
if (exitCode == 0 && !error.isEmpty()) {
|
if (exitCode == 0 && !error.isEmpty()) {
|
||||||
libraryInfo.setDumpStatus(LibraryInfo::DumpError, tr("Type dump of C++ plugin failed. Parse error:\n'%1'").arg(error));
|
libraryInfo.setDumpStatus(LibraryInfo::DumpError, tr("Type dump of C++ plugin failed. Parse error:\n'%1'").arg(error));
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ void PluginDumper::dump(const Plugin &plugin)
|
|||||||
libraryXmlFile.close();
|
libraryXmlFile.close();
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
const QList<const FakeMetaObject *> objectsList = parseHelper(xml, &error);
|
const QList<FakeMetaObject::ConstPtr> objectsList = parseHelper(xml, &error);
|
||||||
|
|
||||||
if (error.isEmpty()) {
|
if (error.isEmpty()) {
|
||||||
libraryInfo.setMetaObjects(objectsList);
|
libraryInfo.setMetaObjects(objectsList);
|
||||||
|
Reference in New Issue
Block a user