GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bags/theory_bags_type_enumerator.cpp Lines: 1 32 3.1 %
Date: 2021-05-22 Branches: 2 106 1.9 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Mudathir Mohamed
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
 * Bag enumerator implementation
14
 */
15
16
#include "theory/bags/theory_bags_type_enumerator.h"
17
18
#include "expr/emptybag.h"
19
#include "theory/rewriter.h"
20
#include "theory_bags_type_enumerator.h"
21
22
namespace cvc5 {
23
namespace theory {
24
namespace bags {
25
26
BagEnumerator::BagEnumerator(TypeNode type, TypeEnumeratorProperties* tep)
27
    : TypeEnumeratorBase<BagEnumerator>(type),
28
      d_nodeManager(NodeManager::currentNM()),
29
      d_elementTypeEnumerator(type.getBagElementType(), tep)
30
{
31
  d_currentBag = d_nodeManager->mkConst(EmptyBag(type));
32
  d_element = *d_elementTypeEnumerator;
33
}
34
35
BagEnumerator::BagEnumerator(const BagEnumerator& enumerator)
36
    : TypeEnumeratorBase<BagEnumerator>(enumerator.getType()),
37
      d_nodeManager(enumerator.d_nodeManager),
38
      d_elementTypeEnumerator(enumerator.d_elementTypeEnumerator),
39
      d_currentBag(enumerator.d_currentBag),
40
      d_element(enumerator.d_element)
41
{
42
}
43
44
BagEnumerator::~BagEnumerator() {}
45
46
Node BagEnumerator::operator*()
47
{
48
  Trace("bag-type-enum") << "BagEnumerator::operator* d_currentBag = "
49
                         << d_currentBag << std::endl;
50
51
  return d_currentBag;
52
}
53
54
BagEnumerator& BagEnumerator::operator++()
55
{
56
  // increase the multiplicity by one
57
  Node one = d_nodeManager->mkConst(Rational(1));
58
  TypeNode elementType = d_elementTypeEnumerator.getType();
59
  Node singleton = d_nodeManager->mkBag(elementType, d_element, one);
60
  if (d_currentBag.getKind() == kind::EMPTYBAG)
61
  {
62
    d_currentBag = singleton;
63
  }
64
  else
65
  {
66
    d_currentBag =
67
        d_nodeManager->mkNode(kind::UNION_DISJOINT, singleton, d_currentBag);
68
  }
69
70
  d_currentBag = Rewriter::rewrite(d_currentBag);
71
72
  Assert(d_currentBag.isConst());
73
74
  Trace("bag-type-enum") << "BagEnumerator::operator++ d_currentBag = "
75
                         << d_currentBag << std::endl;
76
  return *this;
77
}
78
79
bool BagEnumerator::isFinished()
80
{
81
  // bags sequence is infinite and it never ends
82
  return false;
83
}
84
85
}  // namespace bags
86
}  // namespace theory
87
28191
}  // namespace cvc5