[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
|
---|
[630a82a] | 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Fri Apr 8 17:16:23 2016
|
---|
| 13 | // Update Count : 40
|
---|
[0dd3a2f] | 14 | //
|
---|
| 15 |
|
---|
[51b73452] | 16 | #include <iostream>
|
---|
| 17 | #include <cassert>
|
---|
| 18 | #include <list>
|
---|
| 19 | #include <algorithm>
|
---|
| 20 |
|
---|
| 21 | #include <iterator>
|
---|
| 22 |
|
---|
| 23 | #include "Type.h"
|
---|
[630a82a] | 24 | #include "Initializer.h"
|
---|
[51b73452] | 25 | #include "Expression.h"
|
---|
| 26 | #include "Declaration.h"
|
---|
| 27 | #include "Statement.h"
|
---|
| 28 | #include "TypeSubstitution.h"
|
---|
[d3b7937] | 29 | #include "Common/utility.h"
|
---|
[51b73452] | 30 |
|
---|
| 31 |
|
---|
| 32 | Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {}
|
---|
[0dd3a2f] | 33 |
|
---|
[d0d9610] | 34 | Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ) {
|
---|
[0dd3a2f] | 35 | cloneAll( other.results, results );
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | Expression::~Expression() {
|
---|
| 39 | delete env;
|
---|
[7f5566b] | 40 | delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix
|
---|
[0dd3a2f] | 41 | deleteAll( results );
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | void Expression::add_result( Type *t ) {
|
---|
| 45 | if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) {
|
---|
| 46 | std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) );
|
---|
| 47 | } else {
|
---|
| 48 | results.push_back(t);
|
---|
| 49 | } // if
|
---|
[51b73452] | 50 | }
|
---|
| 51 |
|
---|
[59db689] | 52 | void Expression::print( std::ostream &os, int indent ) const {
|
---|
[0dd3a2f] | 53 | if ( env ) {
|
---|
[cf0941d] | 54 | os << std::string( indent, ' ' ) << "with environment:" << std::endl;
|
---|
[0dd3a2f] | 55 | env->print( os, indent+2 );
|
---|
| 56 | } // if
|
---|
[51b73452] | 57 |
|
---|
[0dd3a2f] | 58 | if ( argName ) {
|
---|
[cf0941d] | 59 | os << std::string( indent, ' ' ) << "with designator:";
|
---|
[0dd3a2f] | 60 | argName->print( os, indent+2 );
|
---|
| 61 | } // if
|
---|
[51b73452] | 62 | }
|
---|
| 63 |
|
---|
[0dd3a2f] | 64 | ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) {
|
---|
| 65 | add_result( constant.get_type()->clone() );
|
---|
[51b73452] | 66 | }
|
---|
| 67 |
|
---|
[0dd3a2f] | 68 | ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) {
|
---|
| 69 | }
|
---|
[51b73452] | 70 |
|
---|
| 71 | ConstantExpr::~ConstantExpr() {}
|
---|
| 72 |
|
---|
[0dd3a2f] | 73 | void ConstantExpr::print( std::ostream &os, int indent ) const {
|
---|
[d58ebf3] | 74 | os << std::string( indent, ' ' ) << "constant expression " ;
|
---|
[cf0941d] | 75 | constant.print( os );
|
---|
[0dd3a2f] | 76 | Expression::print( os, indent );
|
---|
[d58ebf3] | 77 | os << std::endl;
|
---|
[51b73452] | 78 | }
|
---|
| 79 |
|
---|
[0dd3a2f] | 80 | VariableExpr::VariableExpr( DeclarationWithType *_var, Expression *_aname ) : Expression( _aname ), var( _var ) {
|
---|
| 81 | add_result( var->get_type()->clone() );
|
---|
| 82 | for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
|
---|
| 83 | (*i)->set_isLvalue( true );
|
---|
| 84 | } // for
|
---|
[51b73452] | 85 | }
|
---|
| 86 |
|
---|
[0dd3a2f] | 87 | VariableExpr::VariableExpr( const VariableExpr &other ) : Expression( other ), var( other.var ) {
|
---|
[51b73452] | 88 | }
|
---|
| 89 |
|
---|
[0dd3a2f] | 90 | VariableExpr::~VariableExpr() {
|
---|
| 91 | // don't delete the declaration, since it points somewhere else in the tree
|
---|
[51b73452] | 92 | }
|
---|
| 93 |
|
---|
[0dd3a2f] | 94 | void VariableExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 95 | os << std::string( indent, ' ' ) << "Variable Expression: ";
|
---|
[51b73452] | 96 |
|
---|
[0dd3a2f] | 97 | Declaration *decl = get_var();
|
---|
| 98 | // if ( decl != 0) decl->print(os, indent + 2);
|
---|
| 99 | if ( decl != 0) decl->printShort(os, indent + 2);
|
---|
| 100 | os << std::endl;
|
---|
| 101 | Expression::print( os, indent );
|
---|
[51b73452] | 102 | }
|
---|
| 103 |
|
---|
| 104 | SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) :
|
---|
[0dd3a2f] | 105 | Expression( _aname ), expr(expr_), type(0), isType(false) {
|
---|
[bfebb6c5] | 106 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[51b73452] | 107 | }
|
---|
| 108 |
|
---|
| 109 | SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) :
|
---|
[0dd3a2f] | 110 | Expression( _aname ), expr(0), type(type_), isType(true) {
|
---|
[bfebb6c5] | 111 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[51b73452] | 112 | }
|
---|
| 113 |
|
---|
[0dd3a2f] | 114 | SizeofExpr::SizeofExpr( const SizeofExpr &other ) :
|
---|
| 115 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
|
---|
[51b73452] | 116 | }
|
---|
| 117 |
|
---|
[0dd3a2f] | 118 | SizeofExpr::~SizeofExpr() {
|
---|
| 119 | delete expr;
|
---|
| 120 | delete type;
|
---|
[51b73452] | 121 | }
|
---|
| 122 |
|
---|
| 123 | void SizeofExpr::print( std::ostream &os, int indent) const {
|
---|
[44b5ca0] | 124 | os << std::string( indent, ' ' ) << "Sizeof Expression on: ";
|
---|
[51b73452] | 125 |
|
---|
[47534159] | 126 | if (isType)
|
---|
| 127 | type->print(os, indent + 2);
|
---|
| 128 | else
|
---|
| 129 | expr->print(os, indent + 2);
|
---|
| 130 |
|
---|
| 131 | os << std::endl;
|
---|
| 132 | Expression::print( os, indent );
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
|
---|
| 136 | Expression( _aname ), expr(expr_), type(0), isType(false) {
|
---|
[bfebb6c5] | 137 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[47534159] | 138 | }
|
---|
| 139 |
|
---|
| 140 | AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
|
---|
| 141 | Expression( _aname ), expr(0), type(type_), isType(true) {
|
---|
[bfebb6c5] | 142 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[47534159] | 143 | }
|
---|
| 144 |
|
---|
| 145 | AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
|
---|
| 146 | Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | AlignofExpr::~AlignofExpr() {
|
---|
| 150 | delete expr;
|
---|
| 151 | delete type;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | void AlignofExpr::print( std::ostream &os, int indent) const {
|
---|
| 155 | os << std::string( indent, ' ' ) << "Alignof Expression on: ";
|
---|
| 156 |
|
---|
[0dd3a2f] | 157 | if (isType)
|
---|
| 158 | type->print(os, indent + 2);
|
---|
| 159 | else
|
---|
| 160 | expr->print(os, indent + 2);
|
---|
[51b73452] | 161 |
|
---|
[0dd3a2f] | 162 | os << std::endl;
|
---|
| 163 | Expression::print( os, indent );
|
---|
[51b73452] | 164 | }
|
---|
| 165 |
|
---|
[2a4b088] | 166 | UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) :
|
---|
| 167 | Expression( _aname ), type(type_), member(member_) {
|
---|
| 168 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) :
|
---|
| 172 | Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {}
|
---|
| 173 |
|
---|
| 174 | UntypedOffsetofExpr::~UntypedOffsetofExpr() {
|
---|
| 175 | delete type;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | void UntypedOffsetofExpr::print( std::ostream &os, int indent) const {
|
---|
| 179 | os << std::string( indent, ' ' ) << "Untyped Offsetof Expression on member " << member << " of ";
|
---|
| 180 |
|
---|
| 181 | if ( type ) {
|
---|
| 182 | type->print(os, indent + 2);
|
---|
| 183 | } else {
|
---|
| 184 | os << "<NULL>";
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | os << std::endl;
|
---|
| 188 | Expression::print( os, indent );
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[25a054f] | 191 | OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) :
|
---|
| 192 | Expression( _aname ), type(type_), member(member_) {
|
---|
[bfebb6c5] | 193 | add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );
|
---|
[25a054f] | 194 | }
|
---|
| 195 |
|
---|
| 196 | OffsetofExpr::OffsetofExpr( const OffsetofExpr &other ) :
|
---|
| 197 | Expression( other ), type( maybeClone( other.type ) ), member( maybeClone( other.member ) ) {}
|
---|
| 198 |
|
---|
| 199 | OffsetofExpr::~OffsetofExpr() {
|
---|
| 200 | delete type;
|
---|
| 201 | delete member;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | void OffsetofExpr::print( std::ostream &os, int indent) const {
|
---|
| 205 | os << std::string( indent, ' ' ) << "Offsetof Expression on member ";
|
---|
| 206 |
|
---|
| 207 | if ( member ) {
|
---|
| 208 | os << member->get_name();
|
---|
| 209 | } else {
|
---|
| 210 | os << "<NULL>";
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | os << " of ";
|
---|
| 214 |
|
---|
| 215 | if ( type ) {
|
---|
| 216 | type->print(os, indent + 2);
|
---|
| 217 | } else {
|
---|
| 218 | os << "<NULL>";
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | os << std::endl;
|
---|
| 222 | Expression::print( os, indent );
|
---|
| 223 | }
|
---|
| 224 |
|
---|
[afc1045] | 225 | OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
|
---|
| 226 | add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
|
---|
| 230 |
|
---|
| 231 | OffsetPackExpr::~OffsetPackExpr() { delete type; }
|
---|
| 232 |
|
---|
| 233 | void OffsetPackExpr::print( std::ostream &os, int indent ) const {
|
---|
| 234 | os << std::string( indent, ' ' ) << "Offset pack expression on ";
|
---|
| 235 |
|
---|
| 236 | if ( type ) {
|
---|
| 237 | type->print(os, indent + 2);
|
---|
| 238 | } else {
|
---|
| 239 | os << "<NULL>";
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[25a054f] | 242 | os << std::endl;
|
---|
| 243 | Expression::print( os, indent );
|
---|
| 244 | }
|
---|
| 245 |
|
---|
[51b73452] | 246 | AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
|
---|
[0dd3a2f] | 247 | Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
|
---|
[51b73452] | 248 | }
|
---|
| 249 |
|
---|
| 250 | AttrExpr::AttrExpr( Expression *attr, Type *type_, Expression *_aname ) :
|
---|
[0dd3a2f] | 251 | Expression( _aname ), attr( attr ), expr(0), type(type_), isType(true) {
|
---|
[51b73452] | 252 | }
|
---|
| 253 |
|
---|
[0dd3a2f] | 254 | AttrExpr::AttrExpr( const AttrExpr &other ) :
|
---|
| 255 | Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
|
---|
[51b73452] | 256 | }
|
---|
| 257 |
|
---|
[0dd3a2f] | 258 | AttrExpr::~AttrExpr() {
|
---|
| 259 | delete attr;
|
---|
| 260 | delete expr;
|
---|
| 261 | delete type;
|
---|
[51b73452] | 262 | }
|
---|
| 263 |
|
---|
| 264 | void AttrExpr::print( std::ostream &os, int indent) const {
|
---|
[44b5ca0] | 265 | os << std::string( indent, ' ' ) << "Attr ";
|
---|
[0dd3a2f] | 266 | attr->print( os, indent + 2 );
|
---|
| 267 | if ( isType || expr ) {
|
---|
| 268 | os << "applied to: ";
|
---|
[51b73452] | 269 |
|
---|
[0dd3a2f] | 270 | if (isType)
|
---|
| 271 | type->print(os, indent + 2);
|
---|
| 272 | else
|
---|
| 273 | expr->print(os, indent + 2);
|
---|
| 274 | } // if
|
---|
[51b73452] | 275 |
|
---|
[0dd3a2f] | 276 | os << std::endl;
|
---|
| 277 | Expression::print( os, indent );
|
---|
[51b73452] | 278 | }
|
---|
| 279 |
|
---|
[0dd3a2f] | 280 | CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) {
|
---|
| 281 | add_result(toType);
|
---|
[51b73452] | 282 | }
|
---|
| 283 |
|
---|
| 284 | CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) {
|
---|
| 285 | }
|
---|
| 286 |
|
---|
[0dd3a2f] | 287 | CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) {
|
---|
[51b73452] | 288 | }
|
---|
| 289 |
|
---|
| 290 | CastExpr::~CastExpr() {
|
---|
[0dd3a2f] | 291 | delete arg;
|
---|
[51b73452] | 292 | }
|
---|
| 293 |
|
---|
| 294 | // CastExpr *CastExpr::clone() const { return 0; }
|
---|
| 295 |
|
---|
| 296 | void CastExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 297 | os << std::string( indent, ' ' ) << "Cast of:" << std::endl;
|
---|
[0dd3a2f] | 298 | arg->print(os, indent+2);
|
---|
[44b5ca0] | 299 | os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl;
|
---|
[0dd3a2f] | 300 | if ( results.empty() ) {
|
---|
[44b5ca0] | 301 | os << std::string( indent+2, ' ' ) << "nothing" << std::endl;
|
---|
[0dd3a2f] | 302 | } else {
|
---|
| 303 | printAll(results, os, indent+2);
|
---|
| 304 | } // if
|
---|
| 305 | Expression::print( os, indent );
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[51b73452] | 308 | UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) :
|
---|
[0dd3a2f] | 309 | Expression( _aname ), member(_member), aggregate(_aggregate) {}
|
---|
[51b73452] | 310 |
|
---|
[0dd3a2f] | 311 | UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) :
|
---|
| 312 | Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
|
---|
[51b73452] | 313 | }
|
---|
| 314 |
|
---|
| 315 | UntypedMemberExpr::~UntypedMemberExpr() {
|
---|
[0dd3a2f] | 316 | delete aggregate;
|
---|
[51b73452] | 317 | }
|
---|
| 318 |
|
---|
| 319 | void UntypedMemberExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 320 | os << std::string( indent, ' ' ) << "Member Expression, with field: " << get_member();
|
---|
[51b73452] | 321 |
|
---|
[0dd3a2f] | 322 | Expression *agg = get_aggregate();
|
---|
[44b5ca0] | 323 | os << std::string( indent, ' ' ) << "from aggregate: ";
|
---|
[0dd3a2f] | 324 | if (agg != 0) agg->print(os, indent + 2);
|
---|
| 325 | Expression::print( os, indent );
|
---|
[51b73452] | 326 | }
|
---|
| 327 |
|
---|
| 328 |
|
---|
| 329 | MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) :
|
---|
[0dd3a2f] | 330 | Expression( _aname ), member(_member), aggregate(_aggregate) {
|
---|
| 331 | add_result( member->get_type()->clone() );
|
---|
| 332 | for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) {
|
---|
| 333 | (*i)->set_isLvalue( true );
|
---|
| 334 | } // for
|
---|
[51b73452] | 335 | }
|
---|
| 336 |
|
---|
[0dd3a2f] | 337 | MemberExpr::MemberExpr( const MemberExpr &other ) :
|
---|
| 338 | Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
|
---|
[51b73452] | 339 | }
|
---|
| 340 |
|
---|
| 341 | MemberExpr::~MemberExpr() {
|
---|
[0dd3a2f] | 342 | delete member;
|
---|
| 343 | delete aggregate;
|
---|
[51b73452] | 344 | }
|
---|
| 345 |
|
---|
| 346 | void MemberExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 347 | os << std::string( indent, ' ' ) << "Member Expression, with field: " << std::endl;
|
---|
[51b73452] | 348 |
|
---|
[0dd3a2f] | 349 | assert( member );
|
---|
[44b5ca0] | 350 | os << std::string( indent + 2, ' ' );
|
---|
[0dd3a2f] | 351 | member->print( os, indent + 2 );
|
---|
| 352 | os << std::endl;
|
---|
[51b73452] | 353 |
|
---|
[0dd3a2f] | 354 | Expression *agg = get_aggregate();
|
---|
[44b5ca0] | 355 | os << std::string( indent, ' ' ) << "from aggregate: " << std::endl;
|
---|
[0dd3a2f] | 356 | if (agg != 0) agg->print(os, indent + 2);
|
---|
| 357 | Expression::print( os, indent );
|
---|
[51b73452] | 358 | }
|
---|
| 359 |
|
---|
| 360 |
|
---|
| 361 | UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function ) {}
|
---|
| 362 |
|
---|
[0dd3a2f] | 363 | UntypedExpr::UntypedExpr( const UntypedExpr &other ) :
|
---|
| 364 | Expression( other ), function( maybeClone( other.function ) ) {
|
---|
| 365 | cloneAll( other.args, args );
|
---|
[51b73452] | 366 | }
|
---|
| 367 |
|
---|
| 368 | UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :
|
---|
[0dd3a2f] | 369 | Expression( _aname ), function(_function), args(_args) {}
|
---|
[51b73452] | 370 |
|
---|
| 371 | UntypedExpr::~UntypedExpr() {}
|
---|
| 372 |
|
---|
| 373 | void UntypedExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 374 | os << std::string( indent, ' ' ) << "Applying untyped: " << std::endl;
|
---|
[0dd3a2f] | 375 | function->print(os, indent + 4);
|
---|
[44b5ca0] | 376 | os << std::string( indent, ' ' ) << "...to: " << std::endl;
|
---|
[0dd3a2f] | 377 | printArgs(os, indent + 4);
|
---|
| 378 | Expression::print( os, indent );
|
---|
[51b73452] | 379 | }
|
---|
| 380 |
|
---|
[0dd3a2f] | 381 | void UntypedExpr::printArgs( std::ostream &os, int indent ) const {
|
---|
| 382 | std::list<Expression *>::const_iterator i;
|
---|
| 383 | for (i = args.begin(); i != args.end(); i++)
|
---|
| 384 | (*i)->print(os, indent);
|
---|
[51b73452] | 385 | }
|
---|
| 386 |
|
---|
| 387 | NameExpr::NameExpr( std::string _name, Expression *_aname ) : Expression( _aname ), name(_name) {}
|
---|
| 388 |
|
---|
[0dd3a2f] | 389 | NameExpr::NameExpr( const NameExpr &other ) : Expression( other ), name( other.name ) {
|
---|
[51b73452] | 390 | }
|
---|
| 391 |
|
---|
| 392 | NameExpr::~NameExpr() {}
|
---|
| 393 |
|
---|
| 394 | void NameExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 395 | os << std::string( indent, ' ' ) << "Name: " << get_name() << std::endl;
|
---|
[0dd3a2f] | 396 | Expression::print( os, indent );
|
---|
[51b73452] | 397 | }
|
---|
| 398 |
|
---|
| 399 | LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) :
|
---|
[0dd3a2f] | 400 | Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) {
|
---|
| 401 | add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
|
---|
[51b73452] | 402 | }
|
---|
| 403 |
|
---|
[0dd3a2f] | 404 | LogicalExpr::LogicalExpr( const LogicalExpr &other ) :
|
---|
| 405 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) {
|
---|
[51b73452] | 406 | }
|
---|
| 407 |
|
---|
[a08ba92] | 408 | LogicalExpr::~LogicalExpr() {
|
---|
[0dd3a2f] | 409 | delete arg1;
|
---|
| 410 | delete arg2;
|
---|
[51b73452] | 411 | }
|
---|
| 412 |
|
---|
| 413 | void LogicalExpr::print( std::ostream &os, int indent )const {
|
---|
[44b5ca0] | 414 | os << std::string( indent, ' ' ) << "Short-circuited operation (" << (isAnd?"and":"or") << ") on: ";
|
---|
[0dd3a2f] | 415 | arg1->print(os);
|
---|
| 416 | os << " and ";
|
---|
| 417 | arg2->print(os);
|
---|
| 418 | os << std::endl;
|
---|
| 419 | Expression::print( os, indent );
|
---|
[51b73452] | 420 | }
|
---|
| 421 |
|
---|
| 422 | ConditionalExpr::ConditionalExpr( Expression *arg1_, Expression *arg2_, Expression *arg3_, Expression *_aname ) :
|
---|
[0dd3a2f] | 423 | Expression( _aname ), arg1(arg1_), arg2(arg2_), arg3(arg3_) {}
|
---|
[51b73452] | 424 |
|
---|
[0dd3a2f] | 425 | ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) :
|
---|
| 426 | Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) {
|
---|
| 427 | }
|
---|
[51b73452] | 428 |
|
---|
| 429 | ConditionalExpr::~ConditionalExpr() {
|
---|
[0dd3a2f] | 430 | delete arg1;
|
---|
| 431 | delete arg2;
|
---|
| 432 | delete arg3;
|
---|
[51b73452] | 433 | }
|
---|
| 434 |
|
---|
| 435 | void ConditionalExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 436 | os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl;
|
---|
[0dd3a2f] | 437 | arg1->print( os, indent+2 );
|
---|
[44b5ca0] | 438 | os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
|
---|
[0dd3a2f] | 439 | arg2->print( os, indent+2 );
|
---|
[44b5ca0] | 440 | os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
|
---|
[0dd3a2f] | 441 | arg3->print( os, indent+2 );
|
---|
| 442 | os << std::endl;
|
---|
| 443 | Expression::print( os, indent );
|
---|
| 444 | }
|
---|
| 445 |
|
---|
[3be261a] | 446 | AsmExpr::AsmExpr( const AsmExpr & other ) : inout( maybeClone( other.inout ) ), constraint( maybeClone( other.constraint ) ), operand( maybeClone( other.operand ) ) {}
|
---|
| 447 |
|
---|
| 448 |
|
---|
[7f5566b] | 449 | void AsmExpr::print( std::ostream &os, int indent ) const {
|
---|
| 450 | os << "Asm Expression: " << std::endl;
|
---|
| 451 | if ( inout ) inout->print( os, indent + 2 );
|
---|
| 452 | if ( constraint ) constraint->print( os, indent + 2 );
|
---|
| 453 | if ( operand ) operand->print( os, indent + 2 );
|
---|
| 454 | }
|
---|
| 455 |
|
---|
[3be261a] | 456 | UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}
|
---|
| 457 |
|
---|
| 458 | UntypedValofExpr::~UntypedValofExpr() { delete body; }
|
---|
| 459 |
|
---|
[0dd3a2f] | 460 | void UntypedValofExpr::print( std::ostream &os, int indent ) const {
|
---|
[44b5ca0] | 461 | os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;
|
---|
[0dd3a2f] | 462 | if ( get_body() != 0 )
|
---|
| 463 | get_body()->print( os, indent + 2 );
|
---|
| 464 | }
|
---|
| 465 |
|
---|
[3be261a] | 466 |
|
---|
[630a82a] | 467 | CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
|
---|
| 468 | add_result( type->clone() );
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
|
---|
| 472 |
|
---|
| 473 | CompoundLiteralExpr::~CompoundLiteralExpr() {
|
---|
| 474 | delete initializer;
|
---|
| 475 | delete type;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
|
---|
| 479 | os << "Compound Literal Expression: " << std::endl;
|
---|
| 480 | if ( type ) type->print( os, indent + 2 );
|
---|
| 481 | if ( initializer ) initializer->print( os, indent + 2 );
|
---|
| 482 | }
|
---|
| 483 |
|
---|
[3be261a] | 484 |
|
---|
[baf7fee] | 485 | std::ostream & operator<<( std::ostream & out, Expression * expr ) {
|
---|
| 486 | expr->print( out );
|
---|
| 487 | return out;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
[0dd3a2f] | 490 | // Local Variables: //
|
---|
| 491 | // tab-width: 4 //
|
---|
| 492 | // mode: c++ //
|
---|
| 493 | // compile-command: "make install" //
|
---|
| 494 | // End: //
|
---|