verbose.pas 14 KB

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