[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 |
---|
[d58ebf3] | 11 | // Last Modified By : Rob Schluntz |
---|
[d668182] | 12 | // Last Modified On : Fri May 13 13:23:11 2016 |
---|
[630a82a] | 13 | // Update Count : 40 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include <iostream> |
---|
| 17 | #include <cassert> |
---|
| 18 | #include <list> |
---|
| 19 | #include <algorithm> |
---|
| 20 | |
---|
| 21 | #include <iterator> |
---|
| 22 | |
---|
| 23 | #include "Type.h" |
---|
[630a82a] | 24 | #include "Initializer.h" |
---|
[51b7345] | 25 | #include "Expression.h" |
---|
| 26 | #include "Declaration.h" |
---|
| 27 | #include "Statement.h" |
---|
| 28 | #include "TypeSubstitution.h" |
---|
[d3b7937] | 29 | #include "Common/utility.h" |
---|
[51b7345] | 30 | |
---|
| 31 | |
---|
| 32 | Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {} |
---|
[0dd3a2f] | 33 | |
---|
[d0d9610] | 34 | Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ) { |
---|
[0dd3a2f] | 35 | cloneAll( other.results, results ); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | Expression::~Expression() { |
---|
| 39 | delete env; |
---|
[7f5566b] | 40 | delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix |
---|
[0dd3a2f] | 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 |
---|
[51b7345] | 50 | } |
---|
| 51 | |
---|
[59db689] | 52 | void Expression::print( std::ostream &os, int indent ) const { |
---|
[0dd3a2f] | 53 | if ( env ) { |
---|
[cf0941d] | 54 | os << std::string( indent, ' ' ) << "with environment:" << std::endl; |
---|
[0dd3a2f] | 55 | env->print( os, indent+2 ); |
---|
| 56 | } // if |
---|
[51b7345] | 57 | |
---|
[0dd3a2f] | 58 | if ( argName ) { |
---|
[cf0941d] | 59 | os << std::string( indent, ' ' ) << "with designator:"; |
---|
[0dd3a2f] | 60 | argName->print( os, indent+2 ); |
---|
| 61 | } // if |
---|
[51b7345] | 62 | } |
---|
| 63 | |
---|
[0dd3a2f] | 64 | ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) { |
---|
| 65 | add_result( constant.get_type()->clone() ); |
---|
[51b7345] | 66 | } |
---|
| 67 | |
---|
[0dd3a2f] | 68 | ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) { |
---|
| 69 | } |
---|
[51b7345] | 70 | |
---|
| 71 | ConstantExpr::~ConstantExpr() {} |
---|
| 72 | |
---|
[0dd3a2f] | 73 | void ConstantExpr::print( std::ostream &os, int indent ) const { |
---|
[60089f4] | 74 | os << "constant expression " ; |
---|
[cf0941d] | 75 | constant.print( os ); |
---|
[0dd3a2f] | 76 | Expression::print( os, indent ); |
---|
[51b7345] | 77 | } |
---|
| 78 | |
---|
[0dd3a2f] | 79 | VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) { |
---|
[db4ecc5] | 80 | assert( var ); |
---|
| 81 | assert( var->get_type() ); |
---|
[0dd3a2f] | 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 |
---|
[51b7345] | 86 | } |
---|
| 87 | |
---|
[0dd3a2f] | 88 | VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) { |
---|
[51b7345] | 89 | } |
---|
| 90 | |
---|
[0dd3a2f] | 91 | VariableExpr::~VariableExpr() { |
---|
| 92 | // don't delete the declaration, since it points somewhere else in the tree |
---|
[51b7345] | 93 | } |
---|
| 94 | |
---|
[0dd3a2f] | 95 | void VariableExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 96 | os << "Variable Expression: "; |
---|
[51b7345] | 97 | |
---|
[0dd3a2f] | 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 ); |
---|
[51b7345] | 103 | } |
---|
| 104 | |
---|
| 105 | SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) : |
---|
[0dd3a2f] | 106 | Expression( _aname ), expr(expr_), type(0), isType(false) { |
---|
[bfebb6c5] | 107 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
[51b7345] | 108 | } |
---|
| 109 | |
---|
| 110 | SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) : |
---|
[0dd3a2f] | 111 | Expression( _aname ), expr(0), type(type_), isType(true) { |
---|
[bfebb6c5] | 112 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
[51b7345] | 113 | } |
---|
| 114 | |
---|
[0dd3a2f] | 115 | SizeofExpr::SizeofExpr( const SizeofExpr &other ) : |
---|
| 116 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { |
---|
[51b7345] | 117 | } |
---|
| 118 | |
---|
[0dd3a2f] | 119 | SizeofExpr::~SizeofExpr() { |
---|
| 120 | delete expr; |
---|
| 121 | delete type; |
---|
[51b7345] | 122 | } |
---|
| 123 | |
---|
| 124 | void SizeofExpr::print( std::ostream &os, int indent) const { |
---|
[89231bc] | 125 | os << "Sizeof Expression on: "; |
---|
[51b7345] | 126 | |
---|
[47534159] | 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) { |
---|
[bfebb6c5] | 138 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
[47534159] | 139 | } |
---|
| 140 | |
---|
| 141 | AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) : |
---|
| 142 | Expression( _aname ), expr(0), type(type_), isType(true) { |
---|
[bfebb6c5] | 143 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
[47534159] | 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 | |
---|
[0dd3a2f] | 158 | if (isType) |
---|
| 159 | type->print(os, indent + 2); |
---|
| 160 | else |
---|
| 161 | expr->print(os, indent + 2); |
---|
[51b7345] | 162 | |
---|
[0dd3a2f] | 163 | os << std::endl; |
---|
| 164 | Expression::print( os, indent ); |
---|
[51b7345] | 165 | } |
---|
| 166 | |
---|
[2a4b088] | 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 | |
---|
[25a054f] | 192 | OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) : |
---|
| 193 | Expression( _aname ), type(type_), member(member_) { |
---|
[bfebb6c5] | 194 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); |
---|
[25a054f] | 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 | |
---|
[afc1045] | 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 | |
---|
[25a054f] | 243 | os << std::endl; |
---|
| 244 | Expression::print( os, indent ); |
---|
| 245 | } |
---|
| 246 | |
---|
[51b7345] | 247 | AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) : |
---|
[0dd3a2f] | 248 | Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) { |
---|
[51b7345] | 249 | } |
---|
| 250 | |
---|
| 251 | AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) : |
---|
[0dd3a2f] | 252 | Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) { |
---|
[51b7345] | 253 | } |
---|
| 254 | |
---|
[0dd3a2f] | 255 | AttrExpr::AttrExpr( const AttrExpr &other ) : |
---|
| 256 | Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { |
---|
[51b7345] | 257 | } |
---|
| 258 | |
---|
[0dd3a2f] | 259 | AttrExpr::~AttrExpr() { |
---|
| 260 | delete attr; |
---|
| 261 | delete expr; |
---|
| 262 | delete type; |
---|
[51b7345] | 263 | } |
---|
| 264 | |
---|
| 265 | void AttrExpr::print( std::ostream &os, int indent) const { |
---|
[44b5ca0] | 266 | os << std::string( indent, ' ' ) << "Attr "; |
---|
[0dd3a2f] | 267 | attr->print( os, indent + 2 ); |
---|
| 268 | if ( isType || expr ) { |
---|
| 269 | os << "applied to: "; |
---|
[51b7345] | 270 | |
---|
[0dd3a2f] | 271 | if (isType) |
---|
| 272 | type->print(os, indent + 2); |
---|
| 273 | else |
---|
| 274 | expr->print(os, indent + 2); |
---|
| 275 | } // if |
---|
[51b7345] | 276 | |
---|
[0dd3a2f] | 277 | os << std::endl; |
---|
| 278 | Expression::print( os, indent ); |
---|
[51b7345] | 279 | } |
---|
| 280 | |
---|
[0dd3a2f] | 281 | CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { |
---|
| 282 | add_result(toType); |
---|
[51b7345] | 283 | } |
---|
| 284 | |
---|
| 285 | CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) { |
---|
| 286 | } |
---|
| 287 | |
---|
[0dd3a2f] | 288 | CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { |
---|
[51b7345] | 289 | } |
---|
| 290 | |
---|
| 291 | CastExpr::~CastExpr() { |
---|
[0dd3a2f] | 292 | delete arg; |
---|
[51b7345] | 293 | } |
---|
| 294 | |
---|
| 295 | // CastExpr *CastExpr::clone() const { return 0; } |
---|
| 296 | |
---|
| 297 | void CastExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 298 | os << "Cast of:" << std::endl << std::string( indent+2, ' ' ); |
---|
[0dd3a2f] | 299 | arg->print(os, indent+2); |
---|
[44b5ca0] | 300 | os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl; |
---|
[0dd3a2f] | 301 | if ( results.empty() ) { |
---|
[44b5ca0] | 302 | os << std::string( indent+2, ' ' ) << "nothing" << std::endl; |
---|
[0dd3a2f] | 303 | } else { |
---|
| 304 | printAll(results, os, indent+2); |
---|
| 305 | } // if |
---|
| 306 | Expression::print( os, indent ); |
---|
| 307 | } |
---|
| 308 | |
---|
[51b7345] | 309 | UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) : |
---|
[0dd3a2f] | 310 | Expression( _aname ), member(_member), aggregate(_aggregate) {} |
---|
[51b7345] | 311 | |
---|
[0dd3a2f] | 312 | UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : |
---|
| 313 | Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { |
---|
[51b7345] | 314 | } |
---|
| 315 | |
---|
| 316 | UntypedMemberExpr::~UntypedMemberExpr() { |
---|
[0dd3a2f] | 317 | delete aggregate; |
---|
[51b7345] | 318 | } |
---|
| 319 | |
---|
| 320 | void UntypedMemberExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 321 | os << "Untyped Member Expression, with field: " << get_member(); |
---|
[51b7345] | 322 | |
---|
[0dd3a2f] | 323 | Expression *agg = get_aggregate(); |
---|
[9243a501] | 324 | os << ", from aggregate: "; |
---|
[89231bc] | 325 | if (agg != 0) { |
---|
[bb8ea30] | 326 | os << std::string( indent + 2, ' ' ); |
---|
[89231bc] | 327 | agg->print(os, indent + 2); |
---|
| 328 | } |
---|
| 329 | os << std::string( indent+2, ' ' ); |
---|
[0dd3a2f] | 330 | Expression::print( os, indent ); |
---|
[51b7345] | 331 | } |
---|
| 332 | |
---|
| 333 | |
---|
| 334 | MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : |
---|
[0dd3a2f] | 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 |
---|
[51b7345] | 340 | } |
---|
| 341 | |
---|
[0dd3a2f] | 342 | MemberExpr::MemberExpr( const MemberExpr &other ) : |
---|
| 343 | Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { |
---|
[51b7345] | 344 | } |
---|
| 345 | |
---|
| 346 | MemberExpr::~MemberExpr() { |
---|
[0dd3a2f] | 347 | delete member; |
---|
| 348 | delete aggregate; |
---|
[51b7345] | 349 | } |
---|
| 350 | |
---|
| 351 | void MemberExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 352 | os << "Member Expression, with field: " << std::endl; |
---|
[51b7345] | 353 | |
---|
[0dd3a2f] | 354 | assert( member ); |
---|
[44b5ca0] | 355 | os << std::string( indent + 2, ' ' ); |
---|
[0dd3a2f] | 356 | member->print( os, indent + 2 ); |
---|
| 357 | os << std::endl; |
---|
[51b7345] | 358 | |
---|
[0dd3a2f] | 359 | Expression *agg = get_aggregate(); |
---|
[44b5ca0] | 360 | os << std::string( indent, ' ' ) << "from aggregate: " << std::endl; |
---|
[89231bc] | 361 | if (agg != 0) { |
---|
[bb8ea30] | 362 | os << std::string( indent + 2, ' ' ); |
---|
[89231bc] | 363 | agg->print(os, indent + 2); |
---|
| 364 | } |
---|
| 365 | os << std::string( indent+2, ' ' ); |
---|
[0dd3a2f] | 366 | Expression::print( os, indent ); |
---|
[51b7345] | 367 | } |
---|
| 368 | |
---|
| 369 | |
---|
| 370 | UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {} |
---|
| 371 | |
---|
[0dd3a2f] | 372 | UntypedExpr::UntypedExpr( const UntypedExpr &other ) : |
---|
| 373 | Expression( other ), function( maybeClone( other.function ) ) { |
---|
| 374 | cloneAll( other.args, args ); |
---|
[51b7345] | 375 | } |
---|
| 376 | |
---|
| 377 | UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) : |
---|
[0dd3a2f] | 378 | Expression( _aname ), function(_function), args(_args) {} |
---|
[51b7345] | 379 | |
---|
| 380 | UntypedExpr::~UntypedExpr() {} |
---|
| 381 | |
---|
| 382 | void UntypedExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 383 | os << "Applying untyped: " << std::endl; |
---|
[bb8ea30] | 384 | os << std::string( indent+2, ' ' ); |
---|
| 385 | function->print(os, indent + 2); |
---|
[44b5ca0] | 386 | os << std::string( indent, ' ' ) << "...to: " << std::endl; |
---|
[bb8ea30] | 387 | printAll(args, os, indent + 2); |
---|
[0dd3a2f] | 388 | Expression::print( os, indent ); |
---|
[51b7345] | 389 | } |
---|
| 390 | |
---|
[0dd3a2f] | 391 | void UntypedExpr::printArgs( std::ostream &os, int indent ) const { |
---|
| 392 | std::list<Expression *>::const_iterator i; |
---|
[60089f4] | 393 | for (i = args.begin(); i != args.end(); i++) { |
---|
| 394 | os << std::string(indent, ' ' ); |
---|
[0dd3a2f] | 395 | (*i)->print(os, indent); |
---|
[60089f4] | 396 | } |
---|
[51b7345] | 397 | } |
---|
| 398 | |
---|
| 399 | NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {} |
---|
| 400 | |
---|
[0dd3a2f] | 401 | NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) { |
---|
[51b7345] | 402 | } |
---|
| 403 | |
---|
| 404 | NameExpr::~NameExpr() {} |
---|
| 405 | |
---|
| 406 | void NameExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 407 | os << "Name: " << get_name() << std::endl; |
---|
[0dd3a2f] | 408 | Expression::print( os, indent ); |
---|
[51b7345] | 409 | } |
---|
| 410 | |
---|
| 411 | LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : |
---|
[0dd3a2f] | 412 | Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { |
---|
| 413 | add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); |
---|
[51b7345] | 414 | } |
---|
| 415 | |
---|
[0dd3a2f] | 416 | LogicalExpr::LogicalExpr( const LogicalExpr &other ) : |
---|
| 417 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { |
---|
[51b7345] | 418 | } |
---|
| 419 | |
---|
[a08ba92] | 420 | LogicalExpr::~LogicalExpr() { |
---|
[0dd3a2f] | 421 | delete arg1; |
---|
| 422 | delete arg2; |
---|
[51b7345] | 423 | } |
---|
| 424 | |
---|
| 425 | void LogicalExpr::print( std::ostream &os, int indent )const { |
---|
[44b5ca0] | 426 | os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; |
---|
[0dd3a2f] | 427 | arg1->print(os); |
---|
| 428 | os << " and "; |
---|
| 429 | arg2->print(os); |
---|
| 430 | os << std::endl; |
---|
| 431 | Expression::print( os, indent ); |
---|
[51b7345] | 432 | } |
---|
| 433 | |
---|
| 434 | ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) : |
---|
[0dd3a2f] | 435 | Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {} |
---|
[51b7345] | 436 | |
---|
[0dd3a2f] | 437 | ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : |
---|
| 438 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { |
---|
| 439 | } |
---|
[51b7345] | 440 | |
---|
| 441 | ConditionalExpr::~ConditionalExpr() { |
---|
[0dd3a2f] | 442 | delete arg1; |
---|
| 443 | delete arg2; |
---|
| 444 | delete arg3; |
---|
[51b7345] | 445 | } |
---|
| 446 | |
---|
| 447 | void ConditionalExpr::print( std::ostream &os, int indent ) const { |
---|
[44b5ca0] | 448 | os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl; |
---|
[0dd3a2f] | 449 | arg1->print( os, indent+2 ); |
---|
[44b5ca0] | 450 | os << std::string( indent, ' ' ) << "First alternative:" << std::endl; |
---|
[0dd3a2f] | 451 | arg2->print( os, indent+2 ); |
---|
[44b5ca0] | 452 | os << std::string( indent, ' ' ) << "Second alternative:" << std::endl; |
---|
[0dd3a2f] | 453 | arg3->print( os, indent+2 ); |
---|
| 454 | os << std::endl; |
---|
| 455 | Expression::print( os, indent ); |
---|
| 456 | } |
---|
| 457 | |
---|
[3be261a] | 458 | AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {} |
---|
| 459 | |
---|
| 460 | |
---|
[7f5566b] | 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 | |
---|
[db4ecc5] | 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); |
---|
[dc2e7e0] | 493 | os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl; |
---|
| 494 | printAll(returnDecls, os, indent+2); |
---|
[db4ecc5] | 495 | Expression::print( os, indent ); |
---|
| 496 | } |
---|
| 497 | |
---|
[3be261a] | 498 | UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {} |
---|
| 499 | |
---|
| 500 | UntypedValofExpr::~UntypedValofExpr() { delete body; } |
---|
| 501 | |
---|
[0dd3a2f] | 502 | void UntypedValofExpr::print( std::ostream &os, int indent ) const { |
---|
[44b5ca0] | 503 | os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl; |
---|
[0dd3a2f] | 504 | if ( get_body() != 0 ) |
---|
| 505 | get_body()->print( os, indent + 2 ); |
---|
| 506 | } |
---|
| 507 | |
---|
[3be261a] | 508 | |
---|
[630a82a] | 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 | |
---|
[3be261a] | 526 | |
---|
[baf7fee] | 527 | std::ostream & operator<<( std::ostream & out, Expression * expr ) { |
---|
| 528 | expr->print( out ); |
---|
| 529 | return out; |
---|
| 530 | } |
---|
| 531 | |
---|
[0dd3a2f] | 532 | // Local Variables: // |
---|
| 533 | // tab-width: 4 // |
---|
| 534 | // mode: c++ // |
---|
| 535 | // compile-command: "make install" // |
---|
| 536 | // End: // |
---|