Changes in src/Validate/Autogen.cpp [d6c464d:fb4dc28]
- File:
-
- 1 edited
-
src/Validate/Autogen.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
rd6c464d rfb4dc28 125 125 // Built-ins do not use autogeneration. 126 126 bool shouldAutogen() const final { return !decl->linkage.is_builtin && !structHasFlexibleArray(decl); } 127 void genADTFuncs();128 void getADTFuncBody(const ast::ObjectDecl * lhs, ast::FunctionDecl * func);129 127 private: 130 128 void genFuncBody( ast::FunctionDecl * decl ) final; … … 240 238 if ( !enumDecl->body ) return; 241 239 240 // if ( auto enumBaseType = enumDecl->base ) { 241 // if ( auto enumBaseTypeAsStructInst = dynamic_cast<const ast::StructInstType *>(enumBaseType.get()) ) { 242 // const ast::StructDecl * structDecl = enumBaseTypeAsStructInst->base.get(); 243 // this->previsit( structDecl ); 244 // } 245 // } 246 242 247 ast::EnumInstType enumInst( enumDecl->name ); 243 248 enumInst.base = enumDecl; … … 259 264 } 260 265 StructFuncGenerator gen( structDecl, &structInst, functionNesting ); 261 262 gen.genADTFuncs();263 266 gen.generateAndAppendFunctions( declsToAddAfter ); 264 267 } … … 472 475 } 473 476 produceDecl( decl ); 474 }475 }476 477 void StructFuncGenerator::getADTFuncBody(478 const ast::ObjectDecl * lhs,479 ast::FunctionDecl * func480 ) {481 const CodeLocation& location = func->location;482 assert( decl->members.size() == 2 );483 auto first = (decl->members[0]).as<ast::ObjectDecl>();484 assert(first != nullptr);485 auto firstType = first->type;486 auto unionInstDecl = firstType.as<ast::UnionInstType>();487 assert(unionInstDecl != nullptr);488 489 auto unionDecl = unionInstDecl->base;490 491 const ast::ObjectDecl * dstParam =492 func->params.front().strict_as<ast::ObjectDecl>();493 const ast::ObjectDecl * srcParam =494 func->params.back().strict_as<ast::ObjectDecl>();495 496 ast::Expr * srcSelect = new ast::VariableExpr( location, srcParam );497 498 ast::CompoundStmt * stmts = new ast::CompoundStmt( location );499 500 InitTweak::InitExpander_new srcParamTweak( srcSelect );501 ast::Expr * dstSelect =502 new ast::MemberExpr(503 location,504 lhs,505 new ast::MemberExpr(506 location,507 first,508 new ast::CastExpr(509 location,510 new ast::VariableExpr( location, dstParam ),511 dstParam->type.strict_as<ast::ReferenceType>()->base512 )513 )514 );515 auto stmt = genImplicitCall(516 srcParamTweak, dstSelect, location, func->name,517 first, SymTab::LoopForward518 );519 stmts->push_back( stmt );520 func->stmts = stmts;521 }522 523 void StructFuncGenerator::genADTFuncs() {524 if ( decl->kind != ast::AggregateDecl::Adt ) return;525 assert( decl->members.size() == 2 );526 auto first = (decl->members[0]).as<ast::ObjectDecl>();527 assert(first != nullptr);528 auto firstType = first->type;529 auto unionInstDecl = firstType.as<ast::UnionInstType>();530 assert(unionInstDecl != nullptr);531 auto unionDecl = unionInstDecl->base;532 533 // for (auto mem: unionDecl->members) {534 for ( std::size_t i = 0; i < unionDecl->members.size(); ++i ) {535 auto mem = unionDecl->members[i];536 const ast::ObjectDecl * mem_as_obj = mem.as<ast::ObjectDecl>();537 assert( mem_as_obj );538 auto mem_type = mem_as_obj->type.as<ast::StructInstType>();539 assert( mem_type );540 auto location = getLocation();541 ast::FunctionDecl * func = new ast::FunctionDecl(542 getLocation(),543 "?{}", // name544 {}, //forall545 { dstParam(), new ast::ObjectDecl( getLocation(), "_src", ast::deepCopy( mem_type ) ) }, // params546 {}, // returns547 {}, // statements548 // Use static storage if we are at the top level.549 (0 < functionNesting) ? ast::Storage::Classes() : ast::Storage::Static,550 proto_linkage,551 std::vector<ast::ptr<ast::Attribute>>(),552 // Auto-generated routines are inline to avoid conflicts.553 ast::Function::Specs( ast::Function::Inline )554 );555 getADTFuncBody(mem_as_obj, func);556 func->fixUniqueId();557 produceForwardDecl(func);558 if ( CodeGen::isAssignment( func->name ) ) {559 appendReturnThis( func );560 }561 produceDecl( func );562 477 } 563 478 }
Note:
See TracChangeset
for help on using the changeset viewer.