This PR compartmentalizes our code into tidier classes and removes the "hacky" RecordDecl::reorderFields() method that our code was the only client of.
Clang seems to make extensive use of friend classes, so, that's what I've done here.
The way it works is RecordFieldReorganizer is a base class that provides an interface for safely reordering a RecordDecl's fields. Sub-classes are required to override the protected reorganize method. This is what our new Randstruct class is doing.
Callers will then call reorganizeFields() which drives the safe reordering of a RecordDecl's fields. I say "safe" because this method will ensure that no fields are added or dropped as a result of the reordering, meaning that future subclasses cannot sabotage the Record (why would they though?)
This PR compartmentalizes our code into tidier classes and removes the "hacky"
RecordDecl::reorderFields()
method that our code was the only client of.Clang seems to make extensive use of friend classes, so, that's what I've done here.
The way it works is
RecordFieldReorganizer
is a base class that provides an interface for safely reordering aRecordDecl
's fields. Sub-classes are required to override the protectedreorganize
method. This is what our newRandstruct
class is doing.Callers will then call
reorganizeFields()
which drives the safe reordering of aRecordDecl
's fields. I say "safe" because this method will ensure that no fields are added or dropped as a result of the reordering, meaning that future subclasses cannot sabotage the Record (why would they though?)