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