verbose.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. {
  2. $Id$
  3. Copyright (c) 1998 by the FPC development team
  4. This unit handles the verbose management
  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 verbose;
  19. interface
  20. uses
  21. messages;
  22. {$ifdef TP}
  23. {$define EXTERN_MSG}
  24. {$endif}
  25. {$ifndef EXTERN_MSG}
  26. {$i msgtxt.inc}
  27. {$endif}
  28. {$i msgidx.inc}
  29. Const
  30. { <$10000 will show file and line }
  31. V_Fatal = $0;
  32. V_Error = $1;
  33. V_Normal = $2; { doesn't show a text like Error: }
  34. V_Warning = $4;
  35. V_Note = $8;
  36. V_Hint = $10;
  37. V_Macro = $100;
  38. V_Procedure = $200;
  39. V_Conditional = $400;
  40. V_Info = $10000;
  41. V_Status = $20000;
  42. V_Used = $40000;
  43. V_Tried = $80000;
  44. V_Debug = $100000;
  45. V_Declarations = $200000;
  46. V_ShowFile = $ffff;
  47. V_All = $ffffffff;
  48. V_Default = V_Fatal + V_Error + V_Normal;
  49. var
  50. msg : pmessage;
  51. procedure SetRedirectFile(const fn:string);
  52. function SetVerbosity(const s:string):boolean;
  53. procedure LoadMsgFile(const fn:string);
  54. procedure UpdateReplacement(var s:string);
  55. procedure Stop;
  56. procedure ShowStatus;
  57. procedure Internalerror(i:longint);
  58. procedure Comment(l:longint;s:string);
  59. procedure Message(w:tmsgconst);
  60. procedure Message1(w:tmsgconst;const s1:string);
  61. procedure Message2(w:tmsgconst;const s1,s2:string);
  62. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  63. procedure InitVerbose;
  64. implementation
  65. uses
  66. files,comphook,
  67. globals;
  68. var
  69. redirexitsave : pointer;
  70. {****************************************************************************
  71. Extra Handlers for default compiler
  72. ****************************************************************************}
  73. procedure DoneRedirectFile;{$ifndef FPC}far;{$ENDIF}
  74. begin
  75. exitproc:=redirexitsave;
  76. if status.use_redir then
  77. close(status.redirfile);
  78. end;
  79. procedure SetRedirectFile(const fn:string);
  80. begin
  81. assign(status.redirfile,fn);
  82. {$I-}
  83. rewrite(status.redirfile);
  84. {$I+}
  85. status.use_redir:=(ioresult=0);
  86. if status.use_redir then
  87. begin
  88. redirexitsave:=exitproc;
  89. exitproc:=@DoneRedirectFile;
  90. end;
  91. end;
  92. function SetVerbosity(const s:string):boolean;
  93. var
  94. m : Longint;
  95. i : Word;
  96. inverse : boolean;
  97. c : char;
  98. begin
  99. Setverbosity:=false;
  100. val(s,m,i);
  101. if (i=0) and (s<>'') then
  102. status.verbosity:=m
  103. else
  104. begin
  105. for i:=1 to length(s) do
  106. begin
  107. c:=upcase(s[i]);
  108. inverse:=false;
  109. { on/off ? }
  110. if (i<length(s)) then
  111. case s[i+1] of
  112. '-' : begin
  113. inc(i);
  114. inverse:=true;
  115. end;
  116. '+' : inc(i);
  117. end;
  118. { handle switch }
  119. case c of
  120. { Special cases }
  121. 'A' : status.verbosity:=V_All;
  122. '0' : status.verbosity:=V_Default;
  123. 'R' : begin
  124. if inverse then
  125. begin
  126. status.use_gccoutput:=false;
  127. status.use_stderr:=false;
  128. end
  129. else
  130. begin
  131. status.use_gccoutput:=true;
  132. status.use_stderr:=true;
  133. end;
  134. end;
  135. { Normal cases - do an or }
  136. 'E' : if inverse then
  137. status.verbosity:=status.verbosity and (not V_Error)
  138. else
  139. status.verbosity:=status.verbosity or V_Error;
  140. 'I' : if inverse then
  141. status.verbosity:=status.verbosity and (not V_Info)
  142. else
  143. status.verbosity:=status.verbosity or V_Info;
  144. 'W' : if inverse then
  145. status.verbosity:=status.verbosity and (not V_Warning)
  146. else
  147. status.verbosity:=status.verbosity or V_Warning;
  148. 'N' : if inverse then
  149. status.verbosity:=status.verbosity and (not V_Note)
  150. else
  151. status.verbosity:=status.verbosity or V_Note;
  152. 'H' : if inverse then
  153. status.verbosity:=status.verbosity and (not V_Hint)
  154. else
  155. status.verbosity:=status.verbosity or V_Hint;
  156. 'L' : if inverse then
  157. status.verbosity:=status.verbosity and (not V_Status)
  158. else
  159. status.verbosity:=status.verbosity or V_Status;
  160. 'U' : if inverse then
  161. status.verbosity:=status.verbosity and (not V_Used)
  162. else
  163. status.verbosity:=status.verbosity or V_Used;
  164. 'T' : if inverse then
  165. status.verbosity:=status.verbosity and (not V_Tried)
  166. else
  167. status.verbosity:=status.verbosity or V_Tried;
  168. 'M' : if inverse then
  169. status.verbosity:=status.verbosity and (not V_Macro)
  170. else
  171. status.verbosity:=status.verbosity or V_Macro;
  172. 'P' : if inverse then
  173. status.verbosity:=status.verbosity and (not V_Procedure)
  174. else
  175. status.verbosity:=status.verbosity or V_Procedure;
  176. 'C' : if inverse then
  177. status.verbosity:=status.verbosity and (not V_Conditional)
  178. else
  179. status.verbosity:=status.verbosity or V_Conditional;
  180. 'D' : if inverse then
  181. status.verbosity:=status.verbosity and (not V_Debug)
  182. else
  183. status.verbosity:=status.verbosity or V_Debug;
  184. 'B' : if inverse then
  185. status.verbosity:=status.verbosity and (not V_Declarations)
  186. else
  187. status.verbosity:=status.verbosity or V_Declarations;
  188. end;
  189. end;
  190. end;
  191. if status.verbosity=0 then
  192. status.verbosity:=V_Default;
  193. setverbosity:=true;
  194. end;
  195. procedure LoadMsgFile(const fn:string);
  196. begin
  197. if not(msg=nil) then
  198. dispose(msg,Done);
  199. msg:=new(pmessage,InitExtern(fn,ord(endmsgconst)));
  200. end;
  201. procedure UpdateReplacement(var s:string);
  202. begin
  203. Replace(s,'$FPCVER',version_string);
  204. Replace(s,'$FPCDATE',date_string);
  205. Replace(s,'$FPCTARGET',target_string);
  206. end;
  207. var
  208. lastfileidx,
  209. lastmoduleidx : longint;
  210. Procedure UpdateStatus;
  211. begin
  212. { fix status }
  213. status.currentline:=aktfilepos.line;
  214. status.currentcolumn:=aktfilepos.column;
  215. if assigned(current_module) and
  216. ((current_module^.unit_index<>lastmoduleidx) or
  217. (aktfilepos.fileindex<>lastfileidx)) then
  218. begin
  219. status.currentsource:=current_module^.sourcefiles.get_file_name(aktfilepos.fileindex);
  220. lastmoduleidx:=current_module^.unit_index;
  221. { update lastfileidx only if name known PM }
  222. if status.currentsource<>'' then
  223. lastfileidx:=aktfilepos.fileindex
  224. else
  225. lastfileidx:=0;
  226. end;
  227. end;
  228. procedure stop;
  229. begin
  230. {$ifndef TP}
  231. do_stop();
  232. {$else}
  233. do_stop;
  234. {$endif}
  235. end;
  236. procedure ShowStatus;
  237. begin
  238. UpdateStatus;
  239. {$ifndef TP}
  240. if do_status() then
  241. stop;
  242. {$else}
  243. if do_status then
  244. stop;
  245. {$endif}
  246. end;
  247. procedure internalerror(i : longint);
  248. begin
  249. do_internalerror(i);
  250. stop;
  251. end;
  252. procedure Comment(l:longint;s:string);
  253. var
  254. dostop : boolean;
  255. begin
  256. dostop:=((l and V_Fatal)<>0);
  257. if (l and V_Error)<>0 then
  258. inc(status.errorcount);
  259. { Create status info }
  260. UpdateStatus;
  261. { Fix replacements }
  262. UpdateReplacement(s);
  263. { show comment }
  264. if do_comment(l,s) or dostop or (status.errorcount>=status.maxerrorcount) then
  265. stop
  266. end;
  267. Procedure Msg2Comment(s:string);
  268. var
  269. idx,i,v : longint;
  270. dostop : boolean;
  271. begin
  272. {Reset}
  273. dostop:=false;
  274. v:=0;
  275. {Parse options}
  276. idx:=pos('_',s);
  277. if idx=0 then
  278. v:=V_Normal
  279. else
  280. if (idx in [1..5]) then
  281. begin
  282. for i:=1 to idx do
  283. begin
  284. case upcase(s[i]) of
  285. 'F' : begin
  286. v:=v or V_Fatal;
  287. inc(status.errorcount);
  288. dostop:=true;
  289. end;
  290. 'E' : begin
  291. v:=v or V_Error;
  292. inc(status.errorcount);
  293. end;
  294. 'O' : v:=v or V_Normal;
  295. 'W' : v:=v or V_Warning;
  296. 'N' : v:=v or V_Note;
  297. 'H' : v:=v or V_Hint;
  298. 'I' : v:=v or V_Info;
  299. 'L' : v:=v or V_Status;
  300. 'U' : v:=v or V_Used;
  301. 'T' : v:=v or V_Tried;
  302. 'M' : v:=v or V_Macro;
  303. 'P' : v:=v or V_Procedure;
  304. 'C' : v:=v or V_Conditional;
  305. 'D' : v:=v or V_Debug;
  306. 'B' : v:=v or V_Declarations;
  307. 'S' : dostop:=true;
  308. '_' : ;
  309. end;
  310. end;
  311. end;
  312. Delete(s,1,idx);
  313. { fix status }
  314. UpdateStatus;
  315. { Fix replacements }
  316. UpdateReplacement(s);
  317. { show comment }
  318. if do_comment(v,s) or dostop or (status.errorcount>=status.maxerrorcount) then
  319. stop;
  320. end;
  321. procedure Message(w:tmsgconst);
  322. begin
  323. Msg2Comment(msg^.Get(ord(w)));
  324. end;
  325. procedure Message1(w:tmsgconst;const s1:string);
  326. begin
  327. Msg2Comment(msg^.Get1(ord(w),s1));
  328. end;
  329. procedure Message2(w:tmsgconst;const s1,s2:string);
  330. begin
  331. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  332. end;
  333. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  334. begin
  335. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  336. end;
  337. procedure InitVerbose;
  338. begin
  339. { Init }
  340. FillChar(Status,sizeof(TCompilerStatus),0);
  341. status.verbosity:=V_Default;
  342. Status.MaxErrorCount:=50;
  343. end;
  344. begin
  345. {$ifndef EXTERN_MSG}
  346. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  347. {$else}
  348. LoadMsgFile(exepath+'errore.msg');
  349. {$endif}
  350. end.
  351. {
  352. $Log$
  353. Revision 1.20 1998-09-05 22:11:06 florian
  354. + switch -vb
  355. * while/repeat loops accept now also word/longbool conditions
  356. * makebooltojump did an invalid ungetregister32, fixed
  357. Revision 1.19 1998/09/01 12:49:52 peter
  358. * better setverbosity to support W+/W- etc.
  359. Revision 1.18 1998/08/29 13:52:40 peter
  360. + new messagefile
  361. * merged optione.msg into errore.msg
  362. Revision 1.17 1998/08/19 14:57:52 peter
  363. * small fix for aktfilepos
  364. Revision 1.16 1998/08/18 14:17:15 pierre
  365. * bug about assigning the return value of a function to
  366. a procvar fixed : warning
  367. assigning a proc to a procvar need @ in FPC mode !!
  368. * missing file/line info restored
  369. Revision 1.15 1998/08/18 09:24:49 pierre
  370. * small warning position bug fixed
  371. * support_mmx switches splitting was missing
  372. * rhide error and warning output corrected
  373. Revision 1.14 1998/08/11 14:09:15 peter
  374. * fixed some messages and smaller msgtxt.inc
  375. Revision 1.13 1998/08/10 14:50:37 peter
  376. + localswitches, moduleswitches, globalswitches splitting
  377. Revision 1.12 1998/08/10 10:18:37 peter
  378. + Compiler,Comphook unit which are the new interface units to the
  379. compiler
  380. Revision 1.11 1998/07/14 14:47:13 peter
  381. * released NEWINPUT
  382. Revision 1.10 1998/07/07 12:32:56 peter
  383. * status.currentsource is now calculated in verbose (more accurated)
  384. Revision 1.9 1998/07/07 11:20:20 peter
  385. + NEWINPUT for a better inputfile and scanner object
  386. Revision 1.8 1998/05/23 01:21:35 peter
  387. + aktasmmode, aktoptprocessor, aktoutputformat
  388. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  389. + $LIBNAME to set the library name where the unit will be put in
  390. * splitted cgi386 a bit (codeseg to large for bp7)
  391. * nasm, tasm works again. nasm moved to ag386nsm.pas
  392. Revision 1.7 1998/05/21 19:33:40 peter
  393. + better procedure directive handling and only one table
  394. Revision 1.6 1998/05/12 10:47:01 peter
  395. * moved printstatus to verb_def
  396. + V_Normal which is between V_Error and V_Warning and doesn't have a
  397. prefix like error: warning: and is included in V_Default
  398. * fixed some messages
  399. * first time parameter scan is only for -v and -T
  400. - removed old style messages
  401. Revision 1.5 1998/04/30 15:59:43 pierre
  402. * GDB works again better :
  403. correct type info in one pass
  404. + UseTokenInfo for better source position
  405. * fixed one remaining bug in scanner for line counts
  406. * several little fixes
  407. Revision 1.4 1998/04/23 12:11:22 peter
  408. * fixed -v0 to displayV_Default (=errors+fatals)
  409. Revision 1.3 1998/04/13 21:15:42 florian
  410. * error handling of pass_1 and cgi386 fixed
  411. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  412. fixed, verified
  413. }