Changeset 90409 in webkit


Ignore:
Timestamp:
Jul 5, 2011 3:20:53 PM (13 years ago)
Author:
Adam Roben
Message:

Make prepare-ChangeLog include modified Perl functions in its ChangeLog template

This is a very simple first cut. Functions must start with a line that starts with "sub "
and end with a line that starts with a closing brace. No leading whitespace is allowed.
Package names aren't parsed at all.

Fixes <http://webkit.org/b/21591> prepare-ChangeLog should know how to find functions in
Perl files

Reviewed by David Kilzer.

  • Scripts/prepare-ChangeLog: Removed redundant code that ignored certain files when

searching for function line ranges. This is already done inside the get_function_line_ranges
function.
(get_function_line_ranges): Cleaned up coding style a little bit. Call
get_function_line_ranges_for_perl for files with .pl and .pm extensions. For files with an
unknown extension or no extension, read the shebang line to try to determine the script
interpreter. Call get_function_line_ranges_for_perl if the interpreter seems to be Perl.
(get_function_line_ranges_for_perl): Added. Does extremely basic parsing of the file to find
lines starting with "sub " or "}".

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r90408 r90409  
     12011-07-05  Adam Roben  <aroben@apple.com>
     2
     3        Make prepare-ChangeLog include modified Perl functions in its ChangeLog template
     4
     5        This is a very simple first cut. Functions must start with a line that starts with "sub "
     6        and end with a line that starts with a closing brace. No leading whitespace is allowed.
     7        Package names aren't parsed at all.
     8
     9        Fixes <http://webkit.org/b/21591> prepare-ChangeLog should know how to find functions in
     10        Perl files
     11
     12        Reviewed by David Kilzer.
     13
     14        * Scripts/prepare-ChangeLog: Removed redundant code that ignored certain files when
     15        searching for function line ranges. This is already done inside the get_function_line_ranges
     16        function.
     17        (get_function_line_ranges): Cleaned up coding style a little bit. Call
     18        get_function_line_ranges_for_perl for files with .pl and .pm extensions. For files with an
     19        unknown extension or no extension, read the shebang line to try to determine the script
     20        interpreter. Call get_function_line_ranges_for_perl if the interpreter seems to be Perl.
     21        (get_function_line_ranges_for_perl): Added. Does extremely basic parsing of the file to find
     22        lines starting with "sub " or "}".
     23
    1242011-07-05  Adam Roben  <aroben@apple.com>
    225
  • trunk/Tools/Scripts/prepare-ChangeLog

    r90229 r90409  
    9090sub get_function_line_ranges_for_java($$);
    9191sub get_function_line_ranges_for_javascript($$);
     92sub get_function_line_ranges_for_perl($$);
    9293sub get_selector_line_ranges_for_css($$);
    9394sub method_decl_to_selector($);
     
    208209    print STDERR "  Extracting affected function names from source files.\n";
    209210    foreach my $file (keys %changed_line_ranges) {
    210         # Only look for function names in certain source files.
    211         next unless $file =~ /\.(c|cpp|m|mm|h|java|js)/;
    212    
    213211        # Find all the functions in the file.
    214212        open SOURCE, $file or next;
     
    495493    my ($file_handle, $file_name) = @_;
    496494
    497     if ($file_name =~ /\.(c|cpp|m|mm|h)$/) {
    498         return get_function_line_ranges_for_c ($file_handle, $file_name);
    499     } elsif ($file_name =~ /\.java$/) {
    500         return get_function_line_ranges_for_java ($file_handle, $file_name);
    501     } elsif ($file_name =~ /\.js$/) {
    502         return get_function_line_ranges_for_javascript ($file_handle, $file_name);
    503     } elsif ($file_name =~ /\.css$/) {
    504         return get_selector_line_ranges_for_css ($file_handle, $file_name);
    505     }
     495    # Try to determine the source language based on the file extension.
     496
     497    return get_function_line_ranges_for_c($file_handle, $file_name) if $file_name =~ /\.(c|cpp|m|mm|h)$/;
     498    return get_function_line_ranges_for_java($file_handle, $file_name) if $file_name =~ /\.java$/;
     499    return get_function_line_ranges_for_javascript($file_handle, $file_name) if $file_name =~ /\.js$/;
     500    return get_selector_line_ranges_for_css($file_handle, $file_name) if $file_name =~ /\.css$/;
     501    return get_function_line_ranges_for_perl($file_handle, $file_name) if $file_name =~ /\.p[lm]$/;
     502
     503    # Try to determine the source language based on the script interpreter.
     504
     505    my $first_line = <$file_handle>;
     506    seek($file_handle, 0, 0);
     507
     508    return () unless $first_line =~ /^#!(\S+)/;
     509    my $interpreter = $1;
     510
     511    return get_function_line_ranges_for_perl($file_handle, $file_name) if $interpreter =~ /perl$/;
     512
    506513    return ();
    507514}
     
    11981205    warn "mismatched braces in $fileName\n" if $bracesDepth;
    11991206    warn "mismatched parentheses in $fileName\n" if $parenthesesDepth;
     1207
     1208    return @ranges;
     1209}
     1210
     1211# Read a file and get all the line ranges of the things that look like Perl functions. Functions
     1212# start on a line that starts with "sub ", and end on the first line starting with "}" thereafter.
     1213#
     1214# Result is a list of triples: [ start_line, end_line, function ].
     1215
     1216sub get_function_line_ranges_for_perl($$)
     1217{
     1218    my ($fileHandle, $fileName) = @_;
     1219
     1220    my @ranges;
     1221
     1222    my $currentFunction = "";
     1223    my $start = 0;
     1224
     1225    while (<$fileHandle>) {
     1226        if (/^sub\s+([^(\s]+)/) {
     1227            # Skip over forward declarations, which don't contain a brace and end with a semicolon.
     1228            next if !/{/ && /;$/;
     1229
     1230            if ($currentFunction) {
     1231                warn "nested functions found at top-level at $fileName:$.\n";
     1232                next;
     1233            }
     1234            $currentFunction = $1;
     1235            $start = $.;
     1236        }
     1237        if (index($_, "}") == 0) {
     1238            next unless $start;
     1239            push(@ranges, [$start, $., $currentFunction]);
     1240            $currentFunction = "";
     1241            $start = 0;
     1242            next;
     1243        }
     1244    }
    12001245
    12011246    return @ranges;
Note: See TracChangeset for help on using the changeset viewer.