- Timestamp:
- Jul 10, 2024, 3:39:26 AM (5 months ago)
- Branches:
- master
- Children:
- dbff8ec
- Parents:
- 550afde2
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Create.cpp
r550afde2 rbb336a6 76 76 } 77 77 78 EnumDecl * asForward( EnumDecl const * decl ) { 79 if ( !decl->body ) { 80 return nullptr; 81 } 82 EnumDecl * fwd = new EnumDecl( decl->location, 83 decl->name, 84 decl->isCfa, 85 vectorCopy( decl->attributes ), 86 decl->linkage, 87 decl->base, 88 decl->hide 89 ); 90 fwd->params = vectorCopy( decl->params ); 91 return fwd; 78 92 } 93 94 } -
src/AST/Create.hpp
r550afde2 rbb336a6 24 24 StructDecl * asForward( StructDecl const * ); 25 25 UnionDecl * asForward( UnionDecl const * ); 26 EnumDecl * asForward( EnumDecl const * ); 26 27 27 28 } -
src/ResolvExpr/ResolveTypeof.cpp
r550afde2 rbb336a6 61 61 if ( typeofType->kind == ast::TypeofType::Basetypeof ) { 62 62 // replace basetypeof(<enum>) by int 63 if ( newType.as< ast::EnumInstType >() ) {64 newType = new ast::BasicType(65 ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) );66 }63 // if ( newType.as< ast::EnumInstType >() ) { 64 // newType = new ast::BasicType( 65 // ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) ); 66 // } 67 67 reset_qualifiers( 68 68 newType, -
src/Validate/Autogen.cpp
r550afde2 rbb336a6 88 88 89 89 // Internal helpers: 90 v oid genStandardFuncs();90 virtual void genStandardFuncs(); 91 91 void produceDecl( const ast::FunctionDecl * decl ); 92 92 void produceForwardDecl( const ast::FunctionDecl * decl ); … … 196 196 197 197 bool shouldAutogen() const final { return true; } 198 void generateAndPrependDecls( std::list<ast::ptr<ast::Decl>> & ); 199 void genForwards(); 198 200 private: 199 201 void genFuncBody( ast::FunctionDecl * decl ) final; 200 202 void genFieldCtors() final; 201 203 const ast::Decl * getDecl() const final { return decl; } 204 protected: 205 void genStandardFuncs() override; 202 206 }; 203 207 … … 242 246 enumInst.base = enumDecl; 243 247 EnumFuncGenerator gen( enumDecl, &enumInst, functionNesting ); 244 gen.generateAndAppendFunctions( declsToAddAfter ); 248 gen.generateAndPrependDecls( declsToAddBefore ); 249 250 EnumFuncGenerator gen2( enumDecl, &enumInst, functionNesting ); 251 gen2.generateAndAppendFunctions( declsToAddAfter ); 245 252 } 246 253 … … 709 716 } 710 717 718 void EnumFuncGenerator::generateAndPrependDecls( std::list<ast::ptr<ast::Decl>> & decls ) { 719 genForwards(); 720 decls.splice( decls.end(), forwards ); 721 } 722 723 void 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 736 void 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 711 753 void EnumFuncGenerator::genFieldCtors() { 712 754 // Enumerations to not have field constructors. -
src/Validate/ImplementEnumFunc.cpp
r550afde2 rbb336a6 104 104 auto memAsObjectDecl = mem.as<ast::ObjectDecl>(); 105 105 assert(memAsObjectDecl); 106 if (memAsObjectDecl->init) { 106 if (auto& init = memAsObjectDecl->init) { 107 auto singleInit = init.strict_as<ast::SingleInit>(); 108 auto nameExpr = singleInit->value.as<ast::NameExpr>(); 109 if (nameExpr) { 110 auto name = nameExpr->name; 111 if (auto it = std::find_if(decl->members.begin(), decl->members.end(), 112 [name](ast::ptr<ast::Decl> mem_decl) { 113 return (mem_decl->name == name); 114 }); it != std::end(decl->members) 115 ) { 116 // ast::SingleInit* newInit = new ast::SingleInit( 117 // init->location, new ast::CastExpr( nameExpr->location, 118 // nameExpr, new ast::BasicType( ast::BasicKind::UnsignedInt ), ast::ExplicitCast ) 119 // ); 120 // auto targetInit = (*it).strict_as<ast::ObjectDecl>()->init; 121 // inits.emplace_back( targetInit ); 122 auto index = std::distance( decl->members.begin(), it ); 123 auto targetInit = inits.at(index).strict_as<ast::SingleInit>(); 124 auto targetExpr = targetInit->value; 125 inits.push_back( new ast::SingleInit( targetExpr->location, targetExpr ) ); 126 continue; 127 } 128 } 129 107 130 inits.emplace_back(memAsObjectDecl->init); 108 131 } else { … … 406 429 void EnumAttrFuncGenerator::genTypedEnumFunction(const ast::EnumAttribute attr) { 407 430 if (attr == ast::EnumAttribute::Value) { 408 if (decl-> base) {431 if (decl->isTyped()) { 409 432 // TypedEnum's backing arrays 410 433 std::vector<ast::ptr<ast::Init>> inits = genValueInit(); … … 441 464 442 465 void EnumAttrFuncGenerator::genTypedEnumFuncs() { 443 genTypedEnumFunction(ast::EnumAttribute::Value);444 genTypedEnumFunction(ast::EnumAttribute::Label);445 genTypedEnumFunction(ast::EnumAttribute::Posn);466 // genTypedEnumFunction(ast::EnumAttribute::Value); 467 // genTypedEnumFunction(ast::EnumAttribute::Label); 468 // genTypedEnumFunction(ast::EnumAttribute::Posn); 446 469 } 447 470 … … 456 479 std::list<ast::ptr<ast::Decl>>& decls) { 457 480 // Generate the functions (they go into forwards and definitions). 458 genTypeNameFunc();481 // genTypeNameFunc(); 459 482 genTypedEnumFuncs(); 460 genSerialTraitFuncs();461 genBoundedFunctions();483 // genSerialTraitFuncs(); 484 // genBoundedFunctions(); 462 485 // Now export the lists contents. 463 486 decls.splice(decls.end(), forwards); … … 483 506 enumInst.base = enumDecl; 484 507 EnumAttrFuncGenerator gen(enumDecl, &enumInst, functionNesting); 485 gen.generateAndAppendFunctions(declsToAddAfter);508 // gen.generateAndAppendFunctions(declsToAddAfter); 486 509 } 487 510
Note: See TracChangeset
for help on using the changeset viewer.