source: src/AST/Stmt.hpp @ 23f99e1

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 23f99e1 was 23f99e1, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Finished implementing declarations

  • Property mode set to 100644
File size: 7.0 KB
RevLine 
[2bb4a01]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
28namespace ast {
29
30class Expr;
31
32/// Base statement node
33class Stmt : public ParseNode {
34public:
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
[23f99e1]42        const Stmt* accept( Visitor& v ) const override = 0;
[2bb4a01]43private:
[23f99e1]44        Stmt* clone() const override = 0;
[2bb4a01]45};
46
47/// Compound statement `{ ... }`
48class CompoundStmt final : public Stmt {
49public:
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
[23f99e1]61        const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); }
[2bb4a01]62private:
[23f99e1]63        CompoundStmt* clone() const override { return new CompoundStmt{ *this }; }
[2bb4a01]64};
65
66/// Empty statment `;`
67class NullStmt final : public Stmt {
68public:
69        NullStmt( const CodeLocation& loc, std::vector<Label>&& labels = {} )
70        : Stmt(loc, std::move(labels)) {}
71
[23f99e1]72        const NullStmt * accept( Visitor& v ) const override { return v.visit( this ); }
[2bb4a01]73private:
[23f99e1]74        NullStmt * clone() const override { return new NullStmt{ *this }; }
[2bb4a01]75};
76
77/// Expression wrapped by statement
78class ExprStmt final : public Stmt {
79public:
80        ptr<Expr> expr;
81
82        ExprStmt( const CodeLocation& loc, Expr* e ) : Stmt(loc), expr(e) {}
83
[23f99e1]84        const Stmt * accept( Visitor& v ) const override { return v.visit( this ); }
[2bb4a01]85private:
[23f99e1]86        ExprStmt * clone() const override { return new ExprStmt{ *this }; }
[2bb4a01]87};
88
89
90
[e0115286]91//=================================================================================================
92/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
93/// remove only if there is a better solution
94/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
95/// forward declarations
96inline void increment( const class Stmt * node, Node::ref_type ref ) { node->increment( ref ); }
97inline void decrement( const class Stmt * node, Node::ref_type ref ) { node->decrement( ref ); }
98inline void increment( const class CompoundStmt * node, Node::ref_type ref ) { node->increment( ref ); }
99inline void decrement( const class CompoundStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
100inline void increment( const class ExprStmt * node, Node::ref_type ref ) { node->increment( ref ); }
101inline void decrement( const class ExprStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
[6d51bd7]102// inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); }
103// inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
104// inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); }
105// inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
106// inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); }
107// inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
108// inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); }
109// inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
110// inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
111// inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
112// inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
113// inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
114// inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); }
115// inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
116// inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
117// inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
118// inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); }
119// inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
120// inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); }
121// inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
122// inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); }
123// inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
124// inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
125// inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
126// inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); }
127// inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
128// inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
129// inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
130// inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); }
131// inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
132// inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); }
133// inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
[e0115286]134inline void increment( const class NullStmt * node, Node::ref_type ref ) { node->increment( ref ); }
135inline void decrement( const class NullStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
[6d51bd7]136// inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); }
137// inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
[e0115286]138
[2bb4a01]139}
140
141// Local Variables: //
142// tab-width: 4 //
143// mode: c++ //
144// compile-command: "make install" //
145// End: //
Note: See TracBrowser for help on using the repository browser.