Changeset 5070fe4 for src/SymTab
- Timestamp:
- Aug 5, 2016, 10:55:01 AM (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, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- c331406
- Parents:
- ea5daeb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
rea5daeb r5070fe4 203 203 } 204 204 205 void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool forward = true ) {205 void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool isDynamicLayout, bool forward = true ) { 206 206 if ( isGeneric ) { 207 207 // rewrite member type in terms of the type variables on this operator … … 226 226 227 227 makeArrayFunction( src, dstselect, array, func->get_name(), back_inserter( func->get_statements()->get_kids() ), forward ); 228 if ( is Generic&& returnVal ) {228 if ( isDynamicLayout && returnVal ) { 229 229 UntypedExpr *derefRet = new UntypedExpr( new NameExpr( "*?" ) ); 230 230 derefRet->get_args().push_back( new VariableExpr( returnVal ) ); … … 235 235 } else { 236 236 makeScalarFunction( src, dstParam, field, func->get_name(), back_inserter( func->get_statements()->get_kids() ) ); 237 if ( is Generic&& returnVal ) makeScalarFunction( src, returnVal, field, func->get_name(), back_inserter( func->get_statements()->get_kids() ) );237 if ( isDynamicLayout && returnVal ) makeScalarFunction( src, returnVal, field, func->get_name(), back_inserter( func->get_statements()->get_kids() ) ); 238 238 } // if 239 239 } 240 240 241 241 template<typename Iterator> 242 void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool forward = true ) {242 void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool isDynamicLayout, bool forward = true ) { 243 243 for ( ; member != end; ++member ) { 244 244 if ( DeclarationWithType *field = dynamic_cast< DeclarationWithType * >( *member ) ) { // otherwise some form of type declaration, e.g. Aggregate … … 276 276 277 277 Expression *srcselect = srcParam ? new MemberExpr( field, new VariableExpr( srcParam ) ) : NULL; 278 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isGeneric, forward );278 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isGeneric, isDynamicLayout, forward ); 279 279 } // if 280 280 } // for … … 284 284 /// void ?{}(A *, int) and void?{}(A *, int, int) for a struct A which has two int fields. 285 285 template<typename Iterator> 286 void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric ) {286 void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool isDynamicLayout ) { 287 287 FunctionType * ftype = func->get_functionType(); 288 288 std::list<DeclarationWithType*> & params = ftype->get_parameters(); … … 310 310 // matching parameter, initialize field with copy ctor 311 311 Expression *srcselect = new VariableExpr(*parameter); 312 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isGeneric );312 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isGeneric, isDynamicLayout ); 313 313 ++parameter; 314 314 } else { 315 315 // no matching parameter, initialize field with default ctor 316 makeStructMemberOp( dstParam, NULL, field, func, genericSubs, isGeneric );316 makeStructMemberOp( dstParam, NULL, field, func, genericSubs, isGeneric, isDynamicLayout ); 317 317 } 318 318 } … … 325 325 // Make function polymorphic in same parameters as generic struct, if applicable 326 326 bool isGeneric = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union) 327 bool isDynamicLayout = false; // NOTE see above re: kludge 327 328 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 328 329 std::list< Expression* > structParams; // List of matching parameters to put on types … … 330 331 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 331 332 isGeneric = true; 333 if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true; 332 334 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 333 335 assignType->get_forall().push_back( typeParam ); … … 389 391 FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType->clone(), new CompoundStmt( noLabels ), true, false ); 390 392 ctor->fixUniqueId(); 391 makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isGeneric );393 makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isGeneric, isDynamicLayout ); 392 394 memCtors.push_back( ctor ); 393 395 } … … 395 397 396 398 // generate appropriate calls to member ctor, assignment 397 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, isGeneric );398 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, isGeneric );399 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, isGeneric );399 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, isGeneric, isDynamicLayout ); 400 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, isGeneric, isDynamicLayout ); 401 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, isGeneric, isDynamicLayout ); 400 402 // needs to do everything in reverse, so pass "forward" as false 401 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, isGeneric, false );403 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, isGeneric, isDynamicLayout, false ); 402 404 403 405 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); … … 414 416 415 417 // Make function polymorphic in same parameters as generic union, if applicable 416 bool is Generic = false;// NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)418 bool isDynamicLayout = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct) 417 419 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 418 420 std::list< Expression* > unionParams; // List of matching parameters to put on types 419 421 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 420 i sGeneric= true;422 if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true; 421 423 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 422 424 assignType->get_forall().push_back( typeParam ); … … 454 456 455 457 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 456 if ( isGeneric ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 457 458 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 458 if ( isDynamicLayout ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 459 else assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 459 460 460 461 // body of assignment and copy ctor is the same
Note: See TracChangeset
for help on using the changeset viewer.