fortran-modules.exp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright (C) 2012-2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. # helper to deal with fortran modules
  16. # Remove files for specified Fortran modules.
  17. proc cleanup-modules { modlist } {
  18. global clean
  19. foreach mod [concat $modlist $clean] {
  20. set m [string tolower $mod].mod
  21. verbose "cleanup-module `$m'" 2
  22. if [is_remote host] {
  23. remote_file host delete $m
  24. }
  25. remote_file build delete $m
  26. }
  27. }
  28. proc keep-modules { modlist } {
  29. global clean
  30. # if the modlist is empty, keep everything
  31. if {[llength $modlist] < 1} {
  32. set clean {}
  33. } else {
  34. set cleansed {}
  35. foreach cl $clean {
  36. if {[lsearch $cl $modlist] < 0} {
  37. lappend cleansed $cl
  38. }
  39. }
  40. if {[llength $clean] == [llength $cleansed]} {
  41. warning "keep-modules had no effect?! Possible typo in module name."
  42. }
  43. set clean $cleansed
  44. }
  45. }
  46. # collect all module names from a source-file
  47. proc list-module-names { files } {
  48. global clean
  49. set clean {}
  50. foreach file $files {
  51. foreach mod [list-module-names-1 $file] {
  52. if {[lsearch $clean $mod] < 0} {
  53. lappend clean $mod
  54. }
  55. }
  56. }
  57. return [join $clean " "]
  58. }
  59. proc list-module-names-1 { file } {
  60. set result {}
  61. 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]
  62. if {![string match "" $tmp]} {
  63. foreach i $tmp {
  64. regexp "(\[0-9\]+)\[ \t\]+(?:(?:#)?\[ \t\]*include\[ \t\]+)\[\"\](\[^\"\]*)\[\"\]" $i dummy lineno include_file
  65. if {[info exists include_file]} {
  66. set dir [file dirname $file]
  67. set inc "$dir/$include_file"
  68. unset include_file
  69. if {![file readable $inc]} {
  70. # We do not currently use include path search logic, punt
  71. continue
  72. }
  73. verbose "Line $lineno includes `$inc'" 3
  74. foreach mod [list-module-names-1 $inc] {
  75. if {[lsearch $result $mod] < 0} {
  76. lappend result $mod
  77. }
  78. }
  79. continue
  80. }
  81. 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
  82. if {![info exists lineno]} {
  83. continue
  84. }
  85. verbose "Line $lineno mentions module `$mod'" 3
  86. if {[lsearch $result $mod] < 0} {
  87. lappend result $mod
  88. }
  89. }
  90. }
  91. return $result
  92. }