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

Constructor & Destructor Documentation

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

Definition at line 4804 of file z3py.py.

4804  def __init__(self, v=None, ctx=None):
4805  self.vector = None
4806  if v == None:
4807  self.ctx = _get_ctx(ctx)
4808  self.vector = Z3_mk_ast_vector(self.ctx.ref())
4809  else:
4810  self.vector = v
4811  assert ctx != None
4812  self.ctx = ctx
4813  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
4814 
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:4804
Z3_ast_vector Z3_API Z3_mk_ast_vector(__in Z3_context c)
Return an empty AST vector.
def __del__ (   self)

Definition at line 4815 of file z3py.py.

4815  def __del__(self):
4816  if self.vector != None:
4817  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
4818 
def __del__(self)
Definition: z3py.py:4815
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 4888 of file z3py.py.

4888  def __contains__(self, item):
4889  """Return `True` if the vector contains `item`.
4890 
4891  >>> x = Int('x')
4892  >>> A = AstVector()
4893  >>> x in A
4894  False
4895  >>> A.push(x)
4896  >>> x in A
4897  True
4898  >>> (x+1) in A
4899  False
4900  >>> A.push(x+1)
4901  >>> (x+1) in A
4902  True
4903  >>> A
4904  [x, x + 1]
4905  """
4906  for elem in self:
4907  if elem.eq(item):
4908  return True
4909  return False
4910 
def __contains__(self, item)
Definition: z3py.py:4888
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 4832 of file z3py.py.

4832  def __getitem__(self, i):
4833  """Return the AST at position `i`.
4834 
4835  >>> A = AstVector()
4836  >>> A.push(Int('x') + 1)
4837  >>> A.push(Int('y'))
4838  >>> A[0]
4839  x + 1
4840  >>> A[1]
4841  y
4842  """
4843  if i >= self.__len__():
4844  raise IndexError
4845  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
4846 
def __len__(self)
Definition: z3py.py:4819
def __getitem__(self, i)
Definition: z3py.py:4832
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 4819 of file z3py.py.

Referenced by AstVector.__getitem__().

4819  def __len__(self):
4820  """Return the size of the vector `self`.
4821 
4822  >>> A = AstVector()
4823  >>> len(A)
4824  0
4825  >>> A.push(Int('x'))
4826  >>> A.push(Int('x'))
4827  >>> len(A)
4828  2
4829  """
4830  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
4831 
def __len__(self)
Definition: z3py.py:4819
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 4924 of file z3py.py.

4924  def __repr__(self):
4925  return obj_to_string(self)
4926 
def __repr__(self)
Definition: z3py.py:4924
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 4847 of file z3py.py.

4847  def __setitem__(self, i, v):
4848  """Update AST at position `i`.
4849 
4850  >>> A = AstVector()
4851  >>> A.push(Int('x') + 1)
4852  >>> A.push(Int('y'))
4853  >>> A[0]
4854  x + 1
4855  >>> A[0] = Int('x')
4856  >>> A[0]
4857  x
4858  """
4859  if i >= self.__len__():
4860  raise IndexError
4861  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
4862 
def __len__(self)
Definition: z3py.py:4819
def __setitem__(self, i, v)
Definition: z3py.py:4847
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 4863 of file z3py.py.

4863  def push(self, v):
4864  """Add `v` in the end of the vector.
4865 
4866  >>> A = AstVector()
4867  >>> len(A)
4868  0
4869  >>> A.push(Int('x'))
4870  >>> len(A)
4871  1
4872  """
4873  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
4874 
def push(self, v)
Definition: z3py.py:4863
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 4875 of file z3py.py.

4875  def resize(self, sz):
4876  """Resize the vector to `sz` elements.
4877 
4878  >>> A = AstVector()
4879  >>> A.resize(10)
4880  >>> len(A)
4881  10
4882  >>> for i in range(10): A[i] = Int('x')
4883  >>> A[5]
4884  x
4885  """
4886  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
4887 
def resize(self, sz)
Definition: z3py.py:4875
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 4927 of file z3py.py.

Referenced by Fixedpoint.__repr__().

4927  def sexpr(self):
4928  """Return a textual representation of the s-expression representing the vector."""
4929  return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
4930 
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:4927
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 4911 of file z3py.py.

4911  def translate(self, other_ctx):
4912  """Copy vector `self` to context `other_ctx`.
4913 
4914  >>> x = Int('x')
4915  >>> A = AstVector()
4916  >>> A.push(x)
4917  >>> c2 = Context()
4918  >>> B = A.translate(c2)
4919  >>> B
4920  [x]
4921  """
4922  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
4923 
def translate(self, other_ctx)
Definition: z3py.py:4911
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