verbose.pas 18 KB

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