X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/853c670e4b839fd435507201f04d16080590a894..4d534c82fb65897999ade6867534ab952a9bc019:/src/checks.c diff --git a/src/checks.c b/src/checks.c index 9283309..cccdedb 100644 --- a/src/checks.c +++ b/src/checks.c @@ -1,6 +1,7 @@ /* GOB C Preprocessor * Copyright (C) 1999-2000 the Free Software Foundation. * Copyright (C) 2000 Eazel, Inc. + * Copyright (C) 2001-2004 George Lebl * * Author: George Lebl * @@ -32,15 +33,13 @@ #include "checks.h" static void -check_duplicate(Class *c, Node *node, char *id, int line_no, - gboolean underscore) +check_duplicate (Class *c, Node *node, const char *id, int line_no) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; - char *nid; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + const char *nid; int nline_no; - gboolean here_underscore = FALSE; if(n->type == METHOD_NODE) { Method *m = (Method *)n; @@ -48,11 +47,8 @@ check_duplicate(Class *c, Node *node, char *id, int line_no, if(m->method == OVERRIDE_METHOD) continue; - nid = get_real_id(m->id); + nid = m->id; nline_no = m->line_no; - - if(m->id[0] == '_' && m->id[1] != '\0') - here_underscore = TRUE; } else if(n->type == VARIABLE_NODE) { Variable *v = (Variable *)n; nid = v->id; @@ -64,52 +60,40 @@ check_duplicate(Class *c, Node *node, char *id, int line_no, n->type != node->type || strcmp(nid, id) != 0) continue; - /* this can only happen if the things were methods and - * one had an underscore and the other one didn't */ - if( ! no_kill_underscores && underscore != here_underscore) - error_printf(GOB_ERROR, nline_no, - "symbol '%s' ('_%s') redefined, " - "first defined on line %d. " - "Note that '%s' and '_%s' are " - "eqivalent.", - id, id, line_no, id, id); - else - error_printf(GOB_ERROR, nline_no, - "symbol '%s' redefined, " - "first defined on line %d", - id, line_no); + + error_printf (GOB_ERROR, nline_no, + "symbol '%s' redefined, " + "first defined on line %d", + id, line_no); } } void -check_duplicate_symbols(Class *c) +check_duplicate_symbols (Class *c) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; - if(n->type == METHOD_NODE) { + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + + if (n->type == METHOD_NODE) { Method *m = (Method *)n; - gboolean underscore = FALSE; /* override methods are checked separately */ - if(m->method == OVERRIDE_METHOD) - continue; - if(m->id[0] == '_' && m->id[1] != '\0') - underscore = TRUE; - check_duplicate(c, n, get_real_id(m->id), m->line_no, - underscore); - } else if(n->type == VARIABLE_NODE) { + if (m->method != OVERRIDE_METHOD) { + check_duplicate (c, n, m->id, m->line_no); + } + } else if (n->type == VARIABLE_NODE) { Variable *v = (Variable *)n; - check_duplicate(c, n, v->id, v->line_no, FALSE); + check_duplicate (c, n, v->id, v->line_no); } } } static void -check_duplicate_override(Class *c, Method *method) +check_duplicate_override (Class *c, Method *method) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; Method *m = (Method *)n; if(n->type != METHOD_NODE || m->method != OVERRIDE_METHOD) @@ -117,22 +101,22 @@ check_duplicate_override(Class *c, Method *method) if(method == m || method->line_no > m->line_no || - strcmp(get_real_id(m->id), get_real_id(method->id)) != 0 || + strcmp(m->id, method->id) != 0 || strcmp(m->otype, method->otype) != 0) continue; error_printf(GOB_ERROR, m->line_no, "override '%s(%s)' redefined, " "first defined on line %d", - get_real_id(m->id), m->otype, method->line_no); + m->id, m->otype, method->line_no); } } void check_duplicate_overrides(Class *c) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for(li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; Method *m = (Method *)n; if(n->type != METHOD_NODE || m->method != OVERRIDE_METHOD) @@ -144,15 +128,16 @@ check_duplicate_overrides(Class *c) void check_bad_symbols(Class *c) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for(li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; if((m->method == SIGNAL_LAST_METHOD || m->method == SIGNAL_FIRST_METHOD || m->method == VIRTUAL_METHOD) && - (strcmp(m->id, "__parent__")==0 || + (strcmp(m->id, "_epv")==0 || + strcmp(m->id, "__parent__")==0 || strcmp(m->id, "___parent__")==0)) { error_printf(GOB_ERROR, m->line_no, "'%s' not allowed as an " @@ -162,8 +147,8 @@ check_bad_symbols(Class *c) } if(m->method != INIT_METHOD && m->method != CLASS_INIT_METHOD && - (strcmp(get_real_id(m->id), "init")==0 || - strcmp(get_real_id(m->id), "class_init")==0)) { + (strcmp(m->id, "init")==0 || + strcmp(m->id, "class_init")==0)) { error_print(GOB_ERROR, m->line_no, "init, or class_init not " "allowed as an " @@ -183,54 +168,63 @@ check_bad_symbols(Class *c) } static void -check_duplicate_named(Class *c, Node *node, char *id, int line_no) +check_duplicate_named (Class *c, Node *node, const char *id, int line_no) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; - char *nid; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + const char *nid; int nline_no; - if(n->type == METHOD_NODE) { + if (n->type == METHOD_NODE) { Method *m = (Method *)n; - if(m->method == SIGNAL_LAST_METHOD || - m->method == SIGNAL_FIRST_METHOD) { - nid = get_real_id(m->id); + if (m->method == SIGNAL_LAST_METHOD || + m->method == SIGNAL_FIRST_METHOD) { + nid = m->id; nline_no = m->line_no; - } else + } else { continue; - } else if(n->type == ARGUMENT_NODE) { + } + } else if (n->type == ARGUMENT_NODE) { Argument *a = (Argument *)n; nid = a->name; nline_no = a->line_no; - } else + } else if (n->type == PROPERTY_NODE) { + Property *p = (Property *)n; + nid = p->name; + nline_no = p->line_no; + } else { continue; - if(n == node || - line_no >= nline_no || - g_strcasecmp(nid, id)!=0) + } + if (n == node || + line_no >= nline_no || + g_strcasecmp (nid, id) != 0) continue; - error_printf(GOB_ERROR, nline_no, - "named symbol (argument or signal) '%s' " - "redefined, first defined on line %d " - "(case insensitive)", - id, line_no); + error_printf (GOB_ERROR, nline_no, + "named symbol (argument or signal) '%s' " + "redefined, first defined on line %d " + "(case insensitive)", + id, line_no); } } void -check_duplicate_signals_args(Class *c) +check_duplicate_signals_args (Class *c) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; - if(n->type == METHOD_NODE) { + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + if (n->type == METHOD_NODE) { Method *m = (Method *)n; if(m->method == SIGNAL_LAST_METHOD || m->method == SIGNAL_FIRST_METHOD) - check_duplicate_named(c, n, get_real_id(m->id), - m->line_no); - } else if(n->type == ARGUMENT_NODE) { + check_duplicate_named (c, n, m->id, + m->line_no); + } else if (n->type == PROPERTY_NODE) { + Property *p = (Property *)n; + check_duplicate_named (c, n, p->name, p->line_no); + } else if (n->type == ARGUMENT_NODE) { Argument *a = (Argument *)n; - check_duplicate_named(c, n, a->name, a->line_no); + check_duplicate_named (c, n, a->name, a->line_no); } } } @@ -238,12 +232,12 @@ check_duplicate_signals_args(Class *c) void check_public_new(Class *c) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for(li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; - if((strcmp(get_real_id(m->id), "new")==0) && + if((strcmp(m->id, "new")==0) && (m->method != REGULAR_METHOD || m->scope != PUBLIC_SCOPE)) error_print(GOB_WARN, m->line_no, @@ -256,9 +250,9 @@ check_public_new(Class *c) void check_vararg(Class *c) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for(li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; if( ! m->vararg) @@ -279,9 +273,9 @@ check_vararg(Class *c) void check_firstarg(Class *c) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for(li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; if(m->args) @@ -302,7 +296,7 @@ void check_nonvoidempty(Class *c) { GList *li; - for(li = c->nodes; li != NULL; li = g_list_next(li)) { + for(li = c->nodes; li != NULL; li = li->next) { Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; @@ -327,10 +321,10 @@ check_nonvoidempty(Class *c) } void -check_signal_args(Class *c) +check_signal_args (Class *c) { GList *li; - for(li = c->nodes; li != NULL; li = g_list_next(li)) { + for (li = c->nodes; li != NULL; li = li->next) { Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; @@ -339,39 +333,67 @@ check_signal_args(Class *c) m->method != SIGNAL_FIRST_METHOD) continue; - for(l=m->gtktypes;l;l=l->next) { - if(get_cast(l->data, FALSE)) + for (l = m->gtktypes; l != NULL; l = l->next) { + if (strcmp (l->data, "BOXED") == 0) { + error_printf (GOB_ERROR, m->line_no, + "BOXED not allowed as " + "a signal argument, use " + "POINTER, or BOXED_*"); + continue; + } else if (strcmp (l->data, "FLAGS") == 0) { + error_printf (GOB_ERROR, m->line_no, + "FLAGS not allowed as " + "a signal argument, use " + "UINT"); continue; - error_printf(GOB_ERROR, m->line_no, - "Unknown GTK+ type '%s' " - "among signal types", - (char *)l->data); + } + if (get_cast (l->data, FALSE)) + continue; + error_printf (GOB_ERROR, m->line_no, + "Unknown GTK+ type '%s' " + "among signal types", + (char *)l->data); } } } } void -check_argument_types(Class *c) +check_argument_types (Class *c) { - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == ARGUMENT_NODE) { Argument *a = (Argument *)n; if(get_cast(a->gtktype, FALSE)) continue; - /* this could perhaps be a warning, but - can there really be a type beyond the - fundementals? */ error_printf(GOB_ERROR, a->line_no, - "Unknown GTK+ type '%s' " + "Unknown GLib type '%s' " "as argument type", a->gtktype); } } } +void +check_property_types (Class *c) +{ + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + if (n->type == PROPERTY_NODE) { + Property *p = (Property *)n; + if (get_cast (p->gtktype, FALSE)) + continue; + error_printf (GOB_ERROR, p->line_no, + "Unknown GLib type '%s' " + "as property type", + p->gtktype); + } + } +} + static void check_func_arg_check_func_arg(Method *m, FuncArg *fa) { @@ -388,7 +410,7 @@ check_func_arg_check_func_arg(Method *m, FuncArg *fa) return; } - for(li = fa->checks; li; li = g_list_next(li)) { + for(li = fa->checks; li; li = li->next) { Check *ch = li->data; if(ch->chtype == TYPE_CHECK) { char *p; @@ -437,7 +459,7 @@ static void check_func_arg_check_method(Method *m) { GList *li; - for(li = m->args; li; li = g_list_next(li)) { + for(li = m->args; li; li = li->next) { FuncArg *fa = li->data; check_func_arg_check_func_arg(m, fa); } @@ -447,7 +469,7 @@ void check_func_arg_checks(Class *c) { GList *li; - for(li = c->nodes; li != NULL; li = g_list_next(li)) { + for(li = c->nodes; li != NULL; li = li->next) { Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; @@ -456,13 +478,33 @@ check_func_arg_checks(Class *c) } } +void +check_for_class_destructors (Class *c) +{ + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + if (n->type == VARIABLE_NODE) { + Variable *v = (Variable *)n; + if (v->destructor != NULL && + v->scope == CLASS_SCOPE) { + error_print (GOB_WARN, v->line_no, + "classwide members cannot have " + "destructors since the classes " + "are static and never get " + "destroyed anyway"); + } + } + } +} + int count_signals(Class *c) { int num = 0; - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for(li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; if(m->method == SIGNAL_LAST_METHOD || @@ -473,12 +515,43 @@ count_signals(Class *c) return num; } +int +count_set_properties (Class *c) +{ + int num = 0; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + Property *p = li->data; + if (n->type == PROPERTY_NODE && + p->set != NULL) + num ++; + } + return num; +} + +int +count_get_properties (Class *c) +{ + int num = 0; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + Property *p = li->data; + if (n->type == PROPERTY_NODE && + p->get != NULL) + num ++; + } + return num; +} + + int count_set_arguments(Class *c) { int num = 0; GList *li; - for(li = c->nodes; li != NULL; li = g_list_next(li)) { + for(li = c->nodes; li != NULL; li = li->next) { Node *n = li->data; Argument *a = li->data; if(n->type == ARGUMENT_NODE && @@ -493,7 +566,7 @@ count_get_arguments(Class *c) { int num = 0; GList *li; - for(li = c->nodes; li != NULL; li = g_list_next(li)) { + for(li = c->nodes; li != NULL; li = li->next) { Node *n = li->data; Argument *a = li->data; if(n->type == ARGUMENT_NODE && @@ -507,9 +580,9 @@ int count_overrides(Class *c) { int num = 0; - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for(li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; if(m->method == OVERRIDE_METHOD) @@ -523,9 +596,9 @@ int count_privates(Class *c) { int num = 0; - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for(li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == VARIABLE_NODE) { Variable *v = (Variable *)n; if(v->scope == PRIVATE_SCOPE) @@ -536,12 +609,12 @@ count_privates(Class *c) } int -count_protecteds(Class *c) +count_protecteds (Class *c) { int num = 0; - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; if(n->type == METHOD_NODE) { Method *m = (Method *)n; if(m->scope == PROTECTED_SCOPE) @@ -552,15 +625,17 @@ count_protecteds(Class *c) } int -count_destructors(Class *c) +count_unreftors (Class *c) { int num = 0; - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; - if(n->type == VARIABLE_NODE) { + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + if (n->type == VARIABLE_NODE) { Variable *v = (Variable *)n; - if(v->destructor) + if (v->destructor != NULL && + v->destructor_unref && + v->scope != CLASS_SCOPE) num++; } } @@ -568,17 +643,75 @@ count_destructors(Class *c) } int -count_initializers(Class *c) +count_destructors (Class *c) { int num = 0; - GList *l; - for(l = c->nodes; l != NULL; l = g_list_next(l)) { - Node *n = l->data; - if(n->type == VARIABLE_NODE) { + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + if (n->type == VARIABLE_NODE) { + Variable *v = (Variable *)n; + if (v->destructor != NULL && + ! v->destructor_unref && + v->scope != CLASS_SCOPE) + num++; + } + } + return num; +} + +int +count_initializers (Class *c) +{ + int num = 0; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + if (n->type == VARIABLE_NODE) { + Variable *v = (Variable *)n; + if (v->initializer != NULL) + num++; + } + } + return num; +} + +int +count_glade_widgets (Class *c) +{ + int num = 0; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + if (n->type == VARIABLE_NODE) { Variable *v = (Variable *)n; - if(v->initializer) + if (v->glade_widget) num++; } } return num; } + +gboolean +find_get_type (Class *c) +{ + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + Method *m = (Method *)n; + if (n->type == METHOD_NODE && + strcmp (m->id, "get_type") == 0) { + if (m->method != REGULAR_METHOD || + m->scope != PUBLIC_SCOPE || + m->args != NULL) { + error_printf (GOB_ERROR, m->line_no, + "get_type method must be a " + "regular public method with " + "no arguments"); + } + return TRUE; + } + } + + return FALSE; +}