GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/type_set.cpp Lines: 57 59 96.6 %
Date: 2021-09-17 Branches: 60 102 58.8 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Clark Barrett, 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 type set class.
14
 */
15
#include "theory/type_set.h"
16
17
using namespace std;
18
using namespace cvc5::kind;
19
20
namespace cvc5 {
21
namespace theory {
22
23
108474
TypeSet::~TypeSet()
24
{
25
54237
  iterator it;
26
135793
  for (it = d_typeSet.begin(); it != d_typeSet.end(); ++it)
27
  {
28
81556
    delete (*it).second;
29
  }
30
54237
  TypeToTypeEnumMap::iterator it2;
31
58553
  for (it2 = d_teMap.begin(); it2 != d_teMap.end(); ++it2)
32
  {
33
4316
    delete (*it2).second;
34
  }
35
54237
}
36
37
937
void TypeSet::setTypeEnumeratorProperties(TypeEnumeratorProperties* tep)
38
{
39
937
  d_tep = tep;
40
937
}
41
42
861754
void TypeSet::add(TypeNode t, TNode n)
43
{
44
861754
  iterator it = d_typeSet.find(t);
45
  std::set<Node>* s;
46
861754
  if (it == d_typeSet.end())
47
  {
48
78872
    s = new std::set<Node>;
49
78872
    d_typeSet[t] = s;
50
  }
51
  else
52
  {
53
782882
    s = (*it).second;
54
  }
55
861754
  s->insert(n);
56
861754
}
57
58
372441
std::set<Node>* TypeSet::getSet(TypeNode t) const
59
{
60
372441
  const_iterator it = d_typeSet.find(t);
61
372441
  if (it == d_typeSet.end())
62
  {
63
167272
    return NULL;
64
  }
65
205169
  return (*it).second;
66
}
67
68
14545
Node TypeSet::nextTypeEnum(TypeNode t, bool useBaseType)
69
{
70
  TypeEnumerator* te;
71
14545
  TypeToTypeEnumMap::iterator it = d_teMap.find(t);
72
14545
  if (it == d_teMap.end())
73
  {
74
4316
    te = new TypeEnumerator(t, d_tep);
75
4316
    d_teMap[t] = te;
76
  }
77
  else
78
  {
79
10229
    te = (*it).second;
80
  }
81
14545
  if (te->isFinished())
82
  {
83
    return Node();
84
  }
85
86
14545
  if (useBaseType)
87
  {
88
14068
    t = t.getBaseType();
89
  }
90
14545
  iterator itSet = d_typeSet.find(t);
91
  std::set<Node>* s;
92
14545
  if (itSet == d_typeSet.end())
93
  {
94
2684
    s = new std::set<Node>;
95
2684
    d_typeSet[t] = s;
96
  }
97
  else
98
  {
99
11861
    s = (*itSet).second;
100
  }
101
29090
  Node n = **te;
102
25607
  while (s->find(n) != s->end())
103
  {
104
5531
    ++(*te);
105
5531
    if (te->isFinished())
106
    {
107
      return Node();
108
    }
109
5531
    n = **te;
110
  }
111
14545
  s->insert(n);
112
  // add all subterms of n to this set as well
113
  // this is necessary for parametric types whose values are constructed from
114
  // other types to ensure that we do not enumerate subterms of other
115
  // previously enumerated values
116
29090
  std::unordered_set<TNode> visited;
117
14545
  addSubTerms(n, visited);
118
14545
  ++(*te);
119
14545
  return n;
120
}
121
122
45702
void TypeSet::addSubTerms(TNode n,
123
                          std::unordered_set<TNode>& visited,
124
                          bool topLevel)
125
{
126
45702
  if (visited.find(n) == visited.end())
127
  {
128
36277
    visited.insert(n);
129
36277
    if (!topLevel)
130
    {
131
21732
      add(n.getType(), n);
132
    }
133
67434
    for (unsigned i = 0; i < n.getNumChildren(); i++)
134
    {
135
31157
      addSubTerms(n[i], visited, false);
136
    }
137
  }
138
45702
}
139
140
}  // namespace theory
141
29577
}  // namespace cvc5