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 winapi_c_parser;
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
30 use options qw($options);
31 use output qw($output);
39 ########################################################################
44 my $class = ref($proto) || $proto;
46 bless ($self, $class);
48 my $file = \${$self->{FILE}};
49 my $create_function = \${$self->{CREATE_FUNCTION}};
50 my $create_type = \${$self->{CREATE_TYPE}};
51 my $found_comment = \${$self->{FOUND_COMMENT}};
52 my $found_declaration = \${$self->{FOUND_DECLARATION}};
53 my $found_function = \${$self->{FOUND_FUNCTION}};
54 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
55 my $found_line = \${$self->{FOUND_LINE}};
56 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
57 my $found_statement = \${$self->{FOUND_STATEMENT}};
58 my $found_type = \${$self->{FOUND_TYPE}};
59 my $found_variable = \${$self->{FOUND_VARIABLE}};
63 $$create_function = sub { return new c_function; };
64 $$create_type = sub { return new c_type; };
65 $$found_comment = sub { return 1; };
66 $$found_declaration = sub { return 1; };
67 $$found_function = sub { return 1; };
68 $$found_function_call = sub { return 1; };
69 $$found_line = sub { return 1; };
70 $$found_preprocessor = sub { return 1; };
71 $$found_statement = sub { return 1; };
72 $$found_type = sub { return 1; };
73 $$found_variable = sub { return 1; };
78 ########################################################################
79 # set_found_comment_callback
81 sub set_found_comment_callback($$) {
84 my $found_comment = \${$self->{FOUND_COMMENT}};
86 $$found_comment = shift;
89 ########################################################################
90 # set_found_declaration_callback
92 sub set_found_declaration_callback($$) {
95 my $found_declaration = \${$self->{FOUND_DECLARATION}};
97 $$found_declaration = shift;
100 ########################################################################
101 # set_found_function_callback
103 sub set_found_function_callback($$) {
106 my $found_function = \${$self->{FOUND_FUNCTION}};
108 $$found_function = shift;
111 ########################################################################
112 # set_found_function_call_callback
114 sub set_found_function_call_callback($$) {
117 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
119 $$found_function_call = shift;
122 ########################################################################
123 # set_found_line_callback
125 sub set_found_line_callback($$) {
128 my $found_line = \${$self->{FOUND_LINE}};
130 $$found_line = shift;
133 ########################################################################
134 # set_found_preprocessor_callback
136 sub set_found_preprocessor_callback($$) {
139 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
141 $$found_preprocessor = shift;
144 ########################################################################
145 # set_found_statement_callback
147 sub set_found_statement_callback($$) {
150 my $found_statement = \${$self->{FOUND_STATEMENT}};
152 $$found_statement = shift;
155 ########################################################################
156 # set_found_type_callback
158 sub set_found_type_callback($$) {
161 my $found_type = \${$self->{FOUND_TYPE}};
163 $$found_type = shift;
166 ########################################################################
167 # set_found_variable_callback
169 sub set_found_variable_callback($$) {
172 my $found_variable = \${$self->{FOUND_VARIABLE}};
174 $$found_variable = shift;
177 ########################################################################
180 sub parse_c_file($$$$) {
183 my $file = \${$self->{FILE}};
185 my $found_comment = \${$self->{FOUND_COMMENT}};
186 my $found_declaration = \${$self->{FOUND_DECLARATION}};
187 my $create_function = \${$self->{CREATE_FUNCTION}};
188 my $found_function = \${$self->{FOUND_FUNCTION}};
189 my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
190 my $found_line = \${$self->{FOUND_LINE}};
191 my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
192 my $found_statement = \${$self->{FOUND_STATEMENT}};
193 my $found_variable = \${$self->{FOUND_VARIABLE}};
195 my $refcurrent = shift;
197 my $refcolumn = shift;
199 my $_create_function = sub {
200 return 'function'->new;
203 my $_create_type = sub {
207 my $_found_function = sub {
208 my $old_function = shift;
210 my $function = new c_function;
212 $function->file($old_function->file);
214 $function->begin_line($old_function->function_line);
215 $function->begin_column(0);
216 $function->end_line($old_function->function_line);
217 $function->end_column(0);
219 $function->linkage($old_function->linkage);
220 $function->return_type($old_function->return_type);
221 $function->calling_convention($old_function->calling_convention);
222 $function->name($old_function->internal_name);
224 if(defined($old_function->argument_types)) {
225 $function->argument_types([@{$old_function->argument_types}]);
227 if(defined($old_function->argument_names)) {
228 $function->argument_names([@{$old_function->argument_names}]);
231 $function->statements_line($old_function->statements_line);
232 $function->statements_column(0);
233 $function->statements($old_function->statements);
235 &$$found_function($function);
238 my $_found_preprocessor = sub {
239 my $directive = shift;
240 my $argument = shift;
243 my $begin_column = 0;
244 my $preprocessor = "#$directive $argument";
246 &$$found_preprocessor($begin_line, $begin_column, $preprocessor);
249 my $_found_type = sub {
253 winapi_parser::parse_c_file($$file, {
254 # c_comment_found => $found_c_comment,
255 # cplusplus_comment_found => $found_cplusplus_comment,
256 function_create => $_create_function,
257 function_found => $_found_function,
258 preprocessor_found => $_found_preprocessor,
259 type_create => $_create_type,
260 type_found => $_found_type,