Home | History | Annotate | Download | only in Scripts
      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 use VCSUtils;
     37 
     38 setConfiguration();
     39 chdirWebKit();
     40 
     41 my %words;
     42 
     43 # find all files we want to process
     44 
     45 my @paths;
     46 find(\&wanted, "JavaScriptCore");
     47 find(\&wanted, "JavaScriptGlue");
     48 find(\&wanted, "WebCore");
     49 find(\&wanted, "WebKit");
     50 
     51 sub wanted
     52 {
     53     my $file = $_;
     54 
     55     if ($file eq "icu") {
     56         $File::Find::prune = 1;
     57         return;
     58     }
     59 
     60     if ($file =~ /^\../) {
     61         $File::Find::prune = 1;
     62         return;
     63     }
     64 
     65     return if $file =~ /^ChangeLog/;
     66     return if -d $file;
     67 
     68     push @paths, $File::Find::name;
     69 }
     70 my $isDOMTypeRename = 0;
     71 my %renames = (
     72     "m_sel" => "m_selection",
     73 );
     74 
     75 my %renamesContemplatedForTheFuture = (
     76     "HTMLPlugInImageElement" => "HTMLEmbeddedObjectElement",
     77 
     78     "DOMObject" => "JSDOMObject",
     79 
     80     "runtimeObjectGetter" => "pluginElementGetter",
     81     "runtimeObjectPropertyGetter" => "pluginElementPropertyGetter",
     82     "runtimeObjectCustomGetOwnPropertySlot" => "pluginElementCustomGetOwnPropertySlot",
     83     "runtimeObjectCustomPut" => "pluginElementCustomPut",
     84     "runtimeObjectImplementsCall" => "pluginElementImplementsCall",
     85     "runtimeObjectCallAsFunction" => "pluginElementCallAsFunction",
     86 
     87     "CLONE_CONTENTS" => "Clone",
     88     "DELETE_CONTENTS" => "Delete",
     89     "EXTRACT_CONTENTS" => "Extract",
     90 
     91     "DateInstance" => "JSDate",
     92     "ErrorInstance" => "JSError",
     93 
     94     "KURL" => "URL",
     95     "KURLCFNet" => "URLCF",
     96     "KURLHash" => "URLHash",
     97     "KURLMac" => "URLMac",
     98     "KURL_h" => "URL_h",
     99 
    100     "ThreadSafeSharedBase" => "ThreadSafeRefCountedBase",
    101     "ThreadSafeShared" => "ThreadSafeRefCounted",
    102     "TreeShared" => "TreeRefCounted",
    103 
    104     "StringImpl" => "SharedString",
    105 
    106     "RenderView" => "RenderViewport",
    107 
    108     "ObjcFallbackObjectImp" => "ObjCFallbackObject",
    109     "RuntimeObjectImp" => "ForeignObject",
    110 
    111     "runtime_array" => "BridgedArray",
    112     "runtime_method" => "BridgedFunction",
    113     "runtime_object" => "BridgedObject",
    114     "objc_runtime" => "ObjCBridge",
    115 
    116     "equalIgnoringCase" => "equalFoldingCase",
    117 
    118     "FTPDirectoryTokenizer" => "FTPDirectoryDocumentBuilder",
    119     "HTMLTokenizer" => "HTMLDocumentBuilder",
    120     "ImageTokenizer" => "ImageDocumentBuilder",
    121     "PluginTokenizer" => "PluginDocumentBuilder",
    122     "TextTokenizer" => "TextDocumentBuilder",
    123     "Tokenizer" => "DocumentBuilder",
    124     "Tokenizer_h" => "DocumentBuilder_h",
    125     "XMLTokenizer" => "XMLDocumentBuilder",
    126     "isHTMLTokenizer" => "isHTMLDocumentBuilder",
    127     "m_tokenizer" => "m_builder",
    128     "createTokenizer" => "createBuilder",
    129     "tokenizerProcessedData" => "documentBuilderProcessedData",
    130 
    131     "WTF_UNICODE_H" => "Unicode_h",
    132     "WTF_UNICODE_ICU_H" => "UnicodeICU_h",
    133     "WTF_UNICODE_QT4_H" => "UnicodeQt4_h",
    134     "UnicodeIcu" => "UnicodeICU",
    135 
    136     "m_invertibleCTM" => "m_transformIsInvertible",
    137 
    138     "NativeFunctionWrapper_h" => "JSHostFunction_h",
    139     "NativeFunctionWrapper" => "JSHostFunction",
    140     "nativeFunctionThunk" => "hostFunctionThunk",
    141     "nativeFunction" => "hostFunction",
    142     "NativeFunction" => "HostFunction",
    143 );
    144 
    145 # rename files
    146 
    147 my %newFile;
    148 for my $file (sort @paths) {
    149     my $f = $file;
    150     $f = "$1$renames{$2}$3" if $f =~ /^(.*\/)(\w+)(\.\w+)$/ && $renames{$2};
    151     if ($f ne $file) {
    152         $newFile{$file} = $f;
    153     }
    154 }
    155 
    156 
    157 my $isGit = isGit();
    158 
    159 for my $file (sort @paths) {
    160     if ($newFile{$file}) {
    161         my $newFile = $newFile{$file};
    162         print "Renaming $file to $newFile\n";
    163         if ($isGit) {
    164             system "git mv $file $newFile";
    165         } else {
    166             system "svn move $file $newFile";
    167         }
    168     }
    169 }
    170 
    171 # change all file contents
    172 
    173 for my $file (sort @paths) {
    174     $file = $newFile{$file} if $newFile{$file};
    175     my $contents;
    176     {
    177         local $/;
    178         open FILE, $file or die;
    179         $contents = <FILE>;
    180         close FILE;
    181     }
    182     my $newContents = $contents;
    183 
    184     if ($isDOMTypeRename) {
    185         for my $from (keys %renames) {
    186             $newContents =~ s/\b$from/$renames{$from}/g;
    187         }
    188     } else {
    189         for my $from (keys %renames) {
    190             $newContents =~ s/\b$from(?!["\w])/$renames{$from}/g; # this " unconfuses Xcode syntax highlighting
    191         }
    192     }
    193 
    194     if ($newContents ne $contents) {
    195         open FILE, ">", $file or die;
    196         print FILE $newContents;
    197         close FILE;
    198     }
    199 }
    200