[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 |
|
---|
[906e24d] | 33 | Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
|
---|
[0dd3a2f] | 34 |
|
---|
[906e24d] | 35 | Expression::Expression( const Expression &other ) : result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
|
---|
[0dd3a2f] | 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
|
---|
[906e24d] | 41 | delete result;
|
---|
[51b73452] | 42 | }
|
---|
| 43 |
|
---|
[59db689] | 44 | void Expression::print( std::ostream &os, int indent ) const {
|
---|
[0dd3a2f] | 45 | if ( env ) {
|
---|
[cf0941d] | 46 | os << std::string( indent, ' ' ) << "with environment:" << std::endl;
|
---|
[0dd3a2f] | 47 | env->print( os, indent+2 );
|
---|
| 48 | } // if
|
---|
[51b73452] | 49 |
|
---|
[0dd3a2f] | 50 | if ( argName ) {
|
---|
[cf0941d] | 51 | os << std::string( indent, ' ' ) << "with designator:";
|
---|
[0dd3a2f] | 52 | argName->print( os, indent+2 );
|
---|
| 53 | } // if
|
---|
[e04ef3a] | 54 |
|
---|
| 55 | if ( extension ) {
|
---|
| 56 | os << std::string( indent, ' ' ) << "with extension:";
|
---|
| 57 | } // if
|
---|
[51b73452] | 58 | }
|
---|
| 59 |
|
---|
[0dd3a2f] | 60 | ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
|
---|
[906e24d] | 61 | set_result( constant.get_type()->clone() );
|
---|
[51b73452] | 62 | }
|
---|
| 63 |
|
---|
[0dd3a2f] | 64 | ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
|
---|
| 65 | }
|
---|
[51b73452] | 66 |
|
---|
| 67 | ConstantExpr::~ConstantExpr() {}
|
---|
| 68 |
|
---|
[0dd3a2f] | 69 | void ConstantExpr::print( std::ostream &os, int indent ) const {
|
---|
[60089f4] | 70 | os << "constant expression " ;
|
---|
[cf0941d] | 71 | constant.print( os );
|
---|
[0dd3a2f] | 72 | Expression::print( os, indent );
|
---|
[51b73452] | 73 | }
|
---|
| 74 |
|
---|
[0dd3a2f] | 75 | VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) {
|
---|
[db4ecc5] | 76 | assert( var );
|
---|
| 77 | assert( var->get_type() );
|
---|
[906e24d] | 78 | Type * type = var->get_type()->clone();
|
---|
| 79 | type->set_isLvalue( true );
|
---|
| 80 | set_result( type );
|
---|
[51b73452] | 81 | }
|
---|
| 82 |
|
---|
[0dd3a2f] | 83 | VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
|
---|
[51b73452] | 84 | }
|
---|
| 85 |
|
---|
[0dd3a2f] | 86 | VariableExpr::~VariableExpr() {
|
---|
| 87 | // don't delete the declaration, since it points somewhere else in the tree
|
---|
[51b73452] | 88 | }
|
---|
| 89 |
|
---|
[0dd3a2f] | 90 | void VariableExpr::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 91 | os << "Variable Expression: ";
|
---|
[51b73452] | 92 |
|
---|
[0dd3a2f] | 93 | Declaration *decl = get_var();
|
---|
| 94 | // if ( decl != 0) decl->print(os, indent + 2);
|
---|
| 95 | if ( decl != 0) decl->printShort(os, indent + 2);
|
---|
| 96 | os << std::endl;
|
---|
| 97 | Expression::print( os, indent );
|
---|
[51b73452] | 98 | }
|
---|
| 99 |
|
---|
| 100 | SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
|
---|
[0dd3a2f] | 101 | Expression( _aname ), expr(expr_), type(0), isType(false) {
|
---|
[906e24d] | 102 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[51b73452] | 103 | }
|
---|
| 104 |
|
---|
| 105 | SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
|
---|
[0dd3a2f] | 106 | Expression( _aname ), expr(0), type(type_), isType(true) {
|
---|
[906e24d] | 107 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[51b73452] | 108 | }
|
---|
| 109 |
|
---|
[0dd3a2f] | 110 | SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
|
---|
| 111 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
|
---|
[51b73452] | 112 | }
|
---|
| 113 |
|
---|
[0dd3a2f] | 114 | SizeofExpr::~SizeofExpr() {
|
---|
| 115 | delete expr;
|
---|
| 116 | delete type;
|
---|
[51b73452] | 117 | }
|
---|
| 118 |
|
---|
| 119 | void SizeofExpr::print( std::ostream &os, int indent) const {
|
---|
[89231bc] | 120 | os << "Sizeof Expression on: ";
|
---|
[51b73452] | 121 |
|
---|
[47534159] | 122 | if (isType)
|
---|
| 123 | type->print(os, indent + 2);
|
---|
| 124 | else
|
---|
| 125 | expr->print(os, indent + 2);
|
---|
| 126 |
|
---|
| 127 | os << std::endl;
|
---|
| 128 | Expression::print( os, indent );
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
|
---|
| 132 | Expression( _aname ), expr(expr_), type(0), isType(false) {
|
---|
[906e24d] | 133 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[47534159] | 134 | }
|
---|
| 135 |
|
---|
| 136 | AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
|
---|
| 137 | Expression( _aname ), expr(0), type(type_), isType(true) {
|
---|
[906e24d] | 138 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[47534159] | 139 | }
|
---|
| 140 |
|
---|
| 141 | AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
|
---|
| 142 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | AlignofExpr::~AlignofExpr() {
|
---|
| 146 | delete expr;
|
---|
| 147 | delete type;
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void AlignofExpr::print( std::ostream &os, int indent) const {
|
---|
| 151 | os << std::string( indent, ' ' ) << "Alignof Expression on: ";
|
---|
| 152 |
|
---|
[0dd3a2f] | 153 | if (isType)
|
---|
| 154 | type->print(os, indent + 2);
|
---|
| 155 | else
|
---|
| 156 | expr->print(os, indent + 2);
|
---|
[51b73452] | 157 |
|
---|
[0dd3a2f] | 158 | os << std::endl;
|
---|
| 159 | Expression::print( os, indent );
|
---|
[51b73452] | 160 | }
|
---|
| 161 |
|
---|
[2a4b088] | 162 | UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
|
---|
| 163 | Expression( _aname ), type(type_), member(member_) {
|
---|
[906e24d] | 164 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[2a4b088] | 165 | }
|
---|
| 166 |
|
---|
| 167 | UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
|
---|
| 168 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
|
---|
| 169 |
|
---|
| 170 | UntypedOffsetofExpr::~UntypedOffsetofExpr() {
|
---|
| 171 | delete type;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | void UntypedOffsetofExpr::print( std::ostream &os, int indent) const {
|
---|
| 175 | os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of ";
|
---|
| 176 |
|
---|
| 177 | if ( type ) {
|
---|
| 178 | type->print(os, indent + 2);
|
---|
| 179 | } else {
|
---|
| 180 | os << "<NULL>";
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | os << std::endl;
|
---|
| 184 | Expression::print( os, indent );
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[25a054f] | 187 | OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
|
---|
| 188 | Expression( _aname ), type(type_), member(member_) {
|
---|
[906e24d] | 189 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[25a054f] | 190 | }
|
---|
| 191 |
|
---|
| 192 | OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
|
---|
[79970ed] | 193 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
|
---|
[25a054f] | 194 |
|
---|
| 195 | OffsetofExpr::~OffsetofExpr() {
|
---|
| 196 | delete type;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | void OffsetofExpr::print( std::ostream &os, int indent) const {
|
---|
| 200 | os << std::string( indent, ' ' ) << "Offsetof Expression on member ";
|
---|
| 201 |
|
---|
| 202 | if ( member ) {
|
---|
| 203 | os << member->get_name();
|
---|
| 204 | } else {
|
---|
| 205 | os << "<NULL>";
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | os << " of ";
|
---|
| 209 |
|
---|
| 210 | if ( type ) {
|
---|
| 211 | type->print(os, indent + 2);
|
---|
| 212 | } else {
|
---|
| 213 | os << "<NULL>";
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | os << std::endl;
|
---|
| 217 | Expression::print( os, indent );
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[afc1045] | 220 | OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
|
---|
[906e24d] | 221 | set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
|
---|
[afc1045] | 222 | }
|
---|
| 223 |
|
---|
| 224 | OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
|
---|
| 225 |
|
---|
| 226 | OffsetPackExpr::~OffsetPackExpr() { delete type; }
|
---|
| 227 |
|
---|
| 228 | void OffsetPackExpr::print( std::ostream &os, int indent ) const {
|
---|
| 229 | os << std::string( indent, ' ' ) << "Offset pack expression on ";
|
---|
| 230 |
|
---|
| 231 | if ( type ) {
|
---|
| 232 | type->print(os, indent + 2);
|
---|
| 233 | } else {
|
---|
| 234 | os << "<NULL>";
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[25a054f] | 237 | os << std::endl;
|
---|
| 238 | Expression::print( os, indent );
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[51b73452] | 241 | AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
|
---|
[0dd3a2f] | 242 | Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
|
---|
[51b73452] | 243 | }
|
---|
| 244 |
|
---|
| 245 | AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
|
---|
[0dd3a2f] | 246 | Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
|
---|
[51b73452] | 247 | }
|
---|
| 248 |
|
---|
[0dd3a2f] | 249 | AttrExpr::AttrExpr( const AttrExpr &other ) :
|
---|
| 250 | Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
|
---|
[51b73452] | 251 | }
|
---|
| 252 |
|
---|
[0dd3a2f] | 253 | AttrExpr::~AttrExpr() {
|
---|
| 254 | delete attr;
|
---|
| 255 | delete expr;
|
---|
| 256 | delete type;
|
---|
[51b73452] | 257 | }
|
---|
| 258 |
|
---|
| 259 | void AttrExpr::print( std::ostream &os, int indent) const {
|
---|
[44b5ca0] | 260 | os << std::string( indent, ' ' ) << "Attr ";
|
---|
[0dd3a2f] | 261 | attr->print( os, indent + 2 );
|
---|
| 262 | if ( isType || expr ) {
|
---|
| 263 | os << "applied to: ";
|
---|
[51b73452] | 264 |
|
---|
[0dd3a2f] | 265 | if (isType)
|
---|
| 266 | type->print(os, indent + 2);
|
---|
| 267 | else
|
---|
| 268 | expr->print(os, indent + 2);
|
---|
| 269 | } // if
|
---|
[51b73452] | 270 |
|
---|
[0dd3a2f] | 271 | os << std::endl;
|
---|
| 272 | Expression::print( os, indent );
|
---|
[51b73452] | 273 | }
|
---|
| 274 |
|
---|
[0dd3a2f] | 275 | CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
|
---|
[906e24d] | 276 | set_result(toType);
|
---|
[51b73452] | 277 | }
|
---|
| 278 |
|
---|
| 279 | CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
|
---|
[906e24d] | 280 | set_result( new VoidType( Type::Qualifiers() ) );
|
---|
[51b73452] | 281 | }
|
---|
| 282 |
|
---|
[0dd3a2f] | 283 | CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
|
---|
[51b73452] | 284 | }
|
---|
| 285 |
|
---|
| 286 | CastExpr::~CastExpr() {
|
---|
[0dd3a2f] | 287 | delete arg;
|
---|
[51b73452] | 288 | }
|
---|
| 289 |
|
---|
| 290 | // CastExpr *CastExpr::clone() const { return 0; }
|
---|
| 291 |
|
---|
| 292 | void CastExpr::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 293 | os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
|
---|
[0dd3a2f] | 294 | arg->print(os, indent+2);
|
---|
[44b5ca0] | 295 | os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
|
---|
[906e24d] | 296 | os << std::string( indent+2, ' ' );
|
---|
| 297 | if ( result->isVoid() ) {
|
---|
| 298 | os << "nothing";
|
---|
[0dd3a2f] | 299 | } else {
|
---|
[906e24d] | 300 | result->print( os, indent+2 );
|
---|
[0dd3a2f] | 301 | } // if
|
---|
[906e24d] | 302 | os << std::endl;
|
---|
[0dd3a2f] | 303 | Expression::print( os, indent );
|
---|
| 304 | }
|
---|
| 305 |
|
---|
[3b58d91] | 306 | UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
|
---|
[0dd3a2f] | 307 | Expression( _aname ), member(_member), aggregate(_aggregate) {}
|
---|
[51b73452] | 308 |
|
---|
[0dd3a2f] | 309 | UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
|
---|
[3b58d91] | 310 | Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
|
---|
[51b73452] | 311 | }
|
---|
| 312 |
|
---|
| 313 | UntypedMemberExpr::~UntypedMemberExpr() {
|
---|
[0dd3a2f] | 314 | delete aggregate;
|
---|
[3b58d91] | 315 | delete member;
|
---|
[51b73452] | 316 | }
|
---|
| 317 |
|
---|
| 318 | void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
|
---|
[3b58d91] | 319 | os << "Untyped Member Expression, with field: " << std::endl;
|
---|
[8c49c0e] | 320 | os << std::string( indent+2, ' ' );
|
---|
[3b58d91] | 321 | get_member()->print(os, indent+4);
|
---|
| 322 | os << std::string( indent+2, ' ' );
|
---|
[51b73452] | 323 |
|
---|
[0dd3a2f] | 324 | Expression *agg = get_aggregate();
|
---|
[3b58d91] | 325 | os << "from aggregate: " << std::endl;
|
---|
[89231bc] | 326 | if (agg != 0) {
|
---|
[3b58d91] | 327 | os << std::string( indent + 4, ' ' );
|
---|
| 328 | agg->print(os, indent + 4);
|
---|
[89231bc] | 329 | }
|
---|
| 330 | os << std::string( indent+2, ' ' );
|
---|
[0dd3a2f] | 331 | Expression::print( os, indent );
|
---|
[51b73452] | 332 | }
|
---|
| 333 |
|
---|
| 334 |
|
---|
| 335 | MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
|
---|
[0dd3a2f] | 336 | Expression( _aname ), member(_member), aggregate(_aggregate) {
|
---|
[906e24d] | 337 | set_result( member->get_type()->clone() );
|
---|
| 338 | get_result()->set_isLvalue( true );
|
---|
[51b73452] | 339 | }
|
---|
| 340 |
|
---|
[39f84a4] | 341 | //// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...
|
---|
[0dd3a2f] | 342 | MemberExpr::MemberExpr( const MemberExpr &other ) :
|
---|
[39f84a4] | 343 | Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
|
---|
[51b73452] | 344 | }
|
---|
| 345 |
|
---|
| 346 | MemberExpr::~MemberExpr() {
|
---|
[39f84a4] | 347 | // delete member;
|
---|
[0dd3a2f] | 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) {
|
---|
[bb8ea30] | 362 | os << std::string( indent + 2, ' ' );
|
---|
[89231bc] | 363 | agg->print(os, indent + 2);
|
---|
| 364 | }
|
---|
| 365 | os << std::string( indent+2, ' ' );
|
---|
[0dd3a2f] | 366 | Expression::print( os, indent );
|
---|
[51b73452] | 367 | }
|
---|
| 368 |
|
---|
[6eb8948] | 369 | UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
|
---|
| 370 | Expression( _aname ), function(_function), args(_args) {}
|
---|
[51b73452] | 371 |
|
---|
[0dd3a2f] | 372 | UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
|
---|
| 373 | Expression( other ), function( maybeClone( other.function ) ) {
|
---|
| 374 | cloneAll( other.args, args );
|
---|
[51b73452] | 375 | }
|
---|
| 376 |
|
---|
[ac71a86] | 377 | UntypedExpr::~UntypedExpr() {
|
---|
| 378 | delete function;
|
---|
[03b812d2] | 379 | deleteAll( args );
|
---|
[ac71a86] | 380 | }
|
---|
[51b73452] | 381 |
|
---|
| 382 | void UntypedExpr::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 383 | os << "Applying untyped: " << std::endl;
|
---|
[bb8ea30] | 384 | os << std::string( indent+2, ' ' );
|
---|
| 385 | function->print(os, indent + 2);
|
---|
[44b5ca0] | 386 | os << std::string( indent, ' ' ) << "...to: " << std::endl;
|
---|
[bb8ea30] | 387 | printAll(args, os, indent + 2);
|
---|
[0dd3a2f] | 388 | Expression::print( os, indent );
|
---|
[51b73452] | 389 | }
|
---|
| 390 |
|
---|
[0dd3a2f] | 391 | void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
|
---|
| 392 | std::list<Expression *>::const_iterator i;
|
---|
[60089f4] | 393 | for (i = args.begin(); i != args.end(); i++) {
|
---|
| 394 | os << std::string(indent, ' ' );
|
---|
[0dd3a2f] | 395 | (*i)->print(os, indent);
|
---|
[60089f4] | 396 | }
|
---|
[51b73452] | 397 | }
|
---|
| 398 |
|
---|
| 399 | NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {}
|
---|
| 400 |
|
---|
[0dd3a2f] | 401 | NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
|
---|
[51b73452] | 402 | }
|
---|
| 403 |
|
---|
| 404 | NameExpr::~NameExpr() {}
|
---|
| 405 |
|
---|
| 406 | void NameExpr::print( std::ostream &os, int indent ) const {
|
---|
[89231bc] | 407 | os << "Name: " << get_name() << std::endl;
|
---|
[0dd3a2f] | 408 | Expression::print( os, indent );
|
---|
[51b73452] | 409 | }
|
---|
| 410 |
|
---|
| 411 | LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
|
---|
[0dd3a2f] | 412 | Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
|
---|
[906e24d] | 413 | set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
|
---|
[51b73452] | 414 | }
|
---|
| 415 |
|
---|
[0dd3a2f] | 416 | LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
|
---|
| 417 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
|
---|
[51b73452] | 418 | }
|
---|
| 419 |
|
---|
[a08ba92] | 420 | LogicalExpr::~LogicalExpr() {
|
---|
[0dd3a2f] | 421 | delete arg1;
|
---|
| 422 | delete arg2;
|
---|
[51b73452] | 423 | }
|
---|
| 424 |
|
---|
| 425 | void LogicalExpr::print( std::ostream &os, int indent )const {
|
---|
[44b5ca0] | 426 | os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
|
---|
[0dd3a2f] | 427 | arg1->print(os);
|
---|
| 428 | os << " and ";
|
---|
| 429 | arg2->print(os);
|
---|
| 430 | os << std::endl;
|
---|
| 431 | Expression::print( os, indent );
|
---|
[51b73452] | 432 | }
|
---|
| 433 |
|
---|
| 434 | ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
|
---|
[0dd3a2f] | 435 | Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
|
---|
[51b73452] | 436 |
|
---|
[0dd3a2f] | 437 | ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
|
---|
| 438 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
|
---|
| 439 | }
|
---|
[51b73452] | 440 |
|
---|
| 441 | ConditionalExpr::~ConditionalExpr() {
|
---|
[0dd3a2f] | 442 | delete arg1;
|
---|
| 443 | delete arg2;
|
---|
| 444 | delete arg3;
|
---|
[51b73452] | 445 | }
|
---|
| 446 |
|
---|
| 447 | void ConditionalExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 448 | os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl;
|
---|
[0dd3a2f] | 449 | arg1->print( os, indent+2 );
|
---|
[44b5ca0] | 450 | os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
|
---|
[0dd3a2f] | 451 | arg2->print( os, indent+2 );
|
---|
[44b5ca0] | 452 | os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
|
---|
[0dd3a2f] | 453 | arg3->print( os, indent+2 );
|
---|
| 454 | os << std::endl;
|
---|
| 455 | Expression::print( os, indent );
|
---|
| 456 | }
|
---|
| 457 |
|
---|
[3be261a] | 458 | AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
|
---|
| 459 |
|
---|
| 460 |
|
---|
[7f5566b] | 461 | void AsmExpr::print( std::ostream &os, int indent ) const {
|
---|
| 462 | os << "Asm Expression: " << std::endl;
|
---|
| 463 | if ( inout ) inout->print( os, indent + 2 );
|
---|
| 464 | if ( constraint ) constraint->print( os, indent + 2 );
|
---|
| 465 | if ( operand ) operand->print( os, indent + 2 );
|
---|
| 466 | }
|
---|
| 467 |
|
---|
[db4ecc5] | 468 |
|
---|
| 469 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
|
---|
| 470 | assert( callExpr );
|
---|
[906e24d] | 471 | assert( callExpr->has_result() );
|
---|
| 472 | set_result( callExpr->get_result()->clone() );
|
---|
[db4ecc5] | 473 | }
|
---|
| 474 |
|
---|
| 475 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
|
---|
| 476 | cloneAll( other.tempDecls, tempDecls );
|
---|
| 477 | cloneAll( other.returnDecls, returnDecls );
|
---|
| 478 | cloneAll( other.dtors, dtors );
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
|
---|
| 482 | delete callExpr;
|
---|
| 483 | deleteAll( tempDecls );
|
---|
| 484 | deleteAll( returnDecls );
|
---|
| 485 | deleteAll( dtors );
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 | void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
|
---|
[b6fe7e6] | 489 | os << "Implicit Copy Constructor Expression: " << std::endl;
|
---|
[db4ecc5] | 490 | assert( callExpr );
|
---|
| 491 | callExpr->print( os, indent + 2 );
|
---|
| 492 | os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;
|
---|
| 493 | printAll(tempDecls, os, indent+2);
|
---|
[dc2e7e0] | 494 | os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl;
|
---|
| 495 | printAll(returnDecls, os, indent+2);
|
---|
[db4ecc5] | 496 | Expression::print( os, indent );
|
---|
| 497 | }
|
---|
| 498 |
|
---|
[3be261a] | 499 |
|
---|
[b6fe7e6] | 500 | ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
|
---|
| 501 | // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
|
---|
| 502 | assert( callExpr );
|
---|
| 503 | Expression * arg = InitTweak::getCallArg( callExpr, 0 );
|
---|
| 504 | assert( arg );
|
---|
[906e24d] | 505 | set_result( maybeClone( arg->get_result() ) );
|
---|
[b6fe7e6] | 506 | }
|
---|
[3be261a] | 507 |
|
---|
[b6fe7e6] | 508 | ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | ConstructorExpr::~ConstructorExpr() {
|
---|
| 512 | delete callExpr;
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 | void ConstructorExpr::print( std::ostream &os, int indent ) const {
|
---|
| 516 | os << "Constructor Expression: " << std::endl;
|
---|
| 517 | assert( callExpr );
|
---|
| 518 | os << std::string( indent+2, ' ' );
|
---|
| 519 | callExpr->print( os, indent + 2 );
|
---|
| 520 | Expression::print( os, indent );
|
---|
[0dd3a2f] | 521 | }
|
---|
| 522 |
|
---|
[3be261a] | 523 |
|
---|
[630a82a] | 524 | CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
|
---|
[3c13c03] | 525 | assert( type && initializer );
|
---|
[906e24d] | 526 | set_result( type->clone() );
|
---|
[630a82a] | 527 | }
|
---|
| 528 |
|
---|
[3c13c03] | 529 | CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( other.type->clone() ), initializer( other.initializer->clone() ) {}
|
---|
[630a82a] | 530 |
|
---|
| 531 | CompoundLiteralExpr::~CompoundLiteralExpr() {
|
---|
| 532 | delete initializer;
|
---|
| 533 | delete type;
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
|
---|
| 537 | os << "Compound Literal Expression: " << std::endl;
|
---|
[3c13c03] | 538 | os << std::string( indent+2, ' ' );
|
---|
| 539 | type->print( os, indent + 2 );
|
---|
| 540 | os << std::string( indent+2, ' ' );
|
---|
| 541 | initializer->print( os, indent + 2 );
|
---|
[630a82a] | 542 | }
|
---|
| 543 |
|
---|
[b6fe7e6] | 544 | UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
|
---|
| 545 |
|
---|
| 546 | UntypedValofExpr::~UntypedValofExpr() { delete body; }
|
---|
| 547 |
|
---|
| 548 | void UntypedValofExpr::print( std::ostream &os, int indent ) const {
|
---|
| 549 | os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;
|
---|
| 550 | if ( get_body() != 0 )
|
---|
| 551 | get_body()->print( os, indent + 2 );
|
---|
| 552 | }
|
---|
| 553 |
|
---|
[d9e2280] | 554 | RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
|
---|
[3c13c03] | 555 | RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
|
---|
[8688ce1] | 556 | void RangeExpr::print( std::ostream &os, int indent ) const {
|
---|
[3c13c03] | 557 | os << "Range Expression: ";
|
---|
[8688ce1] | 558 | low->print( os, indent );
|
---|
| 559 | os << " ... ";
|
---|
| 560 | high->print( os, indent );
|
---|
| 561 | }
|
---|
[3be261a] | 562 |
|
---|
[6eb8948] | 563 | StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
|
---|
| 564 | assert( statements );
|
---|
| 565 | std::list< Statement * > & body = statements->get_kids();
|
---|
| 566 | if ( ! body.empty() ) {
|
---|
| 567 | if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
|
---|
[aa8f9df] | 568 | set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
|
---|
[6eb8948] | 569 | }
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
[3c13c03] | 572 | StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {}
|
---|
[6eb8948] | 573 | StmtExpr::~StmtExpr() {
|
---|
| 574 | delete statements;
|
---|
| 575 | }
|
---|
| 576 | void StmtExpr::print( std::ostream &os, int indent ) const {
|
---|
[3c13c03] | 577 | os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
|
---|
[6eb8948] | 578 | statements->print( os, indent+2 );
|
---|
| 579 | }
|
---|
| 580 |
|
---|
[3c13c03] | 581 |
|
---|
[bf32bb8] | 582 | long long UniqueExpr::count = 0;
|
---|
[77971f6] | 583 | UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( new Expression* ), object( new ObjectDecl* ), id( idVal ) {
|
---|
[bf32bb8] | 584 | assert( count != -1 );
|
---|
| 585 | if ( id == -1 ) id = count++;
|
---|
[3c13c03] | 586 | set_expr( expr );
|
---|
| 587 | assert( expr );
|
---|
[bf32bb8] | 588 | if ( expr->get_result() ) {
|
---|
| 589 | set_result( expr->get_result()->clone() );
|
---|
| 590 | }
|
---|
[77971f6] | 591 | set_object( nullptr );
|
---|
[3c13c03] | 592 | }
|
---|
[77971f6] | 593 | UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( other.expr ), object( other.object ), id( other.id ) {
|
---|
[3c13c03] | 594 | }
|
---|
| 595 | UniqueExpr::~UniqueExpr() {
|
---|
| 596 | if ( expr.unique() ) {
|
---|
| 597 | delete *expr;
|
---|
| 598 | }
|
---|
[77971f6] | 599 | if ( object.unique() ) {
|
---|
| 600 | delete *object;
|
---|
| 601 | }
|
---|
[3c13c03] | 602 | }
|
---|
| 603 | void UniqueExpr::print( std::ostream &os, int indent ) const {
|
---|
[bf32bb8] | 604 | os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' );
|
---|
[3c13c03] | 605 | get_expr()->print( os, indent+2 );
|
---|
[77971f6] | 606 | if ( get_object() ) {
|
---|
| 607 | os << " with decl: ";
|
---|
| 608 | get_object()->printShort( os, indent+2 );
|
---|
| 609 | }
|
---|
[3c13c03] | 610 | }
|
---|
| 611 |
|
---|
[3906301] | 612 | std::ostream & operator<<( std::ostream & out, const Expression * expr ) {
|
---|
[baf7fee] | 613 | expr->print( out );
|
---|
| 614 | return out;
|
---|
| 615 | }
|
---|
| 616 |
|
---|
[0dd3a2f] | 617 | // Local Variables: //
|
---|
| 618 | // tab-width: 4 //
|
---|
| 619 | // mode: c++ //
|
---|
| 620 | // compile-command: "make install" //
|
---|
| 621 | // End: //
|
---|