Update copyright headers.
[cvc5.git] / src / theory / theory_rewriter.h
1 /********************* */
2 /*! \file theory_rewriter.h
3 ** \verbatim
4 ** Top contributors (to current version):
5 ** Andres Noetzli, Morgan Deters, Andrew Reynolds
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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 TheoryRewriter class
13 **
14 ** The TheoryRewriter class is the interface that theory rewriters implement.
15 **/
16
17 #include "cvc4_private.h"
18
19 #ifndef CVC4__THEORY__THEORY_REWRITER_H
20 #define CVC4__THEORY__THEORY_REWRITER_H
21
22 #include "expr/node.h"
23
24 namespace CVC4 {
25 namespace theory {
26
27 class Rewriter;
28
29 /**
30 * Theory rewriters signal whether more rewriting is needed (or not)
31 * by using a member of this enumeration. See RewriteResponse, below.
32 */
33 enum RewriteStatus
34 {
35 /** The node is fully rewritten (no more rewrites apply) */
36 REWRITE_DONE,
37 /** The node may be rewritten further */
38 REWRITE_AGAIN,
39 /** Subnodes of the node may be rewritten further */
40 REWRITE_AGAIN_FULL
41 }; /* enum RewriteStatus */
42
43 /**
44 * Instances of this class serve as response codes from
45 * TheoryRewriter::preRewrite() and TheoryRewriter::postRewrite(). The response
46 * consists of the rewritten node as well as a status that indicates whether
47 * more rewriting is needed or not.
48 */
49 struct RewriteResponse
50 {
51 const RewriteStatus d_status;
52 const Node d_node;
53 RewriteResponse(RewriteStatus status, Node n) : d_status(status), d_node(n) {}
54 }; /* struct RewriteResponse */
55
56 /**
57 * The interface that a theory rewriter has to implement.
58 *
59 * Note: A theory rewriter is expected to handle all kinds of a theory, even
60 * the ones that are removed by `Theory::expandDefinition()` since it may be
61 * called on terms before the definitions have been expanded.
62 */
63 class TheoryRewriter
64 {
65 public:
66 virtual ~TheoryRewriter() = default;
67
68 /**
69 * Registers the rewrites of a given theory with the rewriter.
70 *
71 * @param rewriter The rewriter to register the rewrites with.
72 */
73 virtual void registerRewrites(Rewriter* rewriter) {}
74
75 /**
76 * Performs a pre-rewrite step.
77 *
78 * @param node The node to rewrite
79 */
80 virtual RewriteResponse postRewrite(TNode node) = 0;
81
82 /**
83 * Performs a post-rewrite step.
84 *
85 * @param node The node to rewrite
86 */
87 virtual RewriteResponse preRewrite(TNode node) = 0;
88 };
89
90 } // namespace theory
91 } // namespace CVC4
92
93 #endif /* CVC4__THEORY__THEORY_REWRITER_H */