* Scripts/do-webcore-rename: Yet more renaming ideas.
[WebKit-https.git] / WebKitTools / Scripts / do-webcore-rename
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2006, 2007 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 use FindBin;
33 use lib $FindBin::Bin;
34 use webkitdirs;
35 use File::Find;
36
37 setConfiguration();
38 chdirWebKit();
39
40 my %words;
41
42 # find all files we want to process
43
44 my @paths;
45 find(\&wanted, "JavaScriptCore");
46 find(\&wanted, "WebCore");
47 find(\&wanted, "WebKit");
48
49 sub wanted
50 {
51     my $file = $_;
52
53     if ($file eq "icu") {
54         $File::Find::prune = 1;
55         return;
56     }
57
58     if ($file =~ /^\../) {
59         $File::Find::prune = 1;
60         return;
61     }
62
63     return if $file =~ /^ChangeLog/;
64     return if -d $file;
65
66     push @paths, $File::Find::name;
67 }
68
69 my %renames = (
70     "ActivationImp" => "Activation",
71     "ActivationImpData" => "ActivationData",
72     "ArrayObjectImp" => "ArrayConstructor",
73     "ArrayProtoFuncConcat" => "ArrayFunctionConcat",
74     "ArrayProtoFuncEvery" => "ArrayFunctionEvery",
75     "ArrayProtoFuncFilter" => "ArrayFunctionFilter",
76     "ArrayProtoFuncForEach" => "ArrayFunctionForEach",
77     "ArrayProtoFuncIndexOf" => "ArrayFunctionIndexOf",
78     "ArrayProtoFuncJoin" => "ArrayFunctionJoin",
79     "ArrayProtoFuncLastIndexOf" => "ArrayFunctionLastIndexOf",
80     "ArrayProtoFuncMap" => "ArrayFunctionMap",
81     "ArrayProtoFuncPop" => "ArrayFunctionPop",
82     "ArrayProtoFuncPush" => "ArrayFunctionPush",
83     "ArrayProtoFuncReverse" => "ArrayFunctionReverse",
84     "ArrayProtoFuncShift" => "ArrayFunctionShift",
85     "ArrayProtoFuncSlice" => "ArrayFunctionSlice",
86     "ArrayProtoFuncSome" => "ArrayFunctionSome",
87     "ArrayProtoFuncSort" => "ArrayFunctionSort",
88     "ArrayProtoFuncSplice" => "ArrayFunctionSplice",
89     "ArrayProtoFuncToLocaleString" => "ArrayFunctionToLocaleString",
90     "ArrayProtoFuncToString" => "ArrayFunctionToString",
91     "ArrayProtoFuncUnShift" => "ArrayFunctionUnshift",
92     "BooleanObjectImp" => "BooleanConstructor",
93     "BooleanProtoFunc" => "BooleanFunction",
94     "DateObjectFuncImp" => "DateFunction",
95     "DateObjectImp" => "DateConstructor",
96     "DateProtoFuncGetDate" => "DateFunctionGetDate",
97     "DateProtoFuncGetDay" => "DateFunctionGetDay",
98     "DateProtoFuncGetFullYear" => "DateFunctionGetFullYear",
99     "DateProtoFuncGetHours" => "DateFunctionGetHours",
100     "DateProtoFuncGetMilliSeconds" => "DateFunctionGetMilliSeconds",
101     "DateProtoFuncGetMinutes" => "DateFunctionGetMinutes",
102     "DateProtoFuncGetMonth" => "DateFunctionGetMonth",
103     "DateProtoFuncGetSeconds" => "DateFunctionGetSeconds",
104     "DateProtoFuncGetTime" => "DateFunctionGetTime",
105     "DateProtoFuncGetTimezoneOffset" => "DateFunctionGetTimezoneOffset",
106     "DateProtoFuncGetUTCDate" => "DateFunctionGetUTCDate",
107     "DateProtoFuncGetUTCDay" => "DateFunctionGetUTCDay",
108     "DateProtoFuncGetUTCFullYear" => "DateFunctionGetUTCFullYear",
109     "DateProtoFuncGetUTCHours" => "DateFunctionGetUTCHours",
110     "DateProtoFuncGetUTCMilliseconds" => "DateFunctionGetUTCMilliseconds",
111     "DateProtoFuncGetUTCMinutes" => "DateFunctionGetUTCMinutes",
112     "DateProtoFuncGetUTCMonth" => "DateFunctionGetUTCMonth",
113     "DateProtoFuncGetUTCSeconds" => "DateFunctionGetUTCSeconds",
114     "DateProtoFuncGetYear" => "DateFunctionGetYear",
115     "DateProtoFuncSetDate" => "DateFunctionSetDate",
116     "DateProtoFuncSetFullYear" => "DateFunctionSetFullYear",
117     "DateProtoFuncSetHours" => "DateFunctionSetHours",
118     "DateProtoFuncSetMilliSeconds" => "DateFunctionSetMilliSeconds",
119     "DateProtoFuncSetMinutes" => "DateFunctionSetMinutes",
120     "DateProtoFuncSetMonth" => "DateFunctionSetMonth",
121     "DateProtoFuncSetSeconds" => "DateFunctionSetSeconds",
122     "DateProtoFuncSetTime" => "DateFunctionSetTime",
123     "DateProtoFuncSetUTCDate" => "DateFunctionSetUTCDate",
124     "DateProtoFuncSetUTCFullYear" => "DateFunctionSetUTCFullYear",
125     "DateProtoFuncSetUTCHours" => "DateFunctionSetUTCHours",
126     "DateProtoFuncSetUTCMilliseconds" => "DateFunctionSetUTCMilliseconds",
127     "DateProtoFuncSetUTCMinutes" => "DateFunctionSetUTCMinutes",
128     "DateProtoFuncSetUTCMonth" => "DateFunctionSetUTCMonth",
129     "DateProtoFuncSetUTCSeconds" => "DateFunctionSetUTCSeconds",
130     "DateProtoFuncSetYear" => "DateFunctionSetYear",
131     "DateProtoFuncToDateString" => "DateFunctionToDateString",
132     "DateProtoFuncToGMTString" => "DateFunctionToGMTString",
133     "DateProtoFuncToLocaleDateString" => "DateFunctionToLocaleDateString",
134     "DateProtoFuncToLocaleString" => "DateFunctionToLocaleString",
135     "DateProtoFuncToLocaleTimeString" => "DateFunctionToLocaleTimeString",
136     "DateProtoFuncToString" => "DateFunctionToString",
137     "DateProtoFuncToTimeString" => "DateFunctionToTimeString",
138     "DateProtoFuncToUTCString" => "DateFunctionToUTCString",
139     "DateProtoFuncValueOf" => "DateFunctionValueOf",
140     "DebuggerImp" => "DebuggerData",
141     "ErrorObjectImp" => "ErrorConstructor",
142     "ErrorProtoFuncToString" => "ErrorFunction",
143     "FRAMES_ON_STACK" => "numFramesOnStack",
144     "FunctionImp" => "FunctionInstance",
145     "FunctionObjectImp" => "FunctionConstructor",
146     "FunctionProtoFunc" => "FunctionFunction",
147     "GetterSetterImp" => "GetterSetter",
148     "GlobalFuncImp" => "GlobalFunction",
149     "GlobalImp" => "TestGlobalObject",
150     "HTMLGenericFormElement" => "HTMLFormControlElement",
151     "HTMLGenericFormElement_h" => "HTMLFormControlElement_h",
152     "ImageConstructorImp" => "JSImageConstructor",
153     "InternalFunctionImp" => "InternalFunction",
154     "JSXMLHttpRequestConstructorImp" => "JSXMLHttpRequestConstructor",
155     "KURL" => "URL",
156     "KURLCFNet" => "URLCF",
157     "KURLMac" => "URLMac",
158     "KURL_H_" => "URL_h",
159     "MathObjectImp" => "MathConstructor",
160     "MathProtoFuncACos" => "MathFunctionACos",
161     "MathProtoFuncASin" => "MathFunctionASin",
162     "MathProtoFuncATan" => "MathFunctionATan",
163     "MathProtoFuncATan2" => "MathFunctionATan2",
164     "MathProtoFuncAbs" => "MathFunctionAbs",
165     "MathProtoFuncCeil" => "MathFunctionCeil",
166     "MathProtoFuncCos" => "MathFunctionCos",
167     "MathProtoFuncExp" => "MathFunctionExp",
168     "MathProtoFuncFloor" => "MathFunctionFloor",
169     "MathProtoFuncLog" => "MathFunctionLog",
170     "MathProtoFuncMax" => "MathFunctionMax",
171     "MathProtoFuncMin" => "MathFunctionMin",
172     "MathProtoFuncPow" => "MathFunctionPow",
173     "MathProtoFuncRandom" => "MathFunctionRandom",
174     "MathProtoFuncRound" => "MathFunctionRound",
175     "MathProtoFuncSin" => "MathFunctionSin",
176     "MathProtoFuncSqrt" => "MathFunctionSqrt",
177     "MathProtoFuncTan" => "MathFunctionTan",
178     "NativeErrorImp" => "NativeErrorConstructor",
179     "Navigator" => "JSNavigator",
180     "NumberImp" => "NumberValue",
181     "NumberObjectImp" => "NumberConstructor",
182     "NumberProtoFunc" => "NumberFunction",
183     "ObjcFallbackObjectImp" => "ObjCFallbackObject",
184     "ObjectObjectImp" => "ObjectConstructor",
185     "ObjectProtoFunc" => "ObjectFunction",
186     "RegExpImp" => "RegExpInstance",
187     "RegExpObjectImp" => "RegExpConstructor",
188     "RegExpObjectImpPrivate" => "RegExpObjectPrivate",
189     "RegExpProtoFunc" => "RegExpFunction",
190     "RuntimeObjectImp" => "ExternalLanguageObject",
191     "StringImp" => "StringValue",
192     "StringImpl" => "SharedString",
193     "StringObjectFuncImp" => "StringFunction",
194     "StringObjectImp" => "StringConstructor",
195     "StringProtoFuncAnchor" => "StringFunctionAnchor",
196     "StringProtoFuncBig" => "StringFunctionBig",
197     "StringProtoFuncBlink" => "StringFunctionBlink",
198     "StringProtoFuncBold" => "StringFunctionBold",
199     "StringProtoFuncCharAt" => "StringFunctionCharAt",
200     "StringProtoFuncCharCodeAt" => "StringFunctionCharCodeAt",
201     "StringProtoFuncConcat" => "StringFunctionConcat",
202     "StringProtoFuncFixed" => "StringFunctionFixed",
203     "StringProtoFuncFontcolor" => "StringFunctionFontcolor",
204     "StringProtoFuncFontsize" => "StringFunctionFontsize",
205     "StringProtoFuncIndexOf" => "StringFunctionIndexOf",
206     "StringProtoFuncItalics" => "StringFunctionItalics",
207     "StringProtoFuncLastIndexOf" => "StringFunctionLastIndexOf",
208     "StringProtoFuncLink" => "StringFunctionLink",
209     "StringProtoFuncLocaleCompare" => "StringFunctionLocaleCompare",
210     "StringProtoFuncMatch" => "StringFunctionMatch",
211     "StringProtoFuncReplace" => "StringFunctionReplace",
212     "StringProtoFuncSearch" => "StringFunctionSearch",
213     "StringProtoFuncSlice" => "StringFunctionSlice",
214     "StringProtoFuncSmall" => "StringFunctionSmall",
215     "StringProtoFuncSplit" => "StringFunctionSplit",
216     "StringProtoFuncStrike" => "StringFunctionStrike",
217     "StringProtoFuncSub" => "StringFunctionSub",
218     "StringProtoFuncSubstr" => "StringFunctionSubstr",
219     "StringProtoFuncSubstring" => "StringFunctionSubstring",
220     "StringProtoFuncSup" => "StringFunctionSup",
221     "StringProtoFuncToLocaleLowerCase" => "StringFunctionToLocaleLowerCase",
222     "StringProtoFuncToLocaleUpperCase" => "StringFunctionToLocaleUpperCase",
223     "StringProtoFuncToLowerCase" => "StringFunctionToLowerCase",
224     "StringProtoFuncToString" => "StringFunctionToString",
225     "StringProtoFuncToUpperCase" => "StringFunctionToUpperCase",
226     "StringProtoFuncValueOf" => "StringFunctionValueOf",
227     "TestFunctionImp" => "TestFunction",
228     "XSLTProcessorConstructorImp" => "JSXSLTProcessorConstructor",
229     "XSLTProcessorPrototype" => "JSXSLTProcessorPrototype",
230     "animationController" => "animation",
231     "branchfirstbyte" => "branchFirstByte",
232     "branchreqbyte" => "branchReqByte",
233     "caseSensitive" => "foldCase",
234     "codeptr" => "codePtr",
235     "domString" => "string",
236     "equalIgnoringCase" => "equalFoldingCase",
237     "errorcodeptr" => "errorCodePtr",
238     "errorptr" => "errorPtr",
239     "first_byte" => "firstByte",
240     "first_byte_caseless" => "firstByteIsCaseless",
241     "first_char" => "firstChar",
242     "firstbyte" => "firstByte",
243     "groupsetfirstbyte" => "didGroupSetFirstByte",
244     "is_quantifier" => "isQuantifier",
245     "isclass" => "isClass",
246     "kjs_binding" => "JSDOMBinding",
247     "kjs_binding_h" => "JSDOMBinding_h",
248     "kjs_css" => "JSRGBColor",
249     "kjs_css_h" => "JSRGBColor_h",
250     "kjs_proxy" => "ScriptController",
251     "kjs_proxy_h" => "ScriptController_h",
252     "last_branch" => "lastBranch",
253     "mclength" => "mcLength",
254     "offsetcount" => "offsetCount",
255     "op_type" => "opType",
256     "prev_length" => "prevLength",
257     "ptrptr" => "ptrPtr",
258     "repeat_min" => "repeatMin",
259     "repeat_type" => "repeatType",
260     "req_byte" => "reqByte",
261     "req_byte2" => "reqByte2",
262     "req_byte_caseless" => "reqByteIsCaseless",
263     "req_caseopt" => "reqCaseOpt",
264     "req_varyopt" => "reqVaryOpt",
265     "reqbyte" => "reqByte",
266     "resetcount" => "resetCount",
267     "scriptProxy" => "script",
268     "selectionController" => "selection",
269     "skipbytes" => "skipBytes",
270     "subfirstbyte" => "subFirstByte",
271     "subreqbyte" => "subReqByte",
272     "top_backref" => "topBackref",
273     "top_bracket" => "topBracket",
274     "using_temporary_offsets" => "usingTemporaryOffsets",
275     "zerofirstbyte" => "zeroFirstByte",
276     "zeroreqbyte" => "zeroReqByte",
277 );
278
279 # rename files
280
281 my %newFile;
282 for my $file (sort @paths) {
283     my $f = $file;
284     $f = "$1$renames{$2}$3" if $f =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
285     if ($f ne $file) {
286         $newFile{$file} = $f;
287     }
288 }
289
290 for my $file (sort @paths) {
291     if ($newFile{$file}) {
292         my $newFile = $newFile{$file};
293         print "Renaming $file to $newFile\n";
294         system "svn move $file $newFile";
295     }
296 }
297
298 # change all file contents
299
300 for my $file (sort @paths) {
301     $file = $newFile{$file} if $newFile{$file};
302     my $contents;
303     {
304         local $/;
305         open FILE, $file or die;
306         $contents = <FILE>;
307         close FILE;
308     }
309     my $newContents = $contents;
310
311     for my $from (keys %renames) {
312         $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
313     }
314
315     if ($newContents ne $contents) {
316         open FILE, ">", $file or die;
317         print FILE $newContents;
318         close FILE;
319     }
320 }