2 * Copyright (C) 1999-2000 the Free Software Foundation.
3 * Copyright (C) 2000 Eazel, Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include "treefuncs.h"
35 check_duplicate(Class *c, Node *node, const char *id, int line_no,
39 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
43 gboolean here_underscore = FALSE;
44 if(n->type == METHOD_NODE) {
45 Method *m = (Method *)n;
47 /* override methods are checked separately */
48 if(m->method == OVERRIDE_METHOD)
51 nid = get_real_id(m->id);
52 nline_no = m->line_no;
54 if(m->id[0] == '_' && m->id[1] != '\0')
55 here_underscore = TRUE;
56 } else if(n->type == VARIABLE_NODE) {
57 Variable *v = (Variable *)n;
59 nline_no = v->line_no;
64 n->type != node->type ||
67 /* this can only happen if the things were methods and
68 * one had an underscore and the other one didn't */
69 if( ! no_kill_underscores && underscore != here_underscore)
70 error_printf(GOB_ERROR, nline_no,
71 "symbol '%s' ('_%s') redefined, "
72 "first defined on line %d. "
73 "Note that '%s' and '_%s' are "
75 id, id, line_no, id, id);
77 error_printf(GOB_ERROR, nline_no,
78 "symbol '%s' redefined, "
79 "first defined on line %d",
85 check_duplicate_symbols(Class *c)
88 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
90 if(n->type == METHOD_NODE) {
91 Method *m = (Method *)n;
92 gboolean underscore = FALSE;
93 /* override methods are checked separately */
94 if(m->method == OVERRIDE_METHOD)
96 if(m->id[0] == '_' && m->id[1] != '\0')
98 check_duplicate(c, n, get_real_id(m->id), m->line_no,
100 } else if(n->type == VARIABLE_NODE) {
101 Variable *v = (Variable *)n;
102 check_duplicate(c, n, v->id, v->line_no, FALSE);
108 check_duplicate_override(Class *c, Method *method)
111 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
113 Method *m = (Method *)n;
114 if(n->type != METHOD_NODE ||
115 m->method != OVERRIDE_METHOD)
119 method->line_no > m->line_no ||
120 strcmp(get_real_id(m->id), get_real_id(method->id)) != 0 ||
121 strcmp(m->otype, method->otype) != 0)
123 error_printf(GOB_ERROR, m->line_no,
124 "override '%s(%s)' redefined, "
125 "first defined on line %d",
126 get_real_id(m->id), m->otype, method->line_no);
131 check_duplicate_overrides(Class *c)
134 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
136 Method *m = (Method *)n;
137 if(n->type != METHOD_NODE ||
138 m->method != OVERRIDE_METHOD)
140 check_duplicate_override(c, m);
145 check_bad_symbols(Class *c)
148 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
150 if(n->type == METHOD_NODE) {
151 Method *m = (Method *)n;
152 if((m->method == SIGNAL_LAST_METHOD ||
153 m->method == SIGNAL_FIRST_METHOD ||
154 m->method == VIRTUAL_METHOD) &&
155 (strcmp(m->id, "__parent__")==0 ||
156 strcmp(m->id, "___parent__")==0)) {
157 error_printf(GOB_ERROR, m->line_no,
158 "'%s' not allowed as an "
159 "identifier of signal "
160 "or virtual methods",
163 if(m->method != INIT_METHOD &&
164 m->method != CLASS_INIT_METHOD &&
165 (strcmp(get_real_id(m->id), "init")==0 ||
166 strcmp(get_real_id(m->id), "class_init")==0)) {
167 error_print(GOB_ERROR, m->line_no,
168 "init, or class_init not "
171 "constructor methods");
173 } else if(n->type == VARIABLE_NODE) {
174 Variable *v = (Variable *)n;
175 if(strcmp(v->id, "_priv")==0 ||
176 strcmp(v->id, "__parent__")==0) {
177 error_printf(GOB_ERROR, v->line_no,
178 "'%s' not allowed as a "
179 "data member name", v->id);
186 check_duplicate_named(Class *c, Node *node, const char *id, int line_no)
189 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
193 if(n->type == METHOD_NODE) {
194 Method *m = (Method *)n;
195 if(m->method == SIGNAL_LAST_METHOD ||
196 m->method == SIGNAL_FIRST_METHOD) {
197 nid = get_real_id(m->id);
198 nline_no = m->line_no;
201 } else if(n->type == ARGUMENT_NODE) {
202 Argument *a = (Argument *)n;
204 nline_no = a->line_no;
208 line_no >= nline_no ||
209 g_strcasecmp(nid, id)!=0)
211 error_printf(GOB_ERROR, nline_no,
212 "named symbol (argument or signal) '%s' "
213 "redefined, first defined on line %d "
214 "(case insensitive)",
220 check_duplicate_signals_args(Class *c)
223 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
225 if(n->type == METHOD_NODE) {
226 Method *m = (Method *)n;
227 if(m->method == SIGNAL_LAST_METHOD ||
228 m->method == SIGNAL_FIRST_METHOD)
229 check_duplicate_named(c, n, get_real_id(m->id),
231 } else if(n->type == ARGUMENT_NODE) {
232 Argument *a = (Argument *)n;
233 check_duplicate_named(c, n, a->name, a->line_no);
239 check_public_new(Class *c)
242 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
244 if(n->type == METHOD_NODE) {
245 Method *m = (Method *)n;
246 if((strcmp(get_real_id(m->id), "new")==0) &&
247 (m->method != REGULAR_METHOD ||
248 m->scope != PUBLIC_SCOPE))
249 error_print(GOB_WARN, m->line_no,
250 "'new' should be a regular\n"
257 check_vararg(Class *c)
260 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
262 if(n->type == METHOD_NODE) {
263 Method *m = (Method *)n;
266 if(m->method == OVERRIDE_METHOD ||
267 m->method == SIGNAL_LAST_METHOD ||
268 m->method == SIGNAL_FIRST_METHOD ||
269 m->method == VIRTUAL_METHOD) {
270 error_print(GOB_ERROR, m->line_no,
271 "signals, overrides and virtuals, "
272 "can't have variable argument "
280 check_firstarg(Class *c)
283 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
285 if(n->type == METHOD_NODE) {
286 Method *m = (Method *)n;
289 if(m->method == OVERRIDE_METHOD ||
290 m->method == SIGNAL_LAST_METHOD ||
291 m->method == SIGNAL_FIRST_METHOD ||
292 m->method == VIRTUAL_METHOD) {
293 error_print(GOB_ERROR, m->line_no,
294 "signals, overrides and virtuals, "
295 "can't have no arguments");
302 check_nonvoidempty(Class *c)
305 for(li = c->nodes; li != NULL; li = g_list_next(li)) {
307 if(n->type == METHOD_NODE) {
308 Method *m = (Method *)n;
309 if(m->method != REGULAR_METHOD)
311 if(!(strcmp(m->mtype->name, "void")==0 &&
312 m->mtype->pointer == NULL) &&
314 error_print(GOB_WARN, m->line_no,
315 "non-void empty method found, "
316 "regular non-void function should "
318 /* add a body here, so that the user will also
319 get a warning from gcc, and so that it will
320 at least point him to the prototype of the
321 function in the .gob file */
322 m->cbuf = g_strdup("/*empty*/");
323 m->ccode_line = m->line_no;
330 check_signal_args(Class *c)
333 for(li = c->nodes; li != NULL; li = g_list_next(li)) {
335 if(n->type == METHOD_NODE) {
336 Method *m = (Method *)n;
338 if(m->method != SIGNAL_LAST_METHOD &&
339 m->method != SIGNAL_FIRST_METHOD)
342 for(l=m->gtktypes;l;l=l->next) {
343 if(get_cast(l->data, FALSE))
345 error_printf(GOB_ERROR, m->line_no,
346 "Unknown GTK+ type '%s' "
347 "among signal types",
355 check_argument_types(Class *c)
358 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
360 if(n->type == ARGUMENT_NODE) {
361 Argument *a = (Argument *)n;
362 if(get_cast(a->gtktype, FALSE))
364 /* this could perhaps be a warning, but
365 can there really be a type beyond the
367 error_printf(GOB_ERROR, a->line_no,
368 "Unknown GTK+ type '%s' "
376 check_func_arg_check_func_arg(Method *m, FuncArg *fa)
384 if(strcmp(fa->atype->name, "void") == 0 &&
385 fa->atype->pointer == NULL) {
386 error_print(GOB_ERROR, m->line_no,
387 "Running checks on a void function argument");
391 for(li = fa->checks; li; li = g_list_next(li)) {
392 Check *ch = li->data;
393 if(ch->chtype == TYPE_CHECK) {
395 gboolean got_type = FALSE;
396 s = g_strdup(fa->atype->name);
400 goto type_check_error;
403 if(strcmp(p, "const") != 0) {
406 goto type_check_error;
410 p = strtok(NULL, " ");
414 goto type_check_error;
416 if(fa->atype->pointer == NULL ||
417 (strcmp(fa->atype->pointer, "*") != 0 &&
418 strcmp(fa->atype->pointer, "* const") != 0 &&
419 strcmp(fa->atype->pointer, "const *") != 0))
420 goto type_check_error;
426 if(fa->atype->pointer)
427 error_printf(GOB_ERROR, m->line_no,
428 "Cannot check the type of '%s %s'",
429 fa->atype->name, fa->atype->pointer);
431 error_printf(GOB_ERROR, m->line_no,
432 "Cannot check the type of '%s'",
437 check_func_arg_check_method(Method *m)
440 for(li = m->args; li; li = g_list_next(li)) {
441 FuncArg *fa = li->data;
442 check_func_arg_check_func_arg(m, fa);
447 check_func_arg_checks(Class *c)
450 for(li = c->nodes; li != NULL; li = g_list_next(li)) {
452 if(n->type == METHOD_NODE) {
453 Method *m = (Method *)n;
454 check_func_arg_check_method(m);
460 count_signals(Class *c)
464 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
466 if(n->type == METHOD_NODE) {
467 Method *m = (Method *)n;
468 if(m->method == SIGNAL_LAST_METHOD ||
469 m->method == SIGNAL_FIRST_METHOD)
477 count_set_arguments(Class *c)
481 for(li = c->nodes; li != NULL; li = g_list_next(li)) {
483 Argument *a = li->data;
484 if(n->type == ARGUMENT_NODE &&
492 count_get_arguments(Class *c)
496 for(li = c->nodes; li != NULL; li = g_list_next(li)) {
498 Argument *a = li->data;
499 if(n->type == ARGUMENT_NODE &&
507 count_overrides(Class *c)
511 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
513 if(n->type == METHOD_NODE) {
514 Method *m = (Method *)n;
515 if(m->method == OVERRIDE_METHOD)
523 count_privates(Class *c)
527 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
529 if(n->type == VARIABLE_NODE) {
530 Variable *v = (Variable *)n;
531 if(v->scope == PRIVATE_SCOPE)
539 count_protecteds(Class *c)
543 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
545 if(n->type == METHOD_NODE) {
546 Method *m = (Method *)n;
547 if(m->scope == PROTECTED_SCOPE)
555 count_destructors(Class *c)
559 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
561 if(n->type == VARIABLE_NODE) {
562 Variable *v = (Variable *)n;
571 count_initializers(Class *c)
575 for(l = c->nodes; l != NULL; l = g_list_next(l)) {
577 if(n->type == VARIABLE_NODE) {
578 Variable *v = (Variable *)n;