[glibmm/gmmproc-refactor] Sections hookup.



commit fc26240330fff26f534c87b8d8ff77ea2a54bd38
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Tue Apr 17 04:03:24 2012 +0200

    Sections hookup.

 tools/pm/Common/SectionManager.pm |  178 +++++++++++++++++++++++++++++++++++--
 tools/pm/Common/WrapParser.pm     |    2 +-
 2 files changed, 170 insertions(+), 10 deletions(-)
---
diff --git a/tools/pm/Common/SectionManager.pm b/tools/pm/Common/SectionManager.pm
index 78d1f35..c705d46 100644
--- a/tools/pm/Common/SectionManager.pm
+++ b/tools/pm/Common/SectionManager.pm
@@ -32,6 +32,161 @@ use constant
   'VARIABLE_UNKNOWN' => 'NO_SUCH_VARIABLE_FOR_NOW',
 };
 
+##
+## begin section prepares
+##
+
+# TODO: get wrapparser?
+
+sub _get_header ()
+{
+  my @code =
+  (
+    '// -*- mode: C++ -*-',
+    '// Generated by gmmproc -- DO NOT MODIFY!',
+    ''
+  );
+
+  return join "\n", @code;
+}
+
+sub _get_header_guard ($$)
+{
+  my ($self, $suffix) = @_;
+  my $base = $self->_get_base;
+  my $mm_module = $self->_get_mm_module;
+
+  $base =~ s/-/_/g;
+  $mm_module =~ s/-/_/g;
+
+  return join '_', '', (uc $mm_module), (uc $base), $suffix, '';
+}
+
+sub _prepare_h_section ($)
+{
+  my ($self) = @_;
+  my $header_guard = $self->_get_header_guard ('H');
+  my $mm_module = $self->_get_mm_module;
+  my @code =
+  (
+    _get_header,
+    (join '', '#ifndef ', $header_guard),
+    (join '', '#define ', $header_guard),
+    ''
+  );
+
+  $self->push_section (Common::Sections::H->[0]);
+  $self->append_string (join "\n", @code);
+  $self->append_section (Common::Sections::H_BEGIN->[0]);
+  if ($mm_module ne 'glibmm')
+  {
+    @code =
+    (
+      '',
+      '#include <glibmm/ustring.h>',
+      '#include <sigc++/sigc++.h>',
+      ''
+    );
+    $self->append_string (join "\n", @code);
+  }
+  $self->append_section (Common::Sections::H_CONTENTS->[0]);
+  @code =
+  (
+    '',
+    (join '', '#endif // ', $header_guard),
+    ''
+  );
+  $self->append_string (join "\n", @code);
+  $self->pop_entry;
+}
+
+sub _prepare_cc_section ($)
+{
+  my ($self) = @_;
+  my @code =
+  (
+    _get_header,
+    ''
+  );
+
+  $self->push_section (Common::Sections::CC->[0]);
+  $self->append_string (join "\n", @code);
+  $self->append_section (Common::Sections::CC_PRE_INCLUDES->[0]);
+  $self->append_string ("\n");
+  $self->append_section (Common::Sections::CC_GENERATED_INCLUDES->[0]);
+  $self->append_string ("\n");
+  $self->append_section (Common::Sections::CC_INCLUDES->[0]);
+  $self->append_string ("\n");
+  $self->append_section (Common::Sections::CC_CONTENTS->[0]);
+  @code =
+  (
+    '',
+    'namespace',
+    '{',
+    ''
+  );
+  $self->append_string (join "\n", @code);
+  $self->append_section (Common::Sections::CC_UNNAMED_NAMESPACE->[0]);
+  @code =
+  (
+    '',
+    '} // unnamed namespace',
+    '',
+    ''
+  );
+  $self->append_string (join "\n", @code);
+  $self->append_section (Common::Sections::CC_GENERATED->[0]);
+  $self->pop_entry;
+}
+
+sub _prepare_p_h_section ($)
+{
+  my ($self) = @_;
+  my $header_guard = $self->_get_header_guard ('P_H');
+  my @code =
+  (
+    _get_header,
+    (join '', '#ifndef ', $header_guard),
+    (join '', '#define ', $header_guard),
+    ''
+  );
+
+  $self->push_section (Common::Sections::P_H->[0]);
+  $self->append_string (join "\n", @code);
+  $self->append_section (Common::Sections::P_H_GENERATED->[0]);
+  @code =
+  (
+    '',
+    (join '', '#endif // ', $header_guard),
+    ''
+  );
+  $self->append_string (join "\n", @code);
+  $self->pop_entry;
+}
+
+sub _prepare_dev_null_section ($)
+{
+  die;
+}
+
+##
+## end section prepares
+##
+
+sub _get_base ($)
+{
+  my ($self) = @_;
+
+  return $self->{'base'};
+}
+
+sub _get_mm_module ($)
+{
+  my ($self) = @_;
+
+  return $self->{'mm_module'};
+}
+
 sub _get_section ($$)
 {
   my ($self, $section_name) = @_;
@@ -177,9 +332,9 @@ sub _get_main_sections ($)
   return $self->{'main_sections'};
 }
 
-sub new ($)
+sub new ($$$)
 {
-  my ($type) = @_;
+  my ($type, $base, $mm_module) = @_;
   my $class = (ref $type or $type or 'Common::SectionManager');
   my $main_h_section = Common::Sections::Section->new_main (Common::Sections::H->[0]);
   my $main_cc_section = Common::Sections::Section->new_main (Common::Sections::CC->[0]);
@@ -190,10 +345,10 @@ sub new ($)
   {
     'main_sections' =>
     {
-      $main_h_section->get_name => $main_h_section,
-      $main_cc_section->get_name => $main_cc_section,
-      $main_p_h_section->get_name => $main_p_h_section,
-      $main_dev_null_section->get_name => $main_dev_null_section
+      $main_h_section->get_name => [$main_h_section, \&_prepare_h_section],
+      $main_cc_section->get_name => [$main_cc_section, \&_prepare_cc_section],
+      $main_p_h_section->get_name => [$main_p_h_section, \&_prepare_p_h_section],
+      $main_dev_null_section->get_name => [$main_dev_null_section, \&_prepare_dev_null_section]
     },
     'all_sections' =>
     {
@@ -204,7 +359,9 @@ sub new ($)
     },
     'conditionals' => {},
     'variables' => {},
-    'entries_stack' => []
+    'entries_stack' => [],
+    'base' => $base,
+    'mm_module' => $mm_module
   };
 
   $self = bless $self, $class;
@@ -304,6 +461,10 @@ sub write_main_section_to_file ($$$)
     exit 1;
   }
 
+  my $section_entry = $main_sections->{$section_name};
+  my $section = $section_entry->[0];
+  my $prepare_section_method = $section_entry->[1];
+  my $entries = $section->get_entries;
   my $fd = IO::File->new ($file_name, 'w');
 
   unless (defined $fd)
@@ -312,8 +473,7 @@ sub write_main_section_to_file ($$$)
     exit 1;
   }
 
-  my $section = $main_sections->{$section_name};
-  my $entries = $section->get_entries;
+  $self->$prepare_section_method;
 
   for (my $iter = 0; $iter < @{$entries}; ++$iter)
   {
diff --git a/tools/pm/Common/WrapParser.pm b/tools/pm/Common/WrapParser.pm
index 632e47a..be5a311 100644
--- a/tools/pm/Common/WrapParser.pm
+++ b/tools/pm/Common/WrapParser.pm
@@ -2575,7 +2575,7 @@ sub new ($$$$$$$)
     'tokens' => [],
     'parsing_stage' => STAGE_INVALID,
     'main_section' => Common::Sections::DEV_NULL->[0],
-    'section_manager' => Common::SectionManager->new,
+    'section_manager' => Common::SectionManager->new ($base, $mm_module),
     'stage_section_tuples' =>
     {
       STAGE_HG() => [Common::Sections::H, 'tokens_hg', 'hg'],



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