Changeset 3f7e12cb for src/CodeGen/CodeGenerator.cc
- Timestamp:
- Nov 8, 2017, 5:43:33 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 954908d
- Parents:
- 78315272 (diff), e35f30a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r78315272 r3f7e12cb 287 287 void CodeGenerator::postvisit( TypeDecl * typeDecl ) { 288 288 assertf( ! genC, "TypeDecls should not reach code generation." ); 289 output << typeDecl->genTypeString() << " " << typeDecl-> get_name();290 if ( typeDecl-> get_kind() != TypeDecl::Any && typeDecl->get_sized()) {291 output << " | sized(" << typeDecl-> get_name()<< ")";292 } 293 if ( ! typeDecl-> get_assertions().empty() ) {289 output << typeDecl->genTypeString() << " " << typeDecl->name; 290 if ( typeDecl->sized ) { 291 output << " | sized(" << typeDecl->name << ")"; 292 } 293 if ( ! typeDecl->assertions.empty() ) { 294 294 output << " | { "; 295 genCommaList( typeDecl->get_assertions().begin(), typeDecl->get_assertions().end() ); 295 for ( DeclarationWithType * assert : typeDecl->assertions ) { 296 assert->accept( *visitor ); 297 output << "; "; 298 } 296 299 output << " }"; 297 300 } … … 443 446 void CodeGenerator::postvisit( UntypedExpr * untypedExpr ) { 444 447 extension( untypedExpr ); 445 if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr-> get_function()) ) {448 if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) { 446 449 OperatorInfo opInfo; 447 if ( operatorLookup( nameExpr-> get_name(), opInfo ) ) {448 std::list< Expression* >::iterator arg = untypedExpr-> get_args().begin();450 if ( operatorLookup( nameExpr->name, opInfo ) ) { 451 std::list< Expression* >::iterator arg = untypedExpr->args.begin(); 449 452 switch ( opInfo.type ) { 450 453 case OT_INDEX: 451 assert( untypedExpr-> get_args().size() == 2 );454 assert( untypedExpr->args.size() == 2 ); 452 455 (*arg++)->accept( *visitor ); 453 456 output << "["; … … 461 464 case OT_CTOR: 462 465 case OT_DTOR: 463 if ( untypedExpr-> get_args().size() == 1 ) {466 if ( untypedExpr->args.size() == 1 ) { 464 467 // the expression fed into a single parameter constructor or destructor may contain side 465 468 // effects, so must still output this expression … … 480 483 (*arg++)->accept( *visitor ); 481 484 output << opInfo.symbol << "{ "; 482 genCommaList( arg, untypedExpr-> get_args().end() );485 genCommaList( arg, untypedExpr->args.end() ); 483 486 output << "}) /* " << opInfo.inputName << " */"; 484 487 } // if … … 488 491 case OT_PREFIXASSIGN: 489 492 case OT_LABELADDRESS: 490 assert( untypedExpr-> get_args().size() == 1 );493 assert( untypedExpr->args.size() == 1 ); 491 494 output << "("; 492 495 output << opInfo.symbol; … … 497 500 case OT_POSTFIX: 498 501 case OT_POSTFIXASSIGN: 499 assert( untypedExpr-> get_args().size() == 1 );502 assert( untypedExpr->args.size() == 1 ); 500 503 (*arg)->accept( *visitor ); 501 504 output << opInfo.symbol; … … 504 507 case OT_INFIX: 505 508 case OT_INFIXASSIGN: 506 assert( untypedExpr-> get_args().size() == 2 );509 assert( untypedExpr->args.size() == 2 ); 507 510 output << "("; 508 511 (*arg++)->accept( *visitor ); … … 517 520 } // switch 518 521 } else { 519 if ( nameExpr->get_name() == "..." ) { // case V1 ... V2 or case V1~V2 520 assert( untypedExpr->get_args().size() == 2 ); 521 (*untypedExpr->get_args().begin())->accept( *visitor ); 522 output << " ... "; 523 (*--untypedExpr->get_args().end())->accept( *visitor ); 524 } else { // builtin routines 525 nameExpr->accept( *visitor ); 526 output << "("; 527 genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() ); 528 output << ")"; 529 } // if 522 // builtin routines 523 nameExpr->accept( *visitor ); 524 output << "("; 525 genCommaList( untypedExpr->args.begin(), untypedExpr->args.end() ); 526 output << ")"; 530 527 } // if 531 528 } else { 532 untypedExpr-> get_function()->accept( *visitor );529 untypedExpr->function->accept( *visitor ); 533 530 output << "("; 534 genCommaList( untypedExpr-> get_args().begin(), untypedExpr->get_args().end() );531 genCommaList( untypedExpr->args.begin(), untypedExpr->args.end() ); 535 532 output << ")"; 536 533 } // if … … 538 535 539 536 void CodeGenerator::postvisit( RangeExpr * rangeExpr ) { 540 rangeExpr-> get_low()->accept( *visitor );537 rangeExpr->low->accept( *visitor ); 541 538 output << " ... "; 542 rangeExpr-> get_high()->accept( *visitor );539 rangeExpr->high->accept( *visitor ); 543 540 } 544 541 … … 546 543 extension( nameExpr ); 547 544 OperatorInfo opInfo; 548 if ( operatorLookup( nameExpr->get_name(), opInfo ) ) { 549 assert( opInfo.type == OT_CONSTANT ); 550 output << opInfo.symbol; 545 if ( operatorLookup( nameExpr->name, opInfo ) ) { 546 if ( opInfo.type == OT_CONSTANT ) { 547 output << opInfo.symbol; 548 } else { 549 output << opInfo.outputName; 550 } 551 551 } else { 552 552 output << nameExpr->get_name(); … … 885 885 886 886 void CodeGenerator::postvisit( CaseStmt * caseStmt ) { 887 updateLocation( caseStmt ); 888 output << indent; 887 889 if ( caseStmt->isDefault()) { 888 890 output << "default"; … … 947 949 output << ";"; 948 950 } 951 void CodeGenerator::postvisit( CatchStmt * stmt ) { 952 assertf( ! genC, "Catch statements should not reach code generation." ); 953 954 output << ((stmt->get_kind() == CatchStmt::Terminate) ? 955 "catch" : "catchResume"); 956 output << "( "; 957 stmt->decl->accept( *visitor ); 958 output << " ) "; 959 960 if( stmt->cond ) { 961 output << "if/when(?) ("; 962 stmt->cond->accept( *visitor ); 963 output << ") "; 964 } 965 stmt->body->accept( *visitor ); 966 } 967 968 void CodeGenerator::postvisit( WaitForStmt * stmt ) { 969 assertf( ! genC, "Waitfor statements should not reach code generation." ); 970 971 bool first = true; 972 for( auto & clause : stmt->clauses ) { 973 if(first) { output << "or "; first = false; } 974 if( clause.condition ) { 975 output << "when("; 976 stmt->timeout.condition->accept( *visitor ); 977 output << ") "; 978 } 979 output << "waitfor("; 980 clause.target.function->accept( *visitor ); 981 for( Expression * expr : clause.target.arguments ) { 982 output << ","; 983 expr->accept( *visitor ); 984 } 985 output << ") "; 986 clause.statement->accept( *visitor ); 987 } 988 989 if( stmt->timeout.statement ) { 990 output << "or "; 991 if( stmt->timeout.condition ) { 992 output << "when("; 993 stmt->timeout.condition->accept( *visitor ); 994 output << ") "; 995 } 996 output << "timeout("; 997 stmt->timeout.time->accept( *visitor ); 998 output << ") "; 999 stmt->timeout.statement->accept( *visitor ); 1000 } 1001 1002 if( stmt->orelse.statement ) { 1003 output << "or "; 1004 if( stmt->orelse.condition ) { 1005 output << "when("; 1006 stmt->orelse.condition->accept( *visitor ); 1007 output << ")"; 1008 } 1009 output << "else "; 1010 stmt->orelse.statement->accept( *visitor ); 1011 } 1012 } 1013 949 1014 950 1015 void CodeGenerator::postvisit( WhileStmt * whileStmt ) { … … 1025 1090 } 1026 1091 } // namespace CodeGen 1092 1093 1094 unsigned Indenter::tabsize = 2; 1095 1096 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) { 1097 if ( node ) { 1098 node->print( out ); 1099 } else { 1100 out << "nullptr"; 1101 } 1102 return out; 1103 } 1027 1104 1028 1105 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.