Changeset 0bd3faf
- Timestamp:
- Nov 13, 2023, 1:40:12 PM (22 months ago)
- Branches:
- master
- Children:
- 6ea85b22
- Parents:
- 25f2798
- Location:
- src
- Files:
-
- 42 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/SymbolTable.cpp
r25f2798 r0bd3faf 39 39 static inline auto stats() { 40 40 using namespace Stats::Counters; 41 static auto group = build<CounterGroup>(" Indexers");41 static auto group = build<CounterGroup>("Symbol Tables"); 42 42 static struct { 43 43 SimpleCounter * count; -
src/AST/SymbolTable.hpp
r25f2798 r0bd3faf 88 88 using Ptr = std::shared_ptr<const SymbolTable>; 89 89 90 Ptr prevScope; ///< Indexerfor parent scope90 Ptr prevScope; ///< Symbol Table for parent scope 91 91 unsigned long scope; ///< Scope index of this indexer 92 92 unsigned long repScope; ///< Scope index of currently represented scope -
src/CodeGen/CodeGeneratorNew.cpp
r25f2798 r0bd3faf 24 24 namespace CodeGen { 25 25 26 int CodeGenerator _new::tabsize = 4;26 int CodeGenerator::tabsize = 4; 27 27 28 28 // The kinds of statements that should be followed by whitespace. … … 35 35 } 36 36 37 void CodeGenerator _new::extension( ast::Expr const * expr ) {37 void CodeGenerator::extension( ast::Expr const * expr ) { 38 38 if ( expr->extension ) output << "__extension__ "; 39 39 } 40 40 41 void CodeGenerator _new::extension( ast::Decl const * decl ) {41 void CodeGenerator::extension( ast::Decl const * decl ) { 42 42 if ( decl->extension ) output << "__extension__ "; 43 43 } 44 44 45 void CodeGenerator _new::asmName( ast::DeclWithType const * decl ) {45 void CodeGenerator::asmName( ast::DeclWithType const * decl ) { 46 46 if ( auto asmName = decl->asmName.as<ast::ConstantExpr>() ) { 47 47 output << " asm ( " << asmName->rep << " )"; … … 49 49 } 50 50 51 CodeGenerator _new::LabelPrinter & CodeGenerator_new::LabelPrinter::operator()(51 CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()( 52 52 std::vector<ast::Label> const & l ) { 53 53 labels = &l; … … 55 55 } 56 56 57 std::ostream & CodeGenerator _new::LabelPrinter::operator()( std::ostream & output ) const {57 std::ostream & CodeGenerator::LabelPrinter::operator()( std::ostream & output ) const { 58 58 const std::vector<ast::Label> & labels = *this->labels; 59 59 for ( const ast::Label & label : labels ) { … … 66 66 // Using updateLocation at the beginning of a node and endl within a node 67 67 // should become the method of formating. 68 void CodeGenerator _new::updateLocation( CodeLocation const & to ) {68 void CodeGenerator::updateLocation( CodeLocation const & to ) { 69 69 // Skip if linemarks shouldn't appear or if location is unset. 70 70 if ( !options.lineMarks || to.isUnset() ) return; … … 86 86 } 87 87 88 void CodeGenerator _new::updateLocation( ast::ParseNode const * to ) {88 void CodeGenerator::updateLocation( ast::ParseNode const * to ) { 89 89 updateLocation( to->location ); 90 90 } 91 91 92 std::ostream & CodeGenerator _new::LineEnder::operator()( std::ostream & os ) const {92 std::ostream & CodeGenerator::LineEnder::operator()( std::ostream & os ) const { 93 93 os << "\n" << std::flush; 94 94 cg.currentLocation.first_line++; … … 96 96 } 97 97 98 CodeGenerator _new::CodeGenerator_new( std::ostream & os, const Options & options ) :99 indent( 0, CodeGenerator _new::tabsize ), output( os ),98 CodeGenerator::CodeGenerator( std::ostream & os, const Options & options ) : 99 indent( 0, CodeGenerator::tabsize ), output( os ), 100 100 options( options ), printLabels( *this ), endl( *this ) 101 101 {} 102 102 103 std::string CodeGenerator _new::mangleName( ast::DeclWithType const * decl ) {103 std::string CodeGenerator::mangleName( ast::DeclWithType const * decl ) { 104 104 // GCC builtins should always be printed unmangled. 105 105 if ( options.pretty || decl->linkage.is_gcc_builtin ) { … … 112 112 } 113 113 114 void CodeGenerator _new::genAttributes(114 void CodeGenerator::genAttributes( 115 115 const std::vector<ast::ptr<ast::Attribute>> & attributes ) { 116 116 if ( attributes.empty() ) return; … … 129 129 } 130 130 131 void CodeGenerator _new::previsit( ast::Node const * ) {131 void CodeGenerator::previsit( ast::Node const * ) { 132 132 // All traversal is manual. 133 133 // TODO: Which means the ast::Pass is just providing a default no visit? … … 135 135 } 136 136 137 void CodeGenerator _new::previsit( ast::ParseNode const * node ) {137 void CodeGenerator::previsit( ast::ParseNode const * node ) { 138 138 previsit( (ast::Node const *)node ); 139 139 updateLocation( node ); 140 140 } 141 141 142 void CodeGenerator _new::postvisit( ast::Node const * node ) {142 void CodeGenerator::postvisit( ast::Node const * node ) { 143 143 std::stringstream ss; 144 144 ast::print( ss, node ); … … 146 146 } 147 147 148 void CodeGenerator _new::previsit( ast::Expr const * expr ) {148 void CodeGenerator::previsit( ast::Expr const * expr ) { 149 149 previsit( (ast::ParseNode const *)expr ); 150 150 GuardAction( [this, expr](){ … … 155 155 } 156 156 157 void CodeGenerator _new::postvisit( ast::FunctionDecl const * decl ) {157 void CodeGenerator::postvisit( ast::FunctionDecl const * decl ) { 158 158 // Deleted decls should never be used, so don't print them in C. 159 159 if ( decl->isDeleted && options.genC ) return; … … 168 168 169 169 std::ostringstream acc; 170 ast::Pass<CodeGenerator _new> subCG( acc, subOptions );170 ast::Pass<CodeGenerator> subCG( acc, subOptions ); 171 171 // Add the forall clause. 172 172 // TODO: These probably should be removed by now and the assert used. … … 213 213 } 214 214 215 //void CodeGenerator_new::postvisit( ast::ObjectDecl const * decl_ ) { 216 ast::ObjectDecl const * CodeGenerator_new::postvisit( 215 ast::ObjectDecl const * CodeGenerator::postvisit( 217 216 ast::ObjectDecl const * decl ) { 218 217 // Deleted decls should never be used, so don't print them in C. … … 262 261 } 263 262 264 void CodeGenerator _new::handleStorageClass( ast::DeclWithType const * decl ) {263 void CodeGenerator::handleStorageClass( ast::DeclWithType const * decl ) { 265 264 if ( decl->storage.any() ) { 266 265 ast::print( output, decl->storage ); … … 268 267 } 269 268 270 void CodeGenerator _new::handleAggregate(269 void CodeGenerator::handleAggregate( 271 270 ast::AggregateDecl const * decl, std::string const & kind ) { 272 271 if ( !decl->params.empty() && !options.genC ) { … … 296 295 } 297 296 298 void CodeGenerator _new::postvisit( ast::StructDecl const * decl ) {297 void CodeGenerator::postvisit( ast::StructDecl const * decl ) { 299 298 extension( decl ); 300 299 handleAggregate( decl, "struct " ); 301 300 } 302 301 303 void CodeGenerator _new::postvisit( ast::UnionDecl const * decl ) {302 void CodeGenerator::postvisit( ast::UnionDecl const * decl ) { 304 303 extension( decl ); 305 304 handleAggregate( decl, "union " ); … … 332 331 } 333 332 334 void CodeGenerator _new::postvisit( ast::EnumDecl const * decl ) {333 void CodeGenerator::postvisit( ast::EnumDecl const * decl ) { 335 334 extension( decl ); 336 335 auto members = decl->members; … … 370 369 } 371 370 372 void CodeGenerator _new::postvisit( ast::TraitDecl const * decl ) {371 void CodeGenerator::postvisit( ast::TraitDecl const * decl ) { 373 372 assertf( !options.genC, "TraitDecls should not reach code generation." ); 374 373 extension( decl ); … … 376 375 } 377 376 378 void CodeGenerator _new::postvisit( ast::TypedefDecl const * decl ) {377 void CodeGenerator::postvisit( ast::TypedefDecl const * decl ) { 379 378 assertf( !options.genC, "Typedefs should not reach code generation." ); 380 379 output << "typedef " << genType( decl->base, decl->name, options ) << endl; 381 380 } 382 381 383 void CodeGenerator _new::postvisit( ast::TypeDecl const * decl ) {382 void CodeGenerator::postvisit( ast::TypeDecl const * decl ) { 384 383 assertf( !options.genC, "TypeDecls should not reach code generation." ); 385 384 output << decl->genTypeString() << " " << decl->name; … … 397 396 } 398 397 399 void CodeGenerator _new::postvisit( ast::StaticAssertDecl const * decl ) {398 void CodeGenerator::postvisit( ast::StaticAssertDecl const * decl ) { 400 399 output << "_Static_assert("; 401 400 decl->cond->accept( *visitor ); … … 405 404 } 406 405 407 void CodeGenerator _new::postvisit( ast::Designation const * designation ) {406 void CodeGenerator::postvisit( ast::Designation const * designation ) { 408 407 auto designators = designation->designators; 409 408 if ( 0 == designators.size() ) return; … … 423 422 } 424 423 425 void CodeGenerator _new::postvisit( ast::SingleInit const * init ) {424 void CodeGenerator::postvisit( ast::SingleInit const * init ) { 426 425 init->value->accept( *visitor ); 427 426 } 428 427 429 void CodeGenerator _new::postvisit( ast::ListInit const * init ) {428 void CodeGenerator::postvisit( ast::ListInit const * init ) { 430 429 auto initBegin = init->initializers.begin(); 431 430 auto initEnd = init->initializers.end(); … … 446 445 } 447 446 448 void CodeGenerator _new::postvisit( ast::ConstructorInit const * init ) {447 void CodeGenerator::postvisit( ast::ConstructorInit const * init ) { 449 448 assertf( !options.genC, "ConstructorInit nodes should not reach code generation." ); 450 449 // This isn't actual code, but labels the constructor/destructor pairs. … … 456 455 } 457 456 458 void CodeGenerator _new::postvisit( ast::ApplicationExpr const * expr ) {457 void CodeGenerator::postvisit( ast::ApplicationExpr const * expr ) { 459 458 extension( expr ); 460 459 if ( auto var = expr->func.as<ast::VariableExpr>() ) { … … 550 549 } 551 550 552 void CodeGenerator _new::postvisit( ast::UntypedExpr const * expr ) {551 void CodeGenerator::postvisit( ast::UntypedExpr const * expr ) { 553 552 extension( expr ); 554 553 if ( auto name = expr->func.as<ast::NameExpr>() ) { … … 638 637 } 639 638 640 void CodeGenerator _new::postvisit( ast::RangeExpr const * expr ) {639 void CodeGenerator::postvisit( ast::RangeExpr const * expr ) { 641 640 expr->low->accept( *visitor ); 642 641 output << " ... "; … … 644 643 } 645 644 646 void CodeGenerator _new::postvisit( ast::NameExpr const * expr ) {645 void CodeGenerator::postvisit( ast::NameExpr const * expr ) { 647 646 extension( expr ); 648 647 if ( const OperatorInfo * opInfo = operatorLookup( expr->name ) ) { … … 657 656 } 658 657 659 void CodeGenerator _new::postvisit( ast::DimensionExpr const * expr ) {658 void CodeGenerator::postvisit( ast::DimensionExpr const * expr ) { 660 659 extension( expr ); 661 660 output << "/*non-type*/" << expr->name; 662 661 } 663 662 664 void CodeGenerator _new::postvisit( ast::AddressExpr const * expr ) {663 void CodeGenerator::postvisit( ast::AddressExpr const * expr ) { 665 664 extension( expr ); 666 665 output << "(&"; … … 669 668 } 670 669 671 void CodeGenerator _new::postvisit( ast::LabelAddressExpr const * expr ) {670 void CodeGenerator::postvisit( ast::LabelAddressExpr const * expr ) { 672 671 extension( expr ); 673 672 output << "(&&" << expr->arg << ")"; 674 673 } 675 674 676 void CodeGenerator _new::postvisit( ast::CastExpr const * expr ) {675 void CodeGenerator::postvisit( ast::CastExpr const * expr ) { 677 676 extension( expr ); 678 677 output << "("; … … 688 687 } 689 688 690 void CodeGenerator _new::postvisit( ast::KeywordCastExpr const * expr ) {689 void CodeGenerator::postvisit( ast::KeywordCastExpr const * expr ) { 691 690 assertf( !options.genC, "KeywordCastExpr should not reach code generation." ); 692 691 extension( expr ); … … 696 695 } 697 696 698 void CodeGenerator _new::postvisit( ast::VirtualCastExpr const * expr ) {697 void CodeGenerator::postvisit( ast::VirtualCastExpr const * expr ) { 699 698 assertf( !options.genC, "VirtualCastExpr should not reach code generation." ); 700 699 extension( expr ); … … 705 704 } 706 705 707 void CodeGenerator _new::postvisit( ast::UntypedMemberExpr const * expr ) {706 void CodeGenerator::postvisit( ast::UntypedMemberExpr const * expr ) { 708 707 assertf( !options.genC, "UntypedMemberExpr should not reach code generation." ); 709 708 extension( expr ); … … 713 712 } 714 713 715 void CodeGenerator _new::postvisit( ast::MemberExpr const * expr ) {714 void CodeGenerator::postvisit( ast::MemberExpr const * expr ) { 716 715 extension( expr ); 717 716 expr->aggregate->accept( *visitor ); … … 719 718 } 720 719 721 void CodeGenerator _new::postvisit( ast::VariableExpr const * expr ) {720 void CodeGenerator::postvisit( ast::VariableExpr const * expr ) { 722 721 extension( expr ); 723 722 const OperatorInfo * opInfo; … … 733 732 } 734 733 735 void CodeGenerator _new::postvisit( ast::ConstantExpr const * expr ) {734 void CodeGenerator::postvisit( ast::ConstantExpr const * expr ) { 736 735 extension( expr ); 737 736 output << expr->rep; 738 737 } 739 738 740 void CodeGenerator _new::postvisit( ast::SizeofExpr const * expr ) {739 void CodeGenerator::postvisit( ast::SizeofExpr const * expr ) { 741 740 extension( expr ); 742 741 output << "sizeof("; … … 749 748 } 750 749 751 void CodeGenerator _new::postvisit( ast::AlignofExpr const * expr ) {750 void CodeGenerator::postvisit( ast::AlignofExpr const * expr ) { 752 751 // Using the GCC extension to avoid changing the std to C11. 753 752 extension( expr ); … … 761 760 } 762 761 763 void CodeGenerator _new::postvisit( ast::UntypedOffsetofExpr const * expr ) {762 void CodeGenerator::postvisit( ast::UntypedOffsetofExpr const * expr ) { 764 763 assertf( !options.genC, "UntypedOffsetofExpr should not reach code generation." ); 765 764 output << "offsetof("; … … 769 768 } 770 769 771 void CodeGenerator _new::postvisit( ast::OffsetofExpr const * expr ) {770 void CodeGenerator::postvisit( ast::OffsetofExpr const * expr ) { 772 771 // Use GCC builtin 773 772 output << "__builtin_offsetof("; … … 777 776 } 778 777 779 void CodeGenerator _new::postvisit( ast::OffsetPackExpr const * expr ) {778 void CodeGenerator::postvisit( ast::OffsetPackExpr const * expr ) { 780 779 assertf( !options.genC, "OffsetPackExpr should not reach code generation." ); 781 780 output << "__CFA_offsetpack(" << genType( expr->type, "", options ) << ")"; 782 781 } 783 782 784 void CodeGenerator _new::postvisit( ast::LogicalExpr const * expr ) {783 void CodeGenerator::postvisit( ast::LogicalExpr const * expr ) { 785 784 extension( expr ); 786 785 output << "("; … … 791 790 } 792 791 793 void CodeGenerator _new::postvisit( ast::ConditionalExpr const * expr ) {792 void CodeGenerator::postvisit( ast::ConditionalExpr const * expr ) { 794 793 extension( expr ); 795 794 output << "("; … … 802 801 } 803 802 804 void CodeGenerator _new::postvisit( ast::CommaExpr const * expr ) {803 void CodeGenerator::postvisit( ast::CommaExpr const * expr ) { 805 804 extension( expr ); 806 805 output << "("; … … 818 817 } 819 818 820 void CodeGenerator _new::postvisit( ast::TupleAssignExpr const * expr ) {819 void CodeGenerator::postvisit( ast::TupleAssignExpr const * expr ) { 821 820 assertf( !options.genC, "TupleAssignExpr should not reach code generation." ); 822 821 expr->stmtExpr->accept( *visitor ); 823 822 } 824 823 825 void CodeGenerator _new::postvisit( ast::UntypedTupleExpr const * expr ) {824 void CodeGenerator::postvisit( ast::UntypedTupleExpr const * expr ) { 826 825 assertf( !options.genC, "UntypedTupleExpr should not reach code generation." ); 827 826 extension( expr ); … … 831 830 } 832 831 833 void CodeGenerator _new::postvisit( ast::TupleExpr const * expr ) {832 void CodeGenerator::postvisit( ast::TupleExpr const * expr ) { 834 833 assertf( !options.genC, "TupleExpr should not reach code generation." ); 835 834 extension( expr ); … … 839 838 } 840 839 841 void CodeGenerator _new::postvisit( ast::TupleIndexExpr const * expr ) {840 void CodeGenerator::postvisit( ast::TupleIndexExpr const * expr ) { 842 841 assertf( !options.genC, "TupleIndexExpr should not reach code generation." ); 843 842 extension( expr ); … … 846 845 } 847 846 848 void CodeGenerator _new::postvisit( ast::TypeExpr const * expr ) {847 void CodeGenerator::postvisit( ast::TypeExpr const * expr ) { 849 848 // TODO: Should there be an assertion there? 850 849 if ( !options.genC ) { … … 853 852 } 854 853 855 void CodeGenerator _new::postvisit( ast::AsmExpr const * expr ) {854 void CodeGenerator::postvisit( ast::AsmExpr const * expr ) { 856 855 if ( !expr->inout.empty() ) { 857 856 output << "[ " << expr->inout << " ] "; … … 863 862 } 864 863 865 void CodeGenerator _new::postvisit( ast::CompoundLiteralExpr const * expr ) {864 void CodeGenerator::postvisit( ast::CompoundLiteralExpr const * expr ) { 866 865 //assert( expr->result && dynamic_cast<ast::ListInit const *>( expr->init ) ); 867 866 assert( expr->result && expr->init.as<ast::ListInit>() ); … … 870 869 } 871 870 872 void CodeGenerator _new::postvisit( ast::UniqueExpr const * expr ) {871 void CodeGenerator::postvisit( ast::UniqueExpr const * expr ) { 873 872 assertf( !options.genC, "UniqueExpr should not reach code generation." ); 874 873 output << "unq<" << expr->id << ">{ "; … … 877 876 } 878 877 879 void CodeGenerator _new::postvisit( ast::StmtExpr const * expr ) {878 void CodeGenerator::postvisit( ast::StmtExpr const * expr ) { 880 879 auto stmts = expr->stmts->kids; 881 880 output << "({" << endl; … … 905 904 } 906 905 907 void CodeGenerator _new::postvisit( ast::ConstructorExpr const * expr ) {906 void CodeGenerator::postvisit( ast::ConstructorExpr const * expr ) { 908 907 assertf( !options.genC, "ConstructorExpr should not reach code generation." ); 909 908 expr->callExpr->accept( *visitor ); 910 909 } 911 910 912 void CodeGenerator _new::postvisit( ast::DeletedExpr const * expr ) {911 void CodeGenerator::postvisit( ast::DeletedExpr const * expr ) { 913 912 assertf( !options.genC, "DeletedExpr should not reach code generation." ); 914 913 expr->expr->accept( *visitor ); 915 914 } 916 915 917 void CodeGenerator _new::postvisit( ast::DefaultArgExpr const * expr ) {916 void CodeGenerator::postvisit( ast::DefaultArgExpr const * expr ) { 918 917 assertf( !options.genC, "DefaultArgExpr should not reach code generation." ); 919 918 expr->expr->accept( *visitor ); 920 919 } 921 920 922 void CodeGenerator _new::postvisit( ast::GenericExpr const * expr ) {921 void CodeGenerator::postvisit( ast::GenericExpr const * expr ) { 923 922 assertf( !options.genC, "GenericExpr should not reach code generation." ); 924 923 output << "_Generic("; … … 940 939 } 941 940 942 void CodeGenerator _new::postvisit( ast::CompoundStmt const * stmt ) {941 void CodeGenerator::postvisit( ast::CompoundStmt const * stmt ) { 943 942 output << "{" << endl; 944 943 … … 955 954 } 956 955 957 void CodeGenerator _new::postvisit( ast::ExprStmt const * stmt ) {956 void CodeGenerator::postvisit( ast::ExprStmt const * stmt ) { 958 957 assert( stmt ); 959 958 // Cast the top-level expression to void to reduce gcc warnings. … … 967 966 } 968 967 969 void CodeGenerator _new::postvisit( ast::AsmStmt const * stmt ) {968 void CodeGenerator::postvisit( ast::AsmStmt const * stmt ) { 970 969 output << "asm "; 971 970 if ( stmt->isVolatile ) output << "volatile "; … … 991 990 } 992 991 993 void CodeGenerator _new::postvisit( ast::AsmDecl const * decl ) {992 void CodeGenerator::postvisit( ast::AsmDecl const * decl ) { 994 993 output << "asm "; 995 994 ast::AsmStmt const * stmt = decl->stmt; … … 999 998 } 1000 999 1001 void CodeGenerator _new::postvisit( ast::DirectiveDecl const * decl ) {1000 void CodeGenerator::postvisit( ast::DirectiveDecl const * decl ) { 1002 1001 // endl prevents spaces before the directive. 1003 1002 output << endl << decl->stmt->directive; 1004 1003 } 1005 1004 1006 void CodeGenerator _new::postvisit( ast::DirectiveStmt const * stmt ) {1005 void CodeGenerator::postvisit( ast::DirectiveStmt const * stmt ) { 1007 1006 // endl prevents spaces before the directive. 1008 1007 output << endl << stmt->directive; 1009 1008 } 1010 1009 1011 void CodeGenerator _new::postvisit( ast::IfStmt const * stmt ) {1010 void CodeGenerator::postvisit( ast::IfStmt const * stmt ) { 1012 1011 output << "if ( "; 1013 1012 stmt->cond->accept( *visitor ); … … 1022 1021 } 1023 1022 1024 void CodeGenerator _new::postvisit( ast::SwitchStmt const * stmt ) {1023 void CodeGenerator::postvisit( ast::SwitchStmt const * stmt ) { 1025 1024 output << "switch ( "; 1026 1025 stmt->cond->accept( *visitor ); … … 1036 1035 } 1037 1036 1038 void CodeGenerator _new::postvisit( ast::CaseClause const * clause ) {1037 void CodeGenerator::postvisit( ast::CaseClause const * clause ) { 1039 1038 updateLocation( clause ); 1040 1039 output << indent; … … 1056 1055 } 1057 1056 1058 void CodeGenerator _new::postvisit( ast::BranchStmt const * stmt ) {1057 void CodeGenerator::postvisit( ast::BranchStmt const * stmt ) { 1059 1058 switch ( stmt->kind ) { 1060 1059 case ast::BranchStmt::Goto: … … 1091 1090 } 1092 1091 1093 void CodeGenerator _new::postvisit( ast::ReturnStmt const * stmt ) {1092 void CodeGenerator::postvisit( ast::ReturnStmt const * stmt ) { 1094 1093 output << "return "; 1095 1094 if ( stmt->expr ) stmt->expr->accept( *visitor ); … … 1097 1096 } 1098 1097 1099 void CodeGenerator _new::postvisit( ast::ThrowStmt const * stmt ) {1098 void CodeGenerator::postvisit( ast::ThrowStmt const * stmt ) { 1100 1099 assertf( !options.genC, "ThrowStmt should not reach code generation." ); 1101 1100 … … 1112 1111 } 1113 1112 1114 void CodeGenerator _new::postvisit( ast::CatchClause const * stmt ) {1113 void CodeGenerator::postvisit( ast::CatchClause const * stmt ) { 1115 1114 assertf( !options.genC, "CatchClause should not reach code generation." ); 1116 1115 … … 1126 1125 } 1127 1126 1128 void CodeGenerator _new::postvisit( ast::WaitForStmt const * stmt ) {1127 void CodeGenerator::postvisit( ast::WaitForStmt const * stmt ) { 1129 1128 assertf( !options.genC, "WaitforStmt should not reach code generation." ); 1130 1129 … … 1172 1171 } 1173 1172 1174 void CodeGenerator _new::postvisit( ast::WithStmt const * stmt ) {1173 void CodeGenerator::postvisit( ast::WithStmt const * stmt ) { 1175 1174 assertf( !options.genC, "WithStmt should not reach code generation." ); 1176 1175 … … 1181 1180 } 1182 1181 1183 void CodeGenerator _new::postvisit( ast::WhileDoStmt const * stmt ) {1182 void CodeGenerator::postvisit( ast::WhileDoStmt const * stmt ) { 1184 1183 if ( stmt->isDoWhile ) { 1185 1184 output << "do"; … … 1191 1190 output << " "; 1192 1191 1193 output << CodeGenerator _new::printLabels( stmt->body->labels );1192 output << CodeGenerator::printLabels( stmt->body->labels ); 1194 1193 stmt->body->accept( *visitor ); 1195 1194 … … 1203 1202 } 1204 1203 1205 void CodeGenerator _new::postvisit( ast::ForStmt const * stmt ) {1204 void CodeGenerator::postvisit( ast::ForStmt const * stmt ) { 1206 1205 // Initializer is always hoised so don't generate it. 1207 1206 // TODO: Do an assertion check? … … 1226 1225 } 1227 1226 1228 void CodeGenerator _new::postvisit( ast::NullStmt const * ) {1227 void CodeGenerator::postvisit( ast::NullStmt const * ) { 1229 1228 output << "/* null statement */ ;"; 1230 1229 } 1231 1230 1232 void CodeGenerator _new::postvisit( ast::DeclStmt const * stmt ) {1231 void CodeGenerator::postvisit( ast::DeclStmt const * stmt ) { 1233 1232 stmt->decl->accept( *visitor ); 1234 1233 … … 1236 1235 } 1237 1236 1238 void CodeGenerator _new::postvisit( ast::ImplicitCtorDtorStmt const * stmt ) {1237 void CodeGenerator::postvisit( ast::ImplicitCtorDtorStmt const * stmt ) { 1239 1238 assertf( !options.genC, "ImplicitCtorCtorStmt should not reach code generation." ); 1240 1239 stmt->callStmt->accept( *visitor ); 1241 1240 } 1242 1241 1243 void CodeGenerator _new::postvisit( ast::MutexStmt const * stmt ) {1242 void CodeGenerator::postvisit( ast::MutexStmt const * stmt ) { 1244 1243 assertf( !options.genC, "MutexStmt should not reach code generation." ); 1245 1244 // TODO: But this isn't what a mutex statement looks like. -
src/CodeGen/CodeGeneratorNew.hpp
r25f2798 r0bd3faf 25 25 namespace CodeGen { 26 26 27 #warning Remove the _new when old version is removed. 28 struct CodeGenerator_new : 27 struct CodeGenerator final : 29 28 public ast::WithGuards, 30 29 public ast::WithShortCircuiting, 31 public ast::WithVisitorRef<CodeGenerator _new> {32 CodeGenerator _new( std::ostream & out, Options const & options );30 public ast::WithVisitorRef<CodeGenerator> { 31 CodeGenerator( std::ostream & out, Options const & options ); 33 32 34 33 // Turn off visit_children for all nodes. … … 119 118 /// Custom local implementation of endl that updates print location. 120 119 struct LineEnder { 121 CodeGenerator _new& cg;122 LineEnder( CodeGenerator _new& cg ) : cg( cg ) {}120 CodeGenerator & cg; 121 LineEnder( CodeGenerator & cg ) : cg( cg ) {} 123 122 std::ostream & operator()( std::ostream & ) const; 124 123 }; … … 129 128 /// Wrapper class to help print vectors of Labels. 130 129 struct LabelPrinter { 131 LabelPrinter( CodeGenerator _new& cg ) : cg( cg ), labels( nullptr ) {}130 LabelPrinter( CodeGenerator & cg ) : cg( cg ), labels( nullptr ) {} 132 131 LabelPrinter & operator()( std::vector<ast::Label> const & l ); 133 132 std::ostream & operator()( std::ostream & ) const; 134 CodeGenerator _new& cg;133 CodeGenerator & cg; 135 134 std::vector<ast::Label> const * labels; 136 135 }; -
src/CodeGen/GenType.cc
r25f2798 r0bd3faf 21 21 #include "AST/Print.hpp" // for print 22 22 #include "AST/Vector.hpp" // for vector 23 #include "CodeGeneratorNew.hpp" // for CodeGenerator _new23 #include "CodeGeneratorNew.hpp" // for CodeGenerator 24 24 #include "Common/UniqueName.h" // for UniqueName 25 25 … … 28 28 namespace { 29 29 30 #warning Remove the _new when old version is removed. 31 struct GenType_new : 30 struct GenType final : 32 31 public ast::WithShortCircuiting, 33 public ast::WithVisitorRef<GenType _new> {32 public ast::WithVisitorRef<GenType> { 34 33 std::string result; 35 GenType _new( const std::string &typeString, const Options &options );34 GenType( const std::string &typeString, const Options &options ); 36 35 37 36 void previsit( ast::Node const * ); … … 67 66 }; 68 67 69 GenType _new::GenType_new( const std::string &typeString, const Options &options ) : result( typeString ), options( options ) {}70 71 void GenType _new::previsit( ast::Node const * ) {68 GenType::GenType( const std::string &typeString, const Options &options ) : result( typeString ), options( options ) {} 69 70 void GenType::previsit( ast::Node const * ) { 72 71 // Turn off automatic recursion for all nodes, to allow each visitor to 73 72 // precisely control the order in which its children are visited. … … 75 74 } 76 75 77 void GenType _new::postvisit( ast::Node const * node ) {76 void GenType::postvisit( ast::Node const * node ) { 78 77 std::stringstream ss; 79 78 ast::print( ss, node ); … … 81 80 } 82 81 83 void GenType _new::postvisit( ast::VoidType const * type ) {82 void GenType::postvisit( ast::VoidType const * type ) { 84 83 result = "void " + result; 85 84 handleQualifiers( type ); 86 85 } 87 86 88 void GenType _new::postvisit( ast::BasicType const * type ) {87 void GenType::postvisit( ast::BasicType const * type ) { 89 88 ast::BasicType::Kind kind = type->kind; 90 89 assert( 0 <= kind && kind < ast::BasicType::NUMBER_OF_BASIC_TYPES ); … … 93 92 } 94 93 95 void GenType _new::genArray( const ast::CV::Qualifiers & qualifiers, ast::Type const * base, ast::Expr const *dimension, bool isVarLen, bool isStatic ) {94 void GenType::genArray( const ast::CV::Qualifiers & qualifiers, ast::Type const * base, ast::Expr const *dimension, bool isVarLen, bool isStatic ) { 96 95 std::ostringstream os; 97 96 if ( result != "" ) { … … 119 118 } 120 119 if ( dimension != 0 ) { 121 ast::Pass<CodeGenerator _new>::read( dimension, os, options );120 ast::Pass<CodeGenerator>::read( dimension, os, options ); 122 121 } else if ( isVarLen ) { 123 122 // no dimension expression on a VLA means it came in with the * token … … 131 130 } 132 131 133 void GenType _new::postvisit( ast::PointerType const * type ) {132 void GenType::postvisit( ast::PointerType const * type ) { 134 133 if ( type->isStatic || type->isVarLen || type->dimension ) { 135 134 genArray( type->qualifiers, type->base, type->dimension, type->isVarLen, type->isStatic ); … … 145 144 } 146 145 147 void GenType _new::postvisit( ast::ArrayType const * type ) {146 void GenType::postvisit( ast::ArrayType const * type ) { 148 147 genArray( type->qualifiers, type->base, type->dimension, type->isVarLen, type->isStatic ); 149 148 } 150 149 151 void GenType _new::postvisit( ast::ReferenceType const * type ) {150 void GenType::postvisit( ast::ReferenceType const * type ) { 152 151 assertf( !options.genC, "Reference types should not reach code generation." ); 153 152 handleQualifiers( type ); … … 156 155 } 157 156 158 void GenType _new::postvisit( ast::FunctionType const * type ) {157 void GenType::postvisit( ast::FunctionType const * type ) { 159 158 std::ostringstream os; 160 159 … … 196 195 //assertf( !options.genC, "FunctionDecl type parameters should not reach code generation." ); 197 196 std::ostringstream os; 198 ast::Pass<CodeGenerator _new> cg( os, options );197 ast::Pass<CodeGenerator> cg( os, options ); 199 198 os << "forall("; 200 199 cg.core.genCommaList( type->forall ); … … 204 203 } 205 204 206 std::string GenType _new::handleGeneric( ast::BaseInstType const * type ) {205 std::string GenType::handleGeneric( ast::BaseInstType const * type ) { 207 206 if ( !type->params.empty() ) { 208 207 std::ostringstream os; 209 ast::Pass<CodeGenerator _new> cg( os, options );208 ast::Pass<CodeGenerator> cg( os, options ); 210 209 os << "("; 211 210 cg.core.genCommaList( type->params ); … … 216 215 } 217 216 218 void GenType _new::postvisit( ast::StructInstType const * type ) {217 void GenType::postvisit( ast::StructInstType const * type ) { 219 218 result = type->name + handleGeneric( type ) + " " + result; 220 219 if ( options.genC ) result = "struct " + result; … … 222 221 } 223 222 224 void GenType _new::postvisit( ast::UnionInstType const * type ) {223 void GenType::postvisit( ast::UnionInstType const * type ) { 225 224 result = type->name + handleGeneric( type ) + " " + result; 226 225 if ( options.genC ) result = "union " + result; … … 228 227 } 229 228 230 void GenType _new::postvisit( ast::EnumInstType const * type ) {229 void GenType::postvisit( ast::EnumInstType const * type ) { 231 230 if ( type->base && type->base->base ) { 232 231 result = genType( type->base->base, result, options ); … … 240 239 } 241 240 242 void GenType _new::postvisit( ast::TypeInstType const * type ) {241 void GenType::postvisit( ast::TypeInstType const * type ) { 243 242 assertf( !options.genC, "TypeInstType should not reach code generation." ); 244 243 result = type->name + " " + result; … … 246 245 } 247 246 248 void GenType _new::postvisit( ast::TupleType const * type ) {247 void GenType::postvisit( ast::TupleType const * type ) { 249 248 assertf( !options.genC, "TupleType should not reach code generation." ); 250 249 unsigned int i = 0; … … 259 258 } 260 259 261 void GenType _new::postvisit( ast::VarArgsType const * type ) {260 void GenType::postvisit( ast::VarArgsType const * type ) { 262 261 result = "__builtin_va_list " + result; 263 262 handleQualifiers( type ); 264 263 } 265 264 266 void GenType _new::postvisit( ast::ZeroType const * type ) {265 void GenType::postvisit( ast::ZeroType const * type ) { 267 266 // Ideally these wouldn't hit codegen at all, but should be safe to make them ints. 268 267 result = (options.pretty ? "zero_t " : "long int ") + result; … … 270 269 } 271 270 272 void GenType _new::postvisit( ast::OneType const * type ) {271 void GenType::postvisit( ast::OneType const * type ) { 273 272 // Ideally these wouldn't hit codegen at all, but should be safe to make them ints. 274 273 result = (options.pretty ? "one_t " : "long int ") + result; … … 276 275 } 277 276 278 void GenType _new::postvisit( ast::GlobalScopeType const * type ) {277 void GenType::postvisit( ast::GlobalScopeType const * type ) { 279 278 assertf( !options.genC, "GlobalScopeType should not reach code generation." ); 280 279 handleQualifiers( type ); 281 280 } 282 281 283 void GenType _new::postvisit( ast::TraitInstType const * type ) {282 void GenType::postvisit( ast::TraitInstType const * type ) { 284 283 assertf( !options.genC, "TraitInstType should not reach code generation." ); 285 284 result = type->name + " " + result; … … 287 286 } 288 287 289 void GenType _new::postvisit( ast::TypeofType const * type ) {288 void GenType::postvisit( ast::TypeofType const * type ) { 290 289 std::ostringstream os; 291 290 os << "typeof("; 292 ast::Pass<CodeGenerator _new>::read( type, os, options );291 ast::Pass<CodeGenerator>::read( type, os, options ); 293 292 os << ") " << result; 294 293 result = os.str(); … … 296 295 } 297 296 298 void GenType _new::postvisit( ast::VTableType const * type ) {297 void GenType::postvisit( ast::VTableType const * type ) { 299 298 assertf( !options.genC, "Virtual table types should not reach code generation." ); 300 299 std::ostringstream os; … … 304 303 } 305 304 306 void GenType _new::postvisit( ast::QualifiedType const * type ) {305 void GenType::postvisit( ast::QualifiedType const * type ) { 307 306 assertf( !options.genC, "QualifiedType should not reach code generation." ); 308 307 std::ostringstream os; … … 312 311 } 313 312 314 void GenType _new::handleQualifiers( ast::Type const * type ) {313 void GenType::handleQualifiers( ast::Type const * type ) { 315 314 if ( type->is_const() ) { 316 315 result = "const " + result; … … 327 326 } 328 327 329 std::string GenType _new::genParamList( const ast::vector<ast::Type> & range ) {328 std::string GenType::genParamList( const ast::vector<ast::Type> & range ) { 330 329 auto cur = range.begin(); 331 330 auto end = range.end(); … … 346 345 std::ostringstream os; 347 346 if ( !type->attributes.empty() ) { 348 ast::Pass<CodeGenerator _new> cg( os, options );347 ast::Pass<CodeGenerator> cg( os, options ); 349 348 cg.core.genAttributes( type->attributes ); 350 349 } 351 350 352 return os.str() + ast::Pass<GenType _new>::read( type, base, options );351 return os.str() + ast::Pass<GenType>::read( type, base, options ); 353 352 } 354 353 355 354 std::string genTypeNoAttr( ast::Type const * type, const std::string & base, const Options & options ) { 356 return ast::Pass<GenType _new>::read( type, base, options );355 return ast::Pass<GenType>::read( type, base, options ); 357 356 } 358 357 -
src/CodeGen/Generate.cc
r25f2798 r0bd3faf 19 19 #include <string> // for operator<< 20 20 21 #include "CodeGeneratorNew.hpp" // for CodeGenerator _new, doSemicolon, ...21 #include "CodeGeneratorNew.hpp" // for CodeGenerator, doSemicolon, ... 22 22 #include "GenType.h" // for genPrettyType 23 23 … … 32 32 33 33 /// Removes various nodes that should not exist in CodeGen. 34 struct TreeCleaner _new{34 struct TreeCleaner final { 35 35 ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt ) { 36 36 auto mutStmt = ast::mutate( stmt ); … … 51 51 bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) { 52 52 erase_if( translationUnit.decls, shouldClean ); 53 ast::Pass<TreeCleaner _new>::run( translationUnit );53 ast::Pass<TreeCleaner>::run( translationUnit ); 54 54 55 ast::Pass<CodeGenerator _new> cgv( os,55 ast::Pass<CodeGenerator> cgv( os, 56 56 Options( pretty, generateC, lineMarks, printExprTypes ) ); 57 57 for ( auto & decl : translationUnit.decls ) { -
src/CodeGen/Generate.h
r25f2798 r0bd3faf 17 17 18 18 #include <iostream> // for ostream 19 #include <list> // for list20 21 class BaseSyntaxNode;22 class Declaration;23 19 24 20 namespace ast { -
src/InitTweak/FixGlobalInit.cc
r25f2798 r0bd3faf 27 27 28 28 namespace InitTweak { 29 class GlobalFixer _new: public ast::WithShortCircuiting {29 class GlobalFixer : public ast::WithShortCircuiting { 30 30 public: 31 31 void previsit (const ast::ObjectDecl *); … … 42 42 43 43 void fixGlobalInit(ast::TranslationUnit & translationUnit, bool inLibrary) { 44 ast::Pass<GlobalFixer _new> fixer;44 ast::Pass<GlobalFixer> fixer; 45 45 accept_all(translationUnit, fixer); 46 46 … … 73 73 } 74 74 75 void GlobalFixer _new::previsit(const ast::ObjectDecl * objDecl) {75 void GlobalFixer::previsit(const ast::ObjectDecl * objDecl) { 76 76 auto mutDecl = mutate(objDecl); 77 77 assertf(mutDecl == objDecl, "Global object decl must be unique"); -
src/InitTweak/FixInitNew.cpp
r25f2798 r0bd3faf 917 917 // static variables with the same name in different functions. 918 918 // Note: it isn't sufficient to modify only the mangleName, because 919 // then subsequent Indexerpasses can choke on seeing the object's name919 // then subsequent SymbolTable passes can choke on seeing the object's name 920 920 // if another object has the same name and type. An unfortunate side-effect 921 921 // of renaming the object is that subsequent NameExprs may fail to resolve, … … 1169 1169 arg2 = new ast::MemberExpr(funcDecl->location, field, new ast::VariableExpr(funcDecl->location, function->params.back() ) ); 1170 1170 } 1171 InitExpander _newsrcParam( arg2 );1171 InitExpander srcParam( arg2 ); 1172 1172 // cast away reference type and construct field. 1173 1173 ast::Expr * thisExpr = new ast::CastExpr(funcDecl->location, new ast::VariableExpr(funcDecl->location, thisParam ), thisParam->get_type()->stripReferences()); -
src/InitTweak/GenInit.cc
r25f2798 r0bd3faf 46 46 namespace { 47 47 48 # warning Remove the _New suffix after the conversion is complete.49 50 48 // Outer pass finds declarations, for their type could wrap a type that needs hoisting 51 struct HoistArrayDimension_NoResolve _Newfinal :49 struct HoistArrayDimension_NoResolve final : 52 50 public ast::WithDeclsToAdd<>, public ast::WithShortCircuiting, 53 51 public ast::WithGuards, public ast::WithConstTranslationUnit, 54 public ast::WithVisitorRef<HoistArrayDimension_NoResolve _New>,52 public ast::WithVisitorRef<HoistArrayDimension_NoResolve>, 55 53 public ast::WithSymbolTableX<ast::SymbolTable::ErrorDetection::IgnoreErrors> { 56 54 … … 59 57 public ast::WithShortCircuiting, public ast::WithGuards { 60 58 61 HoistArrayDimension_NoResolve _New* outer;62 HoistDimsFromTypes( HoistArrayDimension_NoResolve _New* outer ) : outer(outer) {}59 HoistArrayDimension_NoResolve * outer; 60 HoistDimsFromTypes( HoistArrayDimension_NoResolve * outer ) : outer(outer) {} 63 61 64 62 // Only intended for visiting through types. … … 211 209 212 210 213 struct ReturnFixer _Newfinal :211 struct ReturnFixer final : 214 212 public ast::WithStmtsToAdd<>, ast::WithGuards, ast::WithShortCircuiting { 215 213 void previsit( const ast::FunctionDecl * decl ); … … 219 217 }; 220 218 221 void ReturnFixer _New::previsit( const ast::FunctionDecl * decl ) {219 void ReturnFixer::previsit( const ast::FunctionDecl * decl ) { 222 220 if (decl->linkage == ast::Linkage::Intrinsic) visit_children = false; 223 221 GuardValue( funcDecl ) = decl; 224 222 } 225 223 226 const ast::ReturnStmt * ReturnFixer _New::previsit(224 const ast::ReturnStmt * ReturnFixer::previsit( 227 225 const ast::ReturnStmt * stmt ) { 228 226 auto & returns = funcDecl->returns; … … 265 263 266 264 void genInit( ast::TranslationUnit & transUnit ) { 267 ast::Pass<HoistArrayDimension_NoResolve _New>::run( transUnit );268 ast::Pass<ReturnFixer _New>::run( transUnit );265 ast::Pass<HoistArrayDimension_NoResolve>::run( transUnit ); 266 ast::Pass<ReturnFixer>::run( transUnit ); 269 267 } 270 268 271 269 void fixReturnStatements( ast::TranslationUnit & transUnit ) { 272 ast::Pass<ReturnFixer _New>::run( transUnit );273 } 274 275 bool ManagedTypes _new::isManaged( const ast::Type * type ) const {270 ast::Pass<ReturnFixer>::run( transUnit ); 271 } 272 273 bool ManagedTypes::isManaged( const ast::Type * type ) const { 276 274 // references are never constructed 277 275 if ( dynamic_cast< const ast::ReferenceType * >( type ) ) return false; … … 292 290 } 293 291 294 bool ManagedTypes _new::isManaged( const ast::ObjectDecl * objDecl ) const {292 bool ManagedTypes::isManaged( const ast::ObjectDecl * objDecl ) const { 295 293 const ast::Type * type = objDecl->type; 296 294 while ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) { … … 302 300 } 303 301 304 void ManagedTypes _new::handleDWT( const ast::DeclWithType * dwt ) {302 void ManagedTypes::handleDWT( const ast::DeclWithType * dwt ) { 305 303 // if this function is a user-defined constructor or destructor, mark down the type as "managed" 306 304 if ( ! dwt->linkage.is_overrideable && CodeGen::isCtorDtor( dwt->name ) ) { … … 313 311 } 314 312 315 void ManagedTypes _new::handleStruct( const ast::StructDecl * aggregateDecl ) {313 void ManagedTypes::handleStruct( const ast::StructDecl * aggregateDecl ) { 316 314 // don't construct members, but need to take note if there is a managed member, 317 315 // because that means that this type is also managed … … 329 327 } 330 328 331 void ManagedTypes _new::beginScope() { managedTypes.beginScope(); }332 void ManagedTypes _new::endScope() { managedTypes.endScope(); }329 void ManagedTypes::beginScope() { managedTypes.beginScope(); } 330 void ManagedTypes::endScope() { managedTypes.endScope(); } 333 331 334 332 ast::ptr<ast::Stmt> genCtorDtor (const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg) { 335 333 assertf(objDecl, "genCtorDtor passed null objDecl"); 336 InitExpander _newsrcParam(arg);334 InitExpander srcParam(arg); 337 335 return SymTab::genImplicitCall(srcParam, new ast::VariableExpr(loc, objDecl), loc, fname, objDecl); 338 336 } … … 341 339 // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor for each 342 340 // constructable object 343 InitExpander _newsrcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr };341 InitExpander srcParam{ objDecl->init }, nullParam{ (const ast::Init *)nullptr }; 344 342 ast::ptr< ast::Expr > dstParam = new ast::VariableExpr(loc, objDecl); 345 343 -
src/InitTweak/GenInit.h
r25f2798 r0bd3faf 37 37 ast::ConstructorInit * genCtorInit( const CodeLocation & loc, const ast::ObjectDecl * objDecl ); 38 38 39 class ManagedTypes _new{39 class ManagedTypes final { 40 40 public: 41 41 bool isManaged( const ast::ObjectDecl * objDecl ) const ; // determine if object is managed -
src/InitTweak/InitTweak.cc
r25f2798 r0bd3faf 39 39 namespace InitTweak { 40 40 namespace { 41 struct HasDesignations _new: public ast::WithShortCircuiting {41 struct HasDesignations : public ast::WithShortCircuiting { 42 42 bool result = false; 43 43 … … 57 57 }; 58 58 59 struct InitDepthChecker _new{59 struct InitDepthChecker { 60 60 bool result = true; 61 61 const ast::Type * type; 62 62 int curDepth = 0, maxDepth = 0; 63 InitDepthChecker _new( const ast::Type * type ) : type( type ) {63 InitDepthChecker( const ast::Type * type ) : type( type ) { 64 64 const ast::Type * t = type; 65 65 while ( auto at = dynamic_cast< const ast::ArrayType * >( t ) ) { … … 78 78 }; 79 79 80 struct InitFlattener _new: public ast::WithShortCircuiting {80 struct InitFlattener : public ast::WithShortCircuiting { 81 81 std::vector< ast::ptr< ast::Expr > > argList; 82 82 … … 90 90 91 91 bool isDesignated( const ast::Init * init ) { 92 ast::Pass<HasDesignations _new> finder;92 ast::Pass<HasDesignations> finder; 93 93 maybe_accept( init, finder ); 94 94 return finder.core.result; … … 96 96 97 97 bool checkInitDepth( const ast::ObjectDecl * objDecl ) { 98 ast::Pass<InitDepthChecker _new> checker( objDecl->type );98 ast::Pass<InitDepthChecker> checker( objDecl->type ); 99 99 maybe_accept( objDecl->init.get(), checker ); 100 100 return checker.core.result; … … 102 102 103 103 std::vector< ast::ptr< ast::Expr > > makeInitList( const ast::Init * init ) { 104 ast::Pass< InitFlattener _new> flattener;104 ast::Pass< InitFlattener > flattener; 105 105 maybe_accept( init, flattener ); 106 106 return std::move( flattener.core.argList ); 107 107 } 108 108 109 class InitExpander _new::ExpanderImpl {109 class InitExpander::ExpanderImpl { 110 110 public: 111 111 virtual ~ExpanderImpl() = default; … … 137 137 template< typename Out > 138 138 void build( 139 ast::UntypedExpr * callExpr, const InitExpander _new::IndexList & indices,139 ast::UntypedExpr * callExpr, const InitExpander::IndexList & indices, 140 140 const ast::Init * init, Out & out 141 141 ) { … … 183 183 } 184 184 185 class InitImpl _new final : public InitExpander_new::ExpanderImpl {185 class InitImpl final : public InitExpander::ExpanderImpl { 186 186 ast::ptr< ast::Init > init; 187 187 public: 188 InitImpl _new( const ast::Init * i ) : init( i ) {}189 190 std::vector< ast::ptr< ast::Expr > > next( InitExpander _new::IndexList & ) override {188 InitImpl( const ast::Init * i ) : init( i ) {} 189 190 std::vector< ast::ptr< ast::Expr > > next( InitExpander::IndexList & ) override { 191 191 return makeInitList( init ); 192 192 } 193 193 194 194 ast::ptr< ast::Stmt > buildListInit( 195 ast::UntypedExpr * callExpr, InitExpander _new::IndexList & indices195 ast::UntypedExpr * callExpr, InitExpander::IndexList & indices 196 196 ) override { 197 197 // If array came with an initializer list, initialize each element. We may have more … … 215 215 }; 216 216 217 class ExprImpl _new final : public InitExpander_new::ExpanderImpl {217 class ExprImpl final : public InitExpander::ExpanderImpl { 218 218 ast::ptr< ast::Expr > arg; 219 219 public: 220 ExprImpl _new( const ast::Expr * a ) : arg( a ) {}220 ExprImpl( const ast::Expr * a ) : arg( a ) {} 221 221 222 222 std::vector< ast::ptr< ast::Expr > > next( 223 InitExpander _new::IndexList & indices223 InitExpander::IndexList & indices 224 224 ) override { 225 225 if ( ! arg ) return {}; … … 237 237 238 238 ast::ptr< ast::Stmt > buildListInit( 239 ast::UntypedExpr *, InitExpander _new::IndexList &239 ast::UntypedExpr *, InitExpander::IndexList & 240 240 ) override { 241 241 return {}; … … 244 244 } // anonymous namespace 245 245 246 InitExpander _new::InitExpander_new( const ast::Init * init )247 : expander( new InitImpl _new{ init } ), crnt(), indices() {}248 249 InitExpander _new::InitExpander_new( const ast::Expr * expr )250 : expander( new ExprImpl _new{ expr } ), crnt(), indices() {}251 252 std::vector< ast::ptr< ast::Expr > > InitExpander _new::operator* () { return crnt; }253 254 InitExpander _new & InitExpander_new::operator++ () {246 InitExpander::InitExpander( const ast::Init * init ) 247 : expander( new InitImpl{ init } ), crnt(), indices() {} 248 249 InitExpander::InitExpander( const ast::Expr * expr ) 250 : expander( new ExprImpl{ expr } ), crnt(), indices() {} 251 252 std::vector< ast::ptr< ast::Expr > > InitExpander::operator* () { return crnt; } 253 254 InitExpander & InitExpander::operator++ () { 255 255 crnt = expander->next( indices ); 256 256 return *this; … … 259 259 /// builds statement which has the same semantics as a C-style list initializer (for array 260 260 /// initializers) using callExpr as the base expression to perform initialization 261 ast::ptr< ast::Stmt > InitExpander _new::buildListInit( ast::UntypedExpr * callExpr ) {261 ast::ptr< ast::Stmt > InitExpander::buildListInit( ast::UntypedExpr * callExpr ) { 262 262 return expander->buildListInit( callExpr, indices ); 263 263 } 264 264 265 void InitExpander _new::addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ) {265 void InitExpander::addArrayIndex( const ast::Expr * index, const ast::Expr * dimension ) { 266 266 indices.emplace_back( index ); 267 267 indices.emplace_back( dimension ); 268 268 } 269 269 270 void InitExpander _new::clearArrayIndices() { indices.clear(); }271 272 bool InitExpander _new::addReference() {270 void InitExpander::clearArrayIndices() { indices.clear(); } 271 272 bool InitExpander::addReference() { 273 273 for ( ast::ptr< ast::Expr > & expr : crnt ) { 274 274 expr = new ast::AddressExpr{ expr }; … … 308 308 } 309 309 310 struct CallFinder _newfinal {310 struct CallFinder final { 311 311 std::vector< const ast::Expr * > matches; 312 312 const std::vector< std::string > names; 313 313 314 CallFinder _new( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {}314 CallFinder( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {} 315 315 316 316 void handleCallExpr( const ast::Expr * expr ) { … … 326 326 327 327 std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt ) { 328 ast::Pass< CallFinder _new> finder{ std::vector< std::string >{ "?{}", "^?{}" } };328 ast::Pass< CallFinder > finder{ std::vector< std::string >{ "?{}", "^?{}" } }; 329 329 maybe_accept( stmt, finder ); 330 330 return std::move( finder.core.matches ); … … 381 381 } 382 382 383 struct ConstExprChecker _new: public ast::WithShortCircuiting {383 struct ConstExprChecker : public ast::WithShortCircuiting { 384 384 // most expressions are not const expr 385 385 void previsit( const ast::Expr * ) { result = false; visit_children = false; } … … 426 426 bool isConstExpr( const ast::Expr * expr ) { 427 427 if ( expr ) { 428 ast::Pass<ConstExprChecker _new> checker;428 ast::Pass<ConstExprChecker> checker; 429 429 expr->accept( checker ); 430 430 return checker.core.result; … … 435 435 bool isConstExpr( const ast::Init * init ) { 436 436 if ( init ) { 437 ast::Pass<ConstExprChecker _new> checker;437 ast::Pass<ConstExprChecker> checker; 438 438 init->accept( checker ); 439 439 return checker.core.result; … … 486 486 } 487 487 488 } 488 } // namespace InitTweak -
src/InitTweak/InitTweak.h
r25f2798 r0bd3faf 79 79 void addDataSectionAttribute( ast::ObjectDecl * objDecl ); 80 80 81 class InitExpander _new{81 class InitExpander final { 82 82 public: 83 83 using IndexList = std::vector< ast::ptr< ast::Expr > >; … … 92 92 public: 93 93 /// Expand by stepping through init to get each list of arguments 94 InitExpander _new( const ast::Init * init );94 InitExpander( const ast::Init * init ); 95 95 96 96 /// Always expand to expression 97 InitExpander _new( const ast::Expr * expr );97 InitExpander( const ast::Expr * expr ); 98 98 99 99 std::vector< ast::ptr< ast::Expr > > operator* (); 100 InitExpander _new& operator++ ();100 InitExpander & operator++ (); 101 101 102 102 /// builds statement which has the same semantics as a C-style list initializer (for array … … 111 111 bool addReference(); 112 112 }; 113 } // namespace 113 } // namespace InitTweak 114 114 115 115 // Local Variables: // -
src/ResolvExpr/AdjustExprType.cc
r25f2798 r0bd3faf 23 23 24 24 namespace { 25 class AdjustExprType _newfinal : public ast::WithShortCircuiting {25 class AdjustExprType final : public ast::WithShortCircuiting { 26 26 const ast::SymbolTable & symtab; 27 27 public: 28 28 const ast::TypeEnvironment & tenv; 29 29 30 AdjustExprType _new( const ast::TypeEnvironment & e, const ast::SymbolTable & syms )30 AdjustExprType( const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) 31 31 : symtab( syms ), tenv( e ) {} 32 32 … … 75 75 const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 76 76 ) { 77 ast::Pass<AdjustExprType _new> adjuster{ env, symtab };77 ast::Pass<AdjustExprType> adjuster{ env, symtab }; 78 78 return type->accept( adjuster ); 79 79 } -
src/ResolvExpr/AdjustExprType.hpp
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 namespace SymTab {20 class Indexer;21 }22 18 namespace ast { 23 19 class SymbolTable; … … 27 23 28 24 namespace ResolvExpr { 29 30 class TypeEnvironment;31 32 /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function33 void adjustExprType( Type *& type, const TypeEnvironment & env, const SymTab::Indexer & indexer );34 35 /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function using empty TypeEnvironment and Indexer.36 void adjustExprType( Type *& type );37 38 template< typename ForwardIterator >39 void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment & env, const SymTab::Indexer & indexer ) {40 while ( begin != end ) {41 adjustExprType( *begin++, env, indexer );42 } // while43 }44 25 45 26 /// Replaces array types with equivalent pointer, -
src/ResolvExpr/CandidateFinder.cpp
r25f2798 r0bd3faf 61 61 namespace { 62 62 /// First index is which argument, second is which alternative, third is which exploded element 63 using ExplodedArgs _new= std::deque< std::vector< ExplodedArg > >;63 using ExplodedArgs = std::deque< std::vector< ExplodedArg > >; 64 64 65 65 /// Returns a list of alternatives with the minimum cost in the given list … … 255 255 256 256 /// Gets the list of exploded candidates for this pack 257 const ExplodedArg & getExpl( const ExplodedArgs _new& args ) const {257 const ExplodedArg & getExpl( const ExplodedArgs & args ) const { 258 258 return args[ nextArg-1 ][ explAlt ]; 259 259 } … … 281 281 bool instantiateArgument( 282 282 const CodeLocation & location, 283 const ast::Type * paramType, const ast::Init * init, const ExplodedArgs _new& args,283 const ast::Type * paramType, const ast::Init * init, const ExplodedArgs & args, 284 284 std::vector< ArgPack > & results, std::size_t & genStart, const ast::SymbolTable & symtab, 285 285 unsigned nTuples = 0 … … 618 618 const CodeLocation & location, 619 619 const CandidateRef & func, const ast::FunctionType * funcType, 620 const ExplodedArgs _new& args, CandidateList & out );620 const ExplodedArgs & args, CandidateList & out ); 621 621 622 622 /// Adds implicit struct-conversions to the alternative list … … 737 737 const CodeLocation & location, 738 738 const CandidateRef & func, const ast::FunctionType * funcType, 739 const ExplodedArgs _new& args, CandidateList & out739 const ExplodedArgs & args, CandidateList & out 740 740 ) { 741 741 ast::OpenVarSet funcOpen; … … 997 997 998 998 // pre-explode arguments 999 ExplodedArgs _newargExpansions;999 ExplodedArgs argExpansions; 1000 1000 for ( const CandidateFinder & args : argCandidates ) { 1001 1001 argExpansions.emplace_back(); -
src/ResolvExpr/CastCost.cc
r25f2798 r0bd3faf 26 26 #include "ResolvExpr/ConversionCost.h" // for conversionCost 27 27 #include "ResolvExpr/PtrsCastable.hpp" // for ptrsCastable 28 #include "ResolvExpr/typeops.h" // for ptrsCastable29 28 #include "ResolvExpr/Unify.h" // for typesCompatibleIgnoreQualifiers 30 29 … … 38 37 39 38 namespace { 40 struct CastCost _new : public ConversionCost_new{41 using ConversionCost _new::previsit;42 using ConversionCost _new::postvisit;39 struct CastCost : public ConversionCost { 40 using ConversionCost::previsit; 41 using ConversionCost::postvisit; 43 42 44 CastCost _new(43 CastCost( 45 44 const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab, 46 45 const ast::TypeEnvironment & env, CostCalculation costFunc ) 47 : ConversionCost _new( dst, srcIsLvalue, symtab, env, costFunc ) {}46 : ConversionCost( dst, srcIsLvalue, symtab, env, costFunc ) {} 48 47 49 48 void postvisit( const ast::BasicType * basicType ) { … … 85 84 }; 86 85 87 #warning For overload resolution between the two versions.88 int localPtrsCastable(const ast::Type * t1, const ast::Type * t2,89 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) {90 return ptrsCastable( t1, t2, symtab, env );91 }92 Cost localCastCost(93 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,94 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env95 ) { return castCost( src, dst, srcIsLvalue, symtab, env ); }96 86 } // anonymous namespace 97 87 … … 136 126 } else if ( auto refType = dynamic_cast< const ast::ReferenceType * >( dst ) ) { 137 127 PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; ) 138 #warning cast on ptrsCastable artifact of having two functions, remove when port done139 128 return convertToReferenceCost( 140 src, refType, srcIsLvalue, symtab, env, localPtrsCastable );129 src, refType, srcIsLvalue, symtab, env, ptrsCastable ); 141 130 } else { 142 #warning cast on castCost artifact of having two functions, remove when port done 143 ast::Pass< CastCost_new > converter( 144 dst, srcIsLvalue, symtab, env, localCastCost ); 131 ast::Pass< CastCost > converter( 132 dst, srcIsLvalue, symtab, env, castCost ); 145 133 src->accept( converter ); 146 134 return converter.core.cost; -
src/ResolvExpr/CastCost.hpp
r25f2798 r0bd3faf 18 18 #include "ResolvExpr/Cost.h" // for Cost 19 19 20 class Type;21 namespace SymTab {22 class Indexer;23 }24 20 namespace ast { 25 21 class SymbolTable; … … 30 26 namespace ResolvExpr { 31 27 32 class TypeEnvironment;33 34 Cost castCost(35 const Type * src, const Type * dest, bool srcIsLvalue,36 const SymTab::Indexer & indexer, const TypeEnvironment & env );37 28 Cost castCost( 38 29 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, -
src/ResolvExpr/CommonType.cc
r25f2798 r0bd3faf 343 343 ); 344 344 345 class CommonType _newfinal : public ast::WithShortCircuiting {345 class CommonType final : public ast::WithShortCircuiting { 346 346 const ast::Type * type2; 347 347 WidenMode widen; … … 354 354 ast::ptr< ast::Type > result; 355 355 356 CommonType _new(356 CommonType( 357 357 const ast::Type * t2, WidenMode w, 358 358 ast::TypeEnvironment & env, const ast::OpenVarSet & o, … … 388 388 result = enumDecl->base.get(); 389 389 } else { 390 #warning remove casts when `commonTypes` moved to new AST391 390 ast::BasicType::Kind kind = commonTypes[ basic->kind ][ ast::BasicType::SignedInt ]; 392 391 if ( … … 739 738 }; 740 739 741 // size_t CommonType _new::traceId = Stats::Heap::new_stacktrace_id("CommonType_new");740 // size_t CommonType::traceId = Stats::Heap::new_stacktrace_id("CommonType"); 742 741 namespace { 743 742 ast::ptr< ast::Type > handleReference( … … 811 810 } 812 811 // otherwise both are reference types of the same depth and this is handled by the visitor 813 ast::Pass<CommonType _new> visitor{ type2, widen, env, open, need, have };812 ast::Pass<CommonType> visitor{ type2, widen, env, open, need, have }; 814 813 type1->accept( visitor ); 815 814 // ast::ptr< ast::Type > result = visitor.core.result; -
src/ResolvExpr/ConversionCost.cc
r25f2798 r0bd3faf 153 153 154 154 namespace { 155 # warning For overload resolution between the two versions.156 155 int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2, 157 156 const ast::SymbolTable &, const ast::TypeEnvironment & env ) { 158 157 return ptrsAssignable( t1, t2, env ); 159 158 } 160 Cost localConversionCost(161 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,162 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env163 ) { return conversionCost( src, dst, srcIsLvalue, symtab, env ); }164 159 } 165 160 … … 191 186 return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable ); 192 187 } else { 193 return ast::Pass<ConversionCost _new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost );188 return ast::Pass<ConversionCost>::read( src, dst, srcIsLvalue, symtab, env, conversionCost ); 194 189 } 195 190 } … … 232 227 } 233 228 } else { 234 return ast::Pass<ConversionCost _new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost );229 return ast::Pass<ConversionCost>::read( src, dst, srcIsLvalue, symtab, env, conversionCost ); 235 230 } 236 231 } else { … … 264 259 } 265 260 266 void ConversionCost _new::postvisit( const ast::VoidType * voidType ) {261 void ConversionCost::postvisit( const ast::VoidType * voidType ) { 267 262 (void)voidType; 268 263 cost = Cost::infinity; 269 264 } 270 265 271 void ConversionCost _new::conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest ) {266 void ConversionCost::conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest ) { 272 267 int tableResult = costMatrix[ src->kind ][ dest->kind ]; 273 268 if ( tableResult == -1 ) { … … 280 275 } 281 276 282 void ConversionCost _new::postvisit( const ast::BasicType * basicType ) {277 void ConversionCost::postvisit( const ast::BasicType * basicType ) { 283 278 if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) { 284 279 conversionCostFromBasicToBasic( basicType, dstAsBasic ); … … 286 281 const ast::EnumDecl * enumDecl = enumInst->base.get(); 287 282 if ( enumDecl->isTyped && !enumDecl->base.get() ) { 288 cost = Cost::infinity; 283 cost = Cost::infinity; 289 284 } else if ( const ast::Type * enumType = enumDecl->base.get() ) { 290 285 if ( const ast::BasicType * enumTypeAsBasic = dynamic_cast<const ast::BasicType *>(enumType) ) { … … 299 294 } 300 295 301 void ConversionCost _new::postvisit( const ast::PointerType * pointerType ) {296 void ConversionCost::postvisit( const ast::PointerType * pointerType ) { 302 297 if ( const ast::PointerType * dstAsPtr = dynamic_cast< const ast::PointerType * >( dst ) ) { 303 298 ast::CV::Qualifiers tq1 = pointerType->base->qualifiers; … … 345 340 } 346 341 347 void ConversionCost _new::postvisit( const ast::ArrayType * arrayType ) {342 void ConversionCost::postvisit( const ast::ArrayType * arrayType ) { 348 343 (void)arrayType; 349 344 } 350 345 351 void ConversionCost _new::postvisit( const ast::ReferenceType * refType ) {346 void ConversionCost::postvisit( const ast::ReferenceType * refType ) { 352 347 assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) ); 353 348 … … 367 362 } 368 363 369 void ConversionCost _new::postvisit( const ast::FunctionType * functionType ) {364 void ConversionCost::postvisit( const ast::FunctionType * functionType ) { 370 365 (void)functionType; 371 366 } 372 367 373 void ConversionCost _new::postvisit( const ast::EnumInstType * enumInstType ) {368 void ConversionCost::postvisit( const ast::EnumInstType * enumInstType ) { 374 369 const ast::EnumDecl * baseEnum = enumInstType->base; 375 370 if ( const ast::Type * baseType = baseEnum->base ) { … … 384 379 } 385 380 386 void ConversionCost _new::postvisit( const ast::TraitInstType * traitInstType ) {381 void ConversionCost::postvisit( const ast::TraitInstType * traitInstType ) { 387 382 (void)traitInstType; 388 383 } 389 384 390 void ConversionCost _new::postvisit( const ast::TypeInstType * typeInstType ) {385 void ConversionCost::postvisit( const ast::TypeInstType * typeInstType ) { 391 386 if ( const ast::EqvClass * eqv = env.lookup( *typeInstType ) ) { 392 387 cost = costCalc( eqv->bound, dst, srcIsLvalue, symtab, env ); … … 405 400 } 406 401 407 void ConversionCost _new::postvisit( const ast::TupleType * tupleType ) {402 void ConversionCost::postvisit( const ast::TupleType * tupleType ) { 408 403 Cost c = Cost::zero; 409 404 if ( const ast::TupleType * dstAsTuple = dynamic_cast< const ast::TupleType * >( dst ) ) { … … 427 422 } 428 423 429 void ConversionCost _new::postvisit( const ast::VarArgsType * varArgsType ) {424 void ConversionCost::postvisit( const ast::VarArgsType * varArgsType ) { 430 425 (void)varArgsType; 431 426 if ( dynamic_cast< const ast::VarArgsType * >( dst ) ) { … … 434 429 } 435 430 436 void ConversionCost _new::postvisit( const ast::ZeroType * zeroType ) {431 void ConversionCost::postvisit( const ast::ZeroType * zeroType ) { 437 432 (void)zeroType; 438 433 if ( dynamic_cast< const ast::ZeroType * >( dst ) ) { … … 461 456 } 462 457 463 void ConversionCost _new::postvisit( const ast::OneType * oneType ) {458 void ConversionCost::postvisit( const ast::OneType * oneType ) { 464 459 (void)oneType; 465 460 if ( dynamic_cast< const ast::OneType * >( dst ) ) { 466 461 cost = Cost::zero; 467 462 } else if ( const ast::BasicType * dstAsBasic = 468 dynamic_cast< const ast::BasicType * >( dst ) ) { 463 dynamic_cast< const ast::BasicType * >( dst ) ) { 469 464 int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ]; 470 465 if ( -1 == tableResult ) { … … 475 470 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 476 471 } 477 478 // cost = Cost::zero; 479 } 480 } 481 // size_t ConversionCost_new::traceId = Stats::Heap::new_stacktrace_id("ConversionCost"); 472 } 473 } 474 475 // size_t ConversionCost::traceId = Stats::Heap::new_stacktrace_id("ConversionCost"); 482 476 483 477 } // namespace ResolvExpr -
src/ResolvExpr/ConversionCost.h
r25f2798 r0bd3faf 23 23 #include "AST/Pass.hpp" // for WithShortCircuiting 24 24 25 namespace SymTab {26 class Indexer;27 } // namespace SymTab28 29 25 namespace ResolvExpr { 30 class TypeEnvironment;31 26 32 27 // Some function pointer types, differ in return type. … … 44 39 PtrsCalculation func ); 45 40 46 #warning when the old ConversionCost is removed, get ride of the _new suffix. 47 class ConversionCost_new : public ast::WithShortCircuiting { 41 class ConversionCost : public ast::WithShortCircuiting { 48 42 protected: 49 43 const ast::Type * dst; … … 57 51 Cost result() { return cost; } 58 52 59 ConversionCost _new( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab,53 ConversionCost( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab, 60 54 const ast::TypeEnvironment & env, CostCalculation costCalc ) : 61 55 dst( dst ), srcIsLvalue( srcIsLvalue ), symtab( symtab ), env( env ), -
src/ResolvExpr/FindOpenVars.cc
r25f2798 r0bd3faf 25 25 26 26 namespace { 27 struct FindOpenVars _newfinal : public ast::WithGuards {27 struct FindOpenVars final : public ast::WithGuards { 28 28 ast::OpenVarSet & open; 29 29 ast::OpenVarSet & closed; … … 33 33 bool nextIsOpen; 34 34 35 FindOpenVars _new(35 FindOpenVars( 36 36 ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n, 37 37 ast::AssertionSet & h, ast::TypeEnvironment & env, FirstMode firstIsOpen ) … … 73 73 const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed, 74 74 ast::AssertionSet & need, ast::AssertionSet & have, ast::TypeEnvironment & env, FirstMode firstIsOpen ) { 75 ast::Pass< FindOpenVars _new> finder{ open, closed, need, have, env, firstIsOpen };75 ast::Pass< FindOpenVars > finder{ open, closed, need, have, env, firstIsOpen }; 76 76 type->accept( finder ); 77 77 -
src/ResolvExpr/PolyCost.cc
r25f2798 r0bd3faf 21 21 namespace ResolvExpr { 22 22 23 // TODO: When the old PolyCost is torn out get rid of the _new suffix. 24 class PolyCost_new { 23 class PolyCost { 25 24 const ast::SymbolTable &symtab; 26 25 public: … … 28 27 const ast::TypeEnvironment &env_; 29 28 30 PolyCost _new( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env )29 PolyCost( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) 31 30 : symtab( symtab ), result( 0 ), env_( env ) {} 32 31 … … 49 48 const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env 50 49 ) { 51 ast::Pass<PolyCost _new> costing( symtab, env );50 ast::Pass<PolyCost> costing( symtab, env ); 52 51 type->accept( costing ); 53 52 return (costing.core.result > 0) ? 1 : 0; -
src/ResolvExpr/PolyCost.hpp
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 namespace SymTab {20 class Indexer;21 }22 18 namespace ast { 23 19 class SymbolTable; … … 28 24 namespace ResolvExpr { 29 25 30 class TypeEnvironment;31 32 int polyCost( Type * type,33 const TypeEnvironment & env, const SymTab::Indexer & indexer );34 26 int polyCost( const ast::Type * type, 35 27 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ); -
src/ResolvExpr/PtrsAssignable.cc
r25f2798 r0bd3faf 22 22 namespace ResolvExpr { 23 23 24 // TODO: Get rid of the `_new` suffix when the old version is removed. 25 struct PtrsAssignable_new : public ast::WithShortCircuiting { 24 struct PtrsAssignable : public ast::WithShortCircuiting { 26 25 const ast::Type * dst; 27 26 const ast::TypeEnvironment & typeEnv; 28 27 int result; 29 28 30 PtrsAssignable _new( const ast::Type * dst, const ast::TypeEnvironment & env ) :29 PtrsAssignable( const ast::Type * dst, const ast::TypeEnvironment & env ) : 31 30 dst( dst ), typeEnv( env ), result( 0 ) {} 32 31 33 void previsit( Type * ) { visit_children = false; }32 void previsit( ast::Type * ) { visit_children = false; } 34 33 35 34 void postvisit( const ast::EnumInstType * ) { … … 63 62 return -1; 64 63 } else { 65 ast::Pass<PtrsAssignable _new> visitor( dst, env );64 ast::Pass<PtrsAssignable> visitor( dst, env ); 66 65 src->accept( visitor ); 67 66 return visitor.core.result; -
src/ResolvExpr/PtrsAssignable.hpp
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 18 namespace ast { 20 19 class Type; … … 24 23 namespace ResolvExpr { 25 24 26 class TypeEnvironment;27 28 int ptrsAssignable( const Type * src, const Type * dest,29 const TypeEnvironment & env );30 25 int ptrsAssignable( const ast::Type * src, const ast::Type * dst, 31 26 const ast::TypeEnvironment & env ); -
src/ResolvExpr/PtrsCastable.cc
r25f2798 r0bd3faf 55 55 } 56 56 57 class PtrsCastable _new: public ast::WithShortCircuiting {57 class PtrsCastable : public ast::WithShortCircuiting { 58 58 const ast::Type * dst; 59 59 const ast::TypeEnvironment & env; … … 62 62 int result; 63 63 64 PtrsCastable _new(64 PtrsCastable( 65 65 const ast::Type * d, const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) 66 66 : dst( d ), env( e ), symtab( syms ), result( 0 ) {} … … 149 149 return objectCast( src, env, symtab ); 150 150 } else { 151 return ast::Pass<PtrsCastable _new>::read( src, dst, env, symtab );151 return ast::Pass<PtrsCastable>::read( src, dst, env, symtab ); 152 152 } 153 153 } -
src/ResolvExpr/PtrsCastable.hpp
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 namespace SymTab {20 class Indexer;21 }22 18 namespace ast { 23 19 class SymbolTable; … … 28 24 namespace ResolvExpr { 29 25 30 class TypeEnvironment;31 32 int ptrsCastable(33 const Type * src, const Type * dst,34 const TypeEnvironment & env, const SymTab::Indexer & indexer );35 26 int ptrsCastable( 36 27 const ast::Type * src, const ast::Type * dst, -
src/ResolvExpr/RenameVars.cc
r25f2798 r0bd3faf 101 101 RenamingData renaming; 102 102 103 struct RenameVars _new: public ast::PureVisitor /*: public ast::WithForallSubstitutor*/ {103 struct RenameVars final : public ast::PureVisitor /*: public ast::WithForallSubstitutor*/ { 104 104 RenameMode mode; 105 105 … … 132 132 133 133 const ast::Type * renameTyVars( const ast::Type * t, RenameMode mode, bool reset ) { 134 ast::Pass<RenameVars _new> renamer;134 ast::Pass<RenameVars> renamer; 135 135 renamer.core.mode = mode; 136 136 if (mode == GEN_USAGE && reset) { -
src/ResolvExpr/ResolveTypeof.cc
r25f2798 r0bd3faf 33 33 34 34 namespace { 35 struct ResolveTypeof _new: public ast::WithShortCircuiting {35 struct ResolveTypeof : public ast::WithShortCircuiting { 36 36 const ResolveContext & context; 37 37 38 ResolveTypeof _new( const ResolveContext & context ) :38 ResolveTypeof( const ResolveContext & context ) : 39 39 context( context ) {} 40 40 … … 78 78 79 79 const ast::Type * resolveTypeof( const ast::Type * type , const ResolveContext & context ) { 80 ast::Pass< ResolveTypeof _new> mutator( context );80 ast::Pass< ResolveTypeof > mutator( context ); 81 81 return type->accept( mutator ); 82 82 } -
src/ResolvExpr/ResolveTypeof.h
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 namespace SymTab {20 class Indexer;21 } // namespace SymTab22 18 namespace ast { 23 19 class Type; … … 28 24 struct ResolveContext; 29 25 30 Type *resolveTypeof( Type*, const SymTab::Indexer &indexer );31 26 const ast::Type * resolveTypeof( const ast::Type *, const ResolveContext & ); 32 27 const ast::Type * fixArrayType( const ast::Type *, const ResolveContext & ); 33 28 const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ResolveContext & ); 34 const ast::ObjectDecl * fixObjectInit( const ast::ObjectDecl * decl , const ResolveContext & );29 const ast::ObjectDecl * fixObjectInit( const ast::ObjectDecl * decl , const ResolveContext & ); 35 30 } // namespace ResolvExpr 36 31 -
src/ResolvExpr/Resolver.cc
r25f2798 r0bd3faf 62 62 namespace { 63 63 /// Finds deleted expressions in an expression tree 64 struct DeleteFinder _new final : public ast::WithShortCircuiting, public ast::WithVisitorRef<DeleteFinder_new> {64 struct DeleteFinder final : public ast::WithShortCircuiting, public ast::WithVisitorRef<DeleteFinder> { 65 65 const ast::DeletedExpr * result = nullptr; 66 66 … … 80 80 }; 81 81 82 struct ResolveDesignators _newfinal : public ast::WithShortCircuiting {82 struct ResolveDesignators final : public ast::WithShortCircuiting { 83 83 ResolveContext& context; 84 84 bool result = false; 85 85 86 ResolveDesignators _new( ResolveContext& _context ): context{_context} {};86 ResolveDesignators( ResolveContext& _context ): context{_context} {}; 87 87 88 88 void previsit( const ast::Node * ) { … … 113 113 /// Check if this expression is or includes a deleted expression 114 114 const ast::DeletedExpr * findDeletedExpr( const ast::Expr * expr ) { 115 return ast::Pass<DeleteFinder _new>::read( expr );115 return ast::Pass<DeleteFinder>::read( expr ); 116 116 } 117 117 … … 203 203 204 204 /// Strips extraneous casts out of an expression 205 struct StripCasts _newfinal {205 struct StripCasts final { 206 206 const ast::Expr * postvisit( const ast::CastExpr * castExpr ) { 207 207 if ( … … 217 217 218 218 static void strip( ast::ptr< ast::Expr > & expr ) { 219 ast::Pass< StripCasts _new> stripper;219 ast::Pass< StripCasts > stripper; 220 220 expr = expr->accept( stripper ); 221 221 } … … 251 251 expr.get_and_mutate()->env = std::move( newenv ); 252 252 // remove unncecessary casts 253 StripCasts _new::strip( expr );253 StripCasts::strip( expr ); 254 254 } 255 255 … … 368 368 } 369 369 370 class Resolver _newfinal370 class Resolver final 371 371 : public ast::WithSymbolTable, public ast::WithGuards, 372 public ast::WithVisitorRef<Resolver _new>, public ast::WithShortCircuiting,372 public ast::WithVisitorRef<Resolver>, public ast::WithShortCircuiting, 373 373 public ast::WithStmtsToAdd<> { 374 374 … … 376 376 ast::CurrentObject currentObject; 377 377 // for work previously in GenInit 378 static InitTweak::ManagedTypes _newmanagedTypes;378 static InitTweak::ManagedTypes managedTypes; 379 379 ResolveContext context; 380 380 … … 383 383 public: 384 384 static size_t traceId; 385 Resolver _new( const ast::TranslationGlobal & global ) :385 Resolver( const ast::TranslationGlobal & global ) : 386 386 ast::WithSymbolTable(ast::SymbolTable::ErrorDetection::ValidateOnAdd), 387 387 context{ symtab, global } {} 388 Resolver _new( const ResolveContext & context ) :388 Resolver( const ResolveContext & context ) : 389 389 ast::WithSymbolTable{ context.symtab }, 390 390 context{ symtab, context.global } {} … … 427 427 bool on_error(ast::ptr<ast::Decl> & decl); 428 428 }; 429 // size_t Resolver _new::traceId = Stats::Heap::new_stacktrace_id("Resolver");430 431 InitTweak::ManagedTypes _new Resolver_new::managedTypes;429 // size_t Resolver::traceId = Stats::Heap::new_stacktrace_id("Resolver"); 430 431 InitTweak::ManagedTypes Resolver::managedTypes; 432 432 433 433 void resolve( ast::TranslationUnit& translationUnit ) { 434 ast::Pass< Resolver _new>::run( translationUnit, translationUnit.global );434 ast::Pass< Resolver >::run( translationUnit, translationUnit.global ); 435 435 } 436 436 … … 439 439 ) { 440 440 assert( ctorInit ); 441 ast::Pass< Resolver _new> resolver( context );441 ast::Pass< Resolver > resolver( context ); 442 442 return ctorInit->accept( resolver ); 443 443 } … … 447 447 ) { 448 448 assert( stmtExpr ); 449 ast::Pass< Resolver _new> resolver( context );449 ast::Pass< Resolver > resolver( context ); 450 450 auto ret = mutate(stmtExpr->accept(resolver)); 451 451 strict_dynamic_cast< ast::StmtExpr * >( ret )->computeResult(); … … 489 489 } 490 490 491 const ast::FunctionDecl * Resolver _new::previsit( const ast::FunctionDecl * functionDecl ) {491 const ast::FunctionDecl * Resolver::previsit( const ast::FunctionDecl * functionDecl ) { 492 492 GuardValue( functionReturn ); 493 493 … … 563 563 } 564 564 565 const ast::FunctionDecl * Resolver _new::postvisit( const ast::FunctionDecl * functionDecl ) {565 const ast::FunctionDecl * Resolver::postvisit( const ast::FunctionDecl * functionDecl ) { 566 566 // default value expressions have an environment which shouldn't be there and trips up 567 567 // later passes. … … 591 591 } 592 592 593 const ast::ObjectDecl * Resolver _new::previsit( const ast::ObjectDecl * objectDecl ) {593 const ast::ObjectDecl * Resolver::previsit( const ast::ObjectDecl * objectDecl ) { 594 594 // To handle initialization of routine pointers [e.g. int (*fp)(int) = foo()], 595 595 // class-variable `initContext` is changed multiple times because the LHS is analyzed … … 630 630 // constructed objects cannot be designated 631 631 if ( InitTweak::isDesignated( mutDecl->init ) ) { 632 ast::Pass<ResolveDesignators _new> res( context );632 ast::Pass<ResolveDesignators> res( context ); 633 633 maybe_accept( mutDecl->init.get(), res ); 634 634 if ( !res.core.result ) { … … 650 650 } 651 651 652 void Resolver _new::previsit( const ast::AggregateDecl * _aggDecl ) {652 void Resolver::previsit( const ast::AggregateDecl * _aggDecl ) { 653 653 auto aggDecl = mutate(_aggDecl); 654 654 assertf(aggDecl == _aggDecl, "type declarations must be unique"); … … 662 662 } 663 663 664 void Resolver _new::previsit( const ast::StructDecl * structDecl ) {664 void Resolver::previsit( const ast::StructDecl * structDecl ) { 665 665 previsit(static_cast<const ast::AggregateDecl *>(structDecl)); 666 666 managedTypes.handleStruct(structDecl); 667 667 } 668 668 669 void Resolver _new::previsit( const ast::EnumDecl * ) {669 void Resolver::previsit( const ast::EnumDecl * ) { 670 670 // in case we decide to allow nested enums 671 671 GuardValue( inEnumDecl ); … … 674 674 } 675 675 676 const ast::StaticAssertDecl * Resolver _new::previsit(676 const ast::StaticAssertDecl * Resolver::previsit( 677 677 const ast::StaticAssertDecl * assertDecl 678 678 ) { … … 694 694 } 695 695 696 const ast::ArrayType * Resolver _new::previsit( const ast::ArrayType * at ) {696 const ast::ArrayType * Resolver::previsit( const ast::ArrayType * at ) { 697 697 return handlePtrType( at, context ); 698 698 } 699 699 700 const ast::PointerType * Resolver _new::previsit( const ast::PointerType * pt ) {700 const ast::PointerType * Resolver::previsit( const ast::PointerType * pt ) { 701 701 return handlePtrType( pt, context ); 702 702 } 703 703 704 const ast::ExprStmt * Resolver _new::previsit( const ast::ExprStmt * exprStmt ) {704 const ast::ExprStmt * Resolver::previsit( const ast::ExprStmt * exprStmt ) { 705 705 visit_children = false; 706 706 assertf( exprStmt->expr, "ExprStmt has null expression in resolver" ); … … 710 710 } 711 711 712 const ast::AsmExpr * Resolver _new::previsit( const ast::AsmExpr * asmExpr ) {712 const ast::AsmExpr * Resolver::previsit( const ast::AsmExpr * asmExpr ) { 713 713 visit_children = false; 714 714 … … 719 719 } 720 720 721 const ast::AsmStmt * Resolver _new::previsit( const ast::AsmStmt * asmStmt ) {721 const ast::AsmStmt * Resolver::previsit( const ast::AsmStmt * asmStmt ) { 722 722 visitor->maybe_accept( asmStmt, &ast::AsmStmt::input ); 723 723 visitor->maybe_accept( asmStmt, &ast::AsmStmt::output ); … … 726 726 } 727 727 728 const ast::IfStmt * Resolver _new::previsit( const ast::IfStmt * ifStmt ) {728 const ast::IfStmt * Resolver::previsit( const ast::IfStmt * ifStmt ) { 729 729 return ast::mutate_field( 730 730 ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, context ) ); 731 731 } 732 732 733 const ast::WhileDoStmt * Resolver _new::previsit( const ast::WhileDoStmt * whileDoStmt ) {733 const ast::WhileDoStmt * Resolver::previsit( const ast::WhileDoStmt * whileDoStmt ) { 734 734 return ast::mutate_field( 735 735 whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, context ) ); 736 736 } 737 737 738 const ast::ForStmt * Resolver _new::previsit( const ast::ForStmt * forStmt ) {738 const ast::ForStmt * Resolver::previsit( const ast::ForStmt * forStmt ) { 739 739 if ( forStmt->cond ) { 740 740 forStmt = ast::mutate_field( … … 750 750 } 751 751 752 const ast::SwitchStmt * Resolver _new::previsit( const ast::SwitchStmt * switchStmt ) {752 const ast::SwitchStmt * Resolver::previsit( const ast::SwitchStmt * switchStmt ) { 753 753 GuardValue( currentObject ); 754 754 switchStmt = ast::mutate_field( … … 759 759 } 760 760 761 const ast::CaseClause * Resolver _new::previsit( const ast::CaseClause * caseStmt ) {761 const ast::CaseClause * Resolver::previsit( const ast::CaseClause * caseStmt ) { 762 762 if ( caseStmt->cond ) { 763 763 std::deque< ast::InitAlternative > initAlts = currentObject.getOptions(); … … 780 780 } 781 781 782 const ast::BranchStmt * Resolver _new::previsit( const ast::BranchStmt * branchStmt ) {782 const ast::BranchStmt * Resolver::previsit( const ast::BranchStmt * branchStmt ) { 783 783 visit_children = false; 784 784 // must resolve the argument of a computed goto … … 793 793 } 794 794 795 const ast::ReturnStmt * Resolver _new::previsit( const ast::ReturnStmt * returnStmt ) {795 const ast::ReturnStmt * Resolver::previsit( const ast::ReturnStmt * returnStmt ) { 796 796 visit_children = false; 797 797 if ( returnStmt->expr ) { … … 803 803 } 804 804 805 const ast::ThrowStmt * Resolver _new::previsit( const ast::ThrowStmt * throwStmt ) {805 const ast::ThrowStmt * Resolver::previsit( const ast::ThrowStmt * throwStmt ) { 806 806 visit_children = false; 807 807 if ( throwStmt->expr ) { … … 818 818 } 819 819 820 const ast::CatchClause * Resolver _new::previsit( const ast::CatchClause * catchClause ) {820 const ast::CatchClause * Resolver::previsit( const ast::CatchClause * catchClause ) { 821 821 // Until we are very sure this invarent (ifs that move between passes have then) 822 822 // holds, check it. This allows a check for when to decode the mangling. … … 834 834 } 835 835 836 const ast::CatchClause * Resolver _new::postvisit( const ast::CatchClause * catchClause ) {836 const ast::CatchClause * Resolver::postvisit( const ast::CatchClause * catchClause ) { 837 837 // Decode the catchStmt so everything is stored properly. 838 838 const ast::IfStmt * ifStmt = catchClause->body.as<ast::IfStmt>(); … … 849 849 } 850 850 851 const ast::WaitForStmt * Resolver _new::previsit( const ast::WaitForStmt * stmt ) {851 const ast::WaitForStmt * Resolver::previsit( const ast::WaitForStmt * stmt ) { 852 852 visit_children = false; 853 853 … … 1114 1114 } 1115 1115 1116 const ast::WithStmt * Resolver _new::previsit( const ast::WithStmt * withStmt ) {1116 const ast::WithStmt * Resolver::previsit( const ast::WithStmt * withStmt ) { 1117 1117 auto mutStmt = mutate(withStmt); 1118 1118 resolveWithExprs(mutStmt->exprs, stmtsToAddBefore); … … 1120 1120 } 1121 1121 1122 void Resolver _new::resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd) {1122 void Resolver::resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd) { 1123 1123 for (auto & expr : exprs) { 1124 1124 // only struct- and union-typed expressions are viable candidates … … 1146 1146 1147 1147 1148 const ast::SingleInit * Resolver _new::previsit( const ast::SingleInit * singleInit ) {1148 const ast::SingleInit * Resolver::previsit( const ast::SingleInit * singleInit ) { 1149 1149 visit_children = false; 1150 1150 // resolve initialization using the possibilities as determined by the `currentObject` … … 1195 1195 } 1196 1196 1197 const ast::ListInit * Resolver _new::previsit( const ast::ListInit * listInit ) {1197 const ast::ListInit * Resolver::previsit( const ast::ListInit * listInit ) { 1198 1198 // move cursor into brace-enclosed initializer-list 1199 1199 currentObject.enterListInit( listInit->location ); … … 1218 1218 } 1219 1219 1220 const ast::ConstructorInit * Resolver _new::previsit( const ast::ConstructorInit * ctorInit ) {1220 const ast::ConstructorInit * Resolver::previsit( const ast::ConstructorInit * ctorInit ) { 1221 1221 visitor->maybe_accept( ctorInit, &ast::ConstructorInit::ctor ); 1222 1222 visitor->maybe_accept( ctorInit, &ast::ConstructorInit::dtor ); … … 1240 1240 1241 1241 // suppress error on autogen functions and mark invalid autogen as deleted. 1242 bool Resolver _new::on_error(ast::ptr<ast::Decl> & decl) {1242 bool Resolver::on_error(ast::ptr<ast::Decl> & decl) { 1243 1243 if (auto functionDecl = decl.as<ast::FunctionDecl>()) { 1244 1244 // xxx - can intrinsic gen ever fail? -
src/ResolvExpr/Resolver.h
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 #include <list> // for list19 20 18 #include "AST/Node.hpp" // for ptr 21 22 class ConstructorInit;23 class Declaration;24 class Expression;25 class DeletedExpr;26 class StmtExpr;27 class Type;28 namespace SymTab {29 class Indexer;30 } // namespace SymTab31 19 32 20 namespace ast { … … 45 33 46 34 namespace ResolvExpr { 47 /// Checks types and binds syntactic constructs to typed representations48 void resolve( std::list< Declaration * > translationUnit );49 void resolveDecl( Declaration *, const SymTab::Indexer & indexer );50 Expression *resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer );51 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer );52 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer );53 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer );54 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer );55 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer );56 /// Searches expr and returns the first DeletedExpr found, otherwise nullptr57 DeletedExpr * findDeletedExpr( Expression * expr );58 /// Resolves with-stmts and with-clauses on functions59 void resolveWithExprs( std::list< Declaration * > & translationUnit );60 35 61 36 /// Helper Type: Passes around information between various sub-calls. -
src/ResolvExpr/SpecCost.cc
r25f2798 r0bd3faf 76 76 77 77 public: 78 int get_count() const { return 0 <= count ? count : 0; }78 int result() const { return 0 <= count ? count : 0; } 79 79 80 80 // Mark specialization of base type. … … 125 125 return 0; 126 126 } 127 ast::Pass<SpecCounter> counter; 128 type->accept( counter ); 129 return counter.core.get_count(); 127 return ast::Pass<SpecCounter>::read( type ); 130 128 } 131 129 -
src/ResolvExpr/Unify.cc
r25f2798 r0bd3faf 105 105 /// If this isn't done when satifying ttype assertions, then argument lists can have 106 106 /// different size and structure when they should be compatible. 107 struct TtypeExpander _new: public ast::WithShortCircuiting, public ast::PureVisitor {107 struct TtypeExpander : public ast::WithShortCircuiting, public ast::PureVisitor { 108 108 ast::TypeEnvironment & tenv; 109 109 110 TtypeExpander _new( ast::TypeEnvironment & env ) : tenv( env ) {}110 TtypeExpander( ast::TypeEnvironment & env ) : tenv( env ) {} 111 111 112 112 const ast::Type * postvisit( const ast::TypeInstType * typeInst ) { … … 128 128 dst.reserve( src.size() ); 129 129 for ( const auto & d : src ) { 130 ast::Pass<TtypeExpander _new> expander{ env };130 ast::Pass<TtypeExpander> expander{ env }; 131 131 // TtypeExpander pass is impure (may mutate nodes in place) 132 132 // need to make nodes shared to prevent accidental mutation … … 268 268 } 269 269 270 class Unify _newfinal : public ast::WithShortCircuiting {270 class Unify final : public ast::WithShortCircuiting { 271 271 const ast::Type * type2; 272 272 ast::TypeEnvironment & tenv; … … 279 279 bool result; 280 280 281 Unify _new(281 Unify( 282 282 const ast::Type * type2, ast::TypeEnvironment & env, ast::AssertionSet & need, 283 283 ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen ) … … 606 606 if ( ! tuple2 ) return; 607 607 608 ast::Pass<TtypeExpander _new> expander{ tenv };608 ast::Pass<TtypeExpander> expander{ tenv }; 609 609 610 610 const ast::Type * flat = tuple->accept( expander ); … … 634 634 }; 635 635 636 // size_t Unify_new::traceId = Stats::Heap::new_stacktrace_id("Unify_new"); 636 // size_t Unify::traceId = Stats::Heap::new_stacktrace_id("Unify"); 637 637 638 bool unify( 638 639 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, … … 678 679 return env.bindVar( var2, type1, ast::TypeData{var2->base}, need, have, open, widen ); 679 680 } else { 680 return ast::Pass<Unify _new>::read(681 return ast::Pass<Unify>::read( 681 682 type1, type2, env, need, have, open, widen ); 682 683 } -
src/ResolvExpr/typeops.h
r25f2798 r0bd3faf 19 19 20 20 #include "AST/Type.hpp" 21 22 namespace SymTab {23 class Indexer;24 }25 21 26 22 namespace ResolvExpr { -
src/SymTab/FixFunction.cc
r25f2798 r0bd3faf 26 26 27 27 namespace { 28 struct FixFunction _newfinal : public ast::WithShortCircuiting {28 struct FixFunction final : public ast::WithShortCircuiting { 29 29 bool isVoid = false; 30 30 … … 70 70 71 71 const ast::DeclWithType * fixFunction( const ast::DeclWithType * dwt, bool & isVoid ) { 72 ast::Pass< FixFunction _new> fixer;72 ast::Pass< FixFunction > fixer; 73 73 dwt = dwt->accept( fixer ); 74 74 isVoid |= fixer.core.isVoid; … … 77 77 78 78 const ast::Type * fixFunction( const ast::Type * type, bool & isVoid ) { 79 ast::Pass< FixFunction _new> fixer;79 ast::Pass< FixFunction > fixer; 80 80 type = type->accept( fixer ); 81 81 isVoid |= fixer.core.isVoid; -
src/SymTab/GenImplicitCall.cpp
r25f2798 r0bd3faf 32 32 template< typename OutIter > 33 33 ast::ptr< ast::Stmt > genCall( 34 InitTweak::InitExpander _new& srcParam, const ast::Expr * dstParam,34 InitTweak::InitExpander & srcParam, const ast::Expr * dstParam, 35 35 const CodeLocation & loc, const std::string & fname, OutIter && out, 36 36 const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward ); … … 42 42 template< typename OutIter > 43 43 ast::ptr< ast::Stmt > genScalarCall( 44 InitTweak::InitExpander _new& srcParam, const ast::Expr * dstParam,44 InitTweak::InitExpander & srcParam, const ast::Expr * dstParam, 45 45 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 46 46 const ast::Type * addCast = nullptr … … 98 98 template< typename OutIter > 99 99 void genArrayCall( 100 InitTweak::InitExpander _new& srcParam, const ast::Expr * dstParam,100 InitTweak::InitExpander & srcParam, const ast::Expr * dstParam, 101 101 const CodeLocation & loc, const std::string & fname, OutIter && out, 102 102 const ast::ArrayType * array, const ast::Type * addCast = nullptr, … … 167 167 template< typename OutIter > 168 168 ast::ptr< ast::Stmt > genCall( 169 InitTweak::InitExpander _new& srcParam, const ast::Expr * dstParam,169 InitTweak::InitExpander & srcParam, const ast::Expr * dstParam, 170 170 const CodeLocation & loc, const std::string & fname, OutIter && out, 171 171 const ast::Type * type, const ast::Type * addCast, LoopDirection forward … … 185 185 186 186 ast::ptr< ast::Stmt > genImplicitCall( 187 InitTweak::InitExpander _new& srcParam, const ast::Expr * dstParam,187 InitTweak::InitExpander & srcParam, const ast::Expr * dstParam, 188 188 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 189 189 LoopDirection forward -
src/SymTab/GenImplicitCall.hpp
r25f2798 r0bd3faf 26 26 /// dstParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. 27 27 ast::ptr<ast::Stmt> genImplicitCall( 28 InitTweak::InitExpander _new& srcParam, const ast::Expr * dstParam,28 InitTweak::InitExpander & srcParam, const ast::Expr * dstParam, 29 29 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 30 30 LoopDirection forward = LoopForward -
src/SymTab/Mangler.cc
r25f2798 r0bd3faf 30 30 namespace { 31 31 /// Mangles names to a unique C identifier 32 struct Mangler _new : public ast::WithShortCircuiting, public ast::WithVisitorRef<Mangler_new>, public ast::WithGuards {33 Mangler _new( Mangle::Mode mode );34 Mangler _new( const Mangler_new& ) = delete;32 struct Mangler : public ast::WithShortCircuiting, public ast::WithVisitorRef<Mangler>, public ast::WithGuards { 33 Mangler( Mangle::Mode mode ); 34 Mangler( const Mangler & ) = delete; 35 35 36 36 void previsit( const ast::Node * ) { visit_children = false; } … … 72 72 73 73 private: 74 Mangler _new( bool mangleOverridable, bool typeMode, bool mangleGenericParams,74 Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 75 75 int nextVarNum, const VarMapType& varNums ); 76 friend class ast::Pass<Mangler _new>;76 friend class ast::Pass<Mangler>; 77 77 78 78 private: … … 81 81 82 82 void printQualifiers( const ast::Type *type ); 83 }; // Mangler _new83 }; // Mangler 84 84 } // namespace 85 85 86 86 std::string mangle( const ast::Node * decl, Mangle::Mode mode ) { 87 return ast::Pass<Mangler _new>::read( decl, mode );87 return ast::Pass<Mangler>::read( decl, mode ); 88 88 } 89 89 90 90 namespace { 91 Mangler _new::Mangler_new( Mangle::Mode mode )91 Mangler::Mangler( Mangle::Mode mode ) 92 92 : nextVarNum( 0 ), isTopLevel( true ), 93 93 mangleOverridable ( ! mode.no_overrideable ), … … 95 95 mangleGenericParams( ! mode.no_generic_params ) {} 96 96 97 Mangler _new::Mangler_new( bool mangleOverridable, bool typeMode, bool mangleGenericParams,97 Mangler::Mangler( bool mangleOverridable, bool typeMode, bool mangleGenericParams, 98 98 int nextVarNum, const VarMapType& varNums ) 99 99 : varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( false ), … … 101 101 mangleGenericParams( mangleGenericParams ) {} 102 102 103 void Mangler _new::mangleDecl( const ast::DeclWithType * decl ) {103 void Mangler::mangleDecl( const ast::DeclWithType * decl ) { 104 104 bool wasTopLevel = isTopLevel; 105 105 if ( isTopLevel ) { … … 131 131 } 132 132 133 void Mangler _new::postvisit( const ast::ObjectDecl * decl ) {133 void Mangler::postvisit( const ast::ObjectDecl * decl ) { 134 134 mangleDecl( decl ); 135 135 } 136 136 137 void Mangler _new::postvisit( const ast::FunctionDecl * decl ) {137 void Mangler::postvisit( const ast::FunctionDecl * decl ) { 138 138 mangleDecl( decl ); 139 139 } 140 140 141 void Mangler _new::postvisit( const ast::VoidType * voidType ) {141 void Mangler::postvisit( const ast::VoidType * voidType ) { 142 142 printQualifiers( voidType ); 143 143 mangleName += Encoding::void_t; 144 144 } 145 145 146 void Mangler _new::postvisit( const ast::BasicType * basicType ) {146 void Mangler::postvisit( const ast::BasicType * basicType ) { 147 147 printQualifiers( basicType ); 148 148 assertf( basicType->kind < ast::BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->kind ); … … 150 150 } 151 151 152 void Mangler _new::postvisit( const ast::PointerType * pointerType ) {152 void Mangler::postvisit( const ast::PointerType * pointerType ) { 153 153 printQualifiers( pointerType ); 154 154 // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers … … 157 157 } 158 158 159 void Mangler _new::postvisit( const ast::ArrayType * arrayType ) {159 void Mangler::postvisit( const ast::ArrayType * arrayType ) { 160 160 // TODO: encode dimension 161 161 printQualifiers( arrayType ); … … 164 164 } 165 165 166 void Mangler _new::postvisit( const ast::ReferenceType * refType ) {166 void Mangler::postvisit( const ast::ReferenceType * refType ) { 167 167 // don't print prefix (e.g. 'R') for reference types so that references and non-references do not overload. 168 168 // Further, do not print the qualifiers for a reference type (but do run printQualifers because of TypeDecls, etc.), … … 174 174 } 175 175 176 void Mangler _new::postvisit( const ast::FunctionType * functionType ) {176 void Mangler::postvisit( const ast::FunctionType * functionType ) { 177 177 printQualifiers( functionType ); 178 178 mangleName += Encoding::function; … … 189 189 } 190 190 191 void Mangler _new::mangleRef(191 void Mangler::mangleRef( 192 192 const ast::BaseInstType * refType, const std::string & prefix ) { 193 193 printQualifiers( refType ); … … 206 206 } 207 207 208 void Mangler _new::postvisit( const ast::StructInstType * aggregateUseType ) {208 void Mangler::postvisit( const ast::StructInstType * aggregateUseType ) { 209 209 mangleRef( aggregateUseType, Encoding::struct_t ); 210 210 } 211 211 212 void Mangler _new::postvisit( const ast::UnionInstType * aggregateUseType ) {212 void Mangler::postvisit( const ast::UnionInstType * aggregateUseType ) { 213 213 mangleRef( aggregateUseType, Encoding::union_t ); 214 214 } 215 215 216 void Mangler _new::postvisit( const ast::EnumInstType * aggregateUseType ) {216 void Mangler::postvisit( const ast::EnumInstType * aggregateUseType ) { 217 217 mangleRef( aggregateUseType, Encoding::enum_t ); 218 218 } 219 219 220 void Mangler _new::postvisit( const ast::TypeInstType * typeInst ) {220 void Mangler::postvisit( const ast::TypeInstType * typeInst ) { 221 221 VarMapType::iterator varNum = varNums.find( typeInst->name ); 222 222 if ( varNum == varNums.end() ) { … … 234 234 } 235 235 236 void Mangler _new::postvisit( const ast::TraitInstType * inst ) {236 void Mangler::postvisit( const ast::TraitInstType * inst ) { 237 237 printQualifiers( inst ); 238 238 mangleName += std::to_string( inst->name.size() ) + inst->name; 239 239 } 240 240 241 void Mangler _new::postvisit( const ast::TupleType * tupleType ) {241 void Mangler::postvisit( const ast::TupleType * tupleType ) { 242 242 printQualifiers( tupleType ); 243 243 mangleName += Encoding::tuple + std::to_string( tupleType->types.size() ); … … 245 245 } 246 246 247 void Mangler _new::postvisit( const ast::VarArgsType * varArgsType ) {247 void Mangler::postvisit( const ast::VarArgsType * varArgsType ) { 248 248 printQualifiers( varArgsType ); 249 249 static const std::string vargs = "__builtin_va_list"; … … 251 251 } 252 252 253 void Mangler _new::postvisit( const ast::ZeroType * ) {253 void Mangler::postvisit( const ast::ZeroType * ) { 254 254 mangleName += Encoding::zero; 255 255 } 256 256 257 void Mangler _new::postvisit( const ast::OneType * ) {257 void Mangler::postvisit( const ast::OneType * ) { 258 258 mangleName += Encoding::one; 259 259 } 260 260 261 void Mangler _new::postvisit( const ast::QualifiedType * qualType ) {261 void Mangler::postvisit( const ast::QualifiedType * qualType ) { 262 262 bool inqual = inQualifiedType; 263 263 if ( !inqual ) { … … 275 275 } 276 276 277 void Mangler _new::postvisit( const ast::TypeDecl * decl ) {277 void Mangler::postvisit( const ast::TypeDecl * decl ) { 278 278 // TODO: is there any case where mangling a TypeDecl makes sense? If so, this code needs to be 279 279 // fixed to ensure that two TypeDecls mangle to the same name when they are the same type and vice versa. … … 281 281 // and the case has not yet come up in practice. Alternatively, if not then this code can be removed 282 282 // aside from the assert false. 283 assertf(false, "Mangler _newshould not visit typedecl: %s", toCString(decl));283 assertf(false, "Mangler should not visit typedecl: %s", toCString(decl)); 284 284 assertf( decl->kind < ast::TypeDecl::Kind::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind ); 285 285 mangleName += Encoding::typeVariables[ decl->kind ] + std::to_string( decl->name.length() ) + decl->name; … … 293 293 } 294 294 295 void Mangler _new::printQualifiers( const ast::Type * type ) {295 void Mangler::printQualifiers( const ast::Type * type ) { 296 296 // skip if not including qualifiers 297 297 if ( typeMode ) return; … … 318 318 } // for 319 319 for ( auto & assert : funcType->assertions ) { 320 assertionNames.push_back( ast::Pass<Mangler _new>::read(320 assertionNames.push_back( ast::Pass<Mangler>::read( 321 321 assert->var.get(), 322 322 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ) ); -
src/Tuples/TupleAssignment.cc
r25f2798 r0bd3faf 65 65 66 66 /// Dispatcher for tuple (multiple and mass) assignment operations 67 class TupleAssignSpotter _newfinal {67 class TupleAssignSpotter final { 68 68 /// Actually finds tuple assignment operations, by subclass 69 69 struct Matcher { 70 70 ResolvExpr::CandidateList lhs, rhs; 71 TupleAssignSpotter _new& spotter;71 TupleAssignSpotter & spotter; 72 72 CodeLocation location; 73 73 ResolvExpr::Cost baseCost; … … 84 84 85 85 Matcher( 86 TupleAssignSpotter _new& s, const CodeLocation & loc,86 TupleAssignSpotter & s, const CodeLocation & loc, 87 87 const ResolvExpr::CandidateList & l, const ResolvExpr::CandidateList & r ) 88 88 : lhs( l ), rhs( r ), spotter( s ), location( loc ), … … 161 161 struct MassAssignMatcher final : public Matcher { 162 162 MassAssignMatcher( 163 TupleAssignSpotter _new& s, const CodeLocation & loc,163 TupleAssignSpotter & s, const CodeLocation & loc, 164 164 const ResolvExpr::CandidateList & l, const ResolvExpr::CandidateList & r ) 165 165 : Matcher( s, loc, l, r ) {} … … 191 191 struct MultipleAssignMatcher final : public Matcher { 192 192 MultipleAssignMatcher( 193 TupleAssignSpotter _new& s, const CodeLocation & loc,193 TupleAssignSpotter & s, const CodeLocation & loc, 194 194 const ResolvExpr::CandidateList & l, const ResolvExpr::CandidateList & r ) 195 195 : Matcher( s, loc, l, r ) {} … … 240 240 241 241 public: 242 TupleAssignSpotter _new( ResolvExpr::CandidateFinder & f )242 TupleAssignSpotter( ResolvExpr::CandidateFinder & f ) 243 243 : crntFinder( f ), fname(), matcher() {} 244 244 … … 377 377 std::vector< ResolvExpr::CandidateFinder > & args 378 378 ) { 379 TupleAssignSpotter _newspotter{ finder };379 TupleAssignSpotter spotter{ finder }; 380 380 spotter.spot( assign, args ); 381 381 } -
src/Validate/Autogen.cpp
r25f2798 r0bd3faf 49 49 50 50 // -------------------------------------------------------------------------- 51 struct AutogenerateRoutines _newfinal :51 struct AutogenerateRoutines final : 52 52 public ast::WithDeclsToAdd<>, 53 53 public ast::WithShortCircuiting { … … 232 232 233 233 // -------------------------------------------------------------------------- 234 void AutogenerateRoutines _new::previsit( const ast::EnumDecl * enumDecl ) {234 void AutogenerateRoutines::previsit( const ast::EnumDecl * enumDecl ) { 235 235 // Must visit children (enum constants) to add them to the symbol table. 236 236 if ( !enumDecl->body ) return; … … 249 249 } 250 250 251 void AutogenerateRoutines _new::previsit( const ast::StructDecl * structDecl ) {251 void AutogenerateRoutines::previsit( const ast::StructDecl * structDecl ) { 252 252 visit_children = false; 253 253 if ( !structDecl->body ) return; … … 265 265 } 266 266 267 void AutogenerateRoutines _new::previsit( const ast::UnionDecl * unionDecl ) {267 void AutogenerateRoutines::previsit( const ast::UnionDecl * unionDecl ) { 268 268 visit_children = false; 269 269 if ( !unionDecl->body ) return; … … 282 282 283 283 /// Generate ctor/dtors/assign for typedecls, e.g., otype T = int *; 284 void AutogenerateRoutines _new::previsit( const ast::TypeDecl * typeDecl ) {284 void AutogenerateRoutines::previsit( const ast::TypeDecl * typeDecl ) { 285 285 if ( !typeDecl->base ) return; 286 286 … … 290 290 } 291 291 292 void AutogenerateRoutines _new::previsit( const ast::TraitDecl * ) {292 void AutogenerateRoutines::previsit( const ast::TraitDecl * ) { 293 293 // Ensure that we don't add assignment ops for types defined as part of the trait 294 294 visit_children = false; 295 295 } 296 296 297 void AutogenerateRoutines _new::previsit( const ast::FunctionDecl * ) {297 void AutogenerateRoutines::previsit( const ast::FunctionDecl * ) { 298 298 // Track whether we're currently in a function. 299 299 // Can ignore function type idiosyncrasies, because function type can never … … 302 302 } 303 303 304 void AutogenerateRoutines _new::postvisit( const ast::FunctionDecl * ) {304 void AutogenerateRoutines::postvisit( const ast::FunctionDecl * ) { 305 305 functionNesting -= 1; 306 306 } … … 521 521 const ast::Expr * src, const ast::ObjectDecl * field, 522 522 ast::FunctionDecl * func, SymTab::LoopDirection direction ) { 523 InitTweak::InitExpander _newsrcParam( src );523 InitTweak::InitExpander srcParam( src ); 524 524 // Assign to destination. 525 525 ast::MemberExpr * dstSelect = new ast::MemberExpr( … … 795 795 796 796 void autogenerateRoutines( ast::TranslationUnit & translationUnit ) { 797 ast::Pass<AutogenerateRoutines _new>::run( translationUnit );797 ast::Pass<AutogenerateRoutines>::run( translationUnit ); 798 798 } 799 799
Note:
See TracChangeset
for help on using the changeset viewer.