source: src/SynTree/Expression.cc @ 487845d7

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

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

  • Property mode set to 100644
File size: 22.9 KB
Line 
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//
7// Expression.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Jul 25 14:15:47 2017
13// Update Count     : 54
14//
15
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
32
33#include "GenPoly/Lvalue.h"
34
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
47Expression::Expression() : result( 0 ), env( 0 ) {}
48
49Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ) {
50}
51
52Expression::~Expression() {
53        delete env;
54        delete result;
55}
56
57void Expression::print( std::ostream &os, Indenter indent ) const {
58        printInferParams( inferParams, os, indent+1, 0 );
59
60        if ( env ) {
61                os << std::endl << indent << "... with environment:" << std::endl;
62                env->print( os, indent+1 );
63        } // if
64
65        if ( extension ) {
66                os << std::endl << indent << "... with extension:";
67        } // if
68}
69
70ConstantExpr::ConstantExpr( Constant _c ) : Expression(), constant( _c ) {
71        set_result( constant.get_type()->clone() );
72}
73
74ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
75}
76
77ConstantExpr::~ConstantExpr() {}
78
79void ConstantExpr::print( std::ostream &os, Indenter indent ) const {
80        os << "constant expression " ;
81        constant.print( os );
82        Expression::print( os, indent );
83}
84
85VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) {
86        assert( var );
87        assert( var->get_type() );
88        Type * type = var->get_type()->clone();
89        type->set_lvalue( true );
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
104        set_result( type );
105}
106
107VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
108}
109
110VariableExpr::~VariableExpr() {
111        // don't delete the declaration, since it points somewhere else in the tree
112}
113
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
120void VariableExpr::print( std::ostream &os, Indenter indent ) const {
121        os << "Variable Expression: ";
122        var->printShort(os, indent);
123        Expression::print( os, indent );
124}
125
126SizeofExpr::SizeofExpr( Expression *expr_ ) :
127                Expression(), expr(expr_), type(0), isType(false) {
128        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
129}
130
131SizeofExpr::SizeofExpr( Type *type_ ) :
132                Expression(), expr(0), type(type_), isType(true) {
133        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
134}
135
136SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
137        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
138}
139
140SizeofExpr::~SizeofExpr() {
141        delete expr;
142        delete type;
143}
144
145void SizeofExpr::print( std::ostream &os, Indenter indent) const {
146        os << "Sizeof Expression on: ";
147        if (isType) type->print(os, indent+1);
148        else expr->print(os, indent+1);
149        Expression::print( os, indent );
150}
151
152AlignofExpr::AlignofExpr( Expression *expr_ ) :
153                Expression(), expr(expr_), type(0), isType(false) {
154        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
155}
156
157AlignofExpr::AlignofExpr( Type *type_ ) :
158                Expression(), expr(0), type(type_), isType(true) {
159        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
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
171void AlignofExpr::print( std::ostream &os, Indenter indent) const {
172        os << "Alignof Expression on: ";
173        if (isType) type->print(os, indent+1);
174        else expr->print(os, indent+1);
175        Expression::print( os, indent );
176}
177
178UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type, const std::string &member ) :
179                Expression(), type(type), member(member) {
180        assert( type );
181        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
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
191void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const {
192        os << "Untyped Offsetof Expression on member " << member << " of ";
193        type->print(os, indent+1);
194        Expression::print( os, indent );
195}
196
197OffsetofExpr::OffsetofExpr( Type *type, DeclarationWithType *member ) :
198                Expression(), type(type), member(member) {
199        assert( member );
200        assert( type );
201        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
202}
203
204OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
205        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
206
207OffsetofExpr::~OffsetofExpr() {
208        delete type;
209}
210
211void OffsetofExpr::print( std::ostream &os, Indenter indent) const {
212        os << "Offsetof Expression on member " << member->name << " of ";
213        type->print(os, indent+1);
214        Expression::print( os, indent );
215}
216
217OffsetPackExpr::OffsetPackExpr( StructInstType *type ) : Expression(), type( type ) {
218        assert( type );
219        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
220}
221
222OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
223
224OffsetPackExpr::~OffsetPackExpr() { delete type; }
225
226void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const {
227        os << "Offset pack expression on ";
228        type->print(os, indent+1);
229        Expression::print( os, indent );
230}
231
232AttrExpr::AttrExpr( Expression *attr, Expression *expr_ ) :
233                Expression(), attr( attr ), expr(expr_), type(0), isType(false) {
234}
235
236AttrExpr::AttrExpr( Expression *attr, Type *type_ ) :
237                Expression(), attr( attr ), expr(0), type(type_), isType(true) {
238}
239
240AttrExpr::AttrExpr( const AttrExpr &other ) :
241                Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
242}
243
244AttrExpr::~AttrExpr() {
245        delete attr;
246        delete expr;
247        delete type;
248}
249
250void AttrExpr::print( std::ostream &os, Indenter indent) const {
251        os << "Attr ";
252        attr->print( os, indent+1);
253        if ( isType || expr ) {
254                os << "applied to: ";
255                if (isType) type->print(os, indent+1);
256                else expr->print(os, indent+1);
257        } // if
258        Expression::print( os, indent );
259}
260
261CastExpr::CastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
262        set_result(toType);
263}
264
265CastExpr::CastExpr( Expression *arg_ ) : Expression(), arg(arg_) {
266        set_result( new VoidType( Type::Qualifiers() ) );
267}
268
269CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
270}
271
272CastExpr::~CastExpr() {
273        delete arg;
274}
275
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:";
280        if ( result->isVoid() ) {
281                os << " nothing";
282        } else {
283                os << std::endl << indent+1;
284                result->print( os, indent+1 );
285        } // if
286        Expression::print( os, indent );
287}
288
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
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:";
304        if ( ! result ) {
305                os << " unknown";
306        } else {
307                os << std::endl << indent+1;
308                result->print( os, indent+1 );
309        } // if
310        Expression::print( os, indent );
311}
312
313UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression *aggregate ) :
314                Expression(), member(member), aggregate(aggregate) {
315        assert( aggregate );
316}
317
318UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
319                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
320}
321
322UntypedMemberExpr::~UntypedMemberExpr() {
323        delete aggregate;
324        delete member;
325}
326
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);
332        Expression::print( os, indent );
333}
334
335namespace {
336        TypeSubstitution makeSub( Type * t ) {
337                if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( t ) ) {
338                        return makeSub( refType->get_base() );
339                } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
340                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );
341                } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
342                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );
343                } else {
344                        assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() );
345                }
346        }
347}
348
349
350MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) :
351                Expression(), member(member), aggregate(aggregate) {
352        assert( member );
353        assert( aggregate );
354
355        TypeSubstitution sub( makeSub( aggregate->get_result() ) );
356        Type * res = member->get_type()->clone();
357        sub.apply( res );
358        result = res;
359        result->set_lvalue( true );
360        result->get_qualifiers() |= aggregate->result->get_qualifiers();
361}
362
363MemberExpr::MemberExpr( const MemberExpr &other ) :
364                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
365}
366
367MemberExpr::~MemberExpr() {
368        // don't delete the member declaration, since it points somewhere else in the tree
369        delete aggregate;
370}
371
372void MemberExpr::print( std::ostream &os, Indenter indent ) const {
373        os << "Member Expression, with field: " << std::endl;
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);
378        Expression::print( os, indent );
379}
380
381UntypedExpr::UntypedExpr( Expression *function, const std::list<Expression *> &args ) :
382                Expression(), function(function), args(args) {}
383
384UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
385                Expression( other ), function( maybeClone( other.function ) ) {
386        cloneAll( other.args, args );
387}
388
389UntypedExpr::~UntypedExpr() {
390        delete function;
391        deleteAll( args );
392}
393
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 );
398                assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() );
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                }
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
423void UntypedExpr::print( std::ostream &os, Indenter indent ) const {
424        os << "Applying untyped: " << std::endl;
425        os << indent+1;
426        function->print(os, indent+1);
427        os << std::endl << indent << "...to: " << std::endl;
428        printAll(args, os, indent+1);
429        Expression::print( os, indent );
430}
431
432NameExpr::NameExpr( std::string name ) : Expression(), name(name) {
433        assertf(name != "0", "Zero is not a valid name");
434        assertf(name != "1", "One is not a valid name");
435}
436
437NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
438}
439
440NameExpr::~NameExpr() {}
441
442void NameExpr::print( std::ostream &os, Indenter indent ) const {
443        os << "Name: " << get_name();
444        Expression::print( os, indent );
445}
446
447LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp ) :
448                Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) {
449        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
450}
451
452LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
453                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
454}
455
456LogicalExpr::~LogicalExpr() {
457        delete arg1;
458        delete arg2;
459}
460
461void LogicalExpr::print( std::ostream &os, Indenter indent )const {
462        os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: ";
463        arg1->print(os);
464        os << " and ";
465        arg2->print(os);
466        Expression::print( os, indent );
467}
468
469ConditionalExpr::ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ) :
470                Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {}
471
472ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
473                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
474}
475
476ConditionalExpr::~ConditionalExpr() {
477        delete arg1;
478        delete arg2;
479        delete arg3;
480}
481
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 );
489        Expression::print( os, indent );
490}
491
492AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
493
494
495void AsmExpr::print( std::ostream &os, Indenter indent ) const {
496        os << "Asm Expression: " << std::endl;
497        if ( inout ) inout->print( os, indent+1 );
498        if ( constraint ) constraint->print( os, indent+1 );
499        if ( operand ) operand->print( os, indent+1 );
500}
501
502
503ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
504        assert( callExpr );
505        assert( callExpr->result );
506        set_result( callExpr->get_result()->clone() );
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() {
516        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
517        delete callExpr;
518        deleteAll( tempDecls );
519        deleteAll( returnDecls );
520        deleteAll( dtors );
521}
522
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 );
530        Expression::print( os, indent );
531}
532
533
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 );
539        set_result( maybeClone( arg->result ) );
540}
541
542ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
543}
544
545ConstructorExpr::~ConstructorExpr() {
546        delete callExpr;
547}
548
549void ConstructorExpr::print( std::ostream &os, Indenter indent ) const {
550        os <<  "Constructor Expression: " << std::endl << indent+1;
551        callExpr->print( os, indent + 2 );
552        Expression::print( os, indent );
553}
554
555
556CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
557        assert( type && initializer );
558        type->set_lvalue( true );
559        set_result( type );
560}
561
562CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
563
564CompoundLiteralExpr::~CompoundLiteralExpr() {
565        delete initializer;
566}
567
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 );
573        Expression::print( os, indent );
574}
575
576RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
577RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
578void RangeExpr::print( std::ostream &os, Indenter indent ) const {
579        os << "Range Expression: ";
580        low->print( os, indent );
581        os << " ... ";
582        high->print( os, indent );
583        Expression::print( os, indent );
584}
585
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() ) ) {
591                        set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
592                }
593        }
594        // ensure that StmtExpr has a result type
595        if ( ! result ) {
596                set_result( new VoidType( Type::Qualifiers() ) );
597        }
598}
599StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
600        cloneAll( other.returnDecls, returnDecls );
601        cloneAll( other.dtors, dtors );
602}
603StmtExpr::~StmtExpr() {
604        delete statements;
605        deleteAll( dtors );
606        deleteAll( returnDecls );
607}
608void StmtExpr::print( std::ostream &os, Indenter indent ) const {
609        os << "Statement Expression: " << std::endl << indent+1;
610        statements->print( os, indent+1 );
611        if ( ! returnDecls.empty() ) {
612                os << indent+1 << "... with returnDecls: ";
613                printAll( returnDecls, os, indent+1 );
614        }
615        if ( ! dtors.empty() ) {
616                os << indent+1 << "... with dtors: ";
617                printAll( dtors, os, indent+1 );
618        }
619        Expression::print( os, indent );
620}
621
622
623long long UniqueExpr::count = 0;
624UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
625        assert( expr );
626        assert( count != -1 );
627        if ( id == -1 ) id = count++;
628        if ( expr->get_result() ) {
629                set_result( expr->get_result()->clone() );
630        }
631}
632UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
633}
634UniqueExpr::~UniqueExpr() {
635        delete expr;
636        delete object;
637        delete var;
638}
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 );
645        }
646        Expression::print( os, indent );
647}
648
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
662void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const {
663        os << "Untyped Init Expression" << std::endl << indent+1;
664        expr->print( os, indent+1 );
665        if ( ! initAlts.empty() ) {
666                for ( const InitAlternative & alt : initAlts ) {
667                        os << indent+1 <<  "InitAlternative: ";
668                        alt.type->print( os, indent+1 );
669                        alt.designation->print( os, indent+1 );
670                }
671        }
672}
673
674InitExpr::InitExpr( Expression * expr, Designation * designation ) : expr( expr ), designation( designation ) {
675        set_result( expr->get_result()->clone() );
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
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 );
688}
689
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.