2 * Copyright (C) 1999-2000 the Free Software Foundation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
34 check_duplicate(Class *c, Node *node, char *id, int line_no)
37 for(l=c->nodes;l;l=g_list_next(l)) {
42 if(n->type == METHOD_NODE) {
43 Method *m = (Method *)n;
45 nline_no = m->line_no;
46 } else if(n->type == VARIABLE_NODE) {
47 Variable *v = (Variable *)n;
49 nline_no = v->line_no;
55 n->type != node->type)
57 s = g_strdup_printf("symbol '%s' redefined, "
58 "first defined on line %d",
60 print_error(FALSE,s,nline_no);
65 check_duplicate_symbols(Class *c)
68 for(l=c->nodes;l;l=g_list_next(l)) {
70 if(n->type == METHOD_NODE) {
71 Method *m = (Method *)n;
72 check_duplicate(c,n,m->id,m->line_no);
73 } else if(n->type == VARIABLE_NODE) {
74 Variable *v = (Variable *)n;
75 check_duplicate(c,n,v->id,v->line_no);
81 check_bad_symbols(Class *c)
84 for(l=c->nodes;l;l=g_list_next(l)) {
86 if(n->type == METHOD_NODE) {
87 Method *m = (Method *)n;
88 if((m->method == SIGNAL_LAST_METHOD ||
89 m->method == SIGNAL_FIRST_METHOD ||
90 m->method == VIRTUAL_METHOD) &&
91 strcmp(m->id,"__parent__")==0) {
93 s = g_strdup_printf("'%s' not allowed as an "
94 "identifier of signal "
97 print_error(FALSE,s,m->line_no);
100 if(m->method != INIT_METHOD &&
101 m->method != CLASS_INIT_METHOD &&
102 (strcmp(m->id,"init")==0 ||
103 strcmp(m->id,"class_init")==0)) {
104 print_error(FALSE,"init, or class_init not "
107 "constructor methods",m->line_no);
109 } else if(n->type == VARIABLE_NODE) {
110 Variable *v = (Variable *)n;
111 if(strcmp(v->id,"_priv")==0 ||
112 strcmp(v->id,"__parent__")==0) {
114 s = g_strdup_printf("'%s' not allowed as a "
115 "data member name",v->id);
116 print_error(FALSE,s,v->line_no);
125 check_duplicate_named(Class *c,Node *node,char *id, int line_no)
128 for(l=c->nodes;l;l=g_list_next(l)) {
133 if(n->type == METHOD_NODE) {
134 Method *m = (Method *)n;
135 if(m->method == SIGNAL_LAST_METHOD ||
136 m->method == SIGNAL_FIRST_METHOD) {
138 nline_no = m->line_no;
141 } else if(n->type == ARGUMENT_NODE) {
142 Argument *a = (Argument *)n;
144 nline_no = a->line_no;
149 g_strcasecmp(nid,id)!=0)
151 s = g_strdup_printf("named symbol (argument or signal) '%s' "
152 "redefined, first defined on line %d "
153 "(case insensitive)",
155 print_error(FALSE,s,nline_no);
160 check_duplicate_signals_args(Class *c)
163 for(l=c->nodes;l;l=g_list_next(l)) {
165 if(n->type == METHOD_NODE) {
166 Method *m = (Method *)n;
167 if(m->method == SIGNAL_LAST_METHOD ||
168 m->method == SIGNAL_FIRST_METHOD)
169 check_duplicate_named(c,n,m->id,m->line_no);
170 } else if(n->type == ARGUMENT_NODE) {
171 Argument *a = (Argument *)n;
172 check_duplicate_named(c,n,a->name,a->line_no);
178 check_public_new(Class *c)
181 for(l=c->nodes;l;l=g_list_next(l)) {
183 if(n->type == METHOD_NODE) {
184 Method *m = (Method *)n;
185 if((strcmp(m->id,"new")==0) &&
186 (m->method != REGULAR_METHOD ||
187 m->scope != PUBLIC_SCOPE))
189 "'new' should be a regular\n"
197 check_vararg(Class *c)
200 for(l=c->nodes;l;l=g_list_next(l)) {
202 if(n->type == METHOD_NODE) {
203 Method *m = (Method *)n;
206 if(m->method == OVERRIDE_METHOD ||
207 m->method == SIGNAL_LAST_METHOD ||
208 m->method == SIGNAL_FIRST_METHOD ||
209 m->method == VIRTUAL_METHOD) {
211 "signals, overrides and virtuals, "
212 "can't have variable argument "
221 check_firstarg(Class *c)
224 for(l=c->nodes;l;l=g_list_next(l)) {
226 if(n->type == METHOD_NODE) {
227 Method *m = (Method *)n;
230 if(m->method == OVERRIDE_METHOD ||
231 m->method == SIGNAL_LAST_METHOD ||
232 m->method == SIGNAL_FIRST_METHOD ||
233 m->method == VIRTUAL_METHOD) {
235 "signals, overrides and virtuals, "
236 "can't have no arguments",
244 check_nonvoidempty(Class *c)
247 for(li=c->nodes; li; li=g_list_next(li)) {
249 if(n->type == METHOD_NODE) {
250 Method *m = (Method *)n;
251 if(m->method != REGULAR_METHOD)
253 if(!(strcmp(m->mtype->name, "void")==0 &&
254 m->mtype->stars == 0) &&
257 "non-void empty method found, "
258 "regular non-void function should "
261 /* add a body here, so that the user will also
262 get a warning from gcc, and so that it will
263 at least point him to the prototype of the
264 function in the .gob file */
265 m->cbuf = g_strdup("/*empty*/");
266 m->ccode_line = m->line_no;
273 check_signal_args(Class *c)
276 for(li=c->nodes; li; li=g_list_next(li)) {
278 if(n->type == METHOD_NODE) {
279 Method *m = (Method *)n;
281 if(m->method != SIGNAL_LAST_METHOD &&
282 m->method != SIGNAL_FIRST_METHOD)
285 for(l=m->gtktypes;l;l=l->next) {
287 if(get_cast(l->data, FALSE))
289 s = g_strdup_printf("Unknown GTK+ type '%s' "
290 "among signal types",
292 print_error(FALSE, s, m->line_no);
300 check_argument_types(Class *c)
303 for(l=c->nodes;l;l=g_list_next(l)) {
305 if(n->type == ARGUMENT_NODE) {
306 Argument *a = (Argument *)n;
308 if(get_cast(a->gtktype, FALSE))
310 s = g_strdup_printf("Unknown GTK+ type '%s' "
313 /* this could perhaps be a warning, but
314 can there really be a type beyond the
316 print_error(FALSE, s, a->line_no);
323 count_signals(Class *c)
327 for(l=c->nodes;l;l=g_list_next(l)) {
329 if(n->type == METHOD_NODE) {
330 Method *m = (Method *)n;
331 if(m->method == SIGNAL_LAST_METHOD ||
332 m->method == SIGNAL_FIRST_METHOD)
340 count_arguments(Class *c)
345 for(li=c->nodes;li;li=g_list_next(li)) {
347 if(n->type == ARGUMENT_NODE)
354 count_overrides(Class *c)
358 for(l=c->nodes;l;l=g_list_next(l)) {
360 if(n->type == METHOD_NODE) {
361 Method *m = (Method *)n;
362 if(m->method == OVERRIDE_METHOD)
370 count_privates(Class *c)
374 for(l=c->nodes;l;l=g_list_next(l)) {
376 if(n->type == VARIABLE_NODE) {
377 Variable *v = (Variable *)n;
378 if(v->scope == PRIVATE_SCOPE)
386 count_protecteds(Class *c)
390 for(l=c->nodes;l;l=g_list_next(l)) {
392 if(n->type == METHOD_NODE) {
393 Method *m = (Method *)n;
394 if(m->scope == PROTECTED_SCOPE)
402 count_destructors(Class *c)
406 for(l=c->nodes;l;l=g_list_next(l)) {
408 if(n->type == VARIABLE_NODE) {
409 Variable *v = (Variable *)n;
418 count_initializers(Class *c)
422 for(l=c->nodes;l;l=g_list_next(l)) {
424 if(n->type == VARIABLE_NODE) {
425 Variable *v = (Variable *)n;