Commit bdf8c948 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Get rid off the friend QmlJS::Link declaration.

parent 8f5a1225
......@@ -67,6 +67,31 @@ QStringList Bind::localImports() const
return _localImports;
}
Interpreter::ObjectValue *Bind::currentObjectValue() const
{
return _currentObjectValue;
}
Interpreter::ObjectValue *Bind::idEnvironment() const
{
return _idEnvironment;
}
Interpreter::ObjectValue *Bind::functionEnvironment() const
{
return _functionEnvironment;
}
Interpreter::ObjectValue *Bind::rootObjectValue() const
{
return _rootObjectValue;
}
Interpreter::ObjectValue *Bind::findQmlObject(AST::Node *node) const
{
return _qmlObjects.value(node);
}
ObjectValue *Bind::switchObjectValue(ObjectValue *newObjectValue)
{
ObjectValue *oldObjectValue = _currentObjectValue;
......@@ -139,9 +164,9 @@ ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitia
}
// normal component instance
ASTObjectValue *objectValue = new ASTObjectValue(qualifiedTypeNameId, initializer, _doc, &_interp);
ASTObjectValue *objectValue = new ASTObjectValue(qualifiedTypeNameId, initializer, _doc, &_engine);
QmlPrototypeReference *prototypeReference =
new QmlPrototypeReference(qualifiedTypeNameId, _doc, &_interp);
new QmlPrototypeReference(qualifiedTypeNameId, _doc, &_engine);
objectValue->setPrototype(prototypeReference);
parentObjectValue = switchObjectValue(objectValue);
......@@ -163,15 +188,15 @@ void Bind::accept(Node *node)
bool Bind::visit(AST::UiProgram *)
{
_idEnvironment = _interp.newObject(/*prototype =*/ 0);
_functionEnvironment = _interp.newObject(/*prototype =*/ 0);
_idEnvironment = _engine.newObject(/*prototype =*/ 0);
_functionEnvironment = _engine.newObject(/*prototype =*/ 0);
return true;
}
bool Bind::visit(AST::Program *)
{
_currentObjectValue = _interp.globalObject();
_rootObjectValue = _interp.globalObject();
_currentObjectValue = _engine.globalObject();
_rootObjectValue = _engine.globalObject();
return true;
}
......@@ -237,7 +262,7 @@ bool Bind::visit(VariableDeclaration *ast)
if (! ast->name)
return false;
ASTVariableReference *ref = new ASTVariableReference(ast, &_interp);
ASTVariableReference *ref = new ASTVariableReference(ast, &_engine);
_currentObjectValue->setProperty(ast->name->asString(), ref);
return false;
}
......@@ -250,7 +275,7 @@ bool Bind::visit(FunctionDeclaration *ast)
//if (_currentObjectValue->property(ast->name->asString(), 0))
// return false;
ASTFunctionValue *function = new ASTFunctionValue(ast, &_interp);
ASTFunctionValue *function = new ASTFunctionValue(ast, &_engine);
// ### set the function's scope.
_currentObjectValue->setProperty(ast->name->asString(), function);
......
......@@ -53,12 +53,17 @@ public:
QStringList includedScripts() const;
QStringList localImports() const;
protected:
using AST::Visitor::visit;
Interpreter::ObjectValue *currentObjectValue() const;
Interpreter::ObjectValue *idEnvironment() const;
Interpreter::ObjectValue *functionEnvironment() const;
Interpreter::ObjectValue *rootObjectValue() const;
Interpreter::ObjectValue *findQmlObject(AST::Node *node) const;
static QString toString(AST::UiQualifiedId *qualifiedId, QChar delimiter = QChar('.'));
AST::ExpressionNode *expression(AST::UiScriptBinding *ast) const;
void processScript(AST::UiQualifiedId *qualifiedId, AST::UiObjectInitializer *initializer);
protected:
using AST::Visitor::visit;
void accept(AST::Node *node);
......@@ -77,13 +82,15 @@ protected:
virtual bool visit(AST::FunctionDeclaration *ast);
virtual bool visit(AST::VariableDeclaration *ast);
protected:
Interpreter::ObjectValue *switchObjectValue(Interpreter::ObjectValue *newObjectValue);
Interpreter::ObjectValue *bindObject(AST::UiQualifiedId *qualifiedTypeNameId, AST::UiObjectInitializer *initializer);
AST::ExpressionNode *expression(AST::UiScriptBinding *ast) const;
void processScript(AST::UiQualifiedId *qualifiedId, AST::UiObjectInitializer *initializer);
private:
Document *_doc;
Interpreter::Engine _interp;
Interpreter::Engine _engine;
Interpreter::ObjectValue *_currentObjectValue;
Interpreter::ObjectValue *_idEnvironment;
......@@ -93,8 +100,6 @@ private:
QHash<AST::Node *, Interpreter::ObjectValue *> _qmlObjects;
QStringList _includedScripts;
QStringList _localImports;
friend class Link;
};
} // end of namespace Qml
......
......@@ -732,7 +732,8 @@ void Context::setTypeEnvironment(const QmlJS::Document *doc, const ObjectValue *
void Context::pushScope(const ObjectValue *object)
{
_scopeChain.append(object);
if (object != 0)
_scopeChain.append(object);
}
void Context::popScope()
......
......@@ -47,11 +47,11 @@ void Link::scopeChainAt(Document::Ptr doc, Node *currentObject)
ObjectValue *scopeObject = 0;
if (UiObjectDefinition *definition = cast<UiObjectDefinition *>(currentObject))
scopeObject = bind->_qmlObjects.value(definition);
scopeObject = bind->findQmlObject(definition);
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(currentObject))
scopeObject = bind->_qmlObjects.value(binding);
scopeObject = bind->findQmlObject(binding);
else if (FunctionDeclaration *fun = cast<FunctionDeclaration *>(currentObject)) {
_context->pushScope(bind->_rootObjectValue);
_context->pushScope(bind->rootObjectValue());
ObjectValue *activation = engine()->newObject(/*prototype = */ 0);
for (FormalParameterList *it = fun->formals; it; it = it->next) {
......@@ -62,10 +62,10 @@ void Link::scopeChainAt(Document::Ptr doc, Node *currentObject)
}
if (scopeObject) {
if (bind->_rootObjectValue)
_context->pushScope(bind->_rootObjectValue);
if (bind->rootObjectValue())
_context->pushScope(bind->rootObjectValue());
if (scopeObject != bind->_rootObjectValue)
if (scopeObject != bind->rootObjectValue())
_context->pushScope(scopeObject);
}
......@@ -75,16 +75,13 @@ void Link::scopeChainAt(Document::Ptr doc, Node *currentObject)
if (Document::Ptr scriptDoc = _snapshot.document(scriptFile)) {
if (scriptDoc->jsProgram()) {
_context->pushScope(scriptDoc->bind()->_rootObjectValue);
_context->pushScope(scriptDoc->bind()->rootObjectValue());
}
}
}
if (bind->_functionEnvironment)
_context->pushScope(bind->_functionEnvironment);
if (bind->_idEnvironment)
_context->pushScope(bind->_idEnvironment);
_context->pushScope(bind->functionEnvironment());
_context->pushScope(bind->idEnvironment());
if (const ObjectValue *typeEnvironment = _context->typeEnvironment(doc.data()))
_context->pushScope(typeEnvironment);
......@@ -133,7 +130,7 @@ void Link::populateImportedTypes(Interpreter::ObjectValue *typeEnv, Document::Pt
continue;
typeEnv->setProperty(componentName(otherFileInfo.fileName()),
otherDoc->bind()->_rootObjectValue);
otherDoc->bind()->rootObjectValue());
}
// explicit imports, whether directories or files
......@@ -197,7 +194,7 @@ void Link::importFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc,
if (importNamespace)
importInto = importNamespace;
importInto->setProperty(targetName, otherDoc->bind()->_rootObjectValue);
importInto->setProperty(targetName, otherDoc->bind()->rootObjectValue());
}
}
......
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