aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-26 19:47:59 +0200
committerEugen Wissner <belka@caraus.de>2026-07-26 19:47:59 +0200
commit5cdaceb77af6a1d98145f8afb34ce6884e21a3d6 (patch)
tree1f75fa1aeee67a72017dbaa2fb006e93c943700d /gcc
parentdea1c177cd3592cc24fd15ad446a676da2e4da28 (diff)
downloadelna-5cdaceb77af6a1d98145f8afb34ce6884e21a3d6.tar.gz
Type check traits properly
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gcc/elna-generic.cc85
-rw-r--r--gcc/gcc/elna-spec.cc2
-rw-r--r--gcc/gcc/elna1.cc10
3 files changed, 9 insertions, 88 deletions
diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc
index 7491372..00581df 100644
--- a/gcc/gcc/elna-generic.cc
+++ b/gcc/gcc/elna-generic.cc
@@ -39,8 +39,6 @@ namespace elna::gcc
generic_visitor::generic_visitor(const std::shared_ptr<symbol_table>& symbol_table,
boot::symbol_bag bag, const boot::target_info& target)
: bag(std::move(bag)), symbols(symbol_table), target(target)
- , const_evaluator(std::make_unique<boot::evaluator>(this->bag, this->target,
- this->evaluated_initializers))
{
}
@@ -802,32 +800,12 @@ namespace elna::gcc
declaration_tree = declare_variable(variable_identifier.name(), *variable_symbol, this->symbols);
}
- // Set initializer if given.
+ // Set initializer if given. The constant_folder pass has
+ // already folded the initializer into literals at this point.
if (declaration->initializer != nullptr)
{
declaration->initializer->accept(this);
- tree initializer_tree = this->current_expression;
-
- std::map<std::string, boot::expression*> evaluated_initializers;
- boot::evaluator constant_evaluator(this->bag, this->target, evaluated_initializers);
- if (auto constant_value = constant_evaluator.evaluate(*declaration->initializer))
- {
- tree folded = constant_to_tree(constant_value.value(), TREE_TYPE(declaration_tree));
- if (folded != NULL_TREE)
- {
- initializer_tree = folded;
- }
- }
- // Follow a const variable's DECL_INITIAL when the
- // evaluator cannot chain (e.g. y := x with x: const Int).
- if (initializer_tree != NULL_TREE
- && TREE_CODE(initializer_tree) == VAR_DECL
- && TREE_READONLY(initializer_tree)
- && DECL_INITIAL(initializer_tree) != NULL_TREE)
- {
- initializer_tree = DECL_INITIAL(initializer_tree);
- }
- DECL_INITIAL(declaration_tree) = initializer_tree;
+ DECL_INITIAL(declaration_tree) = this->current_expression;
}
else if (!declaration->is_extern && POINTER_TYPE_P(TREE_TYPE(declaration_tree)))
{
@@ -918,63 +896,6 @@ namespace elna::gcc
}
}
- void generic_visitor::visit(boot::traits_expression *trait)
- {
- location_t trait_location = get_location(&trait->position());
-
- if (trait->name == "size" || trait->name == "alignment"
- || trait->name == "min" || trait->name == "max")
- {
- if (trait->arguments.size() != 1)
- {
- error_at(trait_location, "Trait '%s' expects 1 argument, got %lu",
- trait->name.name().c_str(), trait->arguments.size());
- this->current_expression = error_mark_node;
- return;
- }
- if (auto value = this->const_evaluator->evaluate_traits(*trait))
- {
- this->current_expression = constant_to_tree(*value);
- }
- else
- {
- this->current_expression = error_mark_node;
- }
- }
- else if (trait->name == "offset")
- {
- if (trait->arguments.size() != 2)
- {
- error_at(trait_location, "Trait '%s' expects 2 arguments, got %lu",
- trait->name.name().c_str(), trait->arguments.size());
- this->current_expression = error_mark_node;
- return;
- }
- auto *field_type = trait->arguments.at(1)->is_named();
-
- if (field_type == nullptr)
- {
- error_at(trait_location,
- "The second argument to the offset trait is expected to be a field name,"
- "got a type expression");
- this->current_expression = error_mark_node;
- return;
- }
- if (auto value = this->const_evaluator->evaluate_traits(*trait))
- {
- this->current_expression = constant_to_tree(*value);
- }
- else
- {
- this->current_expression = error_mark_node;
- }
- }
- else
- {
- this->current_expression = error_mark_node;
- }
- }
-
void generic_visitor::visit(boot::field_access_expression *expression)
{
expression->base().accept(this);
diff --git a/gcc/gcc/elna-spec.cc b/gcc/gcc/elna-spec.cc
index 5d1ace1..5b3b1c2 100644
--- a/gcc/gcc/elna-spec.cc
+++ b/gcc/gcc/elna-spec.cc
@@ -22,7 +22,7 @@ void lang_specific_driver(struct cl_decoded_option ** /* in_decoded_options */,
}
/* Called before linking. Returns 0 on success and -1 on failure. */
-int lang_specific_pre_link(void)
+int lang_specific_pre_link()
{
return 0;
}
diff --git a/gcc/gcc/elna1.cc b/gcc/gcc/elna1.cc
index 8eb103b..0602b99 100644
--- a/gcc/gcc/elna1.cc
+++ b/gcc/gcc/elna1.cc
@@ -52,7 +52,7 @@ union GTY ((desc("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
/* Language hooks. */
-static bool elna_langhook_init(void)
+static bool elna_langhook_init()
{
build_common_tree_nodes(false);
@@ -115,7 +115,7 @@ static elna::boot::dependency elna_parse_file(dependency_state& state, const cha
if (cached_import == std::cend(state))
{
- auto filename_pointer = ggc_strdup(sub_path.native().c_str());
+ const char *filename_pointer = ggc_strdup(sub_path.native().c_str());
elna_parse_file(state, filename_pointer);
cached_import = state.find(sub_path);
@@ -137,7 +137,7 @@ static elna::boot::dependency elna_parse_file(dependency_state& state, const cha
return outcome;
}
-static void elna_langhook_parse_file(void)
+static void elna_langhook_parse_file()
{
dependency_state state{ elna::gcc::builtin_symbol_table() };
@@ -223,7 +223,7 @@ static tree elna_langhook_type_for_mode(enum machine_mode mode, int unsignedp)
return nullptr;
}
-static bool global_bindings_p(void)
+static bool global_bindings_p()
{
return current_function_decl == NULL_TREE;
}
@@ -239,7 +239,7 @@ static tree elna_langhook_builtin_function(tree decl)
return decl;
}
-static unsigned int elna_langhook_option_lang_mask(void)
+static unsigned int elna_langhook_option_lang_mask()
{
return CL_Elna;
}