verb_def.pas 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. This unit handles the default verbose routines
  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 verb_def;
  19. interface
  20. uses verbose;
  21. {$define allow_oldstyle}
  22. procedure SetRedirectFile(const fn:string);
  23. procedure _stop;
  24. procedure _comment(Level:Longint;const s:string);
  25. {$ifdef allow_oldstyle}
  26. function _warning(w : tmsgconst) : boolean;
  27. function _note(w : tmsgconst) : boolean;
  28. function _error(w : tmsgconst) : boolean;
  29. function _fatalerror(w : tmsgconst) : boolean;
  30. function _internalerror(i : longint) : boolean;
  31. {$endif}
  32. implementation
  33. uses
  34. strings,dos,cobjects,systems,globals,files;
  35. const
  36. { RHIDE expect gcc like error output }
  37. rh_errorstr='error: ';
  38. rh_warningstr='warning: ';
  39. fatalstr='Fatal Error: ';
  40. errorstr='Error: ';
  41. warningstr='Warning: ';
  42. notestr='Note: ';
  43. hintstr='Hint: ';
  44. var
  45. redirexitsave : pointer;
  46. redirtext : boolean;
  47. redirfile : text;
  48. {****************************************************************************
  49. Extra Handlers for default compiler
  50. ****************************************************************************}
  51. procedure DoneRedirectFile;{$ifndef FPC}far;{$ENDIF}
  52. begin
  53. exitproc:=redirexitsave;
  54. if redirtext then
  55. close(redirfile);
  56. end;
  57. procedure SetRedirectFile(const fn:string);
  58. begin
  59. assign(redirfile,fn);
  60. {$I-}
  61. rewrite(redirfile);
  62. {$I+}
  63. redirtext:=(ioresult=0);
  64. if redirtext then
  65. begin
  66. redirexitsave:=exitproc;
  67. exitproc:=@DoneRedirectFile;
  68. end;
  69. end;
  70. {****************************************************************************
  71. Predefined default Handlers
  72. ****************************************************************************}
  73. { predefined handler to stop the compiler }
  74. procedure _stop;
  75. begin
  76. halt(1);
  77. end;
  78. Procedure _comment(Level:Longint;const s:string);
  79. var
  80. hs : string;
  81. i : longint;
  82. begin
  83. if (verbosity and Level)=Level then
  84. begin
  85. {Create hs}
  86. hs:='';
  87. if not(use_rhide) then
  88. begin
  89. if (verbosity and Level)=V_Hint then
  90. hs:=hintstr;
  91. if (verbosity and Level)=V_Note then
  92. hs:=notestr;
  93. if (verbosity and Level)=V_Warning then
  94. hs:=warningstr;
  95. if (verbosity and Level)=V_Error then
  96. hs:=errorstr;
  97. if (verbosity and Level)=V_Fatal then
  98. hs:=fatalstr;
  99. end
  100. else
  101. begin
  102. if (verbosity and Level)=V_Hint then
  103. hs:=rh_warningstr;
  104. if (verbosity and Level)=V_Note then
  105. hs:=rh_warningstr;
  106. if (verbosity and Level)=V_Warning then
  107. hs:=rh_warningstr;
  108. if (verbosity and Level)=V_Error then
  109. hs:=rh_errorstr;
  110. if (verbosity and Level)=V_Fatal then
  111. hs:=rh_errorstr;
  112. end;
  113. if (Level<$100) and Assigned(current_module) and
  114. Assigned(current_module^.current_inputfile) then
  115. hs:=current_module^.current_inputfile^.get_file_line+' '+hs;
  116. (* {$ifdef USE_RHIDE}
  117. What was this ??? I did not code that (PM)
  118. if (Level<$100) then
  119. begin
  120. i:=length(hs)+1;
  121. hs:=hs+lowercase(Copy(s,1,5))+Copy(s,6,255);
  122. end
  123. else
  124. {$endif USE_RHIDE} *)
  125. hs:=hs+s;
  126. {$ifdef FPC}
  127. if UseStdErr and (Level<$100) then
  128. begin
  129. writeln(stderr,hs);
  130. flush(stderr);
  131. end
  132. else
  133. {$ENDIF}
  134. begin
  135. if redirtext then
  136. writeln(redirfile,hs)
  137. else
  138. writeln(hs);
  139. end;
  140. end;
  141. end;
  142. function _internalerror(i : longint) : boolean;
  143. begin
  144. comment(V_Fatal,'Internal error '+tostr(i));
  145. _internalerror:=true;
  146. end;
  147. {****************************************************************************
  148. Old Style
  149. ****************************************************************************}
  150. {$ifdef allow_oldstyle}
  151. procedure ShowExtError(l:longint;w:tmsgconst);
  152. var
  153. s : string;
  154. begin
  155. {fix the string to be written }
  156. s:=msg^.get(ord(w));
  157. if assigned(exterror) then
  158. begin
  159. s:=s+strpas(exterror);
  160. strdispose(exterror);
  161. exterror:=nil;
  162. end;
  163. _comment(l,s);
  164. end;
  165. { predefined handler for warnings }
  166. function _warning(w : tmsgconst) : boolean;
  167. begin
  168. ShowExtError(V_Warning,w);
  169. _warning:=false;
  170. end;
  171. function _note(w : tmsgconst) : boolean;
  172. begin
  173. ShowExtError(V_Note,w);
  174. _note:=false;
  175. end;
  176. function _error(w : tmsgconst) : boolean;
  177. begin
  178. ShowExtError(V_Error,w);
  179. _error:=(errorcount>50);
  180. end;
  181. function _fatalerror(w : tmsgconst) : boolean;
  182. begin
  183. ShowExtError(V_Error,w);
  184. _fatalerror:=true;
  185. end;
  186. {$endif}
  187. begin
  188. (* {$ifdef USE_RHIDE}
  189. UseStdErr:=true;
  190. {$endif USE_RHIDE} *)
  191. {$ifdef FPC}
  192. do_stop:=@_stop;
  193. do_comment:=@_comment;
  194. {$ifdef allow_oldstyle}
  195. do_note:=@_note;
  196. do_warning:=@_warning;
  197. do_error:=@_error;
  198. do_fatalerror:=@_fatalerror;
  199. do_internalerror:=@_internalerror;
  200. {$endif}
  201. {$else}
  202. do_stop:=_stop;
  203. do_comment:=_comment;
  204. {$ifdef allow_oldstyle}
  205. do_note:=_note;
  206. do_warning:=_warning;
  207. do_error:=_error;
  208. do_fatalerror:=_fatalerror;
  209. do_internalerror:=_internalerror;
  210. {$endif}
  211. {$endif}
  212. end.
  213. {
  214. $Log$
  215. Revision 1.5 1998-04-30 15:59:43 pierre
  216. * GDB works again better :
  217. correct type info in one pass
  218. + UseTokenInfo for better source position
  219. * fixed one remaining bug in scanner for line counts
  220. * several little fixes
  221. Revision 1.4 1998/04/29 10:34:09 pierre
  222. + added some code for ansistring (not complete nor working yet)
  223. * corrected operator overloading
  224. * corrected nasm output
  225. + started inline procedures
  226. + added starstarn : use ** for exponentiation (^ gave problems)
  227. + started UseTokenInfo cond to get accurate positions
  228. Revision 1.2 1998/03/28 23:09:57 florian
  229. * secondin bugfix (m68k and i386)
  230. * overflow checking bugfix (m68k and i386) -- pretty useless in
  231. secondadd, since everything is done using 32-bit
  232. * loading pointer to routines hopefully fixed (m68k)
  233. * flags problem with calls to RTL internal routines fixed (still strcmp
  234. to fix) (m68k)
  235. * #ELSE was still incorrect (didn't take care of the previous level)
  236. * problem with filenames in the command line solved
  237. * problem with mangledname solved
  238. * linking name problem solved (was case insensitive)
  239. * double id problem and potential crash solved
  240. * stop after first error
  241. * and=>test problem removed
  242. * correct read for all float types
  243. * 2 sigsegv fixes and a cosmetic fix for Internal Error
  244. * push/pop is now correct optimized (=> mov (%esp),reg)
  245. Revision 1.1.1.1 1998/03/25 11:18:15 root
  246. * Restored version
  247. Revision 1.6 1998/03/10 16:43:34 peter
  248. * fixed Fatal error writting
  249. Revision 1.5 1998/03/10 01:17:30 peter
  250. * all files have the same header
  251. * messages are fully implemented, EXTDEBUG uses Comment()
  252. + AG... files for the Assembler generation
  253. Revision 1.4 1998/03/06 00:53:02 peter
  254. * replaced all old messages from errore.msg, only ExtDebug and some
  255. Comment() calls are left
  256. * fixed options.pas
  257. Revision 1.3 1998/03/04 17:34:15 michael
  258. + Changed ifdef FPK to ifdef FPC
  259. Revision 1.2 1998/03/03 16:45:25 peter
  260. + message support for assembler parsers
  261. }