Title: [273651] trunk/Tools
Revision
273651
Author
commit-qu...@webkit.org
Date
2021-03-01 08:38:39 -0800 (Mon, 01 Mar 2021)

Log Message

Teach prepare-ChangeLog to recognize Swift structs/enums/protocols/extensions
https://bugs.webkit.org/show_bug.cgi?id=222551

It formerly only knew how to recognize classes.

Patch by Adam Roben <aro...@apple.com> on 2021-03-01
Reviewed by Jonathan Bedard.

* Scripts/prepare-ChangeLog:
(get_function_line_ranges_for_swift): Replaced "class" with "type" in
variable names to make them more general. Generalized the pattern used
to find class declarations to find struct/enum/protocol/extension
declarations as well.

* Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests-expected.txt:
Added new ranges to the results.

* Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests.swift:
(MyStruct.structFunction(argument:)):
(MyEnum.enumFunction(argument:)):
(MyProtocol.protocolFunction(argument:)):
(ExtendedType.extensionFunction(argument:)):
Added these new types/functions (and look, they got parsed!).

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (273650 => 273651)


--- trunk/Tools/ChangeLog	2021-03-01 15:34:03 UTC (rev 273650)
+++ trunk/Tools/ChangeLog	2021-03-01 16:38:39 UTC (rev 273651)
@@ -1,3 +1,28 @@
+2021-03-01  Adam Roben  <aro...@apple.com>
+
+        Teach prepare-ChangeLog to recognize Swift structs/enums/protocols/extensions
+        https://bugs.webkit.org/show_bug.cgi?id=222551
+
+        It formerly only knew how to recognize classes.
+
+        Reviewed by Jonathan Bedard.
+
+        * Scripts/prepare-ChangeLog:
+        (get_function_line_ranges_for_swift): Replaced "class" with "type" in
+        variable names to make them more general. Generalized the pattern used
+        to find class declarations to find struct/enum/protocol/extension
+        declarations as well.
+
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests-expected.txt:
+        Added new ranges to the results.
+
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests.swift:
+        (MyStruct.structFunction(argument:)):
+        (MyEnum.enumFunction(argument:)):
+        (MyProtocol.protocolFunction(argument:)):
+        (ExtendedType.extensionFunction(argument:)):
+        Added these new types/functions (and look, they got parsed!).
+
 2021-02-27  Megan Gardner  <megan_gard...@apple.com>
 
         API test for AppHighlights

Modified: trunk/Tools/Scripts/prepare-ChangeLog (273650 => 273651)


--- trunk/Tools/Scripts/prepare-ChangeLog	2021-03-01 15:34:03 UTC (rev 273650)
+++ trunk/Tools/Scripts/prepare-ChangeLog	2021-03-01 16:38:39 UTC (rev 273651)
@@ -3,7 +3,7 @@
 
 #
 #  Copyright (C) 2000, 2001 Eazel, Inc.
-#  Copyright (C) 2002-2020 Apple Inc.  All rights reserved.
+#  Copyright (C) 2002-2021 Apple Inc.  All rights reserved.
 #  Copyright (C) 2009 Torch Mobile, Inc.
 #  Copyright (C) 2009 Cameron McCormack <c...@mcc.id.au>
 #
@@ -1957,11 +1957,11 @@
     my @ranges;
 
     my $currentFunction = "";
-    my $currentClass = "";
+    my $currentType = "";
     my $functionStart = 0;
-    my $classStart = 0;
+    my $typeStart = 0;
     my $functionScopeDepth = 0;
-    my $classScopeDepth = 0;
+    my $typeScopeDepth = 0;
     my $scopeDepth = 0;
 
     while (<$fileHandle>) {
@@ -1973,14 +1973,14 @@
             if ($2) {
                 $currentFunction = "$currentFunction(". parseSwiftFunctionArgs($2) . ")";
             }
-            if ($currentClass) {
-                $currentFunction = "$currentClass.$currentFunction";
+            if ($currentType) {
+                $currentFunction = "$currentType.$currentFunction";
             }
             $functionStart = $.;
-        } elsif (/class\s+([\w_][\w\d_]*)/) {
-            $classScopeDepth = $scopeDepth;
-            $currentClass = $1;
-            $classStart = $.;
+        } elsif (/(?:class|struct|enum|protocol|extension)\s+([\w_][\w\d_]*)/) {
+            $typeScopeDepth = $scopeDepth;
+            $currentType = $1;
+            $typeStart = $.;
         }
         if (index($_, "{") > -1) {
             $scopeDepth++;
@@ -1993,10 +1993,10 @@
             push(@ranges, [$functionStart, $., $currentFunction]);
             $currentFunction = "";
             $functionStart = 0;
-        } elsif ($scopeDepth == $classScopeDepth) {
-            next unless $classStart;
-            $currentClass = "";
-            $classStart = 0;
+        } elsif ($scopeDepth == $typeScopeDepth) {
+            next unless $typeStart;
+            $currentType = "";
+            $typeStart = 0;
         }
     }
 

Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests-expected.txt (273650 => 273651)


--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests-expected.txt	2021-03-01 15:34:03 UTC (rev 273650)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests-expected.txt	2021-03-01 16:38:39 UTC (rev 273651)
@@ -47,5 +47,25 @@
       '79',
       'MyClass.readOnlyComputedVariable'
     ],
+    [
+      '85',
+      '86',
+      'MyStruct.structFunction(argument:)'
+    ],
+    [
+      '93',
+      '94',
+      'MyEnum.enumFunction(argument:)'
+    ],
+    [
+      '99',
+      '100',
+      'MyProtocol.protocolFunction(argument:)'
+    ],
+    [
+      '105',
+      '106',
+      'ExtendedType.extensionFunction(argument:)'
+    ],
   ]
 }

Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests.swift (273650 => 273651)


--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests.swift	2021-03-01 15:34:03 UTC (rev 273650)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests.swift	2021-03-01 16:38:39 UTC (rev 273651)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc.  All rights reserved.
+ * Copyright (C) 2015-2021 Apple Inc.  All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -80,7 +80,33 @@
 
 }
 
+struct MyStruct {
+    // `MyStruct.structFunction(argument:)`
+    func structFunction(argument arg: Arg) {
+    }
+}
+
+enum MyEnum {
+    case a, b, c
+
+    // `MyEnum.enumFunction(argument:)`
+    func enumFunction(argument arg: Arg) {
+    }
+}
+
+protocol MyProtocol {
+    // `MyProtocol.protocolFunction(argument:)`
+    func protocolFunction(argument arg: Arg) {
+    }
+}
+
+extension ExtendedType {
+    // `ExtendedType.extensionFunction(argument:)`
+    func extensionFunction(argument arg: Arg) {
+    }
+}
+
 // Swift functions also support type overloading. Traditionally we don't include types in
 // the ChangeLogs for Objective-C, but I assume this can come up in C++ code so I'd suggest
 // doing whatever we do there. That said, overloading is only supported in pure Swift,
-// which I don't anticipate needing to worry about for a while longer.
\ No newline at end of file
+// which I don't anticipate needing to worry about for a while longer.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to