/* Miscellaneous types used across stage boundaries. Copyright (C) 2025 Free Software Foundation, Inc. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ #pragma once #include #include #include #include #include namespace elna::boot { /** * Position in the source text. */ struct position { /// Line. std::size_t line = 1; /// Column. std::size_t column = 1; }; /** * A compilation error consists of an error message and position. */ class error { protected: error(const char *path, const struct position position); public: const struct position position; const char *path; virtual ~error() = default; /// Error text. virtual std::string what() const = 0; /// Error line in the source text. std::size_t line() const; /// Error column in the source text. std::size_t column() const; }; using error_list = typename std::deque>; class error_container { protected: error_list m_errors; error_container(const char *input_file); public: const char *input_file; error_list& errors(); template void add_error(Args... arguments) { auto new_error = std::make_unique(arguments...); m_errors.emplace_back(std::move(new_error)); } bool has_errors() const; }; /** * Tags a procedure type as never returning. */ template struct return_declaration { return_declaration() = default; explicit return_declaration(T type) : proper_type(type) { } explicit return_declaration(std::monostate) : no_return(true) { } T proper_type{}; bool no_return{ false }; }; }