From aba851645cc2999126229eeaede1055e236441b8 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Sun, 4 Nov 2001 15:42:46 +0000 Subject: [PATCH] 2001-11-04 Mike Kestner * codegen/defs-parse.pl : struct generation. Added float and double type mapping entries. * codegen/hardcoded.defs : GdkGeometry definition. define-struct doesn't appear to be supported in the current defs files. This file will be used for manual definition of unsupported defs. * codegen/makefile : add hardcoded.defs. svn path=/trunk/gtk-sharp/; revision=1256 --- ChangeLog | 9 +++++++++ codegen/defs-parse.pl | 44 ++++++++++++++++++++++++++++++++++++------ codegen/hardcoded.defs | 18 +++++++++++++++++ codegen/makefile | 2 +- 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 codegen/hardcoded.defs diff --git a/ChangeLog b/ChangeLog index f9fe2c953..ac3c25204 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2001-11-04 Mike Kestner + + * codegen/defs-parse.pl : struct generation. Added float and double + type mapping entries. + * codegen/hardcoded.defs : GdkGeometry definition. define-struct + doesn't appear to be supported in the current defs files. This file + will be used for manual definition of unsupported defs. + * codegen/makefile : add hardcoded.defs. + 2001-11-02 Mike Kestner * codegen/defs-parse.pl : define-struct detection. Partial ctor diff --git a/codegen/defs-parse.pl b/codegen/defs-parse.pl index aa1aeb4a9..a9930b722 100755 --- a/codegen/defs-parse.pl +++ b/codegen/defs-parse.pl @@ -9,12 +9,12 @@ %maptypes = ( 'none', "void", 'gboolean', "bool", 'gint', "int", 'guint', "uint", 'guint32', "uint", 'const-gchar', "String", 'GObject', "GLib.Object", - 'gchar', "String"); + 'gchar', "String", 'gfloat', "float", 'gdouble', "double"); %marshaltypes = ( 'none', "void", 'gboolean', "bool", 'gint', "int", 'guint', "uint", 'guint32', "uint", 'const-gchar', "IntPtr", 'GObject', "IntPtr", - 'gchar', "IntPtr"); + 'gchar', "IntPtr", 'gfloat', "float", 'gdouble', "double"); `mkdir -p ../gdk/generated`; `mkdir -p ../gtk/generated`; @@ -25,11 +25,8 @@ while ($def = get_def()) { gen_enum (split (/\n/, $def)); } elsif ($def =~ /^\(define-struct (\w+)/) { $name = $1; - $def =~ /c-name "(\w+)"/; - $cname=$1; $def =~ s/\n\s*//g; - $maptypes{$cname} = $name; - $marshaltypes{$cname} = "IntPtr"; + gen_struct ($name, $def); } elsif ($def =~ /^\(define-object (\w+)/) { $name = $1; $def =~ /c-name "(\w+)"/; @@ -159,6 +156,41 @@ sub gen_enum close (OUTFILE); } +sub gen_struct +{ + my ($name, $def) = @_; + + $def =~ /c-name "(\w+)"/; + $cname = $1; + $def =~ /in-module "(\w+)"/; + $namespace = $1; + + $maptypes{$cname} = $name; + $marshaltypes{$cname} = $name; + + $dir = "../" . lc ($namespace) . "/generated"; + open (OUTFILE, ">$dir/$name.cs") || die "can't open file"; + + print OUTFILE "// Generated file: Do not modify\n\n"; + print OUTFILE "namespace $namespace {\n\n"; + print OUTFILE "\t/// $name Structure \n"; + print OUTFILE "\t/// \n\t///\tFIXME: Add docs.\n"; + print OUTFILE "\t/// \n\n"; + + print OUTFILE "\tpublic struct $name {\n"; + + if ($def =~ /fields'\((.*)\)\)\)/) { + foreach $parm (split(/\)'\(/, $1)) { + $parm =~ s/\*//g; + $parm =~ /"(\S*)" "(\S*)"/; + print OUTFILE "\t\tpublic $maptypes{$1} $2;\n"; + } + } + + print OUTFILE "\t}\n\n}\n"; + close (OUTFILE); +} + # Code generation for objects. sub gen_object { diff --git a/codegen/hardcoded.defs b/codegen/hardcoded.defs new file mode 100644 index 000000000..9c31b0c7d --- /dev/null +++ b/codegen/hardcoded.defs @@ -0,0 +1,18 @@ +(define-struct Geometry + (in-module "Gdk") + (c-name "GdkGeometry") + (fields + '("gint" "min_width") + '("gint" "max_width") + '("gint" "min_height") + '("gint" "max_height") + '("gint" "base_width") + '("gint" "base_height") + '("gint" "width_inc") + '("gint" "height_inc") + '("gdouble" "min_aspect") + '("gdouble" "max_aspect") + '("GdkGravity" "win_gravity") + ) +) + diff --git a/codegen/makefile b/codegen/makefile index a85803abc..3838a7d96 100755 --- a/codegen/makefile +++ b/codegen/makefile @@ -3,7 +3,7 @@ all: @echo "'make unix' is broken for now." windows: - cat gdk-types.defs gtk-types.defs gtk-props.defs gtk.defs | ./defs-parse.pl + cat gdk-types.defs hardcoded.defs gtk-types.defs gtk-props.defs gtk.defs | ./defs-parse.pl unix: @echo "'make unix' is broken for now."