Changeset 1e97287
- Timestamp:
- May 15, 2019, 4:04:26 PM (6 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:
- 89c2f7c9
- Parents:
- 23f99e1
- Location:
- src/AST
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.hpp
r23f99e1 r1e97287 9 9 // Author : Thierry Delisle 10 10 // Created On : Wed May 8 10:27:04 2019 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 8 11:00:00 201913 // Update Count : 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 15 16:02:00 2019 13 // Update Count : 3 14 14 // 15 15 … … 137 137 const node_t & operator* () const { return *node; } 138 138 explicit operator bool() const { return node; } 139 operator const node_t * const() const { return node; }139 operator const node_t *() const { return node; } 140 140 141 141 template<typename o_node_t> -
src/AST/Stmt.cpp
r23f99e1 r1e97287 8 8 // 9 9 // Author : Aaron B. Moss 10 // Created On : Wed May 8 13:00:00 201911 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 8 13:00:00 201913 // Update Count : 110 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 15 15:53:00 2019 13 // Update Count : 2 14 14 // 15 15 … … 18 18 #include "DeclReplacer.hpp" 19 19 20 namespace ast { 21 20 22 // --- CompoundStmt 23 CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) { 24 assert(!"implemented"); 25 } 21 26 22 namespace ast { 23 CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) { 24 assert(!"implemented"); 25 } 27 // --- BranchStmt 28 BranchStmt( const CodeLocation& loc, Kind kind, Label target, std::vector<Label>&& labels ) 29 : Stmt(loc, std::move(labels)), originalTarget(target), target(target), kind(kind) { 30 // Make sure a syntax error hasn't slipped through. 31 assert( Goto != kind || !target.empty() ); 32 } 33 34 const char * BranchStmt::kindNames[] = { 35 "Goto", "Break", "Continue", "FallThrough", "FallThroughDefault" 36 } 37 26 38 } 27 39 -
src/AST/Stmt.hpp
r23f99e1 r1e97287 8 8 // 9 9 // Author : Aaron B. Moss 10 // Created On : Wed May 8 13:00:00 201911 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 8 13:00:00 201913 // Update Count : 110 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 15 16:01:00 2019 13 // Update Count : 2 14 14 // 15 15 … … 70 70 : Stmt(loc, std::move(labels)) {} 71 71 72 const NullStmt 73 private: 74 NullStmt 72 const NullStmt* accept( Visitor& v ) const override { return v.visit( this ); } 73 private: 74 NullStmt* clone() const override { return new NullStmt{ *this }; } 75 75 }; 76 76 … … 80 80 ptr<Expr> expr; 81 81 82 ExprStmt( const CodeLocation& loc, Expr* e ) : Stmt(loc), expr(e) {}82 ExprStmt( const CodeLocation& loc, const Expr* e ) : Stmt(loc), expr(e) {} 83 83 84 84 const Stmt * accept( Visitor& v ) const override { return v.visit( this ); } … … 87 87 }; 88 88 89 89 class AsmStmt final : public Stmt { 90 public: 91 bool isVolatile; 92 ptr<Expr> instruction; 93 std::vector<ptr<Expr>> output, input; 94 std::vector<ptr<ConstantExpr>> clobber; 95 std::vector<Label> gotoLabels; 96 97 AsmStmt( const CodeLocation& loc, bool isVolatile, const Expr * instruction, 98 std::vector<ptr<Expr>>&& output, std::vector<ptr<Expr>>&& input, 99 std::vector<ptr<ConstantExpr>>&& clobber, std::vector<Label>&& gotoLabels, 100 std::vector<Label>&& labels = {}) 101 : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction), 102 output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)), 103 gotoLabels(std::move(gotoLabels)) {} 104 105 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 106 private: 107 AsmStmt* clone() const override { return new AsmStmt{ *this }; } 108 }; 109 110 class DirectiveStmt final : public Stmt { 111 public: 112 std::string directive; 113 114 DirectiveStmt( const CodeLocation& loc, const std::string & directive, 115 std::vector<Label>&& labels = {} ) 116 : Stmt(loc, std::move(labels)), directive(directive) {} 117 118 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 119 private: 120 DirectiveStmt* clone() const override { return new DirectiveStmt{ *this }; } 121 }; 122 123 class IfStmt final : public Stmt { 124 public: 125 ptr<Expr> cond; 126 ptr<Stmt> thenPart; 127 ptr<Stmt> elsePart; 128 std::vector<ptr<Stmt>> inits; 129 130 IfStmt( const CodeLocation& loc, const Expr* cond, const Stmt* thenPart, 131 Stmt * const elsePart, std::vector<ptr<Stmt>>&& inits, 132 std::vector<Label>&& labels = {} ) 133 : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart), 134 inits(std::move(inits)) {} 135 136 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 137 private: 138 IfStmt* clone() const override { return new IfStmt{ *this }; } 139 }; 140 141 class SwitchStmt final : public Stmt { 142 public: 143 ptr<Expr> cond; 144 std::vector<ptr<Stmt>> stmts; 145 146 SwitchStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts, 147 std::vector<Label>&& labels = {} ) 148 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 149 150 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 151 private: 152 SwitchStmt* clone() const override { return new SwitchStmt{ *this }; } 153 }; 154 155 class CaseStmt final : public Stmt { 156 public: 157 ptr<Expr> cond; 158 std::vector<ptr<Stmt>> stmts; 159 160 CaseStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts, 161 std::vector<Label>&& labels = {} ) 162 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {} 163 164 bool isDefault() { return !cond; } 165 166 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 167 private: 168 CaseStmt* clone() const override { return new CaseStmt{ *this }; } 169 }; 170 171 class WhileStmt final : public Stmt { 172 public: 173 ptr<Expr> cond; 174 ptr<Stmt> body; 175 std::vector<ptr<Stmt>> inits; 176 bool isDoWhile; 177 178 WhileStmt( const CodeLocation& loc, const Expr* cond, const Stmt* body, 179 std::vector<ptr<Stmt>>&& inits, bool isDoWhile = false, std::vector<Label>&& labels = {} ) 180 : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)), 181 isDoWhile(isDoWhile) {} 182 183 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 184 private: 185 WhileStmt* clone() const override { return new WhileStmt{ *this }; } 186 }; 187 188 class ForStmt final : public Stmt { 189 public: 190 std::vector<ptr<Stmt>> inits; 191 ptr<Expr> cond; 192 ptr<Expr> increment; 193 ptr<Stmt> body; 194 195 ForStmt( const CodeLocation& loc, std::vector<ptr<Stmt>>&& inits, const Expr* cond, 196 const Expr* increment, const Stmt* body, std::vector<Label>&& labels = {} ) 197 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), increment(increment), 198 body(body) {} 199 200 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 201 private: 202 ForStmt* clone() const override { return new ForStmt{ *this }; } 203 }; 204 205 class BranchStmt final : public Stmt { 206 public: 207 enum Kind { Goto, Break, Continue, FallThrough, FallThroughDefault }; 208 static constexpr size_t kindEnd = 1 + (size_t)FallThroughDefault; 209 210 const Label originalTarget; 211 Label target; 212 ptr<Expr> computedTarget; 213 Kind kind; 214 215 BranchStmt( const CodeLocation& loc, Kind kind, Label target, 216 std::vector<Label>&& labels = {} ); 217 BranchStmt( const CodeLocation& loc, const Expr* computedTarget, 218 std::vector<Label>&& labels = {} ) 219 : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc), 220 computedTarget(computedTarget), kind(Goto) {} 221 222 const char * kindName() { return kindNames[kind]; } 223 224 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 225 private: 226 BranchStmt* clone() const override { return new BranchStmt{ *this }; } 227 static const char * kindNames[kindEnd]; 228 }; 229 230 class ReturnStmt final : public Stmt { 231 public: 232 ptr<Expr> expr; 233 234 ReturnStmt( const CodeLocation& loc, const Expr* expr, std::vector<Label>&& labels = {} ) 235 : Stmt(loc, std::move(labels)), expr(expr) {} 236 237 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 238 private: 239 ReturnStmt* clone() const override { return new ReturnStmt{ *this }; } 240 }; 241 242 class ThrowStmt final : public Stmt { 243 public: 244 enum Kind { Terminate, Resume }; 245 246 ptr<Expr> expr; 247 ptr<Expr> target; 248 Kind kind; 249 250 ThrowStmt( const CodeLocation& loc, Kind kind, const Expr* expr, const Expr* target, 251 std::vector<Label>&& labels = {} ) 252 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {} 253 254 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 255 private: 256 ThrowStmt* clone() const override { return new ThrowStmt{ *this }; } 257 }; 258 259 class TryStmt final : public Stmt { 260 public: 261 ptr<CompoundStmt> body; 262 std::vector<ptr<CatchStmt>> handlers; 263 ptr<FinallyStmt> finally; 264 265 TryStmt( const CodeLocation& loc, const CompoundStmt* body, 266 std::vector<ptr<CatchStmt>>&& handlers, const FinallyStmt* finally, 267 std::vector<Label>&& labels = {} ) 268 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {} 269 270 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 271 private: 272 TryStmt* clone() const override { return new TryStmt{ *this }; } 273 }; 274 275 class CatchStmt final : public Stmt { 276 public: 277 enum Kind { Terminate, Resume }; 278 279 ptr<Decl> decl; 280 ptr<Expr> cond; 281 ptr<Stmt> body; 282 Kind kind; 283 284 CatchStmt( const CodeLocation& loc, Kind kind, const Decl* decl, const Expr* cond, 285 const Stmt* body, std::vector<Label>&& labels = {} ) 286 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {} 287 288 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 289 private: 290 CatchStmt* clone() const override { return new CatchStmt{ *this }; } 291 }; 292 293 class FinallyStmt final : public Stmt { 294 public: 295 ptr<CompoundStmt> body; 296 297 FinallyStmt( const CodeLocation& loc, const CompoundStmt* body, 298 std::vector<Label>&& labels = {} ) 299 : Stmt(loc, std::move(labels)), body(body) {} 300 301 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 302 private: 303 FinallyStmt* clone() const override { return new FinallyStmt{ *this }; } 304 }; 305 306 class WaitForStmt final : public Stmt { 307 public: 308 struct Target { 309 ptr<Expr> function; 310 std::vector<ptr<Expr>> arguments; 311 }; 312 313 struct Clause { 314 Target target; 315 ptr<Stmt> stmt; 316 ptr<Expr> cond; 317 }; 318 319 struct Timeout { 320 ptr<Expr> time; 321 ptr<Stmt> stmt; 322 ptr<Expr> cond; 323 }; 324 325 struct OrElse { 326 ptr<Stmt> stmt; 327 ptr<Expr> cond; 328 }; 329 330 std::vector<Clause> clauses; 331 Timeout timeout; 332 OrElse orElse; 333 334 WaitForStmt( const CodeLocation& loc, std::vector<Label>&& labels = {} ) 335 : Stmt(loc, std::move(labels)) {} 336 337 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 338 private: 339 WaitForStmt* clone() const override { return new WaitForStmt{ *this }; } 340 }; 341 342 class WithStmt final : public Stmt { 343 public: 344 std::vector<ptr<Expr>> exprs; 345 ptr<Stmt> stmt; 346 347 WithStmt( const CodeLocation& loc, std::vector<ptr<Expr>>&& exprs, const Stmt* stmt, 348 std::vector<Label>&& labels = {} ) 349 : Stmt(loc, std::move(labels)), exprs(std::move(exprs)), stmt(stmt) {} 350 351 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 352 private: 353 WithStmt* clone() const override { return new WithStmt{ *this }; } 354 }; 355 356 class DeclStmt final : public Stmt { 357 public: 358 ptr<Decl> decl; 359 360 DeclStmt( const CodeLocation& loc, const Decl* decl, std::vector<Label>&& labels = {} ) 361 : Stmt(loc, std::move(labels)), decl(decl) {} 362 363 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 364 private: 365 DeclStmt* clone() const override { return new DeclStmt{ *this }; } 366 }; 367 368 class ImplicitCtorDtorStmt final : public Stmt { 369 public: 370 readonly<Stmt> callStmt; 371 372 ImplicitCtorDtorStmt( const CodeLocation& loc, const Stmt* callStmt, 373 std::vector<Label>&& labels = {} ) 374 : Stmt(loc, std::move(labels)), callStmt(callStmt) {} 375 376 const Stmt* accept( Visitor& v ) const override { return v.visit( this ); } 377 private: 378 ImplicitCtorDtorStmt* clone() const override { return new ImplicitCtorDtorStmt{ *this }; } 379 }; 90 380 91 381 //================================================================================================= -
src/AST/porting.md
r23f99e1 r1e97287 109 109 * `get_statement()` exclusively used for code location, replaced with `CodeLocation` field 110 110 111 `CaseStmt` 112 * `_isDefault` has been removed 113 * `isDefault` calculates value from `cond` 114 * default may not have a condition. I believe case (!default) requires a condition. 115 116 `BranchStmt` 117 * `Type` -> `Kind` and `type` -> `kind` 118 * Constructors no longer throw SemanticErrorException: 119 * `label` constructor claims it is now considered a syntax error, replaced with assert. 120 * `computedTarget` constructor assumes `Goto`, other check would have SegFaulted. 121 122 `TryStmt` 123 * `block` -> `body` and `finallyBlock` -> `finally` 124 125 `FinallyStmt` 126 * `block` -> `body` 127 111 128 `CompoundStmt` 112 129 * **TODO** port copy operator
Note: See TracChangeset
for help on using the changeset viewer.