Jun 16, 2017, 3:25:58 PM (5 years ago)
Thierry Delisle <tdelisle@…>
aaron-thesis, arm-eh, 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, resolv-new, with_gc
0e44184, 1bc9dcb, 20877d2
cc3e4d0 (diff), f522618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

1 edited


  • doc/proposals/tagged-struct.txt

    rcc3e4d0 rd33bc7c  
    33Tagged structures allow for dynamic casting between types in a hierarchy.
    44Children (rather pointers to) can be up-cast to their parents, a safe
    5 conversion that may recive language level support or even be implicate.
     5conversion that may recive language level support or even be implicit.
    66Parents can be down cast to their children, which might fail if the underlying
    77object is not of the child type, or a child of that.
    1111function call.
    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.
    2422The keywords can change (although they currently reflect the concept name
    25 closely). More formally, in terms of grammer this adds:
     23closely). More formally, in terms of grammar this adds:
    4846parent type object.
    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.
    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.
    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
    8582bug#11 might require `bool dynamic_cast(T ** dst, U * src)` instead.
     85Tagging Unions (Extention):
     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.
     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.