/// <summary> /// generate local variables and code to do the calculation of the math. /// the calculation result is assigned to the variable this[4] /// </summary> /// <returns></returns> public override void ExportCodeStatements(IMethodCompile method) { MathNode.Trace("ExportCodeStatements for {0}", this.GetType()); //0:function //1:index //2:begin //3:end //4:sum OnPrepareVariable(method); CodeVariableReferenceExpression sum = new CodeVariableReferenceExpression(((IVariable)this[4]).CodeVariableName); CodeVariableDeclarationStatement p; if (((IVariable)this[4]).VariableType.Type.IsValueType) { p = new CodeVariableDeclarationStatement(((IVariable)this[4]).VariableType.Type, ((IVariable)this[4]).CodeVariableName); } else { p = new CodeVariableDeclarationStatement(((IVariable)this[4]).VariableType.Type, ((IVariable)this[4]).CodeVariableName, ValueTypeUtil.GetDefaultCodeByType(((IVariable)this[4]).VariableType.Type)); } method.MethodCode.Statements.Add(p); CodeExpression idx = this[1].ExportCode(method); CodeIterationStatement cis = new CodeIterationStatement( new CodeVariableDeclarationStatement(this[1].DataType.Type, ((IVariable)this[1]).CodeVariableName, this[2].ExportCode(method)), new CodeBinaryOperatorExpression(idx, CodeBinaryOperatorType.LessThanOrEqual, this[3].ExportCode(method)), new CodeAssignStatement(idx, new CodeBinaryOperatorExpression(idx, CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1))), new CodeStatement[] { new CodeAssignStatement(sum, new CodeBinaryOperatorExpression(sum, CodeBinaryOperatorType.Add, this[0].ExportCode(method))) }); method.MethodCode.Statements.Add(cis); }
public override CodeExpression ExportCode(IMethodCompile method) { if (_passin != null) { return(_passin); } string s = method.GetParameterCodeNameById(this.Parameter.ID); if (string.IsNullOrEmpty(s)) { MathNode.Trace("Argument '{0}' is not an argument for method '{1}'", ArgumentName, method.MethodName); return(ValueTypeUtil.GetDefaultCodeByType(Parameter.DataType.Type)); } else { MathNode.Trace("{0}.ExportCode maps {1} to {2}", this.GetType().Name, ArgumentName, s); return(new CodeArgumentReferenceExpression(s)); } }
public override CodeExpression ExportCode(IMethodCompile method) //) { CodeStatementCollection supprtStatements = method.MethodCode.Statements; if (this.UseDefaultValue) { if (_default == null) { MathNode.Trace("MathNodeParameter.ExportCode: Use default case 0:null"); return(ValueTypeUtil.GetDefaultCodeByType(this.DataType.Type)); } else { MathNode.Trace("MathNodeParameter.ExportCode: Use default case 1:{0}", _default); return(ObjectCreationCodeGen.ObjectCreationCode(_default)); } } else { if (this.InPort != null && this.InPort.LinkedPortID != 0) { MathNode.Trace("MathNodeParameter.ExportCode: call linked item"); IMathExpression rootContainer = this.root.RootContainer; if (rootContainer == null) { throw new MathException(XmlSerialization.FormatString("Parameter {0} not associated with a root container", this.TraceInfo)); } MathExpItem LinkedItem = rootContainer.GetItemByID(this.InPort.LinkedPortID); if (LinkedItem == null) { throw new MathException(string.Format("Linked Port ID {0} from ({1}) does not match an item", InPort.LinkedPortID, this.TraceInfo)); } CodeExpression ce = LinkedItem.ReturnCodeExpression(method); return(RaisDataType.GetConversionCode(LinkedItem.MathExpression.DataType, ce, this.DataType, supprtStatements)); } // MathNode.Trace("MathNodeParameter.ExportCode: call MathNodeVariable.ExportCode"); return(base.ExportCode(method)); } }
/// <summary> /// declare a variable and initialize it with default value. /// </summary> /// <param name="supprtStatements"></param> /// <param name="var"></param> public static void DeclareVariable(CodeStatementCollection supprtStatements, IVariable var) { if (var is MathNodeVariableDummy) { return; } if (!VariableDeclared(supprtStatements, var.CodeVariableName)) { MathNode.Trace("Declare variable {0}", var.TraceInfo); CodeVariableDeclarationStatement p; if (var.VariableType.Type.IsValueType) { p = new CodeVariableDeclarationStatement(new CodeTypeReference(var.VariableType.Type), var.CodeVariableName); } else { p = new CodeVariableDeclarationStatement(new CodeTypeReference(var.VariableType.Type), var.CodeVariableName, ValueTypeUtil.GetDefaultCodeByType(var.VariableType.Type)); } supprtStatements.Add(p); } }