예제 #1
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ("\tusing System.Runtime.InteropServices;");
            sw.WriteLine ();

            sw.WriteLine ("#region Autogenerated code");
            if (IsDeprecated)
                sw.WriteLine ("\t[Obsolete]");
            sw.Write ("\t{0} class " + Name, IsInternal ? "internal" : "public");
            sw.WriteLine (" {");
            sw.WriteLine ();

            GenProperties (gen_info, null);
            GenMethods (gen_info, null, null);

            sw.WriteLine ("#endregion");
            AppendCustom(sw, gen_info.CustomDir);

            sw.WriteLine ("\t}");
            sw.WriteLine ("}");

            sw.Close ();
            gen_info.Writer = null;
        }
예제 #2
0
        public override void Generate(GenerationInfo gen_info)
        {
            Method copy = methods["Copy"] as Method;
            Method free = methods["Free"] as Method;
            methods.Remove ("Copy");
            methods.Remove ("Free");

            gen_info.CurrentType = QualifiedName;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
            base.Generate (gen_info);
            sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)");
            sw.WriteLine ("\t\t{");

            sw.WriteLine ("\t\t\tGLib.Value val = GLib.Value.Empty;");
            sw.WriteLine ("\t\t\tval.Init (" + QualifiedName + ".GType);");
            sw.WriteLine ("\t\t\tval.Val = boxed;");
            sw.WriteLine ("\t\t\treturn val;");
            sw.WriteLine ("\t\t}");
            sw.WriteLine ();
            sw.WriteLine ("\t\tpublic static explicit operator " + QualifiedName + " (GLib.Value val)");
            sw.WriteLine ("\t\t{");

            sw.WriteLine ("\t\t\treturn (" + QualifiedName + ") val.Val;");
            sw.WriteLine ("\t\t}");

            if (copy != null && copy.IsDeprecated) {
                sw.WriteLine ();
                sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
                sw.WriteLine ("\t\tpublic " + QualifiedName + " Copy() {");
                sw.WriteLine ("\t\t\treturn this;");
                sw.WriteLine ("\t\t}");
            }

            if (free != null && free.IsDeprecated) {
                sw.WriteLine ();
                sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
                sw.WriteLine ("\t\tpublic " + QualifiedName + " Free () {");
                sw.WriteLine ("\t\t\treturn this;");
                sw.WriteLine ("\t\t}");
            }

            sw.WriteLine ("#endregion");
                        AppendCustom(sw, gen_info.CustomDir);
                        sw.WriteLine ("\t}");
                        sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
            Statistics.BoxedCount++;
        }
예제 #3
0
        public override void Generate(GenerationInfo gen_info)
        {
            Method copy = methods["Copy"] as Method;
            methods.Remove ("Copy");
            methods.Remove ("Free");

            gen_info.CurrentType = Name;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
            base.Generate (gen_info);
            sw.WriteLine ("\t\t[DllImport(\"glibsharpglue-2\")]");
            sw.WriteLine ("\t\tstatic extern IntPtr glibsharp_value_get_boxed (ref GLib.Value val);");
            sw.WriteLine ();
            sw.WriteLine ("\t\t[DllImport(\"glibsharpglue-2\")]");
            sw.WriteLine ("\t\tstatic extern void glibsharp_value_set_boxed (ref GLib.Value val, ref " + QualifiedName + " boxed);");
            sw.WriteLine ();
            sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)");
            sw.WriteLine ("\t\t{");

            sw.WriteLine ("\t\t\tGLib.Value val = GLib.Value.Empty;");
            sw.WriteLine ("\t\t\tval.Init (" + QualifiedName + ".GType);");
            sw.WriteLine ("\t\t\tglibsharp_value_set_boxed (ref val, ref boxed);");
            sw.WriteLine ("\t\t\treturn val;");
            sw.WriteLine ("\t\t}");
            sw.WriteLine ();
            sw.WriteLine ("\t\tpublic static explicit operator " + QualifiedName + " (GLib.Value val)");
            sw.WriteLine ("\t\t{");

            sw.WriteLine ("\t\t\tIntPtr boxed_ptr = glibsharp_value_get_boxed (ref val);");
            sw.WriteLine ("\t\t\treturn New (boxed_ptr);");
            sw.WriteLine ("\t\t}");

            if (copy != null && copy.IsDeprecated) {
                sw.WriteLine ();
                sw.WriteLine ("\t\t[Obsolete(\"This is a no-op\")]");
                sw.WriteLine ("\t\tpublic " + QualifiedName + " Copy() {");
                sw.WriteLine ("\t\t\treturn this;");
                sw.WriteLine ("\t\t}");
            }

            sw.WriteLine ("#endregion");
                        AppendCustom(sw, gen_info.CustomDir);
                        sw.WriteLine ("\t}");
                        sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
            Statistics.BoxedCount++;
        }
예제 #4
0
		public override void Generate (GenerationInfo gen_info)
		{
			StreamWriter sw = gen_info.OpenStream (Name);

			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();

			sw.WriteLine ("#region Autogenerated code");
					
			if (Elem.GetAttribute("type") == "flags")
				sw.WriteLine ("\t[Flags]");
			if (Elem.HasAttribute("gtype"))
				sw.WriteLine ("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]");

			string access = IsInternal ? "internal" : "public";
			sw.WriteLine ("\t" + access + " enum " + Name + enum_type + " {");
			sw.WriteLine ();
				
			foreach (string member in members)
				sw.WriteLine (member);

			sw.WriteLine ("\t}");

			if (Elem.HasAttribute ("gtype")) {
				sw.WriteLine ();
				sw.WriteLine ("\tinternal class " + Name + "GType {");
				sw.WriteLine ("\t\t[DllImport (\"" + LibraryName + "\")]");
				sw.WriteLine ("\t\tstatic extern IntPtr " + Elem.GetAttribute ("gtype") + " ();");
				sw.WriteLine ();
				sw.WriteLine ("\t\tpublic static GLib.GType GType {");
				sw.WriteLine ("\t\t\tget {");
				sw.WriteLine ("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute ("gtype") + " ());");
				sw.WriteLine ("\t\t\t}");
				sw.WriteLine ("\t\t}");
				sw.WriteLine ("\t}");
			}

			sw.WriteLine ("#endregion");
			sw.WriteLine ("}");
			sw.Close ();
			Statistics.EnumCount++;
		}
예제 #5
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = QualifiedName;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);
            base.Generate (gen_info);
            if (GetMethod ("GetType") == null && GetMethod ("GetGType") == null) {
                sw.WriteLine ("\t\tprivate static GLib.GType GType {");
                sw.WriteLine ("\t\t\tget { return GLib.GType.Pointer; }");
                sw.WriteLine ("\t\t}");
            }
            sw.WriteLine ("#endregion");
            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
            Statistics.StructCount++;
        }
예제 #6
0
		public override void Generate (GenerationInfo gen_info)
		{
			bool need_close = false;
			if (gen_info.Writer == null) {
				gen_info.Writer = gen_info.OpenStream (Name, NS);
				need_close = true;
			}

			StreamWriter sw = gen_info.Writer;
			
			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Collections;");
			sw.WriteLine ("\tusing System.Collections.Generic;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();

			sw.WriteLine ("#region Autogenerated code");
			if (IsDeprecated)
				sw.WriteLine ("\t[Obsolete]");
			string access = IsInternal ? "internal" : "public";
			sw.WriteLine ("\t" + access + " partial class {0} : {1} IEquatable<{0}> {{", Name, Parent == null ? "GLib.IWrapper," : (Parent.QualifiedName + ","));
			sw.WriteLine ();

			GenNativeStruct (gen_info);
			GenNativeAccessor (gen_info);
			GenFields (gen_info);
			sw.WriteLine ();
			GenCtors (gen_info);
			GenMethods (gen_info, null, this);
			GenEqualsAndHash (sw);

			if (!need_close)
				return;

			sw.WriteLine ("#endregion");

			sw.WriteLine ("\t}");
			sw.WriteLine ("}");
			sw.Close ();
			gen_info.Writer = null;
		}
예제 #7
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = QualifiedName;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);

            base.Generate(gen_info);
            if (GetMethod("GetType") == null && GetMethod("GetGType") == null)
            {
                sw.WriteLine("\t\tprivate static GLib.GType GType {");
                sw.WriteLine("\t\t\tget { return GLib.GType.Pointer; }");
                sw.WriteLine("\t\t}");
            }
            sw.WriteLine("#endregion");
            AppendCustom(sw, gen_info.CustomDir);
            sw.WriteLine("\t}");
            sw.WriteLine("}");
            sw.Close();
            gen_info.Writer = null;
            Statistics.StructCount++;
        }
예제 #8
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);

            base.Generate(gen_info);
            sw.WriteLine("#endregion");
            AppendCustom(sw, gen_info.CustomDir);
            sw.WriteLine("\t}");
            var method = GetMethod("GetType") ?? GetMethod("GetGType");

            if (method != null)
            {
                AttributeHelper.Gen(sw, Name, LibraryName, method.CName);
            }
            sw.WriteLine("}");
            sw.Close();
            gen_info.Writer = null;
            Statistics.StructCount++;
        }
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            sig = new Signature(parms);

            StreamWriter sw = gen_info.OpenStream(Name);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine();
            sw.WriteLine("\t{0} delegate " + retval.CSType + " " + Name + "(" + sig.ToString() + ");", IsInternal ? "internal" : "public");
            sw.WriteLine();
            sw.WriteLine("}");

            sw.Close();

            GenWrapper(gen_info);

            Statistics.CBCount++;
        }
예제 #10
0
        public override void Generate(GenerationInfo gen_info)
        {
            GenerateAdapter (gen_info);
            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ();
            sw.WriteLine ("#region Autogenerated code");
            string access = IsInternal ? "internal" : "public";
            sw.WriteLine ("\t" + access + " interface " + Name + " : GLib.IWrapper {");
            sw.WriteLine ();

            foreach (Signal sig in sigs.Values) {
                sig.GenerateDecl (sw);
                sig.GenEventHandler (gen_info);
            }

            foreach (Method method in methods.Values) {
                if (IgnoreMethod (method, this))
                    continue;
                method.GenerateDecl (sw);
            }

            foreach (Property prop in props.Values)
                prop.GenerateDecl (sw, "\t\t");

            AppendCustom (sw, gen_info.CustomDir);

            sw.WriteLine ("\t}");
            GenerateImplementorIface (sw);
            sw.WriteLine ("#endregion");
            sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
            Statistics.IFaceCount++;
        }
예제 #11
0
        private static void GenerateMapper(DirectoryInfo dir_info, GenerationInfo gen_info)
        {
            StreamWriter sw = gen_info.OpenStream ("ObjectManager");

            sw.WriteLine ("namespace GtkSharp." + Studlify (dir_info.assembly_name) + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tpublic class ObjectManager {");
            sw.WriteLine ();
            sw.WriteLine ("\t\tstatic bool initialized = false;");
            sw.WriteLine ("\t\t// Call this method from the appropriate module init function.");
            sw.WriteLine ("\t\tpublic static void Initialize ()");
            sw.WriteLine ("\t\t{");
            sw.WriteLine ("\t\t\tif (initialized)");
            sw.WriteLine ("\t\t\t\treturn;");
            sw.WriteLine ("");
            sw.WriteLine ("\t\t\tinitialized = true;");

            foreach (string key in dir_info.objects.Keys) {
                if (GetExpected(key) != ((string) dir_info.objects[key]))
                    sw.WriteLine ("\t\t\tGLib.GType.Register ({0}.GType, typeof ({0}));", dir_info.objects [key]);
            }

            sw.WriteLine ("\t\t}");
            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
        }
예제 #12
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            string asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower () + "-sharp" : gen_info.AssemblyName;
            DirectoryInfo di = GetDirectoryInfo (gen_info.Dir, asm_name);

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ("\tusing System.Collections;");
            sw.WriteLine ("\tusing System.Runtime.InteropServices;");
            sw.WriteLine ();

            SymbolTable table = SymbolTable.Table;

            sw.WriteLine ("#region Autogenerated code");
            if (IsDeprecated)
                sw.WriteLine ("\t[Obsolete]");
            foreach (string attr in custom_attrs)
                sw.WriteLine ("\t" + attr);
            sw.Write ("\t{0} {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));
            if (cs_parent != "") {
                di.objects.Add (CName, QualifiedName);
                sw.Write (" : " + cs_parent);
            }
            foreach (string iface in interfaces) {
                if (Parent != null && Parent.Implements (iface))
                    continue;
                sw.Write (", " + table.GetCSType (iface));
            }
            foreach (string iface in managed_interfaces) {
                if (Parent != null && Parent.Implements (iface))
                    continue;
                sw.Write (", " + iface);
            }
            sw.WriteLine (" {");
            sw.WriteLine ();

            GenCtors (gen_info);
            GenProperties (gen_info, null);
            GenFields (gen_info);
            GenChildProperties (gen_info);

            bool has_sigs = (sigs != null && sigs.Count > 0);
            if (!has_sigs) {
                foreach (string iface in interfaces) {
                    InterfaceGen igen = table.GetClassGen (iface) as InterfaceGen;
                    if (igen != null && igen.Signals != null) {
                        has_sigs = true;
                        break;
                    }
                }
            }

            if (has_sigs && Elem.HasAttribute("parent")) {
                GenSignals (gen_info, null);
            }

            GenClassMembers (gen_info, cs_parent);
            GenMethods (gen_info, null, null);

            if (interfaces.Count != 0) {
                Hashtable all_methods = new Hashtable ();
                foreach (Method m in Methods.Values)
                    all_methods[m.Name] = m;
                Hashtable collisions = new Hashtable ();
                foreach (string iface in interfaces) {
                    ClassBase igen = table.GetClassGen (iface);
                    foreach (Method m in igen.Methods.Values) {
                        Method collision = all_methods[m.Name] as Method;
                        if (collision != null && collision.Signature.Types == m.Signature.Types)
                            collisions[m.Name] = true;
                        else
                            all_methods[m.Name] = m;
                    }
                }

                foreach (string iface in interfaces) {
                    if (Parent != null && Parent.Implements (iface))
                        continue;
                    InterfaceGen igen = table.GetClassGen (iface) as InterfaceGen;
                    igen.GenMethods (gen_info, collisions, this);
                    igen.GenProperties (gen_info, this);
                    igen.GenSignals (gen_info, this);
                    igen.GenVirtualMethods (gen_info, this);
                }
            }

            foreach (XmlElement str in strings) {
                sw.Write ("\t\tpublic static string " + str.GetAttribute ("name"));
                sw.WriteLine (" {\n\t\t\t get { return \"" + str.GetAttribute ("value") + "\"; }\n\t\t}");
            }

            if (cs_parent != String.Empty && GetExpected (CName) != QualifiedName) {
                sw.WriteLine ();
                sw.WriteLine ("\t\tstatic " + Name + " ()");
                sw.WriteLine ("\t\t{");
                sw.WriteLine ("\t\t\tGtkSharp." + Studlify (asm_name) + ".ObjectManager.Initialize ();");
                sw.WriteLine ("\t\t}");
            }

            sw.WriteLine ("#endregion");
            AppendCustom (sw, gen_info.CustomDir);

            sw.WriteLine ("\t}");
            sw.WriteLine ("}");

            sw.Close ();
            gen_info.Writer = null;
            Statistics.ObjectCount++;
        }
예제 #13
0
        void GenerateAdapter(GenerationInfo gen_info)
        {
            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name + "Adapter");

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();
            sw.WriteLine("#region Autogenerated code");
            sw.WriteLine("\tpublic class " + Name + "Adapter : GLib.GInterfaceAdapter, " + QualifiedName + " {");
            sw.WriteLine();

            if (!IsConsumeOnly)
            {
                GenerateIfaceStruct(sw);
                GenerateStaticCtor(sw);
                GenerateCallbacks(sw);
                GenerateInitialize(sw);
            }
            GenerateCtors(sw);
            GenerateGType(sw);
            GenerateHandleProp(sw);
            GenerateGetObject(sw);
            if (!IsConsumeOnly)
            {
                GenerateImplementorProp(sw);
            }

            GenProperties(gen_info, null);

            foreach (Signal sig in sigs.Values)
            {
                sig.GenEvent(sw, null, "GLib.Object.GetObject (Handle)");
            }

            Method temp = methods ["GetType"] as Method;

            if (temp != null)
            {
                methods.Remove("GetType");
            }
            GenMethods(gen_info, new Hashtable(), this);
            if (temp != null)
            {
                methods ["GetType"] = temp;
            }

            sw.WriteLine("#endregion");

            string custom = Path.Combine(gen_info.CustomDir, Name + "Adapter.custom");

            if (File.Exists(custom))
            {
                sw.WriteLine("#region Customized extensions");
                sw.WriteLine("#line 1 \"" + Name + "Adapter.custom\"");
                using (StreamReader sr = new StreamReader(new FileStream(custom, FileMode.Open, FileAccess.Read)))
                    sw.WriteLine(sr.ReadToEnd());

                sw.WriteLine("#endregion");
            }

            sw.WriteLine("\t}");
            sw.WriteLine("}");
            sw.Close();
            gen_info.Writer = null;
        }
예제 #14
0
		public override void Generate (GenerationInfo gen_info)
		{
			gen_info.CurrentType = QualifiedName;

			sig = new Signature (parms);

			StreamWriter sw = gen_info.OpenStream (Name, NS);

			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ();
			sw.WriteLine ("\t{0} delegate " + retval.CSType + " " + Name + "(" + sig.ToString() + ");", IsInternal ? "internal" : "public");
			sw.WriteLine ();
			sw.WriteLine ("}");

			sw.Close ();
			
			GenWrapper (gen_info);

			Statistics.CBCount++;
		}
예제 #15
0
파일: Signal.cs 프로젝트: rubenv/tripod
		public void GenEventHandler (GenerationInfo gen_info)
		{
			if (IsEventHandler)
				return;

			string ns = container_type.NS;

			StreamWriter sw = gen_info.OpenStream (EventHandlerName);
			
			sw.WriteLine ("namespace " + ns + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");

			sw.WriteLine ();
			sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
			sw.WriteLine ();
			sw.WriteLine ("\tpublic class " + EventArgsName + " : GLib.SignalArgs {");
			for (int i = 1; i < parms.Count; i++) {
				sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
				if (parms[i].PassAs != "out") {
					sw.WriteLine ("\t\t\tget {");
					sw.WriteLine ("\t\t\t\treturn (" + parms[i].CSType + ") Args[" + (i - 1) + "];");
					sw.WriteLine ("\t\t\t}");
				}
				if (parms[i].PassAs != "") {
					sw.WriteLine ("\t\t\tset {");
					sw.WriteLine ("\t\t\t\tArgs[" + (i - 1) + "] = (" + parms[i].CSType + ")value;");
					sw.WriteLine ("\t\t\t}");
				}
				sw.WriteLine ("\t\t}");
				sw.WriteLine ();
			}
			sw.WriteLine ("\t}");
			sw.WriteLine ("}");
			sw.Close ();
		}
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            sw.WriteLine("#region Autogenerated code");

            SymbolTable table = SymbolTable.Table;

            Method ref_, unref, dispose;

            GetSpecialMethods(out ref_, out unref, out dispose);

            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            GenerateAttribute(sw);
            sw.Write("\t{0} class " + Name, IsInternal ? "internal" : "public");
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));

            if (cs_parent != "")
            {
                sw.Write(" : " + cs_parent);
            }
            else
            {
                sw.Write(" : GLib.Opaque");
            }
            sw.WriteLine(" {");
            sw.WriteLine();

            GenFields(gen_info);
            GenMethods(gen_info, null, null);
            GenCtors(gen_info);

            if (ref_ != null)
            {
                ref_.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Ref (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (!Owned) {");
                sw.WriteLine("\t\t\t\t" + ref_.CName + " (raw);");
                sw.WriteLine("\t\t\t\tOwned = true;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (ref_.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    if (ref_.ReturnType == "void")
                    {
                        sw.WriteLine("\t\tpublic void Ref () {}");
                    }
                    else
                    {
                        sw.WriteLine("\t\tpublic " + Name + " Ref () { return this; }");
                    }
                    sw.WriteLine();
                }
            }

            if (unref != null)
            {
                unref.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Unref (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (Owned) {");
                sw.WriteLine("\t\t\t\t" + unref.CName + " (raw);");
                sw.WriteLine("\t\t\t\tOwned = false;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (unref.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    sw.WriteLine("\t\tpublic void Unref () {}");
                    sw.WriteLine();
                }
            }

            if (dispose != null)
            {
                dispose.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Free (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\t" + dispose.CName + " (raw);");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (dispose.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]");
                    sw.WriteLine("\t\tpublic void " + dispose.Name + " () {}");
                    sw.WriteLine();
                }
            }

#if false
            Method copy = Methods ["Copy"] as Method;
            if (copy != null && copy.Parameters.Count == 0)
            {
                sw.WriteLine("\t\tprotected override GLib.Opaque Copy (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));");
                sw.WriteLine("\t\t\tresult.Owned = true;");
                sw.WriteLine("\t\t\treturn result;");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
            }
#endif
            sw.WriteLine("#endregion");

            AppendCustom(sw, gen_info.CustomDir);

            sw.WriteLine("\t}");
            var parentGType = GetParentWithGType(this);
            if (parentGType == this)
            {
                var method = parentGType.GetMethod("GetType") ?? parentGType.GetMethod("GetGType");
                AttributeHelper.Gen(sw, Name, LibraryName, method.CName);
            }
            sw.WriteLine("}");

            sw.Close();
            gen_info.Writer = null;
            Statistics.OpaqueCount++;
        }
예제 #17
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = QualifiedName;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name, NS);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Collections.Generic;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            sw.WriteLine("#region Autogenerated code");

            SymbolTable table = SymbolTable.Table;

            Method ref_, unref, dispose, set_gvalue;

            GetSpecialMethods(out ref_, out unref, out dispose, out set_gvalue);

            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            sw.Write("\t{0} partial {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : String.Empty);
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));

            if (cs_parent != "")
            {
                sw.Write(" : " + cs_parent);
            }
            else
            {
                sw.Write(" : GLib.Opaque");
            }

            foreach (string iface in managed_interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + iface);
            }

            sw.WriteLine(" {");
            sw.WriteLine();

            GenConstants(gen_info);
            GenFields(gen_info);
            GenMethods(gen_info, null, null);
            GenCtors(gen_info);

            if (ref_ != null)
            {
                ref_.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Ref (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (!Owned) {");
                sw.WriteLine("\t\t\t\t" + ref_.CName + " (raw);");
                sw.WriteLine("\t\t\t\tOwned = true;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (ref_.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    if (ref_.ReturnType == "void")
                    {
                        sw.WriteLine("\t\tpublic void Ref () {}");
                    }
                    else
                    {
                        sw.WriteLine("\t\tpublic " + Name + " Ref () { return this; }");
                    }
                    sw.WriteLine();
                }
            }

            bool finalizer_needed = false;

            if (unref != null)
            {
                unref.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Unref (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (Owned) {");
                sw.WriteLine("\t\t\t\t" + unref.CName + " (raw);");
                sw.WriteLine("\t\t\t\tOwned = false;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (unref.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    sw.WriteLine("\t\tpublic void Unref () {}");
                    sw.WriteLine();
                }
                finalizer_needed = true;
            }

            if (dispose != null)
            {
                dispose.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Free (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\t" + dispose.CName + " (raw);");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (dispose.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]");
                    sw.WriteLine("\t\tpublic void " + dispose.Name + " () {}");
                    sw.WriteLine();
                }
                finalizer_needed = true;
            }

            if (finalizer_needed)
            {
                sw.WriteLine("\t\tclass FinalizerInfo {");
                sw.WriteLine("\t\t\tIntPtr handle;");
                sw.WriteLine();
                sw.WriteLine("\t\t\tpublic FinalizerInfo (IntPtr handle)");
                sw.WriteLine("\t\t\t{");
                sw.WriteLine("\t\t\t\tthis.handle = handle;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine();
                sw.WriteLine("\t\t\tpublic bool Handler ()");
                sw.WriteLine("\t\t\t{");
                if (dispose != null)
                {
                    sw.WriteLine("\t\t\t\t{0} (handle);", dispose.CName);
                }
                else if (unref != null)
                {
                    sw.WriteLine("\t\t\t\t{0} (handle);", unref.CName);
                }
                sw.WriteLine("\t\t\t\treturn false;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
                sw.WriteLine("\t\t~{0} ()", Name);
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (!Owned)");
                sw.WriteLine("\t\t\t\treturn;");
                sw.WriteLine("\t\t\tFinalizerInfo info = new FinalizerInfo (Handle);");
                sw.WriteLine("\t\t\tGLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
            }

#if false
            Method copy = Methods ["Copy"] as Method;
            if (copy != null && copy.Parameters.Count == 0)
            {
                sw.WriteLine("\t\tprotected override GLib.Opaque Copy (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));");
                sw.WriteLine("\t\t\tresult.Owned = true;");
                sw.WriteLine("\t\t\treturn result;");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
            }
#endif
            if (set_gvalue != null)
            {
                sw.WriteLine("\t\tdelegate IntPtr d_{0}(ref GLib.Value val, IntPtr obj);", set_gvalue.CName);
                sw.WriteLine("\t\tstatic d_{0} {0} = FuncLoader.LoadFunction<d_{0}>(FuncLoader.GetProcAddress(GLibrary.Load(\"{1}\"), \"{0}\"));", set_gvalue.CName, LibraryName);
                sw.WriteLine();
                sw.WriteLine("\t\tpublic void SetGValue (ref GLib.Value val)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\t{0} (ref val, Handle);", set_gvalue.CName);
                sw.WriteLine("\t\t}");
                sw.WriteLine();
            }

            GenerateStructureABI(gen_info);
            sw.WriteLine("#endregion");

            sw.WriteLine("\t}");
            sw.WriteLine("}");

            sw.Close();
            gen_info.Writer = null;
            Statistics.OpaqueCount++;
        }
예제 #18
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = QualifiedName;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name, NS);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Collections.Generic;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            sw.WriteLine("#region Autogenerated code");

            SymbolTable table = SymbolTable.Table;

            Method ref_, unref, dispose, set_gvalue;

            GetSpecialMethods(out ref_, out unref, out dispose, out set_gvalue);

            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            sw.Write("\t{0} partial {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : String.Empty);
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));

            if (cs_parent != "")
            {
                sw.Write(" : " + cs_parent);
            }
            else
            {
                sw.Write(" : GLib.Opaque");
            }

            foreach (string iface in managed_interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + iface);
            }

            sw.WriteLine(" {");
            sw.WriteLine();

            GenConstants(gen_info);
            GenFields(gen_info);
            GenMethods(gen_info, null, null);
            GenCtors(gen_info);

            if (ref_ != null)
            {
                ref_.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Ref (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (!Owned) {");
                sw.WriteLine("\t\t\t\t" + ref_.CName + " (raw);");
                sw.WriteLine("\t\t\t\tOwned = true;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (ref_.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    if (ref_.ReturnType == "void")
                    {
                        sw.WriteLine("\t\tpublic void Ref () {}");
                    }
                    else
                    {
                        sw.WriteLine("\t\tpublic " + Name + " Ref () { return this; }");
                    }
                    sw.WriteLine();
                }
            }

            // GtkWidgetPath has both gtk_widget_path_unref and gtk_widget_path_free
            // If this happens add only one and prefer unref over free
            bool disposeUnmanagedFuncAdded = false;

            if (unref != null)
            {
                unref.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Unref (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (Owned) {");
                sw.WriteLine("\t\t\t\t" + unref.CName + " (raw);");
                sw.WriteLine("\t\t\t\tOwned = false;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
                sw.WriteLine("\t\tprotected override Action<IntPtr> DisposeUnmanagedFunc {");
                sw.WriteLine("\t\t\tget {");
                sw.WriteLine("\t\t\t\treturn " + unref.CName + ";");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
                disposeUnmanagedFuncAdded = true;
                if (unref.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    sw.WriteLine("\t\tpublic void Unref () {}");
                    sw.WriteLine();
                }
            }

            if (dispose != null)
            {
                dispose.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Free (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\t" + dispose.CName + " (raw);");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
                if (!disposeUnmanagedFuncAdded)
                {
                    sw.WriteLine("\t\tprotected override Action<IntPtr> DisposeUnmanagedFunc {");
                    sw.WriteLine("\t\t\tget {");
                    sw.WriteLine("\t\t\t\treturn " + dispose.CName + ";");
                    sw.WriteLine("\t\t\t}");
                    sw.WriteLine("\t\t}");
                    sw.WriteLine();
                }

                if (dispose.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]");
                    sw.WriteLine("\t\tpublic void " + dispose.Name + " () {}");
                    sw.WriteLine();
                }
            }


#if false
            Method copy = Methods ["Copy"] as Method;
            if (copy != null && copy.Parameters.Count == 0)
            {
                sw.WriteLine("\t\tprotected override GLib.Opaque Copy (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));");
                sw.WriteLine("\t\t\tresult.Owned = true;");
                sw.WriteLine("\t\t\treturn result;");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
            }
#endif
            if (set_gvalue != null)
            {
                sw.WriteLine("\t\t[DllImport(\"{0}\", CallingConvention = CallingConvention.Cdecl)]", LibraryName);
                sw.WriteLine("\t\tstatic extern void {0}(ref GLib.Value val, IntPtr obj);", set_gvalue.CName);
                sw.WriteLine();
                sw.WriteLine("\t\tpublic void SetGValue (ref GLib.Value val)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\t{0} (ref val, Handle);", set_gvalue.CName);
                sw.WriteLine("\t\t}");
                sw.WriteLine();
            }

            GenerateStructureABI(gen_info);
            sw.WriteLine("#endregion");

            sw.WriteLine("\t}");
            sw.WriteLine("}");

            sw.Close();
            gen_info.Writer = null;
            Statistics.OpaqueCount++;
        }
예제 #19
0
		void GenerateAdapter (GenerationInfo gen_info)
		{
			if (IsConsumeOnly)
				return;

			StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name + "Adapter");

			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();
			sw.WriteLine ("#region Autogenerated code");
			sw.WriteLine ("\tpublic class " + Name + "Adapter : GLib.GInterfaceAdapter, " + QualifiedName + " {");
			sw.WriteLine ();

			GenerateIfaceStruct (sw);
			GenerateStaticCtor (sw);
			GenerateCallbacks (sw);
			GenerateInitialize (sw);
			GenerateCtors (sw);
			GenerateGType (sw);
			GenerateHandleProp (sw);
			GenerateGetObject (sw);
			GenerateImplementorProp (sw);

			GenProperties (gen_info, null);

			foreach (Signal sig in sigs.Values)
				sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)");

			Method temp = methods ["GetType"] as Method;
			if (temp != null)
				methods.Remove ("GetType");
			GenMethods (gen_info, new Hashtable (), this);
			if (temp != null)
				methods ["GetType"] = temp;

			sw.WriteLine ("#endregion");

			AppendCustom (sw, gen_info.CustomDir, Name + "Adapter");

			sw.WriteLine ("\t}");
			sw.WriteLine ("}");
			sw.Close ();
			gen_info.Writer = null;
		}
예제 #20
0
		public override void Generate (GenerationInfo gen_info)
		{
			gen_info.CurrentType = Name;

			string asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower () + "-sharp" : gen_info.AssemblyName;
			DirectoryInfo di = GetDirectoryInfo (gen_info.Dir, asm_name);

			StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);

			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Collections;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();

			SymbolTable table = SymbolTable.Table;

			sw.WriteLine ("#region Autogenerated code");
			if (IsDeprecated)
				sw.WriteLine ("\t[Obsolete]");
			foreach (string attr in custom_attrs)
				sw.WriteLine ("\t" + attr);
			sw.Write ("\t{0} {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
			string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));
			if (cs_parent != "") {
				di.objects.Add (CName, QualifiedName);
				sw.Write (" : " + cs_parent);
			}
			foreach (string iface in managed_interfaces) {
				if (Parent != null && Parent.Implements (iface))
					continue;
				sw.Write (", " + iface);
			}
			sw.WriteLine (" {");
			sw.WriteLine ();

			GenCtors (gen_info);
			GenFields (gen_info);
			
			GenClassMembers (gen_info, cs_parent);
			GenMethods (gen_info, null, null);
			
			foreach (XmlElement str in strings) {
				sw.Write ("\t\tpublic static string " + str.GetAttribute ("name"));
				sw.WriteLine (" {\n\t\t\t get { return \"" + str.GetAttribute ("value") + "\"; }\n\t\t}");
			}

			if (cs_parent != String.Empty && GetExpected (CName) != QualifiedName) {
				sw.WriteLine ();
				sw.WriteLine ("\t\tstatic " + Name + " ()");
				sw.WriteLine ("\t\t{");
				sw.WriteLine ("\t\t\tGtkSharp." + Studlify (asm_name) + ".ObjectManager.Initialize ();");
				sw.WriteLine ("\t\t}");
			}

			sw.WriteLine ("#endregion");
			AppendCustom (sw, gen_info.CustomDir);

			sw.WriteLine ("\t}");
			sw.WriteLine ("}");

			sw.Close ();
			gen_info.Writer = null;
			Statistics.ObjectCount++;
		}
예제 #21
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            string        asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower() + "-sharp" : gen_info.AssemblyName;
            DirectoryInfo di       = GetDirectoryInfo(gen_info.Dir, asm_name);

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            SymbolTable table = SymbolTable.Table;

            sw.WriteLine("#region Autogenerated code");
            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            foreach (string attr in custom_attrs)
            {
                sw.WriteLine("\t" + attr);
            }
            sw.Write("\t{0} {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));

            if (cs_parent != "")
            {
                di.objects.Add(CName, QualifiedName);
                sw.Write(" : " + cs_parent);
            }
            foreach (string iface in managed_interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + iface);
            }
            sw.WriteLine(" {");
            sw.WriteLine();

            GenCtors(gen_info);
            GenFields(gen_info);

            GenClassMembers(gen_info, cs_parent);
            GenMethods(gen_info, null, null);

            foreach (XmlElement str in strings)
            {
                sw.Write("\t\tpublic static string " + str.GetAttribute("name"));
                sw.WriteLine(" {\n\t\t\t get { return \"" + str.GetAttribute("value") + "\"; }\n\t\t}");
            }

            if (cs_parent != String.Empty && GetExpected(CName) != QualifiedName)
            {
                sw.WriteLine();
                sw.WriteLine("\t\tstatic " + Name + " ()");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tGtkSharp." + Studlify(asm_name) + ".ObjectManager.Initialize ();");
                sw.WriteLine("\t\t}");
            }

            sw.WriteLine("#endregion");
            AppendCustom(sw, gen_info.CustomDir);

            sw.WriteLine("\t}");
            sw.WriteLine("}");

            sw.Close();
            gen_info.Writer = null;
            Statistics.ObjectCount++;
        }
예제 #22
0
		public override void Generate (GenerationInfo gen_info)
		{
			bool need_close = false;
			if (gen_info.Writer == null) {
				gen_info.Writer = gen_info.OpenStream (Name, NS);
				need_close = true;
			}

			StreamWriter sw = gen_info.Writer;
			
			sw.WriteLine ("namespace " + NS + " {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Collections;");
			sw.WriteLine ("\tusing System.Collections.Generic;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();
			
			sw.WriteLine ("#region Autogenerated code");
			if (IsDeprecated)
				sw.WriteLine ("\t[Obsolete]");
			if (Union)
				sw.WriteLine ("\t[StructLayout(LayoutKind.Explicit)]");
			else
				sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]");
			string access = IsInternal ? "internal" : "public";
			sw.WriteLine ("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
			sw.WriteLine ();

			need_read_native = false;
			GenFields (gen_info);
			sw.WriteLine ();
			GenCtors (gen_info);
			GenMethods (gen_info, null, this);
			if (need_read_native)
				GenReadNative (sw);
			GenEqualsAndHash (sw);

			if (!need_close)
				return;

			sw.WriteLine ("#endregion");

			sw.WriteLine ("\t}");
			sw.WriteLine ("}");
			sw.Close ();
			gen_info.Writer = null;
		}
        public string GenWrapper(GenerationInfo gen_info)
        {
            string wrapper  = Name + "Native";
            string qualname = MarshalType;

            if (!Validate())
            {
                return(String.Empty);
            }

            body = new MethodBody(parms);

            StreamWriter save_sw = gen_info.Writer;
            StreamWriter sw      = gen_info.Writer = gen_info.OpenStream(qualname);

            sw.WriteLine("namespace " + NS + "Sharp {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();
            sw.WriteLine("#region Autogenerated code");
            sw.WriteLine("\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
            sw.WriteLine("\tinternal delegate " + retval.MarshalType + " " + wrapper + "(" + parms.CallbackImportSignature + ");");
            sw.WriteLine();
            GenInvoker(gen_info, sw);
            sw.WriteLine("\tinternal class " + Name + "Wrapper {");
            sw.WriteLine();
            ManagedCallString call = new ManagedCallString(parms, false);

            sw.WriteLine("\t\tpublic " + retval.MarshalType + " NativeCallback (" + parms.CallbackImportSignature + ")");
            sw.WriteLine("\t\t{");
            string unconditional = call.Unconditional("\t\t\t");

            if (unconditional.Length > 0)
            {
                sw.WriteLine(unconditional);
            }
            sw.WriteLine("\t\t\ttry {");
            string call_setup = call.Setup("\t\t\t\t");

            if (call_setup.Length > 0)
            {
                sw.WriteLine(call_setup);
            }
            if (retval.CSType == "void")
            {
                sw.WriteLine("\t\t\t\tmanaged ({0});", call);
            }
            else
            {
                sw.WriteLine("\t\t\t\t{0} __ret = managed ({1});", retval.CSType, call);
            }
            string finish = call.Finish("\t\t\t\t");

            if (finish.Length > 0)
            {
                sw.WriteLine(finish);
            }
            sw.WriteLine("\t\t\t\tif (release_on_call)\n\t\t\t\t\tgch.Free ();");
            if (retval.CSType != "void")
            {
                sw.WriteLine("\t\t\t\treturn {0};", retval.ToNative("__ret"));
            }

            /* If the function expects one or more "out" parameters(error parameters are excluded) or has a return value different from void and bool, exceptions
             *  thrown in the managed function have to be considered fatal meaning that an exception is to be thrown and the function call cannot not return
             */
            bool fatal = (retval.MarshalType != "void" && retval.MarshalType != "bool") || call.HasOutParam;

            sw.WriteLine("\t\t\t} catch (Exception e) {");
            sw.WriteLine("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
            if (fatal)
            {
                sw.WriteLine("\t\t\t\t// NOTREACHED: Above call does not return.");
                sw.WriteLine("\t\t\t\tthrow e;");
            }
            else if (retval.MarshalType == "bool")
            {
                sw.WriteLine("\t\t\t\treturn false;");
            }
            sw.WriteLine("\t\t\t}");
            sw.WriteLine("\t\t}");
            sw.WriteLine();
            sw.WriteLine("\t\tbool release_on_call = false;");
            sw.WriteLine("\t\tGCHandle gch;");
            sw.WriteLine();
            sw.WriteLine("\t\tpublic void PersistUntilCalled ()");
            sw.WriteLine("\t\t{");
            sw.WriteLine("\t\t\trelease_on_call = true;");
            sw.WriteLine("\t\t\tgch = GCHandle.Alloc (this);");
            sw.WriteLine("\t\t}");
            sw.WriteLine();
            sw.WriteLine("\t\tinternal " + wrapper + " NativeDelegate;");
            sw.WriteLine("\t\t" + NS + "." + Name + " managed;");
            sw.WriteLine();
            sw.WriteLine("\t\tpublic " + Name + "Wrapper (" + NS + "." + Name + " managed)");
            sw.WriteLine("\t\t{");
            sw.WriteLine("\t\t\tthis.managed = managed;");
            sw.WriteLine("\t\t\tif (managed != null)");
            sw.WriteLine("\t\t\t\tNativeDelegate = new " + wrapper + " (NativeCallback);");
            sw.WriteLine("\t\t}");
            sw.WriteLine();
            sw.WriteLine("\t\tpublic static " + NS + "." + Name + " GetManagedDelegate (" + wrapper + " native)");
            sw.WriteLine("\t\t{");
            sw.WriteLine("\t\t\tif (native == null)");
            sw.WriteLine("\t\t\t\treturn null;");
            sw.WriteLine("\t\t\t" + Name + "Wrapper wrapper = (" + Name + "Wrapper) native.Target;");
            sw.WriteLine("\t\t\tif (wrapper == null)");
            sw.WriteLine("\t\t\t\treturn null;");
            sw.WriteLine("\t\t\treturn wrapper.managed;");
            sw.WriteLine("\t\t}");
            sw.WriteLine("\t}");
            sw.WriteLine("#endregion");
            sw.WriteLine("}");
            sw.Close();
            gen_info.Writer = save_sw;
            return(NS + "Sharp." + Name + "Wrapper");
        }
예제 #24
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            sw.WriteLine("#region Autogenerated code");

            SymbolTable table = SymbolTable.Table;

            Method ref_, unref, dispose;

            GetSpecialMethods(out ref_, out unref, out dispose);

            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            sw.Write("\t{0} class " + Name, IsInternal ? "internal" : "public");
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));

            if (cs_parent != "")
            {
                sw.Write(" : " + cs_parent);
            }
            else
            {
                sw.Write(" : GLib.Opaque");
            }
            sw.WriteLine(" {");
            sw.WriteLine();

            GenFields(gen_info);
            GenMethods(gen_info, null, null);
            GenCtors(gen_info);

            if (ref_ != null)
            {
                ref_.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Ref (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (!Owned) {");
                sw.WriteLine("\t\t\t\t" + ref_.CName + " (raw);");
                sw.WriteLine("\t\t\t\tOwned = true;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (ref_.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    if (ref_.ReturnType == "void")
                    {
                        sw.WriteLine("\t\tpublic void Ref () {}");
                    }
                    else
                    {
                        sw.WriteLine("\t\tpublic " + Name + " Ref () { return this; }");
                    }
                    sw.WriteLine();
                }
            }

            bool finalizer_needed = false;

            if (unref != null)
            {
                unref.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Unref (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (Owned) {");
                sw.WriteLine("\t\t\t\t" + unref.CName + " (raw);");
                sw.WriteLine("\t\t\t\tOwned = false;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (unref.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    sw.WriteLine("\t\tpublic void Unref () {}");
                    sw.WriteLine();
                }
                finalizer_needed = true;
            }

            if (dispose != null)
            {
                dispose.GenerateImport(sw);
                sw.WriteLine("\t\tprotected override void Free (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\t" + dispose.CName + " (raw);");
                sw.WriteLine("\t\t}");
                sw.WriteLine();

                if (dispose.IsDeprecated)
                {
                    sw.WriteLine("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]");
                    sw.WriteLine("\t\tpublic void " + dispose.Name + " () {}");
                    sw.WriteLine();
                }
                finalizer_needed = true;
            }

            if (finalizer_needed)
            {
                sw.WriteLine("\t\tclass FinalizerInfo {");
                sw.WriteLine("\t\t\tIntPtr handle;");
                sw.WriteLine();
                sw.WriteLine("\t\t\tpublic FinalizerInfo (IntPtr handle)");
                sw.WriteLine("\t\t\t{");
                sw.WriteLine("\t\t\t\tthis.handle = handle;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine();
                sw.WriteLine("\t\t\tpublic bool Handler ()");
                sw.WriteLine("\t\t\t{");
                if (dispose != null)
                {
                    sw.WriteLine("\t\t\t\t{0} (handle);", dispose.CName);
                }
                else if (unref != null)
                {
                    sw.WriteLine("\t\t\t\t{0} (handle);", unref.CName);
                }
                sw.WriteLine("\t\t\t\treturn false;");
                sw.WriteLine("\t\t\t}");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
                sw.WriteLine("\t\t~{0} ()", Name);
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tif (!Owned)");
                sw.WriteLine("\t\t\t\treturn;");
                sw.WriteLine("\t\t\tFinalizerInfo info = new FinalizerInfo (Handle);");
                sw.WriteLine("\t\t\tGLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
            }

#if false
            Method copy = Methods ["Copy"] as Method;
            if (copy != null && copy.Parameters.Count == 0)
            {
                sw.WriteLine("\t\tprotected override GLib.Opaque Copy (IntPtr raw)");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));");
                sw.WriteLine("\t\t\tresult.Owned = true;");
                sw.WriteLine("\t\t\treturn result;");
                sw.WriteLine("\t\t}");
                sw.WriteLine();
            }
#endif
            sw.WriteLine("#endregion");

            AppendCustom(sw, gen_info.CustomDir);

            sw.WriteLine("\t}");
            sw.WriteLine("}");

            sw.Close();
            gen_info.Writer = null;
            Statistics.OpaqueCount++;
        }
예제 #25
0
        public override void Generate(GenerationInfo gen_info)
        {
            bool need_close = false;

            if (gen_info.Writer == null)
            {
                gen_info.Writer = gen_info.OpenStream(Name, NS);
                need_close      = true;
            }

            StreamWriter sw = gen_info.Writer;

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Collections.Generic;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            sw.WriteLine("#region Autogenerated code");
            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            if (Union)
            {
                sw.WriteLine("\t[StructLayout(LayoutKind.Explicit)]");
            }
            else
            {
                sw.WriteLine("\t[StructLayout(LayoutKind.Sequential)]");
            }
            string access = IsInternal ? "internal" : "public";

            sw.WriteLine("\t" + access + " partial struct {0} : IEquatable<{0}> {{", Name);
            sw.WriteLine();

            need_read_native = false;
            GenFields(gen_info);
            sw.WriteLine();
            GenCtors(gen_info);
            GenMethods(gen_info, null, this);
            if (need_read_native)
            {
                GenReadNative(sw);
            }
            GenEqualsAndHash(sw);

            if (!need_close)
            {
                return;
            }

            sw.WriteLine("#endregion");

            sw.WriteLine("\t}");
            sw.WriteLine("}");
            sw.Close();
            gen_info.Writer = null;
        }
예제 #26
0
		public string GenWrapper (GenerationInfo gen_info)
		{
			string wrapper = Name + "Native";
			string qualname = MarshalType;

			if (!Validate ())
				return String.Empty;

			body = new MethodBody (parms);

			StreamWriter save_sw = gen_info.Writer;
			StreamWriter sw = gen_info.Writer = gen_info.OpenStream (qualname, NS);

			sw.WriteLine ("namespace " + NS + "Sharp {");
			sw.WriteLine ();
			sw.WriteLine ("\tusing System;");
			sw.WriteLine ("\tusing System.Runtime.InteropServices;");
			sw.WriteLine ();
			sw.WriteLine ("#region Autogenerated code");
			sw.WriteLine ("\t[UnmanagedFunctionPointer (CallingConvention.Cdecl)]");
			sw.WriteLine ("\tinternal delegate " + retval.MarshalType + " " + wrapper + "(" + parms.ImportSignature + ");");
			sw.WriteLine ();
			GenInvoker (gen_info, sw);
			sw.WriteLine ("\tinternal class " + Name + "Wrapper {");
			sw.WriteLine ();
			ManagedCallString call = new ManagedCallString (parms);
			sw.WriteLine ("\t\tpublic " + retval.MarshalType + " NativeCallback (" + parms.ImportSignature + ")");
			sw.WriteLine ("\t\t{");
			string unconditional = call.Unconditional ("\t\t\t");
			if (unconditional.Length > 0)
				sw.WriteLine (unconditional);
			sw.WriteLine ("\t\t\ttry {");
			string call_setup = call.Setup ("\t\t\t\t");
			if (call_setup.Length > 0)
				sw.WriteLine (call_setup);
			if (retval.CSType == "void")
				sw.WriteLine ("\t\t\t\tmanaged ({0});", call);
			else
				sw.WriteLine ("\t\t\t\t{0} __ret = managed ({1});", retval.CSType, call);
			string finish = call.Finish ("\t\t\t\t");
			if (finish.Length > 0)
				sw.WriteLine (finish);
			sw.WriteLine ("\t\t\t\tif (release_on_call)\n\t\t\t\t\tgch.Free ();");
			Parameter cnt = retval.CountParameter;
			if (cnt != null)
				sw.WriteLine ("\t\t\t\t{0} = {1}{2};", cnt.Name, cnt.CSType == "int" ? String.Empty : "(" + cnt.MarshalType + ")(" + cnt.CSType + ")", "__ret.Length");
			if (retval.CSType != "void")
				sw.WriteLine ("\t\t\t\treturn {0};", retval.ToNative ("__ret"));

			/* If the function expects one or more "out" parameters(error parameters are excluded) or has a return value different from void and bool, exceptions
			*  thrown in the managed function have to be considered fatal meaning that an exception is to be thrown and the function call cannot not return
			*/
			bool fatal = (retval.MarshalType != "void" && retval.MarshalType != "bool") || call.HasOutParam;
			sw.WriteLine ("\t\t\t} catch (Exception e) {");
			sw.WriteLine ("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" : "false") + ");");
			if (fatal) {
				sw.WriteLine ("\t\t\t\t// NOTREACHED: Above call does not return.");
				sw.WriteLine ("\t\t\t\tthrow e;");
			} else if (retval.MarshalType == "bool") {
				sw.WriteLine ("\t\t\t\treturn false;");
			}
			sw.WriteLine ("\t\t\t}");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ();
			sw.WriteLine ("\t\tbool release_on_call = false;");
			sw.WriteLine ("\t\tGCHandle gch;");
			sw.WriteLine ();
			sw.WriteLine ("\t\tpublic void PersistUntilCalled ()");
			sw.WriteLine ("\t\t{");
			sw.WriteLine ("\t\t\trelease_on_call = true;");
			sw.WriteLine ("\t\t\tgch = GCHandle.Alloc (this);");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ();
			sw.WriteLine ("\t\tinternal " + wrapper + " NativeDelegate;");
			sw.WriteLine ("\t\t" + NS + "." + Name + " managed;");
			sw.WriteLine ();
			sw.WriteLine ("\t\tpublic " + Name + "Wrapper (" + NS + "." + Name + " managed)");
			sw.WriteLine ("\t\t{");
			sw.WriteLine ("\t\t\tthis.managed = managed;");
			sw.WriteLine ("\t\t\tif (managed != null)");
			sw.WriteLine ("\t\t\t\tNativeDelegate = new " + wrapper + " (NativeCallback);");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ();
			sw.WriteLine ("\t\tpublic static " + NS + "." + Name + " GetManagedDelegate (" + wrapper + " native)");
			sw.WriteLine ("\t\t{");
			sw.WriteLine ("\t\t\tif (native == null)");
			sw.WriteLine ("\t\t\t\treturn null;");
			sw.WriteLine ("\t\t\t" + Name + "Wrapper wrapper = (" + Name + "Wrapper) native.Target;");
			sw.WriteLine ("\t\t\tif (wrapper == null)");
			sw.WriteLine ("\t\t\t\treturn null;");
			sw.WriteLine ("\t\t\treturn wrapper.managed;");
			sw.WriteLine ("\t\t}");
			sw.WriteLine ("\t}");
			sw.WriteLine ("#endregion");
			sw.WriteLine ("}");
			sw.Close ();
			gen_info.Writer = save_sw;
			return NS + "Sharp." + Name + "Wrapper";
		}
예제 #27
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = Name;

            string        asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower() + "-sharp" : gen_info.AssemblyName;
            DirectoryInfo di       = GetDirectoryInfo(gen_info.Dir, asm_name);

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            SymbolTable table = SymbolTable.Table;

            sw.WriteLine("#region Autogenerated code");
            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            foreach (string attr in custom_attrs)
            {
                sw.WriteLine("\t" + attr);
            }
            sw.Write("\t{0} {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));

            if (cs_parent != "")
            {
                di.objects.Add(CName, QualifiedName);
                sw.Write(" : " + cs_parent);
            }
            foreach (string iface in interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + table.GetCSType(iface));
            }
            foreach (string iface in managed_interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + iface);
            }
            sw.WriteLine(" {");
            sw.WriteLine();

            GenCtors(gen_info);
            GenProperties(gen_info, null);
            GenFields(gen_info);
            GenChildProperties(gen_info);

            bool has_sigs = (sigs != null && sigs.Count > 0);

            if (!has_sigs)
            {
                foreach (string iface in interfaces)
                {
                    ClassBase igen = table.GetClassGen(iface);
                    if (igen != null && igen.Signals != null)
                    {
                        has_sigs = true;
                        break;
                    }
                }
            }

            if (has_sigs && Elem.HasAttribute("parent"))
            {
                GenSignals(gen_info, null);
            }

            if (vm_nodes.Count > 0)
            {
                if (gen_info.GlueEnabled)
                {
                    GenVirtualMethods(gen_info);
                }
                else
                {
                    Statistics.VMIgnored       = true;
                    Statistics.ThrottledCount += vm_nodes.Count;
                }
            }

            GenMethods(gen_info, null, null);

            if (interfaces.Count != 0)
            {
                Hashtable all_methods = new Hashtable();
                foreach (Method m in Methods.Values)
                {
                    all_methods[m.Name] = m;
                }
                Hashtable collisions = new Hashtable();
                foreach (string iface in interfaces)
                {
                    ClassBase igen = table.GetClassGen(iface);
                    foreach (Method m in igen.Methods.Values)
                    {
                        Method collision = all_methods[m.Name] as Method;
                        if (collision != null && collision.Signature.Types == m.Signature.Types)
                        {
                            collisions[m.Name] = true;
                        }
                        else
                        {
                            all_methods[m.Name] = m;
                        }
                    }
                }

                foreach (string iface in interfaces)
                {
                    if (Parent != null && Parent.Implements(iface))
                    {
                        continue;
                    }
                    ClassBase igen = table.GetClassGen(iface);
                    igen.GenMethods(gen_info, collisions, this);
                    igen.GenProperties(gen_info, this);
                    igen.GenSignals(gen_info, this);
                }
            }

            foreach (XmlElement str in strings)
            {
                sw.Write("\t\tpublic static string " + str.GetAttribute("name"));
                sw.WriteLine(" {\n\t\t\t get { return \"" + str.GetAttribute("value") + "\"; }\n\t\t}");
            }

            if (cs_parent != String.Empty && GetExpected(CName) != QualifiedName)
            {
                sw.WriteLine();
                sw.WriteLine("\t\tstatic " + Name + " ()");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tGtkSharp." + Studlify(asm_name) + ".ObjectManager.Initialize ();");
                sw.WriteLine("\t\t}");
            }

            sw.WriteLine("#endregion");
            AppendCustom(sw, gen_info.CustomDir);

            sw.WriteLine("\t}");
            sw.WriteLine("}");

            sw.Close();
            gen_info.Writer = null;
            Statistics.ObjectCount++;
        }
예제 #28
0
        void GenerateAdapter(GenerationInfo gen_info)
        {
            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (AdapterName);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ("\tusing System.Runtime.InteropServices;");
            sw.WriteLine ();
            sw.WriteLine ("#region Autogenerated code");
            sw.WriteLine ("\tpublic partial class " + AdapterName + " : GLib.GInterfaceAdapter, " + QualifiedName + " {");
            sw.WriteLine ();

            if (!IsConsumeOnly) {
                GenerateClassStruct (gen_info);
                GenerateStaticCtor (sw);
                GenerateCallbacks (sw);
                GenerateInitialize (sw);
            }
            GenerateCtors (sw);
            GenerateGType (sw);
            GenerateHandleProp (sw);
            GenerateGetObject (sw);
            if (!IsConsumeOnly)
                GenerateImplementorProp (sw);

            GenProperties (gen_info, null);

            foreach (Signal sig in sigs.Values)
                sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)");

            Method temp = GetMethod ("GetType");
            if (temp != null)
                Methods.Remove ("GetType");
            GenMethods (gen_info, null, this);
            if (temp != null)
                Methods ["GetType"] = temp;

            sw.WriteLine ("#endregion");

            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
        }
예제 #29
0
파일: Signal.cs 프로젝트: shana/gtk-sharp
        public void GenEventHandler(GenerationInfo gen_info)
        {
            if (IsEventHandler)
                return;

            string ns = container_type.NS;

            StreamWriter sw = gen_info.OpenStream (EventHandlerName);

            sw.WriteLine ("namespace " + ns + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");

            sw.WriteLine ();
            sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
            sw.WriteLine ();
            sw.WriteLine ("\tpublic class " + EventArgsName + " : GLib.SignalArgs {");
            for (int i = 0; i < parms.Count; i++) {
                sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
                if (parms[i].PassAs != "out") {
                    sw.WriteLine ("\t\t\tget {");
                    if (SymbolTable.Table.IsInterface (parms [i].CType))
                        sw.WriteLine ("\t\t\t\treturn {0}Adapter.GetObject (Args [{1}] as GLib.Object);", parms [i].CSType, i);
                    else
                        sw.WriteLine ("\t\t\t\treturn ({0}) Args [{1}];", parms [i].CSType, i);
                    sw.WriteLine ("\t\t\t}");
                }
                if (parms[i].PassAs != "") {
                    sw.WriteLine ("\t\t\tset {");
                    if (SymbolTable.Table.IsInterface (parms [i].CType))
                        sw.WriteLine ("\t\t\t\tArgs [{0}] = value is {1}Adapter ? (value as {1}Adapter).Implementor : value;", i, parms [i].CSType);
                    else
                        sw.WriteLine ("\t\t\t\tArgs[" + i + "] = (" + parms[i].CSType + ")value;");
                    sw.WriteLine ("\t\t\t}");
                }
                sw.WriteLine ("\t\t}");
                sw.WriteLine ();
            }
            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
        }
예제 #30
0
        void GenerateAdapter(GenerationInfo gen_info)
        {
            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name + "Adapter");

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ("\tusing System.Runtime.InteropServices;");
            sw.WriteLine ();
            sw.WriteLine ("#region Autogenerated code");
            sw.WriteLine ("\tpublic class " + Name + "Adapter : GLib.GInterfaceAdapter, " + QualifiedName + " {");
            sw.WriteLine ();

            if (!IsConsumeOnly) {
                GenerateIfaceStruct (sw);
                GenerateStaticCtor (sw);
                GenerateCallbacks (sw);
                GenerateInitialize (sw);
            }
            GenerateCtors (sw);
            GenerateGType (sw);
            GenerateHandleProp (sw);
            GenerateGetObject (sw);
            if (!IsConsumeOnly)
                GenerateImplementorProp (sw);

            GenProperties (gen_info, null);

            foreach (Signal sig in sigs.Values)
                sig.GenEvent (sw, null, "GLib.Object.GetObject (Handle)");

            Method temp = methods ["GetType"] as Method;
            if (temp != null)
                methods.Remove ("GetType");
            GenMethods (gen_info, new Hashtable (), this);
            if (temp != null)
                methods ["GetType"] = temp;

            sw.WriteLine ("#endregion");

            string custom = Path.Combine (gen_info.CustomDir, Name + "Adapter.custom");
            if (File.Exists (custom)) {
                sw.WriteLine ("#region Customized extensions");
                sw.WriteLine ("#line 1 \"" + Name + "Adapter.custom\"");
                using (StreamReader sr = new StreamReader(new FileStream (custom, FileMode.Open, FileAccess.Read)))
                    sw.WriteLine (sr.ReadToEnd ());

                sw.WriteLine ("#endregion");
            }

            sw.WriteLine ("\t}");
            sw.WriteLine ("}");
            sw.Close ();
            gen_info.Writer = null;
        }
예제 #31
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = QualifiedName;

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name);

            sw.WriteLine ("namespace " + NS + " {");
            sw.WriteLine ();
            sw.WriteLine ("\tusing System;");
            sw.WriteLine ("\tusing System.Collections;");
            sw.WriteLine ("\tusing System.Runtime.InteropServices;");
            sw.WriteLine ();

            sw.WriteLine ("#region Autogenerated code");

            SymbolTable table = SymbolTable.Table;

            Method ref_, unref, dispose;
            GetSpecialMethods (out ref_, out unref, out dispose);

            if (IsDeprecated)
                sw.WriteLine ("\t[Obsolete]");
            sw.Write ("\t{0} partial {1}class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : String.Empty);
            string cs_parent = table.GetCSType(Elem.GetAttribute("parent"));
            if (cs_parent != "")
                sw.Write (" : " + cs_parent);
            else
                sw.Write (" : GLib.Opaque");

            foreach (string iface in managed_interfaces) {
                if (Parent != null && Parent.Implements (iface))
                    continue;
                sw.Write (", " + iface);
            }

            sw.WriteLine (" {");
            sw.WriteLine ();

            GenFields (gen_info);
            GenMethods (gen_info, null, null);
            GenCtors (gen_info);

            if (ref_ != null) {
                ref_.GenerateImport (sw);
                sw.WriteLine ("\t\tprotected override void Ref (IntPtr raw)");
                sw.WriteLine ("\t\t{");
                sw.WriteLine ("\t\t\tif (!Owned) {");
                sw.WriteLine ("\t\t\t\t" + ref_.CName + " (raw);");
                sw.WriteLine ("\t\t\t\tOwned = true;");
                sw.WriteLine ("\t\t\t}");
                sw.WriteLine ("\t\t}");
                sw.WriteLine ();

                if (ref_.IsDeprecated) {
                    sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    if (ref_.ReturnType == "void")
                        sw.WriteLine ("\t\tpublic void Ref () {}");
                    else
                        sw.WriteLine ("\t\tpublic " + Name + " Ref () { return this; }");
                    sw.WriteLine ();
                }
            }

            bool finalizer_needed = false;

            if (unref != null) {
                unref.GenerateImport (sw);
                sw.WriteLine ("\t\tprotected override void Unref (IntPtr raw)");
                sw.WriteLine ("\t\t{");
                sw.WriteLine ("\t\t\tif (Owned) {");
                sw.WriteLine ("\t\t\t\t" + unref.CName + " (raw);");
                sw.WriteLine ("\t\t\t\tOwned = false;");
                sw.WriteLine ("\t\t\t}");
                sw.WriteLine ("\t\t}");
                sw.WriteLine ();

                if (unref.IsDeprecated) {
                    sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now refcounted automatically\")]");
                    sw.WriteLine ("\t\tpublic void Unref () {}");
                    sw.WriteLine ();
                }
                finalizer_needed = true;
            }

            if (dispose != null) {
                dispose.GenerateImport (sw);
                sw.WriteLine ("\t\tprotected override void Free (IntPtr raw)");
                sw.WriteLine ("\t\t{");
                sw.WriteLine ("\t\t\t" + dispose.CName + " (raw);");
                sw.WriteLine ("\t\t}");
                sw.WriteLine ();

                if (dispose.IsDeprecated) {
                    sw.WriteLine ("\t\t[Obsolete(\"" + QualifiedName + " is now freed automatically\")]");
                    sw.WriteLine ("\t\tpublic void " + dispose.Name + " () {}");
                    sw.WriteLine ();
                }
                finalizer_needed = true;
            }

            if (finalizer_needed) {
                sw.WriteLine ("\t\tclass FinalizerInfo {");
                sw.WriteLine ("\t\t\tIntPtr handle;");
                sw.WriteLine ();
                sw.WriteLine ("\t\t\tpublic FinalizerInfo (IntPtr handle)");
                sw.WriteLine ("\t\t\t{");
                sw.WriteLine ("\t\t\t\tthis.handle = handle;");
                sw.WriteLine ("\t\t\t}");
                sw.WriteLine ();
                sw.WriteLine ("\t\t\tpublic bool Handler ()");
                sw.WriteLine ("\t\t\t{");
                if (dispose != null)
                    sw.WriteLine ("\t\t\t\t{0} (handle);", dispose.CName);
                else if (unref != null)
                    sw.WriteLine ("\t\t\t\t{0} (handle);", unref.CName);
                sw.WriteLine ("\t\t\t\treturn false;");
                sw.WriteLine ("\t\t\t}");
                sw.WriteLine ("\t\t}");
                sw.WriteLine ();
                sw.WriteLine ("\t\t~{0} ()", Name);
                sw.WriteLine ("\t\t{");
                sw.WriteLine ("\t\t\tif (!Owned)");
                sw.WriteLine ("\t\t\t\treturn;");
                sw.WriteLine ("\t\t\tFinalizerInfo info = new FinalizerInfo (Handle);");
                sw.WriteLine ("\t\t\tGLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));");
                sw.WriteLine ("\t\t}");
                sw.WriteLine ();
            }

            #if false
            Method copy = Methods ["Copy"] as Method;
            if (copy != null && copy.Parameters.Count == 0) {
                sw.WriteLine ("\t\tprotected override GLib.Opaque Copy (IntPtr raw)");
                sw.WriteLine ("\t\t{");
                sw.WriteLine ("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));");
                sw.WriteLine ("\t\t\tresult.Owned = true;");
                sw.WriteLine ("\t\t\treturn result;");
                sw.WriteLine ("\t\t}");
                sw.WriteLine ();
            }
            #endif
            sw.WriteLine ("#endregion");

            sw.WriteLine ("\t}");
            sw.WriteLine ("}");

            sw.Close ();
            gen_info.Writer = null;
            Statistics.OpaqueCount++;
        }
예제 #32
0
        public override void Generate(GenerationInfo gen_info)
        {
            gen_info.CurrentType = QualifiedName;

            string        asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower() + "-sharp" : gen_info.AssemblyName;
            DirectoryInfo di       = GetDirectoryInfo(gen_info.Dir, asm_name);

            StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name, NS);

            sw.WriteLine("namespace " + NS + " {");
            sw.WriteLine();
            sw.WriteLine("\tusing System;");
            sw.WriteLine("\tusing System.Collections;");
            sw.WriteLine("\tusing System.Collections.Generic;");
            sw.WriteLine("\tusing System.Runtime.InteropServices;");
            sw.WriteLine();

            SymbolTable table = SymbolTable.Table;

            sw.WriteLine("#region Autogenerated code");
            if (IsDeprecated)
            {
                sw.WriteLine("\t[Obsolete]");
            }
            foreach (string attr in customAttrs)
            {
                sw.WriteLine("\t" + attr);
            }
            sw.Write("\t{0} {1}partial class " + Name, IsInternal ? "internal" : "public", IsAbstract ? "abstract " : "");
            string csParent = table.GetCSType(Elem.GetAttribute("parent"));

            if (!string.IsNullOrEmpty(csParent))
            {
                di.objects.Add(CName, QualifiedName);
                sw.Write(" : " + csParent);
            }
            foreach (string iface in interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + table.GetCSType(iface));
            }
            foreach (string iface in managed_interfaces)
            {
                if (Parent != null && Parent.Implements(iface))
                {
                    continue;
                }
                sw.Write(", " + iface);
            }
            sw.WriteLine(" {");
            sw.WriteLine();

            GenCtors(gen_info);
            GenProperties(gen_info, null);
            GenFields(gen_info);
            GenChildProperties(gen_info);

            bool has_sigs = (sigs != null && sigs.Count > 0);

            if (!has_sigs)
            {
                foreach (string iface in interfaces)
                {
                    if (table.GetClassGen(iface) is InterfaceGen iGen && iGen.Signals != null)
                    {
                        has_sigs = true;
                        break;
                    }
                }
            }

            if (has_sigs && Elem.HasAttribute("parent"))
            {
                GenSignals(gen_info, null);
            }

            GenConstants(gen_info);
            GenClassMembers(gen_info, csParent);
            GenMethods(gen_info, null, null);

            if (interfaces.Count != 0)
            {
                var all_methods = new Dictionary <string, Method> ();
                foreach (Method m in Methods.Values)
                {
                    all_methods[m.Name] = m;
                }
                var collisions = new Dictionary <string, bool> ();
                foreach (string iface in interfaces)
                {
                    ClassBase igen = table.GetClassGen(iface);
                    foreach (Method m in igen.Methods.Values)
                    {
                        if (m.Name.StartsWith("Get") || m.Name.StartsWith("Set"))
                        {
                            if (GetProperty(m.Name.Substring(3)) != null)
                            {
                                collisions[m.Name] = true;
                                continue;
                            }
                        }

                        all_methods.TryGetValue(m.Name, out Method collision);
                        if (collision != null && collision.Signature.Types == m.Signature.Types)
                        {
                            collisions[m.Name] = true;
                        }
                        else
                        {
                            all_methods[m.Name] = m;
                        }
                    }
                }

                foreach (string iface in interfaces)
                {
                    if (Parent != null && Parent.Implements(iface))
                    {
                        continue;
                    }
                    InterfaceGen igen = table.GetClassGen(iface) as InterfaceGen;
                    igen.GenMethods(gen_info, collisions, this);
                    igen.GenProperties(gen_info, this);
                    igen.GenSignals(gen_info, this);
                    igen.GenVirtualMethods(gen_info, this);
                }
            }

            foreach (XmlElement str in strings)
            {
                sw.Write("\t\tpublic static string " + str.GetAttribute("name"));
                sw.WriteLine(" {\n\t\t\t get { return \"" + str.GetAttribute("value") + "\"; }\n\t\t}");
            }

            if (!string.IsNullOrEmpty(csParent) && GetExpected(CName) != QualifiedName)
            {
                sw.WriteLine();
                sw.WriteLine("\t\tstatic " + Name + " ()");
                sw.WriteLine("\t\t{");
                sw.WriteLine("\t\t\tGtkSharp." + Studlify(asm_name) + ".ObjectManager.Initialize ();");
                sw.WriteLine("\t\t}");
            }

            GenerateStructureABI(gen_info);
            sw.WriteLine("#endregion");

            sw.WriteLine("\t}");
            sw.WriteLine("}");

            sw.Close();
            gen_info.Writer = null;
            Statistics.ObjectCount++;
        }