widl: Add new type_get_type and type_get_real_type_type functions.
Use these to implement a few helper functions. Change the type verification in type accessor functions to use these new functions.
This commit is contained in:
parent
bdb1321544
commit
28ee1ee90f
|
@ -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)
|
||||
|
|
|
@ -51,28 +51,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.
|
||||
|
|
|
@ -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,62 +154,72 @@ 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;
|
||||
|
@ -188,13 +233,15 @@ static inline type_t *type_alias_get_aliasee(const type_t *type)
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -301,6 +301,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;
|
||||
|
@ -460,10 +477,74 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue