Rename AST types to type expressions
This commit is contained in:
@ -180,6 +180,23 @@ namespace gcc
|
||||
constant->accept(this);
|
||||
}
|
||||
for (boot::type_definition *const type : program->types)
|
||||
{
|
||||
tree type_node = NULL_TREE;
|
||||
|
||||
if (type->body().is_record())
|
||||
{
|
||||
type_node = make_node(RECORD_TYPE);
|
||||
}
|
||||
else if (type->body().is_union())
|
||||
{
|
||||
type_node = make_node(UNION_TYPE);
|
||||
}
|
||||
if (type_node != NULL_TREE)
|
||||
{
|
||||
this->symbol_map->enter(type->identifier, type_node);
|
||||
}
|
||||
}
|
||||
for (boot::type_definition *const type : program->types)
|
||||
{
|
||||
type->accept(this);
|
||||
}
|
||||
@ -731,33 +748,34 @@ namespace gcc
|
||||
void generic_visitor::visit(boot::type_definition *definition)
|
||||
{
|
||||
location_t definition_location = get_location(&definition->position());
|
||||
this->current_expression = this->symbol_map->lookup(definition->identifier);
|
||||
definition->body().accept(this);
|
||||
|
||||
tree definition_tree = build_decl(definition_location, TYPE_DECL,
|
||||
get_identifier(definition->identifier.c_str()), this->current_expression);
|
||||
auto result = this->symbol_map->enter(definition->identifier, this->current_expression);
|
||||
|
||||
if (result)
|
||||
{
|
||||
/* if (result)
|
||||
{ */
|
||||
TREE_PUBLIC(definition_tree) = definition->exported;
|
||||
TYPE_NAME(this->current_expression) = get_identifier(definition->identifier.c_str());
|
||||
}
|
||||
else
|
||||
// }
|
||||
/* else
|
||||
{
|
||||
error_at(get_location(&definition->position()),
|
||||
"type '%s' already declared in this scope",
|
||||
definition->identifier.c_str());
|
||||
}
|
||||
} */
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
|
||||
tree generic_visitor::build_procedure_type(boot::procedure_type& type)
|
||||
tree generic_visitor::build_procedure_type(boot::procedure_type_expression& type)
|
||||
{
|
||||
std::vector<tree> parameter_types(type.parameters.size());
|
||||
|
||||
for (std::size_t i = 0; i < type.parameters.size(); ++i)
|
||||
{
|
||||
boot::top_type& parameter_type = type.parameters.at(i)->variable_type();
|
||||
boot::type_expression& parameter_type = type.parameters.at(i)->variable_type();
|
||||
parameter_type.accept(this);
|
||||
parameter_types[i] = this->current_expression;
|
||||
}
|
||||
@ -1102,14 +1120,14 @@ namespace gcc
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::basic_type *type)
|
||||
void generic_visitor::visit(boot::primitive_type_expression *type)
|
||||
{
|
||||
tree symbol = this->lookup(type->base_name());
|
||||
tree symbol = this->lookup(type->name);
|
||||
|
||||
if (symbol == NULL_TREE && TYPE_P(symbol))
|
||||
{
|
||||
error_at(get_location(&type->position()),
|
||||
"type '%s' not declared", type->base_name().c_str());
|
||||
"type '%s' not declared", type->name.c_str());
|
||||
|
||||
this->current_expression = error_mark_node;
|
||||
}
|
||||
@ -1119,7 +1137,7 @@ namespace gcc
|
||||
}
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::array_type *type)
|
||||
void generic_visitor::visit(boot::array_type_expression *type)
|
||||
{
|
||||
tree lower_bound = build_int_cst_type(integer_type_node, 0);
|
||||
tree upper_bound = build_int_cst_type(integer_type_node, type->size);
|
||||
@ -1133,7 +1151,7 @@ namespace gcc
|
||||
}
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::pointer_type *type)
|
||||
void generic_visitor::visit(boot::pointer_type_expression *type)
|
||||
{
|
||||
type->base().accept(this);
|
||||
|
||||
@ -1143,10 +1161,12 @@ namespace gcc
|
||||
}
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::record_type *type)
|
||||
void generic_visitor::visit(boot::record_type_expression *type)
|
||||
{
|
||||
std::set<std::string> field_names;
|
||||
tree record_type_node = make_node(RECORD_TYPE);
|
||||
tree record_type_node = this->current_expression == NULL_TREE
|
||||
? make_node(RECORD_TYPE)
|
||||
: this->current_expression;
|
||||
|
||||
for (auto& field : type->fields)
|
||||
{
|
||||
@ -1166,16 +1186,19 @@ namespace gcc
|
||||
tree field_declaration = build_field(get_location(&field.second->position()),
|
||||
record_type_node, field.first, this->current_expression);
|
||||
TYPE_FIELDS(record_type_node) = chainon(TYPE_FIELDS(record_type_node), field_declaration);
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
layout_type(record_type_node);
|
||||
|
||||
this->current_expression = record_type_node;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::union_type *type)
|
||||
void generic_visitor::visit(boot::union_type_expression *type)
|
||||
{
|
||||
std::set<std::string> field_names;
|
||||
tree union_type_node = make_node(UNION_TYPE);
|
||||
tree union_type_node = this->current_expression == NULL_TREE
|
||||
? make_node(UNION_TYPE)
|
||||
: this->current_expression;
|
||||
|
||||
for (auto& field : type->fields)
|
||||
{
|
||||
@ -1195,13 +1218,14 @@ namespace gcc
|
||||
tree field_declaration = build_field(get_location(&field.second->position()),
|
||||
union_type_node, field.first, this->current_expression);
|
||||
TYPE_FIELDS(union_type_node) = chainon(TYPE_FIELDS(union_type_node), field_declaration);
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
layout_type(union_type_node);
|
||||
|
||||
this->current_expression = union_type_node;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::procedure_type *type)
|
||||
void generic_visitor::visit(boot::procedure_type_expression *type)
|
||||
{
|
||||
tree procedure_type_node = build_procedure_type(*type);
|
||||
this->current_expression = build_pointer_type_for_mode(procedure_type_node, VOIDmode, true);
|
||||
|
Reference in New Issue
Block a user