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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 6099 of file z3py.py.

6099 def __init__(self, m=None, ctx=None):
6100 self.map = None
6101 if m is None:
6102 self.ctx = _get_ctx(ctx)
6103 self.map = Z3_mk_ast_map(self.ctx.ref())
6104 else:
6105 self.map = m
6106 assert ctx is not None
6107 self.ctx = ctx
6108 Z3_ast_map_inc_ref(self.ctx.ref(), self.map)
6109
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 6113 of file z3py.py.

6113 def __del__(self):
6114 if self.map is not None and self.ctx.ref() is not None and Z3_ast_map_dec_ref is not None:
6115 Z3_ast_map_dec_ref(self.ctx.ref(), self.map)
6116
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 6130 of file z3py.py.

6130 def __contains__(self, key):
6131 """Return `True` if the map contains key `key`.
6132
6133 >>> M = AstMap()
6134 >>> x = Int('x')
6135 >>> M[x] = x + 1
6136 >>> x in M
6137 True
6138 >>> x+1 in M
6139 False
6140 """
6141 return Z3_ast_map_contains(self.ctx.ref(), self.map, key.as_ast())
6142
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 6110 of file z3py.py.

6110 def __deepcopy__(self, memo={}):
6111 return AstMap(self.map, self.ctx)
6112

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

6143 def __getitem__(self, key):
6144 """Retrieve the value associated with key `key`.
6145
6146 >>> M = AstMap()
6147 >>> x = Int('x')
6148 >>> M[x] = x + 1
6149 >>> M[x]
6150 x + 1
6151 """
6152 return _to_ast_ref(Z3_ast_map_find(self.ctx.ref(), self.map, key.as_ast()), self.ctx)
6153
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 6117 of file z3py.py.

6117 def __len__(self):
6118 """Return the size of the map.
6119
6120 >>> M = AstMap()
6121 >>> len(M)
6122 0
6123 >>> x = Int('x')
6124 >>> M[x] = IntVal(1)
6125 >>> len(M)
6126 1
6127 """
6128 return int(Z3_ast_map_size(self.ctx.ref(), self.map))
6129
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 6170 of file z3py.py.

6170 def __repr__(self):
6171 return Z3_ast_map_to_string(self.ctx.ref(), self.map)
6172
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 6154 of file z3py.py.

6154 def __setitem__(self, k, v):
6155 """Add/Update key `k` with value `v`.
6156
6157 >>> M = AstMap()
6158 >>> x = Int('x')
6159 >>> M[x] = x + 1
6160 >>> len(M)
6161 1
6162 >>> M[x]
6163 x + 1
6164 >>> M[x] = IntVal(1)
6165 >>> M[x]
6166 1
6167 """
6168 Z3_ast_map_insert(self.ctx.ref(), self.map, k.as_ast(), v.as_ast())
6169
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 6173 of file z3py.py.

6173 def erase(self, k):
6174 """Remove the entry associated with key `k`.
6175
6176 >>> M = AstMap()
6177 >>> x = Int('x')
6178 >>> M[x] = x + 1
6179 >>> len(M)
6180 1
6181 >>> M.erase(x)
6182 >>> len(M)
6183 0
6184 """
6185 Z3_ast_map_erase(self.ctx.ref(), self.map, k.as_ast())
6186
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 6202 of file z3py.py.

6202 def keys(self):
6203 """Return an AstVector containing all keys in the map.
6204
6205 >>> M = AstMap()
6206 >>> x = Int('x')
6207 >>> M[x] = x + 1
6208 >>> M[x+x] = IntVal(1)
6209 >>> M.keys()
6210 [x, x + x]
6211 """
6212 return AstVector(Z3_ast_map_keys(self.ctx.ref(), self.map), self.ctx)
6213
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 6187 of file z3py.py.

6187 def reset(self):
6188 """Remove all entries from the map.
6189
6190 >>> M = AstMap()
6191 >>> x = Int('x')
6192 >>> M[x] = x + 1
6193 >>> M[x+x] = IntVal(1)
6194 >>> len(M)
6195 2
6196 >>> M.reset()
6197 >>> len(M)
6198 0
6199 """
6200 Z3_ast_map_reset(self.ctx.ref(), self.map)
6201
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