Changes in src/SynTree/Expression.cc [906e24d:6eb8948]
- File:
-
- 1 edited
-
src/SynTree/Expression.cc (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
r906e24d r6eb8948 31 31 32 32 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 ) { 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 ); 36 37 } 37 38 … … 39 40 delete env; 40 41 delete argName; // xxx -- there's a problem in cloning ConstantExpr I still don't know how to fix 41 delete result; 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 42 51 } 43 52 … … 59 68 60 69 ConstantExpr::ConstantExpr( Constant _c, Expression *_aname ) : Expression( _aname ), constant( _c ) { 61 set_result( constant.get_type()->clone() );70 add_result( constant.get_type()->clone() ); 62 71 } 63 72 … … 76 85 assert( var ); 77 86 assert( var->get_type() ); 78 Type * type = var->get_type()->clone(); 79 type->set_isLvalue( true ); 80 set_result( 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 81 91 } 82 92 … … 100 110 SizeofExpr::SizeofExpr( Expression *expr_, Expression *_aname ) : 101 111 Expression( _aname ), expr(expr_), type(0), isType(false) { 102 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );112 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 103 113 } 104 114 105 115 SizeofExpr::SizeofExpr( Type *type_, Expression *_aname ) : 106 116 Expression( _aname ), expr(0), type(type_), isType(true) { 107 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );117 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 108 118 } 109 119 … … 131 141 AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) : 132 142 Expression( _aname ), expr(expr_), type(0), isType(false) { 133 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );143 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 134 144 } 135 145 136 146 AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) : 137 147 Expression( _aname ), expr(0), type(type_), isType(true) { 138 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );148 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 139 149 } 140 150 … … 162 172 UntypedOffsetofExpr::UntypedOffsetofExpr( Type *type_, const std::string &member_, Expression *_aname ) : 163 173 Expression( _aname ), type(type_), member(member_) { 164 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );174 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 165 175 } 166 176 … … 187 197 OffsetofExpr::OffsetofExpr( Type *type_, DeclarationWithType *member_, Expression *_aname ) : 188 198 Expression( _aname ), type(type_), member(member_) { 189 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) );199 add_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 190 200 } 191 201 … … 219 229 220 230 OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) { 221 set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );231 add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); 222 232 } 223 233 … … 274 284 275 285 CastExpr::CastExpr( Expression *arg_, Type *toType, Expression *_aname ) : Expression( _aname ), arg(arg_) { 276 set_result(toType);286 add_result(toType); 277 287 } 278 288 279 289 CastExpr::CastExpr( Expression *arg_, Expression *_aname ) : Expression( _aname ), arg(arg_) { 280 set_result( new VoidType( Type::Qualifiers() ) );281 290 } 282 291 … … 294 303 arg->print(os, indent+2); 295 304 os << std::endl << std::string( indent, ' ' ) << "to:" << std::endl; 296 os << std::string( indent+2, ' ' ); 297 if ( result->isVoid() ) { 298 os << "nothing"; 305 if ( results.empty() ) { 306 os << std::string( indent+2, ' ' ) << "nothing" << std::endl; 299 307 } else { 300 result->print( os, indent+2);308 printAll(results, os, indent+2); 301 309 } // if 302 os << std::endl; 303 Expression::print( os, indent ); 304 } 305 306 UntypedMemberExpr::UntypedMemberExpr( std::string _member, Expression *_aggregate, Expression *_aname ) : 310 Expression::print( os, indent ); 311 } 312 313 UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) : 307 314 Expression( _aname ), member(_member), aggregate(_aggregate) {} 308 315 309 316 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : 310 Expression( other ), member( other.member), aggregate( maybeClone( other.aggregate ) ) {317 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { 311 318 } 312 319 313 320 UntypedMemberExpr::~UntypedMemberExpr() { 314 321 delete aggregate; 322 delete member; 315 323 } 316 324 317 325 void UntypedMemberExpr::print( std::ostream &os, int indent ) const { 318 os << "Untyped Member Expression, with field: " << get_member(); 326 os << "Untyped Member Expression, with field: " << std::endl; 327 get_member()->print(os, indent+4); 328 os << std::string( indent+2, ' ' ); 319 329 320 330 Expression *agg = get_aggregate(); 321 os << " , from aggregate: ";331 os << "from aggregate: " << std::endl; 322 332 if (agg != 0) { 323 os << std::string( indent + 2, ' ' );324 agg->print(os, indent + 2);333 os << std::string( indent + 4, ' ' ); 334 agg->print(os, indent + 4); 325 335 } 326 336 os << std::string( indent+2, ' ' ); … … 331 341 MemberExpr::MemberExpr( DeclarationWithType *_member, Expression *_aggregate, Expression *_aname ) : 332 342 Expression( _aname ), member(_member), aggregate(_aggregate) { 333 set_result( member->get_type()->clone() ); 334 get_result()->set_isLvalue( true ); 343 add_result( member->get_type()->clone() ); 344 for ( std::list< Type* >::iterator i = get_results().begin(); i != get_results().end(); ++i ) { 345 (*i)->set_isLvalue( true ); 346 } // for 335 347 } 336 348 … … 363 375 } 364 376 365 366 UntypedExpr::UntypedExpr( Expression *_function, Expression *_aname ) : Expression( _aname ), function( _function) {}377 UntypedExpr::UntypedExpr( Expression *_function, const std::list<Expression *> &_args, Expression *_aname ) : 378 Expression( _aname ), function(_function), args(_args) {} 367 379 368 380 UntypedExpr::UntypedExpr( const UntypedExpr &other ) : … … 370 382 cloneAll( other.args, args ); 371 383 } 372 373 UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :374 Expression( _aname ), function(_function), args(_args) {}375 384 376 385 UntypedExpr::~UntypedExpr() { … … 410 419 LogicalExpr::LogicalExpr( Expression *arg1_, Expression *arg2_, bool andp, Expression *_aname ) : 411 420 Expression( _aname ), arg1(arg1_), arg2(arg2_), isAnd(andp) { 412 set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );421 add_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 413 422 } 414 423 … … 468 477 ImplicitCopyCtorExpr::ImplicitCopyCtorExpr( ApplicationExpr * callExpr ) : callExpr( callExpr ) { 469 478 assert( callExpr ); 470 assert( callExpr->has_result() ); 471 set_result( callExpr->get_result()->clone() ); 479 cloneAll( callExpr->get_results(), results ); 472 480 } 473 481 … … 502 510 Expression * arg = InitTweak::getCallArg( callExpr, 0 ); 503 511 assert( arg ); 504 set_result( maybeClone( arg->get_result() ));512 cloneAll( arg->get_results(), results ); 505 513 } 506 514 … … 522 530 523 531 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) { 524 set_result( type->clone() );532 add_result( type->clone() ); 525 533 } 526 534 … … 557 565 } 558 566 567 StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) { 568 assert( statements ); 569 std::list< Statement * > & body = statements->get_kids(); 570 if ( ! body.empty() ) { 571 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) { 572 cloneAll( exprStmt->get_expr()->get_results(), get_results() ); 573 } 574 } 575 } 576 StmtExpr::StmtExpr( const StmtExpr &other ) : statements( other.statements->clone() ) {} 577 StmtExpr::~StmtExpr() { 578 delete statements; 579 } 580 void StmtExpr::print( std::ostream &os, int indent ) const { 581 os << std::string( indent, ' ' ) << "Statement Expression: " << std::endl; 582 statements->print( os, indent+2 ); 583 } 584 559 585 std::ostream & operator<<( std::ostream & out, const Expression * expr ) { 560 586 expr->print( out );
Note:
See TracChangeset
for help on using the changeset viewer.