source: src/SynTree/Expression.cc@ 274ce8c

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 274ce8c was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Big header cleaning pass - commit 3

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