source: src/SynTree/Expression.cc @ 81644e0

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 81644e0 was 487845d7, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Add aggregate qualifiers to MemberExpr? type [fixes #65]

  • Property mode set to 100644
File size: 22.9 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
[a5f0529]12// Last Modified On : Tue Jul 25 14:15:47 2017
13// Update Count     : 54
[0dd3a2f]14//
15
[ea6332d]16#include "SynTree/Expression.h"
17
18#include <cassert>                   // for assert, assertf
19#include <iostream>                  // for ostream, operator<<, basic_ostream
20#include <list>                      // for list, _List_iterator, list<>::co...
21
22#include "Common/utility.h"          // for maybeClone, cloneAll, deleteAll
23#include "Declaration.h"             // for ObjectDecl, DeclarationWithType
24#include "Expression.h"              // for Expression, ImplicitCopyCtorExpr
25#include "InitTweak/InitTweak.h"     // for getCallArg, getPointerBase
26#include "Initializer.h"             // for Designation, Initializer
27#include "Statement.h"               // for CompoundStmt, ExprStmt, Statement
28#include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
29#include "SynTree/Constant.h"        // for Constant
30#include "Type.h"                    // for Type, BasicType, Type::Qualifiers
31#include "TypeSubstitution.h"        // for TypeSubstitution
[51b7345]32
[b0440b7]33#include "GenPoly/Lvalue.h"
[51b7345]34
[68195a6]35void printInferParams( const InferredParams & inferParams, std::ostream &os, Indenter indent, int level ) {
36        if ( ! inferParams.empty() ) {
37                os << indent << "with inferred parameters " << level << ":" << std::endl;
38                for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
39                        os << indent+1;
40                        Declaration::declFromId( i->second.decl )->printShort( os, indent+1 );
41                        os << std::endl;
42                        printInferParams( *i->second.inferParams, os, indent+1, level+1 );
43                } // for
44        } // if
45}
46
[bf4b4cf]47Expression::Expression() : result( 0 ), env( 0 ) {}
[0dd3a2f]48
[df626eb]49Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ) {
[0dd3a2f]50}
51
52Expression::~Expression() {
53        delete env;
[906e24d]54        delete result;
[51b7345]55}
56
[50377a4]57void Expression::print( std::ostream &os, Indenter indent ) const {
[68195a6]58        printInferParams( inferParams, os, indent+1, 0 );
59
[0dd3a2f]60        if ( env ) {
[50377a4]61                os << std::endl << indent << "... with environment:" << std::endl;
62                env->print( os, indent+1 );
[0dd3a2f]63        } // if
[e04ef3a]64
65        if ( extension ) {
[50377a4]66                os << std::endl << indent << "... with extension:";
[e04ef3a]67        } // if
[51b7345]68}
69
[bf4b4cf]70ConstantExpr::ConstantExpr( Constant _c ) : Expression(), constant( _c ) {
[906e24d]71        set_result( constant.get_type()->clone() );
[51b7345]72}
73
[0dd3a2f]74ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
75}
[51b7345]76
77ConstantExpr::~ConstantExpr() {}
78
[50377a4]79void ConstantExpr::print( std::ostream &os, Indenter indent ) const {
[60089f4]80        os << "constant expression " ;
[cf0941d]81        constant.print( os );
[0dd3a2f]82        Expression::print( os, indent );
[51b7345]83}
84
[bf4b4cf]85VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) {
[db4ecc5]86        assert( var );
87        assert( var->get_type() );
[906e24d]88        Type * type = var->get_type()->clone();
[615a096]89        type->set_lvalue( true );
[3de176d]90
91        // xxx - doesn't quite work yet - get different alternatives with the same cost
92
93        // // enumerators are not lvalues
94        // if ( EnumInstType * inst = dynamic_cast< EnumInstType * >( var->get_type() ) ) {
95        //      assert( inst->baseEnum );
96        //      EnumDecl * decl = inst->baseEnum;
97        //      for ( Declaration * member : decl->members ) {
98        //              if ( member == _var ) {
99        //                      type->set_lvalue( false );
100        //              }
101        //      }
102        // }
103
[906e24d]104        set_result( type );
[51b7345]105}
106
[0dd3a2f]107VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
[51b7345]108}
109
[0dd3a2f]110VariableExpr::~VariableExpr() {
111        // don't delete the declaration, since it points somewhere else in the tree
[51b7345]112}
113
[8a6cf7e]114VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) {
115        VariableExpr * funcExpr = new VariableExpr( func );
116        funcExpr->set_result( new PointerType( Type::Qualifiers(), funcExpr->get_result() ) );
117        return funcExpr;
118}
119
[50377a4]120void VariableExpr::print( std::ostream &os, Indenter indent ) const {
[89231bc]121        os << "Variable Expression: ";
[50377a4]122        var->printShort(os, indent);
[0dd3a2f]123        Expression::print( os, indent );
[51b7345]124}
125
[bf4b4cf]126SizeofExpr::SizeofExpr( Expression *expr_ ) :
127                Expression(), expr(expr_), type(0), isType(false) {
[906e24d]128        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[51b7345]129}
130
[bf4b4cf]131SizeofExpr::SizeofExpr( Type *type_ ) :
132                Expression(), expr(0), type(type_), isType(true) {
[906e24d]133        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[51b7345]134}
135
[0dd3a2f]136SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
137        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
[51b7345]138}
139
[0dd3a2f]140SizeofExpr::~SizeofExpr() {
141        delete expr;
142        delete type;
[51b7345]143}
144
[50377a4]145void SizeofExpr::print( std::ostream &os, Indenter indent) const {
[89231bc]146        os << "Sizeof Expression on: ";
[50377a4]147        if (isType) type->print(os, indent+1);
148        else expr->print(os, indent+1);
[47534159]149        Expression::print( os, indent );
150}
151
[bf4b4cf]152AlignofExpr::AlignofExpr( Expression *expr_ ) :
153                Expression(), expr(expr_), type(0), isType(false) {
[906e24d]154        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[47534159]155}
156
[bf4b4cf]157AlignofExpr::AlignofExpr( Type *type_ ) :
158                Expression(), expr(0), type(type_), isType(true) {
[906e24d]159        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[47534159]160}
161
162AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
163        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
164}
165
166AlignofExpr::~AlignofExpr() {
167        delete expr;
168        delete type;
169}
170
[50377a4]171void AlignofExpr::print( std::ostream &os, Indenter indent) const {
[f19339e]172        os << "Alignof Expression on: ";
[50377a4]173        if (isType) type->print(os, indent+1);
174        else expr->print(os, indent+1);
[0dd3a2f]175        Expression::print( os, indent );
[51b7345]176}
177
[bf4b4cf]178UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type, const std::string &member ) :
179                Expression(), type(type), member(member) {
[50377a4]180        assert( type );
[906e24d]181        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[2a4b088]182}
183
184UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
185        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
186
187UntypedOffsetofExpr::~UntypedOffsetofExpr() {
188        delete type;
189}
190
[50377a4]191void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const {
192        os << "Untyped Offsetof Expression on member " << member << " of ";
193        type->print(os, indent+1);
[2a4b088]194        Expression::print( os, indent );
195}
196
[bf4b4cf]197OffsetofExpr::OffsetofExpr( Type *type, DeclarationWithType *member ) :
198                Expression(), type(type), member(member) {
[50377a4]199        assert( member );
200        assert( type );
[906e24d]201        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
[25a054f]202}
203
204OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
[79970ed]205        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
[25a054f]206
207OffsetofExpr::~OffsetofExpr() {
208        delete type;
209}
210
[50377a4]211void OffsetofExpr::print( std::ostream &os, Indenter indent) const {
212        os << "Offsetof Expression on member " << member->name << " of ";
213        type->print(os, indent+1);
[25a054f]214        Expression::print( os, indent );
215}
216
[bf4b4cf]217OffsetPackExpr::OffsetPackExpr( StructInstType *type ) : Expression(), type( type ) {
[50377a4]218        assert( type );
[906e24d]219        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
[afc1045]220}
221
222OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
223
224OffsetPackExpr::~OffsetPackExpr() { delete type; }
225
[50377a4]226void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const {
227        os << "Offset pack expression on ";
228        type->print(os, indent+1);
[25a054f]229        Expression::print( os, indent );
230}
231
[bf4b4cf]232AttrExpr::AttrExpr( Expression *attr, Expression *expr_ ) :
233                Expression(), attr( attr ), expr(expr_), type(0), isType(false) {
[51b7345]234}
235
[bf4b4cf]236AttrExpr::AttrExpr( Expression *attr, Type *type_ ) :
237                Expression(), attr( attr ), expr(0), type(type_), isType(true) {
[51b7345]238}
239
[0dd3a2f]240AttrExpr::AttrExpr( const AttrExpr &other ) :
241                Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
[51b7345]242}
243
[0dd3a2f]244AttrExpr::~AttrExpr() {
245        delete attr;
246        delete expr;
247        delete type;
[51b7345]248}
249
[50377a4]250void AttrExpr::print( std::ostream &os, Indenter indent) const {
[f19339e]251        os << "Attr ";
[50377a4]252        attr->print( os, indent+1);
[0dd3a2f]253        if ( isType || expr ) {
254                os << "applied to: ";
[50377a4]255                if (isType) type->print(os, indent+1);
256                else expr->print(os, indent+1);
[0dd3a2f]257        } // if
258        Expression::print( os, indent );
[51b7345]259}
260
[bf4b4cf]261CastExpr::CastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
[906e24d]262        set_result(toType);
[51b7345]263}
264
[bf4b4cf]265CastExpr::CastExpr( Expression *arg_ ) : Expression(), arg(arg_) {
[906e24d]266        set_result( new VoidType( Type::Qualifiers() ) );
[51b7345]267}
268
[0dd3a2f]269CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
[51b7345]270}
271
272CastExpr::~CastExpr() {
[0dd3a2f]273        delete arg;
[51b7345]274}
275
[50377a4]276void CastExpr::print( std::ostream &os, Indenter indent ) const {
277        os << "Cast of:" << std::endl << indent+1;
278        arg->print(os, indent+1);
279        os << std::endl << indent << "... to:";
[906e24d]280        if ( result->isVoid() ) {
[50377a4]281                os << " nothing";
[0dd3a2f]282        } else {
[50377a4]283                os << std::endl << indent+1;
284                result->print( os, indent+1 );
[0dd3a2f]285        } // if
286        Expression::print( os, indent );
287}
288
[a5f0529]289VirtualCastExpr::VirtualCastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
290        set_result(toType);
291}
292
293VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
294}
295
296VirtualCastExpr::~VirtualCastExpr() {
297        delete arg;
298}
299
[50377a4]300void VirtualCastExpr::print( std::ostream &os, Indenter indent ) const {
301        os << "Virtual Cast of:" << std::endl << indent+1;
302        arg->print(os, indent+1);
303        os << std::endl << indent << "... to:";
[a5f0529]304        if ( ! result ) {
[50377a4]305                os << " unknown";
[a5f0529]306        } else {
[50377a4]307                os << std::endl << indent+1;
308                result->print( os, indent+1 );
[a5f0529]309        } // if
310        Expression::print( os, indent );
311}
312
[bf4b4cf]313UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression *aggregate ) :
314                Expression(), member(member), aggregate(aggregate) {
[50377a4]315        assert( aggregate );
316}
[51b7345]317
[0dd3a2f]318UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
[3b58d91]319                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
[51b7345]320}
321
322UntypedMemberExpr::~UntypedMemberExpr() {
[0dd3a2f]323        delete aggregate;
[3b58d91]324        delete member;
[51b7345]325}
326
[50377a4]327void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const {
328        os << "Untyped Member Expression, with field: " << std::endl << indent+1;
329        member->print(os, indent+1 );
330        os << indent << "... from aggregate: " << std::endl << indent+1;
331        aggregate->print(os, indent+1);
[0dd3a2f]332        Expression::print( os, indent );
[51b7345]333}
334
[d9fa60a]335namespace {
336        TypeSubstitution makeSub( Type * t ) {
[0698aa1]337                if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( t ) ) {
338                        return makeSub( refType->get_base() );
339                } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
[98a249fb]340                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );
[d9fa60a]341                } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
[98a249fb]342                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );
[d9fa60a]343                } else {
[4b0f997]344                        assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() );
[d9fa60a]345                }
346        }
347}
348
[51b7345]349
[bf4b4cf]350MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) :
351                Expression(), member(member), aggregate(aggregate) {
[50377a4]352        assert( member );
353        assert( aggregate );
[d9fa60a]354
355        TypeSubstitution sub( makeSub( aggregate->get_result() ) );
356        Type * res = member->get_type()->clone();
357        sub.apply( res );
[487845d7]358        result = res;
359        result->set_lvalue( true );
360        result->get_qualifiers() |= aggregate->result->get_qualifiers();
[51b7345]361}
362
[0dd3a2f]363MemberExpr::MemberExpr( const MemberExpr &other ) :
[39f84a4]364                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
[51b7345]365}
366
367MemberExpr::~MemberExpr() {
[4551a6e]368        // don't delete the member declaration, since it points somewhere else in the tree
[0dd3a2f]369        delete aggregate;
[51b7345]370}
371
[50377a4]372void MemberExpr::print( std::ostream &os, Indenter indent ) const {
[89231bc]373        os << "Member Expression, with field: " << std::endl;
[50377a4]374        os << indent+1;
375        member->print( os, indent+1 );
376        os << std::endl << indent << "... from aggregate: " << std::endl << indent+1;
377        aggregate->print(os, indent + 1);
[0dd3a2f]378        Expression::print( os, indent );
[51b7345]379}
380
[bf4b4cf]381UntypedExpr::UntypedExpr( Expression *function, const std::list<Expression *> &args ) :
382                Expression(), function(function), args(args) {}
[51b7345]383
[0dd3a2f]384UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
385                Expression( other ), function( maybeClone( other.function ) ) {
386        cloneAll( other.args, args );
[51b7345]387}
388
[ac71a86]389UntypedExpr::~UntypedExpr() {
390        delete function;
[03b812d2]391        deleteAll( args );
[ac71a86]392}
[51b7345]393
[b3b2077]394UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
395        UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
396        if ( Type * type = expr->get_result() ) {
397                Type * base = InitTweak::getPointerBase( type );
[0698aa1]398                assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() );
[b0440b7]399                ret->set_result( base->clone() );
400                if ( GenPoly::referencesPermissable() ) {
401                        // if references are still allowed in the AST, dereference returns a reference
402                        ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) );
403                } else {
404                        // references have been removed, in which case dereference returns an lvalue of the base type.
405                        ret->get_result()->set_lvalue( true );
406                }
[b3b2077]407        }
408        return ret;
409}
410
411UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) {
412        assert( arg1 && arg2 );
413        UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } );
414        if ( arg1->get_result() && arg2->get_result() ) {
415                // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
416                // so the result is the type of the RHS
417                ret->set_result( arg2->get_result()->clone() );
418        }
419        return ret;
420}
421
422
[50377a4]423void UntypedExpr::print( std::ostream &os, Indenter indent ) const {
[89231bc]424        os << "Applying untyped: " << std::endl;
[50377a4]425        os << indent+1;
426        function->print(os, indent+1);
427        os << std::endl << indent << "...to: " << std::endl;
428        printAll(args, os, indent+1);
[0dd3a2f]429        Expression::print( os, indent );
[51b7345]430}
431
[bf4b4cf]432NameExpr::NameExpr( std::string name ) : Expression(), name(name) {
[50377a4]433        assertf(name != "0", "Zero is not a valid name");
434        assertf(name != "1", "One is not a valid name");
[4cb935e]435}
[51b7345]436
[0dd3a2f]437NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
[51b7345]438}
439
440NameExpr::~NameExpr() {}
441
[50377a4]442void NameExpr::print( std::ostream &os, Indenter indent ) const {
443        os << "Name: " << get_name();
[0dd3a2f]444        Expression::print( os, indent );
[51b7345]445}
446
[bf4b4cf]447LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp ) :
448                Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) {
[906e24d]449        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
[51b7345]450}
451
[0dd3a2f]452LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
453                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
[51b7345]454}
455
[a08ba92]456LogicalExpr::~LogicalExpr() {
[0dd3a2f]457        delete arg1;
458        delete arg2;
[51b7345]459}
460
[50377a4]461void LogicalExpr::print( std::ostream &os, Indenter indent )const {
462        os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: ";
[0dd3a2f]463        arg1->print(os);
464        os << " and ";
465        arg2->print(os);
466        Expression::print( os, indent );
[51b7345]467}
468
[bf4b4cf]469ConditionalExpr::ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ) :
470                Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {}
[51b7345]471
[0dd3a2f]472ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
473                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
474}
[51b7345]475
476ConditionalExpr::~ConditionalExpr() {
[0dd3a2f]477        delete arg1;
478        delete arg2;
479        delete arg3;
[51b7345]480}
481
[50377a4]482void ConditionalExpr::print( std::ostream &os, Indenter indent ) const {
483        os << "Conditional expression on: " << std::endl << indent+1;
484        arg1->print( os, indent+1 );
485        os << indent << "First alternative:" << std::endl << indent+1;
486        arg2->print( os, indent+1 );
487        os << indent << "Second alternative:" << std::endl << indent+1;
488        arg3->print( os, indent+1 );
[0dd3a2f]489        Expression::print( os, indent );
490}
491
[e6cee92]492AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
[3be261a]493
494
[50377a4]495void AsmExpr::print( std::ostream &os, Indenter indent ) const {
[7f5566b]496        os << "Asm Expression: " << std::endl;
[50377a4]497        if ( inout ) inout->print( os, indent+1 );
498        if ( constraint ) constraint->print( os, indent+1 );
499        if ( operand ) operand->print( os, indent+1 );
[7f5566b]500}
501
[db4ecc5]502
503ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
504        assert( callExpr );
[50377a4]505        assert( callExpr->result );
[906e24d]506        set_result( callExpr->get_result()->clone() );
[db4ecc5]507}
508
509ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
510        cloneAll( other.tempDecls, tempDecls );
511        cloneAll( other.returnDecls, returnDecls );
512        cloneAll( other.dtors, dtors );
513}
514
515ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
[d5556a3]516        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
[db4ecc5]517        delete callExpr;
518        deleteAll( tempDecls );
519        deleteAll( returnDecls );
520        deleteAll( dtors );
521}
522
[50377a4]523void ImplicitCopyCtorExpr::print( std::ostream &os, Indenter indent ) const {
524        os <<  "Implicit Copy Constructor Expression: " << std::endl << indent+1;
525        callExpr->print( os, indent+1 );
526        os << std::endl << indent << "... with temporaries:" << std::endl;
527        printAll( tempDecls, os, indent+1 );
528        os << std::endl << indent << "... with return temporaries:" << std::endl;
529        printAll( returnDecls, os, indent+1 );
[db4ecc5]530        Expression::print( os, indent );
531}
532
[3be261a]533
[b6fe7e6]534ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
535        // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
536        assert( callExpr );
537        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
538        assert( arg );
[50377a4]539        set_result( maybeClone( arg->result ) );
[b6fe7e6]540}
[3be261a]541
[b6fe7e6]542ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
543}
544
545ConstructorExpr::~ConstructorExpr() {
546        delete callExpr;
547}
548
[50377a4]549void ConstructorExpr::print( std::ostream &os, Indenter indent ) const {
550        os <<  "Constructor Expression: " << std::endl << indent+1;
[b6fe7e6]551        callExpr->print( os, indent + 2 );
552        Expression::print( os, indent );
[0dd3a2f]553}
554
[3be261a]555
[fbcde64]556CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
[3c13c03]557        assert( type && initializer );
[5ccb10d]558        type->set_lvalue( true );
[fbcde64]559        set_result( type );
[630a82a]560}
561
[fbcde64]562CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
[630a82a]563
564CompoundLiteralExpr::~CompoundLiteralExpr() {
565        delete initializer;
566}
567
[50377a4]568void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const {
569        os << "Compound Literal Expression: " << std::endl << indent+1;
570        result->print( os, indent+1 );
571        os << indent+1;
572        initializer->print( os, indent+1 );
[d5556a3]573        Expression::print( os, indent );
[630a82a]574}
575
[d9e2280]576RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
[3c13c03]577RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
[50377a4]578void RangeExpr::print( std::ostream &os, Indenter indent ) const {
[3c13c03]579        os << "Range Expression: ";
[8688ce1]580        low->print( os, indent );
581        os << " ... ";
582        high->print( os, indent );
[d5556a3]583        Expression::print( os, indent );
[8688ce1]584}
[3be261a]585
[6eb8948]586StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
587        assert( statements );
588        std::list< Statement * > & body = statements->get_kids();
589        if ( ! body.empty() ) {
590                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
[aa8f9df]591                        set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
[6eb8948]592                }
593        }
[07516b56]594        // ensure that StmtExpr has a result type
595        if ( ! result ) {
596                set_result( new VoidType( Type::Qualifiers() ) );
597        }
[6eb8948]598}
[d5556a3]599StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
600        cloneAll( other.returnDecls, returnDecls );
601        cloneAll( other.dtors, dtors );
602}
[6eb8948]603StmtExpr::~StmtExpr() {
604        delete statements;
[d5556a3]605        deleteAll( dtors );
606        deleteAll( returnDecls );
[6eb8948]607}
[50377a4]608void StmtExpr::print( std::ostream &os, Indenter indent ) const {
609        os << "Statement Expression: " << std::endl << indent+1;
610        statements->print( os, indent+1 );
[d5556a3]611        if ( ! returnDecls.empty() ) {
[50377a4]612                os << indent+1 << "... with returnDecls: ";
613                printAll( returnDecls, os, indent+1 );
[d5556a3]614        }
615        if ( ! dtors.empty() ) {
[50377a4]616                os << indent+1 << "... with dtors: ";
617                printAll( dtors, os, indent+1 );
[d5556a3]618        }
619        Expression::print( os, indent );
[6eb8948]620}
621
[3c13c03]622
[bf32bb8]623long long UniqueExpr::count = 0;
[141b786]624UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
625        assert( expr );
[bf32bb8]626        assert( count != -1 );
627        if ( id == -1 ) id = count++;
628        if ( expr->get_result() ) {
629                set_result( expr->get_result()->clone() );
630        }
[3c13c03]631}
[141b786]632UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
[3c13c03]633}
634UniqueExpr::~UniqueExpr() {
[141b786]635        delete expr;
636        delete object;
637        delete var;
[3c13c03]638}
[50377a4]639void UniqueExpr::print( std::ostream &os, Indenter indent ) const {
640        os << "Unique Expression with id:" << id << std::endl << indent+1;
641        expr->print( os, indent+1 );
642        if ( object ) {
643                os << indent << "... with decl: ";
644                get_object()->printShort( os, indent+1 );
[77971f6]645        }
[d5556a3]646        Expression::print( os, indent );
[3c13c03]647}
648
[e4d829b]649InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
650InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
651InitAlternative::~InitAlternative() {
652        delete type;
653        delete designation;
654}
655
656UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
657UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
658UntypedInitExpr::~UntypedInitExpr() {
659        delete expr;
660}
661
[50377a4]662void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const {
663        os << "Untyped Init Expression" << std::endl << indent+1;
664        expr->print( os, indent+1 );
[e4d829b]665        if ( ! initAlts.empty() ) {
666                for ( const InitAlternative & alt : initAlts ) {
[50377a4]667                        os << indent+1 <<  "InitAlternative: ";
668                        alt.type->print( os, indent+1 );
669                        alt.designation->print( os, indent+1 );
[e4d829b]670                }
671        }
672}
673
[62423350]674InitExpr::InitExpr( Expression * expr, Designation * designation ) : expr( expr ), designation( designation ) {
675        set_result( expr->get_result()->clone() );
[e4d829b]676}
677InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
678InitExpr::~InitExpr() {
679        delete expr;
680        delete designation;
681}
682
[50377a4]683void InitExpr::print( std::ostream & os, Indenter indent ) const {
684        os << "Init Expression" << std::endl << indent+1;
685        expr->print( os, indent+1 );
686        os << indent+1 << "... with designation: ";
687        designation->print( os, indent+1 );
[e4d829b]688}
689
[0dd3a2f]690// Local Variables: //
691// tab-width: 4 //
692// mode: c++ //
693// compile-command: "make install" //
694// End: //
Note: See TracBrowser for help on using the repository browser.