diff options
Diffstat (limited to 'c_compiler/include')
-rw-r--r-- | c_compiler/include/declaration.hpp | 31 | ||||
-rw-r--r-- | c_compiler/include/expression.hpp | 7 |
2 files changed, 28 insertions, 10 deletions
diff --git a/c_compiler/include/declaration.hpp b/c_compiler/include/declaration.hpp index bcd12a7..b607c3c 100644 --- a/c_compiler/include/declaration.hpp +++ b/c_compiler/include/declaration.hpp @@ -13,34 +13,47 @@ typedef std::shared_ptr<Declaration> DeclarationPtr; class Declaration : public Node { -private: +protected: TypePtr type_; std::string id_; ExpressionPtr initializer_; DeclarationPtr next_declaration_; DeclarationPtr next_list_declaration_; bool extern_declaration_; - public: - Declaration(const std::string& id = "", Expression* initializer = nullptr); + Declaration(const std::string &id = "", Expression *initializer = nullptr); + Declaration(const std::string &id, ExpressionPtr initializer); virtual void print() const; virtual void printXml() const; - virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned& label_count) const; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; + virtual VariableStackBindings localAsm(VariableStackBindings bindings, unsigned &label_count) const; + virtual void countDeclarations(unsigned &declaration_count) const; - VariableStackBindings localAsm(VariableStackBindings bindings, unsigned& label_count) const; - - void linkDeclaration(Declaration* next_declaration); - void linkListDeclaration(Declaration* next_list_declaration); + void linkDeclaration(Declaration *next_declaration); + void linkListDeclaration(Declaration *next_list_declaration); void setType(TypePtr type); - void setInitializer(Expression* initializer); + void setInitializer(Expression *initializer); void setExternDeclaration(bool is_extern); DeclarationPtr getNext() const; DeclarationPtr getNextListItem() const; + ExpressionPtr getInitializer() const; std::string getId() const; TypePtr getType() const; }; +class ArrayDeclaration : public Declaration +{ +private: + unsigned size_; +public: + ArrayDeclaration(const std::string &id = "", ExpressionPtr initializer = nullptr, const unsigned &size = 0); + + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; + virtual VariableStackBindings localAsm(VariableStackBindings bindings, unsigned &label_count) const; + virtual void countDeclarations(unsigned &declaration_count) const; +}; + #endif diff --git a/c_compiler/include/expression.hpp b/c_compiler/include/expression.hpp index 244b2a8..1e7c557 100644 --- a/c_compiler/include/expression.hpp +++ b/c_compiler/include/expression.hpp @@ -61,10 +61,15 @@ public: class PostfixArrayElement : public UnaryExpression { +private: + ExpressionPtr postfix_expression_; + ExpressionPtr index_expression_; + public: - PostfixArrayElement(); + PostfixArrayElement(Expression *postfix_expression, Expression *index_expression); virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; + virtual void stackPosition(VariableStackBindings bindings) const; }; class PostfixFunctionCall : public UnaryExpression |