| [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 | 
|---|
| [a5f0529] | 12 | // Last Modified On : Tue Jul 25 14:15:47 2017 | 
|---|
|  | 13 | // Update Count     : 54 | 
|---|
| [0dd3a2f] | 14 | // | 
|---|
|  | 15 |  | 
|---|
| [ea6332d] | 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 | 
|---|
| [51b73452] | 32 |  | 
|---|
| [b0440b7] | 33 | #include "GenPoly/Lvalue.h" | 
|---|
| [51b73452] | 34 |  | 
|---|
| [68195a6] | 35 | void printInferParams( const InferredParams & inferParams, std::ostream &os, Indenter indent, int level ) { | 
|---|
|  | 36 | if ( ! inferParams.empty() ) { | 
|---|
|  | 37 | os << indent << "with inferred parameters " << level << ":" << std::endl; | 
|---|
|  | 38 | for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) { | 
|---|
|  | 39 | os << indent+1; | 
|---|
|  | 40 | Declaration::declFromId( i->second.decl )->printShort( os, indent+1 ); | 
|---|
|  | 41 | os << std::endl; | 
|---|
|  | 42 | printInferParams( *i->second.inferParams, os, indent+1, level+1 ); | 
|---|
|  | 43 | } // for | 
|---|
|  | 44 | } // if | 
|---|
|  | 45 | } | 
|---|
|  | 46 |  | 
|---|
| [bf4b4cf] | 47 | Expression::Expression() : result( 0 ), env( 0 ) {} | 
|---|
| [0dd3a2f] | 48 |  | 
|---|
| [df626eb] | 49 | Expression::Expression( const Expression &other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ) { | 
|---|
| [0dd3a2f] | 50 | } | 
|---|
|  | 51 |  | 
|---|
|  | 52 | Expression::~Expression() { | 
|---|
|  | 53 | delete env; | 
|---|
| [906e24d] | 54 | delete result; | 
|---|
| [51b73452] | 55 | } | 
|---|
|  | 56 |  | 
|---|
| [50377a4] | 57 | void Expression::print( std::ostream &os, Indenter indent ) const { | 
|---|
| [68195a6] | 58 | printInferParams( inferParams, os, indent+1, 0 ); | 
|---|
|  | 59 |  | 
|---|
| [0dd3a2f] | 60 | if ( env ) { | 
|---|
| [50377a4] | 61 | os << std::endl << indent << "... with environment:" << std::endl; | 
|---|
|  | 62 | env->print( os, indent+1 ); | 
|---|
| [0dd3a2f] | 63 | } // if | 
|---|
| [e04ef3a] | 64 |  | 
|---|
|  | 65 | if ( extension ) { | 
|---|
| [50377a4] | 66 | os << std::endl << indent << "... with extension:"; | 
|---|
| [e04ef3a] | 67 | } // if | 
|---|
| [51b73452] | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [bf4b4cf] | 70 | ConstantExpr::ConstantExpr( Constant _c ) : Expression(), constant( _c ) { | 
|---|
| [906e24d] | 71 | set_result( constant.get_type()->clone() ); | 
|---|
| [51b73452] | 72 | } | 
|---|
|  | 73 |  | 
|---|
| [0dd3a2f] | 74 | ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) { | 
|---|
|  | 75 | } | 
|---|
| [51b73452] | 76 |  | 
|---|
|  | 77 | ConstantExpr::~ConstantExpr() {} | 
|---|
|  | 78 |  | 
|---|
| [50377a4] | 79 | void ConstantExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
| [60089f4] | 80 | os << "constant expression " ; | 
|---|
| [cf0941d] | 81 | constant.print( os ); | 
|---|
| [0dd3a2f] | 82 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 83 | } | 
|---|
|  | 84 |  | 
|---|
| [ddb80bd] | 85 | long long int ConstantExpr::intValue() const { | 
|---|
|  | 86 | if ( BasicType * basicType = dynamic_cast< BasicType * >( result ) ) { | 
|---|
|  | 87 | if ( basicType->isInteger() ) { | 
|---|
|  | 88 | return get_constant()->get_ival(); | 
|---|
|  | 89 | } | 
|---|
|  | 90 | } else if ( dynamic_cast< OneType * >( result ) ) { | 
|---|
|  | 91 | return 1; | 
|---|
|  | 92 | } else if ( dynamic_cast< ZeroType * >( result ) ) { | 
|---|
|  | 93 | return 0; | 
|---|
|  | 94 | } | 
|---|
| [a16764a6] | 95 | SemanticError( this, "Constant expression of non-integral type " ); | 
|---|
| [ddb80bd] | 96 | } | 
|---|
|  | 97 |  | 
|---|
| [bf4b4cf] | 98 | VariableExpr::VariableExpr( DeclarationWithType *_var ) : Expression(), var( _var ) { | 
|---|
| [db4ecc5] | 99 | assert( var ); | 
|---|
|  | 100 | assert( var->get_type() ); | 
|---|
| [906e24d] | 101 | Type * type = var->get_type()->clone(); | 
|---|
| [615a096] | 102 | type->set_lvalue( true ); | 
|---|
| [3de176d] | 103 |  | 
|---|
|  | 104 | // xxx - doesn't quite work yet - get different alternatives with the same cost | 
|---|
|  | 105 |  | 
|---|
|  | 106 | // // enumerators are not lvalues | 
|---|
|  | 107 | // if ( EnumInstType * inst = dynamic_cast< EnumInstType * >( var->get_type() ) ) { | 
|---|
|  | 108 | //      assert( inst->baseEnum ); | 
|---|
|  | 109 | //      EnumDecl * decl = inst->baseEnum; | 
|---|
| [0690350] | 110 | //      long long int value; | 
|---|
|  | 111 | //      if ( decl->valueOf( var, value ) ) { | 
|---|
|  | 112 | //              type->set_lvalue( false ); | 
|---|
| [3de176d] | 113 | //      } | 
|---|
|  | 114 | // } | 
|---|
|  | 115 |  | 
|---|
| [906e24d] | 116 | set_result( type ); | 
|---|
| [51b73452] | 117 | } | 
|---|
|  | 118 |  | 
|---|
| [0dd3a2f] | 119 | VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) { | 
|---|
| [51b73452] | 120 | } | 
|---|
|  | 121 |  | 
|---|
| [0dd3a2f] | 122 | VariableExpr::~VariableExpr() { | 
|---|
|  | 123 | // don't delete the declaration, since it points somewhere else in the tree | 
|---|
| [51b73452] | 124 | } | 
|---|
|  | 125 |  | 
|---|
| [8a6cf7e] | 126 | VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) { | 
|---|
|  | 127 | VariableExpr * funcExpr = new VariableExpr( func ); | 
|---|
|  | 128 | funcExpr->set_result( new PointerType( Type::Qualifiers(), funcExpr->get_result() ) ); | 
|---|
|  | 129 | return funcExpr; | 
|---|
|  | 130 | } | 
|---|
|  | 131 |  | 
|---|
| [50377a4] | 132 | void VariableExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
| [89231bc] | 133 | os << "Variable Expression: "; | 
|---|
| [50377a4] | 134 | var->printShort(os, indent); | 
|---|
| [0dd3a2f] | 135 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 136 | } | 
|---|
|  | 137 |  | 
|---|
| [bf4b4cf] | 138 | SizeofExpr::SizeofExpr( Expression *expr_ ) : | 
|---|
|  | 139 | Expression(), expr(expr_), type(0), isType(false) { | 
|---|
| [906e24d] | 140 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); | 
|---|
| [51b73452] | 141 | } | 
|---|
|  | 142 |  | 
|---|
| [bf4b4cf] | 143 | SizeofExpr::SizeofExpr( Type *type_ ) : | 
|---|
|  | 144 | Expression(), expr(0), type(type_), isType(true) { | 
|---|
| [906e24d] | 145 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); | 
|---|
| [51b73452] | 146 | } | 
|---|
|  | 147 |  | 
|---|
| [0dd3a2f] | 148 | SizeofExpr::SizeofExpr( const SizeofExpr &other ) : | 
|---|
|  | 149 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { | 
|---|
| [51b73452] | 150 | } | 
|---|
|  | 151 |  | 
|---|
| [0dd3a2f] | 152 | SizeofExpr::~SizeofExpr() { | 
|---|
|  | 153 | delete expr; | 
|---|
|  | 154 | delete type; | 
|---|
| [51b73452] | 155 | } | 
|---|
|  | 156 |  | 
|---|
| [50377a4] | 157 | void SizeofExpr::print( std::ostream &os, Indenter indent) const { | 
|---|
| [89231bc] | 158 | os << "Sizeof Expression on: "; | 
|---|
| [50377a4] | 159 | if (isType) type->print(os, indent+1); | 
|---|
|  | 160 | else expr->print(os, indent+1); | 
|---|
| [47534159] | 161 | Expression::print( os, indent ); | 
|---|
|  | 162 | } | 
|---|
|  | 163 |  | 
|---|
| [bf4b4cf] | 164 | AlignofExpr::AlignofExpr( Expression *expr_ ) : | 
|---|
|  | 165 | Expression(), expr(expr_), type(0), isType(false) { | 
|---|
| [906e24d] | 166 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); | 
|---|
| [47534159] | 167 | } | 
|---|
|  | 168 |  | 
|---|
| [bf4b4cf] | 169 | AlignofExpr::AlignofExpr( Type *type_ ) : | 
|---|
|  | 170 | Expression(), expr(0), type(type_), isType(true) { | 
|---|
| [906e24d] | 171 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); | 
|---|
| [47534159] | 172 | } | 
|---|
|  | 173 |  | 
|---|
|  | 174 | AlignofExpr::AlignofExpr( const AlignofExpr &other ) : | 
|---|
|  | 175 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { | 
|---|
|  | 176 | } | 
|---|
|  | 177 |  | 
|---|
|  | 178 | AlignofExpr::~AlignofExpr() { | 
|---|
|  | 179 | delete expr; | 
|---|
|  | 180 | delete type; | 
|---|
|  | 181 | } | 
|---|
|  | 182 |  | 
|---|
| [50377a4] | 183 | void AlignofExpr::print( std::ostream &os, Indenter indent) const { | 
|---|
| [f19339e] | 184 | os << "Alignof Expression on: "; | 
|---|
| [50377a4] | 185 | if (isType) type->print(os, indent+1); | 
|---|
|  | 186 | else expr->print(os, indent+1); | 
|---|
| [0dd3a2f] | 187 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 188 | } | 
|---|
|  | 189 |  | 
|---|
| [bf4b4cf] | 190 | UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type, const std::string &member ) : | 
|---|
|  | 191 | Expression(), type(type), member(member) { | 
|---|
| [50377a4] | 192 | assert( type ); | 
|---|
| [906e24d] | 193 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); | 
|---|
| [2a4b088] | 194 | } | 
|---|
|  | 195 |  | 
|---|
|  | 196 | UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) : | 
|---|
|  | 197 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} | 
|---|
|  | 198 |  | 
|---|
|  | 199 | UntypedOffsetofExpr::~UntypedOffsetofExpr() { | 
|---|
|  | 200 | delete type; | 
|---|
|  | 201 | } | 
|---|
|  | 202 |  | 
|---|
| [50377a4] | 203 | void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const { | 
|---|
|  | 204 | os << "Untyped Offsetof Expression on member " << member << " of "; | 
|---|
|  | 205 | type->print(os, indent+1); | 
|---|
| [2a4b088] | 206 | Expression::print( os, indent ); | 
|---|
|  | 207 | } | 
|---|
|  | 208 |  | 
|---|
| [bf4b4cf] | 209 | OffsetofExpr::OffsetofExpr( Type *type, DeclarationWithType *member ) : | 
|---|
|  | 210 | Expression(), type(type), member(member) { | 
|---|
| [50377a4] | 211 | assert( member ); | 
|---|
|  | 212 | assert( type ); | 
|---|
| [906e24d] | 213 | set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); | 
|---|
| [25a054f] | 214 | } | 
|---|
|  | 215 |  | 
|---|
|  | 216 | OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) : | 
|---|
| [79970ed] | 217 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} | 
|---|
| [25a054f] | 218 |  | 
|---|
|  | 219 | OffsetofExpr::~OffsetofExpr() { | 
|---|
|  | 220 | delete type; | 
|---|
|  | 221 | } | 
|---|
|  | 222 |  | 
|---|
| [50377a4] | 223 | void OffsetofExpr::print( std::ostream &os, Indenter indent) const { | 
|---|
|  | 224 | os << "Offsetof Expression on member " << member->name << " of "; | 
|---|
|  | 225 | type->print(os, indent+1); | 
|---|
| [25a054f] | 226 | Expression::print( os, indent ); | 
|---|
|  | 227 | } | 
|---|
|  | 228 |  | 
|---|
| [bf4b4cf] | 229 | OffsetPackExpr::OffsetPackExpr( StructInstType *type ) : Expression(), type( type ) { | 
|---|
| [50377a4] | 230 | assert( type ); | 
|---|
| [906e24d] | 231 | set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); | 
|---|
| [afc1045] | 232 | } | 
|---|
|  | 233 |  | 
|---|
|  | 234 | OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {} | 
|---|
|  | 235 |  | 
|---|
|  | 236 | OffsetPackExpr::~OffsetPackExpr() { delete type; } | 
|---|
|  | 237 |  | 
|---|
| [50377a4] | 238 | void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 239 | os << "Offset pack expression on "; | 
|---|
|  | 240 | type->print(os, indent+1); | 
|---|
| [25a054f] | 241 | Expression::print( os, indent ); | 
|---|
|  | 242 | } | 
|---|
|  | 243 |  | 
|---|
| [bf4b4cf] | 244 | AttrExpr::AttrExpr( Expression *attr, Expression *expr_ ) : | 
|---|
|  | 245 | Expression(), attr( attr ), expr(expr_), type(0), isType(false) { | 
|---|
| [51b73452] | 246 | } | 
|---|
|  | 247 |  | 
|---|
| [bf4b4cf] | 248 | AttrExpr::AttrExpr( Expression *attr, Type *type_ ) : | 
|---|
|  | 249 | Expression(), attr( attr ), expr(0), type(type_), isType(true) { | 
|---|
| [51b73452] | 250 | } | 
|---|
|  | 251 |  | 
|---|
| [0dd3a2f] | 252 | AttrExpr::AttrExpr( const AttrExpr &other ) : | 
|---|
|  | 253 | Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { | 
|---|
| [51b73452] | 254 | } | 
|---|
|  | 255 |  | 
|---|
| [0dd3a2f] | 256 | AttrExpr::~AttrExpr() { | 
|---|
|  | 257 | delete attr; | 
|---|
|  | 258 | delete expr; | 
|---|
|  | 259 | delete type; | 
|---|
| [51b73452] | 260 | } | 
|---|
|  | 261 |  | 
|---|
| [50377a4] | 262 | void AttrExpr::print( std::ostream &os, Indenter indent) const { | 
|---|
| [f19339e] | 263 | os << "Attr "; | 
|---|
| [50377a4] | 264 | attr->print( os, indent+1); | 
|---|
| [0dd3a2f] | 265 | if ( isType || expr ) { | 
|---|
|  | 266 | os << "applied to: "; | 
|---|
| [50377a4] | 267 | if (isType) type->print(os, indent+1); | 
|---|
|  | 268 | else expr->print(os, indent+1); | 
|---|
| [0dd3a2f] | 269 | } // if | 
|---|
|  | 270 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 271 | } | 
|---|
|  | 272 |  | 
|---|
| [c0bf94e] | 273 | CastExpr::CastExpr( Expression *arg, Type *toType, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) { | 
|---|
| [906e24d] | 274 | set_result(toType); | 
|---|
| [51b73452] | 275 | } | 
|---|
|  | 276 |  | 
|---|
| [c0bf94e] | 277 | CastExpr::CastExpr( Expression *arg, bool isGenerated ) : Expression(), arg(arg), isGenerated( isGenerated ) { | 
|---|
| [906e24d] | 278 | set_result( new VoidType( Type::Qualifiers() ) ); | 
|---|
| [51b73452] | 279 | } | 
|---|
|  | 280 |  | 
|---|
| [c0bf94e] | 281 | CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) { | 
|---|
| [51b73452] | 282 | } | 
|---|
|  | 283 |  | 
|---|
|  | 284 | CastExpr::~CastExpr() { | 
|---|
| [0dd3a2f] | 285 | delete arg; | 
|---|
| [51b73452] | 286 | } | 
|---|
|  | 287 |  | 
|---|
| [50377a4] | 288 | void CastExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 289 | os << "Cast of:" << std::endl << indent+1; | 
|---|
|  | 290 | arg->print(os, indent+1); | 
|---|
|  | 291 | os << std::endl << indent << "... to:"; | 
|---|
| [906e24d] | 292 | if ( result->isVoid() ) { | 
|---|
| [50377a4] | 293 | os << " nothing"; | 
|---|
| [0dd3a2f] | 294 | } else { | 
|---|
| [50377a4] | 295 | os << std::endl << indent+1; | 
|---|
|  | 296 | result->print( os, indent+1 ); | 
|---|
| [0dd3a2f] | 297 | } // if | 
|---|
|  | 298 | Expression::print( os, indent ); | 
|---|
|  | 299 | } | 
|---|
|  | 300 |  | 
|---|
| [9a705dc8] | 301 | KeywordCastExpr::KeywordCastExpr( Expression *arg, Target target ) : Expression(), arg(arg), target( target ) { | 
|---|
|  | 302 | } | 
|---|
|  | 303 |  | 
|---|
|  | 304 | KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) { | 
|---|
|  | 305 | } | 
|---|
|  | 306 |  | 
|---|
|  | 307 | KeywordCastExpr::~KeywordCastExpr() { | 
|---|
|  | 308 | delete arg; | 
|---|
|  | 309 | } | 
|---|
|  | 310 |  | 
|---|
|  | 311 | const std::string & KeywordCastExpr::targetString() const { | 
|---|
|  | 312 | static const std::string targetStrs[] = { | 
|---|
|  | 313 | "coroutine", "thread", "monitor" | 
|---|
|  | 314 | }; | 
|---|
|  | 315 | static_assert( | 
|---|
|  | 316 | (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS), | 
|---|
|  | 317 | "Each KeywordCastExpr::Target should have a corresponding string representation" | 
|---|
|  | 318 | ); | 
|---|
|  | 319 | return targetStrs[(unsigned long)target]; | 
|---|
|  | 320 | } | 
|---|
|  | 321 |  | 
|---|
|  | 322 | void KeywordCastExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 323 | os << "Keyword Cast of:" << std::endl << indent+1; | 
|---|
|  | 324 | arg->print(os, indent+1); | 
|---|
|  | 325 | os << std::endl << indent << "... to: "; | 
|---|
|  | 326 | os << targetString(); | 
|---|
|  | 327 | Expression::print( os, indent ); | 
|---|
|  | 328 | } | 
|---|
|  | 329 |  | 
|---|
| [a5f0529] | 330 | VirtualCastExpr::VirtualCastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) { | 
|---|
|  | 331 | set_result(toType); | 
|---|
|  | 332 | } | 
|---|
|  | 333 |  | 
|---|
|  | 334 | VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { | 
|---|
|  | 335 | } | 
|---|
|  | 336 |  | 
|---|
|  | 337 | VirtualCastExpr::~VirtualCastExpr() { | 
|---|
|  | 338 | delete arg; | 
|---|
|  | 339 | } | 
|---|
|  | 340 |  | 
|---|
| [50377a4] | 341 | void VirtualCastExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 342 | os << "Virtual Cast of:" << std::endl << indent+1; | 
|---|
|  | 343 | arg->print(os, indent+1); | 
|---|
|  | 344 | os << std::endl << indent << "... to:"; | 
|---|
| [a5f0529] | 345 | if ( ! result ) { | 
|---|
| [50377a4] | 346 | os << " unknown"; | 
|---|
| [a5f0529] | 347 | } else { | 
|---|
| [50377a4] | 348 | os << std::endl << indent+1; | 
|---|
|  | 349 | result->print( os, indent+1 ); | 
|---|
| [a5f0529] | 350 | } // if | 
|---|
|  | 351 | Expression::print( os, indent ); | 
|---|
|  | 352 | } | 
|---|
|  | 353 |  | 
|---|
| [bf4b4cf] | 354 | UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression *aggregate ) : | 
|---|
|  | 355 | Expression(), member(member), aggregate(aggregate) { | 
|---|
| [50377a4] | 356 | assert( aggregate ); | 
|---|
|  | 357 | } | 
|---|
| [51b73452] | 358 |  | 
|---|
| [0dd3a2f] | 359 | UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : | 
|---|
| [3b58d91] | 360 | Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { | 
|---|
| [51b73452] | 361 | } | 
|---|
|  | 362 |  | 
|---|
|  | 363 | UntypedMemberExpr::~UntypedMemberExpr() { | 
|---|
| [0dd3a2f] | 364 | delete aggregate; | 
|---|
| [3b58d91] | 365 | delete member; | 
|---|
| [51b73452] | 366 | } | 
|---|
|  | 367 |  | 
|---|
| [50377a4] | 368 | void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 369 | os << "Untyped Member Expression, with field: " << std::endl << indent+1; | 
|---|
|  | 370 | member->print(os, indent+1 ); | 
|---|
|  | 371 | os << indent << "... from aggregate: " << std::endl << indent+1; | 
|---|
|  | 372 | aggregate->print(os, indent+1); | 
|---|
| [0dd3a2f] | 373 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 374 | } | 
|---|
|  | 375 |  | 
|---|
| [bf4b4cf] | 376 | MemberExpr::MemberExpr( DeclarationWithType *member, Expression *aggregate ) : | 
|---|
|  | 377 | Expression(), member(member), aggregate(aggregate) { | 
|---|
| [50377a4] | 378 | assert( member ); | 
|---|
|  | 379 | assert( aggregate ); | 
|---|
| [9bfc9da] | 380 | assert( aggregate->result ); | 
|---|
| [d9fa60a] | 381 |  | 
|---|
| [9bfc9da] | 382 | TypeSubstitution sub = aggregate->result->genericSubstitution(); | 
|---|
| [d9fa60a] | 383 | Type * res = member->get_type()->clone(); | 
|---|
|  | 384 | sub.apply( res ); | 
|---|
| [487845d7] | 385 | result = res; | 
|---|
|  | 386 | result->set_lvalue( true ); | 
|---|
|  | 387 | result->get_qualifiers() |= aggregate->result->get_qualifiers(); | 
|---|
| [51b73452] | 388 | } | 
|---|
|  | 389 |  | 
|---|
| [0dd3a2f] | 390 | MemberExpr::MemberExpr( const MemberExpr &other ) : | 
|---|
| [39f84a4] | 391 | Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { | 
|---|
| [51b73452] | 392 | } | 
|---|
|  | 393 |  | 
|---|
|  | 394 | MemberExpr::~MemberExpr() { | 
|---|
| [4551a6e] | 395 | // don't delete the member declaration, since it points somewhere else in the tree | 
|---|
| [0dd3a2f] | 396 | delete aggregate; | 
|---|
| [51b73452] | 397 | } | 
|---|
|  | 398 |  | 
|---|
| [50377a4] | 399 | void MemberExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
| [89231bc] | 400 | os << "Member Expression, with field: " << std::endl; | 
|---|
| [50377a4] | 401 | os << indent+1; | 
|---|
|  | 402 | member->print( os, indent+1 ); | 
|---|
|  | 403 | os << std::endl << indent << "... from aggregate: " << std::endl << indent+1; | 
|---|
|  | 404 | aggregate->print(os, indent + 1); | 
|---|
| [0dd3a2f] | 405 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 406 | } | 
|---|
|  | 407 |  | 
|---|
| [bf4b4cf] | 408 | UntypedExpr::UntypedExpr( Expression *function, const std::list<Expression *> &args ) : | 
|---|
|  | 409 | Expression(), function(function), args(args) {} | 
|---|
| [51b73452] | 410 |  | 
|---|
| [0dd3a2f] | 411 | UntypedExpr::UntypedExpr( const UntypedExpr &other ) : | 
|---|
|  | 412 | Expression( other ), function( maybeClone( other.function ) ) { | 
|---|
|  | 413 | cloneAll( other.args, args ); | 
|---|
| [51b73452] | 414 | } | 
|---|
|  | 415 |  | 
|---|
| [ac71a86] | 416 | UntypedExpr::~UntypedExpr() { | 
|---|
|  | 417 | delete function; | 
|---|
| [03b812d2] | 418 | deleteAll( args ); | 
|---|
| [ac71a86] | 419 | } | 
|---|
| [51b73452] | 420 |  | 
|---|
| [b3b2077] | 421 | UntypedExpr * UntypedExpr::createDeref( Expression * expr ) { | 
|---|
|  | 422 | UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } ); | 
|---|
|  | 423 | if ( Type * type = expr->get_result() ) { | 
|---|
|  | 424 | Type * base = InitTweak::getPointerBase( type ); | 
|---|
| [0698aa1] | 425 | assertf( base, "expected pointer type in dereference (type was %s)", toString( type ).c_str() ); | 
|---|
| [b0440b7] | 426 | ret->set_result( base->clone() ); | 
|---|
|  | 427 | if ( GenPoly::referencesPermissable() ) { | 
|---|
|  | 428 | // if references are still allowed in the AST, dereference returns a reference | 
|---|
|  | 429 | ret->set_result( new ReferenceType( Type::Qualifiers(), ret->get_result() ) ); | 
|---|
|  | 430 | } else { | 
|---|
|  | 431 | // references have been removed, in which case dereference returns an lvalue of the base type. | 
|---|
| [0690350] | 432 | ret->result->set_lvalue( true ); | 
|---|
| [b0440b7] | 433 | } | 
|---|
| [b3b2077] | 434 | } | 
|---|
|  | 435 | return ret; | 
|---|
|  | 436 | } | 
|---|
|  | 437 |  | 
|---|
|  | 438 | UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) { | 
|---|
|  | 439 | assert( arg1 && arg2 ); | 
|---|
|  | 440 | UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } ); | 
|---|
|  | 441 | if ( arg1->get_result() && arg2->get_result() ) { | 
|---|
|  | 442 | // if both expressions are typed, assumes that this assignment is a C bitwise assignment, | 
|---|
|  | 443 | // so the result is the type of the RHS | 
|---|
|  | 444 | ret->set_result( arg2->get_result()->clone() ); | 
|---|
|  | 445 | } | 
|---|
|  | 446 | return ret; | 
|---|
|  | 447 | } | 
|---|
|  | 448 |  | 
|---|
|  | 449 |  | 
|---|
| [50377a4] | 450 | void UntypedExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
| [89231bc] | 451 | os << "Applying untyped: " << std::endl; | 
|---|
| [50377a4] | 452 | os << indent+1; | 
|---|
|  | 453 | function->print(os, indent+1); | 
|---|
|  | 454 | os << std::endl << indent << "...to: " << std::endl; | 
|---|
|  | 455 | printAll(args, os, indent+1); | 
|---|
| [0dd3a2f] | 456 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 457 | } | 
|---|
|  | 458 |  | 
|---|
| [bf4b4cf] | 459 | NameExpr::NameExpr( std::string name ) : Expression(), name(name) { | 
|---|
| [50377a4] | 460 | assertf(name != "0", "Zero is not a valid name"); | 
|---|
|  | 461 | assertf(name != "1", "One is not a valid name"); | 
|---|
| [4cb935e] | 462 | } | 
|---|
| [51b73452] | 463 |  | 
|---|
| [0dd3a2f] | 464 | NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) { | 
|---|
| [51b73452] | 465 | } | 
|---|
|  | 466 |  | 
|---|
|  | 467 | NameExpr::~NameExpr() {} | 
|---|
|  | 468 |  | 
|---|
| [50377a4] | 469 | void NameExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 470 | os << "Name: " << get_name(); | 
|---|
| [0dd3a2f] | 471 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 472 | } | 
|---|
|  | 473 |  | 
|---|
| [bf4b4cf] | 474 | LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp ) : | 
|---|
|  | 475 | Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) { | 
|---|
| [906e24d] | 476 | set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); | 
|---|
| [51b73452] | 477 | } | 
|---|
|  | 478 |  | 
|---|
| [0dd3a2f] | 479 | LogicalExpr::LogicalExpr( const LogicalExpr &other ) : | 
|---|
|  | 480 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { | 
|---|
| [51b73452] | 481 | } | 
|---|
|  | 482 |  | 
|---|
| [a08ba92] | 483 | LogicalExpr::~LogicalExpr() { | 
|---|
| [0dd3a2f] | 484 | delete arg1; | 
|---|
|  | 485 | delete arg2; | 
|---|
| [51b73452] | 486 | } | 
|---|
|  | 487 |  | 
|---|
| [50377a4] | 488 | void LogicalExpr::print( std::ostream &os, Indenter indent )const { | 
|---|
|  | 489 | os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: "; | 
|---|
| [0dd3a2f] | 490 | arg1->print(os); | 
|---|
|  | 491 | os << " and "; | 
|---|
|  | 492 | arg2->print(os); | 
|---|
|  | 493 | Expression::print( os, indent ); | 
|---|
| [51b73452] | 494 | } | 
|---|
|  | 495 |  | 
|---|
| [bf4b4cf] | 496 | ConditionalExpr::ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ) : | 
|---|
|  | 497 | Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {} | 
|---|
| [51b73452] | 498 |  | 
|---|
| [0dd3a2f] | 499 | ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : | 
|---|
|  | 500 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { | 
|---|
|  | 501 | } | 
|---|
| [51b73452] | 502 |  | 
|---|
|  | 503 | ConditionalExpr::~ConditionalExpr() { | 
|---|
| [0dd3a2f] | 504 | delete arg1; | 
|---|
|  | 505 | delete arg2; | 
|---|
|  | 506 | delete arg3; | 
|---|
| [51b73452] | 507 | } | 
|---|
|  | 508 |  | 
|---|
| [50377a4] | 509 | void ConditionalExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 510 | os << "Conditional expression on: " << std::endl << indent+1; | 
|---|
|  | 511 | arg1->print( os, indent+1 ); | 
|---|
|  | 512 | os << indent << "First alternative:" << std::endl << indent+1; | 
|---|
|  | 513 | arg2->print( os, indent+1 ); | 
|---|
|  | 514 | os << indent << "Second alternative:" << std::endl << indent+1; | 
|---|
|  | 515 | arg3->print( os, indent+1 ); | 
|---|
| [0dd3a2f] | 516 | Expression::print( os, indent ); | 
|---|
|  | 517 | } | 
|---|
|  | 518 |  | 
|---|
| [e6cee92] | 519 | AsmExpr::AsmExpr( const AsmExpr & other ) : Expression( other ), inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {} | 
|---|
| [3be261a] | 520 |  | 
|---|
|  | 521 |  | 
|---|
| [50377a4] | 522 | void AsmExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
| [7f5566b] | 523 | os << "Asm Expression: " << std::endl; | 
|---|
| [50377a4] | 524 | if ( inout ) inout->print( os, indent+1 ); | 
|---|
|  | 525 | if ( constraint ) constraint->print( os, indent+1 ); | 
|---|
|  | 526 | if ( operand ) operand->print( os, indent+1 ); | 
|---|
| [7f5566b] | 527 | } | 
|---|
|  | 528 |  | 
|---|
| [db4ecc5] | 529 |  | 
|---|
|  | 530 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) { | 
|---|
|  | 531 | assert( callExpr ); | 
|---|
| [50377a4] | 532 | assert( callExpr->result ); | 
|---|
| [906e24d] | 533 | set_result( callExpr->get_result()->clone() ); | 
|---|
| [db4ecc5] | 534 | } | 
|---|
|  | 535 |  | 
|---|
|  | 536 | ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) { | 
|---|
|  | 537 | cloneAll( other.tempDecls, tempDecls ); | 
|---|
|  | 538 | cloneAll( other.returnDecls, returnDecls ); | 
|---|
|  | 539 | cloneAll( other.dtors, dtors ); | 
|---|
|  | 540 | } | 
|---|
|  | 541 |  | 
|---|
|  | 542 | ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() { | 
|---|
| [d5556a3] | 543 | set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment | 
|---|
| [db4ecc5] | 544 | delete callExpr; | 
|---|
|  | 545 | deleteAll( tempDecls ); | 
|---|
|  | 546 | deleteAll( returnDecls ); | 
|---|
|  | 547 | deleteAll( dtors ); | 
|---|
|  | 548 | } | 
|---|
|  | 549 |  | 
|---|
| [50377a4] | 550 | void ImplicitCopyCtorExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 551 | os <<  "Implicit Copy Constructor Expression: " << std::endl << indent+1; | 
|---|
|  | 552 | callExpr->print( os, indent+1 ); | 
|---|
|  | 553 | os << std::endl << indent << "... with temporaries:" << std::endl; | 
|---|
|  | 554 | printAll( tempDecls, os, indent+1 ); | 
|---|
|  | 555 | os << std::endl << indent << "... with return temporaries:" << std::endl; | 
|---|
|  | 556 | printAll( returnDecls, os, indent+1 ); | 
|---|
| [db4ecc5] | 557 | Expression::print( os, indent ); | 
|---|
|  | 558 | } | 
|---|
|  | 559 |  | 
|---|
| [3be261a] | 560 |  | 
|---|
| [b6fe7e6] | 561 | ConstructorExpr::ConstructorExpr( Expression * callExpr ) : callExpr( callExpr ) { | 
|---|
|  | 562 | // allow resolver to type a constructor used as an expression as if it has the same type as its first argument | 
|---|
|  | 563 | assert( callExpr ); | 
|---|
|  | 564 | Expression * arg = InitTweak::getCallArg( callExpr, 0 ); | 
|---|
|  | 565 | assert( arg ); | 
|---|
| [50377a4] | 566 | set_result( maybeClone( arg->result ) ); | 
|---|
| [b6fe7e6] | 567 | } | 
|---|
| [3be261a] | 568 |  | 
|---|
| [b6fe7e6] | 569 | ConstructorExpr::ConstructorExpr( const ConstructorExpr & other ) : Expression( other ), callExpr( maybeClone( other.callExpr ) ) { | 
|---|
|  | 570 | } | 
|---|
|  | 571 |  | 
|---|
|  | 572 | ConstructorExpr::~ConstructorExpr() { | 
|---|
|  | 573 | delete callExpr; | 
|---|
|  | 574 | } | 
|---|
|  | 575 |  | 
|---|
| [50377a4] | 576 | void ConstructorExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 577 | os <<  "Constructor Expression: " << std::endl << indent+1; | 
|---|
| [b6fe7e6] | 578 | callExpr->print( os, indent + 2 ); | 
|---|
|  | 579 | Expression::print( os, indent ); | 
|---|
| [0dd3a2f] | 580 | } | 
|---|
|  | 581 |  | 
|---|
| [3be261a] | 582 |  | 
|---|
| [fbcde64] | 583 | CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : initializer( initializer ) { | 
|---|
| [3c13c03] | 584 | assert( type && initializer ); | 
|---|
| [5ccb10d] | 585 | type->set_lvalue( true ); | 
|---|
| [fbcde64] | 586 | set_result( type ); | 
|---|
| [630a82a] | 587 | } | 
|---|
|  | 588 |  | 
|---|
| [fbcde64] | 589 | CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {} | 
|---|
| [630a82a] | 590 |  | 
|---|
|  | 591 | CompoundLiteralExpr::~CompoundLiteralExpr() { | 
|---|
|  | 592 | delete initializer; | 
|---|
|  | 593 | } | 
|---|
|  | 594 |  | 
|---|
| [50377a4] | 595 | void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 596 | os << "Compound Literal Expression: " << std::endl << indent+1; | 
|---|
|  | 597 | result->print( os, indent+1 ); | 
|---|
|  | 598 | os << indent+1; | 
|---|
|  | 599 | initializer->print( os, indent+1 ); | 
|---|
| [d5556a3] | 600 | Expression::print( os, indent ); | 
|---|
| [630a82a] | 601 | } | 
|---|
|  | 602 |  | 
|---|
| [d9e2280] | 603 | RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} | 
|---|
| [3c13c03] | 604 | RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} | 
|---|
| [50377a4] | 605 | void RangeExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
| [3c13c03] | 606 | os << "Range Expression: "; | 
|---|
| [8688ce1] | 607 | low->print( os, indent ); | 
|---|
|  | 608 | os << " ... "; | 
|---|
|  | 609 | high->print( os, indent ); | 
|---|
| [d5556a3] | 610 | Expression::print( os, indent ); | 
|---|
| [8688ce1] | 611 | } | 
|---|
| [3be261a] | 612 |  | 
|---|
| [6eb8948] | 613 | StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) { | 
|---|
| [5e2c348] | 614 | computeResult(); | 
|---|
|  | 615 | } | 
|---|
|  | 616 | StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) { | 
|---|
|  | 617 | cloneAll( other.returnDecls, returnDecls ); | 
|---|
|  | 618 | cloneAll( other.dtors, dtors ); | 
|---|
|  | 619 | } | 
|---|
|  | 620 | StmtExpr::~StmtExpr() { | 
|---|
|  | 621 | delete statements; | 
|---|
|  | 622 | deleteAll( dtors ); | 
|---|
|  | 623 | deleteAll( returnDecls ); | 
|---|
|  | 624 | } | 
|---|
|  | 625 | void StmtExpr::computeResult() { | 
|---|
| [6eb8948] | 626 | assert( statements ); | 
|---|
| [5e2c348] | 627 | std::list< Statement * > & body = statements->kids; | 
|---|
|  | 628 | delete result; | 
|---|
|  | 629 | result = nullptr; | 
|---|
| [0992849] | 630 | if ( ! returnDecls.empty() ) { | 
|---|
|  | 631 | // prioritize return decl for result type, since if a return decl exists, then | 
|---|
|  | 632 | // the StmtExpr is currently in an intermediate state where the body will always | 
|---|
|  | 633 | // give a void result type. | 
|---|
|  | 634 | result = returnDecls.front()->get_type()->clone(); | 
|---|
|  | 635 | } else if ( ! body.empty() ) { | 
|---|
| [6eb8948] | 636 | if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) { | 
|---|
| [9fe33947] | 637 | result = maybeClone( exprStmt->expr->result ); | 
|---|
| [6eb8948] | 638 | } | 
|---|
|  | 639 | } | 
|---|
| [07516b56] | 640 | // ensure that StmtExpr has a result type | 
|---|
|  | 641 | if ( ! result ) { | 
|---|
| [9fe33947] | 642 | result = new VoidType( Type::Qualifiers() ); | 
|---|
| [07516b56] | 643 | } | 
|---|
| [6eb8948] | 644 | } | 
|---|
| [50377a4] | 645 | void StmtExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 646 | os << "Statement Expression: " << std::endl << indent+1; | 
|---|
|  | 647 | statements->print( os, indent+1 ); | 
|---|
| [d5556a3] | 648 | if ( ! returnDecls.empty() ) { | 
|---|
| [50377a4] | 649 | os << indent+1 << "... with returnDecls: "; | 
|---|
|  | 650 | printAll( returnDecls, os, indent+1 ); | 
|---|
| [d5556a3] | 651 | } | 
|---|
|  | 652 | if ( ! dtors.empty() ) { | 
|---|
| [50377a4] | 653 | os << indent+1 << "... with dtors: "; | 
|---|
|  | 654 | printAll( dtors, os, indent+1 ); | 
|---|
| [d5556a3] | 655 | } | 
|---|
|  | 656 | Expression::print( os, indent ); | 
|---|
| [6eb8948] | 657 | } | 
|---|
|  | 658 |  | 
|---|
| [3c13c03] | 659 |  | 
|---|
| [bf32bb8] | 660 | long long UniqueExpr::count = 0; | 
|---|
| [141b786] | 661 | UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) { | 
|---|
|  | 662 | assert( expr ); | 
|---|
| [bf32bb8] | 663 | assert( count != -1 ); | 
|---|
|  | 664 | if ( id == -1 ) id = count++; | 
|---|
|  | 665 | if ( expr->get_result() ) { | 
|---|
|  | 666 | set_result( expr->get_result()->clone() ); | 
|---|
|  | 667 | } | 
|---|
| [3c13c03] | 668 | } | 
|---|
| [141b786] | 669 | UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) { | 
|---|
| [3c13c03] | 670 | } | 
|---|
|  | 671 | UniqueExpr::~UniqueExpr() { | 
|---|
| [141b786] | 672 | delete expr; | 
|---|
|  | 673 | delete object; | 
|---|
|  | 674 | delete var; | 
|---|
| [3c13c03] | 675 | } | 
|---|
| [50377a4] | 676 | void UniqueExpr::print( std::ostream &os, Indenter indent ) const { | 
|---|
|  | 677 | os << "Unique Expression with id:" << id << std::endl << indent+1; | 
|---|
|  | 678 | expr->print( os, indent+1 ); | 
|---|
|  | 679 | if ( object ) { | 
|---|
|  | 680 | os << indent << "... with decl: "; | 
|---|
|  | 681 | get_object()->printShort( os, indent+1 ); | 
|---|
| [77971f6] | 682 | } | 
|---|
| [d5556a3] | 683 | Expression::print( os, indent ); | 
|---|
| [3c13c03] | 684 | } | 
|---|
|  | 685 |  | 
|---|
| [e4d829b] | 686 | InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {} | 
|---|
|  | 687 | InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {} | 
|---|
|  | 688 | InitAlternative::~InitAlternative() { | 
|---|
|  | 689 | delete type; | 
|---|
|  | 690 | delete designation; | 
|---|
|  | 691 | } | 
|---|
|  | 692 |  | 
|---|
|  | 693 | UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {} | 
|---|
|  | 694 | UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {} | 
|---|
|  | 695 | UntypedInitExpr::~UntypedInitExpr() { | 
|---|
|  | 696 | delete expr; | 
|---|
|  | 697 | } | 
|---|
|  | 698 |  | 
|---|
| [50377a4] | 699 | void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const { | 
|---|
|  | 700 | os << "Untyped Init Expression" << std::endl << indent+1; | 
|---|
|  | 701 | expr->print( os, indent+1 ); | 
|---|
| [e4d829b] | 702 | if ( ! initAlts.empty() ) { | 
|---|
|  | 703 | for ( const InitAlternative & alt : initAlts ) { | 
|---|
| [50377a4] | 704 | os << indent+1 <<  "InitAlternative: "; | 
|---|
|  | 705 | alt.type->print( os, indent+1 ); | 
|---|
|  | 706 | alt.designation->print( os, indent+1 ); | 
|---|
| [e4d829b] | 707 | } | 
|---|
|  | 708 | } | 
|---|
|  | 709 | } | 
|---|
|  | 710 |  | 
|---|
| [62423350] | 711 | InitExpr::InitExpr( Expression * expr, Designation * designation ) : expr( expr ), designation( designation ) { | 
|---|
|  | 712 | set_result( expr->get_result()->clone() ); | 
|---|
| [e4d829b] | 713 | } | 
|---|
|  | 714 | InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {} | 
|---|
|  | 715 | InitExpr::~InitExpr() { | 
|---|
|  | 716 | delete expr; | 
|---|
|  | 717 | delete designation; | 
|---|
|  | 718 | } | 
|---|
|  | 719 |  | 
|---|
| [50377a4] | 720 | void InitExpr::print( std::ostream & os, Indenter indent ) const { | 
|---|
|  | 721 | os << "Init Expression" << std::endl << indent+1; | 
|---|
|  | 722 | expr->print( os, indent+1 ); | 
|---|
|  | 723 | os << indent+1 << "... with designation: "; | 
|---|
|  | 724 | designation->print( os, indent+1 ); | 
|---|
| [e4d829b] | 725 | } | 
|---|
|  | 726 |  | 
|---|
| [44b4114] | 727 | DeletedExpr::DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt ) : expr( expr ), deleteStmt( deleteStmt ) { | 
|---|
|  | 728 | assert( expr->result ); | 
|---|
|  | 729 | result = expr->result->clone(); | 
|---|
|  | 730 | } | 
|---|
|  | 731 | DeletedExpr::DeletedExpr( const DeletedExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), deleteStmt( other.deleteStmt ) {} | 
|---|
|  | 732 | DeletedExpr::~DeletedExpr() { | 
|---|
|  | 733 | delete expr; | 
|---|
|  | 734 | } | 
|---|
|  | 735 |  | 
|---|
|  | 736 | void DeletedExpr::print( std::ostream & os, Indenter indent ) const { | 
|---|
|  | 737 | os << "Deleted Expression" << std::endl << indent+1; | 
|---|
|  | 738 | expr->print( os, indent+1 ); | 
|---|
|  | 739 | os << std::endl << indent+1 << "... deleted by: "; | 
|---|
|  | 740 | deleteStmt->print( os, indent+1 ); | 
|---|
|  | 741 | } | 
|---|
|  | 742 |  | 
|---|
|  | 743 |  | 
|---|
| [0dd3a2f] | 744 | // Local Variables: // | 
|---|
|  | 745 | // tab-width: 4 // | 
|---|
|  | 746 | // mode: c++ // | 
|---|
|  | 747 | // compile-command: "make install" // | 
|---|
|  | 748 | // End: // | 
|---|