Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    r68f9c43 r9a705dc8  
    5252Expression::~Expression() {
    5353        delete env;
     54        delete result;
    5455}
    5556
     
    7374ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
    7475}
     76
     77ConstantExpr::~ConstantExpr() {}
    7578
    7679void ConstantExpr::print( std::ostream &os, Indenter indent ) const {
     
    117120}
    118121
     122VariableExpr::~VariableExpr() {
     123        // don't delete the declaration, since it points somewhere else in the tree
     124}
     125
    119126VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) {
    120127        VariableExpr * funcExpr = new VariableExpr( func );
     
    143150}
    144151
     152SizeofExpr::~SizeofExpr() {
     153        delete expr;
     154        delete type;
     155}
     156
    145157void SizeofExpr::print( std::ostream &os, Indenter indent) const {
    146158        os << "Sizeof Expression on: ";
     
    164176}
    165177
     178AlignofExpr::~AlignofExpr() {
     179        delete expr;
     180        delete type;
     181}
     182
    166183void AlignofExpr::print( std::ostream &os, Indenter indent) const {
    167184        os << "Alignof Expression on: ";
     
    179196UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
    180197        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
     198
     199UntypedOffsetofExpr::~UntypedOffsetofExpr() {
     200        delete type;
     201}
    181202
    182203void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const {
     
    196217        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
    197218
     219OffsetofExpr::~OffsetofExpr() {
     220        delete type;
     221}
     222
    198223void OffsetofExpr::print( std::ostream &os, Indenter indent) const {
    199224        os << "Offsetof Expression on member " << member->name << " of ";
     
    209234OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
    210235
     236OffsetPackExpr::~OffsetPackExpr() { delete type; }
     237
    211238void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const {
    212239        os << "Offset pack expression on ";
     
    225252AttrExpr::AttrExpr( const AttrExpr &other ) :
    226253                Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
     254}
     255
     256AttrExpr::~AttrExpr() {
     257        delete attr;
     258        delete expr;
     259        delete type;
    227260}
    228261
     
    238271}
    239272
    240 CastExpr::CastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
     273CastExpr::CastExpr( Expression *arg, Type *toType, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
    241274        set_result(toType);
    242275}
    243276
    244 CastExpr::CastExpr( Expression *arg_ ) : Expression(), arg(arg_) {
     277CastExpr::CastExpr( Expression *arg, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
    245278        set_result( new VoidType( Type::Qualifiers() ) );
    246279}
    247280
    248 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
     281CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {
     282}
     283
     284CastExpr::~CastExpr() {
     285        delete arg;
    249286}
    250287
     
    262299}
    263300
     301KeywordCastExpr::KeywordCastExpr( Expression *arg, Target target ) : Expression(), arg(arg), target( target ) {
     302}
     303
     304KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) {
     305}
     306
     307KeywordCastExpr::~KeywordCastExpr() {
     308        delete arg;
     309}
     310
     311const std::string & KeywordCastExpr::targetString() const {
     312        static const std::string targetStrs[] = {
     313                "coroutine", "thread", "monitor"
     314        };
     315        static_assert(
     316                (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
     317                "Each KeywordCastExpr::Target should have a corresponding string representation"
     318        );
     319        return targetStrs[(unsigned long)target];
     320}
     321
     322void KeywordCastExpr::print( std::ostream &os, Indenter indent ) const {
     323        os << "Keyword Cast of:" << std::endl << indent+1;
     324        arg->print(os, indent+1);
     325        os << std::endl << indent << "... to: ";
     326        os << targetString();
     327        Expression::print( os, indent );
     328}
     329
    264330VirtualCastExpr::VirtualCastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
    265331        set_result(toType);
     
    267333
    268334VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
     335}
     336
     337VirtualCastExpr::~VirtualCastExpr() {
     338        delete arg;
    269339}
    270340
     
    291361}
    292362
     363UntypedMemberExpr::~UntypedMemberExpr() {
     364        delete aggregate;
     365        delete member;
     366}
     367
    293368void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const {
    294369        os << "Untyped Member Expression, with field: " << std::endl << indent+1;
     
    317392}
    318393
     394MemberExpr::~MemberExpr() {
     395        // don't delete the member declaration, since it points somewhere else in the tree
     396        delete aggregate;
     397}
     398
    319399void MemberExpr::print( std::ostream &os, Indenter indent ) const {
    320400        os << "Member Expression, with field: " << std::endl;
     
    332412                Expression( other ), function( maybeClone( other.function ) ) {
    333413        cloneAll( other.args, args );
     414}
     415
     416UntypedExpr::~UntypedExpr() {
     417        delete function;
     418        deleteAll( args );
    334419}
    335420
     
    380465}
    381466
     467NameExpr::~NameExpr() {}
     468
    382469void NameExpr::print( std::ostream &os, Indenter indent ) const {
    383470        os << "Name: " << get_name();
     
    392479LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
    393480                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
     481}
     482
     483LogicalExpr::~LogicalExpr() {
     484        delete arg1;
     485        delete arg2;
    394486}
    395487
     
    407499ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
    408500                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
     501}
     502
     503ConditionalExpr::~ConditionalExpr() {
     504        delete arg1;
     505        delete arg2;
     506        delete arg3;
    409507}
    410508
     
    444542ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
    445543        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
     544        delete callExpr;
     545        deleteAll( tempDecls );
     546        deleteAll( returnDecls );
     547        deleteAll( dtors );
    446548}
    447549
     
    468570}
    469571
     572ConstructorExpr::~ConstructorExpr() {
     573        delete callExpr;
     574}
     575
    470576void ConstructorExpr::print( std::ostream &os, Indenter indent ) const {
    471577        os <<  "Constructor Expression: " << std::endl << indent+1;
     
    482588
    483589CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
     590
     591CompoundLiteralExpr::~CompoundLiteralExpr() {
     592        delete initializer;
     593}
    484594
    485595void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const {
     
    508618        cloneAll( other.dtors, dtors );
    509619}
     620StmtExpr::~StmtExpr() {
     621        delete statements;
     622        deleteAll( dtors );
     623        deleteAll( returnDecls );
     624}
    510625void StmtExpr::computeResult() {
    511626        assert( statements );
    512627        std::list< Statement * > & body = statements->kids;
     628        delete result;
    513629        result = nullptr;
    514630        if ( ! returnDecls.empty() ) {
     
    553669UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
    554670}
    555 
     671UniqueExpr::~UniqueExpr() {
     672        delete expr;
     673        delete object;
     674        delete var;
     675}
    556676void UniqueExpr::print( std::ostream &os, Indenter indent ) const {
    557677        os << "Unique Expression with id:" << id << std::endl << indent+1;
     
    566686InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
    567687InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
     688InitAlternative::~InitAlternative() {
     689        delete type;
     690        delete designation;
     691}
    568692
    569693UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
    570694UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
     695UntypedInitExpr::~UntypedInitExpr() {
     696        delete expr;
     697}
    571698
    572699void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const {
     
    586713}
    587714InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
     715InitExpr::~InitExpr() {
     716        delete expr;
     717        delete designation;
     718}
    588719
    589720void InitExpr::print( std::ostream & os, Indenter indent ) const {
     
    599730}
    600731DeletedExpr::DeletedExpr( const DeletedExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), deleteStmt( other.deleteStmt ) {}
     732DeletedExpr::~DeletedExpr() {
     733        delete expr;
     734}
    601735
    602736void DeletedExpr::print( std::ostream & os, Indenter indent ) const {
Note: See TracChangeset for help on using the changeset viewer.