do-webcore-rename 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #!/usr/bin/perl -w
  2. # Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  14. # its contributors may be used to endorse or promote products derived
  15. # from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  18. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  21. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. # Script to do a rename in JavaScriptCore, WebCore, and WebKit.
  28. use strict;
  29. use File::Find;
  30. use FindBin;
  31. use Getopt::Long qw(:config pass_through);
  32. use lib $FindBin::Bin;
  33. use webkitdirs;
  34. use VCSUtils;
  35. setConfiguration();
  36. chdirWebKit();
  37. my $showHelp;
  38. my $verbose;
  39. my $programName = basename($0);
  40. my $usage = <<EOF;
  41. Usage: $programName [options]
  42. -h|--help Show this help message
  43. -v|--verbose More verbose output
  44. EOF
  45. my $getOptionsResult = GetOptions(
  46. 'help|h' => \$showHelp,
  47. 'verbose|v' => \$verbose,
  48. );
  49. if (!$getOptionsResult || $showHelp) {
  50. print STDERR $usage;
  51. exit 1;
  52. }
  53. my @directoriesToIgnoreList = (
  54. "icu",
  55. );
  56. my %directoriesToIgnore = map { $_ => 1 } @directoriesToIgnoreList;
  57. # find all files we want to process
  58. my @paths;
  59. find(\&wanted, "Source/JavaScriptCore");
  60. find(\&wanted, "Source/WebCore");
  61. find(\&wanted, "Source/WebKit");
  62. find(\&wanted, "Source/WebKit2");
  63. find(\&wanted, "Tools/DumpRenderTree");
  64. sub wanted
  65. {
  66. my $file = $_;
  67. # Ignore excluded and hidden files/directories.
  68. if ($directoriesToIgnore{$file} or $file =~ /^\../ or $file =~ /^ChangeLog/) {
  69. print "Ignoring $File::Find::name\n" if $verbose;
  70. $File::Find::prune = 1;
  71. return;
  72. }
  73. return if -d $file;
  74. push @paths, $File::Find::name;
  75. }
  76. # Setting isDOMTypeRename to 1 rather than 0 expands the regexps used
  77. # below to handle custom JavaScript bindings.
  78. my $isDOMTypeRename = 1;
  79. my %renames = (
  80. # Renames go here in the form of:
  81. "JavaScriptAudioNode" => "ScriptProcessorNode",
  82. "RealtimeAnalyserNode" => "AnalyserNode",
  83. "AudioGainNode" => "GainNode",
  84. "AudioPannerNode" => "PannerNode",
  85. "AudioChannelSplitter" => "ChannelSplitterNode",
  86. "AudioChannelMerger" => "ChannelMergerNode",
  87. "Oscillator" => "OscillatorNode",
  88. );
  89. my %renamesContemplatedForTheFuture = (
  90. "HTMLPlugInImageElement" => "HTMLEmbeddedObjectElement",
  91. "DOMObject" => "JSDOMObject",
  92. "runtimeObjectGetter" => "pluginElementGetter",
  93. "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
  94. "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
  95. "runtimeObjectCustomPut" => "pluginElementCustomPut",
  96. "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
  97. "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
  98. "CLONE_CONTENTS" => "Clone",
  99. "DELETE_CONTENTS" => "Delete",
  100. "EXTRACT_CONTENTS" => "Extract",
  101. "DateInstance" => "JSDate",
  102. "ErrorInstance" => "JSError",
  103. "KURL" => "URL",
  104. "KURLCFNet" => "URLCF",
  105. "KURLHash" => "URLHash",
  106. "KURLMac" => "URLMac",
  107. "KURL_h" => "URL_h",
  108. "TreeShared" => "TreeRefCounted",
  109. "StringImpl" => "SharedString",
  110. "RenderView" => "RenderViewport",
  111. "ObjcFallbackObjectImp" => "ObjCFallbackObject",
  112. "RuntimeObjectImp" => "ForeignObject",
  113. "runtime_array" => "BridgedArray",
  114. "runtime_method" => "BridgedFunction",
  115. "runtime_object" => "BridgedObject",
  116. "objc_runtime" => "ObjCBridge",
  117. "equalIgnoringCase" => "equalFoldingCase",
  118. "FTPDirectoryTokenizer" => "FTPDirectoryDocumentBuilder",
  119. "HTMLTokenizer" => "HTMLDocumentBuilder",
  120. "ImageTokenizer" => "ImageDocumentBuilder",
  121. "PluginTokenizer" => "PluginDocumentBuilder",
  122. "TextTokenizer" => "TextDocumentBuilder",
  123. "Tokenizer" => "DocumentBuilder",
  124. "Tokenizer_h" => "DocumentBuilder_h",
  125. "XMLTokenizer" => "XMLDocumentBuilder",
  126. "isHTMLTokenizer" => "isHTMLDocumentBuilder",
  127. "m_tokenizer" => "m_builder",
  128. "createTokenizer" => "createBuilder",
  129. "tokenizerProcessedData" => "documentBuilderProcessedData",
  130. "WTF_UNICODE_H" => "Unicode_h",
  131. "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
  132. "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
  133. "UnicodeIcu" => "UnicodeICU",
  134. "m_invertibleCTM" => "m_transformIsInvertible",
  135. "NativeFunctionWrapper_h" => "JSHostFunction_h",
  136. "NativeFunctionWrapper" => "JSHostFunction",
  137. "nativeFunctionThunk" => "hostFunctionThunk",
  138. "nativeFunction" => "hostFunction",
  139. "NativeFunction" => "HostFunction",
  140. );
  141. # Sort the keys of the renames hash in order of decreasing length. This
  142. # handles the case where some of the renames are substrings of others;
  143. # i.e., "Foo" => "Bar" and "FooBuffer" => "BarBuffer".
  144. my @sortedRenameKeys = sort { length($b) - length($a) } keys %renames;
  145. # rename files
  146. sub renameFile
  147. {
  148. my $file = shift;
  149. if ($isDOMTypeRename) {
  150. # Find the longest key in %renames which matches this more permissive regexp.
  151. # (The old regexp would match ".../Foo.cpp" but not ".../JSFooCustom.cpp".)
  152. # This handles renaming of custom JavaScript bindings even when some of the
  153. # renames are substrings of others. The only reason we don't do this all the
  154. # time is to avoid accidental file renamings for short, non-DOM renames.
  155. for my $key (@sortedRenameKeys) {
  156. my $newFile = "";
  157. $newFile = "$1$renames{$2}$3" if $file =~ /^(.*\/\w*)($key)(\w*\.\w+)$/;
  158. if ($newFile ne "") {
  159. return $newFile;
  160. }
  161. }
  162. } else {
  163. $file = "$1$renames{$2}$3" if $file =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
  164. }
  165. return $file;
  166. }
  167. my %newFile;
  168. for my $file (sort @paths) {
  169. my $f = renameFile($file);
  170. if ($f ne $file) {
  171. $newFile{$file} = $f;
  172. }
  173. }
  174. for my $file (sort @paths) {
  175. if ($newFile{$file}) {
  176. my $newFile = $newFile{$file};
  177. print "Renaming $file to $newFile\n";
  178. scmMoveOrRenameFile($file, $newFile);
  179. }
  180. }
  181. # change all file contents
  182. for my $file (sort @paths) {
  183. $file = $newFile{$file} if $newFile{$file};
  184. my $contents;
  185. {
  186. local $/;
  187. open FILE, $file or die "Failed to open $file";
  188. $contents = <FILE>;
  189. close FILE;
  190. }
  191. my $newContents = $contents;
  192. if ($isDOMTypeRename) {
  193. for my $from (@sortedRenameKeys) {
  194. # Handle JavaScript custom bindings.
  195. $newContents =~ s/\b(JS|V8|to|)$from/$1$renames{$from}/g;
  196. }
  197. } else {
  198. for my $from (@sortedRenameKeys) {
  199. $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
  200. }
  201. }
  202. if ($newContents ne $contents) {
  203. open FILE, ">", $file or die "Failed to open $file";
  204. print FILE $newContents;
  205. close FILE;
  206. }
  207. }