fpcompil.pas 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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 FPCompile;
  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. uses
  21. Objects,
  22. Drivers,Views,Dialogs,
  23. WUtils,WViews,
  24. FPSymbol,
  25. FPViews;
  26. type
  27. TCompileMode = (cBuild,cMake,cCompile,cRun);
  28. type
  29. PCompilerMessage = ^TCompilerMessage;
  30. TCompilerMessage = object(TMessageItem)
  31. function GetText(MaxLen: Sw_Integer): String; virtual;
  32. end;
  33. PCompilerMessageListBox = ^TCompilerMessageListBox;
  34. TCompilerMessageListBox = object(TMessageListBox)
  35. function GetPalette: PPalette; virtual;
  36. procedure SelectFirstError;
  37. end;
  38. PCompilerMessageWindow = ^TCompilerMessageWindow;
  39. TCompilerMessageWindow = object(TFPWindow)
  40. constructor Init;
  41. procedure HandleEvent(var Event: TEvent); virtual;
  42. function GetPalette: PPalette; virtual;
  43. procedure Close;virtual;
  44. destructor Done; virtual;
  45. procedure SizeLimits(var Min, Max: TPoint); virtual;
  46. procedure AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  47. procedure ClearMessages;
  48. constructor Load(var S: TStream);
  49. procedure Store(var S: TStream);
  50. private
  51. {CompileShowed : boolean;}
  52. {Mode : TCompileMode;}
  53. MsgLB : PCompilerMessageListBox;
  54. {CurrST,
  55. InfoST : PColorStaticText;}
  56. end;
  57. PCompilerStatusDialog = ^TCompilerStatusDialog;
  58. TCompilerStatusDialog = object(TCenterDialog)
  59. ST : PAdvancedStaticText;
  60. KeyST : PColorStaticText;
  61. constructor Init;
  62. procedure Update;
  63. end;
  64. const
  65. CompilerMessageWindow : PCompilerMessageWindow = nil;
  66. CompilerStatusDialog : PCompilerStatusDialog = nil;
  67. procedure DoCompile(Mode: TCompileMode);
  68. function NeedRecompile(verbose : boolean): boolean;
  69. procedure ParseUserScreen;
  70. procedure RegisterFPCompile;
  71. implementation
  72. uses
  73. {$ifdef linux}
  74. Linux,
  75. {$endif}
  76. Dos,Video,
  77. App,Commands,tokens,
  78. CompHook, Compiler, systems, browcol, switches,
  79. WEditor,
  80. FPString,FPRedir,FPDesk,FPUsrScr,FPHelp,
  81. FPIde,FPConst,FPVars,FPUtils,FPIntf,FPSwitch;
  82. {$ifndef NOOBJREG}
  83. const
  84. RCompilerMessageListBox: TStreamRec = (
  85. ObjType: 1211;
  86. VmtLink: Ofs(TypeOf(TCompilerMessageListBox)^);
  87. Load: @TCompilerMessageListBox.Load;
  88. Store: @TCompilerMessageListBox.Store
  89. );
  90. RCompilerMessageWindow: TStreamRec = (
  91. ObjType: 1212;
  92. VmtLink: Ofs(TypeOf(TCompilerMessageWindow)^);
  93. Load: @TCompilerMessageWindow.Load;
  94. Store: @TCompilerMessageWindow.Store
  95. );
  96. {$endif}
  97. procedure ParseUserScreen;
  98. var
  99. y : longint;
  100. Text,Attr : String;
  101. DisplayCompilerWindow : boolean;
  102. cc: integer;
  103. procedure SearchBackTrace;
  104. var AText,ModuleName,st : String;
  105. row : longint;
  106. begin
  107. if pos(' 0x',Text)=1 then
  108. begin
  109. AText:=Text;
  110. Delete(Text,1,10);
  111. While pos(' ',Text)=1 do
  112. Delete(Text,1,1);
  113. if pos('of ',Text)>0 then
  114. begin
  115. ModuleName:=Copy(Text,pos('of ',Text)+3,255);
  116. While ModuleName[Length(ModuleName)]=' ' do
  117. Delete(ModuleName,Length(ModuleName),1);
  118. end
  119. else
  120. ModuleName:='';
  121. if pos('line ',Text)>0 then
  122. begin
  123. Text:=Copy(Text,Pos('line ',Text)+5,255);
  124. st:=Copy(Text,1,Pos(' ',Text)-1);
  125. Val(st,row,cc);
  126. end
  127. else
  128. row:=0;
  129. CompilerMessageWindow^.AddMessage(V_Fatal,AText
  130. ,ModuleName,row,1);
  131. DisplayCompilerWindow:=true;
  132. end;
  133. end;
  134. procedure InsertInMessages(Const TypeStr : String;_Type : longint;EnableDisplay : boolean);
  135. var p,p2,col,row : longint;
  136. St,ModuleName : string;
  137. begin
  138. p:=pos(TypeStr,Text);
  139. p2:=Pos('(',Text);
  140. if (p>0) and (p2>0) and (p2<p) then
  141. begin
  142. ModuleName:=Copy(Text,1,p2-1);
  143. st:=Copy(Text,p2+1,255);
  144. Val(Copy(st,1,pos(',',st)-1),row,cc);
  145. st:=Copy(st,Pos(',',st)+1,255);
  146. Val(Copy(st,1,pos(')',st)-1),col,cc);
  147. CompilerMessageWindow^.AddMessage(_type,Copy(Text,pos(':',Text)+1,255)
  148. ,ModuleName,row,col);
  149. If EnableDisplay then
  150. DisplayCompilerWindow:=true;
  151. end;
  152. end;
  153. begin
  154. if not assigned(UserScreen) then
  155. exit;
  156. DisplayCompilerWindow:=false;
  157. PushStatus('Parsing User Screen');
  158. for Y:=0 to UserScreen^.GetHeight do
  159. begin
  160. UserScreen^.GetLine(Y,Text,Attr);
  161. SearchBackTrace;
  162. InsertInMessages(' Fatal:',v_Fatal,true);
  163. InsertInMessages(' Error:',v_Error,true);
  164. InsertInMessages(' Warning:',v_Warning,false);
  165. InsertInMessages(' Note:',v_Note,false);
  166. InsertInMessages(' Info:',v_Info,false);
  167. InsertInMessages(' Hint:',v_Hint,false);
  168. end;
  169. if DisplayCompilerWindow then
  170. begin
  171. if not CompilerMessageWindow^.GetState(sfVisible) then
  172. CompilerMessageWindow^.Show;
  173. CompilerMessageWindow^.MakeFirst;
  174. CompilerMessageWindow^.MsgLB^.SelectFirstError;
  175. end;
  176. PopStatus;
  177. end;
  178. {*****************************************************************************
  179. TCompilerMessage
  180. *****************************************************************************}
  181. function TCompilerMessage.GetText(MaxLen: Sw_Integer): String;
  182. var
  183. ClassS: string[20];
  184. S: string;
  185. begin
  186. if TClass=
  187. V_Fatal then ClassS:=msg_class_Fatal else if TClass =
  188. V_Error then ClassS:=msg_class_Error else if TClass =
  189. V_Normal then ClassS:=msg_class_Normal else if TClass =
  190. V_Warning then ClassS:=msg_class_Warning else if TClass =
  191. V_Note then ClassS:=msg_class_Note else if TClass =
  192. V_Hint then ClassS:=msg_class_Hint
  193. {$ifdef VERBOSETXT}
  194. else if TClass =
  195. V_Macro then ClassS:=msg_class_macro else if TClass =
  196. V_Procedure then ClassS:=msg_class_procedure else if TClass =
  197. V_Conditional then ClassS:=msg_class_conditional else if TClass =
  198. V_Info then ClassS:=msg_class_info else if TClass =
  199. V_Status then ClassS:=msg_class_status else if TClass =
  200. V_Used then ClassS:=msg_class_used else if TClass =
  201. V_Tried then ClassS:=msg_class_tried else if TClass =
  202. V_Debug then ClassS:=msg_class_debug
  203. else
  204. ClassS:='???';
  205. {$else}
  206. else
  207. ClassS:='';
  208. {$endif}
  209. if ClassS<>'' then
  210. ClassS:=RExpand(ClassS,0)+': ';
  211. if assigned(Module) and
  212. (TClass<=V_ShowFile)
  213. {and (status.currentsource<>'') and (status.currentline>0)} then
  214. begin
  215. if Row>0 then
  216. begin
  217. if Col>0 then
  218. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+','+IntToStr(Col)+') '+ClassS
  219. else
  220. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS;
  221. end
  222. else
  223. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+ClassS
  224. end
  225. else
  226. S:=ClassS;
  227. if assigned(Text) then
  228. S:=S+Text^;
  229. if length(S)>MaxLen then
  230. S:=copy(S,1,MaxLen-2)+'..';
  231. GetText:=S;
  232. end;
  233. {*****************************************************************************
  234. TCompilerMessageListBox
  235. *****************************************************************************}
  236. function TCompilerMessageListBox.GetPalette: PPalette;
  237. const
  238. P: string[length(CBrowserListBox)] = CBrowserListBox;
  239. begin
  240. GetPalette:=@P;
  241. end;
  242. procedure TCompilerMessageListBox.SelectFirstError;
  243. function IsError(P : PCompilerMessage) : boolean;
  244. begin
  245. IsError:=(P^.TClass and (V_Fatal or V_Error))<>0;
  246. end;
  247. var
  248. P : PCompilerMessage;
  249. begin
  250. P:=List^.FirstThat(@IsError);
  251. If Assigned(P) then
  252. Begin
  253. FocusItem(List^.IndexOf(P));
  254. DrawView;
  255. End;
  256. end;
  257. {*****************************************************************************
  258. TCompilerMessageWindow
  259. *****************************************************************************}
  260. constructor TCompilerMessageWindow.Init;
  261. var R: TRect;
  262. HSB,VSB: PScrollBar;
  263. begin
  264. Desktop^.GetExtent(R);
  265. R.A.Y:=R.B.Y-7;
  266. inherited Init(R,dialog_compilermessages,{SearchFreeWindowNo}wnNoNumber);
  267. HelpCtx:=hcMessagesWindow;
  268. AutoNumber:=true;
  269. HSB:=StandardScrollBar(sbHorizontal+sbHandleKeyboard);
  270. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY;
  271. Insert(HSB);
  272. VSB:=StandardScrollBar(sbVertical+sbHandleKeyboard);
  273. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  274. Insert(VSB);
  275. GetExtent(R);
  276. R.Grow(-1,-1);
  277. New(MsgLB, Init(R, HSB, VSB));
  278. MsgLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  279. Insert(MsgLB);
  280. CompilerMessageWindow:=@self;
  281. end;
  282. procedure TCompilerMessageWindow.AddMessage(AClass: longint;const Msg, Module: string; Line, Column: longint);
  283. begin
  284. if AClass>=V_Info then
  285. Line:=0;
  286. MsgLB^.AddItem(New(PCompilerMessage,Init(AClass, Msg, MsgLB^.AddModuleName(Module), Line, Column)));
  287. end;
  288. procedure TCompilerMessageWindow.ClearMessages;
  289. begin
  290. MsgLB^.Clear;
  291. ReDraw;
  292. end;
  293. {procedure TCompilerMessageWindow.Updateinfo;
  294. begin
  295. if CompileShowed then
  296. begin
  297. InfoST^.SetText(
  298. RExpand(' Main file : '#1#$7f+Copy(SmartPath(MainFile),1,39),40)+#2+
  299. 'Total lines : '#1#$7e+IntToStr(Status.CompiledLines)+#2#13+
  300. RExpand(' Target : '#1#$7f+KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)),40)+#2+
  301. 'Total errors : '#1#$7e+IntToStr(Status.ErrorCount)
  302. );
  303. if status.currentline>0 then
  304. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+'('+IntToStr(status.currentline)+')'#2)
  305. else
  306. CurrST^.SetText(' Status: '#1#$7e+status.currentsource+#2);
  307. end;
  308. ReDraw;
  309. end;}
  310. procedure TCompilerMessageWindow.HandleEvent(var Event: TEvent);
  311. begin
  312. case Event.What of
  313. evBroadcast :
  314. case Event.Command of
  315. cmListFocusChanged :
  316. if Event.InfoPtr=MsgLB then
  317. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  318. end;
  319. end;
  320. inherited HandleEvent(Event);
  321. end;
  322. procedure TCompilerMessageWindow.SizeLimits(var Min, Max: TPoint);
  323. begin
  324. inherited SizeLimits(Min,Max);
  325. Min.X:=20;
  326. Min.Y:=4;
  327. end;
  328. procedure TCompilerMessageWindow.Close;
  329. begin
  330. Hide;
  331. end;
  332. function TCompilerMessageWindow.GetPalette: PPalette;
  333. const
  334. S : string[length(CBrowserWindow)] = CBrowserWindow;
  335. begin
  336. GetPalette:=@S;
  337. end;
  338. constructor TCompilerMessageWindow.Load(var S: TStream);
  339. begin
  340. inherited Load(S);
  341. GetSubViewPtr(S,MsgLB);
  342. end;
  343. procedure TCompilerMessageWindow.Store(var S: TStream);
  344. begin
  345. if MsgLB^.List=nil then
  346. MsgLB^.NewList(New(PCollection, Init(100,100)));
  347. inherited Store(S);
  348. PutSubViewPtr(S,MsgLB);
  349. end;
  350. destructor TCompilerMessageWindow.Done;
  351. begin
  352. CompilerMessageWindow:=nil;
  353. inherited Done;
  354. end;
  355. {****************************************************************************
  356. CompilerStatusDialog
  357. ****************************************************************************}
  358. constructor TCompilerStatusDialog.Init;
  359. var R: TRect;
  360. begin
  361. R.Assign(0,0,50,11);
  362. ClearFormatParams; AddFormatParamStr(KillTilde(SwitchesModeName[SwitchesMode]));
  363. inherited Init(R, FormatStrF(dialog_compilingwithmode, FormatParams));
  364. GetExtent(R); R.B.Y:=11;
  365. R.Grow(-3,-2);
  366. New(ST, Init(R, ''));
  367. Insert(ST);
  368. GetExtent(R); R.B.Y:=11;
  369. R.Grow(-1,-1); R.A.Y:=R.B.Y-1;
  370. New(KeyST, Init(R, '', Blue*16+White+longint($80+Blue*16+White)*256));
  371. Insert(KeyST);
  372. end;
  373. procedure TCompilerStatusDialog.Update;
  374. var
  375. StatusS,KeyS: string;
  376. begin
  377. {$ifdef TEMPHEAP}
  378. switch_to_base_heap;
  379. {$endif TEMPHEAP}
  380. case CompilationPhase of
  381. cpCompiling :
  382. begin
  383. ClearFormatParams; AddFormatParamStr(SmartPath(Status.CurrentSource));
  384. StatusS:=FormatStrF(msg_compilingfile,FormatParams);
  385. KeyS:=msg_hint_pressesctocancel;
  386. end;
  387. cpLinking :
  388. begin
  389. ClearFormatParams; AddFormatParamStr(ExeFile);
  390. StatusS:=FormatStrF(msg_linkingfile,FormatParams);
  391. KeyS:=msg_hint_pleasewait;
  392. end;
  393. cpDone :
  394. begin
  395. StatusS:=msg_compiledone;
  396. KeyS:=msg_hint_compilesuccessfulpressenter;
  397. end;
  398. cpFailed :
  399. begin
  400. StatusS:=msg_failedtocompile;
  401. KeyS:=msg_hint_compilefailed;
  402. end;
  403. cpAborted :
  404. begin
  405. StatusS:=msg_compilationaborted;
  406. KeyS:=msg_hint_compileaborted;
  407. end;
  408. end;
  409. ClearFormatParams;
  410. AddFormatParamStr(SmartPath(MainFile));
  411. AddFormatParamStr(StatusS);
  412. AddFormatParamStr(KillTilde(TargetSwitches^.ItemName(TargetSwitches^.GetCurrSel)));
  413. AddFormatParamInt(Status.CurrentLine);
  414. AddFormatParamInt(MemAvail div 1024);
  415. AddFormatParamInt(Status.CompiledLines);
  416. AddFormatParamInt(Status.ErrorCount);
  417. ST^.SetText(
  418. FormatStrF(
  419. 'Main file: %s'#13+
  420. '%s'+#13#13+
  421. 'Target: %12s '+ 'Line number: %7d'+#13+
  422. 'Free memory: %6dK '+'Total lines: %7d'+#13+
  423. 'Total errors: %5d',
  424. FormatParams)
  425. );
  426. KeyST^.SetText(^C+KeyS);
  427. {$ifdef TEMPHEAP}
  428. switch_to_temp_heap;
  429. {$endif TEMPHEAP}
  430. end;
  431. {****************************************************************************
  432. Compiler Hooks
  433. ****************************************************************************}
  434. function CompilerStatus: boolean; {$ifndef FPC}far;{$endif}
  435. var
  436. event : tevent;
  437. begin
  438. GetKeyEvent(Event);
  439. if (Event.What=evKeyDown) and (Event.KeyCode=kbEsc) then
  440. begin
  441. CompilationPhase:=cpAborted;
  442. { update info messages }
  443. if assigned(CompilerStatusDialog) then
  444. begin
  445. {$ifdef redircompiler}
  446. RedirDisableAll;
  447. {$endif}
  448. CompilerStatusDialog^.Update;
  449. {$ifdef redircompiler}
  450. RedirEnableAll;
  451. {$endif}
  452. end;
  453. CompilerStatus:=true;
  454. exit;
  455. end;
  456. { only display line info every 100 lines, ofcourse all other messages
  457. will be displayed directly }
  458. if (status.currentline mod 100=0) then
  459. begin
  460. { update info messages }
  461. {$ifdef redircompiler}
  462. RedirDisableAll;
  463. {$endif}
  464. if assigned(CompilerStatusDialog) then
  465. CompilerStatusDialog^.Update;
  466. {$ifdef redircompiler}
  467. RedirEnableAll;
  468. {$endif}
  469. { update memory usage }
  470. { HeapView^.Update; }
  471. end;
  472. CompilerStatus:=false;
  473. end;
  474. procedure CompilerStop; {$ifndef FPC}far;{$endif}
  475. begin
  476. end;
  477. function CompilerComment(Level:Longint; const s:string):boolean; {$ifndef FPC}far;{$endif}
  478. begin
  479. {$ifdef TEMPHEAP}
  480. switch_to_base_heap;
  481. {$endif TEMPHEAP}
  482. CompilerComment:=false;
  483. {$ifndef DEV}
  484. if (status.verbosity and Level)=Level then
  485. {$endif}
  486. begin
  487. {$ifdef redircompiler}
  488. RedirDisableAll;
  489. {$endif}
  490. if not CompilerMessageWindow^.GetState(sfVisible) then
  491. CompilerMessageWindow^.Show;
  492. if Desktop^.First<>PView(CompilerMessageWindow) then
  493. CompilerMessageWindow^.MakeFirst;
  494. CompilerMessageWindow^.AddMessage(Level,S,status.currentsourcepath+status.currentsource,
  495. status.currentline,status.currentcolumn);
  496. { update info messages }
  497. if assigned(CompilerStatusDialog) then
  498. CompilerStatusDialog^.Update;
  499. {$ifdef DEBUG}
  500. {$ifndef NODEBUG}
  501. def_gdb_stop(level);
  502. {$endif}
  503. {$endif DEBUG}
  504. {$ifdef redircompiler}
  505. RedirEnableAll;
  506. {$endif}
  507. { update memory usage }
  508. { HeapView^.Update; }
  509. end;
  510. {$ifdef TEMPHEAP}
  511. switch_to_temp_heap;
  512. {$endif TEMPHEAP}
  513. end;
  514. {****************************************************************************
  515. DoCompile
  516. ****************************************************************************}
  517. function GetExePath: string;
  518. var Path: string;
  519. I: Sw_integer;
  520. begin
  521. Path:='.'+DirSep;
  522. if DirectorySwitches<>nil then
  523. with DirectorySwitches^ do
  524. for I:=0 to ItemCount-1 do
  525. begin
  526. if Pos('EXE',KillTilde(ItemName(I)))>0 then
  527. begin Path:=GetStringItem(I); Break; end;
  528. end;
  529. GetExePath:=CompleteDir(FExpand(Path));
  530. end;
  531. function GetMainFile: string;
  532. var FileName: string;
  533. P : PSourceWindow;
  534. begin
  535. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  536. if (PrimaryFileMain='') and (P=nil) then
  537. FileName:='' { nothing to compile }
  538. else
  539. begin
  540. if PrimaryFileMain<>'' then
  541. FileName:=PrimaryFileMain
  542. else
  543. begin
  544. if P^.Editor^.GetModified and (not P^.Editor^.Save) then
  545. FileName:='*' { file not saved }
  546. else
  547. FileName:=P^.Editor^.FileName;
  548. end;
  549. end;
  550. FileName:=FixFileName(FExpand(FileName));
  551. GetMainFile:=FileName;
  552. end;
  553. procedure DoCompile(Mode: TCompileMode);
  554. function IsExitEvent(E: TEvent): boolean;
  555. begin
  556. IsExitEvent:=(E.What=evKeyDown) and
  557. ((E.KeyCode=kbEnter) or (E.KeyCode=kbEsc)) or
  558. ((E.What=evCommand) and (E.command=cmClose));
  559. end;
  560. var
  561. s,FileName: string;
  562. ErrFile : Text;
  563. Error,LinkErrorCount : longint;
  564. E : TEvent;
  565. DummyView: PView;
  566. R: TRect;
  567. const
  568. PpasFile = 'ppas';
  569. begin
  570. { Get FileName }
  571. FileName:=GetMainFile;
  572. if FileName='' then
  573. begin
  574. ErrorBox(msg_nothingtocompile,nil);
  575. Exit;
  576. end else
  577. if FileName='*' then
  578. begin
  579. ErrorBox(msg_cantcompileunsavedfile,nil);
  580. Exit;
  581. end;
  582. { Show Compiler Messages Window }
  583. { if not CompilerMessageWindow^.GetState(sfVisible) then
  584. CompilerMessageWindow^.Show;
  585. CompilerMessageWindow^.MakeFirst;}
  586. CompilerMessageWindow^.ClearMessages;
  587. { Tell why we compile }
  588. NeedRecompile(true);
  589. MainFile:=FileName;
  590. WriteSwitches(SwitchesPath);
  591. { leaving open browsers leads to crashes !! (PM) }
  592. CloseAllBrowsers;
  593. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  594. WriteSymbolsFile(BrowserName);
  595. { MainFile:=FixFileName(FExpand(FileName));}
  596. If GetEXEPath<>'' then
  597. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+ExeExt)
  598. else
  599. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+ExeExt;
  600. { Reset }
  601. CtrlBreakHit:=false;
  602. { Create Compiler Status Dialog }
  603. CompilationPhase:=cpCompiling;
  604. New(CompilerStatusDialog, Init);
  605. CompilerStatusDialog^.SetState(sfModal,true);
  606. Application^.Insert(CompilerStatusDialog);
  607. CompilerStatusDialog^.Update;
  608. { hook compiler output }
  609. {$ifdef TP}
  610. do_status:=CompilerStatus;
  611. do_stop:=CompilerStop;
  612. do_comment:=CompilerComment;
  613. {$else not TP}
  614. do_status:=@CompilerStatus;
  615. do_stop:=@CompilerStop;
  616. do_comment:=@CompilerComment;
  617. {$endif TP}
  618. { Compile ! }
  619. {$ifdef redircompiler}
  620. ChangeRedirOut(FPOutFileName,false);
  621. ChangeRedirError(FPErrFileName,false);
  622. {$endif}
  623. {$ifdef TEMPHEAP}
  624. split_heap;
  625. switch_to_temp_heap;
  626. {$endif TEMPHEAP}
  627. { insert "" around name so that spaces are allowed }
  628. { only supported in compiler after 2000/01/14 PM }
  629. if pos(' ',FileName)>0 then
  630. FileName:='"'+FileName+'"';
  631. if mode=cBuild then
  632. FileName:='-B '+FileName;
  633. { tokens are created and distroed by compiler.compile !! PM }
  634. DoneTokens;
  635. FpIntF.Compile(FileName);
  636. { tokens are created and distroed by compiler.compile !! PM }
  637. InitTokens;
  638. if LinkAfter and IsExe and
  639. (CompilationPhase<>cpAborted) and
  640. (status.errorCount=0) then
  641. begin
  642. CompilationPhase:=cpLinking;
  643. CompilerStatusDialog^.Update;
  644. {$ifndef redircompiler}
  645. { At least here we want to catch output
  646. of batch file PM }
  647. ChangeRedirOut(FPOutFileName,false);
  648. ChangeRedirError(FPErrFileName,false);
  649. {$endif}
  650. {$ifdef linux}
  651. Shell(GetExePath+PpasFile+source_os.scriptext);
  652. Error:=LinuxError;
  653. {$else}
  654. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile+source_os.scriptext);
  655. Error:=DosError;
  656. {$endif}
  657. {$ifndef redircompiler}
  658. RestoreRedirOut;
  659. RestoreRedirError;
  660. {$endif}
  661. if Error<>0 then
  662. Inc(status.errorCount);
  663. if not ExistsFile(EXEFile) then
  664. begin
  665. Inc(status.errorCount);
  666. ClearFormatParams; AddFormatParamStr(ExeFile);
  667. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  668. Assign(ErrFile,FPErrFileName);
  669. Reset(ErrFile);
  670. LinkErrorCount:=0;
  671. While not eof(ErrFile) and (LinkErrorCount<25) do
  672. begin
  673. readln(ErrFile,s);
  674. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  675. inc(LinkErrorCount);
  676. end;
  677. if not eof(ErrFile) then
  678. begin
  679. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  680. CompilerMessageWindow^.AddMessage(V_error,
  681. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  682. end;
  683. Close(ErrFile);
  684. end;
  685. end;
  686. {$ifdef TEMPHEAP}
  687. switch_to_base_heap;
  688. {$endif TEMPHEAP}
  689. {$ifdef redircompiler}
  690. RestoreRedirOut;
  691. RestoreRedirError;
  692. {$endif}
  693. { Set end status }
  694. if CompilationPhase<>cpAborted then
  695. if (status.errorCount=0) then
  696. CompilationPhase:=cpDone
  697. else
  698. CompilationPhase:=cpFailed;
  699. { Show end status }
  700. CompilerStatusDialog^.Update;
  701. CompilerStatusDialog^.SetState(sfModal,false);
  702. if ((CompilationPhase in[cpAborted,cpDone,cpFailed]) or (ShowStatusOnError)) and (Mode<>cRun) then
  703. repeat
  704. CompilerStatusDialog^.GetEvent(E);
  705. if IsExitEvent(E)=false then
  706. CompilerStatusDialog^.HandleEvent(E);
  707. until IsExitEvent(E);
  708. Application^.Delete(CompilerStatusDialog);
  709. Dispose(CompilerStatusDialog, Done);
  710. CompilerStatusDialog:=nil;
  711. { end compilation returns true if the messagewindow should be removed }
  712. if CompilationPhase=cpDone then
  713. begin
  714. CompilerMessageWindow^.Hide;
  715. { This is the last compiled main file }
  716. PrevMainFile:=MainFile;
  717. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  718. end;
  719. { Update the app }
  720. Message(Application,evCommand,cmUpdate,nil);
  721. {$ifdef TEMPHEAP}
  722. releasetempheap;
  723. unsplit_heap;
  724. {$endif TEMPHEAP}
  725. DummyView:=Desktop^.First;
  726. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  727. begin
  728. DummyView:=DummyView^.NextView;
  729. end;
  730. with DummyView^ do
  731. if GetState(sfVisible) then
  732. begin
  733. SetState(sfSelected,false);
  734. SetState(sfSelected,true);
  735. end;
  736. if Assigned(CompilerMessageWindow) then
  737. with CompilerMessageWindow^ do
  738. begin
  739. if GetState(sfVisible) then
  740. begin
  741. SetState(sfSelected,false);
  742. SetState(sfSelected,true);
  743. end;
  744. if (status.errorCount>0) then
  745. MsgLB^.SelectFirstError;
  746. end;
  747. { ^^^ we need this trick to reactivate the desktop }
  748. EditorModified:=false;
  749. { Try to read Browser info in again if compilation failure !! }
  750. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  751. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  752. ReadSymbolsFile(BrowserName);
  753. end;
  754. function NeedRecompile(verbose : boolean): boolean;
  755. var Need: boolean;
  756. I: sw_integer;
  757. SF: PSourceFile;
  758. SourceTime,PPUTime,ObjTime: longint;
  759. begin
  760. if Assigned(SourceFiles)=false then
  761. Need:={(EditorModified=true)}true
  762. else
  763. begin
  764. Need:=(PrevMainFile<>GetMainFile) and (PrevMainFile<>'');
  765. if Need then
  766. begin
  767. if verbose then
  768. begin
  769. ClearFormatParams; AddFormatParamStr(GetMainFile);
  770. CompilerMessageWindow^.AddMessage(V_info,
  771. FormatStrF(msg_firstcompilationof,FormatParams),
  772. '',0,0);
  773. end;
  774. end
  775. else
  776. for I:=0 to SourceFiles^.Count-1 do
  777. begin
  778. SF:=SourceFiles^.At(I);
  779. SourceTime:=GetFileTime(SF^.GetSourceFileName);
  780. PPUTime:=GetFileTime(SF^.GetPPUFileName);
  781. ObjTime:=GetFileTime(SF^.GetObjFileName);
  782. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  783. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  784. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  785. writeln('------');}
  786. { some units don't generate object files }
  787. if (SourceTime<>-1) then
  788. if (SourceTime>PPUTime) or
  789. ((SourceTime>ObjTime) and
  790. (ObjTime<>-1)) then
  791. begin
  792. Need:=true;
  793. if verbose then
  794. begin
  795. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  796. CompilerMessageWindow^.AddMessage(V_info,
  797. FormatStrF(msg_recompilingbecauseof,FormatParams),
  798. SF^.GetSourceFileName,1,1);
  799. end;
  800. Break;
  801. end;
  802. end;
  803. { writeln('Need?', Need); system.readln;}
  804. end;
  805. NeedRecompile:=Need;
  806. end;
  807. procedure RegisterFPCompile;
  808. begin
  809. {$ifndef NOOBJREG}
  810. RegisterType(RCompilerMessageListBox);
  811. RegisterType(RCompilerMessageWindow);
  812. {$endif}
  813. end;
  814. end.
  815. {
  816. $Log$
  817. Revision 1.57 2000-05-02 08:42:27 pierre
  818. * new set of Gabor changes: see fixes.txt
  819. Revision 1.56 2000/04/25 08:42:32 pierre
  820. * New Gabor changes : see fixes.txt
  821. Revision 1.55 2000/04/18 11:42:36 pierre
  822. lot of Gabor changes : see fixes.txt
  823. Revision 1.54 2000/03/23 22:23:21 pierre
  824. + Use PushStatus in ParseUserScreen
  825. Revision 1.53 2000/03/21 23:33:18 pierre
  826. adapted to wcedit addition by Gabor
  827. Revision 1.52 2000/03/08 16:48:07 pierre
  828. + Read BackTrace from UseScreen
  829. Revision 1.51 2000/03/07 21:54:26 pierre
  830. + ParseUserScreen
  831. Revision 1.50 2000/02/06 23:41:42 pierre
  832. + TCompilerMessageListBox.SelectFirstError
  833. Revision 1.49 2000/01/25 00:26:35 pierre
  834. + Browser info saving
  835. Revision 1.48 2000/01/14 15:38:28 pierre
  836. + support for long filenames with spaces for compilation
  837. * avoid too long linker error output
  838. Revision 1.47 2000/01/03 11:38:33 michael
  839. Changes from Gabor
  840. Revision 1.46 1999/12/01 17:08:19 pierre
  841. * GetFileTime moved to wutils unit
  842. Revision 1.45 1999/11/22 15:58:40 pierre
  843. * fix for web bug 633
  844. Revision 1.44 1999/11/21 01:44:34 pierre
  845. + Use def_gdb_stop for easy GDB debugging
  846. Revision 1.43 1999/11/18 13:49:56 pierre
  847. + use IsExe var to know if we need to call ppas
  848. Revision 1.42 1999/11/10 17:20:41 pierre
  849. * Use fpredir.dosexecute
  850. Revision 1.41 1999/10/25 16:34:19 pierre
  851. * some units have no object files
  852. led to wrong NeedRecompile result
  853. Revision 1.40 1999/09/20 15:36:38 pierre
  854. * adapted to new tokens unit
  855. Revision 1.39 1999/09/16 14:34:57 pierre
  856. + TBreakpoint and TWatch registering
  857. + WatchesCollection and BreakpointsCollection stored in desk file
  858. * Syntax highlighting was broken
  859. Revision 1.38 1999/09/13 16:24:43 peter
  860. + clock
  861. * backspace unident like tp7
  862. Revision 1.37 1999/09/09 14:19:16 pierre
  863. * status should not be present in TCompilerMessage.GetText
  864. Revision 1.36 1999/09/07 11:32:13 pierre
  865. * fix for Linux ./ prepended to ppas.sh
  866. * Build add '-B' option
  867. * if linkAfter is set, get errors from linker
  868. by redirecting files
  869. Revision 1.35 1999/08/22 22:27:30 pierre
  870. * not ppas call on compile failure
  871. Revision 1.34 1999/08/16 18:25:13 peter
  872. * Adjusting the selection when the editor didn't contain any line.
  873. * Reserved word recognition redesigned, but this didn't affect the overall
  874. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  875. The syntax scanner loop is a bit slow but the main problem is the
  876. recognition of special symbols. Switching off symbol processing boosts
  877. the performance up to ca. 200%...
  878. * The editor didn't allow copying (for ex to clipboard) of a single character
  879. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  880. * Compiler Messages window (actually the whole desktop) did not act on any
  881. keypress when compilation failed and thus the window remained visible
  882. + Message windows are now closed upon pressing Esc
  883. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  884. only when neccessary
  885. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  886. + LineSelect (Ctrl+K+L) implemented
  887. * The IDE had problems closing help windows before saving the desktop
  888. Revision 1.33 1999/08/03 20:22:26 peter
  889. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  890. + Desktop saving should work now
  891. - History saved
  892. - Clipboard content saved
  893. - Desktop saved
  894. - Symbol info saved
  895. * syntax-highlight bug fixed, which compared special keywords case sensitive
  896. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  897. * with 'whole words only' set, the editor didn't found occourences of the
  898. searched text, if the text appeared previously in the same line, but didn't
  899. satisfied the 'whole-word' condition
  900. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  901. (ie. the beginning of the selection)
  902. * when started typing in a new line, but not at the start (X=0) of it,
  903. the editor inserted the text one character more to left as it should...
  904. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  905. * Shift shouldn't cause so much trouble in TCodeEditor now...
  906. * Syntax highlight had problems recognizing a special symbol if it was
  907. prefixed by another symbol character in the source text
  908. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  909. Revision 1.32 1999/07/12 13:14:13 pierre
  910. * LineEnd bug corrected, now goes end of text even if selected
  911. + Until Return for debugger
  912. + Code for Quit inside GDB Window
  913. Revision 1.31 1999/06/28 19:32:17 peter
  914. * fixes from gabor
  915. Revision 1.30 1999/06/28 15:59:04 pierre
  916. * View Linking stage if external linking
  917. Revision 1.29 1999/06/28 12:39:14 pierre
  918. + close all browsers before compiling
  919. Revision 1.28 1999/06/21 23:42:16 pierre
  920. + LinkAfter and Esc to abort support added
  921. Revision 1.27 1999/05/22 13:44:29 peter
  922. * fixed couple of bugs
  923. Revision 1.26 1999/05/02 14:29:35 peter
  924. * fixed typo disableredir -> redirdisable
  925. Revision 1.25 1999/04/29 22:58:09 pierre
  926. + disabling of redirction in compiler dialogs
  927. Revision 1.24 1999/04/29 09:36:11 peter
  928. * fixed hotkeys with Compiler switches
  929. * fixed compiler status dialog
  930. * Run shows again the output
  931. Revision 1.23 1999/04/07 21:55:43 peter
  932. + object support for browser
  933. * html help fixes
  934. * more desktop saving things
  935. * NODEBUG directive to exclude debugger
  936. Revision 1.22 1999/04/01 10:27:07 pierre
  937. + file(line) in start of message added
  938. Revision 1.21 1999/04/01 10:15:17 pierre
  939. * CurrSt,InfoSt and LineSt were not disposed correctly in done
  940. * TComiplerMessage destructor first calls SetCompileShow(false)
  941. to get proper cleaning up
  942. Revision 1.20 1999/03/23 16:16:38 peter
  943. * linux fixes
  944. Revision 1.19 1999/03/19 16:04:27 peter
  945. * new compiler dialog
  946. Revision 1.18 1999/03/16 12:38:07 peter
  947. * tools macro fixes
  948. + tph writer
  949. + first things for resource files
  950. Revision 1.17 1999/03/12 01:13:56 peter
  951. * flag if trytoopen should look for other extensions
  952. + browser tab in the tools-compiler
  953. Revision 1.16 1999/03/07 23:00:47 pierre
  954. * Fix for path of executable
  955. Revision 1.15 1999/03/01 15:41:50 peter
  956. + Added dummy entries for functions not yet implemented
  957. * MenuBar didn't update itself automatically on command-set changes
  958. * Fixed Debugging/Profiling options dialog
  959. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
  960. set
  961. * efBackSpaceUnindents works correctly
  962. + 'Messages' window implemented
  963. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  964. + Added TP message-filter support (for ex. you can call GREP thru
  965. GREP2MSG and view the result in the messages window - just like in TP)
  966. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  967. so topic search didn't work...
  968. * In FPHELP.PAS there were still context-variables defined as word instead
  969. of THelpCtx
  970. * StdStatusKeys() was missing from the statusdef for help windows
  971. + Topic-title for index-table can be specified when adding a HTML-files
  972. Revision 1.14 1999/02/22 12:46:56 peter
  973. * small fixes for linux and grep
  974. Revision 1.13 1999/02/22 11:51:33 peter
  975. * browser updates from gabor
  976. Revision 1.12 1999/02/22 11:29:36 pierre
  977. + added col info in MessageItem
  978. + grep uses HighLightExts and should work for linux
  979. Revision 1.11 1999/02/08 09:31:00 florian
  980. + some split heap stuff, in $ifdef TEMPHEAP
  981. Revision 1.10 1999/02/05 13:51:39 peter
  982. * unit name of FPSwitches -> FPSwitch which is easier to use
  983. * some fixes for tp7 compiling
  984. Revision 1.9 1999/02/05 13:06:28 pierre
  985. * allow cmClose for Compilation Dialog box
  986. Revision 1.8 1999/02/04 13:32:01 pierre
  987. * Several things added (I cannot commit them independently !)
  988. + added TBreakpoint and TBreakpointCollection
  989. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  990. + Breakpoint list in INIFile
  991. * Select items now also depend of SwitchMode
  992. * Reading of option '-g' was not possible !
  993. + added search for -Fu args pathes in TryToOpen
  994. + added code for automatic opening of FileDialog
  995. if source not found
  996. Revision 1.7 1999/01/21 11:54:11 peter
  997. + tools menu
  998. + speedsearch in symbolbrowser
  999. * working run command
  1000. Revision 1.6 1999/01/15 16:12:43 peter
  1001. * fixed crash after compile
  1002. Revision 1.5 1999/01/14 21:42:19 peter
  1003. * source tracking from Gabor
  1004. Revision 1.4 1999/01/12 14:29:32 peter
  1005. + Implemented still missing 'switch' entries in Options menu
  1006. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  1007. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  1008. ASCII chars and inserted directly in the text.
  1009. + Added symbol browser
  1010. * splitted fp.pas to fpide.pas
  1011. Revision 1.3 1999/01/04 11:49:42 peter
  1012. * 'Use tab characters' now works correctly
  1013. + Syntax highlight now acts on File|Save As...
  1014. + Added a new class to syntax highlight: 'hex numbers'.
  1015. * There was something very wrong with the palette managment. Now fixed.
  1016. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  1017. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  1018. process revised
  1019. Revision 1.2 1998/12/28 15:47:42 peter
  1020. + Added user screen support, display & window
  1021. + Implemented Editor,Mouse Options dialog
  1022. + Added location of .INI and .CFG file
  1023. + Option (INI) file managment implemented (see bottom of Options Menu)
  1024. + Switches updated
  1025. + Run program
  1026. Revision 1.3 1998/12/22 10:39:40 peter
  1027. + options are now written/read
  1028. + find and replace routines
  1029. }