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