GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/builtin/theory_builtin_type_rules.cpp Lines: 16 16 100.0 %
Date: 2021-11-05 Branches: 24 44 54.5 %

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
2583
TypeNode UninterpretedConstantTypeRule::computeType(NodeManager* nodeManager,
28
                                                    TNode n,
29
                                                    bool check)
30
{
31
2583
  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
335
Node SortProperties::mkGroundTerm(TypeNode type)
44
{
45
  // we typically use this method for sorts, although there are other types
46
  // where it is used as well, e.g. arrays that are not closed enumerable.
47
  GroundTermAttribute gta;
48
335
  if (type.hasAttribute(gta))
49
  {
50
300
    return type.getAttribute(gta);
51
  }
52
35
  SkolemManager* sm = NodeManager::currentNM()->getSkolemManager();
53
  Node k = sm->mkDummySkolem(
54
70
      "groundTerm", type, "a ground term created for type " + type.toString());
55
35
  type.setAttribute(gta, k);
56
35
  return k;
57
}
58
59
156
Cardinality FunctionProperties::computeCardinality(TypeNode type)
60
{
61
  // Don't assert this; allow other theories to use this cardinality
62
  // computation.
63
  //
64
  // Assert(type.getKind() == kind::FUNCTION_TYPE);
65
66
312
  Cardinality argsCard(1);
67
  // get the largest cardinality of function arguments/return type
68
402
  for (size_t i = 0, i_end = type.getNumChildren() - 1; i < i_end; ++i)
69
  {
70
246
    argsCard *= type[i].getCardinality();
71
  }
72
73
312
  Cardinality valueCard = type[type.getNumChildren() - 1].getCardinality();
74
75
312
  return valueCard ^ argsCard;
76
}
77
78
}  // namespace builtin
79
}  // namespace theory
80
31125
}  // namespace cvc5