GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/booleans/theory_bool_type_rules.cpp Lines: 30 30 100.0 %
Date: 2021-09-29 Branches: 74 138 53.6 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Dejan Jovanovic, Morgan Deters, Christopher L. Conway
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
 * Typing and cardinality rules for the theory of boolean.
14
 */
15
16
#include "theory/booleans/theory_bool_type_rules.h"
17
18
#include <sstream>
19
20
namespace cvc5 {
21
namespace theory {
22
namespace boolean {
23
24
7103636
TypeNode BooleanTypeRule::computeType(NodeManager* nodeManager,
25
                                      TNode n,
26
                                      bool check)
27
{
28
7103636
  TypeNode booleanType = nodeManager->booleanType();
29
7103636
  if (check)
30
  {
31
28664805
    for (const auto& child : n)
32
    {
33
21565787
      if (!child.getType(check).isBoolean())
34
      {
35
326
        Debug("pb") << "failed type checking: " << child << std::endl;
36
652
        Debug("pb") << "  integer: " << child.getType(check).isInteger()
37
326
                    << std::endl;
38
326
        Debug("pb") << "  real: " << child.getType(check).isReal() << std::endl;
39
        throw TypeCheckingExceptionPrivate(n,
40
326
                                           "expecting a Boolean subexpression");
41
      }
42
    }
43
  }
44
7103310
  return booleanType;
45
}
46
47
966586
TypeNode IteTypeRule::computeType(NodeManager* nodeManager, TNode n, bool check)
48
{
49
1933172
  TypeNode thenType = n[1].getType(check);
50
1933172
  TypeNode elseType = n[2].getType(check);
51
966586
  TypeNode iteType = TypeNode::leastCommonTypeNode(thenType, elseType);
52
966586
  if (check)
53
  {
54
1933172
    TypeNode booleanType = nodeManager->booleanType();
55
966586
    if (n[0].getType(check) != booleanType)
56
    {
57
24
      throw TypeCheckingExceptionPrivate(n, "condition of ITE is not Boolean");
58
    }
59
966562
    if (iteType.isNull())
60
    {
61
16
      std::stringstream ss;
62
8
      ss << "Both branches of the ITE must be a subtype of a common type."
63
8
         << std::endl
64
16
         << "then branch: " << n[1] << std::endl
65
8
         << "its type   : " << thenType << std::endl
66
16
         << "else branch: " << n[2] << std::endl
67
8
         << "its type   : " << elseType << std::endl;
68
8
      throw TypeCheckingExceptionPrivate(n, ss.str());
69
    }
70
  }
71
1933108
  return iteType;
72
}
73
74
}  // namespace boolean
75
}  // namespace theory
76
22746
}  // namespace cvc5