GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/builtin/theory_builtin_type_rules.cpp Lines: 17 17 100.0 %
Date: 2021-09-10 Branches: 26 60 43.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds
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
 * Type rules for the builtin theory.
14
 */
15
16
#include "theory/builtin/theory_builtin_type_rules.h"
17
18
#include "expr/attribute.h"
19
#include "expr/skolem_manager.h"
20
#include "expr/uninterpreted_constant.h"
21
#include "util/cardinality.h"
22
23
namespace cvc5 {
24
namespace theory {
25
namespace builtin {
26
27
2722
TypeNode UninterpretedConstantTypeRule::computeType(NodeManager* nodeManager,
28
                                                    TNode n,
29
                                                    bool check)
30
{
31
2722
  return n.getConst<UninterpretedConstant>().getType();
32
}
33
34
/**
35
 * Attribute for caching the ground term for each type. Maps TypeNode to the
36
 * skolem to return for mkGroundTerm.
37
 */
38
struct GroundTermAttributeId
39
{
40
};
41
typedef expr::Attribute<GroundTermAttributeId, Node> GroundTermAttribute;
42
43
333
Node SortProperties::mkGroundTerm(TypeNode type)
44
{
45
333
  Assert(type.getKind() == kind::SORT_TYPE);
46
  GroundTermAttribute gta;
47
333
  if (type.hasAttribute(gta))
48
  {
49
300
    return type.getAttribute(gta);
50
  }
51
33
  SkolemManager* sm = NodeManager::currentNM()->getSkolemManager();
52
  Node k = sm->mkDummySkolem(
53
66
      "groundTerm", type, "a ground term created for type " + type.toString());
54
33
  type.setAttribute(gta, k);
55
33
  return k;
56
}
57
58
156
Cardinality FunctionProperties::computeCardinality(TypeNode type)
59
{
60
  // Don't assert this; allow other theories to use this cardinality
61
  // computation.
62
  //
63
  // Assert(type.getKind() == kind::FUNCTION_TYPE);
64
65
312
  Cardinality argsCard(1);
66
  // get the largest cardinality of function arguments/return type
67
402
  for (size_t i = 0, i_end = type.getNumChildren() - 1; i < i_end; ++i)
68
  {
69
246
    argsCard *= type[i].getCardinality();
70
  }
71
72
312
  Cardinality valueCard = type[type.getNumChildren() - 1].getCardinality();
73
74
312
  return valueCard ^ argsCard;
75
}
76
77
}  // namespace builtin
78
}  // namespace theory
79
29502
}  // namespace cvc5