Z3
Loading...
Searching...
No Matches
AstMap Class Reference

Public Member Functions

 __init__ (self, m=None, ctx=None)
 __deepcopy__ (self, memo={})
 __del__ (self)
 __len__ (self)
 __contains__ (self, key)
 __getitem__ (self, key)
 __setitem__ (self, k, v)
 __repr__ (self)
 erase (self, k)
 reset (self)
 keys (self)

Data Fields

 map = None
 ctx = _get_ctx(ctx)

Detailed Description

A mapping from ASTs to ASTs.

Definition at line 6134 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 6137 of file z3py.py.

6137 def __init__(self, m=None, ctx=None):
6138 self.map = None
6139 if m is None:
6140 self.ctx = _get_ctx(ctx)
6141 self.map = Z3_mk_ast_map(self.ctx.ref())
6142 else:
6143 self.map = m
6144 assert ctx is not None
6145 self.ctx = ctx
6146 Z3_ast_map_inc_ref(self.ctx.ref(), self.map)
6147
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.

◆ __del__()

__del__ ( self)

Definition at line 6151 of file z3py.py.

6151 def __del__(self):
6152 if self.map is not None and self.ctx.ref() is not None and Z3_ast_map_dec_ref is not None:
6153 Z3_ast_map_dec_ref(self.ctx.ref(), self.map)
6154
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

◆ __contains__()

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

6168 def __contains__(self, key):
6169 """Return `True` if the map contains key `key`.
6170
6171 >>> M = AstMap()
6172 >>> x = Int('x')
6173 >>> M[x] = x + 1
6174 >>> x in M
6175 True
6176 >>> x+1 in M
6177 False
6178 """
6179 return Z3_ast_map_contains(self.ctx.ref(), self.map, key.as_ast())
6180
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.

◆ __deepcopy__()

__deepcopy__ ( self,
memo = {} )

Definition at line 6148 of file z3py.py.

6148 def __deepcopy__(self, memo={}):
6149 return AstMap(self.map, self.ctx)
6150

◆ __getitem__()

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

6181 def __getitem__(self, key):
6182 """Retrieve the value associated with key `key`.
6183
6184 >>> M = AstMap()
6185 >>> x = Int('x')
6186 >>> M[x] = x + 1
6187 >>> M[x]
6188 x + 1
6189 """
6190 return _to_ast_ref(Z3_ast_map_find(self.ctx.ref(), self.map, key.as_ast()), self.ctx)
6191
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.

◆ __len__()

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

6155 def __len__(self):
6156 """Return the size of the map.
6157
6158 >>> M = AstMap()
6159 >>> len(M)
6160 0
6161 >>> x = Int('x')
6162 >>> M[x] = IntVal(1)
6163 >>> len(M)
6164 1
6165 """
6166 return int(Z3_ast_map_size(self.ctx.ref(), self.map))
6167
unsigned Z3_API Z3_ast_map_size(Z3_context c, Z3_ast_map m)
Return the size of the given map.

◆ __repr__()

__repr__ ( self)

Definition at line 6208 of file z3py.py.

6208 def __repr__(self):
6209 return Z3_ast_map_to_string(self.ctx.ref(), self.map)
6210
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m)
Convert the given map into a string.

◆ __setitem__()

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

6192 def __setitem__(self, k, v):
6193 """Add/Update key `k` with value `v`.
6194
6195 >>> M = AstMap()
6196 >>> x = Int('x')
6197 >>> M[x] = x + 1
6198 >>> len(M)
6199 1
6200 >>> M[x]
6201 x + 1
6202 >>> M[x] = IntVal(1)
6203 >>> M[x]
6204 1
6205 """
6206 Z3_ast_map_insert(self.ctx.ref(), self.map, k.as_ast(), v.as_ast())
6207
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.

◆ erase()

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

6211 def erase(self, k):
6212 """Remove the entry associated with key `k`.
6213
6214 >>> M = AstMap()
6215 >>> x = Int('x')
6216 >>> M[x] = x + 1
6217 >>> len(M)
6218 1
6219 >>> M.erase(x)
6220 >>> len(M)
6221 0
6222 """
6223 Z3_ast_map_erase(self.ctx.ref(), self.map, k.as_ast())
6224
void Z3_API Z3_ast_map_erase(Z3_context c, Z3_ast_map m, Z3_ast k)
Erase a key from the map.

◆ keys()

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

6240 def keys(self):
6241 """Return an AstVector containing all keys in the map.
6242
6243 >>> M = AstMap()
6244 >>> x = Int('x')
6245 >>> M[x] = x + 1
6246 >>> M[x+x] = IntVal(1)
6247 >>> M.keys()
6248 [x, x + x]
6249 """
6250 return AstVector(Z3_ast_map_keys(self.ctx.ref(), self.map), self.ctx)
6251
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m)
Return the keys stored in the given map.

◆ reset()

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

6225 def reset(self):
6226 """Remove all entries from the map.
6227
6228 >>> M = AstMap()
6229 >>> x = Int('x')
6230 >>> M[x] = x + 1
6231 >>> M[x+x] = IntVal(1)
6232 >>> len(M)
6233 2
6234 >>> M.reset()
6235 >>> len(M)
6236 0
6237 """
6238 Z3_ast_map_reset(self.ctx.ref(), self.map)
6239
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

map = None