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:
MyTree myTree = ...; BytecodeRootNodesIn the above example, the visitor uses the buildernodes = MyBytecodeRootNodeGen.create(BytecodeConfig.DEFAULT, b -> { 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, it can also prevent garbage collection of any input data stored on it (e.g. source code or ASTs). It may be preferable to construct the input data on the fly (e.g., by reading it from disk) instead of storing it on the parser.
- Since:
- 24.2
-
Method Summary
-
Method Details
-
parse
The parse method. Should be idempotent and free of side-effects.- Since:
- 24.2
-