Changes in src/AST/Convert.cpp [112fe04:d148778]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r112fe04 rd148778 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue May 21 15:30:00 201913 // Update Count : 512 // Last Modified On : Fri May 17 16:01:00 2019 13 // Update Count : 4 14 14 // 15 15 16 16 #include "Convert.hpp" 17 18 #include <unordered_map> 17 19 18 20 #include "AST/Attribute.hpp" … … 42 44 class ConverterNewToOld : public ast::Visitor { 43 45 BaseSyntaxNode * node = nullptr; 46 std::unordered_map< ast::Node *, BaseSyntaxNode * > cache; 44 47 45 48 template<typename T> … … 49 52 template<typename U> 50 53 T * accept1( const ast::ptr<U> & ptr ) { 54 if ( ! ptr ) return nullptr; 51 55 ptr->accept( visitor ); 52 56 T * ret = strict_dynamic_cast< T * >( visitor.node ); … … 87 91 } 88 92 93 /// get new qualifiers from old type 94 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 function 100 ast::Node * nw = it == cache.end() ? getAccept1< NewT >( old ) : it->second; 101 return strict_dynamic_cast< NewT * >( nw ); 102 } 103 89 104 public: 90 105 Declaration * decl( const ast::Decl * declNode ) { … … 93 108 94 109 private: 95 void declPostamble( Declaration * decl, const ast::Decl * node ) {96 decl->location = node->location;97 // name comes from constructor98 // linkage comes from constructor99 decl->extension = node->extension;100 decl->uniqueId = node->uniqueId;101 // storageClasses comes from constructor102 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 constructor112 decl->isDeleted = node->isDeleted;113 // fs comes from constructor114 return nullptr;115 }116 117 110 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 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 ); 111 (void)node; 112 return nullptr; 129 113 } 130 114 131 115 const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 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 ); 116 (void)node; 117 return nullptr; 118 } 119 120 const ast::Decl * visit( const ast::StructDecl * node ) override final { 121 (void)node; 122 return nullptr; 123 } 124 125 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 126 (void)node; 127 return nullptr; 128 } 129 130 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 131 (void)node; 132 return nullptr; 133 } 134 135 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 136 (void)node; 151 137 return nullptr; 152 138 } 153 139 154 140 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 ); 141 (void)node; 142 return nullptr; 178 143 } 179 144 180 145 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; 197 return nullptr; 198 } 199 200 const ast::Decl * visit( const ast::StructDecl * node ) override final { 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 ); 208 } 209 210 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 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 ); 217 } 218 219 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 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 ); 226 } 227 228 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 229 auto decl = new TraitDecl( 230 node->name, 231 {}, 232 LinkageSpec::Spec( node->linkage.val ) 233 ); 234 return aggregatePostamble( decl, node ); 146 (void)node; 147 return nullptr; 235 148 } 236 149 237 150 const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { 238 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) ); 239 declPostamble( decl, node ); 151 (void)node; 240 152 return nullptr; 241 153 } 242 154 243 155 const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { 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 ) { 253 stmt->location = node->location; 254 stmt->labels = makeLabelL( stmt, node->labels ); 255 this->node = stmt; 156 (void)node; 256 157 return nullptr; 257 158 } … … 259 160 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 260 161 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 261 stmtPostamble( stmt, node ); 162 stmt->location = node->location; 163 stmt->labels = makeLabelL( stmt, node->labels ); 164 this->node = stmt; 262 165 return nullptr; 263 166 } … … 265 168 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 266 169 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); 267 return stmtPostamble( stmt, node ); 170 stmt->location = node->location; 171 stmt->labels = makeLabelL( stmt, node->labels ); 172 this->node = stmt; 173 return nullptr; 268 174 } 269 175 … … 277 183 makeLabelL( nullptr, node->gotoLabels ) // What are these labelling? 278 184 ); 279 return stmtPostamble( stmt, node ); 185 stmt->location = node->location; 186 stmt->labels = makeLabelL( stmt, node->labels ); 187 this->node = stmt; 188 return nullptr; 280 189 } 281 190 282 191 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 283 192 auto stmt = new DirectiveStmt( node->directive ); 284 return stmtPostamble( stmt, node ); 193 stmt->location = node->location; 194 stmt->labels = makeLabelL( stmt, node->labels ); 195 this->node = stmt; 196 return nullptr; 285 197 } 286 198 … … 292 204 get<Statement>().acceptL( node->inits ) 293 205 ); 294 return stmtPostamble( stmt, node ); 206 stmt->location = node->location; 207 stmt->labels = makeLabelL( stmt, node->labels ); 208 this->node = stmt; 209 return nullptr; 295 210 } 296 211 … … 300 215 get<Statement>().acceptL( node->stmts ) 301 216 ); 302 return stmtPostamble( stmt, node ); 217 stmt->location = node->location; 218 stmt->labels = makeLabelL( stmt, node->labels ); 219 this->node = stmt; 220 return nullptr; 303 221 } 304 222 … … 309 227 node->isDefault() 310 228 ); 311 return stmtPostamble( stmt, node ); 229 stmt->location = node->location; 230 stmt->labels = makeLabelL( stmt, node->labels ); 231 this->node = stmt; 232 return nullptr; 312 233 } 313 234 … … 320 241 node->isDoWhile 321 242 ); 322 return stmtPostamble( stmt, node ); 243 stmt->location = node->location; 244 stmt->labels = makeLabelL( stmt, node->labels ); 245 this->node = stmt; 246 return nullptr; 323 247 } 324 248 … … 330 254 get<Statement>().accept1( node->body ) 331 255 ); 332 return stmtPostamble( stmt, node ); 256 stmt->location = node->location; 257 stmt->labels = makeLabelL( stmt, node->labels ); 258 this->node = stmt; 259 return nullptr; 333 260 } 334 261 … … 359 286 stmt->target = makeLabel( stmt, node->target ); 360 287 } 361 return stmtPostamble( stmt, node ); 288 stmt->location = node->location; 289 stmt->labels = makeLabelL( stmt, node->labels ); 290 this->node = stmt; 291 return nullptr; 362 292 } 363 293 364 294 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 365 295 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 366 return stmtPostamble( stmt, node ); 296 stmt->location = node->location; 297 stmt->labels = makeLabelL( stmt, node->labels ); 298 this->node = stmt; 299 return nullptr; 367 300 } 368 301 … … 384 317 get<Expression>().accept1( node->target ) 385 318 ); 386 return stmtPostamble( stmt, node ); 319 stmt->location = node->location; 320 stmt->labels = makeLabelL( stmt, node->labels ); 321 this->node = stmt; 322 return nullptr; 387 323 } 388 324 … … 394 330 get<FinallyStmt>().accept1( node->finally ) 395 331 ); 396 return stmtPostamble( stmt, node ); 332 stmt->location = node->location; 333 stmt->labels = makeLabelL( stmt, node->labels ); 334 this->node = stmt; 335 return nullptr; 397 336 } 398 337 … … 415 354 get<Statement>().accept1( node->body ) 416 355 ); 417 return stmtPostamble( stmt, node ); 356 stmt->location = node->location; 357 stmt->labels = makeLabelL( stmt, node->labels ); 358 this->node = stmt; 359 return nullptr; 418 360 } 419 361 420 362 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 421 363 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 422 return stmtPostamble( stmt, node ); 364 stmt->location = node->location; 365 stmt->labels = makeLabelL( stmt, node->labels ); 366 this->node = stmt; 367 return nullptr; 423 368 } 424 369 … … 428 373 for ( auto clause : node->clauses ) { 429 374 stmt->clauses.push_back({{ 430 get<Expression>().accept1( clause.target.func ),431 get<Expression>().acceptL( clause.target.arg s ),375 get<Expression>().accept1( clause.target.function ), 376 get<Expression>().acceptL( clause.target.arguments ), 432 377 }, 433 378 get<Statement>().accept1( clause.stmt ), … … 444 389 get<Expression>().accept1( node->orElse.cond ), 445 390 }; 446 return stmtPostamble( stmt, node ); 391 stmt->location = node->location; 392 stmt->labels = makeLabelL( stmt, node->labels ); 393 this->node = stmt; 394 return nullptr; 447 395 } 448 396 … … 452 400 get<Statement>().accept1( node->stmt ) 453 401 ); 454 return stmtPostamble( stmt, node ); 402 stmt->location = node->location; 403 stmt->labels = makeLabelL( stmt, node->labels ); 404 this->node = stmt; 405 return nullptr; 455 406 } 456 407 457 408 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 458 409 auto stmt = new NullStmt(); 459 stmtPostamble( stmt, node ); 410 stmt->location = node->location; 411 stmt->labels = makeLabelL( stmt, node->labels ); 412 this->node = stmt; 460 413 return nullptr; 461 414 } … … 463 416 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 464 417 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 465 return stmtPostamble( stmt, node ); 418 stmt->location = node->location; 419 stmt->labels = makeLabelL( stmt, node->labels ); 420 this->node = stmt; 421 return nullptr; 466 422 } 467 423 … … 471 427 } 472 428 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 528 429 const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { 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; 430 (void)node; 536 431 return nullptr; 537 432 } 538 433 539 434 const ast::Expr * visit( const ast::UntypedExpr * node ) override final { 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; 435 (void)node; 547 436 return nullptr; 548 437 } 549 438 550 439 const ast::Expr * visit( const ast::NameExpr * node ) override final { 551 auto expr = visitBaseExpr( node, 552 new NameExpr( 553 node->name 554 ) 555 ); 556 this->node = expr; 440 (void)node; 557 441 return nullptr; 558 442 } … … 729 613 730 614 const ast::Type * visit( const ast::VoidType * node ) override final { 731 (void)node;615 this->node = new VoidType{ cv( node ) }; 732 616 return nullptr; 733 617 } 734 618 735 619 const ast::Type * visit( const ast::BasicType * node ) override final { 736 (void)node;620 this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind }; 737 621 return nullptr; 738 622 } 739 623 740 624 const ast::Type * visit( const ast::PointerType * node ) override final { 741 (void)node; 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 }; 742 632 return nullptr; 743 633 } 744 634 745 635 const ast::Type * visit( const ast::ArrayType * node ) override final { 746 (void)node; 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 }; 747 643 return nullptr; 748 644 } 749 645 750 646 const ast::Type * visit( const ast::ReferenceType * node ) override final { 751 (void)node; 647 this->node = new ReferenceType{ 648 cv( node ), 649 get<Type>().accept1( node->base ) 650 }; 752 651 return nullptr; 753 652 } 754 653 755 654 const ast::Type * visit( const ast::QualifiedType * node ) override final { 756 (void)node; 655 this->node = new QualifiedType{ 656 cv( node ), 657 get<Type>().accept1( node->parent ), 658 get<Type>().accept1( node->child ) 659 }; 757 660 return nullptr; 758 661 } 759 662 760 663 const ast::Type * visit( const ast::FunctionType * node ) override final { 761 (void)node; 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; 762 669 return nullptr; 763 670 } … … 867 774 } 868 775 private: 776 /// conversion output 869 777 ast::Node * node; 778 /// cache of nodes that might be referenced by readonly<> for de-duplication 779 std::unordered_map< BaseSyntaxNode *, ast::Node * > cache; 870 780 871 781 // Local Utilities: … … 873 783 template<typename NewT, typename OldT> 874 784 NewT * getAccept1( OldT old ) { 785 if ( ! old ) return nullptr; 875 786 old->accept(*this); 876 787 return strict_dynamic_cast< NewT * >( node ); … … 913 824 # define GET_LABELS_V(labels) \ 914 825 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 function 833 ast::Node * nw = it == cache.end() ? getAccept1< NewT >( old ) : it->second; 834 return strict_dynamic_cast< NewT * >( nw ); 835 } 915 836 916 837 // Now all the visit functions: … … 1315 1236 getAccept1<ast::Expr>(old_i->second) ); 1316 1237 } 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 } 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 1344 1247 } 1345 1248 … … 1355 1258 } 1356 1259 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 ); 1260 virtual void visit( ApplicationExpr * ) override final { 1261 // TODO 1262 } 1263 1264 virtual void visit( UntypedExpr * ) override final { 1265 // TODO 1375 1266 } 1376 1267 … … 1384 1275 } 1385 1276 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 ); 1277 virtual void visit( CastExpr * ) override final { 1278 // TODO ... (rest) 1394 1279 } 1395 1280 … … 1526 1411 } 1527 1412 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 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; 1574 1521 } 1575 1522
Note:
See TracChangeset
for help on using the changeset viewer.