Changeset 106315 in webkit


Ignore:
Timestamp:
Jan 30, 2012 6:40:24 PM (12 years ago)
Author:
haraken@chromium.org
Message:

REGRESSION(r105797): prepare-ChangeLog for a .cpp file can
output an empty method name (i.e. "()")
https://bugs.webkit.org/show_bug.cgi?id=77336

Reviewed by Darin Adler.

r105797 tried to detect a change outside methods, but it causes a bug that
prepare-ChangeLog can output an empty method name, like this:

  • foo/bar/baz.cpp: (method1): (): (method2):

This is because the cpp parser in prepare-ChangeLog cannot distinguish
'{' as the beginning of a method with '{' as the beginning of an array definition
at the top level.

int a[] = { 1, 2, 3 }; This '{' is the beginning of an array definition.

void func() { This '{' is the beginning of a method.

...;

}

This patch fixes prepare-ChangeLog so that it skips an array definition at the top level.

  • Scripts/prepare-ChangeLog:

(get_function_line_ranges_for_cpp): Modified as described above.
(generateFunctionLists): As a hack, modified so that prepare-ChangeLog does not output
an empty method name. Ideally this should not happen but may happen, since the
parsers are not perfect.

  • Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests.cpp: Added test cases.

(NameSpace7):
(NameSpace8):
(Class109):

  • Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests-expected.txt:
Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r106302 r106315  
     12012-01-30  Kentaro Hara  <haraken@chromium.org>
     2
     3        REGRESSION(r105797): prepare-ChangeLog for a .cpp file can
     4        output an empty method name (i.e. "()")
     5        https://bugs.webkit.org/show_bug.cgi?id=77336
     6
     7        Reviewed by Darin Adler.
     8
     9        r105797 tried to detect a change outside methods, but it causes a bug that
     10        prepare-ChangeLog can output an empty method name, like this:
     11
     12            * foo/bar/baz.cpp:
     13            (method1):
     14            ():
     15            (method2):
     16
     17        This is because the cpp parser in prepare-ChangeLog cannot distinguish
     18        '{' as the beginning of a method with '{' as the beginning of an array definition
     19        at the top level.
     20
     21            int a[] = { 1, 2, 3 };  // This '{' is the beginning of an array definition.
     22
     23            void func() { // This '{' is the beginning of a method.
     24                ...;
     25            }
     26
     27        This patch fixes prepare-ChangeLog so that it skips an array definition at the top level.
     28
     29        * Scripts/prepare-ChangeLog:
     30        (get_function_line_ranges_for_cpp): Modified as described above.
     31        (generateFunctionLists): As a hack, modified so that prepare-ChangeLog does not output
     32        an empty method name. Ideally this should not happen but may happen, since the
     33        parsers are not perfect.
     34        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests.cpp: Added test cases.
     35        (NameSpace7):
     36        (NameSpace8):
     37        (Class109):
     38        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests-expected.txt:
     39
    1402012-01-30  Ojan Vafai  <ojan@chromium.org>
    241
  • trunk/Tools/Scripts/prepare-ChangeLog

    r106183 r106315  
    271271                my @function_range = @$function_range_ref;
    272272
     273                # FIXME: This is a hack. If the function name is empty, skip it.
     274                # The cpp, python, javascript, perl, css and java parsers
     275                # are not perfectly implemented and sometimes function names cannot be retrieved
     276                # correctly. As you can see in get_function_line_ranges_XXXX(), those parsers
     277                # are not intended to implement real parsers but intended to just retrieve function names
     278                # for most practical syntaxes.
     279                next unless $function_range[2];
     280
    273281                # Advance to successive change ranges.
    274282                for (;; @change_range = @{shift @change_ranges}) {
     
    619627    my $in_parentheses = 0;
    620628    my $in_braces = 0;
     629    my $in_toplevel_array_brace = 0;
    621630    my $brace_start = 0;
    622631    my $brace_end = 0;
    623632    my $namespace_start = -1;
    624633    my $skip_til_brace_or_semicolon = 0;
     634    my $equal_observed = 0;
    625635
    626636    my $word = "";
     
    750760
    751761        # Find function, interface and method names.
    752         while (m&((?:[[:word:]]+::)*operator(?:[ \t]*\(\)|[^()]*)|[[:word:]:~]+|[(){}:;])|\@(?:implementation|interface|protocol)\s+(\w+)[^{]*&g) {
     762        while (m&((?:[[:word:]]+::)*operator(?:[ \t]*\(\)|[^()]*)|[[:word:]:~]+|[(){}:;=])|\@(?:implementation|interface|protocol)\s+(\w+)[^{]*&g) {
     763            # Skip an array definition at the top level.
     764            # e.g. static int arr[] = { 1, 2, 3 };
     765            if ($1) {
     766                if ($1 eq "=" and !$in_parentheses and !$in_braces) {
     767                    $equal_observed = 1;
     768                } elsif ($1 eq "{" and $equal_observed) {
     769                    # This '{' is the beginning of an array definition, not the beginning of a method.
     770                    $in_toplevel_array_brace = 1;
     771                    $in_braces++;
     772                    $equal_observed = 0;
     773                    next;
     774                } elsif ($1 !~ /[ \t]/) {
     775                    $equal_observed = 0;
     776                }
     777            }
     778
    753779            # interface name
    754780            if ($2) {
     
    834860                # This could be a function body.
    835861                if (!$in_braces and $name) {
     862                    # This is the end of an array definition at the top level, not the end of a method.
     863                    if ($in_toplevel_array_brace) {
     864                        $in_toplevel_array_brace = 0;
     865                        next;
     866                    }
     867
    836868                    push @ranges, [ $start, $., $name ];
    837869                    if (@namespaces) {
  • trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests-expected.txt

    r106183 r106315  
    327327      '321',
    328328      'Class108'
     329    ],
     330    [
     331      '340',
     332      '354',
     333      'NameSpace7'
     334    ],
     335    [
     336      '356',
     337      '369',
     338      'NameSpace8'
     339    ],
     340    [
     341      '371',
     342      '371',
     343      'NameSpace7'
     344    ],
     345    [
     346      '373',
     347      '386',
     348      'Class109'
     349    ],
     350    [
     351      '388',
     352      '388',
     353      'NameSpace7'
    329354    ]
    330355  ]
  • trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests.cpp

    r106183 r106315  
    321321    int h;
    322322};
     323
     324int a[] = { };
     325int a[] = {
     326};
     327int a[] = { 1, 2, 3 };
     328int a[] = {
     329    1,
     330    2,
     331    3
     332};
     333int a[3] = { 1, 2, 3 };
     334int a[][3] = { {1, 2, 3}, {4, 5, 6} };
     335int a[2][3] = { {1, 2, 3}, {4, 5, 6} };
     336extern int a[];
     337char a[4] = "test";
     338
     339namespace NameSpace7 {
     340int a[] = { };
     341int a[] = {
     342};
     343int a[] = { 1, 2, 3 };
     344int a[] = {
     345    1,
     346    2,
     347    3
     348};
     349int a[3] = { 1, 2, 3 };
     350int a[][3] = { {1, 2, 3}, {4, 5, 6} };
     351int a[2][3] = { {1, 2, 3}, {4, 5, 6} };
     352extern int a[];
     353char a[4] = "test";
     354
     355namespace NameSpace8 {
     356int a[] = { };
     357int a[] = {
     358};
     359int a[] = { 1, 2, 3 };
     360int a[] = {
     361    1,
     362    2,
     363    3
     364};
     365int a[3] = { 1, 2, 3 };
     366int a[][3] = { {1, 2, 3}, {4, 5, 6} };
     367int a[2][3] = { {1, 2, 3}, {4, 5, 6} };
     368extern int a[];
     369char a[4] = "test";
     370};
     371
     372class Class109 {
     373    int a[] = { };
     374    int a[] = {
     375    };
     376    int a[] = { 1, 2, 3 };
     377    int a[] = {
     378        1,
     379        2,
     380        3
     381    };
     382    int a[3] = { 1, 2, 3 };
     383    int a[][3] = { {1, 2, 3}, {4, 5, 6} };
     384    int a[2][3] = { {1, 2, 3}, {4, 5, 6} };
     385    extern int a[];
     386    char a[4] = "test";
     387};
     388
     389};
Note: See TracChangeset for help on using the changeset viewer.