Changeset 1a42132
- Timestamp:
- Jun 16, 2017, 1:44:08 PM (7 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/tagged-struct.txt
rf13ee31 r1a42132 11 11 function call. 12 12 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. 13 The name tagged structure comes from tagged union, which carries a value to 14 say which of the possible values is currently stored in the union. The idea 15 here is similar, however the possibilities are more open ended. 18 16 19 17 … … 48 46 parent type object. 49 47 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. 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. 55 51 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. 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. 59 56 60 I f the data on the type object is set, than providing direct access may be61 unnessary. Instead the libraries or base code might be able to implement 62 everything the data is for.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. 63 60 64 61 … … 84 81 85 82 bug#11 might require `bool dynamic_cast(T ** dst, U * src)` instead. 83 84 85 Tagging Unions (Extention): 86 87 Using this system as is does not really work if used on unions directly. 88 No new options to the union can be added, as they must be able to upcast. 89 Similarly, if options are removed, writing to an upcast union is invalid. 90 To allow for growth each option would have to be a structure itself. 91 92 Which brings us to "tagget struct union", ie. a union of tagged structures 93 as opposed to tagging the union itself. This extention acts as a constraint. 94 If unions are declared tagged instead of creating a new tagged type, all 95 possible values of the union must be of that tagged type or a child type.
Note: See TracChangeset
for help on using the changeset viewer.