public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
        {
            string indexName = RepeatIndex.CodeName;

            methodCode.Add(Indentation.GetIndent());
            methodCode.Add("for(");
            methodCode.Add(indexName);
            methodCode.Add("=0;");
            methodCode.Add(indexName);
            methodCode.Add("<");
            methodCode.Add(RepeatCount.CreateJavaScript(methodCode));
            methodCode.Add(";");
            methodCode.Add(indexName);
            methodCode.Add("++) {\r\n");
            Indentation.IndentIncrease();
            string           indents = Indentation.GetIndent();
            StringCollection sc      = new StringCollection();

            if (_iconList != null)
            {
                foreach (ComponentIcon ci in _iconList)
                {
                    ComponentIconLocal cil = ci as ComponentIconLocal;
                    if (cil != null && cil.ScopeGroupId == this.BranchId)
                    {
                        sc.Add(indents);
                        sc.Add("$");
                        sc.Add(cil.LocalPointer.CodeName);
                        sc.Add("=");
                        sc.Add(ValueTypeUtil.GetDefaultPhpScriptValueByType(cil.LocalPointer.BaseClassType));
                        sc.Add(";\r\n");
                    }
                }
            }
            SetWithinLoop();
            Method.SubMethod.Push(this);
            data.AddSubMethod(this);
            bool bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, sc, data);

            Method.SubMethod.Pop();
            //
            for (int i = 0; i < sc.Count; i++)
            {
                methodCode.Add(sc[i]);
            }
            Indentation.IndentDecrease();
            methodCode.Add(Indentation.GetIndent());
            methodCode.Add("}\r\n");
            return(bRet);
        }
Beispiel #2
0
        public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
        {
            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;
            }
            JsMethodSegment  ms0 = null;
            StringCollection sts = methodCode;

            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 = data.GetGotoBranch(this.FirstActionId);
                if (ms0 == null)
                {
                    sts = new StringCollection();
                    ms0 = new JsMethodSegment(sts);
                    data.AddGotoBranch(this.FirstActionId, ms0);
                }
                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.
            }
            bool b0 = base.OnExportPhpScriptCode(previousAction, nt, jsCode, sts, data);

            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(Indentation.GetIndent());
                            sts.Add("goto ");
                            sts.Add(ActionBranch.IdToLabel(_jumpToId));
                            sts.Add(";\r\n");
                            bRet = true;
                        }
                        if (!_jumpToActionBranch.IsCompiled)
                        {
                            if (_jumpToActionBranch.IsGotoPoint)
                            {
                                Indentation.IndentIncrease();
                            }
                            bool b = _jumpToActionBranch.ExportPhpScriptCode(this, null, jsCode, sts, data);
                            if (_jumpToActionBranch.IsGotoPoint)
                            {
                                Indentation.IndentDecrease();
                            }
                            if (!_jumpToActionBranch.IsGotoPoint)
                            {
                                bRet = b;
                            }
                        }
                    }
                    return(bRet);
                }
                else
                {
                    //not completed
                    return(false);
                }
            }
        }
        public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
        {
            string c;

            if (_logicExpression == null)
            {
                c = "true";
            }
            else
            {
                _logicExpression.PrepareForCompile(this.Method);
                c = _logicExpression.CreatePhpScript(methodCode);
            }
            methodCode.Add(Indentation.GetIndent());
            string initCodeStr  = null;
            string increCodeStr = null;

            if (_initAction != null && _initAction.Action != null)
            {
                StringCollection initCode = new StringCollection();
                _initAction.Action.ExportPhpScriptCode(null, null, methodCode, initCode, data);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < initCode.Count; i++)
                {
                    sb.Append(initCode[i]);
                }
                initCodeStr = sb.ToString().Replace("\r\n", "");
            }
            if (_increAction != null && _increAction.Action != null)
            {
                StringCollection increCode = new StringCollection();
                _increAction.Action.ExportPhpScriptCode(null, null, methodCode, increCode, data);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < increCode.Count; i++)
                {
                    sb.Append(increCode[i]);
                }
                increCodeStr = sb.ToString().Replace("\r\n", "");
            }
            if (string.IsNullOrEmpty(initCodeStr))
            {
                initCodeStr = ";";
            }
            if (!string.IsNullOrEmpty(increCodeStr))
            {
                increCodeStr = increCodeStr.Trim();
                while (increCodeStr.EndsWith(";", StringComparison.Ordinal))
                {
                    increCodeStr = increCodeStr.Substring(0, increCodeStr.Length - 1);
                    increCodeStr = increCodeStr.Trim();
                }
            }
            methodCode.Add("for(");
            methodCode.Add(initCodeStr);
            methodCode.Add(c);
            methodCode.Add(";");
            methodCode.Add(increCodeStr);
            methodCode.Add(") {\r\n");
            Indentation.IndentIncrease();
            string           indents = Indentation.GetIndent();
            StringCollection sc      = new StringCollection();

            if (_iconList != null)
            {
                foreach (ComponentIcon ci in _iconList)
                {
                    ComponentIconLocal cil = ci as ComponentIconLocal;
                    if (cil != null && cil.ScopeGroupId == this.BranchId)
                    {
                        sc.Add(indents);
                        sc.Add("$");
                        sc.Add(cil.LocalPointer.CodeName);
                        sc.Add("=");
                        sc.Add(ValueTypeUtil.GetDefaultPhpScriptValueByType(cil.LocalPointer.BaseClassType));
                        sc.Add(";\r\n");
                    }
                }
            }
            Method.SubMethod.Push(this);
            data.AddSubMethod(this);
            bool bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, sc, data);

            Method.SubMethod.Pop();
            //
            for (int i = 0; i < sc.Count; i++)
            {
                methodCode.Add(sc[i]);
            }
            Indentation.IndentDecrease();
            methodCode.Add(Indentation.GetIndent());
            methodCode.Add("}\r\n");
            return(bRet);
        }
Beispiel #4
0
 public override bool OnExportJavaScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
 {
     if (_conditionAction != null)
     {
         if (IsCompiled)
         {
             return(false);
         }
         //preventing of compiling it twice
         IsCompiled = true;
         if (_conditionAction.TrueActions != null && _conditionAction.FalseActions != null && _conditionAction.TrueActions.BranchId == _conditionAction.FalseActions.BranchId)
         {
             throw new DesignerException("Condition action [{0}, {1}] goes to the same action", this.FirstActionBranchId, _conditionAction.Name);
         }
         try
         {
             StringCollection sts = methodCode;
             string           c;
             if (_conditionAction.Condition == null)
             {
                 c = "true";
             }
             else
             {
                 _conditionAction.Condition.SetDataType(typeof(bool));
                 c = _conditionAction.Condition.CreateJavaScript(sts);
             }
             bool   b1     = false;
             bool   b2     = false;
             string indent = Indentation.GetIndent();
             sts.Add(indent);
             sts.Add("if(");
             sts.Add(c);
             sts.Add(") {\r\n");
             if (_ifBlock != null)
             {
                 Indentation.IndentIncrease();
                 b1 = _ifBlock.OnExportJavaScriptCode(previousAction, null, jsCode, sts, data);
                 Indentation.IndentDecrease();
             }
             sts.Add(indent);
             sts.Add("}\r\n");
             if (_elseBlock != null)
             {
                 sts.Add(indent);
                 sts.Add("else {\r\n");
                 Indentation.IndentIncrease();
                 b2 = _elseBlock.OnExportJavaScriptCode(previousAction, null, jsCode, sts, data);
                 Indentation.IndentDecrease();
                 sts.Add(indent);
                 sts.Add("}\r\n");
             }
             if (_mergeBlock != null)
             {
                 return(_mergeBlock.OnExportJavaScriptCode(null, null, jsCode, sts, data));
             }
             else
             {
                 return(b1 && b2);
             }
         }
         catch (Exception err)
         {
             throw new DesignerException(err, "Error compiling Condition action {0}. See inner exception for details", _conditionAction.TraceInfo);
         }
     }
     return(false);
 }
        public override bool OnExportPhpScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
        {
            bool bRet;

            if (_actionData == null)
            {
                _actionData = (ActionSubMethod)this.Method.GetActionInstance(_actId.ActionId);
            }
            SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer;
            SubMethodInfo        mi  = smi.MethodInformation as SubMethodInfo;

            if (mi == null)
            {
                return(false);
            }
            if (mi.IsForeach)
            {
                ParameterClassSubMethod p  = mi.GetParameterType(0, smi, this);
                StringBuilder           sb = new StringBuilder();
                string         s1          = smi.Owner.CodeName;
                IObjectPointer op          = smi.Owner;
                sb.Append(s1);
                while (!(op is ILocalvariable) && op.Owner != null && op.Owner.Owner != null)
                {
                    if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0)
                    {
                        s1 = op.Owner.CodeName;
                        sb.Insert(0, "->");
                        sb.Insert(0, s1);
                    }
                    op = op.Owner;
                }
                if (op is ILocalvariable || op.Owner is ILocalvariable)
                {
                }
                else
                {
                    sb.Insert(0, "$this->");
                }
                s1 = sb.ToString();
                string indents = Indentation.GetIndent();
                string s0      = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                               "\r\n{2}foreach ({0} as {1}) {{\r\n", s1, p.CodeName, indents);
                methodCode.Add(s0);
                //
                Method.SubMethod.Push(this);
                data.AddSubMethod(this);
                Indentation.IndentIncrease();
                bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, methodCode, data);
                Indentation.IndentDecrease();
                Method.SubMethod.Pop();
                //
                methodCode.Add(indents);
                methodCode.Add("}\r\n");
            }
            else
            {
                string         indents = Indentation.GetIndent();
                StringBuilder  sb      = new StringBuilder();
                string         s1      = smi.Owner.CodeName;
                IObjectPointer op      = smi.Owner;
                sb.Append(s1);
                while (!(op is ILocalvariable) && op.Owner != null && op.Owner.Owner != null)
                {
                    if (string.CompareOrdinal(s1, op.Owner.CodeName) != 0)
                    {
                        s1 = op.Owner.CodeName;
                        sb.Insert(0, "->");
                        sb.Insert(0, s1);
                    }
                    op = op.Owner;
                }
                if (op is ILocalvariable)
                {
                }
                else
                {
                    sb.Insert(0, "$this->");
                }
                s1 = sb.ToString();

                ParameterClassSubMethod p = mi.GetParameterType(1, smi, this);
                p.ParameterID = _actionData.ParameterValues[1].ParameterID;
                string v  = p.CodeName;
                string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                          "\r\n{3}foreach ({0} as {1} => {2} ) {{\r\n", s1, mi.GetIndexCodePHP(smi, this.BranchId), v, indents);
                methodCode.Add(s0);
                Method.SubMethod.Push(this);
                data.AddSubMethod(this);
                //
                Indentation.IndentIncrease();
                bRet = base.OnExportPhpScriptCode(previousAction, nextAction, jsCode, methodCode, data);
                Method.SubMethod.Pop();
                //
                Indentation.IndentDecrease();
                methodCode.Add(indents);
                methodCode.Add("}\r\n");
            }

            return(bRet);
        }
        public override bool OnExportJavaScriptCode(ActionBranch previousAction, ActionBranch nextAction, StringCollection jsCode, StringCollection methodCode, JsMethodCompiler data)
        {
            bool bRet;

            if (_actionData == null)
            {
                _actionData = (ActionSubMethod)this.Method.GetActionInstance(_actId.ActionId);                // (ActionSubMethod)compiler.ActionEventList.GetAction(_actId);
            }
            if (_actionData == null)
            {
                return(false);
            }
            SubMethodInfoPointer smi = _actionData.ActionMethod as SubMethodInfoPointer;
            SubMethodInfo        mi  = smi.MethodInformation as SubMethodInfo;

            if (mi == null)
            {
                return(false);
            }
            if (mi.IsForeach)
            {
                ParameterClassSubMethod p  = mi.GetParameterType(0, smi, this);
                StringBuilder           sb = new StringBuilder();
                string         s1          = smi.Owner.CodeName;
                IObjectPointer op          = smi.Owner;
                sb.Append(s1);
                while (!(op is ILocalvariable) && op.Owner != null && op.Owner.Owner != null)
                {
                    if (!s1.StartsWith(op.Owner.CodeName, StringComparison.Ordinal))
                    {
                        s1 = op.Owner.CodeName;
                        sb.Insert(0, ".");
                        sb.Insert(0, s1);
                    }
                    op = op.Owner;
                }
                s1 = sb.ToString();
                string indents = Indentation.GetIndent();
                string a       = string.Format(CultureInfo.InvariantCulture,
                                               "a{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                string idx = string.Format(CultureInfo.InvariantCulture,
                                           "i{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                string s0 = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                          "{4}var {3} = {1};\r\n{4}if({3}) for(var {0}=0;{0}<{3}.length;{0}++) {{\r\n{4}var {2}={3}[{0}]; \r\n", idx, s1, p.CodeName, a, indents);
                methodCode.Add(s0);
                Method.SubMethod.Push(this);
                data.AddSubMethod(this);
                Indentation.IndentIncrease();
                bRet = base.OnExportJavaScriptCode(previousAction, nextAction, jsCode, methodCode, data);
                Indentation.IndentDecrease();
                Method.SubMethod.Pop();
                //
                methodCode.Add(indents);
                methodCode.Add("}\r\n");
            }
            else
            {
                string indents = Indentation.GetIndent();
                methodCode.Add(indents);
                methodCode.Add("for(var ");
                methodCode.Add(mi.GetInitStatementJS(smi, jsCode, methodCode, data, this.BranchId));
                methodCode.Add(mi.GetTestExpressionJS(smi, jsCode, methodCode, data, this.BranchId));
                methodCode.Add(mi.GetIncrementalStatementJS(smi, jsCode, methodCode, data, this.BranchId));
                methodCode.Add(") {\r\n");
                Method.SubMethod.Push(this);
                data.AddSubMethod(this);
                Indentation.IndentIncrease();
                if (_iconList != null)
                {
                    foreach (ComponentIcon ci in _iconList)
                    {
                        ComponentIconLocal cil = ci as ComponentIconLocal;
                        if (cil != null && cil.ScopeGroupId == this.BranchId)
                        {
                            methodCode.Add(Indentation.GetIndent());
                            methodCode.Add("var ");
                            methodCode.Add(cil.LocalPointer.CodeName);
                            methodCode.Add("=");
                            methodCode.Add(ValueTypeUtil.GetDefaultJavaScriptValueByType(cil.LocalPointer.BaseClassType));
                            methodCode.Add(";\r\n");
                        }
                    }
                }
                bRet = base.OnExportJavaScriptCode(previousAction, nextAction, jsCode, methodCode, data);
                Method.SubMethod.Pop();
                //
                Indentation.IndentDecrease();
                methodCode.Add(indents);
                methodCode.Add("}\r\n");
            }

            return(bRet);
        }