コード例 #1
0
        public DeepEnds.Core.Dependency Create(string name, string fullName, DeepEnds.Core.Dependency parent)
        {
            var leaf = this.Dependencies.Create(name, parent);

            parent.AddChild(leaf);
            this.leaves[fullName] = leaf;
            return(leaf);
        }
コード例 #2
0
        public void AddDependency(DeepEnds.Core.Dependency leaf, string dependency)
        {
            if (!this.sets.ContainsKey(leaf))
            {
                this.sets[leaf] = new HashSet <string>();
            }

            this.sets[leaf].Add(dependency);
        }
コード例 #3
0
ファイル: FileVisitor.cs プロジェクト: viboes/DeepEnds
        public FileVisitor(DeepEnds.Core.Parser parser, Dictionary <string, DeepEnds.Core.Dependency> leaves, Dictionary <DeepEnds.Core.Dependency, HashSet <string> > links, TextWriter logger)
        {
            this.parser = parser;
            this.leaves = leaves;
            this.links  = links;
#if false
            this.visited = new HashSet <string>();
#endif
            this.logger     = logger;
            this.namespaces = string.Empty;
            this.current    = null;
        }
コード例 #4
0
        private void Add(DeepEnds.Core.Dependency leaf, TypeReference type)
        {
            var a = type.ToString();

            a = a.Replace("<", ",").Replace(">", ",").Replace("`", ",").Replace("[]", string.Empty).Replace("&", string.Empty).Replace("/", ".");
            foreach (var bit in a.Split(','))
            {
                int i;
                if (!System.Int32.TryParse(bit, out i))
                {
                    this.parser.AddDependency(leaf, bit);
                }
            }
        }
コード例 #5
0
ファイル: Parse.cs プロジェクト: viboes/DeepEnds
        private void ReadNodes(System.Xml.XmlElement root)
        {
            var elements = new List <System.Xml.XmlElement>();

            this.SelectNodes(root, "Node", elements);
            foreach (var node in elements)
            {
                DeepEnds.Core.Dependency dep = null;
                var label = node.GetAttribute("Label");
                if (label.Length == 0)
                {
                    dep = this.parser.Dependencies.Root;
                }
                else
                {
                    dep = new DeepEnds.Core.Dependency(label, null);
                }

                var id = node.GetAttribute("Id");
                this.lookup[id] = dep;

                string loc = string.Empty;
                if (node.HasAttribute("LOC"))
                {
                    loc     = node.GetAttribute("LOC");
                    dep.LOC = System.Convert.ToInt32(loc);
                }

                string reference = string.Empty;
                if (node.HasAttribute("Reference"))
                {
                    reference = node.GetAttribute("Reference");
                    foreach (var key in this.paths.Keys)
                    {
                        reference = reference.Replace(key, this.paths[key]);
                    }

                    this.parser.Sources.Create(dep, new Core.SourceProvider(reference));
                }
            }
        }
コード例 #6
0
        public void Finalise(string sep)
        {
            foreach (var leaf in this.sets.Keys)
            {
                var path = leaf.Path(sep);
                foreach (var item in this.sets[leaf])
                {
                    if (item == path)
                    {
                        continue;
                    }

                    DeepEnds.Core.Dependency dep = null;
                    if (this.leaves.ContainsKey(item))
                    {
                        dep = this.leaves[item];
                    }

                    leaf.AddDependency(item, dep);
                }
            }
        }
コード例 #7
0
ファイル: ParseTree.cs プロジェクト: viboes/DeepEnds
 public TypeWalker(DeepEnds.Core.Parser parser, DeepEnds.Core.Dependency leaf, SemanticModel model)
 {
     this.parser = parser;
     this.leaf   = leaf;
     this.model  = model;
 }
コード例 #8
0
ファイル: FileVisitor.cs プロジェクト: viboes/DeepEnds
        public CXChildVisitResult VisitFile(CXCursor cursor, CXCursor parent, IntPtr data)
        {
            var location = clang.getCursorLocation(cursor);

            if (clang.Location_isInSystemHeader(location) != 0)
            {
                return(CXChildVisitResult.CXChildVisit_Continue);
            }

#if false
            if (false)
            {
                CXFile file;
                uint   i, j, k;
                clang.getFileLocation(location, out file, out i, out j, out k);
                var fileName = clang.getFileName(file).ToString().Replace('/', System.IO.Path.PathSeparator).Replace('\\', System.IO.Path.PathSeparator);

                if (this.visited.Contains(fileName))
                {
                    return(CXChildVisitResult.CXChildVisit_Continue);
                }

                this.visited.Add(fileName);
            }
#endif

            CXCursorKind curKind = clang.getCursorKind(cursor);

            if (curKind == CXCursorKind.CXCursor_Namespace)
            {
                var previous = this.namespaces;
                this.namespaces += "." + clang.getCursorSpelling(cursor).ToString();
                clang.visitChildren(cursor, this.VisitFile, new CXClientData(IntPtr.Zero));
                this.namespaces = previous;
            }
            else if (curKind == CXCursorKind.CXCursor_ClassDecl || curKind == CXCursorKind.CXCursor_StructDecl || curKind == CXCursorKind.CXCursor_UnionDecl)
            {
                var fullName = FullName(cursor);

                if (!this.leaves.ContainsKey(fullName))
                {
                    var filter = string.Empty;
                    var name   = fullName;
                    var i      = fullName.LastIndexOf(".");
                    if (i != -1)
                    {
                        name   = fullName.Substring(i + 1);
                        filter = fullName.Substring(0, i);
                    }

                    var branch = this.parser.Dependencies.GetPath(filter, ".");
                    var leaf   = this.parser.Create(name, fullName, branch);
                    this.SetSourceProvider(leaf, cursor);
                    this.leaves[fullName] = leaf;

                    this.current             = leaf;
                    this.links[this.current] = new HashSet <string>();
                }
                else
                {
                    var leaf = this.leaves[fullName];
                    this.current     = leaf;
                    this.hasChildren = false;
                    clang.visitChildren(cursor, this.VisitChildren, new CXClientData(IntPtr.Zero));
                    if (this.hasChildren)
                    {
                        this.SetSourceProvider(leaf, cursor);
                    }
                }

                clang.visitChildren(cursor, this.VisitClass, new CXClientData(IntPtr.Zero));
                this.current = null;
            }
            else if (curKind == CXCursorKind.CXCursor_CXXMethod || curKind == CXCursorKind.CXCursor_Constructor || curKind == CXCursorKind.CXCursor_Destructor)
            {
                this.current = null;

                var fullName = FileVisitor.GetClass(cursor);
                if (fullName.Length == 0)
                {
                    return(CXChildVisitResult.CXChildVisit_Continue);
                }

                if (this.namespaces.Length > 0)
                {
                    fullName = this.namespaces.Substring(1) + "." + fullName;
                }

                if (this.leaves.ContainsKey(fullName))
                {
                    this.current = this.leaves[fullName];
                    clang.visitChildren(cursor, this.VisitClass, new CXClientData(IntPtr.Zero));
                    this.current = null;
                }
                else
                {
                    this.logger.Write("Cannot find class ");
                    this.logger.WriteLine(fullName);
                }
            }
            else if (curKind != CXCursorKind.CXCursor_UsingDirective && curKind != CXCursorKind.CXCursor_VarDecl)
            {
                this.logger.Write("Skipping ");
                this.logger.WriteLine(curKind.ToString());
            }

            return(CXChildVisitResult.CXChildVisit_Continue);
        }
コード例 #9
0
        private void Process(DeepEnds.Core.Dependency leaf, TypeDefinition type)
        {
            foreach (var field in type.Fields)
            {
                this.Add(leaf, field.FieldType);
            }

            foreach (var inter in type.Interfaces)
            {
                this.Add(leaf, inter);
            }

            foreach (var even in type.Events)
            {
                this.Add(leaf, even.EventType);
            }

            foreach (var prop in type.Properties)
            {
                this.Add(leaf, prop.PropertyType);
            }

            foreach (var attr in type.CustomAttributes)
            {
                this.Add(leaf, attr.Constructor.DeclaringType);
                foreach (var arg in attr.ConstructorArguments)
                {
                    var attrType = arg.Value as TypeDefinition;
                    if (attrType != null)
                    {
                        this.Add(leaf, arg.Value as TypeDefinition);
                    }
                }
            }

            foreach (var method in type.Methods)
            {
                foreach (var p in method.CustomAttributes)
                {
                    this.Add(leaf, p.Constructor.DeclaringType);
                }

                foreach (var p in method.Parameters)
                {
                    this.Add(leaf, p.ParameterType);
                }

                this.Add(leaf, method.ReturnType);
                if (method.Body == null)
                {
                    continue;
                }

                foreach (var local in method.Body.Variables)
                {
                    this.Add(leaf, local.VariableType);
                }

                foreach (var instruction in method.Body.Instructions)
                {
                    var methodReference = instruction.Operand as MethodReference;
                    if (methodReference != null)
                    {
                        this.Add(leaf, methodReference.DeclaringType);
                        this.Add(leaf, methodReference.ReturnType);
                    }

                    var field = instruction.Operand as FieldDefinition;
                    if (field != null)
                    {
                        this.Add(leaf, field.DeclaringType);
                    }

                    var property = instruction.Operand as PropertyDefinition;
                    if (property != null)
                    {
                        this.Add(leaf, property.DeclaringType);
                        this.Add(leaf, property.PropertyType);
                    }

                    var methodDef = instruction.Operand as MethodDefinition;
                    if (methodDef != null)
                    {
                        this.Add(leaf, methodDef.DeclaringType);
                    }

                    var typeDef = instruction.Operand as TypeDefinition;
                    if (typeDef != null)
                    {
                        this.Add(leaf, typeDef);
                    }
                }
            }

            foreach (var nest in type.NestedTypes)
            {
                var fullName = nest.FullName.Replace("/", ".");
                var nested   = this.parser.Create(nest.Name, fullName, leaf);
                this.Process(nested, nest);
            }
        }