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 Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug) { CodeExpression cmi; CodeExpression[] ps; if (parameters != null) { ps = new CodeExpression[parameters.Count]; parameters.CopyTo(ps, 0); } else { ps = new CodeExpression[] { }; } CodeExpression oce; if (_returnReceiver != null) { if (_returnReceiver.BaseClassType.IsArray) { if (ps.Length == 1) { oce = new CodeArrayCreateExpression(_returnReceiver.TypeString, ps[0]); } else { oce = new CodeArrayCreateExpression(_returnReceiver.TypeString, ps); } } else { //currently custom generic type is not supported oce = new CodeObjectCreateExpression(_returnReceiver.GetCodeTypeReference(), ps); } } else { oce = new CodeObjectCreateExpression(ReturnType, ps); } cmi = oce; CodeExpression cr = _returnReceiver.GetReferenceCode(methodToCompile, statements, true); CodeAssignStatement cas = new CodeAssignStatement(cr, cmi); statements.Add(cas); }