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 : Fri Aug 5 14:23:56 2016 |
---|
13 | // Update Count : 49 |
---|
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 | |
---|
31 | |
---|
32 | Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {} |
---|
33 | |
---|
34 | Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) { |
---|
35 | cloneAll( other.results, results ); |
---|
36 | } |
---|
37 | |
---|
38 | Expression::~Expression() { |
---|
39 | delete env; |
---|
40 | delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix |
---|
41 | deleteAll( results ); |
---|
42 | } |
---|
43 | |
---|
44 | void Expression::add_result( Type *t ) { |
---|
45 | if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) { |
---|
46 | std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) ); |
---|
47 | } else { |
---|
48 | results.push_back(t); |
---|
49 | } // if |
---|
50 | } |
---|
51 | |
---|
52 | void Expression::print( std::ostream &os, int indent ) const { |
---|
53 | if ( env ) { |
---|
54 | os << std::string( indent, ' ' ) << "with environment:" << std::endl; |
---|
55 | env->print( os, indent+2 ); |
---|
56 | } // if |
---|
57 | |
---|
58 | if ( argName ) { |
---|
59 | os << std::string( indent, ' ' ) << "with designator:"; |
---|
60 | argName->print( os, indent+2 ); |
---|
61 | } // if |
---|
62 | |
---|
63 | if ( extension ) { |
---|
64 | os << std::string( indent, ' ' ) << "with extension:"; |
---|
65 | } // if |
---|
66 | } |
---|
67 | |
---|
68 | ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) { |
---|
69 | add_result( constant.get_type()->clone() ); |
---|
70 | } |
---|
71 | |
---|
72 | ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) { |
---|
73 | } |
---|
74 | |
---|
75 | ConstantExpr::~ConstantExpr() {} |
---|
76 | |
---|
77 | void ConstantExpr::print( std::ostream &os, int indent ) const { |
---|
78 | os << "constant expression " ; |
---|
79 | constant.print( os ); |
---|
80 | Expression::print( os, indent ); |
---|
81 | } |
---|
82 | |
---|
83 | VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) { |
---|
84 | assert( var ); |
---|
85 | assert( var->get_type() ); |
---|
86 | add_result( var->get_type()->clone() ); |
---|
87 | for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { |
---|
88 | (*i)->set_isLvalue( true ); |
---|
89 | } // for |
---|
90 | } |
---|
91 | |
---|
92 | VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) { |
---|
93 | } |
---|
94 | |
---|
95 | VariableExpr::~VariableExpr() { |
---|
96 | // don't delete the declaration, since it points somewhere else in the tree |
---|
97 | } |
---|
98 | |
---|
99 | void VariableExpr::print( std::ostream &os, int indent ) const { |
---|
100 | os << "Variable Expression: "; |
---|
101 | |
---|
102 | Declaration *decl = get_var(); |
---|
103 | // if ( decl != 0) decl->print(os, indent + 2); |
---|
104 | if ( decl != 0) decl->printShort(os, indent + 2); |
---|
105 | os << std::endl; |
---|
106 | Expression::print( os, indent ); |
---|
107 | } |
---|
108 | |
---|
109 | SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) : |
---|
110 | Expression( _aname ), expr(expr_), type(0), isType(false) { |
---|
111 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
112 | } |
---|
113 | |
---|
114 | SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) : |
---|
115 | Expression( _aname ), expr(0), type(type_), isType(true) { |
---|
116 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
117 | } |
---|
118 | |
---|
119 | SizeofExpr::SizeofExpr( const SizeofExpr &other ) : |
---|
120 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { |
---|
121 | } |
---|
122 | |
---|
123 | SizeofExpr::~SizeofExpr() { |
---|
124 | delete expr; |
---|
125 | delete type; |
---|
126 | } |
---|
127 | |
---|
128 | void SizeofExpr::print( std::ostream &os, int indent) const { |
---|
129 | os << "Sizeof Expression on: "; |
---|
130 | |
---|
131 | if (isType) |
---|
132 | type->print(os, indent + 2); |
---|
133 | else |
---|
134 | expr->print(os, indent + 2); |
---|
135 | |
---|
136 | os << std::endl; |
---|
137 | Expression::print( os, indent ); |
---|
138 | } |
---|
139 | |
---|
140 | AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) : |
---|
141 | Expression( _aname ), expr(expr_), type(0), isType(false) { |
---|
142 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
143 | } |
---|
144 | |
---|
145 | AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) : |
---|
146 | Expression( _aname ), expr(0), type(type_), isType(true) { |
---|
147 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
148 | } |
---|
149 | |
---|
150 | AlignofExpr::AlignofExpr( const AlignofExpr &other ) : |
---|
151 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { |
---|
152 | } |
---|
153 | |
---|
154 | AlignofExpr::~AlignofExpr() { |
---|
155 | delete expr; |
---|
156 | delete type; |
---|
157 | } |
---|
158 | |
---|
159 | void AlignofExpr::print( std::ostream &os, int indent) const { |
---|
160 | os << std::string( indent, ' ' ) << "Alignof Expression on: "; |
---|
161 | |
---|
162 | if (isType) |
---|
163 | type->print(os, indent + 2); |
---|
164 | else |
---|
165 | expr->print(os, indent + 2); |
---|
166 | |
---|
167 | os << std::endl; |
---|
168 | Expression::print( os, indent ); |
---|
169 | } |
---|
170 | |
---|
171 | UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) : |
---|
172 | Expression( _aname ), type(type_), member(member_) { |
---|
173 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
174 | } |
---|
175 | |
---|
176 | UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) : |
---|
177 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} |
---|
178 | |
---|
179 | UntypedOffsetofExpr::~UntypedOffsetofExpr() { |
---|
180 | delete type; |
---|
181 | } |
---|
182 | |
---|
183 | void UntypedOffsetofExpr::print( std::ostream &os, int indent) const { |
---|
184 | os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of "; |
---|
185 | |
---|
186 | if ( type ) { |
---|
187 | type->print(os, indent + 2); |
---|
188 | } else { |
---|
189 | os << "<NULL>"; |
---|
190 | } |
---|
191 | |
---|
192 | os << std::endl; |
---|
193 | Expression::print( os, indent ); |
---|
194 | } |
---|
195 | |
---|
196 | OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) : |
---|
197 | Expression( _aname ), type(type_), member(member_) { |
---|
198 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
199 | } |
---|
200 | |
---|
201 | OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) : |
---|
202 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} |
---|
203 | |
---|
204 | OffsetofExpr::~OffsetofExpr() { |
---|
205 | delete type; |
---|
206 | } |
---|
207 | |
---|
208 | void OffsetofExpr::print( std::ostream &os, int indent) const { |
---|
209 | os << std::string( indent, ' ' ) << "Offsetof Expression on member "; |
---|
210 | |
---|
211 | if ( member ) { |
---|
212 | os << member->get_name(); |
---|
213 | } else { |
---|
214 | os << "<NULL>"; |
---|
215 | } |
---|
216 | |
---|
217 | os << " of "; |
---|
218 | |
---|
219 | if ( type ) { |
---|
220 | type->print(os, indent + 2); |
---|
221 | } else { |
---|
222 | os << "<NULL>"; |
---|
223 | } |
---|
224 | |
---|
225 | os << std::endl; |
---|
226 | Expression::print( os, indent ); |
---|
227 | } |
---|
228 | |
---|
229 | OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) { |
---|
230 | add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); |
---|
231 | } |
---|
232 | |
---|
233 | OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {} |
---|
234 | |
---|
235 | OffsetPackExpr::~OffsetPackExpr() { delete type; } |
---|
236 | |
---|
237 | void OffsetPackExpr::print( std::ostream &os, int indent ) const { |
---|
238 | os << std::string( indent, ' ' ) << "Offset pack expression on "; |
---|
239 | |
---|
240 | if ( type ) { |
---|
241 | type->print(os, indent + 2); |
---|
242 | } else { |
---|
243 | os << "<NULL>"; |
---|
244 | } |
---|
245 | |
---|
246 | os << std::endl; |
---|
247 | Expression::print( os, indent ); |
---|
248 | } |
---|
249 | |
---|
250 | AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) : |
---|
251 | Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) { |
---|
252 | } |
---|
253 | |
---|
254 | AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) : |
---|
255 | Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) { |
---|
256 | } |
---|
257 | |
---|
258 | AttrExpr::AttrExpr( const AttrExpr &other ) : |
---|
259 | Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { |
---|
260 | } |
---|
261 | |
---|
262 | AttrExpr::~AttrExpr() { |
---|
263 | delete attr; |
---|
264 | delete expr; |
---|
265 | delete type; |
---|
266 | } |
---|
267 | |
---|
268 | void AttrExpr::print( std::ostream &os, int indent) const { |
---|
269 | os << std::string( indent, ' ' ) << "Attr "; |
---|
270 | attr->print( os, indent + 2 ); |
---|
271 | if ( isType || expr ) { |
---|
272 | os << "applied to: "; |
---|
273 | |
---|
274 | if (isType) |
---|
275 | type->print(os, indent + 2); |
---|
276 | else |
---|
277 | expr->print(os, indent + 2); |
---|
278 | } // if |
---|
279 | |
---|
280 | os << std::endl; |
---|
281 | Expression::print( os, indent ); |
---|
282 | } |
---|
283 | |
---|
284 | CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { |
---|
285 | add_result(toType); |
---|
286 | } |
---|
287 | |
---|
288 | CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) { |
---|
289 | } |
---|
290 | |
---|
291 | CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { |
---|
292 | } |
---|
293 | |
---|
294 | CastExpr::~CastExpr() { |
---|
295 | delete arg; |
---|
296 | } |
---|
297 | |
---|
298 | // CastExpr *CastExpr::clone() const { return 0; } |
---|
299 | |
---|
300 | void CastExpr::print( std::ostream &os, int indent ) const { |
---|
301 | os << "Cast of:" << std::endl << std::string( indent+2, ' ' ); |
---|
302 | arg->print(os, indent+2); |
---|
303 | os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl; |
---|
304 | if ( results.empty() ) { |
---|
305 | os << std::string( indent+2, ' ' ) << "nothing" << std::endl; |
---|
306 | } else { |
---|
307 | printAll(results, os, indent+2); |
---|
308 | } // if |
---|
309 | Expression::print( os, indent ); |
---|
310 | } |
---|
311 | |
---|
312 | UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) : |
---|
313 | Expression( _aname ), member(_member), aggregate(_aggregate) {} |
---|
314 | |
---|
315 | UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : |
---|
316 | Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { |
---|
317 | } |
---|
318 | |
---|
319 | UntypedMemberExpr::~UntypedMemberExpr() { |
---|
320 | delete aggregate; |
---|
321 | } |
---|
322 | |
---|
323 | void UntypedMemberExpr::print( std::ostream &os, int indent ) const { |
---|
324 | os << "Untyped Member Expression, with field: " << get_member(); |
---|
325 | |
---|
326 | Expression *agg = get_aggregate(); |
---|
327 | os << ", from aggregate: "; |
---|
328 | if (agg != 0) { |
---|
329 | os << std::string( indent + 2, ' ' ); |
---|
330 | agg->print(os, indent + 2); |
---|
331 | } |
---|
332 | os << std::string( indent+2, ' ' ); |
---|
333 | Expression::print( os, indent ); |
---|
334 | } |
---|
335 | |
---|
336 | |
---|
337 | MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : |
---|
338 | Expression( _aname ), member(_member), aggregate(_aggregate) { |
---|
339 | add_result( member->get_type()->clone() ); |
---|
340 | for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { |
---|
341 | (*i)->set_isLvalue( true ); |
---|
342 | } // for |
---|
343 | } |
---|
344 | |
---|
345 | //// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned... |
---|
346 | MemberExpr::MemberExpr( const MemberExpr &other ) : |
---|
347 | Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { |
---|
348 | } |
---|
349 | |
---|
350 | MemberExpr::~MemberExpr() { |
---|
351 | // delete member; |
---|
352 | delete aggregate; |
---|
353 | } |
---|
354 | |
---|
355 | void MemberExpr::print( std::ostream &os, int indent ) const { |
---|
356 | os << "Member Expression, with field: " << std::endl; |
---|
357 | |
---|
358 | assert( member ); |
---|
359 | os << std::string( indent + 2, ' ' ); |
---|
360 | member->print( os, indent + 2 ); |
---|
361 | os << std::endl; |
---|
362 | |
---|
363 | Expression *agg = get_aggregate(); |
---|
364 | os << std::string( indent, ' ' ) << "from aggregate: " << std::endl; |
---|
365 | if (agg != 0) { |
---|
366 | os << std::string( indent + 2, ' ' ); |
---|
367 | agg->print(os, indent + 2); |
---|
368 | } |
---|
369 | os << std::string( indent+2, ' ' ); |
---|
370 | Expression::print( os, indent ); |
---|
371 | } |
---|
372 | |
---|
373 | |
---|
374 | UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {} |
---|
375 | |
---|
376 | UntypedExpr::UntypedExpr( const UntypedExpr &other ) : |
---|
377 | Expression( other ), function( maybeClone( other.function ) ) { |
---|
378 | cloneAll( other.args, args ); |
---|
379 | } |
---|
380 | |
---|
381 | UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) : |
---|
382 | Expression( _aname ), function(_function), args(_args) {} |
---|
383 | |
---|
384 | UntypedExpr::~UntypedExpr() { |
---|
385 | delete function; |
---|
386 | deleteAll( args ); |
---|
387 | } |
---|
388 | |
---|
389 | void UntypedExpr::print( std::ostream &os, int indent ) const { |
---|
390 | os << "Applying untyped: " << std::endl; |
---|
391 | os << std::string( indent+2, ' ' ); |
---|
392 | function->print(os, indent + 2); |
---|
393 | os << std::string( indent, ' ' ) << "...to: " << std::endl; |
---|
394 | printAll(args, os, indent + 2); |
---|
395 | Expression::print( os, indent ); |
---|
396 | } |
---|
397 | |
---|
398 | void UntypedExpr::printArgs( std::ostream &os, int indent ) const { |
---|
399 | std::list<Expression *>::const_iterator i; |
---|
400 | for (i = args.begin(); i != args.end(); i++) { |
---|
401 | os << std::string(indent, ' ' ); |
---|
402 | (*i)->print(os, indent); |
---|
403 | } |
---|
404 | } |
---|
405 | |
---|
406 | NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {} |
---|
407 | |
---|
408 | NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) { |
---|
409 | } |
---|
410 | |
---|
411 | NameExpr::~NameExpr() {} |
---|
412 | |
---|
413 | void NameExpr::print( std::ostream &os, int indent ) const { |
---|
414 | os << "Name: " << get_name() << std::endl; |
---|
415 | Expression::print( os, indent ); |
---|
416 | } |
---|
417 | |
---|
418 | LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : |
---|
419 | Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { |
---|
420 | add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); |
---|
421 | } |
---|
422 | |
---|
423 | LogicalExpr::LogicalExpr( const LogicalExpr &other ) : |
---|
424 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { |
---|
425 | } |
---|
426 | |
---|
427 | LogicalExpr::~LogicalExpr() { |
---|
428 | delete arg1; |
---|
429 | delete arg2; |
---|
430 | } |
---|
431 | |
---|
432 | void LogicalExpr::print( std::ostream &os, int indent )const { |
---|
433 | os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; |
---|
434 | arg1->print(os); |
---|
435 | os << " and "; |
---|
436 | arg2->print(os); |
---|
437 | os << std::endl; |
---|
438 | Expression::print( os, indent ); |
---|
439 | } |
---|
440 | |
---|
441 | ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) : |
---|
442 | Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {} |
---|
443 | |
---|
444 | ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : |
---|
445 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { |
---|
446 | } |
---|
447 | |
---|
448 | ConditionalExpr::~ConditionalExpr() { |
---|
449 | delete arg1; |
---|
450 | delete arg2; |
---|
451 | delete arg3; |
---|
452 | } |
---|
453 | |
---|
454 | void ConditionalExpr::print( std::ostream &os, int indent ) const { |
---|
455 | os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl; |
---|
456 | arg1->print( os, indent+2 ); |
---|
457 | os << std::string( indent, ' ' ) << "First alternative:" << std::endl; |
---|
458 | arg2->print( os, indent+2 ); |
---|
459 | os << std::string( indent, ' ' ) << "Second alternative:" << std::endl; |
---|
460 | arg3->print( os, indent+2 ); |
---|
461 | os << std::endl; |
---|
462 | Expression::print( os, indent ); |
---|
463 | } |
---|
464 | |
---|
465 | AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {} |
---|
466 | |
---|
467 | |
---|
468 | void AsmExpr::print( std::ostream &os, int indent ) const { |
---|
469 | os << "Asm Expression: " << std::endl; |
---|
470 | if ( inout ) inout->print( os, indent + 2 ); |
---|
471 | if ( constraint ) constraint->print( os, indent + 2 ); |
---|
472 | if ( operand ) operand->print( os, indent + 2 ); |
---|
473 | } |
---|
474 | |
---|
475 | |
---|
476 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) { |
---|
477 | assert( callExpr ); |
---|
478 | cloneAll( callExpr->get_results(), results ); |
---|
479 | } |
---|
480 | |
---|
481 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) { |
---|
482 | cloneAll( other.tempDecls, tempDecls ); |
---|
483 | cloneAll( other.returnDecls, returnDecls ); |
---|
484 | cloneAll( other.dtors, dtors ); |
---|
485 | } |
---|
486 | |
---|
487 | ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() { |
---|
488 | delete callExpr; |
---|
489 | deleteAll( tempDecls ); |
---|
490 | deleteAll( returnDecls ); |
---|
491 | deleteAll( dtors ); |
---|
492 | } |
---|
493 | |
---|
494 | void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const { |
---|
495 | os << std::string( indent, ' ' ) << "Implicit Copy Constructor Expression: " << std::endl; |
---|
496 | assert( callExpr ); |
---|
497 | callExpr->print( os, indent + 2 ); |
---|
498 | os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl; |
---|
499 | printAll(tempDecls, os, indent+2); |
---|
500 | os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl; |
---|
501 | printAll(returnDecls, os, indent+2); |
---|
502 | Expression::print( os, indent ); |
---|
503 | } |
---|
504 | |
---|
505 | UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {} |
---|
506 | |
---|
507 | UntypedValofExpr::~UntypedValofExpr() { delete body; } |
---|
508 | |
---|
509 | void UntypedValofExpr::print( std::ostream &os, int indent ) const { |
---|
510 | os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl; |
---|
511 | if ( get_body() != 0 ) |
---|
512 | get_body()->print( os, indent + 2 ); |
---|
513 | } |
---|
514 | |
---|
515 | |
---|
516 | CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) { |
---|
517 | add_result( type->clone() ); |
---|
518 | } |
---|
519 | |
---|
520 | CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {} |
---|
521 | |
---|
522 | CompoundLiteralExpr::~CompoundLiteralExpr() { |
---|
523 | delete initializer; |
---|
524 | delete type; |
---|
525 | } |
---|
526 | |
---|
527 | void CompoundLiteralExpr::print( std::ostream &os, int indent ) const { |
---|
528 | os << "Compound Literal Expression: " << std::endl; |
---|
529 | if ( type ) type->print( os, indent + 2 ); |
---|
530 | if ( initializer ) initializer->print( os, indent + 2 ); |
---|
531 | } |
---|
532 | |
---|
533 | RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} |
---|
534 | RangeExpr::RangeExpr( const RangeExpr &other ) : low( other.low->clone() ), high( other.high->clone() ) {} |
---|
535 | void RangeExpr::print( std::ostream &os, int indent ) const { |
---|
536 | os << std::string( indent, ' ' ) << "Range Expression: "; |
---|
537 | low->print( os, indent ); |
---|
538 | os << " ... "; |
---|
539 | high->print( os, indent ); |
---|
540 | } |
---|
541 | |
---|
542 | std::ostream & operator<<( std::ostream & out, const Expression * expr ) { |
---|
543 | expr->print( out ); |
---|
544 | return out; |
---|
545 | } |
---|
546 | |
---|
547 | // Local Variables: // |
---|
548 | // tab-width: 4 // |
---|
549 | // mode: c++ // |
---|
550 | // compile-command: "make install" // |
---|
551 | // End: // |
---|