Merge branch 'slimconfigure'
[m6w6/ext-psi] / src / types / decl_type.c
index afab9e307cae40995b9bd14abb91e6336d0f6a1b..dfded25d5ad0307e257e6749d57b80f9cd6d1950 100644 (file)
@@ -120,8 +120,7 @@ bool psi_decl_type_get_alias(struct psi_decl_type *type, struct psi_plist *defs)
        }
        if (defs) {
                while (psi_plist_get(defs, i++, &def)) {
-                       if (def->type->type != type->type
-                                       && !strcmp(def->var->name, type->name)) {
+                       if (!strcmp(def->var->name, type->name)) {
                                type->real.def = def;
                                return true;
                        }
@@ -214,18 +213,23 @@ bool psi_decl_type_get_decl(struct psi_decl_type *type, struct psi_plist *decls)
 }
 
 bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type,
-               bool is_pointer, struct psi_validate_stack *type_stack)
+               struct psi_decl_arg *def, struct psi_validate_scope *scope)
 {
        if (psi_decl_type_is_weak(type)) {
                if (!psi_decl_type_get_alias(type, data->types)) {
-                       if (!psi_validate_stack_has_type(type_stack, type->name)) {
+                       if (!psi_validate_scope_has_type(scope, type->name)) {
                                return false;
                        }
-                       type->real.def = psi_validate_stack_get_type(type_stack, type->name);
+                       type->real.def = psi_validate_scope_get_type(scope, type->name);
                }
                if (type->real.def) {
-                       return psi_decl_type_validate(data, type->real.def->type,
-                                       is_pointer, type_stack);
+                       if (!psi_decl_type_validate(data, type->real.def->type,
+                                       type->real.def, scope)) {
+                               return false;
+                       }
+                       if (def) {
+                               def->var->pointer_level += type->real.def->var->pointer_level;
+                       }
                }
                return true;
        }
@@ -233,9 +237,9 @@ bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type,
        switch (type->type) {
        case PSI_T_STRUCT:
                if (!psi_decl_type_get_struct(type, data->structs)) {
-                       if (psi_validate_stack_has_struct(type_stack, type->name)) {
-                               type->real.strct = psi_validate_stack_get_struct(type_stack, type->name);
-                       } else if (is_pointer) {
+                       if (psi_validate_scope_has_struct(scope, type->name)) {
+                               type->real.strct = psi_validate_scope_get_struct(scope, type->name);
+                       } else if (def && def->var->pointer_level) {
                                return true;
                        } else {
                                data->error(data, type->token, PSI_WARNING,
@@ -243,15 +247,15 @@ bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type,
                                return false;
                        }
                }
-               if (!psi_decl_struct_validate(data, type->real.strct, type_stack)) {
+               if (!psi_decl_struct_validate(data, type->real.strct, scope)) {
                        return false;
                }
                break;
        case PSI_T_UNION:
                if (!psi_decl_type_get_union(type, data->unions)) {
-                       if (psi_validate_stack_has_union(type_stack, type->name)) {
-                               type->real.unn = psi_validate_stack_get_union(type_stack, type->name);
-                       } else if (is_pointer) {
+                       if (psi_validate_scope_has_union(scope, type->name)) {
+                               type->real.unn = psi_validate_scope_get_union(scope, type->name);
+                       } else if (def && def->var->pointer_level) {
                                return true;
                        } else {
                                data->error(data, type->token, PSI_WARNING,
@@ -259,7 +263,7 @@ bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type,
                                return false;
                        }
                }
-               if (!psi_decl_union_validate(data, type->real.unn, type_stack)) {
+               if (!psi_decl_union_validate(data, type->real.unn, scope)) {
                        return false;
                }
                break;
@@ -276,7 +280,7 @@ bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type,
                                        "Unknown decl '%s'", type->name);
                        return false;
                }
-               if (!psi_decl_validate_nodl(data, type->real.func, type_stack)) {
+               if (!psi_decl_validate_nodl(data, type->real.func, scope)) {
                        return false;
                }
                break;
@@ -300,11 +304,15 @@ void psi_decl_type_dump_args_with_layout(int fd, struct psi_plist *args,
                while (psi_plist_get(args, i++, &sarg)) {
                        dprintf(fd, "%s", psi_t_indent(level));
                        psi_decl_arg_dump(fd, sarg, level);
-                       if (sarg->layout->bfw) {
-                               dprintf(fd, ":%zu", sarg->layout->bfw->len);
+                       if (sarg->layout) {
+                               if (sarg->layout->bfw) {
+                                       dprintf(fd, ":%zu", sarg->layout->bfw->len);
+                               }
+                               dprintf(fd, "::(%zu, %zu);\n", sarg->layout->pos,
+                                               sarg->layout->len);
+                       } else {
+                               dprintf(fd, ";\n");
                        }
-                       dprintf(fd, "::(%zu, %zu);\n", sarg->layout->pos,
-                                       sarg->layout->len);
                }
                --level;
        }
@@ -355,7 +363,11 @@ void psi_decl_type_dump(int fd, struct psi_decl_type *t, unsigned level)
                        return;
                }
                break;
+
+       default:
+               break;
        }
+
        dprintf(fd, "%s", t->name);
 }
 
@@ -398,6 +410,7 @@ size_t psi_decl_type_get_align(struct psi_decl_type *t)
        case PSI_T_ENUM:
        default:
                align = psi_t_alignment(real->type);
+               break;
        }
 
        return align;