Set STUB_DECL for unique types
This commit is contained in:
parent
09ad85b058
commit
a02e053ed2
@ -50,15 +50,16 @@ namespace elna::gcc
|
||||
}
|
||||
|
||||
static
|
||||
void declare_builtin_type(std::shared_ptr<symbol_table> symbol_table, const char *name, tree type)
|
||||
tree declare_builtin_type(std::shared_ptr<symbol_table> symbol_table, const char *name, tree type)
|
||||
{
|
||||
tree identifier = get_identifier(name);
|
||||
tree type_declaration = build_decl(UNKNOWN_LOCATION, TYPE_DECL, identifier, type);
|
||||
|
||||
TREE_PUBLIC(type_declaration) = 1;
|
||||
TYPE_NAME(type_declaration) = identifier;
|
||||
|
||||
symbol_table->enter(name, type_declaration);
|
||||
|
||||
return type_declaration;
|
||||
}
|
||||
|
||||
std::shared_ptr<symbol_table> builtin_symbol_table()
|
||||
@ -71,7 +72,10 @@ namespace elna::gcc
|
||||
declare_builtin_type(symbol_table, "Bool", elna_bool_type_node);
|
||||
declare_builtin_type(symbol_table, "Byte", elna_byte_type_node);
|
||||
declare_builtin_type(symbol_table, "Float", elna_float_type_node);
|
||||
declare_builtin_type(symbol_table, "String", elna_string_type_node);
|
||||
|
||||
tree string_declaration = declare_builtin_type(symbol_table, "String", elna_string_type_node);
|
||||
TYPE_NAME(elna_string_type_node) = DECL_NAME(string_declaration);
|
||||
TYPE_STUB_DECL(elna_string_type_node) = string_declaration;
|
||||
|
||||
return symbol_table;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ namespace elna::gcc
|
||||
gcc_assert(TYPE_P(type));
|
||||
|
||||
tree unqualified_type = get_qualified_type(type, TYPE_UNQUALIFIED);
|
||||
tree_code code = TREE_CODE(type);
|
||||
|
||||
if (unqualified_type == elna_int_type_node)
|
||||
{
|
||||
@ -91,7 +92,7 @@ namespace elna::gcc
|
||||
return std::string("^" + print_type(pointer_target_type));
|
||||
}
|
||||
}
|
||||
else if (TREE_CODE(type) == FUNCTION_TYPE)
|
||||
else if (code == FUNCTION_TYPE)
|
||||
{
|
||||
std::string output = "proc(";
|
||||
tree parameter_type = TYPE_ARG_TYPES(type);
|
||||
@ -117,19 +118,19 @@ namespace elna::gcc
|
||||
}
|
||||
return output;
|
||||
}
|
||||
else if (is_array_type(unqualified_type))
|
||||
else if (code == ARRAY_TYPE)
|
||||
{
|
||||
return "array";
|
||||
}
|
||||
else if (TREE_CODE(type) == RECORD_TYPE)
|
||||
else if (code == RECORD_TYPE)
|
||||
{
|
||||
return print_aggregate_name(unqualified_type, "record");
|
||||
}
|
||||
else if (TREE_CODE(type) == UNION_TYPE)
|
||||
else if (code == UNION_TYPE)
|
||||
{
|
||||
return print_aggregate_name(unqualified_type, "union");
|
||||
}
|
||||
else if (TREE_CODE(type) == ENUMERAL_TYPE)
|
||||
else if (code == ENUMERAL_TYPE)
|
||||
{
|
||||
return print_aggregate_name(unqualified_type, "enumeration");
|
||||
}
|
||||
|
@ -862,8 +862,15 @@ namespace elna::gcc
|
||||
get_identifier(definition->identifier.identifier.c_str()), this->current_expression);
|
||||
|
||||
TREE_PUBLIC(definition_tree) = definition->identifier.exported;
|
||||
TYPE_NAME(this->current_expression) = get_identifier(definition->identifier.identifier.c_str());
|
||||
|
||||
if (is_unique_type(this->current_expression))
|
||||
{
|
||||
TYPE_NAME(this->current_expression) = DECL_NAME(definition_tree);
|
||||
TYPE_STUB_DECL(this->current_expression) = definition_tree;
|
||||
}
|
||||
else
|
||||
{
|
||||
TYPE_NAME(this->current_expression) = definition_tree;
|
||||
}
|
||||
auto result = this->symbols->enter(definition->identifier.identifier, definition_tree);
|
||||
gcc_assert(result);
|
||||
|
||||
@ -993,7 +1000,7 @@ namespace elna::gcc
|
||||
}
|
||||
tree offset = build2(MINUS_EXPR, elna_word_type_node, this->current_expression, size_one_node);
|
||||
|
||||
if (is_array_type(TREE_TYPE(designator)))
|
||||
if (TREE_CODE(TREE_TYPE(designator)) == ARRAY_TYPE)
|
||||
{
|
||||
tree element_type = TREE_TYPE(TREE_TYPE(designator));
|
||||
|
||||
@ -1127,12 +1134,12 @@ namespace elna::gcc
|
||||
location_t expression_location = get_location(&expression->position());
|
||||
tree aggregate_type = TREE_TYPE(this->current_expression);
|
||||
|
||||
if (is_array_type(aggregate_type) && expression->field() == "length")
|
||||
if (TREE_CODE(aggregate_type) == ARRAY_TYPE && expression->field() == "length")
|
||||
{
|
||||
this->current_expression = convert(build_qualified_type(elna_word_type_node, TYPE_QUAL_CONST),
|
||||
TYPE_MAX_VALUE(TYPE_DOMAIN(aggregate_type)));
|
||||
}
|
||||
else if (is_array_type(aggregate_type) && expression->field() == "ptr")
|
||||
else if (TREE_CODE(aggregate_type) == ARRAY_TYPE && expression->field() == "ptr")
|
||||
{
|
||||
tree ptr_type = build_global_pointer_type(TREE_TYPE(aggregate_type));
|
||||
this->current_expression = build1(ADDR_EXPR,
|
||||
|
@ -37,10 +37,10 @@ namespace elna::gcc
|
||||
return is_integral_type(type) || type == elna_float_type_node;
|
||||
}
|
||||
|
||||
bool is_array_type(tree type)
|
||||
bool is_unique_type(tree type)
|
||||
{
|
||||
gcc_assert(TYPE_P(type));
|
||||
return TREE_CODE(type) == ARRAY_TYPE;
|
||||
return RECORD_OR_UNION_TYPE_P(type) || TREE_CODE(type) == ENUMERAL_TYPE;
|
||||
}
|
||||
|
||||
bool is_void_type(tree type)
|
||||
|
@ -36,7 +36,7 @@ namespace elna::gcc
|
||||
|
||||
bool is_integral_type(tree type);
|
||||
bool is_numeric_type(tree type);
|
||||
bool is_array_type(tree type);
|
||||
bool is_unique_type(tree type);
|
||||
bool is_void_type(tree type);
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user