Create a generic type for types with an error list

This commit is contained in:
2025-03-12 00:23:51 +01:00
parent f739194e06
commit c9a8ecdc0a
13 changed files with 79 additions and 46 deletions

View File

@ -42,20 +42,10 @@ namespace boot
}
driver::driver(const char *input_file)
: input_file(input_file)
: error_container(input_file)
{
}
void driver::error(const yy::location& loc, const std::string& message)
{
m_errors.emplace_back(new boot::syntax_error(message, input_file, loc));
}
const std::list<std::unique_ptr<struct error>>& driver::errors() const noexcept
{
return m_errors;
}
char escape_char(char escape)
{
switch (escape)

View File

@ -290,6 +290,6 @@ defer {
std::stringstream ss;
ss << "Illegal character 0x" << std::hex << static_cast<unsigned int>(yytext[0]);
driver.error(this->location, ss.str());
driver.add_error<elna::boot::syntax_error>(ss.str(), driver.input_file, this->location);
}
%%

View File

@ -578,5 +578,5 @@ actual_parameter_list:
void yy::parser::error(const location_type& loc, const std::string& message)
{
driver.error(loc, message);
driver.add_error<elna::boot::syntax_error>(message, driver.input_file, loc);
}

View File

@ -35,5 +35,15 @@ namespace boot
{
return this->position.column;
}
error_container::error_container(const char *input_file)
: input_file(input_file)
{
}
std::deque<std::unique_ptr<error>>& error_container::errors()
{
return m_errors;
}
}
}

View File

@ -32,7 +32,7 @@ namespace boot
}
declaration_visitor::declaration_visitor(const char *path, std::shared_ptr<symbol_table> symbols)
: path(path), symbols(symbols)
: error_container(path), symbols(symbols)
{
}
@ -66,10 +66,8 @@ namespace boot
}
else
{
auto new_error = std::make_unique<declaration_error>(type_expression->name,
path, type_expression->position());
this->errors.emplace_back(std::move(new_error));
// TODO: Delete the next line.
// TODO:
// add_error<declaration_error>(type_expression->name, this->input_file, type_expression->position());
this->current_type = type(std::make_shared<primitive_type>(type_expression->name));
}
}