source: src/SynTree/Expression.cc@ 579263a

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

Merge branch 'master' into designations

Conflicts:

src/InitTweak/FixInit.cc
src/SymTab/Autogen.h
src/SynTree/Initializer.cc
src/SynTree/Initializer.h
src/Tuples/TupleExpansion.cc

  • Property mode set to 100644
File size: 22.3 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
289void CastExpr::print( std::ostream &os, int indent ) const {
290 os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
291 arg->print(os, indent+2);
292 os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
293 os << std::string( indent+2, ' ' );
294 if ( result->isVoid() ) {
295 os << "nothing";
296 } else {
297 result->print( os, indent+2 );
298 } // if
299 os << std::endl;
300 Expression::print( os, indent );
301}
302
303UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
304 Expression( _aname ), member(_member), aggregate(_aggregate) {}
305
306UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
307 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
308}
309
310UntypedMemberExpr::~UntypedMemberExpr() {
311 delete aggregate;
312 delete member;
313}
314
315void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
316 os << "Untyped Member Expression, with field: " << std::endl;
317 os << std::string( indent+2, ' ' );
318 get_member()->print(os, indent+4);
319 os << std::string( indent+2, ' ' );
320
321 Expression *agg = get_aggregate();
322 os << "from aggregate: " << std::endl;
323 if (agg != 0) {
324 os << std::string( indent + 4, ' ' );
325 agg->print(os, indent + 4);
326 }
327 os << std::string( indent+2, ' ' );
328 Expression::print( os, indent );
329}
330
331namespace {
332 TypeSubstitution makeSub( Type * t ) {
333 if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
334 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
335 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
336 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
337 } else {
338 assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() );
339 }
340 }
341}
342
343
344MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
345 Expression( _aname ), member(_member), aggregate(_aggregate) {
346
347 TypeSubstitution sub( makeSub( aggregate->get_result() ) );
348 Type * res = member->get_type()->clone();
349 sub.apply( res );
350 set_result( res );
351 get_result()->set_lvalue( true );
352}
353
354MemberExpr::MemberExpr( const MemberExpr &other ) :
355 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
356}
357
358MemberExpr::~MemberExpr() {
359 // don't delete the member declaration, since it points somewhere else in the tree
360 delete aggregate;
361}
362
363void MemberExpr::print( std::ostream &os, int indent ) const {
364 os << "Member Expression, with field: " << std::endl;
365
366 assert( member );
367 os << std::string( indent + 2, ' ' );
368 member->print( os, indent + 2 );
369 os << std::endl;
370
371 Expression *agg = get_aggregate();
372 os << std::string( indent, ' ' ) << "from aggregate: " << std::endl;
373 if (agg != 0) {
374 os << std::string( indent + 2, ' ' );
375 agg->print(os, indent + 2);
376 }
377 os << std::string( indent+2, ' ' );
378 Expression::print( os, indent );
379}
380
381UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
382 Expression( _aname ), function(_function), args(_args) {}
383
384UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
385 Expression( other ), function( maybeClone( other.function ) ) {
386 cloneAll( other.args, args );
387}
388
389UntypedExpr::~UntypedExpr() {
390 delete function;
391 deleteAll( args );
392}
393
394UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
395 UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
396 if ( Type * type = expr->get_result() ) {
397 Type * base = InitTweak::getPointerBase( type );
398 if ( ! base ) {
399 std::cerr << type << std::endl;
400 }
401 assertf( base, "expected pointer type in dereference\n" );
402 ret->set_result( maybeClone( base ) );
403 }
404 return ret;
405}
406
407UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) {
408 assert( arg1 && arg2 );
409 UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } );
410 if ( arg1->get_result() && arg2->get_result() ) {
411 // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
412 // so the result is the type of the RHS
413 ret->set_result( arg2->get_result()->clone() );
414 }
415 return ret;
416}
417
418
419void UntypedExpr::print( std::ostream &os, int indent ) const {
420 os << "Applying untyped: " << std::endl;
421 os << std::string( indent+2, ' ' );
422 function->print(os, indent + 2);
423 os << std::string( indent, ' ' ) << "...to: " << std::endl;
424 printAll(args, os, indent + 2);
425 Expression::print( os, indent );
426}
427
428void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
429 std::list<Expression *>::const_iterator i;
430 for (i = args.begin(); i != args.end(); i++) {
431 os << std::string(indent, ' ' );
432 (*i)->print(os, indent);
433 }
434}
435
436NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {
437 assertf(_name != "0", "Zero is not a valid name\n");
438 assertf(_name != "1", "One is not a valid name\n");
439}
440
441NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
442}
443
444NameExpr::~NameExpr() {}
445
446void NameExpr::print( std::ostream &os, int indent ) const {
447 os << "Name: " << get_name() << std::endl;
448 Expression::print( os, indent );
449}
450
451LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
452 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
453 set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
454}
455
456LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
457 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
458}
459
460LogicalExpr::~LogicalExpr() {
461 delete arg1;
462 delete arg2;
463}
464
465void LogicalExpr::print( std::ostream &os, int indent )const {
466 os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
467 arg1->print(os);
468 os << " and ";
469 arg2->print(os);
470 os << std::endl;
471 Expression::print( os, indent );
472}
473
474ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
475 Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
476
477ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
478 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
479}
480
481ConditionalExpr::~ConditionalExpr() {
482 delete arg1;
483 delete arg2;
484 delete arg3;
485}
486
487void ConditionalExpr::print( std::ostream &os, int indent ) const {
488 os << "Conditional expression on: " << std::endl;
489 os << std::string( indent+2, ' ' );
490 arg1->print( os, indent+2 );
491 os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
492 os << std::string( indent+2, ' ' );
493 arg2->print( os, indent+2 );
494 os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
495 os << std::string( indent+2, ' ' );
496 arg3->print( os, indent+2 );
497 os << std::endl;
498 Expression::print( os, indent );
499}
500
501AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
502
503
504void AsmExpr::print( std::ostream &os, int indent ) const {
505 os << "Asm Expression: " << std::endl;
506 if ( inout ) inout->print( os, indent + 2 );
507 if ( constraint ) constraint->print( os, indent + 2 );
508 if ( operand ) operand->print( os, indent + 2 );
509}
510
511
512ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
513 assert( callExpr );
514 assert( callExpr->has_result() );
515 set_result( callExpr->get_result()->clone() );
516}
517
518ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
519 cloneAll( other.tempDecls, tempDecls );
520 cloneAll( other.returnDecls, returnDecls );
521 cloneAll( other.dtors, dtors );
522}
523
524ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
525 set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
526 delete callExpr;
527 deleteAll( tempDecls );
528 deleteAll( returnDecls );
529 deleteAll( dtors );
530}
531
532void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
533 os << "Implicit Copy Constructor Expression: " << std::endl;
534 assert( callExpr );
535 os << std::string( indent+2, ' ' );
536 callExpr->print( os, indent + 2 );
537 os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;
538 printAll(tempDecls, os, indent+2);
539 os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl;
540 printAll(returnDecls, os, indent+2);
541 Expression::print( os, indent );
542}
543
544
545ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
546 // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
547 assert( callExpr );
548 Expression * arg = InitTweak::getCallArg( callExpr, 0 );
549 assert( arg );
550 set_result( maybeClone( arg->get_result() ) );
551}
552
553ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
554}
555
556ConstructorExpr::~ConstructorExpr() {
557 delete callExpr;
558}
559
560void ConstructorExpr::print( std::ostream &os, int indent ) const {
561 os << "Constructor Expression: " << std::endl;
562 assert( callExpr );
563 os << std::string( indent+2, ' ' );
564 callExpr->print( os, indent + 2 );
565 Expression::print( os, indent );
566}
567
568
569CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
570 assert( type && initializer );
571 set_result( type );
572}
573
574CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
575
576CompoundLiteralExpr::~CompoundLiteralExpr() {
577 delete initializer;
578}
579
580void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
581 os << "Compound Literal Expression: " << std::endl;
582 os << std::string( indent+2, ' ' );
583 get_result()->print( os, indent + 2 );
584 os << std::string( indent+2, ' ' );
585 initializer->print( os, indent + 2 );
586 Expression::print( os, indent );
587}
588
589RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
590RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
591void RangeExpr::print( std::ostream &os, int indent ) const {
592 os << "Range Expression: ";
593 low->print( os, indent );
594 os << " ... ";
595 high->print( os, indent );
596 Expression::print( os, indent );
597}
598
599StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
600 assert( statements );
601 std::list< Statement * > & body = statements->get_kids();
602 if ( ! body.empty() ) {
603 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
604 set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
605 }
606 }
607}
608StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
609 cloneAll( other.returnDecls, returnDecls );
610 cloneAll( other.dtors, dtors );
611}
612StmtExpr::~StmtExpr() {
613 delete statements;
614 deleteAll( dtors );
615 deleteAll( returnDecls );
616}
617void StmtExpr::print( std::ostream &os, int indent ) const {
618 os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
619 statements->print( os, indent+2 );
620 if ( ! returnDecls.empty() ) {
621 os << std::string( indent+2, ' ' ) << "with returnDecls: ";
622 printAll( returnDecls, os, indent+2 );
623 }
624 if ( ! dtors.empty() ) {
625 os << std::string( indent+2, ' ' ) << "with dtors: ";
626 printAll( dtors, os, indent+2 );
627 }
628 Expression::print( os, indent );
629}
630
631
632long long UniqueExpr::count = 0;
633UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
634 assert( expr );
635 assert( count != -1 );
636 if ( id == -1 ) id = count++;
637 if ( expr->get_result() ) {
638 set_result( expr->get_result()->clone() );
639 }
640}
641UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
642}
643UniqueExpr::~UniqueExpr() {
644 delete expr;
645 delete object;
646 delete var;
647}
648void UniqueExpr::print( std::ostream &os, int indent ) const {
649 os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' );
650 get_expr()->print( os, indent+2 );
651 if ( get_object() ) {
652 os << std::string( indent+2, ' ' ) << "with decl: ";
653 get_object()->printShort( os, indent+2 );
654 }
655 Expression::print( os, indent );
656}
657
658InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
659InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
660InitAlternative::~InitAlternative() {
661 delete type;
662 delete designation;
663}
664
665UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
666UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
667UntypedInitExpr::~UntypedInitExpr() {
668 delete expr;
669}
670
671void UntypedInitExpr::print( std::ostream & os, int indent ) const {
672 os << "Untyped Init Expression" << std::endl << std::string( indent+2, ' ' );
673 expr->print( os, indent+2 );
674 if ( ! initAlts.empty() ) {
675 for ( const InitAlternative & alt : initAlts ) {
676 os << std::string( indent+2, ' ' ) << "InitAlternative: ";
677 alt.type->print( os, indent+2 );
678 alt.designation->print( os, indent+2 );
679 }
680 }
681}
682
683InitExpr::InitExpr( Expression * expr, Type * type, Designation * designation ) : expr( expr ), designation( designation ) {
684 set_result( type );
685}
686InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
687InitExpr::~InitExpr() {
688 delete expr;
689 delete designation;
690}
691
692void InitExpr::print( std::ostream & os, int indent ) const {
693 os << "Init Expression" << std::endl << std::string( indent+2, ' ' );
694 expr->print( os, indent+2 );
695 os << std::string( indent+2, ' ' ) << "with designation: ";
696 designation->print( os, indent+2 );
697}
698
699
700std::ostream & operator<<( std::ostream & out, const Expression * expr ) {
701 if ( expr ) {
702 expr->print( out );
703 } else {
704 out << "nullptr";
705 }
706 return out;
707}
708
709// Local Variables: //
710// tab-width: 4 //
711// mode: c++ //
712// compile-command: "make install" //
713// End: //
Note: See TracBrowser for help on using the repository browser.