로딩중...
검색중...
일치하는것 없음
by::visitor 클래스 참조

Base visitor class for AST traversal 더 자세히 ...

#include <visitor.hpp>

by::visitor에 대한 상속 다이어그램 :
by::tworker< void, node > by::expander by::generalizer by::graphVisitor by::verifier

Public 멤버 함수

 visitor (nbool isReturnable)
 
void setReturnable (nbool isReturnable)
 
nbool isReturnable () const
 
virtual void visit (const visitInfo &i, node &me)
 
virtual nbool onVisit (const visitInfo &i, node &me, nbool alreadyVisited)
 
virtual void onLeave (const visitInfo &i, node &me, nbool alreadyVisited)
 
virtual void onTraverse (const visitInfo &i, node &me)
 
virtual void onTraverse (const visitInfo &i, asExpr &a)
 
virtual void onTraverse (const visitInfo &i, assignExpr &a)
 
virtual void onTraverse (const visitInfo &i, blockExpr &b)
 
virtual void onTraverse (const visitInfo &i, defVarExpr &d)
 
virtual void onTraverse (const visitInfo &i, FBOExpr &f)
 
virtual void onTraverse (const visitInfo &i, getExpr &e)
 
virtual void onTraverse (const visitInfo &i, retExpr &b)
 
virtual void onTraverse (const visitInfo &i, evalExpr &e)
 
virtual void onTraverse (evalExpr &e, node &subject)
 
virtual void onTraverse (const visitInfo &i, func &f)
 
virtual void onTraverse (const visitInfo &i, frame &f)
 
virtual void onTraverse (const visitInfo &i, forExpr &f)
 
virtual void onTraverse (const visitInfo &i, retStateExpr &r)
 
virtual void onTraverse (const visitInfo &i, ifExpr &f)
 
virtual void onTraverse (const visitInfo &i, whileExpr &w)
 
virtual void onTraverse (const visitInfo &i, defArrayExpr &d)
 
virtual void onTraverse (const visitInfo &i, defNestedFuncExpr &e)
 
virtual void onTraverse (const visitInfo &i, genericOrigin &g)
 
virtual void onTraverse (const visitInfo &i, obj &o)
 
- by::tworker< void, node >(으)로부터 상속된 Public 멤버 함수
 tworker (const errReport &rpt)
 
errReportgetReport ()
 
const errReportgetReport () const BY_CONST_FUNC(getReport()) me &setReport(errReport &rpt)
 
me & setFlag (nint newFlag)
 
me & addFlag (nint flag)
 
me & delFlag (nint clear)
 
nbool isFlag (nint flag) const
 
nint getFlag () const
 
me & setTask (const node &root)
 
me & setTask (const node *it) BY_SIDE_FUNC(it
 
nodegetTask ()
 
const nodegetTask () const BY_CONST_FUNC(getTask()) virtual void rel()
 
void work ()
 
const areagetArea () const BY_CONST_FUNC(_getArea()) nbool isOk() const
 

Protected 멤버 함수

void _onWork () override
 
void _prepare () override
 Protected virtual method for preparation before starting the work.
 
- by::tworker< void, node >(으)로부터 상속된 Protected 멤버 함수
void _report (baseErr *e)
 
virtual void _onEndWork ()
 Protected virtual method called after the work is completed.
 
area_getArea ()
 
void _onEndErrReport (const errReport &rpt) const
 

추가로 상속된 멤버들

- by::tworker< void, node >(으)로부터 상속된 Public 타입
enum  logFlag
 
- by::tworker< void, node >(으)로부터 상속된 Public 속성
me setTask it
 
me setTask * this
 

상세한 설명

Base visitor class for AST traversal

Since byeol focuses on AST, visitor is used frequently. visitor is actively utilized to separate the traversal method from the actions taken when visiting node during traversal.

Traversal

Always follows preorder traversal. Changing to postorder traversal is not possible. visit() consists of 3 stages:

  1. Visit the currently found node (onVisit())
  2. Traverse next child nodes (onTraverse())
  3. Leave the currently found node (onLeave())

Downcasting Through accept

visitor has many virtual functions that represent visits to many concrete types like onVisit(T&). On the other hand, when searching in onTraverse, the node type is mainly used because it uses the tbicontainable interface through node's subs(). So somewhere the node type must be downcast to concrete types like nInt or defNestedFuncExpr. For this purpose, node's virtual function accept() is called. See the example:

void defNestedFuncExpr::accept(const visitInfo& i, visitor& v) {
v.visit(i, *this); // calls visitor::visit(const visitInfo&, defNestedFuncExpr&)
}
Definition tnarr.hpp:9
Visitor context information
Definition visitInfo.hpp:11
Base visitor class for AST traversal
Definition visitor.hpp:61

When the virtual function accept() is called, it reversely calls visitor's visit() as a concrete type through *this. For this, all node-derived classes participating in visitation must override the virtual function accept(), and the VISIT macro is used to make this process easier. You will often see declarations like this:

class _nout pod: public node {
BY(CLASS(pod, node), VISIT()) // <---
Base class for all AST nodes in the byeol language
Definition node.hpp:195
Pod
Definition pod.hpp:21

If a node-derived class does not override accept(), onTraverse(node&) is used instead, which is sufficient for those cases.

Duplicate Visit Elimination

AST sometimes has mutual references between nodes. In this case, traversing without any exception handling revisits already visited nodes and enters an infinite loop. visitor owns a map called _visited. Through this, when visit() is called, it determines if it's an already visited node and provides exception handling. This visit history information is reset right before visitor starts visiting each time. If you want to enable revisiting, change the value with setReturnable(true).

멤버 함수 문서화

◆ _onWork()

void by::visitor::_onWork ( )
overrideprotectedvirtual

◆ _prepare()

void by::visitor::_prepare ( )
overrideprotectedvirtual

Protected virtual method for preparation before starting the work.

This hook allows derived classes to perform any necessary setup or initialization before _onWork() is invoked.

by::tworker< void, node >(으)로부터 재구현되었습니다.

◆ setReturnable()

void by::visitor::setReturnable ( nbool isReturnable)

if you set the visitor as returnable, nodes you have already been visited, will be visited again if it's refered by different nodes. in default, this value is false.


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.:
to Top