genrtti.inc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 : PPchar(Data)^:=Nil;
  27. tkArray :
  28. begin
  29. temp:=Temp+1;
  30. I:=temp^;
  31. temp:=temp+(I+1); // skip name string;
  32. Size:=PArrayRec(Temp)^.Size; // get element size
  33. Count:=PArrayRec(Temp)^.Count; // get element Count
  34. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  35. For I:=0 to Count-1 do
  36. int_Initialize (Data+(I*size),TInfo);
  37. end;
  38. tkrecord :
  39. begin
  40. Temp:=Temp+1;
  41. I:=Temp^;
  42. temp:=temp+(I+1); // skip name string;
  43. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  44. Count:=PRecRec(Temp)^.Count; // get element Count
  45. For I:=1 to count Do
  46. With PRecRec(Temp)^.elements[I] do
  47. int_Initialize (Data+Offset,Info);
  48. end;
  49. end;
  50. end;
  51. {$endif}
  52. {$ifndef FPC_SYSTEM_HAS_FPC_FINALIZE}
  53. Procedure fpc_Finalize (Data,TypeInfo: Pointer);saveregisters;[Public,Alias : 'FPC_FINALIZE']; {$ifdef hascompilerproc} compilerproc; {$endif}
  54. { this definition is sometimes (depending on switches)
  55. already defined or not so define it locally to avoid problems PM }
  56. Type
  57. Pbyte = ^Byte;
  58. Var Temp : PByte;
  59. I : longint;
  60. Size,Count : longint;
  61. TInfo : Pointer;
  62. begin
  63. Temp:=PByte(TypeInfo);
  64. case temp^ of
  65. tkAstring,tkWstring : AnsiStr_Decr_Ref(Data);
  66. tkArray :
  67. begin
  68. Temp:=Temp+1;
  69. I:=temp^;
  70. temp:=temp+(I+1); // skip name string;
  71. Size:=PArrayRec(Temp)^.Size; // get element size
  72. Count:=PArrayRec(Temp)^.Count; // get element Count
  73. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  74. For I:=0 to Count-1 do
  75. int_Finalize (Data+(I*size),TInfo);
  76. end;
  77. tkrecord :
  78. begin
  79. Temp:=Temp+1;
  80. I:=Temp^;
  81. temp:=temp+(I+1); // skip name string;
  82. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  83. Count:=PRecRec(Temp)^.Count; // get element Count
  84. For I:=1 to count do
  85. With PRecRec(Temp)^.elements[I] do
  86. int_Finalize (Data+Offset,Info);
  87. end;
  88. end;
  89. end;
  90. {$endif}
  91. {$ifndef FPC_SYSTEM_HAS_FPC_ADDREF}
  92. Procedure fpc_Addref (Data,TypeInfo : Pointer);saveregisters; [Public,alias : 'FPC_ADDREF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  93. { this definition is sometimes (depending on switches)
  94. already defined or not so define it locally to avoid problems PM }
  95. Type
  96. Pbyte = ^Byte;
  97. PPointer = ^Pointer;
  98. Var Temp : PByte;
  99. I : longint;
  100. Size,Count : longint;
  101. TInfo : Pointer;
  102. begin
  103. Temp:=PByte(TypeInfo);
  104. case temp^ of
  105. { In case of an ansistring, data is pushed as a var parameter. }
  106. { This means that if you look at data as a value parameter, it }
  107. { containst the address of the ansistring. AnsiStr_Incr_Ref also }
  108. { expects a var parameter, so to pass the address of the }
  109. { ansistring and not that of the data parameter on the stack, }
  110. { you have to dereference data (JM) }
  111. tkAstring,tkWstring : fpc_AnsiStr_Incr_Ref(PPointer(Data)^);
  112. tkArray :
  113. begin
  114. Temp:=Temp+1;
  115. I:=temp^;
  116. temp:=temp+(I+1); // skip name string;
  117. Size:=PArrayRec(Temp)^.Size; // get element size
  118. Count:=PArrayRec(Temp)^.Count; // get element Count
  119. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  120. For I:=0 to Count-1 do
  121. int_AddRef (Data+(I*size),TInfo);
  122. end;
  123. tkrecord :
  124. begin
  125. Temp:=Temp+1;
  126. I:=Temp^;
  127. temp:=temp+(I+1); // skip name string;
  128. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  129. Count:=PRecRec(Temp)^.Count; // get element Count
  130. For I:=1 to count do
  131. With PRecRec(Temp)^.elements[I] do
  132. int_AddRef (Data+Offset,Info);
  133. end;
  134. end;
  135. end;
  136. {$endif}
  137. {$ifndef FPC_SYSTEM_HAS_FPC_DECREF}
  138. Procedure fpc_DecRef (Data, TypeInfo : Pointer);saveregisters;[Public,alias : 'FPC_DECREF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  139. { this definition is sometimes (depending on switches)
  140. already defined or not so define it locally to avoid problems PM }
  141. Type
  142. Pbyte = ^Byte;
  143. PPointer = ^Pointer;
  144. Var Temp : PByte;
  145. I : longint;
  146. Size,Count : longint;
  147. TInfo : Pointer;
  148. begin
  149. Temp:=PByte(TypeInfo);
  150. case temp^ of
  151. { see AddRef for comment about below construct (JM) }
  152. tkAstring,tkWstring : fpc_AnsiStr_Decr_Ref(PPointer(Data)^);
  153. tkArray :
  154. begin
  155. Temp:=Temp+1;
  156. I:=temp^;
  157. temp:=temp+(I+1); // skip name string;
  158. Size:=PArrayRec(Temp)^.Size; // get element size
  159. Count:=PArrayRec(Temp)^.Count; // get element Count
  160. TInfo:=PArrayRec(Temp)^.Info; // Get element info
  161. For I:=0 to Count-1 do
  162. fpc_DecRef (Data+(I*size),TInfo);
  163. end;
  164. tkrecord :
  165. begin
  166. Temp:=Temp+1;
  167. I:=Temp^;
  168. temp:=temp+(I+1); // skip name string;
  169. Size:=PRecRec(Temp)^.Size; // get record size; not needed.
  170. Count:=PRecRec(Temp)^.Count; // get element Count
  171. For I:=1 to count do
  172. With PRecRec(Temp)^.elements[I] do
  173. fpc_DecRef (Data+Offset,Info);
  174. end;
  175. end;
  176. end;
  177. {$endif}
  178. {$ifndef FPC_SYSTEM_HAS_FPC_FINALIZEARRAY}
  179. procedure fpc_FinalizeArray(data,typeinfo : pointer;count,size : longint); [Public,Alias:'FPC_FINALIZEARRAY']; {$ifdef hascompilerproc} compilerproc; {$endif}
  180. var
  181. i : longint;
  182. begin
  183. for i:=0 to count-1 do
  184. int_finalize(data+size*i,typeinfo);
  185. end;
  186. {$endif}
  187. {
  188. $Log$
  189. Revision 1.5 2001-08-01 15:00:10 jonas
  190. + "compproc" helpers
  191. * renamed several helpers so that their name is the same as their
  192. "public alias", which should facilitate the conversion of processor
  193. specific code in the code generator to processor independent code
  194. * some small fixes to the val_ansistring and val_widestring helpers
  195. (always immediately exit if the source string is longer than 255
  196. chars)
  197. * fixed fpc_dynarray_high and fpc_dynarray_length if the dynarray is
  198. still nil (used to crash, now return resp -1 and 0)
  199. Revision 1.4 2001/06/28 19:18:57 peter
  200. * ansistr fix merged
  201. Revision 1.3 2001/05/28 20:43:17 peter
  202. * more saveregisters added (merged)
  203. Revision 1.2 2001/04/23 18:25:44 peter
  204. * m68k updates
  205. }