Changeset 5d3d281 for src/Validate/Autogen.cpp
- Timestamp:
- Dec 11, 2024, 7:32:08 PM (7 days ago)
- Branches:
- master
- Children:
- 36dfdac
- Parents:
- e797179
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
re797179 r5d3d281 71 71 class FuncGenerator { 72 72 public: 73 std::list<ast::ptr<ast::Decl>> forwards;74 73 std::list<ast::ptr<ast::Decl>> definitions; 75 74 … … 90 89 virtual void genStandardFuncs(); 91 90 void produceDecl( const ast::FunctionDecl * decl ); 92 void produceForwardDecl( const ast::FunctionDecl * decl );93 91 94 92 const CodeLocation& getLocation() const { return getDecl()->location; } … … 196 194 197 195 bool shouldAutogen() const final { return true; } 198 void generateAndPrependDecls( std::list<ast::ptr<ast::Decl>> & );199 void genForwards();200 196 private: 201 197 void genFuncBody( ast::FunctionDecl * decl ) final; … … 245 241 ast::EnumInstType enumInst( enumDecl->name ); 246 242 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 ); 254 246 } 255 247 … … 320 312 321 313 // Now export the lists contents. 322 decls.splice( decls.end(), forwards ); 314 // decls.splice( decls.end(), forwards ); // mlb wip: delete me 323 315 decls.splice( decls.end(), definitions ); 324 316 } … … 329 321 330 322 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 );340 323 } 341 324 … … 483 466 for ( auto & generator : standardProtos ) { 484 467 ast::FunctionDecl * decl = (this->*generator)(); 485 produceForwardDecl( decl );486 468 genFuncBody( decl ); 487 469 if ( CodeGen::isAssignment( decl->name ) ) { … … 505 487 continue; 506 488 } 507 produceForwardDecl( ctor );508 489 makeFieldCtorBody( decl->members.begin(), decl->members.end(), ctor ); 509 490 produceDecl( ctor ); … … 667 648 return; 668 649 } 669 produceForwardDecl( ctor );670 650 auto params = ctor->params; 671 651 auto dstParam = params.front().strict_as<ast::ObjectDecl>(); … … 695 675 // Add unused attribute to parameter to silence warnings. 696 676 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() );703 677 } 704 678 } … … 718 692 } 719 693 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 738 694 void EnumFuncGenerator::genStandardFuncs() { 739 695 // do everything FuncGenerator does except not make ForwardDecls … … 744 700 for ( auto & generator : standardProtos ) { 745 701 ast::FunctionDecl * decl = (this->*generator)(); 746 produceForwardDecl( decl );747 702 genFuncBody( decl ); 748 703 if ( CodeGen::isAssignment( decl->name ) ) { … … 794 749 // Just add unused attribute to parameter to silence warnings. 795 750 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() );802 751 } 803 752 }
Note: See TracChangeset
for help on using the changeset viewer.