Changeset 6eb8948 for src/SynTree
- Timestamp:
- Sep 12, 2016, 6:32:46 PM (9 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:
- f006f01
- Parents:
- 8f7cea1
- git-author:
- Rob Schluntz <rschlunt@…> (09/12/16 18:24:34)
- git-committer:
- Rob Schluntz <rschlunt@…> (09/12/16 18:32:46)
- Location:
- src/SynTree
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/SynTree/Expression.cc ¶
r8f7cea1 r6eb8948 375 375 } 376 376 377 378 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) {} 379 379 380 380 UntypedExpr::UntypedExpr( const UntypedExpr &other ) : … … 382 382 cloneAll( other.args, args ); 383 383 } 384 385 UntypedExpr::UntypedExpr( Expression *_function, std::list<Expression *> &_args, Expression *_aname ) :386 Expression( _aname ), function(_function), args(_args) {}387 384 388 385 UntypedExpr::~UntypedExpr() { … … 568 565 } 569 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 570 585 std::ostream & operator<<( std::ostream & out, const Expression * expr ) { 571 586 expr->print( out ); -
TabularUnified src/SynTree/Expression.h ¶
r8f7cea1 r6eb8948 98 98 class UntypedExpr : public Expression { 99 99 public: 100 UntypedExpr( Expression *function, Expression *_aname = nullptr );100 UntypedExpr( Expression *function, const std::list<Expression *> &args = std::list< Expression * >(), Expression *_aname = nullptr ); 101 101 UntypedExpr( const UntypedExpr &other ); 102 UntypedExpr( Expression *function, std::list<Expression *> &args, Expression *_aname = nullptr );103 102 virtual ~UntypedExpr(); 104 103 … … 483 482 }; 484 483 485 /// TupleExpr represents a tuple expression ( [a, b, c] )486 class TupleExpr : public Expression {487 public:488 TupleExpr( Expression *_aname = nullptr );489 TupleExpr( const TupleExpr &other );490 virtual ~TupleExpr();491 492 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; }493 std::list<Expression*>& get_exprs() { return exprs; }494 495 virtual TupleExpr *clone() const { return new TupleExpr( *this ); }496 virtual void accept( Visitor &v ) { v.visit( this ); }497 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }498 virtual void print( std::ostream &os, int indent = 0 ) const;499 private:500 std::list<Expression*> exprs;501 };502 503 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on504 class SolvedTupleExpr : public Expression {505 public:506 SolvedTupleExpr( Expression *_aname = nullptr ) : Expression( _aname ) {}507 SolvedTupleExpr( std::list<Expression *> &, Expression *_aname = nullptr );508 SolvedTupleExpr( const SolvedTupleExpr &other );509 virtual ~SolvedTupleExpr() {}510 511 std::list<Expression*> &get_exprs() { return exprs; }512 513 virtual SolvedTupleExpr *clone() const { return new SolvedTupleExpr( *this ); }514 virtual void accept( Visitor &v ) { v.visit( this ); }515 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }516 virtual void print( std::ostream &os, int indent = 0 ) const;517 private:518 std::list<Expression*> exprs;519 };520 521 484 /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter) 522 485 class TypeExpr : public Expression { … … 672 635 }; 673 636 637 /// TupleExpr represents a tuple expression ( [a, b, c] ) 638 class TupleExpr : public Expression { 639 public: 640 TupleExpr( Expression *_aname = nullptr ); 641 TupleExpr( const TupleExpr &other ); 642 virtual ~TupleExpr(); 643 644 void set_exprs( std::list<Expression*> newValue ) { exprs = newValue; } 645 std::list<Expression*>& get_exprs() { return exprs; } 646 647 virtual TupleExpr *clone() const { return new TupleExpr( *this ); } 648 virtual void accept( Visitor &v ) { v.visit( this ); } 649 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 650 virtual void print( std::ostream &os, int indent = 0 ) const; 651 private: 652 std::list<Expression*> exprs; 653 }; 654 674 655 /// TupleIndexExpr represents an element selection operation on a tuple value, e.g. t.3 after processing by the expression analyzer 675 656 class TupleIndexExpr : public Expression { … … 714 695 }; 715 696 716 /// MultipleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f]; 717 class MultipleAssignExpr : public Expression { 718 public: 719 MultipleAssignExpr( Expression * lhs, Expression * rhs ); 720 MultipleAssignExpr( const MultipleAssignExpr &other ); 721 virtual ~MultipleAssignExpr(); 722 723 Expression * get_lhs() const { return lhs; } 724 Expression * get_rhs() const { return rhs; } 725 MultipleAssignExpr * set_lhs( Expression *newValue ) { lhs = newValue; return this; } 726 MultipleAssignExpr * set_rhs( Expression *newValue ) { rhs = newValue; return this; } 727 728 virtual MultipleAssignExpr *clone() const { return new MultipleAssignExpr( *this ); } 729 virtual void accept( Visitor &v ) { v.visit( this ); } 730 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 731 virtual void print( std::ostream &os, int indent = 0 ) const; 732 private: 733 Expression * lhs; 734 Expression * rhs; 735 }; 736 737 /// 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; 738 class MassAssignExpr : public Expression { 739 public: 740 MassAssignExpr( Expression * tuple, int field ); 741 MassAssignExpr( const MassAssignExpr &other ); 742 virtual ~MassAssignExpr(); 743 744 Expression * get_lhs() const { return lhs; } 745 Expression * get_rhs() const { return rhs; } 746 MassAssignExpr * set_lhs( Expression *newValue ) { lhs = newValue; return this; } 747 MassAssignExpr * set_rhs( Expression *newValue ) { rhs = newValue; return this; } 748 749 virtual MassAssignExpr *clone() const { return new MassAssignExpr( *this ); } 750 virtual void accept( Visitor &v ) { v.visit( this ); } 751 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 752 virtual void print( std::ostream &os, int indent = 0 ) const; 753 private: 754 Expression * lhs; // multiple exprs 755 Expression * rhs; // single expr 697 /// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, or a mass assignment operation, where the left hand side has tuple type and the right hand side does not, e.g. [a, b, c] = 5.0; 698 class TupleAssignExpr : public Expression { 699 public: 700 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr ); 701 TupleAssignExpr( const TupleAssignExpr &other ); 702 virtual ~TupleAssignExpr(); 703 704 std::list< Expression * > & get_assigns() { return assigns; } 705 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; } 706 707 virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); } 708 virtual void accept( Visitor &v ) { v.visit( this ); } 709 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 710 virtual void print( std::ostream &os, int indent = 0 ) const; 711 private: 712 std::list< Expression * > assigns; // assignment expressions that use tempDecls 713 std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs 714 }; 715 716 /// StmtExpr represents a GCC 'statement expression', e.g. ({ int x = 5; x; }) 717 class StmtExpr : public Expression { 718 public: 719 StmtExpr( CompoundStmt *statements ); 720 StmtExpr( const StmtExpr & other ); 721 virtual ~StmtExpr(); 722 723 CompoundStmt * get_statements() const { return statements; } 724 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; } 725 726 virtual StmtExpr *clone() const { return new StmtExpr( *this ); } 727 virtual void accept( Visitor &v ) { v.visit( this ); } 728 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 729 virtual void print( std::ostream &os, int indent = 0 ) const; 730 private: 731 CompoundStmt * statements; 756 732 }; 757 733 -
TabularUnified src/SynTree/Mutator.cc ¶
r8f7cea1 r6eb8948 308 308 } 309 309 310 Expression *Mutator::mutate( TupleExpr *tupleExpr ) {311 mutateAll( tupleExpr->get_results(), *this );312 mutateAll( tupleExpr->get_exprs(), *this );313 return tupleExpr;314 }315 316 Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {317 mutateAll( tupleExpr->get_results(), *this );318 mutateAll( tupleExpr->get_exprs(), *this );319 return tupleExpr;320 }321 322 310 Expression *Mutator::mutate( TypeExpr *typeExpr ) { 323 311 mutateAll( typeExpr->get_results(), *this ); … … 364 352 } 365 353 354 Expression *Mutator::mutate( TupleExpr *tupleExpr ) { 355 mutateAll( tupleExpr->get_results(), *this ); 356 mutateAll( tupleExpr->get_exprs(), *this ); 357 return tupleExpr; 358 } 359 366 360 Expression *Mutator::mutate( TupleIndexExpr *tupleExpr ) { 367 361 mutateAll( tupleExpr->get_results(), *this ); … … 377 371 } 378 372 379 Expression *Mutator::mutate( MultipleAssignExpr *assignExpr ) {373 Expression *Mutator::mutate( TupleAssignExpr *assignExpr ) { 380 374 mutateAll( assignExpr->get_results(), *this ); 381 assignExpr->set_lhs( maybeMutate( assignExpr->get_lhs(), *this ));382 assignExpr->set_rhs( maybeMutate( assignExpr->get_rhs(), *this ));375 mutateAll( assignExpr->get_tempDecls(), *this ); 376 mutateAll( assignExpr->get_assigns(), *this ); 383 377 return assignExpr; 384 378 } 385 379 386 Expression *Mutator::mutate( MassAssignExpr *assignExpr ) { 387 mutateAll( assignExpr->get_results(), *this ); 388 assignExpr->set_lhs( maybeMutate( assignExpr->get_lhs(), *this ) ); 389 assignExpr->set_rhs( maybeMutate( assignExpr->get_rhs(), *this ) ); 390 return assignExpr; 380 Expression *Mutator::mutate( StmtExpr *stmtExpr ) { 381 mutateAll( stmtExpr->get_results(), *this ); 382 stmtExpr->set_statements( maybeMutate( stmtExpr->get_statements(), *this ) ); 383 return stmtExpr; 391 384 } 392 385 -
TabularUnified src/SynTree/Mutator.h ¶
r8f7cea1 r6eb8948 71 71 virtual Expression* mutate( ConditionalExpr *conditionalExpr ); 72 72 virtual Expression* mutate( CommaExpr *commaExpr ); 73 virtual Expression* mutate( TupleExpr *tupleExpr );74 virtual Expression* mutate( SolvedTupleExpr *tupleExpr );75 73 virtual Expression* mutate( TypeExpr *typeExpr ); 76 74 virtual Expression* mutate( AsmExpr *asmExpr ); … … 80 78 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 81 79 virtual Expression* mutate( RangeExpr *rangeExpr ); 80 virtual Expression* mutate( TupleExpr *tupleExpr ); 82 81 virtual Expression* mutate( TupleIndexExpr *tupleExpr ); 83 82 virtual Expression* mutate( MemberTupleExpr *tupleExpr ); 84 virtual Expression* mutate( MultipleAssignExpr *assignExpr );85 virtual Expression* mutate( MassAssignExpr *assignExpr );83 virtual Expression* mutate( TupleAssignExpr *assignExpr ); 84 virtual Expression* mutate( StmtExpr * stmtExpr ); 86 85 87 86 virtual Type* mutate( VoidType *basicType ); -
TabularUnified src/SynTree/SynTree.h ¶
r8f7cea1 r6eb8948 76 76 class ConditionalExpr; 77 77 class CommaExpr; 78 class TupleExpr;79 class SolvedTupleExpr;80 78 class TypeExpr; 81 79 class AsmExpr; … … 85 83 class UntypedValofExpr; 86 84 class RangeExpr; 85 class TupleExpr; 87 86 class TupleIndexExpr; 88 87 class MemberTupleExpr; 89 class MultipleAssignExpr;90 class MassAssignExpr;88 class TupleAssignExpr; 89 class StmtExpr; 91 90 92 91 class Type; -
TabularUnified src/SynTree/TupleExpr.cc ¶
r8f7cea1 r6eb8948 17 17 #include "Common/utility.h" 18 18 #include "Type.h" 19 #include "Declaration.h" 19 20 20 21 TupleExpr::TupleExpr( Expression *_aname ) : Expression( _aname ) { … … 31 32 void TupleExpr::print( std::ostream &os, int indent ) const { 32 33 os << std::string( indent, ' ' ) << "Tuple:" << std::endl; 33 printAll( exprs, os, indent+2 );34 Expression::print( os, indent );35 }36 37 SolvedTupleExpr::SolvedTupleExpr( std::list<Expression *> &_exprs, Expression *_aname ) : Expression( _aname ) {38 std::copy(_exprs.begin(), _exprs.end(), back_inserter(exprs));39 }40 41 SolvedTupleExpr::SolvedTupleExpr( const SolvedTupleExpr &other ) : Expression( other ) {42 cloneAll( other.exprs, exprs );43 }44 45 void SolvedTupleExpr::print( std::ostream &os, int indent ) const {46 os << std::string( indent, ' ' ) << "Solved Tuple:" << std::endl;47 34 printAll( exprs, os, indent+2 ); 48 35 Expression::print( os, indent ); … … 90 77 91 78 79 TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) { 80 for ( Expression * expr : assigns ) { 81 cloneAll( expr->get_results(), get_results() ); 82 } 83 } 84 85 TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ), tempDecls( other.tempDecls ) /* temporary */ { 86 cloneAll( other.assigns, assigns ); 87 // xxx - clone needs to go into assigns and replace tempDecls 88 } 89 90 TupleAssignExpr::~TupleAssignExpr() { 91 deleteAll( assigns ); 92 // deleteAll( tempDecls ); 93 } 94 95 void TupleAssignExpr::print( std::ostream &os, int indent ) const { 96 os << std::string( indent, ' ' ) << "Tuple Assignment Expression, with temporaries:" << std::endl; 97 printAll( tempDecls, os, indent+4 ); 98 os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl; 99 printAll( assigns, os, indent+4 ); 100 Expression::print( os, indent ); 101 } 102 103 104 92 105 // Local Variables: // 93 106 // tab-width: 4 // -
TabularUnified src/SynTree/TupleType.cc ¶
r8f7cea1 r6eb8948 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // TupleType.cc -- 7 // TupleType.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 17 17 #include "Common/utility.h" 18 18 19 TupleType::TupleType( const Type::Qualifiers &tq ) : Type( tq) {19 TupleType::TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types ) : Type( tq ), types( types ) { 20 20 } 21 21 -
TabularUnified src/SynTree/Type.h ¶
r8f7cea1 r6eb8948 348 348 class TupleType : public Type { 349 349 public: 350 TupleType( const Type::Qualifiers &tq );350 TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types = std::list< Type * >() ); 351 351 TupleType( const TupleType& ); 352 352 virtual ~TupleType(); -
TabularUnified src/SynTree/Visitor.cc ¶
r8f7cea1 r6eb8948 261 261 } 262 262 263 void Visitor::visit( TupleExpr *tupleExpr ) {264 acceptAll( tupleExpr->get_results(), *this );265 acceptAll( tupleExpr->get_exprs(), *this );266 }267 268 void Visitor::visit( SolvedTupleExpr *tupleExpr ) {269 acceptAll( tupleExpr->get_results(), *this );270 acceptAll( tupleExpr->get_exprs(), *this );271 }272 273 263 void Visitor::visit( TypeExpr *typeExpr ) { 274 264 acceptAll( typeExpr->get_results(), *this ); … … 309 299 } 310 300 301 void Visitor::visit( TupleExpr *tupleExpr ) { 302 acceptAll( tupleExpr->get_results(), *this ); 303 acceptAll( tupleExpr->get_exprs(), *this ); 304 } 305 311 306 void Visitor::visit( TupleIndexExpr *tupleExpr ) { 312 307 acceptAll( tupleExpr->get_results(), *this ); … … 320 315 } 321 316 322 void Visitor::visit( MultipleAssignExpr *assignExpr ) {317 void Visitor::visit( TupleAssignExpr *assignExpr ) { 323 318 acceptAll( assignExpr->get_results(), *this ); 324 maybeAccept( assignExpr->get_lhs(), *this ); 325 maybeAccept( assignExpr->get_rhs(), *this ); 326 } 327 328 void Visitor::visit( MassAssignExpr *assignExpr ) { 329 acceptAll( assignExpr->get_results(), *this ); 330 maybeAccept( assignExpr->get_lhs(), *this ); 331 maybeAccept( assignExpr->get_rhs(), *this ); 319 acceptAll( assignExpr->get_tempDecls(), *this ); 320 acceptAll( assignExpr->get_assigns(), *this ); 321 } 322 323 void Visitor::visit( StmtExpr *stmtExpr ) { 324 acceptAll( stmtExpr->get_results(), *this ); 325 maybeAccept( stmtExpr->get_statements(), *this ); 332 326 } 333 327 -
TabularUnified src/SynTree/Visitor.h ¶
r8f7cea1 r6eb8948 71 71 virtual void visit( ConditionalExpr *conditionalExpr ); 72 72 virtual void visit( CommaExpr *commaExpr ); 73 virtual void visit( TupleExpr *tupleExpr );74 virtual void visit( SolvedTupleExpr *tupleExpr );75 73 virtual void visit( TypeExpr *typeExpr ); 76 74 virtual void visit( AsmExpr *asmExpr ); … … 80 78 virtual void visit( UntypedValofExpr *valofExpr ); 81 79 virtual void visit( RangeExpr *rangeExpr ); 80 virtual void visit( TupleExpr *tupleExpr ); 82 81 virtual void visit( TupleIndexExpr *tupleExpr ); 83 82 virtual void visit( MemberTupleExpr *tupleExpr ); 84 virtual void visit( MultipleAssignExpr *assignExpr );85 virtual void visit( MassAssignExpr *assignExpr );83 virtual void visit( TupleAssignExpr *assignExpr ); 84 virtual void visit( StmtExpr * stmtExpr ); 86 85 87 86 virtual void visit( VoidType *basicType );
Note: See TracChangeset
for help on using the changeset viewer.