Changes in src/ResolvExpr/Resolver.cc [3cfe27f:db4ecc5]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r3cfe27f rdb4ecc5 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 : Peter A. Buhr12 // Last Modified On : Thu Mar 24 16:43:11201613 // Update Count : 18111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Apr 14 11:18:12 2016 13 // Update Count : 203 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 ); 56 57 private: 57 58 typedef std::list< Initializer * >::iterator InitIterator; … … 59 60 void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & ); 60 61 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & ); 61 62 void fallbackInit( ConstructorInit * ctorInit ); 62 63 std::list< Type * > functionReturn; 63 64 Type *initContext; … … 82 83 } 83 84 85 84 86 namespace { 85 87 void finishExpr( Expression *expr, const TypeEnvironment &env ) { … … 87 89 env.makeSubstitution( *expr->get_env() ); 88 90 } 89 90 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 91 global_renamer.reset(); 92 TypeEnvironment env; 93 Expression *newExpr = resolveInVoidContext( untyped, indexer, env ); 94 finishExpr( newExpr, env ); 95 return newExpr; 96 } 97 91 } // namespace 92 93 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 94 global_renamer.reset(); 95 TypeEnvironment env; 96 Expression *newExpr = resolveInVoidContext( untyped, indexer, env ); 97 finishExpr( newExpr, env ); 98 return newExpr; 99 } 100 101 namespace { 98 102 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 99 103 TypeEnvironment env; … … 126 130 } // if 127 131 } 128 132 129 133 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 130 134 TypeEnvironment env; … … 159 163 return newExpr; 160 164 } 161 162 } 163 165 166 } 167 164 168 void Resolver::visit( ObjectDecl *objectDecl ) { 165 169 Type *new_type = resolveTypeof( objectDecl->get_type(), *this ); … … 258 262 forStmt->set_condition( newExpr ); 259 263 } // if 260 264 261 265 if ( forStmt->get_increment() ) { 262 266 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this ); … … 272 276 delete switchStmt->get_condition(); 273 277 switchStmt->set_condition( newExpr ); 274 278 275 279 visitor.Visitor::visit( switchStmt ); 276 280 } … … 314 318 bool isCharType( T t ) { 315 319 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 316 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 320 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 317 321 bt->get_kind() == BasicType::UnsignedChar; 318 322 } … … 326 330 string n = ne->get_name(); 327 331 if (n == "0") { 328 initContext = new BasicType(Type::Qualifiers(), 332 initContext = new BasicType(Type::Qualifiers(), 329 333 BasicType::SignedInt); 330 334 } else { … … 332 336 initContext = decl->get_type(); 333 337 } 334 } else if (ConstantExpr * e = 338 } else if (ConstantExpr * e = 335 339 dynamic_cast<ConstantExpr*>(singleInit->get_value())) { 336 340 Constant *c = e->get_constant(); … … 355 359 singleInit->set_value( ce->get_arg() ); 356 360 ce->set_arg( NULL ); 357 delete ce; 361 delete ce; 358 362 } 359 363 } … … 471 475 #endif 472 476 } 477 478 // ConstructorInit - fall back on C-style initializer 479 void Resolver::fallbackInit( ConstructorInit * ctorInit ) { 480 // could not find valid constructor, or found an intrinsic constructor 481 // fall back on C-style initializer 482 delete ctorInit->get_ctor(); 483 ctorInit->set_ctor( NULL ); 484 maybeAccept( ctorInit->get_init(), *this ); 485 } 486 487 void Resolver::visit( ConstructorInit *ctorInit ) { 488 try { 489 maybeAccept( ctorInit->get_ctor(), *this ); 490 maybeAccept( ctorInit->get_dtor(), *this ); 491 } catch ( SemanticError ) { 492 // no alternatives for the constructor initializer - fallback on C-style initializer 493 // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation? 494 fallbackInit( ctorInit ); 495 return; 496 } 497 498 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * > ( ctorInit->get_ctor() ) ) { 499 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() ); 500 assert( appExpr ); 501 VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() ); 502 assert( function ); 503 if ( LinkageSpec::isOverridable( function->get_var()->get_linkage() ) ) { 504 // if the constructor that was found is intrinsic or autogenerated, reset to C-style 505 // initializer so that code generation is easy to handle 506 fallbackInit( ctorInit ); 507 return; 508 } 509 } 510 // found a constructor - can get rid of C-style initializer 511 delete ctorInit->get_init(); 512 ctorInit->set_init( NULL ); 513 } 473 514 } // namespace ResolvExpr 474 515
Note:
See TracChangeset
for help on using the changeset viewer.