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