Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r4cb935e rd5556a3  
    332332}
    333333
     334namespace {
     335        TypeSubstitution makeSub( Type * t ) {
     336                if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
     337                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
     338                } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
     339                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
     340                } else {
     341                        assertf( false, "makeSub expects struct or union type for aggregate" );
     342                }
     343        }
     344}
     345
    334346
    335347MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
    336348                Expression( _aname ), member(_member), aggregate(_aggregate) {
    337         set_result( member->get_type()->clone() );
     349
     350        TypeSubstitution sub( makeSub( aggregate->get_result() ) );
     351        Type * res = member->get_type()->clone();
     352        sub.apply( res );
     353        set_result( res );
    338354        get_result()->set_isLvalue( true );
    339355}
     
    422438}
    423439
    424 NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {
    425         assertf(_name != "0", "Zero is not a valid name\n");
    426         assertf(_name != "1", "One is not a valid name\n");
    427 }
     440NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {}
    428441
    429442NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
     
    511524
    512525ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
     526        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
    513527        delete callExpr;
    514528        deleteAll( tempDecls );
     
    520534        os <<  "Implicit Copy Constructor Expression: " << std::endl;
    521535        assert( callExpr );
     536        os << std::string( indent+2, ' ' );
    522537        callExpr->print( os, indent + 2 );
    523538        os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;
     
    571586        os << std::string( indent+2, ' ' );
    572587        initializer->print( os, indent + 2 );
     588        Expression::print( os, indent );
    573589}
    574590
     
    590606        os << " ... ";
    591607        high->print( os, indent );
     608        Expression::print( os, indent );
    592609}
    593610
     
    601618        }
    602619}
    603 StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {}
     620StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
     621        cloneAll( other.returnDecls, returnDecls );
     622        cloneAll( other.dtors, dtors );
     623}
    604624StmtExpr::~StmtExpr() {
    605625        delete statements;
     626        deleteAll( dtors );
     627        deleteAll( returnDecls );
    606628}
    607629void StmtExpr::print( std::ostream &os, int indent ) const {
    608630        os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
    609631        statements->print( os, indent+2 );
     632        if ( ! returnDecls.empty() ) {
     633                os << std::string( indent+2, ' ' ) << "with returnDecls: ";
     634                printAll( returnDecls, os, indent+2 );
     635        }
     636        if ( ! dtors.empty() ) {
     637                os << std::string( indent+2, ' ' ) << "with dtors: ";
     638                printAll( dtors, os, indent+2 );
     639        }
     640        Expression::print( os, indent );
    610641}
    611642
     
    631662        get_expr()->print( os, indent+2 );
    632663        if ( get_object() ) {
    633                 os << " with decl: ";
     664                os << std::string( indent+2, ' ' ) << "with decl: ";
    634665                get_object()->printShort( os, indent+2 );
    635666        }
     667        Expression::print( os, indent );
    636668}
    637669
Note: See TracChangeset for help on using the changeset viewer.