Пример #1
0
        protected void GenerateClassStruct(GenerationInfo gen_info)
        {
            if (class_struct_name == null || !CanGenerateClassStruct)
            {
                return;
            }

            StreamWriter sw = gen_info.Writer;

            sw.WriteLine("\t\t[StructLayout (LayoutKind.Sequential)]");
            sw.WriteLine("\t\tstruct " + class_struct_name + " {");
            foreach (object member in class_members)
            {
                if (member is VirtualMethod)
                {
                    VirtualMethod vm = member as VirtualMethod;
                    if (hidden_vms.Contains(vm) || (is_interface && vm is DefaultSignalHandler))
                    {
                        sw.WriteLine("\t\t\tIntPtr {0};", vm.Name);
                    }
                    else
                    {
                        sw.WriteLine("\t\t\tpublic {0}NativeDelegate {0};", vm.Name);
                    }
                }
                else if (member is ClassField)
                {
                    ClassField field = member as ClassField;
                    field.Generate(gen_info, "\t\t\t");
                }
            }
            sw.WriteLine("\t\t}");
            sw.WriteLine();
        }
Пример #2
0
        protected ObjectBase(XmlElement ns, XmlElement elem, bool is_interface)
            : base(ns, elem)
        {
            this.is_interface = is_interface;
            XmlElement class_elem = null;
            Hashtable vms = new Hashtable ();
            Hashtable signal_vms = new Hashtable ();

            if (this.ParserVersion == 1)
                class_struct_name = this.CName + (is_interface ? "Iface" : "Class");

            foreach (XmlNode node in elem.ChildNodes) {
                if (!(node is XmlElement)) continue;
                XmlElement member = node as XmlElement;

                switch (node.Name) {
                case "virtual_method":
                    if (this.ParserVersion == 1) {
                        if (is_interface) // Generating non-signal GObject virtual methods is not supported in compatibility mode
                            AddVM (member, false, is_interface);
                    } else
                        vms.Add (member.GetAttribute ("cname"), member);
                    break;

                case "signal":
                    if (this.ParserVersion == 1 || member.GetAttribute ("field_name") == "")
                        AddVM (member, true, is_interface);
                    else
                        signal_vms.Add (member.GetAttribute ("field_name"), member);

                    if (member.GetAttribute ("hidden") != "1") {
                        string name = member.GetAttribute("name");
                        while (sigs.ContainsKey(name))
                            name += "mangled";
                        sigs.Add (name, new Signal (member, this));
                    }
                    break;

                case "class_struct":
                    class_elem = member;
                    break;
                }
            }

            if (class_elem == null) return;
            class_struct_name = class_elem.GetAttribute ("cname");

            for (int node_idx = 0; node_idx < class_elem.ChildNodes.Count; node_idx++) {
                XmlNode node = class_elem.ChildNodes [node_idx];
                if (!(node is XmlElement)) continue;
                XmlElement member = (XmlElement) node;

                switch (member.Name) {
                case "method":
                    string vm_name;
                    XmlElement vm_elem;
                    bool is_signal_vm = member.HasAttribute ("signal_vm");
                    if (is_signal_vm) {
                        vm_name = member.GetAttribute ("signal_vm");
                        vm_elem = signal_vms [vm_name] as XmlElement;
                    } else {
                        vm_name = member.GetAttribute ("vm");
                        vm_elem = vms [vm_name] as XmlElement;
                    }

                    AddVM (vm_elem, is_signal_vm, is_interface);
                    break;
                case "field":
                    if (node_idx == 0) continue; // Parent class
                    ClassField field = new ClassField (member, this);
                    class_fields.Add (field);
                    class_members.Add (field);
                    break;
                default:
                    Console.WriteLine ("Unexpected node " + member.Name + " in " + class_elem.GetAttribute ("cname"));
                    break;
                }
            }
        }
Пример #3
0
        protected ObjectBase(XmlElement ns, XmlElement elem, bool is_interface) : base(ns, elem)
        {
            this.is_interface = is_interface;
            XmlElement class_elem = null;
            Hashtable  vms        = new Hashtable();
            Hashtable  signal_vms = new Hashtable();

            if (this.ParserVersion == 1)
            {
                class_struct_name = this.CName + (is_interface ? "Iface" : "Class");
            }

            foreach (XmlNode node in elem.ChildNodes)
            {
                if (!(node is XmlElement))
                {
                    continue;
                }
                XmlElement member = node as XmlElement;

                switch (node.Name)
                {
                case "virtual_method":
                    if (this.ParserVersion == 1)
                    {
                        if (is_interface)                         // Generating non-signal GObject virtual methods is not supported in compatibility mode
                        {
                            AddVM(member, false, is_interface);
                        }
                    }
                    else
                    {
                        vms.Add(member.GetAttribute("cname"), member);
                    }
                    break;

                case "signal":
                    if (this.ParserVersion == 1 || member.GetAttribute("field_name") == "")
                    {
                        AddVM(member, true, is_interface);
                    }
                    else
                    {
                        signal_vms.Add(member.GetAttribute("field_name"), member);
                    }

                    if (!member.GetAttributeAsBoolean("hidden"))
                    {
                        string name = member.GetAttribute("name");
                        while (sigs.ContainsKey(name))
                        {
                            name += "mangled";
                        }
                        sigs.Add(name, new Signal(member, this));
                    }
                    break;

                case "class_struct":
                    class_elem = member;
                    break;
                }
            }

            if (class_elem == null)
            {
                return;
            }

            if (class_elem.GetAttributeAsBoolean("private"))
            {
                class_abi_valid = false;
                return;
            }

            class_struct_name = class_elem.GetAttribute("cname");

            int num_abi_fields = 0;

            for (int node_idx = 0; node_idx < class_elem.ChildNodes.Count; node_idx++)
            {
                XmlNode node = class_elem.ChildNodes [node_idx];
                if (!(node is XmlElement))
                {
                    continue;
                }
                XmlElement member = (XmlElement)node;

                // Make sure ABI fields are taken into account, even when hidden.
                if (node.Name == "field")
                {
                    num_abi_fields += 1;
                    if (num_abi_fields != 1)                       // Skip instance parent struct
                    {
                        abi_class_members.Add(new StructABIField(member, this, "class_abi"));
                    }
                }
                else if (node.Name == "union")
                {
                    abi_class_members.Add(new UnionABIField(member, this, "class_abi"));
                }
                else if (node.Name == "method")
                {
                    abi_class_members.Add(new MethodABIField(member, this, "class_abi"));
                }

                switch (member.Name)
                {
                case "method":
                    string     vm_name;
                    XmlElement vm_elem;
                    bool       is_signal_vm = member.HasAttribute("signal_vm");
                    if (is_signal_vm)
                    {
                        vm_name = member.GetAttribute("signal_vm");
                        vm_elem = signal_vms [vm_name] as XmlElement;
                    }
                    else
                    {
                        vm_name = member.GetAttribute("vm");
                        vm_elem = vms [vm_name] as XmlElement;
                    }

                    AddVM(vm_elem, is_signal_vm, is_interface);
                    break;

                case "field":
                    if (node_idx == 0)
                    {
                        continue;                                    // Parent class
                    }
                    ClassField field = new ClassField(member, this);
                    class_fields.Add(field);
                    class_members.Add(field);
                    break;

                default:
                    Console.WriteLine("Unexpected node " + member.Name + " in " + class_elem.GetAttribute("cname"));
                    break;
                }
            }
        }