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); }
public static bool Check(string propertyName, string conditionTemplate) { var condition = conditionTemplate.Replace("${property}", propertyName); var compiler = new ConditionCompiler(condition); return((bool)compiler.Execute()); }
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); }
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!"); } } }
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()); }
public void ShouldEvaluateEqualsConditionAsTrue() { var expression = "'Test1' equals 'Test1'"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsTrue(result); }
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); }
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); }
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); }
public void ShouldEvaluateEndsWithConditionAsTrue() { var expression = "Test1 endsWith Test1"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsTrue(result); }
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); }
public void ShouldEvaluateEqualsConditionAsFalse() { var expression = "Test1 equals Test2"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsFalse(result); }
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); }
public void ShouldEvaluateConditionsContainingTrueKeyword() { var expression = "true contains true"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsTrue(result); }
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); }
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); }
public void ShouldEvaluateContainsConditionWithWhitespacesAsFalse() { var expression = "'Solution items' contains 'Test2'"; var compiler = new ConditionCompiler(expression); var result = compiler.Execute(); Assert.IsFalse(result); }
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); }
public void ShouldEvaluateStartsWithConditionAsFalse() { var expression = "'Test1' startsWith 'Test2'"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsFalse(result); }
public void ShouldEvaluateContainsWithNoContainingString() { var expression = "'test1' contains 'p'"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsFalse(result); }
public void ShouldEvaluateConditionsContainingCombinedKeyword() { var expression = "true startsWith false"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsFalse(result); }
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); }
public void ShouldEvaluateContainsConditionAsTrueWrappedInParens() { var expression = "('Test1' contains 't1')"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsTrue(result); }
public void ShouldEvaluateStartsWithConditionAsTrueWrappedInParens() { var expression = "('Test1' startsWith 'te')"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsTrue(result); }
public void ShouldEvaluateEqualsConditionAsTrueWrappedInParens() { var expression = "(Test1 equals Test1)"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsTrue(result); }
public void ShouldEvaluateContainsConditionWithAliasAsFalse() { var expression = "$this contains 'Test2'"; var compiler = new ConditionCompiler(expression); var result = (bool)compiler.Execute(); Assert.IsFalse(result); }
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()); }
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}:"); }
/// <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); }
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; }
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); }
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); }
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); }