Handle array variable declaration
This commit is contained in:
@ -282,37 +282,56 @@ namespace gcc
|
||||
this->current_expression = NULL_TREE;
|
||||
}
|
||||
|
||||
tree generic_visitor::build_type(source::type_expression& type)
|
||||
{
|
||||
if (source::basic_type_expression *basic_type = type.is_basic())
|
||||
{
|
||||
if (basic_type->base_name() == "Int")
|
||||
{
|
||||
return integer_type_node;
|
||||
}
|
||||
else if (basic_type->base_name() == "Bool")
|
||||
{
|
||||
return boolean_type_node;
|
||||
}
|
||||
else if (basic_type->base_name() == "Float")
|
||||
{
|
||||
return double_type_node;
|
||||
}
|
||||
else if (basic_type->base_name() == "Char")
|
||||
{
|
||||
return elna_char_type_node;
|
||||
}
|
||||
else if (basic_type->base_name() == "String")
|
||||
{
|
||||
return elna_string_type_node;
|
||||
}
|
||||
}
|
||||
else if (source::array_type_expression *array_type = type.is_array())
|
||||
{
|
||||
tree lower_bound = build_int_cst_type(integer_type_node, 0);
|
||||
tree upper_bound = build_int_cst_type(integer_type_node, array_type->size);
|
||||
tree base_type = build_type(array_type->base());
|
||||
|
||||
if (base_type == NULL_TREE)
|
||||
{
|
||||
return NULL_TREE;
|
||||
}
|
||||
tree range_type = build_range_type(integer_type_node, lower_bound, upper_bound);
|
||||
|
||||
return build_array_type(base_type, range_type);
|
||||
}
|
||||
return NULL_TREE;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(source::declaration *declaration)
|
||||
{
|
||||
tree declaration_type = error_mark_node;
|
||||
source::basic_type_expression *basic_type = declaration->type().is_basic();
|
||||
tree declaration_type = build_type(declaration->type());
|
||||
|
||||
gcc_assert(basic_type != nullptr);
|
||||
|
||||
if (basic_type->base() == "Int")
|
||||
{
|
||||
declaration_type = integer_type_node;
|
||||
}
|
||||
else if (basic_type->base() == "Bool")
|
||||
{
|
||||
declaration_type = boolean_type_node;
|
||||
}
|
||||
else if (basic_type->base() == "Float")
|
||||
{
|
||||
declaration_type = double_type_node;
|
||||
}
|
||||
else if (basic_type->base() == "Char")
|
||||
{
|
||||
declaration_type = elna_char_type_node;
|
||||
}
|
||||
else if (basic_type->base() == "String")
|
||||
{
|
||||
declaration_type = elna_string_type_node;
|
||||
}
|
||||
else
|
||||
if (declaration_type == NULL_TREE)
|
||||
{
|
||||
error_at(get_location(&declaration->type().position()),
|
||||
"type '%s' not declared", basic_type->base().c_str());
|
||||
"type '%s' not declared", declaration->type().base_name().c_str());
|
||||
return;
|
||||
}
|
||||
auto declaration_location = get_location(&declaration->position());
|
||||
|
Reference in New Issue
Block a user