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

Constructor & Destructor Documentation

§ __init__()

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

Definition at line 4987 of file z3py.py.

4987  def __init__(self, v=None, ctx=None):
4988  self.vector = None
4989  if v is None:
4990  self.ctx = _get_ctx(ctx)
4991  self.vector = Z3_mk_ast_vector(self.ctx.ref())
4992  else:
4993  self.vector = v
4994  assert ctx is not None
4995  self.ctx = ctx
4996  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
4997 

§ __del__()

def __del__ (   self)

Definition at line 4998 of file z3py.py.

4998  def __del__(self):
4999  if self.vector is not None and self.ctx.ref() is not None:
5000  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
5001 

Member Function Documentation

§ __contains__()

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

5071  def __contains__(self, item):
5072  """Return `True` if the vector contains `item`.
5073 
5074  >>> x = Int('x')
5075  >>> A = AstVector()
5076  >>> x in A
5077  False
5078  >>> A.push(x)
5079  >>> x in A
5080  True
5081  >>> (x+1) in A
5082  False
5083  >>> A.push(x+1)
5084  >>> (x+1) in A
5085  True
5086  >>> A
5087  [x, x + 1]
5088  """
5089  for elem in self:
5090  if elem.eq(item):
5091  return True
5092  return False
5093 

§ __getitem__()

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

5015  def __getitem__(self, i):
5016  """Return the AST at position `i`.
5017 
5018  >>> A = AstVector()
5019  >>> A.push(Int('x') + 1)
5020  >>> A.push(Int('y'))
5021  >>> A[0]
5022  x + 1
5023  >>> A[1]
5024  y
5025  """
5026  if i >= self.__len__():
5027  raise IndexError
5028  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5029 

§ __len__()

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

5002  def __len__(self):
5003  """Return the size of the vector `self`.
5004 
5005  >>> A = AstVector()
5006  >>> len(A)
5007  0
5008  >>> A.push(Int('x'))
5009  >>> A.push(Int('x'))
5010  >>> len(A)
5011  2
5012  """
5013  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
5014 

§ __repr__()

def __repr__ (   self)

Definition at line 5107 of file z3py.py.

5107  def __repr__(self):
5108  return obj_to_string(self)
5109 

§ __setitem__()

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

5030  def __setitem__(self, i, v):
5031  """Update AST at position `i`.
5032 
5033  >>> A = AstVector()
5034  >>> A.push(Int('x') + 1)
5035  >>> A.push(Int('y'))
5036  >>> A[0]
5037  x + 1
5038  >>> A[0] = Int('x')
5039  >>> A[0]
5040  x
5041  """
5042  if i >= self.__len__():
5043  raise IndexError
5044  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
5045 

§ push()

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

5046  def push(self, v):
5047  """Add `v` in the end of the vector.
5048 
5049  >>> A = AstVector()
5050  >>> len(A)
5051  0
5052  >>> A.push(Int('x'))
5053  >>> len(A)
5054  1
5055  """
5056  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
5057 

§ resize()

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

5058  def resize(self, sz):
5059  """Resize the vector to `sz` elements.
5060 
5061  >>> A = AstVector()
5062  >>> A.resize(10)
5063  >>> len(A)
5064  10
5065  >>> for i in range(10): A[i] = Int('x')
5066  >>> A[5]
5067  x
5068  """
5069  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
5070 

§ sexpr()

def sexpr (   self)
Return a textual representation of the s-expression representing the vector.

Definition at line 5110 of file z3py.py.

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

5110  def sexpr(self):
5111  """Return a textual representation of the s-expression representing the vector."""
5112  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
5113 

§ translate()

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

5094  def translate(self, other_ctx):
5095  """Copy vector `self` to context `other_ctx`.
5096 
5097  >>> x = Int('x')
5098  >>> A = AstVector()
5099  >>> A.push(x)
5100  >>> c2 = Context()
5101  >>> B = A.translate(c2)
5102  >>> B
5103  [x]
5104  """
5105  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
5106 

Field Documentation

§ ctx

ctx

§ vector

vector

Definition at line 4988 of file z3py.py.