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