1 /********************* */
2 /*! \file ite_removal.cpp
4 ** Original author: dejan
5 ** Major contributors: mdeters
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
14 ** \brief Removal of term ITEs
16 ** Removal of term ITEs.
21 #include "util/ite_removal.h"
22 #include "theory/rewriter.h"
23 #include "expr/command.h"
30 struct IteRewriteAttrTag
{};
31 typedef expr::Attribute
<IteRewriteAttrTag
, Node
> IteRewriteAttr
;
33 void RemoveITE::run(std::vector
<Node
>& output
) {
34 for (unsigned i
= 0, i_end
= output
.size(); i
< i_end
; ++ i
) {
35 output
[i
] = run(output
[i
], output
);
39 Node
RemoveITE::run(TNode node
, std::vector
<Node
>& output
) {
41 Debug("ite") << "removeITEs(" << node
<< ")" << endl
;
43 // The result may be cached already
45 NodeManager
*nodeManager
= NodeManager::currentNM();
46 if(nodeManager
->getAttribute(node
, IteRewriteAttr(), cachedRewrite
)) {
47 Debug("ite") << "removeITEs: in-cache: " << cachedRewrite
<< endl
;
48 return cachedRewrite
.isNull() ? Node(node
) : cachedRewrite
;
51 // If an ITE replace it
52 if(node
.getKind() == kind::ITE
) {
53 TypeNode nodeType
= node
.getType();
54 if(!nodeType
.isBoolean()) {
55 // Make the skolem to represent the ITE
56 Node skolem
= nodeManager
->mkVar(nodeType
);
58 if(Dump
.isOn("declarations")) {
60 kss
<< Expr::setlanguage(Expr::setlanguage::getLanguage(Dump("declarations"))) << skolem
;
61 string ks
= kss
.str();
62 Dump("declarations") << CommentCommand(ks
+ " is a variable introduced due to term-level ITE removal") << endl
63 << DeclareFunctionCommand(ks
, nodeType
.toType()) << endl
;
68 nodeManager
->mkNode(kind::ITE
, node
[0], skolem
.eqNode(node
[1]),
69 skolem
.eqNode(node
[2]));
70 Debug("ite") << "removeITEs(" << node
<< ") => " << newAssertion
<< endl
;
73 nodeManager
->setAttribute(node
, IteRewriteAttr(), skolem
);
75 // Remove ITEs from the new assertion, rewrite it and push it to the output
76 output
.push_back(run(newAssertion
, output
));
78 // The representation is now the skolem
83 // If not an ITE, go deep
84 vector
<Node
> newChildren
;
85 bool somethingChanged
= false;
86 if(node
.getMetaKind() == kind::metakind::PARAMETERIZED
) {
87 newChildren
.push_back(node
.getOperator());
89 // Remove the ITEs from the children
90 for(TNode::const_iterator it
= node
.begin(), end
= node
.end(); it
!= end
; ++it
) {
91 Node newChild
= run(*it
, output
);
92 somethingChanged
|= (newChild
!= *it
);
93 newChildren
.push_back(newChild
);
96 // If changes, we rewrite
97 if(somethingChanged
) {
98 cachedRewrite
= nodeManager
->mkNode(node
.getKind(), newChildren
);
99 nodeManager
->setAttribute(node
, IteRewriteAttr(), cachedRewrite
);
100 return cachedRewrite
;
102 nodeManager
->setAttribute(node
, IteRewriteAttr(), Node::null());
107 }/* CVC4 namespace */