Exemple #1
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[:])
Exemple #2
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[:])
Exemple #3
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[:])
Exemple #4
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[:])
Exemple #5
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
Exemple #6
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