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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 6773 of file z3py.py.

6773 def __init__(self, m=None, ctx=None):
6774 self.map = None
6775 if m is None:
6776 self.ctx = _get_ctx(ctx)
6777 self.map = Z3_mk_ast_map(self.ctx.ref())
6778 else:
6779 self.map = m
6780 assert ctx is not None
6781 self.ctx = ctx
6782 Z3_ast_map_inc_ref(self.ctx.ref(), self.map)
6783
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 6787 of file z3py.py.

6787 def __del__(self):
6788 if self.map is not None and self.ctx.ref() is not None and Z3_ast_map_dec_ref is not None:
6789 Z3_ast_map_dec_ref(self.ctx.ref(), self.map)
6790
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 6804 of file z3py.py.

6804 def __contains__(self, key):
6805 """Return `True` if the map contains key `key`.
6806
6807 >>> M = AstMap()
6808 >>> x = Int('x')
6809 >>> M[x] = x + 1
6810 >>> x in M
6811 True
6812 >>> x+1 in M
6813 False
6814 """
6815 return Z3_ast_map_contains(self.ctx.ref(), self.map, key.as_ast())
6816
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 6784 of file z3py.py.

6784 def __deepcopy__(self, memo={}):
6785 return AstMap(self.map, self.ctx)
6786

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

6817 def __getitem__(self, key):
6818 """Retrieve the value associated with key `key`.
6819
6820 >>> M = AstMap()
6821 >>> x = Int('x')
6822 >>> M[x] = x + 1
6823 >>> M[x]
6824 x + 1
6825 """
6826 return _to_ast_ref(Z3_ast_map_find(self.ctx.ref(), self.map, key.as_ast()), self.ctx)
6827
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 6791 of file z3py.py.

6791 def __len__(self):
6792 """Return the size of the map.
6793
6794 >>> M = AstMap()
6795 >>> len(M)
6796 0
6797 >>> x = Int('x')
6798 >>> M[x] = IntVal(1)
6799 >>> len(M)
6800 1
6801 """
6802 return int(Z3_ast_map_size(self.ctx.ref(), self.map))
6803
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 6844 of file z3py.py.

6844 def __repr__(self):
6845 return Z3_ast_map_to_string(self.ctx.ref(), self.map)
6846
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 6828 of file z3py.py.

6828 def __setitem__(self, k, v):
6829 """Add/Update key `k` with value `v`.
6830
6831 >>> M = AstMap()
6832 >>> x = Int('x')
6833 >>> M[x] = x + 1
6834 >>> len(M)
6835 1
6836 >>> M[x]
6837 x + 1
6838 >>> M[x] = IntVal(1)
6839 >>> M[x]
6840 1
6841 """
6842 Z3_ast_map_insert(self.ctx.ref(), self.map, k.as_ast(), v.as_ast())
6843
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 6847 of file z3py.py.

6847 def erase(self, k):
6848 """Remove the entry associated with key `k`.
6849
6850 >>> M = AstMap()
6851 >>> x = Int('x')
6852 >>> M[x] = x + 1
6853 >>> len(M)
6854 1
6855 >>> M.erase(x)
6856 >>> len(M)
6857 0
6858 """
6859 Z3_ast_map_erase(self.ctx.ref(), self.map, k.as_ast())
6860
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 6876 of file z3py.py.

6876 def keys(self):
6877 """Return an AstVector containing all keys in the map.
6878
6879 >>> M = AstMap()
6880 >>> x = Int('x')
6881 >>> M[x] = x + 1
6882 >>> M[x+x] = IntVal(1)
6883 >>> M.keys()
6884 [x + x, x]
6885 """
6886 return AstVector(Z3_ast_map_keys(self.ctx.ref(), self.map), self.ctx)
6887
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 6861 of file z3py.py.

6861 def reset(self):
6862 """Remove all entries from the map.
6863
6864 >>> M = AstMap()
6865 >>> x = Int('x')
6866 >>> M[x] = x + 1
6867 >>> M[x+x] = IntVal(1)
6868 >>> len(M)
6869 2
6870 >>> M.reset()
6871 >>> len(M)
6872 0
6873 """
6874 Z3_ast_map_reset(self.ctx.ref(), self.map)
6875
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