2004-03-18 Mike Kestner <mkestner@ximian.com>

* 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
This commit is contained in:
Mike Kestner 2004-03-18 20:56:32 +00:00
parent 37a37adf53
commit 9861569931
13 changed files with 232 additions and 11 deletions

View file

@ -1,3 +1,20 @@
2004-03-18 Mike Kestner <mkestner@ximian.com>
* 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 <mkestner@ximian.com>
* parser/gapi2xml.pl : fix passbyvalue bug in vm parsing.

View file

@ -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

8
atk/glue/.cvsignore Normal file
View file

@ -0,0 +1,8 @@
generated.c
Makefile
Makefile.in
*.la
*.lo
*.o
.deps
.libs

21
atk/glue/Makefile.am Normal file
View file

@ -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

22
atk/glue/makefile.win32 Executable file
View file

@ -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

4
atk/glue/vmglueheaders.h Normal file
View file

@ -0,0 +1,4 @@
/* Headers for virtual method glue compilation */
#include <atk/atk.h>

16
atk/glue/win32dll.c Executable file
View file

@ -0,0 +1,16 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#include <stdio.h>
BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
return TRUE;
}
/*
BOOL APIENTRY DllMainCRTStartup (HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
return TRUE;
}
*/

View file

@ -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

View file

@ -166,6 +166,7 @@ glib/Makefile
glib/glue/Makefile
pango/Makefile
atk/Makefile
atk/glue/Makefile
art/Makefile
gdk/Makefile
gdk/glue/Makefile

View file

@ -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;
}

View file

@ -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;

View file

@ -1,8 +1,9 @@
// GtkSharp.Generation.ObjectGen.cs - The Object Generatable.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
// Author: Mike Kestner <mkestner@ximian.com>
//
// (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 <glib-object.h>");
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)
{

View file

@ -1,8 +1,9 @@
// Statistics.cs : Generation statistics class implementation
//
// Author: Mike Kestner <mkestner@speakeasy.net>
// Author: Mike Kestner <mkestner@ximian.com>
//
// <c> 2002 Mike Kestner
// <c> 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);