Commit graph

14 commits

Author SHA1 Message Date
joeduffy 9939024ccd Begin decoding statements 2017-01-16 07:47:41 -08:00
joeduffy 3ef55ac6b3 Add AST type assertions and kind constants 2017-01-16 07:47:12 -08:00
joeduffy 99f60bf5c8 Clean up some decoding logic
This change splits up the decoding logic into multiple files, to
mirror the AST package structure that the functions correspond to.

Additionally, there is now less "loose" reflection and dynamic lookup
code scattered throughout; it is now consolidated into the decoder,
with a set of "generic" functions like `fieldObject`, `asString`, etc.
2017-01-16 06:46:56 -08:00
joeduffy fee6d94e1f Implement class member decoding
This change implements custom class member decoding.  As with module methods,
the function body AST nodes remain nil, as custom AST decoding isn't yet done.
2017-01-16 06:10:24 -08:00
joeduffy 14c040bc7f Implement custom decoding of ModuleMembers
This change begins to implement some of the AST custom decoding, beneath
the Package's Module map.  In particular, we now unmarshal "one level"
beyond this, populating each Module's ModuleMember map.  This includes
Classes, Exports, ModuleProperties, and ModuleMethods.  The Class AST's
Members have been marked "custom", in addition to Block's Statements,
because they required kind-directed decoding.  But Exports and
ModuleProperties can be decoded entirely using the tag-directed decoding
scheme.  Up next, custom decoding of ClassMembers.  At that point, all
definition-level decoding will be done, leaving MuIL's ASTs.
2017-01-15 14:57:42 -08:00
joeduffy f0b9f157de Add tests for decoding more complex nested structures
This adds deeper nesting into our tests, plus a few more examples of
pointer-based data structures inside of those deeply nested structures.
2017-01-15 13:50:00 -08:00
joeduffy 1ad99bcea1 Fix a few AST marshaling things
This fixes a few things so that MuPackages now unmarshal:

* Mark Module.Members as requiring "custom" decoding.  This is required
  because that's the first point in the tree that leverages polymorphism.
  Everything "above" this unmarshals just fine (e.g., package+modules).

* As such, stop marking Package.Modules as "custom".

* Add the Kind field to the Node.  Although we won't use this for type
  discrimination in the same way, since Go gives us RTTI on the structs,
  it is required for unmarshaling (to avoid "unrecognized fields" errors)
  and it's probably handy to have around for logging, messages, etc.

* Mark Position.Line and Column with "json" annotations so that they
  unmarshal correctly.
2017-01-14 11:22:54 -08:00
joeduffy bd32867e81 Adjust pointers
This change adjusts pointers correctly when unmarshaling into target
pointer types.  This handles arrays and maps of pointer elements, in
addition to consolidating existing logic for marshaling into a
destination top-level pointer as well.
2017-01-14 11:21:27 -08:00
joeduffy d1188ed8c8 Add recursive struct unmarshaling 2017-01-14 10:06:55 -08:00
joeduffy c0c75d0f08 Split decoder logic out from MuPack-specific decode functions 2017-01-14 09:50:25 -08:00
joeduffy ab2d0ae6cb Implement tag-directed decoding
This change eliminates boilerplate decoding logic in all the different
data structures, and instead uses a new tag-directed decoding scheme.
This works a lot like the JSON deserializers, in that it recognizes the
`json:"name"` tags, except that we permit annotation of fields that
require custom deserialization, as `json:"name,custom"`.  The existing
`json:"name,omitempty"` tag is recognized for optional fields.
2017-01-14 09:42:05 -08:00
joeduffy 120f139812 Decode dependencies metadata 2017-01-14 07:58:21 -08:00
joeduffy d334ea322b Add custom decoding for MuPack metadata
This adds basic custom decoding for the MuPack metadata section of
the incoming JSON/YAML.  Because of the type discriminated union nature
of the incoming payload, we cannot rely on the simple built-in JSON/YAML
unmarshaling behavior.  Note that for the metadata section -- what is
in this checkin -- we could have, but the IL AST nodes are problematic.
(To know what kind of structure to creat requires inspecting the "kind"
field of the IL.)  We will use a reflection-driven walk of the target
structure plus a weakly typed deserialized map[string]interface{}, as
is fairly customary in Go for scenarios like this (though good libaries
seem to be lacking in this area...).
2017-01-14 07:40:13 -08:00
joeduffy e7dbfa59c3 Create MuPack and MuIL packages in our Go toolset
This change carries over all of the metadata shapes in the MuPack
and MuIL file formats to our Go toolset.  This includes creating a
proper discriminated AST type tree along with correct annotations
so that the metadata will serialize and deserialize correctly.
2017-01-13 14:32:10 -08:00