Improve interrogate diagnostics when encountering unknown types

This commit is contained in:
rdb 2015-11-19 13:07:28 +01:00
parent fb0902512e
commit 909856c75d
3 changed files with 2553 additions and 2478 deletions

File diff suppressed because it is too large Load Diff

View File

@ -341,6 +341,7 @@ pop_struct() {
%type <u.inst_ident> empty_instance_identifier %type <u.inst_ident> empty_instance_identifier
%type <u.type> type %type <u.type> type
%type <u.decl> type_decl %type <u.decl> type_decl
%type <u.decl> var_type_decl
%type <u.type> predefined_type %type <u.type> predefined_type
%type <u.type> full_type %type <u.type> full_type
%type <u.struct_type> anonymous_struct %type <u.struct_type> anonymous_struct
@ -676,7 +677,7 @@ type_like_declaration:
; ;
multiple_var_declaration: multiple_var_declaration:
storage_class type_decl storage_class var_type_decl
{ {
// We don't need to push/pop type, because we can't nest // We don't need to push/pop type, because we can't nest
// multiple_var_declarations. // multiple_var_declarations.
@ -691,11 +692,15 @@ multiple_var_declaration:
{ {
pop_storage_class(); pop_storage_class();
} }
| storage_class KW_CONST type | storage_class KW_CONST var_type_decl
{ {
// We don't need to push/pop type, because we can't nest // We don't need to push/pop type, because we can't nest
// multiple_var_declarations. // multiple_var_declarations.
current_type = $3; if ($3->as_type_declaration()) {
current_type = $3->as_type_declaration()->_type;
} else {
current_type = $3->as_type();
}
push_storage_class($1); push_storage_class($1);
} }
multiple_const_instance_identifiers multiple_const_instance_identifiers
@ -750,7 +755,7 @@ multiple_const_instance_identifiers:
typedef_declaration: typedef_declaration:
storage_class type_decl storage_class var_type_decl
{ {
// We don't need to push/pop type, because we can't nest // We don't need to push/pop type, because we can't nest
// multiple_var_declarations. // multiple_var_declarations.
@ -765,11 +770,15 @@ typedef_declaration:
{ {
pop_storage_class(); pop_storage_class();
} }
| storage_class KW_CONST type | storage_class KW_CONST var_type_decl
{ {
// We don't need to push/pop type, because we can't nest // We don't need to push/pop type, because we can't nest
// multiple_var_declarations. // multiple_var_declarations.
current_type = $3; if ($3->as_type_declaration()) {
current_type = $3->as_type_declaration()->_type;
} else {
current_type = $3->as_type();
}
push_storage_class($1); push_storage_class($1);
} }
typedef_const_instance_identifiers typedef_const_instance_identifiers
@ -1892,6 +1901,18 @@ predefined_type:
} }
; ;
var_type_decl:
type_decl
{
$$ = $1;
}
| IDENTIFIER
{
yyerror(string("unknown type '") + $1->get_fully_scoped_name() + "'", @1);
$$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_unknown));
}
full_type: full_type:
type empty_instance_identifier type empty_instance_identifier
{ {

View File

@ -1116,7 +1116,7 @@ handle_declaration(CPPDeclaration *decl, CPPScope *global_scope,
// We don't do redefinitions of typedefs. But we don't complain // We don't do redefinitions of typedefs. But we don't complain
// as long as this is actually a typedef to the previous definition. // as long as this is actually a typedef to the previous definition.
if (other_type != def->_type && if (other_type != def->_type &&
(other_td == NULL || other_td->_type != def->_type)) { (other_td == NULL || !other_td->_type->is_equivalent(*def->_type))) {
if (error_sink != NULL) { if (error_sink != NULL) {
ostringstream errstr; ostringstream errstr;