- Timestamp:
- Mar 1, 2024, 4:32:35 PM (11 months ago)
- Branches:
- master
- Children:
- bbf2cb1
- Parents:
- f1149ac
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ConversionCost.cc
rf1149ac r00eaeb8 288 288 cost = Cost::unsafe; 289 289 } 290 } else if ( dynamic_cast< const ast::EnumPosType *>(dst) ) { 291 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 292 cost = costCalc( basicType, integer, srcIsLvalue, symtab, env ); 290 293 } 291 294 } … … 366 369 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 367 370 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 368 // }369 371 if ( cost < Cost::unsafe ) { 370 372 cost.incSafe(); … … 373 375 374 376 void ConversionCost::postvisit( const ast::EnumPosType * ) { 375 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 376 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 377 if ( cost < Cost::unsafe ) { 378 cost.incSafe(); 379 } 377 if ( dynamic_cast<const ast::EnumPosType *>( dst ) ) { 378 // Tempoarary 379 cost = Cost::zero; 380 } else { 381 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 382 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 383 if ( cost < Cost::unsafe ) { 384 cost.incSafe(); 385 } 386 } 387 380 388 } 381 389 -
src/Validate/Autogen.cpp
rf1149ac r00eaeb8 197 197 bool shouldAutogen() const final { return true; } 198 198 void genAttrFuncForward(); 199 void genPosFunctions(); 199 200 private: 200 201 void genFuncBody( ast::FunctionDecl * decl ) final; … … 205 206 ast::FunctionDecl * genLabelProto() const; 206 207 ast::FunctionDecl * genValueProto() const; 207 // 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 void genSuccFunc(ast::FunctionDecl *); 208 215 }; 209 216 … … 250 257 if ( enumDecl->base ) { 251 258 gen.genAttrFuncForward(); 259 gen.genPosFunctions(); 252 260 } 253 261 gen.generateAndAppendFunctions( declsToAddAfter ); … … 790 798 } 791 799 792 // ast::FunctionDecl * EnumFuncGenerator::genValueProto2() const { 793 // return genProto( "valueE", 794 // { new ast::ObjectDecl( getLocation(), "_i", new ast::EnumPosType( new ast::EnumInstType( decl ) ) )}, 795 // { new ast::ObjectDecl( getLocation(), "_ret", ast::deepCopy( decl->base ) ) } ); 796 // } 800 ast::FunctionDecl * EnumFuncGenerator::genSuccProto() const { 801 return genProto( "succ", 802 { new ast::ObjectDecl( getLocation(), "_i", new ast::EnumInstType( decl ) )}, 803 { new ast::ObjectDecl( getLocation(), "_ret", new ast::EnumInstType( decl ))} ); 804 } 805 806 ast::FunctionDecl * EnumFuncGenerator::genPredProto() const { 807 return genProto( "pred", 808 { new ast::ObjectDecl( getLocation(), "_i", new ast::EnumInstType( decl ))}, 809 { new ast::ObjectDecl( getLocation(), "_ret", new ast::EnumInstType( decl ))} ); 810 } 811 812 ast::FunctionDecl * EnumFuncGenerator::genSuccPosProto() const { 813 return genProto( "succ", 814 { new ast::ObjectDecl( getLocation(), "_i", 815 new ast::EnumPosType( new ast::EnumInstType( decl ) ) )}, 816 { 817 new ast::ObjectDecl( getLocation(), "_ret", 818 new ast::EnumPosType( new ast::EnumInstType( decl ) ) ) 819 } ); 820 } 821 822 ast::FunctionDecl * EnumFuncGenerator::genPredPosProto() const { 823 return genProto( "pred", 824 { new ast::ObjectDecl( getLocation(), "_i", 825 new ast::EnumPosType( new ast::EnumInstType( decl ) ) )}, 826 { 827 new ast::ObjectDecl( getLocation(), "_ret", 828 new ast::EnumPosType( new ast::EnumInstType( decl ) ) ) 829 } ); 830 } 831 832 void EnumFuncGenerator::genSuccFunc(ast::FunctionDecl * succDecl) { 833 const CodeLocation& location = getLocation(); 834 835 auto & params = succDecl->params; 836 assert( params.size() == 1 ); 837 auto param = params.front().strict_as<ast::ObjectDecl>(); 838 839 // auto & returns = succDecl->returns; 840 // assert( returns.size() == 1 ); 841 // auto oldRet = returns.front().strict_as<ast::ObjectDecl>(); 842 843 // auto param = new ast::ObjectDecl( getLocation(), "_i", 844 // new ast::EnumPosType( new ast::EnumInstType( decl ) ) ); 845 846 auto newReturn = new ast::ObjectDecl( location, "_returns", 847 new ast::BasicType{ ast::BasicType::SignedInt} ); 848 849 850 ast::UntypedExpr * addOneExpr = new ast::UntypedExpr( location, 851 new ast::NameExpr( location, "?+?" ) 852 ); 853 addOneExpr->args.push_back( 854 new ast::CastExpr( location, 855 new ast::VariableExpr( location, param ), 856 new ast::BasicType{ ast::BasicType::SignedInt } 857 ) 858 ); 859 addOneExpr->args.push_back( 860 ast::ConstantExpr::from_int( location, 1 ) 861 ); 862 863 ast::UntypedExpr * assignExpr = new ast::UntypedExpr( location, 864 new ast::NameExpr( location, "?=?" ) 865 ); 866 assignExpr->args.push_back( 867 new ast::VariableExpr( location, newReturn ) 868 ); 869 assignExpr->args.push_back( 870 addOneExpr 871 ); 872 873 succDecl->stmts = new ast::CompoundStmt( location, 874 { 875 new ast::DeclStmt( location, newReturn ), 876 new ast::ExprStmt( location, assignExpr ), 877 new ast::ReturnStmt( location, 878 new ast::VariableExpr( location, newReturn )) 879 } ); 880 } 797 881 798 882 void EnumFuncGenerator::genAttrFuncForward() { 799 883 if ( decl->base ) { 800 ast::FunctionDecl *(EnumFuncGenerator::*attrProtos[ 3])() const = {884 ast::FunctionDecl *(EnumFuncGenerator::*attrProtos[5])() const = { 801 885 &EnumFuncGenerator::genPosProto, &EnumFuncGenerator::genLabelProto, 802 &EnumFuncGenerator::genValueProto 803 // , &EnumFuncGenerator::genValueProto2804 886 &EnumFuncGenerator::genValueProto, &EnumFuncGenerator::genSuccProto, 887 &EnumFuncGenerator::genPredProto 888 }; 805 889 for ( auto & generator : attrProtos ) { 806 890 produceForwardDecl( (this->*generator)() ); 807 891 } 808 892 } 893 } 894 895 void EnumFuncGenerator::genPosFunctions() { 896 if ( decl->base ) { 897 ast::FunctionDecl * decl = genSuccPosProto(); 898 produceForwardDecl( decl ); 899 genSuccFunc (decl ); 900 produceDecl( decl ); 901 } 902 809 903 } 810 904
Note: See TracChangeset
for help on using the changeset viewer.