On 04/03/2018 07:49 PM, Bernhard Reutner-Fischer wrote:
This patch adds scan-ltrans-tree-dump.
Please check all error calls to talk about the correct function -- at least
scan-ltrans-tree-dump-times is wrong.
Hi,
thanks for noticing that. I'll update the patches to fix that.
But I wonder if it's not a better idea to get the function name using
"info level", and to move the code that checks the number of arguments
into a utility function, as done in the demonstrator patch below.
Rainer, Mike, any comments? I can write a patch that uses check_num_args
in testsuite/lib/*.exp (though I'm not yet sure where to move it such
that it can be used everywhere).
Thanks,
- Tom
diff --git a/gcc/testsuite/lib/scanltranstree.exp b/gcc/testsuite/lib/scanltranstree.exp
index c122abb..e4c5c90 100644
--- a/gcc/testsuite/lib/scanltranstree.exp
+++ b/gcc/testsuite/lib/scanltranstree.exp
@@ -19,6 +19,25 @@
load_lib scandump.exp
+proc check_num_args { args } {
+ set caller_args [lindex $args 0]
+ set min_args [lindex $args 1]
+ if { [lindex $args] >= 2 } {
+ set max_args [lindex $args 2]
+ } else {
+ set max_args $min_args
+ }
+ set caller_fnname [lindex [info level -1] 0]
+ if { [llength $caller_args] < $min_args } {
+ error "$caller_fnname: too few arguments"
+ return
+ }
+ if { [llength $caller_args] > $max_args } {
+ error "$caller_fnname: too many arguments"
+ return
+ }
+}
+
# Utility for scanning compiler result, invoked via dg-final.
# Call pass if pattern is present, otherwise fail.
#
@@ -52,14 +71,7 @@ proc scan-ltrans-tree-dump { args } {
# Argument 3 handles expected failures and the like
proc scan-ltrans-tree-dump-times { args } {
- if { [llength $args] < 3 } {
- error "scan-ltrans-tree-dump: too few arguments"
- return
- }
- if { [llength $args] > 4 } {
- error "scan-ltrans-tree-dump: too many arguments"
- return
- }
+ check_num_args $args 3 4
if { [llength $args] >= 4 } {
scan-dump-times "ltrans-tree" [lindex $args 0] [lindex $args 1] \
"\[0-9\]\[0-9\]\[0-9\]t.[lindex $args 2]" \