home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / IDOL.LZH / ITAGS.IOL < prev    next >
Text File  |  1991-07-18  |  8KB  |  317 lines

  1. # itags - an Icon/Idol tag generator by Nick Kline
  2. # hacks (such as this header comment) by Clint Jeffery
  3. # last edit: 12/13/89
  4. #
  5. # the output is a sorted list of lines of the form
  6. # identifier  owning_scope  category_type  filename  lineno(:length)
  7. #
  8. # owning scope is the name of the class or procedure or record in which
  9. # the tag is defined.
  10. # category type is the kind of tag; one of:
  11. # (global,procedure,record,class,method,param,obj_field,rec_field)
  12. #
  13. global ibrowseflag
  14.  
  15. procedure main(args) 
  16. local line, lineno, fout, i, fin, notvar, objects, actual_file, outlines
  17.  
  18. initial {
  19.     fout := open("ITAGS", "w") | stop("can't open ITAGS for writing"); 
  20.     outlines := [[0,0,0,0,0,0]]
  21.     i := 1
  22.     notid := &cset -- &ucase -- &digits -- &lcase -- '_'
  23. }
  24.  
  25. if(*args=0) then 
  26.     stop("usage: itags file1 [file2 ...]")
  27.  
  28. while i <= *args do {
  29.     if args[i] == "-i" then {
  30.     ibrowseflag := 1
  31.     i +:= 1
  32.     continue
  33.     }
  34.     fin := open(args[i],"r") |
  35.     stop("could not open file ",args[i]," exiting")
  36.     lineno := 1
  37.     objects := program( args[i] )
  38.  
  39.     while line := read(fin) do {
  40.     line[upto('#',line):0] := ""
  41.     line ? {
  42.         tab(many(' ')) 
  43.         
  44.         if =("global") then {
  45.         if(any(notid)) then 
  46.             every objects$addvar( getword(), lineno )
  47.         }
  48.         
  49.         if =("procedure")  then 
  50.           if(any(notid)) then {
  51.             objects$addproc( getword(), lineno )
  52.             objects$myline(tab(0),lineno)
  53.         }
  54.         
  55.  
  56.         if =("class") then 
  57.         if any(notid) then {
  58.             objects$addclass( getword(), lineno )
  59.             objects$myline(tab(0),lineno)
  60.         }
  61.  
  62.  
  63.         if =("method") then {
  64.         if any(notid) then {
  65.             objects$addmethod( getword(), lineno ) 
  66.             objects$myline(tab(0),lineno)
  67.         }
  68.         }
  69.  
  70.         if =("local") then {
  71.         if any(notid) then 
  72.             every objects$addvar( getword(), lineno ) 
  73.         }
  74.  
  75.         if =("static") then {
  76.         if any(notid) then 
  77.             every objects$addstat( getword(), lineno ) 
  78.         }
  79.  
  80.         if =("record") then {
  81.         if any(notid) then {
  82.             objects$addrec( getword(), lineno ) 
  83.             objects$myline(tab(0),lineno)
  84.             objects$endline( lineno)
  85.         }
  86.         }
  87.         if =("end") then
  88.         objects$endline(lineno)
  89.     }
  90.     lineno +:= 1
  91.     }
  92.     objects$drawthyself(outlines)
  93.     i +:= 1
  94. }
  95. # now process all the resulting lines
  96. every i := 2 to *outlines do {
  97.     outlines[i] := (
  98.     left(outlines[i][1],outlines[1][1]+1) ||
  99.     left(outlines[i][2],outlines[1][2]+1) ||
  100.     left(outlines[i][3],outlines[1][3]+1) ||
  101.     left(outlines[i][4],outlines[1][4]+1) ||
  102.     left(outlines[i][5],outlines[1][5]) ||
  103.     (if \outlines[i][6] then ":"||outlines[i][6] else ""))
  104. }
  105. outlines := outlines[2:0]
  106. outlines := sort(outlines)
  107. every write(fout,!outlines)
  108. end
  109.  
  110. class functions(name, lineno,vars,lastline, parent, params,stat,paramtype)
  111.  
  112. method drawthyself(outfile)
  113. local k
  114.     every k := !self.vars do
  115.       emit(outfile, k[1], self.name, "local", self.parent$myfile(),k[2])
  116.     every k := !self.params do
  117.       emit(outfile, k[1], self.name, self.paramtype, self.parent$myfile(),k[2])
  118.     every k := !self.stat do
  119.       emit(outfile, k[1], self.name, "static", self.parent$myfile(),k[2])
  120. end
  121.  
  122. method myline(line,lineno)
  123. local word
  124. static ids,  letters
  125. initial {
  126.     ids := &lcase ++ &ucase ++ &digits ++ '_'
  127.     letters := &ucase ++ &lcase
  128. }
  129.  
  130. line ? while tab(upto(letters)) do  {
  131.     word := tab(many(ids))
  132.     self.params|||:= [[word,lineno]]
  133. }
  134.  
  135. end
  136.  
  137. method addstat(varname, lineno)
  138.     self.stat|||:=[[varname, lineno]]
  139.     return
  140. end
  141.  
  142. method addvar(varname, lineno)
  143.     self.vars|||:=[[varname, lineno]]
  144.     return
  145. end
  146.  
  147. method endline( lineno )
  148.    self.lastline := lineno
  149. end
  150.  
  151. method resetcontext()
  152.     self.parent$resetcontext()
  153. end
  154.  
  155. initially
  156.     self.vars := []
  157.     self.params := []
  158.     self.stat := []
  159.     self.paramtype := "param"
  160. end # end of class functions
  161.  
  162.  
  163. class proc : functions(name,lineno, parent,paramtype)
  164.  
  165. method drawthyself(outfile)
  166.     emit(outfile,self.name, "*" , "procedure", self.parent$myfile(),self.lineno, self.lastline-self.lineno+1)
  167.     self$functions.drawthyself(outfile)
  168. end
  169. initially
  170.  self.paramtype := "param"
  171. end # of class proc
  172.  
  173. class rec : functions(name, lineno, parent, line, paramtype)
  174.  
  175. method drawthyself(outfile)
  176.     emit(outfile,self.name, "*", "record", self.parent$myfile(),
  177.      self.lineno)
  178.     self$functions.drawthyself(outfile)
  179. end
  180. initially
  181.   self.paramtype := "rec_field"
  182. end # class record
  183.  
  184.  
  185.  
  186. class program(public myfile, vars, proc, records, classes, curcontext, contextsave,globals)
  187.  
  188. method endline( lineno )
  189.     self.curcontext$endline( lineno )
  190.     self.curcontext := pop(self.contextsave)
  191. end
  192.  
  193. method myline( line,lineno)
  194.     self.curcontext$myline( line,lineno)
  195. end
  196.    
  197. method drawthyself(outfile)
  198.     every k := !self.globals do
  199.     emit(outfile,k[1], "*", "global", self.myfile,k[2])
  200.     every (!self.proc)$drawthyself(outfile)
  201.     every (!self.records)$drawthyself(outfile)
  202.     every (!self.classes)$drawthyself(outfile)
  203. end
  204.  
  205. method addmethod(name, lineno)
  206.     push(self.contextsave,self.curcontext)
  207.     self.curcontext := self.curcontext$addmethod(name,lineno)
  208.     return
  209. end
  210.  
  211. method addstat(varname, lineno)
  212.     self.curcontext$addstat(varname, lineno)
  213. end
  214.  
  215. method addvar(varname, lineno)
  216.     if self.curcontext === self
  217.     then  self.globals|||:= [[varname,lineno]]
  218.     else self.curcontext$addvar(varname,lineno)
  219.     return
  220. end
  221.  
  222. method addproc(procname, lineno)
  223.     push(self.contextsave, self.curcontext)
  224.     self.curcontext := proc(procname, lineno, self)
  225.     self.proc|||:= [self.curcontext]
  226.     return
  227. end
  228.  
  229. method addrec(recname, lineno)
  230.     push(self.contextsave, self.curcontext)
  231.     self.curcontext := rec(recname, lineno,self)
  232.     self.records|||:=[self.curcontext]
  233.     return
  234. end
  235.  
  236. method addclass(classname, lineno)
  237.     push(self.contextsave, self.curcontext)
  238.     self.curcontext := class_(classname, lineno, self)
  239.     self.classes|||:=[self.curcontext]
  240.     return
  241. end
  242.  
  243. method resetcontext()
  244.     self.curcontext := pop(self.contextsave)
  245. end
  246.  
  247. initially 
  248.  self.globals := []
  249.  self.proc := []
  250.  self.records := []
  251.  self.classes := []
  252.  self.curcontext := self
  253.  self.contextsave := []
  254. end  # end of class program
  255.  
  256.  
  257.  
  258. class class_ : functions (public name, lineno, parent, meth,paramtype)
  259.  
  260. method myfile()
  261.     return self.parent$myfile()
  262. end
  263.  
  264. method addmethod(methname, lineno)
  265.     self.meth|||:= [methods(methname, lineno, self)]
  266.     return (self.meth[-1])
  267. end
  268.  
  269. method drawthyself(outfile)
  270.     emit(outfile,self.name, "*" , "class", self.parent$myfile(),self.lineno, self.lastline-self.lineno+1)    
  271.     every (!self.meth)$drawthyself(outfile)
  272.     self$functions.drawthyself(outfile)
  273. end
  274.  
  275. initially
  276.     self.meth := []
  277.     self.paramtype := "obj_field"
  278. end #end of class_
  279.  
  280. class methods: functions(name, lineno, parent,paramtype)
  281. method drawthyself(outfile)
  282.         emit(outfile,self.name, self.parent$name() , "method", self.parent$myfile(),self.lineno, self.lastline-self.lineno+1)    
  283.     self$functions.drawthyself(outfile)
  284. end
  285. initially
  286.     self.paramtype := "param"
  287. end #end of members    class
  288.  
  289. procedure emit(outlist,ident, scope, type, filename, line, length)
  290.     outlist[1][1] := outlist[1][1] < *ident
  291.     outlist[1][2] := outlist[1][2] < *scope
  292.     outlist[1][3] := outlist[1][3] < *type
  293.     outlist[1][4] := outlist[1][4] < *filename
  294.     outlist[1][5] := outlist[1][5] < *line
  295.     outlist[1][6] := outlist[1][6] < *\length
  296.     if /ibrowseflag then
  297.        put( outlist, [ident,scope,type,filename,line,length] )
  298.     else
  299.        put( outlist, [ident,scope,type,filename,line,length] )
  300. end
  301.  
  302.  
  303. procedure getword()
  304.     local word
  305.     static ids,letts
  306.     initial {
  307.     ids := &ucase ++ &lcase ++ &digits ++ '_'
  308.     letts := &ucase ++ &lcase
  309.     }
  310.  
  311.     while tab(upto(letts)) do {
  312.     word := tab(many(ids))
  313.     suspend word
  314.     }
  315.  
  316. end
  317.