1948380eb2
This change overhauls the approach to custom decoding. Instead of decoding the parts of the struct that are "trivial" in one pass, and then patching up the structure afterwards with custom decoding, the decoder itself understands the notion of custom decoder functions. First, the general purpose logic has moved out of pkg/pack/encoding and into a new package, pkg/util/mapper. Most functions are now members of a new top- level type, Mapper, which may be initialized with custom decoders. This is a map from target type to a function that can decode objects into it. Second, the AST-specific decoding logic is rewritten to use it. All AST nodes are now supported, including definitions, statements, and expressions. The overall approach here is to simply define a custom decoder for any interface type that will occur in a node field position. The mapper, upon encountering such a type, will consult the custom decoder map; if a decoder is found, it will be used, otherwise an error results. This decoder then needs to switch on the type discriminated kind field that is present in the metadata, creating a concrete struct of the right type, and then converting it to the desired interface type. Note that, subtly, interface types used only for "marker" purposes don't require any custom decoding, because they do not appear in field positions and therefore won't be encountered during the decoding process. |
||
---|---|---|
.. | ||
errors.go | ||
mapper.go | ||
mapper_test.go | ||
object.go |