verbose.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. begin
  458. if (i<length(s)) and (s[i+1]='-') then
  459. begin
  460. inc(i);
  461. status.errorwarning:=false;
  462. end
  463. else
  464. status.errorwarning:=true;
  465. end;
  466. 'n','N' :
  467. begin
  468. if (i<length(s)) and (s[i+1]='-') then
  469. begin
  470. inc(i);
  471. status.errornote:=false;
  472. end
  473. else
  474. status.errornote:=true;
  475. end;
  476. 'h','H' :
  477. begin
  478. if (i<length(s)) and (s[i+1]='-') then
  479. begin
  480. inc(i);
  481. status.errorhint:=false;
  482. end
  483. else
  484. status.errorhint:=true;
  485. end;
  486. end;
  487. end;
  488. end;
  489. procedure GenerateError;
  490. begin
  491. inc(status.errorcount);
  492. end;
  493. procedure internalerror(i : longint);
  494. begin
  495. UpdateStatus;
  496. do_internalerror(i);
  497. inc(status.errorcount);
  498. raise ECompilerAbort.Create;
  499. end;
  500. procedure Comment(l:longint;s:ansistring);
  501. var
  502. dostop : boolean;
  503. begin
  504. dostop:=((l and V_Fatal)<>0);
  505. if ((l and V_Error)<>0) or
  506. ((l and V_Fatal)<>0) or
  507. (status.errorwarning and ((l and V_Warning)<>0)) or
  508. (status.errornote and ((l and V_Note)<>0)) or
  509. (status.errorhint and ((l and V_Hint)<>0)) then
  510. inc(status.errorcount)
  511. else
  512. if l and V_Warning <> 0 then
  513. inc(status.countWarnings)
  514. else
  515. if l and V_Note <> 0 then
  516. inc(status.countNotes)
  517. else
  518. if l and V_Hint <> 0 then
  519. inc(status.countHints);
  520. { check verbosity level }
  521. if not CheckVerbosity(l) then
  522. exit;
  523. if (l and V_LineInfoMask)<>0 then
  524. l:=l or V_LineInfo;
  525. { Create status info }
  526. UpdateStatus;
  527. { Fix replacements }
  528. DefaultReplacements(s);
  529. { show comment }
  530. if do_comment(l,s) or dostop then
  531. raise ECompilerAbort.Create;
  532. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  533. begin
  534. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  535. status.skip_error:=true;
  536. raise ECompilerAbort.Create;
  537. end;
  538. end;
  539. function GetMessageState(m:longint):tmsgstate;
  540. var
  541. i: integer;
  542. begin
  543. i:=m div 1000;
  544. { get the default state }
  545. Result:=msg^.msgstates[i]^[m mod 1000];
  546. { and search at the current unit settings }
  547. { todo }
  548. end;
  549. Procedure Msg2Comment(s:ansistring;w:longint;onqueue:tmsgqueueevent);
  550. var
  551. idx,i,v : longint;
  552. dostop : boolean;
  553. doqueue : boolean;
  554. st : tmsgstate;
  555. ch : char;
  556. begin
  557. {Reset}
  558. dostop:=false;
  559. doqueue:=false;
  560. v:=0;
  561. {Parse options}
  562. idx:=pos('_',s);
  563. if idx=0 then
  564. v:=V_None
  565. else
  566. if (idx >= 1) And (idx <= 5) then
  567. begin
  568. for i:=1 to idx do
  569. begin
  570. ch:=upcase(s[i]);
  571. case ch of
  572. 'F' :
  573. begin
  574. v:=v or V_Fatal;
  575. inc(status.errorcount);
  576. dostop:=true;
  577. end;
  578. 'E','W','N','H':
  579. begin
  580. if ch='E' then
  581. st:=ms_error
  582. else
  583. st:=GetMessageState(w);
  584. { We only want to know about local value }
  585. st:= tmsgstate(ord(st) and ms_local_mask);
  586. if st=ms_error then
  587. begin
  588. v:=v or V_Error;
  589. inc(status.errorcount);
  590. end
  591. else if st<>ms_off then
  592. case ch of
  593. 'W':
  594. begin
  595. v:=v or V_Warning;
  596. if CheckVerbosity(V_Warning) then
  597. if status.errorwarning then
  598. inc(status.errorcount)
  599. else
  600. inc(status.countWarnings);
  601. end;
  602. 'N' :
  603. begin
  604. v:=v or V_Note;
  605. if CheckVerbosity(V_Note) then
  606. if status.errornote then
  607. inc(status.errorcount)
  608. else
  609. inc(status.countNotes);
  610. end;
  611. 'H' :
  612. begin
  613. v:=v or V_Hint;
  614. if CheckVerbosity(V_Hint) then
  615. if status.errorhint then
  616. inc(status.errorcount)
  617. else
  618. inc(status.countHints);
  619. end;
  620. end;
  621. end;
  622. 'O' :
  623. v:=v or V_Normal;
  624. 'I' :
  625. v:=v or V_Info;
  626. 'L' :
  627. v:=v or V_LineInfo;
  628. 'U' :
  629. v:=v or V_Used;
  630. 'T' :
  631. v:=v or V_Tried;
  632. 'C' :
  633. v:=v or V_Conditional;
  634. 'D' :
  635. v:=v or V_Debug;
  636. 'X' :
  637. v:=v or V_Executable;
  638. 'S' :
  639. dostop:=true;
  640. '_' : ;
  641. end;
  642. end;
  643. end;
  644. Delete(s,1,idx);
  645. { check verbosity level }
  646. if not CheckVerbosity(v) then
  647. begin
  648. doqueue := onqueue <> nil;
  649. if not doqueue then
  650. exit;
  651. end;
  652. if (v and V_LineInfoMask)<>0 then
  653. v:=v or V_LineInfo;
  654. { fix status }
  655. UpdateStatus;
  656. { Fix replacements }
  657. DefaultReplacements(s);
  658. if status.showmsgnrs then
  659. s:='('+tostr(w)+') '+s;
  660. if doqueue then
  661. begin
  662. onqueue(s,v,w);
  663. exit;
  664. end;
  665. { show comment }
  666. if do_comment(v,s) or dostop then
  667. raise ECompilerAbort.Create;
  668. if (status.errorcount>=status.maxerrorcount) and not status.skip_error then
  669. begin
  670. Message1(unit_f_errors_in_unit,tostr(status.errorcount));
  671. status.skip_error:=true;
  672. raise ECompilerAbort.Create;
  673. end;
  674. end;
  675. function MessagePchar(w:longint):pchar;
  676. begin
  677. MaybeLoadMessageFile;
  678. MessagePchar:=msg^.GetPchar(w)
  679. end;
  680. procedure Message(w:longint;onqueue:tmsgqueueevent=nil);
  681. begin
  682. MaybeLoadMessageFile;
  683. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  684. end;
  685. procedure Message1(w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  686. begin
  687. MaybeLoadMessageFile;
  688. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  689. end;
  690. procedure Message2(w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  691. begin
  692. MaybeLoadMessageFile;
  693. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  694. end;
  695. procedure Message3(w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  696. begin
  697. MaybeLoadMessageFile;
  698. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  699. end;
  700. procedure Message4(w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  701. begin
  702. MaybeLoadMessageFile;
  703. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  704. end;
  705. procedure MessagePos(const pos:tfileposinfo;w:longint;onqueue:tmsgqueueevent=nil);
  706. var
  707. oldpos : tfileposinfo;
  708. begin
  709. oldpos:=current_filepos;
  710. current_filepos:=pos;
  711. MaybeLoadMessageFile;
  712. Msg2Comment(msg^.Get(w,[]),w,onqueue);
  713. current_filepos:=oldpos;
  714. end;
  715. procedure MessagePos1(const pos:tfileposinfo;w:longint;const s1:TMsgStr;onqueue:tmsgqueueevent=nil);
  716. var
  717. oldpos : tfileposinfo;
  718. begin
  719. oldpos:=current_filepos;
  720. current_filepos:=pos;
  721. MaybeLoadMessageFile;
  722. Msg2Comment(msg^.Get(w,[s1]),w,onqueue);
  723. current_filepos:=oldpos;
  724. end;
  725. procedure MessagePos2(const pos:tfileposinfo;w:longint;const s1,s2:TMsgStr;onqueue:tmsgqueueevent=nil);
  726. var
  727. oldpos : tfileposinfo;
  728. begin
  729. oldpos:=current_filepos;
  730. current_filepos:=pos;
  731. MaybeLoadMessageFile;
  732. Msg2Comment(msg^.Get(w,[s1,s2]),w,onqueue);
  733. current_filepos:=oldpos;
  734. end;
  735. procedure MessagePos3(const pos:tfileposinfo;w:longint;const s1,s2,s3:TMsgStr;onqueue:tmsgqueueevent=nil);
  736. var
  737. oldpos : tfileposinfo;
  738. begin
  739. oldpos:=current_filepos;
  740. current_filepos:=pos;
  741. MaybeLoadMessageFile;
  742. Msg2Comment(msg^.Get(w,[s1,s2,s3]),w,onqueue);
  743. current_filepos:=oldpos;
  744. end;
  745. procedure MessagePos4(const pos:tfileposinfo;w:longint;const s1,s2,s3,s4:TMsgStr;onqueue:tmsgqueueevent=nil);
  746. var
  747. oldpos : tfileposinfo;
  748. begin
  749. oldpos:=current_filepos;
  750. current_filepos:=pos;
  751. MaybeLoadMessageFile;
  752. Msg2Comment(msg^.Get(w,[s1,s2,s3,s4]),w,onqueue);
  753. current_filepos:=oldpos;
  754. end;
  755. {*****************************************************************************
  756. override the message calls to set codegenerror
  757. *****************************************************************************}
  758. procedure cgmessage(t : longint);
  759. var
  760. olderrorcount : longint;
  761. begin
  762. if not(codegenerror) then
  763. begin
  764. olderrorcount:=Errorcount;
  765. verbose.Message(t);
  766. codegenerror:=olderrorcount<>Errorcount;
  767. end;
  768. end;
  769. procedure cgmessage1(t : longint;const s : TMsgStr);
  770. var
  771. olderrorcount : longint;
  772. begin
  773. if not(codegenerror) then
  774. begin
  775. olderrorcount:=Errorcount;
  776. verbose.Message1(t,s);
  777. codegenerror:=olderrorcount<>Errorcount;
  778. end;
  779. end;
  780. procedure cgmessage2(t : longint;const s1,s2 : TMsgStr);
  781. var
  782. olderrorcount : longint;
  783. begin
  784. if not(codegenerror) then
  785. begin
  786. olderrorcount:=Errorcount;
  787. verbose.Message2(t,s1,s2);
  788. codegenerror:=olderrorcount<>Errorcount;
  789. end;
  790. end;
  791. procedure cgmessage3(t : longint;const s1,s2,s3 : TMsgStr);
  792. var
  793. olderrorcount : longint;
  794. begin
  795. if not(codegenerror) then
  796. begin
  797. olderrorcount:=Errorcount;
  798. verbose.Message3(t,s1,s2,s3);
  799. codegenerror:=olderrorcount<>Errorcount;
  800. end;
  801. end;
  802. procedure cgmessagepos(const pos:tfileposinfo;t : longint);
  803. var
  804. olderrorcount : longint;
  805. begin
  806. if not(codegenerror) then
  807. begin
  808. olderrorcount:=Errorcount;
  809. verbose.MessagePos(pos,t);
  810. codegenerror:=olderrorcount<>Errorcount;
  811. end;
  812. end;
  813. procedure cgmessagepos1(const pos:tfileposinfo;t : longint;const s1 : TMsgStr);
  814. var
  815. olderrorcount : longint;
  816. begin
  817. if not(codegenerror) then
  818. begin
  819. olderrorcount:=Errorcount;
  820. verbose.MessagePos1(pos,t,s1);
  821. codegenerror:=olderrorcount<>Errorcount;
  822. end;
  823. end;
  824. procedure cgmessagepos2(const pos:tfileposinfo;t : longint;const s1,s2 : TMsgStr);
  825. var
  826. olderrorcount : longint;
  827. begin
  828. if not(codegenerror) then
  829. begin
  830. olderrorcount:=Errorcount;
  831. verbose.MessagePos2(pos,t,s1,s2);
  832. codegenerror:=olderrorcount<>Errorcount;
  833. end;
  834. end;
  835. procedure cgmessagepos3(const pos:tfileposinfo;t : longint;const s1,s2,s3 : TMsgStr);
  836. var
  837. olderrorcount : longint;
  838. begin
  839. if not(codegenerror) then
  840. begin
  841. olderrorcount:=Errorcount;
  842. verbose.MessagePos3(pos,t,s1,s2,s3);
  843. codegenerror:=olderrorcount<>Errorcount;
  844. end;
  845. end;
  846. procedure FlushOutput;
  847. begin
  848. if not (Status.Use_StdErr) then (* StdErr is flushed after every line *)
  849. begin
  850. if Status.Use_Redir then
  851. Flush(Status.RedirFile)
  852. else
  853. Flush(Output);
  854. end;
  855. end;
  856. {*****************************************************************************
  857. Initialization
  858. *****************************************************************************}
  859. procedure InitVerbose;
  860. begin
  861. { Init }
  862. msg:=new(pmessage,Init(20,msgidxmax));
  863. if msg=nil then
  864. begin
  865. writeln('Fatal: MsgIdx Wrong');
  866. halt(3);
  867. end;
  868. {$ifndef EXTERN_MSG}
  869. msg^.LoadIntern(@msgtxt,msgtxtsize);
  870. {$else EXTERN_MSG}
  871. LoadMsgFile(exepath+'errore.msg');
  872. {$endif EXTERN_MSG}
  873. FillChar(Status,sizeof(TCompilerStatus),0);
  874. status.verbosity:=V_Default;
  875. Status.MaxErrorCount:=50;
  876. Status.codesize:=aword(-1);
  877. Status.datasize:=aword(-1);
  878. Loadprefixes;
  879. lastfileidx:=-1;
  880. lastmoduleidx:=-1;
  881. status.currentmodule:='';
  882. status.currentsource:='';
  883. status.currentsourcepath:='';
  884. { Register internalerrorproc for cutils/cclasses }
  885. internalerrorproc:=@internalerror;
  886. end;
  887. procedure DoneVerbose;
  888. begin
  889. if assigned(msg) then
  890. begin
  891. dispose(msg,Done);
  892. msg:=nil;
  893. end;
  894. DoneRedirectFile;
  895. end;
  896. initialization
  897. constexp.internalerror:=@internalerror;
  898. finalization
  899. { Be sure to close the redirect files to flush all data }
  900. DoneRedirectFile;
  901. end.