Changeset 3c13c03 for src/SynTree
- Timestamp:
- Sep 17, 2016, 8:27:51 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 8c49c0e
- Parents:
- 12bc63a
- Location:
- src/SynTree
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
r12bc63a r3c13c03 522 522 523 523 CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) { 524 assert( type && initializer ); 524 525 set_result( type->clone() ); 525 526 } 526 527 527 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer) ) {}528 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( other.type->clone() ), initializer( other.initializer->clone() ) {} 528 529 529 530 CompoundLiteralExpr::~CompoundLiteralExpr() { … … 534 535 void CompoundLiteralExpr::print( std::ostream &os, int indent ) const { 535 536 os << "Compound Literal Expression: " << std::endl; 536 if ( type ) type->print( os, indent + 2 ); 537 if ( initializer ) initializer->print( os, indent + 2 ); 537 os << std::string( indent+2, ' ' ); 538 type->print( os, indent + 2 ); 539 os << std::string( indent+2, ' ' ); 540 initializer->print( os, indent + 2 ); 538 541 } 539 542 … … 549 552 550 553 RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} 551 RangeExpr::RangeExpr( const RangeExpr &other ) : low( other.low->clone() ), high( other.high->clone() ) {}554 RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} 552 555 void RangeExpr::print( std::ostream &os, int indent ) const { 553 os << std::string( indent, ' ' ) <<"Range Expression: ";556 os << "Range Expression: "; 554 557 low->print( os, indent ); 555 558 os << " ... "; … … 566 569 } 567 570 } 568 StmtExpr::StmtExpr( const StmtExpr &other ) : statements( other.statements->clone() ) {}571 StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {} 569 572 StmtExpr::~StmtExpr() { 570 573 delete statements; 571 574 } 572 575 void StmtExpr::print( std::ostream &os, int indent ) const { 573 os << std::string( indent, ' ' ) << "Statement Expression: " << std::endl;576 os << "Statement Expression: " << std::endl << std::string( indent, ' ' ); 574 577 statements->print( os, indent+2 ); 578 } 579 580 581 UniqueExpr::UniqueExpr( Expression *expr ) : expr( new Expression* ) { 582 set_expr( expr ); 583 assert( expr ); 584 assert( expr->has_result() ); 585 set_result( expr->get_result()->clone() ); 586 } 587 UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( other.expr ) { 588 } 589 UniqueExpr::~UniqueExpr() { 590 if ( expr.unique() ) { 591 delete *expr; 592 } 593 } 594 void UniqueExpr::print( std::ostream &os, int indent ) const { 595 os << "Unique Expression: " << std::endl << std::string( indent+2, ' ' ); 596 get_expr()->print( os, indent+2 ); 575 597 } 576 598 -
src/SynTree/Expression.h
r12bc63a r3c13c03 639 639 class TupleExpr : public Expression { 640 640 public: 641 TupleExpr( Expression *_aname = nullptr );641 TupleExpr( const std::list< Expression * > & exprs = std::list< Expression * >(), Expression *_aname = nullptr ); 642 642 TupleExpr( const TupleExpr &other ); 643 643 virtual ~TupleExpr(); … … 733 733 }; 734 734 735 class UniqueExpr : public Expression { 736 public: 737 UniqueExpr( Expression * expr ); 738 UniqueExpr( const UniqueExpr & other ); 739 ~UniqueExpr(); 740 741 Expression * get_expr() const { return *expr; } 742 UniqueExpr * set_expr( Expression * newValue ) { *expr = newValue; return this; } 743 744 virtual UniqueExpr *clone() const { return new UniqueExpr( *this ); } 745 virtual void accept( Visitor &v ) { v.visit( this ); } 746 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 747 virtual void print( std::ostream &os, int indent = 0 ) const; 748 private: 749 std::shared_ptr< Expression * > expr; 750 }; 751 735 752 std::ostream & operator<<( std::ostream & out, const Expression * expr ); 736 753 -
src/SynTree/Mutator.cc
r12bc63a r3c13c03 384 384 } 385 385 386 Expression *Mutator::mutate( UniqueExpr *uniqueExpr ) { 387 uniqueExpr->set_result( maybeMutate( uniqueExpr->get_result(), *this ) ); 388 uniqueExpr->set_expr( maybeMutate( uniqueExpr->get_expr(), *this ) ); 389 return uniqueExpr; 390 } 391 386 392 Type *Mutator::mutate( VoidType *voidType ) { 387 393 mutateAll( voidType->get_forall(), *this ); -
src/SynTree/Mutator.h
r12bc63a r3c13c03 83 83 virtual Expression* mutate( TupleAssignExpr *assignExpr ); 84 84 virtual Expression* mutate( StmtExpr * stmtExpr ); 85 virtual Expression* mutate( UniqueExpr * uniqueExpr ); 85 86 86 87 virtual Type* mutate( VoidType *basicType ); -
src/SynTree/SynTree.h
r12bc63a r3c13c03 88 88 class TupleAssignExpr; 89 89 class StmtExpr; 90 class UniqueExpr; 90 91 91 92 class Type; -
src/SynTree/TupleExpr.cc
r12bc63a r3c13c03 18 18 #include "Type.h" 19 19 #include "Declaration.h" 20 #include "Tuples/Tuples.h" 20 21 21 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) { 22 TupleExpr::TupleExpr( const std::list< Expression * > & exprs, Expression *_aname ) : Expression( _aname ), exprs( exprs ) { 23 if ( ! exprs.empty() ) { 24 if ( std::all_of( exprs.begin(), exprs.end(), [](Expression * expr) { return expr->get_result(); } ) ) { 25 set_result( Tuples::makeTupleType( exprs ) ); 26 } 27 } 22 28 } 23 29 … … 36 42 } 37 43 38 TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) {44 TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index ) { 39 45 TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() ); 40 assert( type->size() > =index );41 set_result( *std::next( type->get_types().begin(), index) );46 assert( type->size() > index ); 47 set_result( (*std::next( type->get_types().begin(), index ))->clone() ); 42 48 } 43 49 … … 51 57 void TupleIndexExpr::print( std::ostream &os, int indent ) const { 52 58 os << "Tuple Index Expression, with tuple:" << std::endl; 59 os << std::string( indent+2, ' ' ); 53 60 tuple->print( os, indent+2 ); 54 61 os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl; … … 70 77 void MemberTupleExpr::print( std::ostream &os, int indent ) const { 71 78 os << "Member Tuple Expression, with aggregate:" << std::endl; 79 os << std::string( indent+2, ' ' ); 72 80 aggregate->print( os, indent+2 ); 73 81 os << std::string( indent+2, ' ' ) << "with member: " << std::endl; 82 os << std::string( indent+2, ' ' ); 74 83 member->print( os, indent+2 ); 75 84 Expression::print( os, indent ); … … 97 106 98 107 void TupleAssignExpr::print( std::ostream &os, int indent ) const { 99 os << std::string( indent, ' ' ) <<"Tuple Assignment Expression, with temporaries:" << std::endl;108 os << "Tuple Assignment Expression, with temporaries:" << std::endl; 100 109 printAll( tempDecls, os, indent+4 ); 101 110 os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl; -
src/SynTree/Visitor.cc
r12bc63a r3c13c03 326 326 } 327 327 328 void Visitor::visit( UniqueExpr *uniqueExpr ) { 329 maybeAccept( uniqueExpr->get_result(), *this ); 330 maybeAccept( uniqueExpr->get_expr(), *this ); 331 } 332 328 333 void Visitor::visit( VoidType *voidType ) { 329 334 acceptAll( voidType->get_forall(), *this ); -
src/SynTree/Visitor.h
r12bc63a r3c13c03 83 83 virtual void visit( TupleAssignExpr *assignExpr ); 84 84 virtual void visit( StmtExpr * stmtExpr ); 85 virtual void visit( UniqueExpr * uniqueExpr ); 85 86 86 87 virtual void visit( VoidType *basicType );
Note: See TracChangeset
for help on using the changeset viewer.