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 : 29240 : BoundVarManager::BoundVarManager() {}
23 : :
24 : 24727 : BoundVarManager::~BoundVarManager() {}
25 : :
26 : 366173 : void BoundVarManager::setNameAttr(Node v, const std::string& name)
27 : : {
28 : 366173 : v.setAttribute(expr::VarNameAttr(), name);
29 : 366173 : }
30 : :
31 : 366362 : Node BoundVarManager::getCacheValue(TNode cv1, TNode cv2)
32 : : {
33 : 366362 : return NodeManager::mkNode(Kind::SEXPR, cv1, cv2);
34 : : }
35 : 636 : Node BoundVarManager::getCacheValue(TNode cv1, TNode cv2, TNode cv3)
36 : : {
37 : 636 : return NodeManager::mkNode(Kind::SEXPR, cv1, cv2, cv3);
38 : : }
39 : :
40 : 47047 : Node BoundVarManager::getCacheValue(TNode cv1, TNode cv2, size_t i)
41 : : {
42 : 47047 : NodeManager* nm = cv1.getNodeManager();
43 : 47047 : return NodeManager::mkNode(Kind::SEXPR, cv1, cv2, getCacheValue(nm, i));
44 : : }
45 : :
46 : 776501 : Node BoundVarManager::getCacheValue(NodeManager* nm, size_t i)
47 : : {
48 : 1553002 : return nm->mkConstInt(Rational(i));
49 : : }
50 : :
51 : 364727 : Node BoundVarManager::getCacheValue(TNode cv, size_t i)
52 : : {
53 : 364727 : NodeManager* nm = cv.getNodeManager();
54 : 364727 : return getCacheValue(cv, getCacheValue(nm, i));
55 : : }
56 : :
57 : 459603 : Node BoundVarManager::mkBoundVar(BoundVarId id, Node n, TypeNode tn)
58 : : {
59 : 459603 : std::tuple<BoundVarId, TypeNode, Node> key(id, tn, n);
60 : : std::map<std::tuple<BoundVarId, TypeNode, Node>, Node>::iterator it =
61 : 459603 : d_cache.find(key);
62 [ + + ]: 459603 : if (it != d_cache.end())
63 : : {
64 : 125299 : return it->second;
65 : : }
66 : 334304 : Node v = NodeManager::mkBoundVar(tn);
67 : 334304 : d_cache[key] = v;
68 : 334304 : return v;
69 : 459603 : }
70 : :
71 : 366173 : Node BoundVarManager::mkBoundVar(BoundVarId id,
72 : : Node n,
73 : : const std::string& name,
74 : : TypeNode tn)
75 : : {
76 : 732346 : Node v = mkBoundVar(id, n, tn);
77 : 366173 : setNameAttr(v, name);
78 : 366173 : return v;
79 : 0 : }
80 : :
81 : : } // namespace cvc5::internal
|