fpcompil.pas 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Compiler call routines for the IDE
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  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.
  11. **********************************************************************}
  12. {$i globdir.inc}
  13. unit FPCompil;
  14. interface
  15. { don't redir under linux, because all stdout (also from the ide!) will
  16. then be redired (PFV) }
  17. { this should work now correctly because
  18. RedirDisableAll and RedirEnableAll function are added in fpredir (PM) }
  19. { $define VERBOSETXT}
  20. {$mode objfpc}
  21. uses
  22. Objects,
  23. {$ifdef COMPILER_1_0}
  24. Files,
  25. {$else COMPILER_1_0}
  26. FInput,
  27. {$endif COMPILER_1_0}
  28. Drivers,Views,Dialogs,
  29. WUtils,WViews,WCEdit,
  30. FPSymbol,
  31. FPViews;
  32. type
  33. TCompileMode = (cBuild,cMake,cCompile,cRun);
  34. type
  35. PCompilerMessage = ^TCompilerMessage;
  36. TCompilerMessage = object(TMessageItem)
  37. function GetText(MaxLen: Sw_Integer): String; virtual;
  38. end;
  39. PCompilerMessageListBox = ^TCompilerMessageListBox;
  40. TCompilerMessageListBox = object(TMessageListBox)
  41. function GetPalette: PPalette; virtual;
  42. procedure SelectFirstError;
  43. end;
  44. PCompilerMessageWindow = ^TCompilerMessageWindow;
  45. TCompilerMessageWindow = object(TFPWindow)
  46. constructor Init;
  47. procedure HandleEvent(var Event: TEvent); virtual;
  48. function GetPalette: PPalette; virtual;
  49. procedure Close;virtual;
  50. destructor Done; virtual;
  51. procedure SizeLimits(var Min, Max: TPoint); virtual;
  52. procedure AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  53. procedure ClearMessages;
  54. constructor Load(var S: TStream);
  55. procedure Store(var S: TStream);
  56. procedure SetState(AState: Word; Enable: Boolean); virtual;
  57. procedure UpdateCommands; virtual;
  58. private
  59. {CompileShowed : boolean;}
  60. {Mode : TCompileMode;}
  61. MsgLB : PCompilerMessageListBox;
  62. {CurrST,
  63. InfoST : PColorStaticText;}
  64. end;
  65. PCompilerStatusDialog = ^TCompilerStatusDialog;
  66. TCompilerStatusDialog = object(TCenterDialog)
  67. ST : PAdvancedStaticText;
  68. KeyST : PColorStaticText;
  69. constructor Init;
  70. destructor Done;virtual;
  71. procedure Update;
  72. end;
  73. {$ifdef COMPILER_1_0}
  74. PFPInputFile = ^TFPInputFile;
  75. TFPInputFile = object(tinputfile)
  76. constructor Init(AEditor: PFileEditor);
  77. {$ifdef FPC}protected{$else}public{$endif}
  78. function fileopen(const filename: string): boolean; virtual;
  79. function fileseek(pos: longint): boolean; virtual;
  80. function fileread(var databuf; maxsize: longint): longint; virtual;
  81. function fileeof: boolean; virtual;
  82. function fileclose: boolean; virtual;
  83. private
  84. Editor: PFileEditor;
  85. S: PStream;
  86. end;
  87. {$else COMPILER_1_0}
  88. TFPInputFile = class(tinputfile)
  89. constructor Create(AEditor: PFileEditor);
  90. {$ifdef FPC}protected{$else}public{$endif}
  91. function fileopen(const filename: string): boolean; override;
  92. function fileseek(pos: longint): boolean; override;
  93. function fileread(var databuf; maxsize: longint): longint; override;
  94. function fileeof: boolean; override;
  95. function fileclose: boolean; override;
  96. private
  97. Editor: PFileEditor;
  98. S: PStream;
  99. end;
  100. {$endif COMPILER_1_0}
  101. const
  102. CompilerMessageWindow : PCompilerMessageWindow = nil;
  103. CompilerStatusDialog : PCompilerStatusDialog = nil;
  104. CompileStamp : longint = 0;
  105. RestartingDebugger : boolean = false;
  106. procedure DoCompile(Mode: TCompileMode);
  107. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  108. procedure ParseUserScreen;
  109. procedure RegisterFPCompile;
  110. const
  111. CompilingHiddenFile : PSourceWindow = nil;
  112. implementation
  113. uses
  114. {$ifdef Unix}
  115. {$ifdef VER1_0}
  116. Linux,
  117. {$else}
  118. Unix, BaseUnix,
  119. {$endif}
  120. {$endif}
  121. {$ifdef go32v2}
  122. dpmiexcp,
  123. {$endif}
  124. {$ifdef win32}
  125. signals,
  126. {$endif}
  127. {$ifdef HasSignal}
  128. fpcatch,
  129. {$endif HasSignal}
  130. Dos,
  131. {$ifdef fpc}
  132. Video,
  133. {$endif fpc}
  134. StdDlg,App,tokens,
  135. {$ifdef FVISION}
  136. FVConsts,
  137. {$else}
  138. Commands,
  139. {$endif}
  140. CompHook, Compiler, systems, browcol,
  141. WEditor,
  142. FPString,FPRedir,FPDesk,
  143. FPUsrScr,FPHelp,
  144. {$ifndef NODEBUG}FPDebug,{$endif}
  145. FPConst,FPVars,FPUtils,
  146. FPCodCmp,FPIntf,FPSwitch;
  147. {$ifndef NOOBJREG}
  148. const
  149. RCompilerMessageListBox: TStreamRec = (
  150. ObjType: 1211;
  151. VmtLink: Ofs(TypeOf(TCompilerMessageListBox)^);
  152. Load: @TCompilerMessageListBox.Load;
  153. Store: @TCompilerMessageListBox.Store
  154. );
  155. RCompilerMessageWindow: TStreamRec = (
  156. ObjType: 1212;
  157. VmtLink: Ofs(TypeOf(TCompilerMessageWindow)^);
  158. Load: @TCompilerMessageWindow.Load;
  159. Store: @TCompilerMessageWindow.Store
  160. );
  161. {$endif}
  162. procedure ParseUserScreen;
  163. var
  164. y : longint;
  165. Text,Attr : String;
  166. DisplayCompilerWindow : boolean;
  167. cc: integer;
  168. procedure SearchBackTrace;
  169. var AText,ModuleName,st : String;
  170. row : longint;
  171. begin
  172. if pos(' 0x',Text)=1 then
  173. begin
  174. AText:=Text;
  175. Delete(Text,1,10);
  176. While pos(' ',Text)=1 do
  177. Delete(Text,1,1);
  178. if pos('of ',Text)>0 then
  179. begin
  180. ModuleName:=Copy(Text,pos('of ',Text)+3,255);
  181. While ModuleName[Length(ModuleName)]=' ' do
  182. Delete(ModuleName,Length(ModuleName),1);
  183. end
  184. else
  185. ModuleName:='';
  186. if pos('line ',Text)>0 then
  187. begin
  188. Text:=Copy(Text,Pos('line ',Text)+5,255);
  189. st:=Copy(Text,1,Pos(' ',Text)-1);
  190. Val(st,row,cc);
  191. end
  192. else
  193. row:=0;
  194. CompilerMessageWindow^.AddMessage(V_Fatal,AText
  195. ,ModuleName,row,1);
  196. DisplayCompilerWindow:=true;
  197. end;
  198. end;
  199. procedure InsertInMessages(Const TypeStr : String;_Type : longint;EnableDisplay : boolean);
  200. var p,p2,col,row : longint;
  201. St,ModuleName : string;
  202. begin
  203. p:=pos(TypeStr,Text);
  204. p2:=Pos('(',Text);
  205. if (p>0) and (p2>0) and (p2<p) then
  206. begin
  207. ModuleName:=Copy(Text,1,p2-1);
  208. st:=Copy(Text,p2+1,255);
  209. Val(Copy(st,1,pos(',',st)-1),row,cc);
  210. st:=Copy(st,Pos(',',st)+1,255);
  211. Val(Copy(st,1,pos(')',st)-1),col,cc);
  212. CompilerMessageWindow^.AddMessage(_type,Copy(Text,pos(':',Text)+1,255)
  213. ,ModuleName,row,col);
  214. If EnableDisplay then
  215. DisplayCompilerWindow:=true;
  216. end;
  217. end;
  218. begin
  219. if not assigned(UserScreen) then
  220. exit;
  221. DisplayCompilerWindow:=false;
  222. PushStatus('Parsing User Screen');
  223. CompilerMessageWindow^.Lock;
  224. for Y:=0 to UserScreen^.GetHeight do
  225. begin
  226. UserScreen^.GetLine(Y,Text,Attr);
  227. SearchBackTrace;
  228. InsertInMessages(' Fatal:',v_Fatal,true);
  229. InsertInMessages(' Error:',v_Error,true);
  230. InsertInMessages(' Warning:',v_Warning,false);
  231. InsertInMessages(' Note:',v_Note,false);
  232. InsertInMessages(' Info:',v_Info,false);
  233. InsertInMessages(' Hint:',v_Hint,false);
  234. end;
  235. if DisplayCompilerWindow then
  236. begin
  237. if not CompilerMessageWindow^.GetState(sfVisible) then
  238. CompilerMessageWindow^.Show;
  239. CompilerMessageWindow^.MakeFirst;
  240. CompilerMessageWindow^.MsgLB^.SelectFirstError;
  241. end;
  242. CompilerMessageWindow^.UnLock;
  243. PopStatus;
  244. end;
  245. {*****************************************************************************
  246. TCompilerMessage
  247. *****************************************************************************}
  248. function TCompilerMessage.GetText(MaxLen: Sw_Integer): String;
  249. var
  250. ClassS: string[20];
  251. S: string;
  252. begin
  253. if TClass=
  254. V_Fatal then ClassS:=msg_class_Fatal else if TClass =
  255. V_Error then ClassS:=msg_class_Error else if TClass =
  256. V_Normal then ClassS:=msg_class_Normal else if TClass =
  257. V_Warning then ClassS:=msg_class_Warning else if TClass =
  258. V_Note then ClassS:=msg_class_Note else if TClass =
  259. V_Hint then ClassS:=msg_class_Hint
  260. {$ifdef VERBOSETXT}
  261. else if TClass =
  262. {$ifdef COMPILER_1_0}
  263. V_Macro then ClassS:=msg_class_macro else if TClass =
  264. V_Procedure then ClassS:=msg_class_procedure else if TClass =
  265. {$endif}
  266. V_Conditional then ClassS:=msg_class_conditional else if TClass =
  267. V_Info then ClassS:=msg_class_info else if TClass =
  268. V_Status then ClassS:=msg_class_status else if TClass =
  269. V_Used then ClassS:=msg_class_used else if TClass =
  270. V_Tried then ClassS:=msg_class_tried else if TClass =
  271. V_Debug then ClassS:=msg_class_debug
  272. else
  273. ClassS:='???';
  274. {$else}
  275. else
  276. ClassS:='';
  277. {$endif}
  278. if ClassS<>'' then
  279. ClassS:=RExpand(ClassS,0)+': ';
  280. if assigned(Module) and
  281. {$ifdef COMPILER_1_0}
  282. (TClass<=V_ShowFile)
  283. {$else}
  284. ((TClass and V_LineInfo)=V_LineInfo)
  285. {$endif}
  286. {and (status.currentsource<>'') and (status.currentline>0)} then
  287. begin
  288. if Row>0 then
  289. begin
  290. if Col>0 then
  291. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+','+IntToStr(Col)+') '+ClassS
  292. else
  293. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS;
  294. end
  295. else
  296. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS
  297. end
  298. else
  299. S:=ClassS;
  300. if assigned(Text) then
  301. S:=S+Text^;
  302. if length(S)>MaxLen then
  303. S:=copy(S,1,MaxLen-2)+'..';
  304. GetText:=S;
  305. end;
  306. {*****************************************************************************
  307. TCompilerMessageListBox
  308. *****************************************************************************}
  309. function TCompilerMessageListBox.GetPalette: PPalette;
  310. const
  311. P: string[length(CBrowserListBox)] = CBrowserListBox;
  312. begin
  313. GetPalette:=@P;
  314. end;
  315. procedure TCompilerMessageListBox.SelectFirstError;
  316. function IsError(P : PCompilerMessage) : boolean;
  317. begin
  318. IsError:=(P^.TClass and (V_Fatal or V_Error))<>0;
  319. end;
  320. var
  321. P : PCompilerMessage;
  322. begin
  323. P:=List^.FirstThat(@IsError);
  324. If Assigned(P) then
  325. Begin
  326. FocusItem(List^.IndexOf(P));
  327. DrawView;
  328. End;
  329. end;
  330. {*****************************************************************************
  331. TCompilerMessageWindow
  332. *****************************************************************************}
  333. constructor TCompilerMessageWindow.Init;
  334. var R: TRect;
  335. HSB,VSB: PScrollBar;
  336. begin
  337. Desktop^.GetExtent(R);
  338. R.A.Y:=R.B.Y-7;
  339. inherited Init(R,dialog_compilermessages,{SearchFreeWindowNo}wnNoNumber);
  340. HelpCtx:=hcCompilerMessagesWindow;
  341. AutoNumber:=true;
  342. HSB:=StandardScrollBar(sbHorizontal+sbHandleKeyboard);
  343. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  344. Insert(HSB);
  345. VSB:=StandardScrollBar(sbVertical+sbHandleKeyboard);
  346. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  347. Insert(VSB);
  348. GetExtent(R);
  349. R.Grow(-1,-1);
  350. New(MsgLB, Init(R, HSB, VSB));
  351. MsgLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  352. Insert(MsgLB);
  353. CompilerMessageWindow:=@self;
  354. end;
  355. procedure TCompilerMessageWindow.AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  356. begin
  357. {$ifdef COMPILER_1_0}
  358. if AClass>=V_Info then
  359. {$else}
  360. if (AClass and V_LineInfo)<>V_LineInfo then
  361. {$endif}
  362. Line:=0;
  363. MsgLB^.AddItem(New(PCompilerMessage,Init(AClass, Msg, MsgLB^.AddModuleName(Module), Line, Column)));
  364. if (@Self=CompilerMessageWindow) and ((AClass = V_fatal) or (AClass = V_Error)) then
  365. begin
  366. if not GetState(sfVisible) then
  367. Show;
  368. if Desktop^.First<>PView(CompilerMessageWindow) then
  369. MakeFirst;
  370. end;
  371. end;
  372. procedure TCompilerMessageWindow.ClearMessages;
  373. begin
  374. MsgLB^.Clear;
  375. ReDraw;
  376. end;
  377. {procedure TCompilerMessageWindow.Updateinfo;
  378. begin
  379. if CompileShowed then
  380. begin
  381. InfoST^.SetText(
  382. RExpand(' Main file : '#1#$7f+Copy(SmartPath(MainFile),1,39),40)+#2+
  383. 'Total lines : '#1#$7e+IntToStr(Status.CompiledLines)+#2#13+
  384. RExpand(' Target : '#1#$7f+KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)),40)+#2+
  385. 'Total errors : '#1#$7e+IntToStr(Status.ErrorCount)
  386. );
  387. if status.currentline>0 then
  388. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+'('+IntToStr(status.currentline)+')'#2)
  389. else
  390. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+#2);
  391. end;
  392. ReDraw;
  393. end;}
  394. procedure TCompilerMessageWindow.HandleEvent(var Event: TEvent);
  395. begin
  396. case Event.What of
  397. evBroadcast :
  398. case Event.Command of
  399. cmListFocusChanged :
  400. if Event.InfoPtr=MsgLB then
  401. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  402. end;
  403. end;
  404. inherited HandleEvent(Event);
  405. end;
  406. procedure TCompilerMessageWindow.SizeLimits(var Min, Max: TPoint);
  407. begin
  408. inherited SizeLimits(Min,Max);
  409. Min.X:=20;
  410. Min.Y:=4;
  411. end;
  412. procedure TCompilerMessageWindow.Close;
  413. begin
  414. Hide;
  415. end;
  416. function TCompilerMessageWindow.GetPalette: PPalette;
  417. const
  418. S : string[length(CBrowserWindow)] = CBrowserWindow;
  419. begin
  420. GetPalette:=@S;
  421. end;
  422. constructor TCompilerMessageWindow.Load(var S: TStream);
  423. begin
  424. inherited Load(S);
  425. GetSubViewPtr(S,MsgLB);
  426. end;
  427. procedure TCompilerMessageWindow.Store(var S: TStream);
  428. begin
  429. if MsgLB^.List=nil then
  430. MsgLB^.NewList(New(PCollection, Init(100,100)));
  431. inherited Store(S);
  432. PutSubViewPtr(S,MsgLB);
  433. end;
  434. procedure TCompilerMessageWindow.UpdateCommands;
  435. var Active: boolean;
  436. begin
  437. Active:=GetState(sfActive);
  438. SetCmdState(CompileCmds,Active);
  439. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  440. end;
  441. procedure TCompilerMessageWindow.SetState(AState: Word; Enable: Boolean);
  442. var OldState: word;
  443. begin
  444. OldState:=State;
  445. inherited SetState(AState,Enable);
  446. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  447. UpdateCommands;
  448. end;
  449. destructor TCompilerMessageWindow.Done;
  450. begin
  451. CompilerMessageWindow:=nil;
  452. inherited Done;
  453. end;
  454. {****************************************************************************
  455. CompilerStatusDialog
  456. ****************************************************************************}
  457. constructor TCompilerStatusDialog.Init;
  458. var R: TRect;
  459. begin
  460. R.Assign(0,0,50,11);
  461. ClearFormatParams; AddFormatParamStr(KillTilde(SwitchesModeName[SwitchesMode]));
  462. inherited Init(R, FormatStrF(dialog_compilingwithmode, FormatParams));
  463. GetExtent(R); R.B.Y:=11;
  464. R.Grow(-3,-2);
  465. New(ST, Init(R, ''));
  466. Insert(ST);
  467. GetExtent(R); R.B.Y:=11;
  468. R.Grow(-1,-1); R.A.Y:=R.B.Y-1;
  469. New(KeyST, Init(R, '', Blue*16+White+longint($80+Blue*16+White)*256,true));
  470. Insert(KeyST);
  471. { Reset Status infos see bug 1585 }
  472. Fillchar(Status,SizeOf(Status),#0);
  473. end;
  474. destructor TCompilerStatusDialog.Done;
  475. begin
  476. if @Self=CompilerStatusDialog then
  477. CompilerStatusDialog:=nil;
  478. Inherited Done;
  479. end;
  480. procedure TCompilerStatusDialog.Update;
  481. var
  482. StatusS,KeyS: string;
  483. const
  484. MaxFileNameSize = 46;
  485. begin
  486. case CompilationPhase of
  487. cpCompiling :
  488. begin
  489. ClearFormatParams;
  490. if Status.Compiling_current then
  491. begin
  492. AddFormatParamStr(ShrinkPath(SmartPath(Status.Currentsourcepath+Status.CurrentSource),
  493. MaxFileNameSize - Length(msg_compilingfile)));
  494. StatusS:=FormatStrF(msg_compilingfile,FormatParams);
  495. end
  496. else
  497. begin
  498. if Status.CurrentSource='' then
  499. StatusS:=''
  500. else
  501. begin
  502. StatusS:=ShrinkPath(SmartPath(DirAndNameOf(Status.Currentsourcepath+Status.CurrentSource)),
  503. MaxFileNameSize-Length(msg_loadingunit));
  504. AddFormatParamStr(StatusS);
  505. StatusS:=FormatStrF(msg_loadingunit,FormatParams);
  506. end;
  507. end;
  508. KeyS:=msg_hint_pressesctocancel;
  509. end;
  510. cpLinking :
  511. begin
  512. ClearFormatParams;
  513. AddFormatParamStr(ShrinkPath(ExeFile,
  514. MaxFileNameSize-Length(msg_linkingfile)));
  515. StatusS:=FormatStrF(msg_linkingfile,FormatParams);
  516. KeyS:=msg_hint_pleasewait;
  517. end;
  518. cpDone :
  519. begin
  520. StatusS:=msg_compiledone;
  521. KeyS:=msg_hint_compilesuccessfulpressenter;
  522. end;
  523. cpFailed :
  524. begin
  525. StatusS:=msg_failedtocompile;
  526. KeyS:=msg_hint_compilefailed;
  527. end;
  528. cpAborted :
  529. begin
  530. StatusS:=msg_compilationaborted;
  531. KeyS:=msg_hint_compileaborted;
  532. end;
  533. end;
  534. ClearFormatParams;
  535. AddFormatParamStr(ShrinkPath(SmartPath(MainFile),
  536. MaxFileNameSize-Length('Main file: %s')));
  537. AddFormatParamStr(StatusS);
  538. AddFormatParamStr(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)));
  539. AddFormatParamInt(Status.CurrentLine);
  540. AddFormatParamInt(MemAvail div 1024);
  541. AddFormatParamInt(Status.CompiledLines);
  542. AddFormatParamInt(Status.ErrorCount);
  543. ST^.SetText(
  544. FormatStrF(
  545. 'Main file: %s'#13+
  546. '%s'+#13#13+
  547. 'Target: %12s '+ 'Line number: %7d'+#13+
  548. 'Free memory: %6dK '+'Total lines: %7d'+#13+
  549. 'Total errors: %5d',
  550. FormatParams)
  551. );
  552. KeyST^.SetText(^C+KeyS);
  553. end;
  554. {****************************************************************************
  555. Compiler Hooks
  556. ****************************************************************************}
  557. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  558. var
  559. event : tevent;
  560. begin
  561. GetKeyEvent(Event);
  562. if (Event.What=evKeyDown) and (Event.KeyCode=kbEsc) then
  563. begin
  564. CompilationPhase:=cpAborted;
  565. { update info messages }
  566. if assigned(CompilerStatusDialog) then
  567. begin
  568. {$ifdef redircompiler}
  569. RedirDisableAll;
  570. {$endif}
  571. CompilerStatusDialog^.Update;
  572. {$ifdef redircompiler}
  573. RedirEnableAll;
  574. {$endif}
  575. end;
  576. CompilerStatus:=true;
  577. exit;
  578. end;
  579. { only display line info every 100 lines, ofcourse all other messages
  580. will be displayed directly }
  581. if (status.currentline mod 100=0) then
  582. begin
  583. { update info messages }
  584. {$ifdef redircompiler}
  585. RedirDisableAll;
  586. {$endif}
  587. if assigned(CompilerStatusDialog) then
  588. CompilerStatusDialog^.Update;
  589. {$ifdef redircompiler}
  590. RedirEnableAll;
  591. {$endif}
  592. { update memory usage }
  593. { HeapView^.Update; }
  594. end;
  595. CompilerStatus:=false;
  596. end;
  597. const
  598. LONGJMPCALLED = -1;
  599. procedure CompilerStop(err: longint); {$ifndef FPC}far;{$endif}
  600. begin
  601. {$ifndef GABOR}
  602. {$ifdef HasSignal}
  603. if StopJmpValid then
  604. Longjmp(StopJmp,LONGJMPCALLED)
  605. else
  606. Halt(err);
  607. {$endif}
  608. {$endif}
  609. end;
  610. Function CompilerGetNamedFileTime(const filename : string) : Longint; {$ifndef FPC}far;{$endif}
  611. var t: longint;
  612. W: PSourceWindow;
  613. begin
  614. W:=EditorWindowFile(FExpand(filename));
  615. if Assigned(W) and (W^.Editor^.GetModified) then
  616. t:=Now
  617. else
  618. t:=def_getnamedfiletime(filename);
  619. CompilerGetNamedFileTime:=t;
  620. end;
  621. {$ifdef COMPILER_1_0}
  622. function CompilerOpenInputFile(const filename: string): pinputfile; {$ifndef FPC}far;{$endif}
  623. var f: pinputfile;
  624. W: PSourceWindow;
  625. begin
  626. if assigned(CompilingHiddenFile) and
  627. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  628. W:=CompilingHiddenFile
  629. else
  630. W:=EditorWindowFile(FExpand(filename));
  631. if Assigned(W) and (W^.Editor^.GetModified) then
  632. f:=new(PFPInputFile, Init(W^.Editor))
  633. else
  634. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  635. if assigned(W) then
  636. W^.Editor^.CompileStamp:=CompileStamp;
  637. CompilerOpenInputFile:=f;
  638. end;
  639. {$else COMPILER_1_0}
  640. function CompilerOpenInputFile(const filename: string): tinputfile; {$ifndef FPC}far;{$endif}
  641. var f: tinputfile;
  642. W: PSourceWindow;
  643. begin
  644. if assigned(CompilingHiddenFile) and
  645. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  646. W:=CompilingHiddenFile
  647. else
  648. W:=EditorWindowFile(FExpand(filename));
  649. if Assigned(W) and (W^.Editor^.GetModified) then
  650. f:=TFPInputFile.Create(W^.Editor)
  651. else
  652. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  653. if assigned(W) then
  654. W^.Editor^.CompileStamp:=CompileStamp;
  655. CompilerOpenInputFile:=f;
  656. end;
  657. {$endif COMPILER_1_0}
  658. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  659. begin
  660. CompilerComment:=false;
  661. if (status.verbosity and Level)<>0 then
  662. begin
  663. {$ifdef redircompiler}
  664. RedirDisableAll;
  665. {$endif}
  666. if not CompilerMessageWindow^.GetState(sfVisible) then
  667. CompilerMessageWindow^.Show;
  668. if Desktop^.First<>PView(CompilerMessageWindow) then
  669. CompilerMessageWindow^.MakeFirst;
  670. CompilerMessageWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  671. status.currentline,status.currentcolumn);
  672. { update info messages }
  673. if assigned(CompilerStatusDialog) then
  674. CompilerStatusDialog^.Update;
  675. {$ifdef DEBUG}
  676. {$ifndef NODEBUG}
  677. // def_gdb_stop(level);
  678. {$endif}
  679. {$endif DEBUG}
  680. {$ifdef redircompiler}
  681. RedirEnableAll;
  682. {$endif}
  683. { update memory usage }
  684. { HeapView^.Update; }
  685. end;
  686. end;
  687. {****************************************************************************
  688. DoCompile
  689. ****************************************************************************}
  690. { This function must return '' if
  691. "Options|Directories|Exe and PPU directory" is empty }
  692. function GetExePath: string;
  693. var Path: string;
  694. I: Sw_integer;
  695. begin
  696. Path:='';
  697. if DirectorySwitches<>nil then
  698. with DirectorySwitches^ do
  699. for I:=0 to ItemCount-1 do
  700. begin
  701. if ItemParam(I)='-FE' then
  702. begin
  703. Path:=GetStringItem(I);
  704. Break;
  705. end;
  706. end;
  707. if Path<>'' then
  708. GetExePath:=CompleteDir(FExpand(Path))
  709. else
  710. GetExePath:='';
  711. end;
  712. function GetMainFile(Mode: TCompileMode): string;
  713. var FileName: string;
  714. P : PSourceWindow;
  715. begin
  716. if assigned(CompilingHiddenFile) then
  717. P:=CompilingHiddenFile
  718. else
  719. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  720. if (PrimaryFileMain='') and (P=nil) then
  721. FileName:='' { nothing to compile }
  722. else
  723. begin
  724. if (PrimaryFileMain<>'') and (Mode<>cCompile) then
  725. FileName:=PrimaryFileMain
  726. else if assigned(P) then
  727. begin
  728. FileName:=P^.Editor^.FileName;
  729. if FileName='' then
  730. begin
  731. P^.Editor^.SaveAsk(true);
  732. FileName:=P^.Editor^.FileName;
  733. end;
  734. end
  735. else
  736. FileName:='';
  737. end;
  738. If (FileName<>'') then
  739. FileName:=FixFileName(FExpand(FileName));
  740. GetMainFile:=FileName;
  741. end;
  742. procedure ResetErrorMessages;
  743. procedure ResetErrorLine(P: PView); {$ifndef FPC}far;{$endif}
  744. begin
  745. if assigned(P) and
  746. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  747. PSourceWindow(P)^.Editor^.SetErrorMessage('');
  748. end;
  749. begin
  750. Desktop^.ForEach(@ResetErrorLine);
  751. end;
  752. procedure DoCompile(Mode: TCompileMode);
  753. function IsExitEvent(E: TEvent): boolean;
  754. begin
  755. { following suggestion by Harsha Senanayake }
  756. IsExitEvent:=(E.What=evKeyDown);
  757. end;
  758. function GetTargetExeExt : string;
  759. begin
  760. {$ifdef COMPILER_1_0}
  761. GetTargetExeExt:=target_os.exeext;
  762. {$else COMPILER_1_0}
  763. GetTargetExeExt:=target_info.exeext;
  764. {$endif COMPILER_1_0}
  765. end;
  766. var
  767. s,FileName: string;
  768. ErrFile : Text;
  769. MustRestartDebugger,
  770. StoreStopJumpValid : boolean;
  771. StoreStopJmp : Jmp_buf;
  772. StoreExitProc : pointer;
  773. JmpRet,Error,LinkErrorCount : longint;
  774. E : TEvent;
  775. DummyView: PView;
  776. PPasFile : string[64];
  777. begin
  778. AskRecompileIfModifiedFlag:=true;
  779. { Get FileName }
  780. FileName:=GetMainFile(Mode);
  781. if FileName='' then
  782. begin
  783. ErrorBox(msg_nothingtocompile,nil);
  784. Exit;
  785. end else
  786. { THis is not longer necessary as unsaved files are loaded from a memorystream,
  787. and with the file as primaryfile set it is already incompatible with itself
  788. if FileName='*' then
  789. begin
  790. ErrorBox(msg_cantcompileunsavedfile,nil);
  791. Exit;
  792. end; }
  793. PushStatus('Beginning compilation...');
  794. { Show Compiler Messages Window }
  795. { if not CompilerMessageWindow^.GetState(sfVisible) then
  796. CompilerMessageWindow^.Show;
  797. CompilerMessageWindow^.MakeFirst;}
  798. CompilerMessageWindow^.ClearMessages;
  799. { Tell why we compile }
  800. NeedRecompile(Mode,true);
  801. MainFile:=FileName;
  802. SetStatus('Writing switches to file...');
  803. WriteSwitches(SwitchesPath);
  804. { leaving open browsers leads to crashes !! (PM) }
  805. SetStatus('Preparing symbol info...');
  806. CloseAllBrowsers;
  807. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  808. WriteSymbolsFile(BrowserName);
  809. { MainFile:=FixFileName(FExpand(FileName));}
  810. SetStatus('Preparing to compile...'+NameOf(MainFile));
  811. { Reset }
  812. CtrlBreakHit:=false;
  813. { Create Compiler Status Dialog }
  814. CompilationPhase:=cpCompiling;
  815. if not assigned(CompilingHiddenFile) then
  816. begin
  817. New(CompilerStatusDialog, Init);
  818. CompilerStatusDialog^.SetState(sfModal,true);
  819. { disable window closing }
  820. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags and not wfclose;
  821. Application^.Insert(CompilerStatusDialog);
  822. CompilerStatusDialog^.Update;
  823. end;
  824. { hook compiler output }
  825. do_status:=@CompilerStatus;
  826. do_stop:=@CompilerStop;
  827. do_comment:=@CompilerComment;
  828. do_openinputfile:=@CompilerOpenInputFile;
  829. do_getnamedfiletime:=@CompilerGetNamedFileTime;
  830. do_initsymbolinfo:=@InitBrowserCol;
  831. do_donesymbolinfo:=@DoneBrowserCol;
  832. do_extractsymbolinfo:=@CreateBrowserCol;
  833. { Compile ! }
  834. {$ifdef redircompiler}
  835. ChangeRedirOut(FPOutFileName,false);
  836. ChangeRedirError(FPErrFileName,false);
  837. {$endif}
  838. { insert "" around name so that spaces are allowed }
  839. { only supported in compiler after 2000/01/14 PM }
  840. if pos(' ',FileName)>0 then
  841. FileName:='"'+FileName+'"';
  842. if mode=cBuild then
  843. FileName:='-B '+FileName;
  844. { tokens are created and distroed by compiler.compile !! PM }
  845. DoneTokens;
  846. {$ifdef COMPILER_1_0}
  847. PPasFile:='ppas'+source_os.scriptext;
  848. {$else COMPILER_1_0}
  849. PPasFile:='ppas'+source_info.scriptext;
  850. {$endif COMPILER_1_0}
  851. WUtils.DeleteFile(GetExePath+PpasFile);
  852. SetStatus('Compiling...');
  853. {$ifndef GABOR}
  854. {$ifdef HasSignal}
  855. StoreStopJumpValid:=StopJmpValid;
  856. StoreStopJmp:=StopJmp;
  857. {$endif HasSignal}
  858. StoreExitProc:=ExitProc;
  859. {$ifdef HasSignal}
  860. StopJmpValid:=true;
  861. JmpRet:=SetJmp(StopJmp);
  862. {$else}
  863. JmpRet:=0;
  864. {$endif HasSignal}
  865. if JmpRet=0 then
  866. begin
  867. inc(CompileStamp);
  868. ResetErrorMessages;
  869. {$ifndef NODEBUG}
  870. MustRestartDebugger:=false;
  871. if assigned(Debugger) then
  872. if Debugger^.HasExe then
  873. begin
  874. Debugger^.Reset;
  875. MustRestartDebugger:=true;
  876. end;
  877. {$endif NODEBUG}
  878. FpIntF.Compile(FileName,SwitchesPath);
  879. SetStatus('Finished compiling...');
  880. end
  881. else
  882. begin
  883. { We need to restore Exitproc to the value
  884. it was before calling FPintF.compile PM }
  885. ExitProc:=StoreExitProc;
  886. Inc(status.errorCount);
  887. {$ifdef HasSignal}
  888. Case JmpRet of
  889. LONGJMPCALLED : s:='Error';
  890. SIGINT : s := 'Interrupted by Ctrl-C';
  891. SIGILL : s := 'Illegal instruction';
  892. SIGSEGV : s := 'Signal Segmentation violation';
  893. SIGFPE : s:='Floating point signal';
  894. else
  895. s:='Undetermined signal '+inttostr(JmpRet);
  896. end;
  897. CompilerMessageWindow^.AddMessage(V_error,s+' during compilation','',0,0);
  898. {$endif HasSignal}
  899. if JmpRet<>LONGJMPCALLED then
  900. begin
  901. CompilerMessageWindow^.AddMessage(V_error,'Long jumped out of compilation...','',0,0);
  902. SetStatus('Long jumped out of compilation...');
  903. end;
  904. end;
  905. {$ifdef HasSignal}
  906. StopJmpValid:=StoreStopJumpValid;
  907. StopJmp:=StoreStopJmp;
  908. {$endif HasSignal}
  909. {$endif}
  910. { Retrieve created exefile }
  911. If GetEXEPath<>'' then
  912. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+GetTargetExeExt)
  913. else
  914. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+GetTargetExeExt;
  915. { tokens are created and distroyed by compiler.compile !! PM }
  916. InitTokens;
  917. if LinkAfter and
  918. ExistsFile(GetExePath+PpasFile) and
  919. (CompilationPhase<>cpAborted) and
  920. (status.errorCount=0) then
  921. begin
  922. CompilationPhase:=cpLinking;
  923. if assigned(CompilerStatusDialog) then
  924. CompilerStatusDialog^.Update;
  925. SetStatus('Assembling and/or linking...');
  926. {$ifndef redircompiler}
  927. { At least here we want to catch output
  928. of batch file PM }
  929. ChangeRedirOut(FPOutFileName,false);
  930. ChangeRedirError(FPErrFileName,false);
  931. {$endif}
  932. {$ifdef Unix}
  933. {$ifdef ver1_0}
  934. Shell(GetExePath+PpasFile);
  935. Error:=LinuxError;
  936. {$else}
  937. error:=0;
  938. If Shell(GetExePath+PpasFile)=-1 Then
  939. Error:=fpgeterrno;
  940. {$endif}
  941. {$else}
  942. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile);
  943. Error:=DosError;
  944. {$endif}
  945. SetStatus('Finished linking...');
  946. RestoreRedirOut;
  947. RestoreRedirError;
  948. if Error<>0 then
  949. Inc(status.errorCount);
  950. if Status.IsExe and not Status.IsLibrary and not ExistsFile(EXEFile) then
  951. begin
  952. Inc(status.errorCount);
  953. ClearFormatParams; AddFormatParamStr(ExeFile);
  954. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  955. {$I-}
  956. Assign(ErrFile,FPErrFileName);
  957. Reset(ErrFile);
  958. if EatIO<>0 then
  959. ErrorBox(FormatStrStr(msg_cantopenfile,FPErrFileName),nil)
  960. else
  961. begin
  962. LinkErrorCount:=0;
  963. While not eof(ErrFile) and (LinkErrorCount<25) do
  964. begin
  965. readln(ErrFile,s);
  966. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  967. inc(LinkErrorCount);
  968. end;
  969. if not eof(ErrFile) then
  970. begin
  971. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  972. CompilerMessageWindow^.AddMessage(V_error,
  973. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  974. end;
  975. Close(ErrFile);
  976. end;
  977. EatIO;
  978. {$I+}
  979. end
  980. else if error=0 then
  981. WUtils.DeleteFile(GetExePath+PpasFile);
  982. end;
  983. {$ifdef redircompiler}
  984. RestoreRedirOut;
  985. RestoreRedirError;
  986. {$endif}
  987. PopStatus;
  988. { Set end status }
  989. if not (CompilationPhase in [cpAborted,cpFailed]) then
  990. if (status.errorCount=0) then
  991. begin
  992. CompilationPhase:=cpDone;
  993. LastCompileTime := cardinal(Now);
  994. end
  995. else
  996. CompilationPhase:=cpFailed;
  997. { Show end status }
  998. { reenable window closing }
  999. if assigned(CompilerStatusDialog) then
  1000. begin
  1001. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags or wfclose;
  1002. CompilerStatusDialog^.Update;
  1003. CompilerStatusDialog^.ReDraw;
  1004. CompilerStatusDialog^.SetState(sfModal,false);
  1005. if ((CompilationPhase in [cpAborted,cpDone,cpFailed]) or (ShowStatusOnError))
  1006. and ((Mode<>cRun) or (CompilationPhase<>cpDone)) then
  1007. repeat
  1008. CompilerStatusDialog^.GetEvent(E);
  1009. if IsExitEvent(E)=false then
  1010. CompilerStatusDialog^.HandleEvent(E);
  1011. until IsExitEvent(E) or not assigned(CompilerStatusDialog);
  1012. {if IsExitEvent(E) then
  1013. Application^.PutEvent(E);}
  1014. if assigned(CompilerStatusDialog) then
  1015. begin
  1016. Application^.Delete(CompilerStatusDialog);
  1017. Dispose(CompilerStatusDialog, Done);
  1018. end;
  1019. end;
  1020. CompilerStatusDialog:=nil;
  1021. { end compilation returns true if the messagewindow should be removed }
  1022. if CompilationPhase=cpDone then
  1023. begin
  1024. CompilerMessageWindow^.Hide;
  1025. { This is the last compiled main file }
  1026. PrevMainFile:=MainFile;
  1027. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  1028. end;
  1029. { Update the app }
  1030. Message(Application,evCommand,cmUpdate,nil);
  1031. DummyView:=Desktop^.First;
  1032. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  1033. begin
  1034. DummyView:=DummyView^.NextView;
  1035. end;
  1036. with DummyView^ do
  1037. if GetState(sfVisible) then
  1038. begin
  1039. SetState(sfSelected,false);
  1040. SetState(sfSelected,true);
  1041. end;
  1042. if Assigned(CompilerMessageWindow) then
  1043. with CompilerMessageWindow^ do
  1044. begin
  1045. if GetState(sfVisible) then
  1046. begin
  1047. SetState(sfSelected,false);
  1048. SetState(sfSelected,true);
  1049. end;
  1050. if (status.errorCount>0) then
  1051. MsgLB^.SelectFirstError;
  1052. end;
  1053. { ^^^ we need this trick to reactivate the desktop }
  1054. EditorModified:=false;
  1055. {$ifndef NODEBUG}
  1056. if MustRestartDebugger then
  1057. InitDebugger;
  1058. {$endif NODEBUG}
  1059. { In case we have something that the compiler touched }
  1060. AskToReloadAllModifiedFiles;
  1061. { Try to read Browser info in again if compilation failure !! }
  1062. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  1063. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1064. ReadSymbolsFile(BrowserName);
  1065. if UseAllUnitsInCodeComplete and not assigned(CompilingHiddenFile) then
  1066. AddAvailableUnitsToCodeComplete(false);
  1067. end;
  1068. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  1069. var Need: boolean;
  1070. I: sw_integer;
  1071. SF: PSourceFile;
  1072. SourceTime,PPUTime,ObjTime: longint;
  1073. W: PSourceWindow;
  1074. begin
  1075. if Assigned(SourceFiles)=false then
  1076. Need:={(EditorModified=true)}true
  1077. else
  1078. begin
  1079. Need:=(PrevMainFile<>GetMainFile(Mode)) and (PrevMainFile<>'');
  1080. if Need then
  1081. begin
  1082. if verbose then
  1083. begin
  1084. ClearFormatParams; AddFormatParamStr(GetMainFile(Mode));
  1085. CompilerMessageWindow^.AddMessage(V_info,
  1086. FormatStrF(msg_firstcompilationof,FormatParams),
  1087. '',0,0);
  1088. end;
  1089. end
  1090. else
  1091. for I:=0 to SourceFiles^.Count-1 do
  1092. begin
  1093. SF:=SourceFiles^.At(I);
  1094. SourceTime:=GetFileTime(SF^.GetSourceFileName);
  1095. PPUTime:=GetFileTime(SF^.GetPPUFileName);
  1096. ObjTime:=GetFileTime(SF^.GetObjFileName);
  1097. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  1098. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  1099. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  1100. writeln('------');}
  1101. { some units don't generate object files }
  1102. W:=EditorWindowFile(SF^.GetSourceFileName);
  1103. if (SourceTime<>-1) then
  1104. if ((SourceTime>PPUTime) or
  1105. ((SourceTime>ObjTime) and
  1106. (ObjTime<>-1))) or
  1107. (assigned(W) and (W^.Editor^.CompileStamp<0)) then
  1108. begin
  1109. Need:=true;
  1110. if verbose then
  1111. begin
  1112. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  1113. CompilerMessageWindow^.AddMessage(V_info,
  1114. FormatStrF(msg_recompilingbecauseof,FormatParams),
  1115. SF^.GetSourceFileName,1,1);
  1116. end;
  1117. Break;
  1118. end;
  1119. end;
  1120. { writeln('Need?', Need); system.readln;}
  1121. end;
  1122. NeedRecompile:=Need;
  1123. end;
  1124. {$ifdef COMPILER_1_0}
  1125. constructor TFPInputFile.Init(AEditor: PFileEditor);
  1126. begin
  1127. if not Assigned(AEditor) then Fail;
  1128. if inherited Init(AEditor^.FileName)=false then
  1129. Fail;
  1130. Editor:=AEditor;
  1131. end;
  1132. {$else COMPILER_1_0}
  1133. constructor TFPInputFile.Create(AEditor: PFileEditor);
  1134. begin
  1135. if not Assigned(AEditor) then Fail;
  1136. if inherited Create(AEditor^.FileName)=nil then
  1137. Fail;
  1138. Editor:=AEditor;
  1139. end;
  1140. {$endif COMPILER_1_0}
  1141. function TFPInputFile.fileopen(const filename: string): boolean;
  1142. var OK: boolean;
  1143. begin
  1144. S:=New(PMemoryStream, Init(0,0));
  1145. OK:=Assigned(S) and (S^.Status=stOK);
  1146. if OK then OK:=Editor^.SaveToStream(S);
  1147. if OK then
  1148. S^.Seek(0)
  1149. else
  1150. begin
  1151. if Assigned(S) then Dispose(S, Done);
  1152. S:=nil;
  1153. end;
  1154. fileopen:=OK;
  1155. end;
  1156. function TFPInputFile.fileseek(pos: longint): boolean;
  1157. var OK: boolean;
  1158. begin
  1159. OK:=assigned(S);
  1160. if OK then
  1161. begin
  1162. S^.Reset;
  1163. S^.Seek(pos);
  1164. OK:=(S^.Status=stOK);
  1165. end;
  1166. fileseek:=OK;
  1167. end;
  1168. function TFPInputFile.fileread(var databuf; maxsize: longint): longint;
  1169. var
  1170. size: longint;
  1171. begin
  1172. if not assigned(S) then size:=0 else
  1173. begin
  1174. size:=min(maxsize,(S^.GetSize-S^.GetPos));
  1175. S^.Read(databuf,size);
  1176. if S^.Status<>stOK then size:=0;
  1177. end;
  1178. fileread:=size;
  1179. end;
  1180. function TFPInputFile.fileeof: boolean;
  1181. var EOF: boolean;
  1182. begin
  1183. EOF:=not assigned(S);
  1184. if not EOF then
  1185. EOF:=(S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  1186. fileeof:=EOF;
  1187. end;
  1188. function TFPInputFile.fileclose: boolean;
  1189. var OK: boolean;
  1190. begin
  1191. OK:=assigned(S);
  1192. if OK then
  1193. begin
  1194. S^.Reset;
  1195. Dispose(S, Done);
  1196. S:=nil;
  1197. OK:=true;
  1198. end;
  1199. fileclose:=OK;
  1200. end;
  1201. procedure RegisterFPCompile;
  1202. begin
  1203. {$ifndef NOOBJREG}
  1204. RegisterType(RCompilerMessageListBox);
  1205. RegisterType(RCompilerMessageWindow);
  1206. {$endif}
  1207. end;
  1208. end.
  1209. {
  1210. $Log$
  1211. Revision 1.26 2004-11-05 00:00:33 peter
  1212. set exefile after compilation, before the target_info is not filled
  1213. Revision 1.25 2004/11/02 23:53:19 peter
  1214. * fixed crashes with ide and 1.9.x
  1215. Revision 1.24 2004/09/09 20:33:00 jonas
  1216. * made CompilerStop declaration compliant to new tstopprocedure type in
  1217. compiler
  1218. Revision 1.23 2003/11/14 17:29:38 marco
  1219. * linuxerrorcide
  1220. Revision 1.22 2003/03/28 09:55:46 armin
  1221. * Fixed TCompilerMessageWindow.AddMessage to see line numbers with 1.1
  1222. Revision 1.21 2003/03/27 14:11:53 pierre
  1223. * fix problem in CompilerComment procedure
  1224. Revision 1.20 2003/01/13 09:05:18 pierre
  1225. * fix error in last commit
  1226. Revision 1.19 2003/01/11 15:52:54 peter
  1227. * adapted for new 1.1 compiler verbosity
  1228. Revision 1.18 2002/12/02 13:58:29 pierre
  1229. * avoid longjmp messages if quitting after compilation error
  1230. Revision 1.17 2002/11/20 17:35:00 pierre
  1231. * use target_os.ExeExt for compiled executable
  1232. Revision 1.16 2002/10/23 19:19:40 hajny
  1233. * another bunch of missing HasSignal conditionals
  1234. Revision 1.15 2002/09/26 15:00:35 pierre
  1235. * fix problems with system unit is not present for __fp__ compilation
  1236. Revision 1.14 2002/09/13 22:30:50 pierre
  1237. * only fpc uses video unit
  1238. Revision 1.13 2002/09/09 06:53:54 pierre
  1239. * avoid to save file used by codecomplete
  1240. Revision 1.12 2002/09/07 15:40:42 peter
  1241. * old logs removed and tabs fixed
  1242. Revision 1.11 2002/09/05 08:45:40 pierre
  1243. * try to fix recompilation on changes problems
  1244. Revision 1.10 2002/09/04 14:07:12 pierre
  1245. + Enhance code complete by inserting unit symbols
  1246. Revision 1.9 2002/08/26 13:03:14 pierre
  1247. + add a lock to speed up parsing of userscreen
  1248. Revision 1.8 2002/04/10 22:37:37 pierre
  1249. * save and restore Exitproc if LongJmp called
  1250. Revision 1.7 2002/03/20 14:48:27 pierre
  1251. * moved StopJmp buffer to fpcatch unit
  1252. }