]> git.draconx.ca Git - gob-dx.git/blobdiff - src/checks.c
Release 1.0.2
[gob-dx.git] / src / checks.c
index 7ce3bea967e83f2e2e2a26961a46781c13174c0b..7c675ee041e20a75ed1fb49b88ad5d3b5a9d1380 100644 (file)
@@ -317,7 +317,7 @@ check_nonvoidempty(Class *c)
                        if(m->method != REGULAR_METHOD)
                                continue;
                        if(!(strcmp(m->mtype->name, "void")==0 &&
-                            m->mtype->stars == 0) &&
+                            m->mtype->pointer == NULL) &&
                           !m->cbuf) {
                                print_error(TRUE,
                                            "non-void empty method found, "
@@ -385,6 +385,89 @@ check_argument_types(Class *c)
        }
 }
 
+static void
+check_func_arg_check_func_arg(Method *m, FuncArg *fa)
+{
+       GList *li;
+       char *s;
+
+       if( ! fa->checks)
+               return;
+
+       if(strcmp(fa->atype->name, "void") == 0 &&
+          fa->atype->pointer == NULL) {
+               print_error(FALSE, "Running checks on a void function "
+                           "argument", m->line_no);
+               return;
+       }
+       
+       for(li = fa->checks; li; li = g_list_next(li)) {
+               Check *ch = li->data;
+               if(ch->chtype == TYPE_CHECK) {
+                       char *p;
+                       gboolean got_type = FALSE;
+                       s = g_strdup(fa->atype->name);
+                       p = strtok(s, " ");
+                       if( ! p) {
+                               g_free(s);
+                               goto type_check_error;
+                       }
+                       while(p) {
+                               if(strcmp(p, "const") != 0) {
+                                       if(got_type) {
+                                               g_free(s);
+                                               goto type_check_error;
+                                       }
+                                       got_type = TRUE;
+                               }
+                               p = strtok(NULL, " ");
+                       }
+                       g_free(s);
+                       if( ! got_type)
+                               goto type_check_error;
+
+                       if(fa->atype->pointer == NULL ||
+                          (strcmp(fa->atype->pointer, "*") != 0 &&
+                           strcmp(fa->atype->pointer, "* const") != 0))
+                               goto type_check_error;
+               }
+       }
+       return;
+
+type_check_error:
+       if(fa->atype->pointer)
+               s = g_strdup_printf("Cannot check the type of '%s %s'",
+                                   fa->atype->name, fa->atype->pointer);
+       else
+               s = g_strdup_printf("Cannot check the type of '%s'",
+                                   fa->atype->name);
+       print_error(FALSE, s, m->line_no);
+       g_free(s);
+}
+
+static void
+check_func_arg_check_method(Method *m)
+{
+       GList *li;
+       for(li = m->args; li; li = g_list_next(li)) {
+               FuncArg *fa = li->data;
+               check_func_arg_check_func_arg(m, fa);
+       }
+}
+
+void
+check_func_arg_checks(Class *c)
+{
+       GList *li;
+       for(li = c->nodes; li != NULL; li = g_list_next(li)) {
+               Node *n = li->data;
+               if(n->type == METHOD_NODE) {
+                       Method *m = (Method *)n;
+                       check_func_arg_check_method(m);
+               }
+       }
+}
+
 int
 count_signals(Class *c)
 {