- Timestamp:
- Jun 19, 2019, 4:51:14 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c0f9efe
- Parents:
- 17a0ede2
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r17a0ede2 r1ae47de 1075 1075 } 1076 1076 1077 const ast::Type * visitType( const ast::Type * node, Type * type ) { 1078 // Some types do this in their constructor so add a check. 1079 if ( !node->attributes.empty() && type->attributes.empty() ) { 1080 type->attributes = get<Attribute>().acceptL( node->attributes ); 1081 } 1082 this->node = type; 1083 return nullptr; 1084 } 1085 1077 1086 const ast::Type * visit( const ast::VoidType * node ) override final { 1078 this->node = new VoidType{ cv( node ) }; 1079 return nullptr; 1087 return visitType( node, new VoidType{ cv( node ) } ); 1080 1088 } 1081 1089 … … 1086 1094 Validate::SizeType = type; 1087 1095 } 1088 this->node = type; 1089 return nullptr; 1096 return visitType( node, type ); 1090 1097 } 1091 1098 1092 1099 const ast::Type * visit( const ast::PointerType * node ) override final { 1093 this->node =new PointerType{1100 return visitType( node, new PointerType{ 1094 1101 cv( node ), 1095 1102 get<Type>().accept1( node->base ), … … 1097 1104 (bool)node->isVarLen, 1098 1105 (bool)node->isStatic 1099 }; 1100 return nullptr; 1106 } ); 1101 1107 } 1102 1108 1103 1109 const ast::Type * visit( const ast::ArrayType * node ) override final { 1104 this->node =new ArrayType{1110 return visitType( node, new ArrayType{ 1105 1111 cv( node ), 1106 1112 get<Type>().accept1( node->base ), … … 1108 1114 (bool)node->isVarLen, 1109 1115 (bool)node->isStatic 1110 }; 1111 return nullptr; 1116 } ); 1112 1117 } 1113 1118 1114 1119 const ast::Type * visit( const ast::ReferenceType * node ) override final { 1115 this->node =new ReferenceType{1120 return visitType( node, new ReferenceType{ 1116 1121 cv( node ), 1117 1122 get<Type>().accept1( node->base ) 1118 }; 1119 return nullptr; 1123 } ); 1120 1124 } 1121 1125 1122 1126 const ast::Type * visit( const ast::QualifiedType * node ) override final { 1123 this->node =new QualifiedType{1127 return visitType( node, new QualifiedType{ 1124 1128 cv( node ), 1125 1129 get<Type>().accept1( node->parent ), 1126 1130 get<Type>().accept1( node->child ) 1127 }; 1128 return nullptr; 1131 } ); 1129 1132 } 1130 1133 … … 1137 1140 ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 1138 1141 ty->forall = get<TypeDecl>().acceptL( node->forall ); 1139 this->node = ty; 1140 return nullptr; 1141 } 1142 1143 void postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) { 1142 return visitType( node, ty ); 1143 } 1144 1145 const ast::Type * postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) { 1144 1146 ty->forall = get<TypeDecl>().acceptL( old->forall ); 1145 1147 ty->parameters = get<Expression>().acceptL( old->params ); 1146 1148 ty->hoistType = old->hoistType; 1149 return visitType( old, ty ); 1147 1150 } 1148 1151 … … 1162 1165 }; 1163 1166 } 1164 postvisit( node, ty ); 1165 this->node = ty; 1166 return nullptr; 1167 return postvisit( node, ty ); 1167 1168 } 1168 1169 … … 1182 1183 }; 1183 1184 } 1184 postvisit( node, ty ); 1185 this->node = ty; 1186 return nullptr; 1185 return postvisit( node, ty ); 1187 1186 } 1188 1187 … … 1202 1201 }; 1203 1202 } 1204 postvisit( node, ty ); 1205 this->node = ty; 1206 return nullptr; 1203 return postvisit( node, ty ); 1207 1204 } 1208 1205 … … 1222 1219 }; 1223 1220 } 1224 postvisit( node, ty ); 1225 this->node = ty; 1226 return nullptr; 1221 return postvisit( node, ty ); 1227 1222 } 1228 1223 … … 1244 1239 }; 1245 1240 } 1246 postvisit( node, ty ); 1247 this->node = ty; 1248 return nullptr; 1241 return postvisit( node, ty ); 1249 1242 } 1250 1243 1251 1244 const ast::Type * visit( const ast::TupleType * node ) override final { 1252 this->node =new TupleType{1245 return visitType( node, new TupleType{ 1253 1246 cv( node ), 1254 1247 get<Type>().acceptL( node->types ) 1255 1248 // members generated by TupleType c'tor 1256 }; 1257 return nullptr; 1249 } ); 1258 1250 } 1259 1251 1260 1252 const ast::Type * visit( const ast::TypeofType * node ) override final { 1261 this->node =new TypeofType{1253 return visitType( node, new TypeofType{ 1262 1254 cv( node ), 1263 1255 get<Expression>().accept1( node->expr ), 1264 1256 (bool)node->kind 1265 }; 1266 return nullptr; 1257 } ); 1267 1258 } 1268 1259 1269 1260 const ast::Type * visit( const ast::VarArgsType * node ) override final { 1270 this->node = new VarArgsType{ cv( node ) }; 1271 return nullptr; 1261 return visitType( node, new VarArgsType{ cv( node ) } ); 1272 1262 } 1273 1263 1274 1264 const ast::Type * visit( const ast::ZeroType * node ) override final { 1275 this->node = new ZeroType{ cv( node ) }; 1276 return nullptr; 1265 return visitType( node, new ZeroType{ cv( node ) } ); 1277 1266 } 1278 1267 1279 1268 const ast::Type * visit( const ast::OneType * node ) override final { 1280 this->node = new OneType{ cv( node ) }; 1281 return nullptr; 1282 } 1283 1284 const ast::Type * visit( const ast::GlobalScopeType * ) override final { 1285 this->node = new GlobalScopeType{}; 1286 return nullptr; 1269 return visitType( node, new OneType{ cv( node ) } ); 1270 } 1271 1272 const ast::Type * visit( const ast::GlobalScopeType * node ) override final { 1273 return visitType( node, new GlobalScopeType{} ); 1287 1274 } 1288 1275 … … 2442 2429 } 2443 2430 2431 void visitType( Type * old, ast::Type * type ) { 2432 // Some types do this in their constructor so add a check. 2433 if ( !old->attributes.empty() && type->attributes.empty() ) { 2434 type->attributes = GET_ACCEPT_V(attributes, Attribute); 2435 } 2436 this->node = type; 2437 } 2438 2444 2439 virtual void visit( VoidType * old ) override final { 2445 this->node = new ast::VoidType{ cv( old ) };2440 visitType( old, new ast::VoidType{ cv( old ) } ); 2446 2441 } 2447 2442 … … 2452 2447 sizeType = type; 2453 2448 } 2454 this->node = type;2449 visitType( old, type ); 2455 2450 } 2456 2451 2457 2452 virtual void visit( PointerType * old ) override final { 2458 this->node =new ast::PointerType{2453 visitType( old, new ast::PointerType{ 2459 2454 GET_ACCEPT_1( base, Type ), 2460 2455 GET_ACCEPT_1( dimension, Expr ), … … 2462 2457 (ast::DimensionFlag)old->isStatic, 2463 2458 cv( old ) 2464 } ;2459 } ); 2465 2460 } 2466 2461 2467 2462 virtual void visit( ArrayType * old ) override final { 2468 this->node =new ast::ArrayType{2463 visitType( old, new ast::ArrayType{ 2469 2464 GET_ACCEPT_1( base, Type ), 2470 2465 GET_ACCEPT_1( dimension, Expr ), … … 2472 2467 (ast::DimensionFlag)old->isStatic, 2473 2468 cv( old ) 2474 } ;2469 } ); 2475 2470 } 2476 2471 2477 2472 virtual void visit( ReferenceType * old ) override final { 2478 this->node =new ast::ReferenceType{2473 visitType( old, new ast::ReferenceType{ 2479 2474 GET_ACCEPT_1( base, Type ), 2480 2475 cv( old ) 2481 } ;2476 } ); 2482 2477 } 2483 2478 2484 2479 virtual void visit( QualifiedType * old ) override final { 2485 this->node =new ast::QualifiedType{2480 visitType( old, new ast::QualifiedType{ 2486 2481 GET_ACCEPT_1( parent, Type ), 2487 2482 GET_ACCEPT_1( child, Type ), 2488 2483 cv( old ) 2489 } ;2484 } ); 2490 2485 } 2491 2486 … … 2498 2493 ty->params = GET_ACCEPT_V( parameters, DeclWithType ); 2499 2494 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2500 this->node = ty;2495 visitType( old, ty ); 2501 2496 } 2502 2497 … … 2505 2500 ty->params = GET_ACCEPT_V( parameters, Expr ); 2506 2501 ty->hoistType = old->hoistType; 2502 visitType( old, ty ); 2507 2503 } 2508 2504 … … 2523 2519 } 2524 2520 postvisit( old, ty ); 2525 this->node = ty;2526 2521 } 2527 2522 … … 2542 2537 } 2543 2538 postvisit( old, ty ); 2544 this->node = ty;2545 2539 } 2546 2540 … … 2561 2555 } 2562 2556 postvisit( old, ty ); 2563 this->node = ty;2564 2557 } 2565 2558 … … 2580 2573 } 2581 2574 postvisit( old, ty ); 2582 this->node = ty;2583 2575 } 2584 2576 … … 2601 2593 } 2602 2594 postvisit( old, ty ); 2603 this->node = ty;2604 2595 } 2605 2596 2606 2597 virtual void visit( TupleType * old ) override final { 2607 this->node =new ast::TupleType{2598 visitType( old, new ast::TupleType{ 2608 2599 GET_ACCEPT_V( types, Type ), 2609 2600 // members generated by TupleType c'tor 2610 2601 cv( old ) 2611 } ;2602 } ); 2612 2603 } 2613 2604 2614 2605 virtual void visit( TypeofType * old ) override final { 2615 this->node =new ast::TypeofType{2606 visitType( old, new ast::TypeofType{ 2616 2607 GET_ACCEPT_1( expr, Expr ), 2617 2608 (ast::TypeofType::Kind)old->is_basetypeof, 2618 2609 cv( old ) 2619 } ;2610 } ); 2620 2611 } 2621 2612 … … 2625 2616 2626 2617 virtual void visit( VarArgsType * old ) override final { 2627 this->node = new ast::VarArgsType{ cv( old ) };2618 visitType( old, new ast::VarArgsType{ cv( old ) } ); 2628 2619 } 2629 2620 2630 2621 virtual void visit( ZeroType * old ) override final { 2631 this->node = new ast::ZeroType{ cv( old ) };2622 visitType( old, new ast::ZeroType{ cv( old ) } ); 2632 2623 } 2633 2624 2634 2625 virtual void visit( OneType * old ) override final { 2635 this->node = new ast::OneType{ cv( old ) };2636 } 2637 2638 virtual void visit( GlobalScopeType * ) override final {2639 this->node = new ast::GlobalScopeType{};2626 visitType( old, new ast::OneType{ cv( old ) } ); 2627 } 2628 2629 virtual void visit( GlobalScopeType * old ) override final { 2630 visitType( old, new ast::GlobalScopeType{} ); 2640 2631 } 2641 2632 -
src/AST/Type.hpp
r17a0ede2 r1ae47de 39 39 std::vector<ptr<Attribute>> attributes; 40 40 41 Type( CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ) 41 Type( CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} ) 42 42 : qualifiers(q), attributes(std::move(as)) {} 43 43 … … 270 270 ForallList forall; 271 271 272 ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {}, 272 ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {}, 273 273 std::vector<ptr<Attribute>> && as = {} ) 274 274 : Type(q, std::move(as)), forall(std::move(fs)) {} 275 276 ParameterizedType( CV::Qualifiers q, std::vector<ptr<Attribute>> && as = {} ) 275 276 ParameterizedType( CV::Qualifiers q, std::vector<ptr<Attribute>> && as = {} ) 277 277 : Type(q, std::move(as)), forall() {} 278 278
Note: See TracChangeset
for help on using the changeset viewer.