   _buildMemberField: (parent, name, def) ->
     type = def.type?.kind || def.type
     if type == 'struct'
-      res = new StructMemberField(parent, name, def.type.open)
-      @_appendFields(res, res.fields(), def.type.members)
+      res = new StructMemberField(parent, name, def)
+      @_appendFields(res, res.fields(), def.type.members, def)
       res
     else
-      new ValueMemberField(parent, name, type)
+      new ValueMemberField(parent, name, type, def)
   _appendFields: (parent, target, members) ->
     for name, def of members
       target.push @_buildMemberField(parent, name, def)



class MemberField
  constructor: (@_parent, @_name, @_type) ->
  name: ->
    @_name
  type: ->
    @_type
  isStruct: ->

    (if @_parent then @_parent.path() else []).concat(@_name)

class ValueMemberField extends MemberField
  constructor: (parent, name, type, def) ->
    super(parent, name, type, def)
  visit: (callback) ->
    callback(@)

class StructMemberField extends MemberField
  constructor: (parent, name, def) ->
    super(parent, name, 'struct', def)
    @_fields = [] # Array of MemberField
  fields: ->
    @_fields
  isOpen: ->
    @_def.type.open
  visit: (callback) ->
    res = {}
    for field in @fields()
