Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Data Fields
AstRef Class Reference
+ Inheritance diagram for AstRef:

Public Member Functions

def __init__
 
def __del__
 
def __str__
 
def __repr__
 
def sexpr
 
def as_ast
 
def ctx_ref
 
def eq
 
def translate
 
def hash
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

Data Fields

 ast
 
 ctx
 

Detailed Description

AST are Direct Acyclic Graphs (DAGs) used to represent sorts, declarations and expressions.

Definition at line 246 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  ast,
  ctx = None 
)

Definition at line 248 of file z3py.py.

249  def __init__(self, ast, ctx=None):
250  self.ast = ast
251  self.ctx = _get_ctx(ctx)
252  Z3_inc_ref(self.ctx.ref(), self.as_ast())
def __del__ (   self)

Definition at line 253 of file z3py.py.

254  def __del__(self):
255  Z3_dec_ref(self.ctx.ref(), self.as_ast())

Member Function Documentation

def __repr__ (   self)

Definition at line 259 of file z3py.py.

260  def __repr__(self):
261  return obj_to_string(self)
def __str__ (   self)

Definition at line 256 of file z3py.py.

257  def __str__(self):
258  return obj_to_string(self)
def as_ast (   self)
Return a pointer to the corresponding C Z3_ast object.

Definition at line 271 of file z3py.py.

Referenced by AstRef.__del__(), ExprRef.arg(), ExprRef.decl(), AstRef.eq(), AstRef.hash(), ExprRef.num_args(), AstRef.sexpr(), ExprRef.sort(), BoolRef.sort(), and AstRef.translate().

272  def as_ast(self):
273  """Return a pointer to the corresponding C Z3_ast object."""
274  return self.ast
def ctx_ref (   self)
Return a reference to the C context where this AST node is stored.

Definition at line 275 of file z3py.py.

Referenced by SortRef.__eq__(), ExprRef.__eq__(), SortRef.__ne__(), ExprRef.__ne__(), ExprRef.arg(), FuncDeclRef.arity(), SortRef.as_ast(), FuncDeclRef.as_ast(), ExprRef.decl(), FuncDeclRef.domain(), AstRef.eq(), AstRef.hash(), FuncDeclRef.kind(), SortRef.name(), FuncDeclRef.name(), ExprRef.num_args(), FuncDeclRef.range(), AstRef.sexpr(), and BoolRef.sort().

276  def ctx_ref(self):
277  """Return a reference to the C context where this AST node is stored."""
278  return self.ctx.ref()
def eq (   self,
  other 
)
Return `True` if `self` and `other` are structurally identical.

>>> x = Int('x')
>>> n1 = x + 1
>>> n2 = 1 + x
>>> n1.eq(n2)
False
>>> n1 = simplify(n1)
>>> n2 = simplify(n2)
>>> n1.eq(n2)
True

Definition at line 279 of file z3py.py.

Referenced by SortRef.cast(), and BoolSortRef.cast().

280  def eq(self, other):
281  """Return `True` if `self` and `other` are structurally identical.
282 
283  >>> x = Int('x')
284  >>> n1 = x + 1
285  >>> n2 = 1 + x
286  >>> n1.eq(n2)
287  False
288  >>> n1 = simplify(n1)
289  >>> n2 = simplify(n2)
290  >>> n1.eq(n2)
291  True
292  """
293  if __debug__:
294  _z3_assert(is_ast(other), "Z3 AST expected")
295  return Z3_is_eq_ast(self.ctx_ref(), self.as_ast(), other.as_ast())
def hash (   self)
Return a hashcode for the `self`.

>>> n1 = simplify(Int('x') + 1)
>>> n2 = simplify(2 + Int('x') - 1)
>>> n1.hash() == n2.hash()
True

Definition at line 312 of file z3py.py.

313  def hash(self):
314  """Return a hashcode for the `self`.
315 
316  >>> n1 = simplify(Int('x') + 1)
317  >>> n2 = simplify(2 + Int('x') - 1)
318  >>> n1.hash() == n2.hash()
319  True
320  """
321  return Z3_get_ast_hash(self.ctx_ref(), self.as_ast())
def sexpr (   self)
Return an string representing the AST node in s-expression notation.

>>> x = Int('x')
>>> ((x + 1)*x).sexpr()
'(* (+ x 1) x)'

Definition at line 262 of file z3py.py.

Referenced by ArithRef.__div__(), BitVecRef.__div__(), BitVecRef.__ge__(), ArrayRef.__getitem__(), BitVecRef.__gt__(), BitVecRef.__le__(), BitVecRef.__lshift__(), BitVecRef.__lt__(), BitVecRef.__mod__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), BitVecRef.__rlshift__(), BitVecRef.__rmod__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), and BitVecSortRef.cast().

263  def sexpr(self):
264  """Return an string representing the AST node in s-expression notation.
265 
266  >>> x = Int('x')
267  >>> ((x + 1)*x).sexpr()
268  '(* (+ x 1) x)'
269  """
270  return Z3_ast_to_string(self.ctx_ref(), self.as_ast())
def translate (   self,
  target 
)
Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`. 

>>> c1 = Context()
>>> c2 = Context()
>>> x  = Int('x', c1)
>>> y  = Int('y', c2)
>>> # Nodes in different contexts can't be mixed.
>>> # However, we can translate nodes from one context to another.
>>> x.translate(c2) + y
x + y

Definition at line 296 of file z3py.py.

297  def translate(self, target):
298  """Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
299 
300  >>> c1 = Context()
301  >>> c2 = Context()
302  >>> x = Int('x', c1)
303  >>> y = Int('y', c2)
304  >>> # Nodes in different contexts can't be mixed.
305  >>> # However, we can translate nodes from one context to another.
306  >>> x.translate(c2) + y
307  x + y
308  """
309  if __debug__:
310  _z3_assert(isinstance(target, Context), "argument must be a Z3 context")
311  return _to_ast_ref(Z3_translate(self.ctx.ref(), self.as_ast(), target.ref()), target)

Field Documentation

ast

Definition at line 249 of file z3py.py.

Referenced by SortRef.__eq__(), SortRef.__ne__(), FuncDeclRef.arity(), AstRef.as_ast(), SortRef.as_ast(), FuncDeclRef.as_ast(), ExprRef.as_ast(), FuncDeclRef.domain(), SortRef.kind(), FuncDeclRef.kind(), SortRef.name(), FuncDeclRef.name(), and FuncDeclRef.range().

ctx

Definition at line 250 of file z3py.py.

Referenced by ExprRef.__eq__(), Probe.__eq__(), Probe.__ge__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), ExprRef.__ne__(), Probe.__ne__(), Tactic.apply(), ExprRef.arg(), ApplyResult.as_expr(), BoolSortRef.cast(), ApplyResult.convert_model(), ExprRef.decl(), FuncDeclRef.domain(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_rules(), SortRef.kind(), SortRef.name(), FuncDeclRef.name(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), FuncDeclRef.range(), Tactic.solver(), ExprRef.sort(), BoolRef.sort(), and Fixedpoint.statistics().