Make theory rewriters non-static (#3547)
[cvc5.git] / src / theory / rewriter.h
1 /********************* */
2 /*! \file rewriter.h
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Morgan Deters, Dejan Jovanovic, Tim King
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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.\endverbatim
11 **
12 ** \brief The Rewriter class
13 **
14 ** The Rewriter class.
15 **/
16
17 #include "cvc4_private.h"
18
19 #pragma once
20
21 #include "expr/node.h"
22 #include "theory/theory_rewriter.h"
23 #include "util/unsafe_interrupt_exception.h"
24
25 namespace CVC4 {
26 namespace theory {
27
28 class RewriterInitializer;
29
30 /**
31 * The main rewriter class.
32 */
33 class Rewriter {
34 public:
35 Rewriter();
36
37 /**
38 * Rewrites the node using theoryOf() to determine which rewriter to
39 * use on the node.
40 */
41 static Node rewrite(TNode node);
42
43 /**
44 * Garbage collects the rewrite caches.
45 */
46 static void clearCaches();
47
48 private:
49 /**
50 * Get the (singleton) instance of the rewriter.
51 *
52 * TODO(#3468): Get rid of this singleton
53 */
54 static Rewriter& getInstance();
55
56 /** Returns the appropriate cache for a node */
57 Node getPreRewriteCache(theory::TheoryId theoryId, TNode node);
58
59 /** Returns the appropriate cache for a node */
60 Node getPostRewriteCache(theory::TheoryId theoryId, TNode node);
61
62 /** Sets the appropriate cache for a node */
63 void setPreRewriteCache(theory::TheoryId theoryId, TNode node, TNode cache);
64
65 /** Sets the appropriate cache for a node */
66 void setPostRewriteCache(theory::TheoryId theoryId, TNode node, TNode cache);
67
68 /**
69 * Rewrites the node using the given theory rewriter.
70 */
71 Node rewriteTo(theory::TheoryId theoryId, Node node);
72
73 /** Calls the pre-rewriter for the given theory */
74 RewriteResponse callPreRewrite(theory::TheoryId theoryId, TNode node);
75
76 /** Calls the post-rewriter for the given theory */
77 RewriteResponse callPostRewrite(theory::TheoryId theoryId, TNode node);
78
79 /**
80 * Calls the equality-rewriter for the given theory.
81 */
82 Node callRewriteEquality(theory::TheoryId theoryId, TNode equality);
83
84 void clearCachesInternal();
85
86 /** Theory rewriters managed by this rewriter instance */
87 std::unique_ptr<TheoryRewriter> d_theoryRewriters[theory::THEORY_LAST];
88
89 unsigned long d_iterationCount = 0;
90
91 #ifdef CVC4_ASSERTIONS
92 std::unique_ptr<std::unordered_set<Node, NodeHashFunction>> d_rewriteStack =
93 nullptr;
94 #endif /* CVC4_ASSERTIONS */
95 };/* class Rewriter */
96
97 }/* CVC4::theory namespace */
98 }/* CVC4 namespace */