Exemplo n.º 1
0
	def decode(self, data, shared = None):
		"""
		Decode a term to its SMT representation.
		"""
		if cc.is_symb(data):
			s = "|{}|".format(cc.get_symb(data))
			if s not in self.vars and s not in self.aux_vars:
				self.aux_vars.append(s)
				self.commands.append(["declare-const", s, "Term"])
			return s
		elif cc.is_int(data):
			return ["int", build_int(cc.get_int(data))]
		elif cc.is_float(data):
			return ["real", build_real(cc.get_float(data))]
		elif cc.is_atom(data):
			return ["atom", build_ilist(cc.get_atom_chars(data))]
		elif cc.is_list(data):
			items = cc.get_list_subterms(data)
			if shared is None:
				shared = cc.get_shared(data)
			return ["list", build_tlist([self.decode(item, shared) for item in items])]
		elif cc.is_tuple(data):
			items = cc.get_tuple_subterms(data)
			if shared is None:
				shared = cc.get_shared(data)
			return ["tuple", build_tlist([self.decode(item, shared) for item in items])]
		elif cc.is_bitstring(data):
			return ["str", build_slist(cc.get_bits(data))]
		elif cc.is_alias(data):
			return self.decode(shared[cc.get_alias(data)], shared)
		clg.debug_info("decoding failed: " + str(data))
		assert False
Exemplo n.º 2
0
def pretty(d):
    global scnt, symbs
    try:
        # Symbolic Variable
        if cc.is_symb(d):
            s = cc.get_symb(d)
            if s in symbs:
                return symbs[s]
            else:
                scnt += 1
                x = "x%s" % scnt
                symbs[s] = x
                return x
        # Type
        if cc.is_type_message(d):
            return pretty_type(d)
        # Int
        if cc.is_int(d):
            return str(cc.get_int(d))
        # Float
        if cc.is_float(d):
            return str(cc.get_float(d))
        # Atom
        if cc.is_atom(d):
            cs = cc.get_atom_chars(d)
            return "".join(map(chr, cs))
        # List
        if cc.is_list(d):
            return "[%s]" % pretty_list(cc.get_list_subterms(d))
        # Bitstring
        if cc.is_bitstring(d):
            bits = map(lambda x: 1 if x else 0, cc.get_bits(d))
            return "<<%s>>" % pretty_list(bits)
    except KeyError:
        pass
    return str(d)
Exemplo n.º 3
0
def pretty(d):
    global scnt, symbs
    try:
        # Symbolic Variable
        if cc.is_symb(d):
            s = cc.get_symb(d)
            if s in symbs:
                return symbs[s] + "(" + s + ")"
            else:
                scnt += 1
                x = "x%s" % scnt
                symbs[s] = x
                return x + "(" + s + ")"
        # Type
        if cc.is_type_message(d):
            return pretty_type(d)
        # Int
        if cc.is_int(d):
            return str(cc.get_int(d))
        # Float
        if cc.is_float(d):
            return str(cc.get_float(d))
        # Atom
        if cc.is_atom(d):
            cs = cc.get_atom_chars(d)
            return "".join(map(chr, cs))
        # List
        if cc.is_list(d):
            return "[%s]" % pretty_list(cc.get_list_subterms(d))
        # Bitstring
        if cc.is_bitstring(d):
            bits = map(lambda x: 1 if x else 0, cc.get_bits(d))
            return "<<%s>>" % pretty_list(bits)
    except KeyError:
        pass
    return str(d)