def reduce_anno_mtd(smpls, tmpl, cls, mtd): if not mtd.annos: return mname = mtd.name for _anno in mtd.annos: ## ## @Error void mname() ## if _anno.name == C.A.ERR: if not hasattr(cls, "state"): raise ReduceError("no state variable") setattr(cls.state, "error", mtd) state = cls.state.name body = T("${state} = ??;").safe_substitute(locals()) mtd.body = st.to_statements(mtd, body) + mtd.body ## ## @Assemble typ mname(...) ## ## ## @CFG(other_mname) typ mname(...) ## elif _anno.name == C.A.CFG: # find the designated method _, cls_c_name, mtd_c_name = util.explode_mname(_anno.mid) if cls_c_name: mtd_c = class_lookup(cls_c_name).mtd_by_name(mtd_c_name) else: mtd_c = cls.mtd_by_name(mtd_c_name) # and then copy its body if mtd_c: mtd.body = mtd_c[0].body
def sanitize_id(dot_id): pkg, cls, mtd = util.explode_mname(dot_id) if cls and util.is_class_name(cls) and class_lookup(cls): clazz = class_lookup(cls) if clazz.pkg and pkg and clazz.pkg != pkg: # to avoid u'' != None raise Exception("wrong package", pkg, clazz.pkg) return '.'.join([cls, mtd]) return dot_id
def __init__(self, line, depth=0): self._depth = depth m = re.match(r"(>|<) (.*)\((.*)\)", line) if m: # m.group(1) = '>' or '<' self._pkg, self._cls, self._mtd = util.explode_mname(m.group(2)) vals = map(op.methodcaller("strip"), m.group(3).split(',')) self._vals = util.ffilter(vals) # to remove empty strings else: raise Exception("wrong call sequences", line)
def wrap_obj(val): if '@' not in val: return val typ_w_pkg, hsh = val.split('@') _, typ, _ = util.explode_mname(typ_w_pkg + ".<init>") # regard the type's <init> is used at the least if typ not in self._decls: self._decls[typ] = [] if typ in self._objs: if hsh in self._objs[typ]: idx = self._objs[typ].index(hsh) else: # first appearance of this hash idx = len(self._objs[typ]) self._objs[typ].append(hsh) else: # first obj of this typ idx = 0 self._objs[typ] = [hsh] return u"@Object(typ={}, idx={})".format(typ, idx)