widl: Factor and cleanup coclass type declaration and definition.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-02-04 17:43:41 +01:00 committed by Alexandre Julliard
parent 6a1b6a20a3
commit 84b7faeb52
3 changed files with 24 additions and 31 deletions

View File

@ -98,7 +98,6 @@ static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_runtimeclass_attrs(const char *name, attr_list_t *attrs);
static attr_list_t *check_apicontract_attrs(const char *name, attr_list_t *attrs);
const char *get_attr_display_name(enum attr_type type);
@ -306,7 +305,7 @@ static typelib_t *current_typelib;
%type <declarator> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
%type <declarator> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
%type <declarator_list> declarator_list struct_declarator_list
%type <type> coclass coclasshdr coclassdef
%type <type> coclass coclassdef
%type <type> runtimeclass runtimeclass_hdr runtimeclass_def
%type <type> apicontract
%type <num> contract_ver
@ -897,23 +896,12 @@ qualified_type:
| aNAMESPACE '.' { init_lookup_namespace($1); } qualified_seq { $$ = $4; }
;
coclass: tCOCLASS aIDENTIFIER { $$ = type_new_coclass($2); }
| tCOCLASS aKNOWNTYPE { $$ = find_type($2, NULL, 0);
if (type_get_type_detect_alias($$) != TYPE_COCLASS)
error_loc("%s was not declared a coclass at %s:%d\n",
$2, $$->loc_info.input_name,
$$->loc_info.line_number);
}
coclass: tCOCLASS aIDENTIFIER { $$ = type_coclass_declare($2); }
| tCOCLASS aKNOWNTYPE { $$ = type_coclass_declare($2); }
;
coclasshdr: attributes coclass { $$ = $2;
check_def($$);
$$->attrs = check_coclass_attrs($2->name, $1);
}
;
coclassdef: coclasshdr '{' class_interfaces '}' semicolon_opt
{ $$ = type_coclass_define($1, $3); }
coclassdef: attributes coclass '{' class_interfaces '}' semicolon_opt
{ $$ = type_coclass_define($2, $1, $4); }
;
runtimeclass:
@ -2528,7 +2516,7 @@ static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs)
return attrs;
}
static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs)
attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs)
{
const attr_t *attr;
if (!attrs) return attrs;

View File

@ -205,16 +205,6 @@ type_t *type_new_module(char *name)
return type;
}
type_t *type_new_coclass(char *name)
{
type_t *type = get_type(TYPE_COCLASS, name, NULL, 0);
if (type->type_type != TYPE_COCLASS || type->defined)
error_loc("%s: redefinition error; original definition was at %s:%d\n",
type->name, type->loc_info.input_name, type->loc_info.line_number);
type->name = name;
return type;
}
type_t *type_new_runtimeclass(char *name, struct namespace *namespace)
{
type_t *type = get_type(TYPE_RUNTIMECLASS, name, NULL, 0);
@ -512,8 +502,21 @@ void type_module_define(type_t *module, statement_list_t *stmts)
module->defined = TRUE;
}
type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces)
type_t *type_coclass_declare(char *name)
{
type_t *type = get_type(TYPE_COCLASS, name, NULL, 0);
if (type_get_type_detect_alias(type) != TYPE_COCLASS)
error_loc("coclass %s previously not declared a coclass at %s:%d\n",
type->name, type->loc_info.input_name, type->loc_info.line_number);
return type;
}
type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, ifref_list_t *ifaces)
{
if (coclass->defined)
error_loc("coclass %s already defined at %s:%d\n",
coclass->name, coclass->loc_info.input_name, coclass->loc_info.line_number);
coclass->attrs = check_coclass_attrs(coclass->name, attrs);
coclass->details.coclass.ifaces = ifaces;
coclass->defined = TRUE;
return coclass;

View File

@ -29,6 +29,8 @@ enum name_type {
NAME_C
};
attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs);
type_t *type_new_function(var_list_t *args);
type_t *type_new_pointer(type_t *ref);
type_t *type_new_alias(const decl_spec_t *t, const char *name);
@ -38,7 +40,7 @@ type_t *type_new_array(const char *name, const decl_spec_t *element, int declptr
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(char *name);
type_t *type_coclass_declare(char *name);
type_t *type_new_enum(const char *name, struct namespace *namespace, int defined, var_list_t *enums);
type_t *type_new_struct(char *name, struct namespace *namespace, int defined, var_list_t *fields);
type_t *type_new_nonencapsulated_union(const char *name, int defined, var_list_t *fields);
@ -49,7 +51,7 @@ void type_interface_define(type_t *iface, type_t *inherit, statement_list_t *stm
void type_dispinterface_define(type_t *iface, var_list_t *props, var_list_t *methods);
void type_dispinterface_define_from_iface(type_t *dispiface, type_t *iface);
void type_module_define(type_t *module, statement_list_t *stmts);
type_t *type_coclass_define(type_t *coclass, ifref_list_t *ifaces);
type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, ifref_list_t *ifaces);
type_t *type_runtimeclass_define(type_t *runtimeclass, ifref_list_t *ifaces);
int type_is_equal(const type_t *type1, const type_t *type2);
const char *type_get_name(const type_t *type, enum name_type name_type);