3 # Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
29 # Script to do a rename in JavaScriptCore, WebCore, and WebKit.
35 use Getopt::Long qw(:config pass_through);
37 use lib $FindBin::Bin;
47 my $programName = basename($0);
49 Usage: $programName [options]
50 -h|--help Show this help message
51 -v|--verbose More verbose output
54 my $getOptionsResult = GetOptions(
55 'help|h' => \$showHelp,
56 'verbose|v' => \$verbose,
59 if (!$getOptionsResult || $showHelp) {
64 my @directoriesToIgnoreList = (
67 my %directoriesToIgnore = map { $_ => 1 } @directoriesToIgnoreList;
69 # find all files we want to process
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");
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;
91 push @paths, $File::Find::name;
94 # Setting isDOMTypeRename to 1 rather than 0 expands the regexps used
95 # below to handle custom JavaScript bindings.
96 my $isDOMTypeRename = 1;
98 # Renames go here in the form of:
99 "WaveTable" => "PeriodicWave",
102 my %renamesContemplatedForTheFuture = (
103 "HTMLPlugInImageElement" => "HTMLEmbeddedObjectElement",
105 "DOMObject" => "JSDOMObject",
107 "runtimeObjectGetter" => "pluginElementGetter",
108 "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
109 "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
110 "runtimeObjectCustomPut" => "pluginElementCustomPut",
111 "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
112 "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
114 "CLONE_CONTENTS" => "Clone",
115 "DELETE_CONTENTS" => "Delete",
116 "EXTRACT_CONTENTS" => "Extract",
118 "DateInstance" => "JSDate",
119 "ErrorInstance" => "JSError",
122 "KURLCFNet" => "URLCF",
123 "KURLHash" => "URLHash",
124 "KURLMac" => "URLMac",
127 "TreeShared" => "TreeRefCounted",
129 "StringImpl" => "SharedString",
131 "RenderView" => "RenderViewport",
133 "ObjcFallbackObjectImp" => "ObjCFallbackObject",
134 "RuntimeObjectImp" => "ForeignObject",
136 "runtime_array" => "BridgedArray",
137 "runtime_method" => "BridgedFunction",
138 "runtime_object" => "BridgedObject",
139 "objc_runtime" => "ObjCBridge",
141 "equalIgnoringCase" => "equalFoldingCase",
143 "FTPDirectoryTokenizer" => "FTPDirectoryDocumentBuilder",
144 "HTMLTokenizer" => "HTMLDocumentBuilder",
145 "ImageTokenizer" => "ImageDocumentBuilder",
146 "PluginTokenizer" => "PluginDocumentBuilder",
147 "TextTokenizer" => "TextDocumentBuilder",
148 "Tokenizer" => "DocumentBuilder",
149 "Tokenizer_h" => "DocumentBuilder_h",
150 "XMLTokenizer" => "XMLDocumentBuilder",
151 "isHTMLTokenizer" => "isHTMLDocumentBuilder",
152 "m_tokenizer" => "m_builder",
153 "createTokenizer" => "createBuilder",
154 "tokenizerProcessedData" => "documentBuilderProcessedData",
156 "WTF_UNICODE_H" => "Unicode_h",
157 "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
158 "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
159 "UnicodeIcu" => "UnicodeICU",
161 "m_invertibleCTM" => "m_transformIsInvertible",
163 "NativeFunctionWrapper_h" => "JSHostFunction_h",
164 "NativeFunctionWrapper" => "JSHostFunction",
165 "nativeFunctionThunk" => "hostFunctionThunk",
166 "nativeFunction" => "hostFunction",
167 "NativeFunction" => "HostFunction",
170 # Sort the keys of the renames hash in order of decreasing length. This
171 # handles the case where some of the renames are substrings of others;
172 # i.e., "Foo" => "Bar" and "FooBuffer" => "BarBuffer".
173 my @sortedRenameKeys = sort { length($b) - length($a) } keys %renames;
181 if ($isDOMTypeRename) {
182 # Find the longest key in %renames which matches this more permissive regexp.
183 # (The old regexp would match ".../Foo.cpp" but not ".../JSFooCustom.cpp".)
184 # This handles renaming of custom JavaScript bindings even when some of the
185 # renames are substrings of others. The only reason we don't do this all the
186 # time is to avoid accidental file renamings for short, non-DOM renames.
187 for my $key (@sortedRenameKeys) {
189 $newFile = "$1$renames{$2}$3" if $file =~ /^(.*\/\w*)($key)(\w*\.\w+)$/;
190 if ($newFile ne "") {
195 $file = "$1$renames{$2}$3" if $file =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
201 for my $file (sort @paths) {
202 my $f = renameFile($file);
204 $newFile{$file} = $f;
208 for my $file (sort @paths) {
209 if ($newFile{$file}) {
210 my $newFile = $newFile{$file};
211 print "Renaming $file to $newFile\n";
212 scmMoveOrRenameFile($file, $newFile);
216 # change all file contents
218 for my $file (sort @paths) {
219 $file = $newFile{$file} if $newFile{$file};
223 open FILE, $file or die "Failed to open $file";
227 my $newContents = $contents;
229 if ($isDOMTypeRename) {
230 for my $from (@sortedRenameKeys) {
231 # Handle JavaScript custom bindings.
232 $newContents =~ s/\b(JS|V8|to|)$from/$1$renames{$from}/g;
235 for my $from (@sortedRenameKeys) {
236 $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
240 if ($newContents ne $contents) {
241 open FILE, ">", $file or die "Failed to open $file";
242 print FILE $newContents;