aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-17 10:18:58 +0200
committerEugen Wissner <belka@caraus.de>2026-07-17 10:18:58 +0200
commita0e1740227535adc3151c02eb102c4f96b4f9731 (patch)
tree0e29cd3719370eca8c74fb67480f3bfc1a207106 /gcc
parentd0a666507a6f11b65170c257fd483613f462f3f2 (diff)
downloadelna-a0e1740227535adc3151c02eb102c4f96b4f9731.tar.gz
Implement type constness
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gcc/elna-builtins.cc4
-rw-r--r--gcc/gcc/elna-generic.cc51
-rw-r--r--gcc/testlib/elna-dg.exp45
3 files changed, 55 insertions, 45 deletions
diff --git a/gcc/gcc/elna-builtins.cc b/gcc/gcc/elna-builtins.cc
index 9e331cf..3c424f8 100644
--- a/gcc/gcc/elna-builtins.cc
+++ b/gcc/gcc/elna-builtins.cc
@@ -160,6 +160,10 @@ namespace elna::gcc
return build_pointer_type(procedure);
}
+ else if (auto reference = type.get<boot::constant_type>())
+ {
+ return get_inner_alias(reference->unqualified, symbols);
+ }
else if (auto reference = type.get<boot::alias_type>())
{
return TREE_TYPE(handle_symbol(reference->name, reference, symbols));
diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc
index 4067bb6..b849715 100644
--- a/gcc/gcc/elna-generic.cc
+++ b/gcc/gcc/elna-generic.cc
@@ -228,10 +228,6 @@ namespace elna::gcc
{
declaration->accept(this);
}
- for (boot::constant_declaration *const constant : unit->constants)
- {
- constant->accept(this);
- }
for (boot::variable_declaration *const variable : unit->variables)
{
variable->accept(this);
@@ -309,10 +305,6 @@ namespace elna::gcc
{
this->symbols->enter(IDENTIFIER_POINTER(DECL_NAME(argument_chain)), argument_chain);
}
- for (boot::constant_declaration *const constant : declaration->body.value().constants)
- {
- constant->accept(this);
- }
for (boot::variable_declaration *const variable : declaration->body.value().variables)
{
variable->accept(this);
@@ -704,41 +696,6 @@ namespace elna::gcc
}
}
- void generic_visitor::visit(boot::constant_declaration *declaration)
- {
- location_t definition_location = get_location(&declaration->position());
- declaration->initializer().accept(this);
-
- if (assert_constant(definition_location))
- {
- this->current_expression = fold_init(this->current_expression);
- }
- else
- {
- this->current_expression = NULL_TREE;
- return;
- }
- tree definition_tree = build_decl(definition_location, CONST_DECL,
- get_identifier(declaration->identifier.name().c_str()), TREE_TYPE(this->current_expression));
- auto result = this->symbols->enter(declaration->identifier.name(), definition_tree);
-
- if (result)
- {
- DECL_INITIAL(definition_tree) = this->current_expression;
- TREE_CONSTANT(definition_tree) = 1;
- TREE_READONLY(definition_tree) = 1;
- TREE_PUBLIC(definition_tree) = declaration->identifier.exported();
-
- if (!lang_hooks.decls.global_bindings_p())
- {
- auto declaration_statement = build1_loc(definition_location, DECL_EXPR,
- void_type_node, definition_tree);
- append_statement(declaration_statement);
- }
- }
- this->current_expression = NULL_TREE;
- }
-
void generic_visitor::visit(boot::variable_declaration *declaration)
{
for (const auto& variable_identifier : declaration->identifiers)
@@ -762,6 +719,14 @@ namespace elna::gcc
{
DECL_INITIAL(declaration_tree) = elna_pointer_nil_node;
}
+ {
+ auto variable_symbol = this->bag.lookup(variable_identifier.name())->is_variable();
+
+ if (variable_symbol != nullptr && variable_symbol->symbol.get<boot::constant_type>() != nullptr)
+ {
+ TREE_READONLY(declaration_tree) = 1;
+ }
+ }
this->current_expression = NULL_TREE;
if (lang_hooks.decls.global_bindings_p())
diff --git a/gcc/testlib/elna-dg.exp b/gcc/testlib/elna-dg.exp
index ddebf58..5142884 100644
--- a/gcc/testlib/elna-dg.exp
+++ b/gcc/testlib/elna-dg.exp
@@ -35,6 +35,47 @@ proc elna-dg-prune { system text } {
# Utility routines.
#
+# Escapes a directive argument so that it reaches dejagnu intact.
+#
+# dg.exp evaluates each extracted directive as a Tcl script
+# ("catch $op"), which performs one round of backslash, command and
+# variable substitution inside the double-quoted argument. Quoting the
+# affected characters here means the argument dejagnu receives is
+# exactly what the test author wrote, so @Error messages keep their
+# regular expression semantics: "\[2\]" matches literal brackets and
+# "[2]" stays a character class.
+#
+proc elna-escape-directive { text } {
+ return [string map [list \
+ "\\" "\\\\" \
+ "\[" "\\\[" \
+ "\]" "\\\]" \
+ "\$" "\\\$" \
+ "\"" "\\\""] $text]
+}
+
+#
+# Replaces an elna-native directive in the line with its dg-* equivalent,
+# escaping the directive argument for dejagnu's Tcl evaluation.
+#
+# line_var - name of the variable holding the line in the caller.
+# directive - elna directive name, e.g. @Error.
+# dg_name - dejagnu directive name, e.g. dg-error.
+#
+proc elna-convert-directive { line_var directive dg_name } {
+ upvar 1 $line_var line
+
+ if { [regexp -indices "\\(\\*\\s*$directive\\s+(.*?)\\s*\\*\\)" $line whole argument] } {
+ set escaped [elna-escape-directive \
+ [string range $line [lindex $argument 0] [lindex $argument 1]]]
+ set prefix [string range $line 0 [expr {[lindex $whole 0] - 1}]]
+ set suffix [string range $line [expr {[lindex $whole 1] + 1}] end]
+
+ set line "${prefix}(* { $dg_name \"$escaped\" } *)$suffix"
+ }
+}
+
+#
# This procedure copies a test file from the source tree to the
# build directory while rewriting elna-native directives to dejagnu
# dg-* equivalents.
@@ -60,8 +101,8 @@ proc elna-convert-test { base test } {
# Reads the source test file line by line and replace directives with
# Elna equivalents using a regular expression.
while { [gets $fin line] >= 0 } {
- regsub -all {\(\*\s*@Error\s+(.*?)\s*\*\)} $line {(* { dg-error "\1" } *)} line
- regsub -all {\(\*\s*@Flags\s+(.*?)\s*\*\)} $line {(* { dg-additional-options "\1" } *)} line
+ elna-convert-directive line @Error dg-error
+ elna-convert-directive line @Flags dg-additional-options
puts $fout $line
}