void QQmlCodeGenerator::collectTypeReferences()
{
foreach (QmlObject *obj, _objects) {
- if (!stringAt(obj->inheritedTypeNameIndex).isEmpty())
- _typeReferences.add(obj->inheritedTypeNameIndex, obj->location);
+ if (!stringAt(obj->inheritedTypeNameIndex).isEmpty()) {
+ QV4::CompiledData::TypeReference &r = _typeReferences.add(obj->inheritedTypeNameIndex, obj->location);
+ r.needsCreation = true;
+ }
for (QmlProperty *prop = obj->properties->first; prop; prop = prop->next) {
if (prop->type >= QV4::CompiledData::Property::Custom) {
// ### FIXME: We could report the more accurate location here by using prop->location, but the old
// compiler can't and the tests expect it to be the object location right now.
- _typeReferences.add(prop->customTypeNameIndex, obj->location);
+ QV4::CompiledData::TypeReference &r = _typeReferences.add(prop->customTypeNameIndex, obj->location);
+ r.needsCreation = true;
}
}
QScopedPointer<QQmlCompiledData::TypeReference> ref(new QQmlCompiledData::TypeReference);
QQmlType *qmlType = resolvedType->type;
if (resolvedType->typeData) {
- if (qmlType->isCompositeSingleton()) {
+ if (resolvedType->needsCreation && qmlType->isCompositeSingleton()) {
QQmlError error;
QString reason = tr("Composite Singleton Type %1 is not creatable.").arg(qmlType->qmlTypeName());
error.setDescription(reason);
ref->type = qmlType;
Q_ASSERT(ref->type);
- if (!ref->type->isCreatable()) {
+ if (resolvedType->needsCreation && !ref->type->isCreatable()) {
QQmlError error;
QString reason = ref->type->noCreationReason();
if (reason.isEmpty())
qint32 column;
};
+struct TypeReference
+{
+ TypeReference(const Location &loc)
+ : location(loc)
+ , needsCreation(false)
+ {}
+ Location location; // first use
+ bool needsCreation; // whether the type needs to be creatable or not
+};
+
// map from name index to location of first use
-struct TypeReferenceMap : QHash<int, Location>
+struct TypeReferenceMap : QHash<int, TypeReference>
{
- void add(int nameIndex, const Location &loc) {
- if (contains(nameIndex))
- return;
- insert(nameIndex, loc);
+ TypeReference &add(int nameIndex, const Location &loc) {
+ Iterator it = find(nameIndex);
+ if (it != end())
+ return *it;
+ return *insert(nameIndex, loc);
}
};
error.setDescription(QQmlTypeLoader::tr("%1 %2").arg(name).arg(error.description()));
}
- error.setLine(unresolvedRef->line);
- error.setColumn(unresolvedRef->column);
+ error.setLine(unresolvedRef->location.line);
+ error.setColumn(unresolvedRef->location.column);
errors.prepend(error);
setError(errors);
ref.majorVersion = majorVersion;
ref.minorVersion = minorVersion;
- ref.location.line = unresolvedRef->line;
- ref.location.column = unresolvedRef->column;
+ ref.location.line = unresolvedRef->location.line;
+ ref.location.column = unresolvedRef->location.column;
+
+ ref.needsCreation = unresolvedRef->needsCreation;
m_resolvedTypes.insert(unresolvedRef.key(), ref);
}
public:
struct TypeReference
{
- TypeReference() : type(0), majorVersion(0), minorVersion(0), typeData(0) {}
+ TypeReference() : type(0), majorVersion(0), minorVersion(0), typeData(0), needsCreation(true) {}
QQmlScript::Location location;
QQmlType *type;
int minorVersion;
QQmlTypeData *typeData;
QString prefix; // used by CompositeSingleton types
+ bool needsCreation;
};
struct ScriptReference