From e7265af15f77abf60a899b3d53a59652b5ca71ea Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Wed, 15 Jul 2026 17:23:42 +0200 Subject: Track identifier positions for the diagnostics --- boot/result.cc | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 94 insertions(+), 13 deletions(-) (limited to 'boot/result.cc') diff --git a/boot/result.cc b/boot/result.cc index 90d0ad6..5f3c516 100644 --- a/boot/result.cc +++ b/boot/result.cc @@ -19,22 +19,57 @@ along with GCC; see the file COPYING3. If not see namespace elna::boot { - location::location(std::size_t line, std::size_t column) - : line(line), column(column) + location::location(const std::size_t line, const std::size_t column) + : m_line(line), m_column(column) { } + std::size_t location::line() const + { + return this->m_line; + } + + std::size_t location::column() const + { + return this->m_column; + } + bool location::available() const { - return this->line != 0 || this->column != 0; + return this->m_line != 0 || this->m_column != 0; + } + + bool location::operator==(const location& that) const + { + return this->m_line == that.m_line && this->m_column == that.m_column; + } + + bool location::operator!=(const location& that) const + { + return !(*this == that); } - position::position(location start, location end) - : start(start), end(end) + source_position::source_position(location start, location end) + : m_start(start), m_end(end) { } - error::error(const struct position position) + const location& source_position::start() const + { + return this->m_start; + } + + const location& source_position::end() const + { + return this->m_end; + } + + bool source_position::is_span() const + { + return this->m_start != this->m_end; + } + + error::error(const source_position position) : position(position) { } @@ -49,19 +84,65 @@ namespace elna::boot return !m_errors.empty(); } - bool identifier_definition::operator==(const identifier_definition& that) const + identifier::identifier(const std::string& name, const source_position& position) + : m_name(name), m_position(position) + { + } + + const std::string& identifier::name() const + { + return this->m_name; + } + + const source_position& identifier::position() const + { + return this->m_position; + } + + bool identifier::operator==(const identifier& that) const + { + return this->m_name == that.m_name; + } + + bool identifier::operator!=(const identifier& that) const + { + return !(*this == that); + } + + bool identifier::operator==(const std::string& that) const + { + return this->m_name == that; + } + + bool identifier::operator!=(const std::string& that) const + { + return !(*this == that); + } + + identifier_definition::identifier_definition(const std::string& name, + const source_position& position, const bool exported) + : m_identifier(name, position), m_exported(exported) + { + } + + const std::string& identifier_definition::name() const + { + return this->m_identifier.name(); + } + + const identifier& identifier_definition::id() const { - return *this == that.name; + return this->m_identifier; } - bool identifier_definition::operator==(const std::string& that) const + bool identifier_definition::exported() const { - return this->name == that; + return this->m_exported; } } -std::size_t std::hash::operator()( - const elna::boot::identifier_definition& key) const +std::size_t std::hash::operator()( + const elna::boot::identifier& key) const { - return std::hash{}(key.name); + return std::hash{}(key.name()); } -- cgit v1.2.3