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/lib/misc/symbol.hh | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tiger-compiler/lib/misc/symbol.hh (limited to 'tiger-compiler/lib/misc/symbol.hh') diff --git a/tiger-compiler/lib/misc/symbol.hh b/tiger-compiler/lib/misc/symbol.hh new file mode 100644 index 0000000..6d0a1e1 --- /dev/null +++ b/tiger-compiler/lib/misc/symbol.hh @@ -0,0 +1,77 @@ +/** + ** \file misc/symbol.hh + ** \brief Definition of misc::symbol. + */ + +#pragma once + +#include +#include +#include + +#include + +namespace misc +{ + /** \brief Define symbol class. + ** + ** Map any string to a unique reference. + ** This allows to avoid an "strcmp()" style comparison of strings: + ** reference comparison is much faster. + */ + class symbol : public unique + { + using super_type = unique; + /// The type "set of strings". + using string_set_type = super_type::object_set_type; + /// The type for the size of string map. + using string_size_type = string_set_type::size_type; + + /** \name Ctor & Dtor. + ** \{ */ + public: + /** \brief Construct a symbol. + ** \param s referenced string */ + symbol(const std::string& s); + /** \brief Construct a symbol. + ** \param s referenced string */ + symbol(const char* s = ""); + /** \brief Construct a symbol. + ** \param s symbol to copy. */ + constexpr symbol(const symbol& s) = default; + /** \} */ + + /** \name Operators. + ** \{ */ + public: + /** \brief Assign a symbol to this symbol. + ** \param rhs symbol to copy. */ + symbol& operator=(const symbol& rhs); + + /** \brief Compare two symbol for equality. + ** \param rhs string to compare with. */ + bool operator==(const symbol& rhs) const; + /** \brief Compare two symbol for inequality. + ** \param rhs string to compare with. *//* */ + bool operator!=(const symbol& rhs) const; + /** \} */ + + public: + /** \name Factory methods. + ** \{ */ + /** \brief Create a new unique symbol. */ + static symbol fresh(); + /** \brief Create a new unique symbol, forged from \a s. */ + static symbol fresh(const symbol& s); + /** \} */ + }; + + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param the a reference to the symbol to redirect + */ + std::ostream& operator<<(std::ostream& ostr, const symbol& the); + +} // namespace misc + +#include -- cgit v1.2.3