GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/proof/proof_step_buffer.cpp Lines: 20 44 45.5 %
Date: 2021-09-29 Branches: 14 88 15.9 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, 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 proof step and proof step buffer utilities.
14
 */
15
16
#include "proof/proof_step_buffer.h"
17
18
#include "proof/proof_checker.h"
19
20
using namespace cvc5::kind;
21
22
namespace cvc5 {
23
24
ProofStep::ProofStep() : d_rule(PfRule::UNKNOWN) {}
25
53215
ProofStep::ProofStep(PfRule r,
26
                     const std::vector<Node>& children,
27
53215
                     const std::vector<Node>& args)
28
53215
    : d_rule(r), d_children(children), d_args(args)
29
{
30
53215
}
31
std::ostream& operator<<(std::ostream& out, ProofStep step)
32
{
33
  out << "(step " << step.d_rule;
34
  for (const Node& c : step.d_children)
35
  {
36
    out << " " << c;
37
  }
38
  if (!step.d_args.empty())
39
  {
40
    out << " :args";
41
    for (const Node& a : step.d_args)
42
    {
43
      out << " " << a;
44
    }
45
  }
46
  out << ")";
47
  return out;
48
}
49
50
329
ProofStepBuffer::ProofStepBuffer(ProofChecker* pc) : d_checker(pc) {}
51
52
286
Node ProofStepBuffer::tryStep(PfRule id,
53
                              const std::vector<Node>& children,
54
                              const std::vector<Node>& args,
55
                              Node expected)
56
{
57
286
  if (d_checker == nullptr)
58
  {
59
    Assert(false) << "ProofStepBuffer::ProofStepBuffer: no proof checker.";
60
    return Node::null();
61
  }
62
  Node res =
63
572
      d_checker->checkDebug(id, children, args, expected, "pf-step-buffer");
64
286
  if (!res.isNull())
65
  {
66
    // add proof step
67
572
    d_steps.push_back(
68
572
        std::pair<Node, ProofStep>(res, ProofStep(id, children, args)));
69
  }
70
286
  return res;
71
}
72
73
52698
void ProofStepBuffer::addStep(PfRule id,
74
                              const std::vector<Node>& children,
75
                              const std::vector<Node>& args,
76
                              Node expected)
77
{
78
105396
  d_steps.push_back(
79
105396
      std::pair<Node, ProofStep>(expected, ProofStep(id, children, args)));
80
52698
}
81
82
void ProofStepBuffer::addSteps(ProofStepBuffer& psb)
83
{
84
  const std::vector<std::pair<Node, ProofStep>>& steps = psb.getSteps();
85
  for (const std::pair<Node, ProofStep>& step : steps)
86
  {
87
    addStep(step.second.d_rule,
88
            step.second.d_children,
89
            step.second.d_args,
90
            step.first);
91
  }
92
}
93
94
void ProofStepBuffer::popStep()
95
{
96
  Assert(!d_steps.empty());
97
  if (!d_steps.empty())
98
  {
99
    d_steps.pop_back();
100
  }
101
}
102
103
size_t ProofStepBuffer::getNumSteps() const { return d_steps.size(); }
104
105
4408
const std::vector<std::pair<Node, ProofStep>>& ProofStepBuffer::getSteps() const
106
{
107
4408
  return d_steps;
108
}
109
110
4404
void ProofStepBuffer::clear() { d_steps.clear(); }
111
112
22746
}  // namespace cvc5