diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-03 16:24:07 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-03 16:24:07 +0000 |
commit | 522cc9d286c5d35ca25ebaa85374f5f9214a7f6e (patch) | |
tree | e4c944cce2fcd736834e35d8e5d06f984b57a976 /c_compiler/include | |
parent | 446c2394ec8970198d645bbbb462c67b9e3f1b1e (diff) | |
download | Compiler-522cc9d286c5d35ca25ebaa85374f5f9214a7f6e.tar.gz Compiler-522cc9d286c5d35ca25ebaa85374f5f9214a7f6e.zip |
Still working on ast
Diffstat (limited to 'c_compiler/include')
-rw-r--r-- | c_compiler/include/base.hpp | 5 | ||||
-rw-r--r-- | c_compiler/include/expression.hpp | 6 | ||||
-rw-r--r-- | c_compiler/include/function.hpp | 18 | ||||
-rw-r--r-- | c_compiler/include/primitives.hpp | 34 | ||||
-rw-r--r-- | c_compiler/include/statement.hpp | 40 |
5 files changed, 40 insertions, 63 deletions
diff --git a/c_compiler/include/base.hpp b/c_compiler/include/base.hpp index ae7cfd7..eff825a 100644 --- a/c_compiler/include/base.hpp +++ b/c_compiler/include/base.hpp @@ -109,10 +109,7 @@ protected: const Base* type; public: - BasePrimitive(const std::string& _id) - : id(_id), type(new EmptyNode) {} - - BasePrimitive(const std::string& _id, const Base* _type) + BasePrimitive(const std::string& _id = "", const Base* _type = new EmptyNode) : id(_id), type(_type) {} virtual ~BasePrimitive() { diff --git a/c_compiler/include/expression.hpp b/c_compiler/include/expression.hpp index 9eb9efd..1e2bf04 100644 --- a/c_compiler/include/expression.hpp +++ b/c_compiler/include/expression.hpp @@ -6,11 +6,9 @@ class Expression : public BaseNode { private: public: - Expression() : BaseNode() {} + Expression(const Base* expr = new EmptyNode); - virtual void print() const override {} - virtual void printxml() const override {} - virtual void printasm() const override {} + virtual void printasm() const override; }; #endif diff --git a/c_compiler/include/function.hpp b/c_compiler/include/function.hpp index 955420d..b1ee88d 100644 --- a/c_compiler/include/function.hpp +++ b/c_compiler/include/function.hpp @@ -9,22 +9,10 @@ protected: std::string id; public: - Function(const std::string& _id, const BaseList* _param_list, const BaseNode* _comp_statement) - : BaseNode(_param_list, _comp_statement), id(_id) {} + Function(const std::string& _id, const BaseList* _param_list, const BaseNode* _comp_statement); - virtual void printxml() const override { - std::cout << "<Function id=\"" << id << "\">" << std::endl; - leftNode->printxml(); - rightNode->printxml(); - std::cout << "</Function>" << std::endl; - } -}; - - -class ParamList : public BaseList { -public: - ParamList() : BaseList() {} - ParamList(const Base* _param) : BaseList(_param) {} + virtual void printxml() const override; + virtual void printasm() const override; }; diff --git a/c_compiler/include/primitives.hpp b/c_compiler/include/primitives.hpp index f4c5087..d433072 100644 --- a/c_compiler/include/primitives.hpp +++ b/c_compiler/include/primitives.hpp @@ -1,26 +1,40 @@ -#ifndef AST_PRIMITIVES_HPP -#define AST_PRIMITIVES_HPP +#ifndef PRIMITIVES_HPP +#define PRIMITIVES_HPP #include "ast.hpp" +#include <cstdint> + + +class ParamList : public BaseList { +public: + ParamList(); + ParamList(const Base* _param); +}; + class Declarator : public BasePrimitive { public: - Declarator(const std::string& _id) : BasePrimitive(_id) {} + Declarator(const std::string& _id); - virtual void printxml() const { - std::cout << "<Variable id=\"" << id << "\" />" << std::endl; - } + virtual void printxml() const; }; class Parameter : public BasePrimitive { public: - Parameter(const std::string& _id) : BasePrimitive(_id) {} + Parameter(const std::string& _id); + + virtual void printxml() const; +}; + +class Immediate : public BasePrimitive { +protected: + int32_t imm; +public: + Immediate(const int32_t& _imm); - virtual void printxml() const { - std::cout << "<Parameter id=\"" << id << "\" />" << std::endl; - } + virtual void printasm() const override; }; diff --git a/c_compiler/include/statement.hpp b/c_compiler/include/statement.hpp index 451d368..bf15aa5 100644 --- a/c_compiler/include/statement.hpp +++ b/c_compiler/include/statement.hpp @@ -6,61 +6,41 @@ class Statement : public BaseNode { public: - Statement() : BaseNode() {} - - Statement(const Base* _el) : BaseNode(_el) {} + Statement(const Base* _left = new EmptyNode, const Base* _right = new EmptyNode); }; class StatementList : public BaseList { public: - StatementList(const Base* _statement) : BaseList(_statement) {} + StatementList(const Base* _statement); }; class CompoundStatement : public Statement { public: - CompoundStatement() : Statement() {} - CompoundStatement(const Base* _el) : Statement(_el) {} - - CompoundStatement(const Base* _dec, const Base* _statement) { - leftNode = _dec; - rightNode = _statement; - } + CompoundStatement(const Base* _dec = new EmptyNode, const Base* _statement = new EmptyNode); - virtual void printxml() const override { - std::cout << "<Scope>" << std::endl; - leftNode->printxml(); - rightNode->printxml(); - std::cout << "</Scope>" << std::endl; - } + virtual void printxml() const override; }; class SelectionStatement : public Statement { public: - SelectionStatement() : Statement() {} - SelectionStatement(const Base* _el) : Statement(_el) {} - - SelectionStatement(const Base* _if, const Base* _else) { - leftNode = _if; - rightNode = _else; - } + SelectionStatement(const Base* _if, const Base* _else = new EmptyNode); }; class ExpressionStatement : public Statement { public: - ExpressionStatement() : Statement() {} - ExpressionStatement(const Base* expr) : Statement(expr) {} + ExpressionStatement(const Base* expr = new EmptyNode); }; class JumpStatement : public Statement { public: - JumpStatement() : Statement() {} - JumpStatement(const Base* _el) : Statement(_el) {} + JumpStatement(const Base* _el); + + virtual void printasm() const override; }; class IterationStatement : public Statement { public: - IterationStatement() : Statement() {} - IterationStatement(const Base* _el) : Statement(_el) {} + IterationStatement(const Base* _el); }; #endif |