Commit 450ad48f authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Clean up QmlJS::Bind.

parent 0f031609
......@@ -46,29 +46,31 @@ Bind::Bind(Document::Ptr doc, Interpreter::Engine *interp)
_functionEnvironment(0),
_rootObjectValue(0)
{
(*this)();
if (_doc && _doc->qmlProgram() != 0) {
UiProgram *program = _doc->qmlProgram();
_currentObjectValue = 0;
_typeEnvironment = _interp->newObject(/*prototype =*/ 0);
_idEnvironment = _interp->newObject(/*prototype =*/ 0);
_functionEnvironment = _interp->newObject(/*prototype =*/ 0);
_rootObjectValue = 0;
_qmlObjectDefinitions.clear();
_qmlObjectBindings.clear();
accept(program);
}
}
Bind::~Bind()
{
}
void Bind::operator()()
ObjectValue *Bind::switchObjectValue(ObjectValue *newObjectValue)
{
UiProgram *program = _doc->qmlProgram();
if (!program)
return;
_currentObjectValue = 0;
_typeEnvironment = _interp->newObject(/*prototype =*/ 0);
_idEnvironment = _interp->newObject(/*prototype =*/ 0);
_functionEnvironment = _interp->newObject(/*prototype =*/ 0);
_rootObjectValue = 0;
_qmlObjectDefinitions.clear();
_qmlObjectBindings.clear();
accept(program);
ObjectValue *oldObjectValue = _currentObjectValue;
_currentObjectValue = newObjectValue;
return oldObjectValue;
}
ObjectValue *Bind::scopeChainAt(Document::Ptr currentDocument, const Snapshot &snapshot,
......@@ -86,10 +88,13 @@ ObjectValue *Bind::scopeChainAt(Document::Ptr currentDocument, const Snapshot &s
currentBind = newBind;
}
LinkImports()(binds);
LinkImports linkImports;
Link link;
linkImports(binds);
ObjectValue *scope = interp->globalObject();
if (currentBind)
scope = Link()(binds, currentBind, currentObject);
scope = link(binds, currentBind, currentObject);
qDeleteAll(binds);
return scope;
......@@ -110,19 +115,30 @@ QString Bind::toString(UiQualifiedId *qualifiedId, QChar delimiter)
return result;
}
void Bind::accept(Node *node)
ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitializer *initializer)
{
Node::accept(node, this);
}
ObjectValue *parentObjectValue;
bool Bind::visit(UiProgram *)
{
return true;
if (toString(qualifiedTypeNameId) == QLatin1String("Script")) {
// Script blocks all contribute to the same scope
parentObjectValue = switchObjectValue(_functionEnvironment);
} else { // normal component instance
ObjectValue *objectValue = _interp->newObject(/*prototype =*/0);
parentObjectValue = switchObjectValue(objectValue);
if (parentObjectValue)
objectValue->setProperty("parent", parentObjectValue);
else
_rootObjectValue = objectValue;
}
accept(initializer);
return switchObjectValue(parentObjectValue);
}
bool Bind::visit(UiImportList *)
void Bind::accept(Node *node)
{
return true;
Node::accept(node, this);
}
/*
......@@ -199,32 +215,6 @@ bool Bind::visit(UiPublicMember *ast)
return false;
}
bool Bind::visit(UiSourceElement *)
{
return true;
}
ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitializer *initializer)
{
ObjectValue *parentObjectValue;
if (toString(qualifiedTypeNameId) == QLatin1String("Script")) {
// Script blocks all contribute to the same scope
parentObjectValue = switchObjectValue(_functionEnvironment);
} else { // normal component instance
ObjectValue *objectValue = _interp->newObject(/*prototype =*/0);
parentObjectValue = switchObjectValue(objectValue);
if (parentObjectValue)
objectValue->setProperty("parent", parentObjectValue);
else
_rootObjectValue = objectValue;
}
accept(initializer);
return switchObjectValue(parentObjectValue);
}
bool Bind::visit(UiObjectDefinition *ast)
{
ObjectValue *value = bindObject(ast->qualifiedTypeNameId, ast->initializer);
......@@ -244,11 +234,6 @@ bool Bind::visit(UiObjectBinding *ast)
return false;
}
bool Bind::visit(UiObjectInitializer *)
{
return true;
}
bool Bind::visit(UiScriptBinding *ast)
{
if (toString(ast->qualifiedId) == QLatin1String("id")) {
......@@ -268,361 +253,6 @@ bool Bind::visit(UiArrayBinding *)
return true;
}
bool Bind::visit(UiObjectMemberList *)
{
return true;
}
bool Bind::visit(UiArrayMemberList *)
{
return true;
}
bool Bind::visit(UiQualifiedId *)
{
return true;
}
bool Bind::visit(UiSignature *)
{
return true;
}
bool Bind::visit(UiFormalList *)
{
return true;
}
bool Bind::visit(UiFormal *)
{
return true;
}
bool Bind::visit(ThisExpression *)
{
return true;
}
bool Bind::visit(IdentifierExpression *)
{
return true;
}
bool Bind::visit(NullExpression *)
{
return true;
}
bool Bind::visit(TrueLiteral *)
{
return true;
}
bool Bind::visit(FalseLiteral *)
{
return true;
}
bool Bind::visit(StringLiteral *)
{
return true;
}
bool Bind::visit(NumericLiteral *)
{
return true;
}
bool Bind::visit(RegExpLiteral *)
{
return true;
}
bool Bind::visit(ArrayLiteral *)
{
return true;
}
bool Bind::visit(ObjectLiteral *)
{
return true;
}
bool Bind::visit(ElementList *)
{
return true;
}
bool Bind::visit(Elision *)
{
return true;
}
bool Bind::visit(PropertyNameAndValueList *)
{
return true;
}
bool Bind::visit(NestedExpression *)
{
return true;
}
bool Bind::visit(IdentifierPropertyName *)
{
return true;
}
bool Bind::visit(StringLiteralPropertyName *)
{
return true;
}
bool Bind::visit(NumericLiteralPropertyName *)
{
return true;
}
bool Bind::visit(ArrayMemberExpression *)
{
return true;
}
bool Bind::visit(FieldMemberExpression *)
{
return true;
}
bool Bind::visit(NewMemberExpression *)
{
return true;
}
bool Bind::visit(NewExpression *)
{
return true;
}
bool Bind::visit(CallExpression *)
{
return true;
}
bool Bind::visit(ArgumentList *)
{
return true;
}
bool Bind::visit(PostIncrementExpression *)
{
return true;
}
bool Bind::visit(PostDecrementExpression *)
{
return true;
}
bool Bind::visit(DeleteExpression *)
{
return true;
}
bool Bind::visit(VoidExpression *)
{
return true;
}
bool Bind::visit(TypeOfExpression *)
{
return true;
}
bool Bind::visit(PreIncrementExpression *)
{
return true;
}
bool Bind::visit(PreDecrementExpression *)
{
return true;
}
bool Bind::visit(UnaryPlusExpression *)
{
return true;
}
bool Bind::visit(UnaryMinusExpression *)
{
return true;
}
bool Bind::visit(TildeExpression *)
{
return true;
}
bool Bind::visit(NotExpression *)
{
return true;
}
bool Bind::visit(BinaryExpression *)
{
return true;
}
bool Bind::visit(ConditionalExpression *)
{
return true;
}
bool Bind::visit(Expression *)
{
return true;
}
bool Bind::visit(Block *)
{
return true;
}
bool Bind::visit(StatementList *)
{
return true;
}
bool Bind::visit(VariableStatement *)
{
return true;
}
bool Bind::visit(VariableDeclarationList *)
{
return true;
}
bool Bind::visit(VariableDeclaration *)
{
return true;
}
bool Bind::visit(EmptyStatement *)
{
return true;
}
bool Bind::visit(ExpressionStatement *)
{
return true;
}
bool Bind::visit(IfStatement *)
{
return true;
}
bool Bind::visit(DoWhileStatement *)
{
return true;
}
bool Bind::visit(WhileStatement *)
{
return true;
}
bool Bind::visit(ForStatement *)
{
return true;
}
bool Bind::visit(LocalForStatement *)
{
return true;
}
bool Bind::visit(ForEachStatement *)
{
return true;
}
bool Bind::visit(LocalForEachStatement *)
{
return true;
}
bool Bind::visit(ContinueStatement *)
{
return true;
}
bool Bind::visit(BreakStatement *)
{
return true;
}
bool Bind::visit(ReturnStatement *)
{
return true;
}
bool Bind::visit(WithStatement *)
{
return true;
}
bool Bind::visit(SwitchStatement *)
{
return true;
}
bool Bind::visit(CaseBlock *)
{
return true;
}
bool Bind::visit(CaseClauses *)
{
return true;
}
bool Bind::visit(CaseClause *)
{
return true;
}
bool Bind::visit(DefaultClause *)
{
return true;
}
bool Bind::visit(LabelledStatement *)
{
return true;
}
bool Bind::visit(ThrowStatement *)
{
return true;
}
bool Bind::visit(TryStatement *)
{
return true;
}
bool Bind::visit(Catch *)
{
return true;
}
bool Bind::visit(Finally *)
{
return true;
}
bool Bind::visit(FunctionDeclaration *ast)
{
if (!ast->name)
......@@ -639,50 +269,3 @@ bool Bind::visit(FunctionDeclaration *ast)
_currentObjectValue->setProperty(ast->name->asString(), function);
return false; // ### eventually want to visit function bodies
}
bool Bind::visit(FunctionExpression *)
{
return true;
}
bool Bind::visit(FormalParameterList *)
{
return true;
}
bool Bind::visit(FunctionBody *)
{
return true;
}
bool Bind::visit(Program *)
{
return true;
}
bool Bind::visit(SourceElements *)
{
return true;
}
bool Bind::visit(FunctionSourceElement *)
{
return true;
}
bool Bind::visit(StatementSourceElement *)
{
return true;
}
bool Bind::visit(DebuggerStatement *)
{
return true;
}
ObjectValue *Bind::switchObjectValue(ObjectValue *newObjectValue)
{
ObjectValue *oldObjectValue = _currentObjectValue;
_currentObjectValue = newObjectValue;
return oldObjectValue;
}
......@@ -47,8 +47,6 @@ public:
Bind(Document::Ptr doc, Interpreter::Engine *interp);
virtual ~Bind();
void operator()();
// ### TODO: This methods should go. Bind each document after parsing, link later.
static Interpreter::ObjectValue *scopeChainAt(Document::Ptr currentDocument,
const Snapshot &snapshot,
......@@ -63,98 +61,13 @@ protected:
void accept(AST::Node *node);
// Ui
virtual bool visit(AST::UiProgram *ast);
virtual bool visit(AST::UiImportList *ast);
virtual bool visit(AST::UiImport *ast);
virtual bool visit(AST::UiPublicMember *ast);
virtual bool visit(AST::UiSourceElement *ast);
virtual bool visit(AST::UiObjectDefinition *ast);
virtual bool visit(AST::UiObjectInitializer *ast);
virtual bool visit(AST::UiObjectBinding *ast);
virtual bool visit(AST::UiScriptBinding *ast);
virtual bool visit(AST::UiArrayBinding *ast);
virtual bool visit(AST::UiObjectMemberList *ast);
virtual bool visit(AST::UiArrayMemberList *ast);
virtual bool visit(AST::UiQualifiedId *ast);
virtual bool visit(AST::UiSignature *ast);
virtual bool visit(AST::UiFormalList *ast);
virtual bool visit(AST::UiFormal *ast);
// QmlJS
virtual bool visit(AST::ThisExpression *ast);
virtual bool visit(AST::IdentifierExpression *ast);
virtual bool visit(AST::NullExpression *ast);
virtual bool visit(AST::TrueLiteral *ast);
virtual bool visit(AST::FalseLiteral *ast);
virtual bool visit(AST::StringLiteral *ast);
virtual bool visit(AST::NumericLiteral *ast);
virtual bool visit(AST::RegExpLiteral *ast);
virtual bool visit(AST::ArrayLiteral *ast);
virtual bool visit(AST::ObjectLiteral *ast);
virtual bool visit(AST::ElementList *ast);
virtual bool visit(AST::Elision *ast);
virtual bool visit(AST::PropertyNameAndValueList *ast);
virtual bool visit(AST::NestedExpression *ast);
virtual bool visit(AST::IdentifierPropertyName *ast);
virtual bool visit(AST::StringLiteralPropertyName *ast);
virtual bool visit(AST::NumericLiteralPropertyName *ast);
virtual bool visit(AST::ArrayMemberExpression *ast);
virtual bool visit(AST::FieldMemberExpression *ast);
virtual bool visit(AST::NewMemberExpression *ast);
virtual bool visit(AST::NewExpression *ast);
virtual bool visit(AST::CallExpression *ast);
virtual bool visit(AST::ArgumentList *ast);
virtual bool visit(AST::PostIncrementExpression *ast);
virtual bool visit(AST::PostDecrementExpression *ast);
virtual bool visit(AST::DeleteExpression *ast);
virtual bool visit(AST::VoidExpression *ast);
virtual bool visit(AST::TypeOfExpression *ast);
virtual bool visit(AST::PreIncrementExpression *ast);
virtual bool visit(AST::PreDecrementExpression *ast);
virtual bool visit(AST::UnaryPlusExpression *ast);
virtual bool visit(AST::UnaryMinusExpression *ast);
virtual bool visit(AST::TildeExpression *ast);
virtual bool visit(AST::NotExpression *ast);
virtual bool visit(AST::BinaryExpression *ast);
virtual bool visit(AST::ConditionalExpression *ast);
virtual bool visit(AST