1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Morgan Deters, Tim King |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Enumerator for uninterpreted sorts and functions. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__BUILTIN__TYPE_ENUMERATOR_H |
19 |
|
#define CVC5__THEORY__BUILTIN__TYPE_ENUMERATOR_H |
20 |
|
|
21 |
|
#include "expr/kind.h" |
22 |
|
#include "expr/type_node.h" |
23 |
|
#include "expr/uninterpreted_constant.h" |
24 |
|
#include "theory/type_enumerator.h" |
25 |
|
#include "util/integer.h" |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
namespace theory { |
29 |
|
namespace builtin { |
30 |
|
|
31 |
6948 |
class UninterpretedSortEnumerator : public TypeEnumeratorBase<UninterpretedSortEnumerator> { |
32 |
|
Integer d_count; |
33 |
|
bool d_has_fixed_bound; |
34 |
|
Integer d_fixed_bound; |
35 |
|
|
36 |
|
public: |
37 |
2985 |
UninterpretedSortEnumerator(TypeNode type, |
38 |
|
TypeEnumeratorProperties* tep = nullptr) |
39 |
2985 |
: TypeEnumeratorBase<UninterpretedSortEnumerator>(type), d_count(0) |
40 |
|
{ |
41 |
2985 |
Assert(type.getKind() == kind::SORT_TYPE); |
42 |
2985 |
d_has_fixed_bound = false; |
43 |
2985 |
Trace("uf-type-enum") << "UF enum " << type << ", tep = " << tep << std::endl; |
44 |
2985 |
if( tep && tep->d_fixed_usort_card ){ |
45 |
2176 |
d_has_fixed_bound = true; |
46 |
2176 |
std::map< TypeNode, Integer >::iterator it = tep->d_fixed_card.find( type ); |
47 |
2176 |
if( it!=tep->d_fixed_card.end() ){ |
48 |
2176 |
d_fixed_bound = it->second; |
49 |
|
}else{ |
50 |
|
d_fixed_bound = Integer(1); |
51 |
|
} |
52 |
2176 |
Trace("uf-type-enum") << "...fixed bound : " << d_fixed_bound << std::endl; |
53 |
|
} |
54 |
2985 |
} |
55 |
|
|
56 |
17507 |
Node operator*() override |
57 |
|
{ |
58 |
17507 |
if(isFinished()) { |
59 |
980 |
throw NoMoreValuesException(getType()); |
60 |
|
} |
61 |
|
return NodeManager::currentNM()->mkConst( |
62 |
16527 |
UninterpretedConstant(getType(), d_count)); |
63 |
|
} |
64 |
|
|
65 |
5665 |
UninterpretedSortEnumerator& operator++() override |
66 |
|
{ |
67 |
5665 |
d_count += 1; |
68 |
5665 |
return *this; |
69 |
|
} |
70 |
|
|
71 |
40481 |
bool isFinished() override |
72 |
|
{ |
73 |
40481 |
if( d_has_fixed_bound ){ |
74 |
29196 |
return d_count>=d_fixed_bound; |
75 |
|
}else{ |
76 |
11285 |
return false; |
77 |
|
} |
78 |
|
} |
79 |
|
|
80 |
|
};/* class UninterpretedSortEnumerator */ |
81 |
|
|
82 |
|
/** FunctionEnumerator |
83 |
|
* This enumerates function values, based on the enumerator for the |
84 |
|
* array type corresponding to the given function type. |
85 |
|
*/ |
86 |
|
class FunctionEnumerator : public TypeEnumeratorBase<FunctionEnumerator> |
87 |
|
{ |
88 |
|
public: |
89 |
|
FunctionEnumerator(TypeNode type, TypeEnumeratorProperties* tep = nullptr); |
90 |
|
/** Get the current term of the enumerator. */ |
91 |
|
Node operator*() override; |
92 |
|
/** Increment the enumerator. */ |
93 |
|
FunctionEnumerator& operator++() override; |
94 |
|
/** is the enumerator finished? */ |
95 |
|
bool isFinished() override { return d_arrayEnum.isFinished(); } |
96 |
|
private: |
97 |
|
/** Enumerates arrays, which we convert to functions. */ |
98 |
|
TypeEnumerator d_arrayEnum; |
99 |
|
/** The bound variable list for the function type we are enumerating. |
100 |
|
* All terms output by this enumerator are of the form (LAMBDA d_bvl t) for |
101 |
|
* some term t. |
102 |
|
*/ |
103 |
|
Node d_bvl; |
104 |
|
}; /* class FunctionEnumerator */ |
105 |
|
|
106 |
|
} // namespace builtin |
107 |
|
} // namespace theory |
108 |
|
} // namespace cvc5 |
109 |
|
|
110 |
|
#endif /* CVC5__THEORY__BUILTIN_TYPE_ENUMERATOR_H */ |