diff options
author | ymherklotz <ymherklotz@gmail.com> | 2017-03-23 12:47:29 +0000 |
---|---|---|
committer | ymherklotz <ymherklotz@gmail.com> | 2017-03-23 12:47:29 +0000 |
commit | aeb81c1a8959905878c242e752b596325325db8f (patch) | |
tree | 7d234603b0375bd4f4806d60f0a4f7647f0a48f6 /c_compiler/include | |
parent | 0a74a6393cc45c3e12fbc316fbb440dcea14740d (diff) | |
download | Compiler-aeb81c1a8959905878c242e752b596325325db8f.tar.gz Compiler-aeb81c1a8959905878c242e752b596325325db8f.zip |
Better types
Diffstat (limited to 'c_compiler/include')
-rw-r--r-- | c_compiler/include/declaration.hpp | 2 | ||||
-rw-r--r-- | c_compiler/include/type.hpp | 82 |
2 files changed, 60 insertions, 24 deletions
diff --git a/c_compiler/include/declaration.hpp b/c_compiler/include/declaration.hpp index f99c4a3..bcd12a7 100644 --- a/c_compiler/include/declaration.hpp +++ b/c_compiler/include/declaration.hpp @@ -33,7 +33,7 @@ public: void linkDeclaration(Declaration* next_declaration); void linkListDeclaration(Declaration* next_list_declaration); - void setType(Type* type); + void setType(TypePtr type); void setInitializer(Expression* initializer); void setExternDeclaration(bool is_extern); diff --git a/c_compiler/include/type.hpp b/c_compiler/include/type.hpp index bd9fd4b..8c881c1 100644 --- a/c_compiler/include/type.hpp +++ b/c_compiler/include/type.hpp @@ -13,15 +13,14 @@ typedef std::shared_ptr<Type> TypePtr; class Type : public Node { public: - virtual void print() const; - virtual void printXml() const; - virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned& label_count) const; - - virtual std::string getType() const = 0; - - virtual TypePtr type(); - virtual TypePtr type(Type* type_ptr); - virtual TypePtr type(TypePtr type_ptr); + virtual void print() const = 0; + virtual void printXml() const = 0; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const = 0; + + virtual TypePtr type() = 0; + virtual TypePtr type(Type *type_ptr) = 0; + virtual TypePtr type(TypePtr type_ptr) = 0; + virtual void setSigned(bool _signed); virtual void setExtern(bool _extern); virtual void setStatic(bool _static); @@ -31,16 +30,35 @@ public: class Array : public Type { +private: + int size_; + TypePtr type_; public: - Array(); - virtual std::string getType() const; + Array(const int &size, TypePtr type_); + + virtual void print() const; + virtual void printXml() const; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; + + virtual TypePtr type(); + virtual TypePtr type(Type *type_ptr); + virtual TypePtr type(TypePtr type_ptr); }; class Pointer : public Type { +private: + TypePtr type_; public: Pointer(); - virtual std::string getType() const; + + virtual void print() const; + virtual void printXml() const; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; + + virtual TypePtr type(); + virtual TypePtr type(Type *type_ptr); + virtual TypePtr type(TypePtr type_ptr); }; class TypeContainer : public Type @@ -56,10 +74,14 @@ protected: public: TypeContainer(); - virtual std::string getType() const; + virtual void print() const; + virtual void printXml() const; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; + virtual TypePtr type(); - virtual TypePtr type(Type* type_ptr); + virtual TypePtr type(Type *type_ptr); virtual TypePtr type(TypePtr type_ptr); + virtual void setSigned(bool _signed); virtual void setExtern(bool _extern); virtual void setStatic(bool _static); @@ -70,39 +92,53 @@ public: class Specifier : public Type { public: - virtual std::string getType() const = 0; + virtual void print() const = 0; + virtual void printXml() const = 0; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const = 0; + + virtual TypePtr type(); + virtual TypePtr type(Type *type_ptr); + virtual TypePtr type(TypePtr type_ptr); }; class Int : public Specifier { public: Int(); - - virtual std::string getType() const; + + virtual void print() const; + virtual void printXml() const; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; }; class Void : public Specifier { public: Void(); - - virtual std::string getType() const; + + virtual void print() const; + virtual void printXml() const; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; }; class Char : public Specifier { public: Char(); - - virtual std::string getType() const; + + virtual void print() const; + virtual void printXml() const; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; }; class Float : public Specifier { public: Float(); - - virtual std::string getType() const; + + virtual void print() const; + virtual void printXml() const; + virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned &label_count) const; }; #endif |