Z3
Loading...
Searching...
No Matches
AstVector Class Reference
Inheritance diagram for AstVector:

Public Member Functions

 __init__ (self, v=None, ctx=None)
 __del__ (self)
 __len__ (self)
 __getitem__ (self, i)
 __setitem__ (self, i, v)
 push (self, v)
 resize (self, sz)
 __contains__ (self, item)
 translate (self, other_ctx)
 __copy__ (self)
 __deepcopy__ (self, memo={})
 __repr__ (self)
 sexpr (self)
Public Member Functions inherited from Z3PPObject
 use_pp (self)

Data Fields

 vector = None
 ctx = _get_ctx(ctx)

Additional Inherited Members

Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)

Detailed Description

A collection (vector) of ASTs.

Definition at line 6069 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 6072 of file z3py.py.

6072 def __init__(self, v=None, ctx=None):
6073 self.vector = None
6074 if v is None:
6075 self.ctx = _get_ctx(ctx)
6076 self.vector = Z3_mk_ast_vector(self.ctx.ref())
6077 else:
6078 self.vector = v
6079 assert ctx is not None
6080 self.ctx = ctx
6081 Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
6082
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v)
Increment the reference counter of the given AST vector.
Z3_ast_vector Z3_API Z3_mk_ast_vector(Z3_context c)
Return an empty AST vector.

◆ __del__()

__del__ ( self)

Definition at line 6083 of file z3py.py.

6083 def __del__(self):
6084 if self.vector is not None and self.ctx.ref() is not None and Z3_ast_vector_dec_ref is not None:
6085 Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
6086
void Z3_API Z3_ast_vector_dec_ref(Z3_context c, Z3_ast_vector v)
Decrement the reference counter of the given AST vector.

Member Function Documentation

◆ __contains__()

__contains__ ( self,
item )
Return `True` if the vector contains `item`.

>>> x = Int('x')
>>> A = AstVector()
>>> x in A
False
>>> A.push(x)
>>> x in A
True
>>> (x+1) in A
False
>>> A.push(x+1)
>>> (x+1) in A
True
>>> A
[x, x + 1]

Definition at line 6170 of file z3py.py.

6170 def __contains__(self, item):
6171 """Return `True` if the vector contains `item`.
6172
6173 >>> x = Int('x')
6174 >>> A = AstVector()
6175 >>> x in A
6176 False
6177 >>> A.push(x)
6178 >>> x in A
6179 True
6180 >>> (x+1) in A
6181 False
6182 >>> A.push(x+1)
6183 >>> (x+1) in A
6184 True
6185 >>> A
6186 [x, x + 1]
6187 """
6188 for elem in self:
6189 if elem.eq(item):
6190 return True
6191 return False
6192

◆ __copy__()

__copy__ ( self)

Definition at line 6209 of file z3py.py.

6209 def __copy__(self):
6210 return self.translate(self.ctx)
6211

◆ __deepcopy__()

__deepcopy__ ( self,
memo = {} )

Definition at line 6212 of file z3py.py.

6212 def __deepcopy__(self, memo={}):
6213 return self.translate(self.ctx)
6214

◆ __getitem__()

__getitem__ ( self,
i )
Return the AST at position `i`.

>>> A = AstVector()
>>> A.push(Int('x') + 1)
>>> A.push(Int('y'))
>>> A[0]
x + 1
>>> A[1]
y

Definition at line 6100 of file z3py.py.

6100 def __getitem__(self, i):
6101 """Return the AST at position `i`.
6102
6103 >>> A = AstVector()
6104 >>> A.push(Int('x') + 1)
6105 >>> A.push(Int('y'))
6106 >>> A[0]
6107 x + 1
6108 >>> A[1]
6109 y
6110 """
6111
6112 if isinstance(i, int):
6113 if i < 0:
6114 i += self.__len__()
6115
6116 if i >= self.__len__():
6117 raise IndexError
6118 return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
6119
6120 elif isinstance(i, slice):
6121 result = []
6122 for ii in range(*i.indices(self.__len__())):
6123 result.append(_to_ast_ref(
6124 Z3_ast_vector_get(self.ctx.ref(), self.vector, ii),
6125 self.ctx,
6126 ))
6127 return result
6128
Z3_ast Z3_API Z3_ast_vector_get(Z3_context c, Z3_ast_vector v, unsigned i)
Return the AST at position i in the AST vector v.

◆ __len__()

__len__ ( self)
Return the size of the vector `self`.

>>> A = AstVector()
>>> len(A)
0
>>> A.push(Int('x'))
>>> A.push(Int('x'))
>>> len(A)
2

Definition at line 6087 of file z3py.py.

6087 def __len__(self):
6088 """Return the size of the vector `self`.
6089
6090 >>> A = AstVector()
6091 >>> len(A)
6092 0
6093 >>> A.push(Int('x'))
6094 >>> A.push(Int('x'))
6095 >>> len(A)
6096 2
6097 """
6098 return int(Z3_ast_vector_size(self.ctx.ref(), self.vector))
6099
unsigned Z3_API Z3_ast_vector_size(Z3_context c, Z3_ast_vector v)
Return the size of the given AST vector.

Referenced by __getitem__(), and __setitem__().

◆ __repr__()

__repr__ ( self)

Definition at line 6215 of file z3py.py.

6215 def __repr__(self):
6216 return obj_to_string(self)
6217

◆ __setitem__()

__setitem__ ( self,
i,
v )
Update AST at position `i`.

>>> A = AstVector()
>>> A.push(Int('x') + 1)
>>> A.push(Int('y'))
>>> A[0]
x + 1
>>> A[0] = Int('x')
>>> A[0]
x

Definition at line 6129 of file z3py.py.

6129 def __setitem__(self, i, v):
6130 """Update AST at position `i`.
6131
6132 >>> A = AstVector()
6133 >>> A.push(Int('x') + 1)
6134 >>> A.push(Int('y'))
6135 >>> A[0]
6136 x + 1
6137 >>> A[0] = Int('x')
6138 >>> A[0]
6139 x
6140 """
6141 if i >= self.__len__():
6142 raise IndexError
6143 Z3_ast_vector_set(self.ctx.ref(), self.vector, i, v.as_ast())
6144
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a)
Update position i of the AST vector v with the AST a.

◆ push()

push ( self,
v )
Add `v` in the end of the vector.

>>> A = AstVector()
>>> len(A)
0
>>> A.push(Int('x'))
>>> len(A)
1

Definition at line 6145 of file z3py.py.

6145 def push(self, v):
6146 """Add `v` in the end of the vector.
6147
6148 >>> A = AstVector()
6149 >>> len(A)
6150 0
6151 >>> A.push(Int('x'))
6152 >>> len(A)
6153 1
6154 """
6155 Z3_ast_vector_push(self.ctx.ref(), self.vector, v.as_ast())
6156
void Z3_API Z3_ast_vector_push(Z3_context c, Z3_ast_vector v, Z3_ast a)
Add the AST a in the end of the AST vector v. The size of v is increased by one.

Referenced by Solver.__enter__().

◆ resize()

resize ( self,
sz )
Resize the vector to `sz` elements.

>>> A = AstVector()
>>> A.resize(10)
>>> len(A)
10
>>> for i in range(10): A[i] = Int('x')
>>> A[5]
x

Definition at line 6157 of file z3py.py.

6157 def resize(self, sz):
6158 """Resize the vector to `sz` elements.
6159
6160 >>> A = AstVector()
6161 >>> A.resize(10)
6162 >>> len(A)
6163 10
6164 >>> for i in range(10): A[i] = Int('x')
6165 >>> A[5]
6166 x
6167 """
6168 Z3_ast_vector_resize(self.ctx.ref(), self.vector, sz)
6169
void Z3_API Z3_ast_vector_resize(Z3_context c, Z3_ast_vector v, unsigned n)
Resize the AST vector v.

◆ sexpr()

sexpr ( self)
Return a textual representation of the s-expression representing the vector.

Definition at line 6218 of file z3py.py.

6218 def sexpr(self):
6219 """Return a textual representation of the s-expression representing the vector."""
6220 return Z3_ast_vector_to_string(self.ctx.ref(), self.vector)
6221
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v)
Convert AST vector into a string.

◆ translate()

translate ( self,
other_ctx )
Copy vector `self` to context `other_ctx`.

>>> x = Int('x')
>>> A = AstVector()
>>> A.push(x)
>>> c2 = Context()
>>> B = A.translate(c2)
>>> B
[x]

Definition at line 6193 of file z3py.py.

6193 def translate(self, other_ctx):
6194 """Copy vector `self` to context `other_ctx`.
6195
6196 >>> x = Int('x')
6197 >>> A = AstVector()
6198 >>> A.push(x)
6199 >>> c2 = Context()
6200 >>> B = A.translate(c2)
6201 >>> B
6202 [x]
6203 """
6204 return AstVector(
6205 Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()),
6206 ctx=other_ctx,
6207 )
6208
Z3_ast_vector Z3_API Z3_ast_vector_translate(Z3_context s, Z3_ast_vector v, Z3_context t)
Translate the AST vector v from context s into an AST vector in context t.

Referenced by __copy__(), FuncInterp.__copy__(), ModelRef.__copy__(), __deepcopy__(), FuncInterp.__deepcopy__(), and ModelRef.__deepcopy__().

Field Documentation

◆ ctx

◆ vector

vector = None

Definition at line 6073 of file z3py.py.

Referenced by __del__(), __getitem__(), __len__(), __setitem__(), push(), resize(), sexpr(), and translate().