public Item Compile(ByteCodeGenerator generator)
        {
            Chain thenExit = null;

            var item = new ConditionCompiler(node.Condition).Compile(generator);
            var elseChain = item.JumpFalse();

            Item x = null;
            if (!item.IsFalse())
            {
                generator.ResolveChain(item.TrueJumps);

                x = new ExpressionCompiler(node.ThenExpression).Compile(generator).Load();

                thenExit = generator.Branch(OpCodeValue.@goto);
            }
            if (elseChain != null)
            {
                generator.ResolveChain(elseChain);

                x = new ExpressionCompiler(node.ElseExpression).Compile(generator).Load();
            }
            generator.ResolveChain(thenExit);

            //var type = tb.Type.FindCommonType(fb.Type);
            var type = x.Type;

            return new StackItem(generator, type);
        }
Пример #2
0
        public static bool Check(string propertyName, string conditionTemplate)
        {
            var condition = conditionTemplate.Replace("${property}", propertyName);
            var compiler  = new ConditionCompiler(condition);

            return((bool)compiler.Execute());
        }
Пример #3
0
        public void Compile(ByteCodeGenerator generator)
        {
            var item = new ConditionCompiler(node.Condition).Compile(generator);
            var elseChain = item.JumpFalse();

            Chain thenExit = null;
            if (!item.IsFalse())
            {
                generator.ResolveChain(item.TrueJumps);

                generator.PushScope();

                new StatementCompiler(node.TrueBranch).Compile(generator);
                thenExit = generator.Branch(OpCodeValue.@goto);

                generator.PopScope();
            }
            if (elseChain != null)
            {
                generator.ResolveChain(elseChain);

                if (node.FalseBranch != null)
                {
                    generator.PushScope();
                    new StatementCompiler(node.FalseBranch).Compile(generator);
                    generator.PopScope();
                }
            }

            generator.ResolveChain(thenExit);
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.OutputEncoding  = System.Text.Encoding.GetEncoding(28591);
            Console.WriteLine(Logo.Art);
            Console.WriteLine("Ultramarine QueryLanguage CLI");
            Console.ResetColor();

            while (true)
            {
                Console.Write('>');
                var input = Console.ReadLine();
                if (input.Equals("exit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
                try
                {
                    var compiler = new ConditionCompiler(input);
                    Console.WriteLine(compiler.Execute());
                }
                catch
                {
                    //TODO: proper parsing error
                    Console.WriteLine("Can't understand that expression. Yet!");
                }
            }
        }
Пример #5
0
        public List <ICodeElementModel> GetCodeElements(string expression)
        {
            var result    = new List <CodeElement>();
            var codeModel = GetCodeModel(_projectItem);

            if (codeModel == null)
            {
                return(null);
            }

            foreach (CodeElement codeElement in _projectItem.FileCodeModel.CodeElements)
            {
                if (codeElement.IsCodeType)
                {
                    var condition = new ConditionCompiler(expression, codeElement.Name);
                    if (condition.Execute())
                    {
                        result.Add(codeElement);
                    }
                    else
                    {
                        result.AddRange(GetInnerCodeElements(codeElement, expression));
                    }
                }
                else
                {
                    result.AddRange(GetInnerCodeElements(codeElement, expression));
                }
            }

            return(result.Select <CodeElement, ICodeElementModel>(c => new CodeElementModel(c)).ToList());
        }
Пример #6
0
        public void ShouldEvaluateEqualsConditionAsTrue()
        {
            var expression = "'Test1' equals 'Test1'";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #7
0
        public void ShouldEvaluateOrTruthyComplexConditions()
        {
            var expression = "'Test1' equals 'Test1' or 'Test2' equals 'Test2'";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #8
0
        public void ShouldEvaluateFalsyComplexConditions()
        {
            var expression = "Test2 endsWith Test1 and Test2 endsWith Test2";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsFalse(result);
        }
Пример #9
0
        public void ShouldEvaluateAndTruthyComplexConditionsWrappedInParens()
        {
            var expression = "(Test1 endsWith Test1) and (Test2 endsWith Test2)";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #10
0
        public void ShouldEvaluateEndsWithConditionAsTrue()
        {
            var expression = "Test1 endsWith Test1";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #11
0
        public void ShouldEvaluateOrTruthyComplexConditions()
        {
            var expression = "Test1 endsWith Test1 or Test2 endsWith Test2";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #12
0
        public void ShouldEvaluateEqualsConditionAsFalse()
        {
            var expression = "Test1 equals Test2";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsFalse(result);
        }
Пример #13
0
        public void ShouldEvaluateAndTruthyComplexConditions()
        {
            var expression = "Test1 equals Test1 and Test2 equals Test2";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #14
0
        public void ShouldEvaluateConditionsContainingTrueKeyword()
        {
            var expression = "true contains true";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #15
0
        public void ShouldEvaluateFalseComplexConditions()
        {
            var expression = "'Test2' contains 'Test1' and 'Test1' contains 'Test2'";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsFalse(result);
        }
Пример #16
0
        public void ShouldEvaluateOrTruthyComplexConditionsWithSpecialOperands()
        {
            var expression = "'Test1.Test1' contains 'Test1' or 'Test2' contains 'Test2'";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #17
0
        public void ShouldEvaluateContainsConditionWithWhitespacesAsFalse()
        {
            var expression = "'Solution items' contains 'Test2'";
            var compiler   = new ConditionCompiler(expression);
            var result     = compiler.Execute();

            Assert.IsFalse(result);
        }
Пример #18
0
        public void ShouldEvaluateAndTruthyComplexConditionsWrappedInParens()
        {
            var expression = "('Test1' contains 'Test1') and ('Test2' contains 'Test2')";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #19
0
        public void ShouldEvaluateStartsWithConditionAsFalse()
        {
            var expression = "'Test1' startsWith 'Test2'";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsFalse(result);
        }
Пример #20
0
        public void ShouldEvaluateContainsWithNoContainingString()
        {
            var expression = "'test1' contains 'p'";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsFalse(result);
        }
Пример #21
0
        public void ShouldEvaluateConditionsContainingCombinedKeyword()
        {
            var expression = "true startsWith false";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsFalse(result);
        }
Пример #22
0
        public void ShouldEvaluateAndTruthyComplexConditions()
        {
            var expression = "'Test1' startsWith 'Test1' and 'Test2' startsWith 'Test2'";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #23
0
        public void ShouldEvaluateContainsConditionAsTrueWrappedInParens()
        {
            var expression = "('Test1' contains 't1')";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #24
0
        public void ShouldEvaluateStartsWithConditionAsTrueWrappedInParens()
        {
            var expression = "('Test1' startsWith 'te')";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #25
0
        public void ShouldEvaluateEqualsConditionAsTrueWrappedInParens()
        {
            var expression = "(Test1 equals Test1)";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsTrue(result);
        }
Пример #26
0
        public void ShouldEvaluateContainsConditionWithAliasAsFalse()
        {
            var expression = "$this contains 'Test2'";
            var compiler   = new ConditionCompiler(expression);
            var result     = (bool)compiler.Execute();

            Assert.IsFalse(result);
        }
Пример #27
0
        public void Initialize(AppConfig appConfig)
        {
            _appConfig = appConfig;

            var conditionCompiler = new ConditionCompiler();
            var conditions        = conditionCompiler.Compile(_appConfig.Conditions.Where(x => x.Type == ConditionType.Regular));

            _conditionFilter = new ConditionFilter(_stateStore, conditions);
        }
        private Condition compile(string conditionText)
        {
            var settings = new ConditionSettings(conditionText, PowerStatus.Undefined, ConditionType.Regular, "", new Socket(1, ""));

            var compiler = new ConditionCompiler();

            return(compiler.Compile(new List <ConditionSettings>()
            {
                settings
            }).FirstOrDefault());
        }
Пример #29
0
        public override void Compile(TextWriter writer, bool isRootStatement)
        {
            string label = Context.GetNextLabelNumber().ToString();

            writer.WriteLine($"  while{label}:");
            ConditionCompiler.CompileBranchNegated(writer, $"endwhile{label}");
            //JR_LTEQF VI 0.0 endwhile0
            writer.WriteLine($"  whilebody{label}:");
            ParentStatement.WhileBody.Compile(writer, false);
            //writer.WriteLine($"    JR whilebody{label}");
            // JR_GTF VI 0.0 whilebody0
            ConditionCompiler.CompileBranch(writer, $"whilebody{label}");
            writer.WriteLine($"  endwhile{label}:");
        }
Пример #30
0
        /// <summary>
        /// Gets all the projects which satisfy given expression
        /// </summary>
        /// <param name="projectNameExpression">Expression given in the QueryLanguage form</param>
        /// <returns>List of Visual Studio projects</returns>
        public List <Project> GetProjects(string expression)
        {
            var result   = new List <Project>();
            var projects = GetProjects();

            foreach (var project in projects)
            {
                var projectName = project.Name;
                var condition   = new ConditionCompiler(expression, projectName);
                if (condition.Execute())
                {
                    result.Add(project);
                }
            }
            return(result);
        }
Пример #31
0
        public IEnumerable<IProjectItemModel> GetProjectItems(string expression, string propertyName = "FileName")
        {
            var result = new List<IProjectItemModel>();
            foreach (var item in ProjectItems)
            {
                var condition = new ConditionCompiler(expression, item.GetProperty(propertyName));
                if (condition.Execute())
                    result.Add(item);

                var subItems = item.GetProjectItems(expression);
                if (subItems != null)
                {
                    subItems.Remove(item);
                    result.AddRange(subItems);
                }
            }
            return result;
        }
Пример #32
0
        public List <IProjectItemModel> GetProjectItems(string expression)
        {
            var result    = new List <IProjectItemModel>();
            var condition = new ConditionCompiler(expression, Name);

            if (condition.Execute())
            {
                result.Add(this);
            }

            foreach (var item in ProjectItems)
            {
                var subItems = item.GetProjectItems(expression);
                if (subItems != null)
                {
                    result.AddRange(subItems);
                }
            }
            return(result);
        }
Пример #33
0
        public void Compile(ByteCodeGenerator generator)
        {
            generator.PushScope();

            var start = generator.CurrentPC();
            new StatementCompiler(node.Initialiser).Compile(generator);

            var item = new ConditionCompiler(node.Condition).Compile(generator);
            var loopDone = item.JumpFalse();

            generator.ResolveChain(item.TrueJumps);

            new StatementCompiler(node.Body).Compile(generator);
            new StatementCompiler(node.Updater).Compile(generator);

            generator.ResolveChain(generator.Branch(OpCodeValue.@goto), start);

            generator.PopScope();

            generator.ResolveChain(loopDone);
        }
Пример #34
0
        public void Compile(ByteCodeGenerator generator)
        {
            var start = generator.EntryPoint();

            // Test Condition
            var item = new ConditionCompiler(node.Expression).Compile(generator);
            var loopDone = item.JumpFalse();

            generator.ResolveChain(item.TrueJumps);

            // Run Body
            generator.PushScope();

            new StatementCompiler(node.Statement).Compile(generator);
            generator.ResolveChain(generator.Branch(OpCodeValue.@goto), start);

            generator.PopScope();

            // End
            generator.ResolveChain(loopDone);
        }