Ignore:
Timestamp:
Jul 10, 2024, 3:39:26 AM (6 weeks ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
dbff8ec
Parents:
550afde2
Message:

Fixed the problem when enum use another enumerator as initializer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    r550afde2 rbb336a6  
    8888
    8989        // Internal helpers:
    90         void genStandardFuncs();
     90        virtual void genStandardFuncs();
    9191        void produceDecl( const ast::FunctionDecl * decl );
    9292        void produceForwardDecl( const ast::FunctionDecl * decl );
     
    196196
    197197        bool shouldAutogen() const final { return true; }
     198        void generateAndPrependDecls( std::list<ast::ptr<ast::Decl>> & );
     199        void genForwards();
    198200private:
    199201        void genFuncBody( ast::FunctionDecl * decl ) final;
    200202        void genFieldCtors() final;
    201203        const ast::Decl * getDecl() const final { return decl; }
     204protected:
     205        void genStandardFuncs() override;
    202206};
    203207
     
    242246        enumInst.base = enumDecl;
    243247        EnumFuncGenerator gen( enumDecl, &enumInst, functionNesting );
    244         gen.generateAndAppendFunctions( declsToAddAfter );
     248        gen.generateAndPrependDecls( declsToAddBefore );
     249
     250        EnumFuncGenerator gen2( enumDecl, &enumInst, functionNesting );
     251        gen2.generateAndAppendFunctions( declsToAddAfter );
    245252}
    246253
     
    709716}
    710717
     718void EnumFuncGenerator::generateAndPrependDecls( std::list<ast::ptr<ast::Decl>> & decls ) {
     719        genForwards();
     720        decls.splice( decls.end(), forwards );
     721}
     722
     723void EnumFuncGenerator::genForwards() {
     724        forwards.push_back( ast::asForward(decl) );
     725
     726        ast::FunctionDecl *(FuncGenerator::*standardProtos[4])() const = {
     727                &EnumFuncGenerator::genCtorProto, &EnumFuncGenerator::genCopyProto,
     728                &EnumFuncGenerator::genDtorProto, &EnumFuncGenerator::genAssignProto };
     729
     730        for ( auto & generator: standardProtos) {
     731                ast::FunctionDecl * decl = (this->*generator)();
     732                produceForwardDecl( decl );
     733        }
     734}
     735
     736void EnumFuncGenerator::genStandardFuncs() {
     737        // do everything FuncGenerator does except not make ForwardDecls
     738        ast::FunctionDecl *(FuncGenerator::*standardProtos[4])() const = {
     739                &EnumFuncGenerator::genCtorProto, &EnumFuncGenerator::genCopyProto,
     740                &EnumFuncGenerator::genDtorProto, &EnumFuncGenerator::genAssignProto };
     741
     742        for ( auto & generator : standardProtos ) {
     743                ast::FunctionDecl * decl = (this->*generator)();
     744                // produceForwardDecl( decl ); Done in genForwards
     745                genFuncBody( decl );
     746                if ( CodeGen::isAssignment( decl->name ) ) {
     747                        appendReturnThis( decl );
     748                }
     749                produceDecl( decl );
     750        }
     751}
     752
    711753void EnumFuncGenerator::genFieldCtors() {
    712754        // Enumerations to not have field constructors.
Note: See TracChangeset for help on using the changeset viewer.