rttidecl.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. PRTTIRecordOpVMT=^TRTTIRecordOpVMT;
  65. TRTTIRecordOpVMT=
  66. {$ifdef USE_PACKED}
  67. packed
  68. {$endif USE_PACKED}
  69. record
  70. case cardinal of
  71. 0:
  72. (
  73. Initialize: TRTTIRecVarOp;
  74. Finalize: TRTTIRecVarOp;
  75. AddRef: TRTTIRecVarOp;
  76. Copy: TRTTIRecCopyOp;
  77. );
  78. 1: (Ops: array[TRTTIRecOpType] of CodePointer);
  79. end;
  80. TRTTIRecordOpOffsetEntry =
  81. {$ifdef USE_PACKED}
  82. packed
  83. {$endif USE_PACKED}
  84. record
  85. ManagmentOperator: CodePointer;
  86. FieldOffset: SizeUInt;
  87. end;
  88. TRTTIRecordOpOffsetTable =
  89. {$ifdef USE_PACKED}
  90. packed
  91. {$endif USE_PACKED}
  92. record
  93. Count: LongWord;
  94. Entries: array[0..0] of TRTTIRecordOpOffsetEntry;
  95. end;
  96. PRTTIRecordOpOffsetTable = ^TRTTIRecordOpOffsetTable;
  97. TRecordInfoInit=
  98. {$ifdef USE_PACKED}
  99. packed
  100. {$endif USE_PACKED}
  101. record
  102. {$if declared(TRttiDataCommon)}
  103. Common: TRttiDataCommon;
  104. {$endif declared TRttiDataCommon}
  105. case TTypeKind of
  106. tkRecord: (
  107. Terminator: Pointer;
  108. Size: Longint;
  109. InitRecordOpTable: PRTTIRecordOpOffsetTable;
  110. RecordOp: PRTTIRecordOpVMT;
  111. Count: Longint;
  112. { Elements: array[count] of TRecordElement }
  113. );
  114. { include for proper alignment }
  115. tkInt64: (
  116. dummy : Int64
  117. );
  118. end;
  119. PArrayInfo=^TArrayInfo;
  120. TArrayInfo=
  121. {$ifdef USE_PACKED}
  122. packed
  123. {$endif USE_PACKED}
  124. record
  125. {$if declared(TRttiDataCommon)}
  126. Common: TRttiDataCommon;
  127. {$endif declared TRttiDataCommon}
  128. case TTypeKind of
  129. tkArray: (
  130. Size: SizeInt;
  131. ElCount: SizeInt;
  132. ElInfo: PPointer;
  133. DimCount: Byte;
  134. Dims:array[0..255] of Pointer;
  135. );
  136. { include for proper alignment }
  137. tkInt64: (
  138. dummy : Int64
  139. );
  140. end;
  141. function RTTIManagementAndSize(typeInfo: Pointer; op: TRTTIRecOpType; out size: SizeInt; onlyCustomOps: boolean): boolean; forward;
  142. function RTTIRecordMopInitTable(ti: Pointer): PRTTIRecordOpOffsetTable; forward;
  143. {$pop}