Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Data Fields
AstVector Class Reference
+ Inheritance diagram for AstVector:

Public Member Functions

def __init__
 
def __deepcopy__
 
def __del__
 
def __len__
 
def __getitem__
 
def __setitem__
 
def push
 
def resize
 
def __contains__
 
def translate
 
def __copy__
 
def __deepcopy__
 
def __repr__
 
def sexpr
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

Data Fields

 vector
 
 ctx
 

Detailed Description

A collection (vector) of ASTs.

Definition at line 5435 of file z3py.py.

Constructor & Destructor Documentation

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

Definition at line 5438 of file z3py.py.

5439  def __init__(self, v=None, ctx=None):
5440  self.vector = None
5441  if v is None:
5442  self.ctx = _get_ctx(ctx)
5443  self.vector = Z3_mk_ast_vector(self.ctx.ref())
5444  else:
5445  self.vector = v
5446  assert ctx is not None
5447  self.ctx = ctx
5448  Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
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:5438
def __del__ (   self)

Definition at line 5452 of file z3py.py.

5453  def __del__(self):
5454  if self.vector is not None and self.ctx.ref() is not None:
5455  Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
def __del__
Definition: z3py.py:5452
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, 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 5534 of file z3py.py.

5535  def __contains__(self, item):
5536  """Return `True` if the vector contains `item`.
5537 
5538  >>> x = Int('x')
5539  >>> A = AstVector()
5540  >>> x in A
5541  False
5542  >>> A.push(x)
5543  >>> x in A
5544  True
5545  >>> (x+1) in A
5546  False
5547  >>> A.push(x+1)
5548  >>> (x+1) in A
5549  True
5550  >>> A
5551  [x, x + 1]
5552  """
5553  for elem in self:
5554  if elem.eq(item):
5555  return True
5556  return False
def __contains__
Definition: z3py.py:5534
def __copy__ (   self)

Definition at line 5570 of file z3py.py.

5571  def __copy__(self):
5572  return self.translate(self.ctx)
def __copy__
Definition: z3py.py:5570
def translate
Definition: z3py.py:5557
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5449 of file z3py.py.

5450  def __deepcopy__(self, memo={}):
5451  return AstVector(self.vector, self.ctx)
def __deepcopy__
Definition: z3py.py:5449
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5573 of file z3py.py.

5574  def __deepcopy__(self, memo={}):
5575  return self.translate(self.ctx)
def __deepcopy__
Definition: z3py.py:5449
def translate
Definition: z3py.py:5557
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 5469 of file z3py.py.

5470  def __getitem__(self, i):
5471  """Return the AST at position `i`.
5472 
5473  >>> A = AstVector()
5474  >>> A.push(Int('x') + 1)
5475  >>> A.push(Int('y'))
5476  >>> A[0]
5477  x + 1
5478  >>> A[1]
5479  y
5480  """
5481 
5482  if isinstance(i, int):
5483  if i < 0:
5484  i += self.__len__()
5485 
5486  if i >= self.__len__():
5487  raise IndexError
5488  return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
5489 
5490  elif isinstance(i, slice):
5491  return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
5492 
def __len__
Definition: z3py.py:5456
def __getitem__
Definition: z3py.py:5469
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3358
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)
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 5456 of file z3py.py.

Referenced by AstVector.__getitem__().

5457  def __len__(self):
5458  """Return the size of the vector `self`.
5459 
5460  >>> A = AstVector()
5461  >>> len(A)
5462  0
5463  >>> A.push(Int('x'))
5464  >>> A.push(Int('x'))
5465  >>> len(A)
5466  2
5467  """
5468  return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
def __len__
Definition: z3py.py:5456
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.
def __repr__ (   self)

Definition at line 5576 of file z3py.py.

5577  def __repr__(self):
5578  return obj_to_string(self)
def __repr__
Definition: z3py.py:5576
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 5493 of file z3py.py.

5494  def __setitem__(self, i, v):
5495  """Update AST at position `i`.
5496 
5497  >>> A = AstVector()
5498  >>> A.push(Int('x') + 1)
5499  >>> A.push(Int('y'))
5500  >>> A[0]
5501  x + 1
5502  >>> A[0] = Int('x')
5503  >>> A[0]
5504  x
5505  """
5506  if i >= self.__len__():
5507  raise IndexError
5508  Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
def __len__
Definition: z3py.py:5456
def __setitem__
Definition: z3py.py:5493
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 5509 of file z3py.py.

5510  def push(self, v):
5511  """Add `v` in the end of the vector.
5512 
5513  >>> A = AstVector()
5514  >>> len(A)
5515  0
5516  >>> A.push(Int('x'))
5517  >>> len(A)
5518  1
5519  """
5520  Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
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 5521 of file z3py.py.

5522  def resize(self, sz):
5523  """Resize the vector to `sz` elements.
5524 
5525  >>> A = AstVector()
5526  >>> A.resize(10)
5527  >>> len(A)
5528  10
5529  >>> for i in range(10): A[i] = Int('x')
5530  >>> A[5]
5531  x
5532  """
5533  Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.
def resize
Definition: z3py.py:5521
def sexpr (   self)
Return a textual representation of the s-expression representing the vector.

Definition at line 5579 of file z3py.py.

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

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

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

5558  def translate(self, other_ctx):
5559  """Copy vector `self` to context `other_ctx`.
5560 
5561  >>> x = Int('x')
5562  >>> A = AstVector()
5563  >>> A.push(x)
5564  >>> c2 = Context()
5565  >>> B = A.translate(c2)
5566  >>> B
5567  [x]
5568  """
5569  return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
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.
def translate
Definition: z3py.py:5557

Field Documentation

ctx

Definition at line 5441 of file z3py.py.

Referenced by AstVector.__copy__(), AstVector.__deepcopy__(), AstMap.__deepcopy__(), Fixedpoint.__deepcopy__(), Optimize.__deepcopy__(), ApplyResult.__deepcopy__(), Tactic.__deepcopy__(), Probe.__deepcopy__(), Probe.__eq__(), Probe.__ge__(), AstVector.__getitem__(), AstMap.__getitem__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Probe.__lt__(), Probe.__ne__(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), ApplyResult.as_expr(), Optimize.assert_and_track(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Optimize.assertions(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_ground_sat_answer(), Fixedpoint.get_rule_names_along_trace(), Fixedpoint.get_rules(), Fixedpoint.get_rules_along_trace(), AstMap.keys(), Optimize.model(), Optimize.objectives(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.query(), Fixedpoint.set(), Optimize.set(), Tactic.solver(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Optimize.unsat_core(), and Fixedpoint.update_rule().

vector

Definition at line 5439 of file z3py.py.

Referenced by AstVector.__deepcopy__(), AstVector.__del__(), AstVector.__getitem__(), AstVector.__len__(), AstVector.__setitem__(), AstVector.push(), AstVector.resize(), AstVector.sexpr(), and AstVector.translate().