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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/********************* */
/*! \file rewriter.h
** \verbatim
** Original author: dejan
** Major contributors: mdeters
** Minor contributors (to current version): none
** This file is part of the CVC4 prototype.
** Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
** Courant Institute of Mathematical Sciences
** New York University
** See the file COPYING in the top-level source directory for licensing
** information.\endverbatim
**
** \brief The Rewriter class
**
** The Rewriter class.
**/
#include "cvc4_private.h"
#pragma once
#include "expr/node.h"
#include "expr/attribute.h"
namespace CVC4 {
namespace theory {
/**
* Theory rewriters signal whether more rewriting is needed (or not)
* by using a member of this enumeration. See RewriteResponse, below.
*/
enum RewriteStatus {
REWRITE_DONE,
REWRITE_AGAIN,
REWRITE_AGAIN_FULL
};/* enum RewriteStatus */
/**
* Instances of this class serve as response codes from
* Theory::preRewrite() and Theory::postRewrite(). Instances of
* derived classes RewriteComplete(n), RewriteAgain(n), and
* FullRewriteNeeded(n) should be used, giving self-documenting
* rewrite behavior.
*/
struct RewriteResponse {
const RewriteStatus status;
const Node node;
RewriteResponse(RewriteStatus status, Node node) :
status(status), node(node) {}
};/* struct RewriteResponse */
/**
* The main rewriter class. All functionality is static.
*/
class Rewriter {
/** Returns the appropriate cache for a node */
static Node getPreRewriteCache(theory::TheoryId theoryId, TNode node);
/** Returns the appropriate cache for a node */
static Node getPostRewriteCache(theory::TheoryId theoryId, TNode node);
/** Sets the appropriate cache for a node */
static void setPreRewriteCache(theory::TheoryId theoryId,
TNode node, TNode cache);
/** Sets the appropriate cache for a node */
static void setPostRewriteCache(theory::TheoryId theoryId,
TNode node, TNode cache);
// disable construction of rewriters; all functionality is static
Rewriter() CVC4_UNUSED;
Rewriter(const Rewriter&) CVC4_UNUSED;
/**
* Rewrites the node using the given theory rewriter.
*/
static Node rewriteTo(theory::TheoryId theoryId, Node node);
/** Calls the pre-rewriter for the given theory */
static RewriteResponse callPreRewrite(theory::TheoryId theoryId, TNode node);
/** Calls the post-rewriter for the given theory */
static RewriteResponse callPostRewrite(theory::TheoryId theoryId, TNode node);
/**
* Calls the equality-rewruter for the given theory.
*/
static Node callRewriteEquality(theory::TheoryId theoryId, TNode equality);
public:
/**
* Rewrites the node using theoryOf() to determine which rewriter to
* use on the node.
*/
static Node rewrite(Node node);
/**
* Rewrite an equality between two terms that are already in normal form, so
* that the equality is in theory-normal form.
*/
static Node rewriteEquality(theory::TheoryId theoryId, TNode node);
/**
* Should be called before the rewriter gets used for the first time.
*/
static void init();
/**
* Should be called to clean up any state.
*/
static void shutdown();
};/* class Rewriter */
}/* CVC4::theory namespace */
}/* CVC4 namespace */
|