Branch data Line data Source code
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-2025 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 : : * A class for allocating a list of free variables 14 : : */ 15 : : #include "expr/free_var_cache.h" 16 : : 17 : : #include "expr/node_algorithm.h" 18 : : 19 : : namespace cvc5::internal { 20 : : 21 : 234195 : TNode FreeVarCache::getFreeVar(const TypeNode& tn, size_t i) 22 : : { 23 [ + + ]: 234195 : while (i >= d_fv[tn].size()) 24 : : { 25 : 19352 : Node v = NodeManager::mkBoundVar(tn); 26 : 9676 : d_allVars.push_back(v); 27 : : // store its id 28 : 9676 : d_fvId[v] = d_fv[tn].size(); 29 [ + - ]: 19352 : Trace("free-var-cache") 30 : 9676 : << "Free variable id " << v << " = " << d_fvId[v] << std::endl; 31 : 9676 : d_fv[tn].push_back(v); 32 : : } 33 : 224519 : return d_fv[tn][i]; 34 : : } 35 : : 36 : 161936 : TNode FreeVarCache::getFreeVarInc(const TypeNode& tn, 37 : : std::map<TypeNode, size_t>& var_count) 38 : : { 39 : 161936 : size_t index = var_count[tn]; 40 : 161936 : var_count[tn]++; 41 : 161936 : return getFreeVar(tn, index); 42 : : } 43 : : 44 : 44735 : bool FreeVarCache::isFreeVar(const Node& n) const 45 : : { 46 : 44735 : return d_fvId.find(n) != d_fvId.end(); 47 : : } 48 : : 49 : 0 : size_t FreeVarCache::getFreeVarId(const Node& n) const 50 : : { 51 : 0 : std::map<Node, size_t>::const_iterator it = d_fvId.find(n); 52 [ - - ]: 0 : if (it == d_fvId.end()) 53 : : { 54 : 0 : DebugUnhandled() << "FreeVarCache::isFreeVar: " << n 55 : 0 : << " is not a cached free variable."; 56 : : return 0; 57 : : } 58 : 0 : return it->second; 59 : : } 60 : : 61 : 0 : bool FreeVarCache::hasFreeVar(const Node& n) const 62 : : { 63 : 0 : return expr::hasSubterm(n, d_allVars); 64 : : } 65 : : 66 : : } // namespace cvc5::internal