Changeset 2e9b59b for src/AST/Stmt.hpp
- Timestamp:
- Apr 19, 2022, 3:00:04 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 5b84a321
- Parents:
- ba897d21 (diff), bb7c77d (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
rba897d21 r2e9b59b 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 2 20:06:41202213 // Update Count : 3 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Mar 28 9:50:00 2022 13 // Update Count : 35 14 14 // 15 15 … … 47 47 private: 48 48 Stmt * clone() const override = 0; 49 MUTATE_FRIEND 50 }; 51 52 // Base statement component node (only serves to group them). 53 class StmtClause : public ParseNode { 54 public: 55 // This is for non-statements that still belong with the statements, 56 // but are not statements, usually some sort of clause. Often these can 57 // (and should) be folded into the approprate parent node, but if they 58 // cannot be, they are sub-types of this type, for organization. 59 60 StmtClause( const CodeLocation & loc ) 61 : ParseNode(loc) {} 62 63 private: 64 StmtClause * clone() const override = 0; 49 65 MUTATE_FRIEND 50 66 }; … … 158 174 public: 159 175 ptr<Expr> cond; 176 std::vector<ptr<CaseClause>> cases; 177 178 SwitchStmt( const CodeLocation & loc, const Expr * cond, 179 const std::vector<ptr<CaseClause>> && cases, 180 const std::vector<Label> && labels = {} ) 181 : Stmt(loc, std::move(labels)), cond(cond), cases(std::move(cases)) {} 182 183 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 184 private: 185 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 186 MUTATE_FRIEND 187 }; 188 189 // Case label: case ...: or default: 190 class CaseClause final : public StmtClause { 191 public: 192 // Null for the default label. 193 ptr<Expr> cond; 160 194 std::vector<ptr<Stmt>> stmts; 161 195 162 SwitchStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts, 163 const std::vector<Label> && labels = {} ) 164 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 165 166 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 167 private: 168 SwitchStmt * clone() const override { return new SwitchStmt{ *this }; } 169 MUTATE_FRIEND 170 }; 171 172 // Case label: case ...: or default: 173 class CaseStmt final : public Stmt { 174 public: 175 // Null for the default label. 176 ptr<Expr> cond; 177 std::vector<ptr<Stmt>> stmts; 178 179 CaseStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts, 180 const std::vector<Label> && labels = {} ) 181 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 196 CaseClause( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts ) 197 : StmtClause(loc), cond(cond), stmts(std::move(stmts)) {} 182 198 183 199 bool isDefault() const { return !cond; } 184 200 185 const Stmt* accept( Visitor & v ) const override { return v.visit( this ); }186 private: 187 Case Stmt * clone() const override { return new CaseStmt{ *this }; }201 const CaseClause * accept( Visitor & v ) const override { return v.visit( this ); } 202 private: 203 CaseClause * clone() const override { return new CaseClause{ *this }; } 188 204 MUTATE_FRIEND 189 205 }; … … 298 314 public: 299 315 ptr<CompoundStmt> body; 300 std::vector<ptr<Catch Stmt>> handlers;301 ptr<Finally Stmt> finally;316 std::vector<ptr<CatchClause>> handlers; 317 ptr<FinallyClause> finally; 302 318 303 319 TryStmt( const CodeLocation & loc, const CompoundStmt * body, 304 const std::vector<ptr<Catch Stmt>> && handlers, const FinallyStmt* finally,320 const std::vector<ptr<CatchClause>> && handlers, const FinallyClause * finally, 305 321 const std::vector<Label> && labels = {} ) 306 322 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} … … 313 329 314 330 // Catch clause of try statement 315 class Catch Stmt final : public Stmt{331 class CatchClause final : public StmtClause { 316 332 public: 317 333 ptr<Decl> decl; … … 320 336 ExceptionKind kind; 321 337 322 Catch Stmt( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,323 const Stmt * body , const std::vector<Label> && labels = {})324 : Stmt (loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {}325 326 const Stmt* accept( Visitor & v ) const override { return v.visit( this ); }327 private: 328 Catch Stmt * clone() const override { return new CatchStmt{ *this }; }338 CatchClause( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond, 339 const Stmt * body ) 340 : StmtClause(loc), decl(decl), cond(cond), body(body), kind(kind) {} 341 342 const CatchClause * accept( Visitor & v ) const override { return v.visit( this ); } 343 private: 344 CatchClause * clone() const override { return new CatchClause{ *this }; } 329 345 MUTATE_FRIEND 330 346 }; 331 347 332 348 // Finally clause of try statement 333 class Finally Stmt final : public Stmt{349 class FinallyClause final : public StmtClause { 334 350 public: 335 351 ptr<CompoundStmt> body; 336 352 337 FinallyStmt( const CodeLocation & loc, const CompoundStmt * body, 338 std::vector<Label> && labels = {} ) 339 : Stmt(loc, std::move(labels)), body(body) {} 340 341 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 342 private: 343 FinallyStmt * clone() const override { return new FinallyStmt{ *this }; } 353 FinallyClause( const CodeLocation & loc, const CompoundStmt * body ) 354 : StmtClause(loc), body(body) {} 355 356 const FinallyClause * accept( Visitor & v ) const override { return v.visit( this ); } 357 private: 358 FinallyClause * clone() const override { return new FinallyClause{ *this }; } 344 359 MUTATE_FRIEND 345 360 };
Note:
See TracChangeset
for help on using the changeset viewer.