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 "JavaScriptAudioNode" => "ScriptProcessorNode",
100 "RealtimeAnalyserNode" => "AnalyserNode",
101 "AudioGainNode" => "GainNode",
102 "AudioPannerNode" => "PannerNode",
103 "AudioChannelSplitter" => "ChannelSplitterNode",
104 "AudioChannelMerger" => "ChannelMergerNode",
105 "Oscillator" => "OscillatorNode",
108 my %renamesContemplatedForTheFuture = (
109 "HTMLPlugInImageElement" => "HTMLEmbeddedObjectElement",
111 "DOMObject" => "JSDOMObject",
113 "runtimeObjectGetter" => "pluginElementGetter",
114 "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
115 "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
116 "runtimeObjectCustomPut" => "pluginElementCustomPut",
117 "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
118 "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
120 "CLONE_CONTENTS" => "Clone",
121 "DELETE_CONTENTS" => "Delete",
122 "EXTRACT_CONTENTS" => "Extract",
124 "DateInstance" => "JSDate",
125 "ErrorInstance" => "JSError",
128 "KURLCFNet" => "URLCF",
129 "KURLHash" => "URLHash",
130 "KURLMac" => "URLMac",
133 "TreeShared" => "TreeRefCounted",
135 "StringImpl" => "SharedString",
137 "RenderView" => "RenderViewport",
139 "ObjcFallbackObjectImp" => "ObjCFallbackObject",
140 "RuntimeObjectImp" => "ForeignObject",
142 "runtime_array" => "BridgedArray",
143 "runtime_method" => "BridgedFunction",
144 "runtime_object" => "BridgedObject",
145 "objc_runtime" => "ObjCBridge",
147 "equalIgnoringCase" => "equalFoldingCase",
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",
162 "WTF_UNICODE_H" => "Unicode_h",
163 "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
164 "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
165 "UnicodeIcu" => "UnicodeICU",
167 "m_invertibleCTM" => "m_transformIsInvertible",
169 "NativeFunctionWrapper_h" => "JSHostFunction_h",
170 "NativeFunctionWrapper" => "JSHostFunction",
171 "nativeFunctionThunk" => "hostFunctionThunk",
172 "nativeFunction" => "hostFunction",
173 "NativeFunction" => "HostFunction",
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;
187 if ($isDOMTypeRename) {
188 # Find the longest key in %renames which matches this more permissive regexp.
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) {
195 $newFile = "$1$renames{$2}$3" if $file =~ /^(.*\/\w*)($key)(\w*\.\w+)$/;
196 if ($newFile ne "") {
201 $file = "$1$renames{$2}$3" if $file =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
207 for my $file (sort @paths) {
208 my $f = renameFile($file);
210 $newFile{$file} = $f;
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);
222 # change all file contents
224 for my $file (sort @paths) {
225 $file = $newFile{$file} if $newFile{$file};
229 open FILE, $file or die "Failed to open $file";
233 my $newContents = $contents;
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;
241 for my $from (@sortedRenameKeys) {
242 $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
246 if ($newContents ne $contents) {
247 open FILE, ">", $file or die "Failed to open $file";
248 print FILE $newContents;