Esempio n. 1
0
        protected IRenderable InstantiateTag(ITag tag, ArgumentList arguments)
        {
            IRenderable statement;

            if (tag is IInlineTag)
            {
                statement = new InlineElement(tag)
                {
                    Arguments = arguments
                };
            }
            else if (tag is IConditionalTag)
            {
                statement = new ConditionalElement(tag)
                {
                    Arguments = arguments
                };
            }
            else if (tag is IBlockTag)
            {
                statement = new BlockElement(tag)
                {
                    Arguments = arguments
                };
            }
            else
            {
                throw new Exception(String.Format(@"Internal compiler error. Unknown tag type {0}", tag));
            }

            // TODO: Validation of parameters.

            return(statement);
        }
Esempio n. 2
0
        public void ConditionalTest()
        {
            ConditionalElement when = new ConditionalElement();

            when.AddItem(new StringConditionItem
            {
                ExpressionLeft  = TempStrGetExpression(),
                ExpressionRight = (StringExpressItem)"1",
            });

            using (ModuleRunScope scope = new ModuleRunScope())
            {
                Assert.IsTrue(when.CanRunInScope(scope));
            }

            XmlDocument xDoc   = when.GetXmlDoc(true);
            string      xmlStr = xDoc.GetXmlDocString(true);

            Trace.Write(xmlStr);

            ConditionalElement restore = xDoc.GetObject <ConditionalElement>();
            string             xmlStr2 = restore.GetXmlDocString(true);

            Trace.Write(xmlStr2);

            Assert.AreEqual(xmlStr.XmlUtf8BOMClear(), xmlStr2.XmlUtf8BOMClear());
        }
Esempio n. 3
0
        public override Node ExitIfExpression(Production node)
        {
            IList childValues = GetChildValues(node);
            var   op          = new ConditionalElement((BaseExpressionElement)childValues[0], (BaseExpressionElement)childValues[1], (BaseExpressionElement)childValues[2]);

            node.AddValue(op);
            return(node);
        }
Esempio n. 4
0
 public static SpecialCharValues Create(SpecialCharFlags flags, ConditionalElement conditional)
 {
     return(new SpecialCharValues
     {
         Flags = flags,
         ConditionalElement = conditional
     });
 }
Esempio n. 5
0
        public void ModuleAnyMatchTest()
        {
            using (ModuleRunScope scope = new ModuleRunScope())
            {
                string[] arrTest = new string[] { "1", "2", "3", "4", "5" };
                scope.SetVariable("$Arr", arrTest);

                ModuleAnyMatch anyMatch = new ModuleAnyMatch
                {
                    BuildInstance            = false,
                    Target                   = BuildTarget.ScopeResult,
                    Type                     = typeof(System.Diagnostics.Trace).AssemblyQualifiedName,
                    ScopeIEnumerableInstance = "$Arr"
                };

                anyMatch.AddStep(new ModuleMethodCallElement
                {
                    MethodName = "WriteLine",
                    Parameters = new ModuleConstructorElement
                    {
                        Arguments = new TypeValueElement[]
                        {
                            new TypeValueElement {
                                Type = "System.String", Value = "$StepSwap"
                            }
                        }
                    }
                });
                anyMatch.AddStep(new ExpressionReturnElement());

                ConditionalElement when = new ConditionalElement();
                when.AddItem(new InstanceIsTypeConditionItem {
                    ScopeInstanceKey = "$StepSwap", CompareType = "string"
                });
                when.AddItem(new StringConditionItem
                {
                    ComparisonMode         = StringComparison.InvariantCultureIgnoreCase,
                    BooleanCompareDelegate = "XmlClrLan.ConditionalElement.StringNotEqual",
                    Logic           = LogicExpression.AND,
                    ExpressionLeft  = (StringExpressItem)"3",
                    ExpressionRight = (StringExpressItem)"$StepSwap",
                });
                anyMatch.Match = when;

                anyMatch.InvokeInScope(scope);

                if (scope.LastError != null)
                {
                    throw scope.LastError;
                }


                XmlDocument    xDoc    = anyMatch.GetXmlDoc(true);
                ModuleAnyMatch restore = xDoc.GetObject <ModuleAnyMatch>();

                Assert.AreEqual(restore.ModuleId, anyMatch.ModuleId);
            }
        }
Esempio n. 6
0
        public override Node ExitFunctionCallExpression(Production node)
        {
            IList  childValues = GetChildValues(node);
            string name        = (string)childValues[0];

            childValues.RemoveAt(0);

            if (string.Equals(name, "if", StringComparison.OrdinalIgnoreCase))
            {
                // TODO: Validate parameter count.

                ConditionalElement op = new ConditionalElement((ExpressionElement)childValues[0], (ExpressionElement)childValues[1], (ExpressionElement)childValues[2]);
                node.AddValue(op);
                return(node);
            }

            ArgumentList        args     = new ArgumentList(childValues);
            FunctionCallElement funcCall = new FunctionCallElement(name, args);

            node.AddValue(funcCall);
            return(node);
        }
Esempio n. 7
0
        ModuleBranch getBranchTest(bool sharedMoudle = false)
        {
            ModuleBranch branch = new ModuleBranch
            {
            };

            //if (sharedMoudle)
            //    branch = ModuleBranch.GetScopeSharedModule("");

            ModuleWhen myWhen = new ModuleWhen();

            ConditionalElement match = new ConditionalElement();

            match.AddItem(new StringConditionItem
            {
                ExpressionLeft         = TempStrGetExpression(),
                ComparisonMode         = StringComparison.InvariantCultureIgnoreCase,
                BooleanCompareDelegate = "XmlClrLan.ConditionalElement.StringNotEqual, XmlClrLan",
                ExpressionRight        = (StringExpressItem)"1",
            });

            myWhen.Match = match;
            myWhen.AddStep(new ModuleMethodCallElement
            {
                MethodName = "AddMainType",
                Parameters = new ModuleConstructorElement
                {
                    Arguments = new TypeValueElement[]
                    {
                        new TypeValueElement {
                            Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule2, DBHR.WinFormUnity"
                        }
                    }
                }
            });
            branch.Conditions = new ModuleWhen[] { myWhen, myWhen };

            //Else
            SubModuleBuildElement elseModule = new SubModuleBuildElement
            {
            };

            elseModule.AddStep(new ModuleMethodCallElement
            {
                MethodName = "AddDetailType",
                Parameters = new ModuleConstructorElement
                {
                    Arguments = new TypeValueElement[]
                    {
                        new TypeValueElement {
                            Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule1, DBHR.WinFormUnity"
                        },
                        new TypeValueElement {
                            Type = "System.Type", Value = "DBHR.WinFormUnity.TestModule2, DBHR.WinFormUnity"
                        }
                    }
                }
            });
            branch.Else = elseModule;

            return(branch);
        }
        public static BoolExpr ConditionalTaken(ConditionalElement ce, string key, Context ctx)
        {
            Contract.Requires(ctx != null);

            switch (ce)
            {
            case ConditionalElement.NONE: return(ctx.MkFalse());

            case ConditionalElement.UNCONDITIONAL: return(ctx.MkTrue());

            case ConditionalElement.C:
            case ConditionalElement.B:
            case ConditionalElement.NAE: return(CF());

            case ConditionalElement.NC:
            case ConditionalElement.AE:
            case ConditionalElement.NB: return(ctx.MkNot(CF()));

            case ConditionalElement.Z:
            case ConditionalElement.E: return(ZF());

            case ConditionalElement.NZ:
            case ConditionalElement.NE: return(ctx.MkNot(ZF()));

            case ConditionalElement.S: return(SF());

            case ConditionalElement.NS: return(ctx.MkNot(SF()));

            case ConditionalElement.P:
            case ConditionalElement.PE: return(PF());

            case ConditionalElement.PO:
            case ConditionalElement.NP: return(ctx.MkNot(PF()));

            case ConditionalElement.O: return(OF());

            case ConditionalElement.NO: return(ctx.MkNot(OF()));

            case ConditionalElement.A:
            case ConditionalElement.NBE: return(ctx.MkAnd(ctx.MkNot(CF()), ctx.MkNot(ZF())));

            case ConditionalElement.BE:
            case ConditionalElement.NA: return(ctx.MkOr(CF(), ZF()));

            case ConditionalElement.G:
            case ConditionalElement.NLE: return(ctx.MkAnd(ctx.MkNot(ZF()), ctx.MkEq(SF(), OF())));

            case ConditionalElement.GE:
            case ConditionalElement.NL: return(ctx.MkEq(SF(), OF()));

            case ConditionalElement.LE:
            case ConditionalElement.NG: return(ctx.MkOr(ctx.MkXor(SF(), OF()), ZF()));

            case ConditionalElement.L:
            case ConditionalElement.NGE: return(ctx.MkXor(SF(), OF()));

            case ConditionalElement.CXZ: return(ctx.MkEq(Tools.Create_Key(Rn.CX, key, ctx), ctx.MkBV(0, 16)));

            case ConditionalElement.ECXZ: return(ctx.MkEq(Tools.Create_Key(Rn.ECX, key, ctx), ctx.MkBV(0, 32)));

            case ConditionalElement.RCXZ: return(ctx.MkEq(Tools.Create_Key(Rn.RCX, key, ctx), ctx.MkBV(0, 64)));

            default:
                // unreachable
                throw new Exception();
            }

            BoolExpr CF()
            {
                return(Tools.Create_Key(Flags.CF, key, ctx));
            }

            BoolExpr ZF()
            {
                return(Tools.Create_Key(Flags.ZF, key, ctx));
            }

            BoolExpr SF()
            {
                return(Tools.Create_Key(Flags.SF, key, ctx));
            }

            BoolExpr OF()
            {
                return(Tools.Create_Key(Flags.OF, key, ctx));
            }

            BoolExpr PF()
            {
                return(Tools.Create_Key(Flags.PF, key, ctx));
            }

            //BoolExpr AF() { return Mnemonics_ng.Tools.Flag_Key(Flags.AF, key, ctx); }
        }
        public static Flags FlagsUsed(ConditionalElement ce)
        {
            switch (ce)
            {
            case ConditionalElement.NONE: return(Flags.NONE);

            case ConditionalElement.UNCONDITIONAL: return(Flags.NONE);

            case ConditionalElement.A: return(Flags.CF | Flags.ZF);

            case ConditionalElement.AE: return(Flags.CF);

            case ConditionalElement.B: return(Flags.CF);

            case ConditionalElement.BE: return(Flags.CF | Flags.ZF);

            case ConditionalElement.C: return(Flags.CF);

            case ConditionalElement.E: return(Flags.ZF);

            case ConditionalElement.G: return(Flags.ZF | Flags.SF | Flags.OF);

            case ConditionalElement.GE: return(Flags.SF | Flags.OF);

            case ConditionalElement.L: return(Flags.SF | Flags.OF);

            case ConditionalElement.LE: return(Flags.SF | Flags.OF | Flags.ZF);

            case ConditionalElement.NA: return(Flags.CF | Flags.ZF);

            case ConditionalElement.NAE: return(Flags.CF);

            case ConditionalElement.NB: return(Flags.CF);

            case ConditionalElement.NBE: return(Flags.CF | Flags.ZF);

            case ConditionalElement.NC: return(Flags.CF);

            case ConditionalElement.NE: return(Flags.ZF);

            case ConditionalElement.NG: return(Flags.SF | Flags.OF | Flags.ZF);

            case ConditionalElement.NGE: return(Flags.SF | Flags.OF);

            case ConditionalElement.NL: return(Flags.SF | Flags.OF);

            case ConditionalElement.NLE: return(Flags.ZF | Flags.SF | Flags.OF);

            case ConditionalElement.NO: return(Flags.OF);

            case ConditionalElement.NP: return(Flags.PF);

            case ConditionalElement.NS: return(Flags.SF);

            case ConditionalElement.NZ: return(Flags.ZF);

            case ConditionalElement.O: return(Flags.OF);

            case ConditionalElement.P: return(Flags.PF);

            case ConditionalElement.PE: return(Flags.PF);

            case ConditionalElement.PO: return(Flags.PF);

            case ConditionalElement.S: return(Flags.SF);

            case ConditionalElement.Z: return(Flags.ZF);

            case ConditionalElement.CXZ: return(Flags.NONE);

            case ConditionalElement.ECXZ: return(Flags.NONE);

            case ConditionalElement.RCXZ: return(Flags.NONE);

            default:
                // unreachable
                throw new Exception();
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Create a print mode conditional element.
 /// </summary>
 /// <param name="element">The element to create.</param>
 /// <returns>The created conditional.</returns>
 public virtual IConditional CreateConditional(ConditionalElement element)
 {
     throw new NotImplementedException();
 }