Base visitor class for AST traversal. More...
#include <visitor.hpp>
Public Member Functions | |
| 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) |
Public Member Functions inherited from by::tworker< void, node > | |
| tworker (const errReport &rpt) | |
| errReport & | getReport () |
| const errReport & | getReport () 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 |
| node * | getTask () |
| const node * | getTask () const BY_CONST_FUNC(getTask()) virtual void rel() |
| void | work () |
| const area & | getArea () const BY_CONST_FUNC(_getArea()) nbool isOk() const |
Protected Member Functions | |
| void | _onWork () override |
| void | _prepare () override |
| Protected virtual method for preparation before starting the work. | |
Protected Member Functions inherited from by::tworker< void, node > | |
| void | _report (baseErr *e) |
| virtual void | _onEndWork () |
| Protected virtual method called after the work is completed. | |
| area & | _getArea () |
| void | _onEndErrReport (const errReport &rpt) const |
Additional Inherited Members | |
Public Types inherited from by::tworker< void, node > | |
| enum | logFlag |
Public Attributes inherited from by::tworker< void, node > | |
| 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.
Always follows preorder traversal. Changing to postorder traversal is not possible. visit() consists of 3 stages:
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:
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:
If a node-derived class does not override accept(), onTraverse(node&) is used instead, which is sufficient for those cases.
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).
|
overrideprotectedvirtual |
Implements by::tworker< void, node >.
|
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.
Reimplemented from by::tworker< void, node >.
| 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.