ExprVisitor之visitcounter源码学习
std::unorderedmap
/! \brief Get reference counter of each internal ExprNode in body. \param body The body expression. \return The reference count mapping. /std::unordered_map<const Node, sizet>GetExprRefCount(const Expr& body) { class ExprRefCounter : private ExprVisitor { public: std::unordered_map
std::unorderedmap
void ExprVisitor::VisitExpr(const Expr& expr) { auto it = visitcounter.find(expr.get()); if (it != visitcounter.end()) { ++it->second; } else { using TParent = ExprFunctor
using TSelf = ExprFunctor
virtual R VisitExpr(const Expr& n, Args… args) { static FType vtable = InitVTable(); return vtable(n, this, std::forward
static FType InitVTable() { FType vtable; // Set dispatch RELAY_EXPR_FUNCTOR_DISPATCH(ConstantNode); RELAY_EXPR_FUNCTOR_DISPATCH(TupleNode); RELAY_EXPR_FUNCTOR_DISPATCH(VarNode); RELAY_EXPR_FUNCTOR_DISPATCH(GlobalVarNode); RELAY_EXPR_FUNCTOR_DISPATCH(FunctionNode); RELAY_EXPR_FUNCTOR_DISPATCH(CallNode); RELAY_EXPR_FUNCTOR_DISPATCH(LetNode); RELAY_EXPR_FUNCTOR_DISPATCH(IfNode); RELAY_EXPR_FUNCTOR_DISPATCH(OpNode); RELAY_EXPR_FUNCTOR_DISPATCH(TupleGetItemNode); RELAY_EXPR_FUNCTOR_DISPATCH(RefCreateNode); RELAY_EXPR_FUNCTOR_DISPATCH(RefReadNode); RELAY_EXPR_FUNCTOR_DISPATCH(RefWriteNode); RELAY_EXPR_FUNCTOR_DISPATCH(ConstructorNode); RELAY_EXPR_FUNCTOR_DISPATCH(MatchNode); return vtable; }
RELAY_EXPR_FUNCTOR_DISPATCH#define RELAY_EXPR_FUNCTOR_DISPATCH(OP) \ vtable.template set_dispatch
//set_dispatch的定义template