public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data) { string indexName = RepeatIndex.CodeName; methodCode.Add(Indentation.GetIndent()); methodCode.Add("for("); methodCode.Add(indexName); methodCode.Add("=0;"); methodCode.Add(indexName); methodCode.Add("<"); methodCode.Add(RepeatCount.CreateJavaScript(methodCode)); methodCode.Add(";"); methodCode.Add(indexName); methodCode.Add("++) {\r\n"); Indentation.IndentIncrease(); string indents = Indentation.GetIndent(); StringCollection sc = new StringCollection(); if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { sc.Add(indents); sc.Add("$"); sc.Add(cil.LocalPointer.CodeName); sc.Add("="); sc.Add(ValueTypeUtil.GetDefaultPhpScriptValueByType(cil.LocalPointer.BaseClassType)); sc.Add(";\r\n"); } } } SetWithinLoop(); Method.SubMethod.Push(this); data.AddSubMethod(this); bool bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, sc, data); Method.SubMethod.Pop(); // for (int i = 0; i < sc.Count; i++) { methodCode.Add(sc[i]); } Indentation.IndentDecrease(); methodCode.Add(Indentation.GetIndent()); methodCode.Add("}\r\n"); return(bRet); }
public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data) { string c; if (_logicExpression == null) { c = "true"; } else { _logicExpression.PrepareForCompile(this.Method); c = _logicExpression.CreatePhpScript(methodCode); } methodCode.Add(Indentation.GetIndent()); string initCodeStr = null; string increCodeStr = null; if (_initAction != null && _initAction.Action != null) { StringCollection initCode = new StringCollection(); _initAction.Action.ExportPhpScriptCode(null, null, methodCode, initCode, data); StringBuilder sb = new StringBuilder(); for (int i = 0; i < initCode.Count; i++) { sb.Append(initCode[i]); } initCodeStr = sb.ToString().Replace("\r\n", ""); } if (_increAction != null && _increAction.Action != null) { StringCollection increCode = new StringCollection(); _increAction.Action.ExportPhpScriptCode(null, null, methodCode, increCode, data); StringBuilder sb = new StringBuilder(); for (int i = 0; i < increCode.Count; i++) { sb.Append(increCode[i]); } increCodeStr = sb.ToString().Replace("\r\n", ""); } if (string.IsNullOrEmpty(initCodeStr)) { initCodeStr = ";"; } if (!string.IsNullOrEmpty(increCodeStr)) { increCodeStr = increCodeStr.Trim(); while (increCodeStr.EndsWith(";", StringComparison.Ordinal)) { increCodeStr = increCodeStr.Substring(0, increCodeStr.Length - 1); increCodeStr = increCodeStr.Trim(); } } methodCode.Add("for("); methodCode.Add(initCodeStr); methodCode.Add(c); methodCode.Add(";"); methodCode.Add(increCodeStr); methodCode.Add(") {\r\n"); Indentation.IndentIncrease(); string indents = Indentation.GetIndent(); StringCollection sc = new StringCollection(); if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { sc.Add(indents); sc.Add("$"); sc.Add(cil.LocalPointer.CodeName); sc.Add("="); sc.Add(ValueTypeUtil.GetDefaultPhpScriptValueByType(cil.LocalPointer.BaseClassType)); sc.Add(";\r\n"); } } } Method.SubMethod.Push(this); data.AddSubMethod(this); bool bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, sc, data); Method.SubMethod.Pop(); // for (int i = 0; i < sc.Count; i++) { methodCode.Add(sc[i]); } Indentation.IndentDecrease(); methodCode.Add(Indentation.GetIndent()); methodCode.Add("}\r\n"); return(bRet); }
public bool ExportPhpScriptCode(StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data) { bool bRet = false; MathNode.Trace("BranchList.ExportPhpScriptCode. Method {0}, action blocks {1}================", _method.Name, this.Count); //create code threads List <ActionBranch> independentThreads; if (_independentThreads == null) { independentThreads = FindoutActionThreads(true); } else { independentThreads = _independentThreads; } IsMultiThreads = (independentThreads.Count > 1); //the case of Count == 0 (empty method) is handled by MethodClass.ExportCode if (independentThreads.Count > 0) { int k0 = 0; // main thread index this.ActionThreads.Clear(); foreach (ActionBranch a in independentThreads) { _threads.Add(a.BranchId, a); } for (int k = 0; k < independentThreads.Count; k++) { if (independentThreads[k].IsMainThread) { k0 = k; break; } } if (k0 == 0) { independentThreads[0].IsMainThread = true; } this.MainThreadId = independentThreads[k0].BranchId; List <UInt32> usedBranches = new List <uint>(); for (int k = 0; k < independentThreads.Count; k++) { independentThreads[k].IsMainThread = (k == k0); independentThreads[k].SetIsMainThreadForSubBranches(usedBranches); } //javascript does not support threading for (int k = 0; k < independentThreads.Count; k++) { if (k != k0) { ActionBranch ab = independentThreads[k]; ab.IsMainThread = false; ////method contents: a single thread ab.ExportPhpScriptCode(null, null, jsCode, methodCode, data); } } //main thread code bRet = independentThreads[k0].ExportPhpScriptCode(null, null, jsCode, methodCode, data); // if (_method == null) { MathNode.LogError("method is null"); } else // { if (_method.ReturnValue != null) { if (!typeof(void).Equals(_method.ReturnValue.ObjectType)) { //check whether all branches ends with a method return statement if (!independentThreads[k0].AllBranchesEndWithMethodReturnStatement()) { methodCode.Add("return "); methodCode.Add(ValueTypeUtil.GetDefaultPhpScriptValueByType(_method.ReturnValue.ObjectType)); methodCode.Add(";\r\n"); } } } } } MathNode.Trace("End of BranchList.ExportPhpScriptCode. Method {0}================", _method.Name); return(bRet); }