/// <summary> /// /// </summary> /// <param name="previousAction"></param> /// <param name="nextAction"></param> /// <param name="compiler"></param> /// <param name="method"></param> /// <param name="statements"></param> public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements) { string indexName = RepeatIndex.CodeName; CodeExpression c = new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(indexName), CodeBinaryOperatorType.LessThan, RepeatCount.GetReferenceCode(Method, statements, true)); CodeIterationStatement cis = new CodeIterationStatement(); cis.TestExpression = c; cis.InitStatement = new CodeVariableDeclarationStatement(typeof(int), indexName, new CodePrimitiveExpression(0)); cis.IncrementStatement = new CodeSnippetStatement(indexName + "++"); statements.Add(cis); if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { cil.LocalPointer.AddVariableDeclaration(cis.Statements); } } } SetWithinLoop(); Method.SubMethod.Push(this); CompilerUtil.AddSubMethod(method, this); bool bRet = base.OnExportCode(previousAction, nextAction, compiler, method, cis.Statements); Method.SubMethod.Pop(); bRet = CompilerUtil.FinishSubMethod(method, this, cis.Statements, bRet); return(bRet); }
public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements) { CodeExpression c; if (_logicExpression == null) { c = new CodePrimitiveExpression(true); } else { _logicExpression.PrepareForCompile(this.Method); c = _logicExpression.ExportCode(this.Method); } CodeIterationStatement cis = new CodeIterationStatement(); cis.TestExpression = c; if (_initAction != null && _initAction.Action != null) { CodeStatementCollection sts = new CodeStatementCollection(); _initAction.Action.ExportCode(null, null, compiler, Method, method, sts, false); if (sts.Count > 0) { for (int i = 0; i < sts.Count; i++) { if (!(sts[i] is CodeCommentStatement)) { cis.InitStatement = sts[i]; break; } } } else { cis.InitStatement = new CodeSnippetStatement(); } } else { cis.InitStatement = new CodeSnippetStatement(); } if (_increAction != null && _increAction.Action != null) { CodeStatementCollection sts = new CodeStatementCollection(); _increAction.Action.ExportCode(null, null, compiler, Method, method, sts, false); if (sts.Count > 0) { for (int i = 0; i < sts.Count; i++) { if (!(sts[i] is CodeCommentStatement)) { cis.IncrementStatement = sts[i]; break; } } } else { cis.IncrementStatement = new CodeSnippetStatement(); } } else { cis.IncrementStatement = new CodeSnippetStatement(); } statements.Add(cis); if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { cil.LocalPointer.AddVariableDeclaration(cis.Statements); } } } Method.SubMethod.Push(this); CompilerUtil.AddSubMethod(method, this); bool bRet = base.OnExportCode(previousAction, nextAction, compiler, method, cis.Statements); Method.SubMethod.Pop(); bRet = CompilerUtil.FinishSubMethod(method, this, cis.Statements, bRet); return(bRet); }
public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements) { bool bRet; if (_actionData == null) { _actionData = (ActionSubMethod)this.Method.GetActionInstance(_actId.ActionId); // (ActionSubMethod)compiler.ActionEventList.GetAction(_actId); } SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer; SubMethodInfo mi = smi.MethodInformation as SubMethodInfo; if (mi.IsForeach) { ParameterClassSubMethod p = mi.GetParameterType(0, smi, this); StringBuilder sb = new StringBuilder(); string s1 = smi.Owner.CodeName; CustomMethodParameterPointer cmpp = smi.Owner.Owner as CustomMethodParameterPointer; if (cmpp == null) { IObjectPointer op = smi.Owner; sb.Append(s1); while (!(op is ILocalvariable) && op.Owner != null && !(op.Owner is MethodClass) && op.Owner.Owner != null) { if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0) { s1 = op.Owner.CodeName; sb.Insert(0, "."); sb.Insert(0, s1); } op = op.Owner; } s1 = sb.ToString(); } string itemTypeString = null; if (mi.ItemType.IsGenericParameter) { CollectionPointer cp = smi.Owner as CollectionPointer; if (cp != null) { CustomPropertyPointer cpp = cp.Owner as CustomPropertyPointer; if (cpp != null) { DataTypePointer dtp = cpp.GetConcreteType(mi.ItemType); if (dtp != null) { itemTypeString = dtp.TypeString; } } } } if (string.IsNullOrEmpty(itemTypeString)) { itemTypeString = VPLUtil.GetTypeCSharpName(mi.ItemType); } string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}foreach({1} {2} in {3}) {{", Indentation.GetIndent(), itemTypeString, p.CodeName, s1); CodeStatement cis0 = new CodeSnippetStatement(s0); statements.Add(cis0); // if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { cil.LocalPointer.AddVariableDeclaration(statements); } } } // CodeStatementCollection sc = new CodeStatementCollection(); Method.SubMethod.Push(this); //smi); CompilerUtil.AddSubMethod(method, this); bRet = base.OnExportCode(previousAction, nextAction, compiler, method, sc); Method.SubMethod.Pop(); bRet = CompilerUtil.FinishSubMethod(method, this, sc, bRet); statements.AddRange(sc); // statements.Add(new CodeSnippetStatement(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}}}", Indentation.GetIndent()))); } else { CodeIterationStatement cis = new CodeIterationStatement(); cis.TestExpression = mi.GetTestExpression(smi, compiler, this.Method, method, statements, this.BranchId); cis.InitStatement = mi.GetInitStatement(smi, compiler, this.Method, method, statements, this.BranchId); cis.IncrementStatement = mi.GetIncrementalStatement(smi, compiler, this.Method, method, statements, this.BranchId); // Method.SubMethod.Push(this); //smi); CompilerUtil.AddSubMethod(method, this); if (_iconList != null) { foreach (ComponentIcon ci in _iconList) { ComponentIconLocal cil = ci as ComponentIconLocal; if (cil != null && cil.ScopeGroupId == this.BranchId) { cil.LocalPointer.AddVariableDeclaration(cis.Statements); } } } bRet = base.OnExportCode(previousAction, nextAction, compiler, method, cis.Statements); Method.SubMethod.Pop(); bRet = CompilerUtil.FinishSubMethod(method, this, cis.Statements, bRet); // // statements.Add(cis); } return(bRet); }