summaryrefslogtreecommitdiff
path: root/src/theory/strings/skolem_cache.cpp
blob: 9f44429a06fa5d7b69028269fae9b4cc1ed9ab91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*********************                                                        */
/*! \file skolem_cache.cpp
 ** \verbatim
 ** Top contributors (to current version):
 **   Andrew Reynolds
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS
 ** in the top-level source directory) and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief Implementation of a cache of skolems for theory of strings.
 **/

#include "theory/strings/skolem_cache.h"

#include "theory/rewriter.h"

namespace CVC4 {
namespace theory {
namespace strings {

SkolemCache::SkolemCache() {}

Node SkolemCache::mkSkolemCached(Node a, Node b, SkolemId id, const char* c)
{
  NodeManager* nm = NodeManager::currentNM();
  if (id == SK_FIRST_CTN_PRE || id == SK_FIRST_CTN_POST)
  {
    Node sk;
    std::map<SkolemId, Node>::iterator it = d_skolemFnCache.find(id);
    if (it == d_skolemFnCache.end())
    {
      std::vector<TypeNode> argTypes;
      argTypes.push_back(a.getType());
      if (!b.isNull()) argTypes.push_back(b.getType());
      sk = nm->mkSkolem(c, nm->mkFunctionType(argTypes, nm->stringType()));
      d_allSkolems.insert(sk);
      d_skolemFnCache[id] = sk;
    }
    else
    {
      sk = it->second;
    }
    Node ret;
    if (b.isNull())
    {
      ret = nm->mkNode(kind::APPLY_UF, sk, a);
    }
    else
    {
      ret = nm->mkNode(kind::APPLY_UF, sk, a, b);
    }
    return ret;
  }
  else
  {
    if (!a.isNull()) a = Rewriter::rewrite(a);
    if (!b.isNull()) b = Rewriter::rewrite(b);
    std::map<SkolemId, Node>::iterator it = d_skolemCache[a][b].find(id);
    if (it == d_skolemCache[a][b].end())
    {
      Node sk = mkSkolem(c);
      d_skolemCache[a][b][id] = sk;
      return sk;
    }
    return it->second;
  }
}

Node SkolemCache::mkSkolemCached(Node a, SkolemId id, const char* c)
{
  return mkSkolemCached(a, Node::null(), id, c);
}

Node SkolemCache::mkSkolem(const char* c)
{
  NodeManager* nm = NodeManager::currentNM();
  Node n = nm->mkSkolem(c, nm->stringType(), "string skolem");
  d_allSkolems.insert(n);
  return n;
}

bool SkolemCache::isSkolem(Node n) const
{
  return d_allSkolems.find(n) != d_allSkolems.end();
}

}  // namespace strings
}  // namespace theory
}  // namespace CVC4
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback