Changeset a465caf for src/SymTab
- Timestamp:
- Aug 8, 2016, 4:20:29 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, 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:
- 0853178
- Parents:
- 242d458
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
r242d458 ra465caf 68 68 copy->get_args().push_back( new VariableExpr( dstParam ) ); 69 69 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 70 copy->get_args().push_back( new SizeofExpr( unionType) );70 copy->get_args().push_back( new SizeofExpr( srcParam->get_type()->clone() ) ); 71 71 72 72 *out++ = new ExprStmt( noLabels, copy ); … … 421 421 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 422 422 if ( isGeneric ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 423 424 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 423 else assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 425 424 426 425 // body of assignment and copy ctor is the same 427 426 copyCtorDecl->set_statements( assignDecl->get_statements()->clone() ); 427 428 // create a constructor which takes the first member type as a parameter. 429 // for example, for Union A { int x; double y; }; generate 430 // void ?{}(A *, int) 431 // This is to mimic C's behaviour which initializes the first member of the union. 432 std::list<Declaration *> memCtors; 433 for ( Declaration * member : aggregateDecl->get_members() ) { 434 if ( DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member ) ) { 435 ObjectDecl * srcParam = new ObjectDecl( "src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, field->get_type()->clone(), 0 ); 436 437 FunctionType * memCtorType = ctorType->clone(); 438 memCtorType->get_parameters().push_back( srcParam ); 439 FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType, new CompoundStmt( noLabels ), true, false ); 440 ctor->fixUniqueId(); 441 442 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( ctor->get_statements()->get_kids() ) ); 443 memCtors.push_back( ctor ); 444 // only generate a ctor for the first field 445 break; 446 } 447 } 428 448 429 449 declsToAdd.push_back( assignDecl ); … … 431 451 declsToAdd.push_back( copyCtorDecl ); 432 452 declsToAdd.push_back( dtorDecl ); 453 declsToAdd.splice( declsToAdd.end(), memCtors ); 433 454 } 434 455
Note: See TracChangeset
for help on using the changeset viewer.