1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Dejan Jovanovic, Tim King, Morgan Deters |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 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 |
|
* Rewriter attributes. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#pragma once |
19 |
|
|
20 |
|
#include "expr/attribute.h" |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
namespace theory { |
24 |
|
|
25 |
|
template <bool pre, theory::TheoryId theoryId> |
26 |
|
struct RewriteCacheTag {}; |
27 |
|
|
28 |
|
template <theory::TheoryId theoryId> |
29 |
|
struct RewriteAttibute { |
30 |
|
|
31 |
|
typedef expr::Attribute< RewriteCacheTag<true, theoryId>, Node> pre_rewrite; |
32 |
|
typedef expr::Attribute< RewriteCacheTag<false, theoryId>, Node> post_rewrite; |
33 |
|
|
34 |
|
/** |
35 |
|
* Get the value of the pre-rewrite cache. |
36 |
|
*/ |
37 |
40458577 |
static Node getPreRewriteCache(TNode node) |
38 |
|
{ |
39 |
80917154 |
Node cache; |
40 |
40458577 |
if (node.hasAttribute(pre_rewrite())) { |
41 |
28708668 |
node.getAttribute(pre_rewrite(), cache); |
42 |
|
} else { |
43 |
11749909 |
return Node::null(); |
44 |
|
} |
45 |
28708668 |
if (cache.isNull()) { |
46 |
23909497 |
return node; |
47 |
|
} else { |
48 |
4799171 |
return cache; |
49 |
|
} |
50 |
|
} |
51 |
|
|
52 |
|
/** |
53 |
|
* Set the value of the pre-rewrite cache. |
54 |
|
*/ |
55 |
12260550 |
static void setPreRewriteCache(TNode node, TNode cache) |
56 |
|
{ |
57 |
12260550 |
Trace("rewriter") << "setting pre-rewrite of " << node << " to " << cache << std::endl; |
58 |
12260550 |
Assert(!cache.isNull()); |
59 |
12260550 |
if (node == cache) { |
60 |
10081264 |
node.setAttribute(pre_rewrite(), Node::null()); |
61 |
|
} else { |
62 |
2179286 |
node.setAttribute(pre_rewrite(), cache); |
63 |
|
} |
64 |
12260550 |
} |
65 |
|
|
66 |
|
/** |
67 |
|
* Get the value of the post-rewrite cache. |
68 |
|
* none). |
69 |
|
*/ |
70 |
122174064 |
static Node getPostRewriteCache(TNode node) |
71 |
|
{ |
72 |
244348128 |
Node cache; |
73 |
122174064 |
if (node.hasAttribute(post_rewrite())) { |
74 |
71604950 |
node.getAttribute(post_rewrite(), cache); |
75 |
|
} else { |
76 |
50569114 |
return Node::null(); |
77 |
|
} |
78 |
71604950 |
if (cache.isNull()) { |
79 |
57290871 |
return node; |
80 |
|
} else { |
81 |
14314079 |
return cache; |
82 |
|
} |
83 |
|
} |
84 |
|
|
85 |
|
/** |
86 |
|
* Set the value of the post-rewrite cache. v cannot be a null Node. |
87 |
|
*/ |
88 |
11451077 |
static void setPostRewriteCache(TNode node, TNode cache) |
89 |
|
{ |
90 |
11451077 |
Assert(!cache.isNull()); |
91 |
11451077 |
Trace("rewriter") << "setting rewrite of " << node << " to " << cache << std::endl; |
92 |
11451077 |
if (node == cache) { |
93 |
5646597 |
node.setAttribute(post_rewrite(), Node::null()); |
94 |
|
} else { |
95 |
5804480 |
node.setAttribute(post_rewrite(), cache); |
96 |
|
} |
97 |
11451077 |
} |
98 |
|
};/* struct RewriteAttribute */ |
99 |
|
|
100 |
|
} // namespace theory |
101 |
|
} // namespace cvc5 |