/usr/lib/x86_64-linux-gnu/glibmm-2.4/proc/generate_wrap_init.pl is in libglibmm-2.4-dev 2.32.1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | #! /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 $debug = 0;
my %objects = (); # Hashmap of arrays of objects (classes) in each file
my %exceptions = (); # Hashmap of arrays of exception classes in each file
my %win32_nowrap = ();
my %deprecated = ();
# $objects{$filename_header} is a reference to an array. That array contains
# references to arrays with two or more elements, ($cppname, $basename, @extra_namespace),
# one reference per object defined in file $filename_header.
# %exceptions has the same structure as %objects.
sub print_with_guards
{
my $file = $_[0];
my $message = $_[1];
if ($deprecated{$file})
{
# The uc(parent_dir) is a bit of a hack. One day it will get it wrong.
print "#ifndef " . uc($parent_dir) ."_DISABLE_DEPRECATED\n"
}
#On Win32, these files are not compiled:
if ($win32_nowrap{$file})
{
print "#ifndef G_OS_WIN32\n"
}
print "$message";
if ($win32_nowrap{$file})
{
print "#endif //G_OS_WIN32\n"
}
if ($deprecated{$file})
{
print "#endif // *_DISABLE_DEPRECATED\n"
}
}
# Loop through command line flags, 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+)/)
{
# Do nothing. Just for backwards compatibility.
}
else
{
print "Error: unknown option $ARGV[0]\n";
exit;
}
shift @ARGV;
}
# Loop through remaining command line arguments, names of .hg files.
while ($ARGV[0])
{
if ($debug) {warn "Processing file : $ARGV[0]\n";}
my $filename = $ARGV[0];
open FILE, $filename or die "Couldn't open file $filename : $!\n";
# Store header filename, so we can #include it later:
my $filename_header = $filename;
$filename_header =~ s#.*/([^/]+)\.hg#$1.h#;
$win32_nowrap{$filename_header} = 0;
$deprecated{$filename_header} = 0;
# Keep track of sub-namespaces, if any.
# Otherwise we can't tell the difference between Gio::Error and Gio::DBus::Error.
my @extra_namespace = ();
while (<FILE>)
{
# Skip comments.
# This is far from foolproof. It only skips one-line comments, and it does
# not try to skip quoted strings.
s#//.*##;
s#/\*.*?\*/##g;
# This is useful when only some classes use a sub-namespace.
# Alternatively, we could parse the namespace start and end parentheses,
# but this hack is easier.
if (/\b_GMMPROC_EXTRA_NAMESPACE\((\w+)\)/)
{
# debug: print "generate_wrap_init: namespace found: $1\n";
push(@extra_namespace, $1);
}
elsif (/\b(_CLASS_GOBJECT|_CLASS_GTKOBJECT|_WRAP_GERROR)\s*\(/)
{
my $type_of_class = $1;
my $line = $_;
while ($line !~ /\)/ && ($_ = <FILE>))
{
$line .= $_;
}
if (!$_)
{
die "Reached end of file $filename in $type_of_class macro. " .
"(No right parenthesis.)\n";
}
$line =~ s/^.*$type_of_class\s*\(//;
$line =~ s/\s+//g;
$line =~ s/\).*//;
my ($cppname, $cname, $ccast) = split(/,/, $line);
my $basename = lc($ccast);
my @names = ($cppname, $basename, @extra_namespace);
if ($type_of_class eq "_CLASS_GOBJECT" or
($type_of_class eq "_CLASS_GTKOBJECT" and
#TODO: Remove this hack eventually.
($cname ne "GtkTree" && $cname ne "GtkTreeItem" && $cname ne "GtkText")))
{
push(@{$objects{$filename_header}}, \@names);
}
elsif ($type_of_class eq "_WRAP_GERROR")
{
push(@{$exceptions{$filename_header}}, \@names);
}
}
elsif (/\b_GTKMMPROC_WIN32_NO_WRAP\b/)
{
$win32_nowrap{$filename_header} = 1; # This file will not be compiled on Win32
}
elsif (/\b_IS_DEPRECATED\b/)
{
$deprecated{$filename_header} = 1; # This file is deprecated
}
}
shift @ARGV;
close(FILE);
}
# Print the wrap_init.cc file.
print << "EOF";
// Generated by generate_wrap_init.pl -- DO NOT MODIFY!
#include <glibmm.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
# keys %deprecated contains all filenames, not just the names of deprecated files.
foreach my $filename_header (sort keys %deprecated)
{
print_with_guards($filename_header, "#include \"$filename_header\"\n");
}
# Declarations of glib functions.
print "\nextern \"C\"\n";
print "{\n";
print "//Declarations of the *_get_type() functions:\n\n";
foreach my $filename_header (sort keys %objects)
{
my @objects_in_file = @{$objects{$filename_header}};
my $message = "";
foreach my $i (@objects_in_file)
{
# $i is a reference to an array with info on one object, declared in file $filename_header.
my $basename = ${$i}[1];
$message .= "GType ${basename}_get_type(void);\n";
}
print_with_guards($filename_header, $message);
}
print "\n//Declarations of the *_error_quark() functions:\n\n";
foreach my $filename_header (sort keys %exceptions)
{
my @exceptions_in_file = @{$exceptions{$filename_header}};
my $message = "";
foreach my $i (@exceptions_in_file)
{
# $i is a reference to an array with info on one exception, declared in file $filename_header.
my $basename = ${$i}[1];
$message .= "GQuark ${basename}_quark(void);\n";
}
print_with_guards($filename_header, $message);
}
print "} // extern \"C\"\n";
print "\n";
my $namespace_whole_declarations = "";
my $namespace_whole_close = "";
foreach (@namespace_whole)
{
$namespace_whole_declarations .= "namespace $_ {\n";
$namespace_whole_close = "} // $_\n$namespace_whole_close";
}
print "$namespace_whole_declarations";
print "\n//Declarations of the *_Class::wrap_new() methods, instead of including all the private headers:\n\n";
foreach my $filename_header (sort keys %objects)
{
my @objects_in_file = @{$objects{$filename_header}};
my $message = "";
foreach my $i (@objects_in_file)
{
my ($cppname, undef, @extra_namespace) = @{$i};
my $namespace_declarations = "";
my $namespace_close = "";
foreach (@extra_namespace)
{
$namespace_declarations .= "namespace $_ { ";
$namespace_close .= " }";
}
$message .= "${namespace_declarations}class ${cppname}_Class " .
"{ public: static Glib::ObjectBase* wrap_new(GObject*); };$namespace_close\n";
}
print_with_guards($filename_header, $message);
}
# wrap_init() calls throw_func() in each exception class. throw_func() is a
# private method. wrap_init() is declared as a friend of the exception class.
# The friends will find each other easily only if the calling wrap_init()
# function is declared in the same namespace as the exception class.
# If there are extra namespaces, we define extra wrap_init() functions, which
# are called from the wrap_init() function in @namespace_whole.
my %extra_namespaces = ();
foreach my $filename_header (keys %exceptions)
{
my @exceptions_in_file = @{$exceptions{$filename_header}};
foreach my $i (@exceptions_in_file)
{
if (@{$i} > 2)
{
my (undef, undef, @extra_namespace) = @{$i};
$extra_namespaces{join("::", @extra_namespace)} = 1;
}
}
}
# Generate the extra wrap_init() functions in sub-namespaces, if any.
# If you suspect that code with three levels of foreach is inefficient, you are
# probably right, but it's not important here. The exception classes are few in
# most modules (hardly more than about 10), and the sub-namespaces are even
# fewer (usually 0 or 1).
print "\n// Register Error domains in sub-namespaces:\n" if keys %extra_namespaces > 0;
foreach my $sub_namespace (sort keys %extra_namespaces)
{
my @extra_namespace = split("::", $sub_namespace);
my $namespace_declarations = "";
my $namespace_close = "";
foreach (@extra_namespace)
{
$namespace_declarations .= "namespace $_ {\n";
$namespace_close = "} // $_\n$namespace_close";
}
print "\n$namespace_declarations";
print "\nvoid wrap_init()\n{\n";
foreach my $filename_header (sort keys %exceptions)
{
my @exceptions_in_file = @{$exceptions{$filename_header}};
my $message = "";
foreach my $i (@exceptions_in_file)
{
my ($cppname, $basename, @extra_namespace) = @{$i};
if (@extra_namespace > 0 && $sub_namespace eq join("::", @extra_namespace))
{
$message .= " Glib::Error::register_domain(${basename}_quark(), &" .
"${sub_namespace}::${cppname}::throw_func);\n";
}
}
print_with_guards($filename_header, $message) if $message;
}
print "\n} // wrap_init()\n";
print "\n$namespace_close";
}
# Generate namespace::wrap_init() body
print "\nvoid ${function_prefix}wrap_init()\n{\n";
print " // Register Error domains in the main namespace:\n";
foreach my $filename_header (sort keys %exceptions)
{
my @exceptions_in_file = @{$exceptions{$filename_header}};
my $message = "";
foreach my $i (@exceptions_in_file)
{
my ($cppname, $basename, @extra_namespace) = @{$i};
if (@extra_namespace == 0)
{
$message .= " Glib::Error::register_domain(${basename}_quark(), &" .
"${cppname}::throw_func);\n";
}
}
print_with_guards($filename_header, $message) if $message;
}
# Exception classes in sub-namespaces are registered after the ones in the main
# namespace. If you ever change this order, check that it's ok with Glib::ThreadError
# and Glib::Threads::ThreadError. Both these classes wrap GThreadError, and
# Glib::ThreadError is deprecated (2012-02-27).
print "\n // Call the wrap_init() functions in sub-namespaces:\n" if keys %extra_namespaces > 0;
foreach my $sub_namespace (sort keys %extra_namespaces)
{
print " ${sub_namespace}::wrap_init();\n";
}
print "\n";
print " // Map gtypes to gtkmm wrapper-creation functions:\n";
foreach my $filename_header (sort keys %objects)
{
my @objects_in_file = @{$objects{$filename_header}};
my $message = "";
foreach my $i (@objects_in_file)
{
my ($cppname, $basename, @extra_namespace) = @{$i};
my $qualified_cppname = join("::", (@extra_namespace, $cppname));
$message .= " Glib::wrap_register(${basename}_get_type(), &" .
"${qualified_cppname}_Class::wrap_new);\n";
}
print_with_guards($filename_header, $message);
}
print "\n";
print " // Register the gtkmm gtypes:\n";
foreach my $filename_header (sort keys %objects)
{
my @objects_in_file = @{$objects{$filename_header}};
my $message = "";
foreach my $i (@objects_in_file)
{
my ($cppname, $basename, @extra_namespace) = @{$i};
my $qualified_cppname = join("::", (@extra_namespace, $cppname));
$message .= " ${qualified_cppname}::get_type();\n"
}
print_with_guards($filename_header, $message);
}
print << "EOF";
} // wrap_init()
$namespace_whole_close
EOF
exit 0;
|