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

Constructor & Destructor Documentation

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

Definition at line 6108 of file z3py.py.

6108  def __init__(self, m=None, ctx=None):
6109  self.map = None
6110  if m is None:
6111  self.ctx = _get_ctx(ctx)
6112  self.map = Z3_mk_ast_map(self.ctx.ref())
6113  else:
6114  self.map = m
6115  assert ctx is not None
6116  self.ctx = ctx
6117  Z3_ast_map_inc_ref(self.ctx.ref(), self.map)
6118 
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:6108
def __del__ (   self)

Definition at line 6122 of file z3py.py.

6122  def __del__(self):
6123  if self.map is not None and self.ctx.ref() is not None and Z3_ast_map_dec_ref is not None:
6124  Z3_ast_map_dec_ref(self.ctx.ref(), self.map)
6125 
def __del__(self)
Definition: z3py.py:6122
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 6139 of file z3py.py.

6139  def __contains__(self, key):
6140  """Return `True` if the map contains key `key`.
6141 
6142  >>> M = AstMap()
6143  >>> x = Int('x')
6144  >>> M[x] = x + 1
6145  >>> x in M
6146  True
6147  >>> x+1 in M
6148  False
6149  """
6150  return Z3_ast_map_contains(self.ctx.ref(), self.map, key.as_ast())
6151 
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:6139
def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 6119 of file z3py.py.

6119  def __deepcopy__(self, memo={}):
6120  return AstMap(self.map, self.ctx)
6121 
def __deepcopy__
Definition: z3py.py:6119
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 6152 of file z3py.py.

6152  def __getitem__(self, key):
6153  """Retrieve the value associated with key `key`.
6154 
6155  >>> M = AstMap()
6156  >>> x = Int('x')
6157  >>> M[x] = x + 1
6158  >>> M[x]
6159  x + 1
6160  """
6161  return _to_ast_ref(Z3_ast_map_find(self.ctx.ref(), self.map, key.as_ast()), self.ctx)
6162 
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:6152
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 6126 of file z3py.py.

6126  def __len__(self):
6127  """Return the size of the map.
6128 
6129  >>> M = AstMap()
6130  >>> len(M)
6131  0
6132  >>> x = Int('x')
6133  >>> M[x] = IntVal(1)
6134  >>> len(M)
6135  1
6136  """
6137  return int(Z3_ast_map_size(self.ctx.ref(), self.map))
6138 
def __len__(self)
Definition: z3py.py:6126
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 6179 of file z3py.py.

6179  def __repr__(self):
6180  return Z3_ast_map_to_string(self.ctx.ref(), self.map)
6181 
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:6179
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 6163 of file z3py.py.

6163  def __setitem__(self, k, v):
6164  """Add/Update key `k` with value `v`.
6165 
6166  >>> M = AstMap()
6167  >>> x = Int('x')
6168  >>> M[x] = x + 1
6169  >>> len(M)
6170  1
6171  >>> M[x]
6172  x + 1
6173  >>> M[x] = IntVal(1)
6174  >>> M[x]
6175  1
6176  """
6177  Z3_ast_map_insert(self.ctx.ref(), self.map, k.as_ast(), v.as_ast())
6178 
def __setitem__(self, k, v)
Definition: z3py.py:6163
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 6182 of file z3py.py.

6182  def erase(self, k):
6183  """Remove the entry associated with key `k`.
6184 
6185  >>> M = AstMap()
6186  >>> x = Int('x')
6187  >>> M[x] = x + 1
6188  >>> len(M)
6189  1
6190  >>> M.erase(x)
6191  >>> len(M)
6192  0
6193  """
6194  Z3_ast_map_erase(self.ctx.ref(), self.map, k.as_ast())
6195 
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:6182
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 6211 of file z3py.py.

6211  def keys(self):
6212  """Return an AstVector containing all keys in the map.
6213 
6214  >>> M = AstMap()
6215  >>> x = Int('x')
6216  >>> M[x] = x + 1
6217  >>> M[x+x] = IntVal(1)
6218  >>> M.keys()
6219  [x, x + x]
6220  """
6221  return AstVector(Z3_ast_map_keys(self.ctx.ref(), self.map), self.ctx)
6222 
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:6211
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 6196 of file z3py.py.

6196  def reset(self):
6197  """Remove all entries from the map.
6198 
6199  >>> M = AstMap()
6200  >>> x = Int('x')
6201  >>> M[x] = x + 1
6202  >>> M[x+x] = IntVal(1)
6203  >>> len(M)
6204  2
6205  >>> M.reset()
6206  >>> len(M)
6207  0
6208  """
6209  Z3_ast_map_reset(self.ctx.ref(), self.map)
6210 
def reset(self)
Definition: z3py.py:6196
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