Changeset 189355 in webkit
- Timestamp:
- Sep 4, 2015 10:43:19 AM (9 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r189353 r189355 1 2015-09-04 Jason Marcell <jmarcell@apple.com> 2 3 prepare-ChangeLog needs to know how to parse Swift files. 4 https://bugs.webkit.org/show_bug.cgi?id=148784 5 <rdar://problem/22510062> 6 7 Reviewed by Darin Adler. 8 9 * Scripts/prepare-ChangeLog: 10 (get_function_line_ranges): Added entry for get_function_line_ranges_for_swift. 11 (get_function_line_ranges_for_swift): Added function that knows how to parse Swift code. 12 (parseSwiftFunctionArgs): Added function that knows how to parse Swift function arguments. 13 * Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl: Added. 14 * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests-expected.txt: Ditto. 15 * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/swift_unittests.swift: Ditto. 16 (freeFunction): Ditto. 17 (MyClass.function): Ditto. 18 (MyClass.functionWithArgument(_:)): Ditto. 19 (MyClass.functionWithMoreArguments(_:arg2:)): Ditto. 20 (MyClass.functionWithNamedFirstArgument(argument:)): Ditto. 21 (MyClass.functionWithNamedFirstAndSecondArgument(first:second:)): Ditto. 22 (MyClass.classFunction): Ditto. 23 (MyClass.readWriteComputedVariable): Ditto. 24 (MyClass.readOnlyComputedVariable): Ditto. 25 1 26 2015-09-04 Ryosuke Niwa <rniwa@webkit.org> 2 27 -
trunk/Tools/Scripts/prepare-ChangeLog
r189195 r189355 93 93 sub get_function_line_ranges_for_perl($$); 94 94 sub get_selector_line_ranges_for_css($$); 95 sub get_function_line_ranges_for_swift($$); 96 sub parseSwiftFunctionArgs($); 95 97 sub isAddedStatus($); 96 98 sub isConflictStatus($$$); … … 640 642 return get_function_line_ranges_for_perl($file_handle, $file_name) if $file_name =~ /\.p[lm]$/; 641 643 return get_function_line_ranges_for_python($file_handle, $file_name) if $file_name =~ /\.py$/ or $file_name =~ /master\.cfg$/; 644 return get_function_line_ranges_for_swift($file_handle, $file_name) if $file_name =~ /\.swift$/; 642 645 643 646 # Try to determine the source language based on the script interpreter. … … 1719 1722 1720 1723 return @ranges; 1724 } 1725 1726 # Read a file and get all the line ranges of the things that look like Swift classes, methods, 1727 # or functions. 1728 # 1729 # Result is a list of triples: [ start_line, end_line, function ]. 1730 1731 sub get_function_line_ranges_for_swift($$) 1732 { 1733 my ($fileHandle, $fileName) = @_; 1734 1735 my @ranges; 1736 1737 my $currentFunction = ""; 1738 my $currentClass = ""; 1739 my $functionStart = 0; 1740 my $classStart = 0; 1741 my $functionScopeDepth = 0; 1742 my $classScopeDepth = 0; 1743 my $scopeDepth = 0; 1744 1745 while (<$fileHandle>) { 1746 chomp; 1747 next if (/^\s*\/\/.*/); 1748 if (/func\s+([\w_][\w\d_]*)\((.*)\)/ || /var\s+([\w_][\w\d_]*):\s+/) { 1749 $functionScopeDepth = $scopeDepth; 1750 $currentFunction = $1; 1751 if ($2) { 1752 $currentFunction = "$currentFunction(". parseSwiftFunctionArgs($2) . ")"; 1753 } 1754 if ($currentClass) { 1755 $currentFunction = "$currentClass.$currentFunction"; 1756 } 1757 $functionStart = $.; 1758 } elsif (/class\s+([\w_][\w\d_]*)/) { 1759 $classScopeDepth = $scopeDepth; 1760 $currentClass = $1; 1761 $classStart = $.; 1762 } 1763 if (index($_, "{") > -1) { 1764 $scopeDepth++; 1765 } 1766 if (index($_, "}") > -1) { 1767 $scopeDepth--; 1768 } 1769 if ($scopeDepth == $functionScopeDepth) { 1770 next unless $functionStart; 1771 push(@ranges, [$functionStart, $., $currentFunction]); 1772 $currentFunction = ""; 1773 $functionStart = 0; 1774 } elsif ($scopeDepth == $classScopeDepth) { 1775 next unless $classStart; 1776 $currentClass = ""; 1777 $classStart = 0; 1778 } 1779 } 1780 1781 return @ranges; 1782 } 1783 1784 sub parseSwiftFunctionArgs($) 1785 { 1786 my ($functionArgs) = @_; 1787 my @words = split /, /, $functionArgs; 1788 my $argCount = scalar(@words); 1789 if ($argCount == 0) { 1790 return ""; 1791 } elsif ($argCount > 0) { 1792 # If the first argument is unnamed, give it the name "_" 1793 $words[0] =~ s/^(\w+: .*)/_ $1/; 1794 return join("", map { $_ =~ s/^(\w+).*/$1/; "$_:" } @words); 1795 } else { 1796 warn "Unknown argument count.\n"; 1797 } 1721 1798 } 1722 1799 -
trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl
r105837 r189355 44 44 "css_unittests.css" => "get_selector_line_ranges_for_css", 45 45 "css_unittests_warning.css" => "get_selector_line_ranges_for_css", 46 "swift_unittests.swift" => "get_function_line_ranges_for_swift", 46 47 ); 47 48
Note: See TracChangeset
for help on using the changeset viewer.