verbose.pas 17 KB

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