Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions cvc5_pythonic_api/cvc5_pythonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ def _to_sort_ref(s, ctx):
return FPRMSortRef(s, ctx)
elif s.isFunction():
return FuncSortRef(s, ctx)
elif s.isDatatype():
return DatatypeSortRef(s, ctx)
return SortRef(s, ctx)


Expand Down Expand Up @@ -1088,6 +1090,8 @@ def _to_expr_ref(a, ctx, r=None):
return SeqRef(ast, ctx, r)
if sort.isFunction():
return FuncDeclRef(ast, ctx, r)
if sort.isDatatype():
return DatatypeRef(ast, ctx, r)
return ExprRef(ast, ctx, r)


Expand Down Expand Up @@ -9054,11 +9058,36 @@ def __call__(self, *args):


class DatatypeRef(ExprRef):
"""Datatype expressions."""
"""Datatype expressions.

Constants and applications of a datatype sort are instances of this class.

>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> isinstance(Const('l', List), DatatypeRef)
True
>>> isinstance(List.cons(10, List.nil), DatatypeRef)
True
"""

def sort(self):
"""Return the datatype sort of the datatype expression `self`."""
return DatatypeSortRef(self.as_ast().getSort(), self.ctx)
"""Return the datatype sort of the datatype expression `self`.

>>> List = Datatype('List')
>>> List.declare('cons', ('car', IntSort()), ('cdr', List))
>>> List.declare('nil')
>>> List = List.create()
>>> l = Const('l', List)
>>> l.sort()
List
>>> l.sort().num_constructors()
2
>>> l.sort().accessor(0, 0)
car
"""
return _sort(self.ctx, self.ast)


def TupleSort(name, sorts, ctx=None):
Expand Down