forked from qt-creator/qt-creator
Fix prototype reference resolution for Qml objects.
This commit is contained in:
@@ -140,7 +140,8 @@ ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitia
|
||||
|
||||
// normal component instance
|
||||
ASTObjectValue *objectValue = new ASTObjectValue(qualifiedTypeNameId, initializer, &_interp);
|
||||
QmlPrototypeReference *prototypeReference = new QmlPrototypeReference(qualifiedTypeNameId, &_interp);
|
||||
QmlPrototypeReference *prototypeReference =
|
||||
new QmlPrototypeReference(qualifiedTypeNameId, _doc, &_interp);
|
||||
objectValue->setPrototype(prototypeReference);
|
||||
|
||||
parentObjectValue = switchObjectValue(objectValue);
|
||||
|
||||
@@ -708,14 +708,14 @@ void Context::setLookupMode(LookupMode lookupMode)
|
||||
_lookupMode = lookupMode;
|
||||
}
|
||||
|
||||
const ObjectValue *Context::typeEnvironment() const
|
||||
const ObjectValue *Context::typeEnvironment(const Document *doc) const
|
||||
{
|
||||
return _typeEnvironment;
|
||||
return _typeEnvironments.value(doc, 0);
|
||||
}
|
||||
|
||||
void Context::setTypeEnvironment(const ObjectValue *typeEnvironment)
|
||||
void Context::setTypeEnvironment(const Document *doc, const ObjectValue *typeEnvironment)
|
||||
{
|
||||
_typeEnvironment = typeEnvironment;
|
||||
_typeEnvironments[doc] = typeEnvironment;
|
||||
}
|
||||
|
||||
void Context::pushScope(const ObjectValue *object)
|
||||
@@ -743,9 +743,9 @@ const Value *Context::lookup(const QString &name)
|
||||
return _engine->undefinedValue();
|
||||
}
|
||||
|
||||
const ObjectValue *Context::lookupType(UiQualifiedId *qmlTypeName)
|
||||
const ObjectValue *Context::lookupType(const Document *doc, UiQualifiedId *qmlTypeName)
|
||||
{
|
||||
const ObjectValue *objectValue = _typeEnvironment;
|
||||
const ObjectValue *objectValue = typeEnvironment(doc);
|
||||
|
||||
for (UiQualifiedId *iter = qmlTypeName; objectValue && iter; iter = iter->next) {
|
||||
if (! iter->name)
|
||||
@@ -1992,9 +1992,11 @@ bool ASTFunctionValue::isVariadic() const
|
||||
return true;
|
||||
}
|
||||
|
||||
QmlPrototypeReference::QmlPrototypeReference(UiQualifiedId *qmlTypeName, Engine *engine)
|
||||
QmlPrototypeReference::QmlPrototypeReference(UiQualifiedId *qmlTypeName, const Document *doc,
|
||||
Engine *engine)
|
||||
: Reference(engine),
|
||||
_qmlTypeName(qmlTypeName)
|
||||
_qmlTypeName(qmlTypeName),
|
||||
_doc(doc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2009,6 +2011,6 @@ UiQualifiedId *QmlPrototypeReference::qmlTypeName() const
|
||||
|
||||
const Value *QmlPrototypeReference::value(Context *context) const
|
||||
{
|
||||
return context->lookupType(_qmlTypeName);
|
||||
return context->lookupType(_doc, _qmlTypeName);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
namespace QmlJS {
|
||||
|
||||
class NameId;
|
||||
class Document;
|
||||
|
||||
namespace Interpreter {
|
||||
|
||||
@@ -229,14 +230,14 @@ public:
|
||||
LookupMode lookupMode() const;
|
||||
void setLookupMode(LookupMode lookupMode);
|
||||
|
||||
const ObjectValue *typeEnvironment() const;
|
||||
void setTypeEnvironment(const ObjectValue *typeEnvironment);
|
||||
const ObjectValue *typeEnvironment(const Document *doc) const;
|
||||
void setTypeEnvironment(const Document *doc, const ObjectValue *typeEnvironment);
|
||||
|
||||
void pushScope(const ObjectValue *object);
|
||||
void popScope();
|
||||
|
||||
const Value *lookup(const QString &name);
|
||||
const ObjectValue *lookupType(AST::UiQualifiedId *qmlTypeName);
|
||||
const ObjectValue *lookupType(const Document *doc, AST::UiQualifiedId *qmlTypeName);
|
||||
|
||||
const Value *property(const ObjectValue *object, const QString &name) const;
|
||||
void setProperty(const ObjectValue *object, const QString &name, const Value *value);
|
||||
@@ -246,9 +247,9 @@ private:
|
||||
|
||||
Engine *_engine;
|
||||
LookupMode _lookupMode;
|
||||
const ObjectValue *_typeEnvironment;
|
||||
QHash<const ObjectValue *, Properties> _properties;
|
||||
ScopeChain _scopeChain;
|
||||
QHash<const Document *, const ObjectValue *> _typeEnvironments;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT Reference: public Value
|
||||
@@ -626,7 +627,7 @@ private:
|
||||
class QMLJS_EXPORT QmlPrototypeReference: public Reference
|
||||
{
|
||||
public:
|
||||
QmlPrototypeReference(AST::UiQualifiedId *qmlTypeName, Engine *engine);
|
||||
QmlPrototypeReference(AST::UiQualifiedId *qmlTypeName, const Document *doc, Engine *engine);
|
||||
virtual ~QmlPrototypeReference();
|
||||
|
||||
AST::UiQualifiedId *qmlTypeName() const;
|
||||
@@ -635,6 +636,7 @@ public:
|
||||
|
||||
private:
|
||||
AST::UiQualifiedId *_qmlTypeName;
|
||||
const Document *_doc;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT ASTObjectValue: public ObjectValue
|
||||
|
||||
@@ -80,20 +80,19 @@ void Link::scopeChainAt(Document::Ptr doc, Node *currentObject)
|
||||
if (bind->_idEnvironment)
|
||||
_context.pushScope(bind->_idEnvironment);
|
||||
|
||||
if (const ObjectValue *typeEnvironment = _typeEnvironments.value(doc.data())) {
|
||||
if (const ObjectValue *typeEnvironment = _context.typeEnvironment(doc.data()))
|
||||
_context.pushScope(typeEnvironment);
|
||||
_context.setTypeEnvironment(typeEnvironment);
|
||||
}
|
||||
}
|
||||
|
||||
void Link::linkImports()
|
||||
{
|
||||
foreach (Document::Ptr doc, _docs) {
|
||||
ObjectValue *typeEnv = engine()->newObject(/*prototype =*/0); // ### FIXME
|
||||
_typeEnvironments.insert(doc.data(), typeEnv);
|
||||
|
||||
// Populate the _typeEnvironment with imports.
|
||||
populateImportedTypes(typeEnv, doc);
|
||||
|
||||
_context.setTypeEnvironment(doc.data(), typeEnv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ private:
|
||||
Snapshot _snapshot;
|
||||
Interpreter::Context _context;
|
||||
QList<Document::Ptr> _docs;
|
||||
QHash<Document *, Interpreter::ObjectValue *> _typeEnvironments;
|
||||
};
|
||||
|
||||
} // namespace QmlJS
|
||||
|
||||
Reference in New Issue
Block a user