2424#include " gcc_types.h"
2525#include " padding.h"
2626#include " type2name.h"
27+ #include " typedef_type.h"
2728
2829void c_typecheck_baset::typecheck_type (typet &type)
2930{
@@ -89,7 +90,9 @@ void c_typecheck_baset::typecheck_type(typet &type)
8990 else if (type.id ()==ID_typeof)
9091 typecheck_typeof_type (type);
9192 else if (type.id () == ID_symbol_type)
92- typecheck_symbol_type (type);
93+ typecheck_symbol_type (to_symbol_type (type));
94+ else if (type.id () == ID_typedef_type)
95+ typecheck_typedef_type (type);
9396 else if (type.id ()==ID_vector)
9497 typecheck_vector_type (to_vector_type (type));
9598 else if (type.id ()==ID_custom_unsignedbv ||
@@ -1425,10 +1428,10 @@ void c_typecheck_baset::typecheck_typeof_type(typet &type)
14251428 c_qualifiers.write (type);
14261429}
14271430
1428- void c_typecheck_baset::typecheck_symbol_type (typet &type)
1431+ void c_typecheck_baset::typecheck_symbol_type (symbol_typet &type)
14291432{
1430- const irep_idt &identifier=
1431- to_symbol_type ( type) .get_identifier ();
1433+ // we do some consistency checking only
1434+ const irep_idt &identifier= type.get_identifier ();
14321435
14331436 symbol_tablet::symbolst::const_iterator s_it=
14341437 symbol_table.symbols .find (identifier);
@@ -1449,25 +1452,48 @@ void c_typecheck_baset::typecheck_symbol_type(typet &type)
14491452 error () << " expected type symbol" << eom;
14501453 throw 0 ;
14511454 }
1455+ }
14521456
1453- if (symbol.is_macro )
1454- {
1455- // overwrite, but preserve (add) any qualifiers and other flags
1457+ void c_typecheck_baset::typecheck_typedef_type (typet &type)
1458+ {
1459+ const irep_idt &identifier=
1460+ to_typedef_type (type).get_identifier ();
14561461
1457- c_qualifierst c_qualifiers (type);
1458- bool is_packed=type.get_bool (ID_C_packed);
1459- irept alignment=type.find (ID_C_alignment);
1462+ symbol_tablet::symbolst::const_iterator s_it=
1463+ symbol_table.symbols .find (identifier);
14601464
1461- c_qualifiers+=c_qualifierst (symbol.type );
1462- type=symbol.type ;
1463- c_qualifiers.write (type);
1465+ if (s_it==symbol_table.symbols .end ())
1466+ {
1467+ error ().source_location =type.source_location ();
1468+ error () << " typedef symbol `" << identifier << " ' not found"
1469+ << eom;
1470+ throw 0 ;
1471+ }
14641472
1465- if (is_packed)
1466- type.set (ID_C_packed, true );
1467- if (alignment.is_not_nil ())
1468- type.set (ID_C_alignment, alignment);
1473+ const symbolt &symbol=s_it->second ;
1474+
1475+ if (!symbol.is_type )
1476+ {
1477+ error ().source_location =type.source_location ();
1478+ error () << " expected type symbol for typedef" << eom;
1479+ throw 0 ;
14691480 }
14701481
1482+ // overwrite, but preserve (add) any qualifiers and other flags
1483+
1484+ c_qualifierst c_qualifiers (type);
1485+ bool is_packed=type.get_bool (ID_C_packed);
1486+ irept alignment=type.find (ID_C_alignment);
1487+
1488+ c_qualifiers+=c_qualifierst (symbol.type );
1489+ type=symbol.type ;
1490+ c_qualifiers.write (type);
1491+
1492+ if (is_packed)
1493+ type.set (ID_C_packed, true );
1494+ if (alignment.is_not_nil ())
1495+ type.set (ID_C_alignment, alignment);
1496+
14711497 // CPROVER extensions
14721498 if (symbol.base_name ==" __CPROVER_rational" )
14731499 {
0 commit comments