Changeset e048ece for src/Parser/TypeData.cc
- Timestamp:
- Mar 11, 2024, 1:00:41 PM (4 months ago)
- Branches:
- master
- Children:
- 6c8b76b
- Parents:
- 9398177
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TypeData.cc
r9398177 re048ece 33 33 using namespace std; 34 34 35 // These must harmonize with the corresponding enumerations in the header. 36 const char * TypeData::basicTypeNames[] = { 37 "void", "_Bool", "char", "int", "int128", 38 "float", "double", "long double", "float80", "float128", 39 "_float16", "_float32", "_float32x", "_float64", "_float64x", "_float128", "_float128x", 40 "NoBasicTypeNames" 41 }; 42 const char * TypeData::complexTypeNames[] = { 43 "_Complex", "NoComplexTypeNames", "_Imaginary" 44 }; // Imaginary unsupported => parse, but make invisible and print error message 45 const char * TypeData::signednessNames[] = { 46 "signed", "unsigned", "NoSignednessNames" 47 }; 48 const char * TypeData::lengthNames[] = { 49 "short", "long", "long long", "NoLengthNames" 50 }; 51 const char * TypeData::builtinTypeNames[] = { 52 "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames" 53 }; 54 35 55 TypeData::TypeData( Kind k ) : location( yylloc ), kind( k ), base( nullptr ), forall( nullptr ) /*, PTR1( (void*)(0xdeadbeefdeadbeef)), PTR2( (void*)(0xdeadbeefdeadbeef) ) */ { 36 56 switch ( kind ) { … … 239 259 break; 240 260 case Builtin: 241 assert( builtintype == DeclarationNode::Zero || builtintype == DeclarationNode::One );261 assert( builtintype == Zero || builtintype == One ); 242 262 newtype->builtintype = builtintype; 243 263 break; … … 261 281 switch ( kind ) { 262 282 case Basic: 263 if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " ";264 if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " ";265 if ( complextype != DeclarationNode::NoComplexType ) os << DeclarationNode::complexTypeNames[ complextype ] << " ";266 if ( basictype != DeclarationNode::NoBasicType ) os << DeclarationNode::basicTypeNames[ basictype ] << " ";283 if ( signedness != NoSignedness ) os << signednessNames[ signedness ] << " "; 284 if ( length != NoLength ) os << lengthNames[ length ] << " "; 285 if ( complextype != NoComplexType ) os << complexTypeNames[ complextype ] << " "; 286 if ( basictype != NoBasicType ) os << basicTypeNames[ basictype ] << " "; 267 287 break; 268 288 case Pointer: … … 429 449 break; 430 450 case Builtin: 431 os << DeclarationNode::builtinTypeNames[builtintype];451 os << builtinTypeNames[builtintype]; 432 452 break; 433 453 case GlobalScope: … … 495 515 } 496 516 497 TypeData * build_basic_type( DeclarationNode::BasicType basic ) {517 TypeData * build_basic_type( TypeData::BasicType basic ) { 498 518 TypeData * type = new TypeData( TypeData::Basic ); 499 519 type->basictype = basic; … … 501 521 } 502 522 503 TypeData * build_complex_type( DeclarationNode::ComplexType complex ) {523 TypeData * build_complex_type( TypeData::ComplexType complex ) { 504 524 TypeData * type = new TypeData( TypeData::Basic ); 505 525 type->complextype = complex; … … 507 527 } 508 528 509 TypeData * build_signedness( DeclarationNode::Signedness signedness ) {529 TypeData * build_signedness( TypeData::Signedness signedness ) { 510 530 TypeData * type = new TypeData( TypeData::Basic ); 511 531 type->signedness = signedness; … … 513 533 } 514 534 515 TypeData * build_builtin_type( DeclarationNode::BuiltinType bit ) {535 TypeData * build_builtin_type( TypeData::BuiltinType bit ) { 516 536 TypeData * type = new TypeData( TypeData::Builtin ); 517 537 type->builtintype = bit; … … 519 539 } 520 540 521 TypeData * build_length( DeclarationNode::Length length ) {541 TypeData * build_length( TypeData::Length length ) { 522 542 TypeData * type = new TypeData( TypeData::Basic ); 523 543 type->length = length; … … 622 642 assert( src->kind == TypeData::Basic ); 623 643 624 if ( dst->basictype == DeclarationNode::NoBasicType ) {644 if ( dst->basictype == TypeData::NoBasicType ) { 625 645 dst->basictype = src->basictype; 626 } else if ( src->basictype != DeclarationNode::NoBasicType ) {646 } else if ( src->basictype != TypeData::NoBasicType ) { 627 647 SemanticError( yylloc, "multiple declaration types \"%s\" and \"%s\".", 628 DeclarationNode::basicTypeNames[ dst->basictype ],629 DeclarationNode::basicTypeNames[ src->basictype ] );648 TypeData::basicTypeNames[ dst->basictype ], 649 TypeData::basicTypeNames[ src->basictype ] ); 630 650 } 631 if ( dst->complextype == DeclarationNode::NoComplexType ) {651 if ( dst->complextype == TypeData::NoComplexType ) { 632 652 dst->complextype = src->complextype; 633 } else if ( src->complextype != DeclarationNode::NoComplexType ) {653 } else if ( src->complextype != TypeData::NoComplexType ) { 634 654 SemanticError( yylloc, "multiple declaration types \"%s\" and \"%s\".", 635 DeclarationNode::complexTypeNames[ src->complextype ],636 DeclarationNode::complexTypeNames[ src->complextype ] );655 TypeData::complexTypeNames[ src->complextype ], 656 TypeData::complexTypeNames[ src->complextype ] ); 637 657 } 638 if ( dst->signedness == DeclarationNode::NoSignedness ) {658 if ( dst->signedness == TypeData::NoSignedness ) { 639 659 dst->signedness = src->signedness; 640 } else if ( src->signedness != DeclarationNode::NoSignedness ) {660 } else if ( src->signedness != TypeData::NoSignedness ) { 641 661 SemanticError( yylloc, "conflicting type specifier \"%s\" and \"%s\".", 642 DeclarationNode::signednessNames[ dst->signedness ],643 DeclarationNode::signednessNames[ src->signedness ] );662 TypeData::signednessNames[ dst->signedness ], 663 TypeData::signednessNames[ src->signedness ] ); 644 664 } 645 if ( dst->length == DeclarationNode::NoLength ) {665 if ( dst->length == TypeData::NoLength ) { 646 666 dst->length = src->length; 647 } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) {648 dst->length = DeclarationNode::LongLong;649 } else if ( src->length != DeclarationNode::NoLength ) {667 } else if ( dst->length == TypeData::Long && src->length == TypeData::Long ) { 668 dst->length = TypeData::LongLong; 669 } else if ( src->length != TypeData::NoLength ) { 650 670 SemanticError( yylloc, "conflicting type specifier \"%s\" and \"%s\".", 651 DeclarationNode::lengthNames[ dst->length ],652 DeclarationNode::lengthNames[ src->length ] );671 TypeData::lengthNames[ dst->length ], 672 TypeData::lengthNames[ src->length ] ); 653 673 } 654 674 } // if … … 1091 1111 case TypeData::Builtin: 1092 1112 switch ( td->builtintype ) { 1093 case DeclarationNode::Zero:1113 case TypeData::Zero: 1094 1114 return new ast::ZeroType(); 1095 case DeclarationNode::One:1115 case TypeData::One: 1096 1116 return new ast::OneType(); 1097 1117 default: … … 1149 1169 1150 1170 1151 static string genTSError( string msg, DeclarationNode::BasicType basictype ) {1152 SemanticError( yylloc, "invalid type specifier \"%s\" for type \"%s\".", msg.c_str(), DeclarationNode::basicTypeNames[basictype] );1171 static string genTSError( string msg, TypeData::BasicType basictype ) { 1172 SemanticError( yylloc, "invalid type specifier \"%s\" for type \"%s\".", msg.c_str(), TypeData::basicTypeNames[basictype] ); 1153 1173 } // genTSError 1154 1174 … … 1157 1177 1158 1178 switch ( td->basictype ) { 1159 case DeclarationNode::Void:1160 if ( td->signedness != DeclarationNode::NoSignedness ) {1161 genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );1162 } // if 1163 if ( td->length != DeclarationNode::NoLength ) {1164 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );1179 case TypeData::Void: 1180 if ( td->signedness != TypeData::NoSignedness ) { 1181 genTSError( TypeData::signednessNames[ td->signedness ], td->basictype ); 1182 } // if 1183 if ( td->length != TypeData::NoLength ) { 1184 genTSError( TypeData::lengthNames[ td->length ], td->basictype ); 1165 1185 } // if 1166 1186 return new ast::VoidType( buildQualifiers( td ) ); 1167 1187 break; 1168 1188 1169 case DeclarationNode::Bool:1170 if ( td->signedness != DeclarationNode::NoSignedness ) {1171 genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );1172 } // if 1173 if ( td->length != DeclarationNode::NoLength ) {1174 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );1189 case TypeData::Bool: 1190 if ( td->signedness != TypeData::NoSignedness ) { 1191 genTSError( TypeData::signednessNames[ td->signedness ], td->basictype ); 1192 } // if 1193 if ( td->length != TypeData::NoLength ) { 1194 genTSError( TypeData::lengthNames[ td->length ], td->basictype ); 1175 1195 } // if 1176 1196 … … 1178 1198 break; 1179 1199 1180 case DeclarationNode::Char:1200 case TypeData::Char: 1181 1201 // C11 Standard 6.2.5.15: The three types char, signed char, and unsigned char are collectively called the 1182 1202 // character types. The implementation shall define char to have the same range, representation, and behavior as … … 1184 1204 static ast::BasicType::Kind chartype[] = { ast::BasicType::SignedChar, ast::BasicType::UnsignedChar, ast::BasicType::Char }; 1185 1205 1186 if ( td->length != DeclarationNode::NoLength ) {1187 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );1206 if ( td->length != TypeData::NoLength ) { 1207 genTSError( TypeData::lengthNames[ td->length ], td->basictype ); 1188 1208 } // if 1189 1209 … … 1191 1211 break; 1192 1212 1193 case DeclarationNode::Int:1213 case TypeData::Int: 1194 1214 static ast::BasicType::Kind inttype[2][4] = { 1195 1215 { ast::BasicType::ShortSignedInt, ast::BasicType::LongSignedInt, ast::BasicType::LongLongSignedInt, ast::BasicType::SignedInt }, … … 1198 1218 1199 1219 Integral: ; 1200 if ( td->signedness == DeclarationNode::NoSignedness ) {1201 const_cast<TypeData *>(td)->signedness = DeclarationNode::Signed;1220 if ( td->signedness == TypeData::NoSignedness ) { 1221 const_cast<TypeData *>(td)->signedness = TypeData::Signed; 1202 1222 } // if 1203 1223 ret = inttype[ td->signedness ][ td->length ]; 1204 1224 break; 1205 1225 1206 case DeclarationNode::Int128:1207 ret = td->signedness == DeclarationNode::Unsigned ? ast::BasicType::UnsignedInt128 : ast::BasicType::SignedInt128;1208 if ( td->length != DeclarationNode::NoLength ) {1209 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );1210 } // if 1211 break; 1212 1213 case DeclarationNode::Float:1214 case DeclarationNode::Double:1215 case DeclarationNode::LongDouble: // not set until below1216 case DeclarationNode::uuFloat80:1217 case DeclarationNode::uuFloat128:1218 case DeclarationNode::uFloat16:1219 case DeclarationNode::uFloat32:1220 case DeclarationNode::uFloat32x:1221 case DeclarationNode::uFloat64:1222 case DeclarationNode::uFloat64x:1223 case DeclarationNode::uFloat128:1224 case DeclarationNode::uFloat128x:1226 case TypeData::Int128: 1227 ret = td->signedness == TypeData::Unsigned ? ast::BasicType::UnsignedInt128 : ast::BasicType::SignedInt128; 1228 if ( td->length != TypeData::NoLength ) { 1229 genTSError( TypeData::lengthNames[ td->length ], td->basictype ); 1230 } // if 1231 break; 1232 1233 case TypeData::Float: 1234 case TypeData::Double: 1235 case TypeData::LongDouble: // not set until below 1236 case TypeData::uuFloat80: 1237 case TypeData::uuFloat128: 1238 case TypeData::uFloat16: 1239 case TypeData::uFloat32: 1240 case TypeData::uFloat32x: 1241 case TypeData::uFloat64: 1242 case TypeData::uFloat64x: 1243 case TypeData::uFloat128: 1244 case TypeData::uFloat128x: 1225 1245 static ast::BasicType::Kind floattype[2][12] = { 1226 1246 { ast::BasicType::FloatComplex, ast::BasicType::DoubleComplex, ast::BasicType::LongDoubleComplex, (ast::BasicType::Kind)-1, (ast::BasicType::Kind)-1, ast::BasicType::uFloat16Complex, ast::BasicType::uFloat32Complex, ast::BasicType::uFloat32xComplex, ast::BasicType::uFloat64Complex, ast::BasicType::uFloat64xComplex, ast::BasicType::uFloat128Complex, ast::BasicType::uFloat128xComplex, }, … … 1229 1249 1230 1250 FloatingPoint: ; 1231 if ( td->signedness != DeclarationNode::NoSignedness ) {1232 genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );1233 } // if 1234 if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) {1235 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );1236 } // if 1237 if ( td->basictype != DeclarationNode::Double && td->length == DeclarationNode::Long ) {1238 genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );1239 } // if 1240 if ( td->complextype == DeclarationNode::Imaginary ) {1241 genTSError( DeclarationNode::complexTypeNames[ td->complextype ], td->basictype );1242 } // if 1243 if ( (td->basictype == DeclarationNode::uuFloat80 || td->basictype == DeclarationNode::uuFloat128) && td->complextype == DeclarationNode::Complex ) { // gcc unsupported1244 genTSError( DeclarationNode::complexTypeNames[ td->complextype ], td->basictype );1245 } // if 1246 if ( td->length == DeclarationNode::Long ) {1247 const_cast<TypeData *>(td)->basictype = DeclarationNode::LongDouble;1248 } // if 1249 1250 ret = floattype[ td->complextype ][ td->basictype - DeclarationNode::Float ];1251 //printf( "XXXX %d %d %d %d\n", td->complextype, td->basictype, DeclarationNode::Float, ret );1252 break; 1253 1254 case DeclarationNode::NoBasicType:1251 if ( td->signedness != TypeData::NoSignedness ) { 1252 genTSError( TypeData::signednessNames[ td->signedness ], td->basictype ); 1253 } // if 1254 if ( td->length == TypeData::Short || td->length == TypeData::LongLong ) { 1255 genTSError( TypeData::lengthNames[ td->length ], td->basictype ); 1256 } // if 1257 if ( td->basictype != TypeData::Double && td->length == TypeData::Long ) { 1258 genTSError( TypeData::lengthNames[ td->length ], td->basictype ); 1259 } // if 1260 if ( td->complextype == TypeData::Imaginary ) { 1261 genTSError( TypeData::complexTypeNames[ td->complextype ], td->basictype ); 1262 } // if 1263 if ( (td->basictype == TypeData::uuFloat80 || td->basictype == TypeData::uuFloat128) && td->complextype == TypeData::Complex ) { // gcc unsupported 1264 genTSError( TypeData::complexTypeNames[ td->complextype ], td->basictype ); 1265 } // if 1266 if ( td->length == TypeData::Long ) { 1267 const_cast<TypeData *>(td)->basictype = TypeData::LongDouble; 1268 } // if 1269 1270 ret = floattype[ td->complextype ][ td->basictype - TypeData::Float ]; 1271 //printf( "XXXX %d %d %d %d\n", td->complextype, td->basictype, TypeData::Float, ret ); 1272 break; 1273 1274 case TypeData::NoBasicType: 1255 1275 // No basic type in declaration => default double for Complex/Imaginary and int type for integral types 1256 if ( td->complextype == DeclarationNode::Complex || td->complextype == DeclarationNode::Imaginary ) {1257 const_cast<TypeData *>(td)->basictype = DeclarationNode::Double;1276 if ( td->complextype == TypeData::Complex || td->complextype == TypeData::Imaginary ) { 1277 const_cast<TypeData *>(td)->basictype = TypeData::Double; 1258 1278 goto FloatingPoint; 1259 1279 } // if 1260 1280 1261 const_cast<TypeData *>(td)->basictype = DeclarationNode::Int;1281 const_cast<TypeData *>(td)->basictype = TypeData::Int; 1262 1282 goto Integral; 1263 1283 default: … … 1803 1823 if ( ! param->type ) { // generate type int for empty parameter type 1804 1824 param->type = new TypeData( TypeData::Basic ); 1805 param->type->basictype = DeclarationNode::Int;1825 param->type->basictype = TypeData::Int; 1806 1826 } // if 1807 1827 } // for
Note: See TracChangeset
for help on using the changeset viewer.