GtkSharp/Source/OldStuff/parser/gapi2xml.pl

1286 lines
36 KiB
Perl
Raw Normal View History

#!/usr/bin/perl
#
# gapi2xml.pl : Generates an XML representation of GObject based APIs.
#
# Author: Mike Kestner <mkestner@speakeasy.net>
#
# Copyright (c) 2001-2003 Mike Kestner
# Copyright (c) 2003-2009 Novell, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
##############################################################
$parser_version = 2;
$debug=$ENV{'GAPI_DEBUG'};
use XML::LibXML;
if (!$ARGV[2]) {
die "Usage: gapi_pp.pl <srcdir> | gapi2xml.pl <namespace> <outfile> <libname>\n";
}
$ns = $ARGV[0];
$libname = $ARGV[2];
# Used by name mangling sub
%num2txt = ('1', "One", '2', "Two", '3', "Three", '4', "Four", '5', "Five",
'6', "Six", '7', "Seven", '8', "Eight", '9', "Nine", '0', "Zero");
##############################################################
# Check if the filename provided exists. We parse existing files into
# a tree and append the namespace to the root node. If the file doesn't
# exist, we create a doc tree and root node to work with.
##############################################################
if (-e $ARGV[1]) {
#parse existing file and get root node.
$doc = XML::LibXML->new->parse_file($ARGV[1]);
$root = $doc->getDocumentElement();
if ($root->getAttribute ('parser_version') != $parser_version) {
die "The version of the file does not match the version of the parser";
}
} else {
$doc = XML::LibXML::Document->new();
$root = $doc->createElement('api');
$root->setAttribute('parser_version', $parser_version);
$doc->setDocumentElement($root);
$warning_node = XML::LibXML::Comment->new ("\n\n This file was automatically generated.\n Please DO NOT MODIFY THIS FILE, modify .metadata files instead.\n\n");
$root->appendChild($warning_node);
}
$ns_elem = $doc->createElement('namespace');
$ns_elem->setAttribute('name', $ns);
$ns_elem->setAttribute('library', $libname);
$root->appendChild($ns_elem);
##############################################################
# First we parse the input for typedefs, structs, enums, and class_init funcs
# and put them into temporary hashes.
##############################################################
while ($line = <STDIN>) {
if ($line =~ /typedef\s+(struct\s+\w+\s+)\*+(\w+);/) {
$ptrs{$2} = $1;
} elsif ($line =~ /typedef\s+(struct\s+\w+)\s+(\w+);/) {
next if ($2 =~ /Private$/);
2002-07-30 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: Change hasDefaultConstructor to protected, adjust now that it is an attr and not a subnode. Also add virtual property AssignToName (for ctors). * generator/Ctor.cs: Add property ForceStatic. (Generate): Optimize return code a bit for the static case. * generator/Method.cs: Assign to a "raw_ret" pointer before calling FromNativeReturn. * generator/Parameters.cs: Change "out ref" to "out", not "ref". * generator/Property.cs: Fix to work correctly with all object and struct types (mostly just some if-cases added). * generator/SignalHandler.cs: Remove args_type and argfields (unused). (Generate): Initialize struct if necessary. * generator/StructBase.cs: Massive reworking to support methods, ctors, etc. * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event fields. Fix docs. * glib/Value.cs: Work correctly with boxed properties. * gnome/Modules.cs: Use new struct ctors. * gnome/Program.custom: Remove Get, this is being generated now. * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. * parser/Metadata.pm: Change per-class attributes to actually be attributes. * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap typedefs. * sample/test/TestColorSelection.cs: Display color string in hex format, update to use IsNull instead of == null, and size dialog to look pretty. * sample/Size.cs: Added. svn path=/trunk/gtk-sharp/; revision=6264
2002-07-30 23:02:12 +00:00
# fixme: siiigh
$2 = "GdkDrawable" if ($1 eq "_GdkDrawable");
$types{$2} = $1;
} elsif ($line =~ /typedef\s+struct/) {
$sdef = $line;
while ($line = <STDIN>) {
$sdef .= $line;
last if ($line =~ /^(deprecated)?}/);
}
$sdef =~ s!/\*.*?(\*/|\n)!!g;
$sdef =~ s/\n\s*//g;
$types{$1} = $sdef if ($sdef =~ /.*\}\s*(\w+);/);
} elsif ($line =~ /typedef\s+(unsigned\s+\w+)\s+(\**)(\w+);/) {
$types{$3} = $1 . $2;
} elsif ($line =~ /typedef\s+(\w+)\s+(\**)(\w+);/) {
$types{$3} = $1 . $2;
} elsif ($line =~ /typedef\s+enum\s+(\w+)\s+(\w+);/) {
$etypes{$1} = $2;
} elsif ($line =~ /^((deprecated)?typedef\s+)?\benum\b/) {
$edef = $line;
while ($line = <STDIN>) {
$edef .= $line;
last if ($line =~ /^(deprecated)?}\s*(\w+)?;/);
}
$edef =~ s/\n\s*//g;
$edef =~ s|/\*.*?\*/||g;
if ($edef =~ /typedef.*}\s*(\w+);/) {
$ename = $1;
} elsif ($edef =~ /^(deprecated)?enum\s+(\w+)\s*{/) {
$ename = $2;
} else {
print "Unexpected enum format\n$edef";
next;
}
$edefs{$ename} = $edef;
} elsif ($line =~ /typedef\s+(const\s+)?\w+\s*\**\s*\(\s*\*\s*(\w+)\s*\)\s*\(/) {
$fname = $2;
$fdef = "";
while ($line !~ /;/) {
$fdef .= $line;
$line = <STDIN>;
}
$fdef .= $line;
$fdef =~ s/\n\s+//g;
$fpdefs{$fname} = $fdef;
} elsif ($line =~ /^(private|deprecated)?struct\s+(\w+)/) {
next if ($line =~ /;/);
$sname = $2;
$sdef = $line;
while ($line = <STDIN>) {
$sdef .= $line;
last if ($line =~ /^(deprecated)?}/);
}
$sdef =~ s!/\*[^<].*?(\*/|\n)!!g;
$sdef =~ s/\n\s*//g;
$sdefs{$sname} = $sdef if (!exists ($sdefs{$sname}));
} elsif ($line =~ /^(\w+)_(class|base|default)_init\b/) {
$class = StudlyCaps($1);
$pedef = $line;
while ($line = <STDIN>) {
$pedef .= $line;
last if ($line =~ /^(deprecated)?}/);
}
$pedefs{lc($class)} = $pedef;
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
} elsif ($line =~ /^(\w+)_get_type\b/) {
$class = StudlyCaps($1);
$pedef = $line;
while ($line = <STDIN>) {
$pedef .= $line;
if ($line =~ /g_boxed_type_register_static/) {
$boxdef = $line;
while ($line !~ /;/) {
$boxdef .= ($line = <STDIN>);
}
$boxdef =~ s/\n\s*//g;
$boxdef =~ /\(\"(\w+)\"/;
my $boxtype = $1;
$boxtype =~ s/($ns)Type(\w+)/$ns$2/;
$boxdefs{$boxtype} = $boxdef;
* parser/gapi2xml.pl: make note of _get_type methods for enums * */*-api.xml: Regen, adding gtype="..." to many enum types * generator/EnumGen.cs (Generate): if the enum has the "gtype" property, add a GTypeAttribute pointing to an internal FooGType class whose GType property can be used to get the enum's GType. * generator/ObjectGen.cs: s/ObjectManager.RegisterType/GType.Register/ * glib/GTypeAttribute.cs: attribute for indicating a property that will return the GType of a type (particularly for enums, which can't have GType properties added to them). * glib/GType.cs: renamed from Type.cs to match the type name (public static readonly GType ...): add a few missing types. (Register): moved from ObjectManager.RegisterType (LookupGType): moved from TypeConverter.LookupType and extended to handle GTypeAttribute. Also, fix mappings for sbyte/byte/char, and return specific GTypes for Object subclasses rather than always returning GType.Object. [Fixes #74699] (LookupType): moved from ObjectWrapper.LookupType (ToString): return the type name * glib/Object.cs (RegisterGType): s/ObjectManager.Register/GType.Register/ (LookupGType): Make this protected internal so GType can access it. * glib/ObjectManager.cs (RegisterType): deprecate in favor of GType.Register. (LookupType): moved to GType * glib/TypeConverter.cs (LookupType): now a deprecated wrapper around GType.LookupGType. * glib/Value.cs: Use GType casts rather than TypeConverter * gtk/NodeStore.cs (ScanType): * gtk/ListStore.custom (ListStore): * gtk/TreeStore.custom (TreeStore): Use (GType) cast rather than TypeConverter. Remove the error check and exception, since the cast never returns GType.Invalid. (The check probably predates GLib.ManagedValue.) * gnome/PanelAppletFactory.cs (Register): Use a GType cast rather than GLib.Object.LookupGType (which is no longer accessible after an mcs bugfix) * sample/GtkDemo/DemoIconView.cs (CreateStore): use the Type[] constructor rather than the GType[] constructor, since it translates typeof(Gdk.Pixbuf) correctly now. svn path=/trunk/gtk-sharp/; revision=44038
2005-05-04 16:54:24 +00:00
} elsif ($line =~ /g_(enum|flags)_register_static/) {
$pedef =~ /^(\w+_get_type)/;
$enum_gtype{$class} = $1;
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
}
last if ($line =~ /^(deprecated)?}/);
}
$typefuncs{lc($class)} = $pedef;
} elsif ($line =~ /^G_DEFINE_TYPE_(EXTENDED|WITH_CODE)\s*\(\s*(\w+)/) {
$typefuncs{lc($2)} = $line;
} elsif ($line =~ /^G_DEFINE_BOXED_TYPE\s*\(\s*(\w+)/) {
$boxdefs{$1} = $line;
} elsif ($line =~ /^G_DEFINE_INTERFACE\s*\(\s*(\w+)\s*,\s*(\w+)/) {
if (exists($get_types{"$2_get_type"})) {
$typedef = $get_types{"$2_get_type"};
if (!exists($ifaces{$typedef})) {
$ifaces{$typedef} = "$1Interface";
}
}
} elsif ($line =~ /^(deprecated)?(const|G_CONST_RETURN)?\s*(struct\s+)?\w+\s*\**(\s*(const|G_CONST_RETURN)\s*\**)?\s*(\w+)\s*\(/) {
$fname = $6;
$fdef = "";
while ($line !~ /;/) {
$fdef .= $line;
$line = <STDIN>;
}
$fdef .= $line;
$fdef =~ s/\n\s*//g;
if ($fdef !~ /^_/) {
$fdefs{$fname} = $fdef;
}
} elsif ($line =~ /CHECK_(\w*)CAST/) {
$cast_macro = $line;
while ($line =~ /\\$/) {
$line = <STDIN>;
$cast_macro .= $line;
}
$cast_macro =~ s/\\\n\s*//g;
$cast_macro =~ s/\s+/ /g;
if ($cast_macro =~ /G_TYPE_CHECK_(\w+)_CAST.*,\s*(\w+),\s*(\w+)\)/) {
if ($1 eq "INSTANCE") {
$objects{$2} = $3 . $objects{$2};
} else {
$objects{$2} .= ":$3";
}
} elsif ($cast_macro =~ /G_TYPE_CHECK_(\w+)_CAST.*,\s*([a-zA-Z0-9]+)_(\w+)_get_type\s*\(\),\s*(\w+)\)/) {
$typename = uc ("$2_type_$3");
if ($1 eq "INSTANCE") {
$objects{$typename} = $4 . $objects{$typename};
} else {
$objects{$typename} .= ":$4";
}
} elsif ($cast_macro =~ /GTK_CHECK_CAST.*,\s*(\w+),\s*(\w+)/) {
$objects{$1} = $2 . $objects{$1};
} elsif ($cast_macro =~ /GTK_CHECK_CLASS_CAST.*,\s*(\w+),\s*(\w+)/) {
$objects{$1} .= ":$2";
} elsif ($cast_macro =~ /GST_IMPLEMENTS_INTERFACE_CHECK_INSTANCE_CAST.*,\s*(\w+),\s*(\w+)/) {
$objects{$1} = $2 . $objects{$1};
}
} elsif ($line =~ /INSTANCE_GET_INTERFACE.*,\s*(\w+),\s*(\w+)/) {
$ifaces{$1} = $2;
} elsif ($line =~ /^BUILTIN\s*\{\s*\"(\w+)\".*GTK_TYPE_BOXED/) {
$boxdefs{$1} = $line;
} elsif ($line =~ /^BUILTIN\s*\{\s*\"(\w+)\".*GTK_TYPE_(ENUM|FLAGS)/) {
# ignoring these for now.
} elsif ($line =~ /^(deprecated)?\#\s*define/) {
my $test_ns = uc ($ns);
if ($line =~ /^deprecated\#\s*define\s+(\w+)\s+\"(.*)\"/) {
$defines{"deprecated$1"} = $2;
} elsif ($line =~ /\#\s*define\s+(\w+)\s+\"(.*)\"/) {
$defines{$1} = $2;
} elsif ($line =~ /\#\s*define\s+(\w+)\s+\(?\s*(\w+_get_type)/) {
$get_types{$2} = $1;
}
} elsif ($line !~ /\/\*/) {
print $line;
}
}
##############################################################
# Produce the enum definitions.
##############################################################
%enums = ();
foreach $cname (sort(keys(%edefs))) {
$ecnt++;
$def = $edefs{$cname};
$cname = $etypes{$cname} if (exists($etypes{$cname}));
$enums{lc($cname)} = $cname;
$enum_elem = addNameElem($ns_elem, 'enum', $cname, $ns);
if ($def =~ /^deprecated/) {
$enum_elem->setAttribute("deprecated", "1");
$def =~ s/deprecated//g;
}
* parser/gapi2xml.pl: make note of _get_type methods for enums * */*-api.xml: Regen, adding gtype="..." to many enum types * generator/EnumGen.cs (Generate): if the enum has the "gtype" property, add a GTypeAttribute pointing to an internal FooGType class whose GType property can be used to get the enum's GType. * generator/ObjectGen.cs: s/ObjectManager.RegisterType/GType.Register/ * glib/GTypeAttribute.cs: attribute for indicating a property that will return the GType of a type (particularly for enums, which can't have GType properties added to them). * glib/GType.cs: renamed from Type.cs to match the type name (public static readonly GType ...): add a few missing types. (Register): moved from ObjectManager.RegisterType (LookupGType): moved from TypeConverter.LookupType and extended to handle GTypeAttribute. Also, fix mappings for sbyte/byte/char, and return specific GTypes for Object subclasses rather than always returning GType.Object. [Fixes #74699] (LookupType): moved from ObjectWrapper.LookupType (ToString): return the type name * glib/Object.cs (RegisterGType): s/ObjectManager.Register/GType.Register/ (LookupGType): Make this protected internal so GType can access it. * glib/ObjectManager.cs (RegisterType): deprecate in favor of GType.Register. (LookupType): moved to GType * glib/TypeConverter.cs (LookupType): now a deprecated wrapper around GType.LookupGType. * glib/Value.cs: Use GType casts rather than TypeConverter * gtk/NodeStore.cs (ScanType): * gtk/ListStore.custom (ListStore): * gtk/TreeStore.custom (TreeStore): Use (GType) cast rather than TypeConverter. Remove the error check and exception, since the cast never returns GType.Invalid. (The check probably predates GLib.ManagedValue.) * gnome/PanelAppletFactory.cs (Register): Use a GType cast rather than GLib.Object.LookupGType (which is no longer accessible after an mcs bugfix) * sample/GtkDemo/DemoIconView.cs (CreateStore): use the Type[] constructor rather than the GType[] constructor, since it translates typeof(Gdk.Pixbuf) correctly now. svn path=/trunk/gtk-sharp/; revision=44038
2005-05-04 16:54:24 +00:00
if ($enum_gtype{$cname}) {
$enum_elem->setAttribute("gtype", $enum_gtype{$cname});
}
if ($def =~ /<</) {
$enum_elem->setAttribute('type', "flags");
} else {
$enum_elem->setAttribute('type', "enum");
}
$def =~ /\{(.*\S)\s*\}/;
@vals = split(/,\s*/, $1);
$vals[0] =~ s/^\s+//;
@nameandval = split(/=/, $vals[0]);
@v0 = split(/_/, $nameandval[0]);
if (@vals > 1) {
$done = 0;
for ($idx = 0, $regex = ""; $idx < @v0; $idx++) {
$regex .= ($v0[$idx] . "_");
foreach $val (@vals) {
$done = 1 if ($val !~ /$regex/);
}
last if $done;
}
$common = join("_", @v0[0..$idx-1]);
} else {
$common = join("_", @v0[0..$#v0-1]);
}
foreach $val (@vals) {
$val =~ s/=\s*\(\s*(.*\S)\s*\)\s*/= \1/;
if ($val =~ /$common\_?(\w+)\s*=\s*(.*)$/) {
$name = $1;
$enumval = $2;
if ($enumval =~ /^(\d+|0x[0-9A-Fa-f]+)u?\s*<<\s*(\d+)$/) {
$enumval = "$1 << $2";
} elsif ($enumval =~ /^$common\_?(\w+)$/) {
$enumval = StudlyCaps(lc($1))
}
} elsif ($val =~ /$common\_?(\w+)/) {
$name = $1; $enumval = "";
} else {
die "Unexpected enum value: $val for common value $common\n";
}
$val_elem = addNameElem($enum_elem, 'member');
$val_elem->setAttribute('cname', "$common\_$name");
$val_elem->setAttribute('name', StudlyCaps(lc($name)));
if ($enumval) {
$val_elem->setAttribute('value', $enumval);
}
}
}
##############################################################
# Parse the callbacks.
##############################################################
foreach $cbname (sort(keys(%fpdefs))) {
next if ($cbname =~ /^_/);
$cbcnt++;
$fdef = $cb = $fpdefs{$cbname};
$cb_elem = addNameElem($ns_elem, 'callback', $cbname, $ns);
$cb =~ /typedef\s+(.*)\(.*\).*\((.*)\);/;
$ret = $1; $params = $2;
addReturnElem($cb_elem, $ret);
if ($params && ($params ne "void")) {
addParamsElem($cb_elem, split(/,/, $params));
}
}
##############################################################
# Parse the interfaces list.
##############################################################
foreach $type (sort(keys(%ifaces))) {
$iface = $ifaces{$type};
($inst, $dontcare) = split(/:/, delete $objects{$type});
$initfunc = $pedefs{lc($inst)};
$ifacetype = delete $types{$iface};
delete $types{$inst};
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
$ifacecnt++;
$iface_el = addNameElem($ns_elem, 'interface', $inst, $ns);
$elem_table{lc($inst)} = $iface_el;
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
if ($ifacetype =~ /struct\s+(\w+)/) {
$classdef = $sdefs{$1};
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
} else {
$classdef = 0;
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
}
if ($classdef) {
my @signal_vms;
if ($initfunc) {
@signal_vms = parseInitFunc($iface_el, $initfunc, $classdef);
} else {
warn "Don't have an init func for $inst.\n" if $debug;
# my @signal_vms;
}
addClassElem ($iface_el, $classdef, @signal_vms);
} else {
$iface_el->setAttribute("consume_only", "1");
}
}
##############################################################
# Parse the classes by walking the objects list.
##############################################################
foreach $type (sort(keys(%objects))) {
($inst, $class) = split(/:/, $objects{$type});
$class = $inst . "Class" if (!$class);
$initfunc = $pedefs{lc($inst)};
$typefunc = $typefuncs{lc($inst)};
$insttype = delete $types{$inst};
$classtype = delete $types{$class};
$instdef = $classdef = "";
$instdef = $sdefs{$1} if ($insttype =~ /struct\s+(\w+)/);
$classdef = $sdefs{$1} if ($classtype =~ /struct\s+(\w+)/);
$classdef =~ s/deprecated//g;
$instdef =~ s/\s+(\*+)([^\/])/\1 \2/g;
warn "Strange Class $inst\n" if (!$instdef && $debug);
$classcnt++;
$obj_el = addNameElem($ns_elem, 'object', $inst, $ns);
$elem_table{lc($inst)} = $obj_el;
# Check if the object is deprecated
if ($instdef =~ /^deprecatedstruct/) {
$obj_el->setAttribute("deprecated", "1");
$instdef =~ s/deprecated//g;
}
# Extract parent and fields from the struct
if ($instdef =~ /^struct/) {
$instdef =~ /\{(.*)\}/;
$fieldstr = $1;
$fieldstr =~ s|/\*[^<].*?\*/||g;
@fields = split(/;/, $fieldstr);
addFieldElems($obj_el, 'private', @fields);
$obj_el->setAttribute('parent', $obj_el->firstChild->getAttribute('type'));
$obj_el->removeChild($obj_el->firstChild);
} elsif ($instdef =~ /privatestruct/) {
# just get the parent for private structs
$instdef =~ /\{\s*(\w+)/;
$obj_el->setAttribute('parent', "$1");
}
# Get the props from the class_init func.
if ($initfunc) {
@signal_vms = parseInitFunc($obj_el, $initfunc, $classdef);
} else {
warn "Don't have an init func for $inst.\n" if $debug;
}
addClassElem ($obj_el, $classdef, @signal_vms) if ($classdef);
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
# Get the interfaces from the class_init func.
if ($typefunc) {
if ($typefunc =~ /G_DEFINE_TYPE_(EXTENDED|WITH_CODE)/) {
parseTypeFuncMacro($obj_el, $typefunc);
} else {
parseTypeFunc($obj_el, $typefunc);
}
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
} else {
warn "Don't have a GetType func for $inst.\n" if $debug;
}
}
##############################################################
# Parse the remaining types.
##############################################################
foreach $key (sort (keys (%types))) {
$lasttype = $type = $key;
while ($type && ($types{$type} !~ /struct/)) {
$lasttype = $type;
$type = $types{$type};
}
if ($types{$type} =~ /struct\s+(\w+)/) {
$type = $1;
if (exists($sdefs{$type})) {
$def = $sdefs{$type};
} else {
$def = "privatestruct";
}
} elsif ($types{$type} =~ /struct/ && $type =~ /^$ns/) {
$def = $types{$type};
} else {
$elem = addNameElem($ns_elem, 'alias', $key, $ns);
$elem->setAttribute('type', $lasttype);
warn "alias $key to $lasttype\n" if $debug;
next;
}
2002-07-30 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: Change hasDefaultConstructor to protected, adjust now that it is an attr and not a subnode. Also add virtual property AssignToName (for ctors). * generator/Ctor.cs: Add property ForceStatic. (Generate): Optimize return code a bit for the static case. * generator/Method.cs: Assign to a "raw_ret" pointer before calling FromNativeReturn. * generator/Parameters.cs: Change "out ref" to "out", not "ref". * generator/Property.cs: Fix to work correctly with all object and struct types (mostly just some if-cases added). * generator/SignalHandler.cs: Remove args_type and argfields (unused). (Generate): Initialize struct if necessary. * generator/StructBase.cs: Massive reworking to support methods, ctors, etc. * generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types. * glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both. * glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event fields. Fix docs. * glib/Value.cs: Work correctly with boxed properties. * gnome/Modules.cs: Use new struct ctors. * gnome/Program.custom: Remove Get, this is being generated now. * parser/Gdk.metadata: Fix the drawable classes to inherit correctly. * parser/Metadata.pm: Change per-class attributes to actually be attributes. * parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor. * parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap typedefs. * sample/test/TestColorSelection.cs: Display color string in hex format, update to use IsNull instead of == null, and size dialog to look pretty. * sample/Size.cs: Added. svn path=/trunk/gtk-sharp/; revision=6264
2002-07-30 23:02:12 +00:00
# fixme: hack
if ($key eq "GdkBitmap") {
$struct_el = addNameElem($ns_elem, 'object', $key, $ns);
} elsif (exists($boxdefs{$key})) {
$struct_el = addNameElem($ns_elem, 'boxed', $key, $ns);
} else {
$struct_el = addNameElem($ns_elem, 'struct', $key, $ns);
}
if ($def =~ /^deprecated/) {
$struct_el->setAttribute("deprecated", "1");
$def =~ s/deprecated//g;
}
$elem_table{lc($key)} = $struct_el;
$def =~ s/\s+/ /g;
if ($def =~ /privatestruct/) {
$struct_el->setAttribute('opaque', 'true');
} else {
$def =~ /\{(.+)\}/;
addFieldElems($struct_el, 'public', split(/;/, $1));
}
}
# really, _really_ opaque structs that aren't even defined in sources. Lovely.
foreach $key (sort (keys (%ptrs))) {
next if $ptrs{$key} !~ /struct\s+(\w+)/;
$type = $1;
$struct_el = addNameElem ($ns_elem, 'struct', $key, $ns);
$struct_el->setAttribute('opaque', 'true');
$elem_table{lc($key)} = $struct_el;
}
addFuncElems();
addStaticFuncElems();
# This should probably be done in a more generic way
foreach $define (sort (keys (%defines))) {
next if $define !~ /[A-Z]_STOCK_/;
if ($stocks{$ns}) {
$stock_el = $stocks{$ns};
} else {
$stock_el = addNameElem($ns_elem, "object", $ns . "Stock", $ns);
$stocks{$ns} = $stock_el;
}
$string_el = addNameElem ($stock_el, "static-string", $define);
$string_name = lc($define);
$string_name =~ s/\w+_stock_//;
$string_el->setAttribute('name', StudlyCaps($string_name));
$string_el->setAttribute('value', $defines{$define});
}
##############################################################
# Output the tree
##############################################################
if ($ARGV[1]) {
open(XMLFILE, ">$ARGV[1]") || die "Couldn't open $ARGV[1] for writing.\n";
print XMLFILE $doc->toString();
close(XMLFILE);
} else {
print $doc->toString();
}
##############################################################
# Generate a few stats from the parsed source.
##############################################################
$scnt = keys(%sdefs); $fcnt = keys(%fdefs); $tcnt = keys(%types);
print "structs: $scnt enums: $ecnt callbacks: $cbcnt\n";
print "funcs: $fcnt types: $tcnt classes: $classcnt\n";
print "props: $propcnt childprops: $childpropcnt signals: $sigcnt\n\n";
sub addClassElem
{
my ($obj_el, $classdef, @signal_vms) = @_;
my %is_signal_vm;
for (@signal_vms) {
$is_signal_vm{$_} = 1;
}
if ($classdef =~ /struct\s+_?(\w+)\s*{(.*)};/) {
my $elem = $doc->createElement('class_struct');
$elem->setAttribute('cname', $1);
$obj_el->insertBefore($elem, $obj_el->firstChild);
$fields = $2;
$fields =~ s!/\*.*?\*/!!g; # Remove comments
foreach $field (split (/;/, $fields)) {
if ($field =~ /\s*(G_CONST_RETURN\s+)?(\S+\s*\**)\s*\(\s*\*\s*(\w+)\s*\)\s*(\((.*?)\))?/) {
$ret = $1 . $2; $cname = $3; $parms = $5;
$class_elem = $doc->createElement('method');
$elem->appendChild($class_elem);
if ($is_signal_vm{$cname}) {
$class_elem->setAttribute('signal_vm', $cname);
} else {
$class_elem->setAttribute('vm', $cname);
$vm_elem = $doc->createElement('virtual_method');
$obj_el->appendChild($vm_elem);
$vm_elem->setAttribute('name', StudlyCaps($cname));
$vm_elem->setAttribute('cname', $cname);
addReturnElem($vm_elem, $ret);
if ($parms && ($parms ne "void")) { # if there are any parameters
@parm_arr = split(/,/, $parms);
$parms =~ /\s*(\w+)/; # Get type of first parameter
if ($1 ne $obj_el->getAttribute ('cname')) {
$vm_elem->setAttribute('shared', 'true'); # First parameter is not of the type of the declaring class -> static vm
} else {
($dump, @parm_arr) = @parm_arr;
}
addParamsElem($vm_elem, @parm_arr);
} else {
$vm_elem->setAttribute('shared', 'true');
}
if ($cname =~ /reserved_?[0-9]+$/ || $cname =~ /padding_?[0-9]+$/ || $cname =~ /recent_?[0-9]+$/) {
$vm_elem->setAttribute('padding', 'true');
}
}
2011-09-26 11:52:12 +00:00
} elsif ($field =~ /(unsigned\s+)?(const\s+)?(\S+)\s+(.+)/) {
my $unsigned = $1; $const = $2; $name = $3; $symb = $4;
$const =~ s/const\s+/const\-/g;
my $type = $unsigned . $const . $name;
foreach $tok (split (/,\s*/, $symb)) { # multiple field defs may occur in one line; like int xrange, yrange;
$tok =~ /(\*)?(\w+)\s*(.*)/;
my $field_type = $type . $1; my $cname = $2; my $modifiers = $3;
$fld_elem = addNameElem($elem, 'field', $cname, "");
$fld_elem->setAttribute('type', "$field_type");
if ($modifiers =~ /\[(.*)\]/) {
$fld_elem->setAttribute('array_len', "$1");
} elsif ($modifiers =~ /\:\s*(\d+)/) {
$fld_elem->setAttribute('bits', "$1");
}
}
} elsif ($field =~ /\S+/) {
print "***** Unmatched class struct field $field\n";
}
}
} else {
print "***** Unmatched $classdef\n";
}
}
sub addFieldElems
{
my ($parent, $defaultaccess, @fields) = @_;
my $access = $defaultaccess;
foreach $field (@fields) {
if ($field =~ m!/\*< (public|private) >.*\*/(.*)$!) {
$access = $1;
$field = $2;
}
next if ($field !~ /\S/);
$field =~ s/GSEAL\s*\((.*)\)/\1/g;
$field =~ s/\bvolatile\s+//g;
$field =~ s/\s+(\*+)/\1 /g;
$field =~ s/(const\s+)?(\w+)\*\s+const\*/const \2\*/g;
$field =~ s/(\w+)\s+const\s*\*/const \1\*/g;
$field =~ s/const /const\-/g;
2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 06:08:52 +00:00
$field =~ s/struct /struct\-/g;
$field =~ s/.*\*\///g;
next if ($field !~ /\S/);
if ($field =~ /(\S+\s+\*?)\(\*\s*(.+)\)\s*\((.*)\)/) {
$elem = addNameElem($parent, 'callback', $2);
addReturnElem($elem, $1);
addParamsElem($elem, $3);
} elsif ($field =~ /(unsigned )?(\S+)\s+(.+)/) {
my $type = $1 . $2; $symb = $3;
foreach $tok (split (/,\s*/, $symb)) {
if ($tok =~ /(\w+)\s*\[(.*)\]/) {
$elem = addNameElem($parent, 'field', $1, "");
$elem->setAttribute('array_len', "$2");
} elsif ($tok =~ /(\w+)\s*\:\s*(\d+)/) {
$elem = addNameElem($parent, 'field', $1, "");
$elem->setAttribute('bits', "$2");
} else {
$elem = addNameElem($parent, 'field', $tok, "");
}
$elem->setAttribute('type', "$type");
if ($access ne $defaultaccess) {
$elem->setAttribute('access', "$access");
}
}
} else {
die "$field\n";
}
}
}
sub addFuncElems
{
my ($obj_el, $inst, $prefix);
$fcnt = keys(%fdefs);
foreach $mname (sort (keys (%fdefs))) {
next if ($mname =~ /^_/);
$obj_el = "";
$prefix = $mname;
$prepend = undef;
while ($prefix =~ /(\w+)_/) {
$prefix = $key = $1;
$key =~ s/_//g;
# FIXME: lame Gdk API hack
if ($key eq "gdkdraw") {
$key = "gdkdrawable";
$prepend = "draw_";
}
if (exists ($elem_table{$key})) {
$prefix .= "_";
$obj_el = $elem_table{$key};
$inst = $key;
last;
} elsif (exists ($enums{$key}) && ($mname =~ /_get_type/)) {
delete $fdefs{$mname};
last;
}
}
next if (!$obj_el);
$mdef = delete $fdefs{$mname};
if ($mname =~ /$prefix(new)/) {
$el = addNameElem($obj_el, 'constructor', $mname);
if ($mdef =~ /^deprecated/) {
$el->setAttribute("deprecated", "1");
$mdef =~ s/deprecated//g;
}
$drop_1st = 0;
} else {
$el = addNameElem($obj_el, 'method', $mname, $prefix, $prepend);
if ($mdef =~ /^deprecated/) {
$el->setAttribute("deprecated", "1");
$mdef =~ s/deprecated//g;
}
$mdef =~ /(.*?)\w+\s*\(/;
addReturnElem($el, $1);
$mdef =~ /\(\s*(const)?\s*(\w+)/;
if (lc($2) ne $inst) {
$el->setAttribute("shared", "true");
$drop_1st = 0;
} else {
$drop_1st = 1;
}
}
parseParms ($el, $mdef, $drop_1st);
* parser/gapi2xml.pl (addFuncElems): if a struct or boxed type has a constructor or a ref, unref, or destroy method, then it must be a reference type, so mark it "opaque" but then also mark all of its fields public and writable. * */*-api*.raw: Regen * generator/Parser.cs (ParseNamespace): make the opaque attribute check actually look at the value of the attribute rather than just checking if it's there, so that you can change a struct's opaque attribute from "true" to "false" via metadata and have that work. * generator/BoxedGen.cs (Generate): do not generate the boxed's "Free" method (since it's guaranteed to crash when we pass it a stack pointer). If "Copy" is marked deprecated, create a deprecated no-op for it, otherwise just skip it (since otherwise it will just leak memory when we copy its result onto the stack). * pango/Pango.metadata: deprecate Pango.Color.Copy and Pango.Matrix.Copy. Hide some array fields in Pango.GlyphString that we've never generated correctly. Tweak Pango.LayoutLine fields to be the same as they used to be. * pango/GlyphItem.custom (glyphs, item): * pango/GlyphString.custom (Zero, New): * pango/Item.custom (Zero, New): * pango/LayoutRun.custom (glyphs, item): add deprecated API compat * gdk/Gdk.metadata: undo the parser's new opaquification of Gdk.Font; it's been deprecated since pre-gtk# times, and no one should be using it, so there's no point in fixing it now. Fix up a few other things to match how they used to be. Fix RgbCmap's constructor args. * gdk/RgbCmap.custom (Zero, New): deprecated API compat * gdk/PangoAttrEmbossed.custom: * gdk/PangoAttrStipple.custom (Zero, New, Attr): deprecated API compat (explicit operator ...): allow casting back and forth between Pango.Attribute. (We can't usefully make them real subclasses of Pango.Attribute, because there's no way for Pango.Attribute.GetAttribute() to be able to dtrt with them.) * gtk/Gtk.metadata: deprecate Gtk.Requisition.Copy, Gtk.TextIter.Copy, and Gtk.TreeIter.Copy. Mark the return value of TextView.DefaultAttributes as "owned". Mark TargetList's fields private so it stays how it used to be. * gtk/TextAttributes.custom (Zero, New): deprecated API compat * gnomevfs/Gnomevfs.metadata: remove a bunch of opaque declarations that the parser figures out on its own now. * art/Art.metadata: * glade/Glade.metadata: * rsvg/Rsvg.metadata: un-mark everything the parser marked opaque in these libraries, because all of the structs in question would still be unusably broken, so the API churn would be pointless. svn path=/trunk/gtk-sharp/; revision=48387
2005-08-15 15:15:57 +00:00
# Don't add "free" to this regexp; that will wrongly catch all boxed types
if ($mname =~ /$prefix(new|destroy|ref|unref)/ &&
($obj_el->nodeName eq "boxed" || $obj_el->nodeName eq "struct") &&
$obj_el->getAttribute("opaque") ne "true") {
$obj_el->setAttribute("opaque", "true");
for my $field ($obj_el->getElementsByTagName("field")) {
if (!$field->getAttribute("access")) {
$field->setAttribute("access", "public");
$field->setAttribute("writeable", "true");
}
}
}
}
}
sub parseParms
{
my ($el, $mdef, $drop_1st) = @_;
$fmt_args = 0;
if ($mdef =~ /G_GNUC_PRINTF.*\((\d+,\s*\d+)\s*\)/) {
$fmt_args = $1;
$mdef =~ s/\s*G_GNUC_PRINTF.*\)//;
}
if (($mdef =~ /\((.*)\)/) && ($1 ne "void")) {
@parms = ();
$parm = "";
$pcnt = 0;
foreach $char (split(//, $1)) {
if ($char eq "(") {
$pcnt++;
} elsif ($char eq ")") {
$pcnt--;
} elsif (($pcnt == 0) && ($char eq ",")) {
@parms = (@parms, $parm);
$parm = "";
next;
}
$parm .= $char;
}
if ($parm) {
@parms = (@parms, $parm);
}
# @parms = split(/,/, $1);
($dump, @parms) = @parms if $drop_1st;
if (@parms > 0) {
addParamsElem($el, @parms);
}
if ($fmt_args != 0) {
$fmt_args =~ /(\d+),\s*(\d+)/;
$fmt = $1; $args = $2;
($params_el, @junk) = $el->getElementsByTagName ("parameters");
(@params) = $params_el->getElementsByTagName ("parameter");
$offset = 1 + $drop_1st;
$params[$fmt-$offset]->setAttribute ("printf_format", "true");
$params[$args-$offset]->setAttribute ("printf_format_args", "true");
}
}
}
sub addStaticFuncElems
{
my ($global_el, $ns_prefix);
@mnames = sort (keys (%fdefs));
$mcount = @mnames;
return if ($mcount == 0);
$ns_prefix = "";
$global_el = "";
for ($i = 0; $i < $mcount; $i++) {
$mname = $mnames[$i];
$prefix = $mname;
next if ($prefix =~ /^_/);
if ($ns_prefix eq "") {
my (@toks) = split(/_/, $prefix);
for ($j = 0; $j < @toks; $j++) {
if (join ("", @toks[0 .. $j]) eq lc($ns)) {
$ns_prefix = join ("_", @toks[0 .. $j]);
last;
}
}
next if ($ns_prefix eq "");
}
next if ($mname !~ /^$ns_prefix/);
if ($mname =~ /($ns_prefix)_([a-zA-Z]+)_\w+/) {
$classname = $2;
$key = $prefix = $1 . "_" . $2 . "_";
$key =~ s/_//g;
$cnt = 1;
if (exists ($enums{$key})) {
$cnt = 1;
} elsif ($classname ne "set" && $classname ne "get" &&
$classname ne "scan" && $classname ne "find" &&
$classname ne "add" && $classname ne "remove" &&
$classname ne "free" && $classname ne "register" &&
$classname ne "execute" && $classname ne "show" &&
$classname ne "parse" && $classname ne "paint" &&
$classname ne "string") {
while ($mnames[$i+$cnt] =~ /$prefix/) { $cnt++; }
}
if ($cnt == 1) {
$mdef = delete $fdefs{$mname};
if (!$global_el) {
$global_el = $doc->createElement('class');
$global_el->setAttribute('name', "Global");
$global_el->setAttribute('cname', $ns . "Global");
$ns_elem->appendChild($global_el);
}
$el = addNameElem($global_el, 'method', $mname, $ns_prefix);
if ($mdef =~ /^deprecated/) {
$el->setAttribute("deprecated", "1");
$mdef =~ s/deprecated//g;
}
$mdef =~ /(.*?)\w+\s*\(/;
addReturnElem($el, $1);
$el->setAttribute("shared", "true");
parseParms ($el, $mdef, 0);
next;
} else {
$class_el = $doc->createElement('class');
$class_el->setAttribute('name', StudlyCaps($classname));
$class_el->setAttribute('cname', StudlyCaps($prefix));
$ns_elem->appendChild($class_el);
for ($j = 0; $j < $cnt; $j++) {
$mdef = delete $fdefs{$mnames[$i+$j]};
$el = addNameElem($class_el, 'method', $mnames[$i+$j], $prefix);
if ($mdef =~ /^deprecated/) {
$el->setAttribute("deprecated", "1");
$mdef =~ s/deprecated//g;
}
$mdef =~ /(.*?)\w+\s*\(/;
addReturnElem($el, $1);
$el->setAttribute("shared", "true");
parseParms ($el, $mdef, 0);
}
$i += ($cnt - 1);
next;
}
}
}
}
sub addNameElem
{
my ($node, $type, $cname, $prefix, $prepend) = @_;
my $elem = $doc->createElement($type);
$node->appendChild($elem);
if (defined $prefix) {
my $match;
if ($cname =~ /$prefix(\w+)/) {
$match = $1;
} else {
$match = $cname;
}
if ($prepend) {
$name = $prepend . $match;
} else {
$name = $match;
}
$elem->setAttribute('name', StudlyCaps($name));
}
if ($cname) {
$elem->setAttribute('cname', $cname);
}
return $elem;
}
sub addParamsElem
{
my ($parent, @params) = @_;
my $parms_elem = $doc->createElement('parameters');
$parent->appendChild($parms_elem);
my $parm_num = 0;
foreach $parm (@params) {
$parm_num++;
$parm =~ s/\s+(\*+)/\1 /g;
my $out = $parm =~ s/G_CONST_RETURN/const/g;
$parm =~ s/(const\s+)?(\w+)\*\s+const\*/const \2\*/g;
$parm =~ s/(\*+)\s*const\s+/\1 /g;
$parm =~ s/(\w+)\s+const\s*\*/const \1\*/g;
$parm =~ s/const\s+/const-/g;
$parm =~ s/unsigned\s+/unsigned-/g;
$parm =~ s/\bvolatile\s+//g;
if ($parm =~ /(.*)\(\s*\**\s*(\w+)\)\s+\((.*)\)/) {
my $ret = $1; my $cbn = $2; my $params = $3;
* parser/gapi2xml.pl (addParamsElem): change the handling of anonymous function pointer types in method signatures. Before, we added a <callback> child to the <parameters> node, but the generator just ignored it. Now we add the callback (with a made-up name) to the toplevel node, and add an ordinary <param> node referencing it to the <parameters> node. Also, if the last param of the callback is a gpointer, rename it from "arg#" to "data" so it will be treated correctly (as the user data passed from the calling method). [Fixes #66241] * art/art-api.raw: * gdk/gdk-api-2.4.raw: * gdk/gdk-api-2.6.raw: Regen * generator/Parameters.cs (IsHidden): loosen the definition of hideable user_data; it doesn't have to occur at the end of the parameter list, as long as there's a callback arg before it. * generator/MethodBody.cs (GetCallString): Use Parameters.IsHidden to decide whether or not to squash user_data params, rather than trying to duplicate its logic. As a side effect, this also causes a handful of methods that take non-hidden IntPtr arguments to start actually passing those arguments to C rather than always passing IntPtr.Zero. * generator/Method.cs (Equals, GetHashCode): Remove unnecessary and possibly erroneous hashing overrides. * gtk/Gtk.metadata: Hide Gtk.Container.ForeachFull, since it's useless and wasn't in gtk# 1.0 * gtk/Menu.custom (Popup): * gtk/TextIter.custom (ForwardFindChar, BackwardFindChar): * gnome/App.custom (CreateMenusInterp, InsertMenusInterp, CreateToolbarInterp): * gnome/Client.custom (RequestInteractionInterp): * gnome/Popup.custom (MenuDoPopupModal, MenuDoPopup): Add [Obsolete] compat overloads for methods that have now lost a useless IntPtr. svn path=/trunk/gtk-sharp/; revision=47566
2005-07-22 19:10:04 +00:00
my $type = $parent->getAttribute('name') . StudlyCaps($cbn);
$cb_elem = addNameElem($ns_elem, 'callback', $type, $ns);
addReturnElem($cb_elem, $ret);
if ($params && ($params ne "void")) {
addParamsElem($cb_elem, split(/,/, $params));
* parser/gapi2xml.pl (addParamsElem): change the handling of anonymous function pointer types in method signatures. Before, we added a <callback> child to the <parameters> node, but the generator just ignored it. Now we add the callback (with a made-up name) to the toplevel node, and add an ordinary <param> node referencing it to the <parameters> node. Also, if the last param of the callback is a gpointer, rename it from "arg#" to "data" so it will be treated correctly (as the user data passed from the calling method). [Fixes #66241] * art/art-api.raw: * gdk/gdk-api-2.4.raw: * gdk/gdk-api-2.6.raw: Regen * generator/Parameters.cs (IsHidden): loosen the definition of hideable user_data; it doesn't have to occur at the end of the parameter list, as long as there's a callback arg before it. * generator/MethodBody.cs (GetCallString): Use Parameters.IsHidden to decide whether or not to squash user_data params, rather than trying to duplicate its logic. As a side effect, this also causes a handful of methods that take non-hidden IntPtr arguments to start actually passing those arguments to C rather than always passing IntPtr.Zero. * generator/Method.cs (Equals, GetHashCode): Remove unnecessary and possibly erroneous hashing overrides. * gtk/Gtk.metadata: Hide Gtk.Container.ForeachFull, since it's useless and wasn't in gtk# 1.0 * gtk/Menu.custom (Popup): * gtk/TextIter.custom (ForwardFindChar, BackwardFindChar): * gnome/App.custom (CreateMenusInterp, InsertMenusInterp, CreateToolbarInterp): * gnome/Client.custom (RequestInteractionInterp): * gnome/Popup.custom (MenuDoPopupModal, MenuDoPopup): Add [Obsolete] compat overloads for methods that have now lost a useless IntPtr. svn path=/trunk/gtk-sharp/; revision=47566
2005-07-22 19:10:04 +00:00
my $data_parm = $cb_elem->lastChild()->lastChild();
if ($data_parm && $data_parm->getAttribute('type') eq "gpointer") {
$data_parm->setAttribute('name', 'data');
}
}
* parser/gapi2xml.pl (addParamsElem): change the handling of anonymous function pointer types in method signatures. Before, we added a <callback> child to the <parameters> node, but the generator just ignored it. Now we add the callback (with a made-up name) to the toplevel node, and add an ordinary <param> node referencing it to the <parameters> node. Also, if the last param of the callback is a gpointer, rename it from "arg#" to "data" so it will be treated correctly (as the user data passed from the calling method). [Fixes #66241] * art/art-api.raw: * gdk/gdk-api-2.4.raw: * gdk/gdk-api-2.6.raw: Regen * generator/Parameters.cs (IsHidden): loosen the definition of hideable user_data; it doesn't have to occur at the end of the parameter list, as long as there's a callback arg before it. * generator/MethodBody.cs (GetCallString): Use Parameters.IsHidden to decide whether or not to squash user_data params, rather than trying to duplicate its logic. As a side effect, this also causes a handful of methods that take non-hidden IntPtr arguments to start actually passing those arguments to C rather than always passing IntPtr.Zero. * generator/Method.cs (Equals, GetHashCode): Remove unnecessary and possibly erroneous hashing overrides. * gtk/Gtk.metadata: Hide Gtk.Container.ForeachFull, since it's useless and wasn't in gtk# 1.0 * gtk/Menu.custom (Popup): * gtk/TextIter.custom (ForwardFindChar, BackwardFindChar): * gnome/App.custom (CreateMenusInterp, InsertMenusInterp, CreateToolbarInterp): * gnome/Client.custom (RequestInteractionInterp): * gnome/Popup.custom (MenuDoPopupModal, MenuDoPopup): Add [Obsolete] compat overloads for methods that have now lost a useless IntPtr. svn path=/trunk/gtk-sharp/; revision=47566
2005-07-22 19:10:04 +00:00
$parm_elem = $doc->createElement('parameter');
$parm_elem->setAttribute('type', $type);
$parm_elem->setAttribute('name', $cbn);
$parms_elem->appendChild($parm_elem);
next;
} elsif ($parm =~ /\.\.\./) {
$parm_elem = $doc->createElement('parameter');
$parms_elem->appendChild($parm_elem);
$parm_elem->setAttribute('ellipsis', 'true');
next;
}
$parm_elem = $doc->createElement('parameter');
$parms_elem->appendChild($parm_elem);
my $name = "";
if ($parm =~ /struct\s+(\S+)\s+(\S+)/) {
$parm_elem->setAttribute('type', $1);
$name = $2;
}elsif ($parm =~ /(unsigned )?(\S+)\s+(\S+)/) {
$parm_elem->setAttribute('type', $1 . $2);
$name = $3;
} elsif ($parm =~ /(\w+\*)(\w+)/) {
$parm_elem->setAttribute('type', $1);
$name = $2;
} elsif ($parm =~ /(\S+)/) {
$parm_elem->setAttribute('type', $1);
$name = "arg" . $parm_num;
}
if ($name =~ /(\w+)\[.*\]/) {
$name = $1;
$parm_elem->setAttribute('array', "true");
}
if ($out) {
$parm_elem->setAttribute('pass_as', "out");
}
$parm_elem->setAttribute('name', $name);
}
}
sub addReturnElem
{
my ($parent, $ret) = @_;
$ret =~ s/(\w+)\s+const\s*\*/const \1\*/g;
$ret =~ s/const|G_CONST_RETURN/const-/g;
$ret =~ s/\s+//g;
$ret =~ s/(const-)?(\w+)\*(const-)\*/const-\2\*\*/g;
my $ret_elem = $doc->createElement('return-type');
$parent->appendChild($ret_elem);
$ret_elem->setAttribute('type', $ret);
Automatic memory management for opaque types [#49565] * glib/Opaque.cs (Owned): new property saying whether or not gtk# owns the memory. (Opaque): Set Owned to true in the void ctor and false in the IntPtr one. (GetOpaque): add a new overload that can also create opaques, a la GLib.Object.GetObject. (Ref, Unref, Free): empty virtual methods to be overridden by subclasses. (set_Raw): Unref() and possibly Free() the old value, Ref() the new one. (~Opaque, Dispose): set Raw to IntPtr.Zero (triggering Free/Unref if needed) * parser/gapi2xml.pl (addReturnElem): if the method is named Copy and returns a pointer, set the "owned" attribute on the return-type. * */*-api.raw: Regen * generator/HandleBase.cs (FromNative): Add new FromNative/FromNativeReturn overloads that takes a "bool owned" param. Implement the 1-arg FromNative and FromNativeReturn in terms of that. * generator/ObjectBase.cs (FromNative): Implement HandleBase's new overload. Use the two-arg version of GLib.Object.GetObject when "owned" is true. * generator/OpaqueGen.cs (Generate): Pull out Ref, Unref, and Free/Destroy/Dispose methods and handle them specially by overriding Opaque.Ref, .Unref, and .Free appropriately. (If any of the methods are marked deprecated, output a deprecated do-nothing method as well, to save us from having to write all those deprecated methods by hand.) (FromNative): use GetOpaque, passing "owned". * generator/ReturnValue.cs (FromNative): if the value is a HandleBase, pass Owned to its FromNative(). * generator/Parameters.cs (Owned): new property (for use on out params) (FromNative): Call FromNative() on the generatable, handling Owned in the case of HandleBase. * generator/ManagedCallString.cs: * generator/MethodBody.cs: * generator/Signal.cs: use param.FromNative() rather than param.Generatable.FromNative(), to get ownership right. * */*.metadata: Mark opaque ref/unref/free methods deprecated (except where we were hiding them before). Add "owned" attributes to return values and out params as needed. * pango/AttrIterator.custom (GetFont): work around a memory-management oddity of the underlying method. * pango/AttrFontDesc.cs (AttrFontDesc): copy the passed-in FontDescriptor, since the attribute will assume ownership of it. * gtk/TreeView.custom (GetPathAtPos): set the "owned" flag on the returned TreePaths. * gtk/TargetList.custom: Remove refcounting stuff, which is now handled automatically * gtk/NodeStore.cs (GetPath): clear the Owned flag on the created TreePath so that the underlying structure doesn't get freed when the function returns * gtkhtml/HTMLStream.custom (Destroy): hide this and then reimplement it by hand to keep OpaqueGen from using it in Dispose(), since calling it after an HTMLStream.Close() will result in a crash. svn path=/trunk/gtk-sharp/; revision=47928
2005-08-02 18:45:21 +00:00
if ($parent->getAttribute('name') eq "Copy" && $ret =~ /\*$/) {
$ret_elem->setAttribute('owned', 'true');
}
return $ret_elem;
}
sub addPropElem
{
my ($spec, $node, $is_child) = @_;
my ($name, $mode, $docs);
$spec =~ /g_param_spec_(\w+)\s*\((.*)\s*\)\s*\)/;
my $type = $1;
my @params = split(/,/, $2);
$name = $params[0];
if ($defines{$name}) {
$name = $defines{$name};
} else {
$name =~ s/\s*\"//g;
}
$mode = $params[$#params];
if ($type =~ /boolean|float|double|^u?int|pointer|unichar/) {
$type = "g$type";
} elsif ($type =~ /string/) {
$type = "gchar*";
} elsif ($type =~ /boxed|object/) {
$type = $params[$#params-1];
$type =~ s/TYPE_//;
$type =~ s/\s+//g;
$type = StudlyCaps(lc($type));
} elsif ($type =~ /enum|flags/) {
$type = $params[$#params-2];
$type =~ s/TYPE_//;
$type =~ s/\s+//g;
$type = StudlyCaps(lc($type));
}
$prop_elem = $doc->createElement($is_child ? "childprop" : "property");
$node->appendChild($prop_elem);
$prop_elem->setAttribute('name', StudlyCaps($name));
$prop_elem->setAttribute('cname', $name);
$prop_elem->setAttribute('type', $type);
$prop_elem->setAttribute('readable', "true") if ($mode =~ /READ/);
$prop_elem->setAttribute('writeable', "true") if ($mode =~ /WRIT/);
$prop_elem->setAttribute('construct', "true") if ($mode =~ /CONSTRUCT(?!_)/);
$prop_elem->setAttribute('construct-only', "true") if ($mode =~ /CONSTRUCT_ONLY/);
}
sub addPropElem2
{
my ($spec, $node, $is_child) = @_;
my ($name, $mode, $docs);
$spec =~ /g_param_spec_(\w+)\s*\((.*)\s*\);/;
my $type = $1;
my @params = split(/,/, $2);
$name = $params[0];
if ($defines{$name}) {
$name = $defines{$name};
} else {
$name =~ s/\s*\"//g;
}
$mode = $params[$#params];
if ($type =~ /boolean|float|double|^u?int|pointer|unichar/) {
$type = "g$type";
} elsif ($type =~ /string/) {
$type = "gchar*";
} elsif ($type =~ /boxed|object/) {
$type = $params[$#params-1];
$type =~ s/TYPE_//;
$type =~ s/\s+//g;
$type = StudlyCaps(lc($type));
} elsif ($type =~ /enum|flags/) {
$type = $params[$#params-2];
$type =~ s/TYPE_//;
$type =~ s/\s+//g;
$type = StudlyCaps(lc($type));
}
$prop_elem = $doc->createElement($is_child ? "childprop" : "property");
$node->appendChild($prop_elem);
$prop_elem->setAttribute('name', StudlyCaps($name));
$prop_elem->setAttribute('cname', $name);
$prop_elem->setAttribute('type', $type);
$prop_elem->setAttribute('readable', "true") if ($mode =~ /READ/);
$prop_elem->setAttribute('writeable', "true") if ($mode =~ /WRIT/);
$prop_elem->setAttribute('construct', "true") if ($mode =~ /CONSTRUCT(?!_)/);
$prop_elem->setAttribute('construct-only', "true") if ($mode =~ /CONSTRUCT_ONLY/);
}
sub parseTypeToken
{
my ($tok) = @_;
if ($tok =~ /G_TYPE_(\w+)/) {
my $type = $1;
if ($type eq "NONE") {
return "void";
} elsif ($type eq "INT") {
return "gint32";
} elsif ($type eq "UINT") {
return "guint32";
} elsif ($type eq "ENUM" || $type eq "FLAGS") {
return "gint32";
} elsif ($type eq "STRING") {
return "gchar*";
} elsif ($type eq "OBJECT") {
return "GObject*";
} else {
return "g" . lc ($type);
}
} else {
$tok =~ s/_TYPE//;
$tok =~ s/\|.*STATIC_SCOPE//;
$tok =~ s/\W+//g;
return StudlyCaps (lc($tok));
}
}
sub addSignalElem
{
my ($spec, $class, $node) = @_;
$spec =~ s/\n\s*//g; $class =~ s/\n\s*//g;
$sig_elem = $doc->createElement('signal');
$node->appendChild($sig_elem);
if ($spec =~ /\(\"([\w\-]+)\"/) {
$sig_elem->setAttribute('name', StudlyCaps($1));
$sig_elem->setAttribute('cname', $1);
}
$sig_elem->setAttribute('when', $1) if ($spec =~ /_RUN_(\w+)/);
$sig_elem->setAttribute('manual', 'true') if ($spec =~ /G_TYPE_POINTER/);
if ($spec =~ /_OFFSET\s*\(\w+,\s*(\w+)\)/) {
my $method = $1;
$sig_elem->setAttribute('field_name', $method);
if ($class =~ /;\s*(\/\*< (public|protected|private) >\s*\*\/)?(G_CONST_RETURN\s+)?(\w+\s*\**)\s*\(\s*\*\s*$method\s*\)\s*\((.*?)\);/) {
$ret = $4; $parms = $5;
addReturnElem($sig_elem, $ret);
if ($parms && ($parms ne "void")) {
my ($dump, @parm_arr) = split (/,/, $parms);
addParamsElem($sig_elem, @parm_arr);
}
return $method;
} else {
die "ERROR: Failed to parse method $method from class definition:\n$class";
}
} else {
@args = split(/,/, $spec);
my $rettype = parseTypeToken ($args[7]);
addReturnElem($sig_elem, $rettype);
$parmcnt = $args[8];
$parmcnt =~ s/.*(\d+).*/\1/;
$parms_elem = $doc->createElement('parameters');
$sig_elem->appendChild($parms_elem);
for (my $idx = 0; $idx < $parmcnt; $idx++) {
my $argtype = parseTypeToken ($args[9+$idx]);
$parm_elem = $doc->createElement('parameter');
$parms_elem->appendChild($parm_elem);
$parm_elem->setAttribute('name', "p$idx");
$parm_elem->setAttribute('type', $argtype);
}
return "";
}
}
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
sub addImplementsElem
{
my ($spec, $node) = @_;
$spec =~ s/\n\s*//g;
if ($spec =~ /,\s*(\w+)_TYPE_(\w+),/) {
$impl_elem = $doc->createElement('interface');
$name = StudlyCaps (lc ("$1_$2"));
$impl_elem->setAttribute ("cname", "$name");
$node->appendChild($impl_elem);
}
}
sub parseInitFunc
{
my ($obj_el, $initfunc, $classdef) = @_;
my @init_lines = split (/\n/, $initfunc);
my @signal_vms = ();
my $linenum = 0;
my $pspec = "";
my $pspec_use = 0;
while ($linenum < @init_lines) {
my $line = $init_lines[$linenum];
if ($line =~ /#define/) {
# FIXME: This ignores the bool helper macro thingie.
} elsif ($line =~ /g_object_(class|interface)_install_prop/) {
my $prop = $line;
$pspec_use = 1;
while ($prop !~ /\)\s*;/) {
$prop .= $init_lines[++$linenum];
if ($init_lines[$linenum] =~ /g_param_spec_/) {
$pspec_use = 0;
}
}
if ($pspec_use) {
# addPropElem2 ($prop.$pspec, $obj_el, 0);
} else {
addPropElem ($prop, $obj_el, 0);
$propcnt++;
}
} elsif ($line =~ /gtk_container_class_install_child_property/) {
my $prop = $line;
do {
$prop .= $init_lines[++$linenum];
} until ($init_lines[$linenum] =~ /\)\s*;/);
addPropElem ($prop, $obj_el, 1);
$childpropcnt++;
} elsif ($line =~ /\bg.*_signal_new/) {
my $sig = $line;
do {
$sig .= $init_lines[++$linenum];
} until ($init_lines[$linenum] =~ /;/);
$signal_vm = addSignalElem ($sig, $classdef, $obj_el);
push (@signal_vms, $signal_vm) if $signal_vm;
$sigcnt++;
} elsif ($line =~ /g_param_spec_/) {
$pspec = $line;
do {
$pspec .= $init_lines[++$linenum];
} until ($init_lines[$linenum] =~ /\)\s*;/);
addPropElem2 ($pspec, $obj_el, 0);
$propcnt++;
}
$linenum++;
}
return @signal_vms;
}
sub parseTypeFuncMacro
{
my ($obj_el, $typefunc) = @_;
$impls_node = undef;
while ($typefunc =~ /G_IMPLEMENT_INTERFACE\s*\(\s*(\w+)/) {
$iface = $1;
if (not $impls_node) {
$impls_node = $doc->createElement ("implements");
$obj_el->appendChild ($impls_node);
}
addImplementsElem ($prop, $impl_node);
if ($iface =~ /(\w+)_TYPE_(\w+)/) {
$impl_elem = $doc->createElement('interface');
$name = StudlyCaps (lc ("$1_$2"));
$impl_elem->setAttribute ("cname", "$name");
$impls_node->appendChild($impl_elem);
}
$typefunc =~ s/G_IMPLEMENT_INTERFACE\s*\(.*?\)//;
}
}
2002-06-21 Rachel Hestilow <hestilow@ximian.com> * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
sub parseTypeFunc
{
my ($obj_el, $typefunc) = @_;
my @type_lines = split (/\n/, $typefunc);
my $linenum = 0;
$impl_node = undef;
while ($linenum < @type_lines) {
my $line = $type_lines[$linenum];
if ($line =~ /#define/) {
# FIXME: This ignores the bool helper macro thingie.
} elsif ($line =~ /g_type_add_interface_static/) {
my $prop = $line;
do {
$prop .= $type_lines[++$linenum];
} until ($type_lines[$linenum] =~ /;/);
if (not $impl_node) {
$impl_node = $doc->createElement ("implements");
$obj_el->appendChild ($impl_node);
}
addImplementsElem ($prop, $impl_node);
}
$linenum++;
}
}
##############################################################
# Converts a dash or underscore separated name to StudlyCaps.
##############################################################
sub StudlyCaps
{
my ($symb) = @_;
$symb =~ s/^([a-z])/\u\1/;
$symb =~ s/^(\d)/\1_/;
$symb =~ s/[-_]([a-z])/\u\1/g;
$symb =~ s/[-_](\d)/\1/g;
$symb =~ s/^2/Two/;
$symb =~ s/^3/Three/;
return $symb;
}