diff options
Diffstat (limited to 'c_compiler/src/type.cpp')
-rw-r--r-- | c_compiler/src/type.cpp | 168 |
1 files changed, 127 insertions, 41 deletions
diff --git a/c_compiler/src/type.cpp b/c_compiler/src/type.cpp index 04bc245..29b6902 100644 --- a/c_compiler/src/type.cpp +++ b/c_compiler/src/type.cpp @@ -6,57 +6,67 @@ // Type definition -void Type::print() const +void Type::setSigned(bool) { - printf("%s\n", getType().c_str()); + throw std::runtime_error("Error : cannot set sign"); } -void Type::printXml() const -{} - -VariableStackBindings Type::printAsm(VariableStackBindings bindings, unsigned&) const +void Type::setExtern(bool) { - return bindings; + throw std::runtime_error("Error : cannot set extern"); } -TypePtr Type::type() +void Type::setStatic(bool) { - throw std::runtime_error("Error : does not have a type"); + throw std::runtime_error("Error : cannot set static"); } -TypePtr Type::type(Type*) +void Type::setConst(bool) { - throw std::runtime_error("Error : cannot assign type"); + throw std::runtime_error("Error : cannot set const"); } -TypePtr Type::type(TypePtr) +void Type::setSize(int) { - throw std::runtime_error("Error : cannot assign type"); + throw std::runtime_error("Error : cannot set size"); } -void Type::setSigned(bool) + +// Array definition + +Array::Array(const int &size, TypePtr type) + : size_(size), type_(type) +{} + +void Array::print() const { - throw std::runtime_error("Error : cannot set sign"); + printf("Array\n"); } -void Type::setExtern(bool) +void Array::printXml() const +{} + +VariableStackBindings Array::printAsm(VariableStackBindings bindings, unsigned &label_count) const { - throw std::runtime_error("Error : cannot set extern"); + return bindings; } -void Type::setStatic(bool) +TypePtr Array::type() { - throw std::runtime_error("Error : cannot set static"); + return type_; } -void Type::setConst(bool) +TypePtr Array::type(Type *type_ptr) { - throw std::runtime_error("Error : cannot set const"); + TypePtr sh_type_ptr(type_ptr); + type_ = sh_type_ptr; + return type_; } -void Type::setSize(int) +TypePtr Array::type(TypePtr type_ptr) { - throw std::runtime_error("Error : cannot set size"); + type_ = type_ptr; + return type_; } @@ -65,32 +75,58 @@ void Type::setSize(int) Pointer::Pointer() {} -std::string Pointer::getType() const +void Pointer::print() const { - return "pointer"; + printf("Pointer\n"); } +void Pointer::printXml() const +{} -// Array definition +VariableStackBindings Pointer::printAsm(VariableStackBindings bindings, unsigned &label_count) const +{ + return bindings; +} -Array::Array() -{} +TypePtr Pointer::type() +{ + return type_; +} -std::string Array::getType() const +TypePtr Pointer::type(Type *type_ptr) { - return "array"; + TypePtr sh_type_ptr(type_ptr); + type_ = sh_type_ptr; + return type_; +} + +TypePtr Pointer::type(TypePtr type_ptr) +{ + type_ = type_ptr; + return type_; } + + // TypeContainer definition TypeContainer::TypeContainer() : type_(nullptr), size_(32), extern_(false), static_(false), const_(false), signed_(true) {} -std::string TypeContainer::getType() const +void TypeContainer::print() const +{ + printf("TypeContainer : "); + type_->print(); +} + +void TypeContainer::printXml() const +{} + +VariableStackBindings TypeContainer::printAsm(VariableStackBindings bindings, unsigned &label_count) const { - return type_->getType(); + return bindings; } TypePtr TypeContainer::type() @@ -98,7 +134,7 @@ TypePtr TypeContainer::type() return type_; } -TypePtr TypeContainer::type(Type* type_ptr) +TypePtr TypeContainer::type(Type *type_ptr) { TypePtr new_type_ptr(type_ptr); type_ = new_type_ptr; @@ -139,14 +175,40 @@ void TypeContainer::setSize(int size) } +// Specifier definitions + +TypePtr Specifier::type() +{ + throw std::runtime_error("Error : Cannot get type"); +} + +TypePtr Specifier::type(Type *) +{ + throw std::runtime_error("Error : Cannot get type"); +} + +TypePtr Specifier::type(TypePtr) +{ + throw std::runtime_error("Error : Cannot get type"); +} + + // Int definition Int::Int() {} -std::string Int::getType() const +void Int::print() const +{ + printf("Int\n"); +} + +void Int::printXml() const +{} + +VariableStackBindings Int::printAsm(VariableStackBindings bindings, unsigned &label_count) const { - return "int"; + return bindings; } @@ -155,9 +217,17 @@ std::string Int::getType() const Void::Void() {} -std::string Void::getType() const +void Void::print() const +{ + printf("Void\n"); +} + +void Void::printXml() const +{} + +VariableStackBindings Void::printAsm(VariableStackBindings bindings, unsigned &label_count) const { - return "void"; + return bindings; } @@ -166,9 +236,17 @@ std::string Void::getType() const Char::Char() {} -std::string Char::getType() const +void Char::print() const { - return "char"; + printf("Char\n"); +} + +void Char::printXml() const +{} + +VariableStackBindings Char::printAsm(VariableStackBindings bindings, unsigned &label_count) const +{ + return bindings; } @@ -177,7 +255,15 @@ std::string Char::getType() const Float::Float() {} -std::string Float::getType() const +void Float::print() const { - return "float"; + printf("Float\n"); +} + +void Float::printXml() const +{} + +VariableStackBindings Float::printAsm(VariableStackBindings bindings, unsigned &label_count) const +{ + return bindings; } |