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