def is_aliasing(self): if not self._init: return False if not self.is_static or not self.is_final: return False fld_a = None if self._init.kind == C.E.DOT: rcv_ty = exp.typ_of_e(None, self._init.le) fld_a = clazz.find_fld(rcv_ty, self._init.re.id) elif self._init.kind == C.E.ID: fld_a = clazz.find_fld(self._clazz.name, self._init.id) return fld_a != None
def typ(self, mtd): curried = lambda e: e.typ(mtd) if self.kind == C.E.ANNO: anno = self.anno if anno.name in [C.A.NEW, C.A.OBJ]: return anno.typ elif anno.name in [C.A.CMP, C.A.CMP_STR]: return C.J.i elif self.kind == C.E.C: if self.c == C.J.N: return C.J.OBJ elif self.c in [C.J.TRUE, C.J.FALSE]: return C.J.z else: return C.J.i elif self.kind == C.E.ID: if hasattr(self, "ty"): return self.ty v = self.id try: return mtd.vars[v] except (AttributeError, KeyError): if util.is_class_name(v): return v elif util.is_str(v): return C.J.STR elif util.is_char(v): return C.J.c else: fld = None if mtd: fld = clazz.find_fld(mtd.clazz.name, v) if fld: return fld.typ else: return C.J.OBJ elif self.kind == C.E.UOP: return C.J.i elif self.kind == C.E.BOP: return C.J.i elif self.kind == C.E.DOT: # with package names, e.g., javax.swing.SwingUtilities # also, avoid constant, e.g., KeyEvent.VK_* if util.is_class_name(self.re.id) and class_lookup(self.re.id): return self.re.id else: rcv_ty = curried(self.le) if self.re.id == C.J.THIS: # ClassName.this return rcv_ty else: # instance field fld = clazz.find_fld(rcv_ty, self.re.id) return fld.typ elif self.kind == C.E.IDX: typ = curried(self.e) return typ[:-2] # trim last "[]" elif self.kind == C.E.NEW: return curried(self.e) elif self.kind == C.E.CALL: arg_typs = map(curried, self.a) if self.f.kind == C.E.DOT: # inner class's <init>, e.g., ViewGroup.LayoutParams(...) if util.is_class_name(self.f.re.id): return unicode(self.f) else: # rcv.mid rcv_ty = curried(self.f.le) mname = self.f.re.id mtd_callees = clazz.find_mtds_by_sig( rcv_ty, mname, arg_typs) if mtd_callees: # TODO: check all found types are compatible or return least upper bound return mtd_callees[0].typ else: raise Exception("unresolved call: {}".format( str(self))) else: # mid mname = self.f.id if mname in C.typ_arrays: return C.J.i elif util.is_class_name(mname): # <init> return mname elif mname == C.J.SUP and mtd.is_init: # super() inside <init> return mtd.clazz.sup else: if mname == C.J.SUP: # super(...) mtd_callees = clazz.find_mtds_by_sig( mtd.clazz.sup, mtd.name, mtd.param_typs) else: # member methods mtd_callees = clazz.find_mtds_by_sig( mtd.clazz.name, mname, arg_typs) if mtd_callees: # TODO: check all found types are compatible or return least upper bound return mtd_callees[0].typ else: raise Exception("unresolved call: {}".format( str(self))) elif self.kind == C.E.CAST: return curried(self.ty) else: # HOLE, GEN return C.J.i
def typ(self, mtd): curried = lambda e: e.typ(mtd) if self.kind == C.E.ANNO: anno = self.anno if anno.name in [C.A.NEW, C.A.OBJ]: return anno.typ elif anno.name in [C.A.CMP, C.A.CMP_STR]: return C.J.i elif self.kind == C.E.C: if self.c == C.J.N: return C.J.OBJ elif self.c in [C.J.TRUE, C.J.FALSE]: return C.J.z else: return C.J.i elif self.kind == C.E.ID: if hasattr(self, "ty"): return self.ty v = self.id try: return mtd.vars[v] except (AttributeError, KeyError): if util.is_class_name(v): return v elif util.is_str(v): return C.J.STR elif util.is_char(v): return C.J.c else: fld = None if mtd: fld = clazz.find_fld(mtd.clazz.name, v) if fld: return fld.typ else: return C.J.OBJ elif self.kind == C.E.UOP: return C.J.i elif self.kind == C.E.BOP: return C.J.i elif self.kind == C.E.DOT: # with package names, e.g., javax.swing.SwingUtilities # also, avoid constant, e.g., KeyEvent.VK_* if util.is_class_name(self.re.id) and class_lookup(self.re.id): return self.re.id else: rcv_ty = curried(self.le) if self.re.id == C.J.THIS: # ClassName.this return rcv_ty else: # instance field fld = clazz.find_fld(rcv_ty, self.re.id) return fld.typ elif self.kind == C.E.IDX: typ = curried(self.e) return typ[:-2] # trim last "[]" elif self.kind == C.E.NEW: return curried(self.e) elif self.kind == C.E.CALL: arg_typs = map(curried, self.a) if self.f.kind == C.E.DOT: # inner class's <init>, e.g., ViewGroup.LayoutParams(...) if util.is_class_name(self.f.re.id): return unicode(self.f) else: # rcv.mid rcv_ty = curried(self.f.le) mname = self.f.re.id mtd_callees = clazz.find_mtds_by_sig(rcv_ty, mname, arg_typs) if mtd_callees: # TODO: check all found types are compatible or return least upper bound return mtd_callees[0].typ else: raise Exception("unresolved call: {}".format(str(self))) else: # mid mname = self.f.id if mname in C.typ_arrays: return C.J.i elif util.is_class_name(mname): # <init> return mname elif mname == C.J.SUP and mtd.is_init: # super() inside <init> return mtd.clazz.sup else: if mname == C.J.SUP: # super(...) mtd_callees = clazz.find_mtds_by_sig(mtd.clazz.sup, mtd.name, mtd.param_typs) else: # member methods mtd_callees = clazz.find_mtds_by_sig(mtd.clazz.name, mname, arg_typs) if mtd_callees: # TODO: check all found types are compatible or return least upper bound return mtd_callees[0].typ else: raise Exception("unresolved call: {}".format(str(self))) elif self.kind == C.E.CAST: return curried(self.ty) else: # HOLE, GEN return C.J.i