verbose.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman
  3. This unit handles the verbose management
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit verbose;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. {$IFNDEF USE_FAKE_SYSUTILS}
  22. sysutils,
  23. {$ELSE}
  24. fksysutl,
  25. {$ENDIF}
  26. cutils,
  27. globtype,finput,
  28. cmsgs;
  29. {$ifndef EXTERN_MSG}
  30. {$i msgtxt.inc}
  31. {$endif}
  32. {$i msgidx.inc}
  33. Const
  34. { Levels }
  35. V_None = $0;
  36. V_Fatal = $1;
  37. V_Error = $2;
  38. V_Normal = $4; { doesn't show a text like Error: }
  39. V_Warning = $8;
  40. V_Note = $10;
  41. V_Hint = $20;
  42. V_LineInfoMask = $fff;
  43. { From here by default no line info }
  44. V_Info = $1000;
  45. V_Status = $2000;
  46. V_Used = $4000;
  47. V_Tried = $8000;
  48. V_Conditional = $10000;
  49. V_Debug = $20000;
  50. V_Executable = $40000;
  51. V_LevelMask = $fffffff;
  52. V_All = V_LevelMask;
  53. V_Default = V_Fatal + V_Error + V_Normal;
  54. { Flags }
  55. V_LineInfo = $10000000;
  56. var
  57. msg : pmessage;
  58. paraprintnodetree : byte;
  59. type
  60. tmsgqueueevent = procedure(const s:TMsgStr;v,w:longint) of object;
  61. const
  62. msgfilename : string = '';
  63. procedure SetRedirectFile(const fn:string);
  64. function SetVerbosity(const s:string):boolean;
  65. procedure PrepareReport;
  66. function CheckVerbosity(v:longint):boolean;
  67. function SetMessageVerbosity(v:longint;state:tmsgstate):boolean;
  68. procedure RestoreLocalVerbosity(pstate : pmessagestaterecord);
  69. procedure FreeLocalVerbosity(var fstate : pmessagestaterecord);
  70. function ChangeMessageVerbosity(s: string; var i: integer;state:tmsgstate): boolean;
  71. procedure ShowStatus;
  72. function ErrorCount:longint;
  73. procedure SetErrorFlags(const s:string);
  74. procedure GenerateError;
  75. procedure Internalerror(i:longint);
  76. procedure Comment(l:longint;s:ansistring);
  77. function MessagePchar(w:longint):pchar;
  78. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  79. procedure Message1(w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  80. procedure Message2(w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  81. procedure Message3(w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  82. procedure Message4(w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  83. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  84. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  85. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  86. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  87. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  88. { message calls with codegenerror support }
  89. procedure cgmessage(t : longint);
  90. procedure cgmessage1(t : longint;const s : TMsgStr);
  91. procedure cgmessage2(t : longint;const s1,s2 : TMsgStr);
  92. procedure cgmessage3(t : longint;const s1,s2,s3 : TMsgStr);
  93. procedure CGMessagePos(const pos:tfileposinfo;t:longint);
  94. procedure CGMessagePos1(const pos:tfileposinfo;t:longint;const s1:TMsgStr);
  95. procedure CGMessagePos2(const pos:tfileposinfo;t:longint;const s1,s2:TMsgStr);
  96. procedure CGMessagePos3(const pos:tfileposinfo;t:longint;const s1,s2,s3:TMsgStr);
  97. procedure FlushOutput;
  98. procedure InitVerbose;
  99. procedure DoneVerbose;
  100. implementation
  101. uses
  102. comphook,fmodule,constexp,globals,cfileutl,switches;
  103. {****************************************************************************
  104. Extra Handlers for default compiler
  105. ****************************************************************************}
  106. procedure DoneRedirectFile;
  107. begin
  108. if status.use_redir then
  109. begin
  110. close(status.redirfile);
  111. status.use_redir:=false;
  112. end;
  113. if status.use_bugreport then
  114. begin
  115. close(status.reportbugfile);
  116. status.use_bugreport:=false;
  117. end;
  118. end;
  119. procedure SetRedirectFile(const fn:string);
  120. begin
  121. { close old redirection file because FileRedirection is handled in both passes }
  122. if status.use_redir then
  123. close(status.redirfile);
  124. assign(status.redirfile,fn);
  125. {$push}{$I-}
  126. append(status.redirfile);
  127. if ioresult <> 0 then
  128. begin
  129. assign(status.redirfile,fn);
  130. rewrite(status.redirfile);
  131. end;
  132. {$pop}
  133. status.use_redir:=(ioresult=0);
  134. end;
  135. procedure PrepareReport;
  136. var
  137. fn : string;
  138. begin
  139. if status.use_bugreport then
  140. exit;
  141. fn:='fpcdebug.txt';
  142. assign(status.reportbugfile,fn);
  143. {$push}{$I-}
  144. append(status.reportbugfile);
  145. if ioresult <> 0 then
  146. rewrite(status.reportbugfile);
  147. {$pop}
  148. status.use_bugreport:=(ioresult=0);
  149. if status.use_bugreport then
  150. writeln(status.reportbugfile,'FPC bug report file');
  151. end;
  152. procedure RestoreLocalVerbosity(pstate : pmessagestaterecord);
  153. begin
  154. msg^.ResetStates;
  155. while assigned(pstate) do
  156. begin
  157. SetMessageVerbosity(pstate^.value,pstate^.state);
  158. pstate:=pstate^.next;
  159. end;
  160. end;
  161. procedure FreeLocalVerbosity(var fstate : pmessagestaterecord);
  162. var pstate : pmessagestaterecord;
  163. begin
  164. pstate:=unaligned(fstate);
  165. while assigned(pstate) do
  166. begin
  167. unaligned(fstate):=pstate^.next;
  168. freemem(pstate);
  169. pstate:=unaligned(fstate);
  170. end;
  171. end;
  172. function ChangeMessageVerbosity(s: string; var i : integer;state:tmsgstate): boolean;
  173. var
  174. tok : string;
  175. msgnr, code : longint;
  176. begin
  177. { delete everything up to and including 'm' }
  178. delete(s,1,i);
  179. { the rest of the string must be message numbers }
  180. inc(i,length(s)+1);
  181. result:=false;
  182. repeat
  183. tok:=GetToken(s,',');
  184. if (tok='') then
  185. break;
  186. val(tok, msgnr, code);
  187. if (code<>0) then
  188. exit;
  189. if not msg^.setverbosity(msgnr,state) then
  190. exit
  191. else
  192. recordpendingmessagestate(msgnr, state);
  193. until false;
  194. result:=true;
  195. end;
  196. function SetMessageVerbosity(v:longint;state:tmsgstate):boolean;
  197. begin
  198. result:=msg^.setverbosity(v,state);
  199. end;
  200. function CheckVerbosity(v:longint):boolean;
  201. begin
  202. result:=do_checkverbosity(v);
  203. end;
  204. function SetVerbosity(const s:string):boolean;
  205. const
  206. message_verbosity:array[boolean] of tmsgstate=(ms_off_global,ms_on_global);
  207. var
  208. m : Longint;
  209. i : Integer;
  210. inverse : boolean;
  211. c : char;
  212. begin
  213. Setverbosity:=false;
  214. val(s,m,i);
  215. if (i=0) and (s<>'') then
  216. status.verbosity:=m
  217. else
  218. begin
  219. i:=1;
  220. while i<=length(s) do
  221. begin
  222. c:=upcase(s[i]);
  223. inverse:=false;
  224. { on/off ? }
  225. if (i<length(s)) then
  226. case s[i+1] of
  227. '-' : begin
  228. inc(i);
  229. inverse:=true;
  230. end;
  231. '+' : inc(i);
  232. end;
  233. { handle switch }
  234. case c of
  235. { Special cases }
  236. '0' : status.verbosity:=V_Default;
  237. 'A' : status.verbosity:=V_All;
  238. 'B' : begin
  239. if inverse then
  240. status.print_source_path:=false
  241. else
  242. status.print_source_path:=true;
  243. end;
  244. 'M' : if not ChangeMessageVerbosity(s,i,message_verbosity[inverse]) then
  245. begin
  246. result:=false;
  247. exit
  248. end;
  249. 'P' : begin
  250. if inverse then
  251. paraprintnodetree:=0
  252. else
  253. paraprintnodetree:=1;
  254. end;
  255. 'Q' : begin
  256. if inverse then
  257. status.showmsgnrs:=false
  258. else
  259. status.showmsgnrs:=true;
  260. end;
  261. 'R' : begin
  262. if inverse then
  263. begin
  264. status.use_gccoutput:=false;
  265. status.use_stderr:=false;
  266. end
  267. else
  268. begin
  269. status.use_gccoutput:=true;
  270. status.use_stderr:=true;
  271. end;
  272. end;
  273. 'V' : PrepareReport;
  274. 'Z' : begin
  275. if inverse then
  276. status.use_stderr:=false
  277. else
  278. status.use_stderr:=true;
  279. end;
  280. { Normal cases - do an or }
  281. 'C' : if inverse then
  282. status.verbosity:=status.verbosity and (not V_Conditional)
  283. else
  284. status.verbosity:=status.verbosity or V_Conditional;
  285. 'D' : if inverse then
  286. status.verbosity:=status.verbosity and (not V_Debug)
  287. else
  288. status.verbosity:=status.verbosity or V_Debug;
  289. 'E' : if inverse then
  290. status.verbosity:=status.verbosity and (not V_Error)
  291. else
  292. status.verbosity:=status.verbosity or V_Error;
  293. 'H' : if inverse then
  294. status.verbosity:=status.verbosity and (not V_Hint)
  295. else
  296. status.verbosity:=status.verbosity or V_Hint;
  297. 'I' : if inverse then
  298. status.verbosity:=status.verbosity and (not V_Info)
  299. else
  300. status.verbosity:=status.verbosity or V_Info;
  301. 'L' : if inverse then
  302. status.verbosity:=status.verbosity and (not V_Status)
  303. else
  304. status.verbosity:=status.verbosity or V_Status;
  305. 'N' : if inverse then
  306. status.verbosity:=status.verbosity and (not V_Note)
  307. else
  308. status.verbosity:=status.verbosity or V_Note;
  309. 'S' : if inverse then
  310. status.verbosity:=status.verbosity and (not V_TimeStamps)
  311. else
  312. status.verbosity:=status.verbosity or V_TimeStamps;
  313. 'T' : if inverse then
  314. status.verbosity:=status.verbosity and (not V_Tried)
  315. else
  316. status.verbosity:=status.verbosity or V_Tried;
  317. 'U' : if inverse then
  318. status.verbosity:=status.verbosity and (not V_Used)
  319. else
  320. status.verbosity:=status.verbosity or V_Used;
  321. 'W' : if inverse then
  322. status.verbosity:=status.verbosity and (not V_Warning)
  323. else
  324. status.verbosity:=status.verbosity or V_Warning;
  325. 'X' : if inverse then
  326. status.verbosity:=status.verbosity and (not V_Executable)
  327. else
  328. status.verbosity:=status.verbosity or V_Executable;
  329. end;
  330. inc(i);
  331. end;
  332. end;
  333. if status.verbosity=0 then
  334. status.verbosity:=V_Default;
  335. setverbosity:=true;
  336. end;
  337. procedure Loadprefixes;
  338. function loadprefix(w:longint):string;
  339. var
  340. s : string;
  341. idx : longint;
  342. begin
  343. s:=msg^.get(w,[]);
  344. idx:=pos('_',s);
  345. if idx>0 then
  346. Loadprefix:=Copy(s,idx+1,255)
  347. else
  348. Loadprefix:=s;
  349. end;
  350. begin
  351. { Load the prefixes }
  352. fatalstr:=Loadprefix(general_i_fatal);
  353. errorstr:=Loadprefix(general_i_error);
  354. warningstr:=Loadprefix(general_i_warning);
  355. notestr:=Loadprefix(general_i_note);
  356. hintstr:=Loadprefix(general_i_hint);
  357. end;
  358. procedure LoadMsgFile(const fn:string);
  359. begin
  360. { reload the internal messages if not already loaded }
  361. {$ifndef EXTERN_MSG}
  362. if not msg^.msgintern then
  363. msg^.LoadIntern(@msgtxt,msgtxtsize);
  364. {$endif}
  365. if not msg^.LoadExtern(fn) then
  366. begin
  367. {$ifdef EXTERN_MSG}
  368. writeln('Fatal: Cannot find error message file.');
  369. halt(3);
  370. {$else}
  371. msg^.LoadIntern(@msgtxt,msgtxtsize);
  372. {$endif}
  373. end;
  374. { reload the prefixes using the new messages }
  375. Loadprefixes;
  376. end;
  377. procedure MaybeLoadMessageFile;
  378. begin
  379. { Load new message file }
  380. if (msgfilename<>'') then
  381. begin
  382. LoadMsgFile(msgfilename);
  383. msgfilename:='';
  384. end;
  385. end;
  386. var
  387. lastfileidx,
  388. lastmoduleidx : longint;
  389. Procedure UpdateStatus;
  390. var
  391. module : tmodulebase;
  392. begin
  393. { fix status }
  394. status.currentline:=current_filepos.line;
  395. status.currentcolumn:=current_filepos.column;
  396. if (current_filepos.moduleindex <> lastmoduleidx) or
  397. (current_filepos.fileindex <> lastfileidx) then
  398. begin
  399. module:=get_module(current_filepos.moduleindex);
  400. if assigned(module) and assigned(module.sourcefiles) then
  401. begin
  402. { update status record }
  403. status.currentmodule:=module.modulename^;
  404. status.currentmodulestate:=ModuleStateStr[module.state];
  405. status.currentsource:=module.sourcefiles.get_file_name(current_filepos.fileindex);
  406. status.currentsourcepath:=module.sourcefiles.get_file_path(current_filepos.fileindex);
  407. { if currentsourcepath is relative, make it absolute }
  408. if not path_absolute(status.currentsourcepath) then
  409. status.currentsourcepath:=GetCurrentDir+status.currentsourcepath;
  410. { update lastfileidx only if name known PM }
  411. if status.currentsource<>'' then
  412. lastfileidx:=current_filepos.fileindex
  413. else
  414. lastfileidx:=0;
  415. lastmoduleidx:=module.unit_index;
  416. end;
  417. end;
  418. end;
  419. procedure ShowStatus;
  420. begin
  421. UpdateStatus;
  422. if do_status() then
  423. raise ECompilerAbort.Create;
  424. end;
  425. function ErrorCount:longint;
  426. begin
  427. ErrorCount:=status.errorcount;
  428. end;
  429. procedure SetErrorFlags(const s:string);
  430. var
  431. code : integer;
  432. i,j,l : longint;
  433. begin
  434. { empty string means error count = 1 for backward compatibility (PFV) }
  435. if s='' then
  436. begin
  437. status.maxerrorcount:=1;
  438. exit;
  439. end;
  440. i:=0;
  441. while (i<length(s)) do
  442. begin
  443. inc(i);
  444. case s[i] of
  445. '0'..'9' :
  446. begin
  447. j:=i;
  448. while (j<=length(s)) and (s[j] in ['0'..'9']) do
  449. inc(j);
  450. val(copy(s,i,j-i),l,code);
  451. if code<>0 then
  452. l:=1;
  453. status.maxerrorcount:=l;
  454. i:=j-1;
  455. end;
  456. 'w','W' :
  457. status.errorwarning:=true;
  458. 'n','N' :
  459. status.errornote:=true;
  460. 'h','H' :
  461. status.errorhint:=true;
  462. end;
  463. end;
  464. end;
  465. procedure GenerateError;
  466. begin
  467. inc(status.errorcount);
  468. end;
  469. procedure internalerror(i : longint);
  470. begin
  471. UpdateStatus;
  472. do_internalerror(i);
  473. inc(status.errorcount);
  474. raise ECompilerAbort.Create;
  475. end;
  476. procedure Comment(l:longint;s:ansistring);
  477. var
  478. dostop : boolean;
  479. begin
  480. dostop:=((l and V_Fatal)<>0);
  481. if ((l and V_Error)<>0) or
  482. ((l and V_Fatal)<>0) or
  483. (status.errorwarning and ((l and V_Warning)<>0)) or
  484. (status.errornote and ((l and V_Note)<>0)) or
  485. (status.errorhint and ((l and V_Hint)<>0)) then
  486. inc(status.errorcount)
  487. else
  488. if l and V_Warning <> 0 then
  489. inc(status.countWarnings)
  490. else
  491. if l and V_Note <> 0 then
  492. inc(status.countNotes)
  493. else
  494. if l and V_Hint <> 0 then
  495. inc(status.countHints);
  496. { check verbosity level }
  497. if not CheckVerbosity(l) then
  498. exit;
  499. if (l and V_LineInfoMask)<>0 then
  500. l:=l or V_LineInfo;
  501. { Create status info }
  502. UpdateStatus;
  503. { Fix replacements }
  504. DefaultReplacements(s);
  505. { show comment }
  506. if do_comment(l,s) or dostop then
  507. raise ECompilerAbort.Create;
  508. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  509. begin
  510. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  511. status.skip_error:=true;
  512. raise ECompilerAbort.Create;
  513. end;
  514. end;
  515. function GetMessageState(m:longint):tmsgstate;
  516. var
  517. i: integer;
  518. begin
  519. i:=m div 1000;
  520. { get the default state }
  521. Result:=msg^.msgstates[i]^[m mod 1000];
  522. { and search at the current unit settings }
  523. { todo }
  524. end;
  525. Procedure Msg2Comment(s:ansistring;w:longint;onqueue:tmsgqueueevent);
  526. var
  527. idx,i,v : longint;
  528. dostop : boolean;
  529. doqueue : boolean;
  530. st : tmsgstate;
  531. ch : char;
  532. begin
  533. {Reset}
  534. dostop:=false;
  535. doqueue:=false;
  536. v:=0;
  537. {Parse options}
  538. idx:=pos('_',s);
  539. if idx=0 then
  540. v:=V_None
  541. else
  542. if (idx >= 1) And (idx <= 5) then
  543. begin
  544. for i:=1 to idx do
  545. begin
  546. ch:=upcase(s[i]);
  547. case ch of
  548. 'F' :
  549. begin
  550. v:=v or V_Fatal;
  551. inc(status.errorcount);
  552. dostop:=true;
  553. end;
  554. 'E','W','N','H':
  555. begin
  556. if ch='E' then
  557. st:=ms_error
  558. else
  559. st:=GetMessageState(w);
  560. { We only want to know about local value }
  561. st:= tmsgstate(ord(st) and ms_local_mask);
  562. if st=ms_error then
  563. begin
  564. v:=v or V_Error;
  565. inc(status.errorcount);
  566. end
  567. else if st<>ms_off then
  568. case ch of
  569. 'W':
  570. begin
  571. v:=v or V_Warning;
  572. if CheckVerbosity(V_Warning) then
  573. if status.errorwarning then
  574. inc(status.errorcount)
  575. else
  576. inc(status.countWarnings);
  577. end;
  578. 'N' :
  579. begin
  580. v:=v or V_Note;
  581. if CheckVerbosity(V_Note) then
  582. if status.errornote then
  583. inc(status.errorcount)
  584. else
  585. inc(status.countNotes);
  586. end;
  587. 'H' :
  588. begin
  589. v:=v or V_Hint;
  590. if CheckVerbosity(V_Hint) then
  591. if status.errorhint then
  592. inc(status.errorcount)
  593. else
  594. inc(status.countHints);
  595. end;
  596. end;
  597. end;
  598. 'O' :
  599. v:=v or V_Normal;
  600. 'I' :
  601. v:=v or V_Info;
  602. 'L' :
  603. v:=v or V_LineInfo;
  604. 'U' :
  605. v:=v or V_Used;
  606. 'T' :
  607. v:=v or V_Tried;
  608. 'C' :
  609. v:=v or V_Conditional;
  610. 'D' :
  611. v:=v or V_Debug;
  612. 'X' :
  613. v:=v or V_Executable;
  614. 'S' :
  615. dostop:=true;
  616. '_' : ;
  617. end;
  618. end;
  619. end;
  620. Delete(s,1,idx);
  621. { check verbosity level }
  622. if not CheckVerbosity(v) then
  623. begin
  624. doqueue := onqueue <> nil;
  625. if not doqueue then
  626. exit;
  627. end;
  628. if (v and V_LineInfoMask)<>0 then
  629. v:=v or V_LineInfo;
  630. { fix status }
  631. UpdateStatus;
  632. { Fix replacements }
  633. DefaultReplacements(s);
  634. if status.showmsgnrs then
  635. s:='('+tostr(w)+') '+s;
  636. if doqueue then
  637. begin
  638. onqueue(s,v,w);
  639. exit;
  640. end;
  641. { show comment }
  642. if do_comment(v,s) or dostop then
  643. raise ECompilerAbort.Create;
  644. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  645. begin
  646. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  647. status.skip_error:=true;
  648. raise ECompilerAbort.Create;
  649. end;
  650. end;
  651. function MessagePchar(w:longint):pchar;
  652. begin
  653. MaybeLoadMessageFile;
  654. MessagePchar:=msg^.GetPchar(w)
  655. end;
  656. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  657. begin
  658. MaybeLoadMessageFile;
  659. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  660. end;
  661. procedure Message1(w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  662. begin
  663. MaybeLoadMessageFile;
  664. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  665. end;
  666. procedure Message2(w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  667. begin
  668. MaybeLoadMessageFile;
  669. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  670. end;
  671. procedure Message3(w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  672. begin
  673. MaybeLoadMessageFile;
  674. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  675. end;
  676. procedure Message4(w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  677. begin
  678. MaybeLoadMessageFile;
  679. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  680. end;
  681. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  682. var
  683. oldpos : tfileposinfo;
  684. begin
  685. oldpos:=current_filepos;
  686. current_filepos:=pos;
  687. MaybeLoadMessageFile;
  688. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  689. current_filepos:=oldpos;
  690. end;
  691. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  692. var
  693. oldpos : tfileposinfo;
  694. begin
  695. oldpos:=current_filepos;
  696. current_filepos:=pos;
  697. MaybeLoadMessageFile;
  698. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  699. current_filepos:=oldpos;
  700. end;
  701. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  702. var
  703. oldpos : tfileposinfo;
  704. begin
  705. oldpos:=current_filepos;
  706. current_filepos:=pos;
  707. MaybeLoadMessageFile;
  708. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  709. current_filepos:=oldpos;
  710. end;
  711. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  712. var
  713. oldpos : tfileposinfo;
  714. begin
  715. oldpos:=current_filepos;
  716. current_filepos:=pos;
  717. MaybeLoadMessageFile;
  718. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  719. current_filepos:=oldpos;
  720. end;
  721. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  722. var
  723. oldpos : tfileposinfo;
  724. begin
  725. oldpos:=current_filepos;
  726. current_filepos:=pos;
  727. MaybeLoadMessageFile;
  728. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  729. current_filepos:=oldpos;
  730. end;
  731. {*****************************************************************************
  732. override the message calls to set codegenerror
  733. *****************************************************************************}
  734. procedure cgmessage(t : longint);
  735. var
  736. olderrorcount : longint;
  737. begin
  738. if not(codegenerror) then
  739. begin
  740. olderrorcount:=Errorcount;
  741. verbose.Message(t);
  742. codegenerror:=olderrorcount<>Errorcount;
  743. end;
  744. end;
  745. procedure cgmessage1(t : longint;const s : TMsgStr);
  746. var
  747. olderrorcount : longint;
  748. begin
  749. if not(codegenerror) then
  750. begin
  751. olderrorcount:=Errorcount;
  752. verbose.Message1(t,s);
  753. codegenerror:=olderrorcount<>Errorcount;
  754. end;
  755. end;
  756. procedure cgmessage2(t : longint;const s1,s2 : TMsgStr);
  757. var
  758. olderrorcount : longint;
  759. begin
  760. if not(codegenerror) then
  761. begin
  762. olderrorcount:=Errorcount;
  763. verbose.Message2(t,s1,s2);
  764. codegenerror:=olderrorcount<>Errorcount;
  765. end;
  766. end;
  767. procedure cgmessage3(t : longint;const s1,s2,s3 : TMsgStr);
  768. var
  769. olderrorcount : longint;
  770. begin
  771. if not(codegenerror) then
  772. begin
  773. olderrorcount:=Errorcount;
  774. verbose.Message3(t,s1,s2,s3);
  775. codegenerror:=olderrorcount<>Errorcount;
  776. end;
  777. end;
  778. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  779. var
  780. olderrorcount : longint;
  781. begin
  782. if not(codegenerror) then
  783. begin
  784. olderrorcount:=Errorcount;
  785. verbose.MessagePos(pos,t);
  786. codegenerror:=olderrorcount<>Errorcount;
  787. end;
  788. end;
  789. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : TMsgStr);
  790. var
  791. olderrorcount : longint;
  792. begin
  793. if not(codegenerror) then
  794. begin
  795. olderrorcount:=Errorcount;
  796. verbose.MessagePos1(pos,t,s1);
  797. codegenerror:=olderrorcount<>Errorcount;
  798. end;
  799. end;
  800. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : TMsgStr);
  801. var
  802. olderrorcount : longint;
  803. begin
  804. if not(codegenerror) then
  805. begin
  806. olderrorcount:=Errorcount;
  807. verbose.MessagePos2(pos,t,s1,s2);
  808. codegenerror:=olderrorcount<>Errorcount;
  809. end;
  810. end;
  811. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : TMsgStr);
  812. var
  813. olderrorcount : longint;
  814. begin
  815. if not(codegenerror) then
  816. begin
  817. olderrorcount:=Errorcount;
  818. verbose.MessagePos3(pos,t,s1,s2,s3);
  819. codegenerror:=olderrorcount<>Errorcount;
  820. end;
  821. end;
  822. procedure FlushOutput;
  823. begin
  824. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  825. begin
  826. if Status.Use_Redir then
  827. Flush(Status.RedirFile)
  828. else
  829. Flush(Output);
  830. end;
  831. end;
  832. {*****************************************************************************
  833. Initialization
  834. *****************************************************************************}
  835. procedure InitVerbose;
  836. begin
  837. { Init }
  838. msg:=new(pmessage,Init(20,msgidxmax));
  839. if msg=nil then
  840. begin
  841. writeln('Fatal: MsgIdx Wrong');
  842. halt(3);
  843. end;
  844. {$ifndef EXTERN_MSG}
  845. msg^.LoadIntern(@msgtxt,msgtxtsize);
  846. {$else EXTERN_MSG}
  847. LoadMsgFile(exepath+'errore.msg');
  848. {$endif EXTERN_MSG}
  849. FillChar(Status,sizeof(TCompilerStatus),0);
  850. status.verbosity:=V_Default;
  851. Status.MaxErrorCount:=50;
  852. Status.codesize:=aword(-1);
  853. Status.datasize:=aword(-1);
  854. Loadprefixes;
  855. lastfileidx:=-1;
  856. lastmoduleidx:=-1;
  857. status.currentmodule:='';
  858. status.currentsource:='';
  859. status.currentsourcepath:='';
  860. { Register internalerrorproc for cutils/cclasses }
  861. internalerrorproc:=@internalerror;
  862. end;
  863. procedure DoneVerbose;
  864. begin
  865. if assigned(msg) then
  866. begin
  867. dispose(msg,Done);
  868. msg:=nil;
  869. end;
  870. DoneRedirectFile;
  871. end;
  872. initialization
  873. constexp.internalerror:=@internalerror;
  874. finalization
  875. { Be sure to close the redirect files to flush all data }
  876. DoneRedirectFile;
  877. end.