verbose.pas 16 KB

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