rttidecl.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2018 by Sven Barth
  4. member of the Free Pascal development team
  5. Contains various RTTI related, private declarations that are used inside
  6. the system unit before rtti.inc might be included.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  14. {$define USE_PACKED}
  15. {$endif}
  16. { 3.1.1 and newer also (re)stores $MinEnumSize and $PackSet upon $Push/$Pop }
  17. {$push}
  18. {$MINENUMSIZE 1 this saves a lot of memory }
  19. {$ifdef FPC_RTTI_PACKSET1}
  20. { for Delphi compatibility }
  21. {$packset 1}
  22. {$endif}
  23. type
  24. PTypeKind = ^TTypeKind;
  25. const
  26. // all potentially managed types
  27. tkManagedTypes = [tkAstring,tkWstring,tkUstring,tkArray,
  28. tkObject,tkRecord,tkDynArray,tkInterface,tkVariant];
  29. type
  30. PRecordElement=^TRecordElement;
  31. TRecordElement=
  32. {$ifdef USE_PACKED}
  33. packed
  34. {$endif USE_PACKED}
  35. record
  36. TypeInfo: PPointer;
  37. Offset: SizeInt;
  38. end;
  39. PRecordInfoFull=^TRecordInfoFull;
  40. TRecordInfoFull=
  41. {$ifdef USE_PACKED}
  42. packed
  43. {$endif USE_PACKED}
  44. record
  45. {$if declared(TRttiDataCommon)}
  46. Common: TRttiDataCommon;
  47. {$endif declared TRttiDataCommon}
  48. case TTypeKind of
  49. tkRecord: (
  50. InitTable: Pointer;
  51. Size: Longint;
  52. Count: Longint;
  53. { Elements: array[count] of TRecordElement }
  54. );
  55. { include for proper alignment }
  56. tkInt64: (
  57. dummy : Int64
  58. );
  59. end;
  60. PRecordInfoInit=^TRecordInfoInit;
  61. TRTTIRecVarOp=procedure(ARec: Pointer);
  62. TRTTIRecCopyOp=procedure(ASrc, ADest: Pointer);
  63. TRTTIRecOpType=(rotInitialize, rotFinalize, rotAddRef, rotCopy);
  64. TRTTIManagement=(manNone, manBuiltin, manCustom);
  65. PRTTIRecordOpVMT=^TRTTIRecordOpVMT;
  66. TRTTIRecordOpVMT=
  67. {$ifdef USE_PACKED}
  68. packed
  69. {$endif USE_PACKED}
  70. record
  71. case cardinal of
  72. 0:
  73. (
  74. Initialize: TRTTIRecVarOp;
  75. Finalize: TRTTIRecVarOp;
  76. AddRef: TRTTIRecVarOp;
  77. Copy: TRTTIRecCopyOp;
  78. );
  79. 1: (Ops: array[TRTTIRecOpType] of CodePointer);
  80. end;
  81. TRTTIRecordOpOffsetEntry =
  82. {$ifdef USE_PACKED}
  83. packed
  84. {$endif USE_PACKED}
  85. record
  86. ManagmentOperator: CodePointer;
  87. FieldOffset: SizeUInt;
  88. end;
  89. TRTTIRecordOpOffsetTable =
  90. {$ifdef USE_PACKED}
  91. packed
  92. {$endif USE_PACKED}
  93. record
  94. Count: LongWord;
  95. Entries: array[0..0] of TRTTIRecordOpOffsetEntry;
  96. end;
  97. PRTTIRecordOpOffsetTable = ^TRTTIRecordOpOffsetTable;
  98. TRecordInfoInit=
  99. {$ifdef USE_PACKED}
  100. packed
  101. {$endif USE_PACKED}
  102. record
  103. {$if declared(TRttiDataCommon)}
  104. Common: TRttiDataCommon;
  105. {$endif declared TRttiDataCommon}
  106. case TTypeKind of
  107. tkRecord: (
  108. Terminator: Pointer;
  109. Size: Longint;
  110. InitRecordOpTable: PRTTIRecordOpOffsetTable;
  111. RecordOp: PRTTIRecordOpVMT;
  112. Count: Longint;
  113. { Elements: array[count] of TRecordElement }
  114. );
  115. { include for proper alignment }
  116. tkInt64: (
  117. dummy : Int64
  118. );
  119. end;
  120. PArrayInfo=^TArrayInfo;
  121. TArrayInfo=
  122. {$ifdef USE_PACKED}
  123. packed
  124. {$endif USE_PACKED}
  125. record
  126. {$if declared(TRttiDataCommon)}
  127. Common: TRttiDataCommon;
  128. {$endif declared TRttiDataCommon}
  129. case TTypeKind of
  130. tkArray: (
  131. Size: SizeInt;
  132. ElCount: SizeInt;
  133. ElInfo: PPointer;
  134. DimCount: Byte;
  135. Dims:array[0..255] of Pointer;
  136. );
  137. { include for proper alignment }
  138. tkInt64: (
  139. dummy : Int64
  140. );
  141. end;
  142. function RTTIManagementAndSize(typeInfo: Pointer; op: TRTTIRecOpType; out size: SizeInt; maxInteresting: TRTTIManagement): TRTTIManagement; forward;
  143. function RTTIRecordMopInitTable(ti: Pointer): PRTTIRecordOpOffsetTable; forward;
  144. {$pop}