Changes in src/ResolvExpr/Resolver.cc [ec79847:3cfe27f]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
rec79847 r3cfe27f 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 : Mon May 09 12:10:19201613 // Update Count : 20311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 24 16:43:11 2016 13 // Update Count : 181 14 14 // 15 15 … … 25 25 #include "SymTab/Indexer.h" 26 26 #include "Common/utility.h" 27 #include "InitTweak/FixInit.h"28 27 29 28 #include <iostream> … … 34 33 public: 35 34 Resolver() : SymTab::Indexer( false ), switchType( 0 ) {} 36 35 37 36 virtual void visit( FunctionDecl *functionDecl ); 38 37 virtual void visit( ObjectDecl *functionDecl ); … … 55 54 virtual void visit( SingleInit *singleInit ); 56 55 virtual void visit( ListInit *listInit ); 57 virtual void visit( ConstructorInit *ctorInit );58 56 private: 59 57 typedef std::list< Initializer * >::iterator InitIterator; … … 61 59 void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & ); 62 60 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & ); 63 void fallbackInit( ConstructorInit * ctorInit ); 61 64 62 std::list< Type * > functionReturn; 65 63 Type *initContext; … … 84 82 } 85 83 86 87 84 namespace { 88 85 void finishExpr( Expression *expr, const TypeEnvironment &env ) { … … 90 87 env.makeSubstitution( *expr->get_env() ); 91 88 } 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 { 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 103 98 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 104 99 TypeEnvironment env; … … 131 126 } // if 132 127 } 133 128 134 129 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) { 135 130 TypeEnvironment env; … … 164 159 return newExpr; 165 160 } 166 167 } 168 161 162 } 163 169 164 void Resolver::visit( ObjectDecl *objectDecl ) { 170 165 Type *new_type = resolveTypeof( objectDecl->get_type(), *this ); … … 263 258 forStmt->set_condition( newExpr ); 264 259 } // if 265 260 266 261 if ( forStmt->get_increment() ) { 267 262 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this ); … … 277 272 delete switchStmt->get_condition(); 278 273 switchStmt->set_condition( newExpr ); 279 274 280 275 visitor.Visitor::visit( switchStmt ); 281 276 } … … 319 314 bool isCharType( T t ) { 320 315 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) { 321 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 316 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar || 322 317 bt->get_kind() == BasicType::UnsignedChar; 323 318 } … … 331 326 string n = ne->get_name(); 332 327 if (n == "0") { 333 initContext = new BasicType(Type::Qualifiers(), 328 initContext = new BasicType(Type::Qualifiers(), 334 329 BasicType::SignedInt); 335 330 } else { … … 337 332 initContext = decl->get_type(); 338 333 } 339 } else if (ConstantExpr * e = 334 } else if (ConstantExpr * e = 340 335 dynamic_cast<ConstantExpr*>(singleInit->get_value())) { 341 336 Constant *c = e->get_constant(); … … 360 355 singleInit->set_value( ce->get_arg() ); 361 356 ce->set_arg( NULL ); 362 delete ce; 357 delete ce; 363 358 } 364 359 } … … 476 471 #endif 477 472 } 478 479 // ConstructorInit - fall back on C-style initializer480 void Resolver::fallbackInit( ConstructorInit * ctorInit ) {481 // could not find valid constructor, or found an intrinsic constructor482 // fall back on C-style initializer483 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 initializer494 // 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 initializer500 delete ctorInit->get_init();501 ctorInit->set_init( NULL );502 503 // intrinsic single parameter constructors and destructors do nothing. Since this was504 // implicitly generated, there's no way for it to have side effects, so get rid of it505 // 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 }515 473 } // namespace ResolvExpr 516 474
Note:
See TracChangeset
for help on using the changeset viewer.