verbose.pas 32 KB

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