Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    rbbf2cb1 r0522ebe  
    133133        /// Generates a single struct member operation.
    134134        /// (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(
    136137                const CodeLocation& location,
    137138                const ast::ObjectDecl * dstParam, const ast::Expr * src,
     
    197198        bool shouldAutogen() const final { return true; }
    198199        void genAttrFuncForward();
    199         void genPosFunctions();
    200200private:
    201201        void genFuncBody( ast::FunctionDecl * decl ) final;
     
    206206        ast::FunctionDecl * genLabelProto() const;
    207207        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;
    216209};
    217210
     
    258251        if ( enumDecl->base ) {
    259252                gen.genAttrFuncForward();
    260                 gen.genPosFunctions();
    261253        }
    262254        gen.generateAndAppendFunctions( declsToAddAfter );
     
    533525}
    534526
    535 const ast::Stmt * StructFuncGenerator::makeMemberOp(
     527ast::ptr<ast::Stmt> StructFuncGenerator::makeMemberOp(
    536528                const CodeLocation& location, const ast::ObjectDecl * dstParam,
    537529                const ast::Expr * src, const ast::ObjectDecl * field,
     
    548540                )
    549541        );
    550         const ast::Stmt * stmt = genImplicitCall(
     542        auto stmt = genImplicitCall(
    551543                srcParam, dstSelect, location, func->name,
    552544                field, direction
     
    606598                        location, field, new ast::VariableExpr( location, srcParam )
    607599                ) : nullptr;
    608                 const ast::Stmt * stmt =
     600                ast::ptr<ast::Stmt> stmt =
    609601                        makeMemberOp( location, dstParam, srcSelect, field, func, direction );
    610602
    611603                if ( nullptr != stmt ) {
    612                         stmts->kids.emplace_back( stmt );
     604                        stmts->kids.push_back( stmt );
    613605                }
    614606        }
     
    631623        for ( auto param = params.begin() + 1 ; current != end ; ++current ) {
    632624                const ast::ptr<ast::Decl> & member = *current;
    633                 const ast::Stmt * stmt = nullptr;
     625                ast::ptr<ast::Stmt> stmt = nullptr;
    634626                auto field = member.as<ast::ObjectDecl>();
    635627                // Not sure why it could be null.
     
    649641
    650642                if ( nullptr != stmt ) {
    651                         stmts->kids.emplace_back( stmt );
     643                        stmts->kids.push_back( stmt );
    652644                }
    653645        }
     
    799791}
    800792
    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// }
    880798
    881799void EnumFuncGenerator::genAttrFuncForward() { 
    882800        if ( decl->base ) {
    883                 ast::FunctionDecl *(EnumFuncGenerator::*attrProtos[5])() const = {
     801                ast::FunctionDecl *(EnumFuncGenerator::*attrProtos[3])() const = {
    884802                        &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                        };
    890806                for ( auto & generator : attrProtos ) {
    891807                        produceForwardDecl( (this->*generator)() );
    892808                }
    893809        }
    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 
    904810}
    905811
Note: See TracChangeset for help on using the changeset viewer.