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/type.hh | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tiger-compiler/src/type/type.hh (limited to 'tiger-compiler/src/type/type.hh') diff --git a/tiger-compiler/src/type/type.hh b/tiger-compiler/src/type/type.hh new file mode 100644 index 0000000..a5f9777 --- /dev/null +++ b/tiger-compiler/src/type/type.hh @@ -0,0 +1,66 @@ +/** + ** \file type/type.hh + ** \brief The class Type. + */ +#pragma once + +#include +#include + +namespace type +{ + /// Abstract a type. + class Type + { + /** \name Ctor & dtor. + ** \{ */ + public: + /// Destroys a Type. + virtual ~Type() = default; + /** \} */ + + /// \name Visitors entry point. + /// \{ */ + /// Accept a const visitor \a v. + virtual void accept(ConstVisitor& v) const = 0; + /// Accept a non-const visitor \a v. + virtual void accept(Visitor& v) = 0; + /// \} + + /** \name Accessors. + ** \{ */ + /// Return the actual type held by THIS. + virtual const Type& actual() const; + /** \} */ + + /** \brief Whether two types are "compatible". + ** + ** I.e., whether "a = b", "a <> b", "a := b" are correctly typed + ** with a of type \a this, and b of type \a other). + ** + ** By default two types are compatible (in the sense of "=" and "<>", + ** not w.r.t. an order) only when they are equal. + ** + ** In the case of assignment, "rec := nil" is valid, but "nil := rec" + ** is not, which suggest that we should have a non commutative + ** assignment specific compatibility check. But since "nil := ..." + ** is incorrect syntactically, that is not needed. + */ + virtual bool compatible_with(const Type& other) const; + }; + + /** \brief Compare two Type s. + ** + ** Return true if \a a and \a b are equivalent Tiger Types. E.g., + ** if \a a and \a b are different but point to the same type, then + ** return true. */ + bool operator==(const Type& lhs, const Type& rhs); + /// !(a == b). + bool operator!=(const Type& lhs, const Type& rhs); + + /// Hide actual types? (i.e., print only the surface type?) + extern const misc::xalloc hide_actual_types; + +} // namespace type + +#include -- cgit v1.2.3