Changes in src/SynTree/Expression.cc [b6fe7e6:bf32bb8]
- File:
-
- 1 edited
-
src/SynTree/Expression.cc (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
rb6fe7e6 rbf32bb8 31 31 32 32 33 Expression::Expression( Expression *_aname ) : env( 0 ), argName( _aname ) {} 34 35 Expression::Expression( const Expression &other ) : env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) { 36 cloneAll( other.results, results ); 33 Expression::Expression( Expression *_aname ) : result( 0 ), env( 0 ), argName( _aname ) {} 34 35 Expression::Expression( const Expression &other ) : result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), argName( maybeClone( other.get_argName() ) ), extension( other.extension ) { 37 36 } 38 37 … … 40 39 delete env; 41 40 delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix 42 deleteAll( results ); 43 } 44 45 void Expression::add_result( Type *t ) { 46 if ( TupleType *tuple = dynamic_cast< TupleType* >( t ) ) { 47 std::copy( tuple->get_types().begin(), tuple->get_types().end(), back_inserter( results ) ); 48 } else { 49 results.push_back(t); 50 } // if 41 delete result; 51 42 } 52 43 … … 68 59 69 60 ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) { 70 add_result( constant.get_type()->clone() );61 set_result( constant.get_type()->clone() ); 71 62 } 72 63 … … 85 76 assert( var ); 86 77 assert( var->get_type() ); 87 add_result( var->get_type()->clone() ); 88 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 89 (*i)->set_isLvalue( true ); 90 } // for 78 Type * type = var->get_type()->clone(); 79 type->set_isLvalue( true ); 80 set_result( type ); 91 81 } 92 82 … … 110 100 SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) : 111 101 Expression( _aname ), expr(expr_), type(0), isType(false) { 112 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );102 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 113 103 } 114 104 115 105 SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) : 116 106 Expression( _aname ), expr(0), type(type_), isType(true) { 117 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );107 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 118 108 } 119 109 … … 141 131 AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) : 142 132 Expression( _aname ), expr(expr_), type(0), isType(false) { 143 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );133 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 144 134 } 145 135 146 136 AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) : 147 137 Expression( _aname ), expr(0), type(type_), isType(true) { 148 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );138 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 149 139 } 150 140 … … 172 162 UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) : 173 163 Expression( _aname ), type(type_), member(member_) { 174 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );164 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 175 165 } 176 166 … … 197 187 OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) : 198 188 Expression( _aname ), type(type_), member(member_) { 199 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );189 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 200 190 } 201 191 … … 229 219 230 220 OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) { 231 add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );221 set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); 232 222 } 233 223 … … 284 274 285 275 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { 286 add_result(toType);276 set_result(toType); 287 277 } 288 278 289 279 CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) { 280 set_result( new VoidType( Type::Qualifiers() ) ); 290 281 } 291 282 … … 303 294 arg->print(os, indent+2); 304 295 os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl; 305 if ( results.empty() ) { 306 os << std::string( indent+2, ' ' ) << "nothing" << std::endl; 296 os << std::string( indent+2, ' ' ); 297 if ( result->isVoid() ) { 298 os << "nothing"; 307 299 } else { 308 printAll(results, os, indent+2);300 result->print( os, indent+2 ); 309 301 } // if 310 Expression::print( os, indent ); 311 } 312 313 UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) : 302 os << std::endl; 303 Expression::print( os, indent ); 304 } 305 306 UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) : 314 307 Expression( _aname ), member(_member), aggregate(_aggregate) {} 315 308 316 309 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : 317 Expression( other ), member( other.member), aggregate( maybeClone( other.aggregate ) ) {310 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { 318 311 } 319 312 320 313 UntypedMemberExpr::~UntypedMemberExpr() { 321 314 delete aggregate; 315 delete member; 322 316 } 323 317 324 318 void UntypedMemberExpr::print( std::ostream &os, int indent ) const { 325 os << "Untyped Member Expression, with field: " << get_member(); 319 os << "Untyped Member Expression, with field: " << std::endl; 320 os << std::string( indent+2, ' ' ); 321 get_member()->print(os, indent+4); 322 os << std::string( indent+2, ' ' ); 326 323 327 324 Expression *agg = get_aggregate(); 328 os << " , from aggregate: ";325 os << "from aggregate: " << std::endl; 329 326 if (agg != 0) { 330 os << std::string( indent + 2, ' ' );331 agg->print(os, indent + 2);327 os << std::string( indent + 4, ' ' ); 328 agg->print(os, indent + 4); 332 329 } 333 330 os << std::string( indent+2, ' ' ); … … 338 335 MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : 339 336 Expression( _aname ), member(_member), aggregate(_aggregate) { 340 add_result( member->get_type()->clone() ); 341 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 342 (*i)->set_isLvalue( true ); 343 } // for 337 set_result( member->get_type()->clone() ); 338 get_result()->set_isLvalue( true ); 344 339 } 345 340 … … 372 367 } 373 368 374 375 UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function) {}369 UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) : 370 Expression( _aname ), function(_function), args(_args) {} 376 371 377 372 UntypedExpr::UntypedExpr( const UntypedExpr &other ) : … … 379 374 cloneAll( other.args, args ); 380 375 } 381 382 UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :383 Expression( _aname ), function(_function), args(_args) {}384 376 385 377 UntypedExpr::~UntypedExpr() { … … 419 411 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : 420 412 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { 421 add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );413 set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 422 414 } 423 415 … … 477 469 ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) { 478 470 assert( callExpr ); 479 cloneAll( callExpr->get_results(), results ); 471 assert( callExpr->has_result() ); 472 set_result( callExpr->get_result()->clone() ); 480 473 } 481 474 … … 510 503 Expression * arg = InitTweak::getCallArg( callExpr, 0 ); 511 504 assert( arg ); 512 cloneAll( arg->get_results(), results);505 set_result( maybeClone( arg->get_result() ) ); 513 506 } 514 507 … … 530 523 531 524 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) { 532 add_result( type->clone() ); 533 } 534 535 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {} 525 assert( type && initializer ); 526 set_result( type->clone() ); 527 } 528 529 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( other.type->clone() ), initializer( other.initializer->clone() ) {} 536 530 537 531 CompoundLiteralExpr::~CompoundLiteralExpr() { … … 542 536 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const { 543 537 os << "Compound Literal Expression: " << std::endl; 544 if ( type ) type->print( os, indent + 2 ); 545 if ( initializer ) initializer->print( os, indent + 2 ); 538 os << std::string( indent+2, ' ' ); 539 type->print( os, indent + 2 ); 540 os << std::string( indent+2, ' ' ); 541 initializer->print( os, indent + 2 ); 546 542 } 547 543 … … 557 553 558 554 RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} 559 RangeExpr::RangeExpr( const RangeExpr &other ) : low( other.low->clone() ), high( other.high->clone() ) {}555 RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} 560 556 void RangeExpr::print( std::ostream &os, int indent ) const { 561 os << std::string( indent, ' ' ) <<"Range Expression: ";557 os << "Range Expression: "; 562 558 low->print( os, indent ); 563 559 os << " ... "; 564 560 high->print( os, indent ); 561 } 562 563 StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) { 564 assert( statements ); 565 std::list< Statement * > & body = statements->get_kids(); 566 if ( ! body.empty() ) { 567 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) { 568 set_result( maybeClone( exprStmt->get_expr()->get_result() ) ); 569 } 570 } 571 } 572 StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {} 573 StmtExpr::~StmtExpr() { 574 delete statements; 575 } 576 void StmtExpr::print( std::ostream &os, int indent ) const { 577 os << "Statement Expression: " << std::endl << std::string( indent, ' ' ); 578 statements->print( os, indent+2 ); 579 } 580 581 582 long long UniqueExpr::count = 0; 583 UniqueExpr::UniqueExpr( Expression *expr, long long idVal ) : expr( new Expression* ), id( idVal ) { 584 assert( count != -1 ); 585 if ( id == -1 ) id = count++; 586 set_expr( expr ); 587 assert( expr ); 588 if ( expr->get_result() ) { 589 set_result( expr->get_result()->clone() ); 590 } 591 } 592 UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( other.expr ), id( other.id ) { 593 } 594 UniqueExpr::~UniqueExpr() { 595 if ( expr.unique() ) { 596 delete *expr; 597 } 598 } 599 void UniqueExpr::print( std::ostream &os, int indent ) const { 600 os << "Unique Expression with id:" << id << std::endl << std::string( indent+2, ' ' ); 601 get_expr()->print( os, indent+2 ); 565 602 } 566 603
Note:
See TracChangeset
for help on using the changeset viewer.