Changeset 74b007ba for src/SymTab
- Timestamp:
- Aug 14, 2017, 2:05:42 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 36a5a77
- Parents:
- 9236060
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
r9236060 r74b007ba 156 156 } 157 157 158 /// true if the aggregate's layout is dynamic159 template< typename AggrDecl >160 bool hasDynamicLayout( AggrDecl * aggregateDecl ) {161 for ( TypeDecl * param : aggregateDecl->get_parameters() ) {162 if ( param->isComplete() ) return true;163 }164 return false;165 }166 167 158 /// generate a function decl from a name and type. Nesting depth determines whether 168 159 /// the declaration is static or not; optional paramter determines if declaration is intrinsic … … 310 301 311 302 /// generates a single struct member operation (constructor call, destructor call, assignment call) 312 void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, bool isDynamicLayout, boolforward = true ) {303 void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, bool forward = true ) { 313 304 InitTweak::InitExpander srcParam( src ); 314 305 … … 320 311 /// generates the body of a struct function by iterating the struct members (via parameters) - generates default ctor, copy ctor, assignment, and dtor bodies, but NOT field ctor bodies 321 312 template<typename Iterator> 322 void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, bool isDynamicLayout, boolforward = true ) {313 void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, bool forward = true ) { 323 314 for ( ; member != end; ++member ) { 324 315 if ( DeclarationWithType *field = dynamic_cast< DeclarationWithType * >( *member ) ) { // otherwise some form of type declaration, e.g. Aggregate … … 356 347 357 348 Expression *srcselect = srcParam ? new MemberExpr( field, new VariableExpr( srcParam ) ) : NULL; 358 makeStructMemberOp( dstParam, srcselect, field, func, isDynamicLayout,forward );349 makeStructMemberOp( dstParam, srcselect, field, func, forward ); 359 350 } // if 360 351 } // for … … 364 355 /// void ?{}(A *, int) and void?{}(A *, int, int) for a struct A which has two int fields. 365 356 template<typename Iterator> 366 void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func , bool isDynamicLayout) {357 void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func ) { 367 358 FunctionType * ftype = func->get_functionType(); 368 359 std::list<DeclarationWithType*> & params = ftype->get_parameters(); … … 390 381 // matching parameter, initialize field with copy ctor 391 382 Expression *srcselect = new VariableExpr(*parameter); 392 makeStructMemberOp( dstParam, srcselect, field, func , isDynamicLayout);383 makeStructMemberOp( dstParam, srcselect, field, func ); 393 384 ++parameter; 394 385 } else { 395 386 // no matching parameter, initialize field with default ctor 396 makeStructMemberOp( dstParam, NULL, field, func , isDynamicLayout);387 makeStructMemberOp( dstParam, NULL, field, func ); 397 388 } 398 389 } … … 410 401 // Make function polymorphic in same parameters as generic struct, if applicable 411 402 const std::list< TypeDecl* > & typeParams = aggregateDecl->get_parameters(); // List of type variables to be placed on the generated functions 412 bool isDynamicLayout = hasDynamicLayout( aggregateDecl ); // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)413 403 414 404 // generate each of the functions based on the supplied FuncData objects … … 436 426 // destructor needs to do everything in reverse, so pass "forward" based on whether the function is a destructor 437 427 if ( ! CodeGen::isDestructor( dcl->get_name() ) ) { 438 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), dcl , isDynamicLayout);428 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), dcl ); 439 429 } else { 440 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dcl, isDynamicLayout,false );430 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dcl, false ); 441 431 } 442 432 if ( CodeGen::isAssignment( dcl->get_name() ) ) { … … 474 464 memCtorType->get_parameters().push_back( new ObjectDecl( member->get_name(), Type::StorageClasses(), LinkageSpec::Cforall, 0, member->get_type()->clone(), 0 ) ); 475 465 FunctionDecl * ctor = genFunc( "?{}", memCtorType->clone(), functionNesting ); 476 makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor , isDynamicLayout);466 makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor ); 477 467 declsToAdd.push_back( ctor ); 478 468 }
Note: See TracChangeset
for help on using the changeset viewer.