diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-02-17 17:27:38 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-02-17 17:27:38 +0000 |
commit | c85746b6a6c3080bac409e0acb8cc8b332b2761e (patch) | |
tree | 7e37429cbe6014e2ed6aba6466b69cf914e2af38 /c_parser/include | |
parent | b81f60d8b523260526af15361d4ce0ac4a7757c8 (diff) | |
download | Compiler-c85746b6a6c3080bac409e0acb8cc8b332b2761e.tar.gz Compiler-c85746b6a6c3080bac409e0acb8cc8b332b2761e.zip |
Finished compound statement for function and added test cases
Diffstat (limited to 'c_parser/include')
-rw-r--r-- | c_parser/include/ast_declaration.hpp | 21 | ||||
-rw-r--r-- | c_parser/include/ast_function.hpp | 5 | ||||
-rw-r--r-- | c_parser/include/ast_primitives.hpp | 10 | ||||
-rw-r--r-- | c_parser/include/ast_statement.hpp | 2 |
4 files changed, 31 insertions, 7 deletions
diff --git a/c_parser/include/ast_declaration.hpp b/c_parser/include/ast_declaration.hpp index 01b1498..72bd375 100644 --- a/c_parser/include/ast_declaration.hpp +++ b/c_parser/include/ast_declaration.hpp @@ -7,14 +7,27 @@ // Declaration that holds a list of declarations -class ast_Declaration : public ast_Base { +class ast_DeclarationList : public ast_Base { private: + mutable std::vector<const ast_Base*> dec_list; public: - virtual void print() const = 0; + ast_DeclarationList(const ast_Base* _dec) { + dec_list.push_back(_dec); + } + + virtual void print() const { + for(size_t i = 0; i < dec_list.size(); ++i) { + dec_list[i]->print(); + } + } + + virtual void push(const ast_Base* _dec) const { + dec_list.push_back(_dec); + } }; -class ast_VariableDeclaration : public ast_Declaration { +class ast_VariableDeclaration : public ast_Base { private: mutable std::vector<const ast_Base*> var_list; @@ -24,7 +37,7 @@ public: } virtual void print() const { - for(int i = 0; i < var_list.size(); ++i) { + for(size_t i = 0; i < var_list.size(); ++i) { var_list[i]->print(); } } diff --git a/c_parser/include/ast_function.hpp b/c_parser/include/ast_function.hpp index 86230d1..1086f49 100644 --- a/c_parser/include/ast_function.hpp +++ b/c_parser/include/ast_function.hpp @@ -22,7 +22,10 @@ public: std::cout << "</Function>" << std::endl; } - virtual void push(const ast_Base* var) const {} + virtual void push(const ast_Base* var) const { + std::cerr << "Error: Can't call this function on this class" << std::endl; + (void)var; + } }; class ast_ParamList : public ast_Base { diff --git a/c_parser/include/ast_primitives.hpp b/c_parser/include/ast_primitives.hpp index d878780..5ae6d12 100644 --- a/c_parser/include/ast_primitives.hpp +++ b/c_parser/include/ast_primitives.hpp @@ -15,7 +15,10 @@ public: std::cout << "<Variable id=\"" << id << "\" />" << std::endl; } - virtual void push(const ast_Base* var) const {} + virtual void push(const ast_Base* var) const { + std::cerr << "Error: Can't call this function on this class" << std::endl; + (void)var; + } }; class ast_Parameter : public ast_Base { @@ -28,7 +31,10 @@ public: std::cout << "<Parameter id=\"" << id << "\" />" << std::endl; } - virtual void push(const ast_Base* var) const {} + virtual void push(const ast_Base* var) const { + std::cerr << "Error: Can't call this function on this class" << std::endl; + (void)var; + } }; #endif diff --git a/c_parser/include/ast_statement.hpp b/c_parser/include/ast_statement.hpp index 725308b..f2c7175 100644 --- a/c_parser/include/ast_statement.hpp +++ b/c_parser/include/ast_statement.hpp @@ -6,6 +6,7 @@ protected: mutable std::vector<const ast_Base*> ast_list; public: + ast_Statement() {} ast_Statement(const ast_Base* _el) { ast_list.push_back(_el); } @@ -23,6 +24,7 @@ public: class ast_CompoundStatement : public ast_Statement { public: + ast_CompoundStatement() : ast_Statement() {} ast_CompoundStatement(const ast_Base* _el) : ast_Statement(_el) {} virtual void print() const override { |