Changeset 7527e63 for src/ResolvExpr/Resolver.cc
- Timestamp:
- Aug 16, 2016, 3:20:06 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1f6d4624
- Parents:
- 950f7a7 (diff), 7880579 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r950f7a7 r7527e63 24 24 #include "SynTree/Initializer.h" 25 25 #include "SymTab/Indexer.h" 26 #include "SymTab/Autogen.h" 26 27 #include "Common/utility.h" 27 28 #include "InitTweak/InitTweak.h" … … 41 42 42 43 virtual void visit( ArrayType * at ); 44 virtual void visit( PointerType * at ); 43 45 44 46 virtual void visit( ExprStmt *exprStmt ); … … 52 54 virtual void visit( BranchStmt *branchStmt ); 53 55 virtual void visit( ReturnStmt *returnStmt ); 54 virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt );55 56 56 57 virtual void visit( SingleInit *singleInit ); … … 59 60 private: 60 61 typedef std::list< Initializer * >::iterator InitIterator; 62 63 template< typename PtrType > 64 void handlePtrType( PtrType * type ); 61 65 62 66 void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & ); … … 192 196 } 193 197 198 template< typename PtrType > 199 void Resolver::handlePtrType( PtrType * type ) { 200 if ( type->get_dimension() ) { 201 CastExpr *castExpr = new CastExpr( type->get_dimension(), SymTab::SizeType->clone() ); 202 Expression *newExpr = findSingleExpression( castExpr, *this ); 203 delete type->get_dimension(); 204 type->set_dimension( newExpr ); 205 } 206 } 207 194 208 void Resolver::visit( ArrayType * at ) { 195 if ( at->get_dimension() ) { 196 BasicType arrayLenType = BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 197 CastExpr *castExpr = new CastExpr( at->get_dimension(), arrayLenType.clone() ); 198 Expression *newExpr = findSingleExpression( castExpr, *this ); 199 delete at->get_dimension(); 200 at->set_dimension( newExpr ); 201 } 209 handlePtrType( at ); 202 210 Visitor::visit( at ); 211 } 212 213 void Resolver::visit( PointerType * pt ) { 214 handlePtrType( pt ); 215 Visitor::visit( pt ); 203 216 } 204 217 … … 422 435 423 436 void Resolver::visit( ListInit * listInit ) { 424 InitIterator iter = listInit->begin _initializers();425 InitIterator end = listInit->end _initializers();437 InitIterator iter = listInit->begin(); 438 InitIterator end = listInit->end(); 426 439 427 440 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) { … … 521 534 // implicitly generated, there's no way for it to have side effects, so get rid of it 522 535 // to clean up generated code. 523 if ( InitTweak::isIn strinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {536 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) { 524 537 delete ctorInit->get_ctor(); 525 538 ctorInit->set_ctor( NULL ); 526 539 } 527 if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) { 540 541 // xxx - todo 542 // if ( InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) { 543 // // can reduce the constructor down to a SingleInit using the 544 // // second argument from the ctor call 545 // } 546 547 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) { 528 548 delete ctorInit->get_dtor(); 529 549 ctorInit->set_dtor( NULL ); 530 550 } 531 }532 533 void Resolver::visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) {534 // before resolving ctor/dtor, need to remove type qualifiers from the first argument (the object being constructed).535 // Do this through a cast expression to greatly simplify the code.536 Expression * callExpr = InitTweak::getCtorDtorCall( impCtorDtorStmt );537 assert( callExpr );538 Expression *& constructee = InitTweak::getCallArg( callExpr, 0 );539 Type * type = 0;540 541 // need to find the type of the first argument, which is unfortunately not uniform since array construction542 // includes an untyped '+' expression.543 if ( UntypedExpr * plusExpr = dynamic_cast< UntypedExpr * >( constructee ) ) {544 // constructee is <array>+<index>545 // get Variable <array>, then get the base type of the VariableExpr - this is the type that needs to be fixed546 Expression * arr = InitTweak::getCallArg( plusExpr, 0 );547 assert( dynamic_cast< VariableExpr * >( arr ) || dynamic_cast< MemberExpr *>( arr ) );548 assert( arr && arr->get_results().size() == 1 );549 type = arr->get_results().front()->clone();550 } else {551 // otherwise, constructing a plain object, which means the object's address is being taken.552 // Need to get the type of the VariableExpr object, because the AddressExpr is rebuilt and uses the553 // type of the VariableExpr to do so.554 assert( constructee->get_results().size() == 1 );555 AddressExpr * addrExpr = dynamic_cast< AddressExpr * > ( constructee );556 assert( addrExpr && addrExpr->get_results().size() == 1 );557 type = addrExpr->get_results().front()->clone();558 }559 // cast to T* with qualifiers removed.560 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument561 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever562 // remove lvalue as a qualifier, this can change to563 // type->get_qualifiers() = Type::Qualifiers();564 Type * base = InitTweak::getPointerBase( type );565 assert( base );566 base->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);567 // if pointer has lvalue qualifier, cast won't appear in output568 type->set_isLvalue( false );569 constructee = new CastExpr( constructee, type );570 571 // finally, resolve the ctor/dtor572 impCtorDtorStmt->get_callStmt()->accept( *this );573 551 } 574 552 } // namespace ResolvExpr
Note:
See TracChangeset
for help on using the changeset viewer.