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/scoped-map.hh | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tiger-compiler/lib/misc/scoped-map.hh (limited to 'tiger-compiler/lib/misc/scoped-map.hh') diff --git a/tiger-compiler/lib/misc/scoped-map.hh b/tiger-compiler/lib/misc/scoped-map.hh new file mode 100644 index 0000000..a193e24 --- /dev/null +++ b/tiger-compiler/lib/misc/scoped-map.hh @@ -0,0 +1,51 @@ +/** + ** \file misc/scoped-map.hh + ** \brief Declaration of misc::scoped_map. + ** + ** This implements a stack of dictionnaries. Each time a scope is + ** opened, a new dictionnary is added on the top of the stack; the + ** dictionary is removed when the scope is closed. Lookup of keys + ** is done in the last added dictionnary first (LIFO). + ** + ** In particular this class is used to implement symbol tables. + **/ + +#pragma once + +#include +#include +#include +#include + +namespace misc +{ + template class scoped_map + { + // FIXME DONE: Some code was deleted here. + public: + // initializes a new stack with an empty map on top as the first scope + scoped_map() + { + scopes_.push_back(std::map()); + } + void put(const Key& key, const Data& value); + Data get(const Key& key) const requires(!std::is_pointer_v); + Data get(const Key& key) const requires(std::is_pointer_v); + std::ostream& dump(std::ostream& ostr) const; + void scope_begin(); + void scope_end(); + + private: + std::vector> scopes_; + }; + + template + std::ostream& operator<<(std::ostream& ostr, + const scoped_map& tbl); + + // FIXME DONE: Some code was deleted here. + // heehee + +} // namespace misc + +#include -- cgit v1.2.3