The cpp parser of prepare-ChangeLog treats if(...) {} as a method
authorharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Jan 2012 06:24:22 +0000 (06:24 +0000)
committerharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Jan 2012 06:24:22 +0000 (06:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77241

Reviewed by Ryosuke Niwa.

The cpp parser of prepare-ChangeLog is wrong, and an inner {} block
in a method in some namespace or class is treated as a method.
This patch fixes the bug.

    class C {
        void func()
        {
            if (1) {    // This should not be treated as a method.
            }
        }
    };

* Scripts/prepare-ChangeLog:
(get_function_line_ranges_for_cpp):
* Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests-expected.txt:
* Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests.cpp:
(Class108):
(Class108::func35):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106183 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/prepare-ChangeLog
Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests-expected.txt
Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests.cpp

index d547f8f..8bb61a9 100644 (file)
@@ -1,3 +1,29 @@
+2012-01-27  Kentaro Hara  <haraken@chromium.org>
+
+        The cpp parser of prepare-ChangeLog treats if(...) {} as a method
+        https://bugs.webkit.org/show_bug.cgi?id=77241
+
+        Reviewed by Ryosuke Niwa.
+
+        The cpp parser of prepare-ChangeLog is wrong, and an inner {} block
+        in a method in some namespace or class is treated as a method.
+        This patch fixes the bug.
+
+            class C {
+                void func()
+                {
+                    if (1) {    // This should not be treated as a method.
+                    }
+                }
+            };
+
+        * Scripts/prepare-ChangeLog:
+        (get_function_line_ranges_for_cpp):
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests-expected.txt:
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/cpp_unittests.cpp:
+        (Class108):
+        (Class108::func35):
+
 2012-01-27  Enrica Casucci  <enrica@apple.com>
 
         Followup to http://trac.webkit.org/changeset/106171.
index 6f30b2e..b18ea62 100755 (executable)
@@ -778,25 +778,27 @@ sub get_function_line_ranges_for_cpp($$)
             if ($1 eq "{") {
                 $skip_til_brace_or_semicolon = 0;
 
-                if ($namespace_start >= 0 and $namespace_start < $potential_start) {
-                    push @ranges, [ $namespace_start . "", $potential_start - 1, $name ];
-                }
+                if (!$in_braces) {
+                    if ($namespace_start >= 0 and $namespace_start < $potential_start) {
+                        push @ranges, [ $namespace_start . "", $potential_start - 1, $name ];
+                    }
 
-                if ($potential_namespace) {
-                    push @namespaces, $potential_namespace;
-                    $potential_namespace = "";
-                    $name = $namespaces[-1];
-                    $namespace_start = $. + 1;
-                    next;
-                }
+                    if ($potential_namespace) {
+                        push @namespaces, $potential_namespace;
+                        $potential_namespace = "";
+                        $name = $namespaces[-1];
+                        $namespace_start = $. + 1;
+                        next;
+                    }
 
-                # Promote potential name to real function name at the
-                # start of the outer level set of braces (function body?).
-                if (!$in_braces and $potential_start) {
-                    $start = $potential_start;
-                    $name = $potential_name;
-                    if (@namespaces && $name && (length($name) < 2 || substr($name,1,1) ne "[")) {
-                        $name = join ('::', @namespaces, $name);
+                    # Promote potential name to real function name at the
+                    # start of the outer level set of braces (function body?).
+                    if ($potential_start) {
+                        $start = $potential_start;
+                        $name = $potential_name;
+                        if (@namespaces && $name && (length($name) < 2 || substr($name,1,1) ne "[")) {
+                            $name = join ('::', @namespaces, $name);
+                        }
                     }
                 }
 
index 93a81be..c4eb58d 100644 (file)
       '302',
       '303',
       'NameSpace5'
+    ],
+    [
+      '307',
+      '307',
+      'Class108'
+    ],
+    [
+      '308',
+      '320',
+      'Class108::func35'
+    ],
+    [
+      '321',
+      '321',
+      'Class108'
     ]
   ]
 }
index 6181c18..c29418b 100644 (file)
@@ -302,3 +302,21 @@ int ll;
 int m;
 int n;
 };
+
+class Class108 {
+    int a;
+    void func35()
+    {
+        int b;
+        if (1) {
+            int c;
+            for (;;) {
+                int d;
+                int e;
+            }
+            int f;
+        }
+        int g;
+    }
+    int h;
+};