Author: fireball
Date: Wed Jan 28 04:41:01 2009
New Revision: 39170
URL:
http://svn.reactos.org/svn/reactos?rev=39170&view=rev
Log:
Rob Shearman <robertshearman(a)gmail.com>
widl: Add a new function, type_alias_get_aliasee to wrap the retrieval of the type that
the alias aliases.
Rob Shearman <robertshearman(a)gmail.com>
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.
Austin English <austinenglish(a)gmail.com>
widl: Fix a compiler warning.
Alexandre Julliard <julliard(a)winehq.org>
widl: We need an offset after the correlation descriptor for unencapsulated unions.
Modified:
trunk/reactos/tools/widl/header.c
trunk/reactos/tools/widl/parser.tab.c
trunk/reactos/tools/widl/parser.y
trunk/reactos/tools/widl/typegen.c
trunk/reactos/tools/widl/typelib.c
trunk/reactos/tools/widl/typetree.h
trunk/reactos/tools/widl/widltypes.h
trunk/reactos/tools/widl/write_msft.c
Modified: trunk/reactos/tools/widl/header.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/widl/header.c?rev=39…
==============================================================================
--- trunk/reactos/tools/widl/header.c [iso-8859-1] (original)
+++ trunk/reactos/tools/widl/header.c [iso-8859-1] Wed Jan 28 04:41:01 2009
@@ -63,7 +63,7 @@
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 @@
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 @@
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 @@
}
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_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");
}
Modified: trunk/reactos/tools/widl/parser.tab.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/widl/parser.tab.c?re…
==============================================================================
--- trunk/reactos/tools/widl/parser.tab.c [iso-8859-1] (original)
+++ trunk/reactos/tools/widl/parser.tab.c [iso-8859-1] Wed Jan 28 04:41:01 2009
@@ -4764,7 +4764,7 @@
{
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 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 @@
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 @@
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++;
Modified: trunk/reactos/tools/widl/parser.y
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/widl/parser.y?rev=39…
==============================================================================
--- trunk/reactos/tools/widl/parser.y [iso-8859-1] (original)
+++ trunk/reactos/tools/widl/parser.y [iso-8859-1] Wed Jan 28 04:41:01 2009
@@ -1443,7 +1443,7 @@
{
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 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 @@
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 @@
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++;
Modified: trunk/reactos/tools/widl/typegen.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/widl/typegen.c?rev=3…
==============================================================================
--- trunk/reactos/tools/widl/typegen.c [iso-8859-1] (original)
+++ trunk/reactos/tools/widl/typegen.c [iso-8859-1] Wed Jan 28 04:41:01 2009
@@ -515,7 +515,7 @@
}
if (type_is_alias(t))
- t = t->orig;
+ t = type_alias_get_aliasee(t);
else
return 0;
}
@@ -1053,7 +1053,7 @@
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 @@
}
*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);
Modified: trunk/reactos/tools/widl/typelib.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/widl/typelib.c?rev=3…
==============================================================================
--- trunk/reactos/tools/widl/typelib.c [iso-8859-1] (original)
+++ trunk/reactos/tools/widl/typelib.c [iso-8859-1] Wed Jan 28 04:41:01 2009
@@ -50,28 +50,12 @@
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.
Modified: trunk/reactos/tools/widl/typetree.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/widl/typetree.h?rev=…
==============================================================================
--- trunk/reactos/tools/widl/typetree.h [iso-8859-1] (original)
+++ trunk/reactos/tools/widl/typetree.h [iso-8859-1] Wed Jan 28 04:41:01 2009
@@ -39,47 +39,78 @@
/* 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 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,60 +154,70 @@
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));
- 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;
+ type = type_get_real_type(type);
+ assert(type_get_type(type) == TYPE_ARRAY);
+ return type->ref;
}
static inline int type_is_alias(const type_t *type)
@@ -180,15 +225,23 @@
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;
}
Modified: trunk/reactos/tools/widl/widltypes.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/widl/widltypes.h?rev…
==============================================================================
--- trunk/reactos/tools/widl/widltypes.h [iso-8859-1] (original)
+++ trunk/reactos/tools/widl/widltypes.h [iso-8859-1] Wed Jan 28 04:41:01 2009
@@ -310,6 +310,23 @@
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 @@
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)
{
Modified: trunk/reactos/tools/widl/write_msft.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/widl/write_msft.c?re…
==============================================================================
--- trunk/reactos/tools/widl/write_msft.c [iso-8859-1] (original)
+++ trunk/reactos/tools/widl/write_msft.c [iso-8859-1] Wed Jan 28 04:41:01 2009
@@ -979,7 +979,7 @@
/* 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 @@
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 @@
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;
}