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