[glibmm] generate_wrap_init.pl: Add _INCLUDE_IN_WRAP_INIT, _GMMPROC_WRAP_CONDITIONALLY.



commit 3bb2561a8ad1c71f4a4e1255ccbc90f27981d9aa
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Mon Jul 2 18:17:47 2012 +0200

    generate_wrap_init.pl: Add _INCLUDE_IN_WRAP_INIT, _GMMPROC_WRAP_CONDITIONALLY.
    
    * tools/generate_wrap_init.pl.in: Handle _INCLUDE_IN_WRAP_INIT and
    _GMMPROC_WRAP_CONDITIONALLY.
    * tools/m4/class_shared.m4: Add _INCLUDE_IN_WRAP_INIT and
    _GMMPROC_WRAP_CONDITIONALLY. Bug #678883.

 ChangeLog                      |    9 +++++++
 tools/generate_wrap_init.pl.in |   50 ++++++++++++++++++++++++++++++++--------
 tools/m4/class_shared.m4       |   28 ++++++++++++++++++++--
 3 files changed, 74 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 541d5dc..b292c6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-07-02  Kjell Ahlstedt  <kjell ahlstedt bredband net>
+
+	generate_wrap_init.pl: Add _INCLUDE_IN_WRAP_INIT, _GMMPROC_WRAP_CONDITIONALLY.
+
+	* tools/generate_wrap_init.pl.in: Handle _INCLUDE_IN_WRAP_INIT and
+	_GMMPROC_WRAP_CONDITIONALLY.
+	* tools/m4/class_shared.m4: Add _INCLUDE_IN_WRAP_INIT and
+	_GMMPROC_WRAP_CONDITIONALLY. Bug #678883.
+
 2012-07-01  Kjell Ahlstedt  <kjell ahlstedt bredband net>
 
 	Update .gitignore.
diff --git a/tools/generate_wrap_init.pl.in b/tools/generate_wrap_init.pl.in
index fa2eea7..ccaf77d 100644
--- a/tools/generate_wrap_init.pl.in
+++ b/tools/generate_wrap_init.pl.in
@@ -11,8 +11,16 @@ 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 %conditional_compilation = ();
 my %deprecated = ();
+my %extra_includes = ();
+
+# The keys in all hashes except %extra_includes are names of header files (xyz.h),
+# corresponding to the read .hg files.
+#
+# The keys in %extra_includes are names of header files to include without reading.
+# %extra_includes is a hash rather than a list because we don't want duplicates.
+# Its values are not used. In C++ it would have been a std::set.
 
 # $objects{$filename_header} is a reference to an array. That array contains
 # references to arrays with two or more elements, ($cppname, $basename, @extra_namespace),
@@ -29,17 +37,16 @@ sub print_with_guards
     print "#ifndef " . uc($parent_dir) ."_DISABLE_DEPRECATED\n"
   }
 
-  #On Win32, these files are not compiled:
-  if ($win32_nowrap{$file})
+  if ($conditional_compilation{$file})
   {
-    print "#ifndef G_OS_WIN32\n"
+    print "#$conditional_compilation{$file}\n"
   }
 
   print "$message";
 
-  if ($win32_nowrap{$file})
+  if ($conditional_compilation{$file})
   {
-    print "#endif //G_OS_WIN32\n"
+    print "#endif // $conditional_compilation{$file}\n"
   }
 
   if ($deprecated{$file})
@@ -94,7 +101,7 @@ while ($ARGV[0])
   # Store header filename, so we can #include it later:
   my $filename_header = $filename;
   $filename_header =~ s#.*/([^/]+)\.hg#$1.h#;
-  $win32_nowrap{$filename_header} = 0;
+  $conditional_compilation{$filename_header} = "";
   $deprecated{$filename_header} = 0;
 
   # Keep track of sub-namespaces, if any.
@@ -150,9 +157,27 @@ while ($ARGV[0])
         push(@{$exceptions{$filename_header}}, \ names);
       }
     }
+    elsif (/\b_INCLUDE_IN_WRAP_INIT\((.+)\)/)
+    {
+      $extra_includes{$1} = 1;
+    }
     elsif (/\b_GTKMMPROC_WIN32_NO_WRAP\b/)
     {
-      $win32_nowrap{$filename_header} = 1; # This file will not be compiled on Win32
+      # This file will not be compiled on Win32.
+      # No extra include is required. If G_OS_WIN32 is defined, it's defined in
+      # a file included indirectly by glibmm.h.
+      $conditional_compilation{$filename_header} = "ifndef G_OS_WIN32";
+    }
+    elsif (/\b_GMMPROC_WRAP_CONDITIONALLY\((.+)\)/)
+    {
+      # The compilation of this file will be controlled by a preprocessor directive.
+
+      # Allow m4 quotes in the parameter. There may be cases where the m4 processor
+      # would misunderstand a parameter without quotes.
+      my $par = $1;
+      $par =~ s/^\s*`*\s*//; # Remove m4 quotes and leading and trailing white space.
+      $par =~ s/\s*'*\s*$//;
+      $conditional_compilation{$filename_header} = $par;
     }
     elsif (/\b_IS_DEPRECATED\b/)
     {
@@ -180,10 +205,15 @@ print << "EOF";
 #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 my $filename_header (sort keys %extra_includes)
+{
+  print "#include <$filename_header>\n";
+}
+
+print "\n// #include the widget headers so that we can call the get_type() static methods:\n";
+
 # keys %deprecated contains all filenames, not just the names of deprecated files.
 foreach my $filename_header (sort keys %deprecated)
 {
diff --git a/tools/m4/class_shared.m4 b/tools/m4/class_shared.m4
index f91c343..c3c1f57 100644
--- a/tools/m4/class_shared.m4
+++ b/tools/m4/class_shared.m4
@@ -282,11 +282,33 @@ dnl Just process it to remove it from the generated file.
 dnl generate_wrap_init.pl will look for this in the original .hg file.
 dnl
 define(`_GTKMMPROC_WIN32_NO_WRAP', dnl
-`//This is not available in on Win32.
-//This source file will not be compiled,
-//and the class will not be registered in wrap_init.h or wrap_init.cc
+`//This is not available on Win32.
+//This source file will not be compiled on Win32,
+//and no class defined in it will be registered by wrap_init`'().
 ')dnl
 
+dnl _GMMPROC_WRAP_CONDITIONALLY(preprocessor_if/ifdef/ifndef_directive_without_#)
+dnl Just process it to remove it from the generated file.
+dnl generate_wrap_init.pl will look for this in the original .hg file.
+dnl
+dnl Example calls:
+dnl _GMMPROC_WRAP_CONDITIONALLY(ifndef G_OS_WIN32) # Same as _GTKMMPROC_WIN32_NO_WRAP
+dnl _GMMPROC_WRAP_CONDITIONALLY(ifdef GDK_WINDOWING_X11)
+dnl _GMMPROC_WRAP_CONDITIONALLY(`if defined(GDK_WINDOWING_X11) || defined(GDK_WINDOWING_QUARTZ)')
+dnl
+define(`_GMMPROC_WRAP_CONDITIONALLY', dnl
+`//This is available only #$1.
+//Otherwise this source file will not be compiled,
+//and no class defined in it will be registered by wrap_init`'().
+')dnl
+
+dnl _INCLUDE_IN_WRAP_INIT(file)
+dnl Usually used in combination with _GMMPROC_WRAP_CONDITIONALLY.
+dnl It does not generate any code in the .h and .cc files.
+dnl generate_wrap_init.pl will look for this in the original .hg file.
+dnl
+define(`_INCLUDE_IN_WRAP_INIT',`')dnl
+
 dnl _IS_DEPRECATED
 dnl ifdef-out the whole .h and .cc files.
 dnl generate_wrap_init.pl will look for this in the original .hg file.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]