Interface BytecodeParser<T extends BytecodeBuilder>
- Type Parameters:
T
- the builder class of the bytecode root node
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
BytecodeBuilder
.
Implementations are commonly written as tree traversals. For example:
BytecodeRootNodesIn the above example, the visitor can use the buildernodes = MyBytecodeRootNodeGen.create(BytecodeConfig.DEFAULT, b -> { MyTree myTree = ...; // parse source code to AST b.beginRoot(...); myTree.accept(new MyTreeVisitor(b)); b.endRoot(); })
b
to emit bytecode.
The parser should be idempotent (i.e., it can be repeatedly invoked and produces the same result). This is because a parser can be invoked multiple times to reparse nodes (e.g., to add source information).
Additionally, if serialization is used, the parser should be free of most side effects. The only side effects permitted are field writes on the generated root nodes (since fields are serialized); all other side effects (e.g., non-builder method calls) will not be captured during serialization.
Since the parser is kept alive for reparsing, any references it captures will be kept alive in the heap. To reduce memory footprint, it is recommended (where possible) to construct input data (e.g., a parse tree) inside the parser instead of capturing a reference to it.
- Since:
- 24.2
-
Method Summary
-
Method Details
-
parse
-