source: src/SynTree/Expression.cc @ 3de176d

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

Add outline for stopping enumerators from being lvalues

  • Property mode set to 100644
File size: 22.8 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        set_result( res );
359        get_result()->set_lvalue( true );
360}
361
362MemberExpr::MemberExpr( const MemberExpr &other ) :
363                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
364}
365
366MemberExpr::~MemberExpr() {
367        // don't delete the member declaration, since it points somewhere else in the tree
368        delete aggregate;
369}
370
371void MemberExpr::print( std::ostream &os, Indenter indent ) const {
372        os << "Member Expression, with field: " << std::endl;
373        os << indent+1;
374        member->print( os, indent+1 );
375        os << std::endl << indent << "... from aggregate: " << std::endl << indent+1;
376        aggregate->print(os, indent + 1);
377        Expression::print( os, indent );
378}
379
380UntypedExpr::UntypedExpr( Expression *function, const std::list<Expression *> &args ) :
381                Expression(), function(function), args(args) {}
382
383UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
384                Expression( other ), function( maybeClone( other.function ) ) {
385        cloneAll( other.args, args );
386}
387
388UntypedExpr::~UntypedExpr() {
389        delete function;
390        deleteAll( args );
391}
392
393UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
394        UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
395        if ( Type * type = expr->get_result() ) {
396                Type * base = InitTweak::getPointerBase( type );
397                assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() );
398                ret->set_result( base->clone() );
399                if ( GenPoly::referencesPermissable() ) {
400                        // if references are still allowed in the AST, dereference returns a reference
401                        ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) );
402                } else {
403                        // references have been removed, in which case dereference returns an lvalue of the base type.
404                        ret->get_result()->set_lvalue( true );
405                }
406        }
407        return ret;
408}
409
410UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) {
411        assert( arg1 && arg2 );
412        UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } );
413        if ( arg1->get_result() && arg2->get_result() ) {
414                // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
415                // so the result is the type of the RHS
416                ret->set_result( arg2->get_result()->clone() );
417        }
418        return ret;
419}
420
421
422void UntypedExpr::print( std::ostream &os, Indenter indent ) const {
423        os << "Applying untyped: " << std::endl;
424        os << indent+1;
425        function->print(os, indent+1);
426        os << std::endl << indent << "...to: " << std::endl;
427        printAll(args, os, indent+1);
428        Expression::print( os, indent );
429}
430
431NameExpr::NameExpr( std::string name ) : Expression(), name(name) {
432        assertf(name != "0", "Zero is not a valid name");
433        assertf(name != "1", "One is not a valid name");
434}
435
436NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
437}
438
439NameExpr::~NameExpr() {}
440
441void NameExpr::print( std::ostream &os, Indenter indent ) const {
442        os << "Name: " << get_name();
443        Expression::print( os, indent );
444}
445
446LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp ) :
447                Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) {
448        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
449}
450
451LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
452                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
453}
454
455LogicalExpr::~LogicalExpr() {
456        delete arg1;
457        delete arg2;
458}
459
460void LogicalExpr::print( std::ostream &os, Indenter indent )const {
461        os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: ";
462        arg1->print(os);
463        os << " and ";
464        arg2->print(os);
465        Expression::print( os, indent );
466}
467
468ConditionalExpr::ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ) :
469                Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {}
470
471ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
472                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
473}
474
475ConditionalExpr::~ConditionalExpr() {
476        delete arg1;
477        delete arg2;
478        delete arg3;
479}
480
481void ConditionalExpr::print( std::ostream &os, Indenter indent ) const {
482        os << "Conditional expression on: " << std::endl << indent+1;
483        arg1->print( os, indent+1 );
484        os << indent << "First alternative:" << std::endl << indent+1;
485        arg2->print( os, indent+1 );
486        os << indent << "Second alternative:" << std::endl << indent+1;
487        arg3->print( os, indent+1 );
488        Expression::print( os, indent );
489}
490
491AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
492
493
494void AsmExpr::print( std::ostream &os, Indenter indent ) const {
495        os << "Asm Expression: " << std::endl;
496        if ( inout ) inout->print( os, indent+1 );
497        if ( constraint ) constraint->print( os, indent+1 );
498        if ( operand ) operand->print( os, indent+1 );
499}
500
501
502ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
503        assert( callExpr );
504        assert( callExpr->result );
505        set_result( callExpr->get_result()->clone() );
506}
507
508ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
509        cloneAll( other.tempDecls, tempDecls );
510        cloneAll( other.returnDecls, returnDecls );
511        cloneAll( other.dtors, dtors );
512}
513
514ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
515        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
516        delete callExpr;
517        deleteAll( tempDecls );
518        deleteAll( returnDecls );
519        deleteAll( dtors );
520}
521
522void ImplicitCopyCtorExpr::print( std::ostream &os, Indenter indent ) const {
523        os <<  "Implicit Copy Constructor Expression: " << std::endl << indent+1;
524        callExpr->print( os, indent+1 );
525        os << std::endl << indent << "... with temporaries:" << std::endl;
526        printAll( tempDecls, os, indent+1 );
527        os << std::endl << indent << "... with return temporaries:" << std::endl;
528        printAll( returnDecls, os, indent+1 );
529        Expression::print( os, indent );
530}
531
532
533ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
534        // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
535        assert( callExpr );
536        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
537        assert( arg );
538        set_result( maybeClone( arg->result ) );
539}
540
541ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
542}
543
544ConstructorExpr::~ConstructorExpr() {
545        delete callExpr;
546}
547
548void ConstructorExpr::print( std::ostream &os, Indenter indent ) const {
549        os <<  "Constructor Expression: " << std::endl << indent+1;
550        callExpr->print( os, indent + 2 );
551        Expression::print( os, indent );
552}
553
554
555CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
556        assert( type && initializer );
557        type->set_lvalue( true );
558        set_result( type );
559}
560
561CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
562
563CompoundLiteralExpr::~CompoundLiteralExpr() {
564        delete initializer;
565}
566
567void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const {
568        os << "Compound Literal Expression: " << std::endl << indent+1;
569        result->print( os, indent+1 );
570        os << indent+1;
571        initializer->print( os, indent+1 );
572        Expression::print( os, indent );
573}
574
575RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
576RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
577void RangeExpr::print( std::ostream &os, Indenter indent ) const {
578        os << "Range Expression: ";
579        low->print( os, indent );
580        os << " ... ";
581        high->print( os, indent );
582        Expression::print( os, indent );
583}
584
585StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
586        assert( statements );
587        std::list< Statement * > & body = statements->get_kids();
588        if ( ! body.empty() ) {
589                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
590                        set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
591                }
592        }
593        // ensure that StmtExpr has a result type
594        if ( ! result ) {
595                set_result( new VoidType( Type::Qualifiers() ) );
596        }
597}
598StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
599        cloneAll( other.returnDecls, returnDecls );
600        cloneAll( other.dtors, dtors );
601}
602StmtExpr::~StmtExpr() {
603        delete statements;
604        deleteAll( dtors );
605        deleteAll( returnDecls );
606}
607void StmtExpr::print( std::ostream &os, Indenter indent ) const {
608        os << "Statement Expression: " << std::endl << indent+1;
609        statements->print( os, indent+1 );
610        if ( ! returnDecls.empty() ) {
611                os << indent+1 << "... with returnDecls: ";
612                printAll( returnDecls, os, indent+1 );
613        }
614        if ( ! dtors.empty() ) {
615                os << indent+1 << "... with dtors: ";
616                printAll( dtors, os, indent+1 );
617        }
618        Expression::print( os, indent );
619}
620
621
622long long UniqueExpr::count = 0;
623UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
624        assert( expr );
625        assert( count != -1 );
626        if ( id == -1 ) id = count++;
627        if ( expr->get_result() ) {
628                set_result( expr->get_result()->clone() );
629        }
630}
631UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
632}
633UniqueExpr::~UniqueExpr() {
634        delete expr;
635        delete object;
636        delete var;
637}
638void UniqueExpr::print( std::ostream &os, Indenter indent ) const {
639        os << "Unique Expression with id:" << id << std::endl << indent+1;
640        expr->print( os, indent+1 );
641        if ( object ) {
642                os << indent << "... with decl: ";
643                get_object()->printShort( os, indent+1 );
644        }
645        Expression::print( os, indent );
646}
647
648InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
649InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
650InitAlternative::~InitAlternative() {
651        delete type;
652        delete designation;
653}
654
655UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
656UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
657UntypedInitExpr::~UntypedInitExpr() {
658        delete expr;
659}
660
661void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const {
662        os << "Untyped Init Expression" << std::endl << indent+1;
663        expr->print( os, indent+1 );
664        if ( ! initAlts.empty() ) {
665                for ( const InitAlternative & alt : initAlts ) {
666                        os << indent+1 <<  "InitAlternative: ";
667                        alt.type->print( os, indent+1 );
668                        alt.designation->print( os, indent+1 );
669                }
670        }
671}
672
673InitExpr::InitExpr( Expression * expr, Designation * designation ) : expr( expr ), designation( designation ) {
674        set_result( expr->get_result()->clone() );
675}
676InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
677InitExpr::~InitExpr() {
678        delete expr;
679        delete designation;
680}
681
682void InitExpr::print( std::ostream & os, Indenter indent ) const {
683        os << "Init Expression" << std::endl << indent+1;
684        expr->print( os, indent+1 );
685        os << indent+1 << "... with designation: ";
686        designation->print( os, indent+1 );
687}
688
689// Local Variables: //
690// tab-width: 4 //
691// mode: c++ //
692// compile-command: "make install" //
693// End: //
Note: See TracBrowser for help on using the repository browser.