source: src/SynTree/Expression.cc @ e6cee92

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

Fix TupleAssignment? code for references

  • Property mode set to 100644
File size: 22.5 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 : Thu Mar 30 16:41:13 2017
13// Update Count     : 52
14//
15
16#include <iostream>
17#include <cassert>
18#include <list>
19#include <algorithm>
20
21#include <iterator>
22
23#include "Declaration.h"
24#include "Expression.h"
25#include "Initializer.h"
26#include "Statement.h"
27#include "Type.h"
28#include "TypeSubstitution.h"
29#include "VarExprReplacer.h"
30
31#include "Common/utility.h"
32#include "Common/PassVisitor.h"
33
34#include "InitTweak/InitTweak.h"
35
36
37Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
38
39Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
40}
41
42Expression::~Expression() {
43        delete env;
44        delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
45        delete result;
46}
47
48void Expression::print( std::ostream &os, int indent ) const {
49        if ( env ) {
50                os << std::string( indent, ' ' ) << "with environment:" << std::endl;
51                env->print( os, indent+2 );
52        } // if
53
54        if ( argName ) {
55                os << std::string( indent, ' ' ) << "with designator:";
56                argName->print( os, indent+2 );
57        } // if
58
59        if ( extension ) {
60                os << std::string( indent, ' ' ) << "with extension:";
61        } // if
62}
63
64ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
65        set_result( constant.get_type()->clone() );
66}
67
68ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
69}
70
71ConstantExpr::~ConstantExpr() {}
72
73void ConstantExpr::print( std::ostream &os, int indent ) const {
74        os << "constant expression " ;
75        constant.print( os );
76        Expression::print( os, indent );
77}
78
79VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) {
80        assert( var );
81        assert( var->get_type() );
82        Type * type = var->get_type()->clone();
83        type->set_lvalue( true );
84        set_result( type );
85}
86
87VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
88}
89
90VariableExpr::~VariableExpr() {
91        // don't delete the declaration, since it points somewhere else in the tree
92}
93
94void VariableExpr::print( std::ostream &os, int indent ) const {
95        os << "Variable Expression: ";
96
97        Declaration *decl = get_var();
98        if ( decl != 0) decl->printShort(os, indent + 2);
99        os << std::endl;
100        Expression::print( os, indent );
101}
102
103SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
104                Expression( _aname ), expr(expr_), type(0), isType(false) {
105        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
106}
107
108SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
109                Expression( _aname ), expr(0), type(type_), isType(true) {
110        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
111}
112
113SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
114        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
115}
116
117SizeofExpr::~SizeofExpr() {
118        delete expr;
119        delete type;
120}
121
122void SizeofExpr::print( std::ostream &os, int indent) const {
123        os << "Sizeof Expression on: ";
124
125        if (isType)
126                type->print(os, indent + 2);
127        else
128                expr->print(os, indent + 2);
129
130        os << std::endl;
131        Expression::print( os, indent );
132}
133
134AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
135                Expression( _aname ), expr(expr_), type(0), isType(false) {
136        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
137}
138
139AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
140                Expression( _aname ), expr(0), type(type_), isType(true) {
141        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
142}
143
144AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
145        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
146}
147
148AlignofExpr::~AlignofExpr() {
149        delete expr;
150        delete type;
151}
152
153void AlignofExpr::print( std::ostream &os, int indent) const {
154        os << std::string( indent, ' ' ) << "Alignof Expression on: ";
155
156        if (isType)
157                type->print(os, indent + 2);
158        else
159                expr->print(os, indent + 2);
160
161        os << std::endl;
162        Expression::print( os, indent );
163}
164
165UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
166                Expression( _aname ), type(type_), member(member_) {
167        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
168}
169
170UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
171        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
172
173UntypedOffsetofExpr::~UntypedOffsetofExpr() {
174        delete type;
175}
176
177void UntypedOffsetofExpr::print( std::ostream &os, int indent) const {
178        os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of ";
179
180        if ( type ) {
181                type->print(os, indent + 2);
182        } else {
183                os << "<NULL>";
184        }
185
186        os << std::endl;
187        Expression::print( os, indent );
188}
189
190OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
191                Expression( _aname ), type(type_), member(member_) {
192        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
193}
194
195OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
196        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
197
198OffsetofExpr::~OffsetofExpr() {
199        delete type;
200}
201
202void OffsetofExpr::print( std::ostream &os, int indent) const {
203        os << std::string( indent, ' ' ) << "Offsetof Expression on member ";
204
205        if ( member ) {
206                os << member->get_name();
207        } else {
208                os << "<NULL>";
209        }
210
211        os << " of ";
212
213        if ( type ) {
214                type->print(os, indent + 2);
215        } else {
216                os << "<NULL>";
217        }
218
219        os << std::endl;
220        Expression::print( os, indent );
221}
222
223OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
224        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
225}
226
227OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
228
229OffsetPackExpr::~OffsetPackExpr() { delete type; }
230
231void OffsetPackExpr::print( std::ostream &os, int indent ) const {
232        os << std::string( indent, ' ' ) << "Offset pack expression on ";
233
234        if ( type ) {
235                type->print(os, indent + 2);
236        } else {
237                os << "<NULL>";
238        }
239
240        os << std::endl;
241        Expression::print( os, indent );
242}
243
244AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
245                Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
246}
247
248AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
249                Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
250}
251
252AttrExpr::AttrExpr( const AttrExpr &other ) :
253                Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
254}
255
256AttrExpr::~AttrExpr() {
257        delete attr;
258        delete expr;
259        delete type;
260}
261
262void AttrExpr::print( std::ostream &os, int indent) const {
263        os << std::string( indent, ' ' ) << "Attr ";
264        attr->print( os, indent + 2 );
265        if ( isType || expr ) {
266                os << "applied to: ";
267
268                if (isType)
269                        type->print(os, indent + 2);
270                else
271                        expr->print(os, indent + 2);
272        } // if
273
274        os << std::endl;
275        Expression::print( os, indent );
276}
277
278CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
279        set_result(toType);
280}
281
282CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
283        set_result( new VoidType( Type::Qualifiers() ) );
284}
285
286CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
287}
288
289CastExpr::~CastExpr() {
290        delete arg;
291}
292
293void CastExpr::print( std::ostream &os, int indent ) const {
294        os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
295        arg->print(os, indent+2);
296        os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
297        os << std::string( indent+2, ' ' );
298        if ( result->isVoid() ) {
299                os << "nothing";
300        } else {
301                result->print( os, indent+2 );
302        } // if
303        os << std::endl;
304        Expression::print( os, indent );
305}
306
307UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
308                Expression( _aname ), member(_member), aggregate(_aggregate) {}
309
310UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
311                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
312}
313
314UntypedMemberExpr::~UntypedMemberExpr() {
315        delete aggregate;
316        delete member;
317}
318
319void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
320        os << "Untyped Member Expression, with field: " << std::endl;
321        os << std::string( indent+2, ' ' );
322        get_member()->print(os, indent+4);
323        os << std::string( indent+2, ' ' );
324
325        Expression *agg = get_aggregate();
326        os << "from aggregate: " << std::endl;
327        if (agg != 0) {
328                os << std::string( indent + 4, ' ' );
329                agg->print(os, indent + 4);
330        }
331        os << std::string( indent+2, ' ' );
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->get_parameters().begin() );
341                } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
342                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_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, Expression *_aname ) :
351                Expression( _aname ), member(_member), aggregate(_aggregate) {
352
353        TypeSubstitution sub( makeSub( aggregate->get_result() ) );
354        Type * res = member->get_type()->clone();
355        sub.apply( res );
356        set_result( res );
357        get_result()->set_lvalue( true );
358}
359
360MemberExpr::MemberExpr( const MemberExpr &other ) :
361                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
362}
363
364MemberExpr::~MemberExpr() {
365        // don't delete the member declaration, since it points somewhere else in the tree
366        delete aggregate;
367}
368
369void MemberExpr::print( std::ostream &os, int indent ) const {
370        os << "Member Expression, with field: " << std::endl;
371
372        assert( member );
373        os << std::string( indent + 2, ' ' );
374        member->print( os, indent + 2 );
375        os << std::endl;
376
377        Expression *agg = get_aggregate();
378        os << std::string( indent, ' ' ) << "from aggregate: " << std::endl;
379        if (agg != 0) {
380                os << std::string( indent + 2, ' ' );
381                agg->print(os, indent + 2);
382        }
383        os << std::string( indent+2, ' ' );
384        Expression::print( os, indent );
385}
386
387UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
388                Expression( _aname ), function(_function), args(_args) {}
389
390UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
391                Expression( other ), function( maybeClone( other.function ) ) {
392        cloneAll( other.args, args );
393}
394
395UntypedExpr::~UntypedExpr() {
396        delete function;
397        deleteAll( args );
398}
399
400UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
401        UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
402        if ( Type * type = expr->get_result() ) {
403                Type * base = InitTweak::getPointerBase( type );
404                assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() );
405                ret->set_result( new ReferenceType( Type::Qualifiers(), base->clone() ) );
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, int indent ) const {
423        os << "Applying untyped: " << std::endl;
424        os << std::string( indent+2, ' ' );
425        function->print(os, indent + 2);
426        os << std::string( indent, ' ' ) << "...to: " << std::endl;
427        printAll(args, os, indent + 2);
428        Expression::print( os, indent );
429}
430
431void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
432        std::list<Expression *>::const_iterator i;
433        for (i = args.begin(); i != args.end(); i++) {
434                os << std::string(indent, ' ' );
435                (*i)->print(os, indent);
436        }
437}
438
439NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {
440        assertf(_name != "0", "Zero is not a valid name\n");
441        assertf(_name != "1", "One is not a valid name\n");
442}
443
444NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
445}
446
447NameExpr::~NameExpr() {}
448
449void NameExpr::print( std::ostream &os, int indent ) const {
450        os << "Name: " << get_name() << std::endl;
451        Expression::print( os, indent );
452}
453
454LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
455                Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
456        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
457}
458
459LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
460                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
461}
462
463LogicalExpr::~LogicalExpr() {
464        delete arg1;
465        delete arg2;
466}
467
468void LogicalExpr::print( std::ostream &os, int indent )const {
469        os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
470        arg1->print(os);
471        os << " and ";
472        arg2->print(os);
473        os << std::endl;
474        Expression::print( os, indent );
475}
476
477ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
478                Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
479
480ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
481                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
482}
483
484ConditionalExpr::~ConditionalExpr() {
485        delete arg1;
486        delete arg2;
487        delete arg3;
488}
489
490void ConditionalExpr::print( std::ostream &os, int indent ) const {
491        os << "Conditional expression on: " << std::endl;
492        os << std::string( indent+2, ' ' );
493        arg1->print( os, indent+2 );
494        os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
495        os << std::string( indent+2, ' ' );
496        arg2->print( os, indent+2 );
497        os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
498        os << std::string( indent+2, ' ' );
499        arg3->print( os, indent+2 );
500        os << std::endl;
501        Expression::print( os, indent );
502}
503
504AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
505
506
507void AsmExpr::print( std::ostream &os, int indent ) const {
508        os << "Asm Expression: " << std::endl;
509        if ( inout ) inout->print( os, indent + 2 );
510        if ( constraint ) constraint->print( os, indent + 2 );
511        if ( operand ) operand->print( os, indent + 2 );
512}
513
514
515ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
516        assert( callExpr );
517        assert( callExpr->has_result() );
518        set_result( callExpr->get_result()->clone() );
519}
520
521ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
522        cloneAll( other.tempDecls, tempDecls );
523        cloneAll( other.returnDecls, returnDecls );
524        cloneAll( other.dtors, dtors );
525}
526
527ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
528        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
529        delete callExpr;
530        deleteAll( tempDecls );
531        deleteAll( returnDecls );
532        deleteAll( dtors );
533}
534
535void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
536        os <<  "Implicit Copy Constructor Expression: " << std::endl;
537        assert( callExpr );
538        os << std::string( indent+2, ' ' );
539        callExpr->print( os, indent + 2 );
540        os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;
541        printAll(tempDecls, os, indent+2);
542        os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl;
543        printAll(returnDecls, os, indent+2);
544        Expression::print( os, indent );
545}
546
547
548ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
549        // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
550        assert( callExpr );
551        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
552        assert( arg );
553        set_result( maybeClone( arg->get_result() ) );
554}
555
556ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
557}
558
559ConstructorExpr::~ConstructorExpr() {
560        delete callExpr;
561}
562
563void ConstructorExpr::print( std::ostream &os, int indent ) const {
564        os <<  "Constructor Expression: " << std::endl;
565        assert( callExpr );
566        os << std::string( indent+2, ' ' );
567        callExpr->print( os, indent + 2 );
568        Expression::print( os, indent );
569}
570
571
572CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
573        assert( type && initializer );
574        set_result( type );
575}
576
577CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
578
579CompoundLiteralExpr::~CompoundLiteralExpr() {
580        delete initializer;
581}
582
583void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
584        os << "Compound Literal Expression: " << std::endl;
585        os << std::string( indent+2, ' ' );
586        get_result()->print( os, indent + 2 );
587        os << std::string( indent+2, ' ' );
588        initializer->print( os, indent + 2 );
589        Expression::print( os, indent );
590}
591
592RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
593RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
594void RangeExpr::print( std::ostream &os, int indent ) const {
595        os << "Range Expression: ";
596        low->print( os, indent );
597        os << " ... ";
598        high->print( os, indent );
599        Expression::print( os, indent );
600}
601
602StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
603        assert( statements );
604        std::list< Statement * > & body = statements->get_kids();
605        if ( ! body.empty() ) {
606                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
607                        set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
608                }
609        }
610}
611StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
612        cloneAll( other.returnDecls, returnDecls );
613        cloneAll( other.dtors, dtors );
614}
615StmtExpr::~StmtExpr() {
616        delete statements;
617        deleteAll( dtors );
618        deleteAll( returnDecls );
619}
620void StmtExpr::print( std::ostream &os, int indent ) const {
621        os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
622        statements->print( os, indent+2 );
623        if ( ! returnDecls.empty() ) {
624                os << std::string( indent+2, ' ' ) << "with returnDecls: ";
625                printAll( returnDecls, os, indent+2 );
626        }
627        if ( ! dtors.empty() ) {
628                os << std::string( indent+2, ' ' ) << "with dtors: ";
629                printAll( dtors, os, indent+2 );
630        }
631        Expression::print( os, indent );
632}
633
634
635long long UniqueExpr::count = 0;
636UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
637        assert( expr );
638        assert( count != -1 );
639        if ( id == -1 ) id = count++;
640        if ( expr->get_result() ) {
641                set_result( expr->get_result()->clone() );
642        }
643}
644UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
645}
646UniqueExpr::~UniqueExpr() {
647        delete expr;
648        delete object;
649        delete var;
650}
651void UniqueExpr::print( std::ostream &os, int indent ) const {
652        os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' );
653        get_expr()->print( os, indent+2 );
654        if ( get_object() ) {
655                os << std::string( indent+2, ' ' ) << "with decl: ";
656                get_object()->printShort( os, indent+2 );
657        }
658        Expression::print( os, indent );
659}
660
661InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
662InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
663InitAlternative::~InitAlternative() {
664        delete type;
665        delete designation;
666}
667
668UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
669UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
670UntypedInitExpr::~UntypedInitExpr() {
671        delete expr;
672}
673
674void UntypedInitExpr::print( std::ostream & os, int indent ) const {
675        os << "Untyped Init Expression" << std::endl << std::string( indent+2, ' ' );
676        expr->print( os, indent+2 );
677        if ( ! initAlts.empty() ) {
678                for ( const InitAlternative & alt : initAlts ) {
679                        os << std::string( indent+2, ' ' ) <<  "InitAlternative: ";
680                        alt.type->print( os, indent+2 );
681                        alt.designation->print( os, indent+2 );
682                }
683        }
684}
685
686InitExpr::InitExpr( Expression * expr, Designation * designation ) : expr( expr ), designation( designation ) {
687        set_result( expr->get_result()->clone() );
688}
689InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
690InitExpr::~InitExpr() {
691        delete expr;
692        delete designation;
693}
694
695void InitExpr::print( std::ostream & os, int indent ) const {
696        os << "Init Expression" << std::endl << std::string( indent+2, ' ' );
697        expr->print( os, indent+2 );
698        os << std::string( indent+2, ' ' ) << "with designation: ";
699        designation->print( os, indent+2 );
700}
701
702
703std::ostream & operator<<( std::ostream & out, const Expression * expr ) {
704        if ( expr ) {
705                expr->print( out );
706        } else {
707                out << "nullptr";
708        }
709        return out;
710}
711
712// Local Variables: //
713// tab-width: 4 //
714// mode: c++ //
715// compile-command: "make install" //
716// End: //
Note: See TracBrowser for help on using the repository browser.