Z3
Public Member Functions | Data Fields
AstVector Class Reference
+ Inheritance diagram for AstVector:

Public Member Functions

def __init__ (self, v=None, ctx=None)
 
def __del__ (self)
 
def __len__ (self)
 
def __getitem__ (self, i)
 
def __setitem__ (self, i, v)
 
def push (self, v)
 
def resize (self, sz)
 
def __contains__ (self, item)
 
def translate (self, other_ctx)
 
def __repr__ (self)
 
def sexpr (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

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.

4864  def __init__(self, v=None, ctx=None):
4865  self.vector = None
4866  if v == None:
4867  self.ctx = _get_ctx(ctx)
4868  self.vector = Z3_mk_ast_vector(self.ctx.ref())
4869  else:
4870  self.vector = v
4871  assert ctx != None
4872  self.ctx = ctx
4873  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
4874 
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__(self, v=None, ctx=None)
Definition: z3py.py:4864
def __del__ (   self)

Definition at line 4875 of file z3py.py.

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

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.

4948  def __contains__(self, item):
4949  """Return `True` if the vector contains `item`.
4950 
4951  >>> x = Int('x')
4952  >>> A = AstVector()
4953  >>> x in A
4954  False
4955  >>> A.push(x)
4956  >>> x in A
4957  True
4958  >>> (x+1) in A
4959  False
4960  >>> A.push(x+1)
4961  >>> (x+1) in A
4962  True
4963  >>> A
4964  [x, x + 1]
4965  """
4966  for elem in self:
4967  if elem.eq(item):
4968  return True
4969  return False
4970 
def __contains__(self, item)
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.

4892  def __getitem__(self, i):
4893  """Return the AST at position `i`.
4894 
4895  >>> A = AstVector()
4896  >>> A.push(Int('x') + 1)
4897  >>> A.push(Int('y'))
4898  >>> A[0]
4899  x + 1
4900  >>> A[1]
4901  y
4902  """
4903  if i >= self.__len__():
4904  raise IndexError
4905  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
4906 
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)
Definition: z3py.py:4879
def __getitem__(self, i)
Definition: z3py.py:4892
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__().

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

Definition at line 4984 of file z3py.py.

4984  def __repr__(self):
4985  return obj_to_string(self)
4986 
def __repr__(self)
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.

4907  def __setitem__(self, i, v):
4908  """Update AST at position `i`.
4909 
4910  >>> A = AstVector()
4911  >>> A.push(Int('x') + 1)
4912  >>> A.push(Int('y'))
4913  >>> A[0]
4914  x + 1
4915  >>> A[0] = Int('x')
4916  >>> A[0]
4917  x
4918  """
4919  if i >= self.__len__():
4920  raise IndexError
4921  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
4922 
def __len__(self)
Definition: z3py.py:4879
def __setitem__(self, i, v)
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.

4923  def push(self, v):
4924  """Add `v` in the end of the vector.
4925 
4926  >>> A = AstVector()
4927  >>> len(A)
4928  0
4929  >>> A.push(Int('x'))
4930  >>> len(A)
4931  1
4932  """
4933  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
4934 
def push(self, v)
Definition: z3py.py:4923
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.

4935  def resize(self, sz):
4936  """Resize the vector to `sz` elements.
4937 
4938  >>> A = AstVector()
4939  >>> A.resize(10)
4940  >>> len(A)
4941  10
4942  >>> for i in range(10): A[i] = Int('x')
4943  >>> A[5]
4944  x
4945  """
4946  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
4947 
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
def resize(self, sz)
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__().

4987  def sexpr(self):
4988  """Return a textual representation of the s-expression representing the vector."""
4989  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
4990 
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.
def sexpr(self)
Definition: z3py.py:4987
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.

4971  def translate(self, other_ctx):
4972  """Copy vector `self` to context `other_ctx`.
4973 
4974  >>> x = Int('x')
4975  >>> A = AstVector()
4976  >>> A.push(x)
4977  >>> c2 = Context()
4978  >>> B = A.translate(c2)
4979  >>> B
4980  [x]
4981  """
4982  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
4983 
def translate(self, other_ctx)
Definition: z3py.py:4971
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.

Field Documentation

ctx
vector