From 98615699314a116d767c8bc1b967e8e68550e9c9 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 18 Mar 2004 20:56:32 +0000 Subject: [PATCH] 2004-03-18 Mike Kestner * configure.in : expand atk/glue/Makefile * atk/Makefile.am : generate glue and build glue dir * atk/makefile.win32 : ditto * atk/glue/Makefile.am : build new glue * atk/glue/makefile.win32 : build new glue * atk/glue/vmglueheaders.h : new includes for vm glue * atk/glue/win32dll.c : win dll building code * generator/CodeGenerator.cs : add --gluelib-name and --glue-filename argument parsing. * generator/GenerationInfo.cs : add GluelibName, GlueFilename, GlueEnabled, GlueWriter, and CloseGlueWriter. * generator/ObjectGen.cs : Add VirtualMethod glue generation * generator/Statistics.cs : Add warning message for virtual method throttling. svn path=/trunk/gtk-sharp/; revision=24292 --- ChangeLog | 17 ++++++++++++ atk/Makefile.am | 9 ++++--- atk/glue/.cvsignore | 8 ++++++ atk/glue/Makefile.am | 21 +++++++++++++++ atk/glue/makefile.win32 | 22 +++++++++++++++ atk/glue/vmglueheaders.h | 4 +++ atk/glue/win32dll.c | 16 +++++++++++ atk/makefile.win32 | 5 +++- configure.in | 1 + generator/CodeGenerator.cs | 17 ++++++++++-- generator/GenerationInfo.cs | 53 +++++++++++++++++++++++++++++++++++-- generator/ObjectGen.cs | 51 +++++++++++++++++++++++++++++++++-- generator/Statistics.cs | 19 ++++++++++++- 13 files changed, 232 insertions(+), 11 deletions(-) create mode 100644 atk/glue/.cvsignore create mode 100644 atk/glue/Makefile.am create mode 100755 atk/glue/makefile.win32 create mode 100644 atk/glue/vmglueheaders.h create mode 100755 atk/glue/win32dll.c diff --git a/ChangeLog b/ChangeLog index c4991cca5..d697b880c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2004-03-18 Mike Kestner + + * configure.in : expand atk/glue/Makefile + * atk/Makefile.am : generate glue and build glue dir + * atk/makefile.win32 : ditto + * atk/glue/Makefile.am : build new glue + * atk/glue/makefile.win32 : build new glue + * atk/glue/vmglueheaders.h : new includes for vm glue + * atk/glue/win32dll.c : win dll building code + * generator/CodeGenerator.cs : add --gluelib-name and + --glue-filename argument parsing. + * generator/GenerationInfo.cs : add GluelibName, GlueFilename, + GlueEnabled, GlueWriter, and CloseGlueWriter. + * generator/ObjectGen.cs : Add VirtualMethod glue generation + * generator/Statistics.cs : Add warning message for virtual + method throttling. + 2004-03-18 Mike Kestner * parser/gapi2xml.pl : fix passbyvalue bug in vm parsing. diff --git a/atk/Makefile.am b/atk/Makefile.am index f63c42d8f..1a32fd3c9 100644 --- a/atk/Makefile.am +++ b/atk/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = . glue + API = atk-api.xml RAW_API = atk-api.raw METADATA = Atk.metadata @@ -9,7 +11,7 @@ assemblydir = $(libdir) gapidir = $(datadir)/gapi assembly_DATA = $(ASSEMBLY) gapi_DATA = $(API) -CLEANFILES = $(ASSEMBLY) generated-stamp generated/*.cs $(API) +CLEANFILES = $(ASSEMBLY) generated-stamp generated/*.cs $(API) glue/generated.c sources = @@ -32,8 +34,9 @@ $(API): $(srcdir)/$(RAW_API) $(srcdir)/$(METADATA) $(RUNTIME) ../parser/gapi-fixup.exe --api=$(API) --metadata=$(srcdir)/$(METADATA) generated-stamp: $(API) ../generator/gapi_codegen.exe $(build_customs) - $(RUNTIME) ../generator/gapi_codegen.exe --generate $(API) \ - --outdir=generated --customdir=$(srcdir) --assembly-name=$(ASSEMBLY_NAME) \ + $(RUNTIME) ../generator/gapi_codegen.exe --generate $(API) \ + --outdir=generated --customdir=$(srcdir) --assembly-name=$(ASSEMBLY_NAME) \ + --gluelib-name=atksharpglue --glue-filename=glue/generated.c \ && touch generated-stamp $(ASSEMBLY): $(build_sources) generated-stamp diff --git a/atk/glue/.cvsignore b/atk/glue/.cvsignore new file mode 100644 index 000000000..4e348378a --- /dev/null +++ b/atk/glue/.cvsignore @@ -0,0 +1,8 @@ +generated.c +Makefile +Makefile.in +*.la +*.lo +*.o +.deps +.libs diff --git a/atk/glue/Makefile.am b/atk/glue/Makefile.am new file mode 100644 index 000000000..2fc40609b --- /dev/null +++ b/atk/glue/Makefile.am @@ -0,0 +1,21 @@ +lib_LTLIBRARIES = libatksharpglue.la + +libatksharpglue_la_LDFLAGS = -module -avoid-version + +libatksharpglue_la_SOURCES = \ + generated.c \ + vmglueheaders.h + +# Adding a new glue file? +# Please remember to update makefile.win32 + +libatksharpglue_la_LIBADD = $(BASE_DEPENDENCIES_LIBS) + +INCLUDES = $(BASE_DEPENDENCIES_CFLAGS) -I$(top_srcdir) + +libatksharpglue.dll: $(libatksharpglue_la_OBJECTS) libatksharpglue.rc libatksharpglue.def + ./build-dll libatksharpglue $(VERSION) + +CLEANFILES = lib*.a lib*.dll + +EXTRA_DIST = makefile.win32 win32dll.c diff --git a/atk/glue/makefile.win32 b/atk/glue/makefile.win32 new file mode 100755 index 000000000..7f4ca4da2 --- /dev/null +++ b/atk/glue/makefile.win32 @@ -0,0 +1,22 @@ +GTK_CFLAGS=`pkg-config --cflags gtk+-win32-2.0 libglade-2.0` +GTK_LIBS=`pkg-config --libs gtk+-win32-2.0 libglade-2.0` +CC=gcc -mno-cygwin -mms-bitfields +DLLWRAP=dllwrap -mno-cygwin -mms-bitfields --target i386-mingw32 --export-all-symbols + +GLUE_OBJS = \ + generated.o \ + win32dll.o + +all: atksharpglue.dll + + +%.o: %.c + $(CC) -c $(CFLAGS) $(GTK_CFLAGS) -o $@ $^ + + +atksharpglue.dll: $(GLUE_OBJS) + $(DLLWRAP) --output-lib=libatksharpglue.a --dllname=atksharpglue.dll --driver-name=gcc --output-def=atksharpglue.def $(GLUE_OBJS) $(GTK_LIBS) + + +clean: + rm -f atksharpglue.dll *.o libatksharpglue.a diff --git a/atk/glue/vmglueheaders.h b/atk/glue/vmglueheaders.h new file mode 100644 index 000000000..f41428a5f --- /dev/null +++ b/atk/glue/vmglueheaders.h @@ -0,0 +1,4 @@ +/* Headers for virtual method glue compilation */ + +#include + diff --git a/atk/glue/win32dll.c b/atk/glue/win32dll.c new file mode 100755 index 000000000..a57c07683 --- /dev/null +++ b/atk/glue/win32dll.c @@ -0,0 +1,16 @@ +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#include + +BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved) +{ + return TRUE; +} + +/* +BOOL APIENTRY DllMainCRTStartup (HINSTANCE hInst, DWORD reason, LPVOID reserved) +{ + return TRUE; +} +*/ diff --git a/atk/makefile.win32 b/atk/makefile.win32 index 7e2945ad7..66c224223 100644 --- a/atk/makefile.win32 +++ b/atk/makefile.win32 @@ -6,9 +6,10 @@ all: windows windows: generated-stamp $(CSC) /unsafe /nowarn:0660,0661 /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /out:$(ASSEMBLY) /recurse:*.cs + cd glue && make -f makefile.win32 generated-stamp: ../generator/codegen.exe atk-api.xml - ../generator/codegen --generate $(APIS) --outdir=generated --customdir=. --assembly-name=atk-sharp && touch generated-stamp + ../generator/codegen --generate $(APIS) --outdir=generated --customdir=. --assembly-name=atk-sharp --gluelib-name=atksharpglue --glue-filename=glue/generated.c && touch generated-stamp atk-api.xml: atk-api.raw Atk.metadata cp atk-api.raw atk-api.xml @@ -19,5 +20,7 @@ clean: rm -f generated-stamp rm -f $(ASSEMBLY) rm -rf generated + rm -f glue/generated.c rm -f atk-api.xml + cd glue && make -f makefile.win32 diff --git a/configure.in b/configure.in index 341e67d7f..22eafe626 100644 --- a/configure.in +++ b/configure.in @@ -166,6 +166,7 @@ glib/Makefile glib/glue/Makefile pango/Makefile atk/Makefile +atk/glue/Makefile art/Makefile gdk/Makefile gdk/glue/Makefile diff --git a/generator/CodeGenerator.cs b/generator/CodeGenerator.cs index cc5cca62c..0744db594 100644 --- a/generator/CodeGenerator.cs +++ b/generator/CodeGenerator.cs @@ -24,6 +24,8 @@ namespace GtkSharp.Generation { string dir = ""; string custom_dir = ""; string assembly_name = ""; + string glue_filename = ""; + string gluelib_name = ""; SymbolTable table = SymbolTable.Table; ArrayList gens = new ArrayList (); @@ -48,6 +50,14 @@ namespace GtkSharp.Generation { include = generate = false; assembly_name = arg.Substring (16); continue; + } else if (arg.StartsWith ("--glue-filename=")) { + include = generate = false; + glue_filename = arg.Substring (16); + continue; + } else if (arg.StartsWith ("--gluelib-name=")) { + include = generate = false; + gluelib_name = arg.Substring (15); + continue; } Parser p = new Parser (); @@ -58,8 +68,8 @@ namespace GtkSharp.Generation { } GenerationInfo gen_info = null; - if (dir != "" || assembly_name != "") - gen_info = new GenerationInfo (dir, custom_dir, assembly_name); + if (dir != "" || assembly_name != "" || glue_filename != "" || gluelib_name != "") + gen_info = new GenerationInfo (dir, custom_dir, assembly_name, glue_filename, gluelib_name); foreach (IGeneratable gen in gens) { if (gen_info == null) @@ -70,6 +80,9 @@ namespace GtkSharp.Generation { ObjectGen.GenerateMappers (); + if (gen_info != null) + gen_info.CloseGlueWriter (); + Statistics.Report(); return 0; } diff --git a/generator/GenerationInfo.cs b/generator/GenerationInfo.cs index 101cf4798..b16a75e0f 100644 --- a/generator/GenerationInfo.cs +++ b/generator/GenerationInfo.cs @@ -16,6 +16,8 @@ namespace GtkSharp.Generation { string dir; string custom_dir; string assembly_name; + string glue_filename; + string gluelib_name; StreamWriter sw; public GenerationInfo (XmlElement ns) @@ -25,15 +27,19 @@ namespace GtkSharp.Generation { dir = ".." + sep + ns_name.ToLower () + sep + "generated"; custom_dir = ".." + sep + ns_name.ToLower (); assembly_name = ns_name.ToLower () + "-sharp"; + gluelib_name = ""; + glue_filename = ""; } - public GenerationInfo (string dir, string assembly_name) : this (dir, dir, assembly_name) {} + public GenerationInfo (string dir, string assembly_name) : this (dir, dir, assembly_name, "", "") {} - public GenerationInfo (string dir, string custom_dir, string assembly_name) + public GenerationInfo (string dir, string custom_dir, string assembly_name, string glue_filename, string gluelib_name) { this.dir = dir; this.custom_dir = custom_dir; this.assembly_name = assembly_name; + this.glue_filename = glue_filename; + this.gluelib_name = gluelib_name; } public string AssemblyName { @@ -54,6 +60,43 @@ namespace GtkSharp.Generation { } } + public string GluelibName { + get { + return gluelib_name; + } + } + + public bool GlueEnabled { + get { + return gluelib_name != String.Empty && glue_filename != String.Empty; + } + } + + public string GlueFilename { + get { + return glue_filename; + } + } + + StreamWriter glue_sw = null; + public StreamWriter GlueWriter { + get { + if (!GlueEnabled) + return null; + + if (glue_sw == null) { + FileStream stream = new FileStream (glue_filename, FileMode.Create, FileAccess.Write); + glue_sw = new StreamWriter (stream); + + glue_sw.WriteLine ("// This file was generated by the Gtk# code generator."); + glue_sw.WriteLine ("// Any changes made will be lost if regenerated."); + glue_sw.WriteLine (); + } + + return glue_sw; + } + } + public StreamWriter Writer { get { return sw; @@ -63,6 +106,12 @@ namespace GtkSharp.Generation { } } + public void CloseGlueWriter () + { + if (glue_sw != null) + glue_sw.Close (); + } + public StreamWriter OpenStream (string name) { char sep = Path.DirectorySeparatorChar; diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 19a644c91..758500c4d 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -1,8 +1,9 @@ // GtkSharp.Generation.ObjectGen.cs - The Object Generatable. // -// Author: Mike Kestner +// Author: Mike Kestner // // (c) 2001-2003 Mike Kestner and Ximian Inc. +// (c) 2004 Novell, Inc. namespace GtkSharp.Generation { @@ -15,6 +16,7 @@ namespace GtkSharp.Generation { public class ObjectGen : ClassBase, IGeneratable { private ArrayList strings = new ArrayList(); + private ArrayList vm_nodes = new ArrayList(); private static Hashtable dirs = new Hashtable (); public ObjectGen (XmlElement ns, XmlElement elem) : base (ns, elem) @@ -27,10 +29,13 @@ namespace GtkSharp.Generation { switch (node.Name) { case "field": case "callback": - case "virtual_method": Statistics.IgnoreCount++; break; + case "virtual_method": + vm_nodes.Add (node); + break; + case "static-string": strings.Add (node); break; @@ -128,6 +133,15 @@ namespace GtkSharp.Generation { 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 != null) { @@ -185,6 +199,39 @@ namespace GtkSharp.Generation { base.GenCtors (gen_info); } + private void GenVMGlue (GenerationInfo gen_info, XmlElement elem) + { + StreamWriter sw = gen_info.GlueWriter; + + string vm_name = elem.GetAttribute ("cname"); + string method = gen_info.GluelibName + "_" + NS + Name + "_override_" + vm_name; + sw.WriteLine (); + sw.WriteLine ("void " + method + " (GType type, gpointer cb);"); + sw.WriteLine (); + sw.WriteLine ("void"); + sw.WriteLine (method + " (GType type, gpointer cb)"); + sw.WriteLine ("{"); + sw.WriteLine ("\t{0} *klass = ({0} *) g_type_class_peek (type);", NS + Name + "Class"); + sw.WriteLine ("\tklass->" + vm_name + " = cb;"); + sw.WriteLine ("}"); + } + + static bool vmhdrs_needed = true; + + private void GenVirtualMethods (GenerationInfo gen_info) + { + if (vmhdrs_needed) { + gen_info.GlueWriter.WriteLine ("#include "); + gen_info.GlueWriter.WriteLine ("#include \"vmglueheaders.h\""); + gen_info.GlueWriter.WriteLine (); + vmhdrs_needed = false; + } + + foreach (XmlElement elem in vm_nodes) { + GenVMGlue (gen_info, elem); + } + } + /* Keep this in sync with the one in glib/ObjectManager.cs */ private static string GetExpected (string cname) { diff --git a/generator/Statistics.cs b/generator/Statistics.cs index 315737e55..69e84a437 100644 --- a/generator/Statistics.cs +++ b/generator/Statistics.cs @@ -1,8 +1,9 @@ // Statistics.cs : Generation statistics class implementation // -// Author: Mike Kestner +// Author: Mike Kestner // // 2002 Mike Kestner +// 2004 Novell, Inc. namespace GtkSharp.Generation { @@ -24,6 +25,7 @@ namespace GtkSharp.Generation { static int sigs = 0; static int throttled = 0; static int ignored = 0; + static bool vm_ignored = false; public static int CBCount { get { @@ -142,8 +144,23 @@ namespace GtkSharp.Generation { } } + public static bool VMIgnored { + get { + return vm_ignored; + } + set { + if (value) + vm_ignored = value; + } + } + public static void Report() { + if (VMIgnored) { + Console.WriteLine(); + Console.WriteLine("Warning: Generation throttled for Virtual Methods."); + Console.WriteLine(" Consider regenerating with --gluelib-name and --glue-filename."); + } Console.WriteLine(); Console.WriteLine("Generation Summary:"); Console.Write(" Enums: " + enums);