Changeset 6943a987 for src/SymTab
- Timestamp:
- Aug 29, 2016, 10:33:05 AM (9 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:
- 5e644d3e
- Parents:
- 79841be (diff), 413ad05 (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. - Location:
- src/SymTab
- Files:
-
- 2 edited
-
Autogen.cc (modified) (2 diffs)
-
Validate.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
r79841be r6943a987 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 -
src/SymTab/Validate.cc
r79841be r6943a987 58 58 #include "Autogen.h" 59 59 #include "ResolvExpr/typeops.h" 60 #include <algorithm> 60 61 61 62 #define debugPrint( x ) if ( doDebug ) { std::cout << x; } … … 162 163 163 164 typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap; 165 typedef std::map< std::string, TypeDecl * > TypeDeclMap; 164 166 TypedefMap typedefNames; 167 TypeDeclMap typedeclNames; 165 168 int scopeLevel; 166 169 }; … … 370 373 } // if 371 374 372 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), ctx->get_members().begin(), ctx->get_members().end(), back_inserter( contextInst->get_members() ) ); 375 // need to clone members of the context for ownership purposes 376 std::list< Declaration * > members; 377 std::transform( ctx->get_members().begin(), ctx->get_members().end(), back_inserter( members ), [](Declaration * dwt) { return dwt->clone(); } ); 378 379 applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), members.begin(), members.end(), back_inserter( contextInst->get_members() ) ); 373 380 } 374 381 … … 521 528 delete typeInst; 522 529 return ret; 530 } else { 531 TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() ); 532 assert( base != typedeclNames.end() ); 533 typeInst->set_baseType( base->second->clone() ); 523 534 } // if 524 535 return typeInst; … … 565 576 typedefNames.erase( i ) ; 566 577 } // if 578 579 typedeclNames[ typeDecl->get_name() ] = typeDecl; 567 580 return typeDecl; 568 581 }
Note:
See TracChangeset
for help on using the changeset viewer.