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