1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // StatementNode.hpp -- |
---|
8 | // |
---|
9 | // Author : Andrew Beach |
---|
10 | // Created On : Wed Apr 5 11:42:00 2023 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Mon Sep 23 22:43:05 2024 |
---|
13 | // Update Count : 3 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include "ParseNode.hpp" |
---|
19 | |
---|
20 | struct StatementNode final : public ParseList<StatementNode> { |
---|
21 | StatementNode() : stmt( nullptr ) {} |
---|
22 | StatementNode( ast::Stmt * stmt ) : stmt( stmt ) {} |
---|
23 | StatementNode( DeclarationNode * decl ); |
---|
24 | virtual ~StatementNode() {} |
---|
25 | |
---|
26 | virtual StatementNode * clone() const final { assert( false ); return nullptr; } |
---|
27 | ast::Stmt * build() { return stmt.release(); } |
---|
28 | |
---|
29 | StatementNode * add_label( |
---|
30 | const CodeLocation & location, |
---|
31 | const std::string * name, |
---|
32 | DeclarationNode * attr = nullptr ); |
---|
33 | |
---|
34 | virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override { |
---|
35 | os << stmt.get() << std::endl; |
---|
36 | } |
---|
37 | |
---|
38 | std::unique_ptr<ast::Stmt> stmt; |
---|
39 | }; // StatementNode |
---|
40 | |
---|
41 | struct ClauseNode final : public ParseList<ClauseNode> { |
---|
42 | ClauseNode( ast::StmtClause * clause ) : clause( clause ) {} |
---|
43 | virtual ~ClauseNode() {} |
---|
44 | |
---|
45 | virtual ClauseNode * clone() const final { assert( false ); return nullptr; } |
---|
46 | ast::StmtClause * build() { return clause.release(); } |
---|
47 | |
---|
48 | virtual ClauseNode * append_last_case( StatementNode * ); |
---|
49 | |
---|
50 | std::unique_ptr<ast::StmtClause> clause; |
---|
51 | }; |
---|
52 | |
---|
53 | ast::Stmt * build_expr( CodeLocation const &, ExpressionNode * ctrl ); |
---|
54 | |
---|
55 | struct CondCtrl { |
---|
56 | CondCtrl( DeclarationNode * decl, ExpressionNode * condition ) : |
---|
57 | init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {} |
---|
58 | |
---|
59 | StatementNode * init; |
---|
60 | ExpressionNode * condition; |
---|
61 | }; |
---|
62 | |
---|
63 | struct ForCtrl { |
---|
64 | ForCtrl( StatementNode * stmt, ExpressionNode * condition, ExpressionNode * change ) : |
---|
65 | init( stmt ), condition( condition ), change( change ), range_over( nullptr ) {} |
---|
66 | ForCtrl( StatementNode * decl, ExpressionNode * range_over, OperKinds kind ) : |
---|
67 | init( decl ), condition( nullptr ), change( nullptr ), range_over( range_over ), kind( kind ) {} |
---|
68 | |
---|
69 | StatementNode * init; |
---|
70 | ExpressionNode * condition; |
---|
71 | ExpressionNode * change; |
---|
72 | ExpressionNode * range_over; |
---|
73 | OperKinds kind; |
---|
74 | }; |
---|
75 | |
---|
76 | ast::Stmt * build_if( const CodeLocation &, CondCtrl * ctrl, StatementNode * then, StatementNode * else_ ); |
---|
77 | ast::Stmt * build_switch( const CodeLocation &, bool isSwitch, ExpressionNode * ctrl, ClauseNode * stmt ); |
---|
78 | ast::CaseClause * build_case( const CodeLocation &, ExpressionNode * ctrl ); |
---|
79 | ast::CaseClause * build_default( const CodeLocation & ); |
---|
80 | ast::Stmt * build_while( const CodeLocation &, CondCtrl * ctrl, StatementNode * stmt, StatementNode * else_ = nullptr ); |
---|
81 | ast::Stmt * build_do_while( const CodeLocation &, ExpressionNode * ctrl, StatementNode * stmt, StatementNode * else_ = nullptr ); |
---|
82 | ast::Stmt * build_for( const CodeLocation &, ForCtrl * forctrl, StatementNode * stmt, StatementNode * else_ = nullptr ); |
---|
83 | ast::Stmt * build_branch( const CodeLocation &, ast::BranchStmt::Kind kind ); |
---|
84 | ast::Stmt * build_branch( const CodeLocation &, std::string * identifier, ast::BranchStmt::Kind kind ); |
---|
85 | ast::Stmt * build_computedgoto( ExpressionNode * ctrl ); |
---|
86 | ast::Stmt * build_return( const CodeLocation &, ExpressionNode * ctrl ); |
---|
87 | ast::Stmt * build_throw( const CodeLocation &, ExpressionNode * ctrl ); |
---|
88 | ast::Stmt * build_resume( const CodeLocation &, ExpressionNode * ctrl ); |
---|
89 | ast::Stmt * build_resume_at( ExpressionNode * ctrl , ExpressionNode * target ); |
---|
90 | ast::Stmt * build_try( const CodeLocation &, StatementNode * try_, ClauseNode * catch_, ClauseNode * finally_ ); |
---|
91 | ast::CatchClause * build_catch( const CodeLocation &, ast::ExceptionKind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ); |
---|
92 | ast::FinallyClause * build_finally( const CodeLocation &, StatementNode * stmt ); |
---|
93 | ast::Stmt * build_compound( const CodeLocation &, StatementNode * first ); |
---|
94 | StatementNode * maybe_build_compound( const CodeLocation &, StatementNode * first ); |
---|
95 | ast::Stmt * build_asm( const CodeLocation &, bool is_volatile, ExpressionNode * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); |
---|
96 | ast::Stmt * build_directive( const CodeLocation &, std::string * directive ); |
---|
97 | ast::SuspendStmt * build_suspend( const CodeLocation &, StatementNode *, ast::SuspendStmt::Kind ); |
---|
98 | ast::WaitForStmt * build_waitfor( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ); |
---|
99 | ast::WaitForStmt * build_waitfor_else( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt ); |
---|
100 | ast::WaitForStmt * build_waitfor_timeout( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt ); |
---|
101 | ast::WaitUntilStmt::ClauseNode * build_waituntil_clause( const CodeLocation &, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt ); |
---|
102 | ast::WaitUntilStmt::ClauseNode * build_waituntil_else( const CodeLocation &, ExpressionNode * when, StatementNode * stmt ); |
---|
103 | ast::WaitUntilStmt * build_waituntil_stmt( const CodeLocation &, ast::WaitUntilStmt::ClauseNode * root ); |
---|
104 | ast::Stmt * build_with( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt ); |
---|
105 | ast::Stmt * build_mutex( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt ); |
---|
106 | ast::Stmt * build_corun( const CodeLocation &, StatementNode * stmt ); |
---|
107 | ast::Stmt * build_cofor( const CodeLocation & location, ForCtrl * forctrl, StatementNode * stmt ); |
---|