verbose.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. {$define allow_oldstyle}
  22. {$IFNDEF EXTERN_MSG}
  23. {$i msgtxt.inc}
  24. {$ENDIF}
  25. {$i msgidx.inc}
  26. Const
  27. MaxErrorCount : longint = 50;
  28. { <$100 can include file and linenr info }
  29. V_Fatal = $0;
  30. V_Error = $1;
  31. V_Warning = $2;
  32. V_Note = $4;
  33. V_Hint = $8;
  34. V_Info = $100;
  35. V_Linenrs = $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;
  44. Verbosity : longint=V_Default;
  45. var
  46. errorcount : longint; { number of generated errors }
  47. msg : pmessage;
  48. UseStdErr : boolean;
  49. Use_Rhide : boolean;
  50. procedure LoadMsgFile(const fn:string);
  51. function SetVerbosity(const s:string):boolean;
  52. procedure stop;
  53. procedure comment(l:longint;const s:string);
  54. procedure internalerror(i:longint);
  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. { old calling style }
  60. {$ifdef allow_oldstyle}
  61. var
  62. exterror : pchar;
  63. procedure note(w:tmsgconst);
  64. procedure warning(w:tmsgconst);
  65. procedure error(w:tmsgconst);
  66. procedure fatalerror(w:tmsgconst);
  67. {$endif}
  68. { Function redirecting for IDE support }
  69. type
  70. tstopprocedure = procedure;
  71. tcommentprocedure = procedure(Level:Longint;const s:string);
  72. {old handlers }
  73. terrorfunction = function(w:tmsgconst) : boolean;
  74. tinternalerrorfunction = function(i : longint) : boolean;
  75. var
  76. { this procedure is called to stop the compiler }
  77. { e.g. this procedure has to restore the state before compiling }
  78. do_stop : tstopprocedure;
  79. { called when writing something to the screen, called with the level }
  80. { of the comment }
  81. do_comment : tcommentprocedure;
  82. { only for compatibility }
  83. do_note,do_warning,do_error,do_fatalerror : terrorfunction;
  84. do_internalerror : tinternalerrorfunction;
  85. implementation
  86. uses globals;
  87. procedure LoadMsgFile(const fn:string);
  88. begin
  89. if not (msg=nil) then
  90. dispose(msg,Done);
  91. msg:=new(pmessage,InitExtern(fn,ord(endmsgconst)));
  92. end;
  93. function SetVerbosity(const s:string):boolean;
  94. var
  95. m : Longint;
  96. i : Word;
  97. inverse : boolean;
  98. c : char;
  99. begin
  100. setverbosity:=false;
  101. val(s,m,i);
  102. if (i=0) and (s<>'') then
  103. verbosity:=m
  104. else
  105. begin
  106. for i:=1 to length(s) do
  107. begin
  108. c:=s[i];
  109. if (i<length(s)) and (s[i+1]='-') then
  110. begin
  111. inc(i);
  112. inverse:=true;
  113. end
  114. else
  115. inverse:=false;
  116. case upcase(s[i]) of
  117. { Special cases }
  118. 'A' : Verbosity:=V_All;
  119. '0' : Verbosity:=V_Default;
  120. 'R' : begin
  121. if inverse then
  122. begin
  123. Use_rhide:=false;
  124. UseStdErr:=false;
  125. end
  126. else
  127. begin
  128. Use_rhide:=true;
  129. UseStdErr:=true;
  130. end;
  131. end;
  132. { Normal cases - do an or }
  133. 'E' : if inverse then
  134. Verbosity:=Verbosity and (not V_Error)
  135. else
  136. Verbosity:=Verbosity or V_Error;
  137. 'I' : if inverse then
  138. Verbosity:=Verbosity and (not V_Info)
  139. else
  140. Verbosity:=Verbosity or V_Info;
  141. 'W' : if inverse then
  142. Verbosity:=Verbosity and (not V_Warning)
  143. else
  144. Verbosity:=Verbosity or V_Warning;
  145. 'N' : if inverse then
  146. Verbosity:=Verbosity and (not V_Note)
  147. else
  148. Verbosity:=Verbosity or V_Note;
  149. 'H' : if inverse then
  150. Verbosity:=Verbosity and (not V_Hint)
  151. else
  152. Verbosity:=Verbosity or V_Hint;
  153. 'L' : if inverse then
  154. Verbosity:=Verbosity and (not V_Linenrs)
  155. else
  156. Verbosity:=Verbosity or V_Linenrs;
  157. 'U' : if inverse then
  158. Verbosity:=Verbosity and (not V_Used)
  159. else
  160. Verbosity:=Verbosity or V_Used;
  161. 'T' : if inverse then
  162. Verbosity:=Verbosity and (not V_Tried)
  163. else
  164. Verbosity:=Verbosity or V_Tried;
  165. 'M' : if inverse then
  166. Verbosity:=Verbosity and (not V_Macro)
  167. else
  168. Verbosity:=Verbosity or V_Macro;
  169. 'P' : if inverse then
  170. Verbosity:=Verbosity and (not V_Procedure)
  171. else
  172. Verbosity:=Verbosity or V_Procedure;
  173. 'C' : if inverse then
  174. Verbosity:=Verbosity and (not V_Conditional)
  175. else
  176. Verbosity:=Verbosity or V_Conditional;
  177. 'D' : if inverse then
  178. Verbosity:=Verbosity and (not V_Debug)
  179. else
  180. Verbosity:=Verbosity or V_Debug;
  181. end;
  182. end;
  183. end;
  184. if Verbosity=0 then
  185. Verbosity:=V_Default;
  186. setverbosity:=true;
  187. end;
  188. procedure stop;
  189. begin
  190. {$ifndef TP}
  191. do_stop();
  192. {$else}
  193. do_stop;
  194. {$endif}
  195. end;
  196. procedure internalerror(i : longint);
  197. begin
  198. do_internalerror(i);
  199. stop;
  200. end;
  201. procedure Comment(l:longint;const s:string);
  202. begin
  203. do_comment(l,s);
  204. end;
  205. Procedure Msg2Comment(s:string);
  206. var
  207. idx,i,v : longint;
  208. dostop : boolean;
  209. begin
  210. {Reset}
  211. dostop:=false;
  212. v:=0;
  213. {Parse options}
  214. idx:=pos('_',s);
  215. if idx=0 then
  216. v:=V_Default
  217. else
  218. if (idx in [1..5]) then
  219. begin
  220. for i:=1 to idx do
  221. begin
  222. case upcase(s[i]) of
  223. 'F' : begin
  224. v:=v or V_Fatal;
  225. dostop:=true;
  226. end;
  227. 'E' : begin
  228. v:=v or V_Error;
  229. inc(errorcount);
  230. dostop:=(errorcount>=maxerrorcount);
  231. end;
  232. 'W' : v:=v or V_Warning;
  233. 'N' : v:=v or V_Note;
  234. 'H' : v:=v or V_Hint;
  235. 'I' : v:=v or V_Info;
  236. 'L' : v:=v or V_Linenrs;
  237. 'U' : v:=v or V_Used;
  238. 'T' : v:=v or V_Tried;
  239. 'M' : v:=v or V_Macro;
  240. 'P' : v:=v or V_Procedure;
  241. 'C' : v:=v or V_Conditional;
  242. 'D' : v:=v or V_Debug;
  243. 'S' : dostop:=true;
  244. '_' : ;
  245. end;
  246. end;
  247. end;
  248. Delete(s,1,idx);
  249. Comment(v,s);
  250. if dostop then
  251. stop;
  252. end;
  253. procedure Message(w:tmsgconst);
  254. begin
  255. Msg2Comment(msg^.Get(ord(w)));
  256. end;
  257. procedure Message1(w:tmsgconst;const s1:string);
  258. begin
  259. Msg2Comment(msg^.Get1(ord(w),s1));
  260. end;
  261. procedure Message2(w:tmsgconst;const s1,s2:string);
  262. begin
  263. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  264. end;
  265. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  266. begin
  267. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  268. end;
  269. {*****************************************************************************
  270. Old Style
  271. *****************************************************************************}
  272. {$ifdef allow_oldstyle}
  273. procedure warning(w:tmsgconst);
  274. begin
  275. if do_warning(w) then
  276. stop;
  277. end;
  278. procedure note(w:tmsgconst);
  279. begin
  280. if do_note(w) then
  281. stop;
  282. end;
  283. procedure error(w:tmsgconst);
  284. begin
  285. inc(errorcount);
  286. if do_error(w) then
  287. stop;
  288. end;
  289. procedure fatalerror(w:tmsgconst);
  290. begin
  291. do_fatalerror(w);
  292. stop;
  293. end;
  294. {$endif}
  295. begin
  296. {$IFNDEF EXTERN_MSG}
  297. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  298. {$ENDIF}
  299. end.
  300. {
  301. $Log$
  302. Revision 1.5 1998-04-30 15:59:43 pierre
  303. * GDB works again better :
  304. correct type info in one pass
  305. + UseTokenInfo for better source position
  306. * fixed one remaining bug in scanner for line counts
  307. * several little fixes
  308. Revision 1.4 1998/04/23 12:11:22 peter
  309. * fixed -v0 to displayV_Default (=errors+fatals)
  310. Revision 1.3 1998/04/13 21:15:42 florian
  311. * error handling of pass_1 and cgi386 fixed
  312. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  313. fixed, verified
  314. Revision 1.2 1998/03/28 23:09:57 florian
  315. * secondin bugfix (m68k and i386)
  316. * overflow checking bugfix (m68k and i386) -- pretty useless in
  317. secondadd, since everything is done using 32-bit
  318. * loading pointer to routines hopefully fixed (m68k)
  319. * flags problem with calls to RTL internal routines fixed (still strcmp
  320. to fix) (m68k)
  321. * #ELSE was still incorrect (didn't take care of the previous level)
  322. * problem with filenames in the command line solved
  323. * problem with mangledname solved
  324. * linking name problem solved (was case insensitive)
  325. * double id problem and potential crash solved
  326. * stop after first error
  327. * and=>test problem removed
  328. * correct read for all float types
  329. * 2 sigsegv fixes and a cosmetic fix for Internal Error
  330. * push/pop is now correct optimized (=> mov (%esp),reg)
  331. Revision 1.1.1.1 1998/03/25 11:18:15 root
  332. * Restored version
  333. Revision 1.17 1998/03/10 16:43:34 peter
  334. * fixed Fatal error writting
  335. Revision 1.16 1998/03/10 01:17:30 peter
  336. * all files have the same header
  337. * messages are fully implemented, EXTDEBUG uses Comment()
  338. + AG... files for the Assembler generation
  339. Revision 1.15 1998/03/06 00:53:02 peter
  340. * replaced all old messages from errore.msg, only ExtDebug and some
  341. Comment() calls are left
  342. * fixed options.pas
  343. Revision 1.14 1998/03/04 01:35:15 peter
  344. * messages for unit-handling and assembler/linker
  345. * the compiler compiles without -dGDB, but doesn't work yet
  346. + -vh for Hint
  347. Revision 1.13 1998/03/03 16:45:25 peter
  348. + message support for assembler parsers
  349. Revision 1.12 1998/03/02 16:02:05 peter
  350. * new style messages for pp.pas
  351. * cleanup of pp.pas
  352. Revision 1.11 1998/03/02 01:49:40 peter
  353. * renamed target_DOS to target_GO32V1
  354. + new verbose system, merged old errors and verbose units into one new
  355. verbose.pas, so errors.pas is obsolete
  356. }