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