Changeset f30b2610
- Timestamp:
- Oct 19, 2017, 11:15:36 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- e41306d
- Parents:
- 1a5ad8c
- git-author:
- Rob Schluntz <rschlunt@…> (10/19/17 11:00:48)
- git-committer:
- Rob Schluntz <rschlunt@…> (10/19/17 11:15:36)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Autogen.cc
r1a5ad8c rf30b2610 213 213 214 214 bool isUnnamedBitfield( ObjectDecl * obj ) { 215 return obj != nullptr && obj-> get_name() == "" && obj->get_bitfieldWidth()!= nullptr;215 return obj != nullptr && obj->name == "" && obj->bitfieldWidth != nullptr; 216 216 } 217 217 … … 219 219 void addForwardDecl( FunctionDecl * functionDecl, std::list< Declaration * > & declsToAdd ) { 220 220 FunctionDecl * decl = functionDecl->clone(); 221 delete decl-> get_statements();222 decl->s et_statements( nullptr );221 delete decl->statements; 222 decl->statements = nullptr; 223 223 declsToAdd.push_back( decl ); 224 224 decl->fixUniqueId(); 225 225 } 226 226 227 const std::list< TypeDecl * > getGenericParams( Type * t ) { 228 std::list< TypeDecl * > * ret = nullptr; 229 if ( StructInstType * inst = dynamic_cast< StructInstType * > ( t ) ) { 230 ret = inst->get_baseParameters(); 231 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( t ) ) { 232 ret = inst->get_baseParameters(); 233 } 234 return ret ? *ret : std::list< TypeDecl * >(); 235 } 236 227 237 /// given type T, generate type of default ctor/dtor, i.e. function type void (*) (T *) 228 238 FunctionType * genDefaultType( Type * paramType ) { 239 const auto & typeParams = getGenericParams( paramType ); 229 240 FunctionType *ftype = new FunctionType( Type::Qualifiers(), false ); 241 cloneAll( typeParams, ftype->forall ); 230 242 ObjectDecl *dstParam = new ObjectDecl( "_dst", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), paramType->clone() ), nullptr ); 231 ftype-> get_parameters().push_back( dstParam );243 ftype->parameters.push_back( dstParam ); 232 244 return ftype; 233 245 } … … 237 249 FunctionType *ftype = genDefaultType( paramType ); 238 250 ObjectDecl *srcParam = new ObjectDecl( "_src", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, paramType->clone(), nullptr ); 239 ftype-> get_parameters().push_back( srcParam );251 ftype->parameters.push_back( srcParam ); 240 252 return ftype; 241 253 } … … 245 257 FunctionType *ftype = genCopyType( paramType ); 246 258 ObjectDecl *returnVal = new ObjectDecl( "_ret", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, paramType->clone(), nullptr ); 247 ftype-> get_returnVals().push_back( returnVal );259 ftype->returnVals.push_back( returnVal ); 248 260 return ftype; 249 261 } … … 276 288 } 277 289 278 const std::list< TypeDecl * > getGenericParams( Type * t ) {279 std::list< TypeDecl * > * ret = nullptr;280 if ( StructInstType * inst = dynamic_cast< StructInstType * > ( t ) ) {281 ret = inst->get_baseParameters();282 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( t ) ) {283 ret = inst->get_baseParameters();284 }285 return ret ? *ret : std::list< TypeDecl * >();286 }287 288 290 //============================================================================================= 289 291 // FuncGenerator member definitions … … 318 320 } 319 321 320 // Make function polymorphic in same parameters as generic struct, if applicable321 std::list< TypeDecl * > typeParams = getGenericParams( type ); // List of type variables to be placed on the generated functions322 cloneAll( typeParams, ftype->forall );323 324 322 newFuncs.push_back( genFunc( data.fname, ftype, functionNesting ) ); 325 323 } … … 353 351 // generate appropriate calls to member ctor, assignment 354 352 // destructor needs to do everything in reverse, so pass "forward" based on whether the function is a destructor 355 if ( ! CodeGen::isDestructor( dcl-> get_name()) ) {353 if ( ! CodeGen::isDestructor( dcl->name ) ) { 356 354 makeFunctionBody( aggregateDecl->members.begin(), aggregateDecl->members.end(), dcl ); 357 355 } else { … … 362 360 void StructFuncGenerator::genFieldCtors() { 363 361 // field ctors are only generated if default constructor and copy constructor are both generated 364 unsigned numCtors = std::count_if( definitions.begin(), definitions.end(), [](Declaration * dcl) { return CodeGen::isConstructor( dcl-> get_name()); } );362 unsigned numCtors = std::count_if( definitions.begin(), definitions.end(), [](Declaration * dcl) { return CodeGen::isConstructor( dcl->name ); } ); 365 363 366 364 // Field constructors are only generated if default and copy constructor … … 371 369 // for example, for struct A { int x, y; }; generate 372 370 // void ?{}(A *, int) and void ?{}(A *, int, int) 373 const auto & typeParams = aggregateDecl->parameters;374 371 FunctionType * memCtorType = genDefaultType( type ); 375 cloneAll( typeParams, memCtorType->forall );376 372 for ( Declaration * member : aggregateDecl->members ) { 377 373 DeclarationWithType * field = strict_dynamic_cast<DeclarationWithType *>( member ); … … 392 388 393 389 // assign to destination 394 Expression *dstselect = new MemberExpr( field, new CastExpr( new VariableExpr( dstParam ), strict_dynamic_cast< ReferenceType* >( dstParam->get_type() )-> get_base()->clone() ) );395 genImplicitCall( srcParam, dstselect, func-> get_name(), back_inserter( func->get_statements()->get_kids()), field, forward );390 Expression *dstselect = new MemberExpr( field, new CastExpr( new VariableExpr( dstParam ), strict_dynamic_cast< ReferenceType* >( dstParam->get_type() )->base->clone() ) ); 391 genImplicitCall( srcParam, dstselect, func->name, back_inserter( func->statements->kids ), field, forward ); 396 392 } 397 393 … … 504 500 // void ?{}(A *, int) 505 501 // This is to mimic C's behaviour which initializes the first member of the union. 506 const auto & typeParams = aggregateDecl->parameters;507 502 FunctionType * memCtorType = genDefaultType( type ); 508 cloneAll( typeParams, memCtorType->forall );509 503 for ( Declaration * member : aggregateDecl->members ) { 510 504 DeclarationWithType * field = strict_dynamic_cast<DeclarationWithType *>( member );
Note: See TracChangeset
for help on using the changeset viewer.