Changeset 1a42132


Ignore:
Timestamp:
Jun 16, 2017, 1:44:08 PM (7 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
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
Children:
f522618
Parents:
f13ee31
Message:

Added Aaron's comments to the tagged-struct proposal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/tagged-struct.txt

    rf13ee31 r1a42132  
    1111function call.
    1212
    13 Tags cannot be used on unions. This is because the different sides interact
    14 with the casts rather badly. There is a similarity with tagged unions still.
    15 Tagged structures also carry data to identify which out of several
    16 possibilies the object actually is. Although the possibilies are dynamic in
    17 this case.
     13The name tagged structure comes from tagged union, which carries a value to
     14say which of the possible values is currently stored in the union. The idea
     15here is similar, however the possibilities are more open ended.
    1816
    1917
     
    4846parent type object.
    4947
    50 If the type field is given a simple name, then the user can easily access the
    51 type object. This might be useful depending on what sort of data is in the
    52 type object, especially if the data can be added to by the user in some way.
    53 Ironically one way to accomplish that is to make the type objects tagged
    54 themselves, but that recursion might not have a base case.
     48The type field could be hidden (as best as C can hide it) or it could be
     49visible to the user with easy access to allow the user to examine the type
     50object directly.
    5551
    56 If the name is mangled and direct access to type objects is still wanted, then
    57 a function could be used to access the type object. Say get_type or get_tag
    58 instead of type or tag.
     52Direct access is more useful if the data on the type-objects can change, other
     53wise the build in function could handle all cases. Perhaps each root object
     54can specify a type object to use or the type objects are themselves tagged,
     55although there may not be a base case with the latter.
    5956
    60 If the data on the type object is set, than providing direct access may be
    61 unnessary. Instead the libraries or base code might be able to implement
    62 everything the data is for.
     57In the simplest case the type object is a pointer to the parent type object.
     58Additional data could be added, such as a name, or a function pointer to the
     59destructor.
    6360
    6461
     
    8481
    8582bug#11 might require `bool dynamic_cast(T ** dst, U * src)` instead.
     83
     84
     85Tagging Unions (Extention):
     86
     87Using this system as is does not really work if used on unions directly.
     88No new options to the union can be added, as they must be able to upcast.
     89Similarly, if options are removed, writing to an upcast union is invalid.
     90To allow for growth each option would have to be a structure itself.
     91
     92Which brings us to "tagget struct union", ie. a union of tagged structures
     93as opposed to tagging the union itself. This extention acts as a constraint.
     94If unions are declared tagged instead of creating a new tagged type, all
     95possible values of the union must be of that tagged type or a child type.
Note: See TracChangeset for help on using the changeset viewer.