Add a char type

This commit is contained in:
2025-01-01 23:02:19 +01:00
parent 8176da5f9b
commit 45eb6a3b84
10 changed files with 70 additions and 25 deletions

View File

@ -28,6 +28,10 @@ namespace gcc
{
return "Float";
}
else if (type == elna_char_type_node)
{
return "Char";
}
else
{
return "<<unknown-type>>";

View File

@ -42,6 +42,10 @@ namespace gcc
{
format_number = "%f\n";
}
else if (argument_type == elna_char_type_node)
{
format_number = "%c\n";
}
else
{
error_at(get_location(&argument->position()),
@ -125,9 +129,14 @@ namespace gcc
mpfr_clear(number);
}
void generic_visitor::visit(source::boolean_literal *literal)
void generic_visitor::visit(source::number_literal<bool> *boolean)
{
this->current_expression = build_int_cst_type(boolean_type_node, literal->boolean());
this->current_expression = build_int_cst_type(boolean_type_node, boolean->number());
}
void generic_visitor::visit(source::char_literal *character)
{
this->current_expression = build_int_cstu(elna_char_type_node, character->character());
}
void generic_visitor::visit(source::binary_expression *expression)
@ -262,6 +271,10 @@ namespace gcc
{
declaration_type = double_type_node;
}
else if (declaration->type().base() == "Char")
{
declaration_type = elna_char_type_node;
}
else
{
error_at(get_location(&declaration->type().position()),

View File

@ -1,3 +1,11 @@
#include "elna/gcc/elna-tree.h"
#include "stor-layout.h"
tree elna_global_trees[ELNA_TI_MAX];
void elna_init_ttree(void)
{
elna_char_type_node = make_unsigned_type(8);
TYPE_STRING_FLAG(elna_char_type_node) = 1;
}

View File

@ -66,7 +66,7 @@ struct GTY (()) language_function
static bool elna_langhook_init(void)
{
build_common_tree_nodes(false);
enumeral_node = make_node(ENUMERAL_TYPE);
elna_init_ttree();
/* I don't know why this has to be done explicitly. */
void_list_node = build_tree_list(NULL_TREE, void_type_node);