#
# $Id: parsedmethod.icn,v 1.1 2004-02-12 17:01:53 rparlett Exp $
#
# This file is in the public domain.
#
# Author: Robert Parlett (parlett@dial.pipex.com)
#
#
# Updated: Bruce Rennie - convert all standard Unicon functions to have "::" prefix
# Date:    2020-12-28
# Updated: Bruce Rennie - define all local variables as local, to prevent problems
#                         when using the Unicon compiler -n option
# Date:    2021-01-03
#

package parser

link ximage

$include "ytab_h.icn"

class ParsedMethod : ParsedFunction(abstract_flag)
   method to_string()
      local s

      s :=  "method " || to_string_impl()
      if \abstract_flag then
         s := "abstract " || s
      return s
   end

   method init(n)
      local prochead, arglist, locals_node, x, l, tok

      self.ParsedFunction.init(n)

      name := n.children[1].s

      arglist := n.children[2]
      every x := arglist.children[1 to *arglist.children].children[1] do {
         ::put(args, x.s)
      }

      if *n.children = 2 then {
         abstract_flag := 1
      } else {
         locals_node := n.children[4]
         initial_node := n.children[5]
         body_node := n.children[6]
         every x := locals_node.children[1 to *locals_node.children] do {
            l := if x.label == "local" then locals else statics
            every tok := x.children[1].children[1 to *x.children - 1].children[1] do
               ::put(l, tok.s)
         }
      }


   end

   initially(n, p)
      self.ParsedFunction.initially(n, p)
end
