/// <summary> /// Called when a <see cref="PHP.Core.AST.TypeDecl"/> AST node is left during the emit phase. /// </summary> public void LeaveTypeDeclaration() { CompilerLocationStack.TypeDeclContext context = locationStack.PeekTypeDecl(); locationStack.Pop(); // close CallSites: this.callSites.Bake(); // restore: this.callSites = context.CallSites; this.TypeContextPlace = context.TypeContextPlace; }
/// <summary> /// Called when a <see cref="PHP.Core.AST.GlobalCode"/> AST node is left during the emit phase. /// </summary> public void LeaveGlobalCodeDeclaration() { CompilerLocationStack.GlobalCodeContext gc_context = locationStack.PeekGlobalCode(); locationStack.Pop(); // clear (for convenience): this.sourceUnit = null; // close CallSites: this.callSites.Bake(); // restore: this.callSites = null; this.il = gc_context.IL; this.ScriptContextPlace = gc_context.ScriptContextPlace; this.TypeContextPlace = gc_context.ClassContextPlace; this.LateStaticBindTypePlace = null; this.SelfPlace = gc_context.SelfPlace; this.ResultPlace = gc_context.ResultPlace; this.ReturnLabel = gc_context.ReturnLabel; this.currentVariablesTable = gc_context.CurrentVariablesTable; this.currentLabels = gc_context.CurrentLabels; this.RTVariablesTablePlace = gc_context.RTVariablesTablePlace; this.OptimizedLocals = gc_context.OptimizedLocals; this.ReturnsPhpReference = gc_context.ReturnsPhpReference; this.ExceptionBlockNestingLevel = gc_context.ExceptionBlockNestingLevel; }
/// <summary> /// Called when a <see cref="PHP.Core.AST.TypeDecl"/> AST node is entered during the emit phase. /// </summary> public void EnterTypeDeclaration(PhpType/*!*/ type) { CompilerLocationStack.TypeDeclContext cd_context = new CompilerLocationStack.TypeDeclContext(); cd_context.Type = type; cd_context.TypeContextPlace = TypeContextPlace; TypeContextPlace = new Place(null, type.TypeDescFieldInfo); // CallSites cd_context.CallSites = callSites; this.callSites = new CallSitesBuilder( sourceUnit.CompilationUnit.Module.GlobalType.RealModuleBuilder, type.QualifiedName.ToString(), TypeContextPlace, /*class_context = TypeContextPlace, can be used in .cctor of call sites container*/ type); // locationStack.PushTypeDecl(cd_context); }
/// <summary> /// Called when a <see cref="PHP.Core.AST.GlobalCode"/> AST node is entered during the emit phase. /// </summary> public void EnterGlobalCodeDeclaration(VariablesTable variablesTable, Dictionary<VariableName, Statement> labels, CompilationSourceUnit/*!*/ sourceUnit) { CompilerLocationStack.GlobalCodeContext gc_context = new CompilerLocationStack.GlobalCodeContext(); // no need to backup current source unit as it is no longer needed: this.sourceUnit = sourceUnit; // set whether access to variables should be generated via locals or table gc_context.OptimizedLocals = this.OptimizedLocals; this.OptimizedLocals = false; // global code returns object gc_context.ReturnsPhpReference = this.ReturnsPhpReference; this.ReturnsPhpReference = false; // CallSites Debug.Assert(this.callSites == null, "Unclosed CallSite!"); this.callSites = new CallSitesBuilder( sourceUnit.CompilationUnit.Module.GlobalType.RealModuleBuilder, sourceUnit.SourceFile.RelativePath.ToString(), null/*Unknown at compile time*/); // set ILEmitter for global code gc_context.IL = il; il = CompilationUnit.ModuleBuilder.CreateGlobalCodeEmitter(); // set current variables table (at codeGenerator) gc_context.CurrentVariablesTable = currentVariablesTable; currentVariablesTable = variablesTable; // set current labels table (at codeGenerator) gc_context.CurrentLabels = currentLabels; currentLabels = labels; // set OpCode for loading hashtable with variables at runtime gc_context.RTVariablesTablePlace = RTVariablesTablePlace; RTVariablesTablePlace = new IndexedPlace(PlaceHolder.Argument, 1); // set Script Context place gc_context.ScriptContextPlace = ScriptContextPlace; ScriptContextPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgContext); // set Class Context place gc_context.ClassContextPlace = TypeContextPlace; TypeContextPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgIncluder); // set Self place gc_context.SelfPlace = SelfPlace; SelfPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgSelf); // set late static bind place gc_context.LateStaticBindTypePlace = LateStaticBindTypePlace; LateStaticBindTypePlace = null; // set Result place and return label gc_context.ResultPlace = ResultPlace; gc_context.ReturnLabel = ReturnLabel; ResultPlace = null; // set exception block nesting: gc_context.ExceptionBlockNestingLevel = ExceptionBlockNestingLevel; ExceptionBlockNestingLevel = 0; locationStack.PushGlobalCode(gc_context); }