diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2009-08-21 11:15:28 (GMT) |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2009-08-21 11:22:34 (GMT) |
commit | bf04e19750502ea6346eb6eac08a6370b11dd0e3 (patch) | |
tree | dc3e097c6e82041438a90f1f429e6ecfae9efca1 /src/declarative | |
parent | 715056fe9939452c0223f5d8ff217bed3b8015de (diff) | |
download | Qt-bf04e19750502ea6346eb6eac08a6370b11dd0e3.zip Qt-bf04e19750502ea6346eb6eac08a6370b11dd0e3.tar.gz Qt-bf04e19750502ea6346eb6eac08a6370b11dd0e3.tar.bz2 |
Store location information for "Type XXX is not available" messages
QmlScriptParser now also stores the locations where a specific type
was referenced.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/qml/qmlcompiler.cpp | 11 | ||||
-rw-r--r-- | src/declarative/qml/qmlcompositetypedata_p.h | 2 | ||||
-rw-r--r-- | src/declarative/qml/qmlcompositetypemanager.cpp | 21 | ||||
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 34 | ||||
-rw-r--r-- | src/declarative/qml/qmlscriptparser_p.h | 18 |
5 files changed, 61 insertions, 25 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 1fb4b46..1771cb4 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -569,6 +569,7 @@ bool QmlCompiler::compile(QmlEngine *engine, for (int ii = 0; ii < unit->types.count(); ++ii) { QmlCompositeTypeData::TypeReference &tref = unit->types[ii]; QmlCompiledData::TypeReference ref; + QmlScriptParser::TypeReference *parserRef = unit->data.referencedTypes().at(ii); if (tref.type) ref.type = tref.type; else if (tref.unit) { @@ -578,7 +579,13 @@ bool QmlCompiler::compile(QmlEngine *engine, QmlError error; error.setUrl(output->url); error.setDescription(QLatin1String("Unable to create type ") + - unit->data.types().at(ii)); + parserRef->name); + if (!parserRef->refObjects.isEmpty()) { + QmlParser::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); @@ -587,7 +594,7 @@ bool QmlCompiler::compile(QmlEngine *engine, ref.ref = tref.unit; ref.ref->addref(); } - ref.className = unit->data.types().at(ii).toLatin1(); + ref.className = parserRef->name.toLatin1(); out->types << ref; } diff --git a/src/declarative/qml/qmlcompositetypedata_p.h b/src/declarative/qml/qmlcompositetypedata_p.h index 3469fea..54933c4 100644 --- a/src/declarative/qml/qmlcompositetypedata_p.h +++ b/src/declarative/qml/qmlcompositetypedata_p.h @@ -91,7 +91,7 @@ struct QmlCompositeTypeData : public QmlRefCount // occurs QmlCompiledData *toCompiledComponent(QmlEngine *); - struct TypeReference + struct TypeReference { TypeReference(); diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 97391e6..0fb6c86 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -311,21 +311,23 @@ void QmlCompositeTypeManager::checkComplete(QmlCompositeTypeData *unit) void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) { - QStringList typeNames = unit->data.types(); + QList<QmlScriptParser::TypeReference*> types = unit->data.referencedTypes(); int waiting = 0; - for (int ii = 0; ii < typeNames.count(); ++ii) { - QByteArray type = typeNames.at(ii).toLatin1(); + for (int ii = 0; ii < types.count(); ++ii) { + QmlScriptParser::TypeReference *parserRef = types.at(ii); + QByteArray typeName = parserRef->name.toLatin1(); QmlCompositeTypeData::TypeReference ref; - if (type == QByteArray("Property") || - type == QByteArray("Signal")) { + + if (typeName == QByteArray("Property") || + typeName == QByteArray("Signal")) { unit->types << ref; continue; } QUrl url; - if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, type, &ref.type, &url)) { + if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url)) { // XXX could produce error message here. } @@ -353,7 +355,12 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit) { QmlError error; error.setUrl(unit->imports.baseUrl()); - error.setDescription(tr("Type %1 unavailable").arg(QLatin1String(type))); + error.setDescription(tr("Type %1 unavailable").arg(QLatin1String(typeName))); + if (!parserRef->refObjects.isEmpty()) { + QmlParser::Object *obj = parserRef->refObjects.first(); + error.setLine(obj->location.start.line); + error.setColumn(obj->location.start.column); + } unit->errors << error; } if (urlUnit->errorType != QmlCompositeTypeData::AccessError) diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 2f82f0d..187f640 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -288,10 +288,13 @@ ProcessAST::defineObjectBinding_helper(AST::UiQualifiedId *propertyName, QString resolvableObjectType = objectType; if (lastTypeDot >= 0) resolvableObjectType.replace(QLatin1Char('.'),QLatin1Char('/')); - const int typeId = _parser->findOrCreateTypeId(resolvableObjectType); + + QmlScriptParser::TypeReference *typeRef = _parser->findOrCreateType(resolvableObjectType); Object *obj = new Object; - obj->type = typeId; + obj->type = typeRef->id; + + typeRef->refObjects.append(obj); // XXX this doesn't do anything (_scope never builds up) _scope.append(resolvableObjectType); @@ -802,9 +805,9 @@ bool QmlScriptParser::parse(const QByteArray &qmldata, const QUrl &url) return _errors.isEmpty(); } -QStringList QmlScriptParser::types() const +QList<QmlScriptParser::TypeReference*> QmlScriptParser::referencedTypes() const { - return _typeNames; + return _refTypes; } Object *QmlScriptParser::tree() const @@ -828,7 +831,8 @@ void QmlScriptParser::clear() root->release(); root = 0; } - _typeNames.clear(); + qDeleteAll(_refTypes); + _refTypes.clear(); _errors.clear(); if (data) { @@ -837,16 +841,22 @@ void QmlScriptParser::clear() } } -int QmlScriptParser::findOrCreateTypeId(const QString &name) +QmlScriptParser::TypeReference *QmlScriptParser::findOrCreateType(const QString &name) { - int index = _typeNames.indexOf(name); - - if (index == -1) { - index = _typeNames.size(); - _typeNames.append(name); + TypeReference *type = 0; + int i = 0; + for (; i < _refTypes.size(); ++i) { + if (_refTypes.at(i)->name == name) { + type = _refTypes.at(i); + break; + } + } + if (!type) { + type = new TypeReference(i, name); + _refTypes.append(type); } - return index; + return type; } void QmlScriptParser::setTree(Object *tree) diff --git a/src/declarative/qml/qmlscriptparser_p.h b/src/declarative/qml/qmlscriptparser_p.h index 355ff75..d489610 100644 --- a/src/declarative/qml/qmlscriptparser_p.h +++ b/src/declarative/qml/qmlscriptparser_p.h @@ -84,12 +84,24 @@ public: QmlParser::LocationSpan location; }; + class TypeReference + { + public: + TypeReference(int typeId, const QString &typeName) : id(typeId), name(typeName) {} + + int id; + // type as it has been referenced in Qml + QString name; + // objects in parse tree referencing the type + QList<QmlParser::Object*> refObjects; + }; + QmlScriptParser(); ~QmlScriptParser(); bool parse(const QByteArray &data, const QUrl &url = QUrl()); - QStringList types() const; + QList<TypeReference*> referencedTypes() const; QmlParser::Object *tree() const; QList<Import> imports() const; @@ -99,7 +111,7 @@ public: QList<QmlError> errors() const; // ### private: - int findOrCreateTypeId(const QString &name); + TypeReference *findOrCreateType(const QString &name); void setTree(QmlParser::Object *tree); void setScriptFile(const QString &filename) {_scriptFile = filename; } @@ -110,7 +122,7 @@ public: QmlParser::Object *root; QList<Import> _imports; - QStringList _typeNames; + QList<TypeReference*> _refTypes; QString _scriptFile; QmlScriptParserJsASTData *data; }; |