Unify the build_type function
This commit is contained in:
@ -464,7 +464,8 @@ namespace boot
|
||||
return *m_base;
|
||||
}
|
||||
|
||||
record_type_expression::record_type_expression(const struct position position, fields_t&& fields)
|
||||
record_type_expression::record_type_expression(const struct position position,
|
||||
std::vector<field_declaration>&& fields)
|
||||
: type_expression(position), fields(std::move(fields))
|
||||
{
|
||||
}
|
||||
@ -479,7 +480,8 @@ namespace boot
|
||||
return std::static_pointer_cast<record_type_expression>(shared_from_this());
|
||||
}
|
||||
|
||||
union_type_expression::union_type_expression(const struct position position, fields_t&& fields)
|
||||
union_type_expression::union_type_expression(const struct position position,
|
||||
std::vector<field_declaration>&& fields)
|
||||
: type_expression(position), fields(std::move(fields))
|
||||
{
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ along with GCC; see the file COPYING3. If not see
|
||||
%type <elna::boot::type_definition *> type_definition;
|
||||
%type <std::vector<elna::boot::type_definition *>> type_definitions type_part;
|
||||
%type <elna::boot::block *> block;
|
||||
%type <elna::boot::field_t> field_declaration;
|
||||
%type <elna::boot::field_declaration> field_declaration;
|
||||
%type <std::vector<std::pair<std::string, std::shared_ptr<elna::boot::type_expression>>>>
|
||||
optional_fields required_fields;
|
||||
%type <std::vector<elna::boot::conditional_statements *>> elsif_then_statements elsif_do_statements;
|
||||
|
@ -69,5 +69,66 @@ namespace boot
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(program *program)
|
||||
{
|
||||
for (type_definition *const type : program->types)
|
||||
{
|
||||
this->unresolved.insert({ type->identifier, new alias_type() });
|
||||
}
|
||||
for (type_definition *const type : program->types)
|
||||
{
|
||||
type->accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(type_definition *definition)
|
||||
{
|
||||
auto unresolved_declaration = this->unresolved.at(definition->identifier);
|
||||
|
||||
definition->body().accept(this);
|
||||
|
||||
if (this->current_type != nullptr)
|
||||
{
|
||||
unresolved_declaration->reference = this->current_type;
|
||||
}
|
||||
this->current_type = nullptr;
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(primitive_type_expression *type)
|
||||
{
|
||||
auto unresolved_alias = this->unresolved.find(type->name);
|
||||
|
||||
if (unresolved_alias != this->unresolved.end())
|
||||
{
|
||||
this->current_type = unresolved_alias->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->current_type = new primitive_type(type->name);
|
||||
}
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(array_type_expression *type)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(pointer_type_expression *type)
|
||||
{
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(record_type_expression *type)
|
||||
{
|
||||
this->current_type = new record_type();
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(union_type_expression *type)
|
||||
{
|
||||
this->current_type = new union_type();
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(procedure_type_expression *type)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user