aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-06 10:44:15 +0200
committerEugen Wissner <belka@caraus.de>2026-07-07 00:47:59 +0200
commit470bfba45661d19558c0bf43b7819696a925ecb4 (patch)
tree44eef131a3edca1cc5489fa45851a5d5685ec530 /boot
parent8ea930783d15c04bbe9a027eaf19ca10e2cd87c0 (diff)
downloadelna-470bfba45661d19558c0bf43b7819696a925ecb4.tar.gz
Fix compiler crashing on syntax errors
after error reporting.
Diffstat (limited to 'boot')
-rw-r--r--boot/dependency.cc19
-rw-r--r--boot/driver.cc10
-rw-r--r--boot/lexer.ll2
-rw-r--r--boot/parser.yy4
-rw-r--r--boot/result.cc9
-rw-r--r--boot/semantic.cc53
6 files changed, 39 insertions, 58 deletions
diff --git a/boot/dependency.cc b/boot/dependency.cc
index 6b10611..84fd800 100644
--- a/boot/dependency.cc
+++ b/boot/dependency.cc
@@ -27,18 +27,13 @@ along with GCC; see the file COPYING3. If not see
namespace elna::boot
{
- dependency::dependency(const char *path)
- : error_container(path)
+ dependency read_source(std::istream& entry_point)
{
- }
-
- dependency read_source(std::istream& entry_point, const char *entry_path)
- {
- driver parse_driver{ entry_path };
+ driver parse_driver;
lexer tokenizer(entry_point);
yy::parser parser(tokenizer, parse_driver);
- dependency outcome{ entry_path };
+ dependency outcome;
if (parser())
{
std::swap(outcome.errors(), parse_driver.errors());
@@ -48,7 +43,7 @@ namespace elna::boot
{
std::swap(outcome.tree, parse_driver.tree);
}
- declaration_visitor declaration_visitor(entry_path);
+ declaration_visitor declaration_visitor;
outcome.tree->accept(&declaration_visitor);
if (!declaration_visitor.errors().empty())
@@ -60,16 +55,16 @@ namespace elna::boot
return outcome;
}
- error_list analyze_semantics(const char *path, std::unique_ptr<unit>& tree, symbol_bag bag)
+ error_list analyze_semantics(std::unique_ptr<unit>& tree, symbol_bag bag)
{
- name_analysis_visitor name_analyser(path, bag);
+ name_analysis_visitor name_analyser(bag);
tree->accept(&name_analyser);
if (name_analyser.has_errors())
{
return std::move(name_analyser.errors());
}
- type_analysis_visitor type_analyzer(path, bag);
+ type_analysis_visitor type_analyzer(bag);
tree->accept(&type_analyzer);
if (type_analyzer.has_errors())
diff --git a/boot/driver.cc b/boot/driver.cc
index abbf0f1..b2ffe60 100644
--- a/boot/driver.cc
+++ b/boot/driver.cc
@@ -28,9 +28,8 @@ namespace elna::boot
return result;
}
- syntax_error::syntax_error(const std::string& message,
- const char *input_file, const yy::location& location)
- : error(input_file, make_position(location)), message(message)
+ syntax_error::syntax_error(const std::string& message, const yy::location& location)
+ : error(make_position(location)), message(message)
{
}
@@ -39,11 +38,6 @@ namespace elna::boot
return message;
}
- driver::driver(const char *input_file)
- : error_container(input_file)
- {
- }
-
char escape_char(char escape)
{
switch (escape)
diff --git a/boot/lexer.ll b/boot/lexer.ll
index fac70f0..4f9fed7 100644
--- a/boot/lexer.ll
+++ b/boot/lexer.ll
@@ -309,6 +309,6 @@ of {
std::stringstream ss;
ss << "Illegal character 0x" << std::hex << static_cast<unsigned int>(yytext[0]);
- driver.add_error<syntax_error>(ss.str(), driver.input_file, this->location);
+ driver.add_error<syntax_error>(ss.str(), this->location);
}
%%
diff --git a/boot/parser.yy b/boot/parser.yy
index 4d4f038..a36b953 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -576,7 +576,7 @@ formal_parameter_list:
"(" ")" {}
| "(" formal_parameters ")" { std::swap($$, $2); }
formal_parameters:
- formal_parameter "," formal_parameters
+ formal_parameter ";" formal_parameters
{
std::swap($$, $3);
$$.emplace($$.cbegin(), std::move($1));
@@ -589,5 +589,5 @@ actual_parameter_list:
void yy::parser::error(const location_type& loc, const std::string& message)
{
- driver.add_error<boot::syntax_error>(message, driver.input_file, loc);
+ driver.add_error<boot::syntax_error>(message, loc);
}
diff --git a/boot/result.cc b/boot/result.cc
index dab82f4..2222bd5 100644
--- a/boot/result.cc
+++ b/boot/result.cc
@@ -19,8 +19,8 @@ along with GCC; see the file COPYING3. If not see
namespace elna::boot
{
- error::error(const char *path, const struct position position)
- : position(position), path(path)
+ error::error(const struct position position)
+ : position(position)
{
}
@@ -34,11 +34,6 @@ namespace elna::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;
diff --git a/boot/semantic.cc b/boot/semantic.cc
index 300c91d..29ef3c1 100644
--- a/boot/semantic.cc
+++ b/boot/semantic.cc
@@ -22,8 +22,8 @@ along with GCC; see the file COPYING3. If not see
namespace elna::boot
{
- undeclared_error::undeclared_error(const std::string& identifier, const char *path, const struct position position)
- : error(path, position), identifier(identifier)
+ undeclared_error::undeclared_error(const std::string& identifier, const struct position position)
+ : error(position), identifier(identifier)
{
}
@@ -32,9 +32,8 @@ namespace elna::boot
return "Type '" + identifier + "' not declared";
}
- already_declared_error::already_declared_error(const std::string& identifier,
- const char *path, const struct position position)
- : error(path, position), identifier(identifier)
+ already_declared_error::already_declared_error(const std::string& identifier, const struct position position)
+ : error(position), identifier(identifier)
{
}
@@ -43,9 +42,8 @@ namespace elna::boot
return "Symbol '" + identifier + "' has been already declared";
}
- field_duplication_error::field_duplication_error(const std::string& field_name,
- const char *path, const struct position position)
- : error(path, position), field_name(field_name)
+ field_duplication_error::field_duplication_error(const std::string& field_name, const struct position position)
+ : error(position), field_name(field_name)
{
}
@@ -55,8 +53,8 @@ namespace elna::boot
}
cyclic_declaration_error::cyclic_declaration_error(const std::vector<std::string>& cycle,
- const char *path, const struct position position)
- : error(path, position), cycle(cycle)
+ const struct position position)
+ : error(position), cycle(cycle)
{
}
@@ -73,8 +71,8 @@ namespace elna::boot
return message;
}
- return_error::return_error(const std::string& identifier, const char *path, const struct position position)
- : error(path, position), identifier(identifier)
+ return_error::return_error(const std::string& identifier, const struct position position)
+ : error(position), identifier(identifier)
{
}
@@ -83,8 +81,8 @@ namespace elna::boot
return "Procedure '" + identifier + "' is expected to return, but does not have a return statement";
}
- variable_initializer_error::variable_initializer_error(const char *path, const struct position position)
- : error(path, position)
+ variable_initializer_error::variable_initializer_error(const struct position position)
+ : error(position)
{
}
@@ -93,8 +91,8 @@ namespace elna::boot
return "Only one variable can be initialized";
}
- type_analysis_visitor::type_analysis_visitor(const char *path, symbol_bag bag)
- : error_container(path), bag(bag)
+ type_analysis_visitor::type_analysis_visitor(symbol_bag bag)
+ : error_container(), bag(bag)
{
}
@@ -113,7 +111,7 @@ namespace elna::boot
}
if (!this->returns)
{
- add_error<return_error>(definition->identifier.name, this->input_file, definition->position());
+ add_error<return_error>(definition->identifier.name, definition->position());
}
}
}
@@ -187,12 +185,12 @@ namespace elna::boot
if (!check_unresolved_symbol(unresolved_type, alias_path))
{
- add_error<cyclic_declaration_error>(alias_path, this->input_file, definition->position());
+ add_error<cyclic_declaration_error>(alias_path, definition->position());
}
}
- name_analysis_visitor::name_analysis_visitor(const char *path, symbol_bag bag)
- : error_container(path), bag(bag)
+ name_analysis_visitor::name_analysis_visitor(symbol_bag bag)
+ : error_container(), bag(bag)
{
}
@@ -280,7 +278,7 @@ namespace elna::boot
{
if (field_names.find(field.first) != field_names.cend())
{
- add_error<field_duplication_error>(field.first, this->input_file, field.second->position());
+ add_error<field_duplication_error>(field.first, field.second->position());
}
else
{
@@ -332,7 +330,7 @@ namespace elna::boot
if (!this->bag.enter(name, variable_symbol))
{
- add_error<already_declared_error>(name, this->input_file, position);
+ add_error<already_declared_error>(name, position);
}
return variable_symbol;
}
@@ -567,7 +565,7 @@ namespace elna::boot
}
else
{
- add_error<undeclared_error>(type_expression->name, this->input_file, type_expression->position());
+ add_error<undeclared_error>(type_expression->name, type_expression->position());
this->current_type = type();
}
}
@@ -623,8 +621,8 @@ namespace elna::boot
this->current_literal = literal->value;
}
- declaration_visitor::declaration_visitor(const char *path)
- : error_container(path)
+ declaration_visitor::declaration_visitor()
+ : error_container()
{
}
@@ -663,8 +661,7 @@ namespace elna::boot
if (!this->unresolved.insert({ type_identifier, std::make_shared<alias_type>(type_identifier) }).second)
{
- add_error<already_declared_error>(definition->identifier.name, this->input_file,
- definition->position());
+ add_error<already_declared_error>(definition->identifier.name, definition->position());
}
}
@@ -672,7 +669,7 @@ namespace elna::boot
{
if (declaration->has_initializer() && declaration->identifiers.size() > 1)
{
- add_error<variable_initializer_error>(this->input_file, declaration->position());
+ add_error<variable_initializer_error>(declaration->position());
}
}