Loading...
Searching...
No Matches
by::expander Class Reference

Visitor for expanding generic types and expressions. More...

#include <expander.hpp>

Inheritance diagram for by::expander:
by::visitor by::tworker< void, node >

Public Member Functions

void rel () override
 
nbool onVisit (const visitInfo &i, defAssignExpr &me, nbool) override
 
nbool onVisit (const visitInfo &i, asExpr &me, nbool) override
 
nbool onVisit (const visitInfo &i, obj &me, nbool) override
 
void onLeave (const visitInfo &i, obj &me, nbool) override
 
nbool onVisit (const visitInfo &i, func &me, nbool) override
 
void onLeave (const visitInfo &i, func &me, nbool) override
 
nbool onVisit (const visitInfo &i, baseFunc &me, nbool) override
 
void onLeave (const visitInfo &i, baseFunc &me, nbool) override
 
nbool onVisit (const visitInfo &i, getGenericExpr &me, nbool) override
 
- Public Member Functions inherited from by::visitor
 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)
 
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 Member Functions

void _onWork () override
 
- Protected Member Functions inherited from by::visitor
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
 

Detailed Description

Visitor for expanding generic types and expressions.

As mentioned in parser, the current prior type inference algorithm doesn't create dependency graphs but collects all prior type inference expressions and repeatedly attempts type inference. Since this approach is used, it's not suitable to perform the operation of repeatedly traversing expressions and attempting prior type inference all at once inside verifier. Therefore, it's necessary to complete prior type inference with expander before verifying with verifier.

Basic operation is based on visitor, so it's good to understand visitor beforehand.

Definition of Expressions Needing Type Inference

Basically, this applies to all expressions where the user did not specify a type. However, not all expressions without type specification are handled. Prior type inference is only needed when there is no type and the symbol exists in an obj scope. Consider the following byeol code example:

age := 57 # 1) type inference
foo() int
name := "kniz" # 2) also type inference
return name.len()
Definition tnarr.hpp:9

Both age in 1 and name in 2 need type inference, but only 1 performs prior type inference. This is because 2 has no influence. That is, since name inside the foo() function is a local variable, it's sufficient for verifier to perform type inference inside the foo() function.

Prior Type Inference Algorithm

When parser encounters an expression (property or function) that needs prior type inference, it puts the expression into a function called @expand of the object it belongs to. expander traverses all given root origin obj through visitor, checking if the @expand function exists. When it exists, it creates context to use during expansion and adds it to _stack.

After all visitation ends, it performs prior type inference through the following process:

  1. If _stack is empty, terminate type inference
  2. For all _stack elements, prepare frame and verify the expression with verifier
  3. If verification succeeds, complete type inference through eval()
  4. If it fails, move to the next element
  5. When type inference is attempted once for all elements, if even 1 succeeded, return to step 1

Type Convergence

For optimization purposes, during visitation for prior type inference, it performs the operation of replacing getExpr with origin objects, which is called type convergence. During convergence, sometimes replacement to origin is immediately possible, but sometimes replacement is only possible after prior type inference is completed. If getExpr is not replaced with origin during visitation, it's stored in _cons and replacement is attempted once after type inference is completed. Even in this case, if it fails, it's just ignored and no error occurs.

Member Function Documentation

◆ _onWork()

void by::expander::_onWork ( )
overrideprotectedvirtual

The documentation for this class was generated from the following file:
to Top