Changes in src/AST/Convert.cpp [d148778:112fe04]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rd148778 r112fe04 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri May 17 16:01:00 201913 // Update Count : 412 // Last Modified On : Tue May 21 15:30:00 2019 13 // Update Count : 5 14 14 // 15 15 16 16 #include "Convert.hpp" 17 18 #include <unordered_map>19 17 20 18 #include "AST/Attribute.hpp" … … 44 42 class ConverterNewToOld : public ast::Visitor { 45 43 BaseSyntaxNode * node = nullptr; 46 std::unordered_map< ast::Node *, BaseSyntaxNode * > cache;47 44 48 45 template<typename T> … … 52 49 template<typename U> 53 50 T * accept1( const ast::ptr<U> & ptr ) { 54 if ( ! ptr ) return nullptr;55 51 ptr->accept( visitor ); 56 52 T * ret = strict_dynamic_cast< T * >( visitor.node ); … … 91 87 } 92 88 93 /// get new qualifiers from old type94 Type::Qualifiers cv( const ast::Type * ty ) { return { ty->qualifiers.val }; }95 96 template<typename NewT, typename OldT>97 NewT * cached( OldT * old ) {98 auto it = cache.find( old );99 // doesn't update cache, that should be handled by the accept function100 ast::Node * nw = it == cache.end() ? getAccept1< NewT >( old ) : it->second;101 return strict_dynamic_cast< NewT * >( nw );102 }103 104 89 public: 105 90 Declaration * decl( const ast::Decl * declNode ) { … … 108 93 109 94 private: 95 void declPostamble( Declaration * decl, const ast::Decl * node ) { 96 decl->location = node->location; 97 // name comes from constructor 98 // linkage comes from constructor 99 decl->extension = node->extension; 100 decl->uniqueId = node->uniqueId; 101 // storageClasses comes from constructor 102 this->node = decl; 103 } 104 105 const ast::DeclWithType * declWithTypePostamble ( 106 DeclarationWithType * decl, const ast::DeclWithType * node ) { 107 declPostamble( decl, node ); 108 decl->mangleName = node->mangleName; 109 decl->scopeLevel = node->scopeLevel; 110 decl->asmName = get<Expression>().accept1( node->asmName ); 111 // attributes comes from constructor 112 decl->isDeleted = node->isDeleted; 113 // fs comes from constructor 114 return nullptr; 115 } 116 110 117 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 111 (void)node; 112 return nullptr; 118 auto decl = new ObjectDecl( 119 node->name, 120 Type::StorageClasses( node->storage.val ), 121 LinkageSpec::Spec( node->linkage.val ), 122 get<Expression>().accept1( node->bitfieldWidth ), 123 get<Type>().accept1( node->type ), 124 get<Initializer>().accept1( node->init ), 125 get<Attribute>().acceptL( node->attributes ), 126 Type::FuncSpecifiers( node->funcSpec.val ) 127 ); 128 return declWithTypePostamble( decl, node ); 113 129 } 114 130 115 131 const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 116 (void)node; 132 auto decl = new FunctionDecl( 133 node->name, 134 Type::StorageClasses( node->storage.val ), 135 LinkageSpec::Spec( node->linkage.val ), 136 get<FunctionType>().accept1( node->type ), 137 get<CompoundStmt>().accept1( node->stmts ), 138 get<Attribute>().acceptL( node->attributes ), 139 Type::FuncSpecifiers( node->funcSpec.val ) 140 ); 141 decl->withExprs = get<Expression>().acceptL( node->withExprs ); 142 return declWithTypePostamble( decl, node ); 143 } 144 145 // NamedTypeDecl 146 const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) { 147 declPostamble( decl, node ); 148 // base comes from constructor 149 decl->parameters = get<TypeDecl>().acceptL( node->params ); 150 decl->assertions = get<DeclarationWithType>().acceptL( node->assertions ); 151 return nullptr; 152 } 153 154 const ast::Decl * visit( const ast::TypeDecl * node ) override final { 155 TypeDecl::Kind kind; 156 switch (node->kind) { 157 case ast::TypeVar::Dtype: 158 kind = TypeDecl::Dtype; 159 break; 160 case ast::TypeVar::Ftype: 161 kind = TypeDecl::Ftype; 162 break; 163 case ast::TypeVar::Ttype: 164 kind = TypeDecl::Ttype; 165 break; 166 default: 167 assertf(false, "Invalid ast::TypeVar::Kind: %d\n", node->kind); 168 }; 169 auto decl = new TypeDecl( 170 node->name, 171 Type::StorageClasses( node->storage.val ), 172 get<Type>().accept1( node->base ), 173 kind, 174 node->sized, 175 get<Type>().accept1( node->init ) 176 ); 177 return namedTypePostamble( decl, node ); 178 } 179 180 const ast::Decl * visit( const ast::TypedefDecl * node ) override final { 181 auto decl = new TypedefDecl( 182 node->name, 183 node->location, 184 Type::StorageClasses( node->storage.val ), 185 get<Type>().accept1( node->base ), 186 LinkageSpec::Spec( node->linkage.val ) 187 ); 188 return namedTypePostamble( decl, node ); 189 } 190 191 const ast::Decl * aggregatePostamble( AggregateDecl * decl, const ast::AggregateDecl * node ) { 192 decl->members = get<Declaration>().acceptL( node->members ); 193 decl->parameters = get<TypeDecl>().acceptL( node->params ); 194 decl->body = node->body; 195 // attributes come from constructor 196 // TODO: Need caching for: decl->parent = node->parent; 117 197 return nullptr; 118 198 } 119 199 120 200 const ast::Decl * visit( const ast::StructDecl * node ) override final { 121 (void)node; 122 return nullptr; 201 auto decl = new StructDecl( 202 node->name, 203 node->kind, 204 get<Attribute>().acceptL( node->attributes ), 205 LinkageSpec::Spec( node->linkage.val ) 206 ); 207 return aggregatePostamble( decl, node ); 123 208 } 124 209 125 210 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 126 (void)node; 127 return nullptr; 211 auto decl = new UnionDecl( 212 node->name, 213 get<Attribute>().acceptL( node->attributes ), 214 LinkageSpec::Spec( node->linkage.val ) 215 ); 216 return aggregatePostamble( decl, node ); 128 217 } 129 218 130 219 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 131 (void)node; 132 return nullptr; 220 auto decl = new EnumDecl( 221 node->name, 222 get<Attribute>().acceptL( node->attributes ), 223 LinkageSpec::Spec( node->linkage.val ) 224 ); 225 return aggregatePostamble( decl, node ); 133 226 } 134 227 135 228 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 136 (void)node; 137 return nullptr; 138 } 139 140 const ast::Decl * visit( const ast::TypeDecl * node ) override final { 141 (void)node; 142 return nullptr; 143 } 144 145 const ast::Decl * visit( const ast::TypedefDecl * node ) override final { 146 (void)node; 147 return nullptr; 229 auto decl = new TraitDecl( 230 node->name, 231 {}, 232 LinkageSpec::Spec( node->linkage.val ) 233 ); 234 return aggregatePostamble( decl, node ); 148 235 } 149 236 150 237 const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { 151 (void)node; 238 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) ); 239 declPostamble( decl, node ); 152 240 return nullptr; 153 241 } 154 242 155 243 const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { 156 (void)node; 157 return nullptr; 158 } 159 160 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 161 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 244 auto decl = new StaticAssertDecl( 245 get<Expression>().accept1( node->cond ), 246 get<ConstantExpr>().accept1( node->msg ) 247 ); 248 declPostamble( decl, node ); 249 return nullptr; 250 } 251 252 const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) { 162 253 stmt->location = node->location; 163 254 stmt->labels = makeLabelL( stmt, node->labels ); … … 166 257 } 167 258 259 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 260 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 261 stmtPostamble( stmt, node ); 262 return nullptr; 263 } 264 168 265 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 169 266 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); 170 stmt->location = node->location; 171 stmt->labels = makeLabelL( stmt, node->labels ); 172 this->node = stmt; 173 return nullptr; 267 return stmtPostamble( stmt, node ); 174 268 } 175 269 … … 183 277 makeLabelL( nullptr, node->gotoLabels ) // What are these labelling? 184 278 ); 185 stmt->location = node->location; 186 stmt->labels = makeLabelL( stmt, node->labels ); 187 this->node = stmt; 188 return nullptr; 279 return stmtPostamble( stmt, node ); 189 280 } 190 281 191 282 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 192 283 auto stmt = new DirectiveStmt( node->directive ); 193 stmt->location = node->location; 194 stmt->labels = makeLabelL( stmt, node->labels ); 195 this->node = stmt; 196 return nullptr; 284 return stmtPostamble( stmt, node ); 197 285 } 198 286 … … 204 292 get<Statement>().acceptL( node->inits ) 205 293 ); 206 stmt->location = node->location; 207 stmt->labels = makeLabelL( stmt, node->labels ); 208 this->node = stmt; 209 return nullptr; 294 return stmtPostamble( stmt, node ); 210 295 } 211 296 … … 215 300 get<Statement>().acceptL( node->stmts ) 216 301 ); 217 stmt->location = node->location; 218 stmt->labels = makeLabelL( stmt, node->labels ); 219 this->node = stmt; 220 return nullptr; 302 return stmtPostamble( stmt, node ); 221 303 } 222 304 … … 227 309 node->isDefault() 228 310 ); 229 stmt->location = node->location; 230 stmt->labels = makeLabelL( stmt, node->labels ); 231 this->node = stmt; 232 return nullptr; 311 return stmtPostamble( stmt, node ); 233 312 } 234 313 … … 241 320 node->isDoWhile 242 321 ); 243 stmt->location = node->location; 244 stmt->labels = makeLabelL( stmt, node->labels ); 245 this->node = stmt; 246 return nullptr; 322 return stmtPostamble( stmt, node ); 247 323 } 248 324 … … 254 330 get<Statement>().accept1( node->body ) 255 331 ); 256 stmt->location = node->location; 257 stmt->labels = makeLabelL( stmt, node->labels ); 258 this->node = stmt; 259 return nullptr; 332 return stmtPostamble( stmt, node ); 260 333 } 261 334 … … 286 359 stmt->target = makeLabel( stmt, node->target ); 287 360 } 288 stmt->location = node->location; 289 stmt->labels = makeLabelL( stmt, node->labels ); 290 this->node = stmt; 291 return nullptr; 361 return stmtPostamble( stmt, node ); 292 362 } 293 363 294 364 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 295 365 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 296 stmt->location = node->location; 297 stmt->labels = makeLabelL( stmt, node->labels ); 298 this->node = stmt; 299 return nullptr; 366 return stmtPostamble( stmt, node ); 300 367 } 301 368 … … 317 384 get<Expression>().accept1( node->target ) 318 385 ); 319 stmt->location = node->location; 320 stmt->labels = makeLabelL( stmt, node->labels ); 321 this->node = stmt; 322 return nullptr; 386 return stmtPostamble( stmt, node ); 323 387 } 324 388 … … 330 394 get<FinallyStmt>().accept1( node->finally ) 331 395 ); 332 stmt->location = node->location; 333 stmt->labels = makeLabelL( stmt, node->labels ); 334 this->node = stmt; 335 return nullptr; 396 return stmtPostamble( stmt, node ); 336 397 } 337 398 … … 354 415 get<Statement>().accept1( node->body ) 355 416 ); 356 stmt->location = node->location; 357 stmt->labels = makeLabelL( stmt, node->labels ); 358 this->node = stmt; 359 return nullptr; 417 return stmtPostamble( stmt, node ); 360 418 } 361 419 362 420 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 363 421 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 364 stmt->location = node->location; 365 stmt->labels = makeLabelL( stmt, node->labels ); 366 this->node = stmt; 367 return nullptr; 422 return stmtPostamble( stmt, node ); 368 423 } 369 424 … … 373 428 for ( auto clause : node->clauses ) { 374 429 stmt->clauses.push_back({{ 375 get<Expression>().accept1( clause.target.func tion),376 get<Expression>().acceptL( clause.target.arg uments ),430 get<Expression>().accept1( clause.target.func ), 431 get<Expression>().acceptL( clause.target.args ), 377 432 }, 378 433 get<Statement>().accept1( clause.stmt ), … … 389 444 get<Expression>().accept1( node->orElse.cond ), 390 445 }; 391 stmt->location = node->location; 392 stmt->labels = makeLabelL( stmt, node->labels ); 393 this->node = stmt; 394 return nullptr; 446 return stmtPostamble( stmt, node ); 395 447 } 396 448 … … 400 452 get<Statement>().accept1( node->stmt ) 401 453 ); 402 stmt->location = node->location; 403 stmt->labels = makeLabelL( stmt, node->labels ); 404 this->node = stmt; 405 return nullptr; 454 return stmtPostamble( stmt, node ); 406 455 } 407 456 408 457 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 409 458 auto stmt = new NullStmt(); 410 stmt->location = node->location; 411 stmt->labels = makeLabelL( stmt, node->labels ); 412 this->node = stmt; 459 stmtPostamble( stmt, node ); 413 460 return nullptr; 414 461 } … … 416 463 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 417 464 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 418 stmt->location = node->location; 419 stmt->labels = makeLabelL( stmt, node->labels ); 420 this->node = stmt; 421 return nullptr; 465 return stmtPostamble( stmt, node ); 422 466 } 423 467 … … 427 471 } 428 472 473 TypeSubstitution * convertTypeSubstitution(const ast::TypeSubstitution * src) { 474 475 TypeSubstitution *rslt = new TypeSubstitution(); 476 477 for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) { 478 rslt->add( src_i->first, 479 get<Type>().accept1(src_i->second) ); 480 } 481 482 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) { 483 rslt->addVar( src_i->first, 484 get<Expression>().accept1(src_i->second) ); 485 } 486 487 return rslt; 488 } 489 490 void convertInferUnion(std::map<UniqueId,ParamEntry> &tgtInferParams, 491 std::vector<UniqueId> &tgtResnSlots, 492 const ast::Expr::InferUnion &srcInferred ) { 493 494 assert( tgtInferParams.empty() ); 495 assert( tgtResnSlots.empty() ); 496 497 if ( srcInferred.mode == ast::Expr::InferUnion::Params ) { 498 const ast::InferredParams &srcParams = srcInferred.inferParamsConst(); 499 for (auto srcParam : srcParams) { 500 tgtInferParams[srcParam.first] = ParamEntry( 501 srcParam.second.decl, 502 get<Type>().accept1(srcParam.second.actualType), 503 get<Type>().accept1(srcParam.second.formalType), 504 get<Expression>().accept1(srcParam.second.expr) 505 ); 506 } 507 } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots ) { 508 const ast::ResnSlots &srcSlots = srcInferred.resnSlotsConst(); 509 for (auto srcSlot : srcSlots) { 510 tgtResnSlots.push_back(srcSlot); 511 } 512 } 513 } 514 515 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { 516 517 tgt->location = src->location; 518 519 tgt->result = get<Type>().accept1(src->result); 520 tgt->env = convertTypeSubstitution(src->env); 521 522 tgt->extension = src->extension; 523 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 524 525 return tgt; 526 } 527 429 528 const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { 430 (void)node; 529 auto expr = visitBaseExpr( node, 530 new ApplicationExpr( 531 get<Expression>().accept1(node->func), 532 get<Expression>().acceptL(node->args) 533 ) 534 ); 535 this->node = expr; 431 536 return nullptr; 432 537 } 433 538 434 539 const ast::Expr * visit( const ast::UntypedExpr * node ) override final { 435 (void)node; 540 auto expr = visitBaseExpr( node, 541 new UntypedExpr( 542 get<Expression>().accept1(node->func), 543 get<Expression>().acceptL(node->args) 544 ) 545 ); 546 this->node = expr; 436 547 return nullptr; 437 548 } 438 549 439 550 const ast::Expr * visit( const ast::NameExpr * node ) override final { 440 (void)node; 551 auto expr = visitBaseExpr( node, 552 new NameExpr( 553 node->name 554 ) 555 ); 556 this->node = expr; 441 557 return nullptr; 442 558 } … … 613 729 614 730 const ast::Type * visit( const ast::VoidType * node ) override final { 615 this->node = new VoidType{ cv( node ) };731 (void)node; 616 732 return nullptr; 617 733 } 618 734 619 735 const ast::Type * visit( const ast::BasicType * node ) override final { 620 this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };736 (void)node; 621 737 return nullptr; 622 738 } 623 739 624 740 const ast::Type * visit( const ast::PointerType * node ) override final { 625 this->node = new PointerType{ 626 cv( node ), 627 get<Type>().accept1( node->base ), 628 get<Expression>().accept1( node->dimension ), 629 node->isVarLen, 630 node->isStatic 631 }; 741 (void)node; 632 742 return nullptr; 633 743 } 634 744 635 745 const ast::Type * visit( const ast::ArrayType * node ) override final { 636 this->node = new ArrayType{ 637 cv( node ), 638 get<Type>().accept1( node->base ), 639 get<Expression>().accept1( node->dimension ), 640 node->isVarLen, 641 node->isStatic 642 }; 746 (void)node; 643 747 return nullptr; 644 748 } 645 749 646 750 const ast::Type * visit( const ast::ReferenceType * node ) override final { 647 this->node = new ReferenceType{ 648 cv( node ), 649 get<Type>().accept1( node->base ) 650 }; 751 (void)node; 651 752 return nullptr; 652 753 } 653 754 654 755 const ast::Type * visit( const ast::QualifiedType * node ) override final { 655 this->node = new QualifiedType{ 656 cv( node ), 657 get<Type>().accept1( node->parent ), 658 get<Type>().accept1( node->child ) 659 }; 756 (void)node; 660 757 return nullptr; 661 758 } 662 759 663 760 const ast::Type * visit( const ast::FunctionType * node ) override final { 664 auto ty = new FunctionType { cv( node ), node->isVarArgs }; 665 ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 666 ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 667 ty->forall = get<TypeDecl>().acceptL( node->forall ); 668 node = ty; 761 (void)node; 669 762 return nullptr; 670 763 } … … 774 867 } 775 868 private: 776 /// conversion output777 869 ast::Node * node; 778 /// cache of nodes that might be referenced by readonly<> for de-duplication779 std::unordered_map< BaseSyntaxNode *, ast::Node * > cache;780 870 781 871 // Local Utilities: … … 783 873 template<typename NewT, typename OldT> 784 874 NewT * getAccept1( OldT old ) { 785 if ( ! old ) return nullptr;786 875 old->accept(*this); 787 876 return strict_dynamic_cast< NewT * >( node ); … … 824 913 # define GET_LABELS_V(labels) \ 825 914 to<std::vector>::from( make_labels( std::move( labels ) ) ) 826 827 static ast::CV::Qualifiers cv( Type * ty ) { return { ty->get_qualifiers().val }; }828 829 template<typename NewT, typename OldT>830 NewT * cached( OldT * old ) {831 auto it = cache.find( old );832 // doesn't update cache, that should be handled by the accept function833 ast::Node * nw = it == cache.end() ? getAccept1< NewT >( old ) : it->second;834 return strict_dynamic_cast< NewT * >( nw );835 }836 915 837 916 // Now all the visit functions: … … 1236 1315 getAccept1<ast::Expr>(old_i->second) ); 1237 1316 } 1238 } 1239 1240 void convertInferUnion(ast::Expr::InferUnion &nwInferred, InferredParams oldInferParams, const std::vector<UniqueId> &oldResnSlots) { 1241 1242 (void) nwInferred; 1243 (void) oldInferParams; 1244 (void) oldResnSlots; 1245 1246 // TODO 1317 1318 return rslt; 1319 } 1320 1321 void convertInferUnion(ast::Expr::InferUnion &newInferred, 1322 const std::map<UniqueId,ParamEntry> &oldInferParams, 1323 const std::vector<UniqueId> &oldResnSlots) { 1324 1325 assert( oldInferParams.empty() || oldResnSlots.empty() ); 1326 assert( newInferred.mode == ast::Expr::InferUnion::Empty ); 1327 1328 if ( !oldInferParams.empty() ) { 1329 ast::InferredParams &tgt = newInferred.inferParams(); 1330 for (auto old : oldInferParams) { 1331 tgt[old.first] = ast::ParamEntry( 1332 old.second.decl, 1333 getAccept1<ast::Type>(old.second.actualType), 1334 getAccept1<ast::Type>(old.second.formalType), 1335 getAccept1<ast::Expr>(old.second.expr) 1336 ); 1337 } 1338 } else if ( !oldResnSlots.empty() ) { 1339 ast::ResnSlots &tgt = newInferred.resnSlots(); 1340 for (auto old : oldResnSlots) { 1341 tgt.push_back(old); 1342 } 1343 } 1247 1344 } 1248 1345 … … 1258 1355 } 1259 1356 1260 virtual void visit( ApplicationExpr * ) override final { 1261 // TODO 1262 } 1263 1264 virtual void visit( UntypedExpr * ) override final { 1265 // TODO 1357 virtual void visit( ApplicationExpr * old ) override final { 1358 this->node = visitBaseExpr( old, 1359 new ast::ApplicationExpr( 1360 old->location, 1361 GET_ACCEPT_1(function, Expr), 1362 GET_ACCEPT_V(args, Expr) 1363 ) 1364 ); 1365 } 1366 1367 virtual void visit( UntypedExpr * old ) override final { 1368 this->node = visitBaseExpr( old, 1369 new ast::UntypedExpr( 1370 old->location, 1371 GET_ACCEPT_1(function, Expr), 1372 GET_ACCEPT_V(args, Expr) 1373 ) 1374 ); 1266 1375 } 1267 1376 … … 1275 1384 } 1276 1385 1277 virtual void visit( CastExpr * ) override final { 1278 // TODO ... (rest) 1386 virtual void visit( CastExpr * old ) override final { 1387 this->node = visitBaseExpr( old, 1388 new ast::CastExpr( 1389 old->location, 1390 nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr 1391 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast 1392 ) 1393 ); 1279 1394 } 1280 1395 … … 1411 1526 } 1412 1527 1413 virtual void visit( VoidType * old ) override final { 1414 this->node = new ast::VoidType{ cv( old ) }; 1415 } 1416 1417 virtual void visit( BasicType * old ) override final { 1418 this->node = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) }; 1419 } 1420 1421 virtual void visit( PointerType * old ) override final { 1422 this->node = new ast::PointerType{ 1423 GET_ACCEPT_1( base, Type ), 1424 GET_ACCEPT_1( dimension, Expr ), 1425 (ast::LengthFlag)old->isVarLen, 1426 (ast::DimensionFlag)old->isStatic, 1427 cv( old ) 1428 }; 1429 } 1430 1431 virtual void visit( ArrayType * old ) override final { 1432 this->node = new ast::ArrayType{ 1433 GET_ACCEPT_1( base, Type ), 1434 GET_ACCEPT_1( dimension, Expr ), 1435 (ast::LengthFlag)old->isVarLen, 1436 (ast::DimensionFlag)old->isStatic, 1437 cv( old ) 1438 }; 1439 } 1440 1441 virtual void visit( ReferenceType * old ) override final { 1442 this->node = new ast::ReferenceType{ 1443 GET_ACCEPT_1( base, Type ), 1444 cv( old ) 1445 }; 1446 } 1447 1448 virtual void visit( QualifiedType * old ) override final { 1449 this->node = new ast::QualifiedType{ 1450 GET_ACCEPT_1( parent, Type ), 1451 GET_ACCEPT_1( child, Type ), 1452 cv( old ) 1453 }; 1454 } 1455 1456 virtual void visit( FunctionType * old ) override final { 1457 auto ty = new ast::FunctionType { 1458 (ast::ArgumentFlag)old->isVarArgs, 1459 cv( old ) 1460 }; 1461 ty->returns = GET_ACCEPT_V( returnVals, DeclWithType ); 1462 ty->params = GET_ACCEPT_V( parameters, DeclWithType ); 1463 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 1464 this->node = ty; 1465 } 1466 1467 void postvisit( ReferenceToType * old, ast::ReferenceToType * ty ) { 1468 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 1469 ty->params = GET_ACCEPT_V( parameters, Expr ); 1470 ty->hoistType = old->hoistType; 1471 } 1472 1473 virtual void visit( StructInstType * old ) override final { 1474 auto ty = new ast::StructInstType{ 1475 cached< ast::StructDecl >( old->baseStruct ), 1476 cv( old ), 1477 GET_ACCEPT_V( attributes, Attribute ) 1478 }; 1479 postvisit( old, ty ); 1480 this->node = ty; 1481 } 1482 1483 virtual void visit( UnionInstType * old ) override final { 1484 auto ty = new ast::UnionInstType{ 1485 cached< ast::UnionDecl >( old->baseUnion ), 1486 cv( old ), 1487 GET_ACCEPT_V( attributes, Attribute ) 1488 }; 1489 postvisit( old, ty ); 1490 this->node = ty; 1491 } 1492 1493 virtual void visit( EnumInstType * old ) override final { 1494 auto ty = new ast::EnumInstType{ 1495 cached< ast::EnumDecl >( old->baseEnum ), 1496 cv( old ), 1497 GET_ACCEPT_V( attributes, Attribute ) 1498 }; 1499 postvisit( old, ty ); 1500 this->node = ty; 1501 } 1502 1503 virtual void visit( TraitInstType * old ) override final { 1504 auto ty = new ast::TraitInstType{ 1505 cached< ast::TraitDecl >( old->baseTrait ), 1506 cv( old ), 1507 GET_ACCEPT_V( attributes, Attribute ) 1508 }; 1509 postvisit( old, ty ); 1510 this->node = ty; 1511 } 1512 1513 virtual void visit( TypeInstType * old ) override final { 1514 auto ty = new ast::TypeInstType{ 1515 cached< ast::TypeDecl >( old->baseStruct ), 1516 cv( old ), 1517 GET_ACCEPT_V( attributes, Attribute ) 1518 }; 1519 postvisit( old, ty ); 1520 this->node = ty; 1528 virtual void visit( VoidType * ) override final { 1529 1530 } 1531 1532 virtual void visit( BasicType * ) override final { 1533 1534 } 1535 1536 virtual void visit( PointerType * ) override final { 1537 1538 } 1539 1540 virtual void visit( ArrayType * ) override final { 1541 1542 } 1543 1544 virtual void visit( ReferenceType * ) override final { 1545 1546 } 1547 1548 virtual void visit( QualifiedType * ) override final { 1549 1550 } 1551 1552 virtual void visit( FunctionType * ) override final { 1553 1554 } 1555 1556 virtual void visit( StructInstType * ) override final { 1557 1558 } 1559 1560 virtual void visit( UnionInstType * ) override final { 1561 1562 } 1563 1564 virtual void visit( EnumInstType * ) override final { 1565 1566 } 1567 1568 virtual void visit( TraitInstType * ) override final { 1569 1570 } 1571 1572 virtual void visit( TypeInstType * ) override final { 1573 1521 1574 } 1522 1575
Note:
See TracChangeset
for help on using the changeset viewer.