bool NodeTemplate<ref_count>::isConst() const { assertTNodeNotExpired(); Debug("isConst") << "Node::isConst() for: " << *this << std::endl; if(isNull()) { return false; } switch(getMetaKind()) { case kind::metakind::CONSTANT: Debug("isConst") << "Node::isConst() returning true, it's a CONSTANT" << std::endl; return true; case kind::metakind::VARIABLE: Debug("isConst") << "Node::isConst() returning false, it's a VARIABLE" << std::endl; return false; default: if(expr::TypeChecker::neverIsConst(NodeManager::currentNM(), *this)){ Debug("isConst") << "Node::isConst() returning false, the kind is never const" << std::endl; return false; } if(getAttribute(IsConstComputedAttr())) { bool bval = getAttribute(IsConstAttr()); Debug("isConst") << "Node::isConst() returning cached value " << (bval ? "true" : "false") << " for: " << *this << std::endl; return bval; } else { bool bval = expr::TypeChecker::computeIsConst(NodeManager::currentNM(), *this); Debug("isConst") << "Node::isConst() computed value " << (bval ? "true" : "false") << " for: " << *this << std::endl; const_cast< NodeTemplate<ref_count>* >(this)->setAttribute(IsConstAttr(), bval); const_cast< NodeTemplate<ref_count>* >(this)->setAttribute(IsConstComputedAttr(), true); return bval; } } }
void NodeValue::printAst(std::ostream& out, int ind) const { RefCountGuard guard(this); indent(out, ind); out << '('; out << getKind(); if(getMetaKind() == kind::metakind::VARIABLE) { out << ' ' << getId(); } else if(getMetaKind() == kind::metakind::CONSTANT) { out << ' '; kind::metakind::NodeValueConstPrinter::toStream(out, this); } else { if(nv_begin() != nv_end()) { for(const_nv_iterator child = nv_begin(); child != nv_end(); ++child) { out << std::endl; (*child)->printAst(out, ind + 1); } out << std::endl; indent(out, ind); } } out << ')'; }