Ignore:
Timestamp:
Jun 29, 2017, 5:09:37 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
1abc5ab
Parents:
2a7b3ca (diff), fe5c01d (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.
Message:

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

File:
1 edited

Legend:

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

    r2a7b3ca r949934e  
    1414say which of the possible values is currently stored in the union. The idea
    1515here is similar, however the possibilities are more open ended.
     16
     17Alternate names include virtual structure and abstract structure.
    1618
    1719
     
    3638their parent's fields to their field list so they can be upcast.
    3739
     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.
     45
     46
     47Usage:
     48
     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.
     53
     54The type field should also allow for equality comparison of types.
     55
     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.
     60
    3861
    3962Implemenation:
    4063
    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.
    4767
    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.
    51 
    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.
    56 
    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.
    6072
    6173
     
    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.
     108
     109
     110Custom Type Objects (Extention):
     111
     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.
     115
     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.)
     118
     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.