GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/type_set.cpp Lines: 57 59 96.6 %
Date: 2021-09-10 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
108482
TypeSet::~TypeSet()
24
{
25
54241
  iterator it;
26
135801
  for (it = d_typeSet.begin(); it != d_typeSet.end(); ++it)
27
  {
28
81560
    delete (*it).second;
29
  }
30
54241
  TypeToTypeEnumMap::iterator it2;
31
58556
  for (it2 = d_teMap.begin(); it2 != d_teMap.end(); ++it2)
32
  {
33
4315
    delete (*it2).second;
34
  }
35
54241
}
36
37
937
void TypeSet::setTypeEnumeratorProperties(TypeEnumeratorProperties* tep)
38
{
39
937
  d_tep = tep;
40
937
}
41
42
862117
void TypeSet::add(TypeNode t, TNode n)
43
{
44
862117
  iterator it = d_typeSet.find(t);
45
  std::set<Node>* s;
46
862117
  if (it == d_typeSet.end())
47
  {
48
78876
    s = new std::set<Node>;
49
78876
    d_typeSet[t] = s;
50
  }
51
  else
52
  {
53
783241
    s = (*it).second;
54
  }
55
862117
  s->insert(n);
56
862117
}
57
58
372458
std::set<Node>* TypeSet::getSet(TypeNode t) const
59
{
60
372458
  const_iterator it = d_typeSet.find(t);
61
372458
  if (it == d_typeSet.end())
62
  {
63
167280
    return NULL;
64
  }
65
205178
  return (*it).second;
66
}
67
68
14543
Node TypeSet::nextTypeEnum(TypeNode t, bool useBaseType)
69
{
70
  TypeEnumerator* te;
71
14543
  TypeToTypeEnumMap::iterator it = d_teMap.find(t);
72
14543
  if (it == d_teMap.end())
73
  {
74
4315
    te = new TypeEnumerator(t, d_tep);
75
4315
    d_teMap[t] = te;
76
  }
77
  else
78
  {
79
10228
    te = (*it).second;
80
  }
81
14543
  if (te->isFinished())
82
  {
83
    return Node();
84
  }
85
86
14543
  if (useBaseType)
87
  {
88
14066
    t = t.getBaseType();
89
  }
90
14543
  iterator itSet = d_typeSet.find(t);
91
  std::set<Node>* s;
92
14543
  if (itSet == d_typeSet.end())
93
  {
94
2684
    s = new std::set<Node>;
95
2684
    d_typeSet[t] = s;
96
  }
97
  else
98
  {
99
11859
    s = (*itSet).second;
100
  }
101
29086
  Node n = **te;
102
25599
  while (s->find(n) != s->end())
103
  {
104
5528
    ++(*te);
105
5528
    if (te->isFinished())
106
    {
107
      return Node();
108
    }
109
5528
    n = **te;
110
  }
111
14543
  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
29086
  std::unordered_set<TNode> visited;
117
14543
  addSubTerms(n, visited);
118
14543
  ++(*te);
119
14543
  return n;
120
}
121
122
45700
void TypeSet::addSubTerms(TNode n,
123
                          std::unordered_set<TNode>& visited,
124
                          bool topLevel)
125
{
126
45700
  if (visited.find(n) == visited.end())
127
  {
128
36275
    visited.insert(n);
129
36275
    if (!topLevel)
130
    {
131
21732
      add(n.getType(), n);
132
    }
133
67432
    for (unsigned i = 0; i < n.getNumChildren(); i++)
134
    {
135
31157
      addSubTerms(n[i], visited, false);
136
    }
137
  }
138
45700
}
139
140
}  // namespace theory
141
29502
}  // namespace cvc5