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