From: Rémi Bernon rbernon@codeweavers.com
--- tools/widl/expr.c | 62 ++++++++----------- tools/widl/parser.y | 64 ++++++++------------ tools/widl/typetree.c | 134 +++++++++++++++++++++-------------------- tools/widl/typetree.h | 2 +- tools/widl/utils.c | 70 ++++++++------------- tools/widl/utils.h | 8 +-- tools/widl/widltypes.h | 9 ++- 7 files changed, 157 insertions(+), 192 deletions(-)
diff --git a/tools/widl/expr.c b/tools/widl/expr.c index 88d59290d6b..e0c56b81089 100644 --- a/tools/widl/expr.c +++ b/tools/widl/expr.c @@ -406,29 +406,25 @@ struct expression_type static void check_scalar_type(const struct expr_loc *expr_loc, const type_t *cont_type, const type_t *type) { - if (!cont_type || (!is_integer_type(type) && !is_ptr(type) && - !is_float_type(type))) - error_loc_info(&expr_loc->v->loc_info, "scalar type required in expression%s%s\n", - expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); + if (!cont_type || (!is_integer_type( type ) && !is_ptr( type ) && !is_float_type( type ))) + error_at( &expr_loc->v->where, "scalar type required in expression%s%s\n", + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); }
static void check_arithmetic_type(const struct expr_loc *expr_loc, const type_t *cont_type, const type_t *type) { - if (!cont_type || (!is_integer_type(type) && !is_float_type(type))) - error_loc_info(&expr_loc->v->loc_info, "arithmetic type required in expression%s%s\n", - expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); + if (!cont_type || (!is_integer_type( type ) && !is_float_type( type ))) + error_at( &expr_loc->v->where, "arithmetic type required in expression%s%s\n", + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); }
static void check_integer_type(const struct expr_loc *expr_loc, const type_t *cont_type, const type_t *type) { - if (!cont_type || !is_integer_type(type)) - error_loc_info(&expr_loc->v->loc_info, "integer type required in expression%s%s\n", - expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); + if (!cont_type || !is_integer_type( type )) + error_at( &expr_loc->v->where, "integer type required in expression%s%s\n", + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); }
static type_t *find_identifier(const char *identifier, const type_t *cont_type, int *found_in_cont_type) @@ -547,11 +543,8 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc result.is_temporary = FALSE; result.type = find_identifier(e->u.sval, cont_type, &found_in_cont_type); if (!result.type) - { - error_loc_info(&expr_loc->v->loc_info, "identifier %s cannot be resolved in expression%s%s\n", - e->u.sval, expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); - } + error_at( &expr_loc->v->where, "identifier %s cannot be resolved in expression%s%s\n", e->u.sval, + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); break; } case EXPR_LOGNOT: @@ -575,9 +568,8 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc case EXPR_ADDRESSOF: result = resolve_expression(expr_loc, cont_type, e->ref); if (!result.is_variable) - error_loc_info(&expr_loc->v->loc_info, "address-of operator applied to non-variable type in expression%s%s\n", - expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); + error_at( &expr_loc->v->where, "address-of operator applied to non-variable type in expression%s%s\n", + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); result.is_variable = FALSE; result.is_temporary = TRUE; result.type = type_new_pointer(result.type); @@ -590,9 +582,8 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc && type_array_is_decl_as_ptr(result.type)) result.type = type_array_get_element_type(result.type); else - error_loc_info(&expr_loc->v->loc_info, "dereference operator applied to non-pointer type in expression%s%s\n", - expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); + error_at( &expr_loc->v->where, "dereference operator applied to non-pointer type in expression%s%s\n", + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); break; case EXPR_CAST: result = resolve_expression(expr_loc, cont_type, e->ref); @@ -645,9 +636,8 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc if (result.type && is_valid_member_operand(result.type)) result = resolve_expression(expr_loc, result.type, e->u.ext); else - error_loc_info(&expr_loc->v->loc_info, "'.' or '->' operator applied to a type that isn't a structure, union or enumeration in expression%s%s\n", - expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); + error_at( &expr_loc->v->where, "'.' or '->' operator applied to a type that isn't a structure, union or enumeration in expression%s%s\n", + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); break; case EXPR_COND: { @@ -658,8 +648,8 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc result_third = resolve_expression(expr_loc, cont_type, e->ext2); check_scalar_type(expr_loc, cont_type, result_second.type); check_scalar_type(expr_loc, cont_type, result_third.type); - if (!is_ptr(result_second.type) ^ !is_ptr(result_third.type)) - error_loc_info(&expr_loc->v->loc_info, "type mismatch in ?: expression\n" ); + if (!is_ptr( result_second.type ) ^ !is_ptr( result_third.type )) + error_at( &expr_loc->v->where, "type mismatch in ?: expression\n" ); /* FIXME: determine the correct return type */ result = result_second; result.is_variable = FALSE; @@ -672,15 +662,15 @@ static struct expression_type resolve_expression(const struct expr_loc *expr_loc struct expression_type index_result; result.type = type_array_get_element_type(result.type); index_result = resolve_expression(expr_loc, cont_type /* FIXME */, e->u.ext); - if (!index_result.type || !is_integer_type(index_result.type)) - error_loc_info(&expr_loc->v->loc_info, "array subscript not of integral type in expression%s%s\n", - expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); + if (!index_result.type || !is_integer_type( index_result.type )) + error_at( &expr_loc->v->where, "array subscript not of integral type in expression%s%s\n", + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); } else - error_loc_info(&expr_loc->v->loc_info, "array subscript operator applied to non-array type in expression%s%s\n", - expr_loc->attr ? " for attribute " : "", - expr_loc->attr ? expr_loc->attr : ""); + { + error_at( &expr_loc->v->where, "array subscript operator applied to non-array type in expression%s%s\n", + expr_loc->attr ? " for attribute " : "", expr_loc->attr ? expr_loc->attr : "" ); + } break; } return result; diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 1176c2427a1..b18e24b1b01 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -1791,9 +1791,7 @@ static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, declarator { if (ptr_attr && ptr_attr != FC_UP && type_get_type(type_pointer_get_ref_type(ptr)) == TYPE_INTERFACE) - warning_loc_info(&v->loc_info, - "%s: pointer attribute applied to interface " - "pointer type has no effect\n", v->name); + warning_at( &v->where, "%s: pointer attribute applied to interface pointer type has no effect\n", v->name ); if (!ptr_attr && top) { /* FIXME: this is a horrible hack to cope with the issue that we @@ -1972,7 +1970,7 @@ var_t *make_var(char *name) init_declspec(&v->declspec, NULL); v->attrs = NULL; v->eval = NULL; - init_loc_info(&v->loc_info); + init_location( &v->where ); v->declonly = FALSE; return v; } @@ -1984,7 +1982,7 @@ static var_t *copy_var(var_t *src, char *name, map_attrs_filter_t attr_filter) v->declspec = src->declspec; v->attrs = map_attrs(src->attrs, attr_filter); v->eval = src->eval; - v->loc_info = src->loc_info; + v->where = src->where; return v; }
@@ -2195,10 +2193,9 @@ static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, at * FIXME: We may consider string separated type tables for each input * for cleaner solution. */ - if (cur && input_name == cur->loc_info.input_name) - error_loc("%s: redefinition error; original definition was at %s:%d\n", - cur->name, cur->loc_info.input_name, - cur->loc_info.line_number); + if (cur && input_name == cur->where.input_name) + error_loc( "%s: redefinition error; original definition was at %s:%d\n", + cur->name, cur->where.input_name, cur->where.line_number );
name = declare_var(attrs, decl_spec, decl, 0); cur = type_new_alias(&name->declspec, name->name); @@ -2486,7 +2483,7 @@ attr_list_t *append_attr(attr_list_t *list, attr_t *attr) LIST_FOR_EACH_ENTRY(attr_existing, list, attr_t, entry) if (attr_existing->type == attr->type) { - parser_warning("duplicate attribute %s\n", get_attr_display_name(attr->type)); + warning_loc( "duplicate attribute %s\n", get_attr_display_name(attr->type) ); /* use the last attribute, like MIDL does */ list_remove(&attr_existing->entry); break; @@ -2779,8 +2776,7 @@ static void check_conformance_expr_list(const char *attr_name, const var_t *arg, { const type_t *expr_type = expr_resolve_type(&expr_loc, container_type, dim); if (!is_allowed_conf_type(expr_type)) - error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n", - attr_name); + error_at( &arg->where, "expression must resolve to integral type <= 32bits for attribute %s\n", attr_name ); } } } @@ -2822,9 +2818,7 @@ static void check_field_common(const type_t *container_type,
if (is_attr(arg->attrs, ATTR_LENGTHIS) && (is_attr(arg->attrs, ATTR_STRING) || is_aliaschain_attr(arg->declspec.type, ATTR_STRING))) - error_loc_info(&arg->loc_info, - "string and length_is specified for argument %s are mutually exclusive attributes\n", - arg->name); + error_at( &arg->where, "string and length_is specified for argument %s are mutually exclusive attributes\n", arg->name );
if (is_attr(arg->attrs, ATTR_SIZEIS)) { @@ -2847,7 +2841,7 @@ static void check_field_common(const type_t *container_type, expr_loc.attr = "iid_is"; expr_type = expr_resolve_type(&expr_loc, container_type, expr); if (!expr_type || !is_ptr_guid_type(expr_type)) - error_loc_info(&arg->loc_info, "expression must resolve to pointer to GUID type for attribute iid_is\n"); + error_at( &arg->where, "expression must resolve to pointer to GUID type for attribute iid_is\n" ); } } if (is_attr(arg->attrs, ATTR_SWITCHIS)) @@ -2861,8 +2855,7 @@ static void check_field_common(const type_t *container_type, expr_loc.attr = "switch_is"; expr_type = expr_resolve_type(&expr_loc, container_type, expr); if (!expr_type || !is_allowed_conf_type(expr_type)) - error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n", - expr_loc.attr); + error_at( &arg->where, "expression must resolve to integral type <= 32bits for attribute %s\n", expr_loc.attr ); } }
@@ -2902,17 +2895,14 @@ static void check_field_common(const type_t *container_type, default: break; } - error_loc_info(&arg->loc_info, "%s '%s' of %s '%s' %s\n", - var_type, arg->name, container_type_name, container_name, reason); + error_at( &arg->where, "%s '%s' of %s '%s' %s\n", var_type, arg->name, container_type_name, container_name, reason ); break; } case TGT_CTXT_HANDLE: case TGT_CTXT_HANDLE_POINTER: if (type_get_type(container_type) != TYPE_FUNCTION) - error_loc_info(&arg->loc_info, - "%s '%s' of %s '%s' cannot be a context handle\n", - var_type, arg->name, container_type_name, - container_name); + error_at( &arg->where, "%s '%s' of %s '%s' cannot be a context handle\n", + var_type, arg->name, container_type_name, container_name ); break; case TGT_STRING: { @@ -2920,7 +2910,7 @@ static void check_field_common(const type_t *container_type, while (is_ptr(t)) t = type_pointer_get_ref_type(t); if (is_aliaschain_attr(t, ATTR_RANGE)) - warning_loc_info(&arg->loc_info, "%s: range not verified for a string of ranged types\n", arg->name); + warning_at( &arg->where, "%s: range not verified for a string of ranged types\n", arg->name ); break; } case TGT_POINTER: @@ -2934,9 +2924,7 @@ static void check_field_common(const type_t *container_type, case TGT_ENUM: type = type_get_real_type(type); if (!type_is_complete(type)) - { - error_loc_info(&arg->loc_info, "undefined type declaration "enum %s"\n", type->name); - } + error_at( &arg->where, "undefined type declaration "enum %s"\n", type->name ); case TGT_USER_TYPE: case TGT_IFACE_POINTER: case TGT_BASIC: @@ -2964,14 +2952,14 @@ static void check_remoting_fields(const var_t *var, type_t *type) if (type_is_complete(type)) fields = type_struct_get_fields(type); else - error_loc_info(&var->loc_info, "undefined type declaration "struct %s"\n", type->name); + error_at( &var->where, "undefined type declaration "struct %s"\n", type->name ); } else if (type_get_type(type) == TYPE_UNION || type_get_type(type) == TYPE_ENCAPSULATED_UNION) { if (type_is_complete(type)) fields = type_union_get_cases(type); else - error_loc_info(&var->loc_info, "undefined type declaration "union %s"\n", type->name); + error_at( &var->where, "undefined type declaration "union %s"\n", type->name ); }
if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry ) @@ -3003,10 +2991,10 @@ static void check_remoting_args(const var_t *func) case TGT_UNION: case TGT_CTXT_HANDLE: case TGT_USER_TYPE: - error_loc_info(&arg->loc_info, "out parameter '%s' of function '%s' is not a pointer\n", arg->name, funcname); + error_at( &arg->where, "out parameter '%s' of function '%s' is not a pointer\n", arg->name, funcname ); break; case TGT_IFACE_POINTER: - error_loc_info(&arg->loc_info, "out interface pointer '%s' of function '%s' is not a double pointer\n", arg->name, funcname); + error_at( &arg->where, "out interface pointer '%s' of function '%s' is not a double pointer\n", arg->name, funcname ); break; case TGT_STRING: if (is_array(type)) @@ -3017,7 +3005,7 @@ static void check_remoting_args(const var_t *func) if (!type_array_has_conformance(type) && type_array_get_dim(type)) break; } if (is_attr( arg->attrs, ATTR_IN )) break; - error_loc_info(&arg->loc_info, "out parameter '%s' of function '%s' cannot be an unsized string\n", arg->name, funcname); + error_at( &arg->where, "out parameter '%s' of function '%s' cannot be an unsized string\n", arg->name, funcname ); break; case TGT_INVALID: /* already error'd before we get here */ @@ -3080,7 +3068,7 @@ static void check_functions(const type_t *iface, int is_inside_library) if (is_attr(func->attrs, ATTR_PROPGET) != is_attr(func_iter->attrs, ATTR_PROPGET)) continue; if (is_attr(func->attrs, ATTR_PROPPUT) != is_attr(func_iter->attrs, ATTR_PROPPUT)) continue; if (is_attr(func->attrs, ATTR_PROPPUTREF) != is_attr(func_iter->attrs, ATTR_PROPPUTREF)) continue; - error_loc_info(&func->loc_info, "duplicated function '%s'\n", func->name); + error_at( &func->where, "duplicated function '%s'\n", func->name ); } } } @@ -3401,11 +3389,11 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s return list; }
-void init_loc_info(loc_info_t *i) +void init_location( struct location *where ) { - i->input_name = input_name ? input_name : "stdin"; - i->line_number = line_number; - i->near_text = parser_text; + where->input_name = input_name ? input_name : "stdin"; + where->line_number = line_number; + where->near_text = parser_text; }
type_t *find_parameterized_type(type_t *type, typeref_list_t *params) diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c index 87ab7d2134c..5f953958532 100644 --- a/tools/widl/typetree.c +++ b/tools/widl/typetree.c @@ -65,7 +65,7 @@ type_t *make_type(enum type_type type) t->tfswrite = FALSE; t->checked = FALSE; t->typelib_idx = -1; - init_loc_info(&t->loc_info); + init_location( &t->where ); return t; }
@@ -172,8 +172,8 @@ static size_t append_type_signature(char **buf, size_t *len, size_t pos, type_t else if (type->signature) n += strappend(buf, len, pos + n, "%s", type->signature); else { - if (!(uuid = get_attrp(type->attrs, ATTR_UUID))) - error_loc_info(&type->loc_info, "cannot compute type signature, no uuid found for type %s.\n", type->name); + if (!(uuid = get_attrp( type->attrs, ATTR_UUID ))) + error_at( &type->where, "cannot compute type signature, no uuid found for type %s.\n", type->name );
n += strappend(buf, len, pos + n, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", uuid->Data1, uuid->Data2, uuid->Data3, @@ -241,7 +241,8 @@ static size_t append_type_signature(char **buf, size_t *len, size_t pos, type_t case TYPE_BASIC_WCHAR: case TYPE_BASIC_ERROR_STATUS_T: case TYPE_BASIC_HANDLE: - error_loc_info(&type->loc_info, "unimplemented type signature for basic type %d.\n", type_basic_get_type(type)); + error_at( &type->where, "unimplemented type signature for basic type %d.\n", + type_basic_get_type( type ) ); break; } case TYPE_ENUM: @@ -260,7 +261,8 @@ static size_t append_type_signature(char **buf, size_t *len, size_t pos, type_t case TYPE_BITFIELD: case TYPE_MODULE: case TYPE_APICONTRACT: - error_loc_info(&type->loc_info, "unimplemented type signature for type %s of type %d.\n", type->name, type->type_type); + error_at( &type->where, "unimplemented type signature for type %s of type %d.\n", + type->name, type->type_type ); break; case TYPE_PARAMETERIZED_TYPE: case TYPE_PARAMETER: @@ -346,8 +348,8 @@ static char *format_parameterized_type_signature(type_t *type, typeref_list_t *p typeref_t *ref; const struct uuid *uuid;
- if (!(uuid = get_attrp(type->attrs, ATTR_UUID))) - error_loc_info(&type->loc_info, "cannot compute type signature, no uuid found for type %s.\n", type->name); + if (!(uuid = get_attrp( type->attrs, ATTR_UUID ))) + error_at( &type->where, "cannot compute type signature, no uuid found for type %s.\n", type->name );
pos += strappend(&buf, &len, pos, "pinterface({%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", uuid->Data1, uuid->Data2, uuid->Data3, @@ -476,7 +478,7 @@ type_t *type_new_alias(const decl_spec_t *t, const char *name) a->name = xstrdup(name); a->attrs = NULL; a->details.alias.aliasee = *t; - init_loc_info(&a->loc_info); + init_location( &a->where );
return a; } @@ -722,17 +724,17 @@ static unsigned int compute_method_indexes(type_t *iface) type_t *type_interface_declare(char *name, struct namespace *namespace) { type_t *type = get_type(TYPE_INTERFACE, name, namespace, 0); - if (type_get_type_detect_alias(type) != TYPE_INTERFACE) - error_loc("interface %s previously not declared an interface at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + if (type_get_type_detect_alias( type ) != TYPE_INTERFACE) + error_loc( "interface %s previously not declared an interface at %s:%d\n", type->name, + type->where.input_name, type->where.line_number ); return type; }
type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit, statement_list_t *stmts, typeref_list_t *requires) { if (iface->defined) - error_loc("interface %s already defined at %s:%d\n", - iface->name, iface->loc_info.input_name, iface->loc_info.line_number); + error_loc( "interface %s already defined at %s:%d\n", iface->name, + iface->where.input_name, iface->where.line_number ); if (iface == inherit) error_loc("interface %s can't inherit from itself\n", iface->name); @@ -753,17 +755,17 @@ type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit type_t *type_dispinterface_declare(char *name) { type_t *type = get_type(TYPE_INTERFACE, name, NULL, 0); - if (type_get_type_detect_alias(type) != TYPE_INTERFACE) - error_loc("dispinterface %s previously not declared a dispinterface at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + if (type_get_type_detect_alias( type ) != TYPE_INTERFACE) + error_loc( "dispinterface %s previously not declared a dispinterface at %s:%d\n", + type->name, type->where.input_name, type->where.line_number ); return type; }
type_t *type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t *props, var_list_t *methods) { if (iface->defined) - error_loc("dispinterface %s already defined at %s:%d\n", - iface->name, iface->loc_info.input_name, iface->loc_info.line_number); + error_loc( "dispinterface %s already defined at %s:%d\n", iface->name, + iface->where.input_name, iface->where.line_number ); iface->attrs = check_dispiface_attrs(iface->name, attrs); iface->details.iface = xmalloc(sizeof(*iface->details.iface)); iface->details.iface->disp_props = props; @@ -782,8 +784,8 @@ type_t *type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *attrs, type_t *iface) { if (dispiface->defined) - error_loc("dispinterface %s already defined at %s:%d\n", - dispiface->name, dispiface->loc_info.input_name, dispiface->loc_info.line_number); + error_loc( "dispinterface %s already defined at %s:%d\n", dispiface->name, + dispiface->where.input_name, dispiface->where.line_number ); dispiface->attrs = check_dispiface_attrs(dispiface->name, attrs); dispiface->details.iface = xmalloc(sizeof(*dispiface->details.iface)); dispiface->details.iface->disp_props = NULL; @@ -802,17 +804,17 @@ type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *att type_t *type_module_declare(char *name) { type_t *type = get_type(TYPE_MODULE, name, NULL, 0); - if (type_get_type_detect_alias(type) != TYPE_MODULE) - error_loc("module %s previously not declared a module at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + if (type_get_type_detect_alias( type ) != TYPE_MODULE) + error_loc( "module %s previously not declared a module at %s:%d\n", type->name, + type->where.input_name, type->where.line_number ); return type; }
type_t *type_module_define(type_t* module, attr_list_t *attrs, statement_list_t *stmts) { if (module->defined) - error_loc("module %s already defined at %s:%d\n", - module->name, module->loc_info.input_name, module->loc_info.line_number); + error_loc( "module %s already defined at %s:%d\n", module->name, + module->where.input_name, module->where.line_number ); module->attrs = check_module_attrs(module->name, attrs); module->details.module = xmalloc(sizeof(*module->details.module)); module->details.module->stmts = stmts; @@ -823,17 +825,17 @@ type_t *type_module_define(type_t* module, attr_list_t *attrs, statement_list_t 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); + 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->where.input_name, type->where.line_number ); return type; }
type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, typeref_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); + error_loc( "coclass %s already defined at %s:%d\n", coclass->name, + coclass->where.input_name, coclass->where.line_number ); coclass->attrs = check_coclass_attrs(coclass->name, attrs); coclass->details.coclass.ifaces = ifaces; coclass->defined = TRUE; @@ -843,9 +845,9 @@ type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, typeref_list_t type_t *type_runtimeclass_declare(char *name, struct namespace *namespace) { type_t *type = get_type(TYPE_RUNTIMECLASS, name, namespace, 0); - if (type_get_type_detect_alias(type) != TYPE_RUNTIMECLASS) - error_loc("runtimeclass %s previously not declared a runtimeclass at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + if (type_get_type_detect_alias( type ) != TYPE_RUNTIMECLASS) + error_loc( "runtimeclass %s previously not declared a runtimeclass at %s:%d\n", type->name, + type->where.input_name, type->where.line_number ); return type; }
@@ -855,8 +857,8 @@ type_t *type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, typer typeref_list_t *requires;
if (runtimeclass->defined) - error_loc("runtimeclass %s already defined at %s:%d\n", - runtimeclass->name, runtimeclass->loc_info.input_name, runtimeclass->loc_info.line_number); + error_loc( "runtimeclass %s already defined at %s:%d\n", runtimeclass->name, + runtimeclass->where.input_name, runtimeclass->where.line_number ); runtimeclass->attrs = check_runtimeclass_attrs(runtimeclass->name, attrs); runtimeclass->details.runtimeclass.ifaces = ifaces; runtimeclass->defined = TRUE; @@ -891,17 +893,17 @@ type_t *type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, typer type_t *type_apicontract_declare(char *name, struct namespace *namespace) { type_t *type = get_type(TYPE_APICONTRACT, name, namespace, 0); - if (type_get_type_detect_alias(type) != TYPE_APICONTRACT) - error_loc("apicontract %s previously not declared a apicontract at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + if (type_get_type_detect_alias( type ) != TYPE_APICONTRACT) + error_loc( "apicontract %s previously not declared a apicontract at %s:%d\n", type->name, + type->where.input_name, type->where.line_number ); return type; }
type_t *type_apicontract_define(type_t *apicontract, attr_list_t *attrs) { if (apicontract->defined) - error_loc("apicontract %s already defined at %s:%d\n", - apicontract->name, apicontract->loc_info.input_name, apicontract->loc_info.line_number); + error_loc( "apicontract %s already defined at %s:%d\n", apicontract->name, + apicontract->where.input_name, apicontract->where.line_number ); apicontract->attrs = check_apicontract_attrs(apicontract->name, attrs); apicontract->defined = TRUE; return apicontract; @@ -922,9 +924,9 @@ static void compute_delegate_iface_names(type_t *delegate, type_t *type, typeref type_t *type_delegate_declare(char *name, struct namespace *namespace) { type_t *type = get_type(TYPE_DELEGATE, name, namespace, 0); - if (type_get_type_detect_alias(type) != TYPE_DELEGATE) - error_loc("delegate %s previously not declared a delegate at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + if (type_get_type_detect_alias( type ) != TYPE_DELEGATE) + error_loc( "delegate %s previously not declared a delegate at %s:%d\n", type->name, + type->where.input_name, type->where.line_number ); return type; }
@@ -933,8 +935,8 @@ type_t *type_delegate_define(type_t *delegate, attr_list_t *attrs, statement_lis type_t *iface;
if (delegate->defined) - error_loc("delegate %s already defined at %s:%d\n", - delegate->name, delegate->loc_info.input_name, delegate->loc_info.line_number); + error_loc( "delegate %s already defined at %s:%d\n", delegate->name, + delegate->where.input_name, delegate->where.line_number );
delegate->attrs = check_interface_attrs(delegate->name, attrs);
@@ -962,9 +964,9 @@ type_t *type_delegate_define(type_t *delegate, attr_list_t *attrs, statement_lis type_t *type_parameterized_interface_declare(char *name, struct namespace *namespace, typeref_list_t *params) { type_t *type = get_type(TYPE_PARAMETERIZED_TYPE, name, namespace, 0); - if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE) - error_loc("pinterface %s previously not declared a pinterface at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + if (type_get_type_detect_alias( type ) != TYPE_PARAMETERIZED_TYPE) + error_loc( "pinterface %s previously not declared a pinterface at %s:%d\n", type->name, + type->where.input_name, type->where.line_number ); type->details.parameterized.type = make_type(TYPE_INTERFACE); type->details.parameterized.params = params; return type; @@ -974,8 +976,8 @@ type_t *type_parameterized_interface_define(type_t *type, attr_list_t *attrs, ty { type_t *iface; if (type->defined) - error_loc("pinterface %s already defined at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + error_loc( "pinterface %s already defined at %s:%d\n", type->name, + type->where.input_name, type->where.line_number );
/* The parameterized type UUID is actually a PIID that is then used as a seed to generate * a new type GUID with the rules described in: @@ -1003,9 +1005,9 @@ type_t *type_parameterized_interface_define(type_t *type, attr_list_t *attrs, ty type_t *type_parameterized_delegate_declare(char *name, struct namespace *namespace, typeref_list_t *params) { type_t *type = get_type(TYPE_PARAMETERIZED_TYPE, name, namespace, 0); - if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE) - error_loc("pdelegate %s previously not declared a pdelegate at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + if (type_get_type_detect_alias( type ) != TYPE_PARAMETERIZED_TYPE) + error_loc( "pdelegate %s previously not declared a pdelegate at %s:%d\n", type->name, + type->where.input_name, type->where.line_number ); type->details.parameterized.type = make_type(TYPE_DELEGATE); type->details.parameterized.params = params; return type; @@ -1016,8 +1018,8 @@ type_t *type_parameterized_delegate_define(type_t *type, attr_list_t *attrs, sta type_t *iface, *delegate;
if (type->defined) - error_loc("pdelegate %s already defined at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + error_loc( "pdelegate %s already defined at %s:%d\n", type->name, + type->where.input_name, type->where.line_number );
type->attrs = check_interface_attrs(type->name, attrs);
@@ -1097,7 +1099,8 @@ static var_list_t *replace_type_parameters_in_var_list(var_list_t *var_list, typ return new_var_list; }
-static statement_t *replace_type_parameters_in_statement(statement_t *stmt, typeref_list_t *orig, typeref_list_t *repl, loc_info_t *loc) +static statement_t *replace_type_parameters_in_statement( statement_t *stmt, typeref_list_t *orig, + typeref_list_t *repl, struct location *where ) { statement_t *new_stmt = xmalloc(sizeof(*new_stmt)); *new_stmt = *stmt; @@ -1121,14 +1124,15 @@ static statement_t *replace_type_parameters_in_statement(statement_t *stmt, type case STMT_IMPORTLIB: case STMT_PRAGMA: case STMT_CPPQUOTE: - error_loc_info(loc, "unimplemented parameterized type replacement for statement type %d.\n", stmt->type); + error_at( where, "unimplemented parameterized type replacement for statement type %d.\n", stmt->type ); break; }
return new_stmt; }
-static statement_list_t *replace_type_parameters_in_statement_list(statement_list_t *stmt_list, typeref_list_t *orig, typeref_list_t *repl, loc_info_t *loc) +static statement_list_t *replace_type_parameters_in_statement_list( statement_list_t *stmt_list, typeref_list_t *orig, + typeref_list_t *repl, struct location *where ) { statement_list_t *new_stmt_list; statement_t *stmt, *new_stmt; @@ -1140,7 +1144,7 @@ static statement_list_t *replace_type_parameters_in_statement_list(statement_lis
LIST_FOR_EACH_ENTRY(stmt, stmt_list, statement_t, entry) { - new_stmt = replace_type_parameters_in_statement(stmt, orig, repl, loc); + new_stmt = replace_type_parameters_in_statement( stmt, orig, repl, where ); list_add_tail(new_stmt_list, &new_stmt->entry); }
@@ -1205,7 +1209,8 @@ static type_t *replace_type_parameters_in_type(type_t *type, typeref_list_t *ori case TYPE_MODULE: case TYPE_COCLASS: case TYPE_APICONTRACT: - error_loc_info(&type->loc_info, "unimplemented parameterized type replacement for type %s of type %d.\n", type->name, type->type_type); + error_at( &type->where, "unimplemented parameterized type replacement for type %s of type %d.\n", + type->name, type->type_type ); break; }
@@ -1217,7 +1222,8 @@ static void type_parameterized_interface_specialize(type_t *tmpl, type_t *iface, iface->details.iface = xmalloc(sizeof(*iface->details.iface)); iface->details.iface->disp_methods = NULL; iface->details.iface->disp_props = NULL; - iface->details.iface->stmts = replace_type_parameters_in_statement_list(tmpl->details.iface->stmts, orig, repl, &tmpl->loc_info); + iface->details.iface->stmts = replace_type_parameters_in_statement_list( tmpl->details.iface->stmts, + orig, repl, &tmpl->where ); iface->details.iface->inherit = replace_type_parameters_in_type(tmpl->details.iface->inherit, orig, repl); iface->details.iface->disp_inherit = NULL; iface->details.iface->async_iface = NULL; @@ -1298,8 +1304,8 @@ type_t *type_parameterized_type_specialize_define(type_t *type)
if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE || type_get_type_detect_alias(tmpl) != TYPE_PARAMETERIZED_TYPE) - error_loc("cannot define non-parameterized type %s, declared at %s:%d\n", - type->name, type->loc_info.input_name, type->loc_info.line_number); + error_loc( "cannot define non-parameterized type %s, declared at %s:%d\n", type->name, + type->where.input_name, type->where.line_number );
if (type_get_type_detect_alias(tmpl->details.parameterized.type) == TYPE_INTERFACE && type_get_type_detect_alias(iface) == TYPE_INTERFACE) @@ -1309,7 +1315,7 @@ type_t *type_parameterized_type_specialize_define(type_t *type) type_parameterized_delegate_specialize(tmpl->details.parameterized.type, iface, orig, repl); else error_loc("pinterface/pdelegate %s previously not declared a pinterface/pdelegate at %s:%d\n", - iface->name, iface->loc_info.input_name, iface->loc_info.line_number); + iface->name, iface->where.input_name, iface->where.line_number);
iface->impl_name = format_parameterized_type_impl_name(type, repl, ""); iface->signature = format_parameterized_type_signature(type, repl); diff --git a/tools/widl/typetree.h b/tools/widl/typetree.h index be2288db021..7cb7f521167 100644 --- a/tools/widl/typetree.h +++ b/tools/widl/typetree.h @@ -392,7 +392,7 @@ static inline type_t *type_runtimeclass_get_default_iface(const type_t *type, in return ref->type;
if (!check) return NULL; - error_loc_info(&type->loc_info, "runtimeclass %s needs a default interface\n", type->name); + error_at( &type->where, "runtimeclass %s needs a default interface\n", type->name ); }
static inline type_t *type_delegate_get_iface(const type_t *type) diff --git a/tools/widl/utils.c b/tools/widl/utils.c index aad40f6b087..0c514632489 100644 --- a/tools/widl/utils.c +++ b/tools/widl/utils.c @@ -46,58 +46,39 @@ static void make_print(char *str) } }
-static void generic_msg(const loc_info_t *loc_info, const char *s, const char *t, va_list ap) +static void generic_msg( const struct location *where, const char *s, const char *t, va_list ap ) { - fprintf(stderr, "%s:%d: %s: ", loc_info->input_name, loc_info->line_number, t); - vfprintf(stderr, s, ap); + fprintf( stderr, "%s:%d: %s: ", where->input_name, where->line_number, t ); + vfprintf( stderr, s, ap );
- if (want_near_indication) - { - char *cpy; - if(loc_info->near_text) - { - cpy = xstrdup(loc_info->near_text); - make_print(cpy); - fprintf(stderr, " near '%s'", cpy); - free(cpy); - } + if (want_near_indication) + { + char *cpy; + if (where->near_text) + { + cpy = xstrdup( where->near_text ); + make_print( cpy ); + fprintf( stderr, " near '%s'", cpy ); + free( cpy ); + } } }
-void error_loc(const char *s, ...) -{ - loc_info_t cur_loc = CURRENT_LOCATION; - va_list ap; - va_start(ap, s); - generic_msg(&cur_loc, s, "error", ap); - va_end(ap); - exit(1); -} - /* yyerror: yacc assumes this is not newline terminated. */ void parser_error(const char *s) { error_loc("%s\n", s); }
-void error_loc_info(const loc_info_t *loc_info, const char *s, ...) +void error_at( const struct location *where, const char *s, ... ) { - va_list ap; - va_start(ap, s); - generic_msg(loc_info, s, "error", ap); - va_end(ap); - exit(1); -} - -int parser_warning(const char *s, ...) -{ - loc_info_t cur_loc = CURRENT_LOCATION; - va_list ap; - va_start(ap, s); - generic_msg(&cur_loc, s, "warning", ap); - va_end(ap); - return 0; + struct location cur_loc = CURRENT_LOCATION; + va_list ap; + va_start( ap, s ); + generic_msg( where ? where : &cur_loc, s, "error", ap ); + va_end( ap ); + exit( 1 ); }
void error(const char *s, ...) @@ -119,12 +100,13 @@ void warning(const char *s, ...) va_end(ap); }
-void warning_loc_info(const loc_info_t *loc_info, const char *s, ...) +void warning_at( const struct location *where, const char *s, ... ) { - va_list ap; - va_start(ap, s); - generic_msg(loc_info, s, "warning", ap); - va_end(ap); + struct location cur_loc = CURRENT_LOCATION; + va_list ap; + va_start( ap, s ); + generic_msg( where ? where : &cur_loc, s, "warning", ap ); + va_end( ap ); }
void chat(const char *s, ...) diff --git a/tools/widl/utils.h b/tools/widl/utils.h index 2a994e9697d..0196dce95fd 100644 --- a/tools/widl/utils.h +++ b/tools/widl/utils.h @@ -24,12 +24,12 @@ #include "widltypes.h"
void parser_error(const char *s) __attribute__((noreturn)); -int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); -void error_loc(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn)); void error(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn)); -void error_loc_info(const loc_info_t *, const char *s, ...) __attribute__((format (printf, 2, 3))) __attribute__((noreturn)); +void error_at( const struct location *, const char *s, ... ) __attribute__((format( printf, 2, 3 ))) __attribute__((noreturn)); +#define error_loc( ... ) error_at( NULL, ## __VA_ARGS__ ) void warning(const char *s, ...) __attribute__((format (printf, 1, 2))); -void warning_loc_info(const loc_info_t *, const char *s, ...) __attribute__((format (printf, 2, 3))); +void warning_at( const struct location *, const char *s, ... ) __attribute__((format( printf, 2, 3 ))); +#define warning_loc( ... ) warning_at( NULL, ## __VA_ARGS__ ) void chat(const char *s, ...) __attribute__((format (printf, 1, 2))); size_t strappend(char **buf, size_t *len, size_t pos, const char* fmt, ...) __attribute__((__format__ (__printf__, 4, 5 )));
diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 0d88e713433..3e1994841a5 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -37,7 +37,6 @@ struct uuid #define TRUE 1 #define FALSE 0
-typedef struct _loc_info_t loc_info_t; typedef struct _attr_t attr_t; typedef struct _attr_custdata_t attr_custdata_t; typedef struct _expr_t expr_t; @@ -311,7 +310,7 @@ enum type_basic_type #define TYPE_BASIC_INT_MIN TYPE_BASIC_INT8 #define TYPE_BASIC_INT_MAX TYPE_BASIC_HYPER
-struct _loc_info_t +struct location { const char *input_name; int line_number; @@ -513,7 +512,7 @@ struct _type_t { unsigned int typestring_offset; unsigned int ptrdesc; /* used for complex structs */ int typelib_idx; - loc_info_t loc_info; + struct location where; unsigned int ignore : 1; unsigned int defined : 1; unsigned int written : 1; @@ -533,7 +532,7 @@ struct _var_t { /* fields specific to functions */ unsigned int procstring_offset, func_idx;
- struct _loc_info_t loc_info; + struct location where;
unsigned int declonly : 1;
@@ -654,7 +653,7 @@ type_t *reg_type(type_t *type, const char *name, struct namespace *namespace, in 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 *); +void init_location( struct location * );
char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix, const char *abi_prefix);
From: Rémi Bernon rbernon@codeweavers.com
--- tools/widl/parser.y | 5 +++-- tools/widl/typetree.c | 42 +++++++++++++++++++++--------------------- tools/widl/utils.c | 4 ++-- tools/widl/widltypes.h | 5 ++++- 4 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/tools/widl/parser.y b/tools/widl/parser.y index b18e24b1b01..5b45c000163 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -2195,7 +2195,7 @@ static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, at */ if (cur && input_name == cur->where.input_name) error_loc( "%s: redefinition error; original definition was at %s:%d\n", - cur->name, cur->where.input_name, cur->where.line_number ); + cur->name, cur->where.input_name, cur->where.first_line );
name = declare_var(attrs, decl_spec, decl, 0); cur = type_new_alias(&name->declspec, name->name); @@ -3392,8 +3392,9 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s void init_location( struct location *where ) { where->input_name = input_name ? input_name : "stdin"; - where->line_number = line_number; where->near_text = parser_text; + where->first_line = line_number; + where->last_line = line_number; }
type_t *find_parameterized_type(type_t *type, typeref_list_t *params) diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c index 5f953958532..8d4837b7943 100644 --- a/tools/widl/typetree.c +++ b/tools/widl/typetree.c @@ -726,7 +726,7 @@ type_t *type_interface_declare(char *name, struct namespace *namespace) type_t *type = get_type(TYPE_INTERFACE, name, namespace, 0); if (type_get_type_detect_alias( type ) != TYPE_INTERFACE) error_loc( "interface %s previously not declared an interface at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line ); return type; }
@@ -734,7 +734,7 @@ type_t *type_interface_define(type_t *iface, attr_list_t *attrs, type_t *inherit { if (iface->defined) error_loc( "interface %s already defined at %s:%d\n", iface->name, - iface->where.input_name, iface->where.line_number ); + iface->where.input_name, iface->where.first_line ); if (iface == inherit) error_loc("interface %s can't inherit from itself\n", iface->name); @@ -757,7 +757,7 @@ type_t *type_dispinterface_declare(char *name) type_t *type = get_type(TYPE_INTERFACE, name, NULL, 0); if (type_get_type_detect_alias( type ) != TYPE_INTERFACE) error_loc( "dispinterface %s previously not declared a dispinterface at %s:%d\n", - type->name, type->where.input_name, type->where.line_number ); + type->name, type->where.input_name, type->where.first_line ); return type; }
@@ -765,7 +765,7 @@ type_t *type_dispinterface_define(type_t *iface, attr_list_t *attrs, var_list_t { if (iface->defined) error_loc( "dispinterface %s already defined at %s:%d\n", iface->name, - iface->where.input_name, iface->where.line_number ); + iface->where.input_name, iface->where.first_line ); iface->attrs = check_dispiface_attrs(iface->name, attrs); iface->details.iface = xmalloc(sizeof(*iface->details.iface)); iface->details.iface->disp_props = props; @@ -785,7 +785,7 @@ type_t *type_dispinterface_define_from_iface(type_t *dispiface, attr_list_t *att { if (dispiface->defined) error_loc( "dispinterface %s already defined at %s:%d\n", dispiface->name, - dispiface->where.input_name, dispiface->where.line_number ); + dispiface->where.input_name, dispiface->where.first_line ); dispiface->attrs = check_dispiface_attrs(dispiface->name, attrs); dispiface->details.iface = xmalloc(sizeof(*dispiface->details.iface)); dispiface->details.iface->disp_props = NULL; @@ -806,7 +806,7 @@ type_t *type_module_declare(char *name) type_t *type = get_type(TYPE_MODULE, name, NULL, 0); if (type_get_type_detect_alias( type ) != TYPE_MODULE) error_loc( "module %s previously not declared a module at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line ); return type; }
@@ -814,7 +814,7 @@ type_t *type_module_define(type_t* module, attr_list_t *attrs, statement_list_t { if (module->defined) error_loc( "module %s already defined at %s:%d\n", module->name, - module->where.input_name, module->where.line_number ); + module->where.input_name, module->where.first_line ); module->attrs = check_module_attrs(module->name, attrs); module->details.module = xmalloc(sizeof(*module->details.module)); module->details.module->stmts = stmts; @@ -827,7 +827,7 @@ 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->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line ); return type; }
@@ -835,7 +835,7 @@ type_t *type_coclass_define(type_t *coclass, attr_list_t *attrs, typeref_list_t { if (coclass->defined) error_loc( "coclass %s already defined at %s:%d\n", coclass->name, - coclass->where.input_name, coclass->where.line_number ); + coclass->where.input_name, coclass->where.first_line ); coclass->attrs = check_coclass_attrs(coclass->name, attrs); coclass->details.coclass.ifaces = ifaces; coclass->defined = TRUE; @@ -847,7 +847,7 @@ type_t *type_runtimeclass_declare(char *name, struct namespace *namespace) type_t *type = get_type(TYPE_RUNTIMECLASS, name, namespace, 0); if (type_get_type_detect_alias( type ) != TYPE_RUNTIMECLASS) error_loc( "runtimeclass %s previously not declared a runtimeclass at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line ); return type; }
@@ -858,7 +858,7 @@ type_t *type_runtimeclass_define(type_t *runtimeclass, attr_list_t *attrs, typer
if (runtimeclass->defined) error_loc( "runtimeclass %s already defined at %s:%d\n", runtimeclass->name, - runtimeclass->where.input_name, runtimeclass->where.line_number ); + runtimeclass->where.input_name, runtimeclass->where.first_line ); runtimeclass->attrs = check_runtimeclass_attrs(runtimeclass->name, attrs); runtimeclass->details.runtimeclass.ifaces = ifaces; runtimeclass->defined = TRUE; @@ -895,7 +895,7 @@ type_t *type_apicontract_declare(char *name, struct namespace *namespace) type_t *type = get_type(TYPE_APICONTRACT, name, namespace, 0); if (type_get_type_detect_alias( type ) != TYPE_APICONTRACT) error_loc( "apicontract %s previously not declared a apicontract at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line ); return type; }
@@ -903,7 +903,7 @@ type_t *type_apicontract_define(type_t *apicontract, attr_list_t *attrs) { if (apicontract->defined) error_loc( "apicontract %s already defined at %s:%d\n", apicontract->name, - apicontract->where.input_name, apicontract->where.line_number ); + apicontract->where.input_name, apicontract->where.first_line ); apicontract->attrs = check_apicontract_attrs(apicontract->name, attrs); apicontract->defined = TRUE; return apicontract; @@ -926,7 +926,7 @@ type_t *type_delegate_declare(char *name, struct namespace *namespace) type_t *type = get_type(TYPE_DELEGATE, name, namespace, 0); if (type_get_type_detect_alias( type ) != TYPE_DELEGATE) error_loc( "delegate %s previously not declared a delegate at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line ); return type; }
@@ -936,7 +936,7 @@ type_t *type_delegate_define(type_t *delegate, attr_list_t *attrs, statement_lis
if (delegate->defined) error_loc( "delegate %s already defined at %s:%d\n", delegate->name, - delegate->where.input_name, delegate->where.line_number ); + delegate->where.input_name, delegate->where.first_line );
delegate->attrs = check_interface_attrs(delegate->name, attrs);
@@ -966,7 +966,7 @@ type_t *type_parameterized_interface_declare(char *name, struct namespace *names type_t *type = get_type(TYPE_PARAMETERIZED_TYPE, name, namespace, 0); if (type_get_type_detect_alias( type ) != TYPE_PARAMETERIZED_TYPE) error_loc( "pinterface %s previously not declared a pinterface at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line ); type->details.parameterized.type = make_type(TYPE_INTERFACE); type->details.parameterized.params = params; return type; @@ -977,7 +977,7 @@ type_t *type_parameterized_interface_define(type_t *type, attr_list_t *attrs, ty type_t *iface; if (type->defined) error_loc( "pinterface %s already defined at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line );
/* The parameterized type UUID is actually a PIID that is then used as a seed to generate * a new type GUID with the rules described in: @@ -1007,7 +1007,7 @@ type_t *type_parameterized_delegate_declare(char *name, struct namespace *namesp type_t *type = get_type(TYPE_PARAMETERIZED_TYPE, name, namespace, 0); if (type_get_type_detect_alias( type ) != TYPE_PARAMETERIZED_TYPE) error_loc( "pdelegate %s previously not declared a pdelegate at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line ); type->details.parameterized.type = make_type(TYPE_DELEGATE); type->details.parameterized.params = params; return type; @@ -1019,7 +1019,7 @@ type_t *type_parameterized_delegate_define(type_t *type, attr_list_t *attrs, sta
if (type->defined) error_loc( "pdelegate %s already defined at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line );
type->attrs = check_interface_attrs(type->name, attrs);
@@ -1305,7 +1305,7 @@ type_t *type_parameterized_type_specialize_define(type_t *type) if (type_get_type_detect_alias(type) != TYPE_PARAMETERIZED_TYPE || type_get_type_detect_alias(tmpl) != TYPE_PARAMETERIZED_TYPE) error_loc( "cannot define non-parameterized type %s, declared at %s:%d\n", type->name, - type->where.input_name, type->where.line_number ); + type->where.input_name, type->where.first_line );
if (type_get_type_detect_alias(tmpl->details.parameterized.type) == TYPE_INTERFACE && type_get_type_detect_alias(iface) == TYPE_INTERFACE) @@ -1315,7 +1315,7 @@ type_t *type_parameterized_type_specialize_define(type_t *type) type_parameterized_delegate_specialize(tmpl->details.parameterized.type, iface, orig, repl); else error_loc("pinterface/pdelegate %s previously not declared a pinterface/pdelegate at %s:%d\n", - iface->name, iface->where.input_name, iface->where.line_number); + iface->name, iface->where.input_name, iface->where.first_line);
iface->impl_name = format_parameterized_type_impl_name(type, repl, ""); iface->signature = format_parameterized_type_signature(type, repl); diff --git a/tools/widl/utils.c b/tools/widl/utils.c index 0c514632489..979851e1b44 100644 --- a/tools/widl/utils.c +++ b/tools/widl/utils.c @@ -32,7 +32,7 @@ #include "utils.h" #include "parser.h"
-#define CURRENT_LOCATION { input_name ? input_name : "stdin", line_number, parser_text } +#define CURRENT_LOCATION { input_name ? input_name : "stdin", parser_text, line_number, 0, line_number, 0 }
static const int want_near_indication = 0;
@@ -48,7 +48,7 @@ static void make_print(char *str)
static void generic_msg( const struct location *where, const char *s, const char *t, va_list ap ) { - fprintf( stderr, "%s:%d: %s: ", where->input_name, where->line_number, t ); + fprintf( stderr, "%s:%d: %s: ", where->input_name, where->first_line, t ); vfprintf( stderr, s, ap );
if (want_near_indication) diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 3e1994841a5..4311811f051 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -313,8 +313,11 @@ enum type_basic_type struct location { const char *input_name; - int line_number; const char *near_text; + int first_line; + int last_line; + int first_column; + int last_column; };
struct str_list_entry_t
From: Rémi Bernon rbernon@codeweavers.com
--- tools/widl/parser.h | 8 ++- tools/widl/parser.l | 43 +++++++++++++--- tools/widl/parser.y | 114 ++++++++++++++++++++++++++++++++++++----- tools/widl/typetree.c | 5 +- tools/widl/utils.c | 53 ++++--------------- tools/widl/utils.h | 2 +- tools/widl/widltypes.h | 3 -- 7 files changed, 157 insertions(+), 71 deletions(-)
diff --git a/tools/widl/parser.h b/tools/widl/parser.h index 81418fca160..a59b439a4d3 100644 --- a/tools/widl/parser.h +++ b/tools/widl/parser.h @@ -21,16 +21,20 @@ #ifndef __WIDL_PARSER_H #define __WIDL_PARSER_H
+#include "widltypes.h" + int parser_parse(void);
+extern void parser_warning( const struct location *where, const char *message ); +extern void parser_error( const struct location *where, const char *error ); +extern void init_location( struct location *copy, const struct location *begin, const struct location *end ); + extern FILE *parser_in; extern char *parser_text; extern int parser_debug; extern int yy_flex_debug;
extern int parse_only; -void push_import( char *import_name ); -void pop_import(void);
int is_type(const char *name);
diff --git a/tools/widl/parser.l b/tools/widl/parser.l index 9fc6a10c501..ef1e2dba52c 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -19,6 +19,7 @@ */
%option bison-bridge +%option bison-locations %option stack %option noinput nounput noyy_top_state %option noyywrap @@ -53,11 +54,15 @@ uuid {hd}{8}-{hd}{4}-{hd}{4}-{hd}{4}-{hd}{12}
#define YYerror PARSER_error #define YYSTYPE PARSER_STYPE +#define YYLTYPE PARSER_LTYPE #define YYUNDEF PARSER_UNDEF #define yyerror parser_error
#include "parser.tab.h"
+#define YY_USER_INIT parser_loc_reset( yylloc, input_name ) +#define YY_USER_ACTION parser_loc_update( yylloc, yytext ); + static void switch_to_acf(void);
static warning_list_t *disabled_warnings = NULL; @@ -65,8 +70,8 @@ static warning_list_t *disabled_warnings = NULL; struct import_state { YY_BUFFER_STATE buffer; + YYLTYPE yylloc; char *input_name; - int line_number; struct list entry; }; static struct list import_stack = LIST_INIT( import_stack ); @@ -180,29 +185,35 @@ static void winrt_enable( int ns_prefix ) <PP_PRAGMA>{ midl_echo/"(" { yy_pop_state(); + yylloc->first_line -= 1; return tCPPQUOTE; } winrt{ws}+ns_prefix[^\n]* { yy_pop_state(); + yylloc->first_line -= 1; winrt_enable( TRUE ); } winrt[^\n]* { yy_pop_state(); + yylloc->first_line -= 1; winrt_enable( FALSE ); } [^\n]* { yy_pop_state(); + yylloc->first_line -= 1; return token_str( aPRAGMA, yytext, yylval ); } } <PP_LINE>[0-9]+{ws}* { - line_number = strtoul( yytext, NULL, 10 ) - 1; /* We didn't read the newline */ + yylloc->first_line = strtoul( yytext, NULL, 10 ) - 1; + yylloc->last_line = yylloc->first_line; yy_pop_state(); yy_push_state(PP_FILE); } <PP_FILE>"(\[^n]|[^"\\n])*"{ws}* { input_name = xstrdup( yytext + 1 ); *strchr( input_name, '"' ) = 0; + yylloc->input_name = input_name; } <PP_FILE>[^"][^\n]* { yy_pop_state(); }
@@ -418,7 +429,7 @@ SAFEARRAY{ws}*/( return tSAFEARRAY; "(\.|[^"\])*" { return token_str( aSTRING, yytext, yylval ); } '(\.|[^'\])*' { return token_str( aSQSTRING, yytext, yylval ); }
- \n { line_number++; } + \n { parser_loc_eol( yylloc ); } {ws} {} << { return SHL; } >> { return SHR; } @@ -445,7 +456,23 @@ SAFEARRAY{ws}*/( return tSAFEARRAY; } %%
-void pop_import(void) +void print_imports(void) +{ + struct import_state *state, *next; + + if (list_empty( &import_stack )) return; + + fprintf( stderr, "In file included from " ); + LIST_FOR_EACH_ENTRY_SAFE_REV( state, next, &import_stack, struct import_state, entry ) + { + if (&next->entry == &import_stack) break; + fprintf( stderr, "%s:%d,\n", state->input_name, state->yylloc.first_line ); + fprintf( stderr, " from "); + } + fprintf( stderr, "%s:%d:\n", state->input_name, state->yylloc.first_line ); +} + +void pop_import( YYLTYPE *yylloc ) { struct list *entry = list_head( &import_stack ); struct import_state *state; @@ -460,11 +487,11 @@ void pop_import(void) yy_switch_to_buffer( state->buffer );
input_name = state->input_name; - line_number = state->line_number; + *yylloc = state->yylloc; free( state ); }
-void push_import( char *import_name ) +void push_import( const char *import_name, YYLTYPE *yylloc ) { struct import_state *state; struct import *import; @@ -476,7 +503,7 @@ void push_import( char *import_name )
state->buffer = YY_CURRENT_BUFFER; state->input_name = input_name; - state->line_number = line_number; + state->yylloc = *yylloc; input_name = NULL;
/* reset buffer for <<EOF>>, in case import fails or already imported */ @@ -491,8 +518,8 @@ void push_import( char *import_name )
input_name = find_input_file( import_name, state->input_name ); file = open_input_file( input_name ); - line_number = 1;
+ parser_loc_reset( yylloc, input_name ); yy_switch_to_buffer( yy_create_buffer( file, YY_BUF_SIZE ) ); }
diff --git a/tools/widl/parser.y b/tools/widl/parser.y index 5b45c000163..650c39ec3d0 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -124,13 +124,111 @@ static typelib_t *current_typelib; %code provides {
-int parser_lex( PARSER_STYPE *yylval ); +int parser_lex( PARSER_STYPE *yylval, PARSER_LTYPE *yylloc );
+void print_imports(void); +void push_import( const char *fname, PARSER_LTYPE *yylloc ); +void pop_import( PARSER_LTYPE *yylloc ); + +void parser_loc_reset( PARSER_LTYPE *yylloc, const char *input_name ); +void parser_loc_eol( PARSER_LTYPE *yylloc ); +void parser_loc_update( PARSER_LTYPE *yylloc, const char *yytext ); + +# define YYLLOC_DEFAULT( cur, rhs, n ) \ + do { if (n) init_location( &(cur), &YYRHSLOC( rhs, 1 ), &YYRHSLOC( rhs, n ) ); \ + else init_location( &(cur), &YYRHSLOC( rhs, 0 ), NULL ); } while(0) + +} + +%code +{ + +static YYLTYPE parser_prev_loc; + +void parser_loc_reset( YYLTYPE *yylloc, const char *input_name ) +{ + yylloc->first_line = 1; + yylloc->last_line = 1; + yylloc->first_column = 1; + yylloc->last_column = 1; + yylloc->input_name = xstrdup( input_name ); +} + +void parser_loc_eol( YYLTYPE *yylloc ) +{ + yylloc->first_line++; + yylloc->last_line++; + yylloc->first_column = 1; + yylloc->last_column = 1; +} + +void parser_loc_update( YYLTYPE *yylloc, const char *yytext ) +{ + int len = strlen( yytext ); + parser_prev_loc = *yylloc; + yylloc->first_column = yylloc->last_column; + yylloc->last_column += len; }
+void init_location( YYLTYPE *where, const YYLTYPE *begin, const YYLTYPE *end ) +{ + if (!begin) begin = &parser_prev_loc; + *where = *begin; + + if (end) + { + where->last_line = end->last_line; + where->last_column = end->last_column; + } + else + { + where->first_line = begin->last_line; + where->first_column = begin->last_column; + } +} + +static void diagnostic( const YYLTYPE *yylloc, const char *type, const char *message ) +{ + char buffer[1024], *line = NULL; + FILE *file; + int i; + + if (!yylloc) yylloc = &parser_prev_loc; + + print_imports(); + + fprintf( stderr, "%s:%d:%d: %s: %s\n", yylloc->input_name, yylloc->first_line, yylloc->first_column, type, message ); + + if (!yylloc->input_name || !(file = fopen( yylloc->input_name, "r" ))) return; + for (i = 0; i < yylloc->first_line; i++) if (!(line = fgets( buffer, sizeof(buffer), file ))) break; + fclose( file ); + if (!line) return; + fprintf( stderr, "%s", line ); + + line = buffer; + for (i = 0; i < yylloc->first_column - 1; i++) line += sprintf( line, " " ); + line += sprintf( line, "^" ); + for (i = yylloc->first_column + 1; i < yylloc->last_column; i++) line += sprintf( line, "~" ); + fprintf( stderr, "%s\n", buffer ); +} + +void parser_error( const YYLTYPE *yylloc, const char *message ) +{ + diagnostic( yylloc, "error", message ); +} + +void parser_warning( const YYLTYPE *yylloc, const char *message ) +{ + diagnostic( yylloc, "warning", message ); +} + +} + +%define api.location.type {struct location} %define api.prefix {parser_} %define api.pure full %define parse.error verbose +%locations
%union { attr_t *attr; @@ -507,9 +605,9 @@ typedecl: cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; } ;
-import_start: tIMPORT aSTRING ';' { $$ = $2; push_import($2); } +import_start: tIMPORT aSTRING ';' { $$ = $2; push_import($2, &yylloc ); } ; -import: import_start imp_statements aEOF { pop_import(); } +import: import_start imp_statements aEOF { pop_import( &yylloc ); } ;
importlib: tIMPORTLIB '(' aSTRING ')' @@ -1970,7 +2068,7 @@ var_t *make_var(char *name) init_declspec(&v->declspec, NULL); v->attrs = NULL; v->eval = NULL; - init_location( &v->where ); + init_location( &v->where, NULL, NULL ); v->declonly = FALSE; return v; } @@ -3389,14 +3487,6 @@ static statement_list_t *append_statement(statement_list_t *list, statement_t *s return list; }
-void init_location( struct location *where ) -{ - where->input_name = input_name ? input_name : "stdin"; - where->near_text = parser_text; - where->first_line = line_number; - where->last_line = line_number; -} - type_t *find_parameterized_type(type_t *type, typeref_list_t *params) { char *name = format_parameterized_type_name(type, params); diff --git a/tools/widl/typetree.c b/tools/widl/typetree.c index 8d4837b7943..345eee6efc5 100644 --- a/tools/widl/typetree.c +++ b/tools/widl/typetree.c @@ -27,6 +27,7 @@ #include "widl.h" #include "utils.h" #include "parser.h" +#include "parser.tab.h" #include "typetree.h" #include "header.h" #include "hash.h" @@ -65,7 +66,7 @@ type_t *make_type(enum type_type type) t->tfswrite = FALSE; t->checked = FALSE; t->typelib_idx = -1; - init_location( &t->where ); + init_location( &t->where, NULL, NULL ); return t; }
@@ -478,7 +479,7 @@ type_t *type_new_alias(const decl_spec_t *t, const char *name) a->name = xstrdup(name); a->attrs = NULL; a->details.alias.aliasee = *t; - init_location( &a->where ); + init_location( &a->where, NULL, NULL );
return a; } diff --git a/tools/widl/utils.c b/tools/widl/utils.c index 979851e1b44..4f2e9d3d602 100644 --- a/tools/widl/utils.c +++ b/tools/widl/utils.c @@ -32,52 +32,16 @@ #include "utils.h" #include "parser.h"
-#define CURRENT_LOCATION { input_name ? input_name : "stdin", parser_text, line_number, 0, line_number, 0 } - -static const int want_near_indication = 0; - -static void make_print(char *str) -{ - while(*str) - { - if(!isprint(*str)) - *str = ' '; - str++; - } -} - -static void generic_msg( const struct location *where, const char *s, const char *t, va_list ap ) -{ - fprintf( stderr, "%s:%d: %s: ", where->input_name, where->first_line, t ); - vfprintf( stderr, s, ap ); - - if (want_near_indication) - { - char *cpy; - if (where->near_text) - { - cpy = xstrdup( where->near_text ); - make_print( cpy ); - fprintf( stderr, " near '%s'", cpy ); - free( cpy ); - } - } -} - - -/* yyerror: yacc assumes this is not newline terminated. */ -void parser_error(const char *s) -{ - error_loc("%s\n", s); -} - void error_at( const struct location *where, const char *s, ... ) { - struct location cur_loc = CURRENT_LOCATION; + char buffer[1024]; + va_list ap; va_start( ap, s ); - generic_msg( where ? where : &cur_loc, s, "error", ap ); + vsnprintf( buffer, sizeof(buffer), s, ap ); va_end( ap ); + + parser_error( where, buffer ); exit( 1 ); }
@@ -102,11 +66,14 @@ void warning(const char *s, ...)
void warning_at( const struct location *where, const char *s, ... ) { - struct location cur_loc = CURRENT_LOCATION; + char buffer[1024]; + va_list ap; va_start( ap, s ); - generic_msg( where ? where : &cur_loc, s, "warning", ap ); + vsnprintf( buffer, sizeof(buffer), s, ap ); va_end( ap ); + + parser_warning( where, buffer ); }
void chat(const char *s, ...) diff --git a/tools/widl/utils.h b/tools/widl/utils.h index 0196dce95fd..2a6bc7d7930 100644 --- a/tools/widl/utils.h +++ b/tools/widl/utils.h @@ -22,8 +22,8 @@ #define __WIDL_UTILS_H
#include "widltypes.h" +#include "parser.h"
-void parser_error(const char *s) __attribute__((noreturn)); void error(const char *s, ...) __attribute__((format (printf, 1, 2))) __attribute__((noreturn)); void error_at( const struct location *, const char *s, ... ) __attribute__((format( printf, 2, 3 ))) __attribute__((noreturn)); #define error_loc( ... ) error_at( NULL, ## __VA_ARGS__ ) diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 4311811f051..fd108ecc473 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -313,7 +313,6 @@ enum type_basic_type struct location { const char *input_name; - const char *near_text; int first_line; int last_line; int first_column; @@ -656,8 +655,6 @@ type_t *reg_type(type_t *type, const char *name, struct namespace *namespace, in var_t *make_var(char *name); var_list_t *append_var(var_list_t *list, var_t *var);
-void init_location( struct location * ); - char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix, const char *abi_prefix); char *format_parameterized_type_name(type_t *type, typeref_list_t *params);
Please split the last patch. It should be easy to make parser changes separated from new diagnostics.
Thanks for working on this. :slight_smile: