Remove type visiting in generic visitor
This commit is contained in:
185
boot/ast.cc
185
boot/ast.cc
@@ -19,6 +19,191 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
namespace elna::boot
|
||||
{
|
||||
void empty_visitor::not_implemented()
|
||||
{
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(named_type_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(array_type_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(pointer_type_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(program *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(type_declaration *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(record_type_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(union_type_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(procedure_type_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(enumeration_type_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(variable_declaration *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(constant_declaration *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(procedure_declaration *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(assign_statement *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(if_statement *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(import_declaration *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(while_statement *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(return_statement *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(defer_statement *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(case_statement *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(procedure_call *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(unit *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(cast_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(traits_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(binary_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(unary_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(variable_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(array_access_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(field_access_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(dereference_expression *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(literal<std::int32_t> *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(literal<std::uint32_t> *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(literal<double> *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(literal<bool> *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(literal<unsigned char> *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(literal<std::nullptr_t> *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
void empty_visitor::visit(literal<std::string> *)
|
||||
{
|
||||
not_implemented();
|
||||
}
|
||||
|
||||
node::node(const struct position position)
|
||||
: source_position(position)
|
||||
{
|
||||
|
@@ -32,7 +32,7 @@ namespace elna::boot
|
||||
{
|
||||
}
|
||||
|
||||
dependency read_sources(std::istream& entry_point, const char *entry_path)
|
||||
dependency read_source(std::istream& entry_point, const char *entry_path)
|
||||
{
|
||||
driver parse_driver{ entry_path };
|
||||
lexer tokenizer(entry_point);
|
||||
@@ -60,6 +60,25 @@ namespace elna::boot
|
||||
return outcome;
|
||||
}
|
||||
|
||||
error_list analyze_semantics(const char *path, std::unique_ptr<unit>& tree, symbol_bag bag)
|
||||
{
|
||||
name_analysis_visitor name_analyser(path, bag);
|
||||
tree->accept(&name_analyser);
|
||||
|
||||
if (name_analyser.has_errors())
|
||||
{
|
||||
return std::move(name_analyser.errors());
|
||||
}
|
||||
type_analysis_visitor type_analyzer(path);
|
||||
tree->accept(&type_analyzer);
|
||||
|
||||
if (type_analyzer.has_errors())
|
||||
{
|
||||
return std::move(type_analyzer.errors());
|
||||
}
|
||||
return error_list{};
|
||||
}
|
||||
|
||||
std::filesystem::path build_path(const std::vector<std::string>& segments)
|
||||
{
|
||||
std::filesystem::path result;
|
||||
|
210
boot/semantic.cc
210
boot/semantic.cc
@@ -32,7 +32,6 @@ 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)
|
||||
@@ -74,6 +73,83 @@ 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)
|
||||
{
|
||||
}
|
||||
|
||||
std::string return_error::what() const
|
||||
{
|
||||
return "Procedure '" + identifier + "' is expected to return, but does not have a return statement";
|
||||
}
|
||||
|
||||
type_analysis_visitor::type_analysis_visitor(const char *path)
|
||||
: error_container(path)
|
||||
{
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(program *program)
|
||||
{
|
||||
visit(static_cast<unit *>(program));
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(procedure_declaration *definition)
|
||||
{
|
||||
if (definition->body.has_value() && definition->heading().return_type.proper_type != nullptr)
|
||||
{
|
||||
for (statement *const statement : definition->body.value().body())
|
||||
{
|
||||
statement->accept(this);
|
||||
}
|
||||
if (!this->returns)
|
||||
{
|
||||
add_error<return_error>(definition->identifier.identifier, this->input_file, definition->position());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(assign_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(if_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(import_declaration *)
|
||||
{
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(while_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(return_statement *)
|
||||
{
|
||||
this->returns = true;
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(defer_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(case_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(procedure_call *)
|
||||
{
|
||||
}
|
||||
|
||||
void type_analysis_visitor::visit(unit *unit)
|
||||
{
|
||||
for (procedure_declaration *const procedure : unit->procedures)
|
||||
{
|
||||
this->returns = false;
|
||||
procedure->accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
name_analysis_visitor::name_analysis_visitor(const char *path, symbol_bag bag)
|
||||
: error_container(path), bag(bag)
|
||||
{
|
||||
@@ -484,87 +560,15 @@ namespace elna::boot
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(named_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(array_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(pointer_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(program *program)
|
||||
{
|
||||
visit(static_cast<unit *>(program));
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(type_declaration *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(record_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(union_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(procedure_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(enumeration_type_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(variable_declaration *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(constant_declaration *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(procedure_declaration *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(assign_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(if_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(import_declaration *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(while_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(return_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(defer_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(case_statement *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(procedure_call *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(unit *unit)
|
||||
{
|
||||
for (import_declaration *const _import : unit->imports)
|
||||
@@ -581,64 +585,4 @@ namespace elna::boot
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(cast_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(traits_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(binary_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(unary_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(variable_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(array_access_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(field_access_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(dereference_expression *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(literal<std::int32_t> *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(literal<std::uint32_t> *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(literal<double> *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(literal<bool> *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(literal<unsigned char> *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(literal<std::nullptr_t> *)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(literal<std::string> *)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user