public override void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, System.CodeDom.CodeMemberMethod method, System.CodeDom.CodeStatementCollection statements, bool debug) { IMathExpression mathExp = MathExp; if (mathExp != null) { CodeExpression ceCondition = null; if (Condition != null) { ceCondition = Condition.ExportCode(methodToCompile); if (ceCondition != null) { ceCondition = CompilerUtil.ConvertToBool(Condition.DataType, ceCondition); } } CodeExpression ce = mathExp.ReturnCodeExpression(methodToCompile); if (ce != null) { if (ceCondition == null) { statements.Add(new CodeMethodReturnStatement(ce)); } else { CodeConditionStatement cd = new CodeConditionStatement(); cd.Condition = ceCondition; cd.TrueStatements.Add(new CodeMethodReturnStatement(ce)); statements.Add(cd); } } } }
public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { if (IsValid) { CodeExpression ceCondition = null; if (_condition != null) { ceCondition = _condition.ExportCode(methodToCompile); if (ceCondition != null) { ceCondition = CompilerUtil.ConvertToBool(_condition.DataType, ceCondition); } } CodeStatementCollection sts = statements; if (ceCondition != null) { CodeConditionStatement cs = new CodeConditionStatement(); cs.Condition = ceCondition; statements.Add(cs); sts = cs.TrueStatements; } CodeExpression right; if (_valType.ValueType == EnumValueType.ConstantValue) { right = _val.GetReferenceCode(methodToCompile, sts, true); } else { List <CodeExpression> ps = new List <CodeExpression>(); ps.Add(_valType.GetReferenceCode(methodToCompile, sts, true)); if (_val.ConstantValue != null) { CodeExpression[] pp = _val.ConstantValue.GetConstructorParameters(methodToCompile, sts); if (pp != null) { ps.AddRange(pp); } } right = new CodeCastExpression(_var.BaseClassType, new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Activator)), "CreateInstance", ps.ToArray()) ); } CodeExpression left = _var.GetReferenceCode(methodToCompile, sts, false); CodeVariableReferenceExpression cvre = left as CodeVariableReferenceExpression; CodeSnippetExpression cse = right as CodeSnippetExpression; if (cvre != null && cse != null && string.CompareOrdinal(cse.Value, string.Format(CultureInfo.InvariantCulture, "{0}++", cvre.VariableName)) == 0) { CodeExpressionStatement ces = new CodeExpressionStatement(right); sts.Add(ces); } else { CodeAssignStatement cas = new CodeAssignStatement(left, right); sts.Add(cas); } } }
public override void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { IMathExpression mathExp = MathExp; if (mathExp != null) { CodeExpression ceCondition = null; if (Condition != null) { ceCondition = Condition.ExportCode(methodToCompile); if (ceCondition != null) { ceCondition = CompilerUtil.ConvertToBool(Condition.DataType, ceCondition); } } CodeExpression ce = mathExp.ReturnCodeExpression(methodToCompile); if (ce != null) { CodeExpression target = null; CodeVariableDeclarationStatement output = null; if (nextAction != null) { if (nextAction.UseInput) { output = new CodeVariableDeclarationStatement(currentAction.OutputType.TypeString, currentAction.OutputCodeName, ce); statements.Add(output); } } IVariable v = mathExp.OutputVariable; if (v != null) { CodeStatement cs; target = v.ExportCode(methodToCompile); if (output != null) { cs = new CodeAssignStatement(target, new CodeVariableReferenceExpression(currentAction.OutputCodeName)); } else { cs = new CodeAssignStatement(target, ce); } if (ceCondition == null) { statements.Add(cs); } else { CodeConditionStatement cd = new CodeConditionStatement(); cd.Condition = ceCondition; cd.TrueStatements.Add(cs); statements.Add(cd); } } } } }
public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { if (IsValid) { CodeExpression ceCondition = null; if (_condition != null) { ceCondition = _condition.ExportCode(methodToCompile); if (ceCondition != null) { ceCondition = CompilerUtil.ConvertToBool(_condition.DataType, ceCondition); } } CodeStatementCollection sts = statements; if (ceCondition != null) { CodeConditionStatement cs = new CodeConditionStatement(); cs.Condition = ceCondition; statements.Add(cs); sts = cs.TrueStatements; } CodeExpression right; if (_valType.ValueType == EnumValueType.ConstantValue) { right = _val.GetReferenceCode(methodToCompile, sts, true); } else { List <CodeExpression> ps = new List <CodeExpression>(); ps.Add(_valType.GetReferenceCode(methodToCompile, sts, true)); if (_val.ConstantValue != null) { CodeExpression[] pp = _val.ConstantValue.GetConstructorParameters(methodToCompile, sts); if (pp != null) { ps.AddRange(pp); } } right = new CodeCastExpression(_var.ObjectType, new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Activator)), "CreateInstance", ps.ToArray()) ); } CodeExpression left = _var.GetReferenceCode(methodToCompile, sts, false); CodeAssignStatement cas = new CodeAssignStatement(left, right); sts.Add(cas); } }