Commit 04a22cc4 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

widl: Hide the details of where arguments, fields, values and cases are stored…

widl: Hide the details of where arguments, fields, values and cases are stored in the type_t structure for functions, structures, enums and unions.
parent fbffe4a2
...@@ -17,6 +17,7 @@ C_SRCS = \ ...@@ -17,6 +17,7 @@ C_SRCS = \
server.c \ server.c \
typegen.c \ typegen.c \
typelib.c \ typelib.c \
typetree.c \
utils.c \ utils.c \
widl.c \ widl.c \
write_msft.c write_msft.c
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "utils.h" #include "utils.h"
#include "expr.h" #include "expr.h"
#include "header.h" #include "header.h"
#include "typetree.h"
expr_t *make_expr(enum expr_type type) expr_t *make_expr(enum expr_type type)
{ {
...@@ -362,17 +363,14 @@ static type_t *find_identifier(const char *identifier, const type_t *cont_type, ...@@ -362,17 +363,14 @@ static type_t *find_identifier(const char *identifier, const type_t *cont_type,
*found_in_cont_type = 0; *found_in_cont_type = 0;
if (cont_type && (cont_type->type == RPC_FC_FUNCTION || is_struct(cont_type->type))) if (cont_type)
fields = cont_type->fields_or_args;
else if (cont_type && is_union(cont_type->type))
{ {
if (cont_type->type == RPC_FC_ENCAPSULATED_UNION) if (cont_type->type == RPC_FC_FUNCTION)
{ fields = type_function_get_args(cont_type);
const var_t *uv = LIST_ENTRY(list_tail(cont_type->fields_or_args), const var_t, entry); else if (is_struct(cont_type->type))
fields = uv->type->fields_or_args; fields = type_struct_get_fields(cont_type);
} else if (is_union(cont_type->type))
else fields = type_union_get_cases(cont_type);
fields = cont_type->fields_or_args;
} }
if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry ) if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "parser.h" #include "parser.h"
#include "header.h" #include "header.h"
#include "expr.h" #include "expr.h"
#include "typetree.h"
typedef struct _user_type_t generic_handle_t; typedef struct _user_type_t generic_handle_t;
...@@ -209,7 +210,7 @@ void write_type_left(FILE *h, type_t *t, int declonly) ...@@ -209,7 +210,7 @@ void write_type_left(FILE *h, type_t *t, int declonly)
else fprintf(h, "enum {\n"); else fprintf(h, "enum {\n");
t->written = TRUE; t->written = TRUE;
indentation++; indentation++;
write_enums(h, t->fields_or_args); write_enums(h, type_enum_get_values(t));
indent(h, -1); indent(h, -1);
fprintf(h, "}"); fprintf(h, "}");
} }
...@@ -227,7 +228,10 @@ void write_type_left(FILE *h, type_t *t, int declonly) ...@@ -227,7 +228,10 @@ void write_type_left(FILE *h, type_t *t, int declonly)
else fprintf(h, "struct {\n"); else fprintf(h, "struct {\n");
t->written = TRUE; t->written = TRUE;
indentation++; indentation++;
write_fields(h, t->fields_or_args); if (t->type == RPC_FC_ENCAPSULATED_UNION)
write_fields(h, type_encapsulated_union_get_fields(t));
else
write_fields(h, type_struct_get_fields(t));
indent(h, -1); indent(h, -1);
fprintf(h, "}"); fprintf(h, "}");
} }
...@@ -239,7 +243,7 @@ void write_type_left(FILE *h, type_t *t, int declonly) ...@@ -239,7 +243,7 @@ void write_type_left(FILE *h, type_t *t, int declonly)
else fprintf(h, "union {\n"); else fprintf(h, "union {\n");
t->written = TRUE; t->written = TRUE;
indentation++; indentation++;
write_fields(h, t->fields_or_args); write_fields(h, type_union_get_cases(t));
indent(h, -1); indent(h, -1);
fprintf(h, "}"); fprintf(h, "}");
} }
...@@ -308,7 +312,7 @@ void write_type_v(FILE *h, type_t *t, int is_field, int declonly, ...@@ -308,7 +312,7 @@ void write_type_v(FILE *h, type_t *t, int is_field, int declonly,
if (pt->type == RPC_FC_FUNCTION) { if (pt->type == RPC_FC_FUNCTION) {
if (ptr_level) fputc(')', h); if (ptr_level) fputc(')', h);
fputc('(', h); fputc('(', h);
write_args(h, pt->fields_or_args, NULL, 0, FALSE); write_args(h, type_function_get_args(pt), NULL, 0, FALSE);
fputc(')', h); fputc(')', h);
} else } else
write_type_right(h, t, is_field); write_type_right(h, t, is_field);
...@@ -409,7 +413,14 @@ void check_for_additional_prototype_types(const var_list_t *list) ...@@ -409,7 +413,14 @@ void check_for_additional_prototype_types(const var_list_t *list)
} }
else else
{ {
check_for_additional_prototype_types(type->fields_or_args); var_list_t *vars = NULL;
if (type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32)
vars = type_enum_get_values(type);
else if (is_struct(type->type))
vars = type_struct_get_fields(type);
else if (is_union(type->type))
vars = type_union_get_cases(type);
check_for_additional_prototype_types(vars);
} }
} }
} }
......
...@@ -45,4 +45,6 @@ void pop_import(void); ...@@ -45,4 +45,6 @@ void pop_import(void);
int is_type(const char *name); int is_type(const char *name);
void check_functions(const type_t *iface);
#endif #endif
/*
* IDL Type Tree
*
* Copyright 2008 Robert Shearman
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include "widl.h"
#include "utils.h"
#include "parser.h"
#include "typetree.h"
#include "header.h"
type_t *type_new_function(var_list_t *args)
{
type_t *t = make_type(RPC_FC_FUNCTION, NULL);
t->fields_or_args = args;
return t;
}
type_t *type_new_pointer(type_t *ref, attr_list_t *attrs)
{
type_t *t = make_type(pointer_default, ref);
t->attrs = attrs;
return t;
}
static int compute_method_indexes(type_t *iface)
{
int idx;
func_t *f;
if (iface->ref)
idx = compute_method_indexes(iface->ref);
else
idx = 0;
if (!iface->funcs)
return idx;
LIST_FOR_EACH_ENTRY( f, iface->funcs, func_t, entry )
if (! is_callas(f->def->attrs))
f->idx = idx++;
return idx;
}
void type_interface_define(type_t *iface, type_t *inherit, func_list_t *funcs)
{
iface->ref = inherit;
iface->funcs = funcs;
iface->defined = TRUE;
check_functions(iface);
compute_method_indexes(iface);
}
void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods)
{
iface->ref = find_type("IDispatch", 0);
if (!iface->ref) error_loc("IDispatch is undefined\n");
iface->funcs = NULL;
iface->fields_or_args = props;
iface->funcs = methods;
iface->defined = TRUE;
check_functions(iface);
compute_method_indexes(iface);
}
void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface)
{
type_dispinterface_define(dispiface, iface->fields_or_args, iface->funcs);
}
/*
* IDL Type Tree
*
* Copyright 2008 Robert Shearman
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "widltypes.h"
#include <assert.h>
#ifndef WIDL_TYPE_TREE_H
#define WIDL_TYPE_TREE_H
type_t *type_new_function(var_list_t *args);
type_t *type_new_pointer(type_t *ref, attr_list_t *attrs);
void type_interface_define(type_t *iface, type_t *inherit, func_list_t *funcs);
void type_dispinterface_define(type_t *iface, var_list_t *props, func_list_t *methods);
void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
static inline var_list_t *type_struct_get_fields(const type_t *type)
{
assert(is_struct(type->type));
return type->fields_or_args;
}
static inline var_list_t *type_function_get_args(const type_t *type)
{
assert(type->type == RPC_FC_FUNCTION);
return type->fields_or_args;
}
static inline var_list_t *type_enum_get_values(const type_t *type)
{
assert(type->type == RPC_FC_ENUM16 || type->type == RPC_FC_ENUM32);
return type->fields_or_args;
}
static inline var_t *type_union_get_switch_value(const type_t *type)
{
assert(type->type == RPC_FC_ENCAPSULATED_UNION);
return LIST_ENTRY(list_head(type->fields_or_args), var_t, entry);
}
static inline var_list_t *type_encapsulated_union_get_fields(const type_t *type)
{
assert(type->type == RPC_FC_ENCAPSULATED_UNION);
return type->fields_or_args;
}
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)
{
const var_t *uv = LIST_ENTRY(list_tail(type->fields_or_args), const var_t, entry);
return uv->type->fields_or_args;
}
else
return type->fields_or_args;
}
static inline var_list_t *type_dispiface_get_props(const type_t *type)
{
assert(type->type == RPC_FC_IP);
return type->fields_or_args;
}
static inline var_list_t *type_dispiface_get_methods(const type_t *type)
{
assert(type->type == RPC_FC_IP);
return type->funcs;
}
static inline int type_is_defined(const type_t *type)
{
return type->defined;
}
#endif /* WIDL_TYPE_TREE_H */
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#define __WIDL_WIDLTYPES_H #define __WIDL_WIDLTYPES_H
#include <stdarg.h> #include <stdarg.h>
#include <assert.h>
#include "guiddef.h" #include "guiddef.h"
#include "wine/rpcfc.h" #include "wine/rpcfc.h"
#include "wine/list.h" #include "wine/list.h"
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "utils.h" #include "utils.h"
#include "header.h" #include "header.h"
#include "hash.h" #include "hash.h"
#include "typetree.h"
enum MSFT_segment_index { enum MSFT_segment_index {
MSFT_SEG_TYPEINFO = 0, /* type information */ MSFT_SEG_TYPEINFO = 0, /* type information */
...@@ -1968,14 +1969,14 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte ...@@ -1968,14 +1969,14 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte
if (dispinterface->funcs) if (dispinterface->funcs)
LIST_FOR_EACH_ENTRY( func, dispinterface->funcs, const func_t, entry ) idx++; LIST_FOR_EACH_ENTRY( func, dispinterface->funcs, const func_t, entry ) idx++;
if (dispinterface->fields_or_args) if (type_dispiface_get_props(dispinterface))
LIST_FOR_EACH_ENTRY( var, dispinterface->fields_or_args, var_t, entry ) LIST_FOR_EACH_ENTRY( var, type_dispiface_get_props(dispinterface), var_t, entry )
add_var_desc(msft_typeinfo, idx++, var); add_var_desc(msft_typeinfo, idx++, var);
if (dispinterface->funcs) if (type_dispiface_get_methods(dispinterface))
{ {
idx = 0; idx = 0;
LIST_FOR_EACH_ENTRY( func, dispinterface->funcs, const func_t, entry ) LIST_FOR_EACH_ENTRY( func, type_dispiface_get_methods(dispinterface), const func_t, entry )
if(add_func_desc(msft_typeinfo, func, idx) == S_OK) if(add_func_desc(msft_typeinfo, func, idx) == S_OK)
idx++; idx++;
} }
...@@ -2052,8 +2053,8 @@ static void add_structure_typeinfo(msft_typelib_t *typelib, type_t *structure) ...@@ -2052,8 +2053,8 @@ static void add_structure_typeinfo(msft_typelib_t *typelib, type_t *structure)
msft_typeinfo = create_msft_typeinfo(typelib, TKIND_RECORD, structure->name, structure->attrs); msft_typeinfo = create_msft_typeinfo(typelib, TKIND_RECORD, structure->name, structure->attrs);
msft_typeinfo->typeinfo->size = 0; msft_typeinfo->typeinfo->size = 0;
if (structure->fields_or_args) if (type_struct_get_fields(structure))
LIST_FOR_EACH_ENTRY( cur, structure->fields_or_args, var_t, entry ) LIST_FOR_EACH_ENTRY( cur, type_struct_get_fields(structure), var_t, entry )
add_var_desc(msft_typeinfo, idx++, cur); add_var_desc(msft_typeinfo, idx++, cur);
} }
...@@ -2067,8 +2068,8 @@ static void add_enum_typeinfo(msft_typelib_t *typelib, type_t *enumeration) ...@@ -2067,8 +2068,8 @@ static void add_enum_typeinfo(msft_typelib_t *typelib, type_t *enumeration)
msft_typeinfo = create_msft_typeinfo(typelib, TKIND_ENUM, enumeration->name, enumeration->attrs); msft_typeinfo = create_msft_typeinfo(typelib, TKIND_ENUM, enumeration->name, enumeration->attrs);
msft_typeinfo->typeinfo->size = 0; msft_typeinfo->typeinfo->size = 0;
if (enumeration->fields_or_args) if (type_enum_get_values(enumeration))
LIST_FOR_EACH_ENTRY( cur, enumeration->fields_or_args, var_t, entry ) LIST_FOR_EACH_ENTRY( cur, type_enum_get_values(enumeration), var_t, entry )
add_var_desc(msft_typeinfo, idx++, cur); add_var_desc(msft_typeinfo, idx++, cur);
} }
......
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