verbose.pas 17 KB

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