/// <summary> /// get the goto branch in sub-method by branch Id /// </summary> /// <param name="method"></param> /// <param name="custMethod"></param> /// <param name="branchId"></param> /// <returns></returns> public static MethodSegment GetGotoBranch(CodeMemberMethod method, MethodClass custMethod, UInt32 branchId) { Dictionary <UInt32, MethodSegment> list = null; if (custMethod.SubMethod.Count > 0) { IMethod0 m0 = custMethod.SubMethod.Peek(); list = AddSubMethod(method, m0); } else { if (method.UserData.Contains(GOTOBRANCHES)) { list = (Dictionary <UInt32, MethodSegment>)method.UserData[GOTOBRANCHES]; } } if (list != null) { MethodSegment ms; if (list.TryGetValue(branchId, out ms)) { return(ms); } } return(null); }
public void RemoveSubMethod(IMethod0 subMethod) { if (_subbranches != null) { if (_subbranches.ContainsKey(subMethod)) { _subbranches.Remove(subMethod); } } }
public override string GetPhpScriptReferenceCode(StringCollection code) { if (this.Method == null) { DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. Method not found. ParameterID:{0}, ActionID:{1}, ClassId:{2}", this.ParameterID, ActionId, this.ClassId); } else { SubMethodInfoPointer smi = this.Method as SubMethodInfoPointer; if (smi == null) { MethodClass mc = this.Method as MethodClass; if (ActionId != 0 && mc != null && mc.ActionList != null) { IAction act = mc.ActionList.GetActionById(ActionId); if (act != null) { smi = act.ActionMethod as SubMethodInfoPointer; } } } if (smi == null) { DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. method [{0}][{1}] found by parameter [{2}] is not a SubMethodInfoPointer", this.Method.MethodName, this.Method.ObjectKey, this.ParameterID); } else { if (this.ActionBranch == null) { MethodClass mc = this.Method as MethodClass; if (mc != null && mc.SubMethod != null && mc.SubMethod.Count > 0) { IMethod0 m0 = mc.SubMethod.Peek(); AB_SubMethodAction asa = m0 as AB_SubMethodAction; if (asa != null) { this.SetActionBranch(asa); } } } if (this.ActionBranch == null) { DesignUtil.WriteToOutputWindowAndLog("GetPhpScriptReferenceCode failed. parameter [{2}] for method [{0}][{1}] missing ActionBranch", this.Method.MethodName, this.Method.ObjectKey, this.ParameterID); } else { SubMethodInfo mi = smi.MethodInformation as SubMethodInfo; string target = smi.Owner.GetPhpScriptReferenceCode(code); return(string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", target, mi.GetIndexCodePHP(smi, this.ActionBranch.BranchId))); } } } return(CodeName); }
public static void RemoveSubMethod(CodeMemberMethod method, IMethod0 subMethod) { Dictionary <IMethod0, Dictionary <UInt32, MethodSegment> > subbranches = (Dictionary <IMethod0, Dictionary <UInt32, MethodSegment> >)method.UserData[SUBMETHODBRANCHES]; if (subbranches != null) { if (subbranches.ContainsKey(subMethod)) { subbranches.Remove(subMethod); } } }
/// <summary> /// if currently in submethod then add goto branch to the sub method; otherwise add it to the method scope /// </summary> /// <param name="method"></param> /// <param name="custMethod"></param> /// <param name="branchId"></param> /// <param name="statements"></param> public static void AddGotoBranch(CodeMemberMethod method, MethodClass custMethod, UInt32 branchId, MethodSegment statements, UInt32 groupId) { Dictionary <UInt32, MethodSegment> branches = null; if (groupId != 0) { Dictionary <UInt32, Dictionary <UInt32, MethodSegment> > groups; if (method.UserData.Contains(GOTOBRANCHES_Group)) { groups = (Dictionary <UInt32, Dictionary <UInt32, MethodSegment> >)method.UserData[GOTOBRANCHES_Group]; if (groups == null) { groups = new Dictionary <uint, Dictionary <uint, MethodSegment> >(); method.UserData[GOTOBRANCHES_Group] = groups; } } else { groups = new Dictionary <uint, Dictionary <uint, MethodSegment> >(); method.UserData.Add(GOTOBRANCHES_Group, groups); } if (!groups.TryGetValue(groupId, out branches)) { branches = new Dictionary <uint, MethodSegment>(); groups.Add(groupId, branches); } } else { if (custMethod.SubMethod.Count > 0) { IMethod0 m0 = custMethod.SubMethod.Peek(); branches = AddSubMethod(method, m0); } else { branches = (Dictionary <UInt32, MethodSegment>)method.UserData[GOTOBRANCHES]; if (branches == null) { branches = new Dictionary <uint, MethodSegment>(); method.UserData.Add(GOTOBRANCHES, branches); } } } if (!branches.ContainsKey(branchId)) { branches.Add(branchId, statements); } }
public Dictionary <UInt32, JsMethodSegment> AddSubMethod(IMethod0 subMethod) { if (_subbranches == null) { _subbranches = new Dictionary <IMethod0, Dictionary <uint, JsMethodSegment> >(); } Dictionary <UInt32, JsMethodSegment> branches; if (!_subbranches.TryGetValue(subMethod, out branches)) { branches = new Dictionary <uint, JsMethodSegment>(); _subbranches.Add(subMethod, branches); } return(branches); }
public override string ToString() { if (Owner != null) { IMethod0 m = Owner.GetOwnerMethod(this.MethodId) as IMethod0; if (m != null) { MethodName = m.MethodName; } } if (string.IsNullOrEmpty(MethodName)) { return(string.Empty); } return(MethodName); }
public static bool FinishSubMethod(CodeMemberMethod method, IMethod0 subMethod, CodeStatementCollection statements, bool completed) { Dictionary <UInt32, MethodSegment> gotoBranches = GetGotoBranches(method, subMethod); RemoveSubMethod(method, subMethod); if (gotoBranches != null && gotoBranches.Count > 0) { string lb = "L_" + Guid.NewGuid().GetHashCode().ToString("x"); bool bUseLabel = false; if (!completed) { //if the last method code is not a return then add a default method return //if at least one of the branches in the method (not including goBranches) is not ended (method return or go to) bUseLabel = true; statements.Add(new CodeGotoStatement(lb)); } foreach (KeyValuePair <UInt32, MethodSegment> kv in gotoBranches) { //if the last statement for this gotoBranch is not a method return then add a default one if (!kv.Value.Completed) { bUseLabel = true; kv.Value.Statements.Add(new CodeGotoStatement(lb)); } //append the label to the end of method code statements.Add(new CodeLabeledStatement(ActionBranch.IdToLabel(kv.Key))); if (kv.Value.Statements.Count == 0) { statements.Add(new CodeSnippetStatement(";")); } //append the staments belonging to this gotoBranch to the end of the method for (int i = 0; i < kv.Value.Statements.Count; i++) { statements.Add(kv.Value.Statements[i]); } } if (bUseLabel) { statements.Add(new CodeLabeledStatement(lb)); statements.Add(new CodeSnippetStatement(";")); } } return(completed); }
/// <summary> /// get goto branches in sub-method scope /// </summary> /// <param name="method"></param> /// <param name="subMethod"></param> /// <returns></returns> public static Dictionary <UInt32, MethodSegment> GetGotoBranches(CodeMemberMethod method, IMethod0 subMethod) { Dictionary <UInt32, MethodSegment> branches = null; Dictionary <IMethod0, Dictionary <UInt32, MethodSegment> > subbranches = (Dictionary <IMethod0, Dictionary <UInt32, MethodSegment> >)method.UserData[SUBMETHODBRANCHES]; if (subbranches != null) { subbranches.TryGetValue(subMethod, out branches); } return(branches); }
public static Dictionary <UInt32, MethodSegment> AddSubMethod(CodeMemberMethod method, IMethod0 subMethod) { Dictionary <IMethod0, Dictionary <UInt32, MethodSegment> > subbranches = (Dictionary <IMethod0, Dictionary <UInt32, MethodSegment> >)method.UserData[SUBMETHODBRANCHES]; if (subbranches == null) { subbranches = new Dictionary <IMethod0, Dictionary <uint, MethodSegment> >(); method.UserData.Add(SUBMETHODBRANCHES, subbranches); } Dictionary <UInt32, MethodSegment> branches; if (!subbranches.TryGetValue(subMethod, out branches)) { branches = new Dictionary <uint, MethodSegment>(); subbranches.Add(subMethod, branches); } return(branches); }