GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/type_set.cpp Lines: 57 59 96.6 %
Date: 2021-08-06 Branches: 60 104 57.7 %

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
109712
TypeSet::~TypeSet()
24
{
25
54856
  iterator it;
26
140183
  for (it = d_typeSet.begin(); it != d_typeSet.end(); ++it)
27
  {
28
85327
    delete (*it).second;
29
  }
30
54856
  TypeToTypeEnumMap::iterator it2;
31
59237
  for (it2 = d_teMap.begin(); it2 != d_teMap.end(); ++it2)
32
  {
33
4381
    delete (*it2).second;
34
  }
35
54856
}
36
37
939
void TypeSet::setTypeEnumeratorProperties(TypeEnumeratorProperties* tep)
38
{
39
939
  d_tep = tep;
40
939
}
41
42
846599
void TypeSet::add(TypeNode t, TNode n)
43
{
44
846599
  iterator it = d_typeSet.find(t);
45
  std::set<Node>* s;
46
846599
  if (it == d_typeSet.end())
47
  {
48
82690
    s = new std::set<Node>;
49
82690
    d_typeSet[t] = s;
50
  }
51
  else
52
  {
53
763909
    s = (*it).second;
54
  }
55
846599
  s->insert(n);
56
846599
}
57
58
387631
std::set<Node>* TypeSet::getSet(TypeNode t) const
59
{
60
387631
  const_iterator it = d_typeSet.find(t);
61
387631
  if (it == d_typeSet.end())
62
  {
63
177379
    return NULL;
64
  }
65
210252
  return (*it).second;
66
}
67
68
14852
Node TypeSet::nextTypeEnum(TypeNode t, bool useBaseType)
69
{
70
  TypeEnumerator* te;
71
14852
  TypeToTypeEnumMap::iterator it = d_teMap.find(t);
72
14852
  if (it == d_teMap.end())
73
  {
74
4381
    te = new TypeEnumerator(t, d_tep);
75
4381
    d_teMap[t] = te;
76
  }
77
  else
78
  {
79
10471
    te = (*it).second;
80
  }
81
14852
  if (te->isFinished())
82
  {
83
    return Node();
84
  }
85
86
14852
  if (useBaseType)
87
  {
88
14424
    t = t.getBaseType();
89
  }
90
14852
  iterator itSet = d_typeSet.find(t);
91
  std::set<Node>* s;
92
14852
  if (itSet == d_typeSet.end())
93
  {
94
2637
    s = new std::set<Node>;
95
2637
    d_typeSet[t] = s;
96
  }
97
  else
98
  {
99
12215
    s = (*itSet).second;
100
  }
101
29704
  Node n = **te;
102
26842
  while (s->find(n) != s->end())
103
  {
104
5995
    ++(*te);
105
5995
    if (te->isFinished())
106
    {
107
      return Node();
108
    }
109
5995
    n = **te;
110
  }
111
14852
  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
29704
  std::unordered_set<TNode> visited;
117
14852
  addSubTerms(n, visited);
118
14852
  ++(*te);
119
14852
  return n;
120
}
121
122
45962
void TypeSet::addSubTerms(TNode n,
123
                          std::unordered_set<TNode>& visited,
124
                          bool topLevel)
125
{
126
45962
  if (visited.find(n) == visited.end())
127
  {
128
36544
    visited.insert(n);
129
36544
    if (!topLevel)
130
    {
131
21692
      add(n.getType(), n);
132
    }
133
67654
    for (unsigned i = 0; i < n.getNumChildren(); i++)
134
    {
135
31110
      addSubTerms(n[i], visited, false);
136
    }
137
  }
138
45962
}
139
140
}  // namespace theory
141
29322
}  // namespace cvc5