| 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.h --
 | 
|---|
| 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 : Fri Aug 11 11:44:07 2023
 | 
|---|
| 13 | // Update Count     : 2
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #pragma once
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include "ParseNode.h"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | struct StatementNode final : public ParseNode {
 | 
|---|
| 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 ParseNode {
 | 
|---|
| 42 |         ClauseNode( ast::StmtClause * clause ) : clause( clause ) {}
 | 
|---|
| 43 |         virtual ~ClauseNode() {}
 | 
|---|
| 44 | 
 | 
|---|
| 45 |         ClauseNode * set_last( ParseNode * newlast ) {
 | 
|---|
| 46 |                 ParseNode::set_last( newlast );
 | 
|---|
| 47 |         return this;
 | 
|---|
| 48 |     }
 | 
|---|
| 49 | 
 | 
|---|
| 50 |         virtual ClauseNode * clone() const final { assert( false ); return nullptr; }
 | 
|---|
| 51 |         ast::StmtClause * build() { return clause.release(); }
 | 
|---|
| 52 | 
 | 
|---|
| 53 |         virtual ClauseNode * append_last_case( StatementNode * );
 | 
|---|
| 54 | 
 | 
|---|
| 55 |         std::unique_ptr<ast::StmtClause> clause;
 | 
|---|
| 56 | };
 | 
|---|
| 57 | 
 | 
|---|
| 58 | ast::Stmt * build_expr( CodeLocation const &, ExpressionNode * ctl );
 | 
|---|
| 59 | 
 | 
|---|
| 60 | struct CondCtl {
 | 
|---|
| 61 |         CondCtl( DeclarationNode * decl, ExpressionNode * condition ) :
 | 
|---|
| 62 |                 init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {}
 | 
|---|
| 63 | 
 | 
|---|
| 64 |         StatementNode * init;
 | 
|---|
| 65 |         ExpressionNode * condition;
 | 
|---|
| 66 | };
 | 
|---|
| 67 | 
 | 
|---|
| 68 | struct ForCtrl {
 | 
|---|
| 69 |         ForCtrl( StatementNode * stmt, ExpressionNode * condition, ExpressionNode * change ) :
 | 
|---|
| 70 |                 init( stmt ), condition( condition ), change( change ) {}
 | 
|---|
| 71 | 
 | 
|---|
| 72 |         StatementNode * init;
 | 
|---|
| 73 |         ExpressionNode * condition;
 | 
|---|
| 74 |         ExpressionNode * change;
 | 
|---|
| 75 | };
 | 
|---|
| 76 | 
 | 
|---|
| 77 | ast::Stmt * build_if( const CodeLocation &, CondCtl * ctl, StatementNode * then, StatementNode * else_ );
 | 
|---|
| 78 | ast::Stmt * build_switch( const CodeLocation &, bool isSwitch, ExpressionNode * ctl, ClauseNode * stmt );
 | 
|---|
| 79 | ast::CaseClause * build_case( const CodeLocation &, ExpressionNode * ctl );
 | 
|---|
| 80 | ast::CaseClause * build_default( const CodeLocation & );
 | 
|---|
| 81 | ast::Stmt * build_while( const CodeLocation &, CondCtl * ctl, StatementNode * stmt, StatementNode * else_ = nullptr );
 | 
|---|
| 82 | ast::Stmt * build_do_while( const CodeLocation &, ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ = nullptr );
 | 
|---|
| 83 | ast::Stmt * build_for( const CodeLocation &, ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ = nullptr );
 | 
|---|
| 84 | ast::Stmt * build_branch( const CodeLocation &, ast::BranchStmt::Kind kind );
 | 
|---|
| 85 | ast::Stmt * build_branch( const CodeLocation &, std::string * identifier, ast::BranchStmt::Kind kind );
 | 
|---|
| 86 | ast::Stmt * build_computedgoto( ExpressionNode * ctl );
 | 
|---|
| 87 | ast::Stmt * build_return( const CodeLocation &, ExpressionNode * ctl );
 | 
|---|
| 88 | ast::Stmt * build_throw( const CodeLocation &, ExpressionNode * ctl );
 | 
|---|
| 89 | ast::Stmt * build_resume( const CodeLocation &, ExpressionNode * ctl );
 | 
|---|
| 90 | ast::Stmt * build_resume_at( ExpressionNode * ctl , ExpressionNode * target );
 | 
|---|
| 91 | ast::Stmt * build_try( const CodeLocation &, StatementNode * try_, ClauseNode * catch_, ClauseNode * finally_ );
 | 
|---|
| 92 | ast::CatchClause * build_catch( const CodeLocation &, ast::ExceptionKind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body );
 | 
|---|
| 93 | ast::FinallyClause * build_finally( const CodeLocation &, StatementNode * stmt );
 | 
|---|
| 94 | ast::Stmt * build_compound( const CodeLocation &, StatementNode * first );
 | 
|---|
| 95 | StatementNode * maybe_build_compound( const CodeLocation &, StatementNode * first );
 | 
|---|
| 96 | ast::Stmt * build_asm( const CodeLocation &, bool is_volatile, ExpressionNode * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
 | 
|---|
| 97 | ast::Stmt * build_directive( const CodeLocation &, std::string * directive );
 | 
|---|
| 98 | ast::SuspendStmt * build_suspend( const CodeLocation &, StatementNode *, ast::SuspendStmt::Kind );
 | 
|---|
| 99 | ast::WaitForStmt * build_waitfor( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt );
 | 
|---|
| 100 | ast::WaitForStmt * build_waitfor_else( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt );
 | 
|---|
| 101 | ast::WaitForStmt * build_waitfor_timeout( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt );
 | 
|---|
| 102 | ast::WaitUntilStmt::ClauseNode * build_waituntil_clause( const CodeLocation &, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt );
 | 
|---|
| 103 | ast::WaitUntilStmt::ClauseNode * build_waituntil_else( const CodeLocation &, ExpressionNode * when, StatementNode * stmt );
 | 
|---|
| 104 | ast::WaitUntilStmt * build_waituntil_stmt( const CodeLocation &, ast::WaitUntilStmt::ClauseNode * root );
 | 
|---|
| 105 | ast::Stmt * build_with( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt );
 | 
|---|
| 106 | ast::Stmt * build_mutex( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt );
 | 
|---|
| 107 | ast::Stmt * build_corun( const CodeLocation &, StatementNode * stmt );
 | 
|---|
| 108 | ast::Stmt * build_cofor( const CodeLocation & location, ForCtrl * forctl, StatementNode * stmt );
 | 
|---|