diff --git a/reactos/tools/widl/header.c b/reactos/tools/widl/header.c index cea25c69207..b7a3ff3a41b 100644 --- a/reactos/tools/widl/header.c +++ b/reactos/tools/widl/header.c @@ -63,7 +63,7 @@ int is_ptrchain_attr(const var_t *var, enum attr_type t) if (is_attr(type->attrs, t)) return 1; else if (type_is_alias(type)) - type = type->orig; + type = type_alias_get_aliasee(type); else if (is_ptr(type)) type = type_pointer_get_ref(type); else return 0; @@ -79,7 +79,7 @@ int is_aliaschain_attr(const type_t *type, enum attr_type attr) if (is_attr(t->attrs, attr)) return 1; else if (type_is_alias(t)) - t = t->orig; + t = type_alias_get_aliasee(t); else return 0; } } @@ -110,8 +110,7 @@ unsigned long get_attrv(const attr_list_t *list, enum attr_type t) int is_void(const type_t *t) { - if (!t->type && !t->ref) return 1; - return 0; + return type_get_type(t) == TYPE_VOID; } int is_conformant_array(const type_t *t) @@ -424,7 +423,7 @@ void check_for_additional_prototype_types(const var_list_t *list) } if (type_is_alias(type)) - type = type->orig; + type = type_alias_get_aliasee(type); else if (is_ptr(type)) type = type_pointer_get_ref(type); else if (is_array(type)) @@ -472,7 +471,7 @@ static void write_generic_handle_routines(FILE *header) static void write_typedef(FILE *header, type_t *type) { fprintf(header, "typedef "); - write_type_def_or_decl(header, type->orig, FALSE, "%s", type->name); + write_type_def_or_decl(header, type_alias_get_aliasee(type), FALSE, "%s", type->name); fprintf(header, ";\n"); } diff --git a/reactos/tools/widl/parser.tab.c b/reactos/tools/widl/parser.tab.c index 4e1a9f82495..931ecb9ef91 100644 --- a/reactos/tools/widl/parser.tab.c +++ b/reactos/tools/widl/parser.tab.c @@ -4764,7 +4764,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl, { ptr_attr = get_attrv(ptr->attrs, ATTR_POINTERTYPE); if (!ptr_attr && type_is_alias(ptr)) - ptr = ptr->orig; + ptr = type_alias_get_aliasee(ptr); else break; } @@ -5098,7 +5098,7 @@ static void add_incomplete(type_t *t) static void fix_type(type_t *t) { if (type_is_alias(t) && is_incomplete(t)) { - type_t *ot = t->orig; + type_t *ot = type_alias_get_aliasee(t); fix_type(ot); if (is_struct(ot->type) || is_union(ot->type)) t->details.structure = ot->details.structure; @@ -5701,9 +5701,9 @@ static void check_field_common(const type_t *container_type, break; } if (type_is_alias(type)) - type = type->orig; + type = type_alias_get_aliasee(type); else if (is_ptr(type)) - type = type->ref; + type = type_pointer_get_ref(type); else if (is_array(type)) type = type_array_get_element(type); else @@ -5763,7 +5763,7 @@ static void check_remoting_args(const var_t *func) if (is_attr(type->attrs, ATTR_CONTEXTHANDLE)) break; if (type_is_alias(type)) - type = type->orig; + type = type_alias_get_aliasee(type); else if (is_ptr(type)) { ptr_level++; diff --git a/reactos/tools/widl/parser.y b/reactos/tools/widl/parser.y index 084b5b3d2a0..91036ab42f0 100644 --- a/reactos/tools/widl/parser.y +++ b/reactos/tools/widl/parser.y @@ -1443,7 +1443,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl, { ptr_attr = get_attrv(ptr->attrs, ATTR_POINTERTYPE); if (!ptr_attr && type_is_alias(ptr)) - ptr = ptr->orig; + ptr = type_alias_get_aliasee(ptr); else break; } @@ -1777,7 +1777,7 @@ static void add_incomplete(type_t *t) static void fix_type(type_t *t) { if (type_is_alias(t) && is_incomplete(t)) { - type_t *ot = t->orig; + type_t *ot = type_alias_get_aliasee(t); fix_type(ot); if (is_struct(ot->type) || is_union(ot->type)) t->details.structure = ot->details.structure; @@ -2380,9 +2380,9 @@ static void check_field_common(const type_t *container_type, break; } if (type_is_alias(type)) - type = type->orig; + type = type_alias_get_aliasee(type); else if (is_ptr(type)) - type = type->ref; + type = type_pointer_get_ref(type); else if (is_array(type)) type = type_array_get_element(type); else @@ -2442,7 +2442,7 @@ static void check_remoting_args(const var_t *func) if (is_attr(type->attrs, ATTR_CONTEXTHANDLE)) break; if (type_is_alias(type)) - type = type->orig; + type = type_alias_get_aliasee(type); else if (is_ptr(type)) { ptr_level++; diff --git a/reactos/tools/widl/typegen.c b/reactos/tools/widl/typegen.c index da5c29bea97..599e2fe70d1 100644 --- a/reactos/tools/widl/typegen.c +++ b/reactos/tools/widl/typegen.c @@ -515,7 +515,7 @@ static type_t *get_user_type(const type_t *t, const char **pname) } if (type_is_alias(t)) - t = t->orig; + t = type_alias_get_aliasee(t); else return 0; } @@ -1053,7 +1053,7 @@ size_t type_memsize(const type_t *t, unsigned int *align) size_t size = 0; if (type_is_alias(t)) - size = type_memsize(t->orig, align); + size = type_memsize(type_alias_get_aliasee(t), align); else if (t->declarray && is_conformant_array(t)) { type_memsize(type_array_get_element(t), align); @@ -2325,6 +2325,8 @@ static size_t write_union_tfs(FILE *file, type_t *type, unsigned int *tfsoff) } *tfsoff += write_conf_or_var_desc(file, NULL, *tfsoff, st, &dummy_expr ); + print_file(file, 2, "NdrFcShort(0x2),\t/* Offset= 2 (%u) */\n", *tfsoff + 2); + *tfsoff += 2; } print_file(file, 2, "NdrFcShort(0x%x),\t/* %d */\n", size, size); diff --git a/reactos/tools/widl/typelib.c b/reactos/tools/widl/typelib.c index 7945f09f71c..08a8ee253dd 100644 --- a/reactos/tools/widl/typelib.c +++ b/reactos/tools/widl/typelib.c @@ -50,28 +50,12 @@ static typelib_t *typelib; int is_ptr(const type_t *t) { - unsigned char c = t->type; - return c == RPC_FC_RP - || c == RPC_FC_UP - || c == RPC_FC_FP - || c == RPC_FC_OP; + return type_get_type(t) == TYPE_POINTER; } int is_array(const type_t *t) { - switch (t->type) - { - case RPC_FC_SMFARRAY: - case RPC_FC_LGFARRAY: - case RPC_FC_SMVARRAY: - case RPC_FC_LGVARRAY: - case RPC_FC_CARRAY: - case RPC_FC_CVARRAY: - case RPC_FC_BOGUS_ARRAY: - return TRUE; - default: - return FALSE; - } + return type_get_type(t) == TYPE_ARRAY; } /* List of oleauto types that should be recognized by name. diff --git a/reactos/tools/widl/typetree.h b/reactos/tools/widl/typetree.h index 8efc62bd996..cf018521af2 100644 --- a/reactos/tools/widl/typetree.h +++ b/reactos/tools/widl/typetree.h @@ -39,47 +39,78 @@ type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces); /* FIXME: shouldn't need to export this */ type_t *duptype(type_t *t, int dupname); +/* un-alias the type until finding the non-alias type */ +static inline type_t *type_get_real_type(const type_t *type) +{ + if (type->is_alias) + return type_get_real_type(type->orig); + else + return (type_t *)type; +} + +static inline enum type_type type_get_type(const type_t *type) +{ + return type_get_type_detect_alias(type_get_real_type(type)); +} + +static inline unsigned char type_basic_get_fc(const type_t *type) +{ + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_BASIC); + return type->type; +} + static inline var_list_t *type_struct_get_fields(const type_t *type) { - assert(is_struct(type->type)); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_STRUCT); return type->details.structure->fields; } static inline var_list_t *type_function_get_args(const type_t *type) { - assert(type->type == RPC_FC_FUNCTION); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_FUNCTION); return type->details.function->args; } static inline type_t *type_function_get_rettype(const type_t *type) { - assert(type->type == RPC_FC_FUNCTION); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_FUNCTION); return type->ref; } static inline var_list_t *type_enum_get_values(const type_t *type) { - assert(type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ENUM); return type->details.enumeration->enums; } static inline var_t *type_union_get_switch_value(const type_t *type) { - assert(type->type == RPC_FC_ENCAPSULATED_UNION); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION); return LIST_ENTRY(list_head(type->details.structure->fields), var_t, entry); } static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type) { - assert(type->type == RPC_FC_ENCAPSULATED_UNION); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ENCAPSULATED_UNION); return type->details.structure->fields; } static inline var_list_t *type_union_get_cases(const type_t *type) { - assert(type->type == RPC_FC_ENCAPSULATED_UNION || - type->type == RPC_FC_NON_ENCAPSULATED_UNION); - if (type->type == RPC_FC_ENCAPSULATED_UNION) + enum type_type type_type; + + type = type_get_real_type(type); + type_type = type_get_type(type); + + assert(type_type == TYPE_UNION || type_type == TYPE_ENCAPSULATED_UNION); + if (type_type == TYPE_ENCAPSULATED_UNION) { const var_t *uv = LIST_ENTRY(list_tail(type->details.structure->fields), const var_t, entry); return uv->type->details.structure->fields; @@ -90,25 +121,29 @@ static inline var_list_t *type_union_get_cases(const type_t *type) static inline statement_list_t *type_iface_get_stmts(const type_t *type) { - assert(type->type == RPC_FC_IP); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_INTERFACE); return type->details.iface->stmts; } static inline type_t *type_iface_get_inherit(const type_t *type) { - assert(type->type == RPC_FC_IP); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_INTERFACE); return type->ref; } static inline var_list_t *type_dispiface_get_props(const type_t *type) { - assert(type->type == RPC_FC_IP); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_INTERFACE); return type->details.iface->disp_props; } static inline var_list_t *type_dispiface_get_methods(const type_t *type) { - assert(type->type == RPC_FC_IP); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_INTERFACE); return type->details.iface->disp_methods; } @@ -119,76 +154,94 @@ static inline int type_is_defined(const type_t *type) static inline int type_is_complete(const type_t *type) { - if (type->type == RPC_FC_FUNCTION) + switch (type_get_type_detect_alias(type)) + { + case TYPE_FUNCTION: return (type->details.function != NULL); - else if (type->type == RPC_FC_IP) + case TYPE_INTERFACE: return (type->details.iface != NULL); - else if (type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32) + case TYPE_ENUM: return (type->details.enumeration != NULL); - else if (is_struct(type->type) || is_union(type->type)) + case TYPE_UNION: + case TYPE_ENCAPSULATED_UNION: + case TYPE_STRUCT: return (type->details.structure != NULL); - else + case TYPE_VOID: + case TYPE_BASIC: + case TYPE_ALIAS: + case TYPE_MODULE: + case TYPE_COCLASS: + case TYPE_POINTER: + case TYPE_ARRAY: return TRUE; + } + return FALSE; } static inline int type_array_has_conformance(const type_t *type) { - assert(is_array(type)); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ARRAY); return (type->details.array.size_is != NULL); } static inline int type_array_has_variance(const type_t *type) { - assert(is_array(type)); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ARRAY); return (type->details.array.length_is != NULL); } static inline unsigned long type_array_get_dim(const type_t *type) { - assert(is_array(type)); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ARRAY); return type->details.array.dim; } static inline expr_t *type_array_get_conformance(const type_t *type) { - assert(is_array(type)); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ARRAY); return type->details.array.size_is; } static inline expr_t *type_array_get_variance(const type_t *type) { - assert(is_array(type)); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ARRAY); return type->details.array.length_is; } static inline type_t *type_array_get_element(const type_t *type) { - assert(is_array(type)); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_ARRAY); return type->ref; } -static inline type_t *type_get_real_type(const type_t *type) -{ - if (type->is_alias) - return type_get_real_type(type->orig); - else - return (type_t *)type; -} - static inline int type_is_alias(const type_t *type) { return type->is_alias; } +static inline type_t *type_alias_get_aliasee(const type_t *type) +{ + assert(type_is_alias(type)); + return type->orig; +} + static inline ifref_list_t *type_coclass_get_ifaces(const type_t *type) { - assert(type->type == RPC_FC_COCLASS); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_COCLASS); return type->details.coclass.ifaces; } static inline type_t *type_pointer_get_ref(const type_t *type) { - assert(is_ptr(type)); + type = type_get_real_type(type); + assert(type_get_type(type) == TYPE_POINTER); return type->ref; } diff --git a/reactos/tools/widl/widltypes.h b/reactos/tools/widl/widltypes.h index f4c47aff9af..85a3ad30ca7 100644 --- a/reactos/tools/widl/widltypes.h +++ b/reactos/tools/widl/widltypes.h @@ -310,6 +310,23 @@ struct coclass_details ifref_list_t *ifaces; }; +enum type_type +{ + TYPE_VOID, + TYPE_BASIC, /* ints, floats and handles */ + TYPE_ENUM, + TYPE_STRUCT, + TYPE_ENCAPSULATED_UNION, + TYPE_UNION, + TYPE_ALIAS, + TYPE_MODULE, + TYPE_COCLASS, + TYPE_FUNCTION, + TYPE_INTERFACE, + TYPE_POINTER, + TYPE_ARRAY, +}; + struct _type_t { const char *name; unsigned char type; @@ -469,10 +486,75 @@ static inline var_list_t *type_get_function_args(const type_t *func_type) return func_type->details.function->args; } +static inline enum type_type type_get_type_detect_alias(const type_t *type) +{ + if (type->is_alias) + return TYPE_ALIAS; + switch (type->type) + { + case 0: + return TYPE_VOID; + case RPC_FC_BYTE: + case RPC_FC_CHAR: + case RPC_FC_USMALL: + case RPC_FC_SMALL: + case RPC_FC_WCHAR: + case RPC_FC_USHORT: + case RPC_FC_SHORT: + case RPC_FC_ULONG: + case RPC_FC_LONG: + case RPC_FC_HYPER: + case RPC_FC_IGNORE: + case RPC_FC_FLOAT: + case RPC_FC_DOUBLE: + case RPC_FC_ERROR_STATUS_T: + case RPC_FC_BIND_PRIMITIVE: + return TYPE_BASIC; + case RPC_FC_ENUM16: + case RPC_FC_ENUM32: + return TYPE_ENUM; + case RPC_FC_RP: + case RPC_FC_UP: + case RPC_FC_FP: + case RPC_FC_OP: + return TYPE_POINTER; + case RPC_FC_STRUCT: + case RPC_FC_PSTRUCT: + case RPC_FC_CSTRUCT: + case RPC_FC_CPSTRUCT: + case RPC_FC_CVSTRUCT: + case RPC_FC_BOGUS_STRUCT: + return TYPE_STRUCT; + case RPC_FC_ENCAPSULATED_UNION: + return TYPE_ENCAPSULATED_UNION; + case RPC_FC_NON_ENCAPSULATED_UNION: + return TYPE_UNION; + case RPC_FC_SMFARRAY: + case RPC_FC_LGFARRAY: + case RPC_FC_SMVARRAY: + case RPC_FC_LGVARRAY: + case RPC_FC_CARRAY: + case RPC_FC_CVARRAY: + case RPC_FC_BOGUS_ARRAY: + return TYPE_ARRAY; + case RPC_FC_FUNCTION: + return TYPE_FUNCTION; + case RPC_FC_COCLASS: + return TYPE_COCLASS; + case RPC_FC_IP: + return TYPE_INTERFACE; + case RPC_FC_MODULE: + return TYPE_MODULE; + default: + assert(0); + return 0; + } +} + #define STATEMENTS_FOR_EACH_FUNC(stmt, stmts) \ if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) \ if (stmt->type == STMT_DECLARATION && stmt->u.var->stgclass == STG_NONE && \ - stmt->u.var->type->type == RPC_FC_FUNCTION) + type_get_type_detect_alias(stmt->u.var->type) == TYPE_FUNCTION) static inline int statements_has_func(const statement_list_t *stmts) { diff --git a/reactos/tools/widl/write_msft.c b/reactos/tools/widl/write_msft.c index 38c234fc15f..b74c562119b 100644 --- a/reactos/tools/widl/write_msft.c +++ b/reactos/tools/widl/write_msft.c @@ -979,7 +979,7 @@ static int encode_type( /* typedef'd types without public attribute aren't included in the typelib */ while (type->typelib_idx < 0 && type_is_alias(type) && !is_attr(type->attrs, ATTR_PUBLIC)) - type = type->orig; + type = type_alias_get_aliasee(type); chat("encode_type: VT_USERDEFINED - type %p name = %s type->type %d idx %d\n", type, type->name, type->type, type->typelib_idx); @@ -2093,8 +2093,11 @@ static void add_typedef_typeinfo(msft_typelib_t *typelib, type_t *tdef) tdef->typelib_idx = typelib->typelib_header.nrtypeinfos; msft_typeinfo = create_msft_typeinfo(typelib, TKIND_ALIAS, tdef->name, tdef->attrs); - encode_type(typelib, get_type_vt(tdef->orig), tdef->orig, &msft_typeinfo->typeinfo->datatype1, &msft_typeinfo->typeinfo->size, - &alignment, &msft_typeinfo->typeinfo->datatype2); + encode_type(typelib, get_type_vt(type_alias_get_aliasee(tdef)), + type_alias_get_aliasee(tdef), + &msft_typeinfo->typeinfo->datatype1, + &msft_typeinfo->typeinfo->size, + &alignment, &msft_typeinfo->typeinfo->datatype2); msft_typeinfo->typeinfo->typekind |= (alignment << 11 | alignment << 6); } @@ -2267,7 +2270,7 @@ static void add_entry(msft_typelib_t *typelib, const statement_t *stmt) if (is_attr(type_entry->type->attrs, ATTR_PUBLIC)) add_typedef_typeinfo(typelib, type_entry->type); else - add_type_typeinfo(typelib, type_entry->type->orig); + add_type_typeinfo(typelib, type_alias_get_aliasee(type_entry->type)); } break; }