51std::vector<std::string> make_source_details(
54 if (file_lines.empty()) {
59 const std::size_t line_index = define.
position().
line - 1;
60 if (line_index >= file_lines.size()) {
65 return printer.print(file_lines, std::vector{line_index});
81 std::optional<CParserFacade> &driver,
const std::filesystem::path &header_path,
const TextFormatter *format)
83 if (!driver.has_value()) {
84 driver.emplace(header_path, format);
86 return driver.value();
106 const std::string &file_path,
107 const std::vector<std::string> &file_lines,
108 const std::string & )
110 const auto source = make_source_string(format, file_path, define);
111 const auto details = make_source_details(format, file_lines, define);
115 "'{}' is not an integer value (found {} define)",
158template <
typename T,
typename ParseFunc>
160 std::optional<CParserFacade> &driver,
162 const std::filesystem::path &header_path,
163 const std::string &define_name,
164 ParseFunc parse_func,
165 const std::string &key,
166 const std::string &provider_name)
169 auto &parser = get_parser_driver(driver, header_path, format);
172 auto result = parser.find_define(define_name);
174 if (!result.has_value()) {
177 if (!std::filesystem::exists(header_path)) {
181 const auto base_error_msg = format->
format(
182 "failed to parse '{}' from '{}':",
185 std::vector<std::string> details_err_msg{};
186 for (
const auto &err : result.chain()) {
187 if (
const auto &details = err->details(*format); !details.empty()) {
188 details_err_msg.append_range(err->details(*format));
189 details_err_msg.emplace_back();
195 if (!result.value().has_value()) {
201 auto layer_result = parse_func(format, result.value().value(), header_path.string(), parser.file_lines(), key);
202 layer_result.source_key = provider_name;
High-level facade for parsing C/C++ source files.
Represents a parsed #define preprocessor statement.
bool is_flag() const
Checks if this define has no value (flag-like).
const std::string & name() const
Returns the macro name.
bool has_int_value() const
Checks if this define has an integer value.
const SourcePosition & position() const
Returns the source position of the #define.
std::int64_t int_value() const
Returns the integer value.
A service for printing file lines with highlighted lines and line numbers.
static const Style bold
Bold text formatting.
Abstract base class for applying text styling with context-aware formatting.
virtual std::string format(const std::string &format_str, const std::vector< FormatParam > ¶ms) const
Formats a string with styled parameters using fmtlib syntax.
@ error
Emit a formatted error and fail decompilation.
A small container that holds an optional-wrapped value, validation state, and metadata about the valu...
static LayerValue valid(T val, std::string source_key, std::string source_info)
Creates a LayerValue representing a valid configuration value.
static LayerValue not_provided()
Creates a LayerValue representing that the provider does not supply this configuration.
static LayerValue invalid(std::string error, std::string source_info)
Creates a LayerValue representing an invalid configuration value.
std::size_t line
1-based line number