Changeset 020fa10 for src


Ignore:
Timestamp:
Feb 1, 2024, 5:28:18 PM (6 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
a55ebcc, bd67442
Parents:
9ddcee1
Message:

Remove duality functions. They are replaced by recent changed in Cost conversion and CandidateFinder?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    r9ddcee1 r020fa10  
    198198        bool shouldAutogen() const final { return true; }
    199199        void genAttrFuncForward();
    200         void __attribute__ ((unused)) genDualFuncs();
    201200private:
    202201        void genFuncBody( ast::FunctionDecl * decl ) final;
     
    204203        const ast::Decl * getDecl() const final { return decl; }
    205204
    206         ast::ObjectDecl * dualDstParam() const;
    207 
    208205        ast::FunctionDecl * genPosProto() const;
    209206        ast::FunctionDecl * genLabelProto() const;
    210207        ast::FunctionDecl * genValueProto() const;
    211 
    212         ast::FunctionDecl * genCopyEnumToDualProto() const;
    213         ast::FunctionDecl * genAssignEnumToDualProto() const;
    214 
    215         void genDualBody( ast::FunctionDecl * decl );
    216208};
    217209
     
    258250        if ( enumDecl->base ) {
    259251                gen.genAttrFuncForward();
    260                 // gen.genDualFuncs();
    261252        }
    262253        gen.generateAndAppendFunctions( declsToAddAfter );
     
    810801}
    811802
    812 ast::ObjectDecl * EnumFuncGenerator::dualDstParam() const {
    813         auto base = decl->base;
    814         assert( base );
    815         return new ast::ObjectDecl( getLocation(), "_dst",
    816                 new ast::ReferenceType( ast::deepCopy( base ) ) );
    817 }
    818 
    819 // void ?{}(T & _dst, enum E _src )
    820 ast::FunctionDecl * EnumFuncGenerator::genCopyEnumToDualProto() const {
    821         return genProto( "?{}", { dualDstParam(), srcParam() }, {} );
    822 }
    823 
    824 // T ?{}(T & _dst, enum E _src )
    825 ast::FunctionDecl * EnumFuncGenerator::genAssignEnumToDualProto() const {
    826         auto retval = dualDstParam();
    827         retval->name = "_ret";
    828         return genProto( "?=?", { dualDstParam(), srcParam() }, { retval });
    829 }
    830 
    831 void EnumFuncGenerator::genDualBody( ast::FunctionDecl * functionDecl ) {
    832         assert( decl->base );
    833         const CodeLocation& location = functionDecl->location;
    834         auto & params = functionDecl->params;
    835        
    836         assert( 2 == params.size() );
    837         auto dstParam = params.front().strict_as<ast::ObjectDecl>();
    838         auto srcParam = params.back().strict_as<ast::ObjectDecl>();
    839 
    840         auto dstExpr = new ast::VariableExpr( location, dstParam );
    841 
    842         auto srcExpr = new ast::ApplicationExpr( location,
    843                 ast::VariableExpr::functionPointer( location, genValueProto() ),
    844                 {
    845                         new ast::VariableExpr( location, srcParam )
    846                 });
    847         auto callExpr = new ast::ApplicationExpr( location,
    848                 ast::VariableExpr::functionPointer( location, functionDecl ),
    849                 { dstExpr, srcExpr } );
    850         functionDecl->stmts = new ast::CompoundStmt( location,
    851                 { new ast::ExprStmt( location, callExpr)} );
    852 }
    853 
    854 void EnumFuncGenerator::genDualFuncs() {
    855         assert( decl->base );
    856         ast::FunctionDecl *(EnumFuncGenerator::*dualProtos[2])() const = {
    857                         &EnumFuncGenerator::genCopyEnumToDualProto,
    858                         &EnumFuncGenerator::genAssignEnumToDualProto };
    859         for ( auto & generator : dualProtos ) {
    860                 ast::FunctionDecl * decl = (this->*generator)();
    861                 produceForwardDecl( decl );
    862                 genDualBody( decl );
    863                 if ( CodeGen::isAssignment( decl->name ) ) {
    864                         appendReturnThis( decl );
    865                 }
    866                 produceDecl( decl );
    867         }
    868 }
    869 
    870803void TypeFuncGenerator::genFieldCtors() {
    871804        // Opaque types do not have field constructors.
Note: See TracChangeset for help on using the changeset viewer.