source: src/SynTree/Expression.cc@ 6a276a0

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 with_gc
Last change on this file since 6a276a0 was 9bfc9da, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Refactor makeSub into genericSubstitution

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