Changeset 94b4364 for src/ResolvExpr
- Timestamp:
- Jun 16, 2015, 3:49:36 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 94e0864d
- Parents:
- b5b0907
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
rb5b0907 r94b4364 10 10 // Created On : Sun May 17 12:17:01 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 10 16:11:19201513 // Update Count : 7712 // Last Modified On : Tue Jun 16 14:50:11 2015 13 // Update Count : 154 14 14 // 15 15 … … 37 37 virtual void visit( ObjectDecl *functionDecl ); 38 38 virtual void visit( TypeDecl *typeDecl ); 39 39 40 virtual void visit( ArrayType * at ); 40 41 … … 51 52 virtual void visit( ListInit *listInit ); 52 53 private: 54 typedef std::list< Initializer * >::iterator InitIterator; 55 56 void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & ); 57 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & ); 58 53 59 std::list< Type * > functionReturn; 54 60 Type *initContext; … … 167 173 delete at->get_dimension(); 168 174 at->set_dimension( newExpr ); 169 170 175 } 171 176 Visitor::visit( at ); 172 177 } 173 178 174 179 void Resolver::visit( TypeDecl *typeDecl ) { 175 180 if ( typeDecl->get_base() ) { … … 179 184 SymTab::Indexer::visit( typeDecl ); 180 185 } 181 186 182 187 void Resolver::visit( FunctionDecl *functionDecl ) { 183 188 #if 0 … … 329 334 } 330 335 331 void Resolver::visit( ListInit *listInit ) { 336 void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd ) { 337 DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl ); 338 assert( dt ); 339 initContext = dt->get_type(); 340 try { 341 if ( init == initEnd ) return; // stop when there are no more initializers 342 (*init)->accept( *this ); 343 ++init; // made it past an initializer 344 } catch( SemanticError & ) { 345 // need to delve deeper, if you can 346 if ( StructInstType * sit = dynamic_cast< StructInstType * >( dt->get_type() ) ) { 347 resolveAggrInit( sit->get_baseStruct(), init, initEnd ); 348 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( dt->get_type() ) ) { 349 resolveAggrInit( uit->get_baseUnion(), init, initEnd ); 350 } else { 351 // might need to rethink what is being thrown 352 throw; 353 } // if 354 } 355 } 356 357 void Resolver::resolveAggrInit( AggregateDecl * aggr, InitIterator & init, InitIterator & initEnd ) { 358 if ( StructDecl * st = dynamic_cast< StructDecl * >( aggr ) ) { 359 // want to resolve each initializer to the members of the struct, 360 // but if there are more initializers than members we should stop 361 list< Declaration * >::iterator it = st->get_members().begin(); 362 for ( ; it != st->get_members().end(); ++it) { 363 resolveSingleAggrInit( *it, init, initEnd ); 364 } 365 } else if ( UnionDecl * un = dynamic_cast< UnionDecl * >( aggr ) ) { 366 // only resolve to the first member of a union 367 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd ); 368 } // if 369 } 370 371 void Resolver::visit( ListInit * listInit ) { 372 InitIterator iter = listInit->begin_initializers(); 373 InitIterator end = listInit->end_initializers(); 374 332 375 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { 333 std::list< Initializer * >::iterator iter( listInit->begin_initializers() );334 for ( ; iter != listInit->end_initializers(); ++iter ) {376 // resolve each member to the base type of the array 377 for ( ; iter != end; ++iter ) { 335 378 initContext = at->get_base(); 336 379 (*iter)->accept( *this ); 337 380 } // for 381 } else if ( StructInstType * st = dynamic_cast< StructInstType * >( initContext ) ) { 382 resolveAggrInit( st->get_baseStruct(), iter, end ); 338 383 } else if ( UnionInstType *st = dynamic_cast< UnionInstType * >( initContext ) ) { 339 DeclarationWithType *dt = dynamic_cast< DeclarationWithType * >( *st->get_baseUnion()->get_members().begin() ); 340 initContext = dt->get_type(); 341 (*listInit->begin_initializers())->accept( *this ); 384 resolveAggrInit( st->get_baseUnion(), iter, end ); 342 385 } else { 343 386 // basic types are handled here
Note: See TracChangeset
for help on using the changeset viewer.