Changes in src/ResolvExpr/Resolver.cc [a9a259c:52f85e0]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
ra9a259c r52f85e0 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Resolver.cc -- 7 // Resolver.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T hu Jan 14 16:45:32 201613 // Update Count : 20311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 9 21:57:52 2016 13 // Update Count : 179 14 14 // 15 15 … … 33 33 public: 34 34 Resolver() : SymTab::Indexer( false ), switchType( 0 ) {} 35 35 36 36 virtual void visit( FunctionDecl *functionDecl ); 37 37 virtual void visit( ObjectDecl *functionDecl ); … … 54 54 virtual void visit( SingleInit *singleInit ); 55 55 virtual void visit( ListInit *listInit ); 56 virtual void visit( ConstructorInit *ctorInit );57 56 private: 58 57 typedef std::list< Initializer * >::iterator InitIterator; … … 60 59 void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & ); 61 60 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & ); 62 void fallbackInit( ConstructorInit * ctorInit );63 61 64 62 std::list< Type * > functionReturn; … … 97 95 return newExpr; 98 96 } 99 97 100 98 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 101 99 TypeEnvironment env; … … 128 126 } // if 129 127 } 130 128 131 129 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 132 130 TypeEnvironment env; … … 161 159 return newExpr; 162 160 } 163 164 } 165 161 162 } 163 166 164 void Resolver::visit( ObjectDecl *objectDecl ) { 167 165 Type *new_type = resolveTypeof( objectDecl->get_type(), *this ); … … 253 251 forStmt->set_condition( newExpr ); 254 252 } // if 255 253 256 254 if ( forStmt->get_increment() ) { 257 255 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this ); … … 267 265 delete switchStmt->get_condition(); 268 266 switchStmt->set_condition( newExpr ); 269 267 270 268 visitor.Visitor::visit( switchStmt ); 271 269 } … … 309 307 bool isCharType( T t ) { 310 308 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 311 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 309 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 312 310 bt->get_kind() == BasicType::UnsignedChar; 313 311 } … … 321 319 string n = ne->get_name(); 322 320 if (n == "0") { 323 initContext = new BasicType(Type::Qualifiers(), 321 initContext = new BasicType(Type::Qualifiers(), 324 322 BasicType::SignedInt); 325 323 } else { … … 327 325 initContext = decl->get_type(); 328 326 } 329 } else if (ConstantExpr * e = 327 } else if (ConstantExpr * e = 330 328 dynamic_cast<ConstantExpr*>(singleInit->get_value())) { 331 329 Constant *c = e->get_constant(); … … 350 348 singleInit->set_value( ce->get_arg() ); 351 349 ce->set_arg( NULL ); 352 delete ce; 350 delete ce; 353 351 } 354 352 } … … 466 464 #endif 467 465 } 468 469 // ConstructorInit - fall back on C-style initializer470 void Resolver::fallbackInit( ConstructorInit * ctorInit ) {471 // could not find valid constructor, or found an intrinsic constructor472 // fall back on C-style initializer473 delete ctorInit->get_ctor();474 ctorInit->set_ctor( NULL );475 maybeAccept( ctorInit->get_init(), *this );476 }477 478 void Resolver::visit( ConstructorInit *ctorInit ) {479 TypeEnvironment env;480 AlternativeFinder finder( *this, env );481 finder.find( ctorInit->get_ctor() );482 483 if ( finder.get_alternatives().size() == 0 ) {484 fallbackInit( ctorInit );485 } else if ( finder.get_alternatives().size() == 1 ) {486 Alternative &choice = finder.get_alternatives().front();487 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( choice.expr ) ) {488 if ( VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() ) ) {489 if ( LinkageSpec::isOverridable( function->get_var()->get_linkage() ) ) {490 // if the constructor that was found is intrinsic or autogenerated, reset to C-style491 // initializer so that code generation is easy to handle492 fallbackInit( ctorInit );493 return;494 }495 }496 }497 // found a constructor - can get rid of C-style initializer498 Expression *newExpr = choice.expr->clone();499 finishExpr( newExpr, choice.env );500 ctorInit->set_ctor( newExpr );501 delete ctorInit->get_init();502 ctorInit->set_init( NULL );503 } else {504 // too many constructors found505 assert(false);506 }507 }508 466 } // namespace ResolvExpr 509 467
Note:
See TracChangeset
for help on using the changeset viewer.