Changeset a2f920f for src/SymTab/Autogen.cc
- Timestamp:
- Aug 5, 2016, 11:39:05 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:
- 71a3593, d1ef1b0
- Parents:
- c331406
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
rc331406 ra2f920f 173 173 } 174 174 175 void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool isDynamicLayout, 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 … … 206 200 207 201 template<typename Iterator> 208 void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool is Generic, bool isDynamicLayout, 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, isDynamicLayout, 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, bool isDynamicLayout ) {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, isDynamicLayout );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, isDynamicLayout );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 isGeneric = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union) 293 bool isDynamicLayout = false; // NOTE see above re: kludge 286 bool isDynamicLayout = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union) 294 287 std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters(); 295 288 std::list< Expression* > structParams; // List of matching parameters to put on types 296 289 TypeSubstitution genericSubs; // Substitutions to make to member types of struct 297 290 for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) { 298 isGeneric = true;299 291 if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true; 300 292 TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() ); … … 357 349 FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType->clone(), new CompoundStmt( noLabels ), true, false ); 358 350 ctor->fixUniqueId(); 359 makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, is Generic, isDynamicLayout );351 makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isDynamicLayout ); 360 352 memCtors.push_back( ctor ); 361 353 } … … 363 355 364 356 // generate appropriate calls to member ctor, assignment 365 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, is Generic, isDynamicLayout );366 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, is Generic, isDynamicLayout );367 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, is Generic, isDynamicLayout );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 ); 368 360 // needs to do everything in reverse, so pass "forward" as false 369 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, is Generic, isDynamicLayout, false );370 371 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 ) ) ); 372 364 373 365 declsToAdd.push_back( assignDecl );
Note: See TracChangeset
for help on using the changeset viewer.