verbose.pas 10 KB

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