aboutsummaryrefslogtreecommitdiff
path: root/gcc/testlib
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/testlib
parentd0a666507a6f11b65170c257fd483613f462f3f2 (diff)
downloadelna-a0e1740227535adc3151c02eb102c4f96b4f9731.tar.gz
Implement type constness
Diffstat (limited to 'gcc/testlib')
-rw-r--r--gcc/testlib/elna-dg.exp45
1 files changed, 43 insertions, 2 deletions
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
}