| 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 | //
 | 
|---|
| 7 | // Expression.cc --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Richard C. Bilson
 | 
|---|
| 10 | // Created On       : Mon May 18 07:44:20 2015
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Tue Jul 25 14:15:47 2017
 | 
|---|
| 13 | // Update Count     : 54
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "SynTree/Expression.h"
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <cassert>                   // for assert, assertf
 | 
|---|
| 19 | #include <iostream>                  // for ostream, operator<<, basic_ostream
 | 
|---|
| 20 | #include <list>                      // for list, _List_iterator, list<>::co...
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "Common/utility.h"          // for maybeClone, cloneAll, deleteAll
 | 
|---|
| 23 | #include "Declaration.h"             // for ObjectDecl, DeclarationWithType
 | 
|---|
| 24 | #include "Expression.h"              // for Expression, ImplicitCopyCtorExpr
 | 
|---|
| 25 | #include "InitTweak/InitTweak.h"     // for getCallArg, getPointerBase
 | 
|---|
| 26 | #include "Initializer.h"             // for Designation, Initializer
 | 
|---|
| 27 | #include "Statement.h"               // for CompoundStmt, ExprStmt, Statement
 | 
|---|
| 28 | #include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
 | 
|---|
| 29 | #include "SynTree/Constant.h"        // for Constant
 | 
|---|
| 30 | #include "Type.h"                    // for Type, BasicType, Type::Qualifiers
 | 
|---|
| 31 | #include "TypeSubstitution.h"        // for TypeSubstitution
 | 
|---|
| 32 | 
 | 
|---|
| 33 | 
 | 
|---|
| 34 | Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {}
 | 
|---|
| 35 | 
 | 
|---|
| 36 | Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) {
 | 
|---|
| 37 | }
 | 
|---|
| 38 | 
 | 
|---|
| 39 | Expression::~Expression() {
 | 
|---|
| 40 |         delete env;
 | 
|---|
| 41 |         delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
 | 
|---|
| 42 |         delete result;
 | 
|---|
| 43 | }
 | 
|---|
| 44 | 
 | 
|---|
| 45 | void Expression::print( std::ostream &os, int indent ) const {
 | 
|---|
| 46 |         if ( env ) {
 | 
|---|
| 47 |                 os << std::string( indent, ' ' ) << "with environment:" << std::endl;
 | 
|---|
| 48 |                 env->print( os, indent+2 );
 | 
|---|
| 49 |         } // if
 | 
|---|
| 50 | 
 | 
|---|
| 51 |         if ( argName ) {
 | 
|---|
| 52 |                 os << std::string( indent, ' ' ) << "with designator:";
 | 
|---|
| 53 |                 argName->print( os, indent+2 );
 | 
|---|
| 54 |         } // if
 | 
|---|
| 55 | 
 | 
|---|
| 56 |         if ( extension ) {
 | 
|---|
| 57 |                 os << std::string( indent, ' ' ) << "with extension:";
 | 
|---|
| 58 |         } // if
 | 
|---|
| 59 | }
 | 
|---|
| 60 | 
 | 
|---|
| 61 | ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
 | 
|---|
| 62 |         set_result( constant.get_type()->clone() );
 | 
|---|
| 63 | }
 | 
|---|
| 64 | 
 | 
|---|
| 65 | ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
 | 
|---|
| 66 | }
 | 
|---|
| 67 | 
 | 
|---|
| 68 | ConstantExpr::~ConstantExpr() {}
 | 
|---|
| 69 | 
 | 
|---|
| 70 | void ConstantExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 71 |         os << "constant expression " ;
 | 
|---|
| 72 |         constant.print( os );
 | 
|---|
| 73 |         Expression::print( os, indent );
 | 
|---|
| 74 | }
 | 
|---|
| 75 | 
 | 
|---|
| 76 | VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) {
 | 
|---|
| 77 |         assert( var );
 | 
|---|
| 78 |         assert( var->get_type() );
 | 
|---|
| 79 |         Type * type = var->get_type()->clone();
 | 
|---|
| 80 |         type->set_lvalue( true );
 | 
|---|
| 81 |         set_result( type );
 | 
|---|
| 82 | }
 | 
|---|
| 83 | 
 | 
|---|
| 84 | VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
 | 
|---|
| 85 | }
 | 
|---|
| 86 | 
 | 
|---|
| 87 | VariableExpr::~VariableExpr() {
 | 
|---|
| 88 |         // don't delete the declaration, since it points somewhere else in the tree
 | 
|---|
| 89 | }
 | 
|---|
| 90 | 
 | 
|---|
| 91 | void VariableExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 92 |         os << "Variable Expression: ";
 | 
|---|
| 93 | 
 | 
|---|
| 94 |         Declaration *decl = get_var();
 | 
|---|
| 95 |         if ( decl != 0) decl->printShort(os, indent + 2);
 | 
|---|
| 96 |         os << std::endl;
 | 
|---|
| 97 |         Expression::print( os, indent );
 | 
|---|
| 98 | }
 | 
|---|
| 99 | 
 | 
|---|
| 100 | SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
 | 
|---|
| 101 |                 Expression( _aname ), expr(expr_), type(0), isType(false) {
 | 
|---|
| 102 |         set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
 | 
|---|
| 103 | }
 | 
|---|
| 104 | 
 | 
|---|
| 105 | SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
 | 
|---|
| 106 |                 Expression( _aname ), expr(0), type(type_), isType(true) {
 | 
|---|
| 107 |         set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
 | 
|---|
| 108 | }
 | 
|---|
| 109 | 
 | 
|---|
| 110 | SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
 | 
|---|
| 111 |         Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
 | 
|---|
| 112 | }
 | 
|---|
| 113 | 
 | 
|---|
| 114 | SizeofExpr::~SizeofExpr() {
 | 
|---|
| 115 |         delete expr;
 | 
|---|
| 116 |         delete type;
 | 
|---|
| 117 | }
 | 
|---|
| 118 | 
 | 
|---|
| 119 | void SizeofExpr::print( std::ostream &os, int indent) const {
 | 
|---|
| 120 |         os << "Sizeof Expression on: ";
 | 
|---|
| 121 | 
 | 
|---|
| 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) {
 | 
|---|
| 133 |         set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
 | 
|---|
| 134 | }
 | 
|---|
| 135 | 
 | 
|---|
| 136 | AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
 | 
|---|
| 137 |                 Expression( _aname ), expr(0), type(type_), isType(true) {
 | 
|---|
| 138 |         set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
 | 
|---|
| 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 | 
 | 
|---|
| 153 |         if (isType)
 | 
|---|
| 154 |                 type->print(os, indent + 2);
 | 
|---|
| 155 |         else
 | 
|---|
| 156 |                 expr->print(os, indent + 2);
 | 
|---|
| 157 | 
 | 
|---|
| 158 |         os << std::endl;
 | 
|---|
| 159 |         Expression::print( os, indent );
 | 
|---|
| 160 | }
 | 
|---|
| 161 | 
 | 
|---|
| 162 | UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
 | 
|---|
| 163 |                 Expression( _aname ), type(type_), member(member_) {
 | 
|---|
| 164 |         set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
 | 
|---|
| 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 | 
 | 
|---|
| 187 | OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
 | 
|---|
| 188 |                 Expression( _aname ), type(type_), member(member_) {
 | 
|---|
| 189 |         set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
 | 
|---|
| 190 | }
 | 
|---|
| 191 | 
 | 
|---|
| 192 | OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
 | 
|---|
| 193 |         Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
 | 
|---|
| 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 | 
 | 
|---|
| 220 | OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
 | 
|---|
| 221 |         set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
 | 
|---|
| 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 | 
 | 
|---|
| 237 |         os << std::endl;
 | 
|---|
| 238 |         Expression::print( os, indent );
 | 
|---|
| 239 | }
 | 
|---|
| 240 | 
 | 
|---|
| 241 | AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
 | 
|---|
| 242 |                 Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
 | 
|---|
| 243 | }
 | 
|---|
| 244 | 
 | 
|---|
| 245 | AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
 | 
|---|
| 246 |                 Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
 | 
|---|
| 247 | }
 | 
|---|
| 248 | 
 | 
|---|
| 249 | AttrExpr::AttrExpr( const AttrExpr &other ) :
 | 
|---|
| 250 |                 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
 | 
|---|
| 251 | }
 | 
|---|
| 252 | 
 | 
|---|
| 253 | AttrExpr::~AttrExpr() {
 | 
|---|
| 254 |         delete attr;
 | 
|---|
| 255 |         delete expr;
 | 
|---|
| 256 |         delete type;
 | 
|---|
| 257 | }
 | 
|---|
| 258 | 
 | 
|---|
| 259 | void AttrExpr::print( std::ostream &os, int indent) const {
 | 
|---|
| 260 |         os << std::string( indent, ' ' ) << "Attr ";
 | 
|---|
| 261 |         attr->print( os, indent + 2 );
 | 
|---|
| 262 |         if ( isType || expr ) {
 | 
|---|
| 263 |                 os << "applied to: ";
 | 
|---|
| 264 | 
 | 
|---|
| 265 |                 if (isType)
 | 
|---|
| 266 |                         type->print(os, indent + 2);
 | 
|---|
| 267 |                 else
 | 
|---|
| 268 |                         expr->print(os, indent + 2);
 | 
|---|
| 269 |         } // if
 | 
|---|
| 270 | 
 | 
|---|
| 271 |         os << std::endl;
 | 
|---|
| 272 |         Expression::print( os, indent );
 | 
|---|
| 273 | }
 | 
|---|
| 274 | 
 | 
|---|
| 275 | CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
 | 
|---|
| 276 |         set_result(toType);
 | 
|---|
| 277 | }
 | 
|---|
| 278 | 
 | 
|---|
| 279 | CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
 | 
|---|
| 280 |         set_result( new VoidType( Type::Qualifiers() ) );
 | 
|---|
| 281 | }
 | 
|---|
| 282 | 
 | 
|---|
| 283 | CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
 | 
|---|
| 284 | }
 | 
|---|
| 285 | 
 | 
|---|
| 286 | CastExpr::~CastExpr() {
 | 
|---|
| 287 |         delete arg;
 | 
|---|
| 288 | }
 | 
|---|
| 289 | 
 | 
|---|
| 290 | void CastExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 291 |         os << "Cast of:" << std::endl << std::string( indent+2, ' ' );
 | 
|---|
| 292 |         arg->print(os, indent+2);
 | 
|---|
| 293 |         os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
 | 
|---|
| 294 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 295 |         if ( result->isVoid() ) {
 | 
|---|
| 296 |                 os << "nothing";
 | 
|---|
| 297 |         } else {
 | 
|---|
| 298 |                 result->print( os, indent+2 );
 | 
|---|
| 299 |         } // if
 | 
|---|
| 300 |         os << std::endl;
 | 
|---|
| 301 |         Expression::print( os, indent );
 | 
|---|
| 302 | }
 | 
|---|
| 303 | 
 | 
|---|
| 304 | VirtualCastExpr::VirtualCastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) {
 | 
|---|
| 305 |         set_result(toType);
 | 
|---|
| 306 | }
 | 
|---|
| 307 | 
 | 
|---|
| 308 | VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
 | 
|---|
| 309 | }
 | 
|---|
| 310 | 
 | 
|---|
| 311 | VirtualCastExpr::~VirtualCastExpr() {
 | 
|---|
| 312 |         delete arg;
 | 
|---|
| 313 | }
 | 
|---|
| 314 | 
 | 
|---|
| 315 | void VirtualCastExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 316 |         os << "Virtual Cast of:" << std::endl << std::string( indent+2, ' ' );
 | 
|---|
| 317 |         arg->print(os, indent+2);
 | 
|---|
| 318 |         os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
 | 
|---|
| 319 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 320 |         if ( ! result ) {
 | 
|---|
| 321 |                 os << "unknown";
 | 
|---|
| 322 |         } else {
 | 
|---|
| 323 |                 result->print( os, indent+2 );
 | 
|---|
| 324 |         } // if
 | 
|---|
| 325 |         os << std::endl;
 | 
|---|
| 326 |         Expression::print( os, indent );
 | 
|---|
| 327 | }
 | 
|---|
| 328 | 
 | 
|---|
| 329 | UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) :
 | 
|---|
| 330 |                 Expression( _aname ), member(_member), aggregate(_aggregate) {}
 | 
|---|
| 331 | 
 | 
|---|
| 332 | UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
 | 
|---|
| 333 |                 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
 | 
|---|
| 334 | }
 | 
|---|
| 335 | 
 | 
|---|
| 336 | UntypedMemberExpr::~UntypedMemberExpr() {
 | 
|---|
| 337 |         delete aggregate;
 | 
|---|
| 338 |         delete member;
 | 
|---|
| 339 | }
 | 
|---|
| 340 | 
 | 
|---|
| 341 | void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 342 |         os << "Untyped Member Expression, with field: " << std::endl;
 | 
|---|
| 343 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 344 |         get_member()->print(os, indent+4);
 | 
|---|
| 345 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 346 | 
 | 
|---|
| 347 |         Expression *agg = get_aggregate();
 | 
|---|
| 348 |         os << "from aggregate: " << std::endl;
 | 
|---|
| 349 |         if (agg != 0) {
 | 
|---|
| 350 |                 os << std::string( indent + 4, ' ' );
 | 
|---|
| 351 |                 agg->print(os, indent + 4);
 | 
|---|
| 352 |         }
 | 
|---|
| 353 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 354 |         Expression::print( os, indent );
 | 
|---|
| 355 | }
 | 
|---|
| 356 | 
 | 
|---|
| 357 | namespace {
 | 
|---|
| 358 |         TypeSubstitution makeSub( Type * t ) {
 | 
|---|
| 359 |                 if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
 | 
|---|
| 360 |                         return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
 | 
|---|
| 361 |                 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
 | 
|---|
| 362 |                         return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
 | 
|---|
| 363 |                 } else {
 | 
|---|
| 364 |                         assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() );
 | 
|---|
| 365 |                 }
 | 
|---|
| 366 |         }
 | 
|---|
| 367 | }
 | 
|---|
| 368 | 
 | 
|---|
| 369 | 
 | 
|---|
| 370 | MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
 | 
|---|
| 371 |                 Expression( _aname ), member(_member), aggregate(_aggregate) {
 | 
|---|
| 372 | 
 | 
|---|
| 373 |         TypeSubstitution sub( makeSub( aggregate->get_result() ) );
 | 
|---|
| 374 |         Type * res = member->get_type()->clone();
 | 
|---|
| 375 |         sub.apply( res );
 | 
|---|
| 376 |         set_result( res );
 | 
|---|
| 377 |         get_result()->set_lvalue( true );
 | 
|---|
| 378 | }
 | 
|---|
| 379 | 
 | 
|---|
| 380 | MemberExpr::MemberExpr( const MemberExpr &other ) :
 | 
|---|
| 381 |                 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
 | 
|---|
| 382 | }
 | 
|---|
| 383 | 
 | 
|---|
| 384 | MemberExpr::~MemberExpr() {
 | 
|---|
| 385 |         // don't delete the member declaration, since it points somewhere else in the tree
 | 
|---|
| 386 |         delete aggregate;
 | 
|---|
| 387 | }
 | 
|---|
| 388 | 
 | 
|---|
| 389 | void MemberExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 390 |         os << "Member Expression, with field: " << std::endl;
 | 
|---|
| 391 | 
 | 
|---|
| 392 |         assert( member );
 | 
|---|
| 393 |         os << std::string( indent + 2, ' ' );
 | 
|---|
| 394 |         member->print( os, indent + 2 );
 | 
|---|
| 395 |         os << std::endl;
 | 
|---|
| 396 | 
 | 
|---|
| 397 |         Expression *agg = get_aggregate();
 | 
|---|
| 398 |         os << std::string( indent, ' ' ) << "from aggregate: " << std::endl;
 | 
|---|
| 399 |         if (agg != 0) {
 | 
|---|
| 400 |                 os << std::string( indent + 2, ' ' );
 | 
|---|
| 401 |                 agg->print(os, indent + 2);
 | 
|---|
| 402 |         }
 | 
|---|
| 403 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 404 |         Expression::print( os, indent );
 | 
|---|
| 405 | }
 | 
|---|
| 406 | 
 | 
|---|
| 407 | UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) :
 | 
|---|
| 408 |                 Expression( _aname ), function(_function), args(_args) {}
 | 
|---|
| 409 | 
 | 
|---|
| 410 | UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
 | 
|---|
| 411 |                 Expression( other ), function( maybeClone( other.function ) ) {
 | 
|---|
| 412 |         cloneAll( other.args, args );
 | 
|---|
| 413 | }
 | 
|---|
| 414 | 
 | 
|---|
| 415 | UntypedExpr::~UntypedExpr() {
 | 
|---|
| 416 |         delete function;
 | 
|---|
| 417 |         deleteAll( args );
 | 
|---|
| 418 | }
 | 
|---|
| 419 | 
 | 
|---|
| 420 | UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
 | 
|---|
| 421 |         UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
 | 
|---|
| 422 |         if ( Type * type = expr->get_result() ) {
 | 
|---|
| 423 |                 Type * base = InitTweak::getPointerBase( type );
 | 
|---|
| 424 |                 if ( ! base ) {
 | 
|---|
| 425 |                         std::cerr << type << std::endl;
 | 
|---|
| 426 |                 }
 | 
|---|
| 427 |                 assertf( base, "expected pointer type in dereference\n" );
 | 
|---|
| 428 |                 ret->set_result( maybeClone( base ) );
 | 
|---|
| 429 |         }
 | 
|---|
| 430 |         return ret;
 | 
|---|
| 431 | }
 | 
|---|
| 432 | 
 | 
|---|
| 433 | UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) {
 | 
|---|
| 434 |         assert( arg1 && arg2 );
 | 
|---|
| 435 |         UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } );
 | 
|---|
| 436 |         if ( arg1->get_result() && arg2->get_result() ) {
 | 
|---|
| 437 |                 // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
 | 
|---|
| 438 |                 // so the result is the type of the RHS
 | 
|---|
| 439 |                 ret->set_result( arg2->get_result()->clone() );
 | 
|---|
| 440 |         }
 | 
|---|
| 441 |         return ret;
 | 
|---|
| 442 | }
 | 
|---|
| 443 | 
 | 
|---|
| 444 | 
 | 
|---|
| 445 | void UntypedExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 446 |         os << "Applying untyped: " << std::endl;
 | 
|---|
| 447 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 448 |         function->print(os, indent + 2);
 | 
|---|
| 449 |         os << std::string( indent, ' ' ) << "...to: " << std::endl;
 | 
|---|
| 450 |         printAll(args, os, indent + 2);
 | 
|---|
| 451 |         Expression::print( os, indent );
 | 
|---|
| 452 | }
 | 
|---|
| 453 | 
 | 
|---|
| 454 | void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
 | 
|---|
| 455 |         std::list<Expression *>::const_iterator i;
 | 
|---|
| 456 |         for (i = args.begin(); i != args.end(); i++) {
 | 
|---|
| 457 |                 os << std::string(indent, ' ' );
 | 
|---|
| 458 |                 (*i)->print(os, indent);
 | 
|---|
| 459 |         }
 | 
|---|
| 460 | }
 | 
|---|
| 461 | 
 | 
|---|
| 462 | NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {
 | 
|---|
| 463 |         assertf(_name != "0", "Zero is not a valid name\n");
 | 
|---|
| 464 |         assertf(_name != "1", "One is not a valid name\n");
 | 
|---|
| 465 | }
 | 
|---|
| 466 | 
 | 
|---|
| 467 | NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
 | 
|---|
| 468 | }
 | 
|---|
| 469 | 
 | 
|---|
| 470 | NameExpr::~NameExpr() {}
 | 
|---|
| 471 | 
 | 
|---|
| 472 | void NameExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 473 |         os << "Name: " << get_name() << std::endl;
 | 
|---|
| 474 |         Expression::print( os, indent );
 | 
|---|
| 475 | }
 | 
|---|
| 476 | 
 | 
|---|
| 477 | LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
 | 
|---|
| 478 |                 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
 | 
|---|
| 479 |         set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
 | 
|---|
| 480 | }
 | 
|---|
| 481 | 
 | 
|---|
| 482 | LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
 | 
|---|
| 483 |                 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
 | 
|---|
| 484 | }
 | 
|---|
| 485 | 
 | 
|---|
| 486 | LogicalExpr::~LogicalExpr() {
 | 
|---|
| 487 |         delete arg1;
 | 
|---|
| 488 |         delete arg2;
 | 
|---|
| 489 | }
 | 
|---|
| 490 | 
 | 
|---|
| 491 | void LogicalExpr::print( std::ostream &os, int indent )const {
 | 
|---|
| 492 |         os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
 | 
|---|
| 493 |         arg1->print(os);
 | 
|---|
| 494 |         os << " and ";
 | 
|---|
| 495 |         arg2->print(os);
 | 
|---|
| 496 |         os << std::endl;
 | 
|---|
| 497 |         Expression::print( os, indent );
 | 
|---|
| 498 | }
 | 
|---|
| 499 | 
 | 
|---|
| 500 | ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
 | 
|---|
| 501 |                 Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
 | 
|---|
| 502 | 
 | 
|---|
| 503 | ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
 | 
|---|
| 504 |                 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
 | 
|---|
| 505 | }
 | 
|---|
| 506 | 
 | 
|---|
| 507 | ConditionalExpr::~ConditionalExpr() {
 | 
|---|
| 508 |         delete arg1;
 | 
|---|
| 509 |         delete arg2;
 | 
|---|
| 510 |         delete arg3;
 | 
|---|
| 511 | }
 | 
|---|
| 512 | 
 | 
|---|
| 513 | void ConditionalExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 514 |         os << "Conditional expression on: " << std::endl;
 | 
|---|
| 515 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 516 |         arg1->print( os, indent+2 );
 | 
|---|
| 517 |         os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
 | 
|---|
| 518 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 519 |         arg2->print( os, indent+2 );
 | 
|---|
| 520 |         os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
 | 
|---|
| 521 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 522 |         arg3->print( os, indent+2 );
 | 
|---|
| 523 |         os << std::endl;
 | 
|---|
| 524 |         Expression::print( os, indent );
 | 
|---|
| 525 | }
 | 
|---|
| 526 | 
 | 
|---|
| 527 | AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
 | 
|---|
| 528 | 
 | 
|---|
| 529 | 
 | 
|---|
| 530 | void AsmExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 531 |         os << "Asm Expression: " << std::endl;
 | 
|---|
| 532 |         if ( inout ) inout->print( os, indent + 2 );
 | 
|---|
| 533 |         if ( constraint ) constraint->print( os, indent + 2 );
 | 
|---|
| 534 |         if ( operand ) operand->print( os, indent + 2 );
 | 
|---|
| 535 | }
 | 
|---|
| 536 | 
 | 
|---|
| 537 | 
 | 
|---|
| 538 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) {
 | 
|---|
| 539 |         assert( callExpr );
 | 
|---|
| 540 |         assert( callExpr->has_result() );
 | 
|---|
| 541 |         set_result( callExpr->get_result()->clone() );
 | 
|---|
| 542 | }
 | 
|---|
| 543 | 
 | 
|---|
| 544 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
 | 
|---|
| 545 |         cloneAll( other.tempDecls, tempDecls );
 | 
|---|
| 546 |         cloneAll( other.returnDecls, returnDecls );
 | 
|---|
| 547 |         cloneAll( other.dtors, dtors );
 | 
|---|
| 548 | }
 | 
|---|
| 549 | 
 | 
|---|
| 550 | ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() {
 | 
|---|
| 551 |         set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment
 | 
|---|
| 552 |         delete callExpr;
 | 
|---|
| 553 |         deleteAll( tempDecls );
 | 
|---|
| 554 |         deleteAll( returnDecls );
 | 
|---|
| 555 |         deleteAll( dtors );
 | 
|---|
| 556 | }
 | 
|---|
| 557 | 
 | 
|---|
| 558 | void ImplicitCopyCtorExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 559 |         os <<  "Implicit Copy Constructor Expression: " << std::endl;
 | 
|---|
| 560 |         assert( callExpr );
 | 
|---|
| 561 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 562 |         callExpr->print( os, indent + 2 );
 | 
|---|
| 563 |         os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl;
 | 
|---|
| 564 |         printAll(tempDecls, os, indent+2);
 | 
|---|
| 565 |         os << std::endl << std::string( indent, ' ' ) << "with return temporaries:" << std::endl;
 | 
|---|
| 566 |         printAll(returnDecls, os, indent+2);
 | 
|---|
| 567 |         Expression::print( os, indent );
 | 
|---|
| 568 | }
 | 
|---|
| 569 | 
 | 
|---|
| 570 | 
 | 
|---|
| 571 | ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) {
 | 
|---|
| 572 |         // allow resolver to type a constructor used as an expression as if it has the same type as its first argument
 | 
|---|
| 573 |         assert( callExpr );
 | 
|---|
| 574 |         Expression * arg = InitTweak::getCallArg( callExpr, 0 );
 | 
|---|
| 575 |         assert( arg );
 | 
|---|
| 576 |         set_result( maybeClone( arg->get_result() ) );
 | 
|---|
| 577 | }
 | 
|---|
| 578 | 
 | 
|---|
| 579 | ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) {
 | 
|---|
| 580 | }
 | 
|---|
| 581 | 
 | 
|---|
| 582 | ConstructorExpr::~ConstructorExpr() {
 | 
|---|
| 583 |         delete callExpr;
 | 
|---|
| 584 | }
 | 
|---|
| 585 | 
 | 
|---|
| 586 | void ConstructorExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 587 |         os <<  "Constructor Expression: " << std::endl;
 | 
|---|
| 588 |         assert( callExpr );
 | 
|---|
| 589 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 590 |         callExpr->print( os, indent + 2 );
 | 
|---|
| 591 |         Expression::print( os, indent );
 | 
|---|
| 592 | }
 | 
|---|
| 593 | 
 | 
|---|
| 594 | 
 | 
|---|
| 595 | CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) {
 | 
|---|
| 596 |         assert( type && initializer );
 | 
|---|
| 597 |         set_result( type );
 | 
|---|
| 598 | }
 | 
|---|
| 599 | 
 | 
|---|
| 600 | CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {}
 | 
|---|
| 601 | 
 | 
|---|
| 602 | CompoundLiteralExpr::~CompoundLiteralExpr() {
 | 
|---|
| 603 |         delete initializer;
 | 
|---|
| 604 | }
 | 
|---|
| 605 | 
 | 
|---|
| 606 | void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 607 |         os << "Compound Literal Expression: " << std::endl;
 | 
|---|
| 608 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 609 |         get_result()->print( os, indent + 2 );
 | 
|---|
| 610 |         os << std::string( indent+2, ' ' );
 | 
|---|
| 611 |         initializer->print( os, indent + 2 );
 | 
|---|
| 612 |         Expression::print( os, indent );
 | 
|---|
| 613 | }
 | 
|---|
| 614 | 
 | 
|---|
| 615 | RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {}
 | 
|---|
| 616 | RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}
 | 
|---|
| 617 | void RangeExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 618 |         os << "Range Expression: ";
 | 
|---|
| 619 |         low->print( os, indent );
 | 
|---|
| 620 |         os << " ... ";
 | 
|---|
| 621 |         high->print( os, indent );
 | 
|---|
| 622 |         Expression::print( os, indent );
 | 
|---|
| 623 | }
 | 
|---|
| 624 | 
 | 
|---|
| 625 | StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
 | 
|---|
| 626 |         assert( statements );
 | 
|---|
| 627 |         std::list< Statement * > & body = statements->get_kids();
 | 
|---|
| 628 |         if ( ! body.empty() ) {
 | 
|---|
| 629 |                 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
 | 
|---|
| 630 |                         set_result( maybeClone( exprStmt->get_expr()->get_result() ) );
 | 
|---|
| 631 |                 }
 | 
|---|
| 632 |         }
 | 
|---|
| 633 | }
 | 
|---|
| 634 | StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
 | 
|---|
| 635 |         cloneAll( other.returnDecls, returnDecls );
 | 
|---|
| 636 |         cloneAll( other.dtors, dtors );
 | 
|---|
| 637 | }
 | 
|---|
| 638 | StmtExpr::~StmtExpr() {
 | 
|---|
| 639 |         delete statements;
 | 
|---|
| 640 |         deleteAll( dtors );
 | 
|---|
| 641 |         deleteAll( returnDecls );
 | 
|---|
| 642 | }
 | 
|---|
| 643 | void StmtExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 644 |         os << "Statement Expression: " << std::endl << std::string( indent, ' ' );
 | 
|---|
| 645 |         statements->print( os, indent+2 );
 | 
|---|
| 646 |         if ( ! returnDecls.empty() ) {
 | 
|---|
| 647 |                 os << std::string( indent+2, ' ' ) << "with returnDecls: ";
 | 
|---|
| 648 |                 printAll( returnDecls, os, indent+2 );
 | 
|---|
| 649 |         }
 | 
|---|
| 650 |         if ( ! dtors.empty() ) {
 | 
|---|
| 651 |                 os << std::string( indent+2, ' ' ) << "with dtors: ";
 | 
|---|
| 652 |                 printAll( dtors, os, indent+2 );
 | 
|---|
| 653 |         }
 | 
|---|
| 654 |         Expression::print( os, indent );
 | 
|---|
| 655 | }
 | 
|---|
| 656 | 
 | 
|---|
| 657 | 
 | 
|---|
| 658 | long long UniqueExpr::count = 0;
 | 
|---|
| 659 | UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {
 | 
|---|
| 660 |         assert( expr );
 | 
|---|
| 661 |         assert( count != -1 );
 | 
|---|
| 662 |         if ( id == -1 ) id = count++;
 | 
|---|
| 663 |         if ( expr->get_result() ) {
 | 
|---|
| 664 |                 set_result( expr->get_result()->clone() );
 | 
|---|
| 665 |         }
 | 
|---|
| 666 | }
 | 
|---|
| 667 | UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {
 | 
|---|
| 668 | }
 | 
|---|
| 669 | UniqueExpr::~UniqueExpr() {
 | 
|---|
| 670 |         delete expr;
 | 
|---|
| 671 |         delete object;
 | 
|---|
| 672 |         delete var;
 | 
|---|
| 673 | }
 | 
|---|
| 674 | void UniqueExpr::print( std::ostream &os, int indent ) const {
 | 
|---|
| 675 |         os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' );
 | 
|---|
| 676 |         get_expr()->print( os, indent+2 );
 | 
|---|
| 677 |         if ( get_object() ) {
 | 
|---|
| 678 |                 os << std::string( indent+2, ' ' ) << "with decl: ";
 | 
|---|
| 679 |                 get_object()->printShort( os, indent+2 );
 | 
|---|
| 680 |         }
 | 
|---|
| 681 |         Expression::print( os, indent );
 | 
|---|
| 682 | }
 | 
|---|
| 683 | 
 | 
|---|
| 684 | InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {}
 | 
|---|
| 685 | InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {}
 | 
|---|
| 686 | InitAlternative::~InitAlternative() {
 | 
|---|
| 687 |         delete type;
 | 
|---|
| 688 |         delete designation;
 | 
|---|
| 689 | }
 | 
|---|
| 690 | 
 | 
|---|
| 691 | UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {}
 | 
|---|
| 692 | UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {}
 | 
|---|
| 693 | UntypedInitExpr::~UntypedInitExpr() {
 | 
|---|
| 694 |         delete expr;
 | 
|---|
| 695 | }
 | 
|---|
| 696 | 
 | 
|---|
| 697 | void UntypedInitExpr::print( std::ostream & os, int indent ) const {
 | 
|---|
| 698 |         os << "Untyped Init Expression" << std::endl << std::string( indent+2, ' ' );
 | 
|---|
| 699 |         expr->print( os, indent+2 );
 | 
|---|
| 700 |         if ( ! initAlts.empty() ) {
 | 
|---|
| 701 |                 for ( const InitAlternative & alt : initAlts ) {
 | 
|---|
| 702 |                         os << std::string( indent+2, ' ' ) <<  "InitAlternative: ";
 | 
|---|
| 703 |                         alt.type->print( os, indent+2 );
 | 
|---|
| 704 |                         alt.designation->print( os, indent+2 );
 | 
|---|
| 705 |                 }
 | 
|---|
| 706 |         }
 | 
|---|
| 707 | }
 | 
|---|
| 708 | 
 | 
|---|
| 709 | InitExpr::InitExpr( Expression * expr, Designation * designation ) : expr( expr ), designation( designation ) {
 | 
|---|
| 710 |         set_result( expr->get_result()->clone() );
 | 
|---|
| 711 | }
 | 
|---|
| 712 | InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {}
 | 
|---|
| 713 | InitExpr::~InitExpr() {
 | 
|---|
| 714 |         delete expr;
 | 
|---|
| 715 |         delete designation;
 | 
|---|
| 716 | }
 | 
|---|
| 717 | 
 | 
|---|
| 718 | void InitExpr::print( std::ostream & os, int indent ) const {
 | 
|---|
| 719 |         os << "Init Expression" << std::endl << std::string( indent+2, ' ' );
 | 
|---|
| 720 |         expr->print( os, indent+2 );
 | 
|---|
| 721 |         os << std::string( indent+2, ' ' ) << "with designation: ";
 | 
|---|
| 722 |         designation->print( os, indent+2 );
 | 
|---|
| 723 | }
 | 
|---|
| 724 | 
 | 
|---|
| 725 | 
 | 
|---|
| 726 | std::ostream & operator<<( std::ostream & out, const Expression * expr ) {
 | 
|---|
| 727 |         if ( expr ) {
 | 
|---|
| 728 |                 expr->print( out );
 | 
|---|
| 729 |         } else {
 | 
|---|
| 730 |                 out << "nullptr";
 | 
|---|
| 731 |         }
 | 
|---|
| 732 |         return out;
 | 
|---|
| 733 | }
 | 
|---|
| 734 | 
 | 
|---|
| 735 | // Local Variables: //
 | 
|---|
| 736 | // tab-width: 4 //
 | 
|---|
| 737 | // mode: c++ //
 | 
|---|
| 738 | // compile-command: "make install" //
 | 
|---|
| 739 | // End: //
 | 
|---|