msvcmaker: Add support for building wine.lib.
[wine] / tools / winapi / winapi.pm
1 #
2 # Copyright 1999, 2000, 2001 Patrik Stridvall
3 #
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.
8 #
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.
13 #
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
17 #
18
19 package winapi;
20
21 use strict;
22
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
24 require Exporter;
25
26 @ISA = qw(Exporter);
27 @EXPORT = qw();
28 @EXPORT_OK = qw($win16api $win32api @winapis);
29
30 use vars qw($win16api $win32api @winapis);
31
32 use config qw($current_dir $wine_dir $winapi_dir);
33 use options qw($options);
34 use output qw($output);
35
36 use vars qw($modules);
37
38 sub found_shared_internal_function($$);
39 sub function_external_calling_convention_in_module($$$);
40 sub function_internal_module($$);
41 sub is_function_stub_in_module($$$);
42 sub new($$$);
43 sub parse_api_file($$);
44 sub parse_spec_file($$);
45
46 sub import(@) {
47     $Exporter::ExportLevel++;
48     Exporter::import(@_);
49     $Exporter::ExportLevel--;
50
51     if (defined($modules) && defined($win16api) && defined($win32api)) {
52         return;
53     }
54
55     require modules;
56     import modules qw($modules);
57
58     my @spec_files16 = $modules->allowed_spec_files16;
59     $win16api = 'winapi'->new("win16", \@spec_files16);
60
61     my @spec_files32 = $modules->allowed_spec_files32;
62     $win32api = 'winapi'->new("win32", \@spec_files32);
63
64     @winapis = ($win16api, $win32api);
65
66     for my $internal_name ($win32api->all_internal_functions) {
67         my $module16 = $win16api->function_internal_module($internal_name);
68         my $module32 = $win16api->function_internal_module($internal_name);
69         if(defined($module16) &&
70            !$win16api->is_function_stub_in_module($module16, $internal_name) &&
71            !$win32api->is_function_stub_in_module($module32, $internal_name))
72         {
73             $win16api->found_shared_internal_function($internal_name);
74             $win32api->found_shared_internal_function($internal_name);
75         }
76     }
77 }
78
79
80 sub new($$$) {
81     my $proto = shift;
82     my $class = ref($proto) || $proto;
83     my $self  = {};
84     bless ($self, $class);
85
86     my $name = \${$self->{NAME}};
87     my $function_forward = \%{$self->{FUNCTION_FORWARD}};
88     my $function_internal_name = \%{$self->{FUNCTION_INTERNAL_NAME}};
89     my $function_module = \%{$self->{FUNCTION_MODULE}};
90
91     $$name = shift;
92     my $refspec_files = shift;
93
94     foreach my $file (@$refspec_files) {
95         $self->parse_spec_file("$wine_dir/$file");
96     }
97
98     $self->parse_api_file("$$name.api");
99
100     foreach my $module (sort(keys(%$function_forward))) {
101         foreach my $external_name (sort(keys(%{$$function_forward{$module}}))) {
102             (my $forward_module, my $forward_external_name) = @{$$function_forward{$module}{$external_name}};
103             my $forward_internal_name = $$function_internal_name{$forward_external_name};
104             if(defined($forward_internal_name)) {
105                 $$function_module{$forward_internal_name} .= " & $module";
106             }
107         }
108     }
109
110     return $self;
111 }
112
113 sub win16api() {
114     return $win16api;
115 }
116
117 sub win32api() {
118     return $win32api;
119 }
120
121 sub parse_api_file($$) {
122     my $self = shift;
123
124     my $allowed_kind = \%{$self->{ALLOWED_KIND}};
125     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
126     my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
127     my $allowed_modules_unlimited = \%{$self->{ALLOWED_MODULES_UNLIMITED}};
128     my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
129     my $type_format = \%{$self->{TYPE_FORMAT}};
130
131     my $file = shift;
132
133     my $module;
134     my $kind;
135     my $format;
136     my $forbidden = 0;
137
138     $output->lazy_progress("$file");
139
140     open(IN, "< $winapi_dir/$file") || die "$winapi_dir/$file: $!\n";
141     $/ = "\n";
142     my $linenum=0;
143     while(<IN>) {
144         $linenum++;
145         s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begin and end of line
146         s/^(.*?)\s*#.*$/$1/;  # remove comments
147         /^$/ && next;         # skip empty lines
148
149         if(/^%%(\S+)$/) {
150             $module = $1;
151             $module =~ s/\.dll$//; # FIXME: Kludge
152         } elsif(!$modules->is_allowed_module($module)) {
153             # Nothing
154         } elsif(s/^%(\S+)\s*//) {
155             $kind = $1;
156             $format = undef;
157             $forbidden = 0;
158
159             $$allowed_kind{$kind} = 1;
160             if(/^--forbidden/) {
161                 $forbidden = 1;
162             } elsif(/^--format=(\".*?\"|\S*)/) {
163                 $format = $1;
164                 $format =~ s/^\"(.*?)\"$/$1/;
165             }
166
167             if(!defined($format)) {
168                 if($kind eq "long") {
169                     $format  = "%d|%u|%x|%X|";
170                     $format .= "%hd|%hu|%hx|%hX|";
171                     $format .= "%ld|%lu|%lx|%lX|";
172                     $format .= "%04x|%04X|0x%04x|0x%04X|";
173                     $format .= "%08x|%08X|0x%08x|0x%08X|";
174                     $format .= "%08lx|%08lX|0x%08lx|0x%08lX";
175                 } elsif($kind eq "longlong") {
176                     $format = "%lld";
177                 } elsif($kind eq "ptr") {
178                     $format = "%p";
179                 } elsif($kind eq "segptr") {
180                     $format = "%p";
181                 } elsif($kind eq "str") {
182                     $format = "%p|%s";
183                 } elsif($kind eq "wstr") {
184                     $format = "%p|%s";
185                 } elsif($kind eq "word") {
186                     $format  = "%d|%u|%x|%X|";
187                     $format .= "%hd|%hu|%hx|%hX|";
188                     $format .= "%04x|%04X|0x%04x|0x%04X";
189                 } else {
190                     $format = "<unknown>";
191                 }
192             }
193         } elsif(defined($kind)) {
194             my $type = $_;
195             if ($type =~ /\blong\b/)
196             {
197                 $output->write("$file:$linenum: type ($type) is not Win64 compatible\n");
198             }
199             if(!$forbidden) {
200                 if(defined($module)) {
201                     if($$allowed_modules_unlimited{$type}) {
202                         $output->write("$file:$linenum: type ($type) already specified as an unlimited type\n");
203                     } elsif(!$$allowed_modules{$type}{$module}) {
204                         $$allowed_modules{$type}{$module} = 1;
205                         $$allowed_modules_limited{$type} = 1;
206                     } else {
207                         $output->write("$file:$linenum: type ($type) already specified\n");
208                     }
209                 } else {
210                     $$allowed_modules_unlimited{$type} = 1;
211                 }
212             } else {
213                 $$allowed_modules_limited{$type} = 1;
214             }
215             if(defined($$translate_argument{$type}) && $$translate_argument{$type} ne $kind) {
216                 $output->write("$file:$linenum: type ($type) respecified as different kind ($kind != $$translate_argument{$type})\n");
217             } else {
218                 $$translate_argument{$type} = $kind;
219             }
220
221             $$type_format{$module}{$type} = $format;
222         } else {
223             $output->write("$file:$linenum: file must begin with %<type> statement\n");
224             exit 1;
225         }
226     }
227     close(IN);
228 }
229
230 sub parse_spec_file($$) {
231     my $self = shift;
232
233     my $function_internal_arguments = \%{$self->{FUNCTION_INTERNAL_ARGUMENTS}};
234     my $function_external_arguments = \%{$self->{FUNCTION_EXTERNAL_ARGUMENTS}};
235     my $function_internal_ordinal = \%{$self->{FUNCTION_INTERNAL_ORDINAL}};
236     my $function_external_ordinal = \%{$self->{FUNCTION_EXTERNAL_ORDINAL}};
237     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
238     my $function_external_calling_convention = \%{$self->{FUNCTION_EXTERNAL_CALLING_CONVENTION}};
239     my $function_internal_name = \%{$self->{FUNCTION_INTERNAL_NAME}};
240     my $function_external_name = \%{$self->{FUNCTION_EXTERNAL_NAME}};
241     my $function_forward = \%{$self->{FUNCTION_FORWARD}};
242     my $function_internal_module = \%{$self->{FUNCTION_INTERNAL_MODULE}};
243     my $function_external_module = \%{$self->{FUNCTION_EXTERNAL_MODULE}};
244     my $function_wine_extension = \%{$self->{FUNCTION_WINE_EXTENSION}};
245     my $modules = \%{$self->{MODULES}};
246     my $module_files = \%{$self->{MODULE_FILES}};
247     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
248
249     my $file = shift;
250     $file =~ s%^\./%%;
251
252     my %ordinals;
253     my $module;
254     my $wine_extension = 0;
255
256     $output->lazy_progress("$file");
257
258     $module = $file;
259     $module =~ s/^.*?([^\/]*)\.spec$/$1/;
260
261     open(IN, "< $file") || die "$file: $!\n";
262     $/ = "\n";
263     my $header = 1;
264     my $lookahead = 0;
265     while($lookahead || defined($_ = <IN>)) {
266         $lookahead = 0;
267         s/^\s*(.*?)\s*$/$1/;
268         if(s/^(.*?)\s*\#\s*(.*)\s*$/$1/) {
269             my $comment = $2;
270             if ($comment =~ /^Wine/i) { # FIXME: Kludge
271                 $wine_extension = 1;
272             }
273         }
274         /^$/ && next;
275
276         if($header)  {
277             if(/^\d+|@/) { $header = 0; $lookahead = 1; }
278             next;
279         }
280
281         my $ordinal;
282         if(/^(\d+|@)\s+
283            (pascal|stdcall|cdecl|varargs)\s+
284            ((?:(?:-noname|-norelay|-i386|-ret16|-ret64|-register|-interrupt|-private)\s+)*)(\S+)\s*\(\s*(.*?)\s*\)\s*(\S*)$/x)
285         {
286             my $calling_convention = $2;
287             my $flags = $3;
288             my $external_name = $4;
289             my $arguments = $5;
290             my $internal_name = $6;
291
292             $ordinal = $1;
293
294             $flags =~ s/\s+/ /g;
295
296             if (!$internal_name)
297             {
298                 $internal_name = ($flags =~ /-register/ ? "__regs_" : "") . $external_name;
299             }
300
301             if($flags =~ /-noname/) {
302                 # $external_name = "@";
303             }
304
305             if($flags =~ /(?:-register|-interrupt)/) {
306                 if($arguments) { $arguments .= " "; }
307                 $arguments .= "ptr";
308                 $calling_convention .= " -register";
309             }
310             if($flags =~ /(?:-i386)/) {
311                 $calling_convention .= " -i386";
312             }
313
314             if ($internal_name =~ /^(.*?)\.(.*?)$/) {
315                 my $forward_module = lc($1);
316                 my $forward_name = $2;
317
318                 if (0) {
319                     $calling_convention .= " -forward";
320                 } else {
321                     $calling_convention = "forward";
322                 }
323
324                 $$function_forward{$module}{$external_name} = [$forward_module, $forward_name];
325             }
326
327             if($external_name ne "@") {
328                 $$module_external_calling_convention{$module}{$external_name} = $calling_convention;
329             } else {
330                 $$module_external_calling_convention{$module}{"\@$ordinal"} = $calling_convention;
331             }
332             if(!$$function_internal_name{$external_name}) {
333                 $$function_internal_name{$external_name} = $internal_name;
334             } else {
335                 $$function_internal_name{$external_name} .= " & $internal_name";
336             }
337             if(!$$function_external_name{$internal_name}) {
338                 $$function_external_name{$internal_name} = $external_name;
339             } else {
340                 $$function_external_name{$internal_name} .= " & $external_name";
341             }
342             $$function_internal_arguments{$internal_name} = $arguments;
343             $$function_external_arguments{$external_name} = $arguments;
344             if(!$$function_internal_ordinal{$internal_name}) {
345                 $$function_internal_ordinal{$internal_name} = $ordinal;
346             } else {
347                 $$function_internal_ordinal{$internal_name} .= " & $ordinal";
348             }
349             if(!$$function_external_ordinal{$external_name}) {
350                 $$function_external_ordinal{$external_name} = $ordinal;
351             } else {
352                 $$function_external_ordinal{$external_name} .= " & $ordinal";
353             }
354             $$function_internal_calling_convention{$internal_name} = $calling_convention;
355             $$function_external_calling_convention{$external_name} = $calling_convention;
356             if(!$$function_internal_module{$internal_name}) {
357                 $$function_internal_module{$internal_name} = "$module";
358             } else {
359                 $$function_internal_module{$internal_name} .= " & $module";
360             }
361             if(!$$function_external_module{$external_name}) {
362                 $$function_external_module{$external_name} = "$module";
363             } else {
364                 $$function_external_module{$external_name} .= " & $module";
365             }
366             $$function_wine_extension{$module}{$external_name} = $wine_extension;
367
368             if(0 && $options->spec_mismatch) {
369                 if($external_name eq "@") {
370                     if($internal_name !~ /^\U$module\E_$ordinal$/) {
371                         $output->write("$file: $external_name: the internal name ($internal_name) mismatch\n");
372                     }
373                 } else {
374                     my $name = $external_name;
375
376                     my $name1 = $name;
377                     $name1 =~ s/^Zw/Nt/;
378
379                     my $name2 = $name;
380                     $name2 =~ s/^(?:_|Rtl|k32|K32)//;
381
382                     my $name3 = $name;
383                     $name3 =~ s/^INT_Int[0-9a-f]{2}Handler$/BUILTIN_DefaultIntHandler/;
384
385                     my $name4 = $name;
386                     $name4 =~ s/^(VxDCall)\d$/$1/;
387
388                     # FIXME: This special case is because of a very ugly kludge that should be fixed IMHO
389                     my $name5 = $name;
390                     $name5 =~ s/^(.*?16)_(.*?)$/$1_fn$2/;
391
392                     if(uc($internal_name) ne uc($external_name) &&
393                        $internal_name !~ /(\Q$name\E|\Q$name1\E|\Q$name2\E|\Q$name3\E|\Q$name4\E|\Q$name5\E)/)
394                     {
395                         $output->write("$file: $external_name: internal name ($internal_name) mismatch\n");
396                     }
397                 }
398             }
399         } elsif(/^(\d+|@)\s+stub(?:\s+(-noname|-norelay|-i386|-ret16|-ret64|-private))?\s+(\S+)$/) {
400             $ordinal = $1;
401
402             my $flags = $2;
403             my $external_name = $3;
404
405             $flags = "" if !defined($flags);
406
407             if($flags =~ /-noname/) {
408                 # $external_name = "@";
409             }
410
411             my $internal_name = $external_name;
412
413             if ($external_name ne "@") {
414                 $$module_external_calling_convention{$module}{$external_name} = "stub";
415             } else {
416                 $$module_external_calling_convention{$module}{"\@$ordinal"} = "stub";
417             }
418             if(!$$function_internal_name{$external_name}) {
419                 $$function_internal_name{$external_name} = $internal_name;
420             } else {
421                 $$function_internal_name{$external_name} .= " & $internal_name";
422             }
423             if(!$$function_external_name{$internal_name}) {
424                 $$function_external_name{$internal_name} = $external_name;
425             } else {
426                 $$function_external_name{$internal_name} .= " & $external_name";
427             }
428             if(!$$function_internal_ordinal{$internal_name}) {
429                 $$function_internal_ordinal{$internal_name} = $ordinal;
430             } else {
431                 $$function_internal_ordinal{$internal_name} .= " & $ordinal";
432             }
433             if(!$$function_external_ordinal{$external_name}) {
434                 $$function_external_ordinal{$external_name} = $ordinal;
435             } else {
436                 $$function_external_ordinal{$external_name} .= " & $ordinal";
437             }
438             if(!$$function_internal_module{$internal_name}) {
439                 $$function_internal_module{$internal_name} = "$module";
440             } else { # if($$function_internal_module{$internal_name} !~ /$module/) {
441                 $$function_internal_module{$internal_name} .= " & $module";
442             }
443             if(!$$function_external_module{$external_name}) {
444                 $$function_external_module{$external_name} = "$module";
445             } else { # if($$function_external_module{$external_name} !~ /$module/) {
446                 $$function_external_module{$external_name} .= " & $module";
447             }
448         } elsif(/^(\d+|@)\s+extern(?:\s+(?:-norelay|-i386|-ret16|-ret64))?\s+(\S+)\s*(\S*)$/) {
449             $ordinal = $1;
450
451             my $external_name = $2;
452             my $internal_name = $3;
453
454             $internal_name = $external_name if !$internal_name;
455
456             if ($external_name ne "@") {
457                 $$module_external_calling_convention{$module}{$external_name} = "extern";
458             } else {
459                 $$module_external_calling_convention{$module}{"\@$ordinal"} = "extern";
460             }
461         } elsif(/^(?:\d+|@)\s+(?:equate|variable)/) {
462             # ignore
463         } else {
464             my $next_line = <IN>;
465             if(!defined($next_line) || $next_line =~ /^\s*\d|@/) {
466                 die "$file: $.: syntax error: '$_'\n";
467             } else {
468                 $_ .= $next_line;
469                 $lookahead = 1;
470             }
471         }
472
473         if(defined($ordinal)) {
474             if($ordinal ne "@" && $ordinals{$ordinal}) {
475                 $output->write("$file: ordinal redefined: $_\n");
476             }
477             $ordinals{$ordinal}++;
478         }
479     }
480     close(IN);
481
482     $$modules{$module}++;
483
484     $$module_files{$module} = $file;
485 }
486
487 sub name($) {
488     my $self = shift;
489     my $name = \${$self->{NAME}};
490
491     return $$name;
492 }
493
494 sub is_allowed_kind($$) {
495     my $self = shift;
496     my $allowed_kind = \%{$self->{ALLOWED_KIND}};
497
498     my $kind = shift;
499     if(defined($kind)) {
500         return $$allowed_kind{$kind};
501     } else {
502         return 0;
503     }
504
505 }
506
507 sub allow_kind($$) {
508     my $self = shift;
509     my $allowed_kind = \%{$self->{ALLOWED_KIND}};
510
511     my $kind = shift;
512
513     $$allowed_kind{$kind}++;
514 }
515
516 sub is_limited_type($$) {
517     my $self = shift;
518     my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
519
520     my $type = shift;
521
522     return $$allowed_modules_limited{$type};
523 }
524
525 sub is_allowed_type_in_module($$) {
526     my $self = shift;
527     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
528     my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
529
530     my $type = shift;
531     my @modules = split(/ \& /, shift);
532
533     if(!$$allowed_modules_limited{$type}) { return 1; }
534
535     foreach my $module (@modules) {
536         if($$allowed_modules{$type}{$module}) { return 1; }
537     }
538
539     return 0;
540 }
541
542 sub allow_type_in_module($$) {
543     my $self = shift;
544     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
545
546     my $type = shift;
547     my @modules = split(/ \& /, shift);
548
549     foreach my $module (@modules) {
550         $$allowed_modules{$type}{$module}++;
551     }
552 }
553
554 sub type_used_in_module($$) {
555     my $self = shift;
556     my $used_modules = \%{$self->{USED_MODULES}};
557
558     my $type = shift;
559     my @modules = split(/ \& /, shift);
560
561     foreach my $module (@modules) {
562         $$used_modules{$type}{$module} = 1;
563     }
564
565     return ();
566 }
567
568 sub types_not_used($) {
569     my $self = shift;
570     my $used_modules = \%{$self->{USED_MODULES}};
571     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
572
573     my $not_used;
574     foreach my $type (sort(keys(%$allowed_modules))) {
575         foreach my $module (sort(keys(%{$$allowed_modules{$type}}))) {
576             if(!$$used_modules{$type}{$module}) {
577                 $$not_used{$module}{$type} = 1;
578             }
579         }
580     }
581     return $not_used;
582 }
583
584 sub types_unlimited_used_in_modules($) {
585     my $self = shift;
586
587     my $used_modules = \%{$self->{USED_MODULES}};
588     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
589     my $allowed_modules_unlimited = \%{$self->{ALLOWED_MODULES_UNLIMITED}};
590
591     my $used_types;
592     foreach my $type (sort(keys(%$allowed_modules_unlimited))) {
593         my $count = 0;
594         my @modules = ();
595         foreach my $module (sort(keys(%{$$used_modules{$type}}))) {
596             $count++;
597             push @modules, $module;
598         }
599         if($count) {
600             foreach my $module (@modules) {
601               $$used_types{$type}{$module} = 1;
602             }
603         }
604     }
605     return $used_types;
606 }
607
608 sub translate_argument($$) {
609     my $self = shift;
610     my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
611
612     my $type = shift;
613
614     return $$translate_argument{$type};
615 }
616
617 sub declare_argument($$$) {
618     my $self = shift;
619     my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
620
621     my $type = shift;
622     my $kind = shift;
623
624     $$translate_argument{$type} = $kind;
625 }
626
627 sub all_declared_types($) {
628     my $self = shift;
629     my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
630
631     return sort(keys(%$translate_argument));
632 }
633
634 sub is_allowed_type_format($$$$) {
635     my $self = shift;
636     my $type_format = \%{$self->{TYPE_FORMAT}};
637
638     my $module = shift;
639     my $type = shift;
640     my $format = shift;
641
642     my $formats;
643
644     if(defined($module) && defined($type)) {
645         local $_;
646         foreach (split(/ & /, $module)) {
647             if(defined($formats)) {
648                 $formats .= "|";
649             } else {
650                 $formats = "";
651             }
652             if(defined($$type_format{$_}{$type})) {
653                 $formats .= $$type_format{$_}{$type};
654             }
655         }
656     }
657
658     if(defined($formats)) {
659         local $_;
660         foreach (split(/\|/, $formats)) {
661             if($_ eq $format) {
662                 return 1;
663             }
664         }
665     }
666
667     return 0;
668 }
669
670 sub all_modules($) {
671     my $self = shift;
672     my $modules = \%{$self->{MODULES}};
673
674     return sort(keys(%$modules));
675 }
676
677 sub is_module($$) {
678     my $self = shift;
679     my $modules = \%{$self->{MODULES}};
680
681     my $name = shift;
682
683     return $$modules{$name};
684 }
685
686 sub module_file($$) {
687     my $self = shift;
688
689     my $module = shift;
690
691     my $module_files = \%{$self->{MODULE_FILES}};
692
693     return $$module_files{$module};
694 }
695
696 sub all_internal_functions($) {
697     my $self = shift;
698     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
699
700     return sort(keys(%$function_internal_calling_convention));
701 }
702
703 sub all_internal_functions_in_module($$) {
704     my $self = shift;
705     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
706     my $function_internal_module = \%{$self->{FUNCTION_INTERNAL_MODULE}};
707
708     my $module = shift;
709
710     my @names;
711     foreach my $name (keys(%$function_internal_calling_convention)) {
712         if($$function_internal_module{$name} eq $module) {
713             push @names, $name;
714         }
715     }
716
717     return sort(@names);
718 }
719
720 sub all_external_functions($) {
721     my $self = shift;
722     my $function_external_name = \%{$self->{FUNCTION_EXTERNAL_NAME}};
723
724     return sort(keys(%$function_external_name));
725 }
726
727 sub all_external_functions_in_module($$) {
728     my $self = shift;
729     my $function_external_name = \%{$self->{FUNCTION_EXTERNAL_NAME}};
730     my $function_external_module = \%{$self->{FUNCTION_EXTERNAL_MODULE}};
731
732     my $module = shift;
733
734     my @names;
735     foreach my $name (keys(%$function_external_name)) {
736         if($$function_external_module{$name} eq $module) {
737             push @names, $name;
738         }
739     }
740
741     return sort(@names);
742 }
743
744 sub all_functions_in_module($$) {
745     my $self = shift;
746     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
747
748     my $module = shift;
749
750     return sort(keys(%{$$module_external_calling_convention{$module}}));
751 }
752
753 sub all_broken_forwards($) {
754     my $self = shift;
755     my $function_forward = \%{$self->{FUNCTION_FORWARD}};
756
757     my @broken_forwards = ();
758     foreach my $module (sort(keys(%$function_forward))) {
759         foreach my $external_name (sort(keys(%{$$function_forward{$module}}))) {
760             (my $forward_module, my $forward_external_name) = @{$$function_forward{$module}{$external_name}};
761
762             my $forward_external_calling_convention =
763                 $self->function_external_calling_convention_in_module($forward_module, $forward_external_name);
764
765             if(!defined($forward_external_calling_convention)) {
766                 push @broken_forwards, [$module, $external_name, $forward_module, $forward_external_name];
767             }
768         }
769     }
770     return @broken_forwards;
771 }
772
773
774 sub function_internal_ordinal($$) {
775     my $self = shift;
776     my $function_internal_ordinal = \%{$self->{FUNCTION_INTERNAL_ORDINAL}};
777
778     my $name = shift;
779
780     return $$function_internal_ordinal{$name};
781 }
782
783 sub function_external_ordinal($$) {
784     my $self = shift;
785     my $function_external_ordinal = \%{$self->{FUNCTION_EXTERNAL_ORDINAL}};
786
787     my $name = shift;
788
789     return $$function_external_ordinal{$name};
790 }
791
792 sub function_internal_calling_convention($$) {
793     my $self = shift;
794     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
795
796     my $name = shift;
797
798     return $$function_internal_calling_convention{$name};
799 }
800
801 sub function_external_calling_convention($$) {
802     my $self = shift;
803     my $function_external_calling_convention = \%{$self->{FUNCTION_EXTERNAL_CALLING_CONVENTION}};
804
805     my $name = shift;
806
807     return $$function_external_calling_convention{$name};
808 }
809
810 sub function_external_calling_convention_in_module($$$) {
811     my $self = shift;
812     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
813
814     my $module = shift;
815     my $name = shift;
816
817     return $$module_external_calling_convention{$module}{$name};
818 }
819
820 sub function_internal_name($$) {
821     my $self = shift;
822     my $function_internal_name = \%{$self->{FUNCTION_INTERNAL_NAME}};
823
824     my $name = shift;
825
826     return $$function_internal_name{$name};
827 }
828
829 sub function_external_name($$) {
830     my $self = shift;
831     my $function_external_name = \%{$self->{FUNCTION_EXTERNAL_NAME}};
832
833     my $name = shift;
834
835     return $$function_external_name{$name};
836 }
837
838 sub function_forward_final_destination($$$) {
839     my $self = shift;
840
841     my $function_forward = \%{$self->{FUNCTION_FORWARD}};
842
843     my $module = shift;
844     my $name = shift;
845
846     my $forward_module = $module;
847     my $forward_name = $name;
848     while(defined(my $forward = $$function_forward{$forward_module}{$forward_name})) {
849         ($forward_module, $forward_name) = @$forward;
850     }
851
852     return ($forward_module, $forward_name);
853 }
854
855 sub is_function($$) {
856     my $self = shift;
857     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
858
859     my $name = shift;
860
861     return $$function_internal_calling_convention{$name};
862 }
863
864 sub all_shared_internal_functions($$) {
865     my $self = shift;
866     my $function_shared = \%{$self->{FUNCTION_SHARED}};
867
868     return sort(keys(%$function_shared));
869 }
870
871 sub is_shared_internal_function($$) {
872     my $self = shift;
873     my $function_shared = \%{$self->{FUNCTION_SHARED}};
874
875     my $name = shift;
876
877     return $$function_shared{$name};
878 }
879
880 sub found_shared_internal_function($$) {
881     my $self = shift;
882     my $function_shared = \%{$self->{FUNCTION_SHARED}};
883
884     my $name = shift;
885
886     $$function_shared{$name} = 1;
887 }
888
889 sub function_internal_arguments($$) {
890     my $self = shift;
891     my $function_internal_arguments = \%{$self->{FUNCTION_INTERNAL_ARGUMENTS}};
892
893     my $name = shift;
894
895     return $$function_internal_arguments{$name};
896 }
897
898 sub function_external_arguments($$) {
899     my $self = shift;
900     my $function_external_arguments = \%{$self->{FUNCTION_EXTERNAL_ARGUMENTS}};
901
902     my $name = shift;
903
904     return $$function_external_arguments{$name};
905 }
906
907 sub function_internal_module($$) {
908     my $self = shift;
909     my $function_internal_module = \%{$self->{FUNCTION_INTERNAL_MODULE}};
910
911     my $name = shift;
912
913     return $$function_internal_module{$name};
914 }
915
916 sub function_external_module($$) {
917     my $self = shift;
918     my $function_external_module = \%{$self->{FUNCTION_EXTERNAL_MODULE}};
919
920     my $name = shift;
921
922     return $$function_external_module{$name};
923 }
924
925 sub function_wine_extension($$$) {
926     my $self = shift;
927     my $function_wine_extension = \%{$self->{FUNCTION_WINE_EXTENSION}};
928
929     my $module = shift;
930     my $name = shift;
931
932     return $$function_wine_extension{$module}{$name};
933 }
934
935 sub is_function_stub($$$) {
936     my $self = shift;
937     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
938
939     my $module = shift;
940     my $name = shift;
941
942     if($$module_external_calling_convention{$module}{$name} eq "stub") {
943         return 1;
944     }
945     return 0;
946 }
947
948 sub is_function_stub_in_module($$$) {
949     my $self = shift;
950     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
951
952     my $module = shift;
953     my $name = shift;
954
955     if(!defined($$module_external_calling_convention{$module}{$name})) {
956         return 0;
957     }
958     return $$module_external_calling_convention{$module}{$name} eq "stub";
959 }
960
961 ########################################################################
962 # class methods
963 #
964
965 sub _get_all_module_internal_ordinal($$) {
966     my $winapi = shift;
967     my $internal_name = shift;
968
969     my @entries = ();
970
971     my @name = (); {
972         my $name = $winapi->function_external_name($internal_name);
973         if(defined($name)) {
974             @name = split(/ & /, $name);
975         }
976     }
977
978     my @module = (); {
979         my $module = $winapi->function_internal_module($internal_name);
980         if(defined($module)) {
981             @module = split(/ & /, $module);
982         }
983     }
984
985     my @ordinal = (); {
986         my $ordinal = $winapi->function_internal_ordinal($internal_name);
987         if(defined($ordinal)) {
988             @ordinal = split(/ & /, $ordinal);
989         }
990     }
991
992     my $name;
993     my $module;
994     my $ordinal;
995     while(defined($name = shift @name) &&
996           defined($module = shift @module) &&
997           defined($ordinal = shift @ordinal))
998     {
999         push @entries, [$name, $module, $ordinal];
1000     }
1001
1002     return @entries;
1003 }
1004
1005 sub get_all_module_internal_ordinal16($) {
1006     return _get_all_module_internal_ordinal($win16api, $_[0]);
1007 }
1008
1009 sub get_all_module_internal_ordinal32($) {
1010     return _get_all_module_internal_ordinal($win32api, $_[0]);
1011 }
1012
1013 sub get_all_module_internal_ordinal($) {
1014     my @entries = ();
1015     foreach my $winapi (@winapis) {
1016         push @entries, _get_all_module_internal_ordinal($winapi, $_[0]);
1017     }
1018
1019     return @entries;
1020 }
1021
1022 sub _get_all_module_external_ordinal($$) {
1023     my $winapi = shift;
1024     my $external_name = shift;
1025
1026     my @entries = ();
1027
1028     my @name = (); {
1029         my $name = $winapi->function_internal_name($external_name);
1030         if(defined($name)) {
1031             @name = split(/ & /, $name);
1032         }
1033     }
1034
1035     my @module = (); {
1036         my $module = $winapi->function_external_module($external_name);
1037         if(defined($module)) {
1038             @module = split(/ & /, $module);
1039         }
1040     }
1041
1042     my @ordinal = (); {
1043         my $ordinal = $winapi->function_external_ordinal($external_name);
1044         if(defined($ordinal)) {
1045             @ordinal = split(/ & /, $ordinal);
1046         }
1047     }
1048
1049     my $name;
1050     my $module;
1051     my $ordinal;
1052     while(defined($name = shift @name) &&
1053           defined($module = shift @module) &&
1054           defined($ordinal = shift @ordinal))
1055     {
1056         push @entries, [$name, $module, $ordinal];
1057     }
1058
1059     return @entries;
1060 }
1061
1062 sub get_all_module_external_ordinal16($) {
1063     return _get_all_module_external_ordinal($win16api, $_[0]);
1064 }
1065
1066 sub get_all_module_external_ordinal32($) {
1067     return _get_all_module_external_ordinal($win32api, $_[0]);
1068 }
1069
1070 sub get_all_module_external_ordinal($) {
1071     my @entries = ();
1072     foreach my $winapi (@winapis) {
1073         push @entries, _get_all_module_external_ordinal($winapi, $_[0]);
1074     }
1075
1076     return @entries;
1077 }
1078
1079 1;