source: src/SynTree/Expression.cc @ b3b2077

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since b3b2077 was b3b2077, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

refactor some code that generates dereference and assignment calls

  • Property mode set to 100644
File size: 19.7 KB
RevLine 
[0dd3a2f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[3be261a]7// Expression.cc --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[e04ef3a]11// Last Modified By : Peter A. Buhr
[d9e2280]12// Last Modified On : Fri Aug  5 14:23:56 2016
13// Update Count     : 49
[0dd3a2f]14//
15
[51b7345]16#include <iostream>
17#include <cassert>
18#include <list>
19#include <algorithm>
20
21#include <iterator>
22
23#include "Type.h"
[630a82a]24#include "Initializer.h"
[51b7345]25#include "Expression.h"
26#include "Declaration.h"
27#include "Statement.h"
28#include "TypeSubstitution.h"
[d3b7937]29#include "Common/utility.h"
[b6fe7e6]30#include "InitTweak/InitTweak.h"
[51b7345]31
32
[906e24d]33Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
[0dd3a2f]34
[906e24d]35Expression::Expression( const Expression &other ) : result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
[0dd3a2f]36}
37
38Expression::~Expression() {
39        delete env;
[7f5566b]40        delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
[906e24d]41        delete result;
[51b7345]42}
43
[59db689]44void Expression::print( std::ostream &os, int indent ) const {
[0dd3a2f]45        if ( env ) {
[cf0941d]46                os << std::string( indent, ' ' ) << "with environment:" << std::endl;
[0dd3a2f]47                env->print( os, indent+2 );
48        } // if
[51b7345]49
[0dd3a2f]50        if ( argName ) {
[cf0941d]51                os << std::string( indent, ' ' ) << "with designator:";
[0dd3a2f]52                argName->print( os, indent+2 );
53        } // if
[e04ef3a]54
55        if ( extension ) {
56                os << std::string( indent, ' ' ) << "with extension:";
57        } // if
[51b7345]58}
59
[0dd3a2f]60ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
[906e24d]61        set_result( constant.get_type()->clone() );
[51b7345]62}
63
[0dd3a2f]64ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
65}
[51b7345]66
67ConstantExpr::~ConstantExpr() {}
68
[0dd3a2f]69void ConstantExpr::print( std::ostream &os, int indent ) const {
[60089f4]70        os << "constant expression " ;
[cf0941d]71        constant.print( os );
[0dd3a2f]72        Expression::print( os, indent );
[51b7345]73}
74
[0dd3a2f]75VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) {
[db4ecc5]76        assert( var );
77        assert( var->get_type() );
[906e24d]78        Type * type = var->get_type()->clone();
79        type->set_isLvalue( true );
80        set_result( type );
[51b7345]81}
82
[0dd3a2f]83VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
[51b7345]84}
85
[0dd3a2f]86VariableExpr::~VariableExpr() {
87        // don't delete the declaration, since it points somewhere else in the tree
[51b7345]88}
89
[0dd3a2f]90void VariableExpr::print( std::ostream &os, int indent ) const {
[89231bc]91        os << "Variable Expression: ";
[51b7345]92
[0dd3a2f]93        Declaration *decl = get_var();
94        // if ( decl != 0) decl->print(os, indent + 2);
95        if ( decl != 0) decl->printShort(os, indent + 2);
96        os << std::endl;
97        Expression::print( os, indent );
[51b7345]98}
99
100SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
[0dd3a2f]101                Expression( _aname ), expr(expr_), type(0), isType(false) {
[906e24d]102        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[51b7345]103}
104
105SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
[0dd3a2f]106                Expression( _aname ), expr(0), type(type_), isType(true) {
[906e24d]107        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[51b7345]108}
109
[0dd3a2f]110SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
111        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
[51b7345]112}
113
[0dd3a2f]114SizeofExpr::~SizeofExpr() {
115        delete expr;
116        delete type;
[51b7345]117}
118
119void SizeofExpr::print( std::ostream &os, int indent) const {
[89231bc]120        os << "Sizeof Expression on: ";
[51b7345]121
[47534159]122        if (isType)
123                type->print(os, indent + 2);
124        else
125                expr->print(os, indent + 2);
126
127        os << std::endl;
128        Expression::print( os, indent );
129}
130
131AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
132                Expression( _aname ), expr(expr_), type(0), isType(false) {
[906e24d]133        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[47534159]134}
135
136AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
137                Expression( _aname ), expr(0), type(type_), isType(true) {
[906e24d]138        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[47534159]139}
140
141AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
142        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
143}
144
145AlignofExpr::~AlignofExpr() {
146        delete expr;
147        delete type;
148}
149
150void AlignofExpr::print( std::ostream &os, int indent) const {
151        os << std::string( indent, ' ' ) << "Alignof Expression on: ";
152
[0dd3a2f]153        if (isType)
154                type->print(os, indent + 2);
155        else
156                expr->print(os, indent + 2);
[51b7345]157
[0dd3a2f]158        os << std::endl;
159        Expression::print( os, indent );
[51b7345]160}
161
[2a4b088]162UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
163                Expression( _aname ), type(type_), member(member_) {
[906e24d]164        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[2a4b088]165}
166
167UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
168        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
169
170UntypedOffsetofExpr::~UntypedOffsetofExpr() {
171        delete type;
172}
173
174void UntypedOffsetofExpr::print( std::ostream &os, int indent) const {
175        os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of ";
176
177        if ( type ) {
178                type->print(os, indent + 2);
179        } else {
180                os << "<NULL>";
181        }
182
183        os << std::endl;
184        Expression::print( os, indent );
185}
186
[25a054f]187OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
188                Expression( _aname ), type(type_), member(member_) {
[906e24d]189        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[25a054f]190}
191
192OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
[79970ed]193        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
[25a054f]194
195OffsetofExpr::~OffsetofExpr() {
196        delete type;
197}
198
199void OffsetofExpr::print( std::ostream &os, int indent) const {
200        os << std::string( indent, ' ' ) << "Offsetof Expression on member ";
201
202        if ( member ) {
203                os << member->get_name();
204        } else {
205                os << "<NULL>";
206        }
207
208        os << " of ";
209
210        if ( type ) {
211                type->print(os, indent + 2);
212        } else {
213                os << "<NULL>";
214        }
215
216        os << std::endl;
217        Expression::print( os, indent );
218}
219
[afc1045]220OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
[906e24d]221        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
[afc1045]222}
223
224OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
225
226OffsetPackExpr::~OffsetPackExpr() { delete type; }
227
228void OffsetPackExpr::print( std::ostream &os, int indent ) const {
229        os << std::string( indent, ' ' ) << "Offset pack expression on ";
230
231        if ( type ) {
232                type->print(os, indent + 2);
233        } else {
234                os << "<NULL>";
235        }
236
[25a054f]237        os << std::endl;
238        Expression::print( os, indent );
239}
240
[51b7345]241AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
[0dd3a2f]242                Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
[51b7345]243}
244
245AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
[0dd3a2f]246                Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
[51b7345]247}
248
[0dd3a2f]249AttrExpr::AttrExpr( const AttrExpr &other ) :
250                Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
[51b7345]251}
252
[0dd3a2f]253AttrExpr::~AttrExpr() {
254        delete attr;
255        delete expr;
256        delete type;
[51b7345]257}
258
259void AttrExpr::print( std::ostream &os, int indent) const {
[44b5ca0]260        os << std::string( indent, ' ' ) << "Attr ";
[0dd3a2f]261        attr->print( os, indent + 2 );
262        if ( isType || expr ) {
263                os << "applied to: ";
[51b7345]264
[0dd3a2f]265                if (isType)
266                        type->print(os, indent + 2);
267                else
268                        expr->print(os, indent + 2);
269        } // if
[51b7345]270
[0dd3a2f]271        os << std::endl;
272        Expression::print( os, indent );
[51b7345]273}
274
[0dd3a2f]275CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
[906e24d]276        set_result(toType);
[51b7345]277}
278
279CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
[906e24d]280        set_result( new VoidType( Type::Qualifiers() ) );
[51b7345]281}
282
[0dd3a2f]283CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
[51b7345]284}
285
286CastExpr::~CastExpr() {
[0dd3a2f]287        delete arg;
[51b7345]288}
289
290// CastExpr *CastExpr::clone() const { return 0; }
291
292void CastExpr::print( std::ostream &os, int indent ) const {
[89231bc]293        os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
[0dd3a2f]294        arg->print(os, indent+2);
[44b5ca0]295        os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
[906e24d]296        os << std::string( indent+2, ' ' );
297        if ( result->isVoid() ) {
298                os << "nothing";
[0dd3a2f]299        } else {
[906e24d]300                result->print( os, indent+2 );
[0dd3a2f]301        } // if
[906e24d]302        os << std::endl;
[0dd3a2f]303        Expression::print( os, indent );
304}
305
[3b58d91]306UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
[0dd3a2f]307                Expression( _aname ), member(_member), aggregate(_aggregate) {}
[51b7345]308
[0dd3a2f]309UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
[3b58d91]310                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
[51b7345]311}
312
313UntypedMemberExpr::~UntypedMemberExpr() {
[0dd3a2f]314        delete aggregate;
[3b58d91]315        delete member;
[51b7345]316}
317
318void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
[3b58d91]319        os << "Untyped Member Expression, with field: " << std::endl;
[8c49c0e]320        os << std::string( indent+2, ' ' );
[3b58d91]321        get_member()->print(os, indent+4);
322        os << std::string( indent+2, ' ' );
[51b7345]323
[0dd3a2f]324        Expression *agg = get_aggregate();
[3b58d91]325        os << "from aggregate: " << std::endl;
[89231bc]326        if (agg != 0) {
[3b58d91]327                os << std::string( indent + 4, ' ' );
328                agg->print(os, indent + 4);
[89231bc]329        }
330        os << std::string( indent+2, ' ' );
[0dd3a2f]331        Expression::print( os, indent );
[51b7345]332}
333
334
335MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
[0dd3a2f]336                Expression( _aname ), member(_member), aggregate(_aggregate) {
[906e24d]337        set_result( member->get_type()->clone() );
338        get_result()->set_isLvalue( true );
[51b7345]339}
340
[39f84a4]341//// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...
[0dd3a2f]342MemberExpr::MemberExpr( const MemberExpr &other ) :
[39f84a4]343                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
[51b7345]344}
345
346MemberExpr::~MemberExpr() {
[39f84a4]347        // delete member;
[0dd3a2f]348        delete aggregate;
[51b7345]349}
350
351void MemberExpr::print( std::ostream &os, int indent ) const {
[89231bc]352        os << "Member Expression, with field: " << std::endl;
[51b7345]353
[0dd3a2f]354        assert( member );
[44b5ca0]355        os << std::string( indent + 2, ' ' );
[0dd3a2f]356        member->print( os, indent + 2 );
357        os << std::endl;
[51b7345]358
[0dd3a2f]359        Expression *agg = get_aggregate();
[44b5ca0]360        os << std::string( indent, ' ' ) << "from aggregate: " << std::endl;
[89231bc]361        if (agg != 0) {
[bb8ea30]362                os << std::string( indent + 2, ' ' );
[89231bc]363                agg->print(os, indent + 2);
364        }
365        os << std::string( indent+2, ' ' );
[0dd3a2f]366        Expression::print( os, indent );
[51b7345]367}
368
[6eb8948]369UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
370                Expression( _aname ), function(_function), args(_args) {}
[51b7345]371
[0dd3a2f]372UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
373                Expression( other ), function( maybeClone( other.function ) ) {
374        cloneAll( other.args, args );
[51b7345]375}
376
[ac71a86]377UntypedExpr::~UntypedExpr() {
378        delete function;
[03b812d2]379        deleteAll( args );
[ac71a86]380}
[51b7345]381
[b3b2077]382UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
383        UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
384        if ( Type * type = expr->get_result() ) {
385                Type * base = InitTweak::getPointerBase( type );
386                if ( ! base ) {
387                        std::cerr << type << std::endl;
388                }
389                assertf( base, "expected pointer type in dereference\n" );
390                ret->set_result( maybeClone( base ) );
391        }
392        return ret;
393}
394
395UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) {
396        assert( arg1 && arg2 );
397        UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } );
398        if ( arg1->get_result() && arg2->get_result() ) {
399                // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
400                // so the result is the type of the RHS
401                ret->set_result( arg2->get_result()->clone() );
402        }
403        return ret;
404}
405
406
[51b7345]407void UntypedExpr::print( std::ostream &os, int indent ) const {
[89231bc]408        os << "Applying untyped: " << std::endl;
[bb8ea30]409        os << std::string( indent+2, ' ' );
410        function->print(os, indent + 2);
[44b5ca0]411        os << std::string( indent, ' ' ) << "...to: " << std::endl;
[bb8ea30]412        printAll(args, os, indent + 2);
[0dd3a2f]413        Expression::print( os, indent );
[51b7345]414}
415
[0dd3a2f]416void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
417        std::list<Expression *>::const_iterator i;
[60089f4]418        for (i = args.begin(); i != args.end(); i++) {
419                os << std::string(indent, ' ' );
[0dd3a2f]420                (*i)->print(os, indent);
[60089f4]421        }
[51b7345]422}
423
424NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {}
425
[0dd3a2f]426NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
[51b7345]427}
428
429NameExpr::~NameExpr() {}
430
431void NameExpr::print( std::ostream &os, int indent ) const {
[89231bc]432        os << "Name: " << get_name() << std::endl;
[0dd3a2f]433        Expression::print( os, indent );
[51b7345]434}
435
436LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
[0dd3a2f]437                Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
[906e24d]438        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
[51b7345]439}
440
[0dd3a2f]441LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
442                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
[51b7345]443}
444
[a08ba92]445LogicalExpr::~LogicalExpr() {
[0dd3a2f]446        delete arg1;
447        delete arg2;
[51b7345]448}
449
450void LogicalExpr::print( std::ostream &os, int indent )const {
[44b5ca0]451        os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
[0dd3a2f]452        arg1->print(os);
453        os << " and ";
454        arg2->print(os);
455        os << std::endl;
456        Expression::print( os, indent );
[51b7345]457}
458
459ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
[0dd3a2f]460                Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
[51b7345]461
[0dd3a2f]462ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
463                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
464}
[51b7345]465
466ConditionalExpr::~ConditionalExpr() {
[0dd3a2f]467        delete arg1;
468        delete arg2;
469        delete arg3;
[51b7345]470}
471
472void ConditionalExpr::print( std::ostream &os, int indent ) const {
[b3b2077]473        os << "Conditional expression on: " << std::endl;
474        os << std::string( indent+2, ' ' );
[0dd3a2f]475        arg1->print( os, indent+2 );
[44b5ca0]476        os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
[b3b2077]477        os << std::string( indent+2, ' ' );
[0dd3a2f]478        arg2->print( os, indent+2 );
[44b5ca0]479        os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
[b3b2077]480        os << std::string( indent+2, ' ' );
[0dd3a2f]481        arg3->print( os, indent+2 );
482        os << std::endl;
483        Expression::print( os, indent );
484}
485
[3be261a]486AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
487
488
[7f5566b]489void AsmExpr::print( std::ostream &os, int indent ) const {
490        os << "Asm Expression: " << std::endl;
491        if ( inout ) inout->print( os, indent + 2 );
492        if ( constraint ) constraint->print( os, indent + 2 );
493        if ( operand ) operand->print( os, indent + 2 );
494}
495
[db4ecc5]496
497ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
498        assert( callExpr );
[906e24d]499        assert( callExpr->has_result() );
500        set_result( callExpr->get_result()->clone() );
[db4ecc5]501}
502
503ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
504        cloneAll( other.tempDecls, tempDecls );
505        cloneAll( other.returnDecls, returnDecls );
506        cloneAll( other.dtors, dtors );
507}
508
509ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
510        delete callExpr;
511        deleteAll( tempDecls );
512        deleteAll( returnDecls );
513        deleteAll( dtors );
514}
515
516void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
[b6fe7e6]517        os <<  "Implicit Copy Constructor Expression: " << std::endl;
[db4ecc5]518        assert( callExpr );
519        callExpr->print( os, indent + 2 );
520        os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;
521        printAll(tempDecls, os, indent+2);
[dc2e7e0]522        os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl;
523        printAll(returnDecls, os, indent+2);
[db4ecc5]524        Expression::print( os, indent );
525}
526
[3be261a]527
[b6fe7e6]528ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
529        // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
530        assert( callExpr );
531        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
532        assert( arg );
[906e24d]533        set_result( maybeClone( arg->get_result() ) );
[b6fe7e6]534}
[3be261a]535
[b6fe7e6]536ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
537}
538
539ConstructorExpr::~ConstructorExpr() {
540        delete callExpr;
541}
542
543void ConstructorExpr::print( std::ostream &os, int indent ) const {
544        os <<  "Constructor Expression: " << std::endl;
545        assert( callExpr );
546        os << std::string( indent+2, ' ' );
547        callExpr->print( os, indent + 2 );
548        Expression::print( os, indent );
[0dd3a2f]549}
550
[3be261a]551
[630a82a]552CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
[3c13c03]553        assert( type && initializer );
[906e24d]554        set_result( type->clone() );
[630a82a]555}
556
[3c13c03]557CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( other.type->clone() ), initializer( other.initializer->clone() ) {}
[630a82a]558
559CompoundLiteralExpr::~CompoundLiteralExpr() {
560        delete initializer;
561        delete type;
562}
563
564void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
565        os << "Compound Literal Expression: " << std::endl;
[3c13c03]566        os << std::string( indent+2, ' ' );
567        type->print( os, indent + 2 );
568        os << std::string( indent+2, ' ' );
569        initializer->print( os, indent + 2 );
[630a82a]570}
571
[b6fe7e6]572UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
573
574UntypedValofExpr::~UntypedValofExpr() { delete body; }
575
576void UntypedValofExpr::print( std::ostream &os, int indent ) const {
577        os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;
578        if ( get_body() != 0 )
579                get_body()->print( os, indent + 2 );
580}
581
[d9e2280]582RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
[3c13c03]583RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
[8688ce1]584void RangeExpr::print( std::ostream &os, int indent ) const {
[3c13c03]585        os << "Range Expression: ";
[8688ce1]586        low->print( os, indent );
587        os << " ... ";
588        high->print( os, indent );
589}
[3be261a]590
[6eb8948]591StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
592        assert( statements );
593        std::list< Statement * > & body = statements->get_kids();
594        if ( ! body.empty() ) {
595                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
[aa8f9df]596                        set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
[6eb8948]597                }
598        }
599}
[3c13c03]600StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {}
[6eb8948]601StmtExpr::~StmtExpr() {
602        delete statements;
603}
604void StmtExpr::print( std::ostream &os, int indent ) const {
[3c13c03]605        os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
[6eb8948]606        statements->print( os, indent+2 );
607}
608
[3c13c03]609
[bf32bb8]610long long UniqueExpr::count = 0;
[77971f6]611UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( new Expression* ), object( new ObjectDecl* ), id( idVal ) {
[bf32bb8]612        assert( count != -1 );
613        if ( id == -1 ) id = count++;
[3c13c03]614        set_expr( expr );
615        assert( expr );
[bf32bb8]616        if ( expr->get_result() ) {
617                set_result( expr->get_result()->clone() );
618        }
[77971f6]619        set_object( nullptr );
[3c13c03]620}
[77971f6]621UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( other.expr ), object( other.object ), id( other.id ) {
[3c13c03]622}
623UniqueExpr::~UniqueExpr() {
624        if ( expr.unique() ) {
625                delete *expr;
626        }
[77971f6]627        if ( object.unique() ) {
628                delete *object;
629        }
[3c13c03]630}
631void UniqueExpr::print( std::ostream &os, int indent ) const {
[bf32bb8]632        os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' );
[3c13c03]633        get_expr()->print( os, indent+2 );
[77971f6]634        if ( get_object() ) {
635                os << " with decl: ";
636                get_object()->printShort( os, indent+2 );
637        }
[3c13c03]638}
639
[3906301]640std::ostream & operator<<( std::ostream & out, const Expression * expr ) {
[baf7fee]641        expr->print( out );
642        return out;
643}
644
[0dd3a2f]645// Local Variables: //
646// tab-width: 4 //
647// mode: c++ //
648// compile-command: "make install" //
649// End: //
Note: See TracBrowser for help on using the repository browser.