[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 |
|
---|
[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"
|
---|
[b6fe7e6] | 30 | #include "InitTweak/InitTweak.h"
|
---|
[51b73452] | 31 |
|
---|
| 32 |
|
---|
| 33 | Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {}
|
---|
[0dd3a2f] | 34 |
|
---|
[e04ef3a] | 35 | Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
|
---|
[0dd3a2f] | 36 | cloneAll( other.results, results );
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | Expression::~Expression() {
|
---|
| 40 | delete env;
|
---|
[7f5566b] | 41 | delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
|
---|
[0dd3a2f] | 42 | deleteAll( results );
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | void Expression::add_result( Type *t ) {
|
---|
| 46 | if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) {
|
---|
| 47 | std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) );
|
---|
| 48 | } else {
|
---|
| 49 | results.push_back(t);
|
---|
| 50 | } // if
|
---|
[51b73452] | 51 | }
|
---|
| 52 |
|
---|
[59db689] | 53 | void Expression::print( std::ostream &os, int indent ) const {
|
---|
[0dd3a2f] | 54 | if ( env ) {
|
---|
[cf0941d] | 55 | os << std::string( indent, ' ' ) << "with environment:" << std::endl;
|
---|
[0dd3a2f] | 56 | env->print( os, indent+2 );
|
---|
| 57 | } // if
|
---|
[51b73452] | 58 |
|
---|
[0dd3a2f] | 59 | if ( argName ) {
|
---|
[cf0941d] | 60 | os << std::string( indent, ' ' ) << "with designator:";
|
---|
[0dd3a2f] | 61 | argName->print( os, indent+2 );
|
---|
| 62 | } // if
|
---|
[e04ef3a] | 63 |
|
---|
| 64 | if ( extension ) {
|
---|
| 65 | os << std::string( indent, ' ' ) << "with extension:";
|
---|
| 66 | } // if
|
---|
[51b73452] | 67 | }
|
---|
| 68 |
|
---|
[0dd3a2f] | 69 | ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
|
---|
| 70 | add_result( constant.get_type()->clone() );
|
---|
[51b73452] | 71 | }
|
---|
| 72 |
|
---|
[0dd3a2f] | 73 | ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
|
---|
| 74 | }
|
---|
[51b73452] | 75 |
|
---|
| 76 | ConstantExpr::~ConstantExpr() {}
|
---|
| 77 |
|
---|
[0dd3a2f] | 78 | void ConstantExpr::print( std::ostream &os, int indent ) const {
|
---|
[60089f4] | 79 | os << "constant expression " ;
|
---|
[cf0941d] | 80 | constant.print( os );
|
---|
[0dd3a2f] | 81 | Expression::print( os, indent );
|
---|
[51b73452] | 82 | }
|
---|
| 83 |
|
---|
[0dd3a2f] | 84 | VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) {
|
---|
[db4ecc5] | 85 | assert( var );
|
---|
| 86 | assert( var->get_type() );
|
---|
[0dd3a2f] | 87 | add_result( var->get_type()->clone() );
|
---|
| 88 | for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
|
---|
| 89 | (*i)->set_isLvalue( true );
|
---|
| 90 | } // for
|
---|
[51b73452] | 91 | }
|
---|
| 92 |
|
---|
[0dd3a2f] | 93 | VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
|
---|
[51b73452] | 94 | }
|
---|
| 95 |
|
---|
[0dd3a2f] | 96 | VariableExpr::~VariableExpr() {
|
---|
| 97 | // don't delete the declaration, since it points somewhere else in the tree
|
---|
[51b73452] | 98 | }
|
---|
| 99 |
|
---|
[0dd3a2f] | 100 | void VariableExpr::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 101 | os << "Variable Expression: ";
|
---|
[51b73452] | 102 |
|
---|
[0dd3a2f] | 103 | Declaration *decl = get_var();
|
---|
| 104 | // if ( decl != 0) decl->print(os, indent + 2);
|
---|
| 105 | if ( decl != 0) decl->printShort(os, indent + 2);
|
---|
| 106 | os << std::endl;
|
---|
| 107 | Expression::print( os, indent );
|
---|
[51b73452] | 108 | }
|
---|
| 109 |
|
---|
| 110 | SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
|
---|
[0dd3a2f] | 111 | Expression( _aname ), expr(expr_), type(0), isType(false) {
|
---|
[bfebb6c5] | 112 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[51b73452] | 113 | }
|
---|
| 114 |
|
---|
| 115 | SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
|
---|
[0dd3a2f] | 116 | Expression( _aname ), expr(0), type(type_), isType(true) {
|
---|
[bfebb6c5] | 117 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[51b73452] | 118 | }
|
---|
| 119 |
|
---|
[0dd3a2f] | 120 | SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
|
---|
| 121 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
|
---|
[51b73452] | 122 | }
|
---|
| 123 |
|
---|
[0dd3a2f] | 124 | SizeofExpr::~SizeofExpr() {
|
---|
| 125 | delete expr;
|
---|
| 126 | delete type;
|
---|
[51b73452] | 127 | }
|
---|
| 128 |
|
---|
| 129 | void SizeofExpr::print( std::ostream &os, int indent) const {
|
---|
[89231bc] | 130 | os << "Sizeof Expression on: ";
|
---|
[51b73452] | 131 |
|
---|
[47534159] | 132 | if (isType)
|
---|
| 133 | type->print(os, indent + 2);
|
---|
| 134 | else
|
---|
| 135 | expr->print(os, indent + 2);
|
---|
| 136 |
|
---|
| 137 | os << std::endl;
|
---|
| 138 | Expression::print( os, indent );
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
|
---|
| 142 | Expression( _aname ), expr(expr_), type(0), isType(false) {
|
---|
[bfebb6c5] | 143 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[47534159] | 144 | }
|
---|
| 145 |
|
---|
| 146 | AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
|
---|
| 147 | Expression( _aname ), expr(0), type(type_), isType(true) {
|
---|
[bfebb6c5] | 148 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[47534159] | 149 | }
|
---|
| 150 |
|
---|
| 151 | AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
|
---|
| 152 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | AlignofExpr::~AlignofExpr() {
|
---|
| 156 | delete expr;
|
---|
| 157 | delete type;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | void AlignofExpr::print( std::ostream &os, int indent) const {
|
---|
| 161 | os << std::string( indent, ' ' ) << "Alignof Expression on: ";
|
---|
| 162 |
|
---|
[0dd3a2f] | 163 | if (isType)
|
---|
| 164 | type->print(os, indent + 2);
|
---|
| 165 | else
|
---|
| 166 | expr->print(os, indent + 2);
|
---|
[51b73452] | 167 |
|
---|
[0dd3a2f] | 168 | os << std::endl;
|
---|
| 169 | Expression::print( os, indent );
|
---|
[51b73452] | 170 | }
|
---|
| 171 |
|
---|
[2a4b088] | 172 | UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
|
---|
| 173 | Expression( _aname ), type(type_), member(member_) {
|
---|
| 174 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
|
---|
| 178 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
|
---|
| 179 |
|
---|
| 180 | UntypedOffsetofExpr::~UntypedOffsetofExpr() {
|
---|
| 181 | delete type;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | void UntypedOffsetofExpr::print( std::ostream &os, int indent) const {
|
---|
| 185 | os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of ";
|
---|
| 186 |
|
---|
| 187 | if ( type ) {
|
---|
| 188 | type->print(os, indent + 2);
|
---|
| 189 | } else {
|
---|
| 190 | os << "<NULL>";
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | os << std::endl;
|
---|
| 194 | Expression::print( os, indent );
|
---|
| 195 | }
|
---|
| 196 |
|
---|
[25a054f] | 197 | OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
|
---|
| 198 | Expression( _aname ), type(type_), member(member_) {
|
---|
[bfebb6c5] | 199 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[25a054f] | 200 | }
|
---|
| 201 |
|
---|
| 202 | OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
|
---|
[79970ed] | 203 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
|
---|
[25a054f] | 204 |
|
---|
| 205 | OffsetofExpr::~OffsetofExpr() {
|
---|
| 206 | delete type;
|
---|
| 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 |
|
---|
[51b73452] | 251 | AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
|
---|
[0dd3a2f] | 252 | Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
|
---|
[51b73452] | 253 | }
|
---|
| 254 |
|
---|
| 255 | AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
|
---|
[0dd3a2f] | 256 | Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
|
---|
[51b73452] | 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 ) {
|
---|
[51b73452] | 261 | }
|
---|
| 262 |
|
---|
[0dd3a2f] | 263 | AttrExpr::~AttrExpr() {
|
---|
| 264 | delete attr;
|
---|
| 265 | delete expr;
|
---|
| 266 | delete type;
|
---|
[51b73452] | 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: ";
|
---|
[51b73452] | 274 |
|
---|
[0dd3a2f] | 275 | if (isType)
|
---|
| 276 | type->print(os, indent + 2);
|
---|
| 277 | else
|
---|
| 278 | expr->print(os, indent + 2);
|
---|
| 279 | } // if
|
---|
[51b73452] | 280 |
|
---|
[0dd3a2f] | 281 | os << std::endl;
|
---|
| 282 | Expression::print( os, indent );
|
---|
[51b73452] | 283 | }
|
---|
| 284 |
|
---|
[0dd3a2f] | 285 | CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
|
---|
| 286 | add_result(toType);
|
---|
[51b73452] | 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 ) ) {
|
---|
[51b73452] | 293 | }
|
---|
| 294 |
|
---|
| 295 | CastExpr::~CastExpr() {
|
---|
[0dd3a2f] | 296 | delete arg;
|
---|
[51b73452] | 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 |
|
---|
[3b58d91] | 313 | UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
|
---|
[0dd3a2f] | 314 | Expression( _aname ), member(_member), aggregate(_aggregate) {}
|
---|
[51b73452] | 315 |
|
---|
[0dd3a2f] | 316 | UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
|
---|
[3b58d91] | 317 | Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
|
---|
[51b73452] | 318 | }
|
---|
| 319 |
|
---|
| 320 | UntypedMemberExpr::~UntypedMemberExpr() {
|
---|
[0dd3a2f] | 321 | delete aggregate;
|
---|
[3b58d91] | 322 | delete member;
|
---|
[51b73452] | 323 | }
|
---|
| 324 |
|
---|
| 325 | void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
|
---|
[3b58d91] | 326 | os << "Untyped Member Expression, with field: " << std::endl;
|
---|
| 327 | get_member()->print(os, indent+4);
|
---|
| 328 | os << std::string( indent+2, ' ' );
|
---|
[51b73452] | 329 |
|
---|
[0dd3a2f] | 330 | Expression *agg = get_aggregate();
|
---|
[3b58d91] | 331 | os << "from aggregate: " << std::endl;
|
---|
[89231bc] | 332 | if (agg != 0) {
|
---|
[3b58d91] | 333 | os << std::string( indent + 4, ' ' );
|
---|
| 334 | agg->print(os, indent + 4);
|
---|
[89231bc] | 335 | }
|
---|
| 336 | os << std::string( indent+2, ' ' );
|
---|
[0dd3a2f] | 337 | Expression::print( os, indent );
|
---|
[51b73452] | 338 | }
|
---|
| 339 |
|
---|
| 340 |
|
---|
| 341 | MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
|
---|
[0dd3a2f] | 342 | Expression( _aname ), member(_member), aggregate(_aggregate) {
|
---|
| 343 | add_result( member->get_type()->clone() );
|
---|
| 344 | for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
|
---|
| 345 | (*i)->set_isLvalue( true );
|
---|
| 346 | } // for
|
---|
[51b73452] | 347 | }
|
---|
| 348 |
|
---|
[39f84a4] | 349 | //// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...
|
---|
[0dd3a2f] | 350 | MemberExpr::MemberExpr( const MemberExpr &other ) :
|
---|
[39f84a4] | 351 | Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
|
---|
[51b73452] | 352 | }
|
---|
| 353 |
|
---|
| 354 | MemberExpr::~MemberExpr() {
|
---|
[39f84a4] | 355 | // delete member;
|
---|
[0dd3a2f] | 356 | delete aggregate;
|
---|
[51b73452] | 357 | }
|
---|
| 358 |
|
---|
| 359 | void MemberExpr::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 360 | os << "Member Expression, with field: " << std::endl;
|
---|
[51b73452] | 361 |
|
---|
[0dd3a2f] | 362 | assert( member );
|
---|
[44b5ca0] | 363 | os << std::string( indent + 2, ' ' );
|
---|
[0dd3a2f] | 364 | member->print( os, indent + 2 );
|
---|
| 365 | os << std::endl;
|
---|
[51b73452] | 366 |
|
---|
[0dd3a2f] | 367 | Expression *agg = get_aggregate();
|
---|
[44b5ca0] | 368 | os << std::string( indent, ' ' ) << "from aggregate: " << std::endl;
|
---|
[89231bc] | 369 | if (agg != 0) {
|
---|
[bb8ea30] | 370 | os << std::string( indent + 2, ' ' );
|
---|
[89231bc] | 371 | agg->print(os, indent + 2);
|
---|
| 372 | }
|
---|
| 373 | os << std::string( indent+2, ' ' );
|
---|
[0dd3a2f] | 374 | Expression::print( os, indent );
|
---|
[51b73452] | 375 | }
|
---|
| 376 |
|
---|
| 377 |
|
---|
| 378 | UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {}
|
---|
| 379 |
|
---|
[0dd3a2f] | 380 | UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
|
---|
| 381 | Expression( other ), function( maybeClone( other.function ) ) {
|
---|
| 382 | cloneAll( other.args, args );
|
---|
[51b73452] | 383 | }
|
---|
| 384 |
|
---|
| 385 | UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :
|
---|
[0dd3a2f] | 386 | Expression( _aname ), function(_function), args(_args) {}
|
---|
[51b73452] | 387 |
|
---|
[ac71a86] | 388 | UntypedExpr::~UntypedExpr() {
|
---|
| 389 | delete function;
|
---|
[03b812d2] | 390 | deleteAll( args );
|
---|
[ac71a86] | 391 | }
|
---|
[51b73452] | 392 |
|
---|
| 393 | void UntypedExpr::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 394 | os << "Applying untyped: " << std::endl;
|
---|
[bb8ea30] | 395 | os << std::string( indent+2, ' ' );
|
---|
| 396 | function->print(os, indent + 2);
|
---|
[44b5ca0] | 397 | os << std::string( indent, ' ' ) << "...to: " << std::endl;
|
---|
[bb8ea30] | 398 | printAll(args, os, indent + 2);
|
---|
[0dd3a2f] | 399 | Expression::print( os, indent );
|
---|
[51b73452] | 400 | }
|
---|
| 401 |
|
---|
[0dd3a2f] | 402 | void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
|
---|
| 403 | std::list<Expression *>::const_iterator i;
|
---|
[60089f4] | 404 | for (i = args.begin(); i != args.end(); i++) {
|
---|
| 405 | os << std::string(indent, ' ' );
|
---|
[0dd3a2f] | 406 | (*i)->print(os, indent);
|
---|
[60089f4] | 407 | }
|
---|
[51b73452] | 408 | }
|
---|
| 409 |
|
---|
| 410 | NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {}
|
---|
| 411 |
|
---|
[0dd3a2f] | 412 | NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
|
---|
[51b73452] | 413 | }
|
---|
| 414 |
|
---|
| 415 | NameExpr::~NameExpr() {}
|
---|
| 416 |
|
---|
| 417 | void NameExpr::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 418 | os << "Name: " << get_name() << std::endl;
|
---|
[0dd3a2f] | 419 | Expression::print( os, indent );
|
---|
[51b73452] | 420 | }
|
---|
| 421 |
|
---|
| 422 | LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
|
---|
[0dd3a2f] | 423 | Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
|
---|
| 424 | add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
|
---|
[51b73452] | 425 | }
|
---|
| 426 |
|
---|
[0dd3a2f] | 427 | LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
|
---|
| 428 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
|
---|
[51b73452] | 429 | }
|
---|
| 430 |
|
---|
[a08ba92] | 431 | LogicalExpr::~LogicalExpr() {
|
---|
[0dd3a2f] | 432 | delete arg1;
|
---|
| 433 | delete arg2;
|
---|
[51b73452] | 434 | }
|
---|
| 435 |
|
---|
| 436 | void LogicalExpr::print( std::ostream &os, int indent )const {
|
---|
[44b5ca0] | 437 | os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
|
---|
[0dd3a2f] | 438 | arg1->print(os);
|
---|
| 439 | os << " and ";
|
---|
| 440 | arg2->print(os);
|
---|
| 441 | os << std::endl;
|
---|
| 442 | Expression::print( os, indent );
|
---|
[51b73452] | 443 | }
|
---|
| 444 |
|
---|
| 445 | ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
|
---|
[0dd3a2f] | 446 | Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
|
---|
[51b73452] | 447 |
|
---|
[0dd3a2f] | 448 | ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
|
---|
| 449 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
|
---|
| 450 | }
|
---|
[51b73452] | 451 |
|
---|
| 452 | ConditionalExpr::~ConditionalExpr() {
|
---|
[0dd3a2f] | 453 | delete arg1;
|
---|
| 454 | delete arg2;
|
---|
| 455 | delete arg3;
|
---|
[51b73452] | 456 | }
|
---|
| 457 |
|
---|
| 458 | void ConditionalExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 459 | os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl;
|
---|
[0dd3a2f] | 460 | arg1->print( os, indent+2 );
|
---|
[44b5ca0] | 461 | os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
|
---|
[0dd3a2f] | 462 | arg2->print( os, indent+2 );
|
---|
[44b5ca0] | 463 | os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
|
---|
[0dd3a2f] | 464 | arg3->print( os, indent+2 );
|
---|
| 465 | os << std::endl;
|
---|
| 466 | Expression::print( os, indent );
|
---|
| 467 | }
|
---|
| 468 |
|
---|
[3be261a] | 469 | AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
|
---|
| 470 |
|
---|
| 471 |
|
---|
[7f5566b] | 472 | void AsmExpr::print( std::ostream &os, int indent ) const {
|
---|
| 473 | os << "Asm Expression: " << std::endl;
|
---|
| 474 | if ( inout ) inout->print( os, indent + 2 );
|
---|
| 475 | if ( constraint ) constraint->print( os, indent + 2 );
|
---|
| 476 | if ( operand ) operand->print( os, indent + 2 );
|
---|
| 477 | }
|
---|
| 478 |
|
---|
[db4ecc5] | 479 |
|
---|
| 480 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
|
---|
| 481 | assert( callExpr );
|
---|
| 482 | cloneAll( callExpr->get_results(), results );
|
---|
| 483 | }
|
---|
| 484 |
|
---|
| 485 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
|
---|
| 486 | cloneAll( other.tempDecls, tempDecls );
|
---|
| 487 | cloneAll( other.returnDecls, returnDecls );
|
---|
| 488 | cloneAll( other.dtors, dtors );
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
|
---|
| 492 | delete callExpr;
|
---|
| 493 | deleteAll( tempDecls );
|
---|
| 494 | deleteAll( returnDecls );
|
---|
| 495 | deleteAll( dtors );
|
---|
| 496 | }
|
---|
| 497 |
|
---|
| 498 | void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
|
---|
[b6fe7e6] | 499 | os << "Implicit Copy Constructor Expression: " << std::endl;
|
---|
[db4ecc5] | 500 | assert( callExpr );
|
---|
| 501 | callExpr->print( os, indent + 2 );
|
---|
| 502 | os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;
|
---|
| 503 | printAll(tempDecls, os, indent+2);
|
---|
[dc2e7e0] | 504 | os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl;
|
---|
| 505 | printAll(returnDecls, os, indent+2);
|
---|
[db4ecc5] | 506 | Expression::print( os, indent );
|
---|
| 507 | }
|
---|
| 508 |
|
---|
[3be261a] | 509 |
|
---|
[b6fe7e6] | 510 | ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
|
---|
| 511 | // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
|
---|
| 512 | assert( callExpr );
|
---|
| 513 | Expression * arg = InitTweak::getCallArg( callExpr, 0 );
|
---|
| 514 | assert( arg );
|
---|
| 515 | cloneAll( arg->get_results(), results );
|
---|
| 516 | }
|
---|
[3be261a] | 517 |
|
---|
[b6fe7e6] | 518 | ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
|
---|
| 519 | }
|
---|
| 520 |
|
---|
| 521 | ConstructorExpr::~ConstructorExpr() {
|
---|
| 522 | delete callExpr;
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | void ConstructorExpr::print( std::ostream &os, int indent ) const {
|
---|
| 526 | os << "Constructor Expression: " << std::endl;
|
---|
| 527 | assert( callExpr );
|
---|
| 528 | os << std::string( indent+2, ' ' );
|
---|
| 529 | callExpr->print( os, indent + 2 );
|
---|
| 530 | Expression::print( os, indent );
|
---|
[0dd3a2f] | 531 | }
|
---|
| 532 |
|
---|
[3be261a] | 533 |
|
---|
[630a82a] | 534 | CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
|
---|
| 535 | add_result( type->clone() );
|
---|
| 536 | }
|
---|
| 537 |
|
---|
| 538 | CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
|
---|
| 539 |
|
---|
| 540 | CompoundLiteralExpr::~CompoundLiteralExpr() {
|
---|
| 541 | delete initializer;
|
---|
| 542 | delete type;
|
---|
| 543 | }
|
---|
| 544 |
|
---|
| 545 | void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
|
---|
| 546 | os << "Compound Literal Expression: " << std::endl;
|
---|
| 547 | if ( type ) type->print( os, indent + 2 );
|
---|
| 548 | if ( initializer ) initializer->print( os, indent + 2 );
|
---|
| 549 | }
|
---|
| 550 |
|
---|
[b6fe7e6] | 551 | UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
|
---|
| 552 |
|
---|
| 553 | UntypedValofExpr::~UntypedValofExpr() { delete body; }
|
---|
| 554 |
|
---|
| 555 | void UntypedValofExpr::print( std::ostream &os, int indent ) const {
|
---|
| 556 | os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;
|
---|
| 557 | if ( get_body() != 0 )
|
---|
| 558 | get_body()->print( os, indent + 2 );
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[d9e2280] | 561 | RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
|
---|
[8688ce1] | 562 | RangeExpr::RangeExpr( const RangeExpr &other ) : low( other.low->clone() ), high( other.high->clone() ) {}
|
---|
| 563 | void RangeExpr::print( std::ostream &os, int indent ) const {
|
---|
| 564 | os << std::string( indent, ' ' ) << "Range Expression: ";
|
---|
| 565 | low->print( os, indent );
|
---|
| 566 | os << " ... ";
|
---|
| 567 | high->print( os, indent );
|
---|
| 568 | }
|
---|
[3be261a] | 569 |
|
---|
[3906301] | 570 | std::ostream & operator<<( std::ostream & out, const Expression * expr ) {
|
---|
[baf7fee] | 571 | expr->print( out );
|
---|
| 572 | return out;
|
---|
| 573 | }
|
---|
| 574 |
|
---|
[0dd3a2f] | 575 | // Local Variables: //
|
---|
| 576 | // tab-width: 4 //
|
---|
| 577 | // mode: c++ //
|
---|
| 578 | // compile-command: "make install" //
|
---|
| 579 | // End: //
|
---|