rtti.inc 19 KB

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