compproc.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. This file contains the declarations of internal compiler helper
  6. routines. That means you can *NOT* call these directly, as they may
  7. be changed or even removed at any time. The only reason they are
  8. included in the interface of the system unit, is so that the
  9. compiler doesn't need special code to access their parameter
  10. list information etc.
  11. Note that due to the "compilerproc" directive, it isn't even possible
  12. to use these routines in your programs.
  13. See the File COPYING.FPC, included in this distribution,
  14. for details about the copyright.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. **********************************************************************}
  19. { some dummy types necessary to have generic resulttypes for certain compilerprocs }
  20. type
  21. fpc_big_chararray = array[0..maxlongint] of char;
  22. fpc_small_set = longint;
  23. fpc_normal_set = array[0..7] of longint;
  24. {$ifdef hascompilerproc}
  25. procedure fpc_Shortstr_SetLength(var s:shortstring;len:StrLenInt); compilerproc;
  26. function fpc_shortstr_to_shortstr(len:longint; const sstr: shortstring): shortstring; compilerproc;
  27. function fpc_shortstr_concat(const s1,s2:shortstring): shortstring; compilerproc;
  28. function fpc_shortstr_compare(const dstr,sstr:shortstring) : longint; compilerproc;
  29. function fpc_pchar_to_shortstr(p:pchar):shortstring; compilerproc;
  30. function fpc_chararray_to_shortstr(const arr: array of char):shortstring; compilerproc;
  31. function fpc_shortstr_to_chararray(arraysize: longint; const src: ShortString): fpc_big_chararray; compilerproc;
  32. function fpc_dynarray_length(p : pointer) : tdynarrayindex; compilerproc;
  33. function fpc_dynarray_high(p : pointer) : tdynarrayindex; compilerproc;
  34. procedure fpc_dynarray_decr_ref(var p : pointer;ti : pointer); compilerproc;
  35. procedure fpc_dynarray_incr_ref(var p : pointer); compilerproc;
  36. procedure fpc_dynarray_setlength(var p : pointer;pti : pointer;
  37. dimcount : dword;dims : pdynarrayindex); compilerproc;
  38. function fpc_dynarray_copy(var p : pointer;ti : pointer;
  39. dimcount : dword;dims : pdynarrayindex) : pointer; compilerproc;
  40. procedure fpc_ShortStr_Float(d : ValReal;len,fr,rt : longint;var s : shortstring); compilerproc;
  41. procedure fpc_ShortStr_Longint(v : longint;len : longint;var s : shortstring); compilerproc;
  42. procedure fpc_shortstr_cardinal(v : cardinal;len : longint;var s : shortstring); compilerproc;
  43. Function fpc_Val_SInt_ShortStr(DestSize: longint; Const S: ShortString; var Code: ValSInt): ValSInt; compilerproc;
  44. Function fpc_Val_UInt_Shortstr(Const S: ShortString; var Code: ValSInt): ValUInt; compilerproc;
  45. Function fpc_Val_Real_ShortStr(const s : shortstring; var code : ValSInt): ValReal; compilerproc;
  46. Procedure fpc_AnsiStr_Decr_Ref (Var S : Pointer); compilerproc;
  47. Procedure fpc_AnsiStr_Incr_Ref (Var S : Pointer); compilerproc;
  48. Procedure fpc_AnsiStr_Assign (Var S1 : Pointer;S2 : Pointer); compilerproc;
  49. function fpc_AnsiStr_Concat (const S1,S2 : AnsiString): AnsiString; compilerproc;
  50. {$ifdef EXTRAANSISHORT}
  51. Procedure fpc_AnsiStr_ShortStr_Concat (Var S1: AnsiString; Var S2 : ShortString); compilerproc;
  52. {$endif EXTRAANSISHORT}
  53. function fpc_AnsiStr_To_ShortStr (high_of_res: longint;const S2 : Ansistring): shortstring; compilerproc;
  54. Function fpc_ShortStr_To_AnsiStr (Const S2 : ShortString): ansistring; compilerproc;
  55. Function fpc_Char_To_AnsiStr(const c : Char): AnsiString; compilerproc;
  56. Function fpc_PChar_To_AnsiStr(const p : pchar): ansistring; compilerproc;
  57. Function fpc_CharArray_To_AnsiStr(const arr: array of char): ansistring; compilerproc;
  58. function fpc_ansistr_to_chararray(arraysize: longint; const src: ansistring): fpc_big_chararray; compilerproc;
  59. Function fpc_AnsiStr_Compare(const S1,S2 : AnsiString): Longint; compilerproc;
  60. Procedure fpc_AnsiStr_CheckZero(p : pointer); compilerproc;
  61. Procedure fpc_AnsiStr_CheckRange(len,index : longint); compilerproc;
  62. Procedure fpc_AnsiStr_SetLength (Var S : AnsiString; l : Longint); compilerproc;
  63. {$ifdef EXTRAANSISHORT}
  64. Function fpc_AnsiStr_ShortStr_Compare (Var S1 : Pointer; Var S2 : ShortString): Longint; compilerproc;
  65. {$endif EXTRAANSISHORT}
  66. Procedure fpc_ansistr_Unique(Var S : AnsiString); compilerproc;
  67. Procedure fpc_WideStr_Decr_Ref (Var S : Pointer); compilerproc;
  68. Procedure fpc_WideStr_Incr_Ref (Var S : Pointer); compilerproc;
  69. function fpc_WideStr_To_ShortStr (high_of_res: longint;const S2 : WideString): shortstring; compilerproc;
  70. Function fpc_ShortStr_To_WideStr (Const S2 : ShortString): WideString; compilerproc;
  71. Function fpc_WideStr_To_AnsiStr (const S2 : WideString): AnsiString; compilerproc;
  72. Function fpc_AnsiStr_To_WideStr (Const S2 : AnsiString): WideString; compilerproc;
  73. Procedure fpc_WideStr_Assign (Var S1 : Pointer;S2 : Pointer); compilerproc;
  74. Function fpc_WideStr_Concat (const S1,S2 : WideString) : WideString; compilerproc;
  75. Function fpc_Char_To_WideStr(const c : Char): WideString; compilerproc;
  76. Function fpc_PChar_To_WideStr(const p : pchar): WideString; compilerproc;
  77. Function fpc_CharArray_To_WideStr(const arr: array of char): WideString; compilerproc;
  78. function fpc_widestr_to_chararray(arraysize: longint; const src: WideString): fpc_big_chararray; compilerproc;
  79. Function fpc_WideStr_Compare(const S1,S2 : WideString): Longint; compilerproc;
  80. Procedure fpc_WideStr_CheckZero(p : pointer); compilerproc;
  81. Procedure fpc_WideStr_CheckRange(len,index : longint); compilerproc;
  82. Procedure fpc_WideStr_SetLength (Var S : WideString; l : Longint); compilerproc;
  83. Procedure fpc_widestr_Unique(Var S : WideString); compilerproc;
  84. Function fpc_Val_Real_AnsiStr(Const S : AnsiString; Var Code : ValSInt): ValReal; compilerproc;
  85. Function fpc_Val_UInt_AnsiStr (Const S : AnsiString; Var Code : ValSInt): ValUInt; compilerproc;
  86. Function fpc_Val_SInt_AnsiStr (DestSize: longint; Const S : AnsiString; Var Code : ValSInt): ValSInt; compilerproc;
  87. Function fpc_Val_qword_AnsiStr (Const S : AnsiString; Var Code : ValSInt): qword;compilerproc;
  88. Function fpc_Val_int64_AnsiStr (Const S : AnsiString; Var Code : ValSInt): Int64; compilerproc;
  89. procedure fpc_AnsiStr_Float(d : ValReal;len,fr,rt : longint;var s : ansistring); compilerproc;
  90. Procedure fpc_AnsiStr_Cardinal(C : Cardinal;Len : Longint; Var S : AnsiString); compilerproc;
  91. Procedure fpc_AnsiStr_Longint(L : Longint; Len : Longint; Var S : AnsiString); compilerproc;
  92. Function fpc_Val_Real_WideStr(Const S : WideString; Var Code : ValSInt): ValReal; compilerproc;
  93. Function fpc_Val_UInt_WideStr (Const S : WideString; Var Code : ValSInt): ValUInt; compilerproc;
  94. Function fpc_Val_SInt_WideStr (DestSize: longint; Const S : WideString; Var Code : ValSInt): ValSInt; compilerproc;
  95. Function fpc_Val_qword_WideStr (Const S : WideString; Var Code : ValSInt): qword; compilerproc;
  96. Function fpc_Val_int64_WideStr (Const S : WideString; Var Code : ValSInt): Int64; compilerproc;
  97. procedure fpc_WideStr_Float(d : ValReal;len,fr,rt : longint;var s : WideString); compilerproc;
  98. Procedure fpc_WideStr_Cardinal(C : Cardinal;Len : Longint; Var S : WideString); compilerproc;
  99. Procedure fpc_WideStr_Longint(L : Longint; Len : Longint; Var S : WideString); compilerproc;
  100. { from text.inc }
  101. Procedure fpc_Write_End(var f:Text); compilerproc;
  102. Procedure fpc_Writeln_End(var f:Text); compilerproc;
  103. Procedure fpc_Write_Text_ShortStr(Len : Longint;var f : Text;const s : String); compilerproc;
  104. Procedure fpc_Write_Text_Pchar_as_Array(Len : Longint;var f : Text;const s : array of char); compilerproc;
  105. Procedure fpc_Write_Text_PChar_As_Pointer(Len : Longint;var f : Text;p : PChar); compilerproc;
  106. Procedure fpc_Write_Text_AnsiStr (Len : Longint; Var f : Text; S : AnsiString); compilerproc;
  107. {$ifdef HASWIDESTRING}
  108. Procedure fpc_Write_Text_WideStr (Len : Longint; Var f : Text; S : WideString); compilerproc;
  109. {$endif HASWIDESTRING}
  110. Procedure fpc_Write_Text_SInt(Len : Longint;var t : Text;l : ValSInt); compilerproc;
  111. Procedure fpc_Write_Text_UInt(Len : Longint;var t : Text;l : ValUInt); compilerproc;
  112. procedure fpc_write_text_qword(len : longint;var t : text;q : qword); compilerproc;
  113. procedure fpc_write_text_int64(len : longint;var t : text;i : int64); compilerproc;
  114. Procedure fpc_Write_Text_Float(rt,fixkomma,Len : Longint;var t : Text;r : ValReal); compilerproc;
  115. Procedure fpc_Write_Text_Boolean(Len : Longint;var t : Text;b : Boolean); compilerproc;
  116. Procedure fpc_Write_Text_Char(Len : Longint;var t : Text;c : Char); compilerproc;
  117. {$ifdef HASWIDECHAR}
  118. Procedure fpc_Write_Text_WideChar(Len : Longint;var t : Text;c : WideChar); compilerproc;
  119. {$endif HASWIDECHAR}
  120. Procedure fpc_Read_End(var f:Text); compilerproc;
  121. Procedure fpc_ReadLn_End(var f : Text); compilerproc;
  122. Procedure fpc_Read_Text_ShortStr(var f : Text;var s : String); compilerproc;
  123. Procedure fpc_Read_Text_PChar_As_Pointer(var f : Text;var s : PChar); compilerproc;
  124. Procedure fpc_Read_Text_PChar_As_Array(var f : Text;var s : array of char); compilerproc;
  125. Procedure fpc_Read_Text_AnsiStr(var f : Text;var s : AnsiString); compilerproc;
  126. Procedure fpc_Read_Text_Char(var f : Text; var c : char); compilerproc;
  127. Procedure fpc_Read_Text_SInt(var f : Text; var l :ValSInt); compilerproc;
  128. Procedure fpc_Read_Text_UInt(var f : Text; var u :ValUInt); compilerproc;
  129. Procedure fpc_Read_Text_Float(var f : Text; var v :ValReal); compilerproc;
  130. Procedure fpc_Read_Text_QWord(var f : text; var q : qword); compilerproc;
  131. Procedure fpc_Read_Text_Int64(var f : text; var i : int64); compilerproc;
  132. { from int64.inc }
  133. procedure fpc_shortstr_qword(v : qword;len : longint;var s : shortstring); compilerproc;
  134. procedure fpc_shortstr_int64(v : int64;len : longint;var s : shortstring); compilerproc;
  135. procedure fpc_ansistr_qword(v : qword;len : longint;var s : ansistring); compilerproc;
  136. procedure fpc_ansistr_int64(v : int64;len : longint;var s : ansistring); compilerproc;
  137. Function fpc_val_int64_shortstr(Const S: ShortString; var Code: ValSInt): Int64; compilerproc;
  138. Function fpc_val_qword_shortstr(Const S: ShortString; var Code: ValSInt): QWord; compilerproc;
  139. procedure fpc_widestr_qword(v : qword;len : longint;var s : widestring); compilerproc;
  140. procedure fpc_widestr_int64(v : int64;len : longint;var s : widestring); compilerproc;
  141. function fpc_do_is(aclass : tclass;aobject : tobject) : boolean; compilerproc;
  142. procedure fpc_do_as(aclass : tclass;aobject : tobject); compilerproc;
  143. procedure fpc_intf_decr_ref(var i: pointer); compilerproc;
  144. procedure fpc_intf_incr_ref(const i: pointer); compilerproc;
  145. procedure fpc_intf_assign(var D: pointer; const S: pointer); compilerproc;
  146. procedure fpc_intf_as(var D: pointer; const S: pointer; const iid: TGUID); compilerproc;
  147. Function fpc_PushExceptAddr (Ft: Longint;_buf,_newaddr : pointer): PJmp_buf ; compilerproc;
  148. Procedure fpc_PushExceptObj (Obj : TObject; AnAddr,AFrame : Pointer); compilerproc;
  149. Function fpc_Raiseexception (Obj : TObject; AnAddr,AFrame : Pointer) : TObject; compilerproc;
  150. Procedure fpc_PopAddrStack; compilerproc;
  151. function fpc_PopObjectStack : TObject; compilerproc;
  152. function fpc_PopSecondObjectStack : TObject; compilerproc;
  153. Procedure fpc_ReRaise; compilerproc;
  154. Function fpc_Catches(Objtype : TClass) : TObject; compilerproc;
  155. Procedure fpc_DestroyException(o : TObject); compilerproc;
  156. procedure fpc_help_constructor; compilerproc;
  157. procedure fpc_help_fail; compilerproc;
  158. procedure fpc_help_destructor; compilerproc;
  159. procedure fpc_new_class; compilerproc;
  160. procedure fpc_dispose_class; compilerproc;
  161. procedure fpc_help_fail_class; compilerproc;
  162. procedure fpc_check_object(obj : pointer); compilerproc;
  163. procedure fpc_check_object_ext; compilerproc;
  164. Procedure fpc_Initialize (Data,TypeInfo : pointer); compilerproc;
  165. Procedure fpc_Finalize (Data,TypeInfo: Pointer); compilerproc;
  166. Procedure fpc_Addref (Data,TypeInfo : Pointer); compilerproc;
  167. Procedure fpc_DecRef (Data,TypeInfo : Pointer); compilerproc;
  168. procedure fpc_FinalizeArray(data,typeinfo : pointer;count,size : longint); compilerproc;
  169. function fpc_set_load_small(l: fpc_small_set): fpc_normal_set; compilerproc;
  170. function fpc_set_create_element(b : byte): fpc_normal_set; compilerproc;
  171. function fpc_set_set_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
  172. function fpc_set_unset_byte(const source: fpc_normal_set; b : byte): fpc_normal_set; compilerproc;
  173. function fpc_set_set_range(const orgset: fpc_normal_set; l,h : byte): fpc_normal_set; compilerproc;
  174. function fpc_set_in_byte(const p: fpc_normal_set; b: byte): boolean; compilerproc;
  175. function fpc_set_add_sets(const set1,set2: fpc_normal_set): fpc_normal_set; compilerproc;
  176. function fpc_set_mul_sets(const set1,set2: fpc_normal_set): fpc_normal_set; compilerproc;
  177. function fpc_set_sub_sets(const set1,set2: fpc_normal_set): fpc_normal_set; compilerproc;
  178. function fpc_set_symdif_sets(const set1,set2: fpc_normal_set): fpc_normal_set; compilerproc;
  179. function fpc_set_comp_sets(const set1,set2: fpc_normal_set): boolean; compilerproc;
  180. function fpc_set_contains_sets(const set1,set2: fpc_normal_set): boolean; compilerproc;
  181. {$ifdef LARGESETS}
  182. procedure fpc_largeset_set_word(p : pointer;b : word); compilerproc;
  183. procedure fpc_largeset_in_word(p : pointer;b : word); compilerproc;
  184. procedure fpc_largeset_add_sets(set1,set2,dest : pointer;size : longint); compilerproc;
  185. procedure fpc_largeset_sets(set1,set2,dest : pointer;size : longint); compilerproc;
  186. procedure fpc_largeset_sub_sets(set1,set2,dest : pointer;size : longint); compilerproc;
  187. procedure fpc_largeset_symdif_sets(set1,set2,dest : pointer;size : longint); compilerproc;
  188. procedure fpc_largeset_comp_sets(set1,set2 : pointer;size : longint); compilerproc;
  189. procedure fpc_largeset_contains_sets(set1,set2 : pointer; size: longint); compilerproc;
  190. {$endif LARGESETS}
  191. procedure fpc_rangeerror; compilerproc;
  192. procedure fpc_overflow; compilerproc;
  193. procedure fpc_iocheck(addr : longint); compilerproc;
  194. procedure fpc_InitializeUnits; compilerproc;
  195. // not generated by compiler, called directly in system unit
  196. // procedure fpc_FinalizeUnits; compilerproc;
  197. {
  198. Procedure fpc_do_exit; compilerproc;
  199. Procedure fpc_lib_exit; compilerproc;
  200. Procedure fpc_HandleErrorAddrFrame (Errno : longint;addr,frame : longint); compilerproc;
  201. Procedure fpc_HandleError (Errno : longint); compilerproc;
  202. }
  203. procedure fpc_AbstractErrorIntern;compilerproc;
  204. procedure fpc_assert(Const Msg,FName:Shortstring;LineNo,ErrorAddr:Longint); compilerproc;
  205. Procedure fpc_reset_typed(var f : TypedFile;Size : Longint); compilerproc;
  206. Procedure fpc_rewrite_typed(var f : TypedFile;Size : Longint); compilerproc;
  207. Procedure fpc_typed_write(TypeSize : Longint;var f : TypedFile;const Buf); compilerproc;
  208. Procedure fpc_typed_read(TypeSize : Longint;var f : TypedFile;var Buf); compilerproc;
  209. {$endif hascompilerproc}
  210. {
  211. $Log$
  212. Revision 1.9 2001-09-04 11:38:55 jonas
  213. + searchsystype() and searchsystype() functions in symtable
  214. * changed ninl and nadd to use these functions
  215. * i386 set comparison functions now return their results in al instead
  216. of in the flags so that they can be sued as compilerprocs
  217. - removed all processor specific code from n386add.pas that has to do
  218. with set handling, it's now all done in nadd.pas
  219. * fixed fpc_set_contains_sets in genset.inc
  220. * fpc_set_in_byte is now coded inline in n386set.pas and doesn't use a
  221. helper anymore
  222. * some small fixes in compproc.inc/set.inc regarding the declaration of
  223. internal helper types (fpc_small_set and fpc_normal_set)
  224. Revision 1.8 2001/09/03 13:27:43 jonas
  225. * compilerproc implementation of set addition/substraction/...
  226. * changed the declaration of some set helpers somewhat to accomodate the
  227. above change
  228. * i386 still uses the old code for comparisons of sets, because its
  229. helpers return the results in the flags
  230. * dummy tc_normal_2_small_set type conversion because I need the original
  231. resulttype of the set add nodes
  232. NOTE: you have to start a cycle with 1.0.5!
  233. Revision 1.7 2001/08/30 15:43:15 jonas
  234. * converted adding/comparing of strings to compileproc. Note that due
  235. to the way the shortstring helpers for i386 are written, they are
  236. still handled by the old code (reason: fpc_shortstr_compare returns
  237. results in the flags instead of in eax and fpc_shortstr_concat
  238. has wierd parameter conventions). The compilerproc stuff should work
  239. fine with the generic implementations though.
  240. * removed some nested comments warnings
  241. Revision 1.6 2001/08/29 19:49:04 jonas
  242. * some fixes in compilerprocs for chararray to string conversions
  243. * conversion from string to chararray is now also done via compilerprocs
  244. Revision 1.5 2001/08/28 13:24:47 jonas
  245. + compilerproc implementation of most string-related type conversions
  246. - removed all code from the compiler which has been replaced by
  247. compilerproc implementations (using (ifdef hascompilerproc) is not
  248. necessary in the compiler)
  249. Revision 1.4 2001/08/23 14:28:36 jonas
  250. + tempcreate/ref/delete nodes (allows the use of temps in the
  251. resulttype and first pass)
  252. * made handling of read(ln)/write(ln) processor independent
  253. * moved processor independent handling for str and reset/rewrite-typed
  254. from firstpass to resulttype pass
  255. * changed names of helpers in text.inc to be generic for use as
  256. compilerprocs + added "iocheck" directive for most of them
  257. * reading of ordinals is done by procedures instead of functions
  258. because otherwise FPC_IOCHECK overwrote the result before it could
  259. be stored elsewhere (range checking still works)
  260. * compilerprocs can now be used in the system unit before they are
  261. implemented
  262. * added note to errore.msg that booleans can't be read using read/readln
  263. Revision 1.3 2001/08/13 12:40:16 jonas
  264. * renamed some str(x,y) and val(x,y) helpers so the naming scheme is the
  265. same for all string types
  266. + added the str(x,y) and val(x,y,z) helpers for int64/qword to
  267. compproc.inc
  268. Revision 1.2 2001/08/06 14:13:55 jonas
  269. * changed buf parameter of fpc_type_write from var to const
  270. + added names of helpers in typefile.inc to compproc.inc
  271. Revision 1.1 2001/08/01 15:00:10 jonas
  272. + "compproc" helpers
  273. * renamed several helpers so that their name is the same as their
  274. "public alias", which should facilitate the conversion of processor
  275. specific code in the code generator to processor independent code
  276. * some small fixes to the val_ansistring and val_widestring helpers
  277. (always immediately exit if the source string is longer than 255
  278. chars)
  279. * fixed fpc_dynarray_high and fpc_dynarray_length if the dynarray is
  280. still nil (used to crash, now return resp -1 and 0)
  281. }