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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
30 use options qw($options);
31 use output qw($output);
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|" .
44 ########################################################################
49 my $class = ref($proto) || $proto;
51 bless ($self, $class);
53 my $file = \${$self->{FILE}};
54 my $create_function = \${$self->{CREATE_FUNCTION}};
55 my $create_type = \${$self->{CREATE_TYPE}};
56 my $found_comment = \${$self->{FOUND_COMMENT}};
57 my $found_declaration = \${$self->{FOUND_DECLARATION}};
58 my $found_function = \${$self->{FOUND_FUNCTION}};
59 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
60 my $found_line = \${$self->{FOUND_LINE}};
61 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
62 my $found_statement = \${$self->{FOUND_STATEMENT}};
63 my $found_type = \${$self->{FOUND_TYPE}};
64 my $found_variable = \${$self->{FOUND_VARIABLE}};
68 $$create_function = sub { return new c_function; };
69 $$create_type = sub { return new c_type; };
70 $$found_comment = sub { return 1; };
71 $$found_declaration = sub { return 1; };
72 $$found_function = sub { return 1; };
73 $$found_function_call = sub { return 1; };
74 $$found_line = sub { return 1; };
75 $$found_preprocessor = sub { return 1; };
76 $$found_statement = sub { return 1; };
77 $$found_type = sub { return 1; };
78 $$found_variable = sub { return 1; };
83 ########################################################################
84 # set_found_comment_callback
86 sub set_found_comment_callback {
89 my $found_comment = \${$self->{FOUND_COMMENT}};
91 $$found_comment = shift;
94 ########################################################################
95 # set_found_declaration_callback
97 sub set_found_declaration_callback {
100 my $found_declaration = \${$self->{FOUND_DECLARATION}};
102 $$found_declaration = shift;
105 ########################################################################
106 # set_found_function_callback
108 sub set_found_function_callback {
111 my $found_function = \${$self->{FOUND_FUNCTION}};
113 $$found_function = shift;
116 ########################################################################
117 # set_found_function_call_callback
119 sub set_found_function_call_callback {
122 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
124 $$found_function_call = shift;
127 ########################################################################
128 # set_found_line_callback
130 sub set_found_line_callback {
133 my $found_line = \${$self->{FOUND_LINE}};
135 $$found_line = shift;
138 ########################################################################
139 # set_found_preprocessor_callback
141 sub set_found_preprocessor_callback {
144 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
146 $$found_preprocessor = shift;
149 ########################################################################
150 # set_found_statement_callback
152 sub set_found_statement_callback {
155 my $found_statement = \${$self->{FOUND_STATEMENT}};
157 $$found_statement = shift;
160 ########################################################################
161 # set_found_type_callback
163 sub set_found_type_callback {
166 my $found_type = \${$self->{FOUND_TYPE}};
168 $$found_type = shift;
171 ########################################################################
172 # set_found_variable_callback
174 sub set_found_variable_callback {
177 my $found_variable = \${$self->{FOUND_VARIABLE}};
179 $$found_variable = shift;
183 ########################################################################
192 if (/^(\w+(?:\s*\*)*)\s*\(\s*\*\s*\)\s*\(\s*(.*?)\s*\)$/s) {
193 my $return_type = $1;
194 my @arguments = split(/\s*,\s*/, $2);
195 foreach my $argument (@arguments) {
196 if ($argument =~ s/^(\w+(?:\s*\*)*)\s*\w+$/$1/) {
197 $argument =~ s/\s+/ /g;
198 $argument =~ s/\s*\*\s*/*/g;
199 $argument =~ s/(\*+)$/ $1/;
203 $_ = "$return_type (*)(" . join(", ", @arguments) . ")";
210 ########################################################################
217 my $refcurrent = shift;
219 my $refcolumn = shift;
221 my $refmatch = shift;
223 local $_ = $$refcurrent;
224 my $line = $$refline;
225 my $column = $$refcolumn;
228 if(s/^(?:$pattern)//s) {
229 $self->_update_c_position($&, \$line, \$column);
235 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
239 $$refcolumn = $column;
246 ########################################################################
258 $message = "parse error" if !$message;
261 if($output->prefix) {
262 # $output->write("\n");
266 $self->_parse_c_warning($_, $line, $column, $context, $message);
271 ########################################################################
274 # FIXME: Use caller (See man perlfunc)
276 sub _parse_c_warning {
285 my $file = \${$self->{FILE}};
287 $message = "warning" if !$message;
291 my @lines = split(/\n/, $_);
293 $current .= $lines[0] . "\n" if $lines[0];
294 $current .= $lines[1] . "\n" if $lines[1];
298 (my $package, my $filename, my $line) = caller(0);
299 $output->write("*** caller ***: $filename:$line\n");
303 $output->write("$$file:$line." . ($column + 1) . ": $context: $message: \\\n$current");
305 $output->write("$$file:$line." . ($column + 1) . ": $context: $message\n");
309 ########################################################################
310 # __parse_c_until_one_of
312 sub __parse_c_until_one_of {
315 my $characters = shift;
316 my $on_same_level = shift;
317 my $refcurrent = shift;
319 my $refcolumn = shift;
322 local $_ = $$refcurrent;
323 my $line = $$refline;
324 my $column = $$refcolumn;
327 if(!defined($match)) {
329 $match = \$blackhole;
334 while(/^[^$characters]/s || $level > 0) {
338 if(s/^[^\(\)\[\]\{\}\n\t\'\"]*//s) {
341 } elsif ($on_same_level) {
342 if(s/^[^$characters\(\)\[\]\{\}\n\t\'\"]*//s) {
346 if(s/^[^$characters\n\t\'\"]*//s) {
353 while(/^./ && !s/^\'//) {
369 $$match .= $submatch;
370 $column += length($submatch);
373 while(/^./ && !s/^\"//) {
389 $$match .= $submatch;
390 $column += length($submatch);
391 } elsif($on_same_level && s/^[\(\[\{]//) {
395 $$match .= $submatch;
397 } elsif($on_same_level && s/^[\)\]\}]//) {
402 $$match .= $submatch;
406 $$match .= $submatch;
412 $$match .= $submatch;
418 $$match .= $submatch;
419 $column = $column + 8 - $column % 8;
421 $$match .= $submatch;
422 $column += length($submatch);
428 $$refcolumn = $column;
432 ########################################################################
433 # _parse_c_until_one_of
435 sub _parse_c_until_one_of {
438 my $characters = shift;
439 my $refcurrent = shift;
441 my $refcolumn = shift;
444 return $self->__parse_c_until_one_of($characters, 0, $refcurrent, $refline, $refcolumn, $match);
447 ########################################################################
448 # _parse_c_on_same_level_until_one_of
450 sub _parse_c_on_same_level_until_one_of {
453 my $characters = shift;
454 my $refcurrent = shift;
456 my $refcolumn = shift;
459 return $self->__parse_c_until_one_of($characters, 1, $refcurrent, $refline, $refcolumn, $match);
462 ########################################################################
465 sub _update_c_position {
470 my $refcolumn = shift;
472 my $line = $$refline;
473 my $column = $$refcolumn;
476 if(s/^[^\n\t\'\"]*//s) {
477 $column += length($&);
482 while(/^./ && !s/^\'//) {
484 $column += length($1);
488 $column += length($1);
491 $column += length($1);
499 while(/^./ && !s/^\"//) {
501 $column += length($1);
505 $column += length($1);
508 $column += length($1);
518 $column = $column + 8 - $column % 8;
523 $$refcolumn = $column;
526 ########################################################################
532 my $refcurrent = shift;
534 my $refcolumn = shift;
536 my $refstatements = shift;
537 my $refstatements_line = shift;
538 my $refstatements_column = shift;
540 local $_ = $$refcurrent;
541 my $line = $$refline;
542 my $column = $$refcolumn;
544 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
554 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
556 my $statements_line = $line;
557 my $statements_column = $column;
562 $self->_parse_c_until_one_of("\\{\\}", \$_, \$line, \$column, \$match);
566 $statements .= $match;
582 $$refcolumn = $column;
583 $$refstatements = $statements;
584 $$refstatements_line = $statements_line;
585 $$refstatements_column = $statements_column;
590 ########################################################################
591 # parse_c_declaration
593 sub parse_c_declaration {
596 my $found_declaration = \${$self->{FOUND_DECLARATION}};
597 my $found_function = \${$self->{FOUND_FUNCTION}};
599 my $refcurrent = shift;
601 my $refcolumn = shift;
603 local $_ = $$refcurrent;
604 my $line = $$refline;
605 my $column = $$refcolumn;
607 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
609 my $begin_line = $line;
610 my $begin_column = $column + 1;
612 my $end_line = $begin_line;
613 my $end_column = $begin_column;
614 $self->_update_c_position($_, \$end_line, \$end_column);
616 if(!&$$found_declaration($begin_line, $begin_column, $end_line, $end_column, $_)) {
621 my $function = shift;
624 my $calling_convention = shift;
625 my $return_type = shift;
627 my @arguments = shift;
628 my @argument_lines = shift;
629 my @argument_columns = shift;
636 } elsif(s/^WINE_(?:DEFAULT|DECLARE)_DEBUG_CHANNEL\s*\(\s*(\w+)\s*\)\s*//s) { # FIXME: Wine specific kludge
637 $self->_update_c_position($&, \$line, \$column);
638 } elsif(s/^__ASM_GLOBAL_FUNC\(\s*(\w+)\s*,\s*//s) { # FIXME: Wine specific kludge
639 $self->_update_c_position($&, \$line, \$column);
640 $self->_parse_c_until_one_of("\)", \$_, \$line, \$column);
644 } elsif(s/^(?:DEFINE_AVIGUID|DEFINE_OLEGUID)\s*(?=\()//s) { # FIXME: Wine specific kludge
645 $self->_update_c_position($&, \$line, \$column);
649 my @argument_columns;
651 if(!$self->parse_c_tuple(\$_, \$line, \$column, \@arguments, \@argument_lines, \@argument_columns)) {
654 } elsif(s/^DEFINE_COMMON_NOTIFICATIONS\(\s*(\w+)\s*,\s*(\w+)\s*\)//s) { # FIXME: Wine specific kludge
655 $self->_update_c_position($&, \$line, \$column);
656 } elsif(s/^MAKE_FUNCPTR\(\s*(\w+)\s*\)//s) { # FIXME: Wine specific kludge
657 $self->_update_c_position($&, \$line, \$column);
658 } elsif(s/^START_TEST\(\s*(\w+)\s*\)\s*{//s) { # FIXME: Wine specific kludge
659 $self->_update_c_position($&, \$line, \$column);
660 } elsif(s/^int\s*_FUNCTION_\s*{//s) { # FIXME: Wine specific kludge
661 $self->_update_c_position($&, \$line, \$column);
662 } elsif(s/^(?:jump|strong)_alias//s) { # FIXME: GNU C library specific kludge
663 $self->_update_c_position($&, \$line, \$column);
664 } elsif(s/^(?:__asm__|asm)\s*\(//) {
665 $self->_update_c_position($&, \$line, \$column);
666 } elsif($self->parse_c_typedef(\$_, \$line, \$column)) {
668 } elsif($self->parse_c_variable(\$_, \$line, \$column, \$linkage, \$type, \$name)) {
670 } elsif($self->parse_c_function(\$_, \$line, \$column, \$function)) {
671 if(&$$found_function($function))
673 my $statements = $function->statements;
674 my $statements_line = $function->statements_line;
675 my $statements_column = $function->statements_column;
677 if(defined($statements)) {
678 if(!$self->parse_c_statements(\$statements, \$statements_line, \$statements_column)) {
684 $self->_parse_c_error($_, $line, $column, "declaration");
689 $$refcolumn = $column;
694 ########################################################################
695 # parse_c_declarations
697 sub parse_c_declarations {
700 my $refcurrent = shift;
702 my $refcolumn = shift;
707 ########################################################################
713 my $refcurrent = shift;
715 my $refcolumn = shift;
717 local $_ = $$refcurrent;
718 my $line = $$refline;
719 my $column = $$refcolumn;
721 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
723 if (!s/^enum\s+((?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)?\s*\{\s*//s) {
726 my $_name = $1 || "";
728 $self->_update_c_position($&, \$line, \$column);
733 while ($self->_parse_c_on_same_level_until_one_of(',', \$_, \$line, \$column, \$match)) {
735 if ($match !~ /^(\w+)\s*(?:=\s*(.*?)\s*)?$/) {
736 $self->_parse_c_error($_, $line, $column, "enum");
739 my $enum_value = $2 || "";
741 # $output->write("enum:$_name:$enum_name:$enum_value\n");
744 if ($self->_parse_c(',', \$_, \$line, \$column)) {
746 } elsif ($self->_parse_c('}', \$_, \$line, \$column)) {
749 my $tuple_line = $line;
750 my $tuple_column = $column - 1;
754 my @argument_columns;
756 if(!$self->parse_c_tuple(\$tuple, \$tuple_line, \$tuple_column,
757 \@arguments, \@argument_lines, \@argument_columns))
759 $self->_parse_c_error($_, $line, $column, "enum");
763 if ($#arguments >= 0) {
764 $name = $arguments[0];
769 $self->_parse_c_error($_, $line, $column, "enum");
773 $self->_update_c_position($_, \$line, \$column);
777 $$refcolumn = $column;
781 ########################################################################
784 sub parse_c_expression {
787 my $refcurrent = shift;
789 my $refcolumn = shift;
791 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
793 local $_ = $$refcurrent;
794 my $line = $$refline;
795 my $column = $$refcolumn;
797 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
800 if(s/^(.*?)(\w+\s*\()/$2/s) {
801 $self->_update_c_position($1, \$line, \$column);
803 my $begin_line = $line;
804 my $begin_column = $column + 1;
809 my @argument_columns;
810 if(!$self->parse_c_function_call(\$_, \$line, \$column, \$name, \@arguments, \@argument_lines, \@argument_columns)) {
814 if(&$$found_function_call($begin_line, $begin_column, $line, $column, $name, \@arguments))
816 while(defined(my $argument = shift @arguments) &&
817 defined(my $argument_line = shift @argument_lines) &&
818 defined(my $argument_column = shift @argument_columns))
820 $self->parse_c_expression(\$argument, \$argument_line, \$argument_column);
828 $self->_update_c_position($_, \$line, \$column);
832 $$refcolumn = $column;
837 ########################################################################
843 my $found_comment = \${$self->{FOUND_COMMENT}};
844 my $found_line = \${$self->{FOUND_LINE}};
846 my $refcurrent = shift;
848 my $refcolumn = shift;
850 local $_ = $$refcurrent;
851 my $line = $$refline;
852 my $column = $$refcolumn;
854 my $declaration = "";
855 my $declaration_line = $line;
856 my $declaration_column = $column;
858 my $previous_line = 0;
859 my $previous_column = -1;
861 my $preprocessor_condition;
868 while($plevel > 0 || $blevel > 0) {
870 $self->_parse_c_until_one_of("#/\\(\\)\\[\\]\\{\\};", \$_, \$line, \$column, \$match);
872 if($line != $previous_line) {
873 &$$found_line($line);
874 } elsif(0 && $column == $previous_column) {
875 $self->_parse_c_error($_, $line, $column, "file", "no progress");
877 # &$$found_line("$line.$column");
879 $previous_line = $line;
880 $previous_column = $column;
882 if($match !~ /^\s+$/s && $options->debug) {
883 $self->_parse_c_warning($_, $line, $column, "file", "$plevel $blevel: '$declaration' '$match'");
886 if(!$declaration && $match =~ s/^\s+//s) {
887 $self->_update_c_position($&, \$declaration_line, \$declaration_column);
891 $declaration .= $match;
894 if ($declaration =~ s/^extern\s*\"C\"//s) {
896 $self->_update_c_position($&, \$line, \$column);
898 $declaration_line = $line;
899 $declaration_column = $column;
904 } elsif ($extern_c && $blevel == 1 && $plevel == 1 && !$declaration) {
906 $self->_update_c_position($&, \$line, \$column);
908 $declaration_line = $line;
909 $declaration_column = $column;
914 } elsif($declaration =~ s/^(?:__DEFINE_(?:GET|SET)_SEG|OUR_GUID_ENTRY)\s*(?=\()//sx) { # FIXME: Wine specific kludge
916 if ($plevel > 2 || !s/^\)//) {
917 $declaration = "$prefix$declaration";
920 $self->_update_c_position($&, \$line, \$column);
925 my @argument_columns;
927 if(!$self->parse_c_tuple(\$declaration, \$declaration_line, \$declaration_column,
928 \@arguments, \@argument_lines, \@argument_columns))
930 $self->_parse_c_error($declaration, $declaration_line, $declaration_column, "file", "tuple expected");
934 $declaration_line = $line;
935 $declaration_column = $column;
939 } elsif ($declaration =~ s/^(?:DEFINE_SHLGUID)\s*\(.*?\)//s) {
940 $self->_update_c_position($&, \$declaration_line, \$declaration_column);
941 } elsif ($declaration =~ s/^(?:DECL_WINELIB_TYPE_AW|DECLARE_HANDLE(?:16)?|TYPE_MARSHAL)\(\s*(\w+)\s*\)\s*//s) {
942 $self->_update_c_position($&, \$declaration_line, \$declaration_column);
943 } elsif ($declaration =~ s/^ICOM_DEFINE\(\s*(\w+)\s*,\s*(\w+)\s*\)\s*//s) {
944 $self->_update_c_position($&, \$declaration_line, \$declaration_column);
950 while(s/^.*?\n//) { $blank_lines++; }
953 $declaration_line = $line;
954 $declaration_column = $column;
956 $declaration .= "\n" x $blank_lines;
964 my $preprocessor_line = $line;
965 my $preprocessor_column = $column;
967 my $preprocessor = $&;
968 while(s/^(.*?)\\\s*\n//) {
970 $preprocessor .= "$1\n";
972 if(s/^(.*?)(\/\*.*?\*\/)(.*?)\n//) {
975 $preprocessor .= "$1$3";
979 } elsif(s/^(.*?)(\/[\*\/].*?)?\n//) {
991 } elsif($preprocessor =~ /^\#\s*if/) {
992 if($preprocessor =~ /^\#\s*if\s*0/) {
997 if($preprocessor =~ /^\#\s*ifdef\s+WORDS_BIGENDIAN$/) {
998 $preprocessor_condition = "defined(WORD_BIGENDIAN)";
999 # $output->write("'$preprocessor_condition':'$declaration'\n")
1001 $preprocessor_condition = "";
1004 } elsif($preprocessor =~ /^\#\s*else/) {
1005 if ($preprocessor_condition ne "") {
1006 $preprocessor_condition =~ "!$preprocessor_condition";
1007 $preprocessor_condition =~ s/^!!/!/;
1008 # $output->write("'$preprocessor_condition':'$declaration'\n")
1010 } elsif($preprocessor =~ /^\#\s*endif/) {
1018 if ($preprocessor_condition ne "") {
1019 # $output->write("'$preprocessor_condition':'$declaration'\n");
1020 $preprocessor_condition = "";
1025 if(!$self->parse_c_preprocessor(\$preprocessor, \$preprocessor_line, \$preprocessor_column)) {
1030 if(s/^\/\*.*?\*\///s) {
1031 &$$found_comment($line, $column + 1, $&);
1037 $column += length($_);
1039 } elsif(s/^\/\/(.*?)\n//) {
1040 &$$found_comment($line, $column + 1, $&);
1049 $line += $blank_lines;
1050 if($blank_lines > 0) {
1055 $declaration_line = $line;
1056 $declaration_column = $column;
1057 } elsif($blank_lines > 0) {
1058 $declaration .= "\n" x $blank_lines;
1080 $self->_parse_c_error($_, $line, $column, "file", ") without (");
1083 if($plevel == 1 && $declaration =~ /^__ASM_GLOBAL_FUNC/) {
1084 if(!$self->parse_c_declaration(\$declaration, \$declaration_line, \$declaration_column)) {
1087 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1089 $declaration_line = $line;
1090 $declaration_column = $column;
1098 $self->_parse_c_error($_, $line, $column, "file", "} without {");
1103 if($declaration =~ /^typedef/s ||
1104 $declaration =~ /^(?:const\s+|extern\s+|static\s+)*(?:struct|union)(?:\s+\w+)?\s*\{/s)
1107 } elsif($plevel == 1 && $blevel == 1) {
1108 if(!$self->parse_c_declaration(\$declaration, \$declaration_line, \$declaration_column)) {
1111 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1113 $declaration_line = $line;
1114 $declaration_column = $column;
1115 } elsif($column == 1 && !$extern_c) {
1116 $self->_parse_c_error("", $line, $column, "file", "inner } ends on column 1");
1120 if(0 && $blevel == 1 &&
1121 $declaration !~ /^typedef/ &&
1122 $declaration !~ /^(?:const\s+|extern\s+|static\s+)?(?:struct|union)(?:\s+\w+)?\s*\{/s &&
1123 $declaration =~ /^(?:\w+(?:\s*\*)*\s+)*(\w+)\s*\(\s*(?:(?:\w+\s*,\s*)*(\w+))?\s*\)\s*(.*?);$/s &&
1124 $1 ne "ICOM_VTABLE" && defined($2) && $2 ne "void" && $3) # K&R
1126 $self->_parse_c_warning("", $line, $column, "file", "function $1: warning: function has K&R format");
1127 } elsif($plevel == 1 && $blevel == 1) {
1128 $declaration =~ s/\s*;$//;
1129 if($declaration && !$self->parse_c_declaration(\$declaration, \$declaration_line, \$declaration_column)) {
1132 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1134 $declaration_line = $line;
1135 $declaration_column = $column;
1137 } elsif(/^\s*$/ && $declaration =~ /^\s*$/ && $match =~ /^\s*$/) {
1141 $self->_parse_c_error($_, $line, $column, "file", "parse error: '$declaration' '$match'");
1147 $$refcolumn = $column;
1152 ########################################################################
1155 sub parse_c_function {
1158 my $file = \${$self->{FILE}};
1159 my $create_function = \${$self->{CREATE_FUNCTION}};
1161 my $refcurrent = shift;
1162 my $refline = shift;
1163 my $refcolumn = shift;
1165 my $reffunction = shift;
1167 local $_ = $$refcurrent;
1168 my $line = $$refline;
1169 my $column = $$refcolumn;
1172 my $calling_convention = "";
1177 my @argument_columns;
1179 my $statements_line;
1180 my $statements_column;
1182 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1184 my $begin_line = $line;
1185 my $begin_column = $column + 1;
1189 } elsif($self->_parse_c('__declspec\((?:dllexport|dllimport|naked)\)|INTERNETAPI|RPCRTAPI', \$_, \$line, \$column)) {
1193 # $self->_parse_c_warning($_, $line, $column, "function", "");
1196 while($self->_parse_c('(?:const|inline|extern(?:\s+\"C\")?|EXTERN_C|static|volatile|' .
1197 'signed(?=\s+__int(?:8|16|32|64)\b|\s+char\b|\s+int\b|\s+long(?:\s+long)?\b|\s+short\b)|' .
1198 'unsigned(?=\s+__int(?:8|16|32|64)\b|\s+char\b|\s+int\b|\s+long(?:\s+long)?\b|\s+short\b)|' .
1199 'long(?=\s+double\b|\s+int\b|\s+long\b))(?=\b)',
1200 \$_, \$line, \$column, \$match))
1202 if($match =~ /^extern|static$/) {
1211 } elsif($self->_parse_c('DECL_GLOBAL_CONSTRUCTOR', \$_, \$line, \$column, \$name)) { # FIXME: Wine specific kludge
1213 } elsif($self->_parse_c('WINE_EXCEPTION_FILTER\(\w+\)', \$_, \$line, \$column, \$name)) { # FIXME: Wine specific kludge
1216 if(!$self->parse_c_type(\$_, \$line, \$column, \$return_type)) {
1220 $self->_parse_c('inline|FAR', \$_, \$line, \$column);
1222 $self->_parse_c($CALL_CONVENTION,
1223 \$_, \$line, \$column, \$calling_convention);
1226 # FIXME: ???: Old variant of __attribute((const))
1227 $self->_parse_c('const', \$_, \$line, \$column);
1229 if(!$self->_parse_c('(?:operator\s*!=|(?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)', \$_, \$line, \$column, \$name)) {
1235 $self->_update_c_position($&, \$line, \$column);
1239 if(!$self->parse_c_tuple(\$_, \$line, \$column, \@arguments, \@argument_lines, \@argument_columns)) {
1245 $self->_update_c_position($&, \$line, \$column);
1247 $self->_parse_c_error($_, $line, $column, "function");
1255 } elsif($self->_parse_c('__attribute__\s*\(\s*\(\s*(?:constructor|destructor)\s*\)\s*\)', \$_, \$line, \$column)) {
1260 # FIXME: Implement proper handling of K&R C functions
1261 $self->_parse_c_until_one_of("{", \$_, \$line, \$column, $kar);
1264 $output->write("K&R: $kar\n");
1267 if($_ && !$self->parse_c_block(\$_, \$line, \$column, \$statements, \$statements_line, \$statements_column)) {
1271 my $end_line = $line;
1272 my $end_column = $column;
1276 $$refcolumn = $column;
1278 my $function = &$$create_function;
1280 $function->file($$file);
1281 $function->begin_line($begin_line);
1282 $function->begin_column($begin_column);
1283 $function->end_line($end_line);
1284 $function->end_column($end_column);
1285 $function->linkage($linkage);
1286 $function->return_type($return_type);
1287 $function->calling_convention($calling_convention);
1288 $function->name($name);
1289 # if(defined($argument_types)) {
1290 # $function->argument_types([@$argument_types]);
1292 # if(defined($argument_names)) {
1293 # $function->argument_names([@$argument_names]);
1295 $function->statements_line($statements_line);
1296 $function->statements_column($statements_column);
1297 $function->statements($statements);
1299 $$reffunction = $function;
1304 ########################################################################
1305 # parse_c_function_call
1307 sub parse_c_function_call {
1310 my $refcurrent = shift;
1311 my $refline = shift;
1312 my $refcolumn = shift;
1314 my $refname = shift;
1315 my $refarguments = shift;
1316 my $refargument_lines = shift;
1317 my $refargument_columns = shift;
1319 local $_ = $$refcurrent;
1320 my $line = $$refline;
1321 my $column = $$refcolumn;
1326 my @argument_columns;
1328 if(s/^(\w+)(\s*)(?=\()//s) {
1329 $self->_update_c_position($&, \$line, \$column);
1333 if(!$self->parse_c_tuple(\$_, \$line, \$column, \@arguments, \@argument_lines, \@argument_columns)) {
1342 $$refcolumn = $column;
1345 @$refarguments = @arguments;
1346 @$refargument_lines = @argument_lines;
1347 @$refargument_columns = @argument_columns;
1352 ########################################################################
1353 # parse_c_preprocessor
1355 sub parse_c_preprocessor {
1358 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
1360 my $refcurrent = shift;
1361 my $refline = shift;
1362 my $refcolumn = shift;
1364 local $_ = $$refcurrent;
1365 my $line = $$refline;
1366 my $column = $$refcolumn;
1368 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1370 my $begin_line = $line;
1371 my $begin_column = $column + 1;
1373 if(!&$$found_preprocessor($begin_line, $begin_column, "$_")) {
1379 } elsif(/^\#\s*define\s*(.*?)$/s) {
1380 $self->_update_c_position($_, \$line, \$column);
1381 } elsif(/^\#\s*else/s) {
1382 $self->_update_c_position($_, \$line, \$column);
1383 } elsif(/^\#\s*endif/s) {
1384 $self->_update_c_position($_, \$line, \$column);
1385 } elsif(/^\#\s*(?:if|ifdef|ifndef)?\s*(.*?)$/s) {
1386 $self->_update_c_position($_, \$line, \$column);
1387 } elsif(/^\#\s*include\s+(.*?)$/s) {
1388 $self->_update_c_position($_, \$line, \$column);
1389 } elsif(/^\#\s*undef\s+(.*?)$/s) {
1390 $self->_update_c_position($_, \$line, \$column);
1392 $self->_parse_c_error($_, $line, $column, "preprocessor");
1397 $$refcolumn = $column;
1402 ########################################################################
1405 sub parse_c_statement {
1408 my $refcurrent = shift;
1409 my $refline = shift;
1410 my $refcolumn = shift;
1412 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
1414 local $_ = $$refcurrent;
1415 my $line = $$refline;
1416 my $column = $$refcolumn;
1418 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1420 $self->_parse_c('(?:case\s+)?(\w+)\s*:\s*', \$_, \$line, \$column);
1422 # $output->write("$line.$column: statement: '$_'\n");
1428 my $statements_line;
1429 my $statements_column;
1430 if(!$self->parse_c_block(\$_, \$line, \$column, \$statements, \$statements_line, \$statements_column)) {
1433 if(!$self->parse_c_statements(\$statements, \$statements_line, \$statements_column)) {
1436 } elsif(s/^(for|if|switch|while)\s*(?=\()//) {
1437 $self->_update_c_position($&, \$line, \$column);
1443 my @argument_columns;
1444 if(!$self->parse_c_tuple(\$_, \$line, \$column, \@arguments, \@argument_lines, \@argument_columns)) {
1448 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1449 if(!$self->parse_c_statement(\$_, \$line, \$column)) {
1452 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1454 while(defined(my $argument = shift @arguments) &&
1455 defined(my $argument_line = shift @argument_lines) &&
1456 defined(my $argument_column = shift @argument_columns))
1458 $self->parse_c_expression(\$argument, \$argument_line, \$argument_column);
1460 } elsif(s/^else//) {
1461 $self->_update_c_position($&, \$line, \$column);
1462 if(!$self->parse_c_statement(\$_, \$line, \$column)) {
1465 } elsif(s/^return//) {
1466 $self->_update_c_position($&, \$line, \$column);
1467 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1468 if(!$self->parse_c_expression(\$_, \$line, \$column)) {
1471 } elsif($self->parse_c_expression(\$_, \$line, \$column)) {
1474 # $self->_parse_c_error($_, $line, $column, "statement");
1477 $self->_update_c_position($_, \$line, \$column);
1481 $$refcolumn = $column;
1486 ########################################################################
1487 # parse_c_statements
1489 sub parse_c_statements {
1492 my $refcurrent = shift;
1493 my $refline = shift;
1494 my $refcolumn = shift;
1496 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
1498 local $_ = $$refcurrent;
1499 my $line = $$refline;
1500 my $column = $$refcolumn;
1502 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1504 # $output->write("$line.$column: statements: '$_'\n");
1507 my $statement_line = $line;
1508 my $statement_column = $column;
1510 my $previous_line = -1;
1511 my $previous_column = -1;
1515 while($plevel > 0 || $blevel > 0) {
1517 $self->_parse_c_until_one_of("\\(\\)\\[\\]\\{\\};", \$_, \$line, \$column, \$match);
1519 if($previous_line == $line && $previous_column == $column) {
1520 $self->_parse_c_error($_, $line, $column, "statements", "no progress");
1522 $previous_line = $line;
1523 $previous_column = $column;
1525 # $output->write("'$match' '$_'\n");
1527 $statement .= $match;
1532 } elsif(s/^[\)\]]//) {
1535 $self->_parse_c_error($_, $line, $column, "statements");
1545 if(!$self->parse_c_statement(\$statement, \$statement_line, \$statement_column)) {
1548 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1550 $statement_line = $line;
1551 $statement_column = $column;
1554 if($plevel == 1 && $blevel == 1) {
1555 if(!$self->parse_c_statement(\$statement, \$statement_line, \$statement_column)) {
1559 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1561 $statement_line = $line;
1562 $statement_column = $column;
1566 } elsif(/^\s*$/ && $statement =~ /^\s*$/ && $match =~ /^\s*$/) {
1570 $self->_parse_c_error($_, $line, $column, "statements");
1574 $self->_update_c_position($_, \$line, \$column);
1578 $$refcolumn = $column;
1583 ########################################################################
1584 # parse_c_struct_union
1586 sub parse_c_struct_union {
1589 my $refcurrent = shift;
1590 my $refline = shift;
1591 my $refcolumn = shift;
1593 my $refkind = shift;
1594 my $ref_name = shift;
1595 my $reffield_type_names = shift;
1596 my $reffield_names = shift;
1597 my $refnames = shift;
1599 local $_ = $$refcurrent;
1600 my $line = $$refline;
1601 my $column = $$refcolumn;
1605 my @field_type_names = ();
1606 my @field_names = ();
1609 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1611 if (!s/^(struct\s+|union\s+)((?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)?\s*\{\s*//s) {
1617 $self->_update_c_position($&, \$line, \$column);
1622 while ($_ && $self->_parse_c_on_same_level_until_one_of(';', \$_, \$line, \$column, \$match))
1625 my $field_type_name;
1628 if ($self->parse_c_variable(\$match, \$line, \$column, \$field_linkage, \$field_type_name, \$field_name)) {
1629 $field_type_name =~ s/\s+/ /g;
1631 push @field_type_names, $field_type_name;
1632 push @field_names, $field_name;
1633 # $output->write("$kind:$_name:$field_type_name:$field_name\n");
1635 $self->_parse_c_error($_, $line, $column, "typedef $kind: '$match'");
1638 if ($self->_parse_c(';', \$_, \$line, \$column)) {
1640 } elsif ($self->_parse_c('}', \$_, \$line, \$column)) {
1643 my $tuple_line = $line;
1644 my $tuple_column = $column - 1;
1648 my @argument_columns;
1650 if(!$self->parse_c_tuple(\$tuple, \$tuple_line, \$tuple_column,
1651 \@arguments, \@argument_lines, \@argument_columns))
1653 $self->_parse_c_error($_, $line, $column, "$kind");
1656 foreach my $argument (@arguments) {
1657 my $name = $argument;
1664 $self->_parse_c_error($_, $line, $column, "$kind");
1670 $$refcolumn = $column;
1673 $$ref_name = $_name;
1674 @$reffield_type_names = @field_type_names;
1675 @$reffield_names = @field_names;
1676 @$refnames = @names;
1681 ########################################################################
1687 my $refcurrent = shift;
1688 my $refline = shift;
1689 my $refcolumn = shift;
1691 # FIXME: Should not write directly
1693 my $item_lines = shift;
1694 my $item_columns = shift;
1696 local $_ = $$refcurrent;
1698 my $line = $$refline;
1699 my $column = $$refcolumn;
1709 my $item_line = $line;
1710 my $item_column = $column + 1;
1713 while($plevel > 0) {
1715 $self->_parse_c_until_one_of("\\(,\\)", \$_, \$line, \$column, \$match);
1723 push @$item_lines, $item_line;
1724 push @$item_columns, $item_column;
1725 push @$items, $item;
1735 push @$item_lines, $item_line;
1736 push @$item_columns, $item_column;
1737 push @$items, $item;
1738 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1740 $item_column = $column + 1;
1752 $$refcolumn = $column;
1757 ########################################################################
1763 my $refcurrent = shift;
1764 my $refline = shift;
1765 my $refcolumn = shift;
1767 my $reftype = shift;
1769 local $_ = $$refcurrent;
1770 my $line = $$refline;
1771 my $column = $$refcolumn;
1775 $self->_parse_c("const", \$_, \$line, \$column);
1779 } elsif($self->_parse_c('ICOM_VTABLE\(.*?\)', \$_, \$line, \$column, \$type)) {
1781 } elsif($self->_parse_c('(?:enum\s+|struct\s+|union\s+)?(?:(?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)\s*(\*\s*)*',
1782 \$_, \$line, \$column, \$type))
1792 $$refcolumn = $column;
1799 ########################################################################
1802 sub parse_c_typedef {
1805 my $create_type = \${$self->{CREATE_TYPE}};
1806 my $found_type = \${$self->{FOUND_TYPE}};
1807 my $preprocessor_condition = \${$self->{PREPROCESSOR_CONDITION}};
1809 my $refcurrent = shift;
1810 my $refline = shift;
1811 my $refcolumn = shift;
1813 local $_ = $$refcurrent;
1814 my $line = $$refline;
1815 my $column = $$refcolumn;
1819 if (!$self->_parse_c("typedef", \$_, \$line, \$column)) {
1827 } elsif ($self->parse_c_enum(\$_, \$line, \$column)) {
1833 my @field_type_names;
1838 } elsif ($self->parse_c_struct_union(\$_, \$line, \$column,
1839 \$kind, \$_name, \@field_type_names, \@field_names, \@names))
1842 foreach my $name (@names)
1844 if ($name =~ /^\w+$/)
1850 $base_name="$kind $_name" if (!defined $base_name and defined $_name);
1851 $base_name=$kind if (!defined $base_name);
1852 foreach my $name (@names) {
1853 if ($name =~ /^\w+$/) {
1854 my $type = &$$create_type();
1857 $type->_name($_name);
1859 $type->field_type_names([@field_type_names]);
1860 $type->field_names([@field_names]);
1862 &$$found_type($type);
1863 } elsif ($name =~ /^(\*+)\s*(?:RESTRICTED_POINTER\s+)?(\w+)$/) {
1864 my $type_name = "$base_name $1";
1867 my $type = &$$create_type();
1871 $type->field_type_names([$type_name]);
1872 $type->field_names([""]);
1874 &$$found_type($type);
1876 $self->_parse_c_error($_, $line, $column, "typedef 2");
1888 } elsif ($self->parse_c_variable(\$_, \$line, \$column, \$linkage, \$type_name, \$name)) {
1889 $type_name =~ s/\s+/ /g;
1891 if(defined($type_name) && defined($name)) {
1892 my $type = &$$create_type();
1894 if (length($name) == 0) {
1895 $self->_parse_c_error($_, $line, $column, "typedef");
1900 $type->field_type_names([$type_name]);
1901 $type->field_names([""]);
1903 &$$found_type($type);
1906 if (0 && $_ && !/^,/) {
1907 $self->_parse_c_error($_, $line, $column, "typedef");
1910 $self->_parse_c_error($_, $line, $column, "typedef");
1915 $$refcolumn = $column;
1920 ########################################################################
1923 sub parse_c_variable {
1926 my $found_variable = \${$self->{FOUND_VARIABLE}};
1928 my $refcurrent = shift;
1929 my $refline = shift;
1930 my $refcolumn = shift;
1932 my $reflinkage = shift;
1933 my $reftype = shift;
1934 my $refname = shift;
1936 local $_ = $$refcurrent;
1937 my $line = $$refline;
1938 my $column = $$refcolumn;
1940 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
1942 my $begin_line = $line;
1943 my $begin_column = $column + 1;
1950 # $self->_parse_c_warning($_, $line, $column, "variable");
1953 while($self->_parse_c('(?:const|inline|extern(?:\s+\"C\")?|EXTERN_C|static|volatile|' .
1954 'signed(?=\s+__int(?:8|16|32|64)\b|\s+char\b|\s+int\b|\s+long(?:\s+long)?\b|\s+short\b)|' .
1955 'unsigned(?=\s+__int(?:8|16|32|64)\b|\s+char\b|\s+int\b|\s+long(?:\s+long)?\b|\s+short\b)|' .
1956 'long(?=\s+double\b|\s+int\b|\s+long\b))(?=\b)',
1957 \$_, \$line, \$column, \$match))
1959 if ($match =~ /^extern|static$/) {
1963 $self->_parse_c_warning($_, $line, $column, "repeated linkage (ignored): $match");
1965 } elsif ($match =~ /^signed|unsigned$/) {
1969 $self->_parse_c_warning($_, $line, $column, "repeated sign (ignored): $match");
1980 } elsif (s/^(enum\s+|struct\s+|union\s+)((?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)?\s*\{\s*//s) {
1983 $self->_update_c_position($&, \$line, \$column);
1985 if(defined($_name)) {
1986 $type = "$kind $_name { }";
1988 $type = "$kind { }";
1992 } elsif(s/^((?:enum\s+|struct\s+|union\s+)?\w+\b(?:\s+DECLSPEC_ALIGN\(.*?\)|\s*(?:const\s*)?\*)*)\s*(\w+)\s*(\[.*?\]$|:\s*(\d+)$|\{)?//s) {
2008 $type = $self->_format_c_type($type);
2011 } elsif(s/^((?:enum\s+|struct\s+|union\s+)?\w+\b(?:\s*\*)*)\s*:\s*(\d+)$//s) {
2012 $type = "$sign$1:$2";
2014 $type = $self->_format_c_type($type);
2017 } elsif(s/^((?:enum\s+|struct\s+|union\s+)?\w+\b(?:\s*\*)*\s*\(\s*(?:$CALL_CONVENTION)?(?:\s*\*)*)\s*(\w+)\s*(\)\s*\(.*?\))$//s) {
2018 $type = $self->_format_c_type("$sign$1$3");
2022 } elsif($self->_parse_c('DEFINE_GUID', \$_, \$line, \$column, \$match)) { # Windows specific
2026 $self->_parse_c_warning($_, $line, $column, "variable", "'$_'");
2032 } elsif($self->_parse_c('SEQ_DEFINEBUF', \$_, \$line, \$column, \$match)) { # Linux specific
2035 } elsif($self->_parse_c('DEFINE_REGS_ENTRYPOINT_\w+|DPQ_DECL_\w+|HANDLER_DEF|IX86_ONLY', # Wine specific
2036 \$_, \$line, \$column, \$match))
2040 } elsif($self->_parse_c('(?:struct\s+)?ICOM_VTABLE\s*\(\w+\)', \$_, \$line, \$column, \$match)) {
2043 } elsif(s/^(enum|struct|union)(?:\s+(\w+))?\s*\{.*?\}\s*//s) {
2046 $self->_update_c_position($&, \$line, \$column);
2048 if(defined($_name)) {
2049 $type = "struct $_name { }";
2051 $type = "struct { }";
2053 } elsif(s/^((?:enum\s+|struct\s+|union\s+)?\w+)\s*(?:\*\s*)*//s) {
2060 # $output->write("*** $type: '$_'\n");
2062 # $self->_parse_c_warning($_, $line, $column, "variable2", "");
2066 } elsif(s/^WINAPI\s*//) {
2067 $self->_update_c_position($&, \$line, \$column);
2068 } elsif(s/^WINE_UNUSED\s*//) {
2069 $self->_update_c_position($&, \$line, \$column);
2074 } elsif(s/^(\((?:$CALL_CONVENTION)?\s*\*?\s*(?:$CALL_CONVENTION)?\w+\s*(?:\[[^\]]*\]\s*)*\))\s*\(//) {
2075 $self->_update_c_position($&, \$line, \$column);
2080 $self->_parse_c_until_one_of("\\)", \$_, \$line, \$column);
2081 if(s/^\)//) { $column++; }
2082 $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
2084 if(!s/^(?:=\s*|,\s*|$)//) {
2087 } elsif(s/^(?:\*\s*)*(?:const\s+)?(\w+)\s*(?:\[[^\]]*\]\s*)*\s*(?:=\s*|,\s*|$)//) {
2088 $self->_update_c_position($&, \$line, \$column);
2098 # $output->write("$type: $name: '$_'\n");
2100 if(1 || $finished) {
2102 } elsif($self->_parse_c('(?:struct\s+)?ICOM_VTABLE\s*\(.*?\)', \$_, \$line, \$column, \$match)) {
2105 } elsif(s/^((?:enum\s+|struct\s+|union\s+)?\w+)\s*
2106 (?:\*\s*)*(\w+|\s*\*?\s*\w+\s*\))\s*(?:\[[^\]]*\]|\([^\)]*\))?
2107 (?:,\s*(?:\*\s*)*(\w+)\s*(?:\[[^\]]*\])?)*
2110 $self->_update_c_position($&, \$line, \$column);
2116 $type =~ s/^struct/struct /;
2117 } elsif(/^(enum|struct|union)(?:\s+(\w+))?\s*\{.*?\}\s*((?:\*\s*)*)(\w+)\s*(?:=|$)/s) {
2118 $self->_update_c_position($&, \$line, \$column);
2125 if(defined($_name)) {
2126 $type = "struct $_name { }";
2128 $type = "struct { }";
2141 $$refcolumn = $column;
2143 $$reflinkage = $linkage;
2147 if(&$$found_variable($begin_line, $begin_column, $linkage, $type, $name))