comphook.pas 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  4. This unit handles the compilerhooks for output to external programs
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit comphook;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. finput;
  23. Const
  24. { <$10000 will show file and line }
  25. V_None = $0;
  26. V_Fatal = $1;
  27. V_Error = $2;
  28. V_Normal = $4; { doesn't show a text like Error: }
  29. V_Warning = $8;
  30. V_Note = $10;
  31. V_Hint = $20;
  32. V_Macro = $100;
  33. V_Procedure = $200;
  34. V_Conditional = $400;
  35. V_Assem = $800;
  36. V_Declarations = $1000;
  37. V_Info = $10000;
  38. V_Status = $20000;
  39. V_Used = $40000;
  40. V_Tried = $80000;
  41. V_Debug = $100000;
  42. V_Executable = $200000;
  43. V_ShowFile = $ffff;
  44. V_All = $ffffffff;
  45. V_Default = V_Fatal + V_Error + V_Normal;
  46. const
  47. { RHIDE expect gcc like error output }
  48. fatalstr : string[20] = 'Fatal:';
  49. errorstr : string[20] = 'Error:';
  50. warningstr : string[20] = 'Warning:';
  51. notestr : string[20] = 'Note:';
  52. hintstr : string[20] = 'Hint:';
  53. type
  54. PCompilerStatus = ^TCompilerStatus;
  55. TCompilerStatus = record
  56. { Current status }
  57. currentmodule,
  58. currentsourcepath,
  59. currentsource : string; { filename }
  60. currentline,
  61. currentcolumn : longint; { current line and column }
  62. { Total Status }
  63. compiledlines : longint; { the number of lines which are compiled }
  64. errorcount : longint; { number of generated errors }
  65. { Settings for the output }
  66. verbosity : longint;
  67. maxerrorcount : longint;
  68. errorwarning,
  69. errornote,
  70. errorhint,
  71. skip_error,
  72. use_stderr,
  73. use_redir,
  74. use_gccoutput : boolean;
  75. { Redirection support }
  76. redirfile : text;
  77. end;
  78. var
  79. status : tcompilerstatus;
  80. { Default Functions }
  81. procedure def_stop;
  82. procedure def_halt(i : longint);
  83. Function def_status:boolean;
  84. Function def_comment(Level:Longint;const s:string):boolean;
  85. function def_internalerror(i:longint):boolean;
  86. procedure def_initsymbolinfo;
  87. procedure def_donesymbolinfo;
  88. procedure def_extractsymbolinfo;
  89. function def_openinputfile(const filename: string): tinputfile;
  90. Function def_getnamedfiletime(Const F : String) : Longint;
  91. {$ifdef DEBUG}
  92. { allow easy stopping in GDB
  93. using
  94. b DEF_GDB_STOP
  95. cond 1 LEVEL <= 8 }
  96. procedure def_gdb_stop(level : longint);
  97. {$endif DEBUG}
  98. { Function redirecting for IDE support }
  99. type
  100. tstopprocedure = procedure;
  101. thaltprocedure = procedure(i : longint);
  102. tstatusfunction = function:boolean;
  103. tcommentfunction = function(Level:Longint;const s:string):boolean;
  104. tinternalerrorfunction = function(i:longint):boolean;
  105. tinitsymbolinfoproc = procedure;
  106. tdonesymbolinfoproc = procedure;
  107. textractsymbolinfoproc = procedure;
  108. topeninputfilefunc = function(const filename: string): tinputfile;
  109. tgetnamedfiletimefunc = function(const filename: string): longint;
  110. const
  111. do_stop : tstopprocedure = def_stop;
  112. do_halt : thaltprocedure = def_halt;
  113. do_status : tstatusfunction = def_status;
  114. do_comment : tcommentfunction = def_comment;
  115. do_internalerror : tinternalerrorfunction = def_internalerror;
  116. do_initsymbolinfo : tinitsymbolinfoproc = def_initsymbolinfo;
  117. do_donesymbolinfo : tdonesymbolinfoproc = def_donesymbolinfo;
  118. do_extractsymbolinfo : textractsymbolinfoproc = def_extractsymbolinfo;
  119. do_openinputfile : topeninputfilefunc = def_openinputfile;
  120. do_getnamedfiletime : tgetnamedfiletimefunc = def_getnamedfiletime;
  121. implementation
  122. uses
  123. {$ifdef delphi}
  124. dmisc
  125. {$else}
  126. dos
  127. {$endif}
  128. ;
  129. {****************************************************************************
  130. Helper Routines
  131. ****************************************************************************}
  132. function gccfilename(const s : string) : string;
  133. var
  134. i : longint;
  135. begin
  136. for i:=1to length(s) do
  137. begin
  138. case s[i] of
  139. '\' : gccfilename[i]:='/';
  140. 'A'..'Z' : gccfilename[i]:=chr(ord(s[i])+32);
  141. else
  142. gccfilename[i]:=s[i];
  143. end;
  144. end;
  145. gccfilename[0]:=s[0];
  146. end;
  147. function tostr(i : longint) : string;
  148. var
  149. hs : string;
  150. begin
  151. str(i,hs);
  152. tostr:=hs;
  153. end;
  154. {****************************************************************************
  155. Predefined default Handlers
  156. ****************************************************************************}
  157. { predefined handler when then compiler stops }
  158. procedure def_stop;
  159. begin
  160. Halt(1);
  161. end;
  162. {$ifdef DEBUG}
  163. { allow easy stopping in GDB
  164. using
  165. b DEF_GDB_STOP
  166. cond 1 LEVEL <= 8 }
  167. procedure def_gdb_stop(level : longint);
  168. begin
  169. { Its only a dummy for GDB }
  170. end;
  171. {$endif DEBUG}
  172. procedure def_halt(i : longint);
  173. begin
  174. halt(i);
  175. end;
  176. function def_status:boolean;
  177. begin
  178. def_status:=false; { never stop }
  179. { Status info?, Called every line }
  180. if ((status.verbosity and V_Status)<>0) then
  181. begin
  182. {$ifndef Delphi}
  183. if (status.compiledlines=1) then
  184. WriteLn(memavail shr 10,' Kb Free');
  185. {$endif Delphi}
  186. if (status.currentline>0) and (status.currentline mod 100=0) then
  187. {$ifdef FPC}
  188. WriteLn(status.currentline,' ',memavail shr 10,'/',system.heapsize shr 10,' Kb Free');
  189. {$else}
  190. {$ifndef Delphi}
  191. WriteLn(status.currentline,' ',memavail shr 10,' Kb Free');
  192. {$endif Delphi}
  193. {$endif}
  194. end
  195. end;
  196. Function def_comment(Level:Longint;const s:string):boolean;
  197. const
  198. rh_errorstr = 'error:';
  199. rh_warningstr = 'warning:';
  200. var
  201. hs : string;
  202. begin
  203. def_comment:=false; { never stop }
  204. hs:='';
  205. if not(status.use_gccoutput) then
  206. begin
  207. if (status.verbosity and Level)=V_Hint then
  208. hs:=hintstr;
  209. if (status.verbosity and Level)=V_Note then
  210. hs:=notestr;
  211. if (status.verbosity and Level)=V_Warning then
  212. hs:=warningstr;
  213. if (status.verbosity and Level)=V_Error then
  214. hs:=errorstr;
  215. if (status.verbosity and Level)=V_Fatal then
  216. hs:=fatalstr;
  217. end
  218. else
  219. begin
  220. if (status.verbosity and Level)=V_Hint then
  221. hs:=rh_warningstr;
  222. if (status.verbosity and Level)=V_Note then
  223. hs:=rh_warningstr;
  224. if (status.verbosity and Level)=V_Warning then
  225. hs:=rh_warningstr;
  226. if (status.verbosity and Level)=V_Error then
  227. hs:=rh_errorstr;
  228. if (status.verbosity and Level)=V_Fatal then
  229. hs:=rh_errorstr;
  230. end;
  231. if (Level<=V_ShowFile) and (status.currentsource<>'') and (status.currentline>0) then
  232. begin
  233. { Adding the column should not confuse RHIDE,
  234. even if it does not yet use it PM
  235. but only if it is after error or warning !! PM }
  236. if status.currentcolumn>0 then
  237. begin
  238. if status.use_gccoutput then
  239. hs:=gccfilename(status.currentsource)+':'+tostr(status.currentline)+': '+hs+' '+
  240. tostr(status.currentcolumn)+': '+s
  241. else
  242. hs:=status.currentsource+'('+tostr(status.currentline)+
  243. ','+tostr(status.currentcolumn)+') '+hs+' '+s;
  244. end
  245. else
  246. begin
  247. if status.use_gccoutput then
  248. hs:=gccfilename(status.currentsource)+': '+hs+' '+tostr(status.currentline)+': '+s
  249. else
  250. hs:=status.currentsource+'('+tostr(status.currentline)+') '+hs+' '+s;
  251. end;
  252. end
  253. else
  254. begin
  255. if hs<>'' then
  256. hs:=hs+' '+s
  257. else
  258. hs:=s;
  259. end;
  260. {$ifdef FPC}
  261. if status.use_stderr then
  262. begin
  263. writeln(stderr,hs);
  264. flush(stderr);
  265. end
  266. else
  267. {$endif}
  268. begin
  269. if status.use_redir then
  270. writeln(status.redirfile,hs)
  271. else
  272. writeln(hs);
  273. end;
  274. {$ifdef DEBUG}
  275. def_gdb_stop(level);
  276. {$endif DEBUG}
  277. end;
  278. function def_internalerror(i : longint) : boolean;
  279. begin
  280. do_comment(V_Fatal,'Internal error '+tostr(i));
  281. def_internalerror:=true;
  282. end;
  283. procedure def_initsymbolinfo;
  284. begin
  285. end;
  286. procedure def_donesymbolinfo;
  287. begin
  288. end;
  289. procedure def_extractsymbolinfo;
  290. begin
  291. end;
  292. function def_openinputfile(const filename: string): tinputfile;
  293. begin
  294. def_openinputfile:=tdosinputfile.create(filename);
  295. end;
  296. Function def_GetNamedFileTime (Const F : String) : Longint;
  297. var
  298. L : Longint;
  299. info : SearchRec;
  300. begin
  301. l:=-1;
  302. {$ifdef delphi}
  303. dmisc.FindFirst (F,archive+readonly+hidden,info);
  304. {$else delphi}
  305. FindFirst (F,archive+readonly+hidden,info);
  306. {$endif delphi}
  307. if DosError=0 then
  308. l:=info.time;
  309. FindClose(info);
  310. def_GetNamedFileTime:=l;
  311. end;
  312. end.
  313. {
  314. $Log$
  315. Revision 1.13 2001-02-05 20:47:00 peter
  316. * support linux unit for ver1_0 compilers
  317. Revision 1.12 2001/01/21 20:32:45 marco
  318. * Renamefest. Compiler part. Not that hard.
  319. Revision 1.11 2000/12/26 15:58:29 peter
  320. * check for verbosity in verbose instead of comphook
  321. Revision 1.10 2000/12/25 00:07:25 peter
  322. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  323. tlinkedlist objects)
  324. Revision 1.9 2000/11/13 15:26:12 marco
  325. * Renamefest
  326. Revision 1.8 2000/09/30 16:07:20 peter
  327. * prefix fix (merged)
  328. Revision 1.7 2000/09/24 21:33:46 peter
  329. * message updates merges
  330. Revision 1.6 2000/09/24 15:06:13 peter
  331. * use defines.inc
  332. Revision 1.5 2000/08/27 16:11:50 peter
  333. * moved some util functions from globals,cobjects to cutils
  334. * splitted files into finput,fmodule
  335. Revision 1.4 2000/08/13 13:04:15 peter
  336. * -vb update
  337. Revision 1.3 2000/08/12 15:30:45 peter
  338. * IDE patch for stream reading (merged)
  339. Revision 1.2 2000/07/13 11:32:38 michael
  340. + removed logs
  341. }