aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/qmljs/qmljsinterpreter.cpp
diff options
context:
space:
mode:
authorChristian Kamm <[email protected]>2010-02-19 10:14:34 +0100
committerChristian Kamm <[email protected]>2010-02-22 10:22:23 +0100
commitc28989735193ca9341ba1b96f9b1101550c60281 (patch)
tree49b99f572e73f48811b2d5079fd8d089b8813072 /src/libs/qmljs/qmljsinterpreter.cpp
parentb0e7b15bfc6b5857aa79e52a947a23e88c2d9557 (diff)
Make QmlJS scope building more flexible.
Instead of only maintaining a flat list of scopes, actually store the global, component chain, root object, scope object, function, id and js scopes separately.
Diffstat (limited to 'src/libs/qmljs/qmljsinterpreter.cpp')
-rw-r--r--src/libs/qmljs/qmljsinterpreter.cpp95
1 files changed, 48 insertions, 47 deletions
diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp
index 20b1f47dbe7..f7dc0c5393d 100644
--- a/src/libs/qmljs/qmljsinterpreter.cpp
+++ b/src/libs/qmljs/qmljsinterpreter.cpp
@@ -725,6 +725,45 @@ void StringValue::accept(ValueVisitor *visitor) const
}
+ScopeChain::ScopeChain()
+ : globalScope(0)
+ , qmlTypes(0)
+{
+}
+
+void ScopeChain::QmlComponentChain::add(QList<const ObjectValue *> *list) const
+{
+ foreach (QmlComponentChain *parent, instantiatingComponents)
+ parent->add(list);
+
+ if (rootObject)
+ list->append(rootObject);
+ list->append(functionScopes);
+ if (ids)
+ list->append(ids);
+}
+
+void ScopeChain::update()
+{
+ all.clear();
+
+ all += globalScope;
+
+ foreach (QmlComponentChain *parent, qmlComponentScope.instantiatingComponents)
+ parent->add(&all);
+
+ if (qmlComponentScope.rootObject)
+ all += qmlComponentScope.rootObject;
+ all += qmlScopeObjects;
+ all += qmlComponentScope.functionScopes;
+ if (qmlComponentScope.ids)
+ all += qmlComponentScope.ids;
+ if (qmlTypes)
+ all += qmlTypes;
+ all += jsScopes;
+}
+
+
Context::Context(Engine *engine)
: _engine(engine),
_lookupMode(JSLookup),
@@ -748,7 +787,12 @@ Engine *Context::engine() const
return _engine;
}
-Context::ScopeChain Context::scopeChain() const
+const ScopeChain &Context::scopeChain() const
+{
+ return _scopeChain;
+}
+
+ScopeChain &Context::scopeChain()
{
return _scopeChain;
}
@@ -773,54 +817,11 @@ void Context::setTypeEnvironment(const QmlJS::Document *doc, const ObjectValue *
_typeEnvironments[doc] = typeEnvironment;
}
-void Context::pushScope(const ObjectValue *object)
-{
- if (object != 0)
- _scopeChain.append(object);
-}
-
-void Context::popScope()
-{
- _scopeChain.removeLast();
- if (_scopeChain.length() <= _qmlScopeObjectIndex)
- _qmlScopeObjectSet = false;
-}
-
-// Marks this to be the location where a scope object can be inserted.
-void Context::markQmlScopeObject()
-{
- _qmlScopeObjectIndex = _scopeChain.length();
-}
-
-// Sets or inserts the scope object if scopeObject != 0, removes it otherwise.
-void Context::setQmlScopeObject(const ObjectValue *scopeObject)
-{
- if (_qmlScopeObjectSet) {
- if (scopeObject == 0) {
- _scopeChain.removeAt(_qmlScopeObjectIndex);
- _qmlScopeObjectSet = false;
- } else {
- _scopeChain[_qmlScopeObjectIndex] = scopeObject;
- }
- } else if (scopeObject != 0 && _scopeChain.length() >= _qmlScopeObjectIndex) {
- _scopeChain.insert(_qmlScopeObjectIndex, scopeObject);
- _qmlScopeObjectSet = true;
- }
-}
-
-// Gets the scope object, if set. Returns 0 otherwise.
-const ObjectValue *Context::qmlScopeObject() const
-{
- if (!_qmlScopeObjectSet)
- return 0;
- else
- return _scopeChain[_qmlScopeObjectIndex];
-}
-
const Value *Context::lookup(const QString &name)
{
- for (int index = _scopeChain.size() - 1; index != -1; --index) {
- const ObjectValue *scope = _scopeChain.at(index);
+ QList<const ObjectValue *> scopes = _scopeChain.all;
+ for (int index = scopes.size() - 1; index != -1; --index) {
+ const ObjectValue *scope = scopes.at(index);
if (const Value *member = scope->lookupMember(name, this)) {
if (_lookupMode == JSLookup || ! dynamic_cast<const ASTVariableReference *>(member)) {