Beispiel #1
0
        public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
        {
            bool bRet = false;

            if (_list != null)
            {
                ActionBranch p = previousAction;
                ActionBranch n;
                _list.ResetBeforeCompile();
                for (int i = 0, j = 1; i < _list.Count; i++, j++)                //ActionBranch a in _list)
                {
                    if (j < _list.Count)
                    {
                        n = _list[j];
                    }
                    else
                    {
                        n = nextAction;
                    }
                    if (!_list[i].IsCompiled)
                    {
                        bRet = _list[i].ExportCode(p, n, compiler, method, statements);
                    }
                    p = _list[i];
                }
            }
            return(bRet);
        }
Beispiel #2
0
 public override void OnExportClientServerCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements,
                                               StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
 {
     if (_actionList != null)
     {
         int last = _actionList.Count - 1;
         for (int k = 0; k < _actionList.Count; k++)
         {
             if (_actionList[k].Action != null)
             {
                 ActionBranch nt = null;
                 if (k == last)
                 {
                     nt = nextAction;
                     if (nt != null && nt.UseInput)
                     {
                         nt.InputName = this.OutputCodeName;
                         nt.InputType = this.OutputType;
                         nt.SetInputName(OutputCodeName, OutputType);
                     }
                 }
                 _actionList[k].Action.ExportJavaScriptCode(this, nt, jsCode, methodCode, data);
             }
         }
     }
 }
Beispiel #3
0
        public override void VisitBranch(ActionBranch output)
        {
            var branchMethod = new CodeMemberMethod()
            {
                ReturnType = !DebugSystem.IsDebugMode ? new CodeTypeReference(typeof(void)) : new CodeTypeReference(typeof(IEnumerator)),
                Name       = output.VariableName
            };

            _.PushStatements(branchMethod.Statements);
            var actionNode = output.Node as ActionNode;

            if (actionNode != null)
            {
                actionNode.WriteActionOutputs(_);
            }

            base.VisitBranch(output);
            if (DebugSystem.IsDebugMode)
            {
                _._("yield break");
            }

            _.PopStatements();
            _.CurrentDeclaration.Members.Add(branchMethod);
        }
Beispiel #4
0
        public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
        {
            bool bRet = false;

            if (_actionList != null)
            {
                int last = _actionList.Count - 1;
                for (int k = 0; k < _actionList.Count; k++)
                {
                    if (_actionList[k].Action != null)
                    {
                        bRet = _actionList[k].Action.IsMethodReturn;
                        ActionBranch nt = null;
                        if (k == last)
                        {
                            nt = nextAction;
                            if (nt != null && nt.UseInput)
                            {
                                nt.InputName = this.OutputCodeName;
                                nt.InputType = this.OutputType;
                                nt.SetInputName(OutputCodeName, OutputType);
                            }
                        }
                        _actionList[k].Action.ExportPhpScriptCode(this, nt, jsCode, methodCode, data);
                    }
                }
            }
            return(bRet);
        }
Beispiel #5
0
        public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
        {
            bool bRet = false;

            if (_actionList != null)
            {
                int last = _actionList.Count - 1;
                for (int k = 0; k < _actionList.Count; k++)
                {
                    if (_actionList[k].Action != null)
                    {
                        bRet = _actionList[k].Action.IsMethodReturn;
                        ActionBranch nt = null;
                        if (k == last)
                        {
                            nt = nextAction;
                            if (nt != null && nt.UseInput)
                            {
                                nt.InputName = this.OutputCodeName;
                                nt.InputType = this.OutputType;
                                nt.SetInputName(OutputCodeName, OutputType);
                            }
                        }
                        _actionList[k].Action.ExportCode(this, nt, compiler, this.Method, method, statements, compiler.Debug);
                    }
                }
            }
            return(bRet);
        }
Beispiel #6
0
        public override ActionBranch SearchBranchById(UInt32 branchId)
        {
            ActionBranch ab = base.SearchBranchById(branchId);

            if (ab != null)
            {
                return(ab);
            }
            if (_ifActions != null)
            {
                ab = _ifActions.SearchBranchById(branchId);
                if (ab != null)
                {
                    return(ab);
                }
            }
            if (_elseActions != null)
            {
                ab = _elseActions.SearchBranchById(branchId);
                if (ab != null)
                {
                    return(ab);
                }
            }
            return(null);
        }
Beispiel #7
0
        public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
        {
            bool bRet = false;

            if (_list != null)
            {
                ActionBranch p = previousAction;
                ActionBranch n;
                _list.ResetBeforeCompile();
                for (int i = 0, j = 1; i < _list.Count; i++, j++)                //ActionBranch a in _list)
                {
                    if (j < _list.Count)
                    {
                        n = _list[j];
                    }
                    else
                    {
                        n = nextAction;
                    }
                    if (!_list[i].IsCompiled)
                    {
                        bRet = _list[i].ExportPhpScriptCode(p, n, jsCode, methodCode, data);
                    }
                    p = _list[i];
                }
            }
            return(bRet);
        }
        public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
        {
            ClassPointer list = compiler.ActionEventList;

            if (list != null)
            {
                if (_actionData == null)
                {
                    _actionData = _actId.LoadActionInstance(this.ActionsHolder);
                }
            }
            if (_actionData != 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);
                    }
                }
                if (_actionData.ActionMethod != null && _actionData.ActionMethod.IsValid)
                {
                    _actionData.ExportCode(this, nextAction, compiler, this.Method, method, statements, compiler.Debug);
                }
                if (_actionData.IsMethodReturn)
                {
                    return(true);
                }
                return(this.IsMethodReturn);
            }
            return(false);
        }
        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 bool OnExportPhpScriptCode(ActionBranch currentAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodToCompile, JsMethodCompiler data)
        {
            ClassPointer list = data.ActionEventList;

            if (list != null && _actId != null)
            {
                _actionData = _actId.LoadActionInstance(this.ActionsHolder);
            }
            if (_actionData != 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);
                    }
                }
                if (_actionData.ActionMethod != null && _actionData.ActionMethod.IsValid)
                {
                    _actionData.ExportPhpScriptCode(this, nextAction, jsCode, methodToCompile, data);
                }
                if (_actionData.IsMethodReturn)
                {
                    return(true);
                }
                return(this.IsMethodReturn);
            }
            return(false);
        }
        /// <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);
        }
Beispiel #12
0
 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);
         }
     }
 }
Beispiel #13
0
        /// <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);
        }
Beispiel #14
0
 public override void InitializeBranches(BranchList branches)
 {
     if (_ifJumpToId != 0)
     {
         if (_ifActions == null)
         {
             _ifActions = branches.GetJumpToActionBranch(_ifJumpToId);
             if (_ifActions == null)
             {
                 throw new DesignerException("Action for True branch not found (id={0})", _ifJumpToId);
             }
         }
     }
     else
     {
         _ifActions = null;
     }
     if (_elseJumpToId != 0)
     {
         if (_elseActions == null)
         {
             _elseActions = branches.GetJumpToActionBranch(_elseJumpToId);
             if (_elseActions == null)
             {
                 throw new DesignerException("Action for False branch not found (id={0})", _elseJumpToId);
             }
         }
     }
     else
     {
         _elseActions = null;
     }
 }
Beispiel #15
0
        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 ActionBranchParameter(Type type, string name, ActionBranch branch)
     : base(type, name, branch.Method)
 {
     _actionBranch    = branch;
     this.ParameterID = branch.BranchId;
     AllowTypeChange  = false;
 }
Beispiel #17
0
        /// <summary>
        /// before executing an action in a method.
        /// it can be called from different threads
        /// </summary>
        /// <param name="objectKey">ObjectKey of the owner of the method</param>
        /// <param name="methodWholeId">method id</param>
        /// <param name="branchId">action branch id of the action to be executed</param>
        /// <param name="executer">object instance executing the method</param>
        public void BeforeExecuteAction(string objectKey, UInt64 methodWholeId, UInt32 branchId, object executer)
        {
            if (_ComponentDebugger.Stopping)
            {
                return;
            }
            int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;

            _ComponentDebugger.IncrementStackLevel(threadId);
            //check if it is at a break point
            MethodClass mc = _ComponentDebugger.GetMethod(methodWholeId);

            if (mc != null)
            {
                //MethodClass mc = mc0.Clone() as MethodClass;
                IActionGroup g      = mc;
                ActionBranch branch = mc.GetBranchByIdInGroup(branchId, ref g);
                if (branch != null)
                {
                    if (_ComponentDebugger.ShouldBreak(threadId) || branch.BreakBeforeExecute)
                    {
                        _ComponentDebugger.SetSelectedObject(executer);
                        _ComponentDebugger.SetAtBreak(threadId, true);
                        _debugUI.ShowBreakPoint(_ComponentDebugger);
                        branch.AtBreak = EnumActionBreakStatus.Before;
                        _ComponentDebugger.ShowBreakPointInMethod(threadId, mc, g, branch);
                        waitForBreakPoint(threadId);
                    }
                }
            }
        }
Beispiel #18
0
 public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
 {
     if (_decisionTable != null)
     {
         CodeConditionStatement ccs = null;
         for (int i = 0; i < _decisionTable.ConditionCount; i++)
         {
             _decisionTable[i].Condition.PrepareForCompile(this.Method);
             CodeExpression c = _decisionTable[i].Condition.ExportCode(this.Method);
             if (ccs == null)
             {
                 ccs = new CodeConditionStatement();
                 statements.Add(ccs);
             }
             else
             {
                 CodeConditionStatement ccs2 = new CodeConditionStatement();
                 ccs.FalseStatements.Add(ccs2);
                 ccs = ccs2;
             }
             ccs.Condition = c;
             if (_decisionTable[i].Actions != null)
             {
                 for (int k = 0; k < _decisionTable[i].Actions.Count; k++)
                 {
                     verifyActionObj(k, i);
                     _decisionTable[i].Actions[k].Action.ExportCode(this, nextAction, compiler, this.Method, method, ccs.TrueStatements, compiler.Debug);
                 }
             }
         }
     }
     return(false);
 }
Beispiel #19
0
 protected override void OnVerifyJump(BranchList branch)
 {
     if (_jumpToId == 0)
     {
         List <ActionPortOut> aos = OutPortList;
         if (aos != null && aos.Count > 0)
         {
             if (aos[0].LinkedInPort != null)
             {
                 ActionBranch ab = aos[0].LinkedInPort.PortOwner as ActionBranch;
                 if (ab != null)
                 {
                     _jumpToId           = ab.BranchId;
                     _jumpToActionBranch = ab;
                 }
             }
         }
     }
     else
     {
         if (_jumpToId == FirstActionId)
         {
             _jumpToId = 0;
         }
     }
 }
Beispiel #20
0
 protected override void OnVerifyJump(BranchList branch)
 {
     if (_ifJumpToId == 0)
     {
         if (OutPortList[0].LinkedInPort != null)
         {
             ActionBranch ab = OutPortList[0].LinkedInPort.PortOwner as ActionBranch;
             if (ab != null)
             {
                 _ifJumpToId = ab.BranchId;
                 _ifActions  = ab;
             }
         }
     }
     if (_elseJumpToId == 0)
     {
         if (OutPortList[1].LinkedInPort != null)
         {
             ActionBranch ab = OutPortList[1].LinkedInPort.PortOwner as ActionBranch;
             if (ab != null)
             {
                 _elseJumpToId = ab.BranchId;
                 _elseActions  = ab;
             }
         }
     }
 }
        public override void ExportJavaScriptCode(ActionBranch currentAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodToCompile, JsMethodCompiler data)
        {
            IMathExpression mathExp = MathExp;

            if (mathExp != null)
            {
                string ce = mathExp.ReturnJavaScriptCodeExpression(methodToCompile);
                if (!string.IsNullOrEmpty(ce))
                {
                    string target = null;
                    string output = null;
                    if (nextAction != null)
                    {
                        if (nextAction.UseInput)
                        {
                            methodToCompile.Add("var ");
                            methodToCompile.Add(currentAction.OutputCodeName);
                            methodToCompile.Add("=");
                            methodToCompile.Add(ce);
                            methodToCompile.Add(";\r\n");
                            output = currentAction.OutputCodeName;
                        }
                    }
                    IVariable v = mathExp.OutputVariable;
                    if (v != null)
                    {
                        string ceCondition = null;
                        if (Condition != null)
                        {
                            ceCondition = Condition.CreateJavaScriptCode(methodToCompile);
                        }
                        target = v.ExportJavaScriptCode(methodToCompile);
                        string jsLine;
                        if (output != null)
                        {
                            jsLine = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                   "{0}={1};\r\n", target, currentAction.OutputCodeName);
                        }
                        else
                        {
                            jsLine = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                   "{0}={1};\r\n", target, ce);
                        }
                        if (string.IsNullOrEmpty(ceCondition))
                        {
                            methodToCompile.Add(jsLine);
                        }
                        else
                        {
                            methodToCompile.Add("if(");
                            methodToCompile.Add(ceCondition);
                            methodToCompile.Add(")\r\n{\r\n");
                            methodToCompile.Add(jsLine);
                            methodToCompile.Add("\r\n}\r\n");
                        }
                    }
                }
            }
        }
 public override bool OnExportCode(ActionBranch previousAction, ActionBranch nextAction, ILimnorCodeCompiler compiler, CodeMemberMethod method, CodeStatementCollection statements)
 {
     if (_eventAction != null)
     {
         _eventAction.AttachCodeDomAction(this.Method, statements, false);
     }
     return(false);
 }
 public override bool OnExportJavaScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
 {
     if (_eventAction != null)
     {
         _eventAction.AttachJavascriptAction(this.BranchId, methodCode, Indentation.GetIndent());
     }
     return(false);
 }
Beispiel #24
0
 public override bool OnExportJavaScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
 {
     if (_nextAction != null && _nextAction.FirstActionBranch != null && _nextAction.FirstActionBranch.InPortCount < 2)
     {
         return(_nextAction.OnExportJavaScriptCode(previousAction, nextAction, jsCode, methodCode, data));
     }
     return(false);
 }
Beispiel #25
0
 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);
     }
 }
Beispiel #26
0
        public override void MakePortLinkForSingleThread(List <UInt32> used, BranchList branch)
        {
            ActionBranch ai = FirstAction;

            if (ai != null)
            {
                ai.MakePortLinkForSingleThread(used, branch);
            }
        }
        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);
                        }
                    }
                }
            }
        }
Beispiel #28
0
        public override ActionPortIn GetActionInport(List <UInt32> used, UInt32 portId, UInt32 portInstanceId)
        {
            ActionBranch ai = FirstAction;

            if (ai != null)
            {
                return(ai.GetActionInport(used, portId, portInstanceId));
            }
            return(null);
        }
 public static bool FinishActionGroup(CodeMemberMethod method, CodeStatementCollection statements, UInt32 groupId, bool completed)
 {
     if (method.UserData.Contains(GOTOBRANCHES_Group))
     {
         Dictionary <UInt32, Dictionary <UInt32, MethodSegment> > groups = (Dictionary <UInt32, Dictionary <UInt32, MethodSegment> >)method.UserData[GOTOBRANCHES_Group];
         if (groups != null)
         {
             Dictionary <UInt32, MethodSegment> gotoBranches;
             if (groups.TryGetValue(groupId, out gotoBranches))
             {
                 if (gotoBranches != null && gotoBranches.Count > 0)
                 {
                     string lb        = "L_" + Guid.NewGuid().GetHashCode().ToString("x");
                     bool   bUseLabel = false;
                     if (!completed)
                     {
                         //if the last method code is not a return then add a default method return
                         //if at least one of the branches in the method (not including goBranches) is not ended (method return or go to)
                         //addDefaultMethodReturn(mc, mm.Statements);
                         bUseLabel = true;
                         statements.Add(new CodeGotoStatement(lb));
                     }
                     foreach (KeyValuePair <UInt32, MethodSegment> kv in gotoBranches)
                     {
                         //if the last statement for this gotoBranch is not a method return then add a default one
                         if (!kv.Value.Completed)
                         {
                             bUseLabel = true;
                             kv.Value.Statements.Add(new CodeGotoStatement(lb));
                         }
                         //append the label to the end of method code
                         statements.Add(new CodeLabeledStatement(ActionBranch.IdToLabel(kv.Key)));
                         if (kv.Value.Statements.Count == 0)
                         {
                             statements.Add(new CodeSnippetStatement(";"));
                         }
                         //append the staments belonging to this gotoBranch to the end of the method
                         for (int i = 0; i < kv.Value.Statements.Count; i++)
                         {
                             statements.Add(kv.Value.Statements[i]);
                         }
                     }
                     if (bUseLabel)
                     {
                         statements.Add(new CodeLabeledStatement(lb));
                         statements.Add(new CodeSnippetStatement(";"));
                     }
                 }
             }
         }
     }
     return(completed);
 }
Beispiel #30
0
 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 override void VisitBranch(ActionBranch output)
        {
            var branchMethod = new CodeMemberMethod()
            {
                ReturnType = !DebugSystem.IsDebugMode ? new CodeTypeReference(typeof(void)) : new CodeTypeReference(typeof(IEnumerator)),
                Name = output.VariableName
            };
            _.PushStatements(branchMethod.Statements);
            var actionNode = output.Node as ActionNode;
            if (actionNode != null)
            {
                actionNode.WriteActionOutputs(_);

            }

            base.VisitBranch(output);
            if (DebugSystem.IsDebugMode)
                _._("yield break");

            _.PopStatements();
            _.CurrentDeclaration.Members.Add(branchMethod);
        }
        public override void VisitBranch(ActionBranch output)
        {
            var branchMethod = new CodeMemberMethod()
            {
                ReturnType = !DebugSystem.IsDebugMode ? new CodeTypeReference(typeof(void)) : new CodeTypeReference(typeof(IEnumerator)),
                Name = output.VariableName
            };


            _.PushStatements(branchMethod.Statements);
            var actionNode = output.Node as ActionNode;
            if (actionNode != null)
            {
                actionNode.WriteActionOutputs(_);
            }

            if (output.ActionFieldInfo != null && output.ActionFieldInfo.IsBranch)
            {
                foreach (var item in output.ActionFieldInfo.DelegateMembers)
                {
                    branchMethod.Parameters.Add(new CodeParameterDeclarationExpression(item.MemberType.FullName, item.MemberName));

                    if (actionNode != null)
                    _._("{0}_{1} = {1}", actionNode.VariableName, item.MemberName);
            

                }
            }
    


            base.VisitBranch(output);
            if (DebugSystem.IsDebugMode)
                _._("yield break");

            var branchesChildItem = output.OutputTo<BranchesChildItem>();
            if (branchesChildItem != null)
            {
                _._("{0}()", branchesChildItem.Name);
            }
            _.PopStatements();
            _.CurrentDeclaration.Members.Add(branchMethod);

        }
 public virtual void VisitBranch(ActionBranch output)
 {
     var item = output.OutputTo<SequenceItemNode>();
     if (item != null)
     {
         Visit(item);
     }
 }
 public virtual void AfterVisitBranch(ActionBranch actionBranch)
 {
         
 }
 public virtual void BeforeVisitBranch(ActionBranch actionBranch)
 {
             
 }