[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 |
---|
| 12 | // Last Modified On : Mon Jun 13 16:03:39 2016 |
---|
| 13 | // Update Count : 42 |
---|
[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 ) : |
---|
| 202 | Expression( other ), type( maybeClone( other.type ) ), member( maybeClone( other.member ) ) {} |
---|
| 203 | |
---|
| 204 | OffsetofExpr::~OffsetofExpr() { |
---|
| 205 | delete type; |
---|
| 206 | delete member; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | void OffsetofExpr::print( std::ostream &os, int indent) const { |
---|
| 210 | os << std::string( indent, ' ' ) << "Offsetof Expression on member "; |
---|
| 211 | |
---|
| 212 | if ( member ) { |
---|
| 213 | os << member->get_name(); |
---|
| 214 | } else { |
---|
| 215 | os << "<NULL>"; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | os << " of "; |
---|
| 219 | |
---|
| 220 | if ( type ) { |
---|
| 221 | type->print(os, indent + 2); |
---|
| 222 | } else { |
---|
| 223 | os << "<NULL>"; |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | os << std::endl; |
---|
| 227 | Expression::print( os, indent ); |
---|
| 228 | } |
---|
| 229 | |
---|
[afc1045] | 230 | OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) { |
---|
| 231 | add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {} |
---|
| 235 | |
---|
| 236 | OffsetPackExpr::~OffsetPackExpr() { delete type; } |
---|
| 237 | |
---|
| 238 | void OffsetPackExpr::print( std::ostream &os, int indent ) const { |
---|
| 239 | os << std::string( indent, ' ' ) << "Offset pack expression on "; |
---|
| 240 | |
---|
| 241 | if ( type ) { |
---|
| 242 | type->print(os, indent + 2); |
---|
| 243 | } else { |
---|
| 244 | os << "<NULL>"; |
---|
| 245 | } |
---|
| 246 | |
---|
[25a054f] | 247 | os << std::endl; |
---|
| 248 | Expression::print( os, indent ); |
---|
| 249 | } |
---|
| 250 | |
---|
[51b7345] | 251 | AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) : |
---|
[0dd3a2f] | 252 | Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) { |
---|
[51b7345] | 253 | } |
---|
| 254 | |
---|
| 255 | AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) : |
---|
[0dd3a2f] | 256 | Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) { |
---|
[51b7345] | 257 | } |
---|
| 258 | |
---|
[0dd3a2f] | 259 | AttrExpr::AttrExpr( const AttrExpr &other ) : |
---|
| 260 | Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { |
---|
[51b7345] | 261 | } |
---|
| 262 | |
---|
[0dd3a2f] | 263 | AttrExpr::~AttrExpr() { |
---|
| 264 | delete attr; |
---|
| 265 | delete expr; |
---|
| 266 | delete type; |
---|
[51b7345] | 267 | } |
---|
| 268 | |
---|
| 269 | void AttrExpr::print( std::ostream &os, int indent) const { |
---|
[44b5ca0] | 270 | os << std::string( indent, ' ' ) << "Attr "; |
---|
[0dd3a2f] | 271 | attr->print( os, indent + 2 ); |
---|
| 272 | if ( isType || expr ) { |
---|
| 273 | os << "applied to: "; |
---|
[51b7345] | 274 | |
---|
[0dd3a2f] | 275 | if (isType) |
---|
| 276 | type->print(os, indent + 2); |
---|
| 277 | else |
---|
| 278 | expr->print(os, indent + 2); |
---|
| 279 | } // if |
---|
[51b7345] | 280 | |
---|
[0dd3a2f] | 281 | os << std::endl; |
---|
| 282 | Expression::print( os, indent ); |
---|
[51b7345] | 283 | } |
---|
| 284 | |
---|
[0dd3a2f] | 285 | CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { |
---|
| 286 | add_result(toType); |
---|
[51b7345] | 287 | } |
---|
| 288 | |
---|
| 289 | CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) { |
---|
| 290 | } |
---|
| 291 | |
---|
[0dd3a2f] | 292 | CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { |
---|
[51b7345] | 293 | } |
---|
| 294 | |
---|
| 295 | CastExpr::~CastExpr() { |
---|
[0dd3a2f] | 296 | delete arg; |
---|
[51b7345] | 297 | } |
---|
| 298 | |
---|
| 299 | // CastExpr *CastExpr::clone() const { return 0; } |
---|
| 300 | |
---|
| 301 | void CastExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 302 | os << "Cast of:" << std::endl << std::string( indent+2, ' ' ); |
---|
[0dd3a2f] | 303 | arg->print(os, indent+2); |
---|
[44b5ca0] | 304 | os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl; |
---|
[0dd3a2f] | 305 | if ( results.empty() ) { |
---|
[44b5ca0] | 306 | os << std::string( indent+2, ' ' ) << "nothing" << std::endl; |
---|
[0dd3a2f] | 307 | } else { |
---|
| 308 | printAll(results, os, indent+2); |
---|
| 309 | } // if |
---|
| 310 | Expression::print( os, indent ); |
---|
| 311 | } |
---|
| 312 | |
---|
[51b7345] | 313 | UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) : |
---|
[0dd3a2f] | 314 | Expression( _aname ), member(_member), aggregate(_aggregate) {} |
---|
[51b7345] | 315 | |
---|
[0dd3a2f] | 316 | UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : |
---|
| 317 | Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { |
---|
[51b7345] | 318 | } |
---|
| 319 | |
---|
| 320 | UntypedMemberExpr::~UntypedMemberExpr() { |
---|
[0dd3a2f] | 321 | delete aggregate; |
---|
[51b7345] | 322 | } |
---|
| 323 | |
---|
| 324 | void UntypedMemberExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 325 | os << "Untyped Member Expression, with field: " << get_member(); |
---|
[51b7345] | 326 | |
---|
[0dd3a2f] | 327 | Expression *agg = get_aggregate(); |
---|
[9243a501] | 328 | os << ", from aggregate: "; |
---|
[89231bc] | 329 | if (agg != 0) { |
---|
[bb8ea30] | 330 | os << std::string( indent + 2, ' ' ); |
---|
[89231bc] | 331 | agg->print(os, indent + 2); |
---|
| 332 | } |
---|
| 333 | os << std::string( indent+2, ' ' ); |
---|
[0dd3a2f] | 334 | Expression::print( os, indent ); |
---|
[51b7345] | 335 | } |
---|
| 336 | |
---|
| 337 | |
---|
| 338 | MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : |
---|
[0dd3a2f] | 339 | Expression( _aname ), member(_member), aggregate(_aggregate) { |
---|
| 340 | add_result( member->get_type()->clone() ); |
---|
| 341 | for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { |
---|
| 342 | (*i)->set_isLvalue( true ); |
---|
| 343 | } // for |
---|
[51b7345] | 344 | } |
---|
| 345 | |
---|
[0dd3a2f] | 346 | MemberExpr::MemberExpr( const MemberExpr &other ) : |
---|
| 347 | Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { |
---|
[51b7345] | 348 | } |
---|
| 349 | |
---|
| 350 | MemberExpr::~MemberExpr() { |
---|
[0dd3a2f] | 351 | delete member; |
---|
| 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, ' ' ); |
---|
[0dd3a2f] | 360 | member->print( os, indent + 2 ); |
---|
| 361 | os << std::endl; |
---|
[51b7345] | 362 | |
---|
[0dd3a2f] | 363 | Expression *agg = get_aggregate(); |
---|
[44b5ca0] | 364 | os << std::string( indent, ' ' ) << "from aggregate: " << std::endl; |
---|
[89231bc] | 365 | if (agg != 0) { |
---|
[bb8ea30] | 366 | os << std::string( indent + 2, ' ' ); |
---|
[89231bc] | 367 | agg->print(os, indent + 2); |
---|
| 368 | } |
---|
| 369 | os << std::string( indent+2, ' ' ); |
---|
[0dd3a2f] | 370 | Expression::print( os, indent ); |
---|
[51b7345] | 371 | } |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {} |
---|
| 375 | |
---|
[0dd3a2f] | 376 | UntypedExpr::UntypedExpr( const UntypedExpr &other ) : |
---|
| 377 | Expression( other ), function( maybeClone( other.function ) ) { |
---|
| 378 | cloneAll( other.args, args ); |
---|
[51b7345] | 379 | } |
---|
| 380 | |
---|
| 381 | UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) : |
---|
[0dd3a2f] | 382 | Expression( _aname ), function(_function), args(_args) {} |
---|
[51b7345] | 383 | |
---|
| 384 | UntypedExpr::~UntypedExpr() {} |
---|
| 385 | |
---|
| 386 | void UntypedExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 387 | os << "Applying untyped: " << std::endl; |
---|
[bb8ea30] | 388 | os << std::string( indent+2, ' ' ); |
---|
| 389 | function->print(os, indent + 2); |
---|
[44b5ca0] | 390 | os << std::string( indent, ' ' ) << "...to: " << std::endl; |
---|
[bb8ea30] | 391 | printAll(args, os, indent + 2); |
---|
[0dd3a2f] | 392 | Expression::print( os, indent ); |
---|
[51b7345] | 393 | } |
---|
| 394 | |
---|
[0dd3a2f] | 395 | void UntypedExpr::printArgs( std::ostream &os, int indent ) const { |
---|
| 396 | std::list<Expression *>::const_iterator i; |
---|
[60089f4] | 397 | for (i = args.begin(); i != args.end(); i++) { |
---|
| 398 | os << std::string(indent, ' ' ); |
---|
[0dd3a2f] | 399 | (*i)->print(os, indent); |
---|
[60089f4] | 400 | } |
---|
[51b7345] | 401 | } |
---|
| 402 | |
---|
| 403 | NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {} |
---|
| 404 | |
---|
[0dd3a2f] | 405 | NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) { |
---|
[51b7345] | 406 | } |
---|
| 407 | |
---|
| 408 | NameExpr::~NameExpr() {} |
---|
| 409 | |
---|
| 410 | void NameExpr::print( std::ostream &os, int indent ) const { |
---|
[89231bc] | 411 | os << "Name: " << get_name() << std::endl; |
---|
[0dd3a2f] | 412 | Expression::print( os, indent ); |
---|
[51b7345] | 413 | } |
---|
| 414 | |
---|
| 415 | LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : |
---|
[0dd3a2f] | 416 | Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { |
---|
| 417 | add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); |
---|
[51b7345] | 418 | } |
---|
| 419 | |
---|
[0dd3a2f] | 420 | LogicalExpr::LogicalExpr( const LogicalExpr &other ) : |
---|
| 421 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { |
---|
[51b7345] | 422 | } |
---|
| 423 | |
---|
[a08ba92] | 424 | LogicalExpr::~LogicalExpr() { |
---|
[0dd3a2f] | 425 | delete arg1; |
---|
| 426 | delete arg2; |
---|
[51b7345] | 427 | } |
---|
| 428 | |
---|
| 429 | void LogicalExpr::print( std::ostream &os, int indent )const { |
---|
[44b5ca0] | 430 | os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: "; |
---|
[0dd3a2f] | 431 | arg1->print(os); |
---|
| 432 | os << " and "; |
---|
| 433 | arg2->print(os); |
---|
| 434 | os << std::endl; |
---|
| 435 | Expression::print( os, indent ); |
---|
[51b7345] | 436 | } |
---|
| 437 | |
---|
| 438 | ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) : |
---|
[0dd3a2f] | 439 | Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {} |
---|
[51b7345] | 440 | |
---|
[0dd3a2f] | 441 | ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : |
---|
| 442 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { |
---|
| 443 | } |
---|
[51b7345] | 444 | |
---|
| 445 | ConditionalExpr::~ConditionalExpr() { |
---|
[0dd3a2f] | 446 | delete arg1; |
---|
| 447 | delete arg2; |
---|
| 448 | delete arg3; |
---|
[51b7345] | 449 | } |
---|
| 450 | |
---|
| 451 | void ConditionalExpr::print( std::ostream &os, int indent ) const { |
---|
[44b5ca0] | 452 | os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl; |
---|
[0dd3a2f] | 453 | arg1->print( os, indent+2 ); |
---|
[44b5ca0] | 454 | os << std::string( indent, ' ' ) << "First alternative:" << std::endl; |
---|
[0dd3a2f] | 455 | arg2->print( os, indent+2 ); |
---|
[44b5ca0] | 456 | os << std::string( indent, ' ' ) << "Second alternative:" << std::endl; |
---|
[0dd3a2f] | 457 | arg3->print( os, indent+2 ); |
---|
| 458 | os << std::endl; |
---|
| 459 | Expression::print( os, indent ); |
---|
| 460 | } |
---|
| 461 | |
---|
[3be261a] | 462 | AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {} |
---|
| 463 | |
---|
| 464 | |
---|
[7f5566b] | 465 | void AsmExpr::print( std::ostream &os, int indent ) const { |
---|
| 466 | os << "Asm Expression: " << std::endl; |
---|
| 467 | if ( inout ) inout->print( os, indent + 2 ); |
---|
| 468 | if ( constraint ) constraint->print( os, indent + 2 ); |
---|
| 469 | if ( operand ) operand->print( os, indent + 2 ); |
---|
| 470 | } |
---|
| 471 | |
---|
[db4ecc5] | 472 | |
---|
| 473 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) { |
---|
| 474 | assert( callExpr ); |
---|
| 475 | cloneAll( callExpr->get_results(), results ); |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) { |
---|
| 479 | cloneAll( other.tempDecls, tempDecls ); |
---|
| 480 | cloneAll( other.returnDecls, returnDecls ); |
---|
| 481 | cloneAll( other.dtors, dtors ); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() { |
---|
| 485 | delete callExpr; |
---|
| 486 | deleteAll( tempDecls ); |
---|
| 487 | deleteAll( returnDecls ); |
---|
| 488 | deleteAll( dtors ); |
---|
| 489 | } |
---|
| 490 | |
---|
| 491 | void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const { |
---|
| 492 | os << std::string( indent, ' ' ) << "Implicit Copy Constructor Expression: " << std::endl; |
---|
| 493 | assert( callExpr ); |
---|
| 494 | callExpr->print( os, indent + 2 ); |
---|
| 495 | os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl; |
---|
| 496 | printAll(tempDecls, os, indent+2); |
---|
[dc2e7e0] | 497 | os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl; |
---|
| 498 | printAll(returnDecls, os, indent+2); |
---|
[db4ecc5] | 499 | Expression::print( os, indent ); |
---|
| 500 | } |
---|
| 501 | |
---|
[3be261a] | 502 | UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {} |
---|
| 503 | |
---|
| 504 | UntypedValofExpr::~UntypedValofExpr() { delete body; } |
---|
| 505 | |
---|
[0dd3a2f] | 506 | void UntypedValofExpr::print( std::ostream &os, int indent ) const { |
---|
[44b5ca0] | 507 | os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl; |
---|
[0dd3a2f] | 508 | if ( get_body() != 0 ) |
---|
| 509 | get_body()->print( os, indent + 2 ); |
---|
| 510 | } |
---|
| 511 | |
---|
[3be261a] | 512 | |
---|
[630a82a] | 513 | CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) { |
---|
| 514 | add_result( type->clone() ); |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {} |
---|
| 518 | |
---|
| 519 | CompoundLiteralExpr::~CompoundLiteralExpr() { |
---|
| 520 | delete initializer; |
---|
| 521 | delete type; |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | void CompoundLiteralExpr::print( std::ostream &os, int indent ) const { |
---|
| 525 | os << "Compound Literal Expression: " << std::endl; |
---|
| 526 | if ( type ) type->print( os, indent + 2 ); |
---|
| 527 | if ( initializer ) initializer->print( os, indent + 2 ); |
---|
| 528 | } |
---|
| 529 | |
---|
[3be261a] | 530 | |
---|
[baf7fee] | 531 | std::ostream & operator<<( std::ostream & out, Expression * expr ) { |
---|
| 532 | expr->print( out ); |
---|
| 533 | return out; |
---|
| 534 | } |
---|
| 535 | |
---|
[0dd3a2f] | 536 | // Local Variables: // |
---|
| 537 | // tab-width: 4 // |
---|
| 538 | // mode: c++ // |
---|
| 539 | // compile-command: "make install" // |
---|
| 540 | // End: // |
---|