verbose.pas 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. setverbosity:=true;
  123. end;
  124. procedure stop;
  125. begin
  126. {$ifndef TP}
  127. do_stop();
  128. {$else}
  129. do_stop;
  130. {$endif}
  131. end;
  132. procedure internalerror(i : longint);
  133. begin
  134. do_internalerror(i);
  135. stop;
  136. end;
  137. procedure Comment(l:longint;const s:string);
  138. begin
  139. do_comment(l,s);
  140. end;
  141. Procedure Msg2Comment(s:string);
  142. var
  143. idx,i,v : longint;
  144. dostop : boolean;
  145. begin
  146. {Reset}
  147. dostop:=false;
  148. v:=0;
  149. {Parse options}
  150. idx:=pos('_',s);
  151. if idx=0 then
  152. v:=V_Default
  153. else
  154. if (idx in [1..5]) then
  155. begin
  156. for i:=1to idx do
  157. begin
  158. case upcase(s[i]) of
  159. 'F' : begin
  160. v:=v or V_Fatal;
  161. dostop:=true;
  162. end;
  163. 'E' : begin
  164. v:=v or V_Error;
  165. inc(errorcount);
  166. dostop:=(errorcount>=maxerrorcount);
  167. end;
  168. 'W' : v:=v or V_Warning;
  169. 'N' : v:=v or V_Note;
  170. 'H' : v:=v or V_Hint;
  171. 'I' : v:=v or V_Info;
  172. 'L' : v:=v or V_Linenrs;
  173. 'U' : v:=v or V_Used;
  174. 'T' : v:=v or V_Tried;
  175. 'M' : v:=v or V_Macro;
  176. 'P' : v:=v or V_Procedure;
  177. 'C' : v:=v or V_Conditional;
  178. 'D' : v:=v or V_Debug;
  179. 'S' : dostop:=true;
  180. '_' : ;
  181. end;
  182. end;
  183. end;
  184. Delete(s,1,idx);
  185. Comment(v,s);
  186. if dostop then
  187. stop;
  188. end;
  189. procedure Message(w:tmsgconst);
  190. begin
  191. Msg2Comment(msg^.Get(ord(w)));
  192. end;
  193. procedure Message1(w:tmsgconst;const s1:string);
  194. begin
  195. Msg2Comment(msg^.Get1(ord(w),s1));
  196. end;
  197. procedure Message2(w:tmsgconst;const s1,s2:string);
  198. begin
  199. Msg2Comment(msg^.Get2(ord(w),s1,s2));
  200. end;
  201. procedure Message3(w:tmsgconst;const s1,s2,s3:string);
  202. begin
  203. Msg2Comment(msg^.Get3(ord(w),s1,s2,s3));
  204. end;
  205. {*****************************************************************************
  206. Old Style
  207. *****************************************************************************}
  208. {$ifdef allow_oldstyle}
  209. procedure warning(w:tmsgconst);
  210. begin
  211. if do_warning(w) then
  212. stop;
  213. end;
  214. procedure note(w:tmsgconst);
  215. begin
  216. if do_note(w) then
  217. stop;
  218. end;
  219. procedure error(w:tmsgconst);
  220. begin
  221. inc(errorcount);
  222. if do_error(w) then
  223. stop;
  224. end;
  225. procedure fatalerror(w:tmsgconst);
  226. begin
  227. do_fatalerror(w);
  228. stop;
  229. end;
  230. {$endif}
  231. begin
  232. {$IFNDEF EXTERN_MSG}
  233. msg:=new(pmessage,Init(@msgtxt,ord(endmsgconst)));
  234. {$ENDIF}
  235. end.
  236. {
  237. $Log$
  238. Revision 1.2 1998-03-28 23:09:57 florian
  239. * secondin bugfix (m68k and i386)
  240. * overflow checking bugfix (m68k and i386) -- pretty useless in
  241. secondadd, since everything is done using 32-bit
  242. * loading pointer to routines hopefully fixed (m68k)
  243. * flags problem with calls to RTL internal routines fixed (still strcmp
  244. to fix) (m68k)
  245. * #ELSE was still incorrect (didn't take care of the previous level)
  246. * problem with filenames in the command line solved
  247. * problem with mangledname solved
  248. * linking name problem solved (was case insensitive)
  249. * double id problem and potential crash solved
  250. * stop after first error
  251. * and=>test problem removed
  252. * correct read for all float types
  253. * 2 sigsegv fixes and a cosmetic fix for Internal Error
  254. * push/pop is now correct optimized (=> mov (%esp),reg)
  255. Revision 1.1.1.1 1998/03/25 11:18:15 root
  256. * Restored version
  257. Revision 1.17 1998/03/10 16:43:34 peter
  258. * fixed Fatal error writting
  259. Revision 1.16 1998/03/10 01:17:30 peter
  260. * all files have the same header
  261. * messages are fully implemented, EXTDEBUG uses Comment()
  262. + AG... files for the Assembler generation
  263. Revision 1.15 1998/03/06 00:53:02 peter
  264. * replaced all old messages from errore.msg, only ExtDebug and some
  265. Comment() calls are left
  266. * fixed options.pas
  267. Revision 1.14 1998/03/04 01:35:15 peter
  268. * messages for unit-handling and assembler/linker
  269. * the compiler compiles without -dGDB, but doesn't work yet
  270. + -vh for Hint
  271. Revision 1.13 1998/03/03 16:45:25 peter
  272. + message support for assembler parsers
  273. Revision 1.12 1998/03/02 16:02:05 peter
  274. * new style messages for pp.pas
  275. * cleanup of pp.pas
  276. Revision 1.11 1998/03/02 01:49:40 peter
  277. * renamed target_DOS to target_GO32V1
  278. + new verbose system, merged old errors and verbose units into one new
  279. verbose.pas, so errors.pas is obsolete
  280. }