uninstaller: Hungarian translation.
[wine.git] / tools / winapi / c_parser.pm
blob4d750e9d0a1e6ff7ff380710022f95ba54f78957
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 c_parser;
21 use strict;
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
24 require Exporter;
26 @ISA = qw(Exporter);
27 @EXPORT = qw();
28 @EXPORT_OK = qw();
30 use options qw($options);
31 use output qw($output);
33 use c_function;
34 use c_type;
36 # Defined a couple common regexp tidbits
37 my $CALL_CONVENTION="__cdecl|__stdcall|" .
38 "__RPC_API|__RPC_STUB|__RPC_USER|" .
39 "CALLBACK|CDECL|NTAPI|PASCAL|RPC_ENTRY|RPC_VAR_ENTRY|" .
40 "VFWAPI|VFWAPIV|WINAPI|WINAPIV|APIENTRY|";
43 sub parse_c_function($$$$$);
44 sub parse_c_function_call($$$$$$$$);
45 sub parse_c_preprocessor($$$$);
46 sub parse_c_statements($$$$);
47 sub parse_c_tuple($$$$$$$);
48 sub parse_c_type($$$$$);
49 sub parse_c_typedef($$$$);
50 sub parse_c_variable($$$$$$$);
53 ########################################################################
54 # new
56 sub new($$) {
57 my $proto = shift;
58 my $class = ref($proto) || $proto;
59 my $self = {};
60 bless ($self, $class);
62 my $file = \${$self->{FILE}};
63 my $create_function = \${$self->{CREATE_FUNCTION}};
64 my $create_type = \${$self->{CREATE_TYPE}};
65 my $found_comment = \${$self->{FOUND_COMMENT}};
66 my $found_declaration = \${$self->{FOUND_DECLARATION}};
67 my $found_function = \${$self->{FOUND_FUNCTION}};
68 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
69 my $found_line = \${$self->{FOUND_LINE}};
70 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
71 my $found_statement = \${$self->{FOUND_STATEMENT}};
72 my $found_type = \${$self->{FOUND_TYPE}};
73 my $found_variable = \${$self->{FOUND_VARIABLE}};
75 $$file = shift;
77 $$create_function = sub { return new c_function; };
78 $$create_type = sub { return new c_type; };
79 $$found_comment = sub { return 1; };
80 $$found_declaration = sub { return 1; };
81 $$found_function = sub { return 1; };
82 $$found_function_call = sub { return 1; };
83 $$found_line = sub { return 1; };
84 $$found_preprocessor = sub { return 1; };
85 $$found_statement = sub { return 1; };
86 $$found_type = sub { return 1; };
87 $$found_variable = sub { return 1; };
89 return $self;
92 ########################################################################
93 # set_found_comment_callback
95 sub set_found_comment_callback($$) {
96 my $self = shift;
98 my $found_comment = \${$self->{FOUND_COMMENT}};
100 $$found_comment = shift;
103 ########################################################################
104 # set_found_declaration_callback
106 sub set_found_declaration_callback($$) {
107 my $self = shift;
109 my $found_declaration = \${$self->{FOUND_DECLARATION}};
111 $$found_declaration = shift;
114 ########################################################################
115 # set_found_function_callback
117 sub set_found_function_callback($$) {
118 my $self = shift;
120 my $found_function = \${$self->{FOUND_FUNCTION}};
122 $$found_function = shift;
125 ########################################################################
126 # set_found_function_call_callback
128 sub set_found_function_call_callback($$) {
129 my $self = shift;
131 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
133 $$found_function_call = shift;
136 ########################################################################
137 # set_found_line_callback
139 sub set_found_line_callback($$) {
140 my $self = shift;
142 my $found_line = \${$self->{FOUND_LINE}};
144 $$found_line = shift;
147 ########################################################################
148 # set_found_preprocessor_callback
150 sub set_found_preprocessor_callback($$) {
151 my $self = shift;
153 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
155 $$found_preprocessor = shift;
158 ########################################################################
159 # set_found_statement_callback
161 sub set_found_statement_callback($$) {
162 my $self = shift;
164 my $found_statement = \${$self->{FOUND_STATEMENT}};
166 $$found_statement = shift;
169 ########################################################################
170 # set_found_type_callback
172 sub set_found_type_callback($$) {
173 my $self = shift;
175 my $found_type = \${$self->{FOUND_TYPE}};
177 $$found_type = shift;
180 ########################################################################
181 # set_found_variable_callback
183 sub set_found_variable_callback($$) {
184 my $self = shift;
186 my $found_variable = \${$self->{FOUND_VARIABLE}};
188 $$found_variable = shift;
192 ########################################################################
193 # _format_c_type
195 sub _format_c_type($$) {
196 my $self = shift;
198 local $_ = shift;
199 s/^\s*(.*?)\s*$/$1/;
201 if (/^(\w+(?:\s*\*)*)\s*\(\s*\*\s*\)\s*\(\s*(.*?)\s*\)$/s) {
202 my $return_type = $1;
203 my @arguments = split(/\s*,\s*/, $2);
204 foreach my $argument (@arguments) {
205 if ($argument =~ s/^(\w+(?:\s*\*)*)\s*\w+$/$1/) {
206 $argument =~ s/\s+/ /g;
207 $argument =~ s/\s*\*\s*/*/g;
208 $argument =~ s/(\*+)$/ $1/;
212 $_ = "$return_type (*)(" . join(", ", @arguments) . ")";
215 return $_;
219 ########################################################################
220 # _parse_c_warning
222 # FIXME: Use caller (See man perlfunc)
224 sub _parse_c_warning($$$$$$) {
225 my $self = shift;
227 local $_ = shift;
228 my $line = shift;
229 my $column = shift;
230 my $context = shift;
231 my $message = shift;
233 my $file = \${$self->{FILE}};
235 $message = "warning" if !$message;
237 my $current = "";
238 if($_) {
239 my @lines = split(/\n/, $_);
241 $current .= $lines[0] . "\n" if $lines[0];
242 $current .= $lines[1] . "\n" if $lines[1];
245 if (0) {
246 (my $package, my $filename, my $line) = caller(0);
247 $output->write("*** caller ***: $filename:$line\n");
250 if($current) {
251 $output->write("$$file:$line." . ($column + 1) . ": $context: $message: \\\n$current");
252 } else {
253 $output->write("$$file:$line." . ($column + 1) . ": $context: $message\n");
257 ########################################################################
258 # _parse_c_error
260 sub _parse_c_error($$$$$$) {
261 my $self = shift;
263 local $_ = shift;
264 my $line = shift;
265 my $column = shift;
266 my $context = shift;
267 my $message = shift;
269 $message = "parse error" if !$message;
271 # Why did I do this?
272 if($output->prefix) {
273 # $output->write("\n");
274 $output->prefix("");
277 $self->_parse_c_warning($_, $line, $column, $context, $message);
279 exit 1;
282 ########################################################################
283 # _update_c_position
285 sub _update_c_position($$$$) {
286 my $self = shift;
288 local $_ = shift;
289 my $refline = shift;
290 my $refcolumn = shift;
292 my $line = $$refline;
293 my $column = $$refcolumn;
295 while($_) {
296 if(s/^[^\n\t\'\"]*//s) {
297 $column += length($&);
300 if(s/^\'//) {
301 $column++;
302 while(/^./ && !s/^\'//) {
303 s/^([^\'\\]*)//s;
304 $column += length($1);
305 if(s/^\\//) {
306 $column++;
307 if(s/^(.)//s) {
308 $column += length($1);
309 if($1 eq "0") {
310 s/^(\d{0,3})//s;
311 $column += length($1);
316 $column++;
317 } elsif(s/^\"//) {
318 $column++;
319 while(/^./ && !s/^\"//) {
320 s/^([^\"\\]*)//s;
321 $column += length($1);
322 if(s/^\\//) {
323 $column++;
324 if(s/^(.)//s) {
325 $column += length($1);
326 if($1 eq "0") {
327 s/^(\d{0,3})//s;
328 $column += length($1);
333 $column++;
334 } elsif(s/^\n//) {
335 $line++;
336 $column = 0;
337 } elsif(s/^\t//) {
338 $column = $column + 8 - $column % 8;
342 $$refline = $line;
343 $$refcolumn = $column;
346 ########################################################################
347 # __parse_c_until_one_of
349 sub __parse_c_until_one_of($$$$$$$) {
350 my $self = shift;
352 my $characters = shift;
353 my $on_same_level = shift;
354 my $refcurrent = shift;
355 my $refline = shift;
356 my $refcolumn = shift;
357 my $match = shift;
359 local $_ = $$refcurrent;
360 my $line = $$refline;
361 my $column = $$refcolumn;
364 if(!defined($match)) {
365 my $blackhole;
366 $match = \$blackhole;
369 my $level = 0;
370 $$match = "";
371 while(/^[^$characters]/s || $level > 0) {
372 my $submatch = "";
374 if ($level > 0) {
375 if(s/^[^\(\)\[\]\{\}\n\t\'\"]*//s) {
376 $submatch .= $&;
378 } elsif ($on_same_level) {
379 if(s/^[^$characters\(\)\[\]\{\}\n\t\'\"]*//s) {
380 $submatch .= $&;
382 } else {
383 if(s/^[^$characters\n\t\'\"]*//s) {
384 $submatch .= $&;
388 if(s/^\'//) {
389 $submatch .= "\'";
390 while(/^./ && !s/^\'//) {
391 s/^([^\'\\]*)//s;
392 $submatch .= $1;
393 if(s/^\\//) {
394 $submatch .= "\\";
395 if(s/^(.)//s) {
396 $submatch .= $1;
397 if($1 eq "0") {
398 s/^(\d{0,3})//s;
399 $submatch .= $1;
404 $submatch .= "\'";
406 $$match .= $submatch;
407 $column += length($submatch);
408 } elsif(s/^\"//) {
409 $submatch .= "\"";
410 while(/^./ && !s/^\"//) {
411 s/^([^\"\\]*)//s;
412 $submatch .= $1;
413 if(s/^\\//) {
414 $submatch .= "\\";
415 if(s/^(.)//s) {
416 $submatch .= $1;
417 if($1 eq "0") {
418 s/^(\d{0,3})//s;
419 $submatch .= $1;
424 $submatch .= "\"";
426 $$match .= $submatch;
427 $column += length($submatch);
428 } elsif($on_same_level && s/^[\(\[\{]//) {
429 $level++;
431 $submatch .= $&;
432 $$match .= $submatch;
433 $column++;
434 } elsif($on_same_level && s/^[\)\]\}]//) {
435 if ($level > 0) {
436 $level--;
438 $submatch .= $&;
439 $$match .= $submatch;
440 $column++;
441 } else {
442 $_ = "$&$_";
443 $$match .= $submatch;
444 last;
446 } elsif(s/^\n//) {
447 $submatch .= "\n";
449 $$match .= $submatch;
450 $line++;
451 $column = 0;
452 } elsif(s/^\t//) {
453 $submatch .= "\t";
455 $$match .= $submatch;
456 $column = $column + 8 - $column % 8;
457 } else {
458 $$match .= $submatch;
459 $column += length($submatch);
463 $$refcurrent = $_;
464 $$refline = $line;
465 $$refcolumn = $column;
466 return 1;
469 ########################################################################
470 # _parse_c_until_one_of
472 sub _parse_c_until_one_of($$$$$$) {
473 my $self = shift;
475 my $characters = shift;
476 my $refcurrent = shift;
477 my $refline = shift;
478 my $refcolumn = shift;
479 my $match = shift;
481 return $self->__parse_c_until_one_of($characters, 0, $refcurrent, $refline, $refcolumn, $match);
484 ########################################################################
485 # _parse_c_on_same_level_until_one_of
487 sub _parse_c_on_same_level_until_one_of($$$$$$) {
488 my $self = shift;
490 my $characters = shift;
491 my $refcurrent = shift;
492 my $refline = shift;
493 my $refcolumn = shift;
494 my $match = shift;
496 return $self->__parse_c_until_one_of($characters, 1, $refcurrent, $refline, $refcolumn, $match);
499 ########################################################################
500 # parse_c_block
502 sub parse_c_block($$$$$$$) {
503 my $self = shift;
505 my $refcurrent = shift;
506 my $refline = shift;
507 my $refcolumn = shift;
509 my $refstatements = shift;
510 my $refstatements_line = shift;
511 my $refstatements_column = shift;
513 local $_ = $$refcurrent;
514 my $line = $$refline;
515 my $column = $$refcolumn;
517 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
519 my $statements;
520 if(s/^\{//) {
521 $column++;
522 $statements = "";
523 } else {
524 return 0;
527 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
529 my $statements_line = $line;
530 my $statements_column = $column;
532 my $plevel = 1;
533 while($plevel > 0) {
534 my $match;
535 $self->_parse_c_until_one_of("\\{\\}", \$_, \$line, \$column, \$match);
537 $column++;
539 $statements .= $match;
540 if(s/^\}//) {
541 $plevel--;
542 if($plevel > 0) {
543 $statements .= "}";
545 } elsif(s/^\{//) {
546 $plevel++;
547 $statements .= "{";
548 } else {
549 return 0;
553 $$refcurrent = $_;
554 $$refline = $line;
555 $$refcolumn = $column;
556 $$refstatements = $statements;
557 $$refstatements_line = $statements_line;
558 $$refstatements_column = $statements_column;
560 return 1;
563 ########################################################################
564 # parse_c_declaration
566 sub parse_c_declaration($$$$$$$$$$$$) {
567 my $self = shift;
569 my $found_declaration = \${$self->{FOUND_DECLARATION}};
570 my $found_function = \${$self->{FOUND_FUNCTION}};
572 my $refcurrent = shift;
573 my $refline = shift;
574 my $refcolumn = shift;
576 local $_ = $$refcurrent;
577 my $line = $$refline;
578 my $column = $$refcolumn;
580 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
582 my $begin_line = $line;
583 my $begin_column = $column + 1;
585 my $end_line = $begin_line;
586 my $end_column = $begin_column;
587 $self->_update_c_position($_, \$end_line, \$end_column);
589 if(!&$$found_declaration($begin_line, $begin_column, $end_line, $end_column, $_)) {
590 return 1;
593 # Function
594 my $function = shift;
596 my $linkage = shift;
597 my $calling_convention = shift;
598 my $return_type = shift;
599 my $name = shift;
600 my @arguments = shift;
601 my @argument_lines = shift;
602 my @argument_columns = shift;
604 # Variable
605 my $type;
607 if(0) {
608 # Nothing
609 } elsif(s/^WINE_(?:DEFAULT|DECLARE)_DEBUG_CHANNEL\s*\(\s*(\w+)\s*\)\s*//s) { # FIXME: Wine specific kludge
610 $self->_update_c_position($&, \$line, \$column);
611 } elsif(s/^__ASM_GLOBAL_FUNC\(\s*(\w+)\s*,\s*//s) { # FIXME: Wine specific kludge
612 $self->_update_c_position($&, \$line, \$column);
613 $self->_parse_c_until_one_of("\)", \$_, \$line, \$column);
614 if(s/\)//) {
615 $column++;
617 } elsif(s/^(?:DEFINE_AVIGUID|DEFINE_OLEGUID)\s*(?=\()//s) { # FIXME: Wine specific kludge
618 $self->_update_c_position($&, \$line, \$column);
620 my @arguments;
621 my @argument_lines;
622 my @argument_columns;
624 if(!$self->parse_c_tuple(\$_, \$line, \$column, \@arguments, \@argument_lines, \@argument_columns)) {
625 return 0;
627 } elsif(s/^DEFINE_COMMON_NOTIFICATIONS\(\s*(\w+)\s*,\s*(\w+)\s*\)//s) { # FIXME: Wine specific kludge
628 $self->_update_c_position($&, \$line, \$column);
629 } elsif(s/^MAKE_FUNCPTR\(\s*(\w+)\s*\)//s) { # FIXME: Wine specific kludge
630 $self->_update_c_position($&, \$line, \$column);
631 } elsif(s/^START_TEST\(\s*(\w+)\s*\)\s*{//s) { # FIXME: Wine specific kludge
632 $self->_update_c_position($&, \$line, \$column);
633 } elsif(s/^int\s*_FUNCTION_\s*{//s) { # FIXME: Wine specific kludge
634 $self->_update_c_position($&, \$line, \$column);
635 } elsif(s/^(?:jump|strong)_alias//s) { # FIXME: GNU C library specific kludge
636 $self->_update_c_position($&, \$line, \$column);
637 } elsif(s/^(?:__asm__|asm)\s*\(//) {
638 $self->_update_c_position($&, \$line, \$column);
639 } elsif($self->parse_c_typedef(\$_, \$line, \$column)) {
640 # Nothing
641 } elsif($self->parse_c_variable(\$_, \$line, \$column, \$linkage, \$type, \$name)) {
642 # Nothing
643 } elsif($self->parse_c_function(\$_, \$line, \$column, \$function)) {
644 if(&$$found_function($function))
646 my $statements = $function->statements;
647 my $statements_line = $function->statements_line;
648 my $statements_column = $function->statements_column;
650 if(defined($statements)) {
651 if(!$self->parse_c_statements(\$statements, \$statements_line, \$statements_column)) {
652 return 0;
656 } else {
657 $self->_parse_c_error($_, $line, $column, "declaration");
660 $$refcurrent = $_;
661 $$refline = $line;
662 $$refcolumn = $column;
664 return 1;
667 ########################################################################
668 # parse_c_declarations
670 sub parse_c_declarations($$$$) {
671 my $self = shift;
673 my $refcurrent = shift;
674 my $refline = shift;
675 my $refcolumn = shift;
677 return 1;
680 ########################################################################
681 # _parse_c
683 sub _parse_c($$$$$$) {
684 my $self = shift;
686 my $pattern = shift;
687 my $refcurrent = shift;
688 my $refline = shift;
689 my $refcolumn = shift;
691 my $refmatch = shift;
693 local $_ = $$refcurrent;
694 my $line = $$refline;
695 my $column = $$refcolumn;
697 my $match;
698 if(s/^(?:$pattern)//s) {
699 $self->_update_c_position($&, \$line, \$column);
700 $match = $&;
701 } else {
702 return 0;
705 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
707 $$refcurrent = $_;
708 $$refline = $line;
709 $$refcolumn = $column;
711 $$refmatch = $match;
713 return 1;
716 ########################################################################
717 # parse_c_enum
719 sub parse_c_enum($$$$) {
720 my $self = shift;
722 my $refcurrent = shift;
723 my $refline = shift;
724 my $refcolumn = shift;
726 local $_ = $$refcurrent;
727 my $line = $$refline;
728 my $column = $$refcolumn;
730 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
732 if (!s/^enum\s+((?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)?\s*\{\s*//s) {
733 return 0;
735 my $_name = $1 || "";
737 $self->_update_c_position($&, \$line, \$column);
739 my $name = "";
741 my $match;
742 while ($self->_parse_c_on_same_level_until_one_of(',', \$_, \$line, \$column, \$match)) {
743 if ($match) {
744 if ($match !~ /^(\w+)\s*(?:=\s*(.*?)\s*)?$/) {
745 $self->_parse_c_error($_, $line, $column, "enum");
747 my $enum_name = $1;
748 my $enum_value = $2 || "";
750 # $output->write("enum:$_name:$enum_name:$enum_value\n");
753 if ($self->_parse_c(',', \$_, \$line, \$column)) {
754 next;
755 } elsif ($self->_parse_c('}', \$_, \$line, \$column)) {
756 # FIXME: Kludge
757 my $tuple = "($_)";
758 my $tuple_line = $line;
759 my $tuple_column = $column - 1;
761 my @arguments;
762 my @argument_lines;
763 my @argument_columns;
765 if(!$self->parse_c_tuple(\$tuple, \$tuple_line, \$tuple_column,
766 \@arguments, \@argument_lines, \@argument_columns))
768 $self->_parse_c_error($_, $line, $column, "enum");
771 # FIXME: Kludge
772 if ($#arguments >= 0) {
773 $name = $arguments[0];
776 last;
777 } else {
778 $self->_parse_c_error($_, $line, $column, "enum");
782 $self->_update_c_position($_, \$line, \$column);
784 $$refcurrent = $_;
785 $$refline = $line;
786 $$refcolumn = $column;
790 ########################################################################
791 # parse_c_expression
793 sub parse_c_expression($$$$) {
794 my $self = shift;
796 my $refcurrent = shift;
797 my $refline = shift;
798 my $refcolumn = shift;
800 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
802 local $_ = $$refcurrent;
803 my $line = $$refline;
804 my $column = $$refcolumn;
806 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
808 while($_) {
809 if(s/^(.*?)(\w+\s*\()/$2/s) {
810 $self->_update_c_position($1, \$line, \$column);
812 my $begin_line = $line;
813 my $begin_column = $column + 1;
815 my $name;
816 my @arguments;
817 my @argument_lines;
818 my @argument_columns;
819 if(!$self->parse_c_function_call(\$_, \$line, \$column, \$name, \@arguments, \@argument_lines, \@argument_columns)) {
820 return 0;
823 if(&$$found_function_call($begin_line, $begin_column, $line, $column, $name, \@arguments))
825 while(defined(my $argument = shift @arguments) &&
826 defined(my $argument_line = shift @argument_lines) &&
827 defined(my $argument_column = shift @argument_columns))
829 $self->parse_c_expression(\$argument, \$argument_line, \$argument_column);
832 } else {
833 $_ = "";
837 $self->_update_c_position($_, \$line, \$column);
839 $$refcurrent = $_;
840 $$refline = $line;
841 $$refcolumn = $column;
843 return 1;
846 ########################################################################
847 # parse_c_file
849 sub parse_c_file($$$$) {
850 my $self = shift;
852 my $found_comment = \${$self->{FOUND_COMMENT}};
853 my $found_line = \${$self->{FOUND_LINE}};
855 my $refcurrent = shift;
856 my $refline = shift;
857 my $refcolumn = shift;
859 local $_ = $$refcurrent;
860 my $line = $$refline;
861 my $column = $$refcolumn;
863 my $declaration = "";
864 my $declaration_line = $line;
865 my $declaration_column = $column;
867 my $previous_line = 0;
868 my $previous_column = -1;
870 my $preprocessor_condition;
871 my $if = 0;
872 my $if0 = 0;
873 my $extern_c = 0;
875 my $blevel = 1;
876 my $plevel = 1;
877 while($plevel > 0 || $blevel > 0) {
878 my $match;
879 $self->_parse_c_until_one_of("#/\\(\\)\\[\\]\\{\\};", \$_, \$line, \$column, \$match);
881 if($line != $previous_line) {
882 &$$found_line($line);
883 } elsif(0 && $column == $previous_column) {
884 $self->_parse_c_error($_, $line, $column, "file", "no progress");
885 } else {
886 # &$$found_line("$line.$column");
888 $previous_line = $line;
889 $previous_column = $column;
891 if($match !~ /^\s+$/s && $options->debug) {
892 $self->_parse_c_warning($_, $line, $column, "file", "$plevel $blevel: '$declaration' '$match'");
895 if(!$declaration && $match =~ s/^\s+//s) {
896 $self->_update_c_position($&, \$declaration_line, \$declaration_column);
899 if(!$if0) {
900 $declaration .= $match;
902 # FIXME: Kludge
903 if ($declaration =~ s/^extern\s*\"C\"//s) {
904 if (s/^\{//) {
905 $self->_update_c_position($&, \$line, \$column);
906 $declaration = "";
907 $declaration_line = $line;
908 $declaration_column = $column;
910 $extern_c = 1;
911 next;
913 } elsif ($extern_c && $blevel == 1 && $plevel == 1 && !$declaration) {
914 if (s/^\}//) {
915 $self->_update_c_position($&, \$line, \$column);
916 $declaration = "";
917 $declaration_line = $line;
918 $declaration_column = $column;
920 $extern_c = 0;
921 next;
923 } elsif($declaration =~ s/^(?:__DEFINE_(?:GET|SET)_SEG|OUR_GUID_ENTRY)\s*(?=\()//sx) { # FIXME: Wine specific kludge
924 my $prefix = $&;
925 if ($plevel > 2 || !s/^\)//) {
926 $declaration = "$prefix$declaration";
927 } else {
928 $plevel--;
929 $self->_update_c_position($&, \$line, \$column);
930 $declaration .= $&;
932 my @arguments;
933 my @argument_lines;
934 my @argument_columns;
936 if(!$self->parse_c_tuple(\$declaration, \$declaration_line, \$declaration_column,
937 \@arguments, \@argument_lines, \@argument_columns))
939 $self->_parse_c_error($declaration, $declaration_line, $declaration_column, "file", "tuple expected");
942 $declaration = "";
943 $declaration_line = $line;
944 $declaration_column = $column;
946 next;
948 } elsif ($declaration =~ s/^(?:DEFINE_SHLGUID)\s*\(.*?\)//s) {
949 $self->_update_c_position($&, \$declaration_line, \$declaration_column);
950 } elsif ($declaration =~ s/^(?:DECL_WINELIB_TYPE_AW|DECLARE_HANDLE(?:16)?|TYPE_MARSHAL)\(\s*(\w+)\s*\)\s*//s) {
951 $self->_update_c_position($&, \$declaration_line, \$declaration_column);
952 } elsif ($declaration =~ s/^ICOM_DEFINE\(\s*(\w+)\s*,\s*(\w+)\s*\)\s*//s) {
953 $self->_update_c_position($&, \$declaration_line, \$declaration_column);
955 } else {
956 my $blank_lines = 0;
958 local $_ = $match;
959 while(s/^.*?\n//) { $blank_lines++; }
961 if(!$declaration) {
962 $declaration_line = $line;
963 $declaration_column = $column;
964 } else {
965 $declaration .= "\n" x $blank_lines;
970 if(/^[\#\/]/) {
971 my $blank_lines = 0;
972 if(s/^\#\s*//) {
973 my $preprocessor_line = $line;
974 my $preprocessor_column = $column;
976 my $preprocessor = $&;
977 while(s/^(.*?)\\\s*\n//) {
978 $blank_lines++;
979 $preprocessor .= "$1\n";
981 if(s/^(.*?)(\/\*.*?\*\/)(.*?)\n//) {
982 $_ = "$2\n$_";
983 if(defined($3)) {
984 $preprocessor .= "$1$3";
985 } else {
986 $preprocessor .= $1;
988 } elsif(s/^(.*?)(\/[\*\/].*?)?\n//) {
989 if(defined($2)) {
990 $_ = "$2\n$_";
991 } else {
992 $blank_lines++;
994 $preprocessor .= $1;
998 if (0) {
999 # Nothing
1000 } elsif($preprocessor =~ /^\#\s*if/) {
1001 if($preprocessor =~ /^\#\s*if\s*0/) {
1002 $if0++;
1003 } elsif($if0 > 0) {
1004 $if++;
1005 } else {
1006 if($preprocessor =~ /^\#\s*ifdef\s+WORDS_BIGENDIAN$/) {
1007 $preprocessor_condition = "defined(WORD_BIGENDIAN)";
1008 # $output->write("'$preprocessor_condition':'$declaration'\n")
1009 } else {
1010 $preprocessor_condition = "";
1013 } elsif($preprocessor =~ /^\#\s*else/) {
1014 if ($preprocessor_condition ne "") {
1015 $preprocessor_condition =~ "!$preprocessor_condition";
1016 $preprocessor_condition =~ s/^!!/!/;
1017 # $output->write("'$preprocessor_condition':'$declaration'\n")
1019 } elsif($preprocessor =~ /^\#\s*endif/) {
1020 if($if0 > 0) {
1021 if($if > 0) {
1022 $if--;
1023 } else {
1024 $if0--;
1026 } else {
1027 if ($preprocessor_condition ne "") {
1028 # $output->write("'$preprocessor_condition':'$declaration'\n");
1029 $preprocessor_condition = "";
1034 if(!$self->parse_c_preprocessor(\$preprocessor, \$preprocessor_line, \$preprocessor_column)) {
1035 return 0;
1039 if(s/^\/\*.*?\*\///s) {
1040 &$$found_comment($line, $column + 1, $&);
1041 local $_ = $&;
1042 while(s/^.*?\n//) {
1043 $blank_lines++;
1045 if($_) {
1046 $column += length($_);
1048 } elsif(s/^\/\/(.*?)\n//) {
1049 &$$found_comment($line, $column + 1, $&);
1050 $blank_lines++;
1051 } elsif(s/^\///) {
1052 if(!$if0) {
1053 $declaration .= $&;
1054 $column++;
1058 $line += $blank_lines;
1059 if($blank_lines > 0) {
1060 $column = 0;
1063 if(!$declaration) {
1064 $declaration_line = $line;
1065 $declaration_column = $column;
1066 } elsif($blank_lines > 0) {
1067 $declaration .= "\n" x $blank_lines;
1070 next;
1073 $column++;
1075 if($if0) {
1076 s/^.//;
1077 next;
1080 if(s/^[\(\[]//) {
1081 $plevel++;
1082 $declaration .= $&;
1083 } elsif(s/^\]//) {
1084 $plevel--;
1085 $declaration .= $&;
1086 } elsif(s/^\)//) {
1087 $plevel--;
1088 if($blevel <= 0) {
1089 $self->_parse_c_error($_, $line, $column, "file", ") without (");
1091 $declaration .= $&;
1092 if($plevel == 1 && $declaration =~ /^__ASM_GLOBAL_FUNC/) {
1093 if(!$self->parse_c_declaration(\$declaration, \$declaration_line, \$declaration_column)) {
1094 return 0;
1096 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1097 $declaration = "";
1098 $declaration_line = $line;
1099 $declaration_column = $column;
1101 } elsif(s/^\{//) {
1102 $blevel++;
1103 $declaration .= $&;
1104 } elsif(s/^\}//) {
1105 $blevel--;
1106 if($blevel <= 0) {
1107 $self->_parse_c_error($_, $line, $column, "file", "} without {");
1110 $declaration .= $&;
1112 if($declaration =~ /^typedef/s ||
1113 $declaration =~ /^(?:const\s+|extern\s+|static\s+|volatile\s+)*(?:interface|struct|union)(?:\s+\w+)?\s*\{/s)
1115 # Nothing
1116 } elsif($plevel == 1 && $blevel == 1) {
1117 if(!$self->parse_c_declaration(\$declaration, \$declaration_line, \$declaration_column)) {
1118 return 0;
1120 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1121 $declaration = "";
1122 $declaration_line = $line;
1123 $declaration_column = $column;
1124 } elsif($column == 1 && !$extern_c) {
1125 $self->_parse_c_error("", $line, $column, "file", "inner } ends on column 1");
1127 } elsif(s/^;//) {
1128 $declaration .= $&;
1129 if(0 && $blevel == 1 &&
1130 $declaration !~ /^typedef/ &&
1131 $declaration !~ /^(?:const\s+|extern\s+|static\s+|volatile\s+)?(?:interface|struct|union)(?:\s+\w+)?\s*\{/s &&
1132 $declaration =~ /^(?:\w+(?:\s*\*)*\s+)*(\w+)\s*\(\s*(?:(?:\w+\s*,\s*)*(\w+))?\s*\)\s*(.*?);$/s &&
1133 $1 ne "ICOM_VTABLE" && defined($2) && $2 ne "void" && $3) # K&R
1135 $self->_parse_c_warning("", $line, $column, "file", "function $1: warning: function has K&R format");
1136 } elsif($plevel == 1 && $blevel == 1) {
1137 $declaration =~ s/\s*;$//;
1138 if($declaration && !$self->parse_c_declaration(\$declaration, \$declaration_line, \$declaration_column)) {
1139 return 0;
1141 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1142 $declaration = "";
1143 $declaration_line = $line;
1144 $declaration_column = $column;
1146 } elsif(/^\s*$/ && $declaration =~ /^\s*$/ && $match =~ /^\s*$/) {
1147 $plevel = 0;
1148 $blevel = 0;
1149 } else {
1150 $self->_parse_c_error($_, $line, $column, "file", "parse error: '$declaration' '$match'");
1154 $$refcurrent = $_;
1155 $$refline = $line;
1156 $$refcolumn = $column;
1158 return 1;
1161 ########################################################################
1162 # parse_c_function
1164 sub parse_c_function($$$$$) {
1165 my $self = shift;
1167 my $file = \${$self->{FILE}};
1168 my $create_function = \${$self->{CREATE_FUNCTION}};
1170 my $refcurrent = shift;
1171 my $refline = shift;
1172 my $refcolumn = shift;
1174 my $reffunction = shift;
1176 local $_ = $$refcurrent;
1177 my $line = $$refline;
1178 my $column = $$refcolumn;
1180 my $linkage = "";
1181 my $calling_convention = "";
1182 my $return_type;
1183 my $name;
1184 my @arguments;
1185 my @argument_lines;
1186 my @argument_columns;
1187 my $statements;
1188 my $statements_line;
1189 my $statements_column;
1191 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1193 my $begin_line = $line;
1194 my $begin_column = $column + 1;
1196 if(0) {
1197 # Nothing
1198 } elsif($self->_parse_c('__declspec\((?:dllexport|dllimport|naked)\)|INTERNETAPI|RPCRTAPI', \$_, \$line, \$column)) {
1199 # Nothing
1202 # $self->_parse_c_warning($_, $line, $column, "function", "");
1204 my $match;
1205 while($self->_parse_c('(?:const|inline|extern(?:\s+\"C\")?|EXTERN_C|static|volatile|' .
1206 'signed(?=\s+__int(?:8|16|32|64)\b|\s+char\b|\s+int\b|\s+long(?:\s+long)?\b|\s+short\b)|' .
1207 'unsigned(?=\s+__int(?:8|16|32|64)\b|\s+char\b|\s+int\b|\s+long(?:\s+long)?\b|\s+short\b)|' .
1208 'long(?=\s+double\b|\s+int\b|\s+long\b))(?=\b)',
1209 \$_, \$line, \$column, \$match))
1211 if($match =~ /^(?:extern|static)$/) {
1212 if(!$linkage) {
1213 $linkage = $match;
1218 if(0) {
1219 # Nothing
1220 } elsif($self->_parse_c('DECL_GLOBAL_CONSTRUCTOR', \$_, \$line, \$column, \$name)) { # FIXME: Wine specific kludge
1221 # Nothing
1222 } elsif($self->_parse_c('WINE_EXCEPTION_FILTER\(\w+\)', \$_, \$line, \$column, \$name)) { # FIXME: Wine specific kludge
1223 # Nothing
1224 } else {
1225 if(!$self->parse_c_type(\$_, \$line, \$column, \$return_type)) {
1226 return 0;
1229 $self->_parse_c('inline|FAR', \$_, \$line, \$column);
1231 $self->_parse_c($CALL_CONVENTION,
1232 \$_, \$line, \$column, \$calling_convention);
1235 # FIXME: ???: Old variant of __attribute((const))
1236 $self->_parse_c('(?:const|volatile)', \$_, \$line, \$column);
1238 if(!$self->_parse_c('(?:operator\s*!=|(?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)', \$_, \$line, \$column, \$name)) {
1239 return 0;
1242 my $p = 0;
1243 if(s/^__P\s*\(//) {
1244 $self->_update_c_position($&, \$line, \$column);
1245 $p = 1;
1248 if(!$self->parse_c_tuple(\$_, \$line, \$column, \@arguments, \@argument_lines, \@argument_columns)) {
1249 return 0;
1252 if($p) {
1253 if (s/^\)//) {
1254 $self->_update_c_position($&, \$line, \$column);
1255 } else {
1256 $self->_parse_c_error($_, $line, $column, "function");
1262 if (0) {
1263 # Nothing
1264 } elsif($self->_parse_c('__attribute__\s*\(\s*\(\s*(?:constructor|destructor)\s*\)\s*\)', \$_, \$line, \$column)) {
1265 # Nothing
1268 my $kar;
1269 # FIXME: Implement proper handling of K&R C functions
1270 $self->_parse_c_until_one_of("{", \$_, \$line, \$column, $kar);
1272 if($kar) {
1273 $output->write("K&R: $kar\n");
1276 if($_ && !$self->parse_c_block(\$_, \$line, \$column, \$statements, \$statements_line, \$statements_column)) {
1277 return 0;
1280 my $end_line = $line;
1281 my $end_column = $column;
1283 $$refcurrent = $_;
1284 $$refline = $line;
1285 $$refcolumn = $column;
1287 my $function = &$$create_function;
1289 $function->file($$file);
1290 $function->begin_line($begin_line);
1291 $function->begin_column($begin_column);
1292 $function->end_line($end_line);
1293 $function->end_column($end_column);
1294 $function->linkage($linkage);
1295 $function->return_type($return_type);
1296 $function->calling_convention($calling_convention);
1297 $function->name($name);
1298 # if(defined($argument_types)) {
1299 # $function->argument_types([@$argument_types]);
1301 # if(defined($argument_names)) {
1302 # $function->argument_names([@$argument_names]);
1304 $function->statements_line($statements_line);
1305 $function->statements_column($statements_column);
1306 $function->statements($statements);
1308 $$reffunction = $function;
1310 return 1;
1313 ########################################################################
1314 # parse_c_function_call
1316 sub parse_c_function_call($$$$$$$$) {
1317 my $self = shift;
1319 my $refcurrent = shift;
1320 my $refline = shift;
1321 my $refcolumn = shift;
1323 my $refname = shift;
1324 my $refarguments = shift;
1325 my $refargument_lines = shift;
1326 my $refargument_columns = shift;
1328 local $_ = $$refcurrent;
1329 my $line = $$refline;
1330 my $column = $$refcolumn;
1332 my $name;
1333 my @arguments;
1334 my @argument_lines;
1335 my @argument_columns;
1337 if(s/^(\w+)(\s*)(?=\()//s) {
1338 $self->_update_c_position($&, \$line, \$column);
1340 $name = $1;
1342 if(!$self->parse_c_tuple(\$_, \$line, \$column, \@arguments, \@argument_lines, \@argument_columns)) {
1343 return 0;
1345 } else {
1346 return 0;
1349 $$refcurrent = $_;
1350 $$refline = $line;
1351 $$refcolumn = $column;
1353 $$refname = $name;
1354 @$refarguments = @arguments;
1355 @$refargument_lines = @argument_lines;
1356 @$refargument_columns = @argument_columns;
1358 return 1;
1361 ########################################################################
1362 # parse_c_preprocessor
1364 sub parse_c_preprocessor($$$$) {
1365 my $self = shift;
1367 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
1369 my $refcurrent = shift;
1370 my $refline = shift;
1371 my $refcolumn = shift;
1373 local $_ = $$refcurrent;
1374 my $line = $$refline;
1375 my $column = $$refcolumn;
1377 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1379 my $begin_line = $line;
1380 my $begin_column = $column + 1;
1382 if(!&$$found_preprocessor($begin_line, $begin_column, "$_")) {
1383 return 1;
1386 if(0) {
1387 # Nothing
1388 } elsif(/^\#\s*define\s*(.*?)$/s) {
1389 $self->_update_c_position($_, \$line, \$column);
1390 } elsif(/^\#\s*else/s) {
1391 $self->_update_c_position($_, \$line, \$column);
1392 } elsif(/^\#\s*endif/s) {
1393 $self->_update_c_position($_, \$line, \$column);
1394 } elsif(/^\#\s*(?:if|ifdef|ifndef)?\s*(.*?)$/s) {
1395 $self->_update_c_position($_, \$line, \$column);
1396 } elsif(/^\#\s*include\s+(.*?)$/s) {
1397 $self->_update_c_position($_, \$line, \$column);
1398 } elsif(/^\#\s*undef\s+(.*?)$/s) {
1399 $self->_update_c_position($_, \$line, \$column);
1400 } else {
1401 $self->_parse_c_error($_, $line, $column, "preprocessor");
1404 $$refcurrent = $_;
1405 $$refline = $line;
1406 $$refcolumn = $column;
1408 return 1;
1411 ########################################################################
1412 # parse_c_statement
1414 sub parse_c_statement($$$$) {
1415 my $self = shift;
1417 my $refcurrent = shift;
1418 my $refline = shift;
1419 my $refcolumn = shift;
1421 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
1423 local $_ = $$refcurrent;
1424 my $line = $$refline;
1425 my $column = $$refcolumn;
1427 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1429 $self->_parse_c('(?:case\s+)?(\w+)\s*:\s*', \$_, \$line, \$column);
1431 # $output->write("$line.$column: statement: '$_'\n");
1433 if(/^$/) {
1434 # Nothing
1435 } elsif(/^\{/) {
1436 my $statements;
1437 my $statements_line;
1438 my $statements_column;
1439 if(!$self->parse_c_block(\$_, \$line, \$column, \$statements, \$statements_line, \$statements_column)) {
1440 return 0;
1442 if(!$self->parse_c_statements(\$statements, \$statements_line, \$statements_column)) {
1443 return 0;
1445 } elsif(s/^(for|if|switch|while)\s*(?=\()//) {
1446 $self->_update_c_position($&, \$line, \$column);
1448 my $name = $1;
1450 my @arguments;
1451 my @argument_lines;
1452 my @argument_columns;
1453 if(!$self->parse_c_tuple(\$_, \$line, \$column, \@arguments, \@argument_lines, \@argument_columns)) {
1454 return 0;
1457 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1458 if(!$self->parse_c_statement(\$_, \$line, \$column)) {
1459 return 0;
1461 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1463 while(defined(my $argument = shift @arguments) &&
1464 defined(my $argument_line = shift @argument_lines) &&
1465 defined(my $argument_column = shift @argument_columns))
1467 $self->parse_c_expression(\$argument, \$argument_line, \$argument_column);
1469 } elsif(s/^else//) {
1470 $self->_update_c_position($&, \$line, \$column);
1471 if(!$self->parse_c_statement(\$_, \$line, \$column)) {
1472 return 0;
1474 } elsif(s/^return//) {
1475 $self->_update_c_position($&, \$line, \$column);
1476 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1477 if(!$self->parse_c_expression(\$_, \$line, \$column)) {
1478 return 0;
1480 } elsif($self->parse_c_expression(\$_, \$line, \$column)) {
1481 # Nothing
1482 } else {
1483 # $self->_parse_c_error($_, $line, $column, "statement");
1486 $self->_update_c_position($_, \$line, \$column);
1488 $$refcurrent = $_;
1489 $$refline = $line;
1490 $$refcolumn = $column;
1492 return 1;
1495 ########################################################################
1496 # parse_c_statements
1498 sub parse_c_statements($$$$) {
1499 my $self = shift;
1501 my $refcurrent = shift;
1502 my $refline = shift;
1503 my $refcolumn = shift;
1505 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
1507 local $_ = $$refcurrent;
1508 my $line = $$refline;
1509 my $column = $$refcolumn;
1511 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1513 # $output->write("$line.$column: statements: '$_'\n");
1515 my $statement = "";
1516 my $statement_line = $line;
1517 my $statement_column = $column;
1519 my $previous_line = -1;
1520 my $previous_column = -1;
1522 my $blevel = 1;
1523 my $plevel = 1;
1524 while($plevel > 0 || $blevel > 0) {
1525 my $match;
1526 $self->_parse_c_until_one_of("\\(\\)\\[\\]\\{\\};", \$_, \$line, \$column, \$match);
1528 if($previous_line == $line && $previous_column == $column) {
1529 $self->_parse_c_error($_, $line, $column, "statements", "no progress");
1531 $previous_line = $line;
1532 $previous_column = $column;
1534 # $output->write("'$match' '$_'\n");
1536 $statement .= $match;
1537 $column++;
1538 if(s/^[\(\[]//) {
1539 $plevel++;
1540 $statement .= $&;
1541 } elsif(s/^[\)\]]//) {
1542 $plevel--;
1543 if($plevel <= 0) {
1544 $self->_parse_c_error($_, $line, $column, "statements");
1546 $statement .= $&;
1547 } elsif(s/^\{//) {
1548 $blevel++;
1549 $statement .= $&;
1550 } elsif(s/^\}//) {
1551 $blevel--;
1552 $statement .= $&;
1553 if($blevel == 1) {
1554 if(!$self->parse_c_statement(\$statement, \$statement_line, \$statement_column)) {
1555 return 0;
1557 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1558 $statement = "";
1559 $statement_line = $line;
1560 $statement_column = $column;
1562 } elsif(s/^;//) {
1563 if($plevel == 1 && $blevel == 1) {
1564 if(!$self->parse_c_statement(\$statement, \$statement_line, \$statement_column)) {
1565 return 0;
1568 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1569 $statement = "";
1570 $statement_line = $line;
1571 $statement_column = $column;
1572 } else {
1573 $statement .= $&;
1575 } elsif(/^\s*$/ && $statement =~ /^\s*$/ && $match =~ /^\s*$/) {
1576 $plevel = 0;
1577 $blevel = 0;
1578 } else {
1579 $self->_parse_c_error($_, $line, $column, "statements");
1583 $self->_update_c_position($_, \$line, \$column);
1585 $$refcurrent = $_;
1586 $$refline = $line;
1587 $$refcolumn = $column;
1589 return 1;
1592 ########################################################################
1593 # parse_c_struct_union
1595 sub parse_c_struct_union($$$$$$$$$) {
1596 my $self = shift;
1598 my $refcurrent = shift;
1599 my $refline = shift;
1600 my $refcolumn = shift;
1602 my $refkind = shift;
1603 my $ref_name = shift;
1604 my $reffield_type_names = shift;
1605 my $reffield_names = shift;
1606 my $refnames = shift;
1608 local $_ = $$refcurrent;
1609 my $line = $$refline;
1610 my $column = $$refcolumn;
1612 my $kind;
1613 my $_name;
1614 my @field_type_names = ();
1615 my @field_names = ();
1616 my @names = ();
1618 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1620 if (!s/^(interface\s+|struct\s+|union\s+)((?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)?\s*\{\s*//s) {
1621 return 0;
1623 $kind = $1;
1624 $_name = $2 || "";
1626 $self->_update_c_position($&, \$line, \$column);
1628 $kind =~ s/\s+//g;
1630 my $match;
1631 while ($_ && $self->_parse_c_on_same_level_until_one_of(';', \$_, \$line, \$column, \$match))
1633 my $field_linkage;
1634 my $field_type_name;
1635 my $field_name;
1637 if ($self->parse_c_variable(\$match, \$line, \$column, \$field_linkage, \$field_type_name, \$field_name)) {
1638 $field_type_name =~ s/\s+/ /g;
1640 push @field_type_names, $field_type_name;
1641 push @field_names, $field_name;
1642 # $output->write("$kind:$_name:$field_type_name:$field_name\n");
1643 } elsif ($match) {
1644 $self->_parse_c_error($_, $line, $column, "typedef $kind: '$match'");
1647 if ($self->_parse_c(';', \$_, \$line, \$column)) {
1648 next;
1649 } elsif ($self->_parse_c('}', \$_, \$line, \$column)) {
1650 # FIXME: Kludge
1651 my $tuple = "($_)";
1652 my $tuple_line = $line;
1653 my $tuple_column = $column - 1;
1655 my @arguments;
1656 my @argument_lines;
1657 my @argument_columns;
1659 if(!$self->parse_c_tuple(\$tuple, \$tuple_line, \$tuple_column,
1660 \@arguments, \@argument_lines, \@argument_columns))
1662 $self->_parse_c_error($_, $line, $column, "$kind");
1665 foreach my $argument (@arguments) {
1666 my $name = $argument;
1668 push @names, $name;
1671 last;
1672 } else {
1673 $self->_parse_c_error($_, $line, $column, "$kind");
1677 $$refcurrent = $_;
1678 $$refline = $line;
1679 $$refcolumn = $column;
1681 $$refkind = $kind;
1682 $$ref_name = $_name;
1683 @$reffield_type_names = @field_type_names;
1684 @$reffield_names = @field_names;
1685 @$refnames = @names;
1687 return 1;
1690 ########################################################################
1691 # parse_c_tuple
1693 sub parse_c_tuple($$$$$$$) {
1694 my $self = shift;
1696 my $refcurrent = shift;
1697 my $refline = shift;
1698 my $refcolumn = shift;
1700 # FIXME: Should not write directly
1701 my $items = shift;
1702 my $item_lines = shift;
1703 my $item_columns = shift;
1705 local $_ = $$refcurrent;
1707 my $line = $$refline;
1708 my $column = $$refcolumn;
1710 my $item;
1711 if(s/^\(//) {
1712 $column++;
1713 $item = "";
1714 } else {
1715 return 0;
1718 my $item_line = $line;
1719 my $item_column = $column + 1;
1721 my $plevel = 1;
1722 while($plevel > 0) {
1723 my $match;
1724 $self->_parse_c_until_one_of("\\(,\\)", \$_, \$line, \$column, \$match);
1726 $column++;
1728 $item .= $match;
1729 if(s/^\)//) {
1730 $plevel--;
1731 if($plevel == 0) {
1732 push @$item_lines, $item_line;
1733 push @$item_columns, $item_column;
1734 push @$items, $item;
1735 $item = "";
1736 } else {
1737 $item .= ")";
1739 } elsif(s/^\(//) {
1740 $plevel++;
1741 $item .= "(";
1742 } elsif(s/^,//) {
1743 if($plevel == 1) {
1744 push @$item_lines, $item_line;
1745 push @$item_columns, $item_column;
1746 push @$items, $item;
1747 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1748 $item_line = $line;
1749 $item_column = $column + 1;
1750 $item = "";
1751 } else {
1752 $item .= ",";
1754 } else {
1755 return 0;
1759 $$refcurrent = $_;
1760 $$refline = $line;
1761 $$refcolumn = $column;
1763 return 1;
1766 ########################################################################
1767 # parse_c_type
1769 sub parse_c_type($$$$$) {
1770 my $self = shift;
1772 my $refcurrent = shift;
1773 my $refline = shift;
1774 my $refcolumn = shift;
1776 my $reftype = shift;
1778 local $_ = $$refcurrent;
1779 my $line = $$refline;
1780 my $column = $$refcolumn;
1782 my $type;
1784 $self->_parse_c("(?:const|volatile)", \$_, \$line, \$column);
1786 if(0) {
1787 # Nothing
1788 } elsif($self->_parse_c('ICOM_VTABLE\(.*?\)', \$_, \$line, \$column, \$type)) {
1789 # Nothing
1790 } elsif($self->_parse_c('(?:enum\s+|interface\s+|struct\s+|union\s+)?(?:(?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)\s*(\*\s*)*',
1791 \$_, \$line, \$column, \$type))
1793 # Nothing
1794 } else {
1795 return 0;
1797 $type =~ s/\s//g;
1799 $$refcurrent = $_;
1800 $$refline = $line;
1801 $$refcolumn = $column;
1803 $$reftype = $type;
1805 return 1;
1808 ########################################################################
1809 # parse_c_typedef
1811 sub parse_c_typedef($$$$) {
1812 my $self = shift;
1814 my $create_type = \${$self->{CREATE_TYPE}};
1815 my $found_type = \${$self->{FOUND_TYPE}};
1816 my $preprocessor_condition = \${$self->{PREPROCESSOR_CONDITION}};
1818 my $refcurrent = shift;
1819 my $refline = shift;
1820 my $refcolumn = shift;
1822 local $_ = $$refcurrent;
1823 my $line = $$refline;
1824 my $column = $$refcolumn;
1826 my $type;
1828 if (!$self->_parse_c("typedef", \$_, \$line, \$column)) {
1829 return 0;
1832 my $finished = 0;
1834 if ($finished) {
1835 # Nothing
1836 } elsif ($self->parse_c_enum(\$_, \$line, \$column)) {
1837 $finished = 1;
1840 my $kind;
1841 my $_name;
1842 my @field_type_names;
1843 my @field_names;
1844 my @names;
1845 if ($finished) {
1846 # Nothing
1847 } elsif ($self->parse_c_struct_union(\$_, \$line, \$column,
1848 \$kind, \$_name, \@field_type_names, \@field_names, \@names))
1850 my $base_name;
1851 foreach my $name (@names)
1853 if ($name =~ /^\w+$/)
1855 $base_name = $name;
1856 last;
1859 $base_name="$kind $_name" if (!defined $base_name and defined $_name);
1860 $base_name=$kind if (!defined $base_name);
1861 foreach my $name (@names) {
1862 if ($name =~ /^\w+$/) {
1863 my $type = &$$create_type();
1865 $type->kind($kind);
1866 $type->_name($_name);
1867 $type->name($name);
1868 $type->field_type_names([@field_type_names]);
1869 $type->field_names([@field_names]);
1871 &$$found_type($type);
1872 } elsif ($name =~ /^(\*+)\s*(?:RESTRICTED_POINTER\s+)?(\w+)$/) {
1873 my $type_name = "$base_name $1";
1874 $name = $2;
1876 my $type = &$$create_type();
1878 $type->kind("");
1879 $type->name($name);
1880 $type->field_type_names([$type_name]);
1881 $type->field_names([""]);
1883 &$$found_type($type);
1884 } else {
1885 $self->_parse_c_error($_, $line, $column, "typedef 2");
1889 $finished = 1;
1892 my $linkage;
1893 my $type_name;
1894 my $name;
1895 if ($finished) {
1896 # Nothing
1897 } elsif ($self->parse_c_variable(\$_, \$line, \$column, \$linkage, \$type_name, \$name)) {
1898 $type_name =~ s/\s+/ /g;
1900 if(defined($type_name) && defined($name)) {
1901 my $type = &$$create_type();
1903 if (length($name) == 0) {
1904 $self->_parse_c_error($_, $line, $column, "typedef");
1907 $type->kind("");
1908 $type->name($name);
1909 $type->field_type_names([$type_name]);
1910 $type->field_names([""]);
1912 &$$found_type($type);
1915 if (0 && $_ && !/^,/) {
1916 $self->_parse_c_error($_, $line, $column, "typedef");
1918 } else {
1919 $self->_parse_c_error($_, $line, $column, "typedef");
1922 $$refcurrent = $_;
1923 $$refline = $line;
1924 $$refcolumn = $column;
1926 return 1;
1929 ########################################################################
1930 # parse_c_variable
1932 sub parse_c_variable($$$$$$$) {
1933 my $self = shift;
1935 my $found_variable = \${$self->{FOUND_VARIABLE}};
1937 my $refcurrent = shift;
1938 my $refline = shift;
1939 my $refcolumn = shift;
1941 my $reflinkage = shift;
1942 my $reftype = shift;
1943 my $refname = shift;
1945 local $_ = $$refcurrent;
1946 my $line = $$refline;
1947 my $column = $$refcolumn;
1949 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1951 my $begin_line = $line;
1952 my $begin_column = $column + 1;
1954 my $linkage = "";
1955 my $sign = "";
1956 my $type = "";
1957 my $name = "";
1959 # $self->_parse_c_warning($_, $line, $column, "variable");
1961 my $match;
1962 while($self->_parse_c('(?:const|inline|extern(?:\s+\"C\")?|EXTERN_C|static|volatile|' .
1963 'signed(?=\s+__int(?:8|16|32|64)\b|\s+char\b|\s+int\b|\s+long(?:\s+long)?\b|\s+short\b)|' .
1964 'unsigned(?=\s+__int(?:8|16|32|64)\b|\s+char\b|\s+int\b|\s+long(?:\s+long)?\b|\s+short\b)|' .
1965 'long(?=\s+double\b|\s+int\b|\s+long\b))(?=\b)',
1966 \$_, \$line, \$column, \$match))
1968 if ($match =~ /^(?:extern|static)$/) {
1969 if (!$linkage) {
1970 $linkage = $match;
1971 } else {
1972 $self->_parse_c_warning($_, $line, $column, "repeated linkage (ignored): $match");
1974 } elsif ($match =~ /^(?:signed|unsigned)$/) {
1975 if (!$sign) {
1976 $sign = "$match ";
1977 } else {
1978 $self->_parse_c_warning($_, $line, $column, "repeated sign (ignored): $match");
1983 my $finished = 0;
1985 if($finished) {
1986 # Nothing
1987 } elsif(/^$/) {
1988 return 0;
1989 } elsif (s/^(enum\s+|interface\s+|struct\s+|union\s+)((?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)?\s*\{\s*//s) {
1990 my $kind = $1;
1991 my $_name = $2;
1992 $self->_update_c_position($&, \$line, \$column);
1994 if(defined($_name)) {
1995 $type = "$kind $_name { }";
1996 } else {
1997 $type = "$kind { }";
2000 $finished = 1;
2001 } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s+DECLSPEC_ALIGN\(.*?\)|\s*(?:const\s*|volatile\s*)?\*)*)\s*(\w+)\s*(\[.*?\]$|:\s*(\d+)$|\{)?//s) {
2002 $type = "$sign$1";
2003 $name = $2;
2005 if (defined($3)) {
2006 my $bits = $4;
2007 local $_ = $3;
2008 if (/^\[/) {
2009 $type .= $_;
2010 } elsif (/^:/) {
2011 $type .= ":$bits";
2012 } elsif (/^\{/) {
2013 # Nothing
2017 $type = $self->_format_c_type($type);
2019 $finished = 1;
2020 } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s*\*)*)\s*:\s*(\d+)$//s) {
2021 $type = "$sign$1:$2";
2022 $name = "";
2023 $type = $self->_format_c_type($type);
2025 $finished = 1;
2026 } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s*\*)*\s*\(\s*(?:$CALL_CONVENTION)?(?:\s*\*)*)\s*(\w+)\s*(\)\s*\(.*?\))$//s) {
2027 $type = $self->_format_c_type("$sign$1$3");
2028 $name = $2;
2030 $finished = 1;
2031 } elsif($self->_parse_c('DEFINE_GUID', \$_, \$line, \$column, \$match)) { # Windows specific
2032 $type = $match;
2033 $finished = 1;
2034 } else {
2035 $self->_parse_c_warning($_, $line, $column, "variable", "'$_'");
2036 $finished = 1;
2039 if($finished) {
2040 # Nothing
2041 } elsif($self->_parse_c('SEQ_DEFINEBUF', \$_, \$line, \$column, \$match)) { # Linux specific
2042 $type = $match;
2043 $finished = 1;
2044 } elsif($self->_parse_c('DEFINE_REGS_ENTRYPOINT_\w+|DPQ_DECL_\w+|HANDLER_DEF|IX86_ONLY', # Wine specific
2045 \$_, \$line, \$column, \$match))
2047 $type = $match;
2048 $finished = 1;
2049 } elsif($self->_parse_c('(?:struct\s+)?ICOM_VTABLE\s*\(\w+\)', \$_, \$line, \$column, \$match)) {
2050 $type = $match;
2051 $finished = 1;
2052 } elsif(s/^(enum|interface|struct|union)(?:\s+(\w+))?\s*\{.*?\}\s*//s) {
2053 my $kind = $1;
2054 my $_name = $2;
2055 $self->_update_c_position($&, \$line, \$column);
2057 if(defined($_name)) {
2058 $type = "struct $_name { }";
2059 } else {
2060 $type = "struct { }";
2062 } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+)\s*(?:\*\s*)*//s) {
2063 $type = $&;
2064 $type =~ s/\s//g;
2065 } else {
2066 return 0;
2069 # $output->write("*** $type: '$_'\n");
2071 # $self->_parse_c_warning($_, $line, $column, "variable2", "");
2073 if($finished) {
2074 # Nothing
2075 } elsif(s/^WINAPI\s*//) {
2076 $self->_update_c_position($&, \$line, \$column);
2079 if($finished) {
2080 # Nothing
2081 } elsif(s/^(\((?:$CALL_CONVENTION)?\s*\*?\s*(?:$CALL_CONVENTION)?\w+\s*(?:\[[^\]]*\]\s*)*\))\s*\(//) {
2082 $self->_update_c_position($&, \$line, \$column);
2084 $name = $1;
2085 $name =~ s/\s//g;
2087 $self->_parse_c_until_one_of("\\)", \$_, \$line, \$column);
2088 if(s/^\)//) { $column++; }
2089 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
2091 if(!s/^(?:=\s*|,\s*|$)//) {
2092 return 0;
2094 } elsif(s/^(?:\*\s*)*(?:const\s+|volatile\s+)?(\w+)\s*(?:\[[^\]]*\]\s*)*\s*(?:=\s*|,\s*|$)//) {
2095 $self->_update_c_position($&, \$line, \$column);
2097 $name = $1;
2098 $name =~ s/\s//g;
2099 } elsif(/^$/) {
2100 $name = "";
2101 } else {
2102 return 0;
2105 # $output->write("$type: $name: '$_'\n");
2107 if(1 || $finished) {
2108 # Nothing
2109 } elsif($self->_parse_c('(?:struct\s+)?ICOM_VTABLE\s*\(.*?\)', \$_, \$line, \$column, \$match)) {
2110 $type = "<type>";
2111 $name = "<name>";
2112 } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+)\s*
2113 (?:\*\s*)*(\w+|\s*\*?\s*\w+\s*\))\s*(?:\[[^\]]*\]|\([^\)]*\))?
2114 (?:,\s*(?:\*\s*)*(\w+)\s*(?:\[[^\]]*\])?)*
2115 \s*(?:=|$)//sx)
2117 $self->_update_c_position($&, \$line, \$column);
2119 $type = $1;
2120 $name = $2;
2122 $type =~ s/\s//g;
2123 $type =~ s/^struct/struct /;
2124 } elsif(/^(enum|interface|struct|union)(?:\s+(\w+))?\s*\{.*?\}\s*((?:\*\s*)*)(\w+)\s*(?:=|$)/s) {
2125 $self->_update_c_position($&, \$line, \$column);
2127 my $kind = $1;
2128 my $_name= $2;
2129 my $stars = $3;
2130 $name = $4;
2132 if(defined($_name)) {
2133 $type = "struct $_name { }";
2134 } else {
2135 $type = "struct { }";
2138 $stars =~ s/\s//g;
2139 if($stars) {
2140 $type .= " $type";
2142 } else {
2143 return 0;
2146 $$refcurrent = $_;
2147 $$refline = $line;
2148 $$refcolumn = $column;
2150 $$reflinkage = $linkage;
2151 $$reftype = $type;
2152 $$refname = $name;
2154 if(&$$found_variable($begin_line, $begin_column, $linkage, $type, $name))
2156 # Nothing
2159 return 1;