1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
|
#! /usr/bin/perl
#
# tools/generate_wrap_init.pl. Generated from generate_wrap_init.pl.in by configure.
#
use strict;
my @namespace_whole = (); # list of strings.
my $function_prefix = "";
my $parent_dir = ""; # e.g. gtkmm
my $path = "gtk--";
my $debug = 0;
my @filenames_headers = ();
my %objects = ();
my %exceptions = ();
my %namespaces = (); # hashmap of lists of strings.
my %basenames = ();
my %win32_nowrap = ();
# Loop through command line arguments, setting variables:
while ($ARGV[0] =~ /^-/)
{
if ($ARGV[0] =~ /--namespace=(\S+)/)
{
push(@namespace_whole, $1);
if($parent_dir eq "")
{ $parent_dir = lc($1) . "mm"; }
}
elsif ($ARGV[0] =~ /--function_prefix=(\S+)/)
{
$function_prefix = "$1";
}
elsif ($ARGV[0] =~ /--parent_dir=(\S+)/)
{
$parent_dir = "$1";
}
elsif
(
$ARGV[0] =~ /--debug/) {$debug = 1;
}
elsif ($ARGV[0] =~ /--path=(\S+)/)
{
$path = "$1";
}
else
{
print "Error: unknown option $ARGV[0]\n";
exit;
}
shift @ARGV;
}
while ($ARGV[0])
{
if ($debug) {warn "Processing file : $ARGV[0]\n";}
my $filename = $ARGV[0];
open FILE, $filename or die "Couldn't open file $ARGV[0] : $!\n";
# my $file = $ARGV[0];
# $file =~ s/.*\/([^\/]+)$/$1/;
# $file =~ s/\.hg//;
my @tmpnamespace = @namespace_whole;
my $cppname = "";
my $cname = "";
my $ccast = "";
while (<FILE>)
{
if (/CLASS_START\((\w+)\)/) #We need a new way to get the namespace.
{
print "generate_wrap_init: namespace found: $1\n";
push(@tmpnamespace, $1);
}
elsif (/_CLASS_GOBJECT\s*\(/) #TODO: There is duplication of code here.
{
my $line = $_;
while ($line !~ /\)/ && ($_ = <FILE>))
{
$line .= $_;
}
$line =~ s/^.*_CLASS_GOBJECT\s*\(//;
$line =~ s/\s+//g;
($cppname, $cname, $ccast) = split(/,/, $line);
$objects{$cppname} = $cname;
@{$namespaces{$cppname}} = ( @tmpnamespace ); #both are lists of strings
$basenames{$cppname} = lc($ccast);
}
elsif (/_CLASS_GTKOBJECT\s*\(/)
{
my $line = $_;
while ($line !~ /\)/ && ($_ = <FILE>))
{
$line .= $_;
}
$line =~ s/^.*_CLASS_GTKOBJECT\s*\(//;
$line =~ s/\s+//g;
($cppname, $cname, $ccast) = split(/,/, $line);
#TODO: Remove this hack eventually.
if( ($cname ne "GtkTree") && ($cname ne "GtkTreeItem") && ($cname ne "GtkText") )
{
$objects{$cppname} = $cname;
@{$namespaces{$cppname}} = ( @tmpnamespace ); #both are lists of strings
$basenames{$cppname} = lc($ccast);
}
}
elsif (/_WRAP_GERROR\s*\(/) #TODO: There is duplication of code here.
{
my $line = $_;
while ($line !~ /\)/ && ($_ = <FILE>))
{
$line .= $_;
}
$line =~ s/^.*_WRAP_GERROR\s*\(//;
$line =~ s/\s+//g;
$line =~ s/\)//;
($cppname, $cname, $ccast) = split(/,/, $line);
$exceptions{$cppname} = $cname;
@{$namespaces{$cppname}} = ( @tmpnamespace ); #both are lists of strings
$basenames{$cppname} = lc($ccast);
}
elsif (/_GTKMMPROC_WIN32_NO_WRAP/)
{
$win32_nowrap{$cppname} = 1;
}
}
# Store header filename so that we can #include it later:
my $filename_header = $filename;
$filename_header =~ s/.*\/([^\/]+)\.hg/$1.h/;
push(@filenames_headers, $filename_header);
shift @ARGV;
close(FILE);
}
# my $namespace_whole_lower = lc($namespace_whole);
print << "EOF";
#include <glib.h>
// Disable the 'const' function attribute of the get_type() functions.
// GCC would optimize them out because we don't use the return value.
#undef G_GNUC_CONST
#define G_GNUC_CONST /* empty */
#include <${parent_dir}/wrap_init.h>
#include <glibmm/error.h>
#include <glibmm/object.h>
// #include the widget headers so that we can call the get_type() static methods:
EOF
foreach( @filenames_headers )
{
print "#include \"" . $_ . "\"\n";
}
print "\n";
# Here we have to be subtle. The gtkmm objects are easy, they all go
# into the Gtk namespace. But in gnomemm, some go into the Gnome
# namespace (most of them), and some into the Gtk one (because the
# corresponding widget is Gtk-prefixed, e.g. GtkTed, GtkDial, etc...
# First, the Gtk namespace
print "extern \"C\"\n";
print "{\n";
print "\n//Declarations of the *_get_type() functions:\n\n";
my $i = 0;
foreach $i (sort keys %objects)
{
#On Win32, these classes are not compiled:
if( $win32_nowrap{$i} eq 1 )
{
print "#ifndef GTKMM_WIN32\n"
}
print "GType $basenames{$i}_get_type(void);\n";
if( $win32_nowrap{$i} eq 1 )
{
print "#endif //GTKMM_WIN32\n"
}
}
print "\n//Declarations of the *_error_quark() functions:\n\n";
my $i = 0;
foreach $i (sort keys %exceptions)
{
print "GQuark $basenames{$i}_quark(void);\n";
}
print "} // extern \"C\"\n";
print "\n";
print "\n//Declarations of the *_Class::wrap_new() methods, instead of including all the private headers:\n\n";
my $i = 0;
foreach $i (sort keys %objects)
{
#On Win32, these classes are not compiled:
if( $win32_nowrap{$i} eq 1 )
{
print "#ifndef GTKMM_WIN32\n"
}
my $namespace_declarations = "";
my $namespace_close = "";
foreach ( @{$namespaces{$i}} )
{
$namespace_declarations .= "namespace $_ { ";
$namespace_close .= " }";
}
print "${namespace_declarations} class ${i}_Class { public: static Glib::ObjectBase* wrap_new(GObject*); }; ${namespace_close}\n";
if( $win32_nowrap{$i} eq 1 )
{
print "#endif //GTKMM_WIN32\n"
}
}
# print "\n//Declarations of the *Error::throw_func() methods:\n\n";
#
# my $i = 0;
# foreach $i (sort keys %exceptions)
# {
# my $namespace_declarations = "";
# my $namespace_close = "";
# foreach ( @{$namespaces{$i}} )
# {
# $namespace_declarations .= "namespace $_ { ";
# $namespace_close .= " }";
# }
#
# print "${namespace_declarations} class ${i} { public: static void throw_func(GError*); }; ${namespace_close}\n";
# }
my $namespace_whole_declarations = "";
my $namespace_whole_close = "";
foreach( @namespace_whole )
{
$namespace_whole_declarations .= "namespace " . $_ ." { ";
$namespace_whole_close = "} //" . $_ . "\n" . $namespace_whole_close;
}
print "\n";
print "$namespace_whole_declarations\n";
print "\n";
print "void " .$function_prefix . "wrap_init()\n{\n";
# Generate namespace::wrap_init() body
#
print " // Register Error domains:\n";
foreach $i (sort keys %exceptions)
{
my $namespace_prefix = "";
foreach( @{$namespaces{$i}} )
{
$namespace_prefix .= $_ ."::";
}
print " Glib::Error::register_domain($basenames{$i}_quark(), &", "${namespace_prefix}${i}::throw_func);\n";
}
print "\n";
print "// Map gtypes to gtkmm wrapper-creation functions:\n";
foreach $i (sort keys %objects)
{
#On Win32, these classes are not compiled:
if( $win32_nowrap{$i} eq 1 )
{
print "#ifndef GTKMM_WIN32\n"
}
my $namespace_prefix = "";
foreach( @{$namespaces{$i}} )
{
$namespace_prefix .= $_ ."::";
}
print " Glib::wrap_register($basenames{$i}_get_type(), &", "${namespace_prefix}${i}_Class::wrap_new);\n";
if( $win32_nowrap{$i} eq 1 )
{
print "#endif //GTKMM_WIN32\n"
}
}
print "\n";
print " // Register the gtkmm gtypes:\n";
foreach $i (sort keys %objects)
{
#On Win32, these classes are not compiled:
if( $win32_nowrap{$i} eq 1 )
{
print "#ifndef GTKMM_WIN32\n"
}
my $namespace_prefix = "";
foreach( @{$namespaces{$i}} )
{
$namespace_prefix .= $_ ."::";
}
print " ${namespace_prefix}${i}::get_type();\n";
if( $win32_nowrap{$i} eq 1 )
{
print "#endif //GTKMM_WIN32\n"
}
}
print << "EOF";
} // wrap_init()
$namespace_whole_close
EOF
exit 0;
|