verbose.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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 messages;
  21. {$ifndef TP}
  22. {$ifndef EXTERN_MSG}
  23. {$i msgtxt.inc}
  24. {$endif}
  25. {$endif}
  26. {$i msgidx.inc}
  27. Const
  28. { <$10000 will show file and line }
  29. V_Fatal = $0;
  30. V_Error = $1;
  31. V_Normal = $2; { doesn't show a text like Error: }
  32. V_Warning = $4;
  33. V_Note = $8;
  34. V_Hint = $10;
  35. V_Macro = $100;
  36. V_Procedure = $200;
  37. V_Conditional = $400;
  38. V_Info = $10000;
  39. V_Status = $20000;
  40. V_Used = $40000;
  41. V_Tried = $80000;
  42. V_Debug = $100000;
  43. V_ShowFile = $ffff;
  44. V_All = $ffffffff;
  45. V_Default = V_Fatal + V_Error + V_Normal;
  46. var
  47. msg : pmessage;
  48. procedure SetRedirectFile(const fn:string);
  49. function SetVerbosity(const s:string):boolean;
  50. procedure LoadMsgFile(const fn:string);
  51. procedure Stop;
  52. procedure ShowStatus;
  53. procedure Internalerror(i:longint);
  54. procedure Comment(l:longint;const s:string);
  55. procedure Message(w:tmsgconst);
  56. procedure Message1(w:tmsgconst;const s1:string);
  57. procedure Message2(w:tmsgconst;const s1,s2:string);
  58. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  59. procedure InitVerbose;
  60. implementation
  61. uses
  62. files,comphook,
  63. globals;
  64. var
  65. redirexitsave : pointer;
  66. {****************************************************************************
  67. Extra Handlers for default compiler
  68. ****************************************************************************}
  69. procedure DoneRedirectFile;{$ifndef FPC}far;{$ENDIF}
  70. begin
  71. exitproc:=redirexitsave;
  72. if status.use_redir then
  73. close(status.redirfile);
  74. end;
  75. procedure SetRedirectFile(const fn:string);
  76. begin
  77. assign(status.redirfile,fn);
  78. {$I-}
  79. rewrite(status.redirfile);
  80. {$I+}
  81. status.use_redir:=(ioresult=0);
  82. if status.use_redir then
  83. begin
  84. redirexitsave:=exitproc;
  85. exitproc:=@DoneRedirectFile;
  86. end;
  87. end;
  88. function SetVerbosity(const s:string):boolean;
  89. var
  90. m : Longint;
  91. i : Word;
  92. inverse : boolean;
  93. c : char;
  94. begin
  95. Setverbosity:=false;
  96. val(s,m,i);
  97. if (i=0) and (s<>'') then
  98. status.verbosity:=m
  99. else
  100. begin
  101. for i:=1 to length(s) do
  102. begin
  103. c:=s[i];
  104. if (i<length(s)) and (s[i+1]='-') then
  105. begin
  106. inc(i);
  107. inverse:=true;
  108. end
  109. else
  110. inverse:=false;
  111. case upcase(s[i]) of
  112. { Special cases }
  113. 'A' : status.verbosity:=V_All;
  114. '0' : status.verbosity:=V_Default;
  115. 'R' : begin
  116. if inverse then
  117. begin
  118. status.use_gccoutput:=false;
  119. status.use_stderr:=false;
  120. end
  121. else
  122. begin
  123. status.use_gccoutput:=true;
  124. status.use_stderr:=true;
  125. end;
  126. end;
  127. { Normal cases - do an or }
  128. 'E' : if inverse then
  129. status.verbosity:=status.verbosity and (not V_Error)
  130. else
  131. status.verbosity:=status.verbosity or V_Error;
  132. 'I' : if inverse then
  133. status.verbosity:=status.verbosity and (not V_Info)
  134. else
  135. status.verbosity:=status.verbosity or V_Info;
  136. 'W' : if inverse then
  137. status.verbosity:=status.verbosity and (not V_Warning)
  138. else
  139. status.verbosity:=status.verbosity or V_Warning;
  140. 'N' : if inverse then
  141. status.verbosity:=status.verbosity and (not V_Note)
  142. else
  143. status.verbosity:=status.verbosity or V_Note;
  144. 'H' : if inverse then
  145. status.verbosity:=status.verbosity and (not V_Hint)
  146. else
  147. status.verbosity:=status.verbosity or V_Hint;
  148. 'L' : if inverse then
  149. status.verbosity:=status.verbosity and (not V_Status)
  150. else
  151. status.verbosity:=status.verbosity or V_Status;
  152. 'U' : if inverse then
  153. status.verbosity:=status.verbosity and (not V_Used)
  154. else
  155. status.verbosity:=status.verbosity or V_Used;
  156. 'T' : if inverse then
  157. status.verbosity:=status.verbosity and (not V_Tried)
  158. else
  159. status.verbosity:=status.verbosity or V_Tried;
  160. 'M' : if inverse then
  161. status.verbosity:=status.verbosity and (not V_Macro)
  162. else
  163. status.verbosity:=status.verbosity or V_Macro;
  164. 'P' : if inverse then
  165. status.verbosity:=status.verbosity and (not V_Procedure)
  166. else
  167. status.verbosity:=status.verbosity or V_Procedure;
  168. 'C' : if inverse then
  169. status.verbosity:=status.verbosity and (not V_Conditional)
  170. else
  171. status.verbosity:=status.verbosity or V_Conditional;
  172. 'D' : if inverse then
  173. status.verbosity:=status.verbosity and (not V_Debug)
  174. else
  175. status.verbosity:=status.verbosity or V_Debug;
  176. end;
  177. end;
  178. end;
  179. if status.verbosity=0 then
  180. status.verbosity:=V_Default;
  181. setverbosity:=true;
  182. end;
  183. procedure LoadMsgFile(const fn:string);
  184. begin
  185. if not (msg=nil) then
  186. dispose(msg,Done);
  187. msg:=new(pmessage,InitExtern(fn,ord(endmsgconst)));
  188. end;
  189. var
  190. lastfileidx,
  191. lastmoduleidx : longint;
  192. Procedure UpdateStatus;
  193. begin
  194. { fix status }
  195. status.currentline:=aktfilepos.line;
  196. status.currentcolumn:=aktfilepos.column;
  197. if assigned(current_module) and
  198. ((current_module^.unit_index<>lastmoduleidx) or
  199. (aktfilepos.fileindex<>lastfileidx)) then
  200. begin
  201. status.currentsource:=current_module^.sourcefiles.get_file_name(aktfilepos.fileindex);
  202. lastmoduleidx:=current_module^.unit_index;
  203. lastfileidx:=aktfilepos.fileindex;
  204. end;
  205. end;
  206. procedure stop;
  207. begin
  208. {$ifndef TP}
  209. do_stop();
  210. {$else}
  211. do_stop;
  212. {$endif}
  213. end;
  214. procedure ShowStatus;
  215. begin
  216. UpdateStatus;
  217. {$ifndef TP}
  218. if do_status() then
  219. stop;
  220. {$else}
  221. if do_status then
  222. stop;
  223. {$endif}
  224. end;
  225. procedure internalerror(i : longint);
  226. begin
  227. do_internalerror(i);
  228. stop;
  229. end;
  230. procedure Comment(l:longint;const s:string);
  231. var
  232. dostop : boolean;
  233. begin
  234. dostop:=((l and V_Fatal)<>0);
  235. if (l and V_Error)<>0 then
  236. inc(status.errorcount);
  237. { Create status info }
  238. UpdateStatus;
  239. { show comment }
  240. if do_comment(l,s) or dostop or (status.errorcount>=status.maxerrorcount) then
  241. stop
  242. end;
  243. Procedure Msg2Comment(s:string);
  244. var
  245. idx,i,v : longint;
  246. dostop : boolean;
  247. begin
  248. {Reset}
  249. dostop:=false;
  250. v:=0;
  251. {Parse options}
  252. idx:=pos('_',s);
  253. if idx=0 then
  254. v:=V_Default
  255. else
  256. if (idx in [1..5]) then
  257. begin
  258. for i:=1 to idx do
  259. begin
  260. case upcase(s[i]) of
  261. 'F' : begin
  262. v:=v or V_Fatal;
  263. inc(status.errorcount);
  264. dostop:=true;
  265. end;
  266. 'E' : begin
  267. v:=v or V_Error;
  268. inc(status.errorcount);
  269. end;
  270. 'O' : v:=v or V_Normal;
  271. 'W' : v:=v or V_Warning;
  272. 'N' : v:=v or V_Note;
  273. 'H' : v:=v or V_Hint;
  274. 'I' : v:=v or V_Info;
  275. 'L' : v:=v or V_Status;
  276. 'U' : v:=v or V_Used;
  277. 'T' : v:=v or V_Tried;
  278. 'M' : v:=v or V_Macro;
  279. 'P' : v:=v or V_Procedure;
  280. 'C' : v:=v or V_Conditional;
  281. 'D' : v:=v or V_Debug;
  282. 'S' : dostop:=true;
  283. '_' : ;
  284. end;
  285. end;
  286. end;
  287. Delete(s,1,idx);
  288. Replace(s,'$VER',version_string);
  289. Replace(s,'$TARGET',target_string);
  290. { fix status }
  291. status.currentline:=aktfilepos.line;
  292. status.currentcolumn:=aktfilepos.column;
  293. if assigned(current_module) and
  294. ((current_module^.unit_index<>lastmoduleidx) or
  295. (aktfilepos.fileindex<>lastfileidx)) then
  296. begin
  297. status.currentsource:=current_module^.sourcefiles.get_file_name(aktfilepos.fileindex);
  298. lastmoduleidx:=current_module^.unit_index;
  299. { update lastfileidx only if name known PM }
  300. if status.currentsource<>'' then
  301. lastfileidx:=aktfilepos.fileindex
  302. else
  303. lastfileidx:=0;
  304. end;
  305. { show comment }
  306. if do_comment(v,s) or dostop or (status.errorcount>=status.maxerrorcount) then
  307. stop;
  308. end;
  309. procedure Message(w:tmsgconst);
  310. begin
  311. Msg2Comment(msg^.Get(ord(w)));
  312. end;
  313. procedure Message1(w:tmsgconst;const s1:string);
  314. begin
  315. Msg2Comment(msg^.Get1(ord(w),s1));
  316. end;
  317. procedure Message2(w:tmsgconst;const s1,s2:string);
  318. begin
  319. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  320. end;
  321. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  322. begin
  323. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  324. end;
  325. procedure InitVerbose;
  326. begin
  327. { Init }
  328. FillChar(Status,sizeof(TCompilerStatus),0);
  329. status.verbosity:=V_Default;
  330. Status.MaxErrorCount:=50;
  331. end;
  332. begin
  333. {$ifndef TP}
  334. {$ifndef EXTERN_MSG}
  335. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  336. {$endif}
  337. {$endif}
  338. end.
  339. {
  340. $Log$
  341. Revision 1.16 1998-08-18 14:17:15 pierre
  342. * bug about assigning the return value of a function to
  343. a procvar fixed : warning
  344. assigning a proc to a procvar need @ in FPC mode !!
  345. * missing file/line info restored
  346. Revision 1.15 1998/08/18 09:24:49 pierre
  347. * small warning position bug fixed
  348. * support_mmx switches splitting was missing
  349. * rhide error and warning output corrected
  350. Revision 1.14 1998/08/11 14:09:15 peter
  351. * fixed some messages and smaller msgtxt.inc
  352. Revision 1.13 1998/08/10 14:50:37 peter
  353. + localswitches, moduleswitches, globalswitches splitting
  354. Revision 1.12 1998/08/10 10:18:37 peter
  355. + Compiler,Comphook unit which are the new interface units to the
  356. compiler
  357. Revision 1.11 1998/07/14 14:47:13 peter
  358. * released NEWINPUT
  359. Revision 1.10 1998/07/07 12:32:56 peter
  360. * status.currentsource is now calculated in verbose (more accurated)
  361. Revision 1.9 1998/07/07 11:20:20 peter
  362. + NEWINPUT for a better inputfile and scanner object
  363. Revision 1.8 1998/05/23 01:21:35 peter
  364. + aktasmmode, aktoptprocessor, aktoutputformat
  365. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  366. + $LIBNAME to set the library name where the unit will be put in
  367. * splitted cgi386 a bit (codeseg to large for bp7)
  368. * nasm, tasm works again. nasm moved to ag386nsm.pas
  369. Revision 1.7 1998/05/21 19:33:40 peter
  370. + better procedure directive handling and only one table
  371. Revision 1.6 1998/05/12 10:47:01 peter
  372. * moved printstatus to verb_def
  373. + V_Normal which is between V_Error and V_Warning and doesn't have a
  374. prefix like error: warning: and is included in V_Default
  375. * fixed some messages
  376. * first time parameter scan is only for -v and -T
  377. - removed old style messages
  378. Revision 1.5 1998/04/30 15:59:43 pierre
  379. * GDB works again better :
  380. correct type info in one pass
  381. + UseTokenInfo for better source position
  382. * fixed one remaining bug in scanner for line counts
  383. * several little fixes
  384. Revision 1.4 1998/04/23 12:11:22 peter
  385. * fixed -v0 to displayV_Default (=errors+fatals)
  386. Revision 1.3 1998/04/13 21:15:42 florian
  387. * error handling of pass_1 and cgi386 fixed
  388. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  389. fixed, verified
  390. }