source: src/SynTree/Expression.cc @ ff29f08

new-envwith_gc
Last change on this file since ff29f08 was 42107b4, checked in by Aaron Moss <a3moss@…>, 6 years ago

Leftover cleanup from merge

  • 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}
55
56void Expression::print( std::ostream &os, Indenter indent ) const {
57        printInferParams( inferParams, os, indent+1, 0 );
58
59        if ( env ) {
60                os << std::endl << indent << "... with environment:" << std::endl;
61                env->print( os, indent+1 );
62        } // if
63
64        if ( extension ) {
65                os << std::endl << indent << "... with extension:";
66        } // if
67}
68
69ConstantExpr::ConstantExpr( Constant _c ) : Expression(), constant( _c ) {
70        set_result( constant.get_type()->clone() );
71}
72
73ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
74}
75
76void ConstantExpr::print( std::ostream &os, Indenter indent ) const {
77        os << "constant expression " ;
78        constant.print( os );
79        Expression::print( os, indent );
80}
81
82long long int ConstantExpr::intValue() const {
83        if ( BasicType * basicType = dynamic_cast< BasicType * >( result ) ) {
84                if ( basicType->isInteger() ) {
85                        return get_constant()->get_ival();
86                }
87        } else if ( dynamic_cast< OneType * >( result ) ) {
88                return 1;
89        } else if ( dynamic_cast< ZeroType * >( result ) ) {
90                return 0;
91        }
92        SemanticError( this, "Constant expression of non-integral type " );
93}
94
95VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) {
96        assert( var );
97        assert( var->get_type() );
98        Type * type = var->get_type()->clone();
99        type->set_lvalue( true );
100
101        // xxx - doesn't quite work yet - get different alternatives with the same cost
102
103        // // enumerators are not lvalues
104        // if ( EnumInstType * inst = dynamic_cast< EnumInstType * >( var->get_type() ) ) {
105        //      assert( inst->baseEnum );
106        //      EnumDecl * decl = inst->baseEnum;
107        //      long long int value;
108        //      if ( decl->valueOf( var, value ) ) {
109        //              type->set_lvalue( false );
110        //      }
111        // }
112
113        set_result( type );
114}
115
116VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
117}
118
119VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) {
120        VariableExpr * funcExpr = new VariableExpr( func );
121        funcExpr->set_result( new PointerType( Type::Qualifiers(), funcExpr->get_result() ) );
122        return funcExpr;
123}
124
125void VariableExpr::print( std::ostream &os, Indenter indent ) const {
126        os << "Variable Expression: ";
127        var->printShort(os, indent);
128        Expression::print( os, indent );
129}
130
131SizeofExpr::SizeofExpr( Expression *expr_ ) :
132                Expression(), expr(expr_), type(0), isType(false) {
133        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
134}
135
136SizeofExpr::SizeofExpr( Type *type_ ) :
137                Expression(), expr(0), type(type_), isType(true) {
138        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
139}
140
141SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
142        Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
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
166void AlignofExpr::print( std::ostream &os, Indenter indent) const {
167        os << "Alignof Expression on: ";
168        if (isType) type->print(os, indent+1);
169        else expr->print(os, indent+1);
170        Expression::print( os, indent );
171}
172
173UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type, const std::string &member ) :
174                Expression(), type(type), member(member) {
175        assert( type );
176        set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
177}
178
179UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
180        Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
181
182void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const {
183        os << "Untyped Offsetof Expression on member " << member << " of ";
184        type->print(os, indent+1);
185        Expression::print( os, indent );
186}
187
188OffsetofExpr::OffsetofExpr( Type *type, DeclarationWithType *member ) :
189                Expression(), type(type), member(member) {
190        assert( member );
191        assert( type );
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
198void OffsetofExpr::print( std::ostream &os, Indenter indent) const {
199        os << "Offsetof Expression on member " << member->name << " of ";
200        type->print(os, indent+1);
201        Expression::print( os, indent );
202}
203
204OffsetPackExpr::OffsetPackExpr( StructInstType *type ) : Expression(), type( type ) {
205        assert( type );
206        set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
207}
208
209OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
210
211void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const {
212        os << "Offset pack expression on ";
213        type->print(os, indent+1);
214        Expression::print( os, indent );
215}
216
217AttrExpr::AttrExpr( Expression *attr, Expression *expr_ ) :
218                Expression(), attr( attr ), expr(expr_), type(0), isType(false) {
219}
220
221AttrExpr::AttrExpr( Expression *attr, Type *type_ ) :
222                Expression(), attr( attr ), expr(0), type(type_), isType(true) {
223}
224
225AttrExpr::AttrExpr( const AttrExpr &other ) :
226                Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
227}
228
229void AttrExpr::print( std::ostream &os, Indenter indent) const {
230        os << "Attr ";
231        attr->print( os, indent+1);
232        if ( isType || expr ) {
233                os << "applied to: ";
234                if (isType) type->print(os, indent+1);
235                else expr->print(os, indent+1);
236        } // if
237        Expression::print( os, indent );
238}
239
240CastExpr::CastExpr( Expression *arg, Type *toType, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
241        set_result(toType);
242}
243
244CastExpr::CastExpr( Expression *arg, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) {
245        set_result( new VoidType( Type::Qualifiers() ) );
246}
247
248CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {
249}
250
251void CastExpr::print( std::ostream &os, Indenter indent ) const {
252        os << "Cast of:" << std::endl << indent+1;
253        arg->print(os, indent+1);
254        os << std::endl << indent << "... to:";
255        if ( result->isVoid() ) {
256                os << " nothing";
257        } else {
258                os << std::endl << indent+1;
259                result->print( os, indent+1 );
260        } // if
261        Expression::print( os, indent );
262}
263
264KeywordCastExpr::KeywordCastExpr( Expression *arg, Target target ) : Expression(), arg(arg), target( target ) {
265}
266
267KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) {
268}
269
270const std::string & KeywordCastExpr::targetString() const {
271        static const std::string targetStrs[] = {
272                "coroutine", "thread", "monitor"
273        };
274        static_assert(
275                (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
276                "Each KeywordCastExpr::Target should have a corresponding string representation"
277        );
278        return targetStrs[(unsigned long)target];
279}
280
281void KeywordCastExpr::print( std::ostream &os, Indenter indent ) const {
282        os << "Keyword Cast of:" << std::endl << indent+1;
283        arg->print(os, indent+1);
284        os << std::endl << indent << "... to: ";
285        os << targetString();
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
296void VirtualCastExpr::print( std::ostream &os, Indenter indent ) const {
297        os << "Virtual Cast of:" << std::endl << indent+1;
298        arg->print(os, indent+1);
299        os << std::endl << indent << "... to:";
300        if ( ! result ) {
301                os << " unknown";
302        } else {
303                os << std::endl << indent+1;
304                result->print( os, indent+1 );
305        } // if
306        Expression::print( os, indent );
307}
308
309UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression *aggregate ) :
310                Expression(), member(member), aggregate(aggregate) {
311        assert( aggregate );
312}
313
314UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
315                Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
316}
317
318void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const {
319        os << "Untyped Member Expression, with field: " << std::endl << indent+1;
320        member->print(os, indent+1 );
321        os << indent << "... from aggregate: " << std::endl << indent+1;
322        aggregate->print(os, indent+1);
323        Expression::print( os, indent );
324}
325
326MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) :
327                Expression(), member(member), aggregate(aggregate) {
328        assert( member );
329        assert( aggregate );
330        assert( aggregate->result );
331
332        TypeSubstitution sub = aggregate->result->genericSubstitution();
333        Type * res = member->get_type()->clone();
334        sub.apply( res );
335        result = res;
336        result->set_lvalue( true );
337        result->get_qualifiers() |= aggregate->result->get_qualifiers();
338}
339
340MemberExpr::MemberExpr( const MemberExpr &other ) :
341                Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
342}
343
344void MemberExpr::print( std::ostream &os, Indenter indent ) const {
345        os << "Member Expression, with field: " << std::endl;
346        os << indent+1;
347        member->print( os, indent+1 );
348        os << std::endl << indent << "... from aggregate: " << std::endl << indent+1;
349        aggregate->print(os, indent + 1);
350        Expression::print( os, indent );
351}
352
353UntypedExpr::UntypedExpr( Expression *function, const std::list<Expression *> &args ) :
354                Expression(), function(function), args(args) {}
355
356UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
357                Expression( other ), function( maybeClone( other.function ) ) {
358        cloneAll( other.args, args );
359}
360
361UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
362        UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
363        if ( Type * type = expr->get_result() ) {
364                Type * base = InitTweak::getPointerBase( type );
365                assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() );
366                ret->set_result( base->clone() );
367                if ( GenPoly::referencesPermissable() ) {
368                        // if references are still allowed in the AST, dereference returns a reference
369                        ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) );
370                } else {
371                        // references have been removed, in which case dereference returns an lvalue of the base type.
372                        ret->result->set_lvalue( true );
373                }
374        }
375        return ret;
376}
377
378UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) {
379        assert( arg1 && arg2 );
380        UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } );
381        if ( arg1->get_result() && arg2->get_result() ) {
382                // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
383                // so the result is the type of the RHS
384                ret->set_result( arg2->get_result()->clone() );
385        }
386        return ret;
387}
388
389
390void UntypedExpr::print( std::ostream &os, Indenter indent ) const {
391        os << "Applying untyped: " << std::endl;
392        os << indent+1;
393        function->print(os, indent+1);
394        os << std::endl << indent << "...to: " << std::endl;
395        printAll(args, os, indent+1);
396        Expression::print( os, indent );
397}
398
399NameExpr::NameExpr( std::string name ) : Expression(), name(name) {
400        assertf(name != "0", "Zero is not a valid name");
401        assertf(name != "1", "One is not a valid name");
402}
403
404NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
405}
406
407void NameExpr::print( std::ostream &os, Indenter indent ) const {
408        os << "Name: " << get_name();
409        Expression::print( os, indent );
410}
411
412LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp ) :
413                Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) {
414        set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
415}
416
417LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
418                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
419}
420
421void LogicalExpr::print( std::ostream &os, Indenter indent )const {
422        os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: ";
423        arg1->print(os);
424        os << " and ";
425        arg2->print(os);
426        Expression::print( os, indent );
427}
428
429ConditionalExpr::ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ) :
430                Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {}
431
432ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
433                Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
434}
435
436void ConditionalExpr::print( std::ostream &os, Indenter indent ) const {
437        os << "Conditional expression on: " << std::endl << indent+1;
438        arg1->print( os, indent+1 );
439        os << indent << "First alternative:" << std::endl << indent+1;
440        arg2->print( os, indent+1 );
441        os << indent << "Second alternative:" << std::endl << indent+1;
442        arg3->print( os, indent+1 );
443        Expression::print( os, indent );
444}
445
446AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
447
448
449void AsmExpr::print( std::ostream &os, Indenter indent ) const {
450        os << "Asm Expression: " << std::endl;
451        if ( inout ) inout->print( os, indent+1 );
452        if ( constraint ) constraint->print( os, indent+1 );
453        if ( operand ) operand->print( os, indent+1 );
454}
455
456
457ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
458        assert( callExpr );
459        assert( callExpr->result );
460        set_result( callExpr->get_result()->clone() );
461}
462
463ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
464        cloneAll( other.tempDecls, tempDecls );
465        cloneAll( other.returnDecls, returnDecls );
466        cloneAll( other.dtors, dtors );
467}
468
469ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
470        set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
471}
472
473void ImplicitCopyCtorExpr::print( std::ostream &os, Indenter indent ) const {
474        os <<  "Implicit Copy Constructor Expression: " << std::endl << indent+1;
475        callExpr->print( os, indent+1 );
476        os << std::endl << indent << "... with temporaries:" << std::endl;
477        printAll( tempDecls, os, indent+1 );
478        os << std::endl << indent << "... with return temporaries:" << std::endl;
479        printAll( returnDecls, os, indent+1 );
480        Expression::print( os, indent );
481}
482
483
484ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
485        // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
486        assert( callExpr );
487        Expression * arg = InitTweak::getCallArg( callExpr, 0 );
488        assert( arg );
489        set_result( maybeClone( arg->result ) );
490}
491
492ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
493}
494
495void ConstructorExpr::print( std::ostream &os, Indenter indent ) const {
496        os <<  "Constructor Expression: " << std::endl << indent+1;
497        callExpr->print( os, indent + 2 );
498        Expression::print( os, indent );
499}
500
501
502CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
503        assert( type && initializer );
504        type->set_lvalue( true );
505        set_result( type );
506}
507
508CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
509
510void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const {
511        os << "Compound Literal Expression: " << std::endl << indent+1;
512        result->print( os, indent+1 );
513        os << indent+1;
514        initializer->print( os, indent+1 );
515        Expression::print( os, indent );
516}
517
518RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
519RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
520void RangeExpr::print( std::ostream &os, Indenter indent ) const {
521        os << "Range Expression: ";
522        low->print( os, indent );
523        os << " ... ";
524        high->print( os, indent );
525        Expression::print( os, indent );
526}
527
528StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
529        computeResult();
530}
531StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
532        cloneAll( other.returnDecls, returnDecls );
533        cloneAll( other.dtors, dtors );
534}
535void StmtExpr::computeResult() {
536        assert( statements );
537        std::list< Statement * > & body = statements->kids;
538        result = nullptr;
539        if ( ! returnDecls.empty() ) {
540                // prioritize return decl for result type, since if a return decl exists, then
541                // the StmtExpr is currently in an intermediate state where the body will always
542                // give a void result type.
543                result = returnDecls.front()->get_type()->clone();
544        } else if ( ! body.empty() ) {
545                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
546                        result = maybeClone( exprStmt->expr->result );
547                }
548        }
549        // ensure that StmtExpr has a result type
550        if ( ! result ) {
551                result = new VoidType( Type::Qualifiers() );
552        }
553}
554void StmtExpr::print( std::ostream &os, Indenter indent ) const {
555        os << "Statement Expression: " << std::endl << indent+1;
556        statements->print( os, indent+1 );
557        if ( ! returnDecls.empty() ) {
558                os << indent+1 << "... with returnDecls: ";
559                printAll( returnDecls, os, indent+1 );
560        }
561        if ( ! dtors.empty() ) {
562                os << indent+1 << "... with dtors: ";
563                printAll( dtors, os, indent+1 );
564        }
565        Expression::print( os, indent );
566}
567
568
569long long UniqueExpr::count = 0;
570UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
571        assert( expr );
572        assert( count != -1 );
573        if ( id == -1 ) id = count++;
574        if ( expr->get_result() ) {
575                set_result( expr->get_result()->clone() );
576        }
577}
578UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
579}
580
581void UniqueExpr::print( std::ostream &os, Indenter indent ) const {
582        os << "Unique Expression with id:" << id << std::endl << indent+1;
583        expr->print( os, indent+1 );
584        if ( object ) {
585                os << indent << "... with decl: ";
586                get_object()->printShort( os, indent+1 );
587        }
588        Expression::print( os, indent );
589}
590
591InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
592InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
593
594UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
595UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
596
597void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const {
598        os << "Untyped Init Expression" << std::endl << indent+1;
599        expr->print( os, indent+1 );
600        if ( ! initAlts.empty() ) {
601                for ( const InitAlternative & alt : initAlts ) {
602                        os << indent+1 <<  "InitAlternative: ";
603                        alt.type->print( os, indent+1 );
604                        alt.designation->print( os, indent+1 );
605                }
606        }
607}
608
609InitExpr::InitExpr( Expression * expr, Designation * designation ) : expr( expr ), designation( designation ) {
610        set_result( expr->get_result()->clone() );
611}
612InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
613
614void InitExpr::print( std::ostream & os, Indenter indent ) const {
615        os << "Init Expression" << std::endl << indent+1;
616        expr->print( os, indent+1 );
617        os << indent+1 << "... with designation: ";
618        designation->print( os, indent+1 );
619}
620
621DeletedExpr::DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) {
622        assert( expr->result );
623        result = expr->result->clone();
624}
625DeletedExpr::DeletedExpr( const DeletedExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), deleteStmt( other.deleteStmt ) {}
626
627void DeletedExpr::print( std::ostream & os, Indenter indent ) const {
628        os << "Deleted Expression" << std::endl << indent+1;
629        expr->print( os, indent+1 );
630        os << std::endl << indent+1 << "... deleted by: ";
631        deleteStmt->print( os, indent+1 );
632}
633
634
635// Local Variables: //
636// tab-width: 4 //
637// mode: c++ //
638// compile-command: "make install" //
639// End: //
Note: See TracBrowser for help on using the repository browser.