Changeset 204358b for src/AST/Stmt.hpp
- Timestamp:
- May 16, 2019, 2:57:41 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b336af9
- Parents:
- 10248ae0 (diff), f3cc5b6 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Stmt.hpp
r10248ae0 r204358b 26 26 #include "Common/CodeLocation.h" 27 27 28 // Must be included in *all* AST classes; should be #undef'd at the end of the file 29 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node); 30 28 31 namespace ast { 29 32 … … 35 38 std::vector<Label> labels; 36 39 37 Stmt( const CodeLocation & loc, std::vector<Label>&& labels = {} )40 Stmt( const CodeLocation & loc, std::vector<Label> && labels = {} ) 38 41 : ParseNode(loc), labels(std::move(labels)) {} 39 42 40 43 Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {} 41 44 42 const Stmt* accept( Visitor& v ) const override = 0; 43 private: 44 Stmt* clone() const override = 0; 45 const Stmt * accept( Visitor & v ) const override = 0; 46 private: 47 Stmt * clone() const override = 0; 48 MUTATE_FRIEND 45 49 }; 46 50 … … 50 54 std::list<ptr<Stmt>> kids; 51 55 52 CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>>&& ks = {} )56 CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {} ) 53 57 : Stmt(loc), kids(std::move(ks)) {} 54 58 … … 56 60 CompoundStmt( CompoundStmt&& o ) = default; 57 61 58 void push_back( Stmt* s ) { kids.emplace_back( s ); } 59 void push_front( Stmt* s ) { kids.emplace_front( s ); } 60 61 const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); } 62 private: 63 CompoundStmt* clone() const override { return new CompoundStmt{ *this }; } 64 65 /// Must be copied in ALL derived classes 66 template<typename node_t> 67 friend auto mutate(const node_t * node); 62 void push_back( Stmt * s ) { kids.emplace_back( s ); } 63 void push_front( Stmt * s ) { kids.emplace_front( s ); } 64 65 const CompoundStmt * accept( Visitor & v ) const override { return v.visit( this ); } 66 private: 67 CompoundStmt * clone() const override { return new CompoundStmt{ *this }; } 68 MUTATE_FRIEND 68 69 }; 69 70 … … 71 72 class NullStmt final : public Stmt { 72 73 public: 73 NullStmt( const CodeLocation & loc, std::vector<Label>&& labels = {} )74 NullStmt( const CodeLocation & loc, std::vector<Label> && labels = {} ) 74 75 : Stmt(loc, std::move(labels)) {} 75 76 76 const NullStmt* accept( Visitor& v ) const override { return v.visit( this ); } 77 private: 78 NullStmt* clone() const override { return new NullStmt{ *this }; } 79 80 /// Must be copied in ALL derived classes 81 template<typename node_t> 82 friend auto mutate(const node_t * node); 77 const NullStmt * accept( Visitor & v ) const override { return v.visit( this ); } 78 private: 79 NullStmt * clone() const override { return new NullStmt{ *this }; } 80 MUTATE_FRIEND 83 81 }; 84 82 … … 90 88 ExprStmt( const CodeLocation & loc, const Expr * e ) : Stmt(loc), expr(e) {} 91 89 92 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }90 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 93 91 private: 94 92 ExprStmt * clone() const override { return new ExprStmt{ *this }; } 95 96 /// Must be copied in ALL derived classes 97 template<typename node_t> 98 friend auto mutate(const node_t * node); 93 MUTATE_FRIEND 99 94 }; 100 95 … … 107 102 std::vector<Label> gotoLabels; 108 103 109 AsmStmt( const CodeLocation & loc, bool isVolatile, const Expr * instruction,110 std::vector<ptr<Expr>> && output, std::vector<ptr<Expr>>&& input,111 std::vector<ptr<ConstantExpr>> && clobber, std::vector<Label>&& gotoLabels,112 std::vector<Label> && labels = {})104 AsmStmt( const CodeLocation & loc, bool isVolatile, const Expr * instruction, 105 std::vector<ptr<Expr>> && output, std::vector<ptr<Expr>> && input, 106 std::vector<ptr<ConstantExpr>> && clobber, std::vector<Label> && gotoLabels, 107 std::vector<Label> && labels = {}) 113 108 : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction), 114 109 output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)), 115 110 gotoLabels(std::move(gotoLabels)) {} 116 111 117 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 118 private: 119 AsmStmt* clone() const override { return new AsmStmt{ *this }; } 120 121 /// Must be copied in ALL derived classes 122 template<typename node_t> 123 friend auto mutate(const node_t * node); 112 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 113 private: 114 AsmStmt * clone() const override { return new AsmStmt{ *this }; } 115 MUTATE_FRIEND 124 116 }; 125 117 … … 128 120 std::string directive; 129 121 130 DirectiveStmt( const CodeLocation & loc, const std::string & directive,131 std::vector<Label> && labels = {} )122 DirectiveStmt( const CodeLocation & loc, const std::string & directive, 123 std::vector<Label> && labels = {} ) 132 124 : Stmt(loc, std::move(labels)), directive(directive) {} 133 125 134 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 135 private: 136 DirectiveStmt* clone() const override { return new DirectiveStmt{ *this }; } 137 138 /// Must be copied in ALL derived classes 139 template<typename node_t> 140 friend auto mutate(const node_t * node); 126 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 127 private: 128 DirectiveStmt * clone() const override { return new DirectiveStmt{ *this }; } 129 MUTATE_FRIEND 141 130 }; 142 131 … … 148 137 std::vector<ptr<Stmt>> inits; 149 138 150 IfStmt( const CodeLocation & loc, const Expr* cond, const Stmt* thenPart,151 Stmt * const elsePart, std::vector<ptr<Stmt>> && inits,152 std::vector<Label> && labels = {} )139 IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * thenPart, 140 Stmt * const elsePart, std::vector<ptr<Stmt>> && inits, 141 std::vector<Label> && labels = {} ) 153 142 : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart), 154 143 inits(std::move(inits)) {} 155 144 156 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 157 private: 158 IfStmt* clone() const override { return new IfStmt{ *this }; } 159 160 /// Must be copied in ALL derived classes 161 template<typename node_t> 162 friend auto mutate(const node_t * node); 145 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 146 private: 147 IfStmt * clone() const override { return new IfStmt{ *this }; } 148 MUTATE_FRIEND 163 149 }; 164 150 … … 168 154 std::vector<ptr<Stmt>> stmts; 169 155 170 SwitchStmt( const CodeLocation & loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts,171 std::vector<Label> && labels = {} )156 SwitchStmt( const CodeLocation & loc, const Expr * cond, std::vector<ptr<Stmt>> && stmts, 157 std::vector<Label> && labels = {} ) 172 158 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 173 159 174 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 175 private: 176 SwitchStmt* clone() const override { return new SwitchStmt{ *this }; } 177 178 /// Must be copied in ALL derived classes 179 template<typename node_t> 180 friend auto mutate(const node_t * node); 160 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 161 private: 162 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 163 MUTATE_FRIEND 181 164 }; 182 165 … … 186 169 std::vector<ptr<Stmt>> stmts; 187 170 188 CaseStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts,189 std::vector<Label>&& labels = {} )190 171 CaseStmt( const CodeLocation & loc, const Expr * cond, std::vector<ptr<Stmt>> && stmts, 172 std::vector<Label> && labels = {} ) 173 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 191 174 192 175 bool isDefault() { return !cond; } 193 176 194 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 195 private: 196 CaseStmt* clone() const override { return new CaseStmt{ *this }; } 197 198 /// Must be copied in ALL derived classes 199 template<typename node_t> 200 friend auto mutate(const node_t * node); 177 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 178 private: 179 CaseStmt * clone() const override { return new CaseStmt{ *this }; } 180 MUTATE_FRIEND 201 181 }; 202 182 … … 208 188 bool isDoWhile; 209 189 210 WhileStmt( const CodeLocation & loc, const Expr* cond, const Stmt* body,211 std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label>&& labels = {} )190 WhileStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, 191 std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label> && labels = {} ) 212 192 : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)), 213 193 isDoWhile(isDoWhile) {} 214 194 215 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 216 private: 217 WhileStmt* clone() const override { return new WhileStmt{ *this }; } 218 219 /// Must be copied in ALL derived classes 220 template<typename node_t> 221 friend auto mutate(const node_t * node); 195 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 196 private: 197 WhileStmt * clone() const override { return new WhileStmt{ *this }; } 198 MUTATE_FRIEND 222 199 }; 223 200 … … 229 206 ptr<Stmt> body; 230 207 231 ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>>&& inits, const Expr* cond,232 const Expr * inc, const Stmt* body, std::vector<Label>&& labels = {} )208 ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>> && inits, const Expr * cond, 209 const Expr * inc, const Stmt * body, std::vector<Label> && labels = {} ) 233 210 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), 234 211 body(body) {} 235 212 236 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 237 private: 238 ForStmt* clone() const override { return new ForStmt{ *this }; } 239 240 /// Must be copied in ALL derived classes 241 template<typename node_t> 242 friend auto mutate(const node_t * node); 213 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 214 private: 215 ForStmt * clone() const override { return new ForStmt{ *this }; } 216 MUTATE_FRIEND 243 217 }; 244 218 … … 253 227 Kind kind; 254 228 255 BranchStmt( const CodeLocation & loc, Kind kind, Label target,256 std::vector<Label> && labels = {} );257 BranchStmt( const CodeLocation & loc, const Expr* computedTarget,258 std::vector<Label> && labels = {} )229 BranchStmt( const CodeLocation & loc, Kind kind, Label target, 230 std::vector<Label> && labels = {} ); 231 BranchStmt( const CodeLocation & loc, const Expr * computedTarget, 232 std::vector<Label> && labels = {} ) 259 233 : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc), 260 234 computedTarget(computedTarget), kind(Goto) {} … … 262 236 const char * kindName() { return kindNames[kind]; } 263 237 264 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 265 private: 266 BranchStmt* clone() const override { return new BranchStmt{ *this }; } 267 268 /// Must be copied in ALL derived classes 269 template<typename node_t> 270 friend auto mutate(const node_t * node); 238 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 239 private: 240 BranchStmt * clone() const override { return new BranchStmt{ *this }; } 241 MUTATE_FRIEND 271 242 272 243 static const char * kindNames[kindEnd]; … … 277 248 ptr<Expr> expr; 278 249 279 ReturnStmt( const CodeLocation & loc, const Expr* expr, std::vector<Label>&& labels = {} )250 ReturnStmt( const CodeLocation & loc, const Expr * expr, std::vector<Label> && labels = {} ) 280 251 : Stmt(loc, std::move(labels)), expr(expr) {} 281 252 282 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 283 private: 284 ReturnStmt* clone() const override { return new ReturnStmt{ *this }; } 285 286 /// Must be copied in ALL derived classes 287 template<typename node_t> 288 friend auto mutate(const node_t * node); 253 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 254 private: 255 ReturnStmt * clone() const override { return new ReturnStmt{ *this }; } 256 MUTATE_FRIEND 289 257 }; 290 258 … … 297 265 Kind kind; 298 266 299 ThrowStmt( const CodeLocation & loc, Kind kind, const Expr* expr, const Expr* target,300 std::vector<Label> && labels = {} )267 ThrowStmt( const CodeLocation & loc, Kind kind, const Expr * expr, const Expr * target, 268 std::vector<Label> && labels = {} ) 301 269 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {} 302 270 303 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 304 private: 305 ThrowStmt* clone() const override { return new ThrowStmt{ *this }; } 306 307 /// Must be copied in ALL derived classes 308 template<typename node_t> 309 friend auto mutate(const node_t * node); 271 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 272 private: 273 ThrowStmt * clone() const override { return new ThrowStmt{ *this }; } 274 MUTATE_FRIEND 310 275 }; 311 276 … … 316 281 ptr<FinallyStmt> finally; 317 282 318 TryStmt( const CodeLocation & loc, const CompoundStmt* body,319 std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt* finally,320 std::vector<Label> && labels = {} )283 TryStmt( const CodeLocation & loc, const CompoundStmt * body, 284 std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally, 285 std::vector<Label> && labels = {} ) 321 286 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} 322 287 323 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 324 private: 325 TryStmt* clone() const override { return new TryStmt{ *this }; } 326 327 /// Must be copied in ALL derived classes 328 template<typename node_t> 329 friend auto mutate(const node_t * node); 288 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 289 private: 290 TryStmt * clone() const override { return new TryStmt{ *this }; } 291 MUTATE_FRIEND 330 292 }; 331 293 … … 339 301 Kind kind; 340 302 341 CatchStmt( const CodeLocation & loc, Kind kind, const Decl* decl, const Expr* cond,342 const Stmt * body, std::vector<Label>&& labels = {} )303 CatchStmt( const CodeLocation & loc, Kind kind, const Decl * decl, const Expr * cond, 304 const Stmt * body, std::vector<Label> && labels = {} ) 343 305 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {} 344 306 345 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 346 private: 347 CatchStmt* clone() const override { return new CatchStmt{ *this }; } 348 349 /// Must be copied in ALL derived classes 350 template<typename node_t> 351 friend auto mutate(const node_t * node); 307 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 308 private: 309 CatchStmt * clone() const override { return new CatchStmt{ *this }; } 310 MUTATE_FRIEND 352 311 }; 353 312 … … 356 315 ptr<CompoundStmt> body; 357 316 358 FinallyStmt( const CodeLocation & loc, const CompoundStmt* body,359 std::vector<Label> && labels = {} )317 FinallyStmt( const CodeLocation & loc, const CompoundStmt * body, 318 std::vector<Label> && labels = {} ) 360 319 : Stmt(loc, std::move(labels)), body(body) {} 361 320 362 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 363 private: 364 FinallyStmt* clone() const override { return new FinallyStmt{ *this }; } 365 366 /// Must be copied in ALL derived classes 367 template<typename node_t> 368 friend auto mutate(const node_t * node); 321 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 322 private: 323 FinallyStmt * clone() const override { return new FinallyStmt{ *this }; } 324 MUTATE_FRIEND 369 325 }; 370 326 … … 397 353 OrElse orElse; 398 354 399 WaitForStmt( const CodeLocation & loc, std::vector<Label>&& labels = {} )355 WaitForStmt( const CodeLocation & loc, std::vector<Label> && labels = {} ) 400 356 : Stmt(loc, std::move(labels)) {} 401 357 402 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 403 private: 404 WaitForStmt* clone() const override { return new WaitForStmt{ *this }; } 405 406 /// Must be copied in ALL derived classes 407 template<typename node_t> 408 friend auto mutate(const node_t * node); 358 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 359 private: 360 WaitForStmt * clone() const override { return new WaitForStmt{ *this }; } 361 MUTATE_FRIEND 409 362 }; 410 363 … … 414 367 ptr<Stmt> stmt; 415 368 416 WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>>&& exprs, const Stmt* stmt,417 std::vector<Label> && labels = {} )369 WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>> && exprs, const Stmt * stmt, 370 std::vector<Label> && labels = {} ) 418 371 : Stmt(loc, std::move(labels)), exprs(std::move(exprs)), stmt(stmt) {} 419 372 420 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 421 private: 422 WithStmt* clone() const override { return new WithStmt{ *this }; } 423 424 /// Must be copied in ALL derived classes 425 template<typename node_t> 426 friend auto mutate(const node_t * node); 373 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 374 private: 375 WithStmt * clone() const override { return new WithStmt{ *this }; } 376 MUTATE_FRIEND 427 377 }; 428 378 … … 431 381 ptr<Decl> decl; 432 382 433 DeclStmt( const CodeLocation & loc, const Decl* decl, std::vector<Label>&& labels = {} )383 DeclStmt( const CodeLocation & loc, const Decl * decl, std::vector<Label> && labels = {} ) 434 384 : Stmt(loc, std::move(labels)), decl(decl) {} 435 385 436 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 437 private: 438 DeclStmt* clone() const override { return new DeclStmt{ *this }; } 439 440 /// Must be copied in ALL derived classes 441 template<typename node_t> 442 friend auto mutate(const node_t * node); 386 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 387 private: 388 DeclStmt * clone() const override { return new DeclStmt{ *this }; } 389 MUTATE_FRIEND 443 390 }; 444 391 … … 447 394 readonly<Stmt> callStmt; 448 395 449 ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt* callStmt,450 std::vector<Label> && labels = {} )396 ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt * callStmt, 397 std::vector<Label> && labels = {} ) 451 398 : Stmt(loc, std::move(labels)), callStmt(callStmt) {} 452 399 453 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 454 private: 455 ImplicitCtorDtorStmt* clone() const override { return new ImplicitCtorDtorStmt{ *this }; } 456 457 /// Must be copied in ALL derived classes 458 template<typename node_t> 459 friend auto mutate(const node_t * node); 400 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 401 private: 402 ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt{ *this }; } 403 MUTATE_FRIEND 460 404 }; 461 405 … … 510 454 } 511 455 456 #undef MUTATE_FRIEND 457 512 458 // Local Variables: // 513 459 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.