/// <summary> /// Generate duck-type interface file for the specified AST. /// </summary> /// <param name="globalCode">Source AST</param> public void ProcessModule(GlobalCode globalCode) { currentModule = new DuckModule(globalCode.SourceUnit.SourceFile.RelativePath.ToString()); globalCode.VisitMe(this); moduleList.Add(currentModule); }
/// <summary> /// Visit global scope element and all children. /// </summary> /// <param name="x">GlobalCode.</param> public virtual void VisitGlobalCode(GlobalCode x) { VisitStatements(x.Statements); }
/// <summary> /// Visit global scope element and all children. /// </summary> /// <param name="x">GlobalCode.</param> public virtual void VisitGlobalCode(GlobalCode x) { VisitStatementList(x.Statements); }
/// <summary> /// Emits a load of the value stored to the result place if available. /// </summary> public void EmitRoutineEpilogue(GlobalCode globalCode, bool transient) { IncludingEx appendedInclusion; if (globalCode != null && (appendedInclusion = globalCode.NodeCompiler<IGlobalCodeCompiler>().AppendedInclusion) != null) { // marks the return label, however return value is ignored since it is // overriden by appended script's return value (TODO: HOW DOES PHP BEHAVE?): if (ResultPlace != null) il.MarkLabel(ReturnLabel); // IF (<is main script>) LOAD <appended file script>.Main(...): appendedInclusion.Emit(this); // returns the value retured by the appended script: il.Emit(OpCodes.Ret); } else { if (globalCode != null && !transient) { // returns default value of the Main routine: il.LoadLiteral(ScriptModule.DefaultMainReturnValue); il.Emit(OpCodes.Box, ScriptModule.DefaultMainReturnValue.GetType()); } else { // function or method contains no return statement: if (ReturnsPhpReference) il.Emit(OpCodes.Newobj, Constructors.PhpReference_Void); else il.Emit(OpCodes.Ldnull); } il.Emit(OpCodes.Ret); if (ResultPlace != null) { // there is a return statement branching to the ReturnLabel and returning value // stored in the ReturnPlace: il.MarkLabel(ReturnLabel); ResultPlace.EmitLoad(il); il.Emit(OpCodes.Ret); } } }