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

Public Member Functions

def __init__
 
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 __copy__ (self)
 
def __deepcopy__
 
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 5787 of file z3py.py.

Constructor & Destructor Documentation

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

Definition at line 5790 of file z3py.py.

5790  def __init__(self, v=None, ctx=None):
5791  self.vector = None
5792  if v is None:
5793  self.ctx = _get_ctx(ctx)
5794  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5795  else:
5796  self.vector = v
5797  assert ctx is not None
5798  self.ctx = ctx
5799  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
5800 
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:5790
def __del__ (   self)

Definition at line 5801 of file z3py.py.

5801  def __del__(self):
5802  if self.vector is not None and self.ctx.ref() is not None:
5803  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5804 
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:5801

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 5888 of file z3py.py.

5888  def __contains__(self, item):
5889  """Return `True` if the vector contains `item`.
5890 
5891  >>> x = Int('x')
5892  >>> A = AstVector()
5893  >>> x in A
5894  False
5895  >>> A.push(x)
5896  >>> x in A
5897  True
5898  >>> (x+1) in A
5899  False
5900  >>> A.push(x+1)
5901  >>> (x+1) in A
5902  True
5903  >>> A
5904  [x, x + 1]
5905  """
5906  for elem in self:
5907  if elem.eq(item):
5908  return True
5909  return False
5910 
def __contains__(self, item)
Definition: z3py.py:5888
def __copy__ (   self)

Definition at line 5927 of file z3py.py.

5927  def __copy__(self):
5928  return self.translate(self.ctx)
5929 
def translate(self, other_ctx)
Definition: z3py.py:5911
def __copy__(self)
Definition: z3py.py:5927
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5930 of file z3py.py.

5930  def __deepcopy__(self, memo={}):
5931  return self.translate(self.ctx)
5932 
def translate(self, other_ctx)
Definition: z3py.py:5911
def __deepcopy__
Definition: z3py.py:5930
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 5818 of file z3py.py.

5818  def __getitem__(self, i):
5819  """Return the AST at position `i`.
5820 
5821  >>> A = AstVector()
5822  >>> A.push(Int('x') + 1)
5823  >>> A.push(Int('y'))
5824  >>> A[0]
5825  x + 1
5826  >>> A[1]
5827  y
5828  """
5829 
5830  if isinstance(i, int):
5831  if i < 0:
5832  i += self.__len__()
5833 
5834  if i >= self.__len__():
5835  raise IndexError
5836  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5837 
5838  elif isinstance(i, slice):
5839  result = []
5840  for ii in range(*i.indices(self.__len__())):
5841  result.append(_to_ast_ref(
5842  Z3_ast_vector_get(self.ctx.ref(), self.vector, ii),
5843  self.ctx,
5844  ))
5845  return result
5846 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3794
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:5805
def __getitem__(self, i)
Definition: z3py.py:5818
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 5805 of file z3py.py.

Referenced by AstVector.__getitem__().

5805  def __len__(self):
5806  """Return the size of the vector `self`.
5807 
5808  >>> A = AstVector()
5809  >>> len(A)
5810  0
5811  >>> A.push(Int('x'))
5812  >>> A.push(Int('x'))
5813  >>> len(A)
5814  2
5815  """
5816  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5817 
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:5805
def __repr__ (   self)

Definition at line 5933 of file z3py.py.

5933  def __repr__(self):
5934  return obj_to_string(self)
5935 
def __repr__(self)
Definition: z3py.py:5933
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 5847 of file z3py.py.

5847  def __setitem__(self, i, v):
5848  """Update AST at position `i`.
5849 
5850  >>> A = AstVector()
5851  >>> A.push(Int('x') + 1)
5852  >>> A.push(Int('y'))
5853  >>> A[0]
5854  x + 1
5855  >>> A[0] = Int('x')
5856  >>> A[0]
5857  x
5858  """
5859  if i >= self.__len__():
5860  raise IndexError
5861  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5862 
def __len__(self)
Definition: z3py.py:5805
def __setitem__(self, i, v)
Definition: z3py.py:5847
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 5863 of file z3py.py.

5863  def push(self, v):
5864  """Add `v` in the end of the vector.
5865 
5866  >>> A = AstVector()
5867  >>> len(A)
5868  0
5869  >>> A.push(Int('x'))
5870  >>> len(A)
5871  1
5872  """
5873  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5874 
def push(self, v)
Definition: z3py.py:5863
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 5875 of file z3py.py.

5875  def resize(self, sz):
5876  """Resize the vector to `sz` elements.
5877 
5878  >>> A = AstVector()
5879  >>> A.resize(10)
5880  >>> len(A)
5881  10
5882  >>> for i in range(10): A[i] = Int('x')
5883  >>> A[5]
5884  x
5885  """
5886  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5887 
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:5875
def sexpr (   self)
Return a textual representation of the s-expression representing the vector.

Definition at line 5936 of file z3py.py.

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

5936  def sexpr(self):
5937  """Return a textual representation of the s-expression representing the vector."""
5938  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5939 
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:5936
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 5911 of file z3py.py.

Referenced by AstVector.__copy__(), and AstVector.__deepcopy__().

5911  def translate(self, other_ctx):
5912  """Copy vector `self` to context `other_ctx`.
5913 
5914  >>> x = Int('x')
5915  >>> A = AstVector()
5916  >>> A.push(x)
5917  >>> c2 = Context()
5918  >>> B = A.translate(c2)
5919  >>> B
5920  [x]
5921  """
5922  return AstVector(
5923  Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()),
5924  ctx=other_ctx,
5925  )
5926 
def translate(self, other_ctx)
Definition: z3py.py:5911
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