private void EntryDecl(SymbolDecl decl, bool skipChildren = false) { if (decl.OverloadKey == null) { throw new ArgumentException(); } MapKey(decl.OverloadKey, decl.OverloadKey); this.Result = new SymbolTree { Tags = decl.Tags, Key = decl.OverloadKey, DisplayName = GetDisplayName(decl), Doc = ContainsDocument(decl), }; if (this.Parent != null) { if (this.Parent.Children == null) { this.Parent.Children = new List <SymbolTree>(); } this.Parent.Children.Add(this.Result); } if (!skipChildren) { GenerateChildren(decl, this.Result); } }
static XDocument CreateSymbolTree(string nsUrlName, string urlName, SymbolDecl[] decls, Dictionary <string, string> symbolFileMapping) { var symbolParentMapping = new Dictionary <string, string>(); var forest = decls .Select(decl => GenerateSymbolTreeVisitor.Execute(decl, symbolParentMapping)) .ToArray(); var root = SymbolTree.Merge(forest); foreach (var key in symbolParentMapping.Keys) { symbolFileMapping.Add(key, "s:" + urlName); } return(new XDocument( new XElement("SymbolTree", new XAttribute("NamespaceUrlName", nsUrlName), new XElement("SymbolParentMapping", symbolParentMapping .Where(p => p.Key != p.Value) .Select(p => new XElement("Map", new XAttribute("From", p.Key), new XAttribute("To", p.Value) ) ) ), root.Serialize() ) )); }
public void SaveSymbTreeTest() { var generator = new FullProgramGenerator <MathProgram, double>(); var tree = new SymbolTree <MathProgram>(); for (var i = 0; i < NUM_PROGS; i++) { var prog = generator.Generate(MathPrimitiveSets.Default, MAX_DEPTH); tree.AddProgram(prog); Console.WriteLine(prog); } var fullPath = Path.GetFullPath("."); var imgPath = Path.Combine(fullPath, $"{SYMB_FILE_NAME}.dot.png"); File.Delete(imgPath); var dotPath = tree.ToGraphvizFile(fullPath, SYMB_FILE_NAME, GraphvizImageType.Png, WAIT_TIMEOUT); Console.WriteLine(imgPath); Assert.IsTrue(File.Exists(dotPath), $"Dot file with information tree should exist in {dotPath}"); Assert.IsTrue(new FileInfo(dotPath).Length > 0, "Dot file size should be > 0 bytes."); Assert.IsTrue(File.Exists(imgPath), $"Image file with information tree should exist in {imgPath}"); Assert.IsTrue(new FileInfo(imgPath).Length > 0, "Image size should be > 0 bytes."); #if !DEBUG File.Delete(dotPath); File.Delete(imgPath); #endif }
private void UpdateSymbolTable(FileSystemEventArgs e) { Trace.WriteLine(String.Format("Changes in file '{0}' caused rebuild of symbol tree", e.FullPath)); var st = CreateSymbolTable(); if (st != null) { _st = st; } }
private void GenerateChildren(SymbolDecl decl, SymbolTree parent) { if (decl.Children != null) { foreach (var subDecl in decl.Children) { ExecuteInternal(subDecl, parent, this.SymbolParentMapping); } } }
public static SymbolTree Execute(SymbolDecl decl, Dictionary <string, string> symbolParentMapping) { var parent = new SymbolTree(); ExecuteInternal(decl, parent, symbolParentMapping); if (parent.Children == null || parent.Children.Count != 1) { throw new ArgumentException(); } return(parent.Children[0]); }
private static SymbolTree ExecuteInternal(SymbolDecl decl, SymbolTree parent, Dictionary <string, string> symbolParentMapping) { var visitor = new GenerateSymbolTreeVisitor { Parent = parent, SymbolParentMapping = symbolParentMapping, }; decl.Accept(visitor); return(visitor.Result); }
/// <inheritdoc /> public double Calculate(ITreeProgram prog1, ITreeProgram prog2) { if (prog1 == null || prog2 == null) { return(0); } if (prog1.Equals(prog2)) { return(1); } var prog1SymbTree = new SymbolTree <ITreeProgram>(); prog1SymbTree.AddProgram(prog1); var prog2SymbTree = new SymbolTree <ITreeProgram>(); prog2SymbTree.AddProgram(prog2); return(prog1SymbTree.GetSimilarity(prog2SymbTree)); }
public FileTable(ILogger logger, String root) { if (String.IsNullOrWhiteSpace(root)) { throw new ArgumentException("root"); } _rootDirectory = root; _logger = logger; var st = CreateSymbolTable(); if (st == null) { throw new Exception(String.Format("Can't create file table for directory '{0}'", _rootDirectory)); } _st = st; InitializeFileSystemWatcher(); }
public static SymbolTree Merge(SymbolTree[] forest) { var result = new SymbolTree(); result.Key = forest[0].Key; result.DisplayName = forest[0].DisplayName; result.Doc = forest.Any(tree => tree.Doc); result.Tags = forest .SelectMany(tree => tree.Tags.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) .Distinct() .OrderBy(t => t) .Aggregate((a, b) => a + ";" + b); result.Children = forest .Where(tree => tree.Children != null) .SelectMany(tree => tree.Children) .GroupBy(tree => tree.Key) .Select(g => Merge(g.ToArray())) .ToList(); return(result); }
private SymbolTree<String, String> CreateSymbolTable() { try { Trace.WriteLine("Fetching list of files... "); var sw = Stopwatch.StartNew(); var files = Directory.GetFiles(_rootDirectory, "*", SearchOption.AllDirectories); Trace.WriteLine(String.Format("Fetched {0} file in {1}", files.Length, sw.Elapsed)); Trace.WriteLine("Building symbol tree... "); sw.Restart(); var st = new SymbolTree<String, String>(_rootDirectory); foreach (var file in files) { var relative = file.Replace(_rootDirectory, "").ToLowerInvariant(); AddFileToSymbolTree(st, relative); } Trace.WriteLine(String.Format("Built symbol tree: {0}", sw.Elapsed)); return st; } catch (Exception exn) { _logger.Log(TraceEventType.Error, "Exception occurs while trying to build SymbolTable from root directory {0}. Details: {1}", _rootDirectory, exn); } return null; }
public void SaveSymbTreeTest() { var prog = new FullProgramGenerator <MathProgram, double>().Generate(MathPrimitiveSets.Default, 4); Console.WriteLine(prog); var tree = new SymbolTree <MathProgram>(); tree.AddProgram(prog); var fullPath = Path.Combine(Path.GetFullPath("."), SYMB_FILE_NAME); File.Delete(fullPath); tree.ToD3JsonFile(fullPath); Console.WriteLine(fullPath); Assert.IsTrue(File.Exists(fullPath), $"Image file with information tree should exist in {fullPath}."); Assert.IsTrue(new FileInfo(fullPath).Length > 0, "Image size should be > 0 bytes."); #if !DEBUG File.Delete(fullPath); #endif }
private static void AddFileToSymbolTree(SymbolTree<String, String> st, String relativeFilePath) { var parts = relativeFilePath.Split(new[] { Path.DirectorySeparatorChar }); var dirs = new String[parts.Length - 2]; Array.Copy(parts, 1, dirs, 0, dirs.Length); st.AddId(dirs, parts.Last(), relativeFilePath); }