Ignore:
Timestamp:
Dec 11, 2024, 7:32:08 PM (7 days ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
36dfdac
Parents:
e797179
Message:

Remove autogen forward declarations, which are never needed, and cause warnings about static declarations without definitions.

Intended to fix the failing test from previous commit.

Autogen forward declarations are never needed because they do not depend on each other, much less with mutual recursion.

Consequences:

  • tests/.expect/(5 tests).(3 archs).txt: Accept generated code that lacks autogen forward declarations
  • libcfa/src/concurrency/thread.*: Remove unused dependency on destructor from constructor (via thrd_start), by splitting trait is_thread with is_basic_thread
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/Autogen.cpp

    re797179 r5d3d281  
    7171class FuncGenerator {
    7272public:
    73         std::list<ast::ptr<ast::Decl>> forwards;
    7473        std::list<ast::ptr<ast::Decl>> definitions;
    7574
     
    9089        virtual void genStandardFuncs();
    9190        void produceDecl( const ast::FunctionDecl * decl );
    92         void produceForwardDecl( const ast::FunctionDecl * decl );
    9391
    9492        const CodeLocation& getLocation() const { return getDecl()->location; }
     
    196194
    197195        bool shouldAutogen() const final { return true; }
    198         void generateAndPrependDecls( std::list<ast::ptr<ast::Decl>> & );
    199         void genForwards();
    200196private:
    201197        void genFuncBody( ast::FunctionDecl * decl ) final;
     
    245241        ast::EnumInstType enumInst( enumDecl->name );
    246242        enumInst.base = enumDecl;
    247         if ( enumDecl->isCfa ) {
    248                 EnumFuncGenerator gen( enumDecl, &enumInst, functionNesting );
    249                 gen.generateAndPrependDecls( declsToAddBefore );
    250         }
    251 
    252         EnumFuncGenerator gen2( enumDecl, &enumInst, functionNesting );
    253         gen2.generateAndAppendFunctions( declsToAddAfter );
     243
     244        EnumFuncGenerator gen( enumDecl, &enumInst, functionNesting );
     245        gen.generateAndAppendFunctions( declsToAddAfter );
    254246}
    255247
     
    320312
    321313        // Now export the lists contents.
    322         decls.splice( decls.end(), forwards );
     314//      decls.splice( decls.end(), forwards );    // mlb wip: delete me
    323315        decls.splice( decls.end(), definitions );
    324316}
     
    329321
    330322        definitions.push_back( decl );
    331 }
    332 
    333 /// Make a forward declaration of the decl and add it to forwards.
    334 void FuncGenerator::produceForwardDecl( const ast::FunctionDecl * decl ) {
    335         if (0 != functionNesting) return;
    336         ast::FunctionDecl * fwd =
    337                 ( decl->stmts ) ? ast::asForward( decl ) : ast::deepCopy( decl ) ;
    338         fwd->fixUniqueId();
    339         forwards.push_back( fwd );
    340323}
    341324
     
    483466        for ( auto & generator : standardProtos ) {
    484467                ast::FunctionDecl * decl = (this->*generator)();
    485                 produceForwardDecl( decl );
    486468                genFuncBody( decl );
    487469                if ( CodeGen::isAssignment( decl->name ) ) {
     
    505487                        continue;
    506488                }
    507                 produceForwardDecl( ctor );
    508489                makeFieldCtorBody( decl->members.begin(), decl->members.end(), ctor );
    509490                produceDecl( ctor );
     
    667648                        return;
    668649                }
    669                 produceForwardDecl( ctor );
    670650                auto params = ctor->params;
    671651                auto dstParam = params.front().strict_as<ast::ObjectDecl>();
     
    695675                // Add unused attribute to parameter to silence warnings.
    696676                addUnusedAttribute( params.front() );
    697 
    698                 // Just an extra step to make the forward and declaration match.
    699                 if ( forwards.empty() ) return;
    700                 ast::FunctionDecl * fwd = strict_dynamic_cast<ast::FunctionDecl *>(
    701                         forwards.back().get_and_mutate() );
    702                 addUnusedAttribute( fwd->params.front() );
    703677        }
    704678}
     
    718692}
    719693
    720 void EnumFuncGenerator::generateAndPrependDecls( std::list<ast::ptr<ast::Decl>> & decls ) {
    721         genForwards();
    722         decls.splice( decls.end(), forwards );
    723 }
    724 
    725 void EnumFuncGenerator::genForwards() {
    726         forwards.push_back( ast::asForward(decl) );
    727 
    728         ast::FunctionDecl *(FuncGenerator::*standardProtos[4])() const = {
    729                 &EnumFuncGenerator::genCtorProto, &EnumFuncGenerator::genCopyProto,
    730                 &EnumFuncGenerator::genDtorProto, &EnumFuncGenerator::genAssignProto };
    731 
    732         for ( auto & generator: standardProtos) {
    733                 ast::FunctionDecl * decl = (this->*generator)();
    734                 produceForwardDecl( decl );
    735         }
    736 }
    737 
    738694void EnumFuncGenerator::genStandardFuncs() {
    739695        // do everything FuncGenerator does except not make ForwardDecls
     
    744700        for ( auto & generator : standardProtos ) {
    745701                ast::FunctionDecl * decl = (this->*generator)();
    746                 produceForwardDecl( decl );
    747702                genFuncBody( decl );
    748703                if ( CodeGen::isAssignment( decl->name ) ) {
     
    794749                // Just add unused attribute to parameter to silence warnings.
    795750                addUnusedAttribute( params.front() );
    796 
    797                 // Just an extra step to make the forward and declaration match.
    798                 if ( forwards.empty() ) return;
    799                 ast::FunctionDecl * fwd = strict_dynamic_cast<ast::FunctionDecl *>(
    800                         forwards.back().get_and_mutate() );
    801                 addUnusedAttribute( fwd->params.front() );
    802751        }
    803752}
Note: See TracChangeset for help on using the changeset viewer.