Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r3b58d91 rb6fe7e6  
    2828#include "TypeSubstitution.h"
    2929#include "Common/utility.h"
     30#include "InitTweak/InitTweak.h"
    3031
    3132
     
    310311}
    311312
    312 UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
     313UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) :
    313314                Expression( _aname ), member(_member), aggregate(_aggregate) {}
    314315
    315316UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
    316                 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
     317                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
    317318}
    318319
    319320UntypedMemberExpr::~UntypedMemberExpr() {
    320321        delete aggregate;
    321         delete member;
    322322}
    323323
    324324void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
    325         os << "Untyped Member Expression, with field: " << std::endl;
    326         get_member()->print(os, indent+4);
    327         os << std::string( indent+2, ' ' );
     325        os << "Untyped Member Expression, with field: " << get_member();
    328326
    329327        Expression *agg = get_aggregate();
    330         os << "from aggregate: " << std::endl;
     328        os << ", from aggregate: ";
    331329        if (agg != 0) {
    332                 os << std::string( indent + 4, ' ' );
    333                 agg->print(os, indent + 4);
     330                os << std::string( indent + 2, ' ' );
     331                agg->print(os, indent + 2);
    334332        }
    335333        os << std::string( indent+2, ' ' );
     
    496494
    497495void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
    498         os << std::string( indent, ' ' ) << "Implicit Copy Constructor Expression: " << std::endl;
     496        os << "Implicit Copy Constructor Expression: " << std::endl;
    499497        assert( callExpr );
    500498        callExpr->print( os, indent + 2 );
     
    506504}
    507505
     506
     507ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
     508        // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
     509        assert( callExpr );
     510        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
     511        assert( arg );
     512        cloneAll( arg->get_results(), results );
     513}
     514
     515ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
     516}
     517
     518ConstructorExpr::~ConstructorExpr() {
     519        delete callExpr;
     520}
     521
     522void ConstructorExpr::print( std::ostream &os, int indent ) const {
     523        os <<  "Constructor Expression: " << std::endl;
     524        assert( callExpr );
     525        os << std::string( indent+2, ' ' );
     526        callExpr->print( os, indent + 2 );
     527        Expression::print( os, indent );
     528}
     529
     530
     531CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
     532        add_result( type->clone() );
     533}
     534
     535CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
     536
     537CompoundLiteralExpr::~CompoundLiteralExpr() {
     538        delete initializer;
     539        delete type;
     540}
     541
     542void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
     543        os << "Compound Literal Expression: " << std::endl;
     544        if ( type ) type->print( os, indent + 2 );
     545        if ( initializer ) initializer->print( os, indent + 2 );
     546}
     547
    508548UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
    509549
     
    514554        if ( get_body() != 0 )
    515555                get_body()->print( os, indent + 2 );
    516 }
    517 
    518 
    519 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
    520         add_result( type->clone() );
    521 }
    522 
    523 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
    524 
    525 CompoundLiteralExpr::~CompoundLiteralExpr() {
    526         delete initializer;
    527         delete type;
    528 }
    529 
    530 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
    531         os << "Compound Literal Expression: " << std::endl;
    532         if ( type ) type->print( os, indent + 2 );
    533         if ( initializer ) initializer->print( os, indent + 2 );
    534556}
    535557
Note: See TracChangeset for help on using the changeset viewer.