compiledData->scripts << scriptData;
}
+ // Resolve component boundaries and aliases
+
+ {
+ // Scan for components, determine their scopes and resolve aliases within the scope.
+ QQmlComponentAndAliasResolver resolver(compiledData->url, parsedQML->jsGenerator.strings, parsedQML->objects, parsedQML->indexOfRootObject, compiledData->resolvedTypes, compiledData->propertyCaches,
+ &compiledData->datas, &compiledData->objectIndexToIdForRoot, &compiledData->objectIndexToIdPerComponent);
+ if (!resolver.resolve()) {
+ errors << resolver.errors;
+ return false;
+ }
+ }
+
// Compile JS binding expressions and signal handlers
JSCodeGen jsCodeGen(typeData->finalUrlString(), parsedQML->code, &parsedQML->jsModule, &parsedQML->jsParserEngine, parsedQML->program, compiledData->importCache);
compiledData->compilationUnit->ref();
compiledData->qmlUnit = qmlUnit; // ownership transferred to m_compiledData
- // Resolve component boundaries and aliases
-
- {
- // Scan for components, determine their scopes and resolve aliases within the scope.
- QQmlComponentAndAliasResolver resolver(compiledData->url, compiledData->qmlUnit, compiledData->resolvedTypes, compiledData->propertyCaches,
- &compiledData->datas, &compiledData->objectIndexToIdForRoot, &compiledData->objectIndexToIdPerComponent);
- if (!resolver.resolve()) {
- errors << resolver.errors;
- return false;
- }
- }
-
// Add to type registry of composites
if (compiledData->isCompositeType())
engine->registerInternalCompositeType(compiledData);
QQmlCompilePass::QQmlCompilePass(const QUrl &url, const QV4::CompiledData::QmlUnit *unit)
: url(url)
- , qmlUnit(unit)
+ , jsUnit(&unit->header)
{
}
QQmlCompilePass::QQmlCompilePass(const QUrl &url, const QStringList &stringTable)
: url(url)
- , qmlUnit(0)
+ , jsUnit(0)
, stringTable(stringTable)
{
: QQmlCompilePass(compiledData->url, compiledData->qmlUnit)
, componentAttached(0)
, engine(parentContext->engine)
+ , qmlUnit(compiledData->qmlUnit)
, jsUnit(compiledData->compilationUnit)
, parentContext(parentContext)
, context(0)
}
-QQmlComponentAndAliasResolver::QQmlComponentAndAliasResolver(const QUrl &url, const QV4::CompiledData::QmlUnit *qmlUnit,
+QQmlComponentAndAliasResolver::QQmlComponentAndAliasResolver(const QUrl &url, const QStringList &stringTable, const QList<QmlObject *> &qmlObjects, int indexOfRootObject,
const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes,
const QList<QQmlPropertyCache *> &propertyCaches, QList<QByteArray> *vmeMetaObjectData,
QHash<int, int> *objectIndexToIdForRoot,
QHash<int, QHash<int, int> > *objectIndexToIdPerComponent)
- : QQmlCompilePass(url, qmlUnit)
+ : QQmlCompilePass(url, stringTable)
+ , qmlObjects(qmlObjects)
+ , indexOfRootObject(indexOfRootObject)
, _componentIndex(-1)
, _objectIndexToIdInScope(0)
, resolvedTypes(resolvedTypes)
// when someProperty _is_ a QQmlComponent. In that case the Item {}
// should be implicitly surrounded by Component {}
- for (quint32 i = 0; i < qmlUnit->nObjects; ++i) {
- const QV4::CompiledData::Object *obj = qmlUnit->objectAt(i);
+ for (int i = 0; i < qmlObjects.count(); ++i) {
+ const QtQml::QmlObject *obj = qmlObjects.at(i);
if (stringAt(obj->inheritedTypeNameIndex).isEmpty())
continue;
componentRoots.append(i);
- if (obj->nFunctions > 0)
+ if (obj->functions->count > 0)
COMPILE_EXCEPTION(obj, tr("Component objects cannot declare new functions."));
- if (obj->nProperties > 0)
+ if (obj->properties->count > 0)
COMPILE_EXCEPTION(obj, tr("Component objects cannot declare new properties."));
- if (obj->nSignals > 0)
+ if (obj->qmlSignals->count > 0)
COMPILE_EXCEPTION(obj, tr("Component objects cannot declare new signals."));
- if (obj->nBindings == 0)
+ if (obj->bindings->count == 0)
COMPILE_EXCEPTION(obj, tr("Cannot create empty component specification"));
- const QV4::CompiledData::Binding *rootBinding = obj->bindingTable();
- if (obj->nBindings > 1 || rootBinding->type != QV4::CompiledData::Binding::Type_Object)
+ const QtQml::Binding *rootBinding = obj->bindings->first;
+ if (rootBinding->next || rootBinding->type != QV4::CompiledData::Binding::Type_Object)
COMPILE_EXCEPTION(rootBinding, tr("Component elements may not contain properties other than id"));
componentBoundaries.append(rootBinding->value.objectIndex);
std::sort(componentBoundaries.begin(), componentBoundaries.end());
for (int i = 0; i < componentRoots.count(); ++i) {
- const QV4::CompiledData::Object *component = qmlUnit->objectAt(componentRoots.at(i));
- const QV4::CompiledData::Binding *rootBinding = component->bindingTable();
+ const QtQml::QmlObject *component = qmlObjects.at(componentRoots.at(i));
+ const QtQml::Binding *rootBinding = component->bindings->first;
_componentIndex = i;
_idToObjectIndex.clear();
_objectIndexToIdInScope = objectIndexToIdForRoot;
_objectsWithAliases.clear();
- collectIdsAndAliases(qmlUnit->indexOfRootObject);
+ collectIdsAndAliases(indexOfRootObject);
resolveAliases();
bool QQmlComponentAndAliasResolver::collectIdsAndAliases(int objectIndex)
{
- const QV4::CompiledData::Object *obj = qmlUnit->objectAt(objectIndex);
+ const QtQml::QmlObject *obj = qmlObjects.at(objectIndex);
QString id = stringAt(obj->idIndex);
if (!id.isEmpty()) {
_objectIndexToIdInScope->insert(objectIndex, _objectIndexToIdInScope->count());
}
- const QV4::CompiledData::Property *property = obj->propertyTable();
- for (quint32 i = 0; i < obj->nProperties; ++i, ++property)
+ for (QtQml::QmlProperty *property = obj->properties->first; property; property = property->next) {
if (property->type == QV4::CompiledData::Property::Alias) {
_objectsWithAliases.append(objectIndex);
break;
}
+ }
- const QV4::CompiledData::Binding *binding = obj->bindingTable();
- for (quint32 i = 0; i < obj->nBindings; ++i, ++binding) {
+ for (QtQml::Binding *binding = obj->bindings->first; binding; binding = binding->next) {
if (binding->type != QV4::CompiledData::Binding::Type_Object
&& binding->type != QV4::CompiledData::Binding::Type_AttachedProperty
&& binding->type != QV4::CompiledData::Binding::Type_GroupProperty)
bool QQmlComponentAndAliasResolver::resolveAliases()
{
foreach (int objectIndex, _objectsWithAliases) {
- const QV4::CompiledData::Object *obj = qmlUnit->objectAt(objectIndex);
+ const QtQml::QmlObject *obj = qmlObjects.at(objectIndex);
QQmlPropertyCache *propertyCache = propertyCaches.value(objectIndex);
Q_ASSERT(propertyCache);
int effectivePropertyIndex = propertyCache->propertyIndexCacheStart + propertyCache->propertyIndexCache.count();
int effectiveAliasIndex = 0;
- const QV4::CompiledData::Property *p = obj->propertyTable();
- for (quint32 propertyIndex = 0; propertyIndex < obj->nProperties; ++propertyIndex, ++p) {
+ const QtQml::QmlProperty *p = obj->properties->first;
+ for (int propertyIndex = 0; propertyIndex < obj->properties->count; ++propertyIndex, p = p->next) {
if (p->type != QV4::CompiledData::Property::Alias)
continue;
quint32 propertyFlags = QQmlPropertyData::IsAlias;
if (property.isEmpty()) {
- const QV4::CompiledData::Object *targetObject = qmlUnit->objectAt(targetObjectIndex);
+ const QtQml::QmlObject *targetObject = qmlObjects.at(targetObjectIndex);
QQmlCompiledData::TypeReference typeRef = resolvedTypes.value(targetObject->inheritedTypeNameIndex);
if (typeRef.type)
const QList<QQmlPropertyCache *> &propertyCaches, const QHash<int, QHash<int, int> > &objectIndexToIdPerComponent,
QHash<int, QByteArray> *customParserData)
: QQmlCompilePass(url, qmlUnit)
+ , qmlUnit(qmlUnit)
, resolvedTypes(resolvedTypes)
, propertyCaches(propertyCaches)
, objectIndexToIdPerComponent(objectIndexToIdPerComponent)
QQmlCompilePass(const QUrl &url, const QStringList &stringTable);
QList<QQmlError> errors;
- QString stringAt(int idx) const { return qmlUnit ? qmlUnit->header.stringAt(idx): stringTable.at(idx); }
+ QString stringAt(int idx) const { return jsUnit ? jsUnit->stringAt(idx): stringTable.at(idx); }
protected:
void recordError(const QV4::CompiledData::Location &location, const QString &description);
const QUrl url;
- const QV4::CompiledData::QmlUnit *qmlUnit;
+ const QV4::CompiledData::Unit *jsUnit;
const QStringList stringTable;
};
{
Q_DECLARE_TR_FUNCTIONS(QQmlAnonymousComponentResolver)
public:
- QQmlComponentAndAliasResolver(const QUrl &url, const QV4::CompiledData::QmlUnit *qmlUnit,
- const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes,
- const QList<QQmlPropertyCache *> &propertyCaches,
- QList<QByteArray> *vmeMetaObjectData,
- QHash<int, int> *objectIndexToIdForRoot,
- QHash<int, QHash<int, int> > *objectIndexToIdPerComponent);
+ QQmlComponentAndAliasResolver(const QUrl &url, const QStringList &stringTable,
+ const QList<QtQml::QmlObject*> &qmlObjects,
+ int indexOfRootObject,
+ const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes,
+ const QList<QQmlPropertyCache *> &propertyCaches,
+ QList<QByteArray> *vmeMetaObjectData,
+ QHash<int, int> *objectIndexToIdForRoot,
+ QHash<int, QHash<int, int> > *objectIndexToIdPerComponent);
bool resolve();
bool isComponentType(int typeNameIndex) const
{ return resolvedTypes.value(typeNameIndex).type == 0; }
+ const QList<QtQml::QmlObject*> &qmlObjects;
+ const int indexOfRootObject;
+
// indices of objects that are of type QQmlComponent
QVector<int> componentBoundaries;
bool isComponent(int objectIndex) const { return objectIndexToIdPerComponent.contains(objectIndex); }
+ const QV4::CompiledData::QmlUnit *qmlUnit;
const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes;
const QList<QQmlPropertyCache *> &propertyCaches;
const QHash<int, QHash<int, int> > objectIndexToIdPerComponent;
void setupFunctions();
QQmlEngine *engine;
+ const QV4::CompiledData::QmlUnit *qmlUnit;
const QV4::CompiledData::CompilationUnit *jsUnit;
QQmlContextData *parentContext;
QQmlContextData *context;