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