This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH RFC] PARAMS elimination: pointer variables


On May 31,  1:01pm, Kevin Buettner wrote:

> ... with a new script which I'll post as a reply to this message.

The script is below along with a sample invocation of it.  When I run it,
it produces one warning (shown below), but it is nothing to worry about.

--- nuke-params-indent-2 ---
#!/usr/bin/perl -w

# Remove occurrences of PARAMS from pointer variable declarations in
# gdb sources.  (It may work for other code too, but I wrote it
# after examining the gdb sources.)
#
# Pointer variable declarations frequently occur either within
# function bodies or within struct declarations, so it's important to
# preserve the leading indentation whilst at the same time reindenting
# the declaration according to GNU coding standards.  This script attempts
# to do all of this.
#
# To invoke the script, merely provide the name of the directory to
# be searched/fixed as the first and only argument to the script.

use File::Find;
use FileHandle;
use IPC::Open3;
use English;

my ($root) = @ARGV;

if (!defined($root)) {
    die "Usage: $0 root\n";
}

@ARGV = ();

find(
    sub { 
	if ($_ eq 'testsuite') {
	    $File::Find::prune = 1;
	} elsif (-f && -T && /\.[chy]$/) {
	    push @ARGV, $File::Find::name;
	}
    },
    $root
);

#$INPLACE_EDIT = '.bak';
$INPLACE_EDIT = '';
undef $/;			# slurp entire files

while (<>) {
    s{^				# line start
      ([^\n]*\w+\W+		# type name, qualifiers, etc.
      \(\*(?:const\s+)?\w+\)\s+) # left paren, star, optional const,
                                # identifier, right paren, spaces
      PARAMS			# what it says
      \s* 			# optional spaces
      \(\(			# double left parens
      ([^;]*)			# parameter list
      \)\)			# double right parens
      ( [;,] 			# semicolon or comma ...
       |			#   or
	(?:[\s\n]*=[^;]+;)	# an assignment
      )
      (?=\s*$)			# look ahead and make sure there's
      				# nothing but spaces and an eventual
				# newline after the semicolon
    }{
	reindent_preserving_leading_indent("$1 ($2)$3");
    }smgex;
    print;
}

sub reindent_preserving_leading_indent {
    my ($decl) = @_;
    my ($tabs, $spaces) = $decl =~ /^(\t*)( *)/;
    my $leading_indent = 8 * length($tabs) + length($spaces);

    my $ret = reindent($decl, 80 - $leading_indent);

    $ret =~ s/^(\t*)/' ' x (length($1) * 8 + $leading_indent)/meg;
    $ret =~ s#^((:? {8})*)#"\t" x (length($1) / 8)#meg;

    $ret;
}

sub reindent {
    my ($decl, $line_length) = @_;
    $line_length = 80		unless defined $line_length;
    my ($rfh, $wfh, $efh) = (FileHandle->new, FileHandle->new,
					      FileHandle->new);
    my $pid = open3($wfh, $rfh, $efh, "indent -l$line_length");
    $rfh->input_record_separator(undef);
    $efh->input_record_separator(undef);
    $wfh->print($decl);
    $wfh->close();
    my $replacement = <$rfh>;
    $rfh->close();
    my $errstr = <$efh>;
    $efh->close();
    waitpid $pid, 0;
    $replacement =~ s#\n$##;
    if ($errstr ne "") {
	print STDERR "Check $ARGV...\n$errstr\nInput:$decl\nOutput:$replacement\n\n"
    }
    $replacement;
}
--- end nuke-params-indent-2 ---

Here's a sample invocation:

ocotillo:gdb-sourceware$ /home/kev/ptests/nuke-params-indent-2 .
Check ./stabsread.h...
indent: Standard input:1: Warning:Extra )

Input:   int (*f)  (struct objfile *, struct symbol *, char *));
Output:int (*f) (struct objfile *, struct symbol *, char *));



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]