From c85746b6a6c3080bac409e0acb8cc8b332b2761e Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Fri, 17 Feb 2017 17:27:38 +0000 Subject: Finished compound statement for function and added test cases --- c_parser/include/ast_declaration.hpp | 21 +++++++++++++++++---- c_parser/include/ast_function.hpp | 5 ++++- c_parser/include/ast_primitives.hpp | 10 ++++++++-- c_parser/include/ast_statement.hpp | 2 ++ 4 files changed, 31 insertions(+), 7 deletions(-) (limited to 'c_parser/include') 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 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 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 << "" << 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 << "" << 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 << "" << 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 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 { -- cgit