genrtti.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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)^);
  154. {$ifdef HASINTF}
  155. tkInterface:
  156. Intf_Incr_Ref(PPointer(Data)^);
  157. {$endif HASINTF}
  158. end;
  159. end;
  160. {$endif}
  161. {$ifdef hascompilerproc}
  162. { alias for internal use }
  163. { we use another name else the compiler gets puzzled because of the wrong forward def }
  164. procedure fpc_systemDecRef (Data, TypeInfo : Pointer);saveregisters;[external name 'FPC_DECREF'];
  165. {$endif compilerproc}
  166. {$ifndef FPC_SYSTEM_HAS_FPC_DECREF}
  167. Procedure fpc_DecRef (Data, TypeInfo : Pointer);saveregisters;[Public,alias : 'FPC_DECREF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  168. { this definition is sometimes (depending on switches)
  169. already defined or not so define it locally to avoid problems PM }
  170. Type
  171. Pbyte = ^Byte;
  172. PPointer = ^Pointer;
  173. Var Temp : PByte;
  174. I : longint;
  175. Size,Count : longint;
  176. TInfo : Pointer;
  177. begin
  178. Temp:=PByte(TypeInfo);
  179. case temp^ of
  180. { see AddRef for comment about below construct (JM) }
  181. tkAstring:
  182. fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
  183. tkWstring:
  184. fpc_WideStr_Decr_Ref(PPointer(Data)^);
  185. tkArray:
  186. begin
  187. inc(Temp);
  188. I:=temp^;
  189. inc(temp,I+1); // skip name string;
  190. Size:=PArrayRec(Temp)^.Size; // get element size
  191. Count:=PArrayRec(Temp)^.Count; // get element Count
  192. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  193. For I:=0 to Count-1 do
  194. fpc_systemDecRef (Data+(I*size),TInfo);
  195. end;
  196. tkrecord:
  197. begin
  198. Temp:=Temp+1;
  199. I:=Temp^;
  200. temp:=temp+(I+1); // skip name string;
  201. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  202. Count:=PRecRec(Temp)^.Count; // get element Count
  203. For I:=1 to count do
  204. With PRecRec(Temp)^.elements[I] do
  205. fpc_systemDecRef (Data+Offset,Info);
  206. end;
  207. tkDynArray:
  208. fpc_dynarray_decr_ref(PPointer(Data)^,TypeInfo);
  209. {$ifdef HASINTF}
  210. tkInterface:
  211. Intf_Decr_Ref(PPointer(Data)^);
  212. {$endif HASINTF}
  213. end;
  214. end;
  215. {$endif}
  216. {$ifndef FPC_SYSTEM_HAS_FPC_FINALIZEARRAY}
  217. procedure fpc_finalize_array(data,typeinfo : pointer;count,size : longint); [Public,Alias:'FPC_FINALIZEARRAY']; {$ifdef hascompilerproc} compilerproc; {$endif}
  218. var
  219. i : longint;
  220. begin
  221. for i:=0 to count-1 do
  222. int_finalize(data+size*i,typeinfo);
  223. end;
  224. {$endif}
  225. {
  226. $Log$
  227. Revision 1.13 2002-07-29 21:28:17 florian
  228. * several fixes to get further with linux/ppc system unit compilation
  229. Revision 1.12 2002/04/25 20:14:57 peter
  230. * updated compilerprocs
  231. * incr ref count has now a value argument instead of var
  232. Revision 1.11 2002/04/24 16:15:35 peter
  233. * fpc_finalize_array renamed
  234. Revision 1.10 2001/11/30 16:25:35 jonas
  235. * fixed web bug 1707:
  236. * tvarsym.getvaluesize doesn't return 0 anymore for dynarrays (found
  237. by Florian)
  238. * in genrtti, some more ppointer(data)^ tricks were necessary
  239. Revision 1.9 2001/11/22 07:33:08 michael
  240. * Fixed memory corruption with finalize() of ansistring in a class
  241. Revision 1.8 2001/11/17 16:56:08 florian
  242. * init and final code in genrtti.inc updated
  243. Revision 1.7 2001/11/17 10:29:48 florian
  244. * make cycle for win32 fixed
  245. Revision 1.6 2001/11/14 22:59:11 michael
  246. + Initial variant support
  247. Revision 1.5 2001/08/01 15:00:10 jonas
  248. + "compproc" helpers
  249. * renamed several helpers so that their name is the same as their
  250. "public alias", which should facilitate the conversion of processor
  251. specific code in the code generator to processor independent code
  252. * some small fixes to the val_ansistring and val_widestring helpers
  253. (always immediately exit if the source string is longer than 255
  254. chars)
  255. * fixed fpc_dynarray_high and fpc_dynarray_length if the dynarray is
  256. still nil (used to crash, now return resp -1 and 0)
  257. Revision 1.4 2001/06/28 19:18:57 peter
  258. * ansistr fix merged
  259. Revision 1.3 2001/05/28 20:43:17 peter
  260. * more saveregisters added (merged)
  261. Revision 1.2 2001/04/23 18:25:44 peter
  262. * m68k updates
  263. }