967a92e123d85a01586280564ff1031ea4059933
[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     "RECURSIVE_MATCH_STARTNG_NEW_GROUP" => "RECURSIVE_MATCH_NEW_GROUP",
187     "RegExpImp" => "RegExpInstance",
188     "RegExpObjectImp" => "RegExpConstructor",
189     "RegExpObjectImpPrivate" => "RegExpObjectPrivate",
190     "RegExpProtoFunc" => "RegExpFunction",
191     "RuntimeObjectImp" => "ExternalLanguageObject",
192     "StringImp" => "StringValue",
193     "StringImpl" => "SharedString",
194     "StringObjectFuncImp" => "StringFunction",
195     "StringObjectImp" => "StringConstructor",
196     "StringProtoFuncAnchor" => "StringFunctionAnchor",
197     "StringProtoFuncBig" => "StringFunctionBig",
198     "StringProtoFuncBlink" => "StringFunctionBlink",
199     "StringProtoFuncBold" => "StringFunctionBold",
200     "StringProtoFuncCharAt" => "StringFunctionCharAt",
201     "StringProtoFuncCharCodeAt" => "StringFunctionCharCodeAt",
202     "StringProtoFuncConcat" => "StringFunctionConcat",
203     "StringProtoFuncFixed" => "StringFunctionFixed",
204     "StringProtoFuncFontcolor" => "StringFunctionFontcolor",
205     "StringProtoFuncFontsize" => "StringFunctionFontsize",
206     "StringProtoFuncIndexOf" => "StringFunctionIndexOf",
207     "StringProtoFuncItalics" => "StringFunctionItalics",
208     "StringProtoFuncLastIndexOf" => "StringFunctionLastIndexOf",
209     "StringProtoFuncLink" => "StringFunctionLink",
210     "StringProtoFuncLocaleCompare" => "StringFunctionLocaleCompare",
211     "StringProtoFuncMatch" => "StringFunctionMatch",
212     "StringProtoFuncReplace" => "StringFunctionReplace",
213     "StringProtoFuncSearch" => "StringFunctionSearch",
214     "StringProtoFuncSlice" => "StringFunctionSlice",
215     "StringProtoFuncSmall" => "StringFunctionSmall",
216     "StringProtoFuncSplit" => "StringFunctionSplit",
217     "StringProtoFuncStrike" => "StringFunctionStrike",
218     "StringProtoFuncSub" => "StringFunctionSub",
219     "StringProtoFuncSubstr" => "StringFunctionSubstr",
220     "StringProtoFuncSubstring" => "StringFunctionSubstring",
221     "StringProtoFuncSup" => "StringFunctionSup",
222     "StringProtoFuncToLocaleLowerCase" => "StringFunctionToLocaleLowerCase",
223     "StringProtoFuncToLocaleUpperCase" => "StringFunctionToLocaleUpperCase",
224     "StringProtoFuncToLowerCase" => "StringFunctionToLowerCase",
225     "StringProtoFuncToString" => "StringFunctionToString",
226     "StringProtoFuncToUpperCase" => "StringFunctionToUpperCase",
227     "StringProtoFuncValueOf" => "StringFunctionValueOf",
228     "TestFunctionImp" => "TestFunction",
229     "XSLTProcessorConstructorImp" => "JSXSLTProcessorConstructor",
230     "XSLTProcessorPrototype" => "JSXSLTProcessorPrototype",
231     "animationController" => "animation",
232     "branchfirstbyte" => "branchFirstByte",
233     "branchreqbyte" => "branchReqByte",
234     "caseSensitive" => "foldCase",
235     "class_charcount" => "classCharCount",
236     "class_lastchar" => "classLastChar",
237     "codeptr" => "codePtr",
238     "domString" => "string",
239     "equalIgnoringCase" => "equalFoldingCase",
240     "errorcodeptr" => "errorCodePtr",
241     "errorptr" => "errorPtr",
242     "first_byte" => "firstByte",
243     "first_byte_caseless" => "firstByteIsCaseless",
244     "first_char" => "firstChar",
245     "firstbyte" => "firstByte",
246     "groupsetfirstbyte" => "didGroupSetFirstByte",
247     "is_quantifier" => "isQuantifier",
248     "isclass" => "isClass",
249     "kjs_binding" => "JSDOMBinding",
250     "kjs_binding_h" => "JSDOMBinding_h",
251     "kjs_css" => "JSRGBColor",
252     "kjs_css_h" => "JSRGBColor_h",
253     "kjs_proxy" => "ScriptController",
254     "kjs_proxy_h" => "ScriptController_h",
255     "last_branch" => "lastBranch",
256     "mclength" => "mcLength",
257     "negate_class" => "negateClass",
258     "offsetcount" => "offsetCount",
259     "op_type" => "opType",
260     "prev_length" => "prevLength",
261     "ptrptr" => "ptrPtr",
262     "repeat_min" => "repeatMin",
263     "repeat_type" => "repeatType",
264     "req_byte" => "reqByte",
265     "req_byte2" => "reqByte2",
266     "req_byte_caseless" => "reqByteIsCaseless",
267     "req_caseopt" => "reqCaseOpt",
268     "req_varyopt" => "reqVaryOpt",
269     "reqbyte" => "reqByte",
270     "resetcount" => "resetCount",
271     "scriptProxy" => "script",
272     "selectionController" => "selection",
273     "should_flip_negation" => "shouldFlipNegation",
274     "skipbytes" => "skipBytes",
275     "subfirstbyte" => "subFirstByte",
276     "subreqbyte" => "subReqByte",
277     "top_backref" => "topBackref",
278     "top_bracket" => "topBracket",
279     "using_temporary_offsets" => "usingTemporaryOffsets",
280     "zerofirstbyte" => "zeroFirstByte",
281     "zeroreqbyte" => "zeroReqByte",
282 );
283
284 # rename files
285
286 my %newFile;
287 for my $file (sort @paths) {
288     my $f = $file;
289     $f = "$1$renames{$2}$3" if $f =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
290     if ($f ne $file) {
291         $newFile{$file} = $f;
292     }
293 }
294
295 for my $file (sort @paths) {
296     if ($newFile{$file}) {
297         my $newFile = $newFile{$file};
298         print "Renaming $file to $newFile\n";
299         system "svn move $file $newFile";
300     }
301 }
302
303 # change all file contents
304
305 for my $file (sort @paths) {
306     $file = $newFile{$file} if $newFile{$file};
307     my $contents;
308     {
309         local $/;
310         open FILE, $file or die;
311         $contents = <FILE>;
312         close FILE;
313     }
314     my $newContents = $contents;
315
316     for my $from (keys %renames) {
317         $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
318     }
319
320     if ($newContents ne $contents) {
321         open FILE, ">", $file or die;
322         print FILE $newContents;
323         close FILE;
324     }
325 }