/// <summary> /// Identify renaming operation in macro-related conflicts /// </summary> /// <param name="x">Input conflict</param> /// <returns>Returns macro related nodes that are renames</returns> public static List <Node> FindRename(MergeConflict x) { List <Node> nodes = new List <Node>(); foreach (Node node1 in x.Downstream) { string value1 = NodeValue(node1, Path); if (!value1.Contains(".h")) { string split = value1.Split('(')[0]; foreach (Node node2 in x.Upstream) { string value2 = NodeValue(node2, Path); if (split != value2.Split('(')[0]) { if (split.Split('_').Length > 0 && value2.Split('(')[0].Split('_').Length > 0) { if (split.Split('_')[0] == value2.Split('(')[0].Split('_')[0]) { nodes.Add(node2); } } } } } } return(nodes); }
/// <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}\""))); }
/// <summary> /// Identifies the project specific pattern. /// </summary> /// <param name="x">The input merge conflict.</param> /// <param name="paths"></param> /// <returns>Returns a list of node that has project specific pattern.</returns> public static IReadOnlyList <Node> FindFreqPattern(MergeConflict x, string[] paths) { IEnumerable <Node> nodes = from stream in Concat(x.Downstream, x.Upstream) from path in paths where NodeValue(stream, Path) == path select stream; return(nodes.ToList()); }
/// <summary> /// Selects the downstream line by index. /// </summary> /// <param name="x">The input merge conflict.</param> /// <param name="k">index</param> /// <returns>Returns the downstream node with the matched index.</returns> public static IReadOnlyList <Node> SelectDownstreamIdx(MergeConflict x, int k) { List <Node> result = new List <Node>(); if (x.Downstream.Count > k) { result.Add(x.Downstream[k]); } return(result); }
/// <summary> /// Returns a list of matched nodes. /// </summary> /// <param name="x">The input merge conflict.</param> /// <param name="paths">List of include file names or macro-related content.</param> /// <returns>Returns the resolved conflict.</returns> public static List <IReadOnlyList <Node> > FindMatch(MergeConflict x, string[] paths) { List <IReadOnlyList <Node> > result = new List <IReadOnlyList <Node> > { FindDuplicateInUpstreamAndDownstream(x), FindFreqPattern(x, paths), FindDuplicateInDownstreamOutside(x), FindDuplicateInUpstreamOutside(x), FindUpstreamSpecific(x), FindDownstreamSpecific(x) }; return(result); }
/// <summary> /// Identifies the fork specific duplicates. /// </summary> /// <param name="x">The merge conflict input.</param> /// <returns>Returns nodes that are duplicate inside the conflicts</returns> public static IReadOnlyList <Node> FindDuplicateDownstreamSpecific(MergeConflict x) { List <Node> upstream = new List <Node>(); List <Node> downstream = new List <Node>(); foreach (Node n in x.Upstream) { if (MainSpecificKeywords.Any(s => NodeValue(n, "path").Contains(s))) { upstream.Add(n); } } foreach (Node n in x.Downstream) { if (ProjectSpecificKeywords.Any(s => NodeValue(n, "path").Contains(s))) { downstream.Add(n); } } List <Node> temp = new List <Node>(); foreach (Node up in upstream) { foreach (Node down in downstream) { string downP = ""; string upP = ""; string[] uppath = NodeValue(up, "path").Split('_'); string[] downpath = NodeValue(down, "path").Split('_'); for (int i = 1; i < uppath.Length; i++) { upP = upP + uppath[i]; } for (int i = 1; i < downpath.Length; i++) { downP = downP + downpath[i]; } if (upP == downP) { temp.Add(up); } } } return(temp.AsReadOnly()); }
/// <summary> /// Identify duplicate headers inside the conflicting region. /// </summary> /// <param name="x">The input merge conflict.</param> /// <returns>Returns the duplicate node within the downstream and the upstream.</returns> public static IReadOnlyList <Node> FindDuplicateInUpstreamAndDownstream(MergeConflict x) { List <Node> nodes = new List <Node>(); foreach (Node upstream in x.Upstream) { string upstreamValue = NodeValue(upstream, Path); foreach (Node downstream in x.Downstream) { string downstreamValue = NodeValue(downstream, Path); if (IsMatchPath(upstreamValue, downstreamValue)) { nodes.Add(upstream); } } } return(nodes); }
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)); }
/// <summary> /// Identify duplicate headers outside the conflicting region (upstream specific). /// </summary> /// <param name="x">The input merge conflict.</param> /// <returns>Returns the duplicate nodes outside the conflicted region.</returns> public static List <Node> FindDuplicateInUpstreamOutside(MergeConflict x) { List <Node> nodes = new List <Node>(); IReadOnlyList <Node> upstreamFileIncludeAst = x.UpstreamContent; foreach (Node upstream in x.Upstream) { string upstreamValue = NodeValue(upstream, Path); foreach (Node outsideInclude in upstreamFileIncludeAst) { string outsideIncludeValue = NodeValue(outsideInclude, Path); if (IsMatchPath(outsideIncludeValue, upstreamValue)) { nodes.Add(upstream); } } } return(nodes); }
/// <summary> /// Executes the program on the <paramref name="input" /> to obtain the output. /// </summary> /// <param name="input">The input token.</param> /// <returns>The result output.</returns> public override IReadOnlyList <Node> Run(MergeConflict input) { State inputState = State.CreateForExecution(LanguageGrammar.Instance.Grammar.InputSymbol, input); return(ProgramNode.Invoke(inputState) as IReadOnlyList <Node>); }
/// <summary> /// Identify the downstream specific header path. /// </summary> /// <param name="x">The input merge conflict.</param> /// <returns>Returns the downstream specific section of the conflict.</returns> public static List <Node> FindDownstreamSpecific(MergeConflict x) { return(FindSpecific(x.Downstream, x.Upstream)); }
/// <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()); }
/// <summary> /// Select the node with the specified path (downstream). /// </summary> /// <param name="x">The input merge conflict.</param> /// <param name="k">Path name</param> /// <returns>Returns the list of downstream nodes that matches with the path name.</returns> public static IReadOnlyList <Node> SelectUpstreamPath(MergeConflict x, string k) { return(SelectPath(x.Upstream, k)); }
/// <summary> /// Selects upstream. /// </summary> /// <param name="x">The input merge conflict.</param> /// <returns>Return list of upstream nodes.</returns> public static IReadOnlyList <Node> SelectUpstream(MergeConflict x) { return(x.Upstream); }
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()); }
public ResolutionExample(MergeConflict input, string resolved) : base(input, ResolutionToString(resolved)) { }