Branch data Line data Source code
1 : : /******************************************************************************
2 : : * This file is part of the cvc5 project.
3 : : *
4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
5 : : * in the top-level source directory and their institutional affiliations.
6 : : * All rights reserved. See the file COPYING in the top-level source
7 : : * directory for licensing information.
8 : : * ****************************************************************************
9 : : *
10 : : * Bound variable manager.
11 : : */
12 : :
13 : : #include "expr/bound_var_manager.h"
14 : :
15 : : #include "expr/node_manager_attributes.h"
16 : : #include "util/rational.h"
17 : :
18 : : using namespace cvc5::internal::kind;
19 : :
20 : : namespace cvc5::internal {
21 : :
22 : 78159 : BoundVarManager::BoundVarManager() {}
23 : :
24 : 72698 : BoundVarManager::~BoundVarManager() {}
25 : :
26 : 1532 : void BoundVarManager::setNameAttr(Node v, const std::string& name)
27 : : {
28 : 1532 : v.setAttribute(expr::VarNameAttr(), name);
29 : 1532 : }
30 : :
31 : 3239 : Node BoundVarManager::getCacheValue(TNode cv1, TNode cv2)
32 : : {
33 : 3239 : return NodeManager::mkNode(Kind::SEXPR, cv1, cv2);
34 : : }
35 : 352 : Node BoundVarManager::getCacheValue(TNode cv1, TNode cv2, TNode cv3)
36 : : {
37 : 352 : return NodeManager::mkNode(Kind::SEXPR, cv1, cv2, cv3);
38 : : }
39 : :
40 : 45093 : Node BoundVarManager::getCacheValue(TNode cv1, TNode cv2, size_t i)
41 : : {
42 : 45093 : NodeManager* nm = cv1.getNodeManager();
43 : 45093 : return NodeManager::mkNode(Kind::SEXPR, cv1, cv2, getCacheValue(nm, i));
44 : : }
45 : :
46 : 45093 : Node BoundVarManager::getCacheValue(NodeManager* nm, size_t i)
47 : : {
48 : 90186 : return nm->mkConstInt(Rational(i));
49 : : }
50 : :
51 : 0 : Node BoundVarManager::getCacheValue(TNode cv, size_t i)
52 : : {
53 : 0 : NodeManager* nm = cv.getNodeManager();
54 : 0 : return getCacheValue(cv, getCacheValue(nm, i));
55 : : }
56 : :
57 : 100848 : Node BoundVarManager::mkBoundVar(BoundVarId id, Node n, TypeNode tn)
58 : : {
59 : 100848 : std::tuple<BoundVarId, TypeNode, Node> key(id, tn, n);
60 : : std::map<std::tuple<BoundVarId, TypeNode, Node>, Node>::iterator it =
61 : 100848 : d_cache.find(key);
62 [ + + ]: 100848 : if (it != d_cache.end())
63 : : {
64 : 62397 : return it->second;
65 : : }
66 : 38451 : Node v = NodeManager::mkBoundVar(tn);
67 : 38451 : d_cache[key] = v;
68 : 38451 : return v;
69 : 100848 : }
70 : :
71 : 1532 : Node BoundVarManager::mkBoundVar(BoundVarId id,
72 : : Node n,
73 : : const std::string& name,
74 : : TypeNode tn)
75 : : {
76 : 3064 : Node v = mkBoundVar(id, n, tn);
77 : 1532 : setNameAttr(v, name);
78 : 1532 : return v;
79 : 0 : }
80 : :
81 : : } // namespace cvc5::internal
|