1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Morgan Deters, Tim King, Mathias Preiner |
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 |
|
* An enumerator for Booleans. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__BOOLEANS__TYPE_ENUMERATOR_H |
19 |
|
#define CVC5__THEORY__BOOLEANS__TYPE_ENUMERATOR_H |
20 |
|
|
21 |
|
#include "theory/type_enumerator.h" |
22 |
|
#include "expr/type_node.h" |
23 |
|
#include "expr/kind.h" |
24 |
|
|
25 |
|
namespace cvc5 { |
26 |
|
namespace theory { |
27 |
|
namespace booleans { |
28 |
|
|
29 |
2213 |
class BooleanEnumerator : public TypeEnumeratorBase<BooleanEnumerator> { |
30 |
|
enum { FALSE, TRUE, DONE } d_value; |
31 |
|
|
32 |
|
public: |
33 |
724 |
BooleanEnumerator(TypeNode type, TypeEnumeratorProperties* tep = nullptr) |
34 |
724 |
: TypeEnumeratorBase<BooleanEnumerator>(type), d_value(FALSE) |
35 |
|
{ |
36 |
724 |
Assert(type.getKind() == kind::TYPE_CONSTANT |
37 |
|
&& type.getConst<TypeConstant>() == BOOLEAN_TYPE); |
38 |
724 |
} |
39 |
|
|
40 |
2032 |
Node operator*() override { |
41 |
2032 |
switch(d_value) { |
42 |
1757 |
case FALSE: |
43 |
1757 |
return NodeManager::currentNM()->mkConst(false); |
44 |
207 |
case TRUE: |
45 |
207 |
return NodeManager::currentNM()->mkConst(true); |
46 |
68 |
default: |
47 |
68 |
throw NoMoreValuesException(getType()); |
48 |
|
} |
49 |
|
} |
50 |
|
|
51 |
258 |
BooleanEnumerator& operator++() override |
52 |
|
{ |
53 |
|
// sequence is FALSE, TRUE |
54 |
258 |
if(d_value == FALSE) { |
55 |
201 |
d_value = TRUE; |
56 |
|
} else { |
57 |
57 |
d_value = DONE; |
58 |
|
} |
59 |
258 |
return *this; |
60 |
|
} |
61 |
|
|
62 |
2334 |
bool isFinished() override { return d_value == DONE; } |
63 |
|
};/* class BooleanEnumerator */ |
64 |
|
|
65 |
|
} // namespace booleans |
66 |
|
} // namespace theory |
67 |
|
} // namespace cvc5 |
68 |
|
|
69 |
|
#endif /* CVC5__THEORY__BOOLEANS__TYPE_ENUMERATOR_H */ |