GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/term_registry.cpp Lines: 52 58 89.7 %
Date: 2021-08-14 Branches: 67 142 47.2 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner
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
 * Term registry class.
14
 */
15
16
#include "theory/quantifiers/term_registry.h"
17
18
#include "options/base_options.h"
19
#include "options/quantifiers_options.h"
20
#include "options/smt_options.h"
21
#include "theory/quantifiers/first_order_model.h"
22
#include "theory/quantifiers/fmf/first_order_model_fmc.h"
23
#include "theory/quantifiers/quantifiers_attributes.h"
24
#include "theory/quantifiers/quantifiers_state.h"
25
#include "theory/quantifiers/term_util.h"
26
27
namespace cvc5 {
28
namespace theory {
29
namespace quantifiers {
30
31
9853
TermRegistry::TermRegistry(QuantifiersState& qs, QuantifiersRegistry& qr)
32
9853
    : d_presolve(qs.getUserContext(), true),
33
9853
      d_presolveCache(qs.getUserContext()),
34
9853
      d_termEnum(new TermEnumeration),
35
9853
      d_termPools(new TermPools(qs)),
36
9853
      d_termDb(new TermDb(qs, qr)),
37
      d_sygusTdb(nullptr),
38
59118
      d_qmodel(nullptr)
39
{
40
9853
  if (options::sygus() || options::sygusInst())
41
  {
42
    // must be constructed here since it is required for datatypes finistInit
43
1151
    d_sygusTdb.reset(new TermDbSygus(qs));
44
  }
45
9853
  Trace("quant-engine-debug") << "Initialize quantifiers engine." << std::endl;
46
19706
  Trace("quant-engine-debug")
47
9853
      << "Initialize model, mbqi : " << options::mbqiMode() << std::endl;
48
9853
}
49
50
9853
void TermRegistry::finishInit(FirstOrderModel* fm,
51
                              QuantifiersInferenceManager* qim)
52
{
53
9853
  d_qmodel = fm;
54
9853
  d_termDb->finishInit(qim);
55
9853
  if (d_sygusTdb.get())
56
  {
57
1151
    d_sygusTdb->finishInit(qim);
58
  }
59
9853
}
60
61
8164
void TermRegistry::presolve()
62
{
63
8164
  d_presolve = false;
64
  // add all terms to database
65
8164
  if (options::incrementalSolving() && !options::termDbCd())
66
  {
67
    Trace("quant-engine-proc")
68
        << "Add presolve cache " << d_presolveCache.size() << std::endl;
69
    for (const Node& t : d_presolveCache)
70
    {
71
      addTerm(t);
72
    }
73
    Trace("quant-engine-proc") << "Done add presolve cache " << std::endl;
74
  }
75
8164
}
76
77
940194
void TermRegistry::addTerm(Node n, bool withinQuant)
78
{
79
  // don't add terms in quantifier bodies
80
940194
  if (withinQuant && !options::registerQuantBodyTerms())
81
  {
82
67840
    return;
83
  }
84
872354
  if (options::incrementalSolving() && !options::termDbCd())
85
  {
86
    d_presolveCache.insert(n);
87
  }
88
  // only wait if we are doing incremental solving
89
872354
  if (!d_presolve || !options::incrementalSolving() || options::termDbCd())
90
  {
91
872354
    d_termDb->addTerm(n);
92
872354
    if (d_sygusTdb.get() && options::sygusEvalUnfold())
93
    {
94
180080
      d_sygusTdb->getEvalUnfold()->registerEvalTerm(n);
95
    }
96
  }
97
}
98
99
2069
Node TermRegistry::getTermForType(TypeNode tn)
100
{
101
2069
  if (tn.isClosedEnumerable())
102
  {
103
100
    return d_termEnum->getEnumerateTerm(tn, 0);
104
  }
105
1969
  return d_termDb->getOrMakeTypeGroundTerm(tn);
106
}
107
108
5
void TermRegistry::declarePool(Node p, const std::vector<Node>& initValue)
109
{
110
5
  d_termPools->registerPool(p, initValue);
111
5
}
112
113
36698
void TermRegistry::processInstantiation(Node q, const std::vector<Node>& terms)
114
{
115
36698
  d_termPools->processInstantiation(q, terms);
116
36698
}
117
2411
void TermRegistry::processSkolemization(Node q,
118
                                        const std::vector<Node>& skolems)
119
{
120
2411
  d_termPools->processSkolemization(q, skolems);
121
2411
}
122
123
16262770
TermDb* TermRegistry::getTermDatabase() const { return d_termDb.get(); }
124
125
3915
TermDbSygus* TermRegistry::getTermDatabaseSygus() const
126
{
127
3915
  return d_sygusTdb.get();
128
}
129
130
576
TermEnumeration* TermRegistry::getTermEnumeration() const
131
{
132
576
  return d_termEnum.get();
133
}
134
135
9857
TermPools* TermRegistry::getTermPools() const { return d_termPools.get(); }
136
137
317958
FirstOrderModel* TermRegistry::getModel() const { return d_qmodel; }
138
139
}  // namespace quantifiers
140
}  // namespace theory
141
29340
}  // namespace cvc5