Z3
Public Member Functions | Data Fields
AstMap Class Reference

Public Member Functions

def __init__
 
def __deepcopy__
 
def __del__ (self)
 
def __len__ (self)
 
def __contains__ (self, key)
 
def __getitem__ (self, key)
 
def __setitem__ (self, k, v)
 
def __repr__ (self)
 
def erase (self, k)
 
def reset (self)
 
def keys (self)
 

Data Fields

 map
 
 ctx
 

Detailed Description

A mapping from ASTs to ASTs.

Definition at line 5947 of file z3py.py.

Constructor & Destructor Documentation

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

Definition at line 5950 of file z3py.py.

5950  def __init__(self, m=None, ctx=None):
5951  self.map = None
5952  if m is None:
5953  self.ctx = _get_ctx(ctx)
5954  self.map = Z3_mk_ast_map(self.ctx.ref())
5955  else:
5956  self.map = m
5957  assert ctx is not None
5958  self.ctx = ctx
5959  Z3_ast_map_inc_ref(self.ctx.ref(), self.map)
5960 
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m)
Increment the reference counter of the given AST map.
Z3_ast_map Z3_API Z3_mk_ast_map(Z3_context c)
Return an empty mapping from AST to AST.
def __init__
Definition: z3py.py:5950
def __del__ (   self)

Definition at line 5964 of file z3py.py.

5964  def __del__(self):
5965  if self.map is not None and self.ctx.ref() is not None:
5966  Z3_ast_map_dec_ref(self.ctx.ref(), self.map)
5967 
def __del__(self)
Definition: z3py.py:5964
void Z3_API Z3_ast_map_dec_ref(Z3_context c, Z3_ast_map m)
Decrement the reference counter of the given AST map.

Member Function Documentation

def __contains__ (   self,
  key 
)
Return `True` if the map contains key `key`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> x in M
True
>>> x+1 in M
False

Definition at line 5981 of file z3py.py.

5981  def __contains__(self, key):
5982  """Return `True` if the map contains key `key`.
5983 
5984  >>> M = AstMap()
5985  >>> x = Int('x')
5986  >>> M[x] = x + 1
5987  >>> x in M
5988  True
5989  >>> x+1 in M
5990  False
5991  """
5992  return Z3_ast_map_contains(self.ctx.ref(), self.map, key.as_ast())
5993 
bool Z3_API Z3_ast_map_contains(Z3_context c, Z3_ast_map m, Z3_ast k)
Return true if the map m contains the AST key k.
def __contains__(self, key)
Definition: z3py.py:5981
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 5961 of file z3py.py.

5961  def __deepcopy__(self, memo={}):
5962  return AstMap(self.map, self.ctx)
5963 
def __deepcopy__
Definition: z3py.py:5961
def __getitem__ (   self,
  key 
)
Retrieve the value associated with key `key`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> M[x]
x + 1

Definition at line 5994 of file z3py.py.

5994  def __getitem__(self, key):
5995  """Retrieve the value associated with key `key`.
5996 
5997  >>> M = AstMap()
5998  >>> x = Int('x')
5999  >>> M[x] = x + 1
6000  >>> M[x]
6001  x + 1
6002  """
6003  return _to_ast_ref(Z3_ast_map_find(self.ctx.ref(), self.map, key.as_ast()), self.ctx)
6004 
Z3_ast Z3_API Z3_ast_map_find(Z3_context c, Z3_ast_map m, Z3_ast k)
Return the value associated with the key k.
def __getitem__(self, key)
Definition: z3py.py:5994
def __len__ (   self)
Return the size of the map.

>>> M = AstMap()
>>> len(M)
0
>>> x = Int('x')
>>> M[x] = IntVal(1)
>>> len(M)
1

Definition at line 5968 of file z3py.py.

5968  def __len__(self):
5969  """Return the size of the map.
5970 
5971  >>> M = AstMap()
5972  >>> len(M)
5973  0
5974  >>> x = Int('x')
5975  >>> M[x] = IntVal(1)
5976  >>> len(M)
5977  1
5978  """
5979  return int(Z3_ast_map_size(self.ctx.ref(), self.map))
5980 
def __len__(self)
Definition: z3py.py:5968
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.
def __repr__ (   self)

Definition at line 6021 of file z3py.py.

6021  def __repr__(self):
6022  return Z3_ast_map_to_string(self.ctx.ref(), self.map)
6023 
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.
def __repr__(self)
Definition: z3py.py:6021
def __setitem__ (   self,
  k,
  v 
)
Add/Update key `k` with value `v`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> len(M)
1
>>> M[x]
x + 1
>>> M[x] = IntVal(1)
>>> M[x]
1

Definition at line 6005 of file z3py.py.

6005  def __setitem__(self, k, v):
6006  """Add/Update key `k` with value `v`.
6007 
6008  >>> M = AstMap()
6009  >>> x = Int('x')
6010  >>> M[x] = x + 1
6011  >>> len(M)
6012  1
6013  >>> M[x]
6014  x + 1
6015  >>> M[x] = IntVal(1)
6016  >>> M[x]
6017  1
6018  """
6019  Z3_ast_map_insert(self.ctx.ref(), self.map, k.as_ast(), v.as_ast())
6020 
def __setitem__(self, k, v)
Definition: z3py.py:6005
void Z3_API Z3_ast_map_insert(Z3_context c, Z3_ast_map m, Z3_ast k, Z3_ast v)
Store/Replace a new key, value pair in the given map.
def erase (   self,
  k 
)
Remove the entry associated with key `k`.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x] = x + 1
>>> len(M)
1
>>> M.erase(x)
>>> len(M)
0

Definition at line 6024 of file z3py.py.

6024  def erase(self, k):
6025  """Remove the entry associated with key `k`.
6026 
6027  >>> M = AstMap()
6028  >>> x = Int('x')
6029  >>> M[x] = x + 1
6030  >>> len(M)
6031  1
6032  >>> M.erase(x)
6033  >>> len(M)
6034  0
6035  """
6036  Z3_ast_map_erase(self.ctx.ref(), self.map, k.as_ast())
6037 
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.
def erase(self, k)
Definition: z3py.py:6024
def keys (   self)
Return an AstVector containing all keys in the map.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x]   = x + 1
>>> M[x+x] = IntVal(1)
>>> M.keys()
[x, x + x]

Definition at line 6053 of file z3py.py.

6053  def keys(self):
6054  """Return an AstVector containing all keys in the map.
6055 
6056  >>> M = AstMap()
6057  >>> x = Int('x')
6058  >>> M[x] = x + 1
6059  >>> M[x+x] = IntVal(1)
6060  >>> M.keys()
6061  [x, x + x]
6062  """
6063  return AstVector(Z3_ast_map_keys(self.ctx.ref(), self.map), self.ctx)
6064 
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.
def keys(self)
Definition: z3py.py:6053
def reset (   self)
Remove all entries from the map.

>>> M = AstMap()
>>> x = Int('x')
>>> M[x]   = x + 1
>>> M[x+x] = IntVal(1)
>>> len(M)
2
>>> M.reset()
>>> len(M)
0

Definition at line 6038 of file z3py.py.

6038  def reset(self):
6039  """Remove all entries from the map.
6040 
6041  >>> M = AstMap()
6042  >>> x = Int('x')
6043  >>> M[x] = x + 1
6044  >>> M[x+x] = IntVal(1)
6045  >>> len(M)
6046  2
6047  >>> M.reset()
6048  >>> len(M)
6049  0
6050  """
6051  Z3_ast_map_reset(self.ctx.ref(), self.map)
6052 
def reset(self)
Definition: z3py.py:6038
void Z3_API Z3_ast_map_reset(Z3_context c, Z3_ast_map m)
Remove all keys from the given map.

Field Documentation

ctx
map