Randomize type declaration order
This commit is contained in:
@ -21,16 +21,28 @@ namespace elna
|
||||
{
|
||||
namespace boot
|
||||
{
|
||||
declaration_error::declaration_error(const std::string& identifier, const char *path, const struct position position)
|
||||
undeclared_error::undeclared_error(const std::string& identifier, const char *path, const struct position position)
|
||||
: error(path, position), identifier(identifier)
|
||||
{
|
||||
}
|
||||
|
||||
std::string declaration_error::what() const
|
||||
std::string undeclared_error::what() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
std::string already_declared_error::what() const
|
||||
{
|
||||
return "Symbol '" + identifier + "' has been already declared";
|
||||
}
|
||||
|
||||
declaration_visitor::declaration_visitor(const char *path, std::shared_ptr<symbol_table> symbols)
|
||||
: error_container(path), symbols(symbols)
|
||||
{
|
||||
@ -40,7 +52,10 @@ namespace boot
|
||||
{
|
||||
for (type_definition *const type : program->types)
|
||||
{
|
||||
this->unresolved.insert({ type->identifier, std::make_shared<alias_type>() });
|
||||
if (!this->unresolved.insert({ type->identifier, std::make_shared<alias_type>() }).second)
|
||||
{
|
||||
add_error<already_declared_error>(type->identifier, this->input_file, type->position());
|
||||
}
|
||||
}
|
||||
for (type_definition *const type : program->types)
|
||||
{
|
||||
@ -64,11 +79,14 @@ namespace boot
|
||||
{
|
||||
this->current_type = type(unresolved_alias->second);
|
||||
}
|
||||
else if (auto from_symbol_table = this->symbols.lookup(type_expression->name))
|
||||
{
|
||||
this->current_type = from_symbol_table->is_type()->symbol;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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));
|
||||
add_error<undeclared_error>(type_expression->name, this->input_file, type_expression->position());
|
||||
this->current_type = type();
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,8 +109,10 @@ namespace boot
|
||||
for (auto& field : type_expression->fields)
|
||||
{
|
||||
field.second->accept(this);
|
||||
|
||||
type_definition->fields.push_back({ field.first, type(this->current_type) });
|
||||
if (!this->current_type.empty())
|
||||
{
|
||||
type_definition->fields.push_back({ field.first, type(this->current_type) });
|
||||
}
|
||||
}
|
||||
this->current_type = type(type_definition);
|
||||
}
|
||||
|
Reference in New Issue
Block a user