verbose.pas 10 KB

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