/// <summary> /// Executes the program on the <paramref name="input" /> to obtain the output. /// </summary> /// <param name="input">The input token.</param> /// <returns>The result string output.</returns> public string RunString(MergeConflict input) { return(string.Join( System.Environment.NewLine, Run(input).Select(n => Semantics.NodeValue(n, Path)) .Where(path => !string.IsNullOrEmpty(path)) .Select(path => $"{Include} \"{path}\""))); }
internal DisjunctiveExamplesSpec WitnessApplyPattern(GrammarRule rule, DisjunctiveExamplesSpec spec) { var result = new Dictionary <State, IEnumerable <object> >(); foreach (KeyValuePair <State, IEnumerable <object> > example in spec.DisjunctiveExamples) { State inputState = example.Key; MergeConflict input = (MergeConflict)inputState[Grammar.InputSymbol]; List <object> ret = example.Value.OfType <IReadOnlyList <Node> >() .Select(output => Semantics.Concat(input.Upstream, input.Downstream).Count != output.Count) .Distinct() .Cast <object>() .ToList(); result[inputState] = ret; } return(DisjunctiveExamplesSpec.From(result)); }
internal DisjunctiveExamplesSpec WitnessConcatTree2(GrammarRule rule, DisjunctiveExamplesSpec spec, DisjunctiveExamplesSpec tree1Spec) { var result = new Dictionary <State, IEnumerable <object> >(); foreach (KeyValuePair <State, IEnumerable <object> > example in spec.DisjunctiveExamples) { State inputState = example.Key; List <IReadOnlyList <Node> > possibleCombinations = new List <IReadOnlyList <Node> >(); foreach (IReadOnlyList <Node> tree1NodeList in tree1Spec.DisjunctiveExamples[inputState]) { IEnumerable <Node> temp = from output in example.Value from outNode in (IReadOnlyList <Node>)output where tree1NodeList.All( tree1Node => Semantics.NodeValue(tree1Node, Path) != Semantics.NodeValue(outNode, Path)) select outNode; possibleCombinations.Add(temp.ToList()); } result[inputState] = possibleCombinations; } return(DisjunctiveExamplesSpec.From(result)); }
/// <summary> /// Identifies the dependecy related pattern. /// </summary> /// <param name="x">The input merge conflict.</param> /// <returns>Returns the dependency pattern related nodes.</returns> public static IReadOnlyList <Node> FindDependency(MergeConflict x) { List <Node> temp = new List <Node>(); foreach (Node n in Semantics.Concat(x.Upstream, x.Downstream)) { string filePath = x.BasePath + "\\" + NodeValue(n, "path").Replace("/", "\\"); if (System.IO.File.Exists(@filePath)) { string[] lines = System.IO.File.ReadAllLines(@filePath); bool flag_conflict = false; bool flag_non_conflict = false; bool flag = false; foreach (string line in lines) { if (!line.StartsWith("//") && flag == false) { if (line.Contains("namespace")) { string[] words = line.Split(' '); int index = 0; for (int i = 0; i < words.Length; i++) { if (words[i] == "namespace") { index = i; flag = true; } } for (int i = index + 1; i < words.Length; i++) { if (words[i] != "{" && words[i] != " ") { foreach (Node node in x.Upstream) { string conflict = NodeValue(node, "path"); if (conflict.Contains(words[i] + "::")) { flag_conflict = true; } } foreach (Node node in x.Downstream) { string conflict = NodeValue(node, "path"); if (conflict.Contains(words[i] + "::")) { flag_conflict = true; } } foreach (Node node in x.UpstreamContent) { string conflict = NodeValue(node, "path"); if (conflict.Contains(words[i] + "::")) { flag_non_conflict = true; } } } } if (flag_conflict == true && flag_non_conflict == false) { temp.Add(n); } } } } } } return(temp.AsReadOnly()); }
internal Optional <ProgramSet> LearnDupLet(SynthesisEngine engine, LetRule rule, LearningTask <DisjunctiveExamplesSpec> task, CancellationToken cancel) { var examples = task.Spec; List <string[]> pathsArr = new List <string[]>(); foreach (KeyValuePair <State, IEnumerable <object> > example in examples.DisjunctiveExamples) { State inputState = example.Key; var input = example.Key[Grammar.InputSymbol] as MergeConflict; List <string> idx = new List <string>(); foreach (IReadOnlyList <Node> output in example.Value) { foreach (Node n in Semantics.Concat(input.Upstream, input.Downstream)) { bool flag = false; n.Attributes.TryGetValue(Path, out string inPath); foreach (Node node in output) { node.Attributes.TryGetValue(Path, out string outputPath); if (inPath == outputPath) { flag = true; } } if (!flag) { idx.Add(inPath); } } } pathsArr.Add(idx.ToArray()); } pathsArr.Add(new string[1] { string.Empty }); List <ProgramSet> programSetList = new List <ProgramSet>(); foreach (string[] path in pathsArr) { NonterminalRule findMatchRule = Grammar.Rule(nameof(Semantics.FindMatch)) as NonterminalRule; ProgramSet letValueSet = ProgramSet.List( Grammar.Symbol("find"), new NonterminalNode( findMatchRule, new VariableNode(Grammar.InputSymbol), new LiteralNode(Grammar.Symbol("paths"), path))); var bodySpec = new Dictionary <State, IEnumerable <object> >(); foreach (KeyValuePair <State, IEnumerable <object> > kvp in task.Spec.DisjunctiveExamples) { State input = kvp.Key; MergeConflict x = (MergeConflict)input[Grammar.InputSymbol]; List <IReadOnlyList <Node> > dupValue = Semantics.FindMatch(x, path); State newState = input.Bind(rule.Variable, dupValue); bodySpec[newState] = kvp.Value; } LearningTask bodyTask = task.Clone(rule.LetBody, new DisjunctiveExamplesSpec(bodySpec)); ProgramSet bodyProgramSet = engine.Learn(bodyTask, cancel); var dupLetProgramSet = ProgramSet.Join(rule, letValueSet, bodyProgramSet); programSetList.Add(dupLetProgramSet); } ProgramSet ps = new UnionProgramSet(rule.Head, programSetList.ToArray()); return(ps.Some()); }