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 : Andrew Beach
|
---|
12 | // Last Modified On : Wed Apr 5 11:57:00 2023
|
---|
13 | // Update Count : 0
|
---|
14 | //
|
---|
15 |
|
---|
16 | #pragma once
|
---|
17 |
|
---|
18 | #include "ParseNode.h"
|
---|
19 |
|
---|
20 | struct StatementNode final : public ParseNode {
|
---|
21 | StatementNode() :
|
---|
22 | stmt( nullptr ), clause( nullptr ) {}
|
---|
23 | StatementNode( ast::Stmt * stmt ) :
|
---|
24 | stmt( stmt ), clause( nullptr ) {}
|
---|
25 | StatementNode( ast::StmtClause * clause ) :
|
---|
26 | stmt( nullptr ), clause( clause ) {}
|
---|
27 | StatementNode( DeclarationNode * decl );
|
---|
28 | virtual ~StatementNode() {}
|
---|
29 |
|
---|
30 | virtual StatementNode * clone() const final { assert( false ); return nullptr; }
|
---|
31 | ast::Stmt * build() const { return const_cast<StatementNode *>(this)->stmt.release(); }
|
---|
32 |
|
---|
33 | StatementNode * add_label(
|
---|
34 | const CodeLocation & location,
|
---|
35 | const std::string * name,
|
---|
36 | DeclarationNode * attr = nullptr );/* {
|
---|
37 | stmt->labels.emplace_back( location,
|
---|
38 | *name,
|
---|
39 | attr ? std::move( attr->attributes )
|
---|
40 | : std::vector<ast::ptr<ast::Attribute>>{} );
|
---|
41 | delete attr;
|
---|
42 | delete name;
|
---|
43 | return this;
|
---|
44 | }*/
|
---|
45 |
|
---|
46 | virtual StatementNode * append_last_case( StatementNode * );
|
---|
47 |
|
---|
48 | virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {
|
---|
49 | os << stmt.get() << std::endl;
|
---|
50 | }
|
---|
51 |
|
---|
52 | std::unique_ptr<ast::Stmt> stmt;
|
---|
53 | std::unique_ptr<ast::StmtClause> clause;
|
---|
54 | }; // StatementNode
|
---|
55 |
|
---|
56 | ast::Stmt * build_expr( CodeLocation const &, ExpressionNode * ctl );
|
---|
57 |
|
---|
58 | struct CondCtl {
|
---|
59 | CondCtl( DeclarationNode * decl, ExpressionNode * condition ) :
|
---|
60 | init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {}
|
---|
61 |
|
---|
62 | StatementNode * init;
|
---|
63 | ExpressionNode * condition;
|
---|
64 | };
|
---|
65 |
|
---|
66 | struct ForCtrl {
|
---|
67 | ForCtrl( StatementNode * stmt, ExpressionNode * condition, ExpressionNode * change ) :
|
---|
68 | init( stmt ), condition( condition ), change( change ) {}
|
---|
69 |
|
---|
70 | StatementNode * init;
|
---|
71 | ExpressionNode * condition;
|
---|
72 | ExpressionNode * change;
|
---|
73 | };
|
---|
74 |
|
---|
75 | ast::Stmt * build_if( const CodeLocation &, CondCtl * ctl, StatementNode * then, StatementNode * else_ );
|
---|
76 | ast::Stmt * build_switch( const CodeLocation &, bool isSwitch, ExpressionNode * ctl, StatementNode * stmt );
|
---|
77 | ast::CaseClause * build_case( ExpressionNode * ctl );
|
---|
78 | ast::CaseClause * build_default( const CodeLocation & );
|
---|
79 | ast::Stmt * build_while( const CodeLocation &, CondCtl * ctl, StatementNode * stmt, StatementNode * else_ = nullptr );
|
---|
80 | ast::Stmt * build_do_while( const CodeLocation &, ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ = nullptr );
|
---|
81 | ast::Stmt * build_for( const CodeLocation &, ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ = nullptr );
|
---|
82 | ast::Stmt * build_branch( const CodeLocation &, ast::BranchStmt::Kind kind );
|
---|
83 | ast::Stmt * build_branch( const CodeLocation &, std::string * identifier, ast::BranchStmt::Kind kind );
|
---|
84 | ast::Stmt * build_computedgoto( ExpressionNode * ctl );
|
---|
85 | ast::Stmt * build_return( const CodeLocation &, ExpressionNode * ctl );
|
---|
86 | ast::Stmt * build_throw( const CodeLocation &, ExpressionNode * ctl );
|
---|
87 | ast::Stmt * build_resume( const CodeLocation &, ExpressionNode * ctl );
|
---|
88 | ast::Stmt * build_resume_at( ExpressionNode * ctl , ExpressionNode * target );
|
---|
89 | ast::Stmt * build_try( const CodeLocation &, StatementNode * try_, StatementNode * catch_, StatementNode * finally_ );
|
---|
90 | ast::CatchClause * build_catch( const CodeLocation &, ast::ExceptionKind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body );
|
---|
91 | ast::FinallyClause * build_finally( const CodeLocation &, StatementNode * stmt );
|
---|
92 | ast::Stmt * build_compound( const CodeLocation &, StatementNode * first );
|
---|
93 | StatementNode * maybe_build_compound( const CodeLocation &, StatementNode * first );
|
---|
94 | ast::Stmt * build_asm( const CodeLocation &, bool voltile, ast::Expr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
|
---|
95 | ast::Stmt * build_directive( const CodeLocation &, std::string * directive );
|
---|
96 | ast::SuspendStmt * build_suspend( const CodeLocation &, StatementNode *, ast::SuspendStmt::Kind );
|
---|
97 | ast::WaitForStmt * build_waitfor( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt );
|
---|
98 | ast::WaitForStmt * build_waitfor_else( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt );
|
---|
99 | ast::WaitForStmt * build_waitfor_timeout( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt );
|
---|
100 | ast::Stmt * build_with( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt );
|
---|
101 | ast::Stmt * build_mutex( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt );
|
---|