|
FLANG
|
#include <flang/Lower/StatementContext.h>
Public Types | |
| using | CleanupFunction = std::function<void()> |
Public Member Functions | |
| StatementContext (bool cleanupProhibited=false) | |
| void | pushScope () |
| Push a context subscope. | |
| void | attachCleanup (CleanupFunction cuf) |
| Append a cleanup function to the "list" of cleanup functions. | |
| void | finalizeAndKeep () |
| Make cleanup calls. Retain the stack top list for a repeat call. | |
| void | finalizeAndReset () |
| Make cleanup calls. Clear the stack top list. | |
| void | pop () |
| Pop the stack top list. | |
| void | finalizeAndPop () |
| Make cleanup calls. Pop the stack top list. | |
| bool | hasCode () const |
| bool | hasCodeInCurrentScope () const |
| Does the stack top list, which finalizeAndPop() would run, have cleanups? | |
When lowering a statement, temporaries for intermediate results may be allocated on the heap. A StatementContext enables their deallocation with one of several explicit finalize calls, or with an implicit call to finalizeAndPop() at the end of the context. A context may prohibit temporary allocation. Otherwise, an initial "outer" context scope may have nested context scopes, which must make explicit subscope finalize calls.
In addition to being useful for individual action statement contexts, a StatementContext is also useful for construct blocks delimited by a pair of statements such as (block-stmt, end-block-stmt), or a program unit delimited by a pair of statements such as (subroutine-stmt, end-subroutine- stmt). Attached cleanup code for these contexts may include stack management code, deallocation code, and finalization of derived type entities in the context.