Update the address of the Free Software Foundation.
[wine] / tools / winapi / winapi_c_parser.pm
1 #
2 # Copyright 1999, 2000, 2001 Patrik Stridvall
3 #
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.
8 #
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.
13 #
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
17 #
18
19 package winapi_c_parser;
20
21 use strict;
22
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
24 require Exporter;
25
26 @ISA = qw(Exporter);
27 @EXPORT = qw();
28 @EXPORT_OK = qw();
29
30 use options qw($options);
31 use output qw($output);
32
33 use c_function;
34 use c_type;
35 use function;
36 use winapi_function;
37 use winapi_parser;
38
39 ########################################################################
40 # new
41 #
42 sub new($$) {
43     my $proto = shift;
44     my $class = ref($proto) || $proto;
45     my $self  = {};
46     bless ($self, $class);
47
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}};
60
61     $$file = shift;
62
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; };
74
75     return $self;
76 }
77
78 ########################################################################
79 # set_found_comment_callback
80 #
81 sub set_found_comment_callback($$) {
82     my $self = shift;
83
84     my $found_comment = \${$self->{FOUND_COMMENT}};
85
86     $$found_comment = shift;
87 }
88
89 ########################################################################
90 # set_found_declaration_callback
91 #
92 sub set_found_declaration_callback($$) {
93     my $self = shift;
94
95     my $found_declaration = \${$self->{FOUND_DECLARATION}};
96
97     $$found_declaration = shift;
98 }
99
100 ########################################################################
101 # set_found_function_callback
102 #
103 sub set_found_function_callback($$) {
104     my $self = shift;
105
106     my $found_function = \${$self->{FOUND_FUNCTION}};
107
108     $$found_function = shift;
109 }
110
111 ########################################################################
112 # set_found_function_call_callback
113 #
114 sub set_found_function_call_callback($$) {
115     my $self = shift;
116
117     my $found_function_call = \${$self->{FOUND_FUNCTION_CALL}};
118
119     $$found_function_call = shift;
120 }
121
122 ########################################################################
123 # set_found_line_callback
124 #
125 sub set_found_line_callback($$) {
126     my $self = shift;
127
128     my $found_line = \${$self->{FOUND_LINE}};
129
130     $$found_line = shift;
131 }
132
133 ########################################################################
134 # set_found_preprocessor_callback
135 #
136 sub set_found_preprocessor_callback($$) {
137     my $self = shift;
138
139     my $found_preprocessor = \${$self->{FOUND_PREPROCESSOR}};
140
141     $$found_preprocessor = shift;
142 }
143
144 ########################################################################
145 # set_found_statement_callback
146 #
147 sub set_found_statement_callback($$) {
148     my $self = shift;
149
150     my $found_statement = \${$self->{FOUND_STATEMENT}};
151
152     $$found_statement = shift;
153 }
154
155 ########################################################################
156 # set_found_type_callback
157 #
158 sub set_found_type_callback($$) {
159     my $self = shift;
160
161     my $found_type = \${$self->{FOUND_TYPE}};
162
163     $$found_type = shift;
164 }
165
166 ########################################################################
167 # set_found_variable_callback
168 #
169 sub set_found_variable_callback($$) {
170     my $self = shift;
171
172     my $found_variable = \${$self->{FOUND_VARIABLE}};
173
174     $$found_variable = shift;
175 }
176
177 ########################################################################
178 # parse_c_file
179
180 sub parse_c_file($$$$) {
181     my $self = shift;
182
183     my $file = \${$self->{FILE}};
184
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}};
194
195     my $refcurrent = shift;
196     my $refline = shift;
197     my $refcolumn = shift;
198
199     my $_create_function = sub {
200         return 'function'->new;
201     };
202
203     my $_create_type = sub {
204         return 'type'->new;
205     };
206
207     my $_found_function = sub {
208         my $old_function = shift;
209
210         my $function = new c_function;
211
212         $function->file($old_function->file);
213         
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);
218
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);
223
224         if(defined($old_function->argument_types)) {
225             $function->argument_types([@{$old_function->argument_types}]);
226         }
227         if(defined($old_function->argument_names)) {
228             $function->argument_names([@{$old_function->argument_names}]);
229         }
230
231         $function->statements_line($old_function->statements_line);
232         $function->statements_column(0);
233         $function->statements($old_function->statements);
234         
235         &$$found_function($function);
236     };
237
238     my $_found_preprocessor = sub {
239         my $directive = shift;
240         my $argument = shift;
241
242         my $begin_line = 0;
243         my $begin_column = 0;
244         my $preprocessor = "#$directive $argument";
245
246         &$$found_preprocessor($begin_line, $begin_column, $preprocessor);
247     };
248
249     my $_found_type = sub {
250         my $type = shift;
251     };
252
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,
261     });
262 }
263
264 1;