Initialize Tizen 2.3
[framework/web/webkit-efl.git] / Tools / Scripts / do-webcore-rename
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     "WaveTable" => "PeriodicWave",
100 );
101
102 my %renamesContemplatedForTheFuture = (
103     "HTMLPlugInImageElement" => "HTMLEmbeddedObjectElement",
104
105     "DOMObject" => "JSDOMObject",
106
107     "runtimeObjectGetter" => "pluginElementGetter",
108     "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
109     "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
110     "runtimeObjectCustomPut" => "pluginElementCustomPut",
111     "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
112     "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
113
114     "CLONE_CONTENTS" => "Clone",
115     "DELETE_CONTENTS" => "Delete",
116     "EXTRACT_CONTENTS" => "Extract",
117
118     "DateInstance" => "JSDate",
119     "ErrorInstance" => "JSError",
120
121     "KURL" => "URL",
122     "KURLCFNet" => "URLCF",
123     "KURLHash" => "URLHash",
124     "KURLMac" => "URLMac",
125     "KURL_h" => "URL_h",
126
127     "TreeShared" => "TreeRefCounted",
128
129     "StringImpl" => "SharedString",
130
131     "RenderView" => "RenderViewport",
132
133     "ObjcFallbackObjectImp" => "ObjCFallbackObject",
134     "RuntimeObjectImp" => "ForeignObject",
135
136     "runtime_array" => "BridgedArray",
137     "runtime_method" => "BridgedFunction",
138     "runtime_object" => "BridgedObject",
139     "objc_runtime" => "ObjCBridge",
140
141     "equalIgnoringCase" => "equalFoldingCase",
142
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",
155
156     "WTF_UNICODE_H" => "Unicode_h",
157     "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
158     "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
159     "UnicodeIcu" => "UnicodeICU",
160
161     "m_invertibleCTM" => "m_transformIsInvertible",
162
163     "NativeFunctionWrapper_h" => "JSHostFunction_h",
164     "NativeFunctionWrapper" => "JSHostFunction",
165     "nativeFunctionThunk" => "hostFunctionThunk",
166     "nativeFunction" => "hostFunction",
167     "NativeFunction" => "HostFunction",
168 );
169
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;
174
175 # rename files
176
177 sub renameFile
178 {
179     my $file = shift;
180
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) {
188             my $newFile = "";
189             $newFile = "$1$renames{$2}$3" if $file =~ /^(.*\/\w*)($key)(\w*\.\w+)$/;
190             if ($newFile ne "") {
191                 return $newFile;
192             }
193         }
194     } else {
195        $file = "$1$renames{$2}$3" if $file =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
196     }
197     return $file;
198 }
199
200 my %newFile;
201 for my $file (sort @paths) {
202     my $f = renameFile($file);
203     if ($f ne $file) {
204         $newFile{$file} = $f;
205     }
206 }
207
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);
213     }
214 }
215
216 # change all file contents
217
218 for my $file (sort @paths) {
219     $file = $newFile{$file} if $newFile{$file};
220     my $contents;
221     {
222         local $/;
223         open FILE, $file or die "Failed to open $file";
224         $contents = <FILE>;
225         close FILE;
226     }
227     my $newContents = $contents;
228
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;
233         }
234     } else {
235         for my $from (@sortedRenameKeys) {
236             $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
237         }
238     }
239
240     if ($newContents ne $contents) {
241         open FILE, ">", $file or die "Failed to open $file";
242         print FILE $newContents;
243         close FILE;
244     }
245 }