source: src/SynTree/Expression.cc@ e4d829b

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 stuck-waitfor-destruct with_gc
Last change on this file since e4d829b was e4d829b, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

major effort on designations, works in many cases

  • 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 : 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->printShort(os, indent + 2);
95 os << std::endl;
96 Expression::print( os, indent );
97}
98
99SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
100 Expression( _aname ), expr(expr_), type(0), isType(false) {
101 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
102}
103
104SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
105 Expression( _aname ), expr(0), type(type_), isType(true) {
106 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
107}
108
109SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
110 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
111}
112
113SizeofExpr::~SizeofExpr() {
114 delete expr;
115 delete type;
116}
117
118void SizeofExpr::print( std::ostream &os, int indent) const {
119 os << "Sizeof Expression on: ";
120
121 if (isType)
122 type->print(os, indent + 2);
123 else
124 expr->print(os, indent + 2);
125
126 os << std::endl;
127 Expression::print( os, indent );
128}
129
130AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
131 Expression( _aname ), expr(expr_), type(0), isType(false) {
132 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
133}
134
135AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
136 Expression( _aname ), expr(0), type(type_), isType(true) {
137 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
138}
139
140AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
141 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
142}
143
144AlignofExpr::~AlignofExpr() {
145 delete expr;
146 delete type;
147}
148
149void AlignofExpr::print( std::ostream &os, int indent) const {
150 os << std::string( indent, ' ' ) << "Alignof Expression on: ";
151
152 if (isType)
153 type->print(os, indent + 2);
154 else
155 expr->print(os, indent + 2);
156
157 os << std::endl;
158 Expression::print( os, indent );
159}
160
161UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
162 Expression( _aname ), type(type_), member(member_) {
163 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
164}
165
166UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
167 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
168
169UntypedOffsetofExpr::~UntypedOffsetofExpr() {
170 delete type;
171}
172
173void UntypedOffsetofExpr::print( std::ostream &os, int indent) const {
174 os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of ";
175
176 if ( type ) {
177 type->print(os, indent + 2);
178 } else {
179 os << "<NULL>";
180 }
181
182 os << std::endl;
183 Expression::print( os, indent );
184}
185
186OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
187 Expression( _aname ), type(type_), member(member_) {
188 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
189}
190
191OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
192 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
193
194OffsetofExpr::~OffsetofExpr() {
195 delete type;
196}
197
198void OffsetofExpr::print( std::ostream &os, int indent) const {
199 os << std::string( indent, ' ' ) << "Offsetof Expression on member ";
200
201 if ( member ) {
202 os << member->get_name();
203 } else {
204 os << "<NULL>";
205 }
206
207 os << " of ";
208
209 if ( type ) {
210 type->print(os, indent + 2);
211 } else {
212 os << "<NULL>";
213 }
214
215 os << std::endl;
216 Expression::print( os, indent );
217}
218
219OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
220 set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
221}
222
223OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
224
225OffsetPackExpr::~OffsetPackExpr() { delete type; }
226
227void OffsetPackExpr::print( std::ostream &os, int indent ) const {
228 os << std::string( indent, ' ' ) << "Offset pack expression on ";
229
230 if ( type ) {
231 type->print(os, indent + 2);
232 } else {
233 os << "<NULL>";
234 }
235
236 os << std::endl;
237 Expression::print( os, indent );
238}
239
240AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
241 Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
242}
243
244AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
245 Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
246}
247
248AttrExpr::AttrExpr( const AttrExpr &other ) :
249 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
250}
251
252AttrExpr::~AttrExpr() {
253 delete attr;
254 delete expr;
255 delete type;
256}
257
258void AttrExpr::print( std::ostream &os, int indent) const {
259 os << std::string( indent, ' ' ) << "Attr ";
260 attr->print( os, indent + 2 );
261 if ( isType || expr ) {
262 os << "applied to: ";
263
264 if (isType)
265 type->print(os, indent + 2);
266 else
267 expr->print(os, indent + 2);
268 } // if
269
270 os << std::endl;
271 Expression::print( os, indent );
272}
273
274CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
275 set_result(toType);
276}
277
278CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
279 set_result( new VoidType( Type::Qualifiers() ) );
280}
281
282CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
283}
284
285CastExpr::~CastExpr() {
286 delete arg;
287}
288
289// CastExpr *CastExpr::clone() const { return 0; }
290
291void CastExpr::print( std::ostream &os, int indent ) const {
292 os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
293 arg->print(os, indent+2);
294 os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
295 os << std::string( indent+2, ' ' );
296 if ( result->isVoid() ) {
297 os << "nothing";
298 } else {
299 result->print( os, indent+2 );
300 } // if
301 os << std::endl;
302 Expression::print( os, indent );
303}
304
305UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
306 Expression( _aname ), member(_member), aggregate(_aggregate) {}
307
308UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
309 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
310}
311
312UntypedMemberExpr::~UntypedMemberExpr() {
313 delete aggregate;
314 delete member;
315}
316
317void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
318 os << "Untyped Member Expression, with field: " << std::endl;
319 os << std::string( indent+2, ' ' );
320 get_member()->print(os, indent+4);
321 os << std::string( indent+2, ' ' );
322
323 Expression *agg = get_aggregate();
324 os << "from aggregate: " << std::endl;
325 if (agg != 0) {
326 os << std::string( indent + 4, ' ' );
327 agg->print(os, indent + 4);
328 }
329 os << std::string( indent+2, ' ' );
330 Expression::print( os, indent );
331}
332
333namespace {
334 TypeSubstitution makeSub( Type * t ) {
335 if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
336 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
337 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
338 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
339 } else {
340 assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() );
341 }
342 }
343}
344
345
346MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
347 Expression( _aname ), member(_member), aggregate(_aggregate) {
348
349 TypeSubstitution sub( makeSub( aggregate->get_result() ) );
350 Type * res = member->get_type()->clone();
351 sub.apply( res );
352 set_result( res );
353 get_result()->set_lvalue( true );
354}
355
356//// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...
357MemberExpr::MemberExpr( const MemberExpr &other ) :
358 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
359}
360
361MemberExpr::~MemberExpr() {
362 // delete member;
363 delete aggregate;
364}
365
366void MemberExpr::print( std::ostream &os, int indent ) const {
367 os << "Member Expression, with field: " << std::endl;
368
369 assert( member );
370 os << std::string( indent + 2, ' ' );
371 member->print( os, indent + 2 );
372 os << std::endl;
373
374 Expression *agg = get_aggregate();
375 os << std::string( indent, ' ' ) << "from aggregate: " << std::endl;
376 if (agg != 0) {
377 os << std::string( indent + 2, ' ' );
378 agg->print(os, indent + 2);
379 }
380 os << std::string( indent+2, ' ' );
381 Expression::print( os, indent );
382}
383
384UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
385 Expression( _aname ), function(_function), args(_args) {}
386
387UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
388 Expression( other ), function( maybeClone( other.function ) ) {
389 cloneAll( other.args, args );
390}
391
392UntypedExpr::~UntypedExpr() {
393 delete function;
394 deleteAll( args );
395}
396
397UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
398 UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
399 if ( Type * type = expr->get_result() ) {
400 Type * base = InitTweak::getPointerBase( type );
401 if ( ! base ) {
402 std::cerr << type << std::endl;
403 }
404 assertf( base, "expected pointer type in dereference\n" );
405 ret->set_result( maybeClone( base ) );
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 ) : 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
592UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
593
594UntypedValofExpr::~UntypedValofExpr() { delete body; }
595
596void UntypedValofExpr::print( std::ostream &os, int indent ) const {
597 os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;
598 if ( get_body() != 0 )
599 get_body()->print( os, indent + 2 );
600}
601
602RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
603RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
604void RangeExpr::print( std::ostream &os, int indent ) const {
605 os << "Range Expression: ";
606 low->print( os, indent );
607 os << " ... ";
608 high->print( os, indent );
609 Expression::print( os, indent );
610}
611
612StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
613 assert( statements );
614 std::list< Statement * > & body = statements->get_kids();
615 if ( ! body.empty() ) {
616 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
617 set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
618 }
619 }
620}
621StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
622 cloneAll( other.returnDecls, returnDecls );
623 cloneAll( other.dtors, dtors );
624}
625StmtExpr::~StmtExpr() {
626 delete statements;
627 deleteAll( dtors );
628 deleteAll( returnDecls );
629}
630void StmtExpr::print( std::ostream &os, int indent ) const {
631 os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
632 statements->print( os, indent+2 );
633 if ( ! returnDecls.empty() ) {
634 os << std::string( indent+2, ' ' ) << "with returnDecls: ";
635 printAll( returnDecls, os, indent+2 );
636 }
637 if ( ! dtors.empty() ) {
638 os << std::string( indent+2, ' ' ) << "with dtors: ";
639 printAll( dtors, os, indent+2 );
640 }
641 Expression::print( os, indent );
642}
643
644
645long long UniqueExpr::count = 0;
646UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
647 assert( expr );
648 assert( count != -1 );
649 if ( id == -1 ) id = count++;
650 if ( expr->get_result() ) {
651 set_result( expr->get_result()->clone() );
652 }
653}
654UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
655}
656UniqueExpr::~UniqueExpr() {
657 delete expr;
658 delete object;
659 delete var;
660}
661void UniqueExpr::print( std::ostream &os, int indent ) const {
662 os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' );
663 get_expr()->print( os, indent+2 );
664 if ( get_object() ) {
665 os << std::string( indent+2, ' ' ) << "with decl: ";
666 get_object()->printShort( os, indent+2 );
667 }
668 Expression::print( os, indent );
669}
670
671InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
672InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
673InitAlternative::~InitAlternative() {
674 delete type;
675 delete designation;
676}
677
678UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
679UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
680UntypedInitExpr::~UntypedInitExpr() {
681 delete expr;
682}
683
684void UntypedInitExpr::print( std::ostream & os, int indent ) const {
685 os << "Untyped Init Expression" << std::endl << std::string( indent+2, ' ' );
686 expr->print( os, indent+2 );
687 if ( ! initAlts.empty() ) {
688 for ( const InitAlternative & alt : initAlts ) {
689 os << std::string( indent+2, ' ' ) << "InitAlternative: ";
690 alt.type->print( os, indent+2 );
691 alt.designation->print( os, indent+2 );
692 }
693 }
694}
695
696InitExpr::InitExpr( Expression * expr, Type * type, Designation * designation ) : expr( expr ), designation( designation ) {
697 set_result( type );
698}
699InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
700InitExpr::~InitExpr() {
701 delete expr;
702 delete designation;
703}
704
705void InitExpr::print( std::ostream & os, int indent ) const {
706 os << "Init Expression" << std::endl << std::string( indent+2, ' ' );
707 expr->print( os, indent+2 );
708 os << std::string( indent+2, ' ' ) << "with designation: ";
709 designation->print( os, indent+2 );
710}
711
712
713std::ostream & operator<<( std::ostream & out, const Expression * expr ) {
714 if ( expr ) {
715 expr->print( out );
716 } else {
717 out << "nullptr";
718 }
719 return out;
720}
721
722// Local Variables: //
723// tab-width: 4 //
724// mode: c++ //
725// compile-command: "make install" //
726// End: //
Note: See TracBrowser for help on using the repository browser.