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

Public Member Functions

def __init__
 
def __del__
 
def __len__
 
def __getitem__
 
def __setitem__
 
def push
 
def resize
 
def __contains__
 
def translate
 
def __repr__
 
def sexpr
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

Data Fields

 vector
 
 ctx
 

Detailed Description

A collection (vector) of ASTs.

Definition at line 4861 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  v = None,
  ctx = None 
)

Definition at line 4864 of file z3py.py.

4865  def __init__(self, v=None, ctx=None):
4866  self.vector = None
4867  if v == None:
4868  self.ctx = _get_ctx(ctx)
4869  self.vector = Z3_mk_ast_vector(self.ctx.ref())
4870  else:
4871  self.vector = v
4872  assert ctx != None
4873  self.ctx = ctx
4874  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.
def __init__
Definition: z3py.py:4864
def __del__ (   self)

Definition at line 4875 of file z3py.py.

4876  def __del__(self):
4877  if self.vector != None:
4878  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
def __del__
Definition: z3py.py:4875
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.

Member Function Documentation

def __contains__ (   self,
  item 
)
Return `True` if the vector contains `item`.

>>> x = Int('x')
>>> A = AstVector()
>>> x in A
False
>>> A.push(x)
>>> x in A
True
>>> (x+1) in A
False
>>> A.push(x+1)
>>> (x+1) in A
True
>>> A
[x, x + 1]

Definition at line 4948 of file z3py.py.

4949  def __contains__(self, item):
4950  """Return `True` if the vector contains `item`.
4951 
4952  >>> x = Int('x')
4953  >>> A = AstVector()
4954  >>> x in A
4955  False
4956  >>> A.push(x)
4957  >>> x in A
4958  True
4959  >>> (x+1) in A
4960  False
4961  >>> A.push(x+1)
4962  >>> (x+1) in A
4963  True
4964  >>> A
4965  [x, x + 1]
4966  """
4967  for elem in self:
4968  if elem.eq(item):
4969  return True
4970  return False
def __contains__
Definition: z3py.py:4948
def __getitem__ (   self,
  i 
)
Return the AST at position `i`.

>>> A = AstVector()
>>> A.push(Int('x') + 1)
>>> A.push(Int('y'))
>>> A[0]
x + 1
>>> A[1]
y

Definition at line 4892 of file z3py.py.

4893  def __getitem__(self, i):
4894  """Return the AST at position `i`.
4895 
4896  >>> A = AstVector()
4897  >>> A.push(Int('x') + 1)
4898  >>> A.push(Int('y'))
4899  >>> A[0]
4900  x + 1
4901  >>> A[1]
4902  y
4903  """
4904  if i >= self.__len__():
4905  raise IndexError
4906  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
def __len__
Definition: z3py.py:4879
def __getitem__
Definition: z3py.py:4892
Z3_ast Z3_API Z3_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.
def __len__ (   self)
Return the size of the vector `self`.

>>> A = AstVector()
>>> len(A)
0
>>> A.push(Int('x'))
>>> A.push(Int('x'))
>>> len(A)
2

Definition at line 4879 of file z3py.py.

Referenced by AstVector.__getitem__().

4880  def __len__(self):
4881  """Return the size of the vector `self`.
4882 
4883  >>> A = AstVector()
4884  >>> len(A)
4885  0
4886  >>> A.push(Int('x'))
4887  >>> A.push(Int('x'))
4888  >>> len(A)
4889  2
4890  """
4891  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
def __len__
Definition: z3py.py:4879
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
def __repr__ (   self)

Definition at line 4984 of file z3py.py.

4985  def __repr__(self):
4986  return obj_to_string(self)
def __repr__
Definition: z3py.py:4984
def __setitem__ (   self,
  i,
  v 
)
Update AST at position `i`.

>>> A = AstVector()
>>> A.push(Int('x') + 1)
>>> A.push(Int('y'))
>>> A[0]
x + 1
>>> A[0] = Int('x')
>>> A[0]
x

Definition at line 4907 of file z3py.py.

4908  def __setitem__(self, i, v):
4909  """Update AST at position `i`.
4910 
4911  >>> A = AstVector()
4912  >>> A.push(Int('x') + 1)
4913  >>> A.push(Int('y'))
4914  >>> A[0]
4915  x + 1
4916  >>> A[0] = Int('x')
4917  >>> A[0]
4918  x
4919  """
4920  if i >= self.__len__():
4921  raise IndexError
4922  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
def __len__
Definition: z3py.py:4879
def __setitem__
Definition: z3py.py:4907
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a)
Update position i of the AST vector v with the AST a.
def push (   self,
  v 
)
Add `v` in the end of the vector.

>>> A = AstVector()
>>> len(A)
0
>>> A.push(Int('x'))
>>> len(A)
1

Definition at line 4923 of file z3py.py.

4924  def push(self, v):
4925  """Add `v` in the end of the vector.
4926 
4927  >>> A = AstVector()
4928  >>> len(A)
4929  0
4930  >>> A.push(Int('x'))
4931  >>> len(A)
4932  1
4933  """
4934  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.
def resize (   self,
  sz 
)
Resize the vector to `sz` elements.

>>> A = AstVector()
>>> A.resize(10)
>>> len(A)
10
>>> for i in range(10): A[i] = Int('x')
>>> A[5]
x

Definition at line 4935 of file z3py.py.

4936  def resize(self, sz):
4937  """Resize the vector to `sz` elements.
4938 
4939  >>> A = AstVector()
4940  >>> A.resize(10)
4941  >>> len(A)
4942  10
4943  >>> for i in range(10): A[i] = Int('x')
4944  >>> A[5]
4945  x
4946  """
4947  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
def resize
Definition: z3py.py:4935
def sexpr (   self)
Return a textual representation of the s-expression representing the vector.

Definition at line 4987 of file z3py.py.

Referenced by Fixedpoint.__repr__(), and Optimize.__repr__().

4988  def sexpr(self):
4989  """Return a textual representation of the s-expression representing the vector."""
4990  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
def translate (   self,
  other_ctx 
)
Copy vector `self` to context `other_ctx`.

>>> x = Int('x')
>>> A = AstVector()
>>> A.push(x)
>>> c2 = Context()
>>> B = A.translate(c2)
>>> B
[x]

Definition at line 4971 of file z3py.py.

4972  def translate(self, other_ctx):
4973  """Copy vector `self` to context `other_ctx`.
4974 
4975  >>> x = Int('x')
4976  >>> A = AstVector()
4977  >>> A.push(x)
4978  >>> c2 = Context()
4979  >>> B = A.translate(c2)
4980  >>> B
4981  [x]
4982  """
4983  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.
def translate
Definition: z3py.py:4971

Field Documentation

ctx

Definition at line 4867 of file z3py.py.

Referenced by Probe.__eq__(), Probe.__ge__(), AstVector.__getitem__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), ApplyResult.as_expr(), Fixedpoint.assert_exprs(), ApplyResult.convert_model(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_rules(), Optimize.model(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.query(), Fixedpoint.set(), Optimize.set(), Tactic.solver(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), and Fixedpoint.update_rule().

vector

Definition at line 4865 of file z3py.py.

Referenced by AstVector.__del__(), AstVector.__getitem__(), AstVector.__len__(), AstVector.__setitem__(), AstVector.push(), AstVector.resize(), AstVector.sexpr(), and AstVector.translate().