verbose.pas 18 KB

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