diff mbox

[gfortran] Cleanup the submodule tests

Message ID E36F21B5-1BF9-47EB-90F8-0A120B45DEB5@lps.ens.fr
State New
Headers show

Commit Message

Dominique d'Humières April 15, 2017, 1:57 p.m. UTC
> Le 15 avr. 2017 à 13:00, Janus Weil <janus@gcc.gnu.org> a écrit :
> 
> Hi Dominique,
> 
> if I'm not mistaken, the cleanup of module file in the testsuite is
> done automatically by now, right? Couldn't one do the same also for
> submodules?
> 
> Cheers,
> Janus
> 

This is indeed doable, but before I’ld like to improve the module cleanup with the following patch (+remove all the non-necessary module cleanup)


Dominique

Comments

Janus Weil April 15, 2017, 3:13 p.m. UTC | #1
2017-04-15 15:57 GMT+02:00 Dominique d'Humières <dominiq@lps.ens.fr>:
>
>> Le 15 avr. 2017 à 13:00, Janus Weil <janus@gcc.gnu.org> a écrit :
>>
>> Hi Dominique,
>>
>> if I'm not mistaken, the cleanup of module file in the testsuite is
>> done automatically by now, right? Couldn't one do the same also for
>> submodules?
>>
>> Cheers,
>> Janus
>>
>
> This is indeed doable, but before I’ld like to improve the module cleanup with the following patch

Yes, looks very useful to me (makes the regexps much more compact &
readable). In addition, couldn't one use \s for whitespace instead of
\[ \t\]   ?

I assume your igrep is just a copy of dejagnu's grep with an additional -nocase?

Cheers,
Janus



> --- ../_clean/gcc/testsuite/lib/fortran-modules.exp     2017-01-01 17:38:58.000000000 +0100
> +++ gcc/testsuite/lib/fortran-modules.exp       2017-01-03 09:19:02.000000000 +0100
> @@ -79,10 +79,11 @@ proc list-module-names { files } {
>
>  proc list-module-names-1 { file } {
>      set result {}
> -    set tmp [grep $file "^\[ \t\]*((#)?\[ \t\]*include|\[mM\]\[oO\]\[dD\]\[uU\]\[lL\]\[eE\](?!\[ \t\]+\[pP\]\[rR\]\[oO\]\[cC\]\[eE\]\[dD\]\[uU\]\[rR\]\[eE\]\[ \t\]+))\[ \t\]+.*" line]
> +    if {[file isdirectory $file]} {return}
> +    set tmp [igrep $file "^\[ \t\]*((#)?\[ \t\]*include|module(?!\[ \t\]+procedure\[ \t\]+))\[ \t\]+.*" line]
>      if {![string match "" $tmp]} {
>         foreach i $tmp {
> -           regexp "(\[0-9\]+)\[ \t\]+(?:(?:#)?\[ \t\]*include\[ \t\]+)\[\"\](\[^\"\]*)\[\"\]" $i dummy lineno include_file
> +           regexp -nocase "(\[0-9\]+)\[ \t\]+(?:(?:#)?\[ \t\]*include\[ \t\]+)\[\"\'\](\[^\"\'\]*)\[\"\'\]" $i dummy lineno include_file
>             if {[info exists include_file]} {
>                 set dir [file dirname $file]
>                 set inc "$dir/$include_file"
> @@ -99,7 +100,7 @@ proc list-module-names-1 { file } {
>                 }
>                 continue
>             }
> -           regexp "(\[0-9\]+)\[ \t\]+(?:(\[mM\]\[oO\]\[dD\]\[uU\]\[lL\]\[eE\]\[ \t\]+(?!\[pP\]\[rR\]\[oO\]\[cC\]\[eE\]\[dD\]\[uU\]\[rR\]\[eE\]\[ \t\]+)))(\[^ \t;\]*)" $i i lineno keyword mod
> +           regexp -nocase "(\[0-9\]+)\[ \t\]+(?:(\module\[ \t\]+(?!procedure\[ \t\]+)))(\[^ \t;\]*)" $i i lineno keyword mod
>             if {![info exists lineno]} {
>                 continue
>             }
> @@ -111,3 +112,54 @@ proc list-module-names-1 { file } {
>      }
>      return $result
>  }
> +
> +# Looks for case insensitive occurrences of a string in a file.
> +#     return:list of lines that matched or NULL if none match.
> +#     args:  first arg is the filename,
> +#            second is the pattern,
> +#            third are any options.
> +#     Options: line  - puts line numbers of match in list
> +#
> +proc igrep { args } {
> +
> +    set file [lindex $args 0]
> +    set pattern [lindex $args 1]
> +
> +    verbose "Grepping $file for the pattern \"$pattern\"" 3
> +
> +    set argc [llength $args]
> +    if { $argc > 2 } {
> +        for { set i 2 } { $i < $argc } { incr i } {
> +            append options [lindex $args $i]
> +            append options " "
> +        }
> +    } else {
> +        set options ""
> +    }
> +
> +    set i 0
> +    set fd [open $file r]
> +    while { [gets $fd cur_line]>=0 } {
> +        incr i
> +        if {[regexp -nocase -- "$pattern" $cur_line match]} {
> +            if {![string match "" $options]} {
> +                foreach opt $options {
> +                    switch $opt {
> +                        "line" {
> +                            lappend grep_out [concat $i $match]
> +                        }
> +                    }
> +                }
> +            } else {
> +                lappend grep_out $match
> +            }
> +        }
> +    }
> +    close $fd
> +    unset fd
> +    unset i
> +    if {![info exists grep_out]} {
> +        set grep_out ""
> +    }
> +    return $grep_out
> +}
>
> Dominique
>
Dominique d'Humières April 15, 2017, 3:54 p.m. UTC | #2
> Le 15 avr. 2017 à 17:13, Janus Weil <janus@gcc.gnu.org> a écrit :
> 
> 2017-04-15 15:57 GMT+02:00 Dominique d'Humières <dominiq@lps.ens.fr>:
>> 
>>> Le 15 avr. 2017 à 13:00, Janus Weil <janus@gcc.gnu.org> a écrit :
>>> 
>>> Hi Dominique,
>>> 
>>> if I'm not mistaken, the cleanup of module file in the testsuite is
>>> done automatically by now, right? Couldn't one do the same also for
>>> submodules?
>>> 
>>> Cheers,
>>> Janus
>>> 
>> 
>> This is indeed doable, but before I’ld like to improve the module cleanup with the following patch
> 
> Yes, looks very useful to me (makes the regexps much more compact &
> readable). In addition, couldn't one use \s for whitespace instead of
> \[ \t\]   ?

I have posted what I have in my working tree. I’ll test the use of \s instead of \[ \t\] . Is it really portable?
> 
> 
> I assume your igrep is just a copy of dejagnu's grep with an additional -nocase?

Yes!

> Cheers,
> Janus

Dominique
Janus Weil April 15, 2017, 4:50 p.m. UTC | #3
2017-04-15 17:54 GMT+02:00 Dominique d'Humières <dominiq@lps.ens.fr>:
>>> This is indeed doable, but before I’ld like to improve the module cleanup with the following patch
>>
>> Yes, looks very useful to me (makes the regexps much more compact &
>> readable). In addition, couldn't one use \s for whitespace instead of
>> \[ \t\]   ?
>
> I have posted what I have in my working tree. I’ll test the use of \s instead of \[ \t\] . Is it really portable?

Not sure. But at least some of the other files in gcc/testsuite/lib
seem to use \s as well (e.g. gcc-dg.exp).


>> I assume your igrep is just a copy of dejagnu's grep with an additional -nocase?
>
> Yes!

Ok to commit  from my side, if you have tested that it works properly.

Cheers,
Janus
diff mbox

Patch

--- ../_clean/gcc/testsuite/lib/fortran-modules.exp	2017-01-01 17:38:58.000000000 +0100
+++ gcc/testsuite/lib/fortran-modules.exp	2017-01-03 09:19:02.000000000 +0100
@@ -79,10 +79,11 @@  proc list-module-names { files } {
 
 proc list-module-names-1 { file } {
     set result {}
-    set tmp [grep $file "^\[ \t\]*((#)?\[ \t\]*include|\[mM\]\[oO\]\[dD\]\[uU\]\[lL\]\[eE\](?!\[ \t\]+\[pP\]\[rR\]\[oO\]\[cC\]\[eE\]\[dD\]\[uU\]\[rR\]\[eE\]\[ \t\]+))\[ \t\]+.*" line]
+    if {[file isdirectory $file]} {return}
+    set tmp [igrep $file "^\[ \t\]*((#)?\[ \t\]*include|module(?!\[ \t\]+procedure\[ \t\]+))\[ \t\]+.*" line]
     if {![string match "" $tmp]} {
 	foreach i $tmp {
-	    regexp "(\[0-9\]+)\[ \t\]+(?:(?:#)?\[ \t\]*include\[ \t\]+)\[\"\](\[^\"\]*)\[\"\]" $i dummy lineno include_file
+	    regexp -nocase "(\[0-9\]+)\[ \t\]+(?:(?:#)?\[ \t\]*include\[ \t\]+)\[\"\'\](\[^\"\'\]*)\[\"\'\]" $i dummy lineno include_file
 	    if {[info exists include_file]} {
 		set dir [file dirname $file]
 		set inc "$dir/$include_file"
@@ -99,7 +100,7 @@  proc list-module-names-1 { file } {
 		}
 		continue
 	    }
-	    regexp "(\[0-9\]+)\[ \t\]+(?:(\[mM\]\[oO\]\[dD\]\[uU\]\[lL\]\[eE\]\[ \t\]+(?!\[pP\]\[rR\]\[oO\]\[cC\]\[eE\]\[dD\]\[uU\]\[rR\]\[eE\]\[ \t\]+)))(\[^ \t;\]*)" $i i lineno keyword mod
+	    regexp -nocase "(\[0-9\]+)\[ \t\]+(?:(\module\[ \t\]+(?!procedure\[ \t\]+)))(\[^ \t;\]*)" $i i lineno keyword mod
 	    if {![info exists lineno]} {
 		continue
 	    }
@@ -111,3 +112,54 @@  proc list-module-names-1 { file } {
     }
     return $result
 }
+
+# Looks for case insensitive occurrences of a string in a file.
+#     return:list of lines that matched or NULL if none match.
+#     args:  first arg is the filename,
+#            second is the pattern,
+#            third are any options.
+#     Options: line  - puts line numbers of match in list
+#
+proc igrep { args } {
+
+    set file [lindex $args 0]
+    set pattern [lindex $args 1]
+
+    verbose "Grepping $file for the pattern \"$pattern\"" 3
+
+    set argc [llength $args]
+    if { $argc > 2 } {
+        for { set i 2 } { $i < $argc } { incr i } {
+            append options [lindex $args $i]
+            append options " "
+        }
+    } else {
+        set options ""
+    }
+
+    set i 0
+    set fd [open $file r]
+    while { [gets $fd cur_line]>=0 } {
+        incr i
+        if {[regexp -nocase -- "$pattern" $cur_line match]} {
+            if {![string match "" $options]} {
+                foreach opt $options {
+                    switch $opt {
+                        "line" {
+                            lappend grep_out [concat $i $match]
+                        }
+                    }
+                }
+            } else {
+                lappend grep_out $match
+            }
+        }
+    }
+    close $fd
+    unset fd
+    unset i
+    if {![info exists grep_out]} {
+        set grep_out ""
+    }
+    return $grep_out
+}