GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/term_enumeration.cpp Lines: 16 29 55.2 %
Date: 2021-09-18 Branches: 27 84 32.1 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Aina Niemetz
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
 * Implementation of term enumeration utility.
14
 */
15
16
#include "theory/quantifiers/term_enumeration.h"
17
18
#include "theory/quantifiers/quant_bound_inference.h"
19
20
using namespace cvc5::kind;
21
22
namespace cvc5 {
23
namespace theory {
24
namespace quantifiers {
25
26
13708
TermEnumeration::TermEnumeration(QuantifiersBoundInference* qbi) : d_qbi(qbi) {}
27
28
1832
Node TermEnumeration::getEnumerateTerm(TypeNode tn, unsigned index)
29
{
30
3664
  Trace("term-db-enum") << "Get enumerate term " << tn << " " << index
31
1832
                        << std::endl;
32
1832
  std::unordered_map<TypeNode, size_t>::iterator it = d_typ_enum_map.find(tn);
33
  size_t teIndex;
34
1832
  if (it == d_typ_enum_map.end())
35
  {
36
600
    teIndex = d_typ_enum.size();
37
600
    d_typ_enum_map[tn] = teIndex;
38
600
    d_typ_enum.push_back(TypeEnumerator(tn));
39
  }
40
  else
41
  {
42
1232
    teIndex = it->second;
43
  }
44
3734
  while (index >= d_enum_terms[tn].size())
45
  {
46
951
    if (d_typ_enum[teIndex].isFinished())
47
    {
48
      return Node::null();
49
    }
50
951
    d_enum_terms[tn].push_back(*d_typ_enum[teIndex]);
51
951
    ++d_typ_enum[teIndex];
52
  }
53
1832
  return d_enum_terms[tn][index];
54
}
55
56
bool TermEnumeration::getDomain(TypeNode tn, std::vector<Node>& dom)
57
{
58
  if (!d_qbi || !d_qbi->mayComplete(tn))
59
  {
60
    return false;
61
  }
62
  Node curre;
63
  unsigned counter = 0;
64
  do
65
  {
66
    curre = getEnumerateTerm(tn, counter);
67
    counter++;
68
    if (!curre.isNull())
69
    {
70
      dom.push_back(curre);
71
    }
72
  } while (!curre.isNull());
73
  return true;
74
}
75
76
}  // namespace quantifiers
77
}  // namespace theory
78
29574
}  // namespace cvc5