verbose.pas 15 KB

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