source: src/SynTree/Expression.cc@ 903f7c3

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 903f7c3 was 4b0f997, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

fix implicit conversion to anonymous members

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