|
tvm
|
A scope stack for maintaining hierarchical state during IR visiting. More...
#include <scope_stack.h>
Public Member Functions | |
| ScopeStack () | |
| Construct with one initial scope level. More... | |
| size_t | size () const |
| Return the number of active scopes. More... | |
| bool | empty () const |
| Return true if no scopes are active. More... | |
| T & | Current () |
| Access the current (innermost) scope element. More... | |
| const T & | Current () const |
| Const access to the current (innermost) scope element. More... | |
| template<typename F > | |
| auto | WithNewScope (F &&body) -> decltype(body()) |
| Execute body within a new scope. More... | |
A scope stack for maintaining hierarchical state during IR visiting.
During IR tree traversal, visitors often need to track scope-local state (e.g., active constraints, variable bindings) that should be automatically cleaned up when leaving a scope. ScopeStack provides this via WithNewScope, which pushes a new element on entry and pops it on exit.
| T | The element type stored on the stack. Must be default-constructible. |
|
inline |
Construct with one initial scope level.
|
inline |
Access the current (innermost) scope element.
The returned reference is stable across push_back/pop_back because std::deque guarantees pointer stability for these operations.
|
inline |
Const access to the current (innermost) scope element.
|
inline |
Return true if no scopes are active.
|
inline |
Return the number of active scopes.
|
inline |
Execute body within a new scope.
Pushes a new T onto the stack, executes the body, then pops it.
| body | A callable to execute within the scope. |