aboutsummaryrefslogtreecommitdiffstats
path: root/c_parser/include/ast_statement.hpp
blob: 4761efbbd76edbe5326ed71919e00021b2ae2fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef AST_STATEMENT_HPP
#define AST_STATEMENT_HPP

#include "ast.hpp"

class Statement : public Base {
protected:
    mutable std::vector<const Base*> list;
    
public:
    Statement() {}
    
    Statement(const Base* _el) {
        list.push_back(_el);
    }

    Statement(const Base* _dec, const Base* _statement) {
        list.push_back(_dec);
        list.push_back(_statement);
    }
    virtual void print() const {
	for(size_t i = 0; i < list.size(); ++i) {
	    list[i]->print();
	}
    }

    virtual void push(const Base* _var) const {
        list.push_back(_var);
    }
};

class StatementList : public Statement {  
public:
    StatementList(const Base* _statement) : Statement(_statement) {}
};

class CompoundStatement : public Statement {
public:
    CompoundStatement() : Statement() {}
    CompoundStatement(const Base* _el) : Statement(_el) {}
    CompoundStatement(const Base* _dec, const Base* _statement) :
        Statement(_dec, _statement) {}

    virtual void print() const override {
	std::cout << "<Scope>" << std::endl;
	for(size_t i = 0; i < list.size(); ++i) {
	    list[i]->print();
	}
	std::cout << "</Scope>" << std::endl;
    }
};

class SelectionStatement : public Statement {
public:
    SelectionStatement() : Statement() {}
    SelectionStatement(const Base* _el) : Statement(_el) {}
    SelectionStatement(const Base* _if, const Base* _else) :
        Statement(_if, _else) {}
};

class ExpressionStatement : public Statement {
public:
    ExpressionStatement() : Statement() {}
    ExpressionStatement(const Base* _el) : Statement(_el) {}
};

class JumpStatement : public Statement {
public:
    JumpStatement() : Statement() {}
    JumpStatement(const Base* _el) : Statement(_el) {}
};

class IterationStatement : public Statement {
public:
    IterationStatement() : Statement() {}
    IterationStatement(const Base* _el) : Statement(_el) {}
    IterationStatement(const Base* _if, const Base* _else) :
        Statement(_if, _else) {}
};

#endif