From e962832eb6efcdc14fde65bb724034ac14daf9cd Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 15 Feb 2013 13:31:32 +0100 Subject: [PATCH] Retain the proper nesting structure in the VM:Function objects Change-Id: I83c0889be7fe354f96fca68f786ca2a05121bb56 Reviewed-by: Simon Hausmann --- src/v4/qv4functionobject.h | 3 +++ src/v4/qv4isel_p.cpp | 21 ++++++++++++--------- src/v4/qv4isel_p.h | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/v4/qv4functionobject.h b/src/v4/qv4functionobject.h index ebf14f8..69d0436 100644 --- a/src/v4/qv4functionobject.h +++ b/src/v4/qv4functionobject.h @@ -120,6 +120,8 @@ struct Function { QVector locals; QVector generatedValues; QVector identifiers; + QVector nestedFunctions; + Function *outer; Lookup *lookups; @@ -132,6 +134,7 @@ struct Function { : name(name) , code(0) , codeData(0) + , outer(0) , lookups(0) , hasNestedFunctions(0) , hasDirectEval(false) diff --git a/src/v4/qv4isel_p.cpp b/src/v4/qv4isel_p.cpp index 56f4ce7..ca57009 100644 --- a/src/v4/qv4isel_p.cpp +++ b/src/v4/qv4isel_p.cpp @@ -23,7 +23,7 @@ EvalInstructionSelection::EvalInstructionSelection(VM::ExecutionEngine *engine, assert(engine); assert(module); - createFunctionMapping(engine, module->rootFunction); + createFunctionMapping(0, module->rootFunction); foreach (IR::Function *f, module->functions) { assert(_irToVM.contains(f)); } @@ -35,29 +35,32 @@ EvalInstructionSelection::~EvalInstructionSelection() EvalISelFactory::~EvalISelFactory() {} -VM::Function *EvalInstructionSelection::createFunctionMapping(VM::ExecutionEngine *engine, Function *irFunction) +VM::Function *EvalInstructionSelection::createFunctionMapping(VM::Function *outer, Function *irFunction) { - VM::Function *vmFunction = engine->newFunction(irFunction->name ? *irFunction->name : QString()); + VM::Function *vmFunction = _engine->newFunction(irFunction->name ? *irFunction->name : QString()); _irToVM.insert(irFunction, vmFunction); vmFunction->hasDirectEval = irFunction->hasDirectEval; vmFunction->usesArgumentsObject = irFunction->usesArgumentsObject; vmFunction->hasNestedFunctions = !irFunction->nestedFunctions.isEmpty(); vmFunction->isStrict = irFunction->isStrict; + vmFunction->outer = outer; + + if (outer) + outer->nestedFunctions.append(vmFunction); foreach (const QString *formal, irFunction->formals) if (formal) - vmFunction->formals.append(engine->newString(*formal)); + vmFunction->formals.append(_engine->newString(*formal)); foreach (const QString *local, irFunction->locals) if (local) - vmFunction->locals.append(engine->newString(*local)); + vmFunction->locals.append(_engine->newString(*local)); foreach (IR::Function *function, irFunction->nestedFunctions) - createFunctionMapping(engine, function); - + createFunctionMapping(vmFunction, function); - if (engine->debugger) - engine->debugger->mapFunction(vmFunction, irFunction); + if (_engine->debugger) + _engine->debugger->mapFunction(vmFunction, irFunction); return vmFunction; } diff --git a/src/v4/qv4isel_p.h b/src/v4/qv4isel_p.h index b336e3a..cf0c325 100644 --- a/src/v4/qv4isel_p.h +++ b/src/v4/qv4isel_p.h @@ -54,7 +54,7 @@ public: void setUseFastLookups(bool b) { useFastLookups = b; } protected: - VM::Function *createFunctionMapping(VM::ExecutionEngine *engine, IR::Function *irFunction); + VM::Function *createFunctionMapping(VM::Function *outer, IR::Function *irFunction); VM::ExecutionEngine *engine() const { return _engine; } virtual void run(VM::Function *vmFunction, IR::Function *function) = 0; -- 2.7.4