comphook.pas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. {
  2. $Id$
  3. Fake comphook unit
  4. }
  5. unit comphook;
  6. interface
  7. Const
  8. { <$10000 will show file and line }
  9. V_Fatal = $0;
  10. V_Error = $1;
  11. V_Normal = $2; { doesn't show a text like Error: }
  12. V_Warning = $4;
  13. V_Note = $8;
  14. V_Hint = $10;
  15. V_Macro = $100;
  16. V_Procedure = $200;
  17. V_Conditional = $400;
  18. V_Info = $10000;
  19. V_Status = $20000;
  20. V_Used = $40000;
  21. V_Tried = $80000;
  22. V_Debug = $100000;
  23. V_ShowFile = $ffff;
  24. V_All = $ffffffff;
  25. V_Default = V_Fatal + V_Error + V_Normal;
  26. type
  27. PCompilerStatus = ^TCompilerStatus;
  28. TCompilerStatus = record
  29. { Current status }
  30. currentmodule,
  31. currentsourcepath,
  32. currentsource : string; { filename }
  33. currentline,
  34. currentcolumn : longint; { current line and column }
  35. { Total Status }
  36. compiledlines : longint; { the number of lines which are compiled }
  37. errorcount : longint; { number of generated errors }
  38. { Settings for the output }
  39. verbosity : longint;
  40. maxerrorcount : longint;
  41. skip_error,
  42. use_stderr,
  43. use_redir,
  44. use_gccoutput : boolean;
  45. { Redirection support }
  46. redirfile : text;
  47. end;
  48. var
  49. status : tcompilerstatus;
  50. { Default Functions }
  51. procedure def_stop;
  52. Function def_status:boolean;
  53. Function def_comment(Level:Longint;const s:string):boolean;
  54. function def_internalerror(i:longint):boolean;
  55. { Function redirecting for IDE support }
  56. type
  57. tstopprocedure = procedure;
  58. tstatusfunction = function:boolean;
  59. tcommentfunction = function(Level:Longint;const s:string):boolean;
  60. tinternalerrorfunction = function(i:longint):boolean;
  61. const
  62. do_stop : tstopprocedure = def_stop;
  63. do_status : tstatusfunction = def_status;
  64. do_comment : tcommentfunction = def_comment;
  65. do_internalerror : tinternalerrorfunction = def_internalerror;
  66. implementation
  67. {$ifdef USEEXCEPT}
  68. uses tpexcept;
  69. {$endif USEEXCEPT}
  70. {****************************************************************************
  71. Helper Routines
  72. ****************************************************************************}
  73. function gccfilename(const s : string) : string;
  74. var
  75. i : longint;
  76. begin
  77. for i:=1to length(s) do
  78. begin
  79. case s[i] of
  80. '\' : gccfilename[i]:='/';
  81. 'A'..'Z' : gccfilename[i]:=chr(ord(s[i])+32);
  82. else
  83. gccfilename[i]:=s[i];
  84. end;
  85. end;
  86. {$ifndef TP}
  87. {$ifopt H+}
  88. setlength(gccfilename,length(s));
  89. {$else}
  90. gccfilename[0]:=s[0];
  91. {$endif}
  92. {$else}
  93. gccfilename[0]:=s[0];
  94. {$endif}
  95. end;
  96. function tostr(i : longint) : string;
  97. var
  98. hs : string;
  99. begin
  100. str(i,hs);
  101. tostr:=hs;
  102. end;
  103. {****************************************************************************
  104. Predefined default Handlers
  105. ****************************************************************************}
  106. { predefined handler when then compiler stops }
  107. procedure def_stop;
  108. begin
  109. {$ifndef USEEXCEPT}
  110. Halt(1);
  111. {$else USEEXCEPT}
  112. Halt(1);
  113. {$endif USEEXCEPT}
  114. end;
  115. function def_status:boolean;
  116. begin
  117. def_status:=false; { never stop }
  118. { Status info?, Called every line }
  119. if ((status.verbosity and V_Status)<>0) then
  120. begin
  121. if (status.compiledlines=1) then
  122. WriteLn(memavail shr 10,' Kb Free');
  123. if (status.currentline>0) and (status.currentline mod 100=0) then
  124. {$ifdef FPC}
  125. WriteLn(status.currentline,' ',memavail shr 10,'/',system.heapsize shr 10,' Kb Free');
  126. {$else}
  127. WriteLn(status.currentline,' ',memavail shr 10,' Kb Free');
  128. {$endif}
  129. end
  130. end;
  131. Function def_comment(Level:Longint;const s:string):boolean;
  132. const
  133. { RHIDE expect gcc like error output }
  134. rh_errorstr='error: ';
  135. rh_warningstr='warning: ';
  136. fatalstr='Fatal: ';
  137. errorstr='Error: ';
  138. warningstr='Warning: ';
  139. notestr='Note: ';
  140. hintstr='Hint: ';
  141. var
  142. hs : string;
  143. begin
  144. def_comment:=false; { never stop }
  145. if (status.verbosity and Level)=Level then
  146. begin
  147. hs:='';
  148. if not(status.use_gccoutput) then
  149. begin
  150. if (status.verbosity and Level)=V_Hint then
  151. hs:=hintstr;
  152. if (status.verbosity and Level)=V_Note then
  153. hs:=notestr;
  154. if (status.verbosity and Level)=V_Warning then
  155. hs:=warningstr;
  156. if (status.verbosity and Level)=V_Error then
  157. hs:=errorstr;
  158. if (status.verbosity and Level)=V_Fatal then
  159. hs:=fatalstr;
  160. end
  161. else
  162. begin
  163. if (status.verbosity and Level)=V_Hint then
  164. hs:=rh_warningstr;
  165. if (status.verbosity and Level)=V_Note then
  166. hs:=rh_warningstr;
  167. if (status.verbosity and Level)=V_Warning then
  168. hs:=rh_warningstr;
  169. if (status.verbosity and Level)=V_Error then
  170. hs:=rh_errorstr;
  171. if (status.verbosity and Level)=V_Fatal then
  172. hs:=rh_errorstr;
  173. end;
  174. if (Level<=V_ShowFile) and (status.currentsource<>'') and (status.currentline>0) then
  175. begin
  176. { Adding the column should not confuse RHIDE,
  177. even if it does not yet use it PM
  178. but only if it is after error or warning !! PM }
  179. if status.currentcolumn>0 then
  180. begin
  181. if status.use_gccoutput then
  182. hs:=gccfilename(status.currentsource)+':'+tostr(status.currentline)+': '+hs
  183. +tostr(status.currentcolumn)+': '
  184. else
  185. hs:=status.currentsource+'('+tostr(status.currentline)
  186. +','+tostr(status.currentcolumn)+') '+hs;
  187. end
  188. else
  189. begin
  190. if status.use_gccoutput then
  191. hs:=gccfilename(status.currentsource)+': '+hs+tostr(status.currentline)+': '
  192. else
  193. hs:=status.currentsource+'('+tostr(status.currentline)+') '+hs;
  194. end;
  195. end;
  196. { add the message to the text }
  197. hs:=hs+s;
  198. {$ifdef FPC}
  199. if status.use_stderr then
  200. begin
  201. writeln(stderr,hs);
  202. flush(stderr);
  203. end
  204. else
  205. {$endif}
  206. begin
  207. if status.use_redir then
  208. writeln(status.redirfile,hs)
  209. else
  210. writeln(hs);
  211. end;
  212. end;
  213. end;
  214. function def_internalerror(i : longint) : boolean;
  215. begin
  216. do_comment(V_Fatal,'Internal error '+tostr(i));
  217. def_internalerror:=true;
  218. end;
  219. end.
  220. {
  221. $Log$
  222. Revision 1.1 2000-07-13 09:48:33 michael
  223. + Initial import
  224. Revision 1.1 1999/01/28 19:56:12 peter
  225. * moved to include compiler/gdb independent of each other
  226. Revision 1.2 1999/01/14 21:43:08 peter
  227. + status.currentsourcepath
  228. Revision 1.1 1998/12/22 14:27:54 peter
  229. * moved
  230. Revision 1.1 1998/12/10 23:54:28 peter
  231. * initial version of the FV IDE
  232. * initial version of a fake compiler
  233. }