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