made the real decl_type a union
[m6w6/ext-psi] / src / context_validate.c
index a5d3604d4a9e3e1ee3e43ba03e00e0f18c3e25ac..5ad642fbc24317ec3293b54312e88c29f7cbf1a7 100644 (file)
@@ -46,14 +46,14 @@ static inline int locate_decl_type_alias(decl_typedefs *defs, decl_type *type) {
        size_t i;
        struct psi_std_type *stdtyp;
 
-       if (type->real) {
+       if (type->real.def) {
                return 1;
        }
        if (defs) for (i = 0; i < defs->count; ++i) {
                decl_arg *def = defs->list[i];
 
                if (def->type->type != type->type && !strcmp(def->var->name, type->name)) {
-                       type->real = def->type;
+                       type->real.def = def;
                        return 1;
                }
        }
@@ -70,12 +70,12 @@ static inline int locate_decl_type_alias(decl_typedefs *defs, decl_type *type) {
 static inline int locate_decl_type_struct(decl_structs *structs, decl_type *type) {
        size_t i;
 
-       if (type->strct) {
+       if (type->real.strct) {
                return 1;
        }
        if (structs) for (i = 0; i < structs->count; ++i) {
                if (!strcmp(structs->list[i]->name, type->name)) {
-                       type->strct = structs->list[i];
+                       type->real.strct = structs->list[i];
                        return 1;
                }
        }
@@ -85,12 +85,12 @@ static inline int locate_decl_type_struct(decl_structs *structs, decl_type *type
 static inline int locate_decl_type_union(decl_unions *unions, decl_type *type) {
        size_t i;
 
-       if (type->unn) {
+       if (type->real.unn) {
                return 1;
        }
        if (unions) for (i = 0; i < unions->count; ++i) {
                if (!strcmp(unions->list[i]->name, type->name)) {
-                       type->unn = unions->list[i];
+                       type->real.unn = unions->list[i];
                        return 1;
                }
        }
@@ -100,12 +100,12 @@ static inline int locate_decl_type_union(decl_unions *unions, decl_type *type) {
 static inline int locate_decl_type_enum(decl_enums *enums, decl_type *type) {
        size_t i;
 
-       if (type->enm) {
+       if (type->real.enm) {
                return 1;
        }
        if (enums) for (i = 0; i < enums->count; ++i) {
                if (!strcmp(enums->list[i]->name, type->name)) {
-                       type->enm = enums->list[i];
+                       type->real.enm = enums->list[i];
                        return 1;
                }
        }
@@ -115,12 +115,12 @@ static inline int locate_decl_type_enum(decl_enums *enums, decl_type *type) {
 static inline int locate_decl_type_decl(decls *decls, decl_type *type) {
        size_t i;
 
-       if (type->func) {
+       if (type->real.func) {
                return 1;
        }
        if (decls) for (i = 0; i < decls->count; ++i) {
                if (!strcmp(decls->list[i]->func->var->name, type->name)) {
-                       type->func = decls->list[i];
+                       type->real.func = decls->list[i];
                        return 1;
                }
        }
@@ -133,19 +133,17 @@ static inline int validate_decl_union(PSI_Data *data, decl_union *u);
 static inline int validate_decl_enum(PSI_Data *data, decl_enum *e);
 
 static inline int validate_decl_type(PSI_Data *data, decl_type *type) {
-       switch (type->type) {
-       case PSI_T_CHAR:
-       case PSI_T_SHORT:
-       case PSI_T_INT:
-       case PSI_T_LONG:
-       case PSI_T_NAME:
+       if (weak_decl_type(type)) {
                if (!locate_decl_type_alias(data->defs, type)) {
                        return 0;
                }
-               if (type->real) {
-                       return validate_decl_type(data, type->real);
+               if (type->real.def) {
+                       return validate_decl_type(data, type->real.def->type);
                }
                return 1;
+       }
+
+       switch (type->type) {
        case PSI_T_STRUCT:
                if (!locate_decl_type_struct(data->structs, type)) {
                        return 0;
@@ -252,26 +250,35 @@ static inline int validate_decl_struct_darg(PSI_Data *data, decl_arg *darg, void
        /* pre-validate any structs/unions/enums */
        switch (real->type) {
        case PSI_T_STRUCT:
-               if (current && current == real->strct) {
+               if (current && current == real->real.strct) {
                        return 1;
                }
-               if (!validate_decl_struct(data, real->strct)) {
+               if (!locate_decl_type_struct(data->structs, real)) {
+                       return 0;
+               }
+               if (!validate_decl_struct(data, real->real.strct)) {
                        return 0;
                }
                break;
        case PSI_T_UNION:
-               if (current && current == real->unn) {
+               if (current && current == real->real.unn) {
                        return 1;
                }
-               if (!validate_decl_union(data, real->unn)) {
+               if (!locate_decl_type_union(data->unions, real)) {
+                       return 0;
+               }
+               if (!validate_decl_union(data, real->real.unn)) {
                        return 0;
                }
                break;
        case PSI_T_ENUM:
-               if (current && current == real->enm) {
+               if (current && current == real->real.enm) {
                        return 1;
                }
-               if (!validate_decl_enum(data, real->enm)) {
+               if (!locate_decl_type_enum(data->enums, real)) {
+                       return 0;
+               }
+               if (!validate_decl_enum(data, real->real.enm)) {
                        return 0;
                }
                break;
@@ -295,10 +302,10 @@ static inline size_t sizeof_decl_arg(decl_arg *darg) {
        } else {
                switch (real->type) {
                case PSI_T_UNION:
-                       size = real->unn->size;
+                       size = real->real.unn->size;
                        break;
                case PSI_T_STRUCT:
-                       size = real->strct->size;
+                       size = real->real.strct->size;
                        break;
                case PSI_T_ENUM:
                default:
@@ -352,10 +359,10 @@ static inline size_t alignof_decl_type(decl_type *t) {
 
        switch (real->type) {
        case PSI_T_STRUCT:
-               align = alignof_decl_struct(real->strct);
+               align = alignof_decl_struct(real->real.strct);
                break;
        case PSI_T_UNION:
-               align = alignof_decl_union(real->unn);
+               align = alignof_decl_union(real->real.unn);
                break;
        case PSI_T_ENUM:
        default:
@@ -820,10 +827,10 @@ static inline int validate_set_value_ex(PSI_Data *data, set_value *set, decl_arg
                if (!set->outer.set || set->outer.set->inner->vals != set->inner->vals) {
                        for (i = 0; i < set->inner->count; ++i) {
                                decl_var *sub_var = set->inner->vals[i]->vars->vars[0];
-                               decl_arg *sub_ref = locate_struct_member(ref_type->strct, sub_var);
+                               decl_arg *sub_ref = locate_struct_member(ref_type->real.strct, sub_var);
 
                                if (sub_ref) {
-                                       if (!validate_set_value_ex(data, set->inner->vals[i], sub_ref, ref_type->strct->args)) {
+                                       if (!validate_set_value_ex(data, set->inner->vals[i], sub_ref, ref_type->real.strct->args)) {
                                                return 0;
                                        }
                                }
@@ -968,7 +975,7 @@ static inline int validate_let_callback(PSI_Data *data, decl_var *cb_var, let_ca
                data->error(data, cb_var->token, PSI_WARNING, "Not a function: %s", cb_var->name);
                return 0;
        }
-       cb_func = cb_type->func;
+       cb_func = cb_type->real.func;
        for (i = 0; i < cb->args->count; ++i) {
                if (!validate_set_value(data, cb->args->vals[i], cb_func->args->count, cb_func->args->args, 0)) {
                        return 0;