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/parse/metavar-map.hxx | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tiger-compiler/src/parse/metavar-map.hxx (limited to 'tiger-compiler/src/parse/metavar-map.hxx') diff --git a/tiger-compiler/src/parse/metavar-map.hxx b/tiger-compiler/src/parse/metavar-map.hxx new file mode 100644 index 0000000..7dc2bbc --- /dev/null +++ b/tiger-compiler/src/parse/metavar-map.hxx @@ -0,0 +1,69 @@ +/** + ** \file parse/metavar-map.hxx + ** \brief Implementation of parse::MetavarMap. + */ + +#pragma once + +#include +#include + +#include +#include +#include + +namespace parse +{ + template + MetavarMap::MetavarMap(const std::string& name) + : name_(name) + , map_() + {} + + template MetavarMap::~MetavarMap() + { + // At this point, every metavariable should have been taken from the map. + assertion(map_.empty()) << *this << "not empty, aborting.\n"; + } + + template + std::string MetavarMap::show(unsigned key) const + { + return '_' + name_ + '(' + std::to_string(key) + ')'; + } + + template + std::ostream& MetavarMap::dump(std::ostream& ostr) const + { + ostr << "MetavarMap<" << name_ << "> = ["; + + if (map_.empty()) + return ostr << " ]" << misc::iendl; + + ostr << misc::incindent; + + for (const auto& [k, v] : map_) + ostr << misc::iendl << show(k) << " -> " << v; + + return ostr << misc::decendl << "]" << misc::iendl; + } + + template + std::string MetavarMap::append_(unsigned& count, Data* data) + { + map_[count] = data; + return show(count++); + } + + template Data* MetavarMap::take_(unsigned key) + { + return map_.take(key); + } + + template + std::ostream& operator<<(std::ostream& ostr, const MetavarMap& m) + { + return m.dump(ostr); + } + +} // namespace parse -- cgit v1.2.3