Fix diagnostic for primitive types
This commit is contained in:
@ -19,8 +19,10 @@ along with GCC; see the file COPYING3. If not see
|
||||
|
||||
#include "elna/gcc/elna-generic.h"
|
||||
#include "elna/gcc/elna-diagnostic.h"
|
||||
#include "elna/gcc/elna1.h"
|
||||
|
||||
#include "input.h"
|
||||
#include "ggc.h"
|
||||
#include "function.h"
|
||||
#include "cgraph.h"
|
||||
#include "gimplify.h"
|
||||
#include "stringpool.h"
|
||||
@ -42,7 +44,7 @@ namespace gcc
|
||||
|
||||
void generic_visitor::visit(boot::call_expression *expression)
|
||||
{
|
||||
tree symbol = this->symbol_map->lookup(expression->name());
|
||||
tree symbol = this->lookup(expression->name());
|
||||
|
||||
if (symbol == NULL_TREE)
|
||||
{
|
||||
@ -91,13 +93,12 @@ namespace gcc
|
||||
{
|
||||
auto body_type = build_type(expression->body());
|
||||
|
||||
this->current_expression = build1(CONVERT_EXPR, this->symbol_map->lookup("Word"), size_in_bytes(body_type));
|
||||
this->current_expression = build1(CONVERT_EXPR, elna_word_type_node, size_in_bytes(body_type));
|
||||
}
|
||||
|
||||
bool generic_visitor::is_numeric_type(tree type)
|
||||
{
|
||||
return is_integral_type(type)
|
||||
|| type == this->symbol_map->lookup("Float");
|
||||
return is_integral_type(type) || type == elna_float_type_node;
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::program *program)
|
||||
@ -124,11 +125,15 @@ namespace gcc
|
||||
};
|
||||
tree declaration_type = build_function_type_array(integer_type_node, 2, parameter_types.data());
|
||||
tree fndecl = build_fn_decl("main", declaration_type);
|
||||
current_function_decl = fndecl;
|
||||
|
||||
tree resdecl = build_decl(UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node);
|
||||
DECL_CONTEXT(resdecl) = fndecl;
|
||||
DECL_RESULT(fndecl) = resdecl;
|
||||
|
||||
push_struct_function(fndecl, false);
|
||||
DECL_STRUCT_FUNCTION(fndecl)->language = ggc_cleared_alloc<language_function>();
|
||||
DECL_STRUCT_FUNCTION(fndecl)->language->binding_level = ggc_cleared_alloc<binding_level>();
|
||||
|
||||
enter_scope();
|
||||
|
||||
tree_chain argument_chain;
|
||||
@ -139,7 +144,7 @@ namespace gcc
|
||||
get_identifier(argument_name.c_str()), parameter_types[i]);
|
||||
DECL_CONTEXT(argc_declaration_tree) = fndecl;
|
||||
DECL_ARG_TYPE(argc_declaration_tree) = parameter_types[i];
|
||||
this->symbol_map->enter(argument_name, argc_declaration_tree);
|
||||
|
||||
argument_chain.append(argc_declaration_tree);
|
||||
}
|
||||
DECL_ARGUMENTS(fndecl) = argument_chain.head();
|
||||
@ -161,7 +166,7 @@ namespace gcc
|
||||
DECL_EXTERNAL(fndecl) = 0;
|
||||
DECL_PRESERVE_P(fndecl) = 1;
|
||||
|
||||
current_function_decl = NULL_TREE;
|
||||
pop_cfun();
|
||||
gimplify_function_tree(fndecl);
|
||||
cgraph_node::finalize_function(fndecl, true);
|
||||
}
|
||||
@ -260,18 +265,57 @@ namespace gcc
|
||||
return tree_symbol_mapping{ bind_expr, new_block };
|
||||
}
|
||||
|
||||
tree generic_visitor::lookup(const std::string& name)
|
||||
{
|
||||
if (name == "Int")
|
||||
{
|
||||
return elna_int_type_node;
|
||||
}
|
||||
if (name == "Word")
|
||||
{
|
||||
return elna_word_type_node;
|
||||
}
|
||||
if (name == "Char")
|
||||
{
|
||||
return elna_char_type_node;
|
||||
}
|
||||
if (name == "Bool")
|
||||
{
|
||||
return elna_bool_type_node;
|
||||
}
|
||||
if (name == "Byte")
|
||||
{
|
||||
return elna_byte_type_node;
|
||||
}
|
||||
if (name == "Float")
|
||||
{
|
||||
return elna_float_type_node;
|
||||
}
|
||||
if (name == "String")
|
||||
{
|
||||
return elna_string_type_node;
|
||||
}
|
||||
if (current_function_decl != NULL_TREE)
|
||||
{
|
||||
for (tree decl = DECL_ARGUMENTS(current_function_decl); decl; decl = DECL_CHAIN(decl))
|
||||
{
|
||||
if (name == IDENTIFIER_POINTER(DECL_NAME(decl)))
|
||||
{
|
||||
return decl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this->symbol_map->lookup(name);
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<std::int32_t> *literal)
|
||||
{
|
||||
auto symbol = this->symbol_map->lookup("Int");
|
||||
|
||||
this->current_expression = build_int_cst(symbol, literal->number());
|
||||
this->current_expression = build_int_cst(elna_int_type_node, literal->number());
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<std::uint32_t> *literal)
|
||||
{
|
||||
auto symbol = this->symbol_map->lookup("Word");
|
||||
|
||||
this->current_expression = build_int_cstu(symbol, literal->number());
|
||||
this->current_expression = build_int_cstu(elna_word_type_node, literal->number());
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<double> *literal)
|
||||
@ -291,16 +335,12 @@ namespace gcc
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<bool> *boolean)
|
||||
{
|
||||
auto symbol = this->symbol_map->lookup("Bool");
|
||||
|
||||
this->current_expression = build_int_cst_type(symbol, boolean->number());
|
||||
this->current_expression = build_int_cst_type(elna_bool_type_node, boolean->number());
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<unsigned char> *character)
|
||||
{
|
||||
auto symbol = this->symbol_map->lookup("Char");
|
||||
|
||||
this->current_expression = build_int_cstu(symbol, character->number());
|
||||
this->current_expression = build_int_cstu(elna_char_type_node, character->number());
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<nullptr_t> *)
|
||||
@ -310,11 +350,8 @@ namespace gcc
|
||||
|
||||
void generic_visitor::visit(boot::number_literal<std::string> *string)
|
||||
{
|
||||
tree index_type = this->symbol_map->lookup("Word");
|
||||
tree index_constant = build_int_cstu(index_type, string->number().size());
|
||||
tree element_type = this->symbol_map->lookup("Char");
|
||||
tree string_type = build_array_type(element_type, build_index_type(index_constant));
|
||||
tree string_record = this->symbol_map->lookup("String");
|
||||
tree index_constant = build_int_cstu(elna_word_type_node, string->number().size());
|
||||
tree string_type = build_array_type(elna_char_type_node, build_index_type(index_constant));
|
||||
|
||||
tree string_literal = build_string(string->number().size(), string->number().c_str());
|
||||
TREE_TYPE(string_literal) = string_type;
|
||||
@ -322,15 +359,16 @@ namespace gcc
|
||||
TREE_READONLY(string_literal) = 1;
|
||||
TREE_STATIC(string_literal) = 1;
|
||||
|
||||
string_type = TREE_TYPE(TREE_CHAIN(TYPE_FIELDS(string_record)));
|
||||
string_literal = build4(ARRAY_REF, element_type, string_literal, integer_zero_node, NULL_TREE, NULL_TREE);
|
||||
string_type = TREE_TYPE(TREE_CHAIN(TYPE_FIELDS(elna_string_type_node)));
|
||||
string_literal = build4(ARRAY_REF, elna_char_type_node,
|
||||
string_literal, integer_zero_node, NULL_TREE, NULL_TREE);
|
||||
string_literal = build1(ADDR_EXPR, string_type, string_literal);
|
||||
|
||||
vec<constructor_elt, va_gc> *elms = NULL;
|
||||
CONSTRUCTOR_APPEND_ELT(elms, TYPE_FIELDS(string_record), index_constant);
|
||||
CONSTRUCTOR_APPEND_ELT(elms, TREE_CHAIN(TYPE_FIELDS(string_record)), string_literal);
|
||||
CONSTRUCTOR_APPEND_ELT(elms, TYPE_FIELDS(elna_string_type_node), index_constant);
|
||||
CONSTRUCTOR_APPEND_ELT(elms, TREE_CHAIN(TYPE_FIELDS(elna_string_type_node)), string_literal);
|
||||
|
||||
this->current_expression = build_constructor(string_record, elms);
|
||||
this->current_expression = build_constructor(elna_string_type_node, elms);
|
||||
}
|
||||
|
||||
tree generic_visitor::build_arithmetic_operation(boot::binary_expression *expression,
|
||||
@ -344,23 +382,21 @@ namespace gcc
|
||||
tree_code operator_code, tree left, tree right)
|
||||
{
|
||||
return build_binary_operation(is_numeric_type(TREE_TYPE(left)) || is_pointer_type(TREE_TYPE(left)),
|
||||
expression, operator_code, left, right, this->symbol_map->lookup("Bool"));
|
||||
expression, operator_code, left, right, elna_bool_type_node);
|
||||
}
|
||||
|
||||
tree generic_visitor::build_logic_operation(boot::binary_expression *expression,
|
||||
tree_code operator_code, tree left, tree right)
|
||||
{
|
||||
auto symbol = this->symbol_map->lookup("Bool");
|
||||
|
||||
return build_binary_operation(TREE_TYPE(left) == symbol,
|
||||
expression, operator_code, left, right, symbol);
|
||||
return build_binary_operation(TREE_TYPE(left) == elna_bool_type_node,
|
||||
expression, operator_code, left, right, elna_bool_type_node);
|
||||
}
|
||||
|
||||
tree generic_visitor::build_equality_operation(boot::binary_expression *expression,
|
||||
tree_code operator_code, tree left, tree right)
|
||||
{
|
||||
return build_binary_operation(true, expression,
|
||||
operator_code, left, right, this->symbol_map->lookup("Bool"));
|
||||
operator_code, left, right, elna_bool_type_node);
|
||||
}
|
||||
|
||||
void generic_visitor::visit(boot::binary_expression *expression)
|
||||
@ -388,7 +424,7 @@ namespace gcc
|
||||
}
|
||||
else if (TREE_TYPE(this->current_expression) == ssizetype)
|
||||
{
|
||||
this->current_expression = fold_convert(this->symbol_map->lookup("Int"), this->current_expression);
|
||||
this->current_expression = fold_convert(elna_int_type_node, this->current_expression);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -524,7 +560,7 @@ namespace gcc
|
||||
{
|
||||
if (boot::basic_type_expression *basic_type = type.is_basic())
|
||||
{
|
||||
tree symbol = this->symbol_map->lookup(basic_type->base_name());
|
||||
tree symbol = this->lookup(basic_type->base_name());
|
||||
|
||||
if (symbol != NULL_TREE && TYPE_P(symbol))
|
||||
{
|
||||
@ -654,7 +690,7 @@ namespace gcc
|
||||
|
||||
void generic_visitor::visit(boot::variable_expression *expression)
|
||||
{
|
||||
auto symbol = this->symbol_map->lookup(expression->name());
|
||||
auto symbol = this->lookup(expression->name());
|
||||
|
||||
if (symbol == NULL_TREE)
|
||||
{
|
||||
|
Reference in New Issue
Block a user