5 use nativeapi qw($nativeapi);
6 use options qw($options);
7 use output qw($output);
8 use winapi qw($win16api $win32api @winapis);
13 my $return_type = $function->return_type;
14 my $calling_convention = $function->calling_convention;
15 my $calling_convention16 = $function->calling_convention16;
16 my $calling_convention32 = $function->calling_convention32;
17 my $internal_name = $function->internal_name;
18 my $external_name16 = $function->external_name16;
19 my $external_name32 = $function->external_name32;
20 my $module16 = $function->module16;
21 my $module32 = $function->module32;
22 my $refargument_types = $function->argument_types;
24 if(!defined($refargument_types)) {
28 if($options->win16 && $options->report_module($module16)) {
29 _check_function($return_type,
30 $calling_convention, $external_name16,
31 $internal_name, $refargument_types,
35 if($options->win32 && $options->report_module($module32)) {
36 _check_function($return_type,
37 $calling_convention, $external_name32,
38 $internal_name, $refargument_types,
44 my $return_type = shift;
45 my $calling_convention = shift;
46 my $external_name = shift;
47 my $internal_name = shift;
48 my $refargument_types = shift;
49 my @argument_types = @$refargument_types;
52 my $module = $winapi->function_internal_module($internal_name);
54 if($winapi->name eq "win16") {
55 if($winapi->is_function_stub_in_module($module, $internal_name)) {
56 if($options->implemented) {
57 $output->write("function implemented but declared as stub in .spec file\n");
60 } elsif($winapi->is_function_stub_in_module($module, $internal_name)) {
61 if($options->implemented_win32) {
62 $output->write("32-bit variant of function implemented but declared as stub in .spec file\n");
66 } elsif($winapi->is_function_stub_in_module($module, $internal_name)) {
67 if($options->implemented) {
68 $output->write("function implemented but declared as stub in .spec file\n");
73 my $forbidden_return_type = 0;
74 my $implemented_return_kind;
75 $winapi->type_used_in_module($return_type,$module);
76 if(!defined($implemented_return_kind = $winapi->translate_argument($return_type))) {
77 if($return_type ne "") {
78 $output->write("no translation defined: " . $return_type . "\n");
80 } elsif(!$winapi->is_allowed_kind($implemented_return_kind) || !$winapi->allowed_type_in_module($return_type,$module)) {
81 $forbidden_return_type = 1;
82 if($options->report_argument_forbidden($return_type)) {
83 $output->write("return type is forbidden: $return_type ($implemented_return_kind)\n");
88 if(defined($implemented_return_kind) && $implemented_return_kind =~ /^segptr|segstr$/) {
92 my $implemented_calling_convention;
93 if($winapi->name eq "win16") {
94 if($calling_convention =~ /^__cdecl$/) {
95 $implemented_calling_convention = "cdecl";
96 } elsif($calling_convention =~ /^VFWAPIV|WINAPIV$/) {
97 $implemented_calling_convention = "varargs";
98 } elsif($calling_convention =~ /^__stdcall|VFWAPI|WINAPI|CALLBACK$/) {
99 if($implemented_return_kind =~ /^s_word|word|void$/) {
100 $implemented_calling_convention = "pascal16";
102 $implemented_calling_convention = "pascal";
104 } elsif($calling_convention =~ /^__asm$/) {
105 $implemented_calling_convention = "asm";
107 $implemented_calling_convention = "cdecl";
109 } elsif($winapi->name eq "win32") {
110 if($calling_convention =~ /^__cdecl$/) {
111 $implemented_calling_convention = "cdecl";
112 } elsif($calling_convention =~ /^VFWAPIV|WINAPIV$/) {
113 $implemented_calling_convention = "varargs";
114 } elsif($calling_convention =~ /^__stdcall|VFWAPI|WINAPI|CALLBACK$/) {
115 if(defined($implemented_return_kind) && $implemented_return_kind =~ /^longlong$/) {
116 $implemented_calling_convention = "stdcall"; # FIXME: Check entry flags
118 $implemented_calling_convention = "stdcall";
120 } elsif($calling_convention =~ /^__asm$/) {
121 $implemented_calling_convention = "asm";
123 $implemented_calling_convention = "cdecl";
127 my $declared_calling_convention = $winapi->function_internal_calling_convention($internal_name);
128 my @declared_argument_kinds = split(/\s+/, $winapi->function_internal_arguments($internal_name));
130 if($declared_calling_convention =~ /^register|interrupt$/) {
131 push @declared_argument_kinds, "ptr";
134 if($declared_calling_convention =~ /^register|interupt$/ &&
135 (($winapi->name eq "win32" && $implemented_calling_convention eq "stdcall") ||
136 (($winapi->name eq "win16" && $implemented_calling_convention =~ /^pascal/))))
139 } elsif($implemented_calling_convention ne $declared_calling_convention &&
140 $implemented_calling_convention ne "asm" &&
141 !($declared_calling_convention =~ /^pascal/ && $forbidden_return_type) &&
142 !($implemented_calling_convention =~ /^cdecl|varargs$/ && $declared_calling_convention =~ /^cdecl|varargs$/))
144 if($options->calling_convention && (
145 ($options->calling_convention_win16 && $winapi->name eq "win16") ||
146 ($options->calling_convention_win32 && $winapi->name eq "win32")) &&
147 !$nativeapi->is_function($internal_name))
149 $output->write("calling convention mismatch: $implemented_calling_convention != $declared_calling_convention\n");
153 if($declared_calling_convention eq "varargs") {
154 if($#argument_types != -1 && $argument_types[$#argument_types] eq "...") {
157 $output->write("function not implemented as vararg\n");
159 } elsif($#argument_types != -1 && $argument_types[$#argument_types] eq "...") {
160 if($#argument_types == 0 || $winapi->name eq "win16") {
163 $output->write("function not declared as vararg\n");
167 if($#argument_types != -1 && $argument_types[$#argument_types] eq "CONTEXT *" &&
168 $internal_name !~ /^(Get|Set)ThreadContext$/) # FIXME: Kludge
173 if($internal_name =~ /^NTDLL__ftol|NTDLL__CIpow$/) { # FIXME: Kludge
177 my @argument_kinds = map {
179 my $kind = "unknown";
180 $winapi->type_used_in_module($type,$module);
181 if(!defined($kind = $winapi->translate_argument($type))) {
182 $output->write("no translation defined: " . $type . "\n");
183 } elsif(!$winapi->is_allowed_kind($kind) ||
184 !$winapi->allowed_type_in_module($type, $module)) {
185 if($options->report_argument_forbidden($type)) {
186 $output->write("forbidden argument " . ($n + 1) . " type " . $type . " (" . $kind . ")\n");
191 if(defined($kind) && $kind eq "longlong") {
200 for my $n (0..$#argument_kinds) {
201 if(!defined($argument_kinds[$n]) || !defined($declared_argument_kinds[$n])) { next; }
203 if($argument_kinds[$n] =~ /^segptr|segstr$/ ||
204 $declared_argument_kinds[$n] =~ /^segptr|segstr$/)
210 if(!defined($argument_types[$n])) {
211 $argument_types[$n] = "";
214 if(!$winapi->is_allowed_kind($argument_kinds[$n]) ||
215 !$winapi->allowed_type_in_module($argument_types[$n], $module))
217 if($options->report_argument_forbidden($argument_types[$n])) {
218 $output->write("argument " . ($n + 1) . " type is forbidden: " .
219 "$argument_types[$n] ($argument_kinds[$n])\n");
221 } elsif($argument_kinds[$n] ne $declared_argument_kinds[$n]) {
222 if($options->report_argument_kind($argument_kinds[$n]) ||
223 $options->report_argument_kind($declared_argument_kinds[$n]))
225 $output->write("argument " . ($n + 1) . " type mismatch: " .
226 $argument_types[$n] . " ($argument_kinds[$n]) != " .
227 $declared_argument_kinds[$n] . "\n");
232 if($#argument_kinds != $#declared_argument_kinds &&
233 $implemented_calling_convention ne "asm")
235 if($options->argument_count) {
236 $output->write("argument count differs: " .
237 ($#argument_types + 1) . " != " .
238 ($#declared_argument_kinds + 1) . "\n");
244 if($segmented && $options->shared_segmented && $winapi->is_shared_internal_function($internal_name)) {
245 $output->write("function using segmented pointers shared between Win16 och Win32\n");
249 sub check_statements {
250 my $functions = shift;
251 my $function = shift;
253 my $module16 = $function->module16;
254 my $module32 = $function->module32;
256 if($options->win16 && $options->report_module($module16)) {
257 _check_statements($win16api, $functions, $function);
260 if($options->win32 && $options->report_module($module32)) {
261 _check_statements($win16api, $functions, $function);
265 sub _check_statements {
267 my $functions = shift;
268 my $function = shift;
270 my $module = $function->module;
271 my $internal_name = $function->internal_name;
273 my $first_debug_message = 1;
274 local $_ = $function->statements;
276 if(s/(\w+)\s*(?:\(\s*(\w+)\s*\))?\s*\(\s*((?:\"[^\"]*\"|\([^\)]*\)|[^\)])*?)\s*\)//) {
277 my $called_name = $1;
279 my $called_arguments = $3;
280 if($called_name =~ /^if|for|while|switch|sizeof$/) {
282 } elsif($called_name =~ /^ERR|FIXME|MSG|TRACE|WARN$/) {
283 if($first_debug_message && $called_name =~ /^FIXME|TRACE$/) {
284 $first_debug_message = 0;
285 if($called_arguments =~ /^\"\((.*?)\)(.*?)\"\s*,\s*(.*?)$/) {
293 while($formating && ($formating =~ s/^([^,]*),?//, $format = $1, $format =~ s/^\s*(.*?)\s*$/$1/) &&
294 $arguments && ($arguments =~ s/^([^,]*),?//, $argument = $1, $argument =~ s/^\s*(.*?)\s*$/$1/))
296 my $type = @{$function->argument_types}[$n];
297 my $name = @{$function->argument_names}[$n];
301 if(!defined($type)) { last; }
303 $format =~ s/^\w+\s*[:=]?\s*//;
304 $format =~ s/\s*\{[^\{\}]*\}$//;
305 $format =~ s/\s*\[[^\[\]]*\]$//;
306 $format =~ s/^\'(.*?)\'$/$1/;
307 $format =~ s/^\\\"(.*?)\\\"$/$1/;
309 if($options->debug_messages) {
310 if($argument !~ /$name/) {
311 $output->write("$called_name: argument $n is wrong ($name != '$argument')\n");
312 } elsif(!$winapi->is_allowed_type_format($module, $type, $format)) {
313 $output->write("$called_name: argument $n ($type $name) has illegal format ($format)\n");
318 if($options->debug_messages) {
319 my $count = $#{$function->argument_types} + 1;
321 $output->write("$called_name: argument count mismatch ($n != $count)\n");
326 } elsif($options->cross_call) {
327 $$functions{$internal_name}->function_called($called_name);
328 if(!defined($$functions{$called_name})) {
329 $$functions{$called_name} = 'winapi_function'->new;
331 $$functions{$called_name}->function_called_by($internal_name);
341 my $functions = shift;
343 if($options->cross_call) {
344 my @names = sort(keys(%$functions));
345 for my $name (@names) {
346 my @called_names = $$functions{$name}->called_function_names;
347 my @called_by_names = $$functions{$name}->called_by_function_names;
348 my $module = $$functions{$name}->module;
350 if($options->cross_call_win32_win16) {
351 my $module16 = $$functions{$name}->module16;
352 my $module32 = $$functions{$name}->module32;
354 if($#called_names >= 0 && (defined($module16) || defined($module32)) ) {
355 for my $called_name (@called_names) {
356 my $called_module16 = $$functions{$called_name}->module16;
357 my $called_module32 = $$functions{$called_name}->module32;
358 if(defined($module32) &&
359 defined($called_module16) && !defined($called_module32) &&
360 $name ne $called_name)
362 $output->write("$file: $module: $name: illegal call to $called_name (Win32 -> Win16)\n");
368 if($options->cross_call_unicode_ascii) {
370 for my $called_name (@called_names) {
371 if($called_name =~ /A$/) {
372 $output->write("$file: $module: $name: illegal call to $called_name (Unicode -> ASCII)\n");