verbose.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. version,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. UpdateStatus;
  256. do_internalerror(i);
  257. inc(status.errorcount);
  258. stop;
  259. end;
  260. procedure Comment(l:longint;s:string);
  261. var
  262. dostop : boolean;
  263. begin
  264. dostop:=((l and V_Fatal)<>0);
  265. if (l and V_Error)<>0 then
  266. inc(status.errorcount);
  267. { Create status info }
  268. UpdateStatus;
  269. { Fix replacements }
  270. UpdateReplacement(s);
  271. { show comment }
  272. if do_comment(l,s) or dostop then
  273. stop;
  274. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  275. begin
  276. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  277. status.skip_error:=true;
  278. stop;
  279. end;
  280. end;
  281. Procedure Msg2Comment(s:string);
  282. var
  283. idx,i,v : longint;
  284. dostop : boolean;
  285. begin
  286. {Reset}
  287. dostop:=false;
  288. v:=0;
  289. {Parse options}
  290. idx:=pos('_',s);
  291. if idx=0 then
  292. v:=V_Normal
  293. else
  294. if (idx >= 1) And (idx <= 5) then
  295. begin
  296. for i:=1 to idx do
  297. begin
  298. case upcase(s[i]) of
  299. 'F' : begin
  300. v:=v or V_Fatal;
  301. inc(status.errorcount);
  302. dostop:=true;
  303. end;
  304. 'E' : begin
  305. v:=v or V_Error;
  306. inc(status.errorcount);
  307. end;
  308. 'O' : v:=v or V_Normal;
  309. 'W' : v:=v or V_Warning;
  310. 'N' : v:=v or V_Note;
  311. 'H' : v:=v or V_Hint;
  312. 'I' : v:=v or V_Info;
  313. 'L' : v:=v or V_Status;
  314. 'U' : v:=v or V_Used;
  315. 'T' : v:=v or V_Tried;
  316. 'M' : v:=v or V_Macro;
  317. 'P' : v:=v or V_Procedure;
  318. 'C' : v:=v or V_Conditional;
  319. 'D' : v:=v or V_Debug;
  320. 'B' : v:=v or V_Declarations;
  321. 'X' : v:=v or V_Executable;
  322. 'S' : dostop:=true;
  323. '_' : ;
  324. end;
  325. end;
  326. end;
  327. Delete(s,1,idx);
  328. { fix status }
  329. UpdateStatus;
  330. { Fix replacements }
  331. UpdateReplacement(s);
  332. { show comment }
  333. if do_comment(v,s) or dostop then
  334. stop;
  335. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  336. begin
  337. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  338. status.skip_error:=true;
  339. stop;
  340. end;
  341. end;
  342. procedure Message(w:tmsgconst);
  343. begin
  344. Msg2Comment(msg^.Get(ord(w)));
  345. end;
  346. procedure Message1(w:tmsgconst;const s1:string);
  347. begin
  348. Msg2Comment(msg^.Get1(ord(w),s1));
  349. end;
  350. procedure Message2(w:tmsgconst;const s1,s2:string);
  351. begin
  352. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  353. end;
  354. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  355. begin
  356. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  357. end;
  358. procedure InitVerbose;
  359. begin
  360. { Init }
  361. {$ifndef EXTERN_MSG}
  362. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  363. {$else}
  364. LoadMsgFile(exepath+'errore.msg');
  365. {$endif}
  366. FillChar(Status,sizeof(TCompilerStatus),0);
  367. status.verbosity:=V_Default;
  368. Status.MaxErrorCount:=50;
  369. end;
  370. procedure DoneVerbose;
  371. begin
  372. if not(msg=nil) then
  373. dispose(msg,Done);
  374. end;
  375. end.
  376. {
  377. $Log$
  378. Revision 1.31 1998-12-11 00:04:04 peter
  379. + globtype,tokens,version unit splitted from globals
  380. Revision 1.30 1998/12/02 16:23:38 jonas
  381. * changed "if longintvar in set" to case or "if () or () .." statements
  382. * tree.pas: changed inlinenumber (and associated constructor/vars) to a byte
  383. Revision 1.29 1998/11/26 13:08:19 peter
  384. * update status also for internalerrors
  385. Revision 1.28 1998/11/06 09:45:41 pierre
  386. * bug on errors (file used after dispose !) fixed
  387. Revision 1.27 1998/10/28 18:26:24 pierre
  388. * removed some erros after other errors (introduced by useexcept)
  389. * stabs works again correctly (for how long !)
  390. Revision 1.26 1998/10/27 13:45:38 pierre
  391. * classes get a vmt allways
  392. * better error info (tried to remove
  393. several error strings introduced by the tpexcept handling)
  394. Revision 1.25 1998/10/22 15:18:49 florian
  395. + switch -vx for win32 added
  396. Revision 1.24 1998/10/08 17:17:39 pierre
  397. * current_module old scanner tagged as invalid if unit is recompiled
  398. + added ppheap for better info on tracegetmem of heaptrc
  399. (adds line column and file index)
  400. * several memory leaks removed ith help of heaptrc !!
  401. Revision 1.23 1998/10/06 17:17:01 pierre
  402. * some memory leaks fixed (thanks to Peter for heaptrc !)
  403. Revision 1.22 1998/10/05 13:51:36 peter
  404. * if maxerrorcount is reached display a msg
  405. Revision 1.21 1998/09/28 16:57:30 pierre
  406. * changed all length(p^.value_str^) into str_length(p)
  407. to get it work with and without ansistrings
  408. * changed sourcefiles field of tmodule to a pointer
  409. Revision 1.20 1998/09/05 22:11:06 florian
  410. + switch -vb
  411. * while/repeat loops accept now also word/longbool conditions
  412. * makebooltojump did an invalid ungetregister32, fixed
  413. Revision 1.19 1998/09/01 12:49:52 peter
  414. * better setverbosity to support W+/W- etc.
  415. Revision 1.18 1998/08/29 13:52:40 peter
  416. + new messagefile
  417. * merged optione.msg into errore.msg
  418. Revision 1.17 1998/08/19 14:57:52 peter
  419. * small fix for aktfilepos
  420. Revision 1.16 1998/08/18 14:17:15 pierre
  421. * bug about assigning the return value of a function to
  422. a procvar fixed : warning
  423. assigning a proc to a procvar need @ in FPC mode !!
  424. * missing file/line info restored
  425. Revision 1.15 1998/08/18 09:24:49 pierre
  426. * small warning position bug fixed
  427. * support_mmx switches splitting was missing
  428. * rhide error and warning output corrected
  429. Revision 1.14 1998/08/11 14:09:15 peter
  430. * fixed some messages and smaller msgtxt.inc
  431. Revision 1.13 1998/08/10 14:50:37 peter
  432. + localswitches, moduleswitches, globalswitches splitting
  433. Revision 1.12 1998/08/10 10:18:37 peter
  434. + Compiler,Comphook unit which are the new interface units to the
  435. compiler
  436. Revision 1.11 1998/07/14 14:47:13 peter
  437. * released NEWINPUT
  438. Revision 1.10 1998/07/07 12:32:56 peter
  439. * status.currentsource is now calculated in verbose (more accurated)
  440. Revision 1.9 1998/07/07 11:20:20 peter
  441. + NEWINPUT for a better inputfile and scanner object
  442. Revision 1.8 1998/05/23 01:21:35 peter
  443. + aktasmmode, aktoptprocessor, aktoutputformat
  444. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  445. + $LIBNAME to set the library name where the unit will be put in
  446. * splitted cgi386 a bit (codeseg to large for bp7)
  447. * nasm, tasm works again. nasm moved to ag386nsm.pas
  448. Revision 1.7 1998/05/21 19:33:40 peter
  449. + better procedure directive handling and only one table
  450. Revision 1.6 1998/05/12 10:47:01 peter
  451. * moved printstatus to verb_def
  452. + V_Normal which is between V_Error and V_Warning and doesn't have a
  453. prefix like error: warning: and is included in V_Default
  454. * fixed some messages
  455. * first time parameter scan is only for -v and -T
  456. - removed old style messages
  457. Revision 1.5 1998/04/30 15:59:43 pierre
  458. * GDB works again better :
  459. correct type info in one pass
  460. + UseTokenInfo for better source position
  461. * fixed one remaining bug in scanner for line counts
  462. * several little fixes
  463. Revision 1.4 1998/04/23 12:11:22 peter
  464. * fixed -v0 to displayV_Default (=errors+fatals)
  465. Revision 1.3 1998/04/13 21:15:42 florian
  466. * error handling of pass_1 and cgi386 fixed
  467. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  468. fixed, verified
  469. }