verbose.pas 31 KB

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