public void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { CodeAssignStatement cas = new CodeAssignStatement(); cas.Left = SetProperty.GetReferenceCode(methodToCompile); if (cas.Left == null) { compiler.AddError("Error: CustomSetter missing property"); } else { CodeExpression rt = Value.GetReferenceCode(methodToCompile); CodeMethodReferenceExpression cmr = rt as CodeMethodReferenceExpression; if (cmr != null) { rt = new CodeMethodInvokeExpression(cmr); } if (nextAction != null && nextAction.UseInput) { CodeVariableDeclarationStatement output = new CodeVariableDeclarationStatement( currentAction.OutputType.TypeString, currentAction.OutputCodeName, rt); statements.Add(output); rt = new CodeVariableReferenceExpression(currentAction.OutputCodeName); } cas.Right = rt; statements.Add(cas); } }
public CodeStatement[] ExportStatements(ILimnorCodeCompiler compiler, IMethodCompile methodToCompile) { List <CodeStatement> ss = new List <CodeStatement>(); //TBD: create statements for _list return(ss.ToArray()); }
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); } } }
/// <summary> /// generate code: /// if( {event name} != null) /// { /// {event name}(parameters); /// } /// </summary> /// <param name="compiler"></param> /// <param name="methodToCompile"></param> /// <param name="method"></param> /// <param name="statements"></param> /// <param name="debug"></param> public void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug) { CodeConditionStatement cs = new CodeConditionStatement(); cs.Condition = new CodeBinaryOperatorExpression( _event.GetReferenceCode(methodToCompile, statements, true), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)); CodeMethodInvokeExpression cme = new CodeMethodInvokeExpression(); if (_event.IsStatic || (_event.Declarer != null && _event.Declarer.IsStatic)) { if (parameters != null && parameters.Count > 0) { CodeTypeReferenceExpression sender = parameters[0] as CodeTypeReferenceExpression; if (sender != null) { if (string.CompareOrdinal(sender.Type.BaseType, _event.Owner.TypeString) == 0) { parameters[0] = new CodeTypeOfExpression(sender.Type.BaseType); } } } cme.Method = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(_event.Owner.TypeString), _event.Name); } else { cme.Method = new CodeMethodReferenceExpression(_event.Owner.GetReferenceCode(methodToCompile, statements, false), _event.Name); } if (parameters != null) { cme.Parameters.AddRange(parameters); } cs.TrueStatements.Add(cme); statements.Add(cs); }
public override CodeStatement GetInitStatement(MethodInfoPointer owner, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, UInt32 branchId) { ParameterInfo[] ps = owner.Info; SubMethodParameterInfo p = (SubMethodParameterInfo)ps[0]; CodeVariableDeclarationStatement vd = new CodeVariableDeclarationStatement(typeof(int), codeName2(p.CodeName, branchId), new CodePrimitiveExpression(0)); return(vd); }
public override CodeExpression GetTestExpression(MethodInfoPointer owner, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, UInt32 branchId) { ParameterInfo[] ps = owner.Info; SubMethodParameterInfo p = (SubMethodParameterInfo)ps[0]; CodeBinaryOperatorExpression bin = new CodeBinaryOperatorExpression( new CodeVariableReferenceExpression(codeName2(p.CodeName, branchId)), CodeBinaryOperatorType.LessThan, new CodePropertyReferenceExpression(owner.Owner.GetReferenceCode(methodToCompile, statements, true), "Length")); return(bin); }
public void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug) { if (_dataTransfers != null) { foreach (KeyValuePair <IProperty, ParameterValue> kv in _dataTransfers) { if (kv.Value != null && kv.Key != null) { MethodDataTransfer.Compile(kv.Key, kv.Value.GetReferenceCode(methodToCompile, statements, true), currentAction, nextAction, compiler, methodToCompile, method, statements, parameters, returnReceiver, debug); } } } }
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); } } }
public void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug) { if (methodToCompile.HasReturn) { CodeMethodReturnStatement mrs; mrs = new CodeMethodReturnStatement(parameters[0]); statements.Add(mrs); } else { CodeMethodReturnStatement mrs = new CodeMethodReturnStatement(); statements.Add(mrs); } }
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); } }
public void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug) { CodeExpression rt = null; if (parameters != null && parameters.Count > 0) { rt = parameters[0]; } else if (_paramCode != null && _paramCode.Length > 0) { rt = _paramCode[0]; } else { compiler.AddError(string.Format("SetterPointer.Compile: {0} missing value expression", ReferenceName)); return; } MethodDataTransfer.Compile(SetProperty, rt, currentAction, nextAction, compiler, methodToCompile, method, statements, parameters, returnReceiver, debug); }
public void Compile(LimnorDesigner.Action.ActionBranch currentAction, LimnorDesigner.Action.ActionBranch nextAction, ILimnorCodeCompiler compiler, MathExp.IMethodCompile methodToCompile, System.CodeDom.CodeMemberMethod method, System.CodeDom.CodeStatementCollection statements, System.CodeDom.CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug) { throw new NotImplementedException(); }
public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, MathExp.IMethodCompile methodToCompile, System.CodeDom.CodeMemberMethod method, System.CodeDom.CodeStatementCollection statements, bool debug) { }
public virtual void Compile(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, CodeExpressionCollection parameters, IObjectPointer returnReceiver, bool debug) { if (_method == null) { return; } CodeExpression cmi = null; if (_method != null) { _method.SetHolder(_holder); CodeMethodReferenceExpression mref = (CodeMethodReferenceExpression)_method.GetReferenceCode(methodToCompile, statements, false); CodeMethodInvokeExpression cmim = new CodeMethodInvokeExpression(); cmim.Method = mref; cmim.Parameters.AddRange(parameters); cmi = cmim; } bool useOutput = false; if (!NoReturn && nextAction != null && nextAction.UseInput) { CodeVariableDeclarationStatement output = new CodeVariableDeclarationStatement( currentAction.OutputType.TypeString, currentAction.OutputCodeName, cmi); statements.Add(output); cmi = new CodeVariableReferenceExpression(currentAction.OutputCodeName); useOutput = true; } if (HasReturn && returnReceiver != null) { CodeExpression cr = returnReceiver.GetReferenceCode(methodToCompile, statements, true); if (_method.ReturnValue != null) { Type target; IClassWrapper wrapper = returnReceiver as IClassWrapper; if (wrapper != null) { target = wrapper.WrappedType; } else { target = returnReceiver.ObjectType; } Type dt; if (useOutput) { dt = currentAction.OutputType.BaseClassType; } else { dt = _method.ReturnValue.BaseClassType; } CompilerUtil.CreateAssignment(cr, target, cmi, dt, statements, true); } else { CodeAssignStatement cas = new CodeAssignStatement(cr, cmi); statements.Add(cas); } } else { if (!useOutput) { CodeExpressionStatement ces = new CodeExpressionStatement(cmi); statements.Add(ces); } } }
public virtual void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { loadEventAction(); if (_eventAction != null) { _eventAction.AttachCodeDomAction(methodToCompile, statements, debug); //ClassPointer root = _class; //CodeExpression methodTarget; //CodeEventReferenceExpression ceRef = _eventAction.Event.GetReferenceCode(methodToCompile, statements, false) as CodeEventReferenceExpression; //if (_eventAction.Event.IsStatic) // methodTarget = new CodeTypeReferenceExpression(root.CodeName); //else // methodTarget = new CodeThisReferenceExpression(); //CodeAttachEventStatement caes = new CodeAttachEventStatement(ceRef, // new CodeDelegateCreateExpression(new CodeTypeReference(_eventAction.Event.EventHandlerType.TypeString), // methodTarget, _eventAction.GetLocalHandlerName())); //statements.Add(caes); } }
public virtual void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { loadEventAction(); if (_eventAction != null) { _eventAction.AttachCodeDomAction(methodToCompile, statements, debug); } }
public abstract CodeExpression GetTestExpression(MethodInfoPointer owner, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, UInt32 branchId);
public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements) { BranchList _list = this.ActionList; if (_list != null) { //link both actions if (nextAction != null) { if (!string.IsNullOrEmpty(OutputCodeName) && OutputType != null && !OutputType.IsVoid) { nextAction.InputName = OutputCodeName; nextAction.InputType = OutputType; nextAction.SetInputName(OutputCodeName, OutputType); } } // CompilerUtil.ClearGroupGotoBranches(method, this.BranchId); bool bRet = _list.ExportCode(compiler, method, statements); bRet = CompilerUtil.FinishActionGroup(method, statements, this.BranchId, bRet); return(bRet); } return(false); }
public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { base.ExportCode(compiler, method, RootPointer.IsWebPage); }
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 override CodeStatement GetIncrementalStatement(MethodInfoPointer owner, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, UInt32 branchId) { ParameterInfo[] ps = owner.Info; SubMethodParameterInfo p = (SubMethodParameterInfo)ps[0]; CodeExpressionStatement incr = new CodeExpressionStatement(new CodeSnippetExpression(codeName2(p.CodeName, branchId) + "++")); return(incr); }
/// <summary> /// it is a fake action block, do not treat it like a normal one, do not add debug breaks /// </summary> /// <param name="compiler"></param> /// <param name="method"></param> /// <param name="statements"></param> public override bool ExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements) { return(OnExportCode(previousAction, nextAction, compiler, method, statements)); }
public abstract CodeStatement GetIncrementalStatement(MethodInfoPointer owner, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, UInt32 branchId);
public override CodeStatement GetIncrementalStatement(MethodInfoPointer owner, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, UInt32 branchId) { return(null); }
public override void OnExportClientServerCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data) { }
/// <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); }
/// <summary> /// Actions do not use return values. Only math expressions use return values. /// If an action is the last action of a method then its return value is the return value of the method. But this logic is not implemented here. It is implemented in the higher level. /// </summary> /// <param name="compiler"></param> /// <param name="method"></param> /// <param name="statements"></param> public void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { MessageBox.Show("ExportCode should not be called because ActionSubMethod can only be for AB_SubMethodAction", "Compile", MessageBoxButtons.OK, MessageBoxIcon.Error); }
public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements) { if (IsCompiled) { return(false); } //preventing of compiling it twice IsCompiled = true; bool isGotoPoint = this.IsGotoPoint; ActionBranch nt = nextAction; if (_jumpToId != 0) { //next action is the one it jumps to nt = _jumpToActionBranch; } MethodSegment ms0 = null; CodeStatementCollection sts = statements; if (isGotoPoint) { //two or more branches in the same thread linked to this branch //since goto-label must be in the method scope, not sub-scope, this branch code must be //in the method scope ms0 = CompilerUtil.GetGotoBranch(method, Method, this.FirstActionId); if (ms0 == null) { sts = new CodeStatementCollection(); ms0 = new MethodSegment(sts); CompilerUtil.AddGotoBranch(method, Method, this.FirstActionId, ms0, this.GroupBranchId); } else { throw new DesignerException("Action list as goto branch {0} compiled twice", this.FirstActionId); } //use goto statement to jump to this branch is the responsibility of the branches jumping to it. } if (this.IsWaitingPoint) { sts.Add(new CodeExpressionStatement( new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(WaitHandle)), "WaitAll", new CodeVariableReferenceExpression(XmlSerialization.FormatString("wh_{0}_{1}", IdToKey(this.StartingBranchId), this.BranchKey))))); } bool b0 = base.OnExportCode(previousAction, nt, compiler, method, sts); if (ms0 != null) { ms0.Completed = b0; } if (b0) { return(true); } else { //not all sub-branches of this branch completed. //check jumping if (_jumpToId != 0) { bool bRet = false; //same thread: use goto or fall through; otherwise use waiting point if (_jumpToActionBranch.StartingBranchId == this.StartingBranchId) { //a goto branch, use goto if (_jumpToActionBranch.IsGotoPoint) { sts.Add(new CodeGotoStatement(ActionBranch.IdToLabel(_jumpToId))); bRet = true; } if (!_jumpToActionBranch.IsCompiled) { bool b = _jumpToActionBranch.ExportCode(this, null, compiler, method, sts); if (!_jumpToActionBranch.IsGotoPoint) { bRet = b; } } } return(bRet); } else { //not completed return(false); } } }
public override void ExportClientServerCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data) { }
public override void ExportCode(ActionBranch currentAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, IMethodCompile methodToCompile, CodeMemberMethod method, CodeStatementCollection statements, bool debug) { EventAction ea = AssignedActions; if (ea != null) { ClassPointer root = Class; CodeExpression methodTarget; CodeEventReferenceExpression ceRef = ea.Event.GetReferenceCode(methodToCompile, statements, false) as CodeEventReferenceExpression; if (ea.Event.IsStatic) { methodTarget = new CodeTypeReferenceExpression(root.CodeName); } else { methodTarget = new CodeThisReferenceExpression(); } CodeRemoveEventStatement caes = new CodeRemoveEventStatement(ceRef, new CodeDelegateCreateExpression(new CodeTypeReference(ea.Event.EventHandlerType.TypeString), methodTarget, ea.GetLocalHandlerName())); statements.Add(caes); } }