source: src/SynTree/Expression.cc@ f6582243

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

Merge branch 'master' into references

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