8 my $return_type = shift;
9 my $calling_convention = shift;
10 my $external_name = shift;
11 my $internal_name = shift;
12 my $refargument_types = shift;
13 my @argument_types = @$refargument_types;
14 my $nativeapi = shift;
17 my $module = $winapi->function_module($internal_name);
19 if($winapi->name eq "win16") {
20 my $name16 = $internal_name;
22 if($name16 ne $internal_name && $winapi->function_stub($name16)) {
23 if($options->implemented) {
24 $output->write("function implemented but declared as stub in .spec file\n");
27 } elsif($winapi->function_stub($internal_name)) {
28 if($options->implemented_win32) {
29 $output->write("32-bit variant of function implemented but declared as stub in .spec file\n");
33 } elsif($winapi->function_stub($internal_name)) {
34 if($options->implemented) {
35 $output->write("function implemented but declared as stub in .spec file\n");
40 my $forbidden_return_type = 0;
41 my $implemented_return_kind;
42 $winapi->type_used_in_module($return_type,$module);
43 if(!defined($implemented_return_kind = $winapi->translate_argument($return_type))) {
44 if($return_type ne "") {
45 $output->write("no translation defined: " . $return_type . "\n");
47 } elsif(!$winapi->is_allowed_kind($implemented_return_kind) || !$winapi->allowed_type_in_module($return_type,$module)) {
48 $forbidden_return_type = 1;
49 if($options->report_argument_forbidden($return_type)) {
50 $output->write("return type is forbidden: $return_type ($implemented_return_kind)\n");
55 if($implemented_return_kind =~ /^segptr|segstr$/) {
59 my $implemented_calling_convention;
60 if($winapi->name eq "win16") {
61 if($calling_convention =~ /^__cdecl$/) {
62 $implemented_calling_convention = "cdecl";
63 } elsif($calling_convention =~ /^VFWAPIV|WINAPIV$/) {
64 $implemented_calling_convention = "varargs";
65 } elsif($calling_convention = ~ /^__stdcall|VFWAPI|WINAPI|CALLBACK$/) {
66 if($implemented_return_kind =~ /^s_word|word|void$/) {
67 $implemented_calling_convention = "pascal16";
69 $implemented_calling_convention = "pascal";
72 } elsif($winapi->name eq "win32") {
73 if($calling_convention =~ /^__cdecl$/) {
74 $implemented_calling_convention = "cdecl";
75 } elsif($calling_convention =~ /^VFWAPIV|WINAPIV$/) {
76 $implemented_calling_convention = "varargs";
77 } elsif($calling_convention =~ /^__stdcall|VFWAPI|WINAPI|CALLBACK$/) {
78 if($implemented_return_kind =~ /^longlong$/) {
79 $implemented_calling_convention = "stdcall"; # FIXME: Check entry flags
81 $implemented_calling_convention = "stdcall";
84 $implemented_calling_convention = "cdecl";
88 my $declared_calling_convention = $winapi->function_calling_convention($internal_name);
89 my @declared_argument_kinds = split(/\s+/, $winapi->function_arguments($internal_name));
91 if($declared_calling_convention =~ /^register|interrupt$/) {
92 push @declared_argument_kinds, "ptr";
95 if($declared_calling_convention =~ /^register|interupt$/ &&
96 (($winapi->name eq "win32" && $implemented_calling_convention eq "stdcall") ||
97 (($winapi->name eq "win16" && $implemented_calling_convention =~ /^pascal/))))
100 } elsif($implemented_calling_convention ne $declared_calling_convention &&
101 !($declared_calling_convention =~ /^pascal/ && $forbidden_return_type) &&
102 !($implemented_calling_convention =~ /^cdecl|varargs$/ && $declared_calling_convention =~ /^cdecl|varargs$/))
104 if($options->calling_convention && (
105 ($options->calling_convention_win16 && $winapi->name eq "win16") ||
106 ($options->calling_convention_win32 && $winapi->name eq "win32")) &&
107 !$nativeapi->is_function($internal_name))
109 $output->write("calling convention mismatch: $implemented_calling_convention != $declared_calling_convention\n");
113 if($declared_calling_convention eq "varargs") {
114 if($#argument_types != -1 && $argument_types[$#argument_types] eq "...") {
117 $output->write("function not implemented as vararg\n");
119 } elsif($#argument_types != -1 && $argument_types[$#argument_types] eq "...") {
120 $output->write("function not declared as vararg\n");
123 if($#argument_types != -1 && $argument_types[$#argument_types] eq "CONTEXT *" &&
124 $internal_name !~ /^(Get|Set)ThreadContext$/) # FIXME: Kludge
129 if($internal_name =~ /^NTDLL__ftol|NTDLL__CIpow$/) { # FIXME: Kludge
133 my @argument_kinds = map {
135 my $kind = "unknown";
136 $winapi->type_used_in_module($type,$module);
137 if(!defined($kind = $winapi->translate_argument($type))) {
138 $output->write("no translation defined: " . $type . "\n");
139 } elsif(!$winapi->is_allowed_kind($kind) ||
140 !$winapi->allowed_type_in_module($type, $module)) {
141 if($options->report_argument_forbidden($type)) {
142 $output->write("forbidden argument " . ($n + 1) . " type " . $type . " (" . $kind . ")\n");
147 if(defined($kind) && $kind eq "longlong") {
156 for my $n (0..$#argument_kinds) {
157 if(!defined($argument_kinds[$n]) || !defined($declared_argument_kinds[$n])) { next; }
159 if($argument_kinds[$n] =~ /^segptr|segstr$/ ||
160 $declared_argument_kinds[$n] =~ /^segptr|segstr$/)
166 if(!defined($argument_types[$n])) {
167 $argument_types[$n] = "";
170 if(!$winapi->is_allowed_kind($argument_kinds[$n]) ||
171 !$winapi->allowed_type_in_module($argument_types[$n], $module))
173 if($options->report_argument_forbidden($argument_types[$n])) {
174 $output->write("argument " . ($n + 1) . " type is forbidden: " .
175 "$argument_types[$n] ($argument_kinds[$n])\n");
177 } elsif($argument_kinds[$n] ne $declared_argument_kinds[$n]) {
178 if($options->report_argument_kind($argument_kinds[$n]) ||
179 $options->report_argument_kind($declared_argument_kinds[$n]))
181 $output->write("argument " . ($n + 1) . " type mismatch: " .
182 $argument_types[$n] . " ($argument_kinds[$n]) != " .
183 $declared_argument_kinds[$n] . "\n");
187 if($#argument_kinds != $#declared_argument_kinds) {
188 if($options->argument_count) {
189 $output->write("argument count differs: " .
190 ($#argument_types + 1) . " != " .
191 ($#declared_argument_kinds + 1) . "\n");
197 if($segmented && $options->shared_segmented && $winapi->is_shared_function($internal_name)) {
198 $output->write("function using segmented pointers shared between Win16 och Win32\n");
202 sub check_statements {
206 my $functions = shift;
207 my $function = shift;
209 my $module = $function->module;
210 my $internal_name = $function->internal_name;
212 my $first_debug_message = 1;
213 local $_ = $function->statements;
215 if(s/(\w+)\s*(?:\(\s*(\w+)\s*\))?\s*\(\s*((?:\"[^\"]*\"|\([^\)]*\)|[^\)])*?)\s*\)//) {
216 my $called_name = $1;
218 my $called_arguments = $3;
219 if($called_name =~ /^if|for|while|switch|sizeof$/) {
221 } elsif($called_name =~ /^ERR|FIXME|MSG|TRACE|WARN$/) {
222 if($first_debug_message && $called_name =~ /^FIXME|TRACE$/) {
223 $first_debug_message = 0;
224 if($called_arguments =~ /^\"\((.*?)\)(.*?)\"\s*,\s*(.*?)$/) {
232 while($formating && ($formating =~ s/^([^,]*),?//, $format = $1, $format =~ s/^\s*(.*?)\s*$/$1/) &&
233 $arguments && ($arguments =~ s/^([^,]*),?//, $argument = $1, $argument =~ s/^\s*(.*?)\s*$/$1/))
235 my $type = @{$function->argument_types}[$n];
236 my $name = @{$function->argument_names}[$n];
240 if(!defined($type)) { last; }
242 $format =~ s/^\w+\s*[:=]?\s*//;
243 $format =~ s/\s*\{[^\{\}]*\}$//;
244 $format =~ s/\s*\[[^\[\]]*\]$//;
245 $format =~ s/^\'(.*?)\'$/$1/;
246 $format =~ s/^\\\"(.*?)\\\"$/$1/;
248 if($argument !~ /$name/) {
249 $output->write("$called_name: argument $n is wrong ($name != '$argument')\n");
250 } elsif(!$winapi->is_allowed_type_format($module, $type, $format)) {
251 $output->write("$called_name: argument $n ($type $name) has illegal format ($format)\n");
255 my $count = $#{$function->argument_types} + 1;
257 $output->write("$called_name: argument count mismatch ($n != $count)\n");
262 $$functions{$internal_name}->function_called($called_name);
263 if(!defined($$functions{$called_name})) {
264 $$functions{$called_name} = 'winapi_function'->new;
266 $$functions{$called_name}->function_called_by($internal_name);
278 my $functions = shift;
280 if($options->cross_call) {
281 my @names = sort(keys(%$functions));
282 for my $name (@names) {
283 my @called_names = $$functions{$name}->called_function_names;
284 my @called_by_names = $$functions{$name}->called_by_function_names;
285 my $module = $$functions{$name}->module;
287 if($options->cross_call_win32_win16) {
288 my $module16 = $$functions{$name}->module16;
289 my $module32 = $$functions{$name}->module32;
291 if($#called_names >= 0 && (defined($module16) || defined($module32)) ) {
292 for my $called_name (@called_names) {
293 my $called_module16 = $$functions{$called_name}->module16;
294 my $called_module32 = $$functions{$called_name}->module32;
295 if(defined($module32) &&
296 defined($called_module16) && !defined($called_module32) &&
297 $name ne $called_name)
299 $output->write("$file: $module: $name: illegal call to $called_name (Win32 -> Win16)\n");
305 if($options->cross_call_unicode_ascii) {
307 for my $called_name (@called_names) {
308 if($called_name =~ /A$/) {
309 $output->write("$file: $module: $name: illegal call to $called_name (Unicode -> ASCII)\n");