Changes in src/ResolvExpr/Resolver.cc [3cfe27f:ec79847]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r3cfe27f rec79847 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 : Mon May 09 12:10:19 2016 13 // Update Count : 203 14 14 // 15 15 … … 25 25 #include "SymTab/Indexer.h" 26 26 #include "Common/utility.h" 27 #include "InitTweak/FixInit.h" 27 28 28 29 #include <iostream> … … 33 34 public: 34 35 Resolver() : SymTab::Indexer( false ), switchType( 0 ) {} 35 36 36 37 virtual void visit( FunctionDecl *functionDecl ); 37 38 virtual void visit( ObjectDecl *functionDecl ); … … 54 55 virtual void visit( SingleInit *singleInit ); 55 56 virtual void visit( ListInit *listInit ); 57 virtual void visit( ConstructorInit *ctorInit ); 56 58 private: 57 59 typedef std::list< Initializer * >::iterator InitIterator; … … 59 61 void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & ); 60 62 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & ); 61 63 void fallbackInit( ConstructorInit * ctorInit ); 62 64 std::list< Type * > functionReturn; 63 65 Type *initContext; … … 82 84 } 83 85 86 84 87 namespace { 85 88 void finishExpr( Expression *expr, const TypeEnvironment &env ) { … … 87 90 env.makeSubstitution( *expr->get_env() ); 88 91 } 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 92 } // namespace 93 94 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 95 global_renamer.reset(); 96 TypeEnvironment env; 97 Expression *newExpr = resolveInVoidContext( untyped, indexer, env ); 98 finishExpr( newExpr, env ); 99 return newExpr; 100 } 101 102 namespace { 98 103 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 99 104 TypeEnvironment env; … … 126 131 } // if 127 132 } 128 133 129 134 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 130 135 TypeEnvironment env; … … 159 164 return newExpr; 160 165 } 161 162 } 163 166 167 } 168 164 169 void Resolver::visit( ObjectDecl *objectDecl ) { 165 170 Type *new_type = resolveTypeof( objectDecl->get_type(), *this ); … … 258 263 forStmt->set_condition( newExpr ); 259 264 } // if 260 265 261 266 if ( forStmt->get_increment() ) { 262 267 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this ); … … 272 277 delete switchStmt->get_condition(); 273 278 switchStmt->set_condition( newExpr ); 274 279 275 280 visitor.Visitor::visit( switchStmt ); 276 281 } … … 314 319 bool isCharType( T t ) { 315 320 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 316 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 321 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 317 322 bt->get_kind() == BasicType::UnsignedChar; 318 323 } … … 326 331 string n = ne->get_name(); 327 332 if (n == "0") { 328 initContext = new BasicType(Type::Qualifiers(), 333 initContext = new BasicType(Type::Qualifiers(), 329 334 BasicType::SignedInt); 330 335 } else { … … 332 337 initContext = decl->get_type(); 333 338 } 334 } else if (ConstantExpr * e = 339 } else if (ConstantExpr * e = 335 340 dynamic_cast<ConstantExpr*>(singleInit->get_value())) { 336 341 Constant *c = e->get_constant(); … … 355 360 singleInit->set_value( ce->get_arg() ); 356 361 ce->set_arg( NULL ); 357 delete ce; 362 delete ce; 358 363 } 359 364 } … … 471 476 #endif 472 477 } 478 479 // ConstructorInit - fall back on C-style initializer 480 void Resolver::fallbackInit( ConstructorInit * ctorInit ) { 481 // could not find valid constructor, or found an intrinsic constructor 482 // fall back on C-style initializer 483 delete ctorInit->get_ctor(); 484 ctorInit->set_ctor( NULL ); 485 maybeAccept( ctorInit->get_init(), *this ); 486 } 487 488 void Resolver::visit( ConstructorInit *ctorInit ) { 489 try { 490 maybeAccept( ctorInit->get_ctor(), *this ); 491 maybeAccept( ctorInit->get_dtor(), *this ); 492 } catch ( SemanticError ) { 493 // no alternatives for the constructor initializer - fallback on C-style initializer 494 // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation? 495 fallbackInit( ctorInit ); 496 return; 497 } 498 499 // found a constructor - can get rid of C-style initializer 500 delete ctorInit->get_init(); 501 ctorInit->set_init( NULL ); 502 503 // intrinsic single parameter constructors and destructors do nothing. Since this was 504 // implicitly generated, there's no way for it to have side effects, so get rid of it 505 // to clean up generated code. 506 if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) { 507 delete ctorInit->get_ctor(); 508 ctorInit->set_ctor( NULL ); 509 } 510 if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) { 511 delete ctorInit->get_dtor(); 512 ctorInit->set_dtor( NULL ); 513 } 514 } 473 515 } // namespace ResolvExpr 474 516
Note:
See TracChangeset
for help on using the changeset viewer.