fpcompil.pas 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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. V_Macro then ClassS:=msg_class_macro else if TClass =
  263. V_Procedure then ClassS:=msg_class_procedure else if TClass =
  264. V_Conditional then ClassS:=msg_class_conditional else if TClass =
  265. V_Info then ClassS:=msg_class_info else if TClass =
  266. V_Status then ClassS:=msg_class_status else if TClass =
  267. V_Used then ClassS:=msg_class_used else if TClass =
  268. V_Tried then ClassS:=msg_class_tried else if TClass =
  269. V_Debug then ClassS:=msg_class_debug
  270. else
  271. ClassS:='???';
  272. {$else}
  273. else
  274. ClassS:='';
  275. {$endif}
  276. if ClassS<>'' then
  277. ClassS:=RExpand(ClassS,0)+': ';
  278. if assigned(Module) and
  279. (TClass<=V_ShowFile)
  280. {and (status.currentsource<>'') and (status.currentline>0)} then
  281. begin
  282. if Row>0 then
  283. begin
  284. if Col>0 then
  285. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+','+IntToStr(Col)+') '+ClassS
  286. else
  287. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS;
  288. end
  289. else
  290. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS
  291. end
  292. else
  293. S:=ClassS;
  294. if assigned(Text) then
  295. S:=S+Text^;
  296. if length(S)>MaxLen then
  297. S:=copy(S,1,MaxLen-2)+'..';
  298. GetText:=S;
  299. end;
  300. {*****************************************************************************
  301. TCompilerMessageListBox
  302. *****************************************************************************}
  303. function TCompilerMessageListBox.GetPalette: PPalette;
  304. const
  305. P: string[length(CBrowserListBox)] = CBrowserListBox;
  306. begin
  307. GetPalette:=@P;
  308. end;
  309. procedure TCompilerMessageListBox.SelectFirstError;
  310. function IsError(P : PCompilerMessage) : boolean;
  311. begin
  312. IsError:=(P^.TClass and (V_Fatal or V_Error))<>0;
  313. end;
  314. var
  315. P : PCompilerMessage;
  316. begin
  317. P:=List^.FirstThat(@IsError);
  318. If Assigned(P) then
  319. Begin
  320. FocusItem(List^.IndexOf(P));
  321. DrawView;
  322. End;
  323. end;
  324. {*****************************************************************************
  325. TCompilerMessageWindow
  326. *****************************************************************************}
  327. constructor TCompilerMessageWindow.Init;
  328. var R: TRect;
  329. HSB,VSB: PScrollBar;
  330. begin
  331. Desktop^.GetExtent(R);
  332. R.A.Y:=R.B.Y-7;
  333. inherited Init(R,dialog_compilermessages,{SearchFreeWindowNo}wnNoNumber);
  334. HelpCtx:=hcCompilerMessagesWindow;
  335. AutoNumber:=true;
  336. HSB:=StandardScrollBar(sbHorizontal+sbHandleKeyboard);
  337. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  338. Insert(HSB);
  339. VSB:=StandardScrollBar(sbVertical+sbHandleKeyboard);
  340. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  341. Insert(VSB);
  342. GetExtent(R);
  343. R.Grow(-1,-1);
  344. New(MsgLB, Init(R, HSB, VSB));
  345. MsgLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  346. Insert(MsgLB);
  347. CompilerMessageWindow:=@self;
  348. end;
  349. procedure TCompilerMessageWindow.AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  350. begin
  351. if AClass>=V_Info then
  352. Line:=0;
  353. MsgLB^.AddItem(New(PCompilerMessage,Init(AClass, Msg, MsgLB^.AddModuleName(Module), Line, Column)));
  354. if (@Self=CompilerMessageWindow) and ((AClass = V_fatal) or (AClass = V_Error)) then
  355. begin
  356. if not GetState(sfVisible) then
  357. Show;
  358. if Desktop^.First<>PView(CompilerMessageWindow) then
  359. MakeFirst;
  360. end;
  361. end;
  362. procedure TCompilerMessageWindow.ClearMessages;
  363. begin
  364. MsgLB^.Clear;
  365. ReDraw;
  366. end;
  367. {procedure TCompilerMessageWindow.Updateinfo;
  368. begin
  369. if CompileShowed then
  370. begin
  371. InfoST^.SetText(
  372. RExpand(' Main file : '#1#$7f+Copy(SmartPath(MainFile),1,39),40)+#2+
  373. 'Total lines : '#1#$7e+IntToStr(Status.CompiledLines)+#2#13+
  374. RExpand(' Target : '#1#$7f+KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)),40)+#2+
  375. 'Total errors : '#1#$7e+IntToStr(Status.ErrorCount)
  376. );
  377. if status.currentline>0 then
  378. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+'('+IntToStr(status.currentline)+')'#2)
  379. else
  380. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+#2);
  381. end;
  382. ReDraw;
  383. end;}
  384. procedure TCompilerMessageWindow.HandleEvent(var Event: TEvent);
  385. begin
  386. case Event.What of
  387. evBroadcast :
  388. case Event.Command of
  389. cmListFocusChanged :
  390. if Event.InfoPtr=MsgLB then
  391. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  392. end;
  393. end;
  394. inherited HandleEvent(Event);
  395. end;
  396. procedure TCompilerMessageWindow.SizeLimits(var Min, Max: TPoint);
  397. begin
  398. inherited SizeLimits(Min,Max);
  399. Min.X:=20;
  400. Min.Y:=4;
  401. end;
  402. procedure TCompilerMessageWindow.Close;
  403. begin
  404. Hide;
  405. end;
  406. function TCompilerMessageWindow.GetPalette: PPalette;
  407. const
  408. S : string[length(CBrowserWindow)] = CBrowserWindow;
  409. begin
  410. GetPalette:=@S;
  411. end;
  412. constructor TCompilerMessageWindow.Load(var S: TStream);
  413. begin
  414. inherited Load(S);
  415. GetSubViewPtr(S,MsgLB);
  416. end;
  417. procedure TCompilerMessageWindow.Store(var S: TStream);
  418. begin
  419. if MsgLB^.List=nil then
  420. MsgLB^.NewList(New(PCollection, Init(100,100)));
  421. inherited Store(S);
  422. PutSubViewPtr(S,MsgLB);
  423. end;
  424. procedure TCompilerMessageWindow.UpdateCommands;
  425. var Active: boolean;
  426. begin
  427. Active:=GetState(sfActive);
  428. SetCmdState(CompileCmds,Active);
  429. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  430. end;
  431. procedure TCompilerMessageWindow.SetState(AState: Word; Enable: Boolean);
  432. var OldState: word;
  433. begin
  434. OldState:=State;
  435. inherited SetState(AState,Enable);
  436. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  437. UpdateCommands;
  438. end;
  439. destructor TCompilerMessageWindow.Done;
  440. begin
  441. CompilerMessageWindow:=nil;
  442. inherited Done;
  443. end;
  444. {****************************************************************************
  445. CompilerStatusDialog
  446. ****************************************************************************}
  447. constructor TCompilerStatusDialog.Init;
  448. var R: TRect;
  449. begin
  450. R.Assign(0,0,50,11);
  451. ClearFormatParams; AddFormatParamStr(KillTilde(SwitchesModeName[SwitchesMode]));
  452. inherited Init(R, FormatStrF(dialog_compilingwithmode, FormatParams));
  453. GetExtent(R); R.B.Y:=11;
  454. R.Grow(-3,-2);
  455. New(ST, Init(R, ''));
  456. Insert(ST);
  457. GetExtent(R); R.B.Y:=11;
  458. R.Grow(-1,-1); R.A.Y:=R.B.Y-1;
  459. New(KeyST, Init(R, '', Blue*16+White+longint($80+Blue*16+White)*256,true));
  460. Insert(KeyST);
  461. { Reset Status infos see bug 1585 }
  462. Fillchar(Status,SizeOf(Status),#0);
  463. end;
  464. destructor TCompilerStatusDialog.Done;
  465. begin
  466. if @Self=CompilerStatusDialog then
  467. CompilerStatusDialog:=nil;
  468. Inherited Done;
  469. end;
  470. procedure TCompilerStatusDialog.Update;
  471. var
  472. StatusS,KeyS: string;
  473. const
  474. MaxFileNameSize = 46;
  475. begin
  476. {$ifdef TEMPHEAP}
  477. switch_to_base_heap;
  478. {$endif TEMPHEAP}
  479. case CompilationPhase of
  480. cpCompiling :
  481. begin
  482. ClearFormatParams;
  483. if Status.Compiling_current then
  484. begin
  485. AddFormatParamStr(ShrinkPath(SmartPath(Status.Currentsourcepath+Status.CurrentSource),
  486. MaxFileNameSize - Length(msg_compilingfile)));
  487. StatusS:=FormatStrF(msg_compilingfile,FormatParams);
  488. end
  489. else
  490. begin
  491. if Status.CurrentSource='' then
  492. StatusS:=''
  493. else
  494. begin
  495. StatusS:=ShrinkPath(SmartPath(DirAndNameOf(Status.Currentsourcepath+Status.CurrentSource)),
  496. MaxFileNameSize-Length(msg_loadingunit));
  497. AddFormatParamStr(StatusS);
  498. StatusS:=FormatStrF(msg_loadingunit,FormatParams);
  499. end;
  500. end;
  501. KeyS:=msg_hint_pressesctocancel;
  502. end;
  503. cpLinking :
  504. begin
  505. ClearFormatParams;
  506. AddFormatParamStr(ShrinkPath(ExeFile,
  507. MaxFileNameSize-Length(msg_linkingfile)));
  508. StatusS:=FormatStrF(msg_linkingfile,FormatParams);
  509. KeyS:=msg_hint_pleasewait;
  510. end;
  511. cpDone :
  512. begin
  513. StatusS:=msg_compiledone;
  514. KeyS:=msg_hint_compilesuccessfulpressenter;
  515. end;
  516. cpFailed :
  517. begin
  518. StatusS:=msg_failedtocompile;
  519. KeyS:=msg_hint_compilefailed;
  520. end;
  521. cpAborted :
  522. begin
  523. StatusS:=msg_compilationaborted;
  524. KeyS:=msg_hint_compileaborted;
  525. end;
  526. end;
  527. ClearFormatParams;
  528. AddFormatParamStr(ShrinkPath(SmartPath(MainFile),
  529. MaxFileNameSize-Length('Main file: %s')));
  530. AddFormatParamStr(StatusS);
  531. AddFormatParamStr(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)));
  532. AddFormatParamInt(Status.CurrentLine);
  533. AddFormatParamInt(MemAvail div 1024);
  534. AddFormatParamInt(Status.CompiledLines);
  535. AddFormatParamInt(Status.ErrorCount);
  536. ST^.SetText(
  537. FormatStrF(
  538. 'Main file: %s'#13+
  539. '%s'+#13#13+
  540. 'Target: %12s '+ 'Line number: %7d'+#13+
  541. 'Free memory: %6dK '+'Total lines: %7d'+#13+
  542. 'Total errors: %5d',
  543. FormatParams)
  544. );
  545. KeyST^.SetText(^C+KeyS);
  546. {$ifdef TEMPHEAP}
  547. switch_to_temp_heap;
  548. {$endif TEMPHEAP}
  549. end;
  550. {****************************************************************************
  551. Compiler Hooks
  552. ****************************************************************************}
  553. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  554. var
  555. event : tevent;
  556. begin
  557. GetKeyEvent(Event);
  558. if (Event.What=evKeyDown) and (Event.KeyCode=kbEsc) then
  559. begin
  560. CompilationPhase:=cpAborted;
  561. { update info messages }
  562. if assigned(CompilerStatusDialog) then
  563. begin
  564. {$ifdef redircompiler}
  565. RedirDisableAll;
  566. {$endif}
  567. CompilerStatusDialog^.Update;
  568. {$ifdef redircompiler}
  569. RedirEnableAll;
  570. {$endif}
  571. end;
  572. CompilerStatus:=true;
  573. exit;
  574. end;
  575. { only display line info every 100 lines, ofcourse all other messages
  576. will be displayed directly }
  577. if (status.currentline mod 100=0) then
  578. begin
  579. { update info messages }
  580. {$ifdef redircompiler}
  581. RedirDisableAll;
  582. {$endif}
  583. if assigned(CompilerStatusDialog) then
  584. CompilerStatusDialog^.Update;
  585. {$ifdef redircompiler}
  586. RedirEnableAll;
  587. {$endif}
  588. { update memory usage }
  589. { HeapView^.Update; }
  590. end;
  591. CompilerStatus:=false;
  592. end;
  593. procedure CompilerStop; {$ifndef FPC}far;{$endif}
  594. begin
  595. {$ifndef GABOR}
  596. {$ifdef HasSignal}
  597. if StopJmpValid then
  598. Longjmp(StopJmp,1)
  599. else
  600. Halt(1);
  601. {$endif}
  602. {$endif}
  603. end;
  604. Function CompilerGetNamedFileTime(const filename : string) : Longint; {$ifndef FPC}far;{$endif}
  605. var t: longint;
  606. W: PSourceWindow;
  607. begin
  608. W:=EditorWindowFile(FExpand(filename));
  609. if Assigned(W) and (W^.Editor^.GetModified) then
  610. t:=Now
  611. else
  612. t:=def_getnamedfiletime(filename);
  613. CompilerGetNamedFileTime:=t;
  614. end;
  615. {$ifdef COMPILER_1_0}
  616. function CompilerOpenInputFile(const filename: string): pinputfile; {$ifndef FPC}far;{$endif}
  617. var f: pinputfile;
  618. W: PSourceWindow;
  619. begin
  620. if assigned(CompilingHiddenFile) and
  621. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  622. W:=CompilingHiddenFile
  623. else
  624. W:=EditorWindowFile(FExpand(filename));
  625. if Assigned(W) and (W^.Editor^.GetModified) then
  626. f:=new(PFPInputFile, Init(W^.Editor))
  627. else
  628. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  629. if assigned(W) then
  630. W^.Editor^.CompileStamp:=CompileStamp;
  631. CompilerOpenInputFile:=f;
  632. end;
  633. {$else COMPILER_1_0}
  634. function CompilerOpenInputFile(const filename: string): tinputfile; {$ifndef FPC}far;{$endif}
  635. var f: tinputfile;
  636. W: PSourceWindow;
  637. begin
  638. if assigned(CompilingHiddenFile) and
  639. (NameandExtof(filename)=CompilingHiddenFile^.Editor^.Filename) then
  640. W:=CompilingHiddenFile
  641. else
  642. W:=EditorWindowFile(FExpand(filename));
  643. if Assigned(W) and (W^.Editor^.GetModified) then
  644. f:=TFPInputFile.Create(W^.Editor)
  645. else
  646. f:={$ifndef GABOR}def_openinputfile(filename){$else}nil{$endif};
  647. if assigned(W) then
  648. W^.Editor^.CompileStamp:=CompileStamp;
  649. CompilerOpenInputFile:=f;
  650. end;
  651. {$endif COMPILER_1_0}
  652. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  653. begin
  654. {$ifdef TEMPHEAP}
  655. switch_to_base_heap;
  656. {$endif TEMPHEAP}
  657. CompilerComment:=false;
  658. {$ifndef DEV}
  659. if (status.verbosity and Level)=Level then
  660. {$endif}
  661. begin
  662. {$ifdef redircompiler}
  663. RedirDisableAll;
  664. {$endif}
  665. if not CompilerMessageWindow^.GetState(sfVisible) then
  666. CompilerMessageWindow^.Show;
  667. if Desktop^.First<>PView(CompilerMessageWindow) then
  668. CompilerMessageWindow^.MakeFirst;
  669. CompilerMessageWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  670. status.currentline,status.currentcolumn);
  671. { update info messages }
  672. if assigned(CompilerStatusDialog) then
  673. CompilerStatusDialog^.Update;
  674. {$ifdef DEBUG}
  675. {$ifndef NODEBUG}
  676. // def_gdb_stop(level);
  677. {$endif}
  678. {$endif DEBUG}
  679. {$ifdef redircompiler}
  680. RedirEnableAll;
  681. {$endif}
  682. { update memory usage }
  683. { HeapView^.Update; }
  684. end;
  685. {$ifdef TEMPHEAP}
  686. switch_to_temp_heap;
  687. {$endif TEMPHEAP}
  688. end;
  689. {****************************************************************************
  690. DoCompile
  691. ****************************************************************************}
  692. { This function must return '' if
  693. "Options|Directories|Exe and PPU directory" is empty }
  694. function GetExePath: string;
  695. var Path: string;
  696. I: Sw_integer;
  697. begin
  698. Path:='';
  699. if DirectorySwitches<>nil then
  700. with DirectorySwitches^ do
  701. for I:=0 to ItemCount-1 do
  702. begin
  703. if ItemParam(I)='-FE' then
  704. begin
  705. Path:=GetStringItem(I);
  706. Break;
  707. end;
  708. end;
  709. if Path<>'' then
  710. GetExePath:=CompleteDir(FExpand(Path))
  711. else
  712. GetExePath:='';
  713. end;
  714. function GetMainFile(Mode: TCompileMode): string;
  715. var FileName: string;
  716. P : PSourceWindow;
  717. begin
  718. if assigned(CompilingHiddenFile) then
  719. P:=CompilingHiddenFile
  720. else
  721. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  722. if (PrimaryFileMain='') and (P=nil) then
  723. FileName:='' { nothing to compile }
  724. else
  725. begin
  726. if (PrimaryFileMain<>'') and (Mode<>cCompile) then
  727. FileName:=PrimaryFileMain
  728. else if assigned(P) then
  729. begin
  730. FileName:=P^.Editor^.FileName;
  731. if FileName='' then
  732. begin
  733. P^.Editor^.SaveAsk(true);
  734. FileName:=P^.Editor^.FileName;
  735. end;
  736. end
  737. else
  738. FileName:='';
  739. end;
  740. If (FileName<>'') then
  741. FileName:=FixFileName(FExpand(FileName));
  742. GetMainFile:=FileName;
  743. end;
  744. procedure ResetErrorMessages;
  745. procedure ResetErrorLine(P: PView); {$ifndef FPC}far;{$endif}
  746. begin
  747. if assigned(P) and
  748. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  749. PSourceWindow(P)^.Editor^.SetErrorMessage('');
  750. end;
  751. begin
  752. Desktop^.ForEach(@ResetErrorLine);
  753. end;
  754. procedure DoCompile(Mode: TCompileMode);
  755. function IsExitEvent(E: TEvent): boolean;
  756. begin
  757. { following suggestion by Harsha Senanayake }
  758. IsExitEvent:=(E.What=evKeyDown);
  759. end;
  760. var
  761. s,FileName: string;
  762. ErrFile : Text;
  763. MustRestartDebugger,
  764. StoreStopJumpValid : boolean;
  765. StoreStopJmp : Jmp_buf;
  766. StoreExitProc : pointer;
  767. JmpRet,Error,LinkErrorCount : longint;
  768. E : TEvent;
  769. DummyView: PView;
  770. PPasFile : string[64];
  771. begin
  772. AskRecompileIfModifiedFlag:=true;
  773. { Get FileName }
  774. FileName:=GetMainFile(Mode);
  775. if FileName='' then
  776. begin
  777. ErrorBox(msg_nothingtocompile,nil);
  778. Exit;
  779. end else
  780. { THis is not longer necessary as unsaved files are loaded from a memorystream,
  781. and with the file as primaryfile set it is already incompatible with itself
  782. if FileName='*' then
  783. begin
  784. ErrorBox(msg_cantcompileunsavedfile,nil);
  785. Exit;
  786. end; }
  787. PushStatus('Beginning compilation...');
  788. { Show Compiler Messages Window }
  789. { if not CompilerMessageWindow^.GetState(sfVisible) then
  790. CompilerMessageWindow^.Show;
  791. CompilerMessageWindow^.MakeFirst;}
  792. CompilerMessageWindow^.ClearMessages;
  793. { Tell why we compile }
  794. NeedRecompile(Mode,true);
  795. MainFile:=FileName;
  796. SetStatus('Writing switches to file...');
  797. WriteSwitches(SwitchesPath);
  798. { leaving open browsers leads to crashes !! (PM) }
  799. SetStatus('Preparing symbol info...');
  800. CloseAllBrowsers;
  801. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  802. WriteSymbolsFile(BrowserName);
  803. { MainFile:=FixFileName(FExpand(FileName));}
  804. SetStatus('Preparing to compile...'+NameOf(MainFile));
  805. If GetEXEPath<>'' then
  806. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+ExeExt)
  807. else
  808. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+ExeExt;
  809. { Reset }
  810. CtrlBreakHit:=false;
  811. { Create Compiler Status Dialog }
  812. CompilationPhase:=cpCompiling;
  813. if not assigned(CompilingHiddenFile) then
  814. begin
  815. New(CompilerStatusDialog, Init);
  816. CompilerStatusDialog^.SetState(sfModal,true);
  817. { disable window closing }
  818. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags and not wfclose;
  819. Application^.Insert(CompilerStatusDialog);
  820. CompilerStatusDialog^.Update;
  821. end;
  822. { hook compiler output }
  823. {$ifdef TP}
  824. do_status:=CompilerStatus;
  825. do_stop:=CompilerStop;
  826. do_comment:=CompilerComment;
  827. {$ifndef GABOR}do_openinputfile:=CompilerOpenInputFile;{$endif}
  828. do_getnamedfiletime:=CompilerGetNamedFileTime;
  829. {$else not TP}
  830. do_status:=@CompilerStatus;
  831. do_stop:=@CompilerStop;
  832. do_comment:=@CompilerComment;
  833. do_openinputfile:=@CompilerOpenInputFile;
  834. do_getnamedfiletime:=@CompilerGetNamedFileTime;
  835. {$endif TP}
  836. do_initsymbolinfo:={$ifdef fpc}@{$endif}InitBrowserCol;
  837. do_donesymbolinfo:={$ifdef fpc}@{$endif}DoneBrowserCol;
  838. do_extractsymbolinfo:={$ifdef fpc}@{$endif}CreateBrowserCol;
  839. { Compile ! }
  840. {$ifdef redircompiler}
  841. ChangeRedirOut(FPOutFileName,false);
  842. ChangeRedirError(FPErrFileName,false);
  843. {$endif}
  844. {$ifdef TEMPHEAP}
  845. split_heap;
  846. switch_to_temp_heap;
  847. {$endif TEMPHEAP}
  848. { insert "" around name so that spaces are allowed }
  849. { only supported in compiler after 2000/01/14 PM }
  850. if pos(' ',FileName)>0 then
  851. FileName:='"'+FileName+'"';
  852. if mode=cBuild then
  853. FileName:='-B '+FileName;
  854. { tokens are created and distroed by compiler.compile !! PM }
  855. DoneTokens;
  856. {$ifdef COMPILER_1_0}
  857. PPasFile:='ppas'+source_os.scriptext;
  858. {$else COMPILER_1_0}
  859. PPasFile:='ppas'+source_info.scriptext;
  860. {$endif COMPILER_1_0}
  861. WUtils.DeleteFile(GetExePath+PpasFile);
  862. SetStatus('Compiling...');
  863. {$ifndef GABOR}
  864. {$ifdef HasSignal}
  865. StoreStopJumpValid:=StopJmpValid;
  866. StoreStopJmp:=StopJmp;
  867. {$endif HasSignal}
  868. StoreExitProc:=ExitProc;
  869. {$ifdef HasSignal}
  870. StopJmpValid:=true;
  871. JmpRet:=SetJmp(StopJmp);
  872. {$else}
  873. JmpRet:=0;
  874. {$endif HasSignal}
  875. if JmpRet=0 then
  876. begin
  877. inc(CompileStamp);
  878. ResetErrorMessages;
  879. {$ifndef NODEBUG}
  880. MustRestartDebugger:=false;
  881. if assigned(Debugger) then
  882. if Debugger^.HasExe then
  883. begin
  884. Debugger^.Reset;
  885. MustRestartDebugger:=true;
  886. end;
  887. {$endif NODEBUG}
  888. FpIntF.Compile(FileName,SwitchesPath);
  889. SetStatus('Finished compiling...');
  890. end
  891. else
  892. begin
  893. { We need to restore Exitproc to the value
  894. it was before calling FPintF.compile PM }
  895. ExitProc:=StoreExitProc;
  896. Inc(status.errorCount);
  897. {$ifdef HasSignal}
  898. Case JmpRet of
  899. SIGINT : s := 'Interrupted by Ctrl-C';
  900. SIGILL : s := 'Illegal instruction';
  901. SIGSEGV : s := 'Signal Segmentation violation';
  902. SIGFPE : s:='Floating point signal';
  903. else
  904. s:='Undetermined signal '+inttostr(JmpRet);
  905. end;
  906. CompilerMessageWindow^.AddMessage(V_error,s+' during compilation','',0,0);
  907. {$endif HasSignal}
  908. CompilerMessageWindow^.AddMessage(V_error,'Long jumped out of compilation...','',0,0);
  909. SetStatus('Long jumped out of compilation...');
  910. end;
  911. {$ifdef HasSignal}
  912. StopJmpValid:=StoreStopJumpValid;
  913. StopJmp:=StoreStopJmp;
  914. {$endif HasSignal}
  915. {$endif}
  916. { tokens are created and distroyed by compiler.compile !! PM }
  917. InitTokens;
  918. if LinkAfter and
  919. ExistsFile(GetExePath+PpasFile) and
  920. (CompilationPhase<>cpAborted) and
  921. (status.errorCount=0) then
  922. begin
  923. CompilationPhase:=cpLinking;
  924. if assigned(CompilerStatusDialog) then
  925. CompilerStatusDialog^.Update;
  926. SetStatus('Assembling and/or linking...');
  927. {$ifndef redircompiler}
  928. { At least here we want to catch output
  929. of batch file PM }
  930. ChangeRedirOut(FPOutFileName,false);
  931. ChangeRedirError(FPErrFileName,false);
  932. {$endif}
  933. {$ifdef Unix}
  934. Shell(GetExePath+PpasFile);
  935. Error:=LinuxError;
  936. {$else}
  937. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile);
  938. Error:=DosError;
  939. {$endif}
  940. SetStatus('Finished linking...');
  941. RestoreRedirOut;
  942. RestoreRedirError;
  943. if Error<>0 then
  944. Inc(status.errorCount);
  945. if Status.IsExe and not Status.IsLibrary and not ExistsFile(EXEFile) then
  946. begin
  947. Inc(status.errorCount);
  948. ClearFormatParams; AddFormatParamStr(ExeFile);
  949. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  950. {$I-}
  951. Assign(ErrFile,FPErrFileName);
  952. Reset(ErrFile);
  953. if EatIO<>0 then
  954. ErrorBox(FormatStrStr(msg_cantopenfile,FPErrFileName),nil)
  955. else
  956. begin
  957. LinkErrorCount:=0;
  958. While not eof(ErrFile) and (LinkErrorCount<25) do
  959. begin
  960. readln(ErrFile,s);
  961. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  962. inc(LinkErrorCount);
  963. end;
  964. if not eof(ErrFile) then
  965. begin
  966. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  967. CompilerMessageWindow^.AddMessage(V_error,
  968. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  969. end;
  970. Close(ErrFile);
  971. end;
  972. EatIO;
  973. {$I+}
  974. end
  975. else if error=0 then
  976. WUtils.DeleteFile(GetExePath+PpasFile);
  977. end;
  978. {$ifdef TEMPHEAP}
  979. switch_to_base_heap;
  980. {$endif TEMPHEAP}
  981. {$ifdef redircompiler}
  982. RestoreRedirOut;
  983. RestoreRedirError;
  984. {$endif}
  985. PopStatus;
  986. { Set end status }
  987. if not (CompilationPhase in [cpAborted,cpFailed]) then
  988. if (status.errorCount=0) then
  989. begin
  990. CompilationPhase:=cpDone;
  991. LastCompileTime := cardinal(Now);
  992. end
  993. else
  994. CompilationPhase:=cpFailed;
  995. { Show end status }
  996. { reenable window closing }
  997. if assigned(CompilerStatusDialog) then
  998. begin
  999. CompilerStatusDialog^.Flags:=CompilerStatusDialog^.Flags or wfclose;
  1000. CompilerStatusDialog^.Update;
  1001. CompilerStatusDialog^.ReDraw;
  1002. CompilerStatusDialog^.SetState(sfModal,false);
  1003. if ((CompilationPhase in [cpAborted,cpDone,cpFailed]) or (ShowStatusOnError))
  1004. and ((Mode<>cRun) or (CompilationPhase<>cpDone)) then
  1005. repeat
  1006. CompilerStatusDialog^.GetEvent(E);
  1007. if IsExitEvent(E)=false then
  1008. CompilerStatusDialog^.HandleEvent(E);
  1009. until IsExitEvent(E) or not assigned(CompilerStatusDialog);
  1010. {if IsExitEvent(E) then
  1011. Application^.PutEvent(E);}
  1012. if assigned(CompilerStatusDialog) then
  1013. begin
  1014. Application^.Delete(CompilerStatusDialog);
  1015. Dispose(CompilerStatusDialog, Done);
  1016. end;
  1017. end;
  1018. CompilerStatusDialog:=nil;
  1019. { end compilation returns true if the messagewindow should be removed }
  1020. if CompilationPhase=cpDone then
  1021. begin
  1022. CompilerMessageWindow^.Hide;
  1023. { This is the last compiled main file }
  1024. PrevMainFile:=MainFile;
  1025. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  1026. end;
  1027. { Update the app }
  1028. Message(Application,evCommand,cmUpdate,nil);
  1029. {$ifdef TEMPHEAP}
  1030. releasetempheap;
  1031. unsplit_heap;
  1032. {$endif TEMPHEAP}
  1033. DummyView:=Desktop^.First;
  1034. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  1035. begin
  1036. DummyView:=DummyView^.NextView;
  1037. end;
  1038. with DummyView^ do
  1039. if GetState(sfVisible) then
  1040. begin
  1041. SetState(sfSelected,false);
  1042. SetState(sfSelected,true);
  1043. end;
  1044. if Assigned(CompilerMessageWindow) then
  1045. with CompilerMessageWindow^ do
  1046. begin
  1047. if GetState(sfVisible) then
  1048. begin
  1049. SetState(sfSelected,false);
  1050. SetState(sfSelected,true);
  1051. end;
  1052. if (status.errorCount>0) then
  1053. MsgLB^.SelectFirstError;
  1054. end;
  1055. { ^^^ we need this trick to reactivate the desktop }
  1056. EditorModified:=false;
  1057. {$ifndef NODEBUG}
  1058. if MustRestartDebugger then
  1059. InitDebugger;
  1060. {$endif NODEBUG}
  1061. { In case we have something that the compiler touched }
  1062. AskToReloadAllModifiedFiles;
  1063. { Try to read Browser info in again if compilation failure !! }
  1064. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  1065. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1066. ReadSymbolsFile(BrowserName);
  1067. if UseAllUnitsInCodeComplete and not assigned(CompilingHiddenFile) then
  1068. AddAvailableUnitsToCodeComplete(false);
  1069. end;
  1070. function NeedRecompile(Mode :TCompileMode; verbose : boolean): boolean;
  1071. var Need: boolean;
  1072. I: sw_integer;
  1073. SF: PSourceFile;
  1074. SourceTime,PPUTime,ObjTime: longint;
  1075. W: PSourceWindow;
  1076. begin
  1077. if Assigned(SourceFiles)=false then
  1078. Need:={(EditorModified=true)}true
  1079. else
  1080. begin
  1081. Need:=(PrevMainFile<>GetMainFile(Mode)) and (PrevMainFile<>'');
  1082. if Need then
  1083. begin
  1084. if verbose then
  1085. begin
  1086. ClearFormatParams; AddFormatParamStr(GetMainFile(Mode));
  1087. CompilerMessageWindow^.AddMessage(V_info,
  1088. FormatStrF(msg_firstcompilationof,FormatParams),
  1089. '',0,0);
  1090. end;
  1091. end
  1092. else
  1093. for I:=0 to SourceFiles^.Count-1 do
  1094. begin
  1095. SF:=SourceFiles^.At(I);
  1096. SourceTime:=GetFileTime(SF^.GetSourceFileName);
  1097. PPUTime:=GetFileTime(SF^.GetPPUFileName);
  1098. ObjTime:=GetFileTime(SF^.GetObjFileName);
  1099. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  1100. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  1101. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  1102. writeln('------');}
  1103. { some units don't generate object files }
  1104. W:=EditorWindowFile(SF^.GetSourceFileName);
  1105. if (SourceTime<>-1) then
  1106. if ((SourceTime>PPUTime) or
  1107. ((SourceTime>ObjTime) and
  1108. (ObjTime<>-1))) or
  1109. (assigned(W) and (W^.Editor^.CompileStamp<0)) then
  1110. begin
  1111. Need:=true;
  1112. if verbose then
  1113. begin
  1114. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  1115. CompilerMessageWindow^.AddMessage(V_info,
  1116. FormatStrF(msg_recompilingbecauseof,FormatParams),
  1117. SF^.GetSourceFileName,1,1);
  1118. end;
  1119. Break;
  1120. end;
  1121. end;
  1122. { writeln('Need?', Need); system.readln;}
  1123. end;
  1124. NeedRecompile:=Need;
  1125. end;
  1126. {$ifdef COMPILER_1_0}
  1127. constructor TFPInputFile.Init(AEditor: PFileEditor);
  1128. begin
  1129. if not Assigned(AEditor) then Fail;
  1130. if inherited Init(AEditor^.FileName)=false then
  1131. Fail;
  1132. Editor:=AEditor;
  1133. end;
  1134. {$else COMPILER_1_0}
  1135. constructor TFPInputFile.Create(AEditor: PFileEditor);
  1136. begin
  1137. if not Assigned(AEditor) then Fail;
  1138. if inherited Create(AEditor^.FileName)=nil then
  1139. Fail;
  1140. Editor:=AEditor;
  1141. end;
  1142. {$endif COMPILER_1_0}
  1143. function TFPInputFile.fileopen(const filename: string): boolean;
  1144. var OK: boolean;
  1145. begin
  1146. S:=New(PMemoryStream, Init(0,0));
  1147. OK:=Assigned(S) and (S^.Status=stOK);
  1148. if OK then OK:=Editor^.SaveToStream(S);
  1149. if OK then
  1150. S^.Seek(0)
  1151. else
  1152. begin
  1153. if Assigned(S) then Dispose(S, Done);
  1154. S:=nil;
  1155. end;
  1156. fileopen:=OK;
  1157. end;
  1158. function TFPInputFile.fileseek(pos: longint): boolean;
  1159. var OK: boolean;
  1160. begin
  1161. OK:=assigned(S);
  1162. if OK then
  1163. begin
  1164. S^.Reset;
  1165. S^.Seek(pos);
  1166. OK:=(S^.Status=stOK);
  1167. end;
  1168. fileseek:=OK;
  1169. end;
  1170. function TFPInputFile.fileread(var databuf; maxsize: longint): longint;
  1171. var
  1172. size: longint;
  1173. begin
  1174. if not assigned(S) then size:=0 else
  1175. begin
  1176. size:=min(maxsize,(S^.GetSize-S^.GetPos));
  1177. S^.Read(databuf,size);
  1178. if S^.Status<>stOK then size:=0;
  1179. end;
  1180. fileread:=size;
  1181. end;
  1182. function TFPInputFile.fileeof: boolean;
  1183. var EOF: boolean;
  1184. begin
  1185. EOF:=not assigned(S);
  1186. if not EOF then
  1187. EOF:=(S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  1188. fileeof:=EOF;
  1189. end;
  1190. function TFPInputFile.fileclose: boolean;
  1191. var OK: boolean;
  1192. begin
  1193. OK:=assigned(S);
  1194. if OK then
  1195. begin
  1196. S^.Reset;
  1197. Dispose(S, Done);
  1198. S:=nil;
  1199. OK:=true;
  1200. end;
  1201. fileclose:=OK;
  1202. end;
  1203. procedure RegisterFPCompile;
  1204. begin
  1205. {$ifndef NOOBJREG}
  1206. RegisterType(RCompilerMessageListBox);
  1207. RegisterType(RCompilerMessageWindow);
  1208. {$endif}
  1209. end;
  1210. end.
  1211. {
  1212. $Log$
  1213. Revision 1.16 2002-10-23 19:19:40 hajny
  1214. * another bunch of missing HasSignal conditionals
  1215. Revision 1.15 2002/09/26 15:00:35 pierre
  1216. * fix problems with system unit is not present for __fp__ compilation
  1217. Revision 1.14 2002/09/13 22:30:50 pierre
  1218. * only fpc uses video unit
  1219. Revision 1.13 2002/09/09 06:53:54 pierre
  1220. * avoid to save file used by codecomplete
  1221. Revision 1.12 2002/09/07 15:40:42 peter
  1222. * old logs removed and tabs fixed
  1223. Revision 1.11 2002/09/05 08:45:40 pierre
  1224. * try to fix recompilation on changes problems
  1225. Revision 1.10 2002/09/04 14:07:12 pierre
  1226. + Enhance code complete by inserting unit symbols
  1227. Revision 1.9 2002/08/26 13:03:14 pierre
  1228. + add a lock to speed up parsing of userscreen
  1229. Revision 1.8 2002/04/10 22:37:37 pierre
  1230. * save and restore Exitproc if LongJmp called
  1231. Revision 1.7 2002/03/20 14:48:27 pierre
  1232. * moved StopJmp buffer to fpcatch unit
  1233. }