GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/builtin/type_enumerator.h Lines: 24 27 88.9 %
Date: 2021-08-06 Branches: 35 84 41.7 %

Line Exec Source
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
6910
class UninterpretedSortEnumerator : public TypeEnumeratorBase<UninterpretedSortEnumerator> {
32
  Integer d_count;
33
  bool d_has_fixed_bound;
34
  Integer d_fixed_bound;
35
36
 public:
37
2966
  UninterpretedSortEnumerator(TypeNode type,
38
                              TypeEnumeratorProperties* tep = nullptr)
39
2966
      : TypeEnumeratorBase<UninterpretedSortEnumerator>(type), d_count(0)
40
  {
41
2966
    Assert(type.getKind() == kind::SORT_TYPE);
42
2966
    d_has_fixed_bound = false;
43
2966
    Trace("uf-type-enum") << "UF enum " << type << ", tep = " << tep << std::endl;
44
2966
    if( tep && tep->d_fixed_usort_card ){
45
2166
      d_has_fixed_bound = true;
46
2166
      std::map< TypeNode, Integer >::iterator it = tep->d_fixed_card.find( type );
47
2166
      if( it!=tep->d_fixed_card.end() ){
48
2166
        d_fixed_bound = it->second;
49
      }else{
50
        d_fixed_bound = Integer(1);
51
      }
52
2166
      Trace("uf-type-enum") << "...fixed bound : " << d_fixed_bound << std::endl;
53
    }
54
2966
  }
55
56
17357
  Node operator*() override
57
  {
58
17357
    if(isFinished()) {
59
980
      throw NoMoreValuesException(getType());
60
    }
61
    return NodeManager::currentNM()->mkConst(
62
16377
        UninterpretedConstant(getType(), d_count));
63
  }
64
65
5617
  UninterpretedSortEnumerator& operator++() override
66
  {
67
5617
    d_count += 1;
68
5617
    return *this;
69
  }
70
71
40133
  bool isFinished() override
72
  {
73
40133
    if( d_has_fixed_bound ){
74
28958
      return d_count>=d_fixed_bound;
75
    }else{
76
11175
      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 */