From 13c39675229cc7789a41c428588f40ef490d0e97 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Thu, 5 Mar 2009 08:23:00 +0000 Subject: [PATCH] widl: Move type_new_enum, type_new_struct, type_new_encapsulated_union and type_new_unencapsulated_union to typetree.c. --- tools/widl/parser.y | 113 ++--------------------------------------- tools/widl/typetree.c | 83 ++++++++++++++++++++++++++++++ tools/widl/typetree.h | 4 ++ tools/widl/widltypes.h | 10 ++++ 4 files changed, 102 insertions(+), 108 deletions(-) diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 816d5e1a77..4c750ec66f 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -89,7 +89,6 @@ typedef struct _decl_spec_t typelist_t incomplete_types = LIST_INIT(incomplete_types); -static void add_incomplete(type_t *t); static void fix_incomplete(void); static void fix_incomplete_types(type_t *complete_type); @@ -106,9 +105,7 @@ static void set_type(var_t *v, decl_spec_t *decl_spec, const declarator_t *decl, static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls); static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface); static ifref_t *make_ifref(type_t *iface); -static var_list_t *append_var(var_list_t *list, var_t *var); static var_list_t *append_var_list(var_list_t *list, var_list_t *vars); -static var_t *make_var(char *name); static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p); static declarator_t *make_declarator(var_t *var); static func_list_t *append_func(func_list_t *list, func_t *func); @@ -117,16 +114,9 @@ static type_t *make_safearray(type_t *type); static typelib_t *make_library(const char *name, const attr_list_t *attrs); static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type); -static type_t *type_new_enum(const char *name, int defined, var_list_t *enums); -static type_t *type_new_struct(char *name, int defined, var_list_t *fields); -static type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields); -static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases); - -static type_t *reg_type(type_t *type, const char *name, int t); static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs); static type_t *find_type_or_error(const char *name, int t); static type_t *find_type_or_error2(char *name, int t); -static type_t *get_type(enum type_type type, char *name, int t); static var_t *reg_const(var_t *var); @@ -162,10 +152,6 @@ static statement_t *make_statement_import(const char *str); static statement_t *make_statement_typedef(var_list_t *names); static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt); -#define tsENUM 1 -#define tsSTRUCT 2 -#define tsUNION 3 - %} %union { attr_t *attr; @@ -1240,95 +1226,6 @@ void clear_all_offsets(void) node->data.typestring_offset = node->data.ptrdesc = 0; } -static type_t *type_new_enum(const char *name, int defined, var_list_t *enums) -{ - type_t *tag_type = name ? find_type(name, tsENUM) : NULL; - type_t *t = make_type(TYPE_ENUM); - t->name = name; - - if (tag_type && tag_type->details.enumeration) - t->details.enumeration = tag_type->details.enumeration; - else if (defined) - { - t->details.enumeration = xmalloc(sizeof(*t->details.enumeration)); - t->details.enumeration->enums = enums; - t->defined = TRUE; - } - - if (name) - { - if (defined) - reg_type(t, name, tsENUM); - else - add_incomplete(t); - } - return t; -} - -static type_t *type_new_struct(char *name, int defined, var_list_t *fields) -{ - type_t *tag_type = name ? find_type(name, tsSTRUCT) : NULL; - type_t *t = make_type(TYPE_STRUCT); - t->name = name; - if (defined || (tag_type && tag_type->details.structure)) - { - if (tag_type && tag_type->details.structure) - t->details.structure = tag_type->details.structure; - else if (defined) - { - t->details.structure = xmalloc(sizeof(*t->details.structure)); - t->details.structure->fields = fields; - t->defined = TRUE; - } - } - if (name) - { - if (fields) - reg_type(t, name, tsSTRUCT); - else - add_incomplete(t); - } - return t; -} - -static type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields) -{ - type_t *tag_type = name ? find_type(name, tsUNION) : NULL; - type_t *t = make_type(TYPE_UNION); - t->name = name; - if (tag_type && tag_type->details.structure) - t->details.structure = tag_type->details.structure; - else if (defined) - { - t->details.structure = xmalloc(sizeof(*t->details.structure)); - t->details.structure->fields = fields; - t->defined = TRUE; - } - if (name) - { - if (defined) - reg_type(t, name, tsUNION); - else - add_incomplete(t); - } - return t; -} - -static type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases) -{ - type_t *t = get_type(TYPE_ENCAPSULATED_UNION, name, tsUNION); - if (!union_field) union_field = make_var( xstrdup("tagged_union") ); - union_field->type = make_type(TYPE_UNION); - union_field->type->details.structure = xmalloc(sizeof(*union_field->type->details.structure)); - union_field->type->details.structure->fields = cases; - union_field->type->defined = TRUE; - t->details.structure = xmalloc(sizeof(*t->details.structure)); - t->details.structure->fields = append_var( NULL, switch_field ); - t->details.structure->fields = append_var( t->details.structure->fields, union_field ); - t->defined = TRUE; - return t; -} - static void type_function_add_head_arg(type_t *type, var_t *arg) { if (!type->details.function->args) @@ -1588,7 +1485,7 @@ static ifref_t *make_ifref(type_t *iface) return l; } -static var_list_t *append_var(var_list_t *list, var_t *var) +var_list_t *append_var(var_list_t *list, var_t *var) { if (!var) return list; if (!list) @@ -1612,7 +1509,7 @@ static var_list_t *append_var_list(var_list_t *list, var_list_t *vars) return list; } -static var_t *make_var(char *name) +var_t *make_var(char *name) { var_t *v = xmalloc(sizeof(var_t)); v->name = name; @@ -1704,7 +1601,7 @@ struct rtype { struct rtype *type_hash[HASHMAX]; -static type_t *reg_type(type_t *type, const char *name, int t) +type_t *reg_type(type_t *type, const char *name, int t) { struct rtype *nt; int hash; @@ -1732,7 +1629,7 @@ static int is_incomplete(const type_t *t) type_get_type_detect_alias(t) == TYPE_ENCAPSULATED_UNION); } -static void add_incomplete(type_t *t) +void add_incomplete(type_t *t) { struct typenode *tn = xmalloc(sizeof *tn); tn->type = t; @@ -1875,7 +1772,7 @@ int is_type(const char *name) return find_type(name, 0) != NULL; } -static type_t *get_type(enum type_type type, char *name, int t) +type_t *get_type(enum type_type type, char *name, int t) { type_t *tp; if (name) { diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c index d109314c59..f58935366c 100644 --- a/tools/widl/typetree.c +++ b/tools/widl/typetree.c @@ -159,6 +159,89 @@ type_t *type_new_void(void) return void_type; } +type_t *type_new_enum(const char *name, int defined, var_list_t *enums) +{ + type_t *tag_type = name ? find_type(name, tsENUM) : NULL; + type_t *t = make_type(TYPE_ENUM); + t->name = name; + + if (tag_type && tag_type->details.enumeration) + t->details.enumeration = tag_type->details.enumeration; + else if (defined) + { + t->details.enumeration = xmalloc(sizeof(*t->details.enumeration)); + t->details.enumeration->enums = enums; + t->defined = TRUE; + } + + if (name) + { + if (defined) + reg_type(t, name, tsENUM); + else + add_incomplete(t); + } + return t; +} + +type_t *type_new_struct(char *name, int defined, var_list_t *fields) +{ + type_t *tag_type = name ? find_type(name, tsSTRUCT) : NULL; + type_t *t = make_type(TYPE_STRUCT); + t->name = name; + if (tag_type && tag_type->details.structure) + t->details.structure = tag_type->details.structure; + else if (defined) + { + t->details.structure = xmalloc(sizeof(*t->details.structure)); + t->details.structure->fields = fields; + t->defined = TRUE; + } + if (name) + { + if (defined) + reg_type(t, name, tsSTRUCT); + else + add_incomplete(t); + } + return t; +} + +type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields) +{ + type_t *tag_type = name ? find_type(name, tsUNION) : NULL; + type_t *t = make_type(TYPE_UNION); + t->name = name; + if (tag_type && tag_type->details.structure) + t->details.structure = tag_type->details.structure; + else if (defined) + { + t->details.structure = xmalloc(sizeof(*t->details.structure)); + t->details.structure->fields = fields; + t->defined = TRUE; + } + if (name) + { + if (defined) + reg_type(t, name, tsUNION); + else + add_incomplete(t); + } + return t; +} + +type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases) +{ + type_t *t = get_type(TYPE_ENCAPSULATED_UNION, name, tsUNION); + if (!union_field) union_field = make_var( xstrdup("tagged_union") ); + union_field->type = type_new_nonencapsulated_union(NULL, TRUE, cases); + t->details.structure = xmalloc(sizeof(*t->details.structure)); + t->details.structure->fields = append_var( NULL, switch_field ); + t->details.structure->fields = append_var( t->details.structure->fields, union_field ); + t->defined = TRUE; + return t; +} + static int compute_method_indexes(type_t *iface) { int idx; diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h index 5e1c481cb7..c267e5fa6b 100644 --- a/tools/widl/typetree.h +++ b/tools/widl/typetree.h @@ -34,6 +34,10 @@ type_t *type_new_basic(enum type_basic_type basic_type); type_t *type_new_int(enum type_basic_type basic_type, int sign); type_t *type_new_void(void); type_t *type_new_coclass(const char *name); +type_t *type_new_enum(const char *name, int defined, var_list_t *enums); +type_t *type_new_struct(char *name, int defined, var_list_t *fields); +type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields); +type_t *type_new_encapsulated_union(char *name, var_t *switch_field, var_t *union_field, var_list_t *cases); void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stmts); 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); diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 1a534e9f7f..e84aba78b5 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -503,9 +503,19 @@ int cant_be_null(const var_t *v); int is_struct(unsigned char tc); int is_union(unsigned char tc); +#define tsENUM 1 +#define tsSTRUCT 2 +#define tsUNION 3 + var_t *find_const(const char *name, int f); type_t *find_type(const char *name, int t); type_t *make_type(enum type_type type); +type_t *get_type(enum type_type type, char *name, int t); +type_t *reg_type(type_t *type, const char *name, int t); +void add_incomplete(type_t *t); + +var_t *make_var(char *name); +var_list_t *append_var(var_list_t *list, var_t *var); void init_loc_info(loc_info_t *);