verbose.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  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_None = $0;
  32. V_Fatal = $1;
  33. V_Error = $2;
  34. V_Normal = $4; { doesn't show a text like Error: }
  35. V_Warning = $8;
  36. V_Note = $10;
  37. V_Hint = $20;
  38. V_Macro = $100;
  39. V_Procedure = $200;
  40. V_Conditional = $400;
  41. V_Assem = $800;
  42. V_Info = $10000;
  43. V_Status = $20000;
  44. V_Used = $40000;
  45. V_Tried = $80000;
  46. V_Debug = $100000;
  47. V_Declarations = $200000;
  48. V_Executable = $400000;
  49. V_ShowFile = $ffff;
  50. V_All = $ffffffff;
  51. V_Default = V_Fatal + V_Error + V_Normal;
  52. var
  53. msg : pmessage;
  54. procedure SetRedirectFile(const fn:string);
  55. function SetVerbosity(const s:string):boolean;
  56. procedure LoadMsgFile(const fn: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. if msg=nil then
  221. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  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. DefaultReplacements(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. DefaultReplacements(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 MessagePos(const pos:tfileposinfo;w:tmsgconst);
  386. var
  387. oldpos : tfileposinfo;
  388. begin
  389. oldpos:=aktfilepos;
  390. aktfilepos:=pos;
  391. Msg2Comment(msg^.Get(ord(w)));
  392. aktfilepos:=oldpos;
  393. end;
  394. procedure MessagePos1(const pos:tfileposinfo;w:tmsgconst;const s1:string);
  395. var
  396. oldpos : tfileposinfo;
  397. begin
  398. oldpos:=aktfilepos;
  399. aktfilepos:=pos;
  400. Msg2Comment(msg^.Get1(ord(w),s1));
  401. aktfilepos:=oldpos;
  402. end;
  403. procedure MessagePos2(const pos:tfileposinfo;w:tmsgconst;const s1,s2:string);
  404. var
  405. oldpos : tfileposinfo;
  406. begin
  407. oldpos:=aktfilepos;
  408. aktfilepos:=pos;
  409. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  410. aktfilepos:=oldpos;
  411. end;
  412. procedure MessagePos3(const pos:tfileposinfo;w:tmsgconst;const s1,s2,s3:string);
  413. var
  414. oldpos : tfileposinfo;
  415. begin
  416. oldpos:=aktfilepos;
  417. aktfilepos:=pos;
  418. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  419. aktfilepos:=oldpos;
  420. end;
  421. procedure InitVerbose;
  422. begin
  423. { Init }
  424. {$ifndef EXTERN_MSG}
  425. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  426. {$else}
  427. LoadMsgFile(exepath+'errore.msg');
  428. {$endif}
  429. FillChar(Status,sizeof(TCompilerStatus),0);
  430. status.verbosity:=V_Default;
  431. Status.MaxErrorCount:=50;
  432. end;
  433. procedure DoneVerbose;
  434. begin
  435. if assigned(msg) then
  436. begin
  437. dispose(msg,Done);
  438. msg:=nil;
  439. end;
  440. end;
  441. end.
  442. {
  443. $Log$
  444. Revision 1.48 2000-03-01 22:29:18 peter
  445. * message files are check for amount of msgs found. If not correct a
  446. line is written to stdout and switched to internal messages
  447. Revision 1.47 2000/03/01 21:45:42 peter
  448. * lowercase .INC -> .inc
  449. Revision 1.46 2000/02/28 17:23:57 daniel
  450. * Current work of symtable integration committed. The symtable can be
  451. activated by defining 'newst', but doesn't compile yet. Changes in type
  452. checking and oop are completed. What is left is to write a new
  453. symtablestack and adapt the parser to use it.
  454. Revision 1.45 2000/02/09 13:23:09 peter
  455. * log truncated
  456. Revision 1.44 2000/01/07 01:14:49 peter
  457. * updated copyright to 2000
  458. Revision 1.43 1999/11/06 14:34:32 peter
  459. * truncated log to 20 revs
  460. Revision 1.42 1999/08/05 16:53:28 peter
  461. * V_Fatal=1, all other V_ are also increased
  462. * Check for local procedure when assigning procvar
  463. * fixed comment parsing because directives
  464. * oldtp mode directives better supported
  465. * added some messages to errore.msg
  466. }