Changeset 04273e9 for src/SymTab
- Timestamp:
- Aug 8, 2016, 5:29:03 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:
- 03da511
- Parents:
- 0853178 (diff), 7bf7fb9 (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
r0853178 r04273e9 173 173 } 174 174 175 void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool forward = true ) { 176 if ( isGeneric ) { 177 // rewrite member type in terms of the type variables on this operator 178 field = field->clone(); 179 genericSubs.apply( field ); 180 181 if ( src ) { 182 genericSubs.apply( src ); 183 } 175 void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout, bool forward = true ) { 176 if ( isDynamicLayout && src ) { 177 genericSubs.apply( src ); 184 178 } 185 179 … … 197 191 genImplicitCall( srcParam, dstselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward ); 198 192 199 if ( is Generic&& returnVal ) {193 if ( isDynamicLayout && returnVal ) { 200 194 UntypedExpr *derefRet = new UntypedExpr( new NameExpr( "*?" ) ); 201 195 derefRet->get_args().push_back( new VariableExpr( returnVal ) ); … … 206 200 207 201 template<typename Iterator> 208 void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool is Generic, bool forward = true ) {202 void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout, bool forward = true ) { 209 203 for ( ; member != end; ++member ) { 210 204 if ( DeclarationWithType *field = dynamic_cast< DeclarationWithType * >( *member ) ) { // otherwise some form of type declaration, e.g. Aggregate … … 242 236 243 237 Expression *srcselect = srcParam ? new MemberExpr( field, new VariableExpr( srcParam ) ) : NULL; 244 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, is Generic, forward );238 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isDynamicLayout, forward ); 245 239 } // if 246 240 } // for … … 250 244 /// void ?{}(A *, int) and void?{}(A *, int, int) for a struct A which has two int fields. 251 245 template<typename Iterator> 252 void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool is Generic) {246 void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout ) { 253 247 FunctionType * ftype = func->get_functionType(); 254 248 std::list<DeclarationWithType*> & params = ftype->get_parameters(); … … 276 270 // matching parameter, initialize field with copy ctor 277 271 Expression *srcselect = new VariableExpr(*parameter); 278 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, is Generic);272 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isDynamicLayout ); 279 273 ++parameter; 280 274 } else { 281 275 // no matching parameter, initialize field with default ctor 282 makeStructMemberOp( dstParam, NULL, field, func, genericSubs, is Generic);276 makeStructMemberOp( dstParam, NULL, field, func, genericSubs, isDynamicLayout ); 283 277 } 284 278 } … … 290 284 291 285 // Make function polymorphic in same parameters as generic struct, if applicable 292 bool is Generic= false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)286 bool isDynamicLayout = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union) 293 287 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 294 288 std::list< Expression* > structParams; // List of matching parameters to put on types 295 289 TypeSubstitution genericSubs; // Substitutions to make to member types of struct 296 290 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 297 i sGeneric= true;291 if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true; 298 292 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 299 293 assignType->get_forall().push_back( typeParam ); … … 355 349 FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType->clone(), new CompoundStmt( noLabels ), true, false ); 356 350 ctor->fixUniqueId(); 357 makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, is Generic);351 makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isDynamicLayout ); 358 352 memCtors.push_back( ctor ); 359 353 } … … 361 355 362 356 // generate appropriate calls to member ctor, assignment 363 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, is Generic);364 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, is Generic);365 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, is Generic);357 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, isDynamicLayout ); 358 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, isDynamicLayout ); 359 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, isDynamicLayout ); 366 360 // needs to do everything in reverse, so pass "forward" as false 367 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, is Generic, false );368 369 if ( ! is Generic) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );361 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, isDynamicLayout, false ); 362 363 if ( ! isDynamicLayout ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 370 364 371 365 declsToAdd.push_back( assignDecl ); … … 380 374 381 375 // Make function polymorphic in same parameters as generic union, if applicable 382 bool is Generic = false;// NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)376 bool isDynamicLayout = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct) 383 377 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 384 378 std::list< Expression* > unionParams; // List of matching parameters to put on types 385 379 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 386 i sGeneric= true;380 if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true; 387 381 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); 388 382 assignType->get_forall().push_back( typeParam ); … … 420 414 421 415 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 422 if ( is Generic) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );416 if ( isDynamicLayout ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 423 417 else assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 424 418
Note: See TracChangeset
for help on using the changeset viewer.