Changes in src/SymTab/Autogen.cc [a465caff:9b4c936]
- File:
-
- 1 edited
-
src/SymTab/Autogen.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
ra465caff r9b4c936 64 64 65 65 template< typename OutputIterator > 66 void makeUnionFieldsAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, UnionInstType *unionType,OutputIterator out ) {66 void makeUnionFieldsAssignment( ObjectDecl *srcParam, ObjectDecl *dstParam, 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 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 } 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 // } 185 179 186 180 ObjectDecl * returnVal = NULL; … … 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 ); … … 419 413 dtorDecl->fixUniqueId(); 420 414 421 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() ) );415 makeUnionFieldsAssignment( srcParam, dstParam, back_inserter( assignDecl->get_statements()->get_kids() ) ); 416 if ( isDynamicLayout ) makeUnionFieldsAssignment( srcParam, returnVal, 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 … … 440 434 ctor->fixUniqueId(); 441 435 442 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ),back_inserter( ctor->get_statements()->get_kids() ) );436 makeUnionFieldsAssignment( srcParam, dstParam, back_inserter( ctor->get_statements()->get_kids() ) ); 443 437 memCtors.push_back( ctor ); 444 438 // only generate a ctor for the first field
Note:
See TracChangeset
for help on using the changeset viewer.