public bool EnterLambdaDeclaration(ILEmitter il, bool aliasReturn, IPlace/*!*/ rtVariablesTablePlace, IPlace/*!*/ scriptContextPlace, IPlace/*!*/ classContextPlace, IPlace/*!*/ selfPlace) { CompilerLocationStack.FunctionDeclContext fd_context = new CompilerLocationStack.FunctionDeclContext(); fd_context.Name = QualifiedName.Lambda; // Set whether access to variables should be generated via locals or table fd_context.OptimizedLocals = this.OptimizedLocals; this.OptimizedLocals = false; // Set the valid method to emit the "return" statement fd_context.ReturnsPhpReference = this.ReturnsPhpReference; this.ReturnsPhpReference = aliasReturn; // CallSites fd_context.CallSites = null; //this.callSites = new Compiler.CodeGenerator.CallSitesBuilder( // sourceUnit.CompilationUnit.Module.GlobalType.RealModuleBuilder, // fd_context.Name.ToString(), // null/*class_context = Unknown (at compile time)*/); // keep current site container, to be compatible with LeaveFunctionDeclaration this.callSites.PushClassContext(null, null); // Set ILEmitter to function's body fd_context.IL = this.il; this.il = il; // current variables table remains unchanged: fd_context.CurrentVariablesTable = this.currentVariablesTable; // current variables table remains unchanged: fd_context.CurrentLabels = this.currentLabels; // Set place for loading hashtable with variables at runtime fd_context.RTVariablesTablePlace = this.RTVariablesTablePlace; this.RTVariablesTablePlace = rtVariablesTablePlace; // Set ScriptContext fd_context.ScriptContextPlace = this.ScriptContextPlace; this.ScriptContextPlace = scriptContextPlace; // Set Class context fd_context.ClassContextPlace = this.TypeContextPlace; this.TypeContextPlace = classContextPlace; // Set Self fd_context.SelfPlace = this.SelfPlace; this.SelfPlace = selfPlace; // set Result place fd_context.ResultPlace = this.ResultPlace; fd_context.ReturnLabel = this.ReturnLabel; fd_context.LateStaticBindTypePlace = this.LateStaticBindTypePlace; this.ResultPlace = null; this.LateStaticBindTypePlace = null; // set exception block nesting: fd_context.ExceptionBlockNestingLevel = this.ExceptionBlockNestingLevel; this.ExceptionBlockNestingLevel = 0; // set current PhpRoutine fd_context.PhpRoutine = null; // locationStack.PushFunctionDecl(fd_context); return true; }
private bool EnterFunctionDeclarationInternal(PhpRoutine/*!*/ function, QualifiedName qualifiedName) { Debug.Assert(function.IsFunction); bool is_optimized = (function.Properties & RoutineProperties.HasUnoptimizedLocals) == 0; bool indirect_local_access = (function.Properties & RoutineProperties.IndirectLocalAccess) != 0; CompilerLocationStack.FunctionDeclContext fd_context = new CompilerLocationStack.FunctionDeclContext(); fd_context.Name = qualifiedName; // Set whether access to variables should be generated via locals or table fd_context.OptimizedLocals = this.OptimizedLocals; this.OptimizedLocals = is_optimized; // Set the valid method to emit the "return" statement fd_context.ReturnsPhpReference = this.ReturnsPhpReference; this.ReturnsPhpReference = function.Signature.AliasReturn; // CallSites fd_context.CallSites = null;//fd_context.CallSites = callSites; //this.callSites = new Compiler.CodeGenerator.CallSitesBuilder( // sourceUnit.CompilationUnit.Module.GlobalType.RealModuleBuilder, // fd_context.Name.ToString(), // LiteralPlace.Null); // keep current site container, just change the class context (to avoid of creating and baking so many types) this.callSites.PushClassContext(LiteralPlace.Null, null); // Set ILEmitter to function's body fd_context.IL = this.il; this.il = new ILEmitter(function.ArgFullInfo); // Set current variables table (at codeGenerator) fd_context.CurrentVariablesTable = this.currentVariablesTable; this.currentVariablesTable = function.Builder.LocalVariables; // Set current variables table (at codeGenerator) fd_context.CurrentLabels = this.currentLabels; this.currentLabels = function.Builder.Labels; // Set place for loading hashtable with variables at runtime fd_context.RTVariablesTablePlace = this.RTVariablesTablePlace; if (indirect_local_access || !is_optimized) { LocalBuilder var_table_local = il.DeclareLocal(PhpVariable.RTVariablesTableType); if (sourceUnit.SymbolDocumentWriter != null) var_table_local.SetLocalSymInfo("<locals>"); this.RTVariablesTablePlace = new Place(var_table_local); } else this.RTVariablesTablePlace = LiteralPlace.Null; // Set ScriptContext fd_context.ScriptContextPlace = this.ScriptContextPlace; this.ScriptContextPlace = new IndexedPlace(PlaceHolder.Argument, FunctionBuilder.ArgContext); // Set Class context fd_context.ClassContextPlace = this.TypeContextPlace; this.TypeContextPlace = LiteralPlace.Null; // Set Self fd_context.SelfPlace = this.SelfPlace; this.SelfPlace = LiteralPlace.Null; // Set Static fd_context.LateStaticBindTypePlace = this.LateStaticBindTypePlace; this.LateStaticBindTypePlace = null; // set Result place fd_context.ResultPlace = this.ResultPlace; fd_context.ReturnLabel = this.ReturnLabel; this.ResultPlace = null; // set exception block nesting: fd_context.ExceptionBlockNestingLevel = this.ExceptionBlockNestingLevel; this.ExceptionBlockNestingLevel = 0; // set current PhpRoutine fd_context.PhpRoutine = function; // locationStack.PushFunctionDecl(fd_context); return true; }