summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativecompiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml/qdeclarativecompiler.cpp')
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp77
1 files changed, 33 insertions, 44 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index f044e1a..5bfe5b2 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -41,7 +41,6 @@
#include "private/qdeclarativecompiler_p.h"
-#include "private/qdeclarativecompositetypedata_p.h"
#include "private/qdeclarativeparser_p.h"
#include "private/qdeclarativescriptparser_p.h"
#include "qdeclarativepropertyvaluesource.h"
@@ -562,7 +561,7 @@ void QDeclarativeCompiler::reset(QDeclarativeCompiledData *data)
on a successful compiler.
*/
bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine,
- QDeclarativeCompositeTypeData *unit,
+ QDeclarativeTypeData *unit,
QDeclarativeCompiledData *out)
{
exceptions.clear();
@@ -573,10 +572,15 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine,
output = out;
// Compile types
- for (int ii = 0; ii < unit->types.count(); ++ii) {
- QDeclarativeCompositeTypeData::TypeReference &tref = unit->types[ii];
+ const QList<QDeclarativeTypeData::TypeReference> &resolvedTypes = unit->resolvedTypes();
+ QList<QDeclarativeScriptParser::TypeReference *> referencedTypes = unit->parser().referencedTypes();
+
+ for (int ii = 0; ii < resolvedTypes.count(); ++ii) {
QDeclarativeCompiledData::TypeReference ref;
- QDeclarativeScriptParser::TypeReference *parserRef = unit->data.referencedTypes().at(ii);
+
+ const QDeclarativeTypeData::TypeReference &tref = resolvedTypes.at(ii);
+ QDeclarativeScriptParser::TypeReference *parserRef = referencedTypes.at(ii);
+
if (tref.type) {
ref.type = tref.type;
if (!ref.type->isCreatable()) {
@@ -585,33 +589,16 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine,
err = tr( "Element is not creatable.");
COMPILE_EXCEPTION(parserRef->refObjects.first(), err);
}
- } else if (tref.unit) {
- ref.component = tref.unit->toComponent(engine);
-
- if (ref.component->isError()) {
- QDeclarativeError error;
- error.setUrl(output->url);
- error.setDescription(QLatin1String("Unable to create type ") +
- parserRef->name);
- if (!parserRef->refObjects.isEmpty()) {
- QDeclarativeParser::Object *parserObject = parserRef->refObjects.first();
- error.setLine(parserObject->location.start.line);
- error.setColumn(parserObject->location.start.column);
- }
-
- exceptions << error;
- exceptions << ref.component->errors();
- reset(out);
- return false;
- }
- ref.ref = tref.unit;
+ } else if (tref.typeData) {
+ ref.component = tref.typeData->component();
+ ref.ref = tref.typeData;
ref.ref->addref();
}
ref.className = parserRef->name.toUtf8();
out->types << ref;
}
- Object *root = unit->data.tree();
+ Object *root = unit->parser().tree();
Q_ASSERT(root);
this->engine = engine;
@@ -664,17 +651,17 @@ void QDeclarativeCompiler::compileTree(Object *tree)
QHash<QString, Object::ScriptBlock> importedScripts;
QStringList importedScriptIndexes;
- for (int ii = 0; ii < unit->scripts.count(); ++ii) {
- QString scriptCode = QString::fromUtf8(unit->scripts.at(ii).resource->data);
- Object::ScriptBlock::Pragmas pragmas = QDeclarativeScriptParser::extractPragmas(scriptCode);
+ foreach (const QDeclarativeTypeData::ScriptReference &script, unit->resolvedScripts()) {
+ QString scriptCode = script.script->scriptSource();
+ Object::ScriptBlock::Pragmas pragmas = script.script->pragmas();
- Q_ASSERT(!importedScripts.contains(unit->scripts.at(ii).qualifier));
+ Q_ASSERT(!importedScripts.contains(script.qualifier));
if (!scriptCode.isEmpty()) {
- Object::ScriptBlock &scriptBlock = importedScripts[unit->scripts.at(ii).qualifier];
+ Object::ScriptBlock &scriptBlock = importedScripts[script.qualifier];
scriptBlock.code = scriptCode;
- scriptBlock.file = unit->scripts.at(ii).resource->url;
+ scriptBlock.file = script.script->finalUrl().toString();
scriptBlock.pragmas = pragmas;
}
}
@@ -704,7 +691,7 @@ void QDeclarativeCompiler::compileTree(Object *tree)
for (int ii = 0; ii < importedScriptIndexes.count(); ++ii)
output->importCache->add(importedScriptIndexes.at(ii), ii);
- unit->imports.populateCache(output->importCache, engine);
+ unit->imports().populateCache(output->importCache, engine);
Q_ASSERT(tree->metatype);
@@ -987,7 +974,7 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj)
}
// Begin the class
- if (obj->parserStatusCast != -1) {
+ if (tr.type && obj->parserStatusCast != -1) {
QDeclarativeInstruction begin;
begin.type = QDeclarativeInstruction::BeginObject;
begin.begin.castValue = obj->parserStatusCast;
@@ -1404,7 +1391,7 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
QDeclarativeType *type = 0;
QDeclarativeImportedNamespace *typeNamespace = 0;
- unit->imports.resolveType(prop->name, &type, 0, 0, 0, &typeNamespace);
+ unit->imports().resolveType(prop->name, &type, 0, 0, 0, &typeNamespace);
if (typeNamespace) {
// ### We might need to indicate that this property is a namespace
@@ -1512,7 +1499,7 @@ bool QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeImportedNamespac
// Setup attached property data
QDeclarativeType *type = 0;
- unit->imports.resolveType(ns, prop->name, &type, 0, 0, 0);
+ unit->imports().resolveType(ns, prop->name, &type, 0, 0, 0);
if (!type || !type->attachedPropertiesType())
COMPILE_EXCEPTION(prop, tr("Non-existent attached object"));
@@ -2139,7 +2126,7 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop
QString typeName = parts.at(0);
QDeclarativeType *type = 0;
- unit->imports.resolveType(typeName.toUtf8(), &type, 0, 0, 0, 0);
+ unit->imports().resolveType(typeName.toUtf8(), &type, 0, 0, 0, 0);
if (!type || obj->typeName != type->qmlTypeName())
return true;
@@ -2166,7 +2153,7 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const
int dot = script.indexOf('.');
if (dot > 0) {
QDeclarativeType *type = 0;
- unit->imports.resolveType(script.left(dot), &type, 0, 0, 0, 0);
+ unit->imports().resolveType(script.left(dot), &type, 0, 0, 0, 0);
if (!type)
return -1;
const QMetaObject *mo = type->metaObject();
@@ -2184,7 +2171,7 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const
const QMetaObject *QDeclarativeCompiler::resolveType(const QByteArray& name) const
{
QDeclarativeType *qmltype = 0;
- if (!unit->imports.resolveType(name, &qmltype, 0, 0, 0, 0))
+ if (!unit->imports().resolveType(name, &qmltype, 0, 0, 0, 0))
return 0;
if (!qmltype)
return 0;
@@ -2342,16 +2329,18 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
QByteArray customTypeName;
QDeclarativeType *qmltype = 0;
QUrl url;
- if (!unit->imports.resolveType(p.customType, &qmltype, &url, 0, 0, 0))
+ if (!unit->imports().resolveType(p.customType, &qmltype, &url, 0, 0, 0))
COMPILE_EXCEPTION(&p, tr("Invalid property type"));
if (!qmltype) {
- QDeclarativeCompositeTypeData *tdata = enginePrivate->typeManager.get(url);
+ QDeclarativeTypeData *tdata = enginePrivate->typeLoader.get(url);
Q_ASSERT(tdata);
- Q_ASSERT(tdata->status == QDeclarativeCompositeTypeData::Complete);
+ Q_ASSERT(tdata->isComplete());
- QDeclarativeCompiledData *data = tdata->toCompiledComponent(engine);
+ QDeclarativeCompiledData *data = tdata->compiledData();
customTypeName = data->root->className();
+ data->release();
+ tdata->release();
} else {
customTypeName = qmltype->typeName();
}
@@ -2746,7 +2735,7 @@ bool QDeclarativeCompiler::completeComponentBuild()
expr.context = binding.bindingContext.object;
expr.property = binding.property;
expr.expression = binding.expression;
- expr.imports = unit->imports;
+ expr.imports = unit->imports();
int index = bindingCompiler.compile(expr, enginePrivate);
if (index != -1) {