Changeset 4e2b9710 for src/SymTab/Autogen.cc
- Timestamp:
- Aug 25, 2016, 9:14:18 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:
- a839867
- Parents:
- c1c1112 (diff), 486341f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
rc1c1112 r4e2b9710 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 ); … … 420 420 copyCtorDecl->set_statements( assignDecl->get_statements()->clone() ); 421 421 422 // create a constructor which takes the first member type as a parameter. 423 // for example, for Union A { int x; double y; }; generate 424 // void ?{}(A *, int) 425 // This is to mimic C's behaviour which initializes the first member of the union. 426 std::list<Declaration *> memCtors; 427 for ( Declaration * member : aggregateDecl->get_members() ) { 428 if ( DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member ) ) { 429 ObjectDecl * srcParam = new ObjectDecl( "src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, field->get_type()->clone(), 0 ); 430 431 FunctionType * memCtorType = ctorType->clone(); 432 memCtorType->get_parameters().push_back( srcParam ); 433 FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType, new CompoundStmt( noLabels ), true, false ); 434 ctor->fixUniqueId(); 435 436 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( ctor->get_statements()->get_kids() ) ); 437 memCtors.push_back( ctor ); 438 // only generate a ctor for the first field 439 break; 440 } 441 } 442 422 443 declsToAdd.push_back( assignDecl ); 423 444 declsToAdd.push_back( ctorDecl ); 424 445 declsToAdd.push_back( copyCtorDecl ); 425 446 declsToAdd.push_back( dtorDecl ); 447 declsToAdd.splice( declsToAdd.end(), memCtors ); 426 448 } 427 449
Note: See TracChangeset
for help on using the changeset viewer.