public override string CreatePhpScript(StringCollection method) { MathNode.Trace("{0}.CreatePhpScript", this.GetType().Name); string e = this[0].CreatePhpScript(method); return(MathNode.FormString("!({0})", e)); }
public override string CreatePhpScript(StringCollection method) { if (!string.IsNullOrEmpty(_passinPhp)) { MathNode.Trace("MathNodeVariable.CreatePhpScript returns _passinPhp"); return(_passinPhp); } string code = this.MathExpression.GetMappedPhpScriptCode(this, method); if (code != null) { return(code); } //if this variable links to a method parameter then the code is a reference to that parameter if (this.InPort != null) { MathExpItem item = this.root.RootContainer.GetItemByID(this.InPort.LinkedPortID); if (item != null) { MathNode.Trace("variable:{0} linked to MathExpItem: {1}", this.TraceInfo, item.MathExpression.TraceInfo); return(item.CreatePhpScript(method)); } } if (!NoAutoDeclare) { DeclarePhpScriptVariable(method, this); } MathNode.Trace("MathNodeVariable.CreateJavaScript returns variable reference to {0}", this.CodeVariableName); return(this.CodeVariableName); }
public override string CreateJavaScript(StringCollection method) { MathNode.Trace("{0}.CreateJavaScript", this.GetType().Name); List <string> args = new List <string>(); ArguementsJS(method, args); if (args.Count <= 0) { return(""); } else if (args.Count == 1) { return(args[0]); } else { StringBuilder sb = new StringBuilder("''.concat("); sb.Append(args[0]); for (int i = 1; i < args.Count; i++) { sb.Append(","); sb.Append(args[i]); } sb.Append(")"); return(sb.ToString()); } }
public override CodeExpression ExportCode(IMethodCompile method) { CodeStatementCollection supprtStatements = method.MethodCode.Statements; if (_passin != null) { MathNode.Trace("MathNodeVariable.ExportCode returns _passin"); return(_passin); } CodeExpression code = this.MathExpression.GetMappedCode(this, method, supprtStatements, true); if (code != null) { return(code); } //if this variable links to a method parameter then the code is a reference to that parameter if (this.InPort != null) { MathExpItem item = this.root.RootContainer.GetItemByID(this.InPort.LinkedPortID); if (item != null) { MathNode.Trace("variable:{0} linked to MathExpItem: {1}", this.TraceInfo, item.MathExpression.TraceInfo); return(item.ReturnCodeExpression(method)); } } if (!NoAutoDeclare) { DeclareVariable(supprtStatements, this); } MathNode.Trace("MathNodeVariable.ExportCode returns variable reference to {0}", this.CodeVariableName); return(new CodeVariableReferenceExpression(this.CodeVariableName)); }
public override void ExportPhpScriptCodeStatements(StringCollection method) { MathNode.Trace("ExportPhpScriptCodeStatements for {0}", this.GetType()); //0: start //1: end //2: function //3: dx IsParam //4: sum IsLocal //5: summing index IsLocal IsParam base.ExportPhpScriptCodeStatements(method); //assign code expression to all x in the function OnPreparePhpScriptVariable(method); MathNodeVariable.DeclarePhpScriptVariable(method, (IVariable)this[4]); string sum = ((IVariable)this[4]).CodeVariableName; method.Add(MathNode.FormString("{0}=0;\r\n", sum)); string c5 = this.GetParameterCodePhp(method, 5); string f1 = MathNode.FormString("for({0}=1;{1}<={2}-1;({1})++)\r\n{\r\n"); method.Add(f1); method.Add(MathNode.FormString("\t{0}={0} + {1};\r\n", sum, this.GetParameterCodePhp(method, 2))); method.Add("}\r\n"); //clear code expression to all x in the function this[2].AssignPhpScriptCodeExp(null, ((MathNodeVariable)this[3]).CodeVariableName); }
public override System.CodeDom.CodeExpression ExportCode(IMethodCompile method) { int n = Branches; MathNode.Trace("{0}.ExportCode: reference to variable '{1}'", this.GetType().Name, ((IVariable)this[n + 1]).CodeVariableName); return(new CodeVariableReferenceExpression(((IVariable)this[n + 1]).CodeVariableName)); }
public override CodeExpression ExportCode(IMethodCompile method) { MathNode.Trace("{0}.ExportCode", this.GetType().Name); int n = ChildNodeCount; CodeExpression[] ps; if (n > 0) { ps = new CodeExpression[n]; for (int i = 0; i < n; i++) { ps[i] = this[i].ExportCode(method); } } else { ps = new CodeExpression[] { }; } if (_targetObject == null) { _targetObject = new CodeThisReferenceExpression(); } CodeMethodInvokeExpression e = new CodeMethodInvokeExpression( _targetObject, _functionName, ps); return(e); }
/// <summary> /// find linked node and use that node's code. /// if not found then use default value /// </summary> /// <returns></returns> public override System.CodeDom.CodeExpression ExportCode(IMethodCompile method) { MathNode.Trace("{0}.ExportCode", this.GetType().Name); if (this.InPort != null) { if (this.InPort.LinkedPortID != 0) { MathExpItem mathParent = root.ContainerMathItem; if (mathParent == null) { throw new MathException(XmlSerialization.FormatString("ExportCode for Default value: Linked port ID {0}. MathNodeRoot missing container.", this.InPort.LinkedPortID)); } if (mathParent.Parent == null) { throw new MathException(XmlSerialization.FormatString("ExportCode for Default value: Linked port ID {0}. MathExpItem missing container.", this.InPort.LinkedPortID)); } MathExpItem item = mathParent.Parent.GetItemByID(this.InPort.LinkedPortID); if (item == null) { throw new MathException(XmlSerialization.FormatString("ExportCode for Default value: Linked port ID {0} does not point to a valid port", this.InPort.LinkedPortID)); } return(item.ReturnCodeExpression(method)); } } return(ValueTypeUtil.GetDefaultValueByType(this.DataType.Type)); }
public override string CreatePhpScript(StringCollection method) { int n = Branches; MathNode.Trace("{0}.CreatePhpScript: reference to variable '{1}'", this.GetType().Name, ((IVariable)this[n + 1]).CodeVariableName); return(((IVariable)this[n + 1]).CodeVariableName); }
public override void ExportCodeStatements(IMethodCompile method) { MathNode.Trace("ExportCodeStatements for {0}", this.GetType()); //0: start //1: end //2: function //3: dx IsParam //4: sum IsLocal //5: summing index IsLocal IsParam base.ExportCodeStatements(method); //assign code expression to all x in the function OnPrepareVariable(method); MathNodeVariable.DeclareVariable(method.MethodCode.Statements, (IVariable)this[4]); CodeVariableReferenceExpression sum = new CodeVariableReferenceExpression(((IVariable)this[4]).CodeVariableName); method.MethodCode.Statements.Add(new CodeAssignStatement(sum, new CodePrimitiveExpression(0))); CodeExpression c5 = this.GetParameterCode(method, 5); CodeIterationStatement cis = new CodeIterationStatement( new CodeVariableDeclarationStatement(this[5].DataType.Type, ((IVariable)this[5]).CodeVariableName, new CodePrimitiveExpression(1)), new CodeBinaryOperatorExpression(c5, CodeBinaryOperatorType.LessThanOrEqual, new CodePrimitiveExpression(_intervals - 1)), new CodeAssignStatement(c5, new CodeBinaryOperatorExpression(c5, CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1))), new CodeStatement[] { new CodeAssignStatement(sum, new CodeBinaryOperatorExpression(sum, CodeBinaryOperatorType.Add, this.GetParameterCode(method, 2))) }); method.MethodCode.Statements.Add(cis); //clear code expression to all x in the function this[2].AssignCodeExp(null, ((MathNodeVariable)this[3]).CodeVariableName); }
public override void ExportCodeStatements(IMethodCompile method) { RaisDataType targetType = this[0].DataType; RaisDataType sourceType = this[1].DataType; Type target = targetType.Type; Type source = sourceType.Type; if (target.Equals(source)) { MathNode.Trace("MathNodeAssign, code 1: same type:{0}", target); method.MethodCode.Statements.Add(new CodeAssignStatement(this[0].ExportCode(method), this[1].ExportCode(method))); } else { MathNode.Trace("MathNodeAssign"); CodeExpression code = RaisDataType.GetConversionCode(sourceType, this[1].ExportCode(method), targetType, method.MethodCode.Statements); if (code != null) { method.MethodCode.Statements.Add(new CodeAssignStatement(this[0].ExportCode(method), code)); } else { if (!target.Equals(typeof(void))) { } } } }
public override string CreateJavaScript(StringCollection method) { MathNode.Trace("{0}.CreateJavaScript", this.GetType().Name); int n = ChildNodeCount; string[] ps; if (n > 0) { ps = new string[n]; for (int i = 0; i < n; i++) { this[i].CompileDataType = new RaisDataType(typeof(int)); ps[i] = this[i].CreateJavaScript(method); } if (n == 1) { return(string.Format(CultureInfo.InvariantCulture, "Math.floor(Math.random() * {0})", ps[0])); } else { return(string.Format(CultureInfo.InvariantCulture, "{0} + Math.floor(Math.random() * {1})", ps[0], ps[1])); } } else { return("Math.floor(Math.random())"); } }
public override CodeExpression ExportCode(IMethodCompile method) { MathNode.Trace("{0}.ExportCode", this.GetType().Name); int n = ChildNodeCount; CodeExpression[] ps; if (n > 0) { ps = new CodeExpression[n]; for (int i = 0; i < n; i++) { this[i].CompileDataType = new RaisDataType(typeof(int)); ps[i] = this[i].ExportCode(method); } } else { ps = new CodeExpression[] { }; } CodeExpression[] cp = new CodeExpression[1]; cp[0] = new CodeMethodInvokeExpression(new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Guid)), "NewGuid", new CodeExpression[] { } ), "GetHashCode", new CodeExpression[] { }); CodeMethodInvokeExpression e = new CodeMethodInvokeExpression( new CodeObjectCreateExpression(typeof(Random), cp), "Next", ps); return(e); }
/// <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) { MathNode.Trace("{0}.ExportCode", this.GetType().Name); CodeExpression e1 = this[0].ExportCode(method); CodeExpression e2 = this[1].ExportCode(method); return(new CodeBinaryOperatorExpression(e1, operaterType, e2)); }
public override CodeExpression ExportCode(IMethodCompile method) { MathNode.Trace("{0}.ExportCode", this.GetType().Name); if (this.StringLength <= 0) { this.StringLength = 10; } return(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(WinUtil)), "GetRandomString", new CodePrimitiveExpression(this.StringLength))); }
/// <summary> /// create conversion code /// </summary> /// <param name="sourceType"></param> /// <param name="sourceCode"></param> /// <param name="targetType"></param> /// <returns>conversion code converting sourceCode to the targetType</returns> public static CodeExpression GetConversionCode(RaisDataType sourceType, CodeExpression sourceCode, RaisDataType targetType, CodeStatementCollection supprtStatements) { CodeExpression codeRet; if (sourceType.IsSameType(targetType)) { return(sourceCode); } if (targetType.IsLibType || sourceType.IsLibType) { if (MathNode.GetTypeConversion != null) { return(MathNode.GetTypeConversion(targetType.Type, sourceCode, sourceType.Type, supprtStatements)); } return(CastOrConvert(sourceCode, sourceType.Type, targetType.Type, supprtStatements)); } string srcType = sourceType.DevType.TypeString; string tgtType = targetType.DevType.TypeString; if (srcType.StartsWith(tgtType)) { return(sourceCode); } if (tgtType.StartsWith(srcType)) { return(new CodeCastExpression(tgtType, VPLUtil.GetCoreExpressionFromCast(sourceCode))); } TypeConverter converter = TypeDescriptor.GetConverter(targetType.Type); if (converter.CanConvertFrom(sourceType.Type)) { MathNode.AddImportLocation(typeof(TypeConverter).Assembly.Location); string converterName = "conv" + targetType.Type.Name; if (!MathNodeVariable.VariableDeclared(supprtStatements, converterName)) { CodeVariableDeclarationStatement cs1 = new CodeVariableDeclarationStatement( typeof(TypeConverter), converterName, new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(TypeDescriptor)), "GetConverter", new CodeExpression[] { new CodeSnippetExpression("typeof(" + tgtType + ")") })); supprtStatements.Add(cs1); } //================================================= // codeRet = new CodeCastExpression(tgtType, new CodeMethodInvokeExpression( new CodeVariableReferenceExpression(converterName), "ConvertFrom", new CodeExpression[] { sourceCode })); MathNode.Trace("\tcode 102: source type:{0}, target type:{1} result=converter.ConvertFrom(code);", sourceType, targetType); } else { codeRet = CastOrConvert(sourceCode, sourceType.Type, targetType.Type, supprtStatements); } return(codeRet); }
public override string CreatePhpScript(StringCollection method) { MathNode.Trace("{0}.CreatePhpScript", this.GetType().Name); MathNodeVariable var = (MathNodeVariable)this[0]; var.VariableType = this.DataType; string e = this[0].CreatePhpScript(method); return(string.Format(CultureInfo.InvariantCulture, "({0})++", e)); }
public void LoadData(ActionList actions, MethodClass method, LimnorProject project, MethodDesignerHolder view) { _viewer = view; _actions = actions; _method = method; _project = project; _loaded = false; this.Text = string.Format("Actions - {0}", actions.Name); #if DEBUG MathNode.Trace("End of DlgActionList.LoadData"); #endif }
/// <summary> /// set NextActions and PreviousActions properties before compiling /// </summary> public override void LinkActions(BranchList branches) { if (_list != null) { for (int i = 1; i < _list.Count; i++) { MathNode.Trace("link action string [{0},{1}] <-> [{2},{3}]", _list[i - 1].BranchId, _list[i - 1].Name, _list[i].BranchId, _list[i].Name); _list[i - 1].SetNextAction(_list[i]); _list[i].SetPreviousAction(_list[i - 1]); } } }
public override CodeExpression ExportCode(IMethodCompile method) { MathNode.Trace("{0}.ExportCode", this.GetType().Name); CodeExpression e = this[0].ExportCode(method); if (!this[0].DataType.Type.Equals(typeof(bool))) { e = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Convert)), "ToBoolean", new CodeExpression[] { e }); } return(new CodeBinaryOperatorExpression(e, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(false))); }
public override CodeExpression ExportCode(MethodType method) { CodeStatementCollection supprtStatements = method.MethodCode.Statements; if (!MathNodeVariable.VariableDeclared(supprtStatements, this.CodeVariableName)) { MathNode.Trace("Declare variable {0}", this.TraceInfo); supprtStatements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference(VariableType.ObjectType), CodeVariableName, ValueTypeUtil.GetDefaultCodeByType(VariableType.ObjectType))); } MathNode.Trace("MathNodeVar.ExportCode returns variable reference to {0}", this.CodeVariableName); return(new CodeVariableReferenceExpression(this.CodeVariableName)); }
protected override void OnPrepareVariable(IMethodCompile method) { MathNode.Trace("OnPrepareVariable for {0}", this.GetType()); CodeExpression cp = new CodeBinaryOperatorExpression(this.GetParameterCode(method, 0), CodeBinaryOperatorType.Add, new CodeBinaryOperatorExpression(this.GetParameterCode(method, 5), CodeBinaryOperatorType.Multiply, new CodeBinaryOperatorExpression( new CodeBinaryOperatorExpression(this.GetParameterCode(method, 1), CodeBinaryOperatorType.Subtract, this.GetParameterCode(method, 0)), CodeBinaryOperatorType.Divide, new CodePrimitiveExpression(_intervals)))); //this[3] is the x, this[2] is the function //for all x in the function, the code expression is cp this[2].AssignCodeExp(cp, ((MathNodeVariable)this[3]).CodeVariableName); }
protected void OnPhpScriptPrepareVariable(StringCollection method) { MathNode.Trace("OnPhpScriptPrepareVariable for {0}", this.GetType()); string s0 = MathNode.FormString("{0} - {1}", this.GetParameterCodePhp(method, 1), this.GetParameterCodePhp(method, 0)); string s1 = MathNode.FormString("({0}) / {1}", s0, _intervals); string s2 = MathNode.FormString("({0}) * ({1})", this.GetParameterCodePhp(method, 5), s1); string s3 = MathNode.FormString("{0} + {1}", this.GetParameterCodePhp(method, 0), s2); //this[3] is the x, this[2] is the function //for all x in the function, the code expression is cp //this[2].AssignCodeExp(cp, ((MathNodeVariable)this[3]).CodeVariableName); this[2].AssignPhpScriptCodeExp(s3, ((MathNodeVariable)this[3]).CodeVariableName); }
public void ExportClientServerCode(ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data) { MathNode.Trace("BranchList.ExportJavaScriptCode. 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); } //client/server does not support threading, process all threads one by one for (int k = 0; k < independentThreads.Count; k++) { independentThreads[k].ExportClientServerCode(null, null, compiler, method, statements, jsCode, methodCode, data); } } }
void miEdit_Click(object sender, EventArgs e) { FormProgress.ShowProgress("Loading action editor, please wait ..."); #if DEBUG MathNode.Trace("Loading action editor"); #endif InitializeInput(); #if DEBUG MathNode.Trace("End of InitializeInput"); #endif // OnEditAction(); FormProgress.HideProgress(); }
public override CodeExpression ExportCode(IMethodCompile method) { MathNode.Trace("{0}.ExportCode", this.GetType().Name); CodeExpression[] ps = new CodeExpression[2]; ps[0] = new CodePrimitiveExpression(33); ps[1] = new CodePrimitiveExpression(123); CodeExpression[] cp = new CodeExpression[1]; cp[0] = new CodeMethodInvokeExpression(new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Guid)), "NewGuid", new CodeExpression[] { } ), "GetHashCode", new CodeExpression[] { }); CodeMethodInvokeExpression e = new CodeMethodInvokeExpression( new CodeObjectCreateExpression(typeof(Random), cp), "Next", ps); return(new CodeCastExpression(typeof(char), e)); }
/// <summary> /// it should be a reference to the object /// </summary> /// <returns></returns> public override CodeExpression ExportCode(IMethodCompile method) { MathNode.Trace("{0}.ExportCode for {1}", this.GetType().Name, _value); if (_value == null) { throw new MathException("object reference is not set"); } IRaisCodeCompiler cc = (IRaisCodeCompiler)MathNode.GetService(typeof(IRaisCodeCompiler)); if (cc == null) { throw new MathException("IRaisCodeCompiler is not available"); } return(_value.ExportCode(cc.CurrentXPath)); }
public override string CreatePhpScript(StringCollection method) { MathNode.Trace("{0}.CreatePhpScript for {1}", this.GetType().Name, _value); if (_value == null) { throw new MathException("object reference is not set"); } IRaisCodeCompiler cc = (IRaisCodeCompiler)MathNode.GetService(typeof(IRaisCodeCompiler)); if (cc == null) { throw new MathException("IRaisCodeCompiler is not available"); } return(_value.CreatePhpScript(method, cc.CurrentXPath)); }
public static void HideProgress() { #if DEBUG MathNode.Trace("Unloading progress message"); #endif if (_form != null) { if (_form.IsDisposed || _form.Disposing) { _form = null; } } if (_form != null) { _form.Close(); } }