Changes in src/Validate/Autogen.cpp [0522ebe:bbf2cb1]
- File:
-
- 1 edited
-
src/Validate/Autogen.cpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
r0522ebe rbbf2cb1 133 133 /// Generates a single struct member operation. 134 134 /// (constructor call, destructor call, assignment call) 135 // This is managed because it uses another helper that returns a ast::ptr. 136 ast::ptr<ast::Stmt> makeMemberOp( 135 const ast::Stmt * makeMemberOp( 137 136 const CodeLocation& location, 138 137 const ast::ObjectDecl * dstParam, const ast::Expr * src, … … 198 197 bool shouldAutogen() const final { return true; } 199 198 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 * genValueProto2() 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(); 209 216 }; 210 217 … … 251 258 if ( enumDecl->base ) { 252 259 gen.genAttrFuncForward(); 260 gen.genPosFunctions(); 253 261 } 254 262 gen.generateAndAppendFunctions( declsToAddAfter ); … … 525 533 } 526 534 527 ast::ptr<ast::Stmt>StructFuncGenerator::makeMemberOp(535 const ast::Stmt * StructFuncGenerator::makeMemberOp( 528 536 const CodeLocation& location, const ast::ObjectDecl * dstParam, 529 537 const ast::Expr * src, const ast::ObjectDecl * field, … … 540 548 ) 541 549 ); 542 autostmt = genImplicitCall(550 const ast::Stmt * stmt = genImplicitCall( 543 551 srcParam, dstSelect, location, func->name, 544 552 field, direction … … 598 606 location, field, new ast::VariableExpr( location, srcParam ) 599 607 ) : nullptr; 600 ast::ptr<ast::Stmt>stmt =608 const ast::Stmt * stmt = 601 609 makeMemberOp( location, dstParam, srcSelect, field, func, direction ); 602 610 603 611 if ( nullptr != stmt ) { 604 stmts->kids. push_back( stmt );612 stmts->kids.emplace_back( stmt ); 605 613 } 606 614 } … … 623 631 for ( auto param = params.begin() + 1 ; current != end ; ++current ) { 624 632 const ast::ptr<ast::Decl> & member = *current; 625 ast::ptr<ast::Stmt>stmt = nullptr;633 const ast::Stmt * stmt = nullptr; 626 634 auto field = member.as<ast::ObjectDecl>(); 627 635 // Not sure why it could be null. … … 641 649 642 650 if ( nullptr != stmt ) { 643 stmts->kids. push_back( stmt );651 stmts->kids.emplace_back( stmt ); 644 652 } 645 653 } … … 791 799 } 792 800 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 // } 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 } 798 880 799 881 void EnumFuncGenerator::genAttrFuncForward() { 800 882 if ( decl->base ) { 801 ast::FunctionDecl *(EnumFuncGenerator::*attrProtos[ 3])() const = {883 ast::FunctionDecl *(EnumFuncGenerator::*attrProtos[5])() const = { 802 884 &EnumFuncGenerator::genPosProto, &EnumFuncGenerator::genLabelProto, 803 &EnumFuncGenerator::genValueProto 804 // , &EnumFuncGenerator::genValueProto2 805 }; 885 &EnumFuncGenerator::genValueProto, &EnumFuncGenerator::genSuccProto, 886 &EnumFuncGenerator::genPredProto 887 // ,&EnumFuncGenerator::genSuccPosProto, 888 // &EnumFuncGenerator::genPredPosProto 889 }; 806 890 for ( auto & generator : attrProtos ) { 807 891 produceForwardDecl( (this->*generator)() ); 808 892 } 809 893 } 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 810 904 } 811 905
Note:
See TracChangeset
for help on using the changeset viewer.