rtti.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt
  4. member of the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { Run-Time type information routines }
  12. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  13. {$define USE_PACKED}
  14. {$endif}
  15. {$ifdef VER2_6}
  16. {$define USE_PACKED}
  17. {$endif}
  18. type
  19. PRecordElement=^TRecordElement;
  20. TRecordElement=
  21. {$ifdef USE_PACKED}
  22. packed
  23. {$endif USE_PACKED}
  24. record
  25. {$ifdef VER3_0}
  26. TypeInfo: Pointer;
  27. {$else}
  28. TypeInfo: PPointer;
  29. {$endif}
  30. {$ifdef VER2_6}
  31. Offset: Longint;
  32. {$else}
  33. Offset: SizeInt;
  34. {$endif}
  35. end;
  36. PRecordInfoFull=^TRecordInfoFull;
  37. TRecordInfoFull=
  38. {$ifdef USE_PACKED}
  39. packed
  40. {$endif USE_PACKED}
  41. record
  42. {$ifndef VER3_0}
  43. InitTable: Pointer;
  44. {$endif VER3_0}
  45. Size: Longint;
  46. Count: Longint;
  47. { Elements: array[count] of TRecordElement }
  48. end;
  49. PRecordInfoInit=^TRecordInfoInit;
  50. {$ifndef VER3_0}
  51. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  52. TRTTIRecVarOp=procedure(ARec: Pointer);
  53. TRTTIRecCopyOp=procedure(ASrc, ADest: Pointer);
  54. TRTTIRecOpType=(rotAny, rotInitialize, rotFinalize, rotAddRef, rotCopy);
  55. PRTTIRecordOpVMT=^TRTTIRecordOpVMT;
  56. TRTTIRecordOpVMT=
  57. {$ifdef USE_PACKED}
  58. packed
  59. {$endif USE_PACKED}
  60. record
  61. Initialize: TRTTIRecVarOp;
  62. Finalize: TRTTIRecVarOp;
  63. AddRef: TRTTIRecVarOp;
  64. Copy: TRTTIRecCopyOp;
  65. end;
  66. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  67. TRecordInfoInit=
  68. {$ifdef USE_PACKED}
  69. packed
  70. {$endif USE_PACKED}
  71. record
  72. Terminator: Pointer;
  73. Size: Longint;
  74. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  75. RecordOp: PRTTIRecordOpVMT;
  76. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  77. Count: Longint;
  78. { Elements: array[count] of TRecordElement }
  79. end;
  80. {$else VER3_0}
  81. TRecordInfoInit=TRecordInfoFull;
  82. {$endif VER3_0}
  83. PArrayInfo=^TArrayInfo;
  84. TArrayInfo=
  85. {$ifdef USE_PACKED}
  86. packed
  87. {$endif USE_PACKED}
  88. record
  89. Size: SizeInt;
  90. ElCount: SizeInt;
  91. {$ifdef VER3_0}
  92. ElInfo: Pointer;
  93. {$else}
  94. ElInfo: PPointer;
  95. {$endif}
  96. DimCount: Byte;
  97. Dims:array[0..255] of Pointer;
  98. end;
  99. function RTTIArraySize(typeInfo: Pointer): SizeInt;
  100. begin
  101. {$ifdef VER3_0}
  102. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  103. {$else VER3_0}
  104. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  105. {$endif VER3_0}
  106. {$ifdef VER2_6}
  107. result:=PArrayInfo(typeInfo)^.Size*PArrayInfo(typeInfo)^.ElCount;
  108. {$else}
  109. result:=PArrayInfo(typeInfo)^.Size;
  110. {$endif}
  111. end;
  112. function RTTIRecordSize(typeInfo: Pointer): SizeInt;
  113. begin
  114. {$ifdef VER3_0}
  115. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  116. {$else VER3_0}
  117. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  118. {$endif VER3_0}
  119. { for size field init table is compatible with rtti table }
  120. result:=PRecordInfoFull(typeInfo)^.Size;
  121. end;
  122. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  123. function RTTIRecordOp(typeInfo: Pointer; var initrtti: Pointer): PRecordInfoInit; inline;
  124. begin
  125. { find init table and management operators }
  126. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  127. result:=typeInfo;
  128. { check terminator, maybe we are already in init table }
  129. if Assigned(result^.Terminator) then
  130. begin
  131. { point to more optimal initrtti }
  132. initrtti:=PRecordInfoFull(result)^.InitTable;
  133. { and point to management operators in our init table }
  134. result:=aligntoqword(initrtti+2+PByte(initrtti)[1]);
  135. end
  136. end;
  137. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  138. function RTTIRecordRttiInfoToInitInfo(typeInfo: Pointer): Pointer; inline;
  139. begin
  140. result:=typeInfo;
  141. {$ifndef VER3_0}
  142. { find init table }
  143. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  144. { check terminator, maybe we are already in init table }
  145. if Assigned(PRecordInfoInit(typeInfo)^.Terminator) then
  146. { point to more optimal initrtti }
  147. result:=PRecordInfoFull(typeInfo)^.InitTable;
  148. {$endif VER3_0}
  149. end;
  150. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  151. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  152. function RTTISizeAndOp(typeInfo: Pointer;
  153. const expectedManagementOp: TRTTIRecOpType; out hasManagementOp: boolean): SizeInt;
  154. begin
  155. hasManagementOp:=false;
  156. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  157. function RTTISize(typeInfo: Pointer): SizeInt;
  158. begin
  159. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  160. case PTypeKind(typeinfo)^ of
  161. tkAString,tkWString,tkUString,
  162. tkInterface,tkDynarray:
  163. result:=sizeof(Pointer);
  164. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  165. tkVariant:
  166. result:=sizeof(TVarData);
  167. {$endif FPC_HAS_FEATURE_VARIANTS}
  168. tkArray:
  169. result:=RTTIArraySize(typeinfo);
  170. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  171. tkObject:
  172. result:=RTTIRecordSize(typeinfo);
  173. tkRecord:
  174. with RTTIRecordOp(typeInfo,typeInfo)^ do
  175. begin
  176. result:=Size;
  177. hasManagementOp := Assigned(RecordOp);
  178. if hasManagementOp then
  179. case expectedManagementOp of
  180. rotInitialize: hasManagementOp:=Assigned(RecordOp^.Initialize);
  181. rotFinalize: hasManagementOp:=Assigned(RecordOp^.Finalize);
  182. rotAddRef: hasManagementOp:=Assigned(RecordOp^.AddRef);
  183. rotCopy: hasManagementOp:=Assigned(RecordOp^.Copy);
  184. end;
  185. end;
  186. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  187. tkObject,tkRecord:
  188. result:=RTTIRecordSize(typeinfo);
  189. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  190. else
  191. result:=-1;
  192. end;
  193. end;
  194. { if you modify this procedure, fpc_copy must be probably modified as well }
  195. procedure RecordRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc);
  196. var
  197. count,
  198. i : longint;
  199. begin
  200. {$ifdef VER3_0}
  201. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  202. {$else VER3_0}
  203. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  204. {$endif VER3_0}
  205. Count:=PRecordInfoInit(typeInfo)^.Count;
  206. Inc(PRecordInfoInit(typeInfo));
  207. { Process elements }
  208. for i:=1 to count Do
  209. begin
  210. rttiproc(Data+PRecordElement(typeInfo)^.Offset,PRecordElement(typeInfo)^.TypeInfo{$ifndef VER3_0}^{$endif});
  211. Inc(PRecordElement(typeInfo));
  212. end;
  213. end;
  214. { if you modify this procedure, fpc_copy must be probably modified as well }
  215. {$ifdef VER2_6}
  216. procedure ArrayRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc);
  217. var
  218. i: SizeInt;
  219. begin
  220. {$ifdef VER3_0}
  221. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  222. {$else VER3_0}
  223. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  224. {$endif VER3_0}
  225. { Process elements }
  226. for I:=0 to PArrayInfo(typeInfo)^.ElCount-1 do
  227. rttiproc(Data+(I*PArrayInfo(typeInfo)^.Size),PArrayInfo(typeInfo)^.ElInfo);
  228. end;
  229. {$else}
  230. procedure ArrayRTTI(Data,TypeInfo:Pointer;rttiproc:TRTTIProc);
  231. var
  232. i,Count,ElSize: SizeInt;
  233. Info: Pointer;
  234. begin
  235. {$ifdef VER3_0}
  236. typeInfo:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  237. {$else VER3_0}
  238. typeInfo:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  239. {$endif VER3_0}
  240. Count:=PArrayInfo(typeInfo)^.ElCount;
  241. { no elements to process => exit }
  242. if Count = 0 then
  243. Exit;
  244. ElSize:=PArrayInfo(typeInfo)^.Size div Count;
  245. Info:=PArrayInfo(typeInfo)^.ElInfo{$ifndef VER3_0}^{$endif};
  246. { Process elements }
  247. for I:=0 to Count-1 do
  248. rttiproc(Data+(I*ElSize),Info);
  249. end;
  250. {$endif}
  251. Procedure fpc_Initialize (Data,TypeInfo : pointer);[Public,Alias : 'FPC_INITIALIZE']; compilerproc;
  252. begin
  253. case PTypeKind(TypeInfo)^ of
  254. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  255. tkDynArray,
  256. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  257. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  258. tkAstring,
  259. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  260. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  261. tkWstring,tkUString,
  262. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  263. tkInterface:
  264. PPchar(Data)^:=Nil;
  265. tkArray:
  266. arrayrtti(data,typeinfo,@int_initialize);
  267. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  268. tkObject,
  269. {$endif FPC_HAS_FEATURE_OBJECTS}
  270. tkRecord:
  271. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  272. { if possible try to use more optimal initrtti }
  273. with RTTIRecordOp(typeinfo, typeinfo)^ do
  274. begin
  275. recordrtti(data,typeinfo,@int_initialize);
  276. if Assigned(recordop) and Assigned(recordop^.Initialize) then
  277. recordop^.Initialize(data);
  278. end;
  279. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  280. begin
  281. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  282. recordrtti(data,typeinfo,@int_initialize);
  283. end;
  284. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  285. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  286. tkVariant:
  287. variant_init(PVarData(Data)^);
  288. {$endif FPC_HAS_FEATURE_VARIANTS}
  289. end;
  290. end;
  291. Procedure fpc_finalize (Data,TypeInfo: Pointer);[Public,Alias : 'FPC_FINALIZE']; compilerproc;
  292. begin
  293. case PTypeKind(TypeInfo)^ of
  294. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  295. tkAstring :
  296. fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
  297. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  298. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  299. tkUstring :
  300. fpc_UnicodeStr_Decr_Ref(PPointer(Data)^);
  301. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  302. tkWstring :
  303. fpc_WideStr_Decr_Ref(PPointer(Data)^);
  304. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  305. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  306. tkArray :
  307. arrayrtti(data,typeinfo,@int_finalize);
  308. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  309. tkObject,
  310. {$endif FPC_HAS_FEATURE_OBJECTS}
  311. tkRecord:
  312. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  313. { if possible try to use more optimal initrtti }
  314. with RTTIRecordOp(typeinfo, typeinfo)^ do
  315. begin
  316. if Assigned(recordop) and Assigned(recordop^.Finalize) then
  317. recordop^.Finalize(data);
  318. recordrtti(data,typeinfo,@int_finalize);
  319. end;
  320. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  321. begin
  322. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  323. recordrtti(data,typeinfo,@int_finalize);
  324. end;
  325. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  326. tkInterface:
  327. Intf_Decr_Ref(PPointer(Data)^);
  328. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  329. tkDynArray:
  330. fpc_dynarray_clear(PPointer(Data)^,TypeInfo);
  331. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  332. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  333. tkVariant:
  334. variant_clear(PVarData(Data)^);
  335. {$endif FPC_HAS_FEATURE_VARIANTS}
  336. end;
  337. end;
  338. Procedure fpc_Addref (Data,TypeInfo : Pointer); [Public,alias : 'FPC_ADDREF']; compilerproc;
  339. begin
  340. case PTypeKind(TypeInfo)^ of
  341. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  342. tkAstring :
  343. fpc_AnsiStr_Incr_Ref(PPointer(Data)^);
  344. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  345. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  346. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  347. tkWstring :
  348. fpc_WideStr_Incr_Ref(PPointer(Data)^);
  349. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  350. tkUstring :
  351. fpc_UnicodeStr_Incr_Ref(PPointer(Data)^);
  352. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  353. tkArray :
  354. arrayrtti(data,typeinfo,@int_addref);
  355. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  356. tkobject,
  357. {$endif FPC_HAS_FEATURE_OBJECTS}
  358. tkrecord :
  359. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  360. { find init table }
  361. with RTTIRecordOp(typeinfo, typeinfo)^ do
  362. begin
  363. recordrtti(data,typeinfo,@int_addref);
  364. if Assigned(recordop) and Assigned(recordop^.AddRef) then
  365. recordop^.AddRef(Data);
  366. end;
  367. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  368. begin
  369. typeinfo:=RTTIRecordRttiInfoToInitInfo(typeinfo);
  370. recordrtti(data,typeinfo,@int_addref);
  371. end;
  372. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  373. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  374. tkDynArray:
  375. fpc_dynarray_incr_ref(PPointer(Data)^);
  376. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  377. tkInterface:
  378. Intf_Incr_Ref(PPointer(Data)^);
  379. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  380. tkVariant:
  381. variant_addref(pvardata(Data)^);
  382. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  383. end;
  384. end;
  385. { define alias for internal use in the system unit }
  386. Function fpc_Copy_internal (Src, Dest, TypeInfo : Pointer) : SizeInt;[external name 'FPC_COPY'];
  387. Function fpc_Copy (Src, Dest, TypeInfo : Pointer) : SizeInt;[Public,alias : 'FPC_COPY']; compilerproc;
  388. var
  389. Temp: pbyte;
  390. copiedsize,
  391. expectedoffset,
  392. count,
  393. offset,
  394. i: SizeInt;
  395. info: pointer;
  396. begin
  397. result:=sizeof(pointer);
  398. case PTypeKind(TypeInfo)^ of
  399. {$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
  400. tkAstring:
  401. fpc_AnsiStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  402. {$endif FPC_HAS_FEATURE_ANSISTRINGS}
  403. {$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
  404. {$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
  405. tkWstring:
  406. fpc_WideStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  407. {$endif FPC_WIDESTRING_EQUAL_UNICODESTRING}
  408. tkUstring:
  409. fpc_UnicodeStr_Assign(PPointer(Dest)^,PPointer(Src)^);
  410. {$endif FPC_HAS_FEATURE_WIDESTRINGS}
  411. tkArray:
  412. begin
  413. {$ifdef VER3_0}
  414. Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  415. {$else VER3_0}
  416. Temp:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  417. {$endif VER3_0}
  418. {$ifdef VER2_6}
  419. { Process elements }
  420. for I:=0 to PArrayInfo(Temp)^.ElCount-1 do
  421. fpc_Copy_internal(Src+(I*PArrayInfo(Temp)^.Size),Dest+(I*PArrayInfo(Temp)^.Size),PArrayInfo(Temp)^.ElInfo);
  422. Result:=PArrayInfo(Temp)^.Size*PArrayInfo(Temp)^.ElCount;
  423. {$else}
  424. Result:=PArrayInfo(Temp)^.Size;
  425. Count:=PArrayInfo(Temp)^.ElCount;
  426. { no elements to process => exit }
  427. if Count = 0 then
  428. Exit;
  429. Info:=PArrayInfo(Temp)^.ElInfo{$ifndef VER3_0}^{$endif};
  430. copiedsize:=Result div Count;
  431. Offset:=0;
  432. { Process elements }
  433. for I:=1 to Count do
  434. begin
  435. fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
  436. inc(Offset,copiedsize);
  437. end;
  438. {$endif}
  439. end;
  440. {$ifdef FPC_HAS_FEATURE_OBJECTS}
  441. tkobject,
  442. {$endif FPC_HAS_FEATURE_OBJECTS}
  443. tkrecord:
  444. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  445. { find init table }
  446. with RTTIRecordOp(typeinfo, typeinfo)^ do
  447. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  448. begin
  449. {$ifndef FPC_HAS_MANAGEMENT_OPERATORS}
  450. typeInfo:=RTTIRecordRttiInfoToInitInfo(typeInfo);
  451. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  452. {$ifdef VER3_0}
  453. Temp:=aligntoptr(typeInfo+2+PByte(typeInfo)[1]);
  454. {$else VER3_0}
  455. Temp:=aligntoqword(typeInfo+2+PByte(typeInfo)[1]);
  456. {$endif VER3_0}
  457. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  458. if Assigned(recordop) and Assigned(recordop^.Copy) then
  459. recordop^.Copy(Src,Dest)
  460. else
  461. begin
  462. Result:=Size;
  463. Inc(PRecordInfoInit(Temp));
  464. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  465. Result:=PRecordInfoFull(Temp)^.Size;
  466. Count:=PRecordInfoFull(Temp)^.Count;
  467. Inc(PRecordInfoFull(Temp));
  468. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  469. expectedoffset:=0;
  470. { Process elements with rtti }
  471. for i:=1 to Count Do
  472. begin
  473. Info:=PRecordElement(Temp)^.TypeInfo{$ifndef VER3_0}^{$endif};
  474. Offset:=PRecordElement(Temp)^.Offset;
  475. Inc(PRecordElement(Temp));
  476. if Offset>expectedoffset then
  477. move((Src+expectedoffset)^,(Dest+expectedoffset)^,Offset-expectedoffset);
  478. copiedsize:=fpc_Copy_internal(Src+Offset,Dest+Offset,Info);
  479. expectedoffset:=Offset+copiedsize;
  480. end;
  481. { elements remaining? }
  482. if result>expectedoffset then
  483. move((Src+expectedoffset)^,(Dest+expectedoffset)^,Result-expectedoffset);
  484. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  485. end;
  486. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  487. end;
  488. {$ifdef FPC_HAS_FEATURE_DYNARRAYS}
  489. tkDynArray:
  490. fpc_dynarray_assign(PPointer(Dest)^,PPointer(Src)^,typeinfo);
  491. {$endif FPC_HAS_FEATURE_DYNARRAYS}
  492. tkInterface:
  493. fpc_intf_assign(PPointer(Dest)^,PPointer(Src)^);
  494. {$ifdef FPC_HAS_FEATURE_VARIANTS}
  495. tkVariant:
  496. begin
  497. VarCopyProc(pvardata(dest)^,pvardata(src)^);
  498. result:=sizeof(tvardata);
  499. end;
  500. {$endif FPC_HAS_FEATURE_VARIANTS}
  501. end;
  502. end;
  503. { For internal use by the compiler, because otherwise $x- can cause trouble. }
  504. { Generally disabling extended syntax checking for all compilerprocs may }
  505. { have unintended side-effects }
  506. procedure fpc_Copy_proc (Src, Dest, TypeInfo : Pointer);compilerproc; inline;
  507. begin
  508. fpc_copy_internal(src,dest,typeinfo);
  509. end;
  510. procedure fpc_initialize_array(data,typeinfo : pointer;count : SizeInt); [public,alias:'FPC_INITIALIZE_ARRAY']; compilerproc;
  511. var
  512. i, size : SizeInt;
  513. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  514. hasManagementOp: boolean;
  515. begin
  516. size:=RTTISizeAndOp(typeinfo, rotInitialize, hasManagementOp);
  517. if (size>0) or hasManagementOp then
  518. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  519. begin
  520. size:=RTTISize(typeInfo);
  521. if size>0 then
  522. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  523. for i:=0 to count-1 do
  524. int_initialize(data+size*i,typeinfo);
  525. end;
  526. procedure fpc_finalize_array(data,typeinfo : pointer;count : SizeInt); [Public,Alias:'FPC_FINALIZE_ARRAY']; compilerproc;
  527. var
  528. i, size: SizeInt;
  529. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  530. hasManagementOp: boolean;
  531. begin
  532. size:=RTTISizeAndOp(typeinfo, rotFinalize, hasManagementOp);
  533. if (size>0) or hasManagementOp then
  534. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  535. begin
  536. size:=RTTISize(typeInfo);
  537. if size>0 then
  538. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  539. for i:=0 to count-1 do
  540. int_finalize(data+size*i,typeinfo);
  541. end;
  542. procedure fpc_addref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_ADDREF_ARRAY']; compilerproc;
  543. var
  544. i, size: SizeInt;
  545. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  546. hasManagementOp: boolean;
  547. begin
  548. size:=RTTISizeAndOp(typeinfo, rotAddRef, hasManagementOp);
  549. if (size>0) or hasManagementOp then
  550. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  551. begin
  552. size:=RTTISize(typeInfo);
  553. if size>0 then
  554. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  555. for i:=0 to count-1 do
  556. int_addref(data+size*i,typeinfo);
  557. end;
  558. { The following two procedures are now obsolete, needed only for bootstrapping }
  559. procedure fpc_decref (Data, TypeInfo : Pointer);[Public,alias : 'FPC_DECREF']; compilerproc;
  560. begin
  561. int_finalize(Data,TypeInfo);
  562. end;
  563. procedure fpc_decref_array(data,typeinfo: pointer; count: SizeInt); [public,alias:'FPC_DECREF_ARRAY']; compilerproc;
  564. begin
  565. int_finalizeArray(data,typeinfo,count);
  566. end;
  567. procedure InitializeArray(p, typeInfo: Pointer; count: SizeInt);
  568. external name 'FPC_INITIALIZE_ARRAY';
  569. procedure FinalizeArray(p, typeInfo: Pointer; count: SizeInt);
  570. external name 'FPC_FINALIZE_ARRAY';
  571. procedure CopyArray(dest, source, typeInfo: Pointer; count: SizeInt);
  572. var
  573. i, size: SizeInt;
  574. {$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
  575. hasManagementOp: boolean;
  576. begin
  577. size:=RTTISizeAndOp(typeinfo, rotCopy, hasManagementOp);
  578. if (size>0) or hasManagementOp then
  579. {$else FPC_HAS_MANAGEMENT_OPERATORS}
  580. begin
  581. size:=RTTISize(typeInfo);
  582. if size>0 then
  583. {$endif FPC_HAS_MANAGEMENT_OPERATORS}
  584. for i:=0 to count-1 do
  585. fpc_Copy_internal(source+size*i, dest+size*i, typeInfo);
  586. end;