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

Constructor & Destructor Documentation

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

Definition at line 4827 of file z3py.py.

4827  def __init__(self, v=None, ctx=None):
4828  self.vector = None
4829  if v == None:
4830  self.ctx = _get_ctx(ctx)
4831  self.vector = Z3_mk_ast_vector(self.ctx.ref())
4832  else:
4833  self.vector = v
4834  assert ctx != None
4835  self.ctx = ctx
4836  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
4837 
void Z3_API Z3_ast_vector_inc_ref(__in Z3_context c, __in Z3_ast_vector v)
Increment the reference counter of the given AST vector.
def __init__
Definition: z3py.py:4827
Z3_ast_vector Z3_API Z3_mk_ast_vector(__in Z3_context c)
Return an empty AST vector.
def __del__ (   self)

Definition at line 4838 of file z3py.py.

4838  def __del__(self):
4839  if self.vector != None:
4840  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
4841 
def __del__(self)
Definition: z3py.py:4838
void Z3_API Z3_ast_vector_dec_ref(__in Z3_context c, __in 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 4911 of file z3py.py.

4911  def __contains__(self, item):
4912  """Return `True` if the vector contains `item`.
4913 
4914  >>> x = Int('x')
4915  >>> A = AstVector()
4916  >>> x in A
4917  False
4918  >>> A.push(x)
4919  >>> x in A
4920  True
4921  >>> (x+1) in A
4922  False
4923  >>> A.push(x+1)
4924  >>> (x+1) in A
4925  True
4926  >>> A
4927  [x, x + 1]
4928  """
4929  for elem in self:
4930  if elem.eq(item):
4931  return True
4932  return False
4933 
def __contains__(self, item)
Definition: z3py.py:4911
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 4855 of file z3py.py.

4855  def __getitem__(self, i):
4856  """Return the AST at position `i`.
4857 
4858  >>> A = AstVector()
4859  >>> A.push(Int('x') + 1)
4860  >>> A.push(Int('y'))
4861  >>> A[0]
4862  x + 1
4863  >>> A[1]
4864  y
4865  """
4866  if i >= self.__len__():
4867  raise IndexError
4868  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
4869 
def __len__(self)
Definition: z3py.py:4842
def __getitem__(self, i)
Definition: z3py.py:4855
Z3_ast Z3_API Z3_ast_vector_get(__in Z3_context c, __in Z3_ast_vector v, __in 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 4842 of file z3py.py.

Referenced by AstVector.__getitem__().

4842  def __len__(self):
4843  """Return the size of the vector `self`.
4844 
4845  >>> A = AstVector()
4846  >>> len(A)
4847  0
4848  >>> A.push(Int('x'))
4849  >>> A.push(Int('x'))
4850  >>> len(A)
4851  2
4852  """
4853  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
4854 
def __len__(self)
Definition: z3py.py:4842
unsigned Z3_API Z3_ast_vector_size(__in Z3_context c, __in Z3_ast_vector v)
Return the size of the given AST vector.
def __repr__ (   self)

Definition at line 4947 of file z3py.py.

4947  def __repr__(self):
4948  return obj_to_string(self)
4949 
def __repr__(self)
Definition: z3py.py:4947
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 4870 of file z3py.py.

4870  def __setitem__(self, i, v):
4871  """Update AST at position `i`.
4872 
4873  >>> A = AstVector()
4874  >>> A.push(Int('x') + 1)
4875  >>> A.push(Int('y'))
4876  >>> A[0]
4877  x + 1
4878  >>> A[0] = Int('x')
4879  >>> A[0]
4880  x
4881  """
4882  if i >= self.__len__():
4883  raise IndexError
4884  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
4885 
def __len__(self)
Definition: z3py.py:4842
def __setitem__(self, i, v)
Definition: z3py.py:4870
void Z3_API Z3_ast_vector_set(__in Z3_context c, __in Z3_ast_vector v, __in unsigned i, __in 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 4886 of file z3py.py.

4886  def push(self, v):
4887  """Add `v` in the end of the vector.
4888 
4889  >>> A = AstVector()
4890  >>> len(A)
4891  0
4892  >>> A.push(Int('x'))
4893  >>> len(A)
4894  1
4895  """
4896  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
4897 
def push(self, v)
Definition: z3py.py:4886
void Z3_API Z3_ast_vector_push(__in Z3_context c, __in Z3_ast_vector v, __in 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 4898 of file z3py.py.

4898  def resize(self, sz):
4899  """Resize the vector to `sz` elements.
4900 
4901  >>> A = AstVector()
4902  >>> A.resize(10)
4903  >>> len(A)
4904  10
4905  >>> for i in range(10): A[i] = Int('x')
4906  >>> A[5]
4907  x
4908  """
4909  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
4910 
def resize(self, sz)
Definition: z3py.py:4898
void Z3_API Z3_ast_vector_resize(__in Z3_context c, __in Z3_ast_vector v, __in unsigned n)
Resize the AST vector v.
def sexpr (   self)
Return a textual representation of the s-expression representing the vector.

Definition at line 4950 of file z3py.py.

Referenced by Fixedpoint.__repr__().

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

4934  def translate(self, other_ctx):
4935  """Copy vector `self` to context `other_ctx`.
4936 
4937  >>> x = Int('x')
4938  >>> A = AstVector()
4939  >>> A.push(x)
4940  >>> c2 = Context()
4941  >>> B = A.translate(c2)
4942  >>> B
4943  [x]
4944  """
4945  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
4946 
def translate(self, other_ctx)
Definition: z3py.py:4934
Z3_ast_vector Z3_API Z3_ast_vector_translate(__in Z3_context s, __in Z3_ast_vector v, __in Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.

Field Documentation

ctx
vector