コード例 #1
0
def parse_enum(node):
    _kind = node.getText()
    cls = Clazz(kind=_kind)
    cls.name = node.getChild(0).getChild(0).getText()
    _nodes = node.getChildren()[1:]  # exclude name
    constants = util.implode_id(util.mk_v_node_w_children(_nodes)).split(',')
    for c in constants:
        # define representative field
        fld = field.Field(clazz=cls, mods=C.PBST, typ=cls.name, name=c)
        cls.add_fld(fld)
        # initialize it in <clinit>
        f = exp.gen_E_id(cls.name)
        init_e = exp.gen_E_new(exp.gen_E_call(f, []))
        init_s = st.gen_S_assign(exp.gen_E_id(c), init_e)
        cls.clinit_fld(fld, [init_s])
    return cls
コード例 #2
0
ファイル: clazz.py プロジェクト: chubbymaggie/java-sketch
def parse_enum(node):
  _kind = node.getText()
  cls = Clazz(kind=_kind)
  cls.name = node.getChild(0).getChild(0).getText()
  _nodes = node.getChildren()[1:] # exclude name
  constants = util.implode_id(util.mk_v_node_w_children(_nodes)).split(',')
  for c in constants:
    # define representative field
    fld = field.Field(clazz=cls, mods=C.PBST, typ=cls.name, name=c)
    cls.add_fld(fld)
    # initialize it in <clinit>
    f = exp.gen_E_id(cls.name)
    init_e = exp.gen_E_new(exp.gen_E_call(f, []))
    init_s = st.gen_S_assign(exp.gen_E_id(c), init_e)
    cls.clinit_fld(fld, [init_s])
  return cls
コード例 #3
0
ファイル: clazz.py プロジェクト: chubbymaggie/java-sketch
  def clinit_fld(self, fld, init_ss=[]):
    clinit = self.get_or_declare_clinit()

    # make initializing statements 
    if not init_ss and not fld.is_final:
      call = Clazz.call_init_if_instantiable(fld.typ)
      if call: init_ss = [st.gen_S_assign(exp.gen_E_id(fld.name), call)]

    # update the method body
    if init_ss:
      self.clinit.body.extend(init_ss[:])
コード例 #4
0
    def clinit_fld(self, fld, init_ss=[]):
        clinit = self.get_or_declare_clinit()

        # make initializing statements
        if not init_ss and not fld.is_final:
            call = Clazz.call_init_if_instantiable(fld.typ)
            if call: init_ss = [st.gen_S_assign(exp.gen_E_id(fld.name), call)]

        # update the method body
        if init_ss:
            self.clinit.body.extend(init_ss[:])
コード例 #5
0
ファイル: clazz.py プロジェクト: chubbymaggie/java-sketch
  def init_fld(self, fld, init_ss=[]):
    # declare <init> if not exists
    inits = self.mtd_by_name(self._name)
    if not inits: inits = [self.add_default_init()]

    # make initializing statements
    if not init_ss and not fld.is_final:
      call = Clazz.call_init_if_instantiable(fld.typ)
      if call: init_ss = [st.gen_S_assign(exp.gen_E_id(fld.name), call)]

    # update the method body
    if init_ss:
      for init in inits: init.body.extend(init_ss[:])
コード例 #6
0
ファイル: clazz.py プロジェクト: chubbymaggie/java-sketch
 def call_init(tname, params=[]):
   args = []
   try:
     cls = class_lookup(tname)
     inits = cls.mtd_by_name(tname) # AttributeError if cls is NoneType
     for init in inits:
       _args = method.sig_match(init.params, params)
       # try to find best matched one
       if len(args) <= len(_args): args = _args
   except (AttributeError, IndexError): pass
   f = exp.gen_E_id(tname)
   args = map(exp.to_expression, args)
   return exp.gen_E_new(exp.gen_E_call(f, args)), args
コード例 #7
0
    def init_fld(self, fld, init_ss=[]):
        # declare <init> if not exists
        inits = self.mtd_by_name(self._name)
        if not inits: inits = [self.add_default_init()]

        # make initializing statements
        if not init_ss and not fld.is_final:
            call = Clazz.call_init_if_instantiable(fld.typ)
            if call: init_ss = [st.gen_S_assign(exp.gen_E_id(fld.name), call)]

        # update the method body
        if init_ss:
            for init in inits:
                init.body.extend(init_ss[:])
コード例 #8
0
 def call_init(tname, params=[]):
     args = []
     try:
         cls = class_lookup(tname)
         inits = cls.mtd_by_name(tname)  # AttributeError if cls is NoneType
         for init in inits:
             _args = method.sig_match(init.params, params)
             # try to find best matched one
             if len(args) <= len(_args): args = _args
     except (AttributeError, IndexError):
         pass
     f = exp.gen_E_id(tname)
     args = map(exp.to_expression, args)
     return exp.gen_E_new(exp.gen_E_call(f, args)), args
コード例 #9
0
ファイル: statement.py プロジェクト: jack51706/pasket
        b = map(curried_s, rm_braces(ss))
        s = gen_S_repeat(e, b)

    # (S... minrepeat { (S... ) })
    elif kind == "minrepeat":
        ss = _nodes[1:]  # exclude the first node: minrepeat
        b = map(curried_s, rm_braces(ss))
        s = gen_S_minrepeat(b)

    # (S... for (FOR_CTRL typ var : (E... ) ) { (S... ) })
    elif kind == "for":
        ctrl = node.getChild(1)
        ty = ctrl.getChild(0).getText()
        i = ctrl.getChild(1).getText()
        mtd.locals[i] = ty  # NOTE: incorrect scope, in fact.
        e_def = gen_E_id(i, ty)
        e_iter = curried_e(ctrl.getChildren()[-1])
        ss = _nodes[2:]  # exclude first two nodes: for (... )
        b = map(curried_s, rm_braces(ss))
        s = gen_S_for(e_def, e_iter, b)

    # (S... break Id? ';')
    elif kind == "break":
        # TODO: break identifier
        s = gen_S_break()

    # (S... try { (S... ) }
    #   (catch (PARAMS typ var) { (S... ) })*
    #   (finally { (S... ) })? )
    elif kind == "try":
        catches = []
コード例 #10
0
ファイル: statement.py プロジェクト: chubbymaggie/java-sketch
    b = map(curried_s, rm_braces(ss))
    s = gen_S_repeat(e, b)

  # (S... minrepeat { (S... ) })
  elif kind == "minrepeat":
    ss = _nodes[1:] # exclude the first node: minrepeat
    b = map(curried_s, rm_braces(ss))
    s = gen_S_minrepeat(b)

  # (S... for (FOR_CTRL typ var : (E... ) ) { (S... ) })
  elif kind == "for":
    ctrl = node.getChild(1)
    ty = ctrl.getChild(0).getText()
    i = ctrl.getChild(1).getText()
    mtd.locals[i] = ty # NOTE: incorrect scope, in fact.
    e_def = gen_E_id(i, ty)
    e_iter = curried_e(ctrl.getChildren()[-1])
    ss = _nodes[2:] # exclude first two nodes: for (... )
    b = map(curried_s, rm_braces(ss))
    s = gen_S_for(e_def, e_iter, b)

  # (S... break Id? ';')
  elif kind == "break":
    # TODO: break identifier
    s = gen_S_break()

  # (S... try { (S... ) }
  #   (catch (PARAMS typ var) { (S... ) })*
  #   (finally { (S... ) })? )
  elif kind == "try":
    catches = []