fpcompil.pas 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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,
  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. {$ifdef TEMPHEAP}
  487. switch_to_base_heap;
  488. {$endif TEMPHEAP}
  489. case CompilationPhase of
  490. cpCompiling :
  491. begin
  492. ClearFormatParams;
  493. if Status.Compiling_current then
  494. begin
  495. AddFormatParamStr(ShrinkPath(SmartPath(Status.Currentsourcepath+Status.CurrentSource),
  496. MaxFileNameSize - Length(msg_compilingfile)));
  497. StatusS:=FormatStrF(msg_compilingfile,FormatParams);
  498. end
  499. else
  500. begin
  501. if Status.CurrentSource='' then
  502. StatusS:=''
  503. else
  504. begin
  505. StatusS:=ShrinkPath(SmartPath(DirAndNameOf(Status.Currentsourcepath+Status.CurrentSource)),
  506. MaxFileNameSize-Length(msg_loadingunit));
  507. AddFormatParamStr(StatusS);
  508. StatusS:=FormatStrF(msg_loadingunit,FormatParams);
  509. end;
  510. end;
  511. KeyS:=msg_hint_pressesctocancel;
  512. end;
  513. cpLinking :
  514. begin
  515. ClearFormatParams;
  516. AddFormatParamStr(ShrinkPath(ExeFile,
  517. MaxFileNameSize-Length(msg_linkingfile)));
  518. StatusS:=FormatStrF(msg_linkingfile,FormatParams);
  519. KeyS:=msg_hint_pleasewait;
  520. end;
  521. cpDone :
  522. begin
  523. StatusS:=msg_compiledone;
  524. KeyS:=msg_hint_compilesuccessfulpressenter;
  525. end;
  526. cpFailed :
  527. begin
  528. StatusS:=msg_failedtocompile;
  529. KeyS:=msg_hint_compilefailed;
  530. end;
  531. cpAborted :
  532. begin
  533. StatusS:=msg_compilationaborted;
  534. KeyS:=msg_hint_compileaborted;
  535. end;
  536. end;
  537. ClearFormatParams;
  538. AddFormatParamStr(ShrinkPath(SmartPath(MainFile),
  539. MaxFileNameSize-Length('Main file: %s')));
  540. AddFormatParamStr(StatusS);
  541. AddFormatParamStr(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)));
  542. AddFormatParamInt(Status.CurrentLine);
  543. AddFormatParamInt(MemAvail div 1024);
  544. AddFormatParamInt(Status.CompiledLines);
  545. AddFormatParamInt(Status.ErrorCount);
  546. ST^.SetText(
  547. FormatStrF(
  548. 'Main file: %s'#13+
  549. '%s'+#13#13+
  550. 'Target: %12s '+ 'Line number: %7d'+#13+
  551. 'Free memory: %6dK '+'Total lines: %7d'+#13+
  552. 'Total errors: %5d',
  553. FormatParams)
  554. );
  555. KeyST^.SetText(^C+KeyS);
  556. {$ifdef TEMPHEAP}
  557. switch_to_temp_heap;
  558. {$endif TEMPHEAP}
  559. end;
  560. {****************************************************************************
  561. Compiler Hooks
  562. ****************************************************************************}
  563. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  564. var
  565. event : tevent;
  566. begin
  567. GetKeyEvent(Event);
  568. if (Event.What=evKeyDown) and (Event.KeyCode=kbEsc) then
  569. begin
  570. CompilationPhase:=cpAborted;
  571. { update info messages }
  572. if assigned(CompilerStatusDialog) then
  573. begin
  574. {$ifdef redircompiler}
  575. RedirDisableAll;
  576. {$endif}
  577. CompilerStatusDialog^.Update;
  578. {$ifdef redircompiler}
  579. RedirEnableAll;
  580. {$endif}
  581. end;
  582. CompilerStatus:=true;
  583. exit;
  584. end;
  585. { only display line info every 100 lines, ofcourse all other messages
  586. will be displayed directly }
  587. if (status.currentline mod 100=0) then
  588. begin
  589. { update info messages }
  590. {$ifdef redircompiler}
  591. RedirDisableAll;
  592. {$endif}
  593. if assigned(CompilerStatusDialog) then
  594. CompilerStatusDialog^.Update;
  595. {$ifdef redircompiler}
  596. RedirEnableAll;
  597. {$endif}
  598. { update memory usage }
  599. { HeapView^.Update; }
  600. end;
  601. CompilerStatus:=false;
  602. end;
  603. const
  604. LONGJMPCALLED = -1;
  605. procedure CompilerStop; {$ifndef FPC}far;{$endif}
  606. begin
  607. {$ifndef GABOR}
  608. {$ifdef HasSignal}
  609. if StopJmpValid then
  610. Longjmp(StopJmp,LONGJMPCALLED)
  611. else
  612. Halt(1);
  613. {$endif}
  614. {$endif}
  615. end;
  616. Function CompilerGetNamedFileTime(const filename : string) : Longint; {$ifndef FPC}far;{$endif}
  617. var t: longint;
  618. W: PSourceWindow;
  619. begin
  620. W:=EditorWindowFile(FExpand(filename));
  621. if Assigned(W) and (W^.Editor^.GetModified) then
  622. t:=Now
  623. else
  624. t:=def_getnamedfiletime(filename);
  625. CompilerGetNamedFileTime:=t;
  626. end;
  627. {$ifdef COMPILER_1_0}
  628. function CompilerOpenInputFile(const filename: string): pinputfile; {$ifndef FPC}far;{$endif}
  629. var f: pinputfile;
  630. W: PSourceWindow;
  631. begin
  632. if assigned(CompilingHiddenFile) and
  633. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  634. W:=CompilingHiddenFile
  635. else
  636. W:=EditorWindowFile(FExpand(filename));
  637. if Assigned(W) and (W^.Editor^.GetModified) then
  638. f:=new(PFPInputFile, Init(W^.Editor))
  639. else
  640. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  641. if assigned(W) then
  642. W^.Editor^.CompileStamp:=CompileStamp;
  643. CompilerOpenInputFile:=f;
  644. end;
  645. {$else COMPILER_1_0}
  646. function CompilerOpenInputFile(const filename: string): tinputfile; {$ifndef FPC}far;{$endif}
  647. var f: tinputfile;
  648. W: PSourceWindow;
  649. begin
  650. if assigned(CompilingHiddenFile) and
  651. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  652. W:=CompilingHiddenFile
  653. else
  654. W:=EditorWindowFile(FExpand(filename));
  655. if Assigned(W) and (W^.Editor^.GetModified) then
  656. f:=TFPInputFile.Create(W^.Editor)
  657. else
  658. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  659. if assigned(W) then
  660. W^.Editor^.CompileStamp:=CompileStamp;
  661. CompilerOpenInputFile:=f;
  662. end;
  663. {$endif COMPILER_1_0}
  664. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  665. begin
  666. {$ifdef TEMPHEAP}
  667. switch_to_base_heap;
  668. {$endif TEMPHEAP}
  669. CompilerComment:=false;
  670. {$ifndef DEV}
  671. if (status.verbosity and Level)=Level then
  672. {$endif}
  673. begin
  674. {$ifdef redircompiler}
  675. RedirDisableAll;
  676. {$endif}
  677. if not CompilerMessageWindow^.GetState(sfVisible) then
  678. CompilerMessageWindow^.Show;
  679. if Desktop^.First<>PView(CompilerMessageWindow) then
  680. CompilerMessageWindow^.MakeFirst;
  681. CompilerMessageWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  682. status.currentline,status.currentcolumn);
  683. { update info messages }
  684. if assigned(CompilerStatusDialog) then
  685. CompilerStatusDialog^.Update;
  686. {$ifdef DEBUG}
  687. {$ifndef NODEBUG}
  688. // def_gdb_stop(level);
  689. {$endif}
  690. {$endif DEBUG}
  691. {$ifdef redircompiler}
  692. RedirEnableAll;
  693. {$endif}
  694. { update memory usage }
  695. { HeapView^.Update; }
  696. end;
  697. {$ifdef TEMPHEAP}
  698. switch_to_temp_heap;
  699. {$endif TEMPHEAP}
  700. end;
  701. {****************************************************************************
  702. DoCompile
  703. ****************************************************************************}
  704. { This function must return '' if
  705. "Options|Directories|Exe and PPU directory" is empty }
  706. function GetExePath: string;
  707. var Path: string;
  708. I: Sw_integer;
  709. begin
  710. Path:='';
  711. if DirectorySwitches<>nil then
  712. with DirectorySwitches^ do
  713. for I:=0 to ItemCount-1 do
  714. begin
  715. if ItemParam(I)='-FE' then
  716. begin
  717. Path:=GetStringItem(I);
  718. Break;
  719. end;
  720. end;
  721. if Path<>'' then
  722. GetExePath:=CompleteDir(FExpand(Path))
  723. else
  724. GetExePath:='';
  725. end;
  726. function GetMainFile(Mode: TCompileMode): string;
  727. var FileName: string;
  728. P : PSourceWindow;
  729. begin
  730. if assigned(CompilingHiddenFile) then
  731. P:=CompilingHiddenFile
  732. else
  733. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  734. if (PrimaryFileMain='') and (P=nil) then
  735. FileName:='' { nothing to compile }
  736. else
  737. begin
  738. if (PrimaryFileMain<>'') and (Mode<>cCompile) then
  739. FileName:=PrimaryFileMain
  740. else if assigned(P) then
  741. begin
  742. FileName:=P^.Editor^.FileName;
  743. if FileName='' then
  744. begin
  745. P^.Editor^.SaveAsk(true);
  746. FileName:=P^.Editor^.FileName;
  747. end;
  748. end
  749. else
  750. FileName:='';
  751. end;
  752. If (FileName<>'') then
  753. FileName:=FixFileName(FExpand(FileName));
  754. GetMainFile:=FileName;
  755. end;
  756. procedure ResetErrorMessages;
  757. procedure ResetErrorLine(P: PView); {$ifndef FPC}far;{$endif}
  758. begin
  759. if assigned(P) and
  760. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  761. PSourceWindow(P)^.Editor^.SetErrorMessage('');
  762. end;
  763. begin
  764. Desktop^.ForEach(@ResetErrorLine);
  765. end;
  766. procedure DoCompile(Mode: TCompileMode);
  767. function IsExitEvent(E: TEvent): boolean;
  768. begin
  769. { following suggestion by Harsha Senanayake }
  770. IsExitEvent:=(E.What=evKeyDown);
  771. end;
  772. function GetTargetExeExt : string;
  773. begin
  774. {$ifdef COMPILER_1_0}
  775. GetTargetExeExt:=target_os.exeext;
  776. {$else COMPILER_1_0}
  777. GetTargetExeExt:=target_info.exeext;
  778. {$endif COMPILER_1_0}
  779. end;
  780. var
  781. s,FileName: string;
  782. ErrFile : Text;
  783. MustRestartDebugger,
  784. StoreStopJumpValid : boolean;
  785. StoreStopJmp : Jmp_buf;
  786. StoreExitProc : pointer;
  787. JmpRet,Error,LinkErrorCount : longint;
  788. E : TEvent;
  789. DummyView: PView;
  790. PPasFile : string[64];
  791. begin
  792. AskRecompileIfModifiedFlag:=true;
  793. { Get FileName }
  794. FileName:=GetMainFile(Mode);
  795. if FileName='' then
  796. begin
  797. ErrorBox(msg_nothingtocompile,nil);
  798. Exit;
  799. end else
  800. { THis is not longer necessary as unsaved files are loaded from a memorystream,
  801. and with the file as primaryfile set it is already incompatible with itself
  802. if FileName='*' then
  803. begin
  804. ErrorBox(msg_cantcompileunsavedfile,nil);
  805. Exit;
  806. end; }
  807. PushStatus('Beginning compilation...');
  808. { Show Compiler Messages Window }
  809. { if not CompilerMessageWindow^.GetState(sfVisible) then
  810. CompilerMessageWindow^.Show;
  811. CompilerMessageWindow^.MakeFirst;}
  812. CompilerMessageWindow^.ClearMessages;
  813. { Tell why we compile }
  814. NeedRecompile(Mode,true);
  815. MainFile:=FileName;
  816. SetStatus('Writing switches to file...');
  817. WriteSwitches(SwitchesPath);
  818. { leaving open browsers leads to crashes !! (PM) }
  819. SetStatus('Preparing symbol info...');
  820. CloseAllBrowsers;
  821. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  822. WriteSymbolsFile(BrowserName);
  823. { MainFile:=FixFileName(FExpand(FileName));}
  824. SetStatus('Preparing to compile...'+NameOf(MainFile));
  825. If GetEXEPath<>'' then
  826. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+GetTargetExeExt)
  827. else
  828. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+GetTargetExeExt;
  829. { Reset }
  830. CtrlBreakHit:=false;
  831. { Create Compiler Status Dialog }
  832. CompilationPhase:=cpCompiling;
  833. if not assigned(CompilingHiddenFile) then
  834. begin
  835. New(CompilerStatusDialog, Init);
  836. CompilerStatusDialog^.SetState(sfModal,true);
  837. { disable window closing }
  838. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags and not wfclose;
  839. Application^.Insert(CompilerStatusDialog);
  840. CompilerStatusDialog^.Update;
  841. end;
  842. { hook compiler output }
  843. {$ifdef TP}
  844. do_status:=CompilerStatus;
  845. do_stop:=CompilerStop;
  846. do_comment:=CompilerComment;
  847. {$ifndef GABOR}do_openinputfile:=CompilerOpenInputFile;{$endif}
  848. do_getnamedfiletime:=CompilerGetNamedFileTime;
  849. {$else not TP}
  850. do_status:=@CompilerStatus;
  851. do_stop:=@CompilerStop;
  852. do_comment:=@CompilerComment;
  853. do_openinputfile:=@CompilerOpenInputFile;
  854. do_getnamedfiletime:=@CompilerGetNamedFileTime;
  855. {$endif TP}
  856. do_initsymbolinfo:={$ifdef fpc}@{$endif}InitBrowserCol;
  857. do_donesymbolinfo:={$ifdef fpc}@{$endif}DoneBrowserCol;
  858. do_extractsymbolinfo:={$ifdef fpc}@{$endif}CreateBrowserCol;
  859. { Compile ! }
  860. {$ifdef redircompiler}
  861. ChangeRedirOut(FPOutFileName,false);
  862. ChangeRedirError(FPErrFileName,false);
  863. {$endif}
  864. {$ifdef TEMPHEAP}
  865. split_heap;
  866. switch_to_temp_heap;
  867. {$endif TEMPHEAP}
  868. { insert "" around name so that spaces are allowed }
  869. { only supported in compiler after 2000/01/14 PM }
  870. if pos(' ',FileName)>0 then
  871. FileName:='"'+FileName+'"';
  872. if mode=cBuild then
  873. FileName:='-B '+FileName;
  874. { tokens are created and distroed by compiler.compile !! PM }
  875. DoneTokens;
  876. {$ifdef COMPILER_1_0}
  877. PPasFile:='ppas'+source_os.scriptext;
  878. {$else COMPILER_1_0}
  879. PPasFile:='ppas'+source_info.scriptext;
  880. {$endif COMPILER_1_0}
  881. WUtils.DeleteFile(GetExePath+PpasFile);
  882. SetStatus('Compiling...');
  883. {$ifndef GABOR}
  884. {$ifdef HasSignal}
  885. StoreStopJumpValid:=StopJmpValid;
  886. StoreStopJmp:=StopJmp;
  887. {$endif HasSignal}
  888. StoreExitProc:=ExitProc;
  889. {$ifdef HasSignal}
  890. StopJmpValid:=true;
  891. JmpRet:=SetJmp(StopJmp);
  892. {$else}
  893. JmpRet:=0;
  894. {$endif HasSignal}
  895. if JmpRet=0 then
  896. begin
  897. inc(CompileStamp);
  898. ResetErrorMessages;
  899. {$ifndef NODEBUG}
  900. MustRestartDebugger:=false;
  901. if assigned(Debugger) then
  902. if Debugger^.HasExe then
  903. begin
  904. Debugger^.Reset;
  905. MustRestartDebugger:=true;
  906. end;
  907. {$endif NODEBUG}
  908. FpIntF.Compile(FileName,SwitchesPath);
  909. SetStatus('Finished compiling...');
  910. end
  911. else
  912. begin
  913. { We need to restore Exitproc to the value
  914. it was before calling FPintF.compile PM }
  915. ExitProc:=StoreExitProc;
  916. Inc(status.errorCount);
  917. {$ifdef HasSignal}
  918. Case JmpRet of
  919. LONGJMPCALLED : s:='Error';
  920. SIGINT : s := 'Interrupted by Ctrl-C';
  921. SIGILL : s := 'Illegal instruction';
  922. SIGSEGV : s := 'Signal Segmentation violation';
  923. SIGFPE : s:='Floating point signal';
  924. else
  925. s:='Undetermined signal '+inttostr(JmpRet);
  926. end;
  927. CompilerMessageWindow^.AddMessage(V_error,s+' during compilation','',0,0);
  928. {$endif HasSignal}
  929. if JmpRet<>LONGJMPCALLED then
  930. begin
  931. CompilerMessageWindow^.AddMessage(V_error,'Long jumped out of compilation...','',0,0);
  932. SetStatus('Long jumped out of compilation...');
  933. end;
  934. end;
  935. {$ifdef HasSignal}
  936. StopJmpValid:=StoreStopJumpValid;
  937. StopJmp:=StoreStopJmp;
  938. {$endif HasSignal}
  939. {$endif}
  940. { tokens are created and distroyed by compiler.compile !! PM }
  941. InitTokens;
  942. if LinkAfter and
  943. ExistsFile(GetExePath+PpasFile) and
  944. (CompilationPhase<>cpAborted) and
  945. (status.errorCount=0) then
  946. begin
  947. CompilationPhase:=cpLinking;
  948. if assigned(CompilerStatusDialog) then
  949. CompilerStatusDialog^.Update;
  950. SetStatus('Assembling and/or linking...');
  951. {$ifndef redircompiler}
  952. { At least here we want to catch output
  953. of batch file PM }
  954. ChangeRedirOut(FPOutFileName,false);
  955. ChangeRedirError(FPErrFileName,false);
  956. {$endif}
  957. {$ifdef Unix}
  958. Shell(GetExePath+PpasFile);
  959. Error:=LinuxError;
  960. {$else}
  961. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile);
  962. Error:=DosError;
  963. {$endif}
  964. SetStatus('Finished linking...');
  965. RestoreRedirOut;
  966. RestoreRedirError;
  967. if Error<>0 then
  968. Inc(status.errorCount);
  969. if Status.IsExe and not Status.IsLibrary and not ExistsFile(EXEFile) then
  970. begin
  971. Inc(status.errorCount);
  972. ClearFormatParams; AddFormatParamStr(ExeFile);
  973. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  974. {$I-}
  975. Assign(ErrFile,FPErrFileName);
  976. Reset(ErrFile);
  977. if EatIO<>0 then
  978. ErrorBox(FormatStrStr(msg_cantopenfile,FPErrFileName),nil)
  979. else
  980. begin
  981. LinkErrorCount:=0;
  982. While not eof(ErrFile) and (LinkErrorCount<25) do
  983. begin
  984. readln(ErrFile,s);
  985. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  986. inc(LinkErrorCount);
  987. end;
  988. if not eof(ErrFile) then
  989. begin
  990. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  991. CompilerMessageWindow^.AddMessage(V_error,
  992. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  993. end;
  994. Close(ErrFile);
  995. end;
  996. EatIO;
  997. {$I+}
  998. end
  999. else if error=0 then
  1000. WUtils.DeleteFile(GetExePath+PpasFile);
  1001. end;
  1002. {$ifdef TEMPHEAP}
  1003. switch_to_base_heap;
  1004. {$endif TEMPHEAP}
  1005. {$ifdef redircompiler}
  1006. RestoreRedirOut;
  1007. RestoreRedirError;
  1008. {$endif}
  1009. PopStatus;
  1010. { Set end status }
  1011. if not (CompilationPhase in [cpAborted,cpFailed]) then
  1012. if (status.errorCount=0) then
  1013. begin
  1014. CompilationPhase:=cpDone;
  1015. LastCompileTime := cardinal(Now);
  1016. end
  1017. else
  1018. CompilationPhase:=cpFailed;
  1019. { Show end status }
  1020. { reenable window closing }
  1021. if assigned(CompilerStatusDialog) then
  1022. begin
  1023. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags or wfclose;
  1024. CompilerStatusDialog^.Update;
  1025. CompilerStatusDialog^.ReDraw;
  1026. CompilerStatusDialog^.SetState(sfModal,false);
  1027. if ((CompilationPhase in [cpAborted,cpDone,cpFailed]) or (ShowStatusOnError))
  1028. and ((Mode<>cRun) or (CompilationPhase<>cpDone)) then
  1029. repeat
  1030. CompilerStatusDialog^.GetEvent(E);
  1031. if IsExitEvent(E)=false then
  1032. CompilerStatusDialog^.HandleEvent(E);
  1033. until IsExitEvent(E) or not assigned(CompilerStatusDialog);
  1034. {if IsExitEvent(E) then
  1035. Application^.PutEvent(E);}
  1036. if assigned(CompilerStatusDialog) then
  1037. begin
  1038. Application^.Delete(CompilerStatusDialog);
  1039. Dispose(CompilerStatusDialog, Done);
  1040. end;
  1041. end;
  1042. CompilerStatusDialog:=nil;
  1043. { end compilation returns true if the messagewindow should be removed }
  1044. if CompilationPhase=cpDone then
  1045. begin
  1046. CompilerMessageWindow^.Hide;
  1047. { This is the last compiled main file }
  1048. PrevMainFile:=MainFile;
  1049. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  1050. end;
  1051. { Update the app }
  1052. Message(Application,evCommand,cmUpdate,nil);
  1053. {$ifdef TEMPHEAP}
  1054. releasetempheap;
  1055. unsplit_heap;
  1056. {$endif TEMPHEAP}
  1057. DummyView:=Desktop^.First;
  1058. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  1059. begin
  1060. DummyView:=DummyView^.NextView;
  1061. end;
  1062. with DummyView^ do
  1063. if GetState(sfVisible) then
  1064. begin
  1065. SetState(sfSelected,false);
  1066. SetState(sfSelected,true);
  1067. end;
  1068. if Assigned(CompilerMessageWindow) then
  1069. with CompilerMessageWindow^ do
  1070. begin
  1071. if GetState(sfVisible) then
  1072. begin
  1073. SetState(sfSelected,false);
  1074. SetState(sfSelected,true);
  1075. end;
  1076. if (status.errorCount>0) then
  1077. MsgLB^.SelectFirstError;
  1078. end;
  1079. { ^^^ we need this trick to reactivate the desktop }
  1080. EditorModified:=false;
  1081. {$ifndef NODEBUG}
  1082. if MustRestartDebugger then
  1083. InitDebugger;
  1084. {$endif NODEBUG}
  1085. { In case we have something that the compiler touched }
  1086. AskToReloadAllModifiedFiles;
  1087. { Try to read Browser info in again if compilation failure !! }
  1088. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  1089. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1090. ReadSymbolsFile(BrowserName);
  1091. if UseAllUnitsInCodeComplete and not assigned(CompilingHiddenFile) then
  1092. AddAvailableUnitsToCodeComplete(false);
  1093. end;
  1094. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  1095. var Need: boolean;
  1096. I: sw_integer;
  1097. SF: PSourceFile;
  1098. SourceTime,PPUTime,ObjTime: longint;
  1099. W: PSourceWindow;
  1100. begin
  1101. if Assigned(SourceFiles)=false then
  1102. Need:={(EditorModified=true)}true
  1103. else
  1104. begin
  1105. Need:=(PrevMainFile<>GetMainFile(Mode)) and (PrevMainFile<>'');
  1106. if Need then
  1107. begin
  1108. if verbose then
  1109. begin
  1110. ClearFormatParams; AddFormatParamStr(GetMainFile(Mode));
  1111. CompilerMessageWindow^.AddMessage(V_info,
  1112. FormatStrF(msg_firstcompilationof,FormatParams),
  1113. '',0,0);
  1114. end;
  1115. end
  1116. else
  1117. for I:=0 to SourceFiles^.Count-1 do
  1118. begin
  1119. SF:=SourceFiles^.At(I);
  1120. SourceTime:=GetFileTime(SF^.GetSourceFileName);
  1121. PPUTime:=GetFileTime(SF^.GetPPUFileName);
  1122. ObjTime:=GetFileTime(SF^.GetObjFileName);
  1123. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  1124. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  1125. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  1126. writeln('------');}
  1127. { some units don't generate object files }
  1128. W:=EditorWindowFile(SF^.GetSourceFileName);
  1129. if (SourceTime<>-1) then
  1130. if ((SourceTime>PPUTime) or
  1131. ((SourceTime>ObjTime) and
  1132. (ObjTime<>-1))) or
  1133. (assigned(W) and (W^.Editor^.CompileStamp<0)) then
  1134. begin
  1135. Need:=true;
  1136. if verbose then
  1137. begin
  1138. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  1139. CompilerMessageWindow^.AddMessage(V_info,
  1140. FormatStrF(msg_recompilingbecauseof,FormatParams),
  1141. SF^.GetSourceFileName,1,1);
  1142. end;
  1143. Break;
  1144. end;
  1145. end;
  1146. { writeln('Need?', Need); system.readln;}
  1147. end;
  1148. NeedRecompile:=Need;
  1149. end;
  1150. {$ifdef COMPILER_1_0}
  1151. constructor TFPInputFile.Init(AEditor: PFileEditor);
  1152. begin
  1153. if not Assigned(AEditor) then Fail;
  1154. if inherited Init(AEditor^.FileName)=false then
  1155. Fail;
  1156. Editor:=AEditor;
  1157. end;
  1158. {$else COMPILER_1_0}
  1159. constructor TFPInputFile.Create(AEditor: PFileEditor);
  1160. begin
  1161. if not Assigned(AEditor) then Fail;
  1162. if inherited Create(AEditor^.FileName)=nil then
  1163. Fail;
  1164. Editor:=AEditor;
  1165. end;
  1166. {$endif COMPILER_1_0}
  1167. function TFPInputFile.fileopen(const filename: string): boolean;
  1168. var OK: boolean;
  1169. begin
  1170. S:=New(PMemoryStream, Init(0,0));
  1171. OK:=Assigned(S) and (S^.Status=stOK);
  1172. if OK then OK:=Editor^.SaveToStream(S);
  1173. if OK then
  1174. S^.Seek(0)
  1175. else
  1176. begin
  1177. if Assigned(S) then Dispose(S, Done);
  1178. S:=nil;
  1179. end;
  1180. fileopen:=OK;
  1181. end;
  1182. function TFPInputFile.fileseek(pos: longint): boolean;
  1183. var OK: boolean;
  1184. begin
  1185. OK:=assigned(S);
  1186. if OK then
  1187. begin
  1188. S^.Reset;
  1189. S^.Seek(pos);
  1190. OK:=(S^.Status=stOK);
  1191. end;
  1192. fileseek:=OK;
  1193. end;
  1194. function TFPInputFile.fileread(var databuf; maxsize: longint): longint;
  1195. var
  1196. size: longint;
  1197. begin
  1198. if not assigned(S) then size:=0 else
  1199. begin
  1200. size:=min(maxsize,(S^.GetSize-S^.GetPos));
  1201. S^.Read(databuf,size);
  1202. if S^.Status<>stOK then size:=0;
  1203. end;
  1204. fileread:=size;
  1205. end;
  1206. function TFPInputFile.fileeof: boolean;
  1207. var EOF: boolean;
  1208. begin
  1209. EOF:=not assigned(S);
  1210. if not EOF then
  1211. EOF:=(S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  1212. fileeof:=EOF;
  1213. end;
  1214. function TFPInputFile.fileclose: boolean;
  1215. var OK: boolean;
  1216. begin
  1217. OK:=assigned(S);
  1218. if OK then
  1219. begin
  1220. S^.Reset;
  1221. Dispose(S, Done);
  1222. S:=nil;
  1223. OK:=true;
  1224. end;
  1225. fileclose:=OK;
  1226. end;
  1227. procedure RegisterFPCompile;
  1228. begin
  1229. {$ifndef NOOBJREG}
  1230. RegisterType(RCompilerMessageListBox);
  1231. RegisterType(RCompilerMessageWindow);
  1232. {$endif}
  1233. end;
  1234. end.
  1235. {
  1236. $Log$
  1237. Revision 1.20 2003-01-13 09:05:18 pierre
  1238. * fix error in last commit
  1239. Revision 1.19 2003/01/11 15:52:54 peter
  1240. * adapted for new 1.1 compiler verbosity
  1241. Revision 1.18 2002/12/02 13:58:29 pierre
  1242. * avoid longjmp messages if quitting after compilation error
  1243. Revision 1.17 2002/11/20 17:35:00 pierre
  1244. * use target_os.ExeExt for compiled executable
  1245. Revision 1.16 2002/10/23 19:19:40 hajny
  1246. * another bunch of missing HasSignal conditionals
  1247. Revision 1.15 2002/09/26 15:00:35 pierre
  1248. * fix problems with system unit is not present for __fp__ compilation
  1249. Revision 1.14 2002/09/13 22:30:50 pierre
  1250. * only fpc uses video unit
  1251. Revision 1.13 2002/09/09 06:53:54 pierre
  1252. * avoid to save file used by codecomplete
  1253. Revision 1.12 2002/09/07 15:40:42 peter
  1254. * old logs removed and tabs fixed
  1255. Revision 1.11 2002/09/05 08:45:40 pierre
  1256. * try to fix recompilation on changes problems
  1257. Revision 1.10 2002/09/04 14:07:12 pierre
  1258. + Enhance code complete by inserting unit symbols
  1259. Revision 1.9 2002/08/26 13:03:14 pierre
  1260. + add a lock to speed up parsing of userscreen
  1261. Revision 1.8 2002/04/10 22:37:37 pierre
  1262. * save and restore Exitproc if LongJmp called
  1263. Revision 1.7 2002/03/20 14:48:27 pierre
  1264. * moved StopJmp buffer to fpcatch unit
  1265. }