home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / declchck.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  92 lines

  1. ############################################################################
  2. #
  3. #    File:     declchck.icn
  4. #
  5. #    Subject:  Program to detect possible declaration errors
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     August 14, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program examines ucode files and reports declared identifiers
  18. #  that may conflict with function names.
  19. #
  20. ############################################################################
  21. #
  22. #  Requires:  UNIX
  23. #
  24. ############################################################################
  25.  
  26. procedure main(args)
  27.    local fset, u1, u2, line, name, base, flag, proc, files, file
  28.  
  29.    fset := set()
  30.    every insert(fset,function())
  31.  
  32.    files := open("ls *.icn", "p")
  33.  
  34.    while file := read(files) do {
  35.       system("cp " || file || " xxxxxx.icn")
  36.       system("icont -c -s xxxxxx.icn")
  37.       write(base := (file ? tab(upto('.'))))
  38.       write("   locals")
  39.       u1 := open("xxxxxx.u1") | {
  40.          write("cannot open .u1 file for ", image(file))
  41.          next
  42.          }
  43.       u2 := open("xxxxxx.u2") | {
  44.          write("cannot open .u1 file for ", image(file))
  45.          next
  46.          }
  47.       while line := read(u1) do {
  48.          line ? {
  49.             if ="proc " then {
  50.                proc := tab(0)
  51.                write("\t", proc)
  52.                while line := read(u1) do {
  53.                   line ? {
  54.                      if ="\tdeclend" then break next
  55.                      else if ="\tlocal\t" then {
  56.                         move(2)
  57.                         flag := tab(many(&digits))
  58.                         if flag == ("001000" | "000020") then {
  59.                            move(1)
  60.                            name := tab(0)
  61.                            if member(fset, name) then
  62.                               write("\t\tpotential local conflict: ", name)
  63.                            }
  64.                         }
  65.                      }
  66.                   }
  67.                }
  68.             }
  69.          }
  70.       write("   globals")
  71.       while line := read(u2) do { 
  72.          line ? {
  73.             if ="global" then break
  74.             }
  75.          }
  76.       while line := read(u2) do {
  77.          line ? {
  78.             if tab(upto(',') + 1) & ="000001," then {
  79.                name := tab(upto(','))
  80.                if member(fset, name) then
  81.                   write("\t\tpotential global conflict: ", name)
  82.                }
  83.             }
  84.          }
  85.       system("rm -f xxxxxx.*")
  86.       close(u1)
  87.       close(u2)
  88.       write()
  89.       }
  90.  
  91. end
  92.