public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] rewrite make-target-delegates matching code
@ 2014-07-16 14:57 Tom Tromey
  2014-07-17 14:46 ` Pedro Alves
  2014-07-23 16:10 ` Tom Tromey
  0 siblings, 2 replies; 3+ messages in thread
From: Tom Tromey @ 2014-07-16 14:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This patch rewrites the make-target-delegates matching code a little
bit.  The result is functionally the same (the output has some small
whitespace differences), but the new code is more forgiving regarding
the formatting of target.h.  In particular now there's no need to
ensure that the return type and the method name appear on the same
line.

2014-07-16  Tom Tromey  <tromey@redhat.com>

	* make-target-delegates ($ARGS_PART): Match trailing close paren.
	($INTRO_PART): Don't match whitespace.
	($METHOD_TRAILER): Move earlier.  Remove trailing semicolon and
	argument matching.
	($METHOD): Add $METHOD_TRAILER.
	(trim): Rewrite.
	(scan_target_h): New sub.
	Change main loop not to collect state.
	* target-delegates.c: Rebuild.
---
 gdb/ChangeLog             | 12 ++++++
 gdb/make-target-delegates | 98 +++++++++++++++++++++++++++--------------------
 gdb/target-delegates.c    | 28 +++++++-------
 3 files changed, 83 insertions(+), 55 deletions(-)

diff --git a/gdb/make-target-delegates b/gdb/make-target-delegates
index f09f89d..28db447 100755
--- a/gdb/make-target-delegates
+++ b/gdb/make-target-delegates
@@ -31,10 +31,10 @@ $ENDER = qr,^\s*};$,;
 $SYMBOL = qr,[a-zA-Z_][a-zA-Z0-9_]*,;
 # Match the name part of a method in struct target_ops.
 $NAME_PART = qr,\(\*(?<name>${SYMBOL}+)\)\s,;
-# Match the start of arguments to a method.
-$ARGS_PART = qr,(?<args>\(.*)$,;
-# Match indentation.
-$INTRO_PART = qr,^\s*,;
+# Match the arguments to a method.
+$ARGS_PART = qr,(?<args>\(.*\)),;
+# We strip the indentation so here we only need the caret.
+$INTRO_PART = qr,^,;
 
 # Match the return type when it is "ordinary".
 $SIMPLE_RETURN_PART = qr,[^\(]+,;
@@ -44,17 +44,22 @@ $VEC_RETURN_PART = qr,VEC\s*\([^\)]+\)[^\(]*,;
 # Match the TARGET_DEFAULT_* attribute for a method.
 $TARGET_DEFAULT_PART = qr,TARGET_DEFAULT_(?<style>[A-Z_]+)\s*\((?<default_arg>.*)\),;
 
-# Match the introductory line to a method definition.
+# Match the arguments and trailing attribute of a method definition.
+# Note we don't match the trailing ";".
+$METHOD_TRAILER = qr,\s*${TARGET_DEFAULT_PART}$,;
+
+# Match an entire method definition.
 $METHOD = ($INTRO_PART . "(?<return_type>" . $SIMPLE_RETURN_PART
 	   . "|" . $VEC_RETURN_PART . ")"
-	   . $NAME_PART . $ARGS_PART);
-
-# Match the arguments and trailing attribute of a method definition.
-$METHOD_TRAILER = qr,(?<args>\(.+\))\s*${TARGET_DEFAULT_PART};$,;
+	   . $NAME_PART . $ARGS_PART
+	   . $METHOD_TRAILER);
 
 sub trim($) {
     my ($result) = @_;
-    $result =~ s,^\s*(\S*)\s*$,\1,;
+
+    $result =~ s,^\s+,,;
+    $result =~ s,\s+$,,;
+
     return $result;
 }
 
@@ -69,6 +74,30 @@ sub find_trigger() {
     die "could not find trigger line\n";
 }
 
+# Scan target.h and return a list of possible target_ops method entries.
+sub scan_target_h() {
+    my $all_the_text = '';
+
+    find_trigger();
+    while (<>) {
+	chomp;
+	# Skip the open brace.
+	next if /{/;
+	last if m/$ENDER/;
+
+	# Just in case somebody ever uses C99.
+	$_ =~ s,//.*$,,;
+	$_ = trim ($_);
+
+	$all_the_text .= $_;
+    }
+
+    # Now strip out the C comments.
+    $all_the_text =~ s,/\*(.*?)\*/,,g;
+
+    return split (/;/, $all_the_text);
+}
+
 # Parse arguments into a list.
 sub parse_argtypes($) {
     my ($typestr) = @_;
@@ -193,45 +222,32 @@ print "/* vi:set ro: */\n\n";
 print "/* To regenerate this file, run:*/\n";
 print "/*      make-target-delegates target.h > target-delegates.c */\n";
 
-find_trigger();
+@lines = scan_target_h();
+
 
 %tdefault_names = ();
 @delegators = ();
-$current_line = '';
-while (<>) {
-    chomp;
-    last if m/$ENDER/;
-
-    if ($current_line ne '') {
-	s/^\s*//;
-	$current_line .= $_;
-    } elsif (m/$METHOD/) {
-	$name = $+{name};
-	$current_line = $+{args};
-	$return_type = trim ($+{return_type});
-    }
+foreach $current_line (@lines) {
+    next unless $current_line =~ m/$METHOD/;
 
-    if ($current_line =~ /\);\s*$/) {
-	if ($current_line =~ m,$METHOD_TRAILER,) {
-	    $current_args = $+{args};
-	    $tdefault = $+{default_arg};
-	    $style = $+{style};
+    $name = $+{name};
+    $current_line = $+{args};
+    $return_type = trim ($+{return_type});
+    $current_args = $+{args};
+    $tdefault = $+{default_arg};
+    $style = $+{style};
 
-	    @argtypes = parse_argtypes ($current_args);
+    @argtypes = parse_argtypes ($current_args);
 
-	    # The first argument must be "this" to be delegatable.
-	    if ($argtypes[0] =~ /\s*struct\s+target_ops\s*\*\s*/) {
-		write_delegator ($name, $return_type, @argtypes);
+    # The first argument must be "this" to be delegatable.
+    if ($argtypes[0] =~ /\s*struct\s+target_ops\s*\*\s*/) {
+	write_delegator ($name, $return_type, @argtypes);
 
-		push @delegators, $name;
-
-		$tdefault_names{$name} = write_tdefault ($tdefault, $style,
-							 $name, $return_type,
-							 @argtypes);
-	    }
-	}
+	push @delegators, $name;
 
-	$current_line = '';
+	$tdefault_names{$name} = write_tdefault ($tdefault, $style,
+						 $name, $return_type,
+						 @argtypes);
     }
 }
 
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index 98ca14b..8c81672 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -734,21 +734,21 @@ delegate_find_memory_regions (struct target_ops *self, find_memory_region_ftype
   return self->to_find_memory_regions (self, arg1, arg2);
 }
 
-static char * 
+static char *
 delegate_make_corefile_notes (struct target_ops *self, bfd *arg1, int *arg2)
 {
   self = self->beneath;
   return self->to_make_corefile_notes (self, arg1, arg2);
 }
 
-static gdb_byte * 
+static gdb_byte *
 delegate_get_bookmark (struct target_ops *self, const char *arg1, int arg2)
 {
   self = self->beneath;
   return self->to_get_bookmark (self, arg1, arg2);
 }
 
-static gdb_byte * 
+static gdb_byte *
 tdefault_get_bookmark (struct target_ops *self, const char *arg1, int arg2)
 {
   tcomplain ();
@@ -780,15 +780,15 @@ tdefault_get_thread_local_address (struct target_ops *self, ptid_t arg1, CORE_AD
   generic_tls_error ();
 }
 
-static enum target_xfer_status 
-delegate_xfer_partial (struct target_ops *self, enum target_object  arg1, const char *arg2, gdb_byte *arg3, const gdb_byte *arg4, ULONGEST arg5, ULONGEST arg6, ULONGEST *arg7)
+static enum target_xfer_status
+delegate_xfer_partial (struct target_ops *self, enum target_object arg1, const char *arg2, gdb_byte *arg3, const gdb_byte *arg4, ULONGEST arg5, ULONGEST arg6, ULONGEST *arg7)
 {
   self = self->beneath;
   return self->to_xfer_partial (self, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
 }
 
-static enum target_xfer_status 
-tdefault_xfer_partial (struct target_ops *self, enum target_object  arg1, const char *arg2, gdb_byte *arg3, const gdb_byte *arg4, ULONGEST arg5, ULONGEST arg6, ULONGEST *arg7)
+static enum target_xfer_status
+tdefault_xfer_partial (struct target_ops *self, enum target_object arg1, const char *arg2, gdb_byte *arg3, const gdb_byte *arg4, ULONGEST arg5, ULONGEST arg6, ULONGEST *arg7)
 {
   return TARGET_XFER_E_IO;
 }
@@ -879,7 +879,7 @@ tdefault_can_execute_reverse (struct target_ops *self)
   return 0;
 }
 
-static enum exec_direction_kind 
+static enum exec_direction_kind
 delegate_execution_direction (struct target_ops *self)
 {
   self = self->beneath;
@@ -1109,14 +1109,14 @@ tdefault_trace_stop (struct target_ops *self)
 }
 
 static int
-delegate_trace_find (struct target_ops *self, enum trace_find_type  arg1, int arg2, CORE_ADDR arg3, CORE_ADDR arg4, int *arg5)
+delegate_trace_find (struct target_ops *self, enum trace_find_type arg1, int arg2, CORE_ADDR arg3, CORE_ADDR arg4, int *arg5)
 {
   self = self->beneath;
   return self->to_trace_find (self, arg1, arg2, arg3, arg4, arg5);
 }
 
 static int
-tdefault_trace_find (struct target_ops *self, enum trace_find_type  arg1, int arg2, CORE_ADDR arg3, CORE_ADDR arg4, int *arg5)
+tdefault_trace_find (struct target_ops *self, enum trace_find_type arg1, int arg2, CORE_ADDR arg3, CORE_ADDR arg4, int *arg5)
 {
   return -1;
 }
@@ -1410,15 +1410,15 @@ tdefault_teardown_btrace (struct target_ops *self, struct btrace_target_info *ar
   tcomplain ();
 }
 
-static enum btrace_error 
-delegate_read_btrace (struct target_ops *self, VEC (btrace_block_s) **arg1, struct btrace_target_info *arg2, enum btrace_read_type  arg3)
+static enum btrace_error
+delegate_read_btrace (struct target_ops *self, VEC (btrace_block_s) **arg1, struct btrace_target_info *arg2, enum btrace_read_type arg3)
 {
   self = self->beneath;
   return self->to_read_btrace (self, arg1, arg2, arg3);
 }
 
-static enum btrace_error 
-tdefault_read_btrace (struct target_ops *self, VEC (btrace_block_s) **arg1, struct btrace_target_info *arg2, enum btrace_read_type  arg3)
+static enum btrace_error
+tdefault_read_btrace (struct target_ops *self, VEC (btrace_block_s) **arg1, struct btrace_target_info *arg2, enum btrace_read_type arg3)
 {
   tcomplain ();
 }
-- 
1.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rewrite make-target-delegates matching code
  2014-07-16 14:57 [PATCH] rewrite make-target-delegates matching code Tom Tromey
@ 2014-07-17 14:46 ` Pedro Alves
  2014-07-23 16:10 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2014-07-17 14:46 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

Hi Tom,

On 07/16/2014 03:50 PM, Tom Tromey wrote:
> This patch rewrites the make-target-delegates matching code a little
> bit.  The result is functionally the same (the output has some small
> whitespace differences), but the new code is more forgiving regarding
> the formatting of target.h.  In particular now there's no need to
> ensure that the return type and the method name appear on the same
> line.

Looks fine to me.

Thanks,
-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rewrite make-target-delegates matching code
  2014-07-16 14:57 [PATCH] rewrite make-target-delegates matching code Tom Tromey
  2014-07-17 14:46 ` Pedro Alves
@ 2014-07-23 16:10 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2014-07-23 16:10 UTC (permalink / raw)
  To: gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> This patch rewrites the make-target-delegates matching code a little
Tom> bit.  The result is functionally the same (the output has some small
Tom> whitespace differences), but the new code is more forgiving regarding
Tom> the formatting of target.h.  In particular now there's no need to
Tom> ensure that the return type and the method name appear on the same
Tom> line.

I'm checking this in.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-23 15:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-16 14:57 [PATCH] rewrite make-target-delegates matching code Tom Tromey
2014-07-17 14:46 ` Pedro Alves
2014-07-23 16:10 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).