public ReferrerTreeViewModel(ReferenceGraph graph, string targetString)
        {
            var rootNode = ReferrerTreeNode.CreateRoot(graph.TargetSet, targetString);

            rootNode.Expand();

            Roots = new[] { rootNode };
        }
        public void NonDependentReferences_ForRootedWorld()
        {
            var referenceGraph = new ReferenceGraph(
                catalog: RootedWorld.Catalog,
                rootTable: RootedWorld.NationsTable);

            Assert.AreEqual(0, referenceGraph[0].NonDependentReferences.Count);
            Assert.AreEqual(0, referenceGraph[1].NonDependentReferences.Count);
            Assert.AreEqual(0, referenceGraph[2].NonDependentReferences.Count);
        }
Esempio n. 3
0
 public Project(UInt32 tag, PathDescriptor location)
     : base(location, location.Name)
 {
     this.tag        = tag;
     this.location   = location;
     this.files      = new ReferenceGraph();
     this.references = new List <Project>();
     this.externals  = new List <FileDescriptor>();
     this.target     = BuildTarget.Default;
 }
Esempio n. 4
0
        public LocalProfile()
        {
            AutoConfigResult result = AutoConfigResult.Create();

            AutoConfig.MapToObject <LocalProfile>(true, ref result);
            if (printToolStack)
            {
                toolStackGraph = new ReferenceGraph();
                toolGraphLock  = new PooledSpinLock();
            }
        }
        public void TableOrder_ForUnrootedWorld()
        {
            var referenceGraph = new ReferenceGraph(
                catalog: UnrootedWorld.Catalog,
                rootTable: UnrootedWorld.NationsTable);

            CollectionAssert.AreEqual(new[]
            {
                UnrootedWorld.NationsTable,
                UnrootedWorld.ProvincesTable,
                UnrootedWorld.ResidentsTable
            }, referenceGraph.Tables.ToArray());
        }
Esempio n. 6
0
        void AddProjectToGraph(ReferenceGraph graph, Project project)
        {
            ProjectGraphNode root = (graph.Add <ProjectGraphNode>(project) as ProjectGraphNode);

            foreach (Project reference in project.References)
            {
                ProjectGraphNode child = graph.Nodes.Where(x => x.File == reference).FirstOrDefault() as ProjectGraphNode;
                if (child == null)
                {
                    child = (graph.Add <ProjectGraphNode>(root, reference) as ProjectGraphNode);
                }
                else
                {
                    child.AddDependency(root);
                }
            }
        }
        public void DependentReferences_ForRootedWorld()
        {
            var referenceGraph = new ReferenceGraph(
                catalog: RootedWorld.Catalog,
                rootTable: RootedWorld.NationsTable);

            ReferenceGraph.Reference reference;

            Assert.AreEqual(0, referenceGraph[0].DependentReferences.Count);

            reference = referenceGraph[1].DependentReferences.Single();
            Assert.AreEqual(RootedWorld.ProvincesTable.FindColumn("NationID"), reference.ParentColumn);
            Assert.AreEqual(RootedWorld.NationsTable, reference.ReferencedTable);

            reference = referenceGraph[2].DependentReferences.Single();
            Assert.AreEqual(RootedWorld.ResidentsTable.FindColumn("ProvinceID"), reference.ParentColumn);
            Assert.AreEqual(RootedWorld.ProvincesTable, reference.ReferencedTable);
        }
Esempio n. 8
0
        public void Assign_replaces_references()
        {
            var graph      = new ReferenceGraph();
            var v          = graph.AddVariable(Variable("foo"));
            var mockSyntax = new Mock <IAbstractSyntax>();
            var ref1       = graph.AddNewObject(Ownership.Owns, Access.Mutable, mockSyntax.Object, false, false);

            v.AddReference(ref1);
            var mockExpression = new Mock <IExpression>();
            var ref2           = graph.AddNewObject(Ownership.Owns, Access.Mutable, mockExpression.Object, false, false);
            var temp           = graph.AddTempValue(mockExpression.Object, DataType());

            temp.AddReference(ref2);

            v.Assign(temp);

            Assert.Equal(new[] { ref2 }, v.References);
        }
        public void NonDependentReferences_ForUnrootedWorld()
        {
            var referenceGraph = new ReferenceGraph(
                catalog: UnrootedWorld.Catalog,
                rootTable: UnrootedWorld.NationsTable);

            ReferenceGraph.Reference reference;

            Assert.AreEqual(0, referenceGraph[0].NonDependentReferences.Count);

            reference = referenceGraph[1].NonDependentReferences.Single();
            Assert.AreEqual(UnrootedWorld.ProvincesTable.FindColumn("LeaderResidentID"), reference.ParentColumn);
            Assert.AreEqual(UnrootedWorld.ResidentsTable, reference.ReferencedTable);

            reference = referenceGraph[2].NonDependentReferences.Single(r => r.ReferencedTable == UnrootedWorld.ResidentsTable);
            Assert.AreEqual(UnrootedWorld.ResidentsTable.FindColumn("SpouseResidentID"), reference.ParentColumn);
            reference = referenceGraph[2].NonDependentReferences.Single(r => r.ReferencedTable == UnrootedWorld.ProvincesTable);
            Assert.AreEqual(UnrootedWorld.ResidentsTable.FindColumn("FavoriteProvinceID"), reference.ParentColumn);
            Assert.AreEqual(2, referenceGraph[2].NonDependentReferences.Count);
        }
Esempio n. 10
0
        public static ReferenceGraph Build(ClrHeap heap, HashSet <ulong> targetAddresses, CancellationToken token = default)
        {
            var graph = new ReferenceGraph();

            var seen = new ObjectSet(heap);

            var stack = new HeapWalkStack();

            var nodeByAddress = new Dictionary <ulong, ReferenceGraphNode>();

            var chainCache = new Dictionary <(uint metadataToken, int fieldOffset), List <FieldReference> >();

            // For each root
            foreach (var root in heap.EnumerateRoots(enumerateStatics: true))
            {
                stack.Clear();

                if (root.Type == null)
                {
                    // This happens, though not sure why
                    continue;
                }

                stack.Push(new ClrObjectReference(-1, root.Object, root.Type));

                while (!stack.IsEmpty)
                {
                    token.ThrowIfCancellationRequested();

                    ref var top = ref stack.Peek();

                    if (top.Enumerator.MoveNext())
                    {
                        var o = top.Enumerator.Current;

                        if (targetAddresses.Contains(o.Address))
                        {
                            // Found a match
                            stack.Push(o);

                            // Ensure our stack's root is registered with the graph
                            ref var rootLevel = ref stack[0];
                            if (rootLevel.GraphNode == null)
                            {
                                var rootNode = new RootGraphNode(root);
                                nodeByAddress[root.Object] = rootNode;
                                rootLevel.GraphNode        = rootNode;
                                graph.Roots.Add(rootNode);
                            }

                            // Build path through graph for the current stack
                            // Skip the first node as it's always non-null
                            for (var i = 1; i < stack.Count; i++)
                            {
                                ref var level = ref stack[i];

                                // Ensure all levels have a graph node object
                                if (level.GraphNode == null)
                                {
                                    if (!nodeByAddress.TryGetValue(level.Reference.Address, out var node))
                                    {
                                        node = new ReferenceGraphNode(level.Reference.Object);
                                        nodeByAddress[level.Reference.Address] = node;

                                        if (i == stack.Count - 1)
                                        {
                                            graph.TargetSet.Add(node);
                                        }
                                    }

                                    level.GraphNode = node;

                                    ref var levelBefore = ref stack[i - 1];

                                    var referenceChain = GetChain(levelBefore.GraphNode.Object.Type, level.Reference);

                                    level.GraphNode.Referrers.Add((node: levelBefore.GraphNode, referenceChain, fieldOffset: level.Reference.FieldOffset));
//                                    levelBefore.GraphNode.References.Add((node: level.GraphNode, referenceChain));
                                }
                            }

                            stack.Pop();
                        }
Esempio n. 11
0
        public override void Execute()
        {
            LoadInput();

            List <Project> projects = new List <Project>();

            foreach (TaskPin inputPin in inputPins)
            {
                projects.Add(inputPin.Data as Project);
            }

            Analyzer.GetModulePaths().ParallelFor((location) =>
            {
                foreach (TaskPin inputPin in inputPins)
                {
                    if ((inputPin.Data as FileDescriptor).Location.Contains(location))
                    {
                        return;
                    }
                }

                List <FileSystemDescriptor> files = Application.GetProjectFiles(location, ProjectLookup.Extensions);
                if (files.Count > 0 || files.Where(x => (x as FileDescriptor).Extension == "cs").Count() == 0)
                {
                    Project module      = ProjectLookup.CreateProject(SystemTags.SharpModule, location, files);
                    module.AssemblyType = OutputAssemblyType.Library;
                    module.IsModule     = true;

                    lock (projects)
                        if (!projects.Contains(module))
                        {
                            Application.Log(SeverityFlags.Full, "Loaded {0} module {1}", ToolDisplayName, module.Name);
                            projects.Add(module);
                        }
                }
            });
            projects.ParallelFor((project) =>
            {
                DependencyResolver.ConnectNamespaces(project, projects);
                DependencyResolver.ResolveNamespaces(project);
            });

            foreach (TaskPin inputPin in inputPins)
            {
                outputPins.Add(new FlaggedPin(this, inputPin.Data, SystemTags.Sharp));
            }

            if (printProjectStack)
            {
                PathDescriptor outputPath = Application.GetDeploymentPath(SystemTags.Analytics);
                if (!outputPath.Exists())
                {
                    try
                    {
                        outputPath.Create();
                    }
                    catch { }
                }

                ReferenceGraph moduleGraph = new ReferenceGraph();
                foreach (Project project in projects)
                {
                    project.Files.Nodes.ParallelFor((file) =>
                    {
                        file.Rect = Rectangle.Empty;
                        file.Slot = null;
                    });
                    project.Files.Save(outputPath, string.Format("{0}.cs", project.Name));
                    AddProjectToGraph(moduleGraph, project);
                }
                moduleGraph.Save(outputPath, "SharpModules");
            }
        }
Esempio n. 12
0
        public override void Execute()
        {
            LoadInput();

            List <Project> projects = new List <Project>();

            foreach (TaskPin inputPin in inputPins)
            {
                projects.Add(inputPin.Data as Project);
            }

            Analyzer.GetModulePaths().ParallelFor((location) =>
            {
                foreach (TaskPin inputPin in inputPins)
                {
                    if ((inputPin.Data as FileDescriptor).Location.Contains(location))
                    {
                        return;
                    }
                }

                foreach (BuildTarget target in CompilerServices.Targets)
                {
                    Project module; if (!ProjectLookup.FromCache(target, SystemTags.Cpp, location, out module))
                    {
                        List <FileSystemDescriptor> files = Application.GetProjectFiles(location, ProjectLookup.Extensions);
                        if (files.Count > 0)
                        {
                            module = ProjectLookup.CreateProject(module, files);
                        }
                    }

                    module.AssemblyType = OutputAssemblyType.Static;
                    module.IsModule     = true;

                    lock (projects)
                        if (!projects.Contains(module))
                        {
                            Application.Log(SeverityFlags.Full, "Loaded {0} module {1}::{2}", ToolDisplayName, module.Name, module.Target.TechnicalName);
                            projects.Add(module);
                        }
                }
            });
            projects.ParallelFor((project) =>
            {
                StorageDescriptor cache = project.Cache;
                if (project.IsCached)
                {
                    cache.Nodes.Values.ParallelFor((element) =>
                    {
                        if (element.Tag == ReferenceStorageTag)
                        {
                            projects.Where(x => x.Target.Id == project.Target.Id).ParallelFor((reference) =>
                            {
                                if (reference == element.Element as FileDescriptor)
                                {
                                    Application.Log(SeverityFlags.Full, "Cached {0} module {1}::{2}", ToolDisplayName, reference.Name, reference.Target.TechnicalName);
                                    lock (project)
                                        project.References.Add(reference);
                                }
                            });
                        }
                        else if (element.Tag == ExternalStorageTag)
                        {
                            project.Externals.Add(element.Element as FileDescriptor);
                        }
                    });
                }
                else
                {
                    DependencyResolver.ConnectFiles(project, projects);

                    foreach (Project referene in project.References)
                    {
                        cache.Store <ReferenceContainer>(referene).Tag = ReferenceStorageTag;
                    }
                    foreach (FileDescriptor referene in project.Externals)
                    {
                        cache.Store <ReferenceContainer>(referene).Tag = ExternalStorageTag;
                    }

                    cache.Save();
                }
            });

            foreach (TaskPin inputPin in inputPins)
            {
                outputPins.Add(new FlaggedPin(this, inputPin.Data, SystemTags.Cpp));
            }

            for (int i = 0; i < inputPins.Count; i++)
            {
                foreach (Project reference in (outputPins[i].Data as Project).References)
                {
                    outputPins.Add(new FlaggedPin(this, reference, SystemTags.Cpp));
                }
            }

            if (printProjectStack)
            {
                PathDescriptor outputPath = Application.GetDeploymentPath(SystemTags.Analytics);
                if (!outputPath.Exists())
                {
                    try
                    {
                        outputPath.Create();
                    }
                    catch { }
                }

                ReferenceGraph moduleGraph = new ReferenceGraph();
                foreach (Project project in projects)
                {
                    project.Files.Nodes.ParallelFor((file) =>
                    {
                        file.Rect = Rectangle.Empty;
                        file.Slot = null;
                    });
                    project.Files.Save(outputPath, string.Format("{0}.cpp", project.Name));
                    AddProjectToGraph(moduleGraph, project);
                }
                moduleGraph.Save(outputPath, "CppModules");
            }
        }