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.

@FunctionalInterface public interface BytecodeParser<T extends BytecodeBuilder>
Functional interface containing a method to parse one or more nodes using a BytecodeBuilder.

Implementations are commonly written as tree traversals. For example:

BytecodeRootNodes nodes = MyBytecodeRootNodeGen.create(BytecodeConfig.DEFAULT, b -> {
    MyTree myTree = ...; // parse source code to AST
    b.beginRoot(...);
    myTree.accept(new MyTreeVisitor(b));
    b.endRoot();
})
In the above example, the visitor can use the builder 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

    Modifier and Type
    Method
    Description
    void
    parse(T builder)
    The parse method.
  • Method Details

    • parse

      void parse(T builder)
      The parse method. Should be idempotent and free of side-effects.
      Since:
      24.2