Exemplo n.º 1
0
        public void GenerateDeclaration(StreamWriter sw, VirtualMethod complement)
        {
            VMSignature vmsig = new VMSignature(parms);

            if (IsGetter)
            {
                string name = Name.StartsWith("Get") ? Name.Substring(3) : Name;
                string type = retval.IsVoid ? parms [1].CSType : retval.CSType;
                if (complement != null && complement.parms [1].CSType == type)
                {
                    sw.WriteLine("\t\t" + type + " " + name + " { get; set; }");
                }
                else
                {
                    sw.WriteLine("\t\t" + type + " " + name + " { get; }");
                    if (complement != null)
                    {
                        sw.WriteLine("\t\t" + complement.retval.CSType + " " + complement.Name + " (" + (new VMSignature(complement.parms)) + ");");
                    }
                }
            }
            else if (IsSetter)
            {
                sw.WriteLine("\t\t" + parms[1].CSType + " " + Name.Substring(3) + " { set; }");
            }
            else
            {
                sw.WriteLine("\t\t" + retval.CSType + " " + Name + " (" + vmsig + ");");
            }
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        void GenerateImplementorIface(StreamWriter sw)
        {
            if (IsConsumeOnly)
            {
                return;
            }

            sw.WriteLine();
            sw.WriteLine("\t[GLib.GInterface (typeof (" + Name + "Adapter))]");
            string access = IsInternal ? "internal" : "public";

            sw.WriteLine("\t" + access + " interface " + Name + "Implementor : GLib.IWrapper {");
            sw.WriteLine();
            Hashtable vm_table = new Hashtable();

            foreach (VirtualMethod vm in vms)
            {
                vm_table [vm.Name] = vm;
            }
            foreach (VirtualMethod vm in vms)
            {
                if (vm_table [vm.Name] == null)
                {
                    continue;
                }
                else if (!vm.IsValid)
                {
                    vm_table.Remove(vm.Name);
                    continue;
                }
                else if (vm.IsGetter || vm.IsSetter)
                {
                    string        cmp_name = (vm.IsGetter ? "Set" : "Get") + vm.Name.Substring(3);
                    VirtualMethod cmp      = vm_table [cmp_name] as VirtualMethod;
                    if (cmp != null && (cmp.IsGetter || cmp.IsSetter))
                    {
                        if (vm.IsSetter)
                        {
                            cmp.GenerateDeclaration(sw, vm);
                        }
                        else
                        {
                            vm.GenerateDeclaration(sw, cmp);
                        }
                        vm_table.Remove(cmp.Name);
                    }
                    else
                    {
                        vm.GenerateDeclaration(sw, null);
                    }
                    vm_table.Remove(vm.Name);
                }
                else
                {
                    vm.GenerateDeclaration(sw, null);
                    vm_table.Remove(vm.Name);
                }
            }
            sw.WriteLine("\t}");
        }
Exemplo n.º 4
0
        public InterfaceGen(XmlElement ns, XmlElement elem) : base(ns, elem)
        {
            consume_only = elem.HasAttribute("consume_only");
            foreach (XmlNode node in elem.ChildNodes)
            {
                switch (node.Name)
                {
                case "virtual_method":
                    VirtualMethod vm = new VirtualMethod(node as XmlElement, this);
                    vms.Add(vm);
                    members.Add(vm);
                    break;

                case "signal":
                    object sig = sigs [(node as XmlElement).GetAttribute("name")];
                    if (sig == null)
                    {
                        sig = new Signal(node as XmlElement, this);
                    }
                    members.Add(sig);
                    break;

                default:
                    if (!IsNodeNameHandled(node.Name))
                    {
                        Console.WriteLine("Unexpected node " + node.Name + " in " + CName);
                    }
                    break;
                }
            }
        }
Exemplo n.º 5
0
        void GenerateIfaceStruct(StreamWriter sw)
        {
            sw.WriteLine("\t\tstatic " + IfaceName + " iface;");
            sw.WriteLine();
            sw.WriteLine("\t\tstruct " + IfaceName + " {");
            sw.WriteLine("\t\t\tpublic IntPtr gtype;");
            sw.WriteLine("\t\t\tpublic IntPtr itype;");
            sw.WriteLine();

            foreach (object member in members)
            {
                if (member is Signal)
                {
                    Signal sig = member as Signal;
                    sw.WriteLine("\t\t\tpublic IntPtr {0};", sig.CName.Replace("\"", "").Replace("-", "_"));
                }
                else if (member is VirtualMethod)
                {
                    VirtualMethod vm         = member as VirtualMethod;
                    bool          has_target = methods [vm.Name] != null;
                    if (!has_target)
                    {
                        Console.WriteLine("Interface " + QualifiedName + " virtual method " + vm.Name + " has no matching method to invoke.");
                    }
                    string type = has_target && vm.IsValid ? vm.Name + "Delegate" : "IntPtr";
                    sw.WriteLine("\t\t\tpublic " + type + " " + vm.CName + ";");
                }
            }

            sw.WriteLine("\t\t}");
            sw.WriteLine();
        }
Exemplo n.º 6
0
		public InterfaceGen (XmlElement ns, XmlElement elem) : base (ns, elem) 
		{
			consume_only = elem.HasAttribute ("consume_only");
			foreach (XmlNode node in elem.ChildNodes) {
				switch (node.Name) {
				case "virtual_method":
					VirtualMethod vm = new VirtualMethod (node as XmlElement, this);
					vms.Add (vm);
					members.Add (vm);
					break;
				case "signal":
					object sig = sigs [(node as XmlElement).GetAttribute ("name")];
					if (sig == null)
						sig = new Signal (node as XmlElement, this);
					members.Add (sig);
					break;
				default:
					if (!IsNodeNameHandled (node.Name))
						Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
					break;
				}
			}
		}
Exemplo n.º 7
0
		public void GenerateDeclaration (StreamWriter sw, VirtualMethod complement)
		{
			VMSignature vmsig = new VMSignature (parms);
			if (IsGetter) {
				string name = Name.StartsWith ("Get") ? Name.Substring (3) : Name;
				string type = retval.IsVoid ? parms [1].CSType : retval.CSType;
				if (complement != null && complement.parms [1].CSType == type)
					sw.WriteLine ("\t\t" + type + " " + name + " { get; set; }");
				else {
					sw.WriteLine ("\t\t" + type + " " + name + " { get; }");
					if (complement != null)
						sw.WriteLine ("\t\t" + complement.retval.CSType + " " + complement.Name + " (" + (new VMSignature (complement.parms)) + ");");
				}
			} else if (IsSetter) 
				sw.WriteLine ("\t\t" + parms[1].CSType + " " + Name.Substring (3) + " { set; }");
			else
				sw.WriteLine ("\t\t" + retval.CSType + " " + Name + " (" + vmsig + ");");
		}