[glibmm/gmmproc-refactor] Implement _PINCLUDE.



commit e1056a0eecaaa32aa4f8a9b5e70eec5353b9eae3
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Wed Apr 18 05:25:15 2012 +0200

    Implement _PINCLUDE.

 tools/pm/Common/Output.pm         |    1 +
 tools/pm/Common/Output/Misc.pm    |   45 +++++++++++++++++++++++++++++++++++++
 tools/pm/Common/Output/Shared.pm  |   25 ++++++++++++++++++++
 tools/pm/Common/SectionManager.pm |    2 +
 tools/pm/Common/Sections.pm       |    5 +++-
 tools/pm/Common/WrapParser.pm     |    9 +++++++
 6 files changed, 86 insertions(+), 1 deletions(-)
---
diff --git a/tools/pm/Common/Output.pm b/tools/pm/Common/Output.pm
index cef7526..1678b95 100644
--- a/tools/pm/Common/Output.pm
+++ b/tools/pm/Common/Output.pm
@@ -33,6 +33,7 @@ use Common::Output::GObject;
 use Common::Output::GtkObject;
 use Common::Output::Interface;
 use Common::Output::Method;
+use Common::Output::Misc;
 use Common::Output::OpaqueCopyable;
 use Common::Output::OpaqueRefcounted;
 use Common::Output::Property;
diff --git a/tools/pm/Common/Output/Misc.pm b/tools/pm/Common/Output/Misc.pm
new file mode 100644
index 0000000..bb8f41c
--- /dev/null
+++ b/tools/pm/Common/Output/Misc.pm
@@ -0,0 +1,45 @@
+# -*- mode: perl; perl-indent-level: 2; indent-tabs-mode: nil -*-
+# gmmproc - Common::Output::Misc module
+#
+# Copyright 2012 glibmm development team
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# 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.
+#
+
+package Common::Output::Misc;
+
+use strict;
+use warnings;
+
+sub nl
+{
+  return Common::Output::Shared::nl @_;
+}
+
+sub p_include ($$)
+{
+  my ($wrap_parser, $include) = @_;
+
+  unless (Common::Output::Shared::already_included $wrap_parser, $include)
+  {
+    my $section_manager = $wrap_parser->get_section_manager;
+    my $section = Common::Output::Shared::get_section $wrap_parser, Common::Sections::P_H_INCLUDES;
+    my $code_string = (nl '#include <', $include, '>');
+
+    $section_manager->append_string_to_section ($code_string, $section);
+  }
+}
+
+1; # indicate proper module load.
diff --git a/tools/pm/Common/Output/Shared.pm b/tools/pm/Common/Output/Shared.pm
index 9a8e89f..4c77d9e 100644
--- a/tools/pm/Common/Output/Shared.pm
+++ b/tools/pm/Common/Output/Shared.pm
@@ -622,4 +622,29 @@ sub deprecate_end ($)
 
 }
 
+sub generate_include_variable ($)
+{
+  my ($include) = @_;
+  my $variable = $include;
+  $variable =~ s#[/.-]#_#g;
+
+  return join '_', 'FLAG', (uc $variable), 'BOOL_VARIABLE';
+}
+
+sub already_included ($$)
+{
+  my ($wrap_parser, $include) = @_;
+  my $conditional = generate_conditional $wrap_parser;
+  my $variable = generate_include_variable $include;
+  my $section_manager = $wrap_parser->get_section_manager;
+  my $value = $section_manager->get_variable ($variable);
+
+  unless ($value)
+  {
+    $section_manager->set_variable ($variable, 1);
+    return 0;
+  }
+  return 1;
+}
+
 1; # indicate proper module load.
diff --git a/tools/pm/Common/SectionManager.pm b/tools/pm/Common/SectionManager.pm
index c705d46..82271e5 100644
--- a/tools/pm/Common/SectionManager.pm
+++ b/tools/pm/Common/SectionManager.pm
@@ -153,6 +153,8 @@ sub _prepare_p_h_section ($)
 
   $self->push_section (Common::Sections::P_H->[0]);
   $self->append_string (join "\n", @code);
+  $self->append_section (Common::Sections::P_H_INCLUDES->[0]);
+  $self->append_string ("\n");
   $self->append_section (Common::Sections::P_H_GENERATED->[0]);
   @code =
   (
diff --git a/tools/pm/Common/Sections.pm b/tools/pm/Common/Sections.pm
index 01350fe..15ce226 100644
--- a/tools/pm/Common/Sections.pm
+++ b/tools/pm/Common/Sections.pm
@@ -29,6 +29,8 @@ use Common::Sections::Section;
 use Common::Sections::Conditional;
 use Common::Sections::Entries;
 
+# TODO: sort those sections in some sensible manner.
+
 use constant
 {
   'H' => ['SECTION_H', Common::Constants::FILE ()], # main header section
@@ -67,7 +69,8 @@ use constant
   'CC_SIGNAL_PROXIES' => ['SECTION_CC_SIGNAL_PROXIES', Common::Constants::CLASS ()],
   'H_PROPERTY_PROXIES' => ['SECTION_H_PROPERTY_PROXIES', Common::Constants::CLASS ()],
   'CC_PROPERTY_PROXIES' => ['SECTION_CC_PROPERTY_PROXIES', Common::Constants::CLASS ()],
-  'CC_INITIALIZE_EXTRA' => ['SECTION_CC_INITIALIZE_EXTRA', Common::Constants::CLASS ()] # TODO: check if needed.
+  'CC_INITIALIZE_EXTRA' => ['SECTION_CC_INITIALIZE_EXTRA', Common::Constants::CLASS ()], # TODO: check if needed.
+  'P_H_INCLUDES' => ['SECTION_P_H_INCLUDES', Common::Constants::FILE ()]
 };
 
 1; # indicate proper module load.
diff --git a/tools/pm/Common/WrapParser.pm b/tools/pm/Common/WrapParser.pm
index be5a311..fccb692 100644
--- a/tools/pm/Common/WrapParser.pm
+++ b/tools/pm/Common/WrapParser.pm
@@ -2487,6 +2487,14 @@ sub _on_module ($)
   $self->{'module'} = $str;
 }
 
+sub _on_pinclude ($)
+{
+  my ($self) = @_;
+  my $str = Common::Util::string_trim $self->_extract_bracketed_text;
+
+  Common::Output::Misc::p_include $self, $str;
+}
+
 ###
 ### HANDLERS ABOVE
 ###
@@ -2634,6 +2642,7 @@ sub new ($$$$$$$)
     '_INSERT_SECTION' => [$self, \&_on_insert_section],
     'class' => [$self, \&_on_class_keyword],
     '_MODULE' => [$self, \&_on_module],
+    '_PINCLUDE' => [$self, \&_on_pinclude]
   };
 
   return $self;



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