diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-23 09:35:44 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-23 09:35:44 +0000 |
commit | 0a74a6393cc45c3e12fbc316fbb440dcea14740d (patch) | |
tree | fbd698cf21cae44d510bd4614c1ea1af7c9a424e | |
parent | ffb5df0e59d93fd5322ef02e337f713ed56c262f (diff) | |
download | Compiler-0a74a6393cc45c3e12fbc316fbb440dcea14740d.tar.gz Compiler-0a74a6393cc45c3e12fbc316fbb440dcea14740d.zip |
Doing arrays
-rw-r--r-- | c_compiler/include/statement.hpp | 4 | ||||
-rw-r--r-- | c_compiler/src/statement.cpp | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/c_compiler/include/statement.hpp b/c_compiler/include/statement.hpp index a34e22d..ed45973 100644 --- a/c_compiler/include/statement.hpp +++ b/c_compiler/include/statement.hpp @@ -30,7 +30,6 @@ public: virtual void countExpressionDepth(unsigned &depth_count) const = 0; virtual int constantFold() const; - virtual StatementPtr getStatementList() const; virtual ExpressionPtr getExpression() const; virtual bool isDefault() const; @@ -95,7 +94,8 @@ public: virtual void countVariables(unsigned &var_count) const; virtual void countArguments(unsigned &argument_count) const; virtual void countExpressionDepth(unsigned &depth_count) const; - virtual StatementPtr getStatementList() const; + + StatementPtr getStatementList() const; }; class IfElseStatement : public Statement diff --git a/c_compiler/src/statement.cpp b/c_compiler/src/statement.cpp index f2fff49..e5fd369 100644 --- a/c_compiler/src/statement.cpp +++ b/c_compiler/src/statement.cpp @@ -16,11 +16,6 @@ int Statement::constantFold() const throw std::runtime_error("Error : not implemented"); } -StatementPtr Statement::getStatementList() const -{ - throw std::runtime_error("Error : not implemented"); -} - ExpressionPtr Statement::getExpression() const { return nullptr; @@ -425,17 +420,22 @@ void SwitchStatement::printXml() const VariableStackBindings SwitchStatement::printAsm(VariableStackBindings bindings, unsigned &label_count) const { unsigned switch_count = label_count++; + std::shared_ptr<CompoundStatement> comp_statement; + StatementPtr case_statement_list; + std::vector<StatementPtr> case_statement_vector; if(next_statement_ != nullptr) next_statement_->printAsm(bindings, label_count); condition_->printAsm(bindings, label_count); - StatementPtr case_statement_list = statement_->getStatementList(); - std::vector<StatementPtr> case_statement_vector; + comp_statement = std::dynamic_pointer_cast<CompoundStatement>(statement_); + if(comp_statement == nullptr) + throw std::runtime_error("Error : not implemented"); bindings.breakLabel("$"+std::to_string(switch_count)+"_break_switch"); - + + case_statement_list = comp_statement->getStatementList(); while(case_statement_list != nullptr) { case_statement_vector.push_back(case_statement_list); |