Changeset 436c0de for src/SynTree
- Timestamp:
- Jun 18, 2017, 9:22:22 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:
- f1e80d8
- Parents:
- ade20d0 (diff), 42b0d73 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/SynTree
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Expression.h
rade20d0 r436c0de 690 690 }; 691 691 692 /// MemberTupleExpr represents a tuple member selection operation on a struct type, e.g. s.[a, b, c] after processing by the expression analyzer693 class MemberTupleExpr : public Expression {694 public:695 MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname = nullptr );696 MemberTupleExpr( const MemberTupleExpr & other );697 virtual ~MemberTupleExpr();698 699 Expression * get_member() const { return member; }700 Expression * get_aggregate() const { return aggregate; }701 MemberTupleExpr * set_member( Expression * newValue ) { member = newValue; return this; }702 MemberTupleExpr * set_aggregate( Expression * newValue ) { aggregate = newValue; return this; }703 704 virtual MemberTupleExpr * clone() const { return new MemberTupleExpr( * this ); }705 virtual void accept( Visitor & v ) { v.visit( this ); }706 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }707 virtual void print( std::ostream & os, int indent = 0 ) const;708 private:709 Expression * member;710 Expression * aggregate;711 };712 713 692 /// TupleAssignExpr represents a multiple assignment operation, where both sides of the assignment have tuple type, e.g. [a, b, c] = [d, e, f];, 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;, or a tuple ctor/dtor expression 714 693 class TupleAssignExpr : public Expression { -
src/SynTree/Initializer.cc
rade20d0 r436c0de 33 33 } 34 34 35 void Initializer::print( std::ostream &os,int indent ) {}35 // void Initializer::print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent ) {} 36 36 37 37 SingleInit::SingleInit( Expression *v, const std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) { -
src/SynTree/Initializer.h
rade20d0 r436c0de 53 53 virtual void accept( Visitor &v ) = 0; 54 54 virtual Initializer *acceptMutator( Mutator &m ) = 0; 55 virtual void print( std::ostream &os, int indent = 0 ) ;55 virtual void print( std::ostream &os, int indent = 0 ) = 0; 56 56 private: 57 57 // std::string name; -
src/SynTree/Mutator.cc
rade20d0 r436c0de 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 30 16:45:19201713 // Update Count : 2 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Mar 8 16:36:00 2017 13 // Update Count : 23 14 14 // 15 15 … … 153 153 } 154 154 155 Statement *Mutator::mutate( ThrowStmt *throwStmt ) { 156 throwStmt->set_expr( maybeMutate( throwStmt->get_expr(), *this ) ); 157 throwStmt->set_target( maybeMutate( throwStmt->get_target(), *this ) ); 158 return throwStmt; 159 } 160 155 161 Statement *Mutator::mutate( TryStmt *tryStmt ) { 156 162 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); … … 408 414 } 409 415 410 Expression *Mutator::mutate( MemberTupleExpr *tupleExpr ) {411 tupleExpr->set_env( maybeMutate( tupleExpr->get_env(), *this ) );412 tupleExpr->set_result( maybeMutate( tupleExpr->get_result(), *this ) );413 tupleExpr->set_member( maybeMutate( tupleExpr->get_member(), *this ) );414 tupleExpr->set_aggregate( maybeMutate( tupleExpr->get_aggregate(), *this ) );415 return tupleExpr;416 }417 418 416 Expression *Mutator::mutate( TupleAssignExpr *assignExpr ) { 419 417 assignExpr->set_env( maybeMutate( assignExpr->get_env(), *this ) ); -
src/SynTree/Mutator.h
rade20d0 r436c0de 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Feb 9 14:23:23201713 // Update Count : 1 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 8 15:45:00 2017 13 // Update Count : 14 14 14 // 15 15 #include <cassert> … … 46 46 virtual Statement* mutate( BranchStmt *branchStmt ); 47 47 virtual Statement* mutate( ReturnStmt *returnStmt ); 48 virtual Statement* mutate( TryStmt *returnStmt ); 48 virtual Statement* mutate( ThrowStmt *throwStmt ); 49 virtual Statement* mutate( TryStmt *tryStmt ); 49 50 virtual Statement* mutate( CatchStmt *catchStmt ); 50 51 virtual Statement* mutate( FinallyStmt *catchStmt ); … … 82 83 virtual Expression* mutate( TupleExpr *tupleExpr ); 83 84 virtual Expression* mutate( TupleIndexExpr *tupleExpr ); 84 virtual Expression* mutate( MemberTupleExpr *tupleExpr );85 85 virtual Expression* mutate( TupleAssignExpr *assignExpr ); 86 86 virtual Expression* mutate( StmtExpr * stmtExpr ); -
src/SynTree/Statement.cc
rade20d0 r436c0de 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Aug 12 13:58:48 201613 // Update Count : 6 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jun 12 10:37:00 2017 13 // Update Count : 64 14 14 // 15 15 … … 101 101 } 102 102 103 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr , bool throwP ) : Statement( labels ), expr( _expr ), isThrow( throwP) {}104 105 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) , isThrow( other.isThrow ){}103 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr ) : Statement( labels ), expr( _expr ) {} 104 105 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} 106 106 107 107 ReturnStmt::~ReturnStmt() { … … 110 110 111 111 void ReturnStmt::print( std::ostream &os, int indent ) const { 112 os << string ( isThrow? "Throw":"Return" ) << "Statement, returning: ";112 os << "Return Statement, returning: "; 113 113 if ( expr != 0 ) { 114 114 os << endl << string( indent+2, ' ' ); … … 287 287 } 288 288 289 ThrowStmt::ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target ) : 290 Statement( labels ), kind(kind), expr(expr), target(target) { 291 assertf(Resume == kind || nullptr == target, "Non-local termination throw is not accepted." ); 292 } 293 294 ThrowStmt::ThrowStmt( const ThrowStmt &other ) : 295 Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { 296 } 297 298 ThrowStmt::~ThrowStmt() { 299 delete expr; 300 delete target; 301 } 302 303 void ThrowStmt::print( std::ostream &os, int indent) const { 304 if ( target ) { 305 os << "Non-Local "; 306 } 307 os << "Throw Statement, raising: "; 308 expr->print(os, indent + 4); 309 if ( target ) { 310 os << "At: "; 311 target->print(os, indent + 4); 312 } 313 } 314 289 315 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_handlers, FinallyStmt *_finallyBlock ) : 290 316 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) { … … 318 344 } 319 345 320 CatchStmt::CatchStmt( std::list<Label> labels, Declaration *_decl, Statement *_body, bool catchAny ) :321 Statement( labels ), decl ( _decl ), body( _body ), catchRest ( catchAny ) {346 CatchStmt::CatchStmt( std::list<Label> labels, Kind _kind, Declaration *_decl, Expression *_cond, Statement *_body ) : 347 Statement( labels ), kind ( _kind ), decl ( _decl ), cond ( _cond ), body( _body ) { 322 348 } 323 349 324 350 CatchStmt::CatchStmt( const CatchStmt & other ) : 325 Statement( other ), decl ( maybeClone( other.decl ) ), body( maybeClone( other.body ) ), catchRest ( other.catchRest) {351 Statement( other ), kind ( other.kind ), decl ( maybeClone( other.decl ) ), cond ( maybeClone( other.cond ) ), body( maybeClone( other.body ) ) { 326 352 } 327 353 … … 332 358 333 359 void CatchStmt::print( std::ostream &os, int indent ) const { 334 os << "Catch Statement" << endl;360 os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; 335 361 336 362 os << string( indent, ' ' ) << "... catching" << endl; … … 338 364 decl->printShort( os, indent + 4 ); 339 365 os << endl; 340 } else if ( catchRest ) 341 os << string( indent + 4 , ' ' ) << "the rest" << endl; 366 } 342 367 else 343 368 os << string( indent + 4 , ' ' ) << ">>> Error: this catch clause must have a declaration <<<" << endl; -
src/SynTree/Statement.h
rade20d0 r436c0de 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Aug 12 13:57:46 201613 // Update Count : 6 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jun 12 13:35:00 2017 13 // Update Count : 67 14 14 // 15 15 … … 57 57 private: 58 58 std::list<Statement*> kids; 59 }; 60 61 class NullStmt : public CompoundStmt { 62 public: 63 NullStmt(); 64 NullStmt( std::list<Label> labels ); 65 66 virtual NullStmt *clone() const { return new NullStmt( *this ); } 67 virtual void accept( Visitor &v ) { v.visit( this ); } 68 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 69 virtual void print( std::ostream &os, int indent = 0 ) const; 70 71 private: 59 72 }; 60 73 … … 261 274 class ReturnStmt : public Statement { 262 275 public: 263 ReturnStmt( std::list<Label> labels, Expression *expr , bool throwP = false);276 ReturnStmt( std::list<Label> labels, Expression *expr ); 264 277 ReturnStmt( const ReturnStmt &other ); 265 278 virtual ~ReturnStmt(); … … 274 287 private: 275 288 Expression *expr; 276 bool isThrow; 277 }; 278 279 280 class NullStmt : public CompoundStmt { 281 public: 282 NullStmt(); 283 NullStmt( std::list<Label> labels ); 284 285 virtual NullStmt *clone() const { return new NullStmt( *this ); } 286 virtual void accept( Visitor &v ) { v.visit( this ); } 287 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 288 virtual void print( std::ostream &os, int indent = 0 ) const; 289 290 private: 289 }; 290 291 class ThrowStmt : public Statement { 292 public: 293 enum Kind { Terminate, Resume }; 294 295 ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr ); 296 ThrowStmt( const ThrowStmt &other ); 297 virtual ~ThrowStmt(); 298 299 Kind get_kind() { return kind; } 300 Expression * get_expr() { return expr; } 301 void set_expr( Expression * newExpr ) { expr = newExpr; } 302 Expression * get_target() { return target; } 303 void set_target( Expression * newTarget ) { target = newTarget; } 304 305 virtual ThrowStmt *clone() const { return new ThrowStmt( *this ); } 306 virtual void accept( Visitor &v ) { v.visit( this ); } 307 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 308 virtual void print( std::ostream &os, int indent = 0 ) const; 309 private: 310 Kind kind; 311 Expression * expr; 312 Expression * target; 291 313 }; 292 314 … … 317 339 class CatchStmt : public Statement { 318 340 public: 319 CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool catchAny = false ); 341 enum Kind { Terminate, Resume }; 342 343 CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, 344 Expression *cond, Statement *body ); 320 345 CatchStmt( const CatchStmt &other ); 321 346 virtual ~CatchStmt(); 322 347 348 Kind get_kind() { return kind; } 323 349 Declaration *get_decl() { return decl; } 324 350 void set_decl( Declaration *newValue ) { decl = newValue; } 325 351 Expression *get_cond() { return cond; } 352 void set_cond( Expression *newCond ) { cond = newCond; } 326 353 Statement *get_body() { return body; } 327 354 void set_body( Statement *newValue ) { body = newValue; } … … 333 360 334 361 private: 362 Kind kind; 335 363 Declaration *decl; 364 Expression *cond; 336 365 Statement *body; 337 bool catchRest;338 366 }; 339 367 -
src/SynTree/SynTree.h
rade20d0 r436c0de 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Feb 9 14:23:49201713 // Update Count : 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 8 17:00:00 2017 13 // Update Count : 9 14 14 // 15 15 … … 51 51 class BranchStmt; 52 52 class ReturnStmt; 53 class ThrowStmt; 53 54 class TryStmt; 54 55 class CatchStmt; … … 89 90 class TupleExpr; 90 91 class TupleIndexExpr; 91 class MemberTupleExpr;92 92 class TupleAssignExpr; 93 93 class StmtExpr; -
src/SynTree/TupleExpr.cc
rade20d0 r436c0de 78 78 } 79 79 80 MemberTupleExpr::MemberTupleExpr( Expression * member, Expression * aggregate, Expression * _aname ) : Expression( _aname ) {81 set_result( maybeClone( member->get_result() ) ); // xxx - ???82 }83 84 MemberTupleExpr::MemberTupleExpr( const MemberTupleExpr &other ) : Expression( other ), member( other.member->clone() ), aggregate( other.aggregate->clone() ) {85 }86 87 MemberTupleExpr::~MemberTupleExpr() {88 delete member;89 delete aggregate;90 }91 92 void MemberTupleExpr::print( std::ostream &os, int indent ) const {93 os << "Member Tuple Expression, with aggregate:" << std::endl;94 os << std::string( indent+2, ' ' );95 aggregate->print( os, indent+2 );96 os << std::string( indent+2, ' ' ) << "with member: " << std::endl;97 os << std::string( indent+2, ' ' );98 member->print( os, indent+2 );99 Expression::print( os, indent );100 }101 102 80 TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ) { 103 81 // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments -
src/SynTree/Visitor.cc
rade20d0 r436c0de 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 30 16:45:25201713 // Update Count : 2 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 8 16:31:00 2017 13 // Update Count : 25 14 14 // 15 15 … … 129 129 } 130 130 131 void Visitor::visit( ThrowStmt * throwStmt ) { 132 maybeAccept( throwStmt->get_expr(), *this ); 133 maybeAccept( throwStmt->get_target(), *this ); 134 } 135 131 136 void Visitor::visit( TryStmt *tryStmt ) { 132 137 maybeAccept( tryStmt->get_block(), *this ); … … 319 324 maybeAccept( tupleExpr->get_result(), *this ); 320 325 maybeAccept( tupleExpr->get_tuple(), *this ); 321 }322 323 void Visitor::visit( MemberTupleExpr *tupleExpr ) {324 maybeAccept( tupleExpr->get_result(), *this );325 maybeAccept( tupleExpr->get_member(), *this );326 maybeAccept( tupleExpr->get_aggregate(), *this );327 326 } 328 327 -
src/SynTree/Visitor.h
rade20d0 r436c0de 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 3 08:58:00 201713 // Update Count : 1 012 // Last Modified On : Thr Jun 08 15:45:00 2017 13 // Update Count : 11 14 14 // 15 15 … … 49 49 virtual void visit( BranchStmt *branchStmt ); 50 50 virtual void visit( ReturnStmt *returnStmt ); 51 virtual void visit( ThrowStmt *throwStmt ); 51 52 virtual void visit( TryStmt *tryStmt ); 52 53 virtual void visit( CatchStmt *catchStmt ); … … 85 86 virtual void visit( TupleExpr *tupleExpr ); 86 87 virtual void visit( TupleIndexExpr *tupleExpr ); 87 virtual void visit( MemberTupleExpr *tupleExpr );88 88 virtual void visit( TupleAssignExpr *assignExpr ); 89 89 virtual void visit( StmtExpr * stmtExpr ); -
src/SynTree/ZeroOneType.cc
rade20d0 r436c0de 20 20 ZeroType::ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes ) : Type( tq, attributes ) {} 21 21 22 void ZeroType::print( std::ostream &os, int indent ) const {22 void ZeroType::print( std::ostream &os, __attribute__((unused)) int indent ) const { 23 23 os << "zero_t"; 24 24 } … … 28 28 OneType::OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes ) : Type( tq, attributes ) {} 29 29 30 void OneType::print( std::ostream &os, int indent ) const {30 void OneType::print( std::ostream &os, __attribute__((unused)) int indent ) const { 31 31 os << "one_t"; 32 32 }
Note: See TracChangeset
for help on using the changeset viewer.