From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/src/type/class.hxx | 88 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tiger-compiler/src/type/class.hxx (limited to 'tiger-compiler/src/type/class.hxx') diff --git a/tiger-compiler/src/type/class.hxx b/tiger-compiler/src/type/class.hxx new file mode 100644 index 0000000..0a41d17 --- /dev/null +++ b/tiger-compiler/src/type/class.hxx @@ -0,0 +1,88 @@ +/** + ** \file type/class.hxx + ** \brief Inline methods for type::Class. + */ +#pragma once + +#include + +#include +#include + +namespace type +{ + inline const Class::attrs_type& Class::attrs_get() const { return attrs_; } + + inline const Attribute* Class::attr_find(misc::symbol key) const + { + for (const Class* cur = this; cur; cur = cur->super_get()) + { + const Attribute* attr = cur->owned_attr_find(key); + if (attr) + return attr; + } + return nullptr; + } + + inline const Method* Class::meth_find(misc::symbol key) const + { + for (const Class* cur = this; cur; cur = cur->super_get()) + { + const Method* meth = cur->owned_meth_find(key); + if (meth) + return meth; + } + return nullptr; + } + + inline const Attribute* Class::owned_attr_find(misc::symbol key) const + { + for (const Attribute& at : attrs_get()) + if (at.name_get() == key) + return &at; + return nullptr; + } + + inline const Method* Class::owned_meth_find(misc::symbol key) const + { + for (const Method* m : meths_get()) + if (m->name_get() == key) + return m; + return nullptr; + } + + inline void Class::attr_add(const Attribute& attr) + { + attrs_.emplace_back(attr); + } + + inline void Class::attr_add(const ast::VarDec* def) + { + attrs_.emplace_back(def); + } + + inline const Class::meths_type& Class::meths_get() const { return meths_; } + + inline void Class::meth_add(const Method* meth) { meths_.emplace_back(meth); } + + inline bool Class::has_data() const { return !attrs_.empty(); } + + inline unsigned Class::id_get() const { return id_; } + + inline const Class* Class::super_get() const { return super_; } + + inline void Class::super_set(const Class* super) { super_ = super; } + + inline const Class::subclasses_type& Class::subclasses_get() const + { + return subclasses_; + } + + inline void Class::subclass_add(const Class* subclass) const + { + subclasses_.emplace_back(subclass); + } + + inline void Class::subclasses_clear() const { subclasses_.clear(); } + +} // namespace type -- cgit v1.2.3