source: src/Parser/StatementNode.h @ 3d5fba21

ADTast-experimental
Last change on this file since 3d5fba21 was c468150, checked in by Andrew Beach <ajbeach@…>, 19 months ago

Split up ParseNode?.h so that headers match implementation. May have a bit less to include total because of it.

  • Property mode set to 100644
File size: 4.8 KB
Line 
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
20struct 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
56ast::Stmt * build_expr( CodeLocation const &, ExpressionNode * ctl );
57
58struct 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
66struct 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
75ast::Stmt * build_if( const CodeLocation &, CondCtl * ctl, StatementNode * then, StatementNode * else_ );
76ast::Stmt * build_switch( const CodeLocation &, bool isSwitch, ExpressionNode * ctl, StatementNode * stmt );
77ast::CaseClause * build_case( ExpressionNode * ctl );
78ast::CaseClause * build_default( const CodeLocation & );
79ast::Stmt * build_while( const CodeLocation &, CondCtl * ctl, StatementNode * stmt, StatementNode * else_ = nullptr );
80ast::Stmt * build_do_while( const CodeLocation &, ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ = nullptr );
81ast::Stmt * build_for( const CodeLocation &, ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ = nullptr );
82ast::Stmt * build_branch( const CodeLocation &, ast::BranchStmt::Kind kind );
83ast::Stmt * build_branch( const CodeLocation &, std::string * identifier, ast::BranchStmt::Kind kind );
84ast::Stmt * build_computedgoto( ExpressionNode * ctl );
85ast::Stmt * build_return( const CodeLocation &, ExpressionNode * ctl );
86ast::Stmt * build_throw( const CodeLocation &, ExpressionNode * ctl );
87ast::Stmt * build_resume( const CodeLocation &, ExpressionNode * ctl );
88ast::Stmt * build_resume_at( ExpressionNode * ctl , ExpressionNode * target );
89ast::Stmt * build_try( const CodeLocation &, StatementNode * try_, StatementNode * catch_, StatementNode * finally_ );
90ast::CatchClause * build_catch( const CodeLocation &, ast::ExceptionKind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body );
91ast::FinallyClause * build_finally( const CodeLocation &, StatementNode * stmt );
92ast::Stmt * build_compound( const CodeLocation &, StatementNode * first );
93StatementNode * maybe_build_compound( const CodeLocation &, StatementNode * first );
94ast::Stmt * build_asm( const CodeLocation &, bool voltile, ast::Expr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
95ast::Stmt * build_directive( const CodeLocation &, std::string * directive );
96ast::SuspendStmt * build_suspend( const CodeLocation &, StatementNode *, ast::SuspendStmt::Kind );
97ast::WaitForStmt * build_waitfor( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt );
98ast::WaitForStmt * build_waitfor_else( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, StatementNode * stmt );
99ast::WaitForStmt * build_waitfor_timeout( const CodeLocation &, ast::WaitForStmt * existing, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt );
100ast::Stmt * build_with( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt );
101ast::Stmt * build_mutex( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt );
Note: See TracBrowser for help on using the repository browser.