1 /********************* */
4 ** Top contributors (to current version):
5 ** Morgan Deters, Tim King, Yoni Zohar
6 ** This file is part of the CVC4 project.
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.\endverbatim
12 ** \brief Reference-counted encapsulation of a pointer to node information.
14 ** Reference-counted encapsulation of a pointer to node information.
16 #include "expr/node.h"
22 #include "base/exception.h"
23 #include "base/output.h"
24 #include "expr/attribute.h"
25 #include "expr/type_checker.h"
31 TypeCheckingExceptionPrivate::TypeCheckingExceptionPrivate(TNode node
,
33 : Exception(message
), d_node(new Node(node
))
37 LastExceptionBuffer
* current
= LastExceptionBuffer::getCurrent();
39 // Since this node is malformed, we cannot use toString().
40 // Instead, we print the kind and the children.
41 ss
<< "node kind: " << node
.getKind() << ". children: ";
43 for (const TNode
& child
: node
)
45 ss
<< "child[" << i
<< "]: " << child
<< ". ";
48 string ssstring
= ss
.str();
49 current
->setContents(ssstring
.c_str());
51 #endif /* CVC4_DEBUG */
54 TypeCheckingExceptionPrivate::~TypeCheckingExceptionPrivate() { delete d_node
; }
56 void TypeCheckingExceptionPrivate::toStream(std::ostream
& os
) const
58 os
<< "Error during type checking: " << d_msg
<< std::endl
<< *d_node
<< endl
<< "The ill-typed expression: " << *d_node
;
61 NodeTemplate
<true> TypeCheckingExceptionPrivate::getNode() const
66 UnknownTypeException::UnknownTypeException(TNode n
)
67 : TypeCheckingExceptionPrivate(
69 "this expression contains an element of unknown type (such as an "
71 " its type cannot be computed until it is substituted away")
75 /** Is this node constant? (and has that been computed yet?) */
76 struct IsConstTag
{ };
77 struct IsConstComputedTag
{ };
78 typedef expr::Attribute
<IsConstTag
, bool> IsConstAttr
;
79 typedef expr::Attribute
<IsConstComputedTag
, bool> IsConstComputedAttr
;
81 template <bool ref_count
>
82 bool NodeTemplate
<ref_count
>::isConst() const {
83 assertTNodeNotExpired();
84 Debug("isConst") << "Node::isConst() for: " << *this << std::endl
;
88 switch(getMetaKind()) {
89 case kind::metakind::CONSTANT
:
90 Debug("isConst") << "Node::isConst() returning true, it's a CONSTANT" << std::endl
;
92 case kind::metakind::VARIABLE
:
93 Debug("isConst") << "Node::isConst() returning false, it's a VARIABLE" << std::endl
;
96 if(getAttribute(IsConstComputedAttr())) {
97 bool bval
= getAttribute(IsConstAttr());
98 Debug("isConst") << "Node::isConst() returning cached value " << (bval
? "true" : "false") << " for: " << *this << std::endl
;
101 bool bval
= expr::TypeChecker::computeIsConst(NodeManager::currentNM(), *this);
102 Debug("isConst") << "Node::isConst() computed value " << (bval
? "true" : "false") << " for: " << *this << std::endl
;
103 const_cast< NodeTemplate
<ref_count
>* >(this)->setAttribute(IsConstAttr(), bval
);
104 const_cast< NodeTemplate
<ref_count
>* >(this)->setAttribute(IsConstComputedAttr(), true);
110 template bool NodeTemplate
<true>::isConst() const;
111 template bool NodeTemplate
<false>::isConst() const;
113 }/* CVC4 namespace */