24
24
#include " gcc_types.h"
25
25
#include " padding.h"
26
26
#include " type2name.h"
27
+ #include " typedef_type.h"
27
28
28
29
void c_typecheck_baset::typecheck_type (typet &type)
29
30
{
@@ -89,7 +90,9 @@ void c_typecheck_baset::typecheck_type(typet &type)
89
90
else if (type.id ()==ID_typeof)
90
91
typecheck_typeof_type (type);
91
92
else if (type.id ()==ID_symbol)
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);
93
96
else if (type.id ()==ID_vector)
94
97
typecheck_vector_type (to_vector_type (type));
95
98
else if (type.id ()==ID_custom_unsignedbv ||
@@ -1425,10 +1428,10 @@ void c_typecheck_baset::typecheck_typeof_type(typet &type)
1425
1428
c_qualifiers.write (type);
1426
1429
}
1427
1430
1428
- void c_typecheck_baset::typecheck_symbol_type (typet &type)
1431
+ void c_typecheck_baset::typecheck_symbol_type (symbol_typet &type)
1429
1432
{
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 ();
1432
1435
1433
1436
symbol_tablet::symbolst::const_iterator s_it=
1434
1437
symbol_table.symbols .find (identifier);
@@ -1449,25 +1452,46 @@ void c_typecheck_baset::typecheck_symbol_type(typet &type)
1449
1452
error () << " expected type symbol" << eom;
1450
1453
throw 0 ;
1451
1454
}
1455
+ }
1452
1456
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 = to_typedef_type (type). get_identifier ();
1456
1460
1457
- c_qualifierst c_qualifiers (type);
1458
- bool is_packed=type.get_bool (ID_C_packed);
1459
- irept alignment=type.find (ID_C_alignment);
1461
+ symbol_tablet::symbolst::const_iterator s_it =
1462
+ symbol_table.symbols .find (identifier);
1460
1463
1461
- c_qualifiers+=c_qualifierst (symbol.type );
1462
- type=symbol.type ;
1463
- c_qualifiers.write (type);
1464
+ if (s_it == symbol_table.symbols .end ())
1465
+ {
1466
+ error ().source_location = type.source_location ();
1467
+ error () << " typedef symbol `" << identifier << " ' not found" << eom;
1468
+ throw 0 ;
1469
+ }
1464
1470
1465
- if (is_packed)
1466
- type.set (ID_C_packed, true );
1467
- if (alignment.is_not_nil ())
1468
- type.set (ID_C_alignment, alignment);
1471
+ const symbolt &symbol = s_it->second ;
1472
+
1473
+ if (!symbol.is_type )
1474
+ {
1475
+ error ().source_location = type.source_location ();
1476
+ error () << " expected type symbol for typedef" << eom;
1477
+ throw 0 ;
1469
1478
}
1470
1479
1480
+ // overwrite, but preserve (add) any qualifiers and other flags
1481
+
1482
+ c_qualifierst c_qualifiers (type);
1483
+ bool is_packed = type.get_bool (ID_C_packed);
1484
+ irept alignment = type.find (ID_C_alignment);
1485
+
1486
+ c_qualifiers += c_qualifierst (symbol.type );
1487
+ type = symbol.type ;
1488
+ c_qualifiers.write (type);
1489
+
1490
+ if (is_packed)
1491
+ type.set (ID_C_packed, true );
1492
+ if (alignment.is_not_nil ())
1493
+ type.set (ID_C_alignment, alignment);
1494
+
1471
1495
// CPROVER extensions
1472
1496
if (symbol.base_name ==" __CPROVER_rational" )
1473
1497
{
0 commit comments