2 # Copyright 1999, 2000, 2001 Patrik Stridvall
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 package winapi_function
;
20 use base
qw(function);
24 use config
qw($current_dir $wine_dir);
25 use util qw(normalize_set);
28 use vars
qw($modules $win16api $win32api @winapis);
30 ########################################################################
36 my $class = ref($proto) || $proto;
38 bless ($self, $class);
42 import modules qw($modules);
45 import winapi qw($win16api $win32api @winapis);
52 ########################################################################
56 sub is_win16($) { my $self = shift; return defined($self->_module($win16api, @_)); }
57 sub is_win32($) { my $self = shift; return defined($self->_module($win32api, @_)); }
59 ########################################################################
63 sub _external_name($$) {
67 my $file = $self->file;
68 my $internal_name = $self->internal_name;
70 my $external_name = $winapi->function_external_name($internal_name);
71 my $module = $winapi->function_internal_module($internal_name);
73 if(!defined($external_name) && !defined($module)) {
77 my @external_names = split(/\s*&\s*/, $external_name);
78 my @modules = split(/\s*&\s*/, $module);
81 while(defined(my $external_name = shift @external_names) &&
82 defined(my $module = shift @modules))
84 if($modules->is_allowed_module_in_file($module, "$current_dir/$file")) {
85 push @external_names2, $external_name;
89 return join(" & ", @external_names2);
92 sub _external_names($$) {
96 my $external_name = $self->_external_name($winapi);
98 if(defined($external_name)) {
99 return split(/\s*&\s*/, $external_name);
105 sub external_name($) {
108 foreach my $winapi (@winapis) {
109 my $external_name = $self->_external_name($winapi, @_);
111 if(defined($external_name)) {
112 return $external_name;
119 sub external_name16($) { my $self = shift; return $self->_external_name($win16api, @_); }
120 sub external_name32($) { my $self = shift; return $self->_external_name($win32api, @_); }
122 sub external_names16($) { my $self = shift; return $self->_external_names($win16api, @_); }
123 sub external_names32($) { my $self = shift; return $self->_external_names($win32api, @_); }
125 sub external_names($) { my $self = shift; return ($self->external_names16, $self->external_names32); }
127 ########################################################################
135 my $file = $self->file;
136 my $internal_name = $self->internal_name;
138 my $module = $winapi->function_internal_module($internal_name);
139 if(!defined($module)) {
143 if(!defined($file)) {
148 foreach my $module (split(/\s*&\s*/, $module)) {
149 if($modules->is_allowed_module_in_file($module, "$current_dir/$file")) {
150 push @modules, $module;
154 return join(" & ", @modules);
161 my $module = $self->_module($winapi);
163 if(defined($module)) {
164 return split(/\s*&\s*/, $module);
170 sub module16($) { my $self = shift; return $self->_module($win16api, @_); }
171 sub module32($) { my $self = shift; return $self->_module($win32api, @_); }
173 sub module($) { my $self = shift; return join (" & ", $self->modules); }
175 sub modules16($) { my $self = shift; return $self->_modules($win16api, @_); }
176 sub modules32($) { my $self = shift; return $self->_modules($win32api, @_); }
178 sub modules($) { my $self = shift; return ($self->modules16, $self->modules32); }
180 ########################################################################
188 my $file = $self->file;
189 my $internal_name = $self->internal_name;
191 my $ordinal = $winapi->function_internal_ordinal($internal_name);
192 my $module = $winapi->function_internal_module($internal_name);
194 if(!defined($ordinal) && !defined($module)) {
198 my @ordinals = split(/\s*&\s*/, $ordinal);
199 my @modules = split(/\s*&\s*/, $module);
202 while(defined(my $ordinal = shift @ordinals) &&
203 defined(my $module = shift @modules))
205 if($modules->is_allowed_module_in_file($module, "$current_dir/$file")) {
206 push @ordinals2, $ordinal;
210 return join(" & ", @ordinals2);
217 my $ordinal = $self->_ordinal($winapi);
219 if(defined($ordinal)) {
220 return split(/\s*&\s*/, $ordinal);
226 sub ordinal16($) { my $self = shift; return $self->_ordinal($win16api, @_); }
227 sub ordinal32($) { my $self = shift; return $self->_ordinal($win32api, @_); }
229 sub ordinal($) { my $self = shift; return join (" & ", $self->ordinals); }
231 sub ordinals16($) { my $self = shift; return $self->_ordinals($win16api, @_); }
232 sub ordinals32($) { my $self = shift; return $self->_ordinals($win32api, @_); }
234 sub ordinals($) { my $self = shift; return ($self->ordinals16, $self->ordinals32); }
236 ########################################################################
242 my $module16 = $self->module16;
243 my $module32 = $self->module32;
245 my $file = $self->file;
246 my $function_line = $self->function_line;
247 my $return_type = $self->return_type;
248 my $internal_name = $self->internal_name;
249 my $calling_convention = $self->calling_convention;
251 my $refargument_types = $self->argument_types;
252 my @argument_types = ();
253 if(defined($refargument_types)) {
254 @argument_types = @$refargument_types;
255 if($#argument_types < 0) {
256 @argument_types = ("void");
264 foreach my $module ($self->modules) {
265 if($used{$module}) { next; }
266 push @modules, $module;
270 if(defined($function_line)) {
271 $prefix .= "$function_line: ";
276 $prefix .= join(" & ", @modules) . ": ";
280 $prefix .= "$return_type ";
281 $prefix .= "$calling_convention " if $calling_convention;
282 $prefix .= "$internal_name(" . join(",", @argument_types) . "): ";
287 ########################################################################
291 sub calling_convention16($) {
293 my $return_kind16 = $self->return_kind16;
296 if(!defined($return_kind16)) {
298 } elsif($return_kind16 =~ /^(?:void|s_word|word)$/) {
300 } elsif($return_kind16 =~ /^(?:long|ptr|segptr|segstr|str|wstr)$/) {
306 local $_ = $self->calling_convention;
307 if($_ eq "__cdecl") {
309 } elsif(/^(?:VFWAPIV|WINAPIV)$/) {
310 if(!defined($suffix)) { return undef; }
311 return "pascal$suffix"; # FIXME: Is this correct?
312 } elsif(/^(?:__stdcall|__RPC_STUB|__RPC_USER|NET_API_FUNCTION|RPC_ENTRY|VFWAPI|WINAPI|CALLBACK)$/) {
313 if(!defined($suffix)) { return undef; }
314 return "pascal$suffix";
315 } elsif($_ eq "__asm") {
322 sub calling_convention32($) {
325 local $_ = $self->calling_convention;
326 if($_ eq "__cdecl") {
328 } elsif(/^(?:VFWAPIV|WINAPIV)$/) {
330 } elsif(/^(?:__stdcall|__RPC_STUB|__RPC_USER|NET_API_FUNCTION|RPC_ENTRY|VFWAPI|WINAPI|CALLBACK)$/) {
332 } elsif($_ eq "__asm") {
339 sub get_all_module_ordinal16($) {
341 my $internal_name = $self->internal_name;
343 return winapi::get_all_module_internal_ordinal16($internal_name);
346 sub get_all_module_ordinal32($) {
348 my $internal_name = $self->internal_name;
350 return winapi::get_all_module_internal_ordinal32($internal_name);
353 sub get_all_module_ordinal($) {
355 my $internal_name = $self->internal_name;
357 return winapi::get_all_module_internal_ordinal($internal_name);
360 sub _return_kind($$) {
363 my $return_type = $self->return_type;
365 return $winapi->translate_argument($return_type);
368 sub return_kind16($) {
369 my $self = shift; return $self->_return_kind($win16api, @_);
372 sub return_kind32($) {
373 my $self = shift; return $self->_return_kind($win32api, @_);
376 sub _argument_kinds($$) {
379 my $refargument_types = $self->argument_types;
381 if(!defined($refargument_types)) {
386 foreach my $argument_type (@$refargument_types) {
387 my $argument_kind = $winapi->translate_argument($argument_type);
389 if(defined($argument_kind) && $argument_kind eq "longlong") {
390 push @argument_kinds, "double";
392 push @argument_kinds, $argument_kind;
396 return [@argument_kinds];
399 sub argument_kinds16($) {
400 my $self = shift; return $self->_argument_kinds($win16api, @_);
403 sub argument_kinds32($) {
404 my $self = shift; return $self->_argument_kinds($win32api, @_);
407 ##############################################################################
411 sub function_called($$) {
413 my $called_function_names = \%{$self->{CALLED_FUNCTION_NAMES}};
417 $$called_function_names{$name}++;
420 sub function_called_by($$) {
422 my $called_by_function_names = \%{$self->{CALLED_BY_FUNCTION_NAMES}};
426 $$called_by_function_names{$name}++;
429 sub called_function_names($) {
431 my $called_function_names = \%{$self->{CALLED_FUNCTION_NAMES}};
433 return sort(keys(%$called_function_names));
436 sub called_by_function_names($) {
438 my $called_by_function_names = \%{$self->{CALLED_BY_FUNCTION_NAMES}};
440 return sort(keys(%$called_by_function_names));