GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/buffered_proof_generator.cpp Lines: 33 44 75.0 %
Date: 2021-05-21 Branches: 55 158 34.8 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Haniel Barbosa
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 a proof generator for buffered proof steps.
14
 */
15
16
#include "expr/buffered_proof_generator.h"
17
18
#include "expr/proof.h"
19
#include "expr/proof_node_manager.h"
20
21
namespace cvc5 {
22
23
10444
BufferedProofGenerator::BufferedProofGenerator(context::Context* c,
24
10444
                                               ProofNodeManager* pnm)
25
10444
    : ProofGenerator(), d_facts(c), d_pnm(pnm)
26
{
27
10444
}
28
29
46249
bool BufferedProofGenerator::addStep(Node fact,
30
                                     ProofStep ps,
31
                                     CDPOverwrite opolicy)
32
{
33
  // check duplicates if we are not always overwriting
34
46249
  if (opolicy != CDPOverwrite::ALWAYS)
35
  {
36
13479
    if (d_facts.find(fact) != d_facts.end())
37
    {
38
      // duplicate
39
88
      return false;
40
    }
41
26870
    Node symFact = CDProof::getSymmFact(fact);
42
13435
    if (!symFact.isNull())
43
    {
44
5210
      if (d_facts.find(symFact) != d_facts.end())
45
      {
46
        // duplicate due to symmetry
47
        return false;
48
      }
49
    }
50
  }
51
  // note that this replaces the value fact is mapped to if there is already one
52
46205
  d_facts.insert(fact, std::make_shared<ProofStep>(ps));
53
46205
  return true;
54
}
55
56
160243
std::shared_ptr<ProofNode> BufferedProofGenerator::getProofFor(Node fact)
57
{
58
320486
  Trace("pfee-fact-gen") << "BufferedProofGenerator::getProofFor: " << fact
59
160243
                         << std::endl;
60
160243
  NodeProofStepMap::iterator it = d_facts.find(fact);
61
160243
  if (it == d_facts.end())
62
  {
63
    Node symFact = CDProof::getSymmFact(fact);
64
    if (symFact.isNull())
65
    {
66
      Trace("pfee-fact-gen") << "...cannot find step" << std::endl;
67
      Assert(false);
68
      return nullptr;
69
    }
70
    it = d_facts.find(symFact);
71
    if (it == d_facts.end())
72
    {
73
      Assert(false);
74
      Trace("pfee-fact-gen") << "...cannot find step (no sym)" << std::endl;
75
      return nullptr;
76
    }
77
  }
78
160243
  Trace("pfee-fact-gen") << "...return via step " << *(*it).second << std::endl;
79
320486
  CDProof cdp(d_pnm);
80
160243
  cdp.addStep(fact, *(*it).second);
81
160243
  return cdp.getProofFor(fact);
82
}
83
84
23645
bool BufferedProofGenerator::hasProofFor(Node f)
85
{
86
23645
  NodeProofStepMap::iterator it = d_facts.find(f);
87
23645
  if (it == d_facts.end())
88
  {
89
16696
    Node symFact = CDProof::getSymmFact(f);
90
16691
    if (symFact.isNull())
91
    {
92
10939
      return false;
93
    }
94
5752
    it = d_facts.find(symFact);
95
5752
    if (it == d_facts.end())
96
    {
97
5747
      return false;
98
    }
99
  }
100
6959
  return true;
101
}
102
103
27735
}  // namespace cvc5