Changes in src/ResolvExpr/Resolver.cc [64071c2:7b3f66b]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r64071c2 r7b3f66b 52 52 virtual void visit( BranchStmt *branchStmt ); 53 53 virtual void visit( ReturnStmt *returnStmt ); 54 virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt );55 54 56 55 virtual void visit( SingleInit *singleInit ); … … 493 492 } catch ( SemanticError ) { 494 493 // no alternatives for the constructor initializer - fallback on C-style initializer 495 // xxx - not sure if this makes a ton of sense - should maybe never be able to have this situation?494 // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation? 496 495 fallbackInit( ctorInit ); 497 496 return; … … 514 513 } 515 514 } 516 517 void Resolver::visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) {518 // before resolving ctor/dtor, need to remove type qualifiers from the first argument (the object being constructed).519 // Do this through a cast expression to greatly simplify the code.520 Expression * callExpr = InitTweak::getCtorDtorCall( impCtorDtorStmt );521 assert( callExpr );522 Expression *& constructee = InitTweak::getCallArg( callExpr, 0 );523 Type * type = 0;524 525 // need to find the type of the first argument, which is unfortunately not uniform since array construction526 // includes an untyped '+' expression.527 if ( UntypedExpr * plusExpr = dynamic_cast< UntypedExpr * >( constructee ) ) {528 // constructee is <array>+<index>529 // get Variable <array>, then get the base type of the VariableExpr - this is the type that needs to be fixed530 Expression * arr = InitTweak::getCallArg( plusExpr, 0 );531 assert( dynamic_cast< VariableExpr * >( arr ) );532 assert( arr && arr->get_results().size() == 1 );533 type = arr->get_results().front()->clone();534 } else {535 // otherwise, constructing a plain object, which means the object's address is being taken.536 // Need to get the type of the VariableExpr object, because the AddressExpr is rebuilt and uses the537 // type of the VariableExpr to do so.538 assert( constructee->get_results().size() == 1 );539 AddressExpr * addrExpr = dynamic_cast< AddressExpr * > ( constructee );540 assert( addrExpr && addrExpr->get_results().size() == 1);541 type = addrExpr->get_results().front()->clone();542 }543 // cast to T* with qualifiers removed.544 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument545 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever546 // remove lvalue as a qualifier, this can change to547 // type->get_qualifiers() = Type::Qualifiers();548 Type * base = InitTweak::getPointerBase( type );549 assert( base );550 base->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);551 // if pointer has lvalue qualifier, cast won't appear in output552 type->set_isLvalue( false );553 constructee = new CastExpr( constructee, type );554 555 // finally, resolve the ctor/dtor556 impCtorDtorStmt->get_callStmt()->accept( *this );557 }558 515 } // namespace ResolvExpr 559 516
Note:
See TracChangeset
for help on using the changeset viewer.