Changes in / [f6cc2096:70284830]
- File:
-
- 1 edited
-
doc/proposals/virtual.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/virtual.txt
rf6cc2096 r70284830 147 147 148 148 This gives us an important extra feature, runtime checking of the parent-child 149 relationship with virtual cast, where a pointer (and maybe a reference) to 150 a virtual type can be cast to another virtual cast. However the cast is 151 dynamicly check and only occurs if the underlying type is a child of the type 152 being cast to. Otherwise null is returned. 153 154 (virtual TYPE)EXPR 155 156 As an extention, the TYPE may be ommitted if it can be determained from 157 context, for instance if the cast occurs on the right hand side of an 158 assignment. 149 relationship with a C++ dynamic_cast like operation. Allowing checked 150 conversions from trait references to more particular references, which works 151 if the underlying type is, or is a child of, the new trait type. 159 152 160 153 Extension: Multiple Parents … … 258 251 autogenerated and often unique. 259 252 260 It may be worth looking into a way to force the vtable pointer to be in a261 particular location, which would save the storage to store the offset and262 maybe the offset operation itself (offset = 0). However it may not be worth263 introducing a new language feature for.264 As of writing, exceptions actually use this system.265 266 253 267 254 Keyword Usage: … … 289 276 Calling free on a trait reference will free the memory for the object. It will 290 277 leave the vtables alone, as those are (always?) statically allocated. 291 292 293 Special Traits:294 295 trait is_virtual_parent(dtype parent, dtype child) { ... };296 297 There are others but I believe this one to be the most important. The trait298 holds if the parent type is a strict virtual ancestor (any number of levels)299 of child. It will have to exist at least internally to check for upcasts and300 it can also be used to optimize virtual casts into upcasts. Or a null value or301 error if the cast would never succeed. Exporting it to a special trait allows302 users to express that requirement in their own polymorphic code.303 304 305 Implementation:306 307 Before we can generate any of the nessasary code, the compiler has to get some308 additional information about the code that it currently does not collect.309 310 First it should establish all child->parent links so that it may travel up the311 hierarchy to grab the nessasary information, and create the actual parent312 pointers in the strict virtual tables. It should also maintain the connections313 between the virtual type (structure or trait), the vtable type and the vtable314 instance (or default instance for relaxed virtual if multiple are allowed). To315 this end a sub-node should be created with the nessasary pointers. Traits and316 structs with virtual can create an instance and store all the nessasary data.317 318 With the hierarchy in place it can generate the vtable type for each type,319 it will generally have a function pointer field for each type assertion in320 some consistant order. Strict virtual will also have a pointer to the parent's321 vtable and intrusive vtables will also have the offset to recover the original322 pointer. Sized types will also carry the size.323 324 Wheither the vtable is intrusive or not should also be save so that the trait325 object/reference/pointer knows if it has to store 1 or 2 pointers. A wrapper326 function will have to be generated for each type assertion so that they may327 be called on the trait type, these can probably be inlined.328 329 The virtual parameter will also have to be marked (implicately or explicately)330 until code generation so that the wrapper functions know where to go to get331 the vtable for the function look up. That could probably be added as a332 storageclass, although one that is only valid on type assertions.333 334 The generated vtable will than have to have a vtable instance created and335 filled with all the approprate values. Stricter matching may have to be used336 to ensure that the functions used are stable. It will also have to use337 ".gnu.linkonce" or equilant to ensure only one copy exists in the final code338 base.
Note:
See TracChangeset
for help on using the changeset viewer.