[glibmm/gmmproc-refactor] Parse template keyword.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/gmmproc-refactor] Parse template keyword.
- Date: Sun, 22 Jul 2012 18:16:05 +0000 (UTC)
commit 7ca6f2339d1f1ec92ab0e62b147a5882223e76e9
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Sun Jul 22 16:13:39 2012 +0200
Parse template keyword.
Copy everything between angle brackets into output. Especially, we
don't want to parse class keyword that may happen there.
tools/pm/Common/Gmmproc.pm | 6 ++--
tools/pm/Common/Scanner.pm | 59 ++++++++++++++++++++++++++++++-
tools/pm/Common/WrapParser.pm | 79 ++++++++++++++++++++++++++++++++++++++++-
3 files changed, 139 insertions(+), 5 deletions(-)
---
diff --git a/tools/pm/Common/Gmmproc.pm b/tools/pm/Common/Gmmproc.pm
index b6ed96b..c974f6c 100644
--- a/tools/pm/Common/Gmmproc.pm
+++ b/tools/pm/Common/Gmmproc.pm
@@ -49,10 +49,10 @@ sub _tokenize_contents_
# - //!
# - //
# - any char proceeded by \
- # - symbols ;{}"`'():
+ # - symbols ;{}"`'()<>:
# - newline
- my @tokens = Common::Shared::cleanup_tokens (split(/([#A-Za-z0-9_]+)|(\/\*[*!]?)|(\*\/)|(\/\/[\/!]?)|(\\.)|([:;{}"'`()])|(\n)/,
- $contents));
+ my @tokens = Common::Shared::cleanup_tokens (split(/([#A-Za-z0-9_]+)|(\/\*[*!]?)|(\*\/)|(\/\/[\/!]?)|(\\.)|([:;{}"'`()<>])|(\n)/,
+ $contents));
return \ tokens;
}
diff --git a/tools/pm/Common/Scanner.pm b/tools/pm/Common/Scanner.pm
index aa941dd..61f204f 100644
--- a/tools/pm/Common/Scanner.pm
+++ b/tools/pm/Common/Scanner.pm
@@ -582,6 +582,62 @@ sub _on_class_keyword ($)
}
}
+sub _on_template_keyword
+{
+ my ($self) = @_;
+ my $tokens = $self->_get_tokens ();
+ my $in_s_comment = 0;
+ my $in_m_comment = 0;
+ my $template_level = 0;
+
+ # extract all tokens with template angles (<...>), so we won't parse
+ # class keyword in template context as in 'template<class T>'.
+ while (@{$tokens})
+ {
+ my $token = $self->_extract_token ();
+
+ if ($in_s_comment)
+ {
+ if ($token eq "\n")
+ {
+ $in_s_comment = 0;
+ }
+ }
+ elsif ($in_m_comment)
+ {
+ if ($token eq '*/')
+ {
+ $in_m_comment = 0;
+ }
+ }
+ elsif ($token eq '//' or $token eq '///' or $token eq '//!')
+ {
+ $in_s_comment = 1;
+ }
+ elsif ($token eq '/*' or $token eq '/**' or $token eq '/*!')
+ {
+ $in_m_comment = 1;
+ }
+ elsif ($token eq '<')
+ {
+ ++$template_level;;
+ }
+ elsif ($token eq '>')
+ {
+ unless ($template_level)
+ {
+ $self->fixed_error ('Expected \'<\' after template keyword, not \'>\'.');
+ }
+ --$template_level;
+ unless ($template_level)
+ {
+ return;
+ }
+ }
+ }
+ return;
+}
+
sub new ($$$)
{
my ($type, $tokens_hg, $tokens_ccg) = @_;
@@ -635,7 +691,8 @@ sub new ($$$)
'_CLASS_OPAQUE_REFCOUNTED' => sub { $self->_on_class_opaque_refcounted (@_); },
'_MODULE' => sub { $self->_on_module (@_); },
'namespace' => sub { $self->_on_namespace_keyword (@_); },
- 'class' => sub { $self->_on_class_keyword (@_); }
+ 'class' => sub { $self->_on_class_keyword (@_); },
+ 'template' => sub { $self->_on_template_keyword (@_); }
};
return $self;
diff --git a/tools/pm/Common/WrapParser.pm b/tools/pm/Common/WrapParser.pm
index 6d8ea22..6fc1b55 100644
--- a/tools/pm/Common/WrapParser.pm
+++ b/tools/pm/Common/WrapParser.pm
@@ -3163,6 +3163,82 @@ sub _on_pop_section
$self->_pop_main_section ();
}
+sub _on_template_keyword
+{
+ my ($self) = @_;
+ my $tokens = $self->get_tokens ();
+ my $section_manager = $self->get_section_manager ();
+ my $main_section = $self->get_main_section ();
+ my $done = 0;
+ my $in_s_comment = 0;
+ my $in_m_comment = 0;
+ my $template_level = 0;
+ my @template_tokens = ('template');
+
+ # extract all tokens with template angles (<...>), so we won't parse
+ # class keyword in template context as in 'template<class T>'.
+ while (@{$tokens})
+ {
+ my $token = $self->_extract_token ();
+
+ if ($in_s_comment)
+ {
+ if ($token eq "\n")
+ {
+ $in_s_comment = 0;
+ }
+ }
+ elsif ($in_m_comment)
+ {
+ if ($token eq '*/')
+ {
+ $in_m_comment = 0;
+ }
+ }
+ elsif ($token eq '//' or $token eq '///' or $token eq '//!')
+ {
+ $in_s_comment = 1;
+ }
+ elsif ($token eq '/*' or $token eq '/**' or $token eq '/*!')
+ {
+ $in_m_comment = 1;
+ }
+ elsif ($token eq '<')
+ {
+ ++$template_level;;
+ }
+ elsif ($token eq '>')
+ {
+ unless ($template_level)
+ {
+ $self->fixed_error ('Expected \'<\' after template keyword, not \'>\'.');
+ }
+ --$template_level;
+ unless ($template_level)
+ {
+ $done = 1;
+ }
+ }
+ elsif ($token !~ /^\s+$/)
+ {
+ unless ($template_level)
+ {
+ $self->fixed_error ('Expected \'<\' after template keyword, not \'' . $token . '\'.');
+ }
+ }
+
+ push (@template_tokens, $token);
+
+ if ($done)
+ {
+ $section_manager->append_string_to_section (join ('', @template_tokens),
+ $main_section);
+ return;
+ }
+ }
+ $self->fixed_error ('Hit eof while processing `template\'.');
+}
+
###
### HANDLERS ABOVE
###
@@ -3342,7 +3418,8 @@ sub new ($$$$$$)
'_GMMPROC_WRAP_CONDITIONALLY' => sub { $self->_on_gmmproc_wrap_conditionally (@_); },
'_INCLUDE_IN_WRAP_INIT' => sub { $self->_on_include_in_wrap_init (@_); },
'_PUSH_SECTION' => sub { $self->_on_push_section (@_); },
- '_POP_SECTION' => sub { $self->_on_pop_section (@_); }
+ '_POP_SECTION' => sub { $self->_on_pop_section (@_); },
+ 'template' => sub { $self->_on_template_keyword (@_); }
};
return $self;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]