Commit 95849cb0 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Store bindings and definitions in one single table.

parent d5326f37
......@@ -270,7 +270,7 @@ bool Bind::visit(UiPublicMember *)
bool Bind::visit(UiObjectDefinition *ast)
{
ObjectValue *value = bindObject(ast->qualifiedTypeNameId, ast->initializer);
_qmlObjectDefinitions.insert(ast, value);
_qmlObjects.insert(ast, value);
return false;
}
......@@ -279,7 +279,7 @@ bool Bind::visit(UiObjectBinding *ast)
{
// const QString name = serialize(ast->qualifiedId);
ObjectValue *value = bindObject(ast->qualifiedTypeNameId, ast->initializer);
_qmlObjectBindings.insert(ast, value);
_qmlObjects.insert(ast, value);
// ### FIXME: we don't handle dot-properties correctly (i.e. font.size)
// _currentObjectValue->setProperty(name, value);
......
......@@ -83,8 +83,7 @@ private:
Interpreter::ObjectValue *_functionEnvironment;
Interpreter::ObjectValue *_rootObjectValue;
QHash<AST::UiObjectDefinition *, Interpreter::ObjectValue *> _qmlObjectDefinitions;
QHash<AST::UiObjectBinding *, Interpreter::ObjectValue *> _qmlObjectBindings;
QHash<AST::Node *, Interpreter::ObjectValue *> _qmlObjects;
QStringList _includedScripts;
QStringList _localImports;
......
......@@ -31,11 +31,7 @@ Link::~Link()
bind->_idEnvironment->setScope(0);
bind->_functionEnvironment->setScope(0);
foreach (ObjectValue *object, bind->_qmlObjectBindings) {
object->setPrototype(0);
object->setScope(0);
}
foreach (ObjectValue *object, bind->_qmlObjectDefinitions) {
foreach (ObjectValue *object, bind->_qmlObjects) {
object->setPrototype(0);
object->setScope(0);
}
......@@ -55,13 +51,9 @@ ObjectValue *Link::scopeChainAt(Document::Ptr doc, Node *currentObject)
{
BindPtr bind = doc->bind();
ObjectValue *scopeObject;
ObjectValue *scopeObject = 0;
if (UiObjectDefinition *definition = cast<UiObjectDefinition *>(currentObject))
scopeObject = bind->_qmlObjectDefinitions.value(definition);
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(currentObject))
scopeObject = bind->_qmlObjectBindings.value(binding);
else
return bind->_interp.globalObject();
scopeObject = bind->_qmlObjects.value(definition);
if (!scopeObject)
return bind->_interp.globalObject();
......@@ -103,29 +95,14 @@ void Link::linkImports()
populateImportedTypes(typeEnv, doc);
// Set the prototypes.
{
QHash<UiObjectDefinition *, ObjectValue *>::iterator it = bind->_qmlObjectDefinitions.begin();
QHash<UiObjectDefinition *, ObjectValue *>::iterator end = bind->_qmlObjectDefinitions.end();
for (; it != end; ++it) {
UiObjectDefinition *key = it.key();
ObjectValue *value = it.value();
if (!key->qualifiedTypeNameId)
continue;
value->setPrototype(lookupType(typeEnv, key->qualifiedTypeNameId));
}
}
{
QHash<UiObjectBinding *, ObjectValue *>::iterator it = bind->_qmlObjectBindings.begin();
QHash<UiObjectBinding *, ObjectValue *>::iterator end = bind->_qmlObjectBindings.end();
for (; it != end; ++it) {
UiObjectBinding *key = it.key();
ObjectValue *value = it.value();
if (!key->qualifiedTypeNameId)
continue;
value->setPrototype(lookupType(typeEnv, key->qualifiedTypeNameId));
}
QHashIterator<Node *, ObjectValue *> it(bind->_qmlObjects);
while (it.hasNext()) {
it.next();
Node *binding = it.key();
ObjectValue *value = it.value();
if (UiQualifiedId *qualifiedId = qualifiedTypeNameId(binding))
value->setPrototype(lookupType(typeEnv, qualifiedId));
}
}
}
......@@ -290,6 +267,16 @@ const ObjectValue *Link::lookupType(ObjectValue *env, UiQualifiedId *id)
return objectValue;
}
UiQualifiedId *Link::qualifiedTypeNameId(Node *node)
{
if (UiObjectBinding *binding = AST::cast<UiObjectBinding *>(node))
return binding->qualifiedTypeNameId;
else if (UiObjectDefinition *binding = AST::cast<UiObjectDefinition *>(node))
return binding->qualifiedTypeNameId;
else
return 0;
}
QList<Document::Ptr> Link::reachableDocuments(Document::Ptr startDoc, const Snapshot &snapshot)
{
QList<Document::Ptr> docs;
......
......@@ -29,6 +29,7 @@ public:
private:
static QList<Document::Ptr> reachableDocuments(Document::Ptr startDoc, const Snapshot &snapshot);
static const Interpreter::ObjectValue *lookupType(Interpreter::ObjectValue *env, AST::UiQualifiedId *id);
static AST::UiQualifiedId *qualifiedTypeNameId(AST::Node *node);
void linkImports();
......@@ -37,7 +38,7 @@ private:
AST::UiImport *import, const QString &startPath);
void importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc,
AST::UiImport *import);
void importObject(BindPtr bind, const QString &name, Interpreter::ObjectValue *object, NameId* targetNamespace);
void importObject(BindPtr bind, const QString &name, Interpreter::ObjectValue *object, NameId* targetNamespace);
private:
Snapshot _snapshot;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment