aboutsummaryrefslogtreecommitdiffstats
path: root/c_compiler/include/statement.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'c_compiler/include/statement.hpp')
-rw-r--r--c_compiler/include/statement.hpp55
1 files changed, 20 insertions, 35 deletions
diff --git a/c_compiler/include/statement.hpp b/c_compiler/include/statement.hpp
index 4761efb..451d368 100644
--- a/c_compiler/include/statement.hpp
+++ b/c_compiler/include/statement.hpp
@@ -3,49 +3,33 @@
#include "ast.hpp"
-class Statement : public Base {
-protected:
- mutable std::vector<const Base*> list;
-
+
+class Statement : public BaseNode {
public:
- Statement() {}
+ Statement() : BaseNode() {}
- 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);
- }
+ Statement(const Base* _el) : BaseNode(_el) {}
};
-class StatementList : public Statement {
+class StatementList : public BaseList {
public:
- StatementList(const Base* _statement) : Statement(_statement) {}
+ StatementList(const Base* _statement) : BaseList(_statement) {}
};
class CompoundStatement : public Statement {
public:
CompoundStatement() : Statement() {}
CompoundStatement(const Base* _el) : Statement(_el) {}
- CompoundStatement(const Base* _dec, const Base* _statement) :
- Statement(_dec, _statement) {}
+
+ CompoundStatement(const Base* _dec, const Base* _statement) {
+ leftNode = _dec;
+ rightNode = _statement;
+ }
- virtual void print() const override {
+ virtual void printxml() const override {
std::cout << "<Scope>" << std::endl;
- for(size_t i = 0; i < list.size(); ++i) {
- list[i]->print();
- }
+ leftNode->printxml();
+ rightNode->printxml();
std::cout << "</Scope>" << std::endl;
}
};
@@ -54,14 +38,17 @@ class SelectionStatement : public Statement {
public:
SelectionStatement() : Statement() {}
SelectionStatement(const Base* _el) : Statement(_el) {}
- SelectionStatement(const Base* _if, const Base* _else) :
- Statement(_if, _else) {}
+
+ SelectionStatement(const Base* _if, const Base* _else) {
+ leftNode = _if;
+ rightNode = _else;
+ }
};
class ExpressionStatement : public Statement {
public:
ExpressionStatement() : Statement() {}
- ExpressionStatement(const Base* _el) : Statement(_el) {}
+ ExpressionStatement(const Base* expr) : Statement(expr) {}
};
class JumpStatement : public Statement {
@@ -74,8 +61,6 @@ class IterationStatement : public Statement {
public:
IterationStatement() : Statement() {}
IterationStatement(const Base* _el) : Statement(_el) {}
- IterationStatement(const Base* _if, const Base* _else) :
- Statement(_if, _else) {}
};
#endif