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