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