OSDN Git Service

merge from open-source master
[android-x86/external-webkit.git] / WebKitTools / 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 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, "JavaScriptGlue");
47 find(\&wanted, "WebCore");
48 find(\&wanted, "WebKit");
49
50 sub wanted
51 {
52     my $file = $_;
53
54     if ($file eq "icu") {
55         $File::Find::prune = 1;
56         return;
57     }
58
59     if ($file =~ /^\../) {
60         $File::Find::prune = 1;
61         return;
62     }
63
64     return if $file =~ /^ChangeLog/;
65     return if -d $file;
66
67     push @paths, $File::Find::name;
68 }
69
70 my %renames = (
71     "JSUnprotectedEventListener" => "JSEventListener",
72     "findJSUnprotectedEventListener" => "findJSEventListener",
73     "findOrCreateJSUnprotectedEventListener" => "findOrCreateJSEventListener",
74     "UnprotectedListenersMap" => "JSListenersMap",
75     "jsUnprotectedEventListeners" => "jsEventListeners",
76     "jsUnprotectedInlineEventListeners" => "jsInlineEventListeners",
77 );
78
79 my %renamesContemplatedForTheFuture = (
80     "DOMObject" => "JSDOMObject",
81
82     "runtimeObjectGetter" => "pluginElementGetter",
83     "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
84     "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
85     "runtimeObjectCustomPut" => "pluginElementCustomPut",
86     "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
87     "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
88
89     "CLONE_CONTENTS" => "Clone",
90     "DELETE_CONTENTS" => "Delete",
91     "EXTRACT_CONTENTS" => "Extract",
92
93     "DateInstance" => "JSDate",
94     "ErrorInstance" => "JSError",
95
96     "KURL" => "URL",
97     "KURLCFNet" => "URLCF",
98     "KURLHash" => "URLHash",
99     "KURLMac" => "URLMac",
100     "KURL_h" => "URL_h",
101
102     "ThreadSafeShared" => "ThreadSafeRefCounted",
103     "TreeShared" => "TreeRefCounted",
104
105     "StringImpl" => "SharedString",
106
107     "RenderView" => "RenderViewport",
108
109     "ObjcFallbackObjectImp" => "ObjCFallbackObject",
110     "RuntimeObjectImp" => "ForeignObject",
111
112     "runtime_array" => "BridgedArray",
113     "runtime_method" => "BridgedFunction",
114     "runtime_object" => "BridgedObject",
115     "objc_runtime" => "ObjCBridge",
116
117     "equalIgnoringCase" => "equalFoldingCase",
118
119     "FTPDirectoryTokenizer" => "FTPDirectoryDocumentBuilder",
120     "HTMLTokenizer" => "HTMLDocumentBuilder",
121     "ImageTokenizer" => "ImageDocumentBuilder",
122     "PluginTokenizer" => "PluginDocumentBuilder",
123     "TextTokenizer" => "TextDocumentBuilder",
124     "Tokenizer" => "DocumentBuilder",
125     "Tokenizer_h" => "DocumentBuilder_h",
126     "XMLTokenizer" => "XMLDocumentBuilder",
127     "isHTMLTokenizer" => "isHTMLDocumentBuilder",
128     "m_tokenizer" => "m_builder",
129     "createTokenizer" => "createBuilder",
130     "tokenizerProcessedData" => "documentBuilderProcessedData",
131
132     "WTF_UNICODE_H" => "Unicode_h",
133     "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
134     "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
135     "UnicodeIcu" => "UnicodeICU",
136
137     "m_invertibleCTM" => "m_transformIsInvertible",
138
139     "JSValuePtr" => "JSValue",
140     "ProtectedJSValuePtr" => "ProtectedJSValue",
141 );
142
143 # rename files
144
145 my %newFile;
146 for my $file (sort @paths) {
147     my $f = $file;
148     $f = "$1$renames{$2}$3" if $f =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
149     if ($f ne $file) {
150         $newFile{$file} = $f;
151     }
152 }
153
154 for my $file (sort @paths) {
155     if ($newFile{$file}) {
156         my $newFile = $newFile{$file};
157         print "Renaming $file to $newFile\n";
158         system "svn move $file $newFile";
159     }
160 }
161
162 # change all file contents
163
164 for my $file (sort @paths) {
165     $file = $newFile{$file} if $newFile{$file};
166     my $contents;
167     {
168         local $/;
169         open FILE, $file or die;
170         $contents = <FILE>;
171         close FILE;
172     }
173     my $newContents = $contents;
174
175     for my $from (keys %renames) {
176         $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
177     }
178
179     if ($newContents ne $contents) {
180         open FILE, ">", $file or die;
181         print FILE $newContents;
182         close FILE;
183     }
184 }