genrtti.inc 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. { In case of an ansistring, data is pushed as a var parameter. }
  127. { This means that if you look at data as a value parameter, it }
  128. { containst the address of the ansistring. AnsiStr_Incr_Ref also }
  129. { expects a var parameter, so to pass the address of the }
  130. { ansistring and not that of the data parameter on the stack, }
  131. { you have to dereference data (JM) }
  132. tkAstring,tkWstring : fpc_AnsiStr_Incr_Ref(PPointer(Data)^);
  133. tkArray :
  134. begin
  135. Temp:=Temp+1;
  136. I:=temp^;
  137. temp:=temp+(I+1); // skip name string;
  138. Size:=PArrayRec(Temp)^.Size; // get element size
  139. Count:=PArrayRec(Temp)^.Count; // get element Count
  140. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  141. For I:=0 to Count-1 do
  142. int_AddRef (Data+(I*size),TInfo);
  143. end;
  144. tkrecord :
  145. begin
  146. Temp:=Temp+1;
  147. I:=Temp^;
  148. temp:=temp+(I+1); // skip name string;
  149. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  150. Count:=PRecRec(Temp)^.Count; // get element Count
  151. For I:=1 to count do
  152. With PRecRec(Temp)^.elements[I] do
  153. int_AddRef (Data+Offset,Info);
  154. end;
  155. tkDynArray:
  156. fpc_dynarray_incr_ref(PPointer(Data)^,TypeInfo);
  157. {$ifdef HASINTF}
  158. tkInterface:
  159. Intf_Incr_Ref(PPointer(Data)^);
  160. {$endif HASINTF}
  161. end;
  162. end;
  163. {$endif}
  164. {$ifndef FPC_SYSTEM_HAS_FPC_DECREF}
  165. Procedure fpc_DecRef (Data, TypeInfo : Pointer);saveregisters;[Public,alias : 'FPC_DECREF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  166. { this definition is sometimes (depending on switches)
  167. already defined or not so define it locally to avoid problems PM }
  168. Type
  169. Pbyte = ^Byte;
  170. PPointer = ^Pointer;
  171. Var Temp : PByte;
  172. I : longint;
  173. Size,Count : longint;
  174. TInfo : Pointer;
  175. begin
  176. Temp:=PByte(TypeInfo);
  177. case temp^ of
  178. { see AddRef for comment about below construct (JM) }
  179. tkAstring,tkWstring:
  180. fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
  181. tkArray:
  182. begin
  183. inc(Temp);
  184. I:=temp^;
  185. inc(temp,I+1); // skip name string;
  186. Size:=PArrayRec(Temp)^.Size; // get element size
  187. Count:=PArrayRec(Temp)^.Count; // get element Count
  188. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  189. For I:=0 to Count-1 do
  190. fpc_DecRef (Data+(I*size),TInfo);
  191. end;
  192. tkrecord:
  193. begin
  194. Temp:=Temp+1;
  195. I:=Temp^;
  196. temp:=temp+(I+1); // skip name string;
  197. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  198. Count:=PRecRec(Temp)^.Count; // get element Count
  199. For I:=1 to count do
  200. With PRecRec(Temp)^.elements[I] do
  201. fpc_DecRef (Data+Offset,Info);
  202. end;
  203. tkDynArray:
  204. fpc_dynarray_decr_ref(PPointer(Data)^,TypeInfo);
  205. {$ifdef HASINTF}
  206. tkInterface:
  207. Intf_Decr_Ref(PPointer(Data)^);
  208. {$endif HASINTF}
  209. end;
  210. end;
  211. {$endif}
  212. {$ifndef FPC_SYSTEM_HAS_FPC_FINALIZEARRAY}
  213. procedure fpc_FinalizeArray(data,typeinfo : pointer;count,size : longint); [Public,Alias:'FPC_FINALIZEARRAY']; {$ifdef hascompilerproc} compilerproc; {$endif}
  214. var
  215. i : longint;
  216. begin
  217. for i:=0 to count-1 do
  218. int_finalize(data+size*i,typeinfo);
  219. end;
  220. {$endif}
  221. {
  222. $Log$
  223. Revision 1.10 2001-11-30 16:25:35 jonas
  224. * fixed web bug 1707:
  225. * tvarsym.getvaluesize doesn't return 0 anymore for dynarrays (found
  226. by Florian)
  227. * in genrtti, some more ppointer(data)^ tricks were necessary
  228. Revision 1.9 2001/11/22 07:33:08 michael
  229. * Fixed memory corruption with finalize() of ansistring in a class
  230. Revision 1.8 2001/11/17 16:56:08 florian
  231. * init and final code in genrtti.inc updated
  232. Revision 1.7 2001/11/17 10:29:48 florian
  233. * make cycle for win32 fixed
  234. Revision 1.6 2001/11/14 22:59:11 michael
  235. + Initial variant support
  236. Revision 1.5 2001/08/01 15:00:10 jonas
  237. + "compproc" helpers
  238. * renamed several helpers so that their name is the same as their
  239. "public alias", which should facilitate the conversion of processor
  240. specific code in the code generator to processor independent code
  241. * some small fixes to the val_ansistring and val_widestring helpers
  242. (always immediately exit if the source string is longer than 255
  243. chars)
  244. * fixed fpc_dynarray_high and fpc_dynarray_length if the dynarray is
  245. still nil (used to crash, now return resp -1 and 0)
  246. Revision 1.4 2001/06/28 19:18:57 peter
  247. * ansistr fix merged
  248. Revision 1.3 2001/05/28 20:43:17 peter
  249. * more saveregisters added (merged)
  250. Revision 1.2 2001/04/23 18:25:44 peter
  251. * m68k updates
  252. }