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 | // Stmt.hpp --
|
---|
8 | //
|
---|
9 | // Author : Aaron B. Moss
|
---|
10 | // Created On : Wed May 8 13:00:00 2019
|
---|
11 | // Last Modified By : Aaron B. Moss
|
---|
12 | // Last Modified On : Wed May 8 13:00:00 2019
|
---|
13 | // Update Count : 1
|
---|
14 | //
|
---|
15 |
|
---|
16 | #pragma once
|
---|
17 |
|
---|
18 | #include <list>
|
---|
19 | #include <utility> // for move
|
---|
20 | #include <vector>
|
---|
21 |
|
---|
22 | #include "Label.hpp"
|
---|
23 | #include "Node.hpp" // for node, ptr
|
---|
24 | #include "ParseNode.hpp"
|
---|
25 | #include "Visitor.hpp"
|
---|
26 | #include "Common/CodeLocation.h"
|
---|
27 |
|
---|
28 | namespace ast {
|
---|
29 |
|
---|
30 | class Expr;
|
---|
31 |
|
---|
32 | /// Base statement node
|
---|
33 | class Stmt : public ParseNode {
|
---|
34 | public:
|
---|
35 | std::vector<Label> labels;
|
---|
36 |
|
---|
37 | Stmt( const CodeLocation& loc, std::vector<Label>&& labels = {} )
|
---|
38 | : ParseNode(loc), labels(std::move(labels)) {}
|
---|
39 |
|
---|
40 | Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {}
|
---|
41 |
|
---|
42 | virtual Stmt* accept( Visitor& v ) override = 0;
|
---|
43 | private:
|
---|
44 | virtual Stmt* clone() const override = 0;
|
---|
45 | };
|
---|
46 |
|
---|
47 | /// Compound statement `{ ... }`
|
---|
48 | class CompoundStmt final : public Stmt {
|
---|
49 | public:
|
---|
50 | std::list<ptr<Stmt>> kids;
|
---|
51 |
|
---|
52 | CompoundStmt(const CodeLocation& loc, std::list<ptr<Stmt>>&& ks = {} )
|
---|
53 | : Stmt(loc), kids(std::move(ks)) {}
|
---|
54 |
|
---|
55 | CompoundStmt( const CompoundStmt& o );
|
---|
56 | CompoundStmt( CompoundStmt&& o ) = default;
|
---|
57 |
|
---|
58 | void push_back( Stmt* s ) { kids.emplace_back( s ); }
|
---|
59 | void push_front( Stmt* s ) { kids.emplace_front( s ); }
|
---|
60 |
|
---|
61 | CompoundStmt* accept( Visitor& v ) override { return v.visit( this ); }
|
---|
62 | private:
|
---|
63 | CompoundStmt* clone() const override { return new CompoundStmt{ *this }; }
|
---|
64 | };
|
---|
65 |
|
---|
66 | /// Empty statment `;`
|
---|
67 | class NullStmt final : public Stmt {
|
---|
68 | public:
|
---|
69 | NullStmt( const CodeLocation& loc, std::vector<Label>&& labels = {} )
|
---|
70 | : Stmt(loc, std::move(labels)) {}
|
---|
71 |
|
---|
72 | NullStmt* accept( Visitor& v ) override { return v.visit( this ); }
|
---|
73 | private:
|
---|
74 | NullStmt* clone() const override { return new NullStmt{ *this }; }
|
---|
75 | };
|
---|
76 |
|
---|
77 | /// Expression wrapped by statement
|
---|
78 | class ExprStmt final : public Stmt {
|
---|
79 | public:
|
---|
80 | ptr<Expr> expr;
|
---|
81 |
|
---|
82 | ExprStmt( const CodeLocation& loc, Expr* e ) : Stmt(loc), expr(e) {}
|
---|
83 |
|
---|
84 | Stmt* accept( Visitor& v ) override { return v.visit( this ); }
|
---|
85 | private:
|
---|
86 | ExprStmt* clone() const override { return new ExprStmt{ *this }; }
|
---|
87 | };
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | // Local Variables: //
|
---|
94 | // tab-width: 4 //
|
---|
95 | // mode: c++ //
|
---|
96 | // compile-command: "make install" //
|
---|
97 | // End: //
|
---|