Commit e9985905 authored by Alexandre Julliard's avatar Alexandre Julliard

widl: Convert attribute lists to standard Wine lists.

parent 5b0bf5dc
......@@ -46,31 +46,28 @@ static void indent(FILE *h, int delta)
if (delta > 0) indentation += delta;
}
int is_attr(const attr_t *a, enum attr_type t)
int is_attr(const attr_list_t *list, enum attr_type t)
{
while (a) {
if (a->type == t) return 1;
a = NEXT_LINK(a);
}
return 0;
const attr_t *attr;
if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
if (attr->type == t) return 1;
return 0;
}
void *get_attrp(const attr_t *a, enum attr_type t)
void *get_attrp(const attr_list_t *list, enum attr_type t)
{
while (a) {
if (a->type == t) return a->u.pval;
a = NEXT_LINK(a);
}
return NULL;
const attr_t *attr;
if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
if (attr->type == t) return attr->u.pval;
return NULL;
}
unsigned long get_attrv(const attr_t *a, enum attr_type t)
unsigned long get_attrv(const attr_list_t *list, enum attr_type t)
{
while (a) {
if (a->type == t) return a->u.ival;
a = NEXT_LINK(a);
}
return 0;
const attr_t *attr;
if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
if (attr->type == t) return attr->u.ival;
return 0;
}
int is_void(const type_t *t, const var_t *v)
......@@ -443,7 +440,8 @@ void write_externdef(const var_t *v)
fprintf(header, ";\n\n");
}
void write_library(const char *name, const attr_t *attr) {
void write_library(const char *name, const attr_list_t *attr)
{
const UUID *uuid = get_attrp(attr, ATTR_UUID);
fprintf(header, "\n");
write_guid(header, "LIBID", name, uuid);
......@@ -496,21 +494,20 @@ int has_out_arg_or_return(const func_t *func)
/********** INTERFACES **********/
int is_object(const attr_t *a)
int is_object(const attr_list_t *list)
{
while (a) {
if (a->type == ATTR_OBJECT || a->type == ATTR_ODL) return 1;
a = NEXT_LINK(a);
}
return 0;
const attr_t *attr;
if (list) LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
if (attr->type == ATTR_OBJECT || attr->type == ATTR_ODL) return 1;
return 0;
}
int is_local(const attr_t *a)
int is_local(const attr_list_t *a)
{
return is_attr(a, ATTR_LOCAL);
}
const var_t *is_callas(const attr_t *a)
const var_t *is_callas(const attr_list_t *a)
{
return get_attrp(a, ATTR_CALLAS);
}
......
......@@ -21,16 +21,16 @@
#ifndef __WIDL_HEADER_H
#define __WIDL_HEADER_H
extern int is_attr(const attr_t *a, enum attr_type t);
extern void *get_attrp(const attr_t *a, enum attr_type t);
extern unsigned long get_attrv(const attr_t *a, enum attr_type t);
extern int is_attr(const attr_list_t *list, enum attr_type t);
extern void *get_attrp(const attr_list_t *list, enum attr_type t);
extern unsigned long get_attrv(const attr_list_t *list, enum attr_type t);
extern int is_void(const type_t *t, const var_t *v);
extern void write_name(FILE *h, const var_t *v);
extern const char* get_name(const var_t *v);
extern void write_type(FILE *h, type_t *t, const var_t *v, const char *n);
extern int is_object(const attr_t *a);
extern int is_local(const attr_t *a);
extern const var_t *is_callas(const attr_t *a);
extern int is_object(const attr_list_t *list);
extern int is_local(const attr_list_t *list);
extern const var_t *is_callas(const attr_list_t *list);
extern void write_args(FILE *h, var_t *arg, const char *name, int obj, int do_indent);
extern void write_array(FILE *h, const expr_t *v, int field);
extern void write_forward(type_t *iface);
......@@ -42,20 +42,20 @@ extern void write_typedef(type_t *type);
extern void write_expr(FILE *h, const expr_t *e, int brackets);
extern void write_constdef(const var_t *v);
extern void write_externdef(const var_t *v);
extern void write_library(const char *name, const attr_t *attr);
extern void write_library(const char *name, const attr_list_t *attr);
extern void write_user_types(void);
extern const var_t* get_explicit_handle_var(const func_t* func);
extern int has_out_arg_or_return(const func_t *func);
extern void write_guid(FILE *f, const char *guid_prefix, const char *name,
const UUID *uuid);
static inline int is_string_type(const attr_t *attrs, int ptr_level, const expr_t *array)
static inline int is_string_type(const attr_list_t *attrs, int ptr_level, const expr_t *array)
{
return (is_attr(attrs, ATTR_STRING) &&
((ptr_level == 1 && !array) || (ptr_level == 0 && array)));
}
static inline int is_array_type(const attr_t *attrs, int ptr_level, const expr_t *array)
static inline int is_array_type(const attr_list_t *attrs, int ptr_level, const expr_t *array)
{
return ((ptr_level == 1 && !array && is_attr(attrs, ATTR_SIZEIS)) ||
(ptr_level == 0 && array));
......
......@@ -64,6 +64,7 @@
# endif
#endif
static attr_list_t *append_attr(attr_list_t *list, attr_t *attr);
static attr_t *make_attr(enum attr_type type);
static attr_t *make_attrv(enum attr_type type, unsigned long val);
static attr_t *make_attrp(enum attr_type type, void *val);
......@@ -88,7 +89,7 @@ static type_t *make_builtin(char *name);
static type_t *make_int(int sign);
static type_t *reg_type(type_t *type, const char *name, int t);
static type_t *reg_typedefs(type_t *type, var_t *names, attr_t *attrs);
static type_t *reg_typedefs(type_t *type, var_t *names, attr_list_t *attrs);
static type_t *find_type(const char *name, int t);
static type_t *find_type2(char *name, int t);
static type_t *get_type(unsigned char type, char *name, int t);
......@@ -98,7 +99,7 @@ static int get_struct_type(var_t *fields);
static var_t *reg_const(var_t *var);
static var_t *find_const(char *name, int f);
static void write_libid(const char *name, const attr_t *attr);
static void write_libid(const char *name, const attr_list_t *attr);
static void write_clsid(type_t *cls);
static void write_diid(type_t *iface);
static void write_iid(type_t *iface);
......@@ -115,6 +116,7 @@ static void check_arg(var_t *arg);
%}
%union {
attr_t *attr;
attr_list_t *attr_list;
expr_t *expr;
type_t *type;
typeref_t *tref;
......@@ -209,7 +211,8 @@ static void check_arg(var_t *arg);
%token tVOID
%token tWCHAR tWIREMARSHAL
%type <attr> m_attributes attributes attrib_list attribute
%type <attr> attribute
%type <attr_list> m_attributes attributes attrib_list
%type <expr> m_exprs /* exprs expr_list */ m_expr expr expr_list_const expr_const
%type <expr> array array_list
%type <type> inherit interface interfacehdr interfacedef interfacedec
......@@ -367,13 +370,9 @@ attributes:
}
;
attrib_list: attribute
| attrib_list ',' attribute { if ($3) { LINK($3, $1); $$ = $3; }
else { $$ = $1; }
}
| attrib_list ']' '[' attribute { if ($4) { LINK($4, $1); $$ = $4; }
else { $$ = $1; }
}
attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
| attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
| attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
;
attribute: { $$ = NULL; }
......@@ -460,11 +459,11 @@ cases: { $$ = NULL; }
case: tCASE expr ':' field { attr_t *a = make_attrp(ATTR_CASE, $2);
$$ = $4; if (!$$) $$ = make_var(NULL);
LINK(a, $$->attrs); $$->attrs = a;
$$->attrs = append_attr( $$->attrs, a );
}
| tDEFAULT ':' field { attr_t *a = make_attr(ATTR_DEFAULT);
$$ = $3; if (!$$) $$ = make_var(NULL);
LINK(a, $$->attrs); $$->attrs = a;
$$->attrs = append_attr( $$->attrs, a );
}
;
......@@ -689,8 +688,7 @@ dispinterfacehdr: attributes dispinterface { attr_t *attrs;
$$ = $2;
if ($$->defined) yyerror("multiple definition error");
attrs = make_attr(ATTR_DISPINTERFACE);
LINK(attrs, $1);
$$->attrs = attrs;
$$->attrs = append_attr( $1, attrs );
$$->ref = find_type("IDispatch", 0);
if (!$$->ref) yyerror("IDispatch is undefined");
$$->defined = TRUE;
......@@ -903,12 +901,23 @@ void init_types(void)
decl_builtin("handle_t", RPC_FC_BIND_PRIMITIVE);
}
static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
{
if (!attr) return list;
if (!list)
{
list = xmalloc( sizeof(*list) );
list_init( list );
}
list_add_tail( list, &attr->entry );
return list;
}
static attr_t *make_attr(enum attr_type type)
{
attr_t *a = xmalloc(sizeof(attr_t));
a->type = type;
a->u.ival = 0;
INIT_LINK(a);
return a;
}
......@@ -917,7 +926,6 @@ static attr_t *make_attrv(enum attr_type type, unsigned long val)
attr_t *a = xmalloc(sizeof(attr_t));
a->type = type;
a->u.ival = val;
INIT_LINK(a);
return a;
}
......@@ -926,7 +934,6 @@ static attr_t *make_attrp(enum attr_type type, void *val)
attr_t *a = xmalloc(sizeof(attr_t));
a->type = type;
a->u.pval = val;
INIT_LINK(a);
return a;
}
......@@ -1285,7 +1292,7 @@ static type_t *reg_type(type_t *type, const char *name, int t)
return type;
}
static type_t *reg_typedefs(type_t *type, var_t *names, attr_t *attrs)
static type_t *reg_typedefs(type_t *type, var_t *names, attr_list_t *attrs)
{
type_t *ptr = type;
int ptrc = 0;
......@@ -1314,11 +1321,7 @@ static type_t *reg_typedefs(type_t *type, var_t *names, attr_t *attrs)
|| type->kind == TKIND_UNION) && ! type->name && ! parse_only)
{
if (! is_attr(attrs, ATTR_PUBLIC))
{
attr_t *new_attrs = make_attr(ATTR_PUBLIC);
LINK(new_attrs, attrs);
attrs = new_attrs;
}
attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
type->name = gen_name();
}
......@@ -1590,7 +1593,7 @@ static var_t *find_const(char *name, int f)
return cur->var;
}
static void write_libid(const char *name, const attr_t *attr)
static void write_libid(const char *name, const attr_list_t *attr)
{
const UUID *uuid = get_attrp(attr, ATTR_UUID);
write_guid(idfile, "LIBID", name, uuid);
......
......@@ -128,7 +128,7 @@ int is_var_ptr(var_t *v)
int cant_be_null(var_t *v)
{
/* Search backwards for the most recent pointer attribute. */
const attr_t *attrs = v->attrs;
const attr_list_t *attrs = v->attrs;
const type_t *type = v->type;
if (! attrs && type)
......@@ -161,7 +161,7 @@ int cant_be_null(var_t *v)
static int is_user_derived(var_t *v)
{
const attr_t *attrs = v->attrs;
const attr_list_t *attrs = v->attrs;
const type_t *type = v->type;
if (! attrs && type)
......
......@@ -610,7 +610,7 @@ size_t get_type_memsize(const type_t *type)
return type_memsize(type, 0, NULL);
}
static int write_pointers(FILE *file, const attr_t *attrs,
static int write_pointers(FILE *file, const attr_list_t *attrs,
const type_t *type, int ptr_level,
const expr_t *array, int level,
unsigned int *typestring_offset)
......@@ -660,7 +660,7 @@ static int write_pointers(FILE *file, const attr_t *attrs,
return pointers_written;
}
static size_t write_pointer_description(FILE *file, const attr_t *attrs,
static size_t write_pointer_description(FILE *file, const attr_list_t *attrs,
const type_t *type, int ptr_level,
const expr_t *array, int level,
size_t typestring_offset)
......@@ -713,7 +713,7 @@ static size_t write_pointer_description(FILE *file, const attr_t *attrs,
return size;
}
static size_t write_string_tfs(FILE *file, const attr_t *attrs,
static size_t write_string_tfs(FILE *file, const attr_list_t *attrs,
const type_t *type, const expr_t *array,
const char *name, unsigned int *typestring_offset)
{
......@@ -802,7 +802,7 @@ static size_t write_string_tfs(FILE *file, const attr_t *attrs,
}
}
static size_t write_array_tfs(FILE *file, const attr_t *attrs,
static size_t write_array_tfs(FILE *file, const attr_list_t *attrs,
const type_t *type, const expr_t *array,
const char *name, unsigned int *typestring_offset)
{
......@@ -1234,7 +1234,7 @@ static size_t write_struct_tfs(FILE *file, const type_t *type,
}
}
static void write_pointer_only_tfs(FILE *file, const attr_t *attrs, int pointer_type,
static void write_pointer_only_tfs(FILE *file, const attr_list_t *attrs, int pointer_type,
unsigned char flags, size_t offset,
unsigned int *typeformat_offset)
{
......@@ -1263,7 +1263,7 @@ static void write_pointer_only_tfs(FILE *file, const attr_t *attrs, int pointer_
*typeformat_offset += 4;
}
static size_t write_union_tfs(FILE *file, const attr_t *attrs,
static size_t write_union_tfs(FILE *file, const attr_list_t *attrs,
const type_t *type, const char *name,
unsigned int *typeformat_offset)
{
......@@ -1271,7 +1271,7 @@ static size_t write_union_tfs(FILE *file, const attr_t *attrs,
return *typeformat_offset;
}
static size_t write_ip_tfs(FILE *file, const attr_t *attrs,
static size_t write_ip_tfs(FILE *file, const attr_list_t *attrs,
const char *name, unsigned int *typeformat_offset)
{
size_t i;
......
......@@ -221,7 +221,7 @@ unsigned short get_var_vt(var_t *v)
return get_type_vt(v->type);
}
void start_typelib(char *name, attr_t *attrs)
void start_typelib(char *name, attr_list_t *attrs)
{
in_typelib++;
if (!do_typelib) return;
......
......@@ -22,7 +22,7 @@
#define __WIDL_TYPELIB_H
extern int in_typelib;
extern void start_typelib(char *name, attr_t *attrs);
extern void start_typelib(char *name, attr_list_t *attrs);
extern void end_typelib(void);
extern void add_typelib_entry(type_t *t);
extern void add_importlib(const char *name);
......
......@@ -172,7 +172,7 @@ enum type_kind
TKIND_UNION,
TKIND_MAX
};
struct _attr_t {
enum attr_type type;
union {
......@@ -180,8 +180,9 @@ struct _attr_t {
void *pval;
} u;
/* parser-internal */
DECL_LINK(attr_t);
struct list entry;
};
typedef struct list attr_list_t;
struct _expr_t {
enum expr_type type;
......@@ -204,7 +205,7 @@ struct _type_t {
enum type_kind kind;
unsigned char type;
struct _type_t *ref;
const attr_t *attrs;
const attr_list_t *attrs;
func_t *funcs; /* interfaces and modules */
var_t *fields; /* interfaces, structures and enumerations */
ifref_t *ifaces; /* coclasses */
......@@ -229,7 +230,7 @@ struct _var_t {
type_t *type;
var_t *args; /* for function pointers */
const char *tname;
attr_t *attrs;
attr_list_t *attrs;
expr_t *eval;
/* parser-internal */
......@@ -247,7 +248,7 @@ struct _func_t {
struct _ifref_t {
type_t *iface;
attr_t *attrs;
attr_list_t *attrs;
/* parser-internal */
DECL_LINK(ifref_t);
......@@ -286,7 +287,7 @@ struct _importlib_t {
struct _typelib_t {
char *name;
char *filename;
attr_t *attrs;
attr_list_t *attrs;
struct list entries;
struct list importlibs;
};
......
......@@ -1282,7 +1282,7 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, func_t *func, int index)
for(arg = func->args; arg; arg = NEXT_LINK(arg)) {
last_arg = arg;
num_params++;
for(attr = arg->attrs; attr; attr = NEXT_LINK(attr)) {
if (arg->attrs) LIST_FOR_EACH_ENTRY( attr, arg->attrs, const attr_t, entry ) {
if(attr->type == ATTR_DEFAULTVALUE_EXPR || attr->type == ATTR_DEFAULTVALUE_STRING) {
num_defaults++;
break;
......@@ -1294,8 +1294,8 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, func_t *func, int index)
name_offset = ctl2_alloc_name(typeinfo->typelib, func->def->name);
for(attr = func->def->attrs; attr; attr = NEXT_LINK(attr)) {
expr_t *expr = attr->u.pval;
if (func->def->attrs) LIST_FOR_EACH_ENTRY( attr, func->def->attrs, const attr_t, entry ) {
expr_t *expr = attr->u.pval;
switch(attr->type) {
case ATTR_ENTRY_ORDINAL:
extra_attr = max(extra_attr, 3);
......@@ -1442,7 +1442,7 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, func_t *func, int index)
if(defaultdata) *defaultdata = -1;
encode_var(typeinfo->typelib, arg, paramdata, NULL, NULL, &decoded_size);
for(attr = arg->attrs; attr; attr = NEXT_LINK(attr)) {
if (arg->attrs) LIST_FOR_EACH_ENTRY( attr, arg->attrs, const attr_t, entry ) {
switch(attr->type) {
case ATTR_DEFAULTVALUE_EXPR:
{
......@@ -1568,8 +1568,8 @@ static HRESULT add_var_desc(msft_typeinfo_t *typeinfo, UINT index, var_t* var)
id = 0x40000000 + index;
for(attr = var->attrs; attr; attr = NEXT_LINK(attr)) {
expr_t *expr = attr->u.pval;
if (var->attrs) LIST_FOR_EACH_ENTRY( attr, var->attrs, const attr_t, entry ) {
expr_t *expr = attr->u.pval;
switch(attr->type) {
case ATTR_HIDDEN:
varflags |= 0x40; /* VARFLAG_FHIDDEN */
......@@ -1727,8 +1727,9 @@ static HRESULT add_impl_type(msft_typeinfo_t *typeinfo, type_t *ref, importinfo_
}
static msft_typeinfo_t *create_msft_typeinfo(msft_typelib_t *typelib, enum type_kind kind,
const char *name, const attr_t *attr)
const char *name, const attr_list_t *attrs)
{
const attr_t *attr;
msft_typeinfo_t *msft_typeinfo;
int nameoffset;
int typeinfo_offset;
......@@ -1757,7 +1758,7 @@ static msft_typeinfo_t *create_msft_typeinfo(msft_typelib_t *typelib, enum type_
if(kind == TKIND_COCLASS)
typeinfo->flags |= 0x2; /* TYPEFLAG_FCANCREATE */
for( ; attr; attr = NEXT_LINK(attr)) {
if (attrs) LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry ) {
switch(attr->type) {
case ATTR_AGGREGATABLE:
if (kind == TKIND_COCLASS)
......@@ -2092,7 +2093,7 @@ static void add_coclass_typeinfo(msft_typelib_t *typelib, type_t *cls)
if(i < num_ifaces - 1)
ref->onext = offset + (i + 1) * sizeof(*ref);
for(attr = iref->attrs; attr; attr = NEXT_LINK(attr)) {
if (iref->attrs) LIST_FOR_EACH_ENTRY( attr, iref->attrs, const attr_t, entry ) {
switch(attr->type) {
case ATTR_DEFAULT:
ref->flags |= 0x1; /* IMPLTYPEFLAG_FDEFAULT */
......@@ -2296,7 +2297,9 @@ static void set_lib_flags(msft_typelib_t *typelib)
const attr_t *attr;
typelib->typelib_header.flags = 0;
for(attr = typelib->typelib->attrs; attr; attr = NEXT_LINK(attr)) {
if (!typelib->typelib->attrs) return;
LIST_FOR_EACH_ENTRY( attr, typelib->typelib->attrs, const attr_t, entry )
{
switch(attr->type) {
case ATTR_CONTROL:
typelib->typelib_header.flags |= 0x02; /* LIBFLAG_FCONTROL */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment