]>
Commit | Line | Data |
---|---|---|
b75a7d8f | 1 | #!/usr/bin/perl |
f3c0d7a5 A |
2 | # Copyright (C) 2016 and later: Unicode, Inc. and others. |
3 | # License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
4 | #* |
5 | #******************************************************************************* | |
51004dcb | 6 | #* Copyright (C) 2001-2012, International Business Machines |
b75a7d8f A |
7 | #* Corporation and others. All Rights Reserved. |
8 | #******************************************************************************* | |
9 | #* | |
10 | #* file name: genren.pl | |
f3c0d7a5 | 11 | #* encoding: UTF-8 |
b75a7d8f A |
12 | #* tab size: 8 (not used) |
13 | #* indentation:4 | |
14 | #* | |
15 | #* Created by: Vladimir Weinstein | |
16 | #* 07/19/2001 | |
17 | #* | |
18 | #* Used to generate renaming headers. | |
19 | #* Run on UNIX platforms (linux) in order to catch all the exports | |
20 | ||
729e4ab9 A |
21 | use POSIX qw(strftime); |
22 | ||
b75a7d8f A |
23 | $headername = 'urename.h'; |
24 | ||
25 | $path = substr($0, 0, rindex($0, "/")+1)."../../common/unicode/uversion.h"; | |
26 | ||
46f4442e A |
27 | $nmopts = '-Cg -f s'; |
28 | $post = ''; | |
29 | ||
729e4ab9 | 30 | $mode = 'POSIX'; |
46f4442e | 31 | |
b75a7d8f A |
32 | (-e $path) || die "Cannot find uversion.h"; |
33 | ||
34 | open(UVERSION, $path); | |
35 | ||
36 | while(<UVERSION>) { | |
37 | if(/\#define U_ICU_VERSION_SUFFIX/) { | |
38 | chop; | |
39 | s/\#define U_ICU_VERSION_SUFFIX //; | |
40 | $U_ICU_VERSION_SUFFIX = "$_"; | |
41 | last; | |
42 | } | |
43 | } | |
44 | ||
45 | while($ARGV[0] =~ /^-/) { # detects whether there are any arguments | |
46 | $_ = shift @ARGV; # extracts the argument for processing | |
47 | /^-v/ && ($VERBOSE++, next); # verbose | |
48 | /^-h/ && (&printHelpMsgAndExit, next); # help | |
49 | /^-o/ && (($headername = shift (@ARGV)), next); # output file | |
46f4442e A |
50 | /^-n/ && (($nmopts = shift (@ARGV)), next); # nm opts |
51 | /^-p/ && (($post = shift (@ARGV)), next); # nm opts | |
52 | /^-x/ && (($mode = shift (@ARGV)), next); # nm opts | |
b75a7d8f A |
53 | /^-S/ && (($U_ICU_VERSION_SUFFIX = shift(@ARGV)), next); # pick the suffix |
54 | warn("Invalid option $_\n"); | |
55 | &printHelpMsgAndExit; | |
56 | } | |
57 | ||
58 | unless(@ARGV > 0) { | |
59 | warn "No libraries, exiting...\n"; | |
60 | &printHelpMsgAndExit; | |
61 | } | |
62 | ||
63 | #$headername = "uren".substr($ARGV[0], 6, index(".", $ARGV[0])-7).".h"; | |
64 | ||
65 | $HEADERDEF = uc($headername); # this is building the constant for #define | |
66 | $HEADERDEF =~ s/\./_/; | |
67 | ||
68 | ||
69 | open HEADER, ">$headername"; # opening a header file | |
70 | ||
71 | #We will print our copyright here + warnings | |
729e4ab9 | 72 | |
b75a7d8f | 73 | print HEADER <<"EndOfHeaderComment"; |
0f5d89e8 A |
74 | // © 2016 and later: Unicode, Inc. and others. |
75 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
76 | /* |
77 | ******************************************************************************* | |
0f5d89e8 | 78 | * Copyright (C) 2002-2016, International Business Machines |
b75a7d8f A |
79 | * Corporation and others. All Rights Reserved. |
80 | ******************************************************************************* | |
81 | * | |
82 | * file name: $headername | |
f3c0d7a5 | 83 | * encoding: UTF-8 |
b75a7d8f A |
84 | * tab size: 8 (not used) |
85 | * indentation:4 | |
86 | * | |
51004dcb | 87 | * Created by: Perl script tools/genren.pl written by Vladimir Weinstein |
b75a7d8f A |
88 | * |
89 | * Contains data for renaming ICU exports. | |
90 | * Gets included by umachine.h | |
91 | * | |
92 | * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT | |
93 | * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN! | |
94 | */ | |
95 | ||
96 | #ifndef $HEADERDEF | |
97 | #define $HEADERDEF | |
98 | ||
51004dcb A |
99 | /* U_DISABLE_RENAMING can be defined in the following ways: |
100 | * - when running configure, e.g. | |
101 | * runConfigureICU Linux --disable-renaming | |
102 | * - by changing the default setting of U_DISABLE_RENAMING in uconfig.h | |
103 | */ | |
104 | ||
105 | #include "unicode/uconfig.h" | |
b75a7d8f A |
106 | |
107 | #if !U_DISABLE_RENAMING | |
729e4ab9 | 108 | |
3d1f044b A |
109 | // Disable Renaming for Visual Studio's IntelliSense feature, so that 'Go-to-Definition' (F12) will work. |
110 | #if !(defined(_MSC_VER) && defined(__INTELLISENSE__)) | |
111 | ||
729e4ab9 A |
112 | /* We need the U_ICU_ENTRY_POINT_RENAME definition. There's a default one in unicode/uvernum.h we can use, but we will give |
113 | the platform a chance to define it first. | |
114 | Normally (if utypes.h or umachine.h was included first) this will not be necessary as it will already be defined. | |
115 | */ | |
4388f060 | 116 | |
729e4ab9 A |
117 | #ifndef U_ICU_ENTRY_POINT_RENAME |
118 | #include "unicode/umachine.h" | |
119 | #endif | |
120 | ||
121 | /* If we still don't have U_ICU_ENTRY_POINT_RENAME use the default. */ | |
122 | #ifndef U_ICU_ENTRY_POINT_RENAME | |
123 | #include "unicode/uvernum.h" | |
124 | #endif | |
125 | ||
126 | /* Error out before the following defines cause very strange and unexpected code breakage */ | |
127 | #ifndef U_ICU_ENTRY_POINT_RENAME | |
128 | #error U_ICU_ENTRY_POINT_RENAME is not defined - cannot continue. Consider defining U_DISABLE_RENAMING if renaming should not be used. | |
129 | #endif | |
130 | ||
b75a7d8f A |
131 | EndOfHeaderComment |
132 | ||
729e4ab9 A |
133 | $fileCount = 0; |
134 | $itemCount = 0; | |
135 | $symbolCount = 0; | |
136 | ||
b75a7d8f | 137 | for(;@ARGV; shift(@ARGV)) { |
729e4ab9 | 138 | $fileCount++; |
46f4442e | 139 | @NMRESULT = `nm $nmopts $ARGV[0] $post`; |
b75a7d8f A |
140 | if($?) { |
141 | warn "Couldn't do 'nm' for $ARGV[0], continuing...\n"; | |
142 | next; # Couldn't do nm for the file | |
143 | } | |
46f4442e A |
144 | if($mode =~ /POSIX/) { |
145 | splice @NMRESULT, 0, 6; | |
146 | } elsif ($mode =~ /Mach-O/) { | |
147 | # splice @NMRESULT, 0, 10; | |
148 | } | |
b75a7d8f | 149 | foreach (@NMRESULT) { # Process every line of result and stuff it in $_ |
729e4ab9 | 150 | $itemCount++; |
46f4442e | 151 | if($mode =~ /POSIX/) { |
4388f060 | 152 | &verbose(" $_"); |
46f4442e | 153 | ($_, $address, $type) = split(/\|/); |
4388f060 | 154 | chop $qtype; |
46f4442e | 155 | } elsif ($mode =~ /Mach-O/) { |
51004dcb A |
156 | ($address, $type, $_) = split(/ /); |
157 | if(/^_(.*)$/) { | |
158 | $_ = $1; | |
46f4442e A |
159 | } else { |
160 | next; | |
161 | } | |
162 | } else { | |
163 | die "Unknown mode $mode"; | |
164 | } | |
b75a7d8f A |
165 | &verbose( "type: \"$type\" "); |
166 | if(!($type =~ /[UAwW?]/)) { | |
167 | if(/@@/) { # These would be imports | |
168 | &verbose( "Import: $_ \"$type\"\n"); | |
b75a7d8f | 169 | &verbose( "C++ method: $_\n"); |
729e4ab9 A |
170 | } elsif (/^[^\(]*::/) { # C++ methods, stuff class name in associative array |
171 | ## DON'T match ... ( foo::bar ... want :: to be to the left of paren | |
4388f060 | 172 | ## icu::CharString::~CharString(void) -> CharString |
b75a7d8f | 173 | @CppName = split(/::/); ## remove scope stuff |
4388f060 | 174 | |
b75a7d8f A |
175 | if(@CppName>1) { |
176 | ## MessageFormat virtual table -> MessageFormat | |
4388f060 A |
177 | if(! ($CppName[0] =~ /icu/ )) { |
178 | # *** WARNING Bad namespace (not 'icu') on ShoeSize::ShoeSize() | |
179 | warn "*** WARNING Bad namespace (not 'icu') on $_\n"; | |
180 | next; | |
181 | } | |
182 | &verbose ( "(Chopping scope $CppName[0] )"); | |
b75a7d8f A |
183 | @CppName = split(/ /, $CppName[1]); ## remove debug stuff |
184 | } | |
185 | ## ures_getUnicodeStringByIndex(UResourceBundle -> ures_getUnicodeStringByIndex | |
186 | @CppName = split(/\(/, $CppName[0]); ## remove function args | |
46f4442e A |
187 | if($CppName[0] =~ /^operator/) { |
188 | &verbose ("Skipping C++ function: $_\n"); | |
189 | } elsif($CppName[0] =~ /^~/) { | |
190 | &verbose ("Skipping C++ destructor: $_\n"); | |
191 | } else { | |
4388f060 A |
192 | &verbose( "Skipping C++ class: '$CppName[0]': $_ \n"); |
193 | # $CppClasses{$CppName[0]}++; | |
194 | # $symbolCount++; | |
46f4442e | 195 | } |
729e4ab9 A |
196 | } elsif ( my ($cfn) = m/^([A-Za-z0-9_]*)\(.*/ ) { |
197 | &verbose ( "$ARGV[0]: got global C++ function $cfn with '$_'\n" ); | |
198 | $CFuncs{$cfn}++; | |
199 | $symbolCount++; | |
b75a7d8f | 200 | } elsif ( /\(/) { # These are strange functions |
729e4ab9 A |
201 | print STDERR "$ARGV[0]: Not sure what to do with '$_'\n"; |
202 | } elsif ( /^_init/ ) { | |
203 | &verbose( "$ARGV[0]: Skipped initializer $_\n" ); | |
204 | } elsif ( /^_fini/ ) { | |
205 | &verbose( "$ARGV[0]: Skipped finilizer $_\n" ); | |
b75a7d8f | 206 | } elsif ( /icu_/) { |
729e4ab9 | 207 | print STDERR "$ARGV[0]: Skipped strange mangled function $_\n"; |
46f4442e | 208 | } elsif ( /^vtable for /) { |
729e4ab9 | 209 | print STDERR "$ARGV[0]: Skipped vtable $_\n"; |
4388f060 | 210 | } elsif ( /^typeinfo/) { |
729e4ab9 | 211 | print STDERR "$ARGV[0]: Skipped typeinfo $_\n"; |
46f4442e | 212 | } elsif ( /operator\+/ ) { |
729e4ab9 | 213 | print STDERR "$ARGV[0]: Skipped ignored function $_\n"; |
b75a7d8f A |
214 | } else { # This is regular C function |
215 | &verbose( "C func: $_\n"); | |
216 | @funcname = split(/[\(\s+]/); | |
217 | $CFuncs{$funcname[0]}++; | |
729e4ab9 | 218 | $symbolCount++; |
b75a7d8f A |
219 | } |
220 | } else { | |
221 | &verbose( "Skipped: $_ $1\n"); | |
222 | } | |
223 | } | |
224 | } | |
225 | ||
729e4ab9 A |
226 | if( $fileCount == 0 ) { |
227 | die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n"; | |
228 | } | |
229 | ||
230 | if( $symbolCount == 0 ) { | |
231 | die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n"; | |
232 | } | |
233 | ||
234 | print " Loaded $symbolCount symbols from $itemCount lines in $fileCount files.\n"; | |
235 | ||
b75a7d8f A |
236 | print HEADER "\n/* C exports renaming data */\n\n"; |
237 | foreach(sort keys(%CFuncs)) { | |
729e4ab9 A |
238 | print HEADER "#define $_ U_ICU_ENTRY_POINT_RENAME($_)\n"; |
239 | # print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n"; | |
b75a7d8f A |
240 | } |
241 | ||
3d1f044b A |
242 | |
243 | print HEADER <<"EndOfHeaderFooter"; | |
244 | ||
245 | #endif /* !(defined(_MSC_VER) && defined(__INTELLISENSE__)) */ | |
246 | #endif /* U_DISABLE_RENAMING */ | |
247 | #endif /* URENAME_H */ | |
248 | ||
249 | EndOfHeaderFooter | |
250 | ||
b75a7d8f A |
251 | |
252 | close HEADER; | |
253 | ||
254 | sub verbose { | |
255 | if($VERBOSE) { | |
256 | print STDERR @_; | |
257 | } | |
258 | } | |
259 | ||
260 | ||
261 | sub printHelpMsgAndExit { | |
262 | print STDERR <<"EndHelpText"; | |
263 | Usage: $0 [OPTIONS] LIBRARY_FILES | |
264 | Options: | |
265 | -v - verbose | |
266 | -h - help | |
267 | -o - output file name (defaults to 'urename.h' | |
268 | -S - suffix (defaults to _MAJOR_MINOR of current ICU version) | |
269 | Will produce a renaming .h file | |
270 | ||
271 | EndHelpText | |
272 | ||
273 | exit 0; | |
274 | ||
275 | } |