Changes in src/Validate/Autogen.cpp [bbf2cb1:0522ebe]
- File:
-
- 1 edited
-
src/Validate/Autogen.cpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
rbbf2cb1 r0522ebe 133 133 /// Generates a single struct member operation. 134 134 /// (constructor call, destructor call, assignment call) 135 const ast::Stmt * makeMemberOp( 135 // This is managed because it uses another helper that returns a ast::ptr. 136 ast::ptr<ast::Stmt> makeMemberOp( 136 137 const CodeLocation& location, 137 138 const ast::ObjectDecl * dstParam, const ast::Expr * src, … … 197 198 bool shouldAutogen() const final { return true; } 198 199 void genAttrFuncForward(); 199 void genPosFunctions();200 200 private: 201 201 void genFuncBody( ast::FunctionDecl * decl ) final; … … 206 206 ast::FunctionDecl * genLabelProto() const; 207 207 ast::FunctionDecl * genValueProto() const; 208 ast::FunctionDecl * genSuccProto() const; 209 ast::FunctionDecl * genPredProto() const; 210 211 ast::FunctionDecl * genSuccPosProto() const; 212 ast::FunctionDecl * genPredPosProto() const; 213 214 ast::FunctionDecl * genSuccPredFunc( bool succ ); 215 // ast::FunctionDecl * genPredFunc(); 208 // ast::FunctionDecl * genValueProto2() const; 216 209 }; 217 210 … … 258 251 if ( enumDecl->base ) { 259 252 gen.genAttrFuncForward(); 260 gen.genPosFunctions();261 253 } 262 254 gen.generateAndAppendFunctions( declsToAddAfter ); … … 533 525 } 534 526 535 const ast::Stmt *StructFuncGenerator::makeMemberOp(527 ast::ptr<ast::Stmt> StructFuncGenerator::makeMemberOp( 536 528 const CodeLocation& location, const ast::ObjectDecl * dstParam, 537 529 const ast::Expr * src, const ast::ObjectDecl * field, … … 548 540 ) 549 541 ); 550 const ast::Stmt *stmt = genImplicitCall(542 auto stmt = genImplicitCall( 551 543 srcParam, dstSelect, location, func->name, 552 544 field, direction … … 606 598 location, field, new ast::VariableExpr( location, srcParam ) 607 599 ) : nullptr; 608 const ast::Stmt *stmt =600 ast::ptr<ast::Stmt> stmt = 609 601 makeMemberOp( location, dstParam, srcSelect, field, func, direction ); 610 602 611 603 if ( nullptr != stmt ) { 612 stmts->kids. emplace_back( stmt );604 stmts->kids.push_back( stmt ); 613 605 } 614 606 } … … 631 623 for ( auto param = params.begin() + 1 ; current != end ; ++current ) { 632 624 const ast::ptr<ast::Decl> & member = *current; 633 const ast::Stmt *stmt = nullptr;625 ast::ptr<ast::Stmt> stmt = nullptr; 634 626 auto field = member.as<ast::ObjectDecl>(); 635 627 // Not sure why it could be null. … … 649 641 650 642 if ( nullptr != stmt ) { 651 stmts->kids. emplace_back( stmt );643 stmts->kids.push_back( stmt ); 652 644 } 653 645 } … … 799 791 } 800 792 801 ast::FunctionDecl * EnumFuncGenerator::genSuccProto() const { 802 return genProto( "succ", 803 { new ast::ObjectDecl( getLocation(), "_i", new ast::EnumInstType( decl ) )}, 804 { new ast::ObjectDecl( getLocation(), "_ret", new ast::EnumInstType( decl ))} ); 805 } 806 807 ast::FunctionDecl * EnumFuncGenerator::genPredProto() const { 808 return genProto( "pred", 809 { new ast::ObjectDecl( getLocation(), "_i", new ast::EnumInstType( decl ))}, 810 { new ast::ObjectDecl( getLocation(), "_ret", new ast::EnumInstType( decl ))} ); 811 } 812 813 ast::FunctionDecl * EnumFuncGenerator::genSuccPosProto() const { 814 return genProto( "_successor_", 815 { new ast::ObjectDecl( getLocation(), "_i", 816 new ast::EnumPosType( new ast::EnumInstType( decl ) ) )}, 817 { 818 new ast::ObjectDecl( getLocation(), "_ret", 819 new ast::EnumPosType( new ast::EnumInstType( decl ) ) ) 820 } ); 821 } 822 823 ast::FunctionDecl * EnumFuncGenerator::genPredPosProto() const { 824 return genProto( "_predessor_", 825 { new ast::ObjectDecl( getLocation(), "_i", 826 new ast::EnumPosType( new ast::EnumInstType( decl ) ) )}, 827 { 828 new ast::ObjectDecl( getLocation(), "_ret", 829 new ast::EnumPosType( new ast::EnumInstType( decl ) ) ) 830 } ); 831 } 832 833 ast::FunctionDecl * EnumFuncGenerator::genSuccPredFunc( bool succ ) { 834 ast::FunctionDecl * decl = succ? genSuccPosProto(): genPredPosProto(); 835 produceForwardDecl( decl ); 836 837 const CodeLocation& location = getLocation(); 838 839 auto & params = decl->params; 840 assert( params.size() == 1 ); 841 auto param = params.front().strict_as<ast::ObjectDecl>(); 842 843 auto newReturn = new ast::ObjectDecl( location, "_returns", 844 new ast::BasicType{ ast::BasicType::SignedInt} ); 845 846 847 ast::UntypedExpr * addOneExpr = new ast::UntypedExpr( location, 848 new ast::NameExpr( location, succ? "?+?": "?-?" ) 849 ); 850 addOneExpr->args.push_back( 851 new ast::CastExpr( location, 852 new ast::VariableExpr( location, param ), 853 new ast::BasicType{ ast::BasicType::SignedInt } 854 ) 855 ); 856 addOneExpr->args.push_back( 857 ast::ConstantExpr::from_int( location, 1 ) 858 ); 859 860 ast::UntypedExpr * assignExpr = new ast::UntypedExpr( location, 861 new ast::NameExpr( location, "?=?" ) 862 ); 863 assignExpr->args.push_back( 864 new ast::VariableExpr( location, newReturn ) 865 ); 866 assignExpr->args.push_back( 867 addOneExpr 868 ); 869 870 decl->stmts = new ast::CompoundStmt( location, 871 { 872 new ast::DeclStmt( location, newReturn ), 873 new ast::ExprStmt( location, assignExpr ), 874 new ast::ReturnStmt( location, 875 new ast::VariableExpr( location, newReturn )) 876 } ); 877 878 return decl; 879 } 793 // ast::FunctionDecl * EnumFuncGenerator::genValueProto2() const { 794 // return genProto( "valueE", 795 // { new ast::ObjectDecl( getLocation(), "_i", new ast::EnumPosType( new ast::EnumInstType( decl ) ) )}, 796 // { new ast::ObjectDecl( getLocation(), "_ret", ast::deepCopy( decl->base ) ) } ); 797 // } 880 798 881 799 void EnumFuncGenerator::genAttrFuncForward() { 882 800 if ( decl->base ) { 883 ast::FunctionDecl *(EnumFuncGenerator::*attrProtos[ 5])() const = {801 ast::FunctionDecl *(EnumFuncGenerator::*attrProtos[3])() const = { 884 802 &EnumFuncGenerator::genPosProto, &EnumFuncGenerator::genLabelProto, 885 &EnumFuncGenerator::genValueProto, &EnumFuncGenerator::genSuccProto, 886 &EnumFuncGenerator::genPredProto 887 // ,&EnumFuncGenerator::genSuccPosProto, 888 // &EnumFuncGenerator::genPredPosProto 889 }; 803 &EnumFuncGenerator::genValueProto 804 // , &EnumFuncGenerator::genValueProto2 805 }; 890 806 for ( auto & generator : attrProtos ) { 891 807 produceForwardDecl( (this->*generator)() ); 892 808 } 893 809 } 894 }895 896 void EnumFuncGenerator::genPosFunctions() {897 if ( decl->base ) {898 ast::FunctionDecl * succ = genSuccPredFunc( true );899 ast::FunctionDecl * pred = genSuccPredFunc( false );900 produceDecl( succ );901 produceDecl( pred );902 }903 904 810 } 905 811
Note:
See TracChangeset
for help on using the changeset viewer.