Skip to content

Commit

Permalink
Add several improvements to DerivedClass_F
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-eschwartz committed Mar 20, 2024
1 parent eeb1b52 commit a76b6ff
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions share/prolog/oorules/rules.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1938,15 +1938,26 @@
DerivedClass, BaseClass, Offset)]).

% An easier to understand version of E that builds on concluded VBTable facts instead of RTTI.
reasonDerivedClass_F(DerivedClass, BaseClass, Offset) :-
reasonDerivedClass_F(DerivedClass, BaseClass, Offset) :-
factObjectInObject(DerivedClass, BaseClass, Offset),
% There's an entry in some VBTable somehere (only unified by Offset so far).
factVBTableEntry(VBTableAddress, _TableObjectOffset, Offset),
factVBTableEntry(VBTableAddress, TableOffset, OffsetFromVBPtr),
% The first offset of a VBTable is the offset from the vbptr to the object start.
TableOffset > 0,
% And that VBTable is installed into an object in some Method.
factVBTableWrite(_Insn, Method, _VBTableOffset, VBTableAddress),
factVBTableWrite(_Insn, Method, VBPtrOffset, VBTableAddress),
% Ensure that BaseClass is not empty. If it is, there could be multiple
% classes at the same offset.
notEmptyClass(BaseClass),
% Finally, check that the method is assigned to the Derived class.
% This is the unification that makes the VBTableEntry relevant.
find(Method, DerivedClass),

% ejs 8/13/22 The offsets in a vbtable are offsets from the location of the vbptr, not from
% the beginning of the class. Sometimes the vbptr is at offset zero, but not always.
Offset is OffsetFromVBPtr + VBPtrOffset,

% Debugging
logtraceln('~@~Q.', [not(factDerivedClass(DerivedClass, BaseClass, Offset)),
reasonDerivedClass_F(DerivedClass, BaseClass, Offset,
Expand Down

0 comments on commit a76b6ff

Please sign in to comment.