fpcompil.pas 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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. 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,true));
  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. PushStatus('Beginning compilation...');
  583. { Show Compiler Messages Window }
  584. { if not CompilerMessageWindow^.GetState(sfVisible) then
  585. CompilerMessageWindow^.Show;
  586. CompilerMessageWindow^.MakeFirst;}
  587. CompilerMessageWindow^.ClearMessages;
  588. { Tell why we compile }
  589. NeedRecompile(true);
  590. MainFile:=FileName;
  591. SetStatus('Writing switches to file...');
  592. WriteSwitches(SwitchesPath);
  593. { leaving open browsers leads to crashes !! (PM) }
  594. SetStatus('Preparing symbol info...');
  595. CloseAllBrowsers;
  596. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  597. WriteSymbolsFile(BrowserName);
  598. { MainFile:=FixFileName(FExpand(FileName));}
  599. SetStatus('Preparing to compile...');
  600. If GetEXEPath<>'' then
  601. EXEFile:=FixFileName(GetEXEPath+NameOf(MainFile)+ExeExt)
  602. else
  603. EXEFile:=DirOf(MainFile)+NameOf(MainFile)+ExeExt;
  604. { Reset }
  605. CtrlBreakHit:=false;
  606. { Create Compiler Status Dialog }
  607. CompilationPhase:=cpCompiling;
  608. New(CompilerStatusDialog, Init);
  609. CompilerStatusDialog^.SetState(sfModal,true);
  610. Application^.Insert(CompilerStatusDialog);
  611. CompilerStatusDialog^.Update;
  612. { hook compiler output }
  613. {$ifdef TP}
  614. do_status:=CompilerStatus;
  615. do_stop:=CompilerStop;
  616. do_comment:=CompilerComment;
  617. {$else not TP}
  618. do_status:=@CompilerStatus;
  619. do_stop:=@CompilerStop;
  620. do_comment:=@CompilerComment;
  621. {$endif TP}
  622. do_initsymbolinfo:=InitBrowserCol;
  623. do_donesymbolinfo:=DoneBrowserCol;
  624. do_extractsymbolinfo:=CreateBrowserCol;
  625. { Compile ! }
  626. {$ifdef redircompiler}
  627. ChangeRedirOut(FPOutFileName,false);
  628. ChangeRedirError(FPErrFileName,false);
  629. {$endif}
  630. {$ifdef TEMPHEAP}
  631. split_heap;
  632. switch_to_temp_heap;
  633. {$endif TEMPHEAP}
  634. { insert "" around name so that spaces are allowed }
  635. { only supported in compiler after 2000/01/14 PM }
  636. if pos(' ',FileName)>0 then
  637. FileName:='"'+FileName+'"';
  638. if mode=cBuild then
  639. FileName:='-B '+FileName;
  640. { tokens are created and distroed by compiler.compile !! PM }
  641. DoneTokens;
  642. SetStatus('Compiling...');
  643. FpIntF.Compile(FileName,SwitchesPath);
  644. SetStatus('Finished compiling...');
  645. { tokens are created and distroed by compiler.compile !! PM }
  646. InitTokens;
  647. if LinkAfter and IsExe and
  648. (CompilationPhase<>cpAborted) and
  649. (status.errorCount=0) then
  650. begin
  651. CompilationPhase:=cpLinking;
  652. CompilerStatusDialog^.Update;
  653. SetStatus('Linking...');
  654. {$ifndef redircompiler}
  655. { At least here we want to catch output
  656. of batch file PM }
  657. ChangeRedirOut(FPOutFileName,false);
  658. ChangeRedirError(FPErrFileName,false);
  659. {$endif}
  660. {$ifdef linux}
  661. Shell(GetExePath+PpasFile+source_os.scriptext);
  662. Error:=LinuxError;
  663. {$else}
  664. DosExecute(GetEnv('COMSPEC'),'/C '+GetExePath+PpasFile+source_os.scriptext);
  665. Error:=DosError;
  666. {$endif}
  667. SetStatus('Finished linking...');
  668. {$ifndef redircompiler}
  669. RestoreRedirOut;
  670. RestoreRedirError;
  671. {$endif}
  672. if Error<>0 then
  673. Inc(status.errorCount);
  674. if not ExistsFile(EXEFile) then
  675. begin
  676. Inc(status.errorCount);
  677. ClearFormatParams; AddFormatParamStr(ExeFile);
  678. CompilerMessageWindow^.AddMessage(V_error,FormatStrF(msg_couldnotcreatefile,FormatParams),'',0,0);
  679. Assign(ErrFile,FPErrFileName);
  680. Reset(ErrFile);
  681. LinkErrorCount:=0;
  682. While not eof(ErrFile) and (LinkErrorCount<25) do
  683. begin
  684. readln(ErrFile,s);
  685. CompilerMessageWindow^.AddMessage(V_error,s,'',0,0);
  686. inc(LinkErrorCount);
  687. end;
  688. if not eof(ErrFile) then
  689. begin
  690. ClearFormatParams; AddFormatParamStr(FPErrFileName);
  691. CompilerMessageWindow^.AddMessage(V_error,
  692. FormatStrF(msg_therearemoreerrorsinfile,FormatParams),'',0,0);
  693. end;
  694. Close(ErrFile);
  695. end;
  696. end;
  697. {$ifdef TEMPHEAP}
  698. switch_to_base_heap;
  699. {$endif TEMPHEAP}
  700. {$ifdef redircompiler}
  701. RestoreRedirOut;
  702. RestoreRedirError;
  703. {$endif}
  704. PopStatus;
  705. { Set end status }
  706. if CompilationPhase<>cpAborted then
  707. if (status.errorCount=0) then
  708. CompilationPhase:=cpDone
  709. else
  710. CompilationPhase:=cpFailed;
  711. { Show end status }
  712. CompilerStatusDialog^.Update;
  713. CompilerStatusDialog^.SetState(sfModal,false);
  714. if ((CompilationPhase in[cpAborted,cpDone,cpFailed]) or (ShowStatusOnError)) and (Mode<>cRun) then
  715. repeat
  716. CompilerStatusDialog^.GetEvent(E);
  717. if IsExitEvent(E)=false then
  718. CompilerStatusDialog^.HandleEvent(E);
  719. until IsExitEvent(E);
  720. Application^.Delete(CompilerStatusDialog);
  721. Dispose(CompilerStatusDialog, Done);
  722. CompilerStatusDialog:=nil;
  723. { end compilation returns true if the messagewindow should be removed }
  724. if CompilationPhase=cpDone then
  725. begin
  726. CompilerMessageWindow^.Hide;
  727. { This is the last compiled main file }
  728. PrevMainFile:=MainFile;
  729. MainHasDebugInfo:=DebugInfoSwitches^.GetCurrSelParam<>'-';
  730. end;
  731. { Update the app }
  732. Message(Application,evCommand,cmUpdate,nil);
  733. {$ifdef TEMPHEAP}
  734. releasetempheap;
  735. unsplit_heap;
  736. {$endif TEMPHEAP}
  737. DummyView:=Desktop^.First;
  738. while (DummyView<>nil) and (DummyView^.GetState(sfVisible)=false) do
  739. begin
  740. DummyView:=DummyView^.NextView;
  741. end;
  742. with DummyView^ do
  743. if GetState(sfVisible) then
  744. begin
  745. SetState(sfSelected,false);
  746. SetState(sfSelected,true);
  747. end;
  748. if Assigned(CompilerMessageWindow) then
  749. with CompilerMessageWindow^ do
  750. begin
  751. if GetState(sfVisible) then
  752. begin
  753. SetState(sfSelected,false);
  754. SetState(sfSelected,true);
  755. end;
  756. if (status.errorCount>0) then
  757. MsgLB^.SelectFirstError;
  758. end;
  759. { ^^^ we need this trick to reactivate the desktop }
  760. EditorModified:=false;
  761. { Try to read Browser info in again if compilation failure !! }
  762. if Not Assigned(Modules) and (CompilationPhase<>cpDone) and
  763. ((DesktopFileFlags and dfSymbolInformation)<>0) then
  764. ReadSymbolsFile(BrowserName);
  765. end;
  766. function NeedRecompile(verbose : boolean): boolean;
  767. var Need: boolean;
  768. I: sw_integer;
  769. SF: PSourceFile;
  770. SourceTime,PPUTime,ObjTime: longint;
  771. begin
  772. if Assigned(SourceFiles)=false then
  773. Need:={(EditorModified=true)}true
  774. else
  775. begin
  776. Need:=(PrevMainFile<>GetMainFile) and (PrevMainFile<>'');
  777. if Need then
  778. begin
  779. if verbose then
  780. begin
  781. ClearFormatParams; AddFormatParamStr(GetMainFile);
  782. CompilerMessageWindow^.AddMessage(V_info,
  783. FormatStrF(msg_firstcompilationof,FormatParams),
  784. '',0,0);
  785. end;
  786. end
  787. else
  788. for I:=0 to SourceFiles^.Count-1 do
  789. begin
  790. SF:=SourceFiles^.At(I);
  791. SourceTime:=GetFileTime(SF^.GetSourceFileName);
  792. PPUTime:=GetFileTime(SF^.GetPPUFileName);
  793. ObjTime:=GetFileTime(SF^.GetObjFileName);
  794. { writeln('S: ',SF^.GetSourceFileName,' - ',SourceTime);
  795. writeln('P: ',SF^.GetPPUFileName,' - ',PPUTime);
  796. writeln('O: ',SF^.GetObjFileName,' - ',ObjTime);
  797. writeln('------');}
  798. { some units don't generate object files }
  799. if (SourceTime<>-1) then
  800. if (SourceTime>PPUTime) or
  801. ((SourceTime>ObjTime) and
  802. (ObjTime<>-1)) then
  803. begin
  804. Need:=true;
  805. if verbose then
  806. begin
  807. ClearFormatParams; AddFormatParamStr(SF^.GetSourceFileName);
  808. CompilerMessageWindow^.AddMessage(V_info,
  809. FormatStrF(msg_recompilingbecauseof,FormatParams),
  810. SF^.GetSourceFileName,1,1);
  811. end;
  812. Break;
  813. end;
  814. end;
  815. { writeln('Need?', Need); system.readln;}
  816. end;
  817. NeedRecompile:=Need;
  818. end;
  819. procedure RegisterFPCompile;
  820. begin
  821. {$ifndef NOOBJREG}
  822. RegisterType(RCompilerMessageListBox);
  823. RegisterType(RCompilerMessageWindow);
  824. {$endif}
  825. end;
  826. end.
  827. {
  828. $Log$
  829. Revision 1.59 2000-06-16 08:50:40 pierre
  830. + new bunch of Gabor's changes
  831. Revision 1.58 2000/05/29 10:44:56 pierre
  832. + New bunch of Gabor's changes: see fixes.txt
  833. Revision 1.57 2000/05/02 08:42:27 pierre
  834. * new set of Gabor changes: see fixes.txt
  835. Revision 1.56 2000/04/25 08:42:32 pierre
  836. * New Gabor changes : see fixes.txt
  837. Revision 1.55 2000/04/18 11:42:36 pierre
  838. lot of Gabor changes : see fixes.txt
  839. Revision 1.54 2000/03/23 22:23:21 pierre
  840. + Use PushStatus in ParseUserScreen
  841. Revision 1.53 2000/03/21 23:33:18 pierre
  842. adapted to wcedit addition by Gabor
  843. Revision 1.52 2000/03/08 16:48:07 pierre
  844. + Read BackTrace from UseScreen
  845. Revision 1.51 2000/03/07 21:54:26 pierre
  846. + ParseUserScreen
  847. Revision 1.50 2000/02/06 23:41:42 pierre
  848. + TCompilerMessageListBox.SelectFirstError
  849. Revision 1.49 2000/01/25 00:26:35 pierre
  850. + Browser info saving
  851. Revision 1.48 2000/01/14 15:38:28 pierre
  852. + support for long filenames with spaces for compilation
  853. * avoid too long linker error output
  854. Revision 1.47 2000/01/03 11:38:33 michael
  855. Changes from Gabor
  856. Revision 1.46 1999/12/01 17:08:19 pierre
  857. * GetFileTime moved to wutils unit
  858. Revision 1.45 1999/11/22 15:58:40 pierre
  859. * fix for web bug 633
  860. Revision 1.44 1999/11/21 01:44:34 pierre
  861. + Use def_gdb_stop for easy GDB debugging
  862. Revision 1.43 1999/11/18 13:49:56 pierre
  863. + use IsExe var to know if we need to call ppas
  864. Revision 1.42 1999/11/10 17:20:41 pierre
  865. * Use fpredir.dosexecute
  866. Revision 1.41 1999/10/25 16:34:19 pierre
  867. * some units have no object files
  868. led to wrong NeedRecompile result
  869. Revision 1.40 1999/09/20 15:36:38 pierre
  870. * adapted to new tokens unit
  871. Revision 1.39 1999/09/16 14:34:57 pierre
  872. + TBreakpoint and TWatch registering
  873. + WatchesCollection and BreakpointsCollection stored in desk file
  874. * Syntax highlighting was broken
  875. Revision 1.38 1999/09/13 16:24:43 peter
  876. + clock
  877. * backspace unident like tp7
  878. Revision 1.37 1999/09/09 14:19:16 pierre
  879. * status should not be present in TCompilerMessage.GetText
  880. Revision 1.36 1999/09/07 11:32:13 pierre
  881. * fix for Linux ./ prepended to ppas.sh
  882. * Build add '-B' option
  883. * if linkAfter is set, get errors from linker
  884. by redirecting files
  885. Revision 1.35 1999/08/22 22:27:30 pierre
  886. * not ppas call on compile failure
  887. Revision 1.34 1999/08/16 18:25:13 peter
  888. * Adjusting the selection when the editor didn't contain any line.
  889. * Reserved word recognition redesigned, but this didn't affect the overall
  890. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  891. The syntax scanner loop is a bit slow but the main problem is the
  892. recognition of special symbols. Switching off symbol processing boosts
  893. the performance up to ca. 200%...
  894. * The editor didn't allow copying (for ex to clipboard) of a single character
  895. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  896. * Compiler Messages window (actually the whole desktop) did not act on any
  897. keypress when compilation failed and thus the window remained visible
  898. + Message windows are now closed upon pressing Esc
  899. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  900. only when neccessary
  901. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  902. + LineSelect (Ctrl+K+L) implemented
  903. * The IDE had problems closing help windows before saving the desktop
  904. Revision 1.33 1999/08/03 20:22:26 peter
  905. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  906. + Desktop saving should work now
  907. - History saved
  908. - Clipboard content saved
  909. - Desktop saved
  910. - Symbol info saved
  911. * syntax-highlight bug fixed, which compared special keywords case sensitive
  912. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  913. * with 'whole words only' set, the editor didn't found occourences of the
  914. searched text, if the text appeared previously in the same line, but didn't
  915. satisfied the 'whole-word' condition
  916. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  917. (ie. the beginning of the selection)
  918. * when started typing in a new line, but not at the start (X=0) of it,
  919. the editor inserted the text one character more to left as it should...
  920. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  921. * Shift shouldn't cause so much trouble in TCodeEditor now...
  922. * Syntax highlight had problems recognizing a special symbol if it was
  923. prefixed by another symbol character in the source text
  924. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  925. Revision 1.32 1999/07/12 13:14:13 pierre
  926. * LineEnd bug corrected, now goes end of text even if selected
  927. + Until Return for debugger
  928. + Code for Quit inside GDB Window
  929. Revision 1.31 1999/06/28 19:32:17 peter
  930. * fixes from gabor
  931. Revision 1.30 1999/06/28 15:59:04 pierre
  932. * View Linking stage if external linking
  933. Revision 1.29 1999/06/28 12:39:14 pierre
  934. + close all browsers before compiling
  935. Revision 1.28 1999/06/21 23:42:16 pierre
  936. + LinkAfter and Esc to abort support added
  937. Revision 1.27 1999/05/22 13:44:29 peter
  938. * fixed couple of bugs
  939. Revision 1.26 1999/05/02 14:29:35 peter
  940. * fixed typo disableredir -> redirdisable
  941. Revision 1.25 1999/04/29 22:58:09 pierre
  942. + disabling of redirction in compiler dialogs
  943. Revision 1.24 1999/04/29 09:36:11 peter
  944. * fixed hotkeys with Compiler switches
  945. * fixed compiler status dialog
  946. * Run shows again the output
  947. Revision 1.23 1999/04/07 21:55:43 peter
  948. + object support for browser
  949. * html help fixes
  950. * more desktop saving things
  951. * NODEBUG directive to exclude debugger
  952. Revision 1.22 1999/04/01 10:27:07 pierre
  953. + file(line) in start of message added
  954. Revision 1.21 1999/04/01 10:15:17 pierre
  955. * CurrSt,InfoSt and LineSt were not disposed correctly in done
  956. * TComiplerMessage destructor first calls SetCompileShow(false)
  957. to get proper cleaning up
  958. Revision 1.20 1999/03/23 16:16:38 peter
  959. * linux fixes
  960. Revision 1.19 1999/03/19 16:04:27 peter
  961. * new compiler dialog
  962. Revision 1.18 1999/03/16 12:38:07 peter
  963. * tools macro fixes
  964. + tph writer
  965. + first things for resource files
  966. Revision 1.17 1999/03/12 01:13:56 peter
  967. * flag if trytoopen should look for other extensions
  968. + browser tab in the tools-compiler
  969. Revision 1.16 1999/03/07 23:00:47 pierre
  970. * Fix for path of executable
  971. Revision 1.15 1999/03/01 15:41:50 peter
  972. + Added dummy entries for functions not yet implemented
  973. * MenuBar didn't update itself automatically on command-set changes
  974. * Fixed Debugging/Profiling options dialog
  975. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
  976. set
  977. * efBackSpaceUnindents works correctly
  978. + 'Messages' window implemented
  979. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  980. + Added TP message-filter support (for ex. you can call GREP thru
  981. GREP2MSG and view the result in the messages window - just like in TP)
  982. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  983. so topic search didn't work...
  984. * In FPHELP.PAS there were still context-variables defined as word instead
  985. of THelpCtx
  986. * StdStatusKeys() was missing from the statusdef for help windows
  987. + Topic-title for index-table can be specified when adding a HTML-files
  988. Revision 1.14 1999/02/22 12:46:56 peter
  989. * small fixes for linux and grep
  990. Revision 1.13 1999/02/22 11:51:33 peter
  991. * browser updates from gabor
  992. Revision 1.12 1999/02/22 11:29:36 pierre
  993. + added col info in MessageItem
  994. + grep uses HighLightExts and should work for linux
  995. Revision 1.11 1999/02/08 09:31:00 florian
  996. + some split heap stuff, in $ifdef TEMPHEAP
  997. Revision 1.10 1999/02/05 13:51:39 peter
  998. * unit name of FPSwitches -> FPSwitch which is easier to use
  999. * some fixes for tp7 compiling
  1000. Revision 1.9 1999/02/05 13:06:28 pierre
  1001. * allow cmClose for Compilation Dialog box
  1002. Revision 1.8 1999/02/04 13:32:01 pierre
  1003. * Several things added (I cannot commit them independently !)
  1004. + added TBreakpoint and TBreakpointCollection
  1005. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  1006. + Breakpoint list in INIFile
  1007. * Select items now also depend of SwitchMode
  1008. * Reading of option '-g' was not possible !
  1009. + added search for -Fu args pathes in TryToOpen
  1010. + added code for automatic opening of FileDialog
  1011. if source not found
  1012. Revision 1.7 1999/01/21 11:54:11 peter
  1013. + tools menu
  1014. + speedsearch in symbolbrowser
  1015. * working run command
  1016. Revision 1.6 1999/01/15 16:12:43 peter
  1017. * fixed crash after compile
  1018. Revision 1.5 1999/01/14 21:42:19 peter
  1019. * source tracking from Gabor
  1020. Revision 1.4 1999/01/12 14:29:32 peter
  1021. + Implemented still missing 'switch' entries in Options menu
  1022. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  1023. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  1024. ASCII chars and inserted directly in the text.
  1025. + Added symbol browser
  1026. * splitted fp.pas to fpide.pas
  1027. Revision 1.3 1999/01/04 11:49:42 peter
  1028. * 'Use tab characters' now works correctly
  1029. + Syntax highlight now acts on File|Save As...
  1030. + Added a new class to syntax highlight: 'hex numbers'.
  1031. * There was something very wrong with the palette managment. Now fixed.
  1032. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  1033. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  1034. process revised
  1035. Revision 1.2 1998/12/28 15:47:42 peter
  1036. + Added user screen support, display & window
  1037. + Implemented Editor,Mouse Options dialog
  1038. + Added location of .INI and .CFG file
  1039. + Option (INI) file managment implemented (see bottom of Options Menu)
  1040. + Switches updated
  1041. + Run program
  1042. Revision 1.3 1998/12/22 10:39:40 peter
  1043. + options are now written/read
  1044. + find and replace routines
  1045. }