Beispiel #1
0
    void CreateTypes(Node root)
    {
        foreach (Node n in root.Children)
        {
            if (n.IsTrue("incomplete") || !n.HasValue("name") || n.Attributes ["name"] == "::")
            {
                continue;
            }

            Namespace ns;
            switch (n.Type)
            {
            case "Class":
            case "Struct":
                ns = new Class(n);
                break;

            case "Enumeration":
                ns = new Enumeration(n);
                break;

            case "Namespace":
                ns = new Namespace(n);
                break;

            case "Typedef":
                var typeNode = GetTypeNode(n);
                if (typeNode.Type != "FunctionType")
                {
                    continue;
                }

                ns = new Function(n);
                NodeToNamespace[typeNode] = ns;
                break;

            default:
                continue;
            }

            NodeToNamespace [n] = ns;
            Lib.Namespaces.Add(ns);
        }

        foreach (Namespace ns in Lib.Namespaces)
        {
            SetParentNamespace(ns);
        }

        // NodeToNamespace mapping is complete. Lets make a copy.

        var mapping = new Dictionary <Node, Namespace> (NodeToNamespace);

        for (var i = 0; i < Lib.Namespaces.Count; i++)
        {
            Namespace ns = Lib.Namespaces [i];

            var filter = GetFilterOrDefault(ns);
            if (filter.Mode == FilterMode.Exclude)
            {
                NodeToNamespace.Remove(ns.Node);
            }

            if (filter.Mode != FilterMode.Include)
            {
                Lib.Namespaces.RemoveAt(i);
                i--;
                continue;
            }

            var klass = ns as Class;
            if (klass == null)
            {
                continue;
            }

            // Compute templates and name
            int index = klass.Name.IndexOf("<");
            if (index >= 0)
            {
                // Separate out the template class name and the template types
                string className     = klass.Name.Substring(0, index).Trim();
                string templateTypes = klass.Name.Substring(index).Trim();
                klass.TemplateName      = klass.Name;
                klass.TemplateClassName = className;
                klass.Name = CreateTemplateClassName(className, templateTypes);

                // Ensure outside references to this class use the proper name as well
                //klass.Node.Name = klass.Name;
            }

            // Compute bases
            foreach (Node bn in klass.Node.Children.Where(o => o.Type == "Base"))
            {
                var nodeForAttr = bn.NodeForAttr("type");
                if (!NodeToNamespace.ContainsKey(nodeForAttr))
                {
                    Console.WriteLine("FATAL ERROR: Base class '{0}' not found for type '{1}'", mapping[nodeForAttr].Name, klass.Name);
                    Environment.Exit(1);
                }
                Class baseClass = NodeToNamespace [nodeForAttr] as Class;
                Debug.Assert(baseClass != null);
                klass.BaseClasses.Add(baseClass);
                if (bn.IsTrue("virtual"))
                {
                    klass.VirtualBases.Add(baseClass);
                }
            }
        }
    }
Beispiel #2
0
    void CreateTypes(Node root)
    {
        foreach (Node n in root.Children)
        {
            if (n.IsTrue("incomplete") || !n.HasValue("name") || n.Attributes ["name"] == "::")
            {
                continue;
            }

            Namespace ns;
            switch (n.Type)
            {
            case "Class":
            case "Struct":
                ns = new Class(n);
                break;

            case "Enumeration":
                ns = new Enumeration(n);
                break;

            case "Namespace":
                ns = new Namespace(n);
                break;

            default:
                continue;
            }

            NodeToNamespace [n] = ns;
            Lib.Namespaces.Add(ns);
        }

        for (var i = 0; i < Lib.Namespaces.Count; i++)
        {
            Namespace ns = Lib.Namespaces [i];
            SetParentNamespace(ns);

            var filter = GetFilterOrDefault(ns);
            if (filter.Mode == FilterMode.Exclude)
            {
                NodeToNamespace.Remove(ns.Node);
            }

            if (filter.Mode != FilterMode.Include)
            {
                Lib.Namespaces.RemoveAt(i);
                i--;
                continue;
            }

            var klass = ns as Class;
            if (klass == null)
            {
                continue;
            }

            // Compute bases
            foreach (Node bn in klass.Node.Children.Where(o => o.Type == "Base"))
            {
                Class baseClass = NodeToNamespace [bn.NodeForAttr("type")] as Class;
                Debug.Assert(baseClass != null);
                klass.BaseClasses.Add(baseClass);
            }
        }
    }