P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::Visitor::Tracker Class Reference

Assists visitors in traversing the IR. More...

Public Member Functions

bool busy (const IR::Node *n) const
 
bool done (const IR::Node *n) const
 
void finish (const IR::Node *n)
 
void revisit_visited ()
 
bool shouldVisitOnce (const IR::Node *n) const
 
VisitStatus try_start (const IR::Node *n, bool defaultVisitOnce)
 
void visitAgain (const IR::Node *n)
 
void visitOnce (const IR::Node *n)
 

Detailed Description

Assists visitors in traversing the IR.

A Tracker object assists visitors traversing the IR by tracking each node. The start method begins tracking, and finish ends it. The done method determines whether the node has been visited.

Member Function Documentation

◆ busy()

bool P4::Visitor::Tracker::busy ( const IR::Node * n) const
inlinenodiscard

Determine whether
is currently being visited and the visitor has not finished That is, start(@n) has been invoked, and finish(@n) has not,

Returns
true if
is being visited and has not finished

◆ done()

bool P4::Visitor::Tracker::done ( const IR::Node * n) const
inlinenodiscard

Determine whether
has been visited and the visitor has finished and we don't want to visit
again the next time we see it. That is, start(@n) has been invoked, followed by finish(@n), and the visitOnce field is true.

Returns
true if
has been visited and the visitor is finished and visitOnce is true

◆ finish()

void P4::Visitor::Tracker::finish ( const IR::Node * n)
inline

Mark the process of visiting
as finished, with @final being the final state of the node, or nullptr if the node was removed from the tree. done(@n) will return true, and result(@n) will return the resulting node, if any.

If @final is a new node, that node is marked as finished as well, as if start(@final); finish(@final); were invoked.

Exceptions
Util::CompilerBugThis method fails if `start(
)` has not previously been invoked.

◆ revisit_visited()

void P4::Visitor::Tracker::revisit_visited ( )
inline

Forget nodes that have already been visited, allowing them to be visited again.

◆ shouldVisitOnce()

bool P4::Visitor::Tracker::shouldVisitOnce ( const IR::Node * n) const
inline

Return a visitOnce flag for node

◆ try_start()

VisitStatus P4::Visitor::Tracker::try_start ( const IR::Node * n,
bool defaultVisitOnce )
inlinenodiscard

Begin tracking
during a visiting pass. Use finish(@n) to mark
as visited once the pass completes.

Returns
Status of the node
wrt visit: whether node is currently being visited (VisitStatus::Busy), or if node was already visited (VisitStatus::Done), node was never seen before (VisitStatus::New) or seen, but should be revisited (VisitStatus::Revisit).