Changeset a1da039
- Timestamp:
- Oct 24, 2023, 3:00:53 PM (14 months ago)
- Branches:
- master
- Children:
- dd7c2ce0
- Parents:
- d8a0e51
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.hpp
rd8a0e51 ra1da039 125 125 126 126 /// Object declaration `int foo()` 127 class FunctionDecl : public DeclWithType {127 class FunctionDecl final : public DeclWithType { 128 128 public: 129 129 std::vector<ptr<TypeDecl>> type_params; … … 314 314 class EnumDecl final : public AggregateDecl { 315 315 public: 316 bool isTyped;// isTyped indicated if the enum has a declaration like:316 // isTyped indicated if the enum has a declaration like: 317 317 // enum (type_optional) Name {...} 318 ptr<Type> base; // if isTyped == true && base.get() == nullptr, it is a "void" type enum 318 bool isTyped; 319 // if isTyped == true && base.get() == nullptr, it is a "void" type enum 320 ptr<Type> base; 319 321 enum class EnumHiding { Visible, Hide } hide; 320 322 … … 374 376 375 377 /// Assembly declaration: `asm ... ( "..." : ... )` 376 class AsmDecl : public Decl {378 class AsmDecl final : public Decl { 377 379 public: 378 380 ptr<AsmStmt> stmt; 379 381 380 382 AsmDecl( const CodeLocation & loc, AsmStmt * stmt ) 381 : Decl( loc, "", {}, {}), stmt(stmt) {}383 : Decl( loc, "", {}, Linkage::C ), stmt(stmt) {} 382 384 383 385 const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); } … … 388 390 389 391 /// C-preprocessor directive `#...` 390 class DirectiveDecl : public Decl {392 class DirectiveDecl final : public Decl { 391 393 public: 392 394 ptr<DirectiveStmt> stmt; 393 395 394 396 DirectiveDecl( const CodeLocation & loc, DirectiveStmt * stmt ) 395 : Decl( loc, "", {}, {}), stmt(stmt) {}397 : Decl( loc, "", {}, Linkage::C ), stmt(stmt) {} 396 398 397 399 const DirectiveDecl * accept( Visitor & v ) const override { return v.visit( this ); } … … 402 404 403 405 /// Static Assertion `_Static_assert( ... , ... );` 404 class StaticAssertDecl : public Decl {406 class StaticAssertDecl final : public Decl { 405 407 public: 406 408 ptr<Expr> cond; … … 408 410 409 411 StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg ) 410 : Decl( loc, "", {}, {}), cond( condition ), msg( msg ) {}412 : Decl( loc, "", {}, Linkage::C ), cond( condition ), msg( msg ) {} 411 413 412 414 const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Stmt.hpp
rd8a0e51 ra1da039 28 28 // Must be included in *all* AST classes; should be #undef'd at the end of the file 29 29 #define MUTATE_FRIEND \ 30 30 template<typename node_t> friend node_t * mutate(const node_t * node); \ 31 31 template<typename node_t> friend node_t * shallowCopy(const node_t * node); 32 32 … … 340 340 341 341 CatchClause( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond, 342 342 const Stmt * body ) 343 343 : StmtClause(loc), decl(decl), cond(cond), body(body), kind(kind) {} 344 344 … … 380 380 // Base class of WaitFor/WaitUntil statements 381 381 // form: KEYWORD(...) ... timeout(...) ... else ... 382 class WaitStmt : public Stmt { 383 public: 384 382 class WaitStmt : public Stmt { 383 public: 384 ptr<Expr> timeout_time; 385 385 ptr<Stmt> timeout_stmt; 386 386 ptr<Expr> timeout_cond; … … 388 388 ptr<Expr> else_cond; 389 389 390 390 WaitStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 391 391 : Stmt(loc, std::move(labels)) {} 392 392 393 393 private: 394 394 WaitStmt * clone() const override = 0; 395 395 MUTATE_FRIEND 396 396 }; … … 444 444 class WaitUntilStmt final : public WaitStmt { 445 445 public: 446 447 448 449 struct ClauseNode { 450 451 452 453 454 455 456 457 458 459 460 461 462 : op(op), left(left), right(right), leaf(nullptr), 463 464 465 466 467 468 469 470 471 472 473 446 // Non-ast node used during compilation to store data needed to generate predicates 447 // and set initial status values for clauses 448 // Used to create a tree corresponding to the structure of the clauses in a WaitUntil 449 struct ClauseNode { 450 enum Op { AND, OR, LEFT_OR, LEAF, ELSE, TIMEOUT } op; // operation/type tag 451 // LEFT_OR used with TIMEOUT/ELSE to indicate that we ignore right hand side after parsing 452 453 ClauseNode * left; 454 ClauseNode * right; 455 WhenClause * leaf; // only set if this node is a leaf (points into vector of clauses) 456 457 bool ambiguousWhen; // used to paint nodes of predicate tree based on when() clauses 458 bool whenState; // used to track if when_cond is toggled on or off for generating init values 459 bool childOfAnd; // true on leaf nodes that are children of AND, false otherwise 460 461 ClauseNode( Op op, ClauseNode * left, ClauseNode * right ) 462 : op(op), left(left), right(right), leaf(nullptr), 463 ambiguousWhen(false), whenState(true), childOfAnd(false) {} 464 ClauseNode( Op op, WhenClause * leaf ) 465 : op(op), left(nullptr), right(nullptr), leaf(leaf), 466 ambiguousWhen(false), whenState(true), childOfAnd(false) {} 467 ClauseNode( WhenClause * leaf ) : ClauseNode(LEAF, leaf) {} 468 469 ~ClauseNode() { 470 if ( left ) delete left; 471 if ( right ) delete right; 472 } 473 }; 474 474 475 475 std::vector<ptr<WhenClause>> clauses; 476 476 ClauseNode * predicateTree; 477 477 478 478 WaitUntilStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 479 479 : WaitStmt(loc, std::move(labels)) {} 480 480 481 481 ~WaitUntilStmt() { delete predicateTree; } 482 482 483 483 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } … … 522 522 std::vector<ptr<Expr>> mutexObjs; 523 523 524 MutexStmt( const CodeLocation & loc, const Stmt * stmt, 524 MutexStmt( const CodeLocation & loc, const Stmt * stmt, 525 525 const std::vector<ptr<Expr>> && mutexes, const std::vector<Label> && labels = {} ) 526 526 : Stmt(loc, std::move(labels)), stmt(stmt), mutexObjs(std::move(mutexes)) {}
Note: See TracChangeset
for help on using the changeset viewer.