diff options
author | Lars Knoll <lars.knoll@digia.com> | 2012-11-01 14:49:09 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-01 15:56:54 +0100 |
commit | 88e869fe567b185e2bc7a851d78776cda3b60c03 (patch) | |
tree | 130c418d8cd0ce61e8f5db8ffa1b85e23c507ab7 /qv4codegen.cpp | |
parent | 9fff7d88693ddbb8364abdb9055f8cc5a202111a (diff) |
Implement Function(...) and new Function(...)
Change-Id: I3ff229740820883a99dee6e32370fc528bf9169c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'qv4codegen.cpp')
-rw-r--r-- | qv4codegen.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/qv4codegen.cpp b/qv4codegen.cpp index 976ab05fa5..39fc3e4901 100644 --- a/qv4codegen.cpp +++ b/qv4codegen.cpp @@ -259,8 +259,10 @@ protected: virtual bool visit(FunctionExpression *ast) { - _env->hasNestedFunctions = true; - _env->enter(ast->name.toString()); + if (_env) { + _env->hasNestedFunctions = true; + _env->enter(ast->name.toString()); + } enterEnvironment(ast); return true; } @@ -323,6 +325,27 @@ IR::Function *Codegen::operator()(Program *node, IR::Module *module, Mode mode) return globalCode; } +IR::Function *Codegen::operator()(AST::FunctionExpression *ast, IR::Module *module) +{ + _module = module; + _env = 0; + + ScanFunctions scan(this); + scan(ast); + + IR::Function *function = defineFunction(ast->name.toString(), ast, ast->formals, ast->body ? ast->body->elements : 0); + + foreach (IR::Function *function, _module->functions) { + linearize(function); + } + + qDeleteAll(_envMap); + _envMap.clear(); + + return function; +} + + void Codegen::enterEnvironment(Node *node) { _env = _envMap.value(node); |