Detect type aliasing cycles
This commit is contained in:
12
boot/ast.cc
12
boot/ast.cc
@ -264,18 +264,8 @@ namespace elna::boot
|
||||
delete m_body;
|
||||
}
|
||||
|
||||
return_declaration::return_declaration(std::shared_ptr<type_expression> type)
|
||||
: type(type)
|
||||
{
|
||||
}
|
||||
|
||||
return_declaration::return_declaration(std::monostate)
|
||||
: no_return(true)
|
||||
{
|
||||
}
|
||||
|
||||
procedure_type_expression::procedure_type_expression(const struct position position,
|
||||
return_declaration return_type)
|
||||
return_declaration<std::shared_ptr<type_expression>> return_type)
|
||||
: type_expression(position), return_type(return_type)
|
||||
{
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
%type <std::vector<elna::boot::statement *>> statements;
|
||||
%type <elna::boot::procedure_definition *> procedure_definition;
|
||||
%type <std::pair<std::vector<std::string>, std::shared_ptr<elna::boot::procedure_type_expression>>> procedure_heading;
|
||||
%type <elna::boot::return_declaration> return_declaration;
|
||||
%type <elna::boot::procedure_type_expression::return_t> return_declaration;
|
||||
%type <std::vector<elna::boot::procedure_definition *>> procedure_definitions procedure_part;
|
||||
%type <elna::boot::type_definition *> type_definition;
|
||||
%type <std::vector<elna::boot::type_definition *>> type_definitions type_part;
|
||||
@ -197,8 +197,8 @@ identifier_definitions:
|
||||
| identifier_definition { $$.emplace_back(std::move($1)); }
|
||||
return_declaration:
|
||||
/* proper procedure */ {}
|
||||
| "->" "!" { $$ = boot::return_declaration(std::monostate{}); }
|
||||
| "->" type_expression { $$ = boot::return_declaration($2); }
|
||||
| "->" "!" { $$ = boot::procedure_type_expression::return_t(std::monostate{}); }
|
||||
| "->" type_expression { $$ = boot::procedure_type_expression::return_t($2); }
|
||||
procedure_heading:
|
||||
"(" formal_parameters ")" return_declaration
|
||||
{
|
||||
|
@ -142,8 +142,28 @@ namespace elna::boot
|
||||
this->current_type = type(result_type);
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(procedure_type_expression *)
|
||||
void declaration_visitor::visit(procedure_type_expression *type_expression)
|
||||
{
|
||||
std::shared_ptr<procedure_type> result_type;
|
||||
|
||||
if (type_expression->return_type.no_return)
|
||||
{
|
||||
result_type = std::make_shared<procedure_type>(procedure_type::return_t(std::monostate{}));
|
||||
}
|
||||
else if (type_expression->return_type.proper_type != nullptr)
|
||||
{
|
||||
type_expression->return_type.proper_type->accept(this);
|
||||
result_type = std::make_shared<procedure_type>(procedure_type::return_t(this->current_type));
|
||||
}
|
||||
else
|
||||
{
|
||||
result_type = std::make_shared<procedure_type>(procedure_type::return_t());
|
||||
}
|
||||
for (auto& parameter : type_expression->parameters)
|
||||
{
|
||||
parameter->accept(this);
|
||||
result_type->parameters.push_back(this->current_type);
|
||||
}
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(variable_declaration *declaration)
|
||||
@ -161,9 +181,9 @@ namespace elna::boot
|
||||
{
|
||||
heading_parameter->accept(this);
|
||||
}
|
||||
if (definition->heading().return_type.type != nullptr)
|
||||
if (definition->heading().return_type.proper_type != nullptr)
|
||||
{
|
||||
definition->heading().return_type.type->accept(this);
|
||||
definition->heading().return_type.proper_type->accept(this);
|
||||
}
|
||||
if (definition->body != nullptr)
|
||||
{
|
||||
|
@ -135,6 +135,11 @@ namespace elna::boot
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool type::operator==(const std::nullptr_t&)
|
||||
{
|
||||
return empty();
|
||||
}
|
||||
|
||||
type::~type()
|
||||
{
|
||||
switch (tag)
|
||||
@ -265,6 +270,11 @@ namespace elna::boot
|
||||
{
|
||||
}
|
||||
|
||||
procedure_type::procedure_type(return_t return_type)
|
||||
: return_type(return_type)
|
||||
{
|
||||
}
|
||||
|
||||
info::~info()
|
||||
{
|
||||
}
|
||||
|
Reference in New Issue
Block a user