GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/ematching/var_match_generator.cpp Lines: 27 32 84.4 %
Date: 2021-09-29 Branches: 47 98 48.0 %

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 variable match generator class.
14
 */
15
#include "theory/quantifiers/ematching/var_match_generator.h"
16
17
#include "theory/quantifiers/term_util.h"
18
#include "theory/rewriter.h"
19
20
using namespace cvc5::kind;
21
22
namespace cvc5 {
23
namespace theory {
24
namespace quantifiers {
25
namespace inst {
26
27
2
VarMatchGeneratorTermSubs::VarMatchGeneratorTermSubs(Trigger* tparent,
28
                                                     Node var,
29
2
                                                     Node subs)
30
4
    : InstMatchGenerator(tparent, Node::null()),
31
      d_var(var),
32
      d_subs(subs),
33
6
      d_rm_prev(false)
34
{
35
2
  d_children_types.push_back(d_var.getAttribute(InstVarNumAttribute()));
36
2
  d_var_type = d_var.getType();
37
2
}
38
39
2
bool VarMatchGeneratorTermSubs::reset(Node eqc)
40
{
41
2
  d_eq_class = eqc;
42
2
  return true;
43
}
44
45
2
int VarMatchGeneratorTermSubs::getNextMatch(Node q, InstMatch& m)
46
{
47
2
  int ret_val = -1;
48
2
  if (!d_eq_class.isNull())
49
  {
50
4
    Trace("var-trigger-matching") << "Matching " << d_eq_class << " against "
51
2
                                  << d_var << " in " << d_subs << std::endl;
52
2
    TNode tvar = d_var;
53
2
    Node s = d_subs.substitute(tvar, d_eq_class);
54
2
    s = Rewriter::rewrite(s);
55
4
    Trace("var-trigger-matching")
56
2
        << "...got " << s << ", " << s.getKind() << std::endl;
57
2
    d_eq_class = Node::null();
58
    // if( s.getType().isSubtypeOf( d_var_type ) ){
59
2
    d_rm_prev = m.get(d_children_types[0]).isNull();
60
2
    if (!m.set(d_qstate, d_children_types[0], s))
61
    {
62
      return -1;
63
    }
64
    else
65
    {
66
2
      ret_val = continueNextMatch(
67
          q, m, InferenceId::QUANTIFIERS_INST_E_MATCHING_VAR_GEN);
68
2
      if (ret_val > 0)
69
      {
70
2
        return ret_val;
71
      }
72
    }
73
  }
74
  if (d_rm_prev)
75
  {
76
    m.d_vals[d_children_types[0]] = Node::null();
77
    d_rm_prev = false;
78
  }
79
  return -1;
80
}
81
82
}  // namespace inst
83
}  // namespace quantifiers
84
}  // namespace theory
85
22746
}  // namespace cvc5