verbose.pas 8.6 KB

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