fpcompil.pas 38 KB

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