GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/quantifiers/theory_quantifiers_type_rules.cpp Lines: 37 44 84.1 %
Date: 2021-05-22 Branches: 90 250 36.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Morgan Deters, Tim King
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
 * Theory of quantifiers.
14
 */
15
16
#include "theory/quantifiers/theory_quantifiers_type_rules.h"
17
18
namespace cvc5 {
19
namespace theory {
20
namespace quantifiers {
21
22
110607
TypeNode QuantifierTypeRule::computeType(NodeManager* nodeManager,
23
                                         TNode n,
24
                                         bool check)
25
{
26
110607
  Debug("typecheck-q") << "type check for fa " << n << std::endl;
27
110607
  Assert((n.getKind() == kind::FORALL || n.getKind() == kind::EXISTS)
28
         && n.getNumChildren() > 0);
29
110607
  if (check)
30
  {
31
110607
    if (n[0].getType(check) != nodeManager->boundVarListType())
32
    {
33
      throw TypeCheckingExceptionPrivate(
34
          n, "first argument of quantifier is not bound var list");
35
    }
36
110607
    if (n[1].getType(check) != nodeManager->booleanType())
37
    {
38
      throw TypeCheckingExceptionPrivate(n,
39
                                         "body of quantifier is not boolean");
40
    }
41
110607
    if (n.getNumChildren() == 3)
42
    {
43
12080
      if (n[2].getType(check) != nodeManager->instPatternListType())
44
      {
45
        throw TypeCheckingExceptionPrivate(
46
            n,
47
            "third argument of quantifier is not instantiation "
48
            "pattern list");
49
      }
50
25308
      for (const Node& p : n[2])
51
      {
52
26456
        if (p.getKind() == kind::INST_POOL
53
26456
            && p.getNumChildren() != n[0].getNumChildren())
54
        {
55
          throw TypeCheckingExceptionPrivate(
56
              n,
57
              "expected number of arguments to pool to be the same as the "
58
              "number of bound variables of the quantified formula");
59
        }
60
      }
61
    }
62
  }
63
110607
  return nodeManager->booleanType();
64
}
65
66
67542
TypeNode QuantifierBoundVarListTypeRule::computeType(NodeManager* nodeManager,
67
                                                     TNode n,
68
                                                     bool check)
69
{
70
67542
  Assert(n.getKind() == kind::BOUND_VAR_LIST);
71
67542
  if (check)
72
  {
73
231414
    for (int i = 0; i < (int)n.getNumChildren(); i++)
74
    {
75
163872
      if (n[i].getKind() != kind::BOUND_VARIABLE)
76
      {
77
        throw TypeCheckingExceptionPrivate(
78
            n, "argument of bound var list is not bound variable");
79
      }
80
    }
81
  }
82
67542
  return nodeManager->boundVarListType();
83
}
84
85
9020
TypeNode QuantifierInstPatternTypeRule::computeType(NodeManager* nodeManager,
86
                                                    TNode n,
87
                                                    bool check)
88
{
89
9020
  Assert(n.getKind() == kind::INST_PATTERN);
90
9020
  if (check)
91
  {
92
18040
    TypeNode tn = n[0].getType(check);
93
    // this check catches the common mistake writing :pattern (f x) instead of
94
    // :pattern ((f x))
95
27075
    if (n[0].isVar() && n[0].getKind() != kind::BOUND_VARIABLE
96
27068
        && tn.isFunction())
97
    {
98
      throw TypeCheckingExceptionPrivate(
99
          n[0], "Pattern must be a list of fully-applied terms.");
100
    }
101
  }
102
9020
  return nodeManager->instPatternType();
103
}
104
105
975
TypeNode QuantifierAnnotationTypeRule::computeType(NodeManager* nodeManager,
106
                                                   TNode n,
107
                                                   bool check)
108
{
109
975
  return nodeManager->instPatternType();
110
}
111
112
9598
TypeNode QuantifierInstPatternListTypeRule::computeType(
113
    NodeManager* nodeManager, TNode n, bool check)
114
{
115
9598
  Assert(n.getKind() == kind::INST_PATTERN_LIST);
116
9598
  if (check)
117
  {
118
19969
    for (const Node& nc : n)
119
    {
120
10371
      Kind k = nc.getKind();
121
10371
      if (k != kind::INST_PATTERN && k != kind::INST_NO_PATTERN
122
1317
          && k != kind::INST_ATTRIBUTE && k != kind::INST_POOL
123
26
          && k != kind::INST_ADD_TO_POOL && k != kind::SKOLEM_ADD_TO_POOL)
124
      {
125
        throw TypeCheckingExceptionPrivate(
126
            n,
127
            "argument of inst pattern list is not a legal quantifiers "
128
            "annotation");
129
      }
130
    }
131
  }
132
9598
  return nodeManager->instPatternListType();
133
}
134
135
}  // namespace quantifiers
136
}  // namespace theory
137
28194
}  // namespace cvc5