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/JavaScriptGlue");
74 find(\&wanted, "Source/WebCore");
75 find(\&wanted, "Source/WebKit");
76 find(\&wanted, "Source/WebKit2");
77 find(\&wanted, "Tools/DumpRenderTree");
83 # Ignore excluded and hidden files/directories.
84 if ($directoriesToIgnore{$file} or $file =~ /^\../ or $file =~ /^ChangeLog/) {
85 print "Ignoring $File::Find::name\n" if $verbose;
86 $File::Find::prune = 1;
92 push @paths, $File::Find::name;
95 # Setting isDOMTypeRename to 1 rather than 0 expands the regexps used
96 # below to handle custom JavaScript bindings.
97 my $isDOMTypeRename = 0;
99 # Renames go here in the form of:
100 "MediaControls" => "MediaControlRootElement",
103 my %renamesContemplatedForTheFuture = (
104 "HTMLPlugInImageElement" => "HTMLEmbeddedObjectElement",
106 "DOMObject" => "JSDOMObject",
108 "runtimeObjectGetter" => "pluginElementGetter",
109 "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
110 "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
111 "runtimeObjectCustomPut" => "pluginElementCustomPut",
112 "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
113 "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
115 "CLONE_CONTENTS" => "Clone",
116 "DELETE_CONTENTS" => "Delete",
117 "EXTRACT_CONTENTS" => "Extract",
119 "DateInstance" => "JSDate",
120 "ErrorInstance" => "JSError",
123 "KURLCFNet" => "URLCF",
124 "KURLHash" => "URLHash",
125 "KURLMac" => "URLMac",
128 "TreeShared" => "TreeRefCounted",
130 "StringImpl" => "SharedString",
132 "RenderView" => "RenderViewport",
134 "ObjcFallbackObjectImp" => "ObjCFallbackObject",
135 "RuntimeObjectImp" => "ForeignObject",
137 "runtime_array" => "BridgedArray",
138 "runtime_method" => "BridgedFunction",
139 "runtime_object" => "BridgedObject",
140 "objc_runtime" => "ObjCBridge",
142 "equalIgnoringCase" => "equalFoldingCase",
144 "FTPDirectoryTokenizer" => "FTPDirectoryDocumentBuilder",
145 "HTMLTokenizer" => "HTMLDocumentBuilder",
146 "ImageTokenizer" => "ImageDocumentBuilder",
147 "PluginTokenizer" => "PluginDocumentBuilder",
148 "TextTokenizer" => "TextDocumentBuilder",
149 "Tokenizer" => "DocumentBuilder",
150 "Tokenizer_h" => "DocumentBuilder_h",
151 "XMLTokenizer" => "XMLDocumentBuilder",
152 "isHTMLTokenizer" => "isHTMLDocumentBuilder",
153 "m_tokenizer" => "m_builder",
154 "createTokenizer" => "createBuilder",
155 "tokenizerProcessedData" => "documentBuilderProcessedData",
157 "WTF_UNICODE_H" => "Unicode_h",
158 "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
159 "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
160 "UnicodeIcu" => "UnicodeICU",
162 "m_invertibleCTM" => "m_transformIsInvertible",
164 "NativeFunctionWrapper_h" => "JSHostFunction_h",
165 "NativeFunctionWrapper" => "JSHostFunction",
166 "nativeFunctionThunk" => "hostFunctionThunk",
167 "nativeFunction" => "hostFunction",
168 "NativeFunction" => "HostFunction",
171 # Sort the keys of the renames hash in order of decreasing length. This
172 # handles the case where some of the renames are substrings of others;
173 # i.e., "Foo" => "Bar" and "FooBuffer" => "BarBuffer".
174 my @sortedRenameKeys = sort { length($b) - length($a) } keys %renames;
182 if ($isDOMTypeRename) {
183 # Find the longest key in %renames which matches this more permissive regexp.
184 # (The old regexp would match ".../Foo.cpp" but not ".../JSFooCustom.cpp".)
185 # This handles renaming of custom JavaScript bindings even when some of the
186 # renames are substrings of others. The only reason we don't do this all the
187 # time is to avoid accidental file renamings for short, non-DOM renames.
188 for my $key (@sortedRenameKeys) {
190 $newFile = "$1$renames{$2}$3" if $file =~ /^(.*\/\w*)($key)(\w*\.\w+)$/;
191 if ($newFile ne "") {
196 $file = "$1$renames{$2}$3" if $file =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
202 for my $file (sort @paths) {
203 my $f = renameFile($file);
205 $newFile{$file} = $f;
209 for my $file (sort @paths) {
210 if ($newFile{$file}) {
211 my $newFile = $newFile{$file};
212 print "Renaming $file to $newFile\n";
213 scmMoveOrRenameFile($file, $newFile);
217 # change all file contents
219 for my $file (sort @paths) {
220 $file = $newFile{$file} if $newFile{$file};
224 open FILE, $file or die "Failed to open $file";
228 my $newContents = $contents;
230 if ($isDOMTypeRename) {
231 for my $from (@sortedRenameKeys) {
232 # Handle JavaScript custom bindings.
233 $newContents =~ s/\b(JS|V8|to|)$from/$1$renames{$from}/g;
236 for my $from (@sortedRenameKeys) {
237 $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
241 if ($newContents ne $contents) {
242 open FILE, ">", $file or die "Failed to open $file";
243 print FILE $newContents;