Changeset 3b58d91 for src/SynTree
- Timestamp:
- Sep 8, 2016, 10:51:07 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:
- cd14861
- Parents:
- 4e7f0f1
- Location:
- src/SynTree
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.cc
r4e7f0f1 r3b58d91 310 310 } 311 311 312 UntypedMemberExpr::UntypedMemberExpr( std::string_member, Expression *_aggregate, Expression *_aname ) :312 UntypedMemberExpr::UntypedMemberExpr( Expression * _member, Expression *_aggregate, Expression *_aname ) : 313 313 Expression( _aname ), member(_member), aggregate(_aggregate) {} 314 314 315 315 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr &other ) : 316 Expression( other ), member( other.member), aggregate( maybeClone( other.aggregate ) ) {316 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { 317 317 } 318 318 319 319 UntypedMemberExpr::~UntypedMemberExpr() { 320 320 delete aggregate; 321 delete member; 321 322 } 322 323 323 324 void UntypedMemberExpr::print( std::ostream &os, int indent ) const { 324 os << "Untyped Member Expression, with field: " << get_member(); 325 os << "Untyped Member Expression, with field: " << std::endl; 326 get_member()->print(os, indent+4); 327 os << std::string( indent+2, ' ' ); 325 328 326 329 Expression *agg = get_aggregate(); 327 os << " , from aggregate: ";330 os << "from aggregate: " << std::endl; 328 331 if (agg != 0) { 329 os << std::string( indent + 2, ' ' );330 agg->print(os, indent + 2);332 os << std::string( indent + 4, ' ' ); 333 agg->print(os, indent + 4); 331 334 } 332 335 os << std::string( indent+2, ' ' ); -
src/SynTree/Expression.h
r4e7f0f1 r3b58d91 200 200 class UntypedMemberExpr : public Expression { 201 201 public: 202 UntypedMemberExpr( std::stringmember, Expression *aggregate, Expression *_aname = nullptr );202 UntypedMemberExpr( Expression *member, Expression *aggregate, Expression *_aname = nullptr ); 203 203 UntypedMemberExpr( const UntypedMemberExpr &other ); 204 204 virtual ~UntypedMemberExpr(); 205 205 206 std::stringget_member() const { return member; }207 void set_member( const std::string &newValue ) { member = newValue; }206 Expression * get_member() const { return member; } 207 void set_member( Expression * newValue ) { member = newValue; } 208 208 Expression *get_aggregate() const { return aggregate; } 209 209 void set_aggregate( Expression *newValue ) { aggregate = newValue; } … … 214 214 virtual void print( std::ostream &os, int indent = 0 ) const; 215 215 private: 216 std::stringmember;216 Expression *member; 217 217 Expression *aggregate; 218 218 }; … … 618 618 CompoundLiteralExpr( Type * type, Initializer * initializer ); 619 619 CompoundLiteralExpr( const CompoundLiteralExpr &other ); 620 ~CompoundLiteralExpr();620 virtual ~CompoundLiteralExpr(); 621 621 622 622 Type * get_type() const { return type; } … … 651 651 private: 652 652 Expression *low, *high; 653 }; 654 655 /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer 656 class TupleIndexExpr : public Expression { 657 public: 658 TupleIndexExpr( Expression * tuple, unsigned int index ); 659 TupleIndexExpr( const TupleIndexExpr &other ); 660 virtual ~TupleIndexExpr(); 661 662 Expression * get_tuple() const { return tuple; } 663 int get_index() const { return index; } 664 TupleIndexExpr * set_tuple( Expression *newValue ) { tuple = newValue; return this; } 665 TupleIndexExpr * set_index( unsigned int newValue ) { index = newValue; return this; } 666 667 virtual TupleIndexExpr *clone() const { return new TupleIndexExpr( *this ); } 668 virtual void accept( Visitor &v ) { v.visit( this ); } 669 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 670 virtual void print( std::ostream &os, int indent = 0 ) const; 671 private: 672 Expression * tuple; 673 unsigned int index; 674 }; 675 676 /// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer 677 class MemberTupleExpr : public Expression { 678 public: 679 MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr ); 680 MemberTupleExpr( const MemberTupleExpr &other ); 681 virtual ~MemberTupleExpr(); 682 683 Expression * get_member() const { return member; } 684 Expression * get_aggregate() const { return aggregate; } 685 MemberTupleExpr * set_member( Expression *newValue ) { member = newValue; return this; } 686 MemberTupleExpr * set_aggregate( Expression *newValue ) { aggregate = newValue; return this; } 687 688 virtual MemberTupleExpr *clone() const { return new MemberTupleExpr( *this ); } 689 virtual void accept( Visitor &v ) { v.visit( this ); } 690 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 691 virtual void print( std::ostream &os, int indent = 0 ) const; 692 private: 693 Expression * member; 694 Expression * aggregate; 695 }; 696 697 /// MultipleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f]; 698 class MultipleAssignExpr : public Expression { 699 public: 700 MultipleAssignExpr( Expression * lhs, Expression * rhs ); 701 MultipleAssignExpr( const MultipleAssignExpr &other ); 702 virtual ~MultipleAssignExpr(); 703 704 Expression * get_lhs() const { return lhs; } 705 Expression * get_rhs() const { return rhs; } 706 MultipleAssignExpr * set_lhs( Expression *newValue ) { lhs = newValue; return this; } 707 MultipleAssignExpr * set_rhs( Expression *newValue ) { rhs = newValue; return this; } 708 709 virtual MultipleAssignExpr *clone() const { return new MultipleAssignExpr( *this ); } 710 virtual void accept( Visitor &v ) { v.visit( this ); } 711 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 712 virtual void print( std::ostream &os, int indent = 0 ) const; 713 private: 714 Expression * lhs; 715 Expression * rhs; 716 }; 717 718 /// MassAssignExpr represents a mass assignment operations, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0; 719 class MassAssignExpr : public Expression { 720 public: 721 MassAssignExpr( Expression * tuple, int field ); 722 MassAssignExpr( const MassAssignExpr &other ); 723 virtual ~MassAssignExpr(); 724 725 Expression * get_lhs() const { return lhs; } 726 Expression * get_rhs() const { return rhs; } 727 MassAssignExpr * set_lhs( Expression *newValue ) { lhs = newValue; return this; } 728 MassAssignExpr * set_rhs( Expression *newValue ) { rhs = newValue; return this; } 729 730 virtual MassAssignExpr *clone() const { return new MassAssignExpr( *this ); } 731 virtual void accept( Visitor &v ) { v.visit( this ); } 732 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 733 virtual void print( std::ostream &os, int indent = 0 ) const; 734 private: 735 Expression * lhs; // multiple exprs 736 Expression * rhs; // single expr 653 737 }; 654 738 -
src/SynTree/Mutator.cc
r4e7f0f1 r3b58d91 216 216 mutateAll( memberExpr->get_results(), *this ); 217 217 memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); 218 memberExpr->set_member( maybeMutate( memberExpr->get_member(), *this ) ); 218 219 return memberExpr; 219 220 } … … 355 356 rangeExpr->set_high( maybeMutate( rangeExpr->get_high(), *this ) ); 356 357 return rangeExpr; 358 } 359 360 Expression *Mutator::mutate( TupleIndexExpr *tupleExpr ) { 361 mutateAll( tupleExpr->get_results(), *this ); 362 tupleExpr->set_tuple( maybeMutate( tupleExpr->get_tuple(), *this ) ); 363 return tupleExpr; 364 } 365 366 Expression *Mutator::mutate( MemberTupleExpr *tupleExpr ) { 367 mutateAll( tupleExpr->get_results(), *this ); 368 tupleExpr->set_member( maybeMutate( tupleExpr->get_member(), *this ) ); 369 tupleExpr->set_aggregate( maybeMutate( tupleExpr->get_aggregate(), *this ) ); 370 return tupleExpr; 371 } 372 373 Expression *Mutator::mutate( MultipleAssignExpr *assignExpr ) { 374 mutateAll( assignExpr->get_results(), *this ); 375 assignExpr->set_lhs( maybeMutate( assignExpr->get_lhs(), *this ) ); 376 assignExpr->set_rhs( maybeMutate( assignExpr->get_rhs(), *this ) ); 377 return assignExpr; 378 } 379 380 Expression *Mutator::mutate( MassAssignExpr *assignExpr ) { 381 mutateAll( assignExpr->get_results(), *this ); 382 assignExpr->set_lhs( maybeMutate( assignExpr->get_lhs(), *this ) ); 383 assignExpr->set_rhs( maybeMutate( assignExpr->get_rhs(), *this ) ); 384 return assignExpr; 357 385 } 358 386 -
src/SynTree/Mutator.h
r4e7f0f1 r3b58d91 79 79 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ); 80 80 virtual Expression* mutate( RangeExpr *rangeExpr ); 81 virtual Expression* mutate( TupleIndexExpr *tupleExpr ); 82 virtual Expression* mutate( MemberTupleExpr *tupleExpr ); 83 virtual Expression* mutate( MultipleAssignExpr *assignExpr ); 84 virtual Expression* mutate( MassAssignExpr *assignExpr ); 81 85 82 86 virtual Type* mutate( VoidType *basicType ); -
src/SynTree/SynTree.h
r4e7f0f1 r3b58d91 84 84 class CompoundLiteralExpr; 85 85 class RangeExpr; 86 class TupleIndexExpr; 87 class MemberTupleExpr; 88 class MultipleAssignExpr; 89 class MassAssignExpr; 86 90 87 91 class Type; -
src/SynTree/TupleExpr.cc
r4e7f0f1 r3b58d91 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TupleExpr.cc -- 7 // TupleExpr.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 16 16 #include "Expression.h" 17 17 #include "Common/utility.h" 18 #include "Type.h" 18 19 19 20 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) { … … 48 49 } 49 50 51 TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) { 52 // TupleType * type = safe_dynamic_cast< TypeType * >( tuple->get_ ) 53 assert( tuple->get_results().size() >= index ); 54 add_result( *std::next( tuple->get_results().begin(), index ) ); 55 } 56 57 TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) { 58 } 59 60 TupleIndexExpr::~TupleIndexExpr() { 61 delete tuple; 62 } 63 64 void TupleIndexExpr::print( std::ostream &os, int indent ) const { 65 os << std::string( indent, ' ' ) << "Tuple Index Expression, with tuple:" << std::endl; 66 tuple->print( os, indent+2 ); 67 os << std::string( indent+2, ' ' ) << "with index: " << index << std::endl; 68 Expression::print( os, indent ); 69 } 70 71 MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) { 72 cloneAll( member->get_results(), get_results() ); // xxx - ??? 73 } 74 75 MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) { 76 } 77 78 MemberTupleExpr::~MemberTupleExpr() { 79 delete member; 80 delete aggregate; 81 } 82 83 void MemberTupleExpr::print( std::ostream &os, int indent ) const { 84 os << std::string( indent, ' ' ) << "Member Tuple Expression, with aggregate:" << std::endl; 85 aggregate->print( os, indent+2 ); 86 os << std::string( indent+2, ' ' ) << "with member: " << std::endl; 87 member->print( os, indent+2 ); 88 Expression::print( os, indent ); 89 } 90 91 50 92 // Local Variables: // 51 93 // tab-width: 4 // -
src/SynTree/Visitor.cc
r4e7f0f1 r3b58d91 182 182 acceptAll( memberExpr->get_results(), *this ); 183 183 maybeAccept( memberExpr->get_aggregate(), *this ); 184 maybeAccept( memberExpr->get_member(), *this ); 184 185 } 185 186 … … 301 302 maybeAccept( rangeExpr->get_low(), *this ); 302 303 maybeAccept( rangeExpr->get_high(), *this ); 304 } 305 306 void Visitor::visit( TupleIndexExpr *tupleExpr ) { 307 acceptAll( tupleExpr->get_results(), *this ); 308 maybeAccept( tupleExpr->get_tuple(), *this ); 309 } 310 311 void Visitor::visit( MemberTupleExpr *tupleExpr ) { 312 acceptAll( tupleExpr->get_results(), *this ); 313 maybeAccept( tupleExpr->get_member(), *this ); 314 maybeAccept( tupleExpr->get_aggregate(), *this ); 315 } 316 317 void Visitor::visit( MultipleAssignExpr *assignExpr ) { 318 acceptAll( assignExpr->get_results(), *this ); 319 maybeAccept( assignExpr->get_lhs(), *this ); 320 maybeAccept( assignExpr->get_rhs(), *this ); 321 } 322 323 void Visitor::visit( MassAssignExpr *assignExpr ) { 324 acceptAll( assignExpr->get_results(), *this ); 325 maybeAccept( assignExpr->get_lhs(), *this ); 326 maybeAccept( assignExpr->get_rhs(), *this ); 303 327 } 304 328 -
src/SynTree/Visitor.h
r4e7f0f1 r3b58d91 79 79 virtual void visit( CompoundLiteralExpr *compLitExpr ); 80 80 virtual void visit( RangeExpr *rangeExpr ); 81 virtual void visit( TupleIndexExpr *tupleExpr ); 82 virtual void visit( MemberTupleExpr *tupleExpr ); 83 virtual void visit( MultipleAssignExpr *assignExpr ); 84 virtual void visit( MassAssignExpr *assignExpr ); 81 85 82 86 virtual void visit( VoidType *basicType );
Note: See TracChangeset
for help on using the changeset viewer.