source: src/SynTree/Expression.cc@ 982f95d

new-env
Last change on this file since 982f95d was eba74ba, checked in by Aaron Moss <a3moss@…>, 7 years ago

Merge remote-tracking branch 'origin/master' into with_gc

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