genrtti.inc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by xxxx
  5. member of the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { Run-Time type information routines - processor dependent part }
  13. {$ifndef FPC_SYSTEM_HAS_FPC_INITIALIZE}
  14. Procedure fpc_Initialize (Data,TypeInfo : pointer);saveregisters;[Public,Alias : 'FPC_INITIALIZE']; {$ifdef hascompilerproc} compilerproc; {$endif}
  15. { this definition is sometimes (depending on switches)
  16. already defined or not so define it locally to avoid problems PM }
  17. Type
  18. Pbyte = ^Byte;
  19. Var Temp : PByte;
  20. I : longint;
  21. Size,Count : longint;
  22. TInfo : Pointer;
  23. begin
  24. Temp:=PByte(TypeInfo);
  25. case temp^ of
  26. tkAstring,tkWstring,tkInterface,tkDynArray:
  27. PPchar(Data)^:=Nil;
  28. tkArray:
  29. begin
  30. inc(temp);
  31. I:=temp^;
  32. inc(temp,(I+1)); // skip name string;
  33. Size:=PArrayRec(Temp)^.Size; // get element size
  34. Count:=PArrayRec(Temp)^.Count; // get element Count
  35. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  36. For I:=0 to Count-1 do
  37. int_Initialize (Data+(I*size),TInfo);
  38. end;
  39. tkRecord,tkClass,tkObject:
  40. begin
  41. inc(Temp);
  42. I:=Temp^;
  43. inc(temp,I+1); // skip name string;
  44. { if it isn't necessary, why should we load it ? FK
  45. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  46. }
  47. Count:=PRecRec(Temp)^.Count; // get element Count
  48. For I:=1 to count Do
  49. With PRecRec(Temp)^.elements[I] do
  50. int_Initialize (Data+Offset,Info);
  51. end;
  52. {$ifdef HASVARIANT}
  53. tkVariant:
  54. variant_init(Variant(PVarData(Data)^))
  55. {$endif HASVARIANT}
  56. end;
  57. end;
  58. {$endif}
  59. {$ifndef FPC_SYSTEM_HAS_FPC_FINALIZE}
  60. Procedure fpc_finalize (Data,TypeInfo: Pointer);saveregisters;[Public,Alias : 'FPC_FINALIZE']; {$ifdef hascompilerproc} compilerproc; {$endif}
  61. { this definition is sometimes (depending on switches)
  62. already defined or not so define it locally to avoid problems PM }
  63. Type
  64. Pbyte = ^Byte;
  65. PPointer = ^Pointer;
  66. Var Temp : PByte;
  67. I : longint;
  68. Size,Count : longint;
  69. TInfo : Pointer;
  70. begin
  71. Temp:=PByte(TypeInfo);
  72. case temp^ of
  73. tkAstring,tkWstring:
  74. fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
  75. tkArray :
  76. begin
  77. inc(Temp);
  78. I:=temp^;
  79. inc(temp,I+1); // skip name string;
  80. Size:=PArrayRec(Temp)^.Size; // get element size
  81. Count:=PArrayRec(Temp)^.Count; // get element Count
  82. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  83. For I:=0 to Count-1 do
  84. int_Finalize (Data+(I*size),TInfo);
  85. end;
  86. tkRecord,tkObject,tkClass:
  87. begin
  88. inc(Temp);
  89. I:=Temp^;
  90. inc(temp,I+1); // skip name string;
  91. { if it isn't necessary, why should we load it? FK
  92. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  93. }
  94. Count:=PRecRec(Temp)^.Count; // get element Count
  95. For I:=1 to count do
  96. With PRecRec(Temp)^.elements[I] do
  97. int_Finalize (Data+Offset,Info);
  98. end;
  99. {$ifdef HASINTF}
  100. tkInterface:
  101. Intf_Decr_Ref(PPointer(Data)^);
  102. {$endif HASINTF}
  103. tkDynArray:
  104. fpc_dynarray_decr_ref(PPointer(Data)^,TypeInfo);
  105. {$ifdef HASVARIANT}
  106. tkVariant:
  107. variant_clear(Variant(PVarData(Data)^))
  108. {$endif HASVARIANT}
  109. end;
  110. end;
  111. {$endif}
  112. {$ifndef FPC_SYSTEM_HAS_FPC_ADDREF}
  113. Procedure fpc_Addref (Data,TypeInfo : Pointer);saveregisters; [Public,alias : 'FPC_ADDREF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  114. { this definition is sometimes (depending on switches)
  115. already defined or not so define it locally to avoid problems PM }
  116. Type
  117. Pbyte = ^Byte;
  118. PPointer = ^Pointer;
  119. Var Temp : PByte;
  120. I : longint;
  121. Size,Count : longint;
  122. TInfo : Pointer;
  123. begin
  124. Temp:=PByte(TypeInfo);
  125. case temp^ of
  126. tkAstring :
  127. fpc_AnsiStr_Incr_Ref(PPointer(Data)^);
  128. tkWstring :
  129. fpc_WideStr_Incr_Ref(PPointer(Data)^);
  130. tkArray :
  131. begin
  132. Inc(Temp);
  133. I:=temp^;
  134. inc(temp,I+1); // skip name string;
  135. Size:=PArrayRec(Temp)^.Size; // get element size
  136. Count:=PArrayRec(Temp)^.Count; // get element Count
  137. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  138. For I:=0 to Count-1 do
  139. int_AddRef (Data+(I*size),TInfo);
  140. end;
  141. tkrecord :
  142. begin
  143. Inc(Temp);
  144. I:=Temp^;
  145. temp:=temp+(I+1); // skip name string;
  146. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  147. Count:=PRecRec(Temp)^.Count; // get element Count
  148. For I:=1 to count do
  149. With PRecRec(Temp)^.elements[I] do
  150. int_AddRef (Data+Offset,Info);
  151. end;
  152. tkDynArray:
  153. fpc_dynarray_incr_ref(PPointer(Data)^,TypeInfo);
  154. {$ifdef HASINTF}
  155. tkInterface:
  156. Intf_Incr_Ref(PPointer(Data)^);
  157. {$endif HASINTF}
  158. end;
  159. end;
  160. {$endif}
  161. {$ifndef FPC_SYSTEM_HAS_FPC_DECREF}
  162. Procedure fpc_DecRef (Data, TypeInfo : Pointer);saveregisters;[Public,alias : 'FPC_DECREF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  163. { this definition is sometimes (depending on switches)
  164. already defined or not so define it locally to avoid problems PM }
  165. Type
  166. Pbyte = ^Byte;
  167. PPointer = ^Pointer;
  168. Var Temp : PByte;
  169. I : longint;
  170. Size,Count : longint;
  171. TInfo : Pointer;
  172. begin
  173. Temp:=PByte(TypeInfo);
  174. case temp^ of
  175. { see AddRef for comment about below construct (JM) }
  176. tkAstring:
  177. fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
  178. tkWstring:
  179. fpc_WideStr_Decr_Ref(PPointer(Data)^);
  180. tkArray:
  181. begin
  182. inc(Temp);
  183. I:=temp^;
  184. inc(temp,I+1); // skip name string;
  185. Size:=PArrayRec(Temp)^.Size; // get element size
  186. Count:=PArrayRec(Temp)^.Count; // get element Count
  187. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  188. For I:=0 to Count-1 do
  189. fpc_DecRef (Data+(I*size),TInfo);
  190. end;
  191. tkrecord:
  192. begin
  193. Temp:=Temp+1;
  194. I:=Temp^;
  195. temp:=temp+(I+1); // skip name string;
  196. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  197. Count:=PRecRec(Temp)^.Count; // get element Count
  198. For I:=1 to count do
  199. With PRecRec(Temp)^.elements[I] do
  200. fpc_DecRef (Data+Offset,Info);
  201. end;
  202. tkDynArray:
  203. fpc_dynarray_decr_ref(PPointer(Data)^,TypeInfo);
  204. {$ifdef HASINTF}
  205. tkInterface:
  206. Intf_Decr_Ref(PPointer(Data)^);
  207. {$endif HASINTF}
  208. end;
  209. end;
  210. {$endif}
  211. {$ifndef FPC_SYSTEM_HAS_FPC_FINALIZEARRAY}
  212. procedure fpc_finalize_array(data,typeinfo : pointer;count,size : longint); [Public,Alias:'FPC_FINALIZEARRAY']; {$ifdef hascompilerproc} compilerproc; {$endif}
  213. var
  214. i : longint;
  215. begin
  216. for i:=0 to count-1 do
  217. int_finalize(data+size*i,typeinfo);
  218. end;
  219. {$endif}
  220. {
  221. $Log$
  222. Revision 1.12 2002-04-25 20:14:57 peter
  223. * updated compilerprocs
  224. * incr ref count has now a value argument instead of var
  225. Revision 1.11 2002/04/24 16:15:35 peter
  226. * fpc_finalize_array renamed
  227. Revision 1.10 2001/11/30 16:25:35 jonas
  228. * fixed web bug 1707:
  229. * tvarsym.getvaluesize doesn't return 0 anymore for dynarrays (found
  230. by Florian)
  231. * in genrtti, some more ppointer(data)^ tricks were necessary
  232. Revision 1.9 2001/11/22 07:33:08 michael
  233. * Fixed memory corruption with finalize() of ansistring in a class
  234. Revision 1.8 2001/11/17 16:56:08 florian
  235. * init and final code in genrtti.inc updated
  236. Revision 1.7 2001/11/17 10:29:48 florian
  237. * make cycle for win32 fixed
  238. Revision 1.6 2001/11/14 22:59:11 michael
  239. + Initial variant support
  240. Revision 1.5 2001/08/01 15:00:10 jonas
  241. + "compproc" helpers
  242. * renamed several helpers so that their name is the same as their
  243. "public alias", which should facilitate the conversion of processor
  244. specific code in the code generator to processor independent code
  245. * some small fixes to the val_ansistring and val_widestring helpers
  246. (always immediately exit if the source string is longer than 255
  247. chars)
  248. * fixed fpc_dynarray_high and fpc_dynarray_length if the dynarray is
  249. still nil (used to crash, now return resp -1 and 0)
  250. Revision 1.4 2001/06/28 19:18:57 peter
  251. * ansistr fix merged
  252. Revision 1.3 2001/05/28 20:43:17 peter
  253. * more saveregisters added (merged)
  254. Revision 1.2 2001/04/23 18:25:44 peter
  255. * m68k updates
  256. }