Jun 23, 2017, 3:26:01 PM (7 years ago)
Andrew Beach <ajbeach@…>
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
376ccadc, 4c03e63

Refinement of the tagged-struct proposal.

1 edited


  • doc/proposals/tagged-struct.txt

    r653f2c7 r88177cf  
    1414say which of the possible values is currently stored in the union. The idea
    1515here is similar, however the possibilities are more open ended.
     17Alternate names include virtual structure and abstract structure.
    3638their parent's fields to their field list so they can be upcast.
     40The type field may be public, if it is then it can be accessed through a
     41simple field access "instance.type". The type field would then be able to be
     42used to access the type object, which contains the information for the type.
     43It may just be a pointer to the type object "*instance.type", although a
     44lookup function could also be used.
     49The central feature for tagged structs is a checked cast between pointer types
     50to the structures. A cast is successful if the true type of the pointed object
     51is of the type being cast to or any of its children, otherwise the cast
     52returns null.
     54The type field should also allow for equality comparison of types.
     56Currently, with only these operations (and similar features) the type field
     57could be hidden and the operations given through helper functions. However
     58if the type object has more complex (or even open ended) information in it
     59than providing direct access becomes very valuable.
    41 Adding to the field list is a simple matter, should be doable during
    42 translation. The type field is just a pointer to a type object. With proper
    43 linking we can create a single unique instance of the type object for each
    44 declared tagged struct. The instance's address is used as an id for the type.
    45 It also holds data about the type, such as its parent's id/a pointer to the
    46 parent type object.
     64Adding to the field list would have to be handled during translation. The
     65simple act of adding declarations should not be difficult, althought it might
     66take a bit of work to find the parent's declarations.
    48 The type field could be hidden (as best as C can hide it) or it could be
    49 visible to the user with easy access to allow the user to examine the type
    50 object directly.
    52 Direct access is more useful if the data on the type-objects can change, other
    53 wise the build in function could handle all cases. Perhaps each root object
    54 can specify a type object to use or the type objects are themselves tagged,
    55 although there may not be a base case with the latter.
    57 In the simplest case the type object is a pointer to the parent type object.
    58 Additional data could be added, such as a name, or a function pointer to the
    59 destructor.
     68Type objects are also simple in to generate, they should just be global
     69(program lifetime) structures. Getting there to be exactly one instance of
     70each allows the pointer to the structure to be used as the type id, and that
     71should be possible to do during linking.
    94106If unions are declared tagged instead of creating a new tagged type, all
    95107possible values of the union must be of that tagged type or a child type.
     110Custom Type Objects (Extention):
     112Some method to define type objects used within a tree of types. One option is
     113to allow the tree's type object to be specified by the tree root. It would
     114then have to be filled in for each type in the tree, including the root.
     116The only required field is the parent field, a pointer to the type object's
     117type. (This is also the only required field on the tagged structure itself.)
     119A further extention could allow expanding type objects, so child types could
     120append fields to their parent's feild list. They might need their own type
     121objects at that point, or maybe static checks will be enough to see the
     122minimum field list.
Note: See TracChangeset for help on using the changeset viewer.