Changes in src/ResolvExpr/Resolver.cc [3cfe27f:5b2f5bb]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r3cfe27f r5b2f5bb 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 : Wed Mar 30 15:47:19 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 & ); 62 void fallbackInit( ConstructorInit * ctorInit ); 61 63 62 64 std::list< Type * > functionReturn; … … 95 97 return newExpr; 96 98 } 97 99 98 100 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 99 101 TypeEnvironment env; … … 126 128 } // if 127 129 } 128 130 129 131 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 130 132 TypeEnvironment env; … … 159 161 return newExpr; 160 162 } 161 162 } 163 163 164 } 165 164 166 void Resolver::visit( ObjectDecl *objectDecl ) { 165 167 Type *new_type = resolveTypeof( objectDecl->get_type(), *this ); 166 168 objectDecl->set_type( new_type ); 167 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that class-variable168 // initContext is changed multiple time because the LHS is analysed twice. The second analysis changes169 // initContext because of a function type can contain object declarations in the return and parameter types. So170 // each value of initContext is retained, so the type on the first analysis is preserved and used for selecting171 // the RHS.172 Type *temp = initContext;173 169 initContext = new_type; 174 170 SymTab::Indexer::visit( objectDecl ); 175 initContext = temp;176 171 } 177 172 … … 258 253 forStmt->set_condition( newExpr ); 259 254 } // if 260 255 261 256 if ( forStmt->get_increment() ) { 262 257 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this ); … … 272 267 delete switchStmt->get_condition(); 273 268 switchStmt->set_condition( newExpr ); 274 269 275 270 visitor.Visitor::visit( switchStmt ); 276 271 } … … 314 309 bool isCharType( T t ) { 315 310 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 316 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 311 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 317 312 bt->get_kind() == BasicType::UnsignedChar; 318 313 } … … 326 321 string n = ne->get_name(); 327 322 if (n == "0") { 328 initContext = new BasicType(Type::Qualifiers(), 323 initContext = new BasicType(Type::Qualifiers(), 329 324 BasicType::SignedInt); 330 325 } else { … … 332 327 initContext = decl->get_type(); 333 328 } 334 } else if (ConstantExpr * e = 329 } else if (ConstantExpr * e = 335 330 dynamic_cast<ConstantExpr*>(singleInit->get_value())) { 336 331 Constant *c = e->get_constant(); … … 355 350 singleInit->set_value( ce->get_arg() ); 356 351 ce->set_arg( NULL ); 357 delete ce; 352 delete ce; 358 353 } 359 354 } … … 471 466 #endif 472 467 } 468 469 // ConstructorInit - fall back on C-style initializer 470 void Resolver::fallbackInit( ConstructorInit * ctorInit ) { 471 // could not find valid constructor, or found an intrinsic constructor 472 // fall back on C-style initializer 473 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 try { 481 maybeAccept( ctorInit->get_ctor(), *this ); 482 maybeAccept( ctorInit->get_dtor(), *this ); 483 } catch ( SemanticError ) { 484 // no alternatives for the constructor initializer - fallback on C-style initializer 485 // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation? 486 fallbackInit( ctorInit ); 487 return; 488 } 489 490 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * > ( ctorInit->get_ctor() ) ) { 491 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() ); 492 assert( appExpr ); 493 VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() ); 494 assert( function ); 495 if ( LinkageSpec::isOverridable( function->get_var()->get_linkage() ) ) { 496 // if the constructor that was found is intrinsic or autogenerated, reset to C-style 497 // initializer so that code generation is easy to handle 498 fallbackInit( ctorInit ); 499 return; 500 } 501 } 502 // found a constructor - can get rid of C-style initializer 503 delete ctorInit->get_init(); 504 ctorInit->set_init( NULL ); 505 } 473 506 } // namespace ResolvExpr 474 507
Note:
See TracChangeset
for help on using the changeset viewer.