files.pas 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. {
  2. $Id$
  3. Copyright (c) 1996-98 by Florian Klaempfl
  4. This unit implements an extended file management and the first loading
  5. and searching of the modules (ppufiles)
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit files;
  20. interface
  21. uses
  22. cobjects,globals
  23. {$ifdef NEWPPU}
  24. ,ppu
  25. {$endif}
  26. ;
  27. const
  28. {$ifdef FPC}
  29. maxunits = 1024;
  30. extbufsize = 65535;
  31. {$else}
  32. maxunits = 128;
  33. extbufsize = 2000;
  34. {$endif}
  35. type
  36. { this isn't a text file, this is t-ext-file }
  37. { which means a extended file this files can }
  38. { be handled by a file manager }
  39. pextfile = ^textfile;
  40. textfile = object(tbufferedfile)
  41. path,name,ext : pstring;
  42. _next : pextfile; { else conflicts with tinputstack }
  43. ref_index : word; { 65000 input files for a unit should be enough !! }
  44. { p must be the complete path (with ending \ (or / for unix ...) }
  45. constructor init(const p,n,e : string);
  46. destructor done;virtual;
  47. end;
  48. pinputfile = ^tinputfile;
  49. tinputfile = object(textfile)
  50. filenotatend : boolean;
  51. line_no : longint;
  52. line_count : longint; { second counter for unimportant tokens }
  53. next : pinputfile; { next input file in the stack of input files }
  54. ref_count : longint; { to handle the browser refs }
  55. constructor init(const p,n,e : string);
  56. procedure write_file_line(var t : text); { writes the file name and line number to t }
  57. function get_file_line : string;
  58. end;
  59. pfilemanager = ^tfilemanager;
  60. tfilemanager = object
  61. files : pextfile;
  62. last_ref_index : word;
  63. constructor init;
  64. destructor done;
  65. procedure close_all;
  66. procedure register_file(f : pextfile);
  67. function get_file(w : word) : pextfile;
  68. end;
  69. type
  70. tunitmap = array[0..maxunits-1] of pointer;
  71. punitmap = ^tunitmap;
  72. pmodule = ^tmodule;
  73. tmodule = object(tlinkedlist_item)
  74. {$ifdef NEWPPU}
  75. ppufile : pppufile; { the PPU file }
  76. {$else}
  77. ppufile : pextfile; { the PPU file }
  78. {$endif}
  79. crc,
  80. flags : longint; { the PPU flags }
  81. compiled, { unit is already compiled }
  82. do_assemble, { only assemble the object, don't recompile }
  83. do_compile, { need to compile the sources }
  84. sources_avail, { if all sources are reachable }
  85. is_unit,
  86. in_implementation, { processing the implementation part? }
  87. in_main : boolean; { global, after uses else false }
  88. map : punitmap; { mapping of all used units }
  89. unitcount : word; { local unit counter }
  90. unit_index : word; { global counter for browser }
  91. symtable : pointer; { pointer to the psymtable of this unit }
  92. output_format : tof; { how to write this file }
  93. uses_imports : boolean; { Set if the module imports from DLL's.}
  94. imports : plinkedlist;
  95. sourcefiles : tfilemanager;
  96. linksharedlibs,
  97. linkstaticlibs,
  98. linkofiles : tstringcontainer;
  99. used_units : tlinkedlist;
  100. current_inputfile : pinputfile;
  101. { used in firstpass for faster settings }
  102. current_index : word;
  103. unitname, { name of the (unit) module in uppercase }
  104. objfilename, { fullname of the objectfile }
  105. asmfilename, { fullname of the assemblerfile }
  106. ppufilename, { fullname of the ppufile }
  107. arfilename, { fullname of the archivefile }
  108. mainsource : pstring; { name of the main sourcefile }
  109. constructor init(const s:string;_is_unit:boolean);
  110. destructor special_done;virtual; { this is to be called only when compiling again }
  111. procedure setfilename(const path,name:string);
  112. {$ifdef NEWPPU}
  113. function openppu(const unit_path:string):boolean;
  114. {$else}
  115. function load_ppu(const unit_path,n,ext:string):boolean;
  116. {$endif}
  117. procedure search_unit(const n : string);
  118. end;
  119. pused_unit = ^tused_unit;
  120. tused_unit = object(tlinkedlist_item)
  121. u : pmodule;
  122. in_uses,
  123. in_interface,
  124. is_stab_written : boolean;
  125. unitid : word;
  126. constructor init(_u : pmodule;f : byte);
  127. destructor done;virtual;
  128. end;
  129. {$ifndef NEWPPU}
  130. type
  131. tunitheader = array[0..19] of char;
  132. const
  133. { compiler version }
  134. { format | }
  135. { signature | | }
  136. { | | | }
  137. { /-------\ /-------\ /----\ }
  138. unitheader : tunitheader = ('P','P','U','0','1','4',#0,#99,
  139. #0,#0,#0,#0,#0,#0,#255,#255,
  140. { | | \---------/ \-------/ }
  141. { | | | | }
  142. { | | check sum | }
  143. { | \--flags unused }
  144. { target system }
  145. #0,#0,#0,#0);
  146. {\---------/ }
  147. { | }
  148. { start of machine language }
  149. ibloadunit = 1;
  150. iborddef = 2;
  151. ibpointerdef = 3;
  152. ibtypesym = 4;
  153. ibarraydef = 5;
  154. ibprocdef = 6;
  155. ibprocsym = 7;
  156. iblinkofile = 8;
  157. ibstringdef = 9;
  158. ibvarsym = 10;
  159. ibconstsym = 11;
  160. ibinitunit = 12;
  161. ibenumsym = 13;
  162. ibtypedconstsym = 14;
  163. ibrecorddef = 15;
  164. ibfiledef = 16;
  165. ibformaldef = 17;
  166. ibobjectdef = 18;
  167. ibenumdef = 19;
  168. ibsetdef = 20;
  169. ibprocvardef = 21;
  170. ibsourcefile = 22;
  171. ibdbxcount = 23;
  172. ibfloatdef = 24;
  173. ibref = 25;
  174. ibextsymref = 26;
  175. ibextdefref = 27;
  176. ibabsolutesym = 28;
  177. ibclassrefdef = 29;
  178. ibpropertysym = 30;
  179. ibsharedlibs = 31;
  180. iblongstringdef = 32;
  181. ibansistringdef = 33;
  182. ibunitname = 34;
  183. ibwidestringdef = 35;
  184. ibstaticlibs = 36;
  185. ibend = 255;
  186. { unit flags }
  187. uf_init = $1;
  188. uf_uses_dbx = $2;
  189. uf_uses_browser = $4;
  190. uf_in_library = $8;
  191. uf_shared_library = $10;
  192. uf_big_endian = $20;
  193. uf_smartlink = $40;
  194. {$endif}
  195. var
  196. main_module : pmodule;
  197. current_module : pmodule;
  198. global_unit_count : word;
  199. loaded_units : tlinkedlist;
  200. implementation
  201. uses
  202. dos,verbose,systems;
  203. {****************************************************************************
  204. TFILE
  205. ****************************************************************************}
  206. constructor textfile.init(const p,n,e : string);
  207. begin
  208. inherited init(p+n+e,extbufsize);
  209. path:=stringdup(p);
  210. name:=stringdup(n);
  211. ext:=stringdup(e);
  212. end;
  213. destructor textfile.done;
  214. begin
  215. inherited done;
  216. end;
  217. {****************************************************************************
  218. TINPUTFILE
  219. ****************************************************************************}
  220. constructor tinputfile.init(const p,n,e : string);
  221. begin
  222. inherited init(p,n,e);
  223. filenotatend:=true;
  224. line_no:=1;
  225. line_count:=0;
  226. next:=nil;
  227. end;
  228. procedure tinputfile.write_file_line(var t : text);
  229. begin
  230. write(t,get_file_line);
  231. end;
  232. function tinputfile.get_file_line : string;
  233. begin
  234. if Use_Rhide then
  235. get_file_line:=lowercase(bstoslash(path^)+name^+ext^)+':'+tostr(line_no)+':'
  236. else
  237. get_file_line:=name^+ext^+'('+tostr(line_no)+')'
  238. end;
  239. {****************************************************************************
  240. TFILEMANAGER
  241. ****************************************************************************}
  242. constructor tfilemanager.init;
  243. begin
  244. files:=nil;
  245. last_ref_index:=0;
  246. end;
  247. destructor tfilemanager.done;
  248. var
  249. hp : pextfile;
  250. begin
  251. hp:=files;
  252. while assigned(hp) do
  253. begin
  254. files:=files^._next;
  255. dispose(hp,done);
  256. hp:=files;
  257. end;
  258. last_ref_index:=0;
  259. end;
  260. procedure tfilemanager.close_all;
  261. var
  262. hp : pextfile;
  263. begin
  264. hp:=files;
  265. while assigned(hp) do
  266. begin
  267. hp^.close;
  268. hp:=hp^._next;
  269. end;
  270. end;
  271. procedure tfilemanager.register_file(f : pextfile);
  272. begin
  273. inc(last_ref_index);
  274. f^._next:=files;
  275. f^.ref_index:=last_ref_index;
  276. files:=f;
  277. end;
  278. function tfilemanager.get_file(w : word) : pextfile;
  279. var
  280. ff : pextfile;
  281. begin
  282. ff:=files;
  283. while assigned(ff) and (ff^.ref_index<>w) do
  284. ff:=ff^._next;
  285. get_file:=ff;
  286. end;
  287. {****************************************************************************
  288. TMODULE
  289. ****************************************************************************}
  290. procedure tmodule.setfilename(const path,name:string);
  291. var
  292. s : string;
  293. begin
  294. stringdispose(objfilename);
  295. stringdispose(asmfilename);
  296. stringdispose(ppufilename);
  297. stringdispose(arfilename);
  298. s:=FixFileName(FixPath(path)+name);
  299. objfilename:=stringdup(s+target_info.objext);
  300. asmfilename:=stringdup(s+target_info.asmext);
  301. ppufilename:=stringdup(s+target_info.unitext);
  302. arfilename:=stringdup(s+target_os.staticlibext);
  303. end;
  304. {$ifdef NEWPPU}
  305. function tmodule.openppu(const unit_path:string):boolean;
  306. var
  307. temp,hs : string;
  308. b : byte;
  309. incfile_found : boolean;
  310. objfiletime,
  311. ppufiletime,
  312. asmfiletime,
  313. source_time : longint;
  314. {$ifdef UseBrowser}
  315. hp : pextfile;
  316. _d : dirstr;
  317. _n : namestr;
  318. _e : extstr;
  319. {$endif UseBrowser}
  320. begin
  321. openppu:=false;
  322. { Get ppufile time (also check if the file exists) }
  323. ppufiletime:=getnamedfiletime(ppufilename^);
  324. if ppufiletime=-1 then
  325. exit;
  326. Message1(unit_u_ppu_loading,ppufilename^);
  327. ppufile:=new(pppufile,init(ppufilename^));
  328. if not ppufile^.open then
  329. begin
  330. dispose(ppufile,done);
  331. Message(unit_d_ppu_file_too_short);
  332. exit;
  333. end;
  334. { check for a valid PPU file }
  335. if not ppufile^.CheckPPUId then
  336. begin
  337. dispose(ppufile,done);
  338. Message(unit_d_ppu_invalid_header);
  339. exit;
  340. end;
  341. { check for allowed PPU versions }
  342. if not (ppufile^.GetPPUVersion in [15]) then
  343. begin
  344. dispose(ppufile,done);
  345. Message1(unit_d_ppu_invalid_version,tostr(ppufile^.GetPPUVersion));
  346. exit;
  347. end;
  348. flags:=ppufile^.header.flags;
  349. { Show Debug info }
  350. Message1(unit_d_ppu_time,filetimestring(ppufiletime));
  351. Message1(unit_d_ppu_flags,tostr(flags));
  352. Message1(unit_d_ppu_crc,tostr(ppufile^.header.checksum));
  353. { Unitname }
  354. b:=ppufile^.readentry;
  355. if b=ibunitname then
  356. begin
  357. stringdispose(unitname);
  358. unitname:=stringdup(ppufile^.getstring);
  359. b:=ppufile^.readentry;
  360. end;
  361. { search source files there is at least one source file }
  362. do_compile:=false;
  363. sources_avail:=true;
  364. if b=ibsourcefile then
  365. begin
  366. while not ppufile^.endofentry do
  367. begin
  368. hs:=ppufile^.getstring;
  369. if (flags and uf_in_library)<>0 then
  370. begin
  371. sources_avail:=false;
  372. temp:=' library';
  373. end
  374. else if pos('Macro ',hs)=1 then
  375. begin
  376. { we don't want to find this file }
  377. { but there is a problem with file indexing !! }
  378. temp:='';
  379. end
  380. else
  381. begin
  382. { check the date of the source files }
  383. Source_Time:=GetNamedFileTime(unit_path+hs);
  384. if Source_Time=-1 then
  385. begin
  386. { search for include files in the includepathlist }
  387. if b<>ibend then
  388. temp:=search(hs,includesearchpath,incfile_found);
  389. if incfile_found then
  390. begin
  391. hs:=temp+hs;
  392. Source_Time:=GetNamedFileTime(hs);
  393. end;
  394. end
  395. else
  396. hs:=unit_path+hs;
  397. if Source_Time=-1 then
  398. begin
  399. sources_avail:=false;
  400. temp:=' not found';
  401. end
  402. else
  403. begin
  404. temp:=' time '+filetimestring(source_time);
  405. if (source_time>ppufiletime) then
  406. begin
  407. do_compile:=true;
  408. temp:=temp+' *'
  409. end;
  410. end;
  411. end;
  412. Message1(unit_t_ppu_source,hs+temp);
  413. {$ifdef UseBrowser}
  414. fsplit(hs,_d,_n,_e);
  415. new(hp,init(_d,_n,_e));
  416. { the indexing should match what is done in writeasunit }
  417. sourcefiles.register_file(hp);
  418. {$endif UseBrowser}
  419. end;
  420. end;
  421. { main source is always the last }
  422. stringdispose(mainsource);
  423. mainsource:=stringdup(hs);
  424. { check the object and assembler file if not a library }
  425. if (flags and uf_in_library)=0 then
  426. begin
  427. if (flags and uf_smartlink)<>0 then
  428. begin
  429. objfiletime:=getnamedfiletime(arfilename^);
  430. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  431. do_compile:=true;
  432. end
  433. else
  434. begin
  435. { the objectfile should be newer than the ppu file }
  436. objfiletime:=getnamedfiletime(objfilename^);
  437. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  438. begin
  439. { check if assembler file is older than ppu file }
  440. asmfileTime:=GetNamedFileTime(asmfilename^);
  441. if (asmfiletime<0) or (ppufiletime>asmfiletime) then
  442. begin
  443. Message(unit_d_obj_and_asm_are_older_than_ppu);
  444. do_compile:=true;
  445. end
  446. else
  447. begin
  448. Message(unit_d_obj_is_older_than_asm);
  449. do_assemble:=true;
  450. end;
  451. end;
  452. end;
  453. end;
  454. openppu:=true;
  455. end;
  456. procedure tmodule.search_unit(const n : string);
  457. var
  458. ext : string[8];
  459. singlepathstring,
  460. Path,
  461. filename : string;
  462. found : boolean;
  463. start,i : longint;
  464. Function UnitExists(const ext:string):boolean;
  465. begin
  466. Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
  467. UnitExists:=FileExists(Singlepathstring+FileName+ext);
  468. end;
  469. begin
  470. start:=1;
  471. filename:=FixFileName(n);
  472. path:=UnitSearchPath;
  473. Found:=false;
  474. repeat
  475. { Create current path to check }
  476. i:=pos(';',path);
  477. if i=0 then
  478. i:=length(path)+1;
  479. singlepathstring:=FixPath(copy(path,start,i-start));
  480. delete(path,start,i-start+1);
  481. { Check for PPL file }
  482. if not (cs_link_static in aktswitches) then
  483. begin
  484. Found:=UnitExists(target_info.unitlibext);
  485. if Found then
  486. Begin
  487. SetFileName(SinglePathString,FileName);
  488. Found:=OpenPPU(singlepathstring);
  489. End;
  490. end;
  491. { Check for PPU file }
  492. if not (cs_link_dynamic in aktswitches) and not Found then
  493. begin
  494. Found:=UnitExists(target_info.unitext);
  495. if Found then
  496. Begin
  497. SetFileName(SinglePathString,FileName);
  498. Found:=OpenPPU(singlepathstring);
  499. End;
  500. end;
  501. { Check for Sources }
  502. if not Found then
  503. begin
  504. ppufile:=nil;
  505. do_compile:=true;
  506. {Check for .pp file}
  507. Found:=UnitExists(target_os.sourceext);
  508. if Found then
  509. Ext:=target_os.sourceext
  510. else
  511. begin
  512. {Check for .pas}
  513. Found:=UnitExists(target_os.pasext);
  514. if Found then
  515. Ext:=target_os.pasext;
  516. end;
  517. stringdispose(mainsource);
  518. if Found then
  519. begin
  520. sources_avail:=true;
  521. {Load Filenames when found}
  522. mainsource:=StringDup(SinglePathString+FileName+Ext);
  523. SetFileName(SinglePathString,FileName);
  524. end
  525. else
  526. sources_avail:=false;
  527. end;
  528. until Found or (path='');
  529. end;
  530. {$else NEWPPU}
  531. function tmodule.load_ppu(const unit_path,n,ext : string):boolean;
  532. var
  533. header : tunitheader;
  534. count : longint;
  535. temp,hs : string;
  536. b : byte;
  537. incfile_found : boolean;
  538. code : word;
  539. ppuversion,
  540. objfiletime,
  541. ppufiletime,
  542. asmfiletime,
  543. source_time : longint;
  544. {$ifdef UseBrowser}
  545. hp : pextfile;
  546. _d : dirstr;
  547. _n : namestr;
  548. _e : extstr;
  549. {$endif UseBrowser}
  550. begin
  551. load_ppu:=false;
  552. { Get ppufile time (also check if the file exists) }
  553. ppufiletime:=getnamedfiletime(ppufilename^);
  554. if ppufiletime=-1 then
  555. exit;
  556. Message1(unit_u_ppu_loading,ppufilename^);
  557. ppufile:=new(pextfile,init(unit_path,n,ext));
  558. ppufile^.reset;
  559. ppufile^.flush;
  560. { load the header }
  561. ppufile^.read_data(header,sizeof(header),count);
  562. if count<>sizeof(header) then
  563. begin
  564. ppufile^.done;
  565. Message(unit_d_ppu_file_too_short);
  566. exit;
  567. end;
  568. { check for a valid PPU file }
  569. if (header[0]<>'P') or (header[1]<>'P') or (header[2]<>'U') then
  570. begin
  571. ppufile^.done;
  572. Message(unit_d_ppu_invalid_header);
  573. exit;
  574. end;
  575. { load ppu version }
  576. val(header[3]+header[4]+header[5],ppuversion,code);
  577. if not(ppuversion in [13..14]) then
  578. begin
  579. ppufile^.done;
  580. Message1(unit_d_ppu_invalid_version,tostr(ppuversion));
  581. exit;
  582. end;
  583. flags:=byte(header[9]);
  584. crc:=plongint(@header[10])^;
  585. {Get ppufile time}
  586. ppufiletime:=getnamedfiletime(ppufilename^);
  587. {Show Debug info}
  588. Message1(unit_d_ppu_time,filetimestring(ppufiletime));
  589. Message1(unit_d_ppu_flags,tostr(flags));
  590. Message1(unit_d_ppu_crc,tostr(crc));
  591. { read name if its there }
  592. ppufile^.read_data(b,1,count);
  593. if b=ibunitname then
  594. begin
  595. ppufile^.read_data(hs[0],1,count);
  596. ppufile^.read_data(hs[1],ord(hs[0]),count);
  597. stringdispose(unitname);
  598. unitname:=stringdup(hs);
  599. ppufile^.read_data(b,1,count);
  600. end;
  601. { search source files there is at least one source file }
  602. do_compile:=false;
  603. sources_avail:=true;
  604. while b<>ibend do
  605. begin
  606. ppufile^.read_data(hs[0],1,count);
  607. ppufile^.read_data(hs[1],ord(hs[0]),count);
  608. ppufile^.read_data(b,1,count);
  609. if (flags and uf_in_library)<>0 then
  610. begin
  611. sources_avail:=false;
  612. temp:=' library';
  613. end
  614. else
  615. begin
  616. { check the date of the source files }
  617. Source_Time:=GetNamedFileTime(unit_path+hs);
  618. if Source_Time=-1 then
  619. begin
  620. { search for include files in the includepathlist }
  621. if b<>ibend then
  622. temp:=search(hs,includesearchpath,incfile_found);
  623. if incfile_found then
  624. begin
  625. hs:=temp+hs;
  626. Source_Time:=GetNamedFileTime(hs);
  627. end;
  628. end
  629. else
  630. hs:=unit_path+hs;
  631. if Source_Time=-1 then
  632. begin
  633. sources_avail:=false;
  634. temp:=' not found';
  635. end
  636. else
  637. begin
  638. temp:=' time '+filetimestring(source_time);
  639. if (source_time>ppufiletime) then
  640. begin
  641. do_compile:=true;
  642. temp:=temp+' *'
  643. end;
  644. end;
  645. end;
  646. Message1(unit_t_ppu_source,hs+temp);
  647. {$ifdef UseBrowser}
  648. fsplit(hs,_d,_n,_e);
  649. new(hp,init(_d,_n,_e));
  650. { the indexing should match what is done in writeasunit }
  651. sourcefiles.register_file(hp);
  652. {$endif UseBrowser}
  653. end;
  654. { main source is always the last }
  655. stringdispose(mainsource);
  656. mainsource:=stringdup(hs);
  657. { check the object and assembler file if not a library }
  658. if (flags and uf_smartlink)<>0 then
  659. begin
  660. objfiletime:=getnamedfiletime(arfilename^);
  661. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  662. do_compile:=true;
  663. end
  664. else
  665. begin
  666. if (flags and uf_in_library)=0 then
  667. begin
  668. { the objectfile should be newer than the ppu file }
  669. objfiletime:=getnamedfiletime(objfilename^);
  670. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  671. begin
  672. { check if assembler file is older than ppu file }
  673. asmfileTime:=GetNamedFileTime(asmfilename^);
  674. if (asmfiletime<0) or (ppufiletime>asmfiletime) then
  675. begin
  676. Message(unit_d_obj_and_asm_are_older_than_ppu);
  677. do_compile:=true;
  678. end
  679. else
  680. begin
  681. Message(unit_d_obj_is_older_than_asm);
  682. do_assemble:=true;
  683. end;
  684. end;
  685. end;
  686. end;
  687. load_ppu:=true;
  688. end;
  689. procedure tmodule.search_unit(const n : string);
  690. var
  691. ext : string[8];
  692. singlepathstring,
  693. Path,
  694. filename : string;
  695. found : boolean;
  696. start,i : longint;
  697. Function UnitExists(const ext:string):boolean;
  698. begin
  699. Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
  700. UnitExists:=FileExists(Singlepathstring+FileName+ext);
  701. end;
  702. begin
  703. start:=1;
  704. filename:=FixFileName(n);
  705. path:=UnitSearchPath;
  706. Found:=false;
  707. repeat
  708. {Create current path to check}
  709. i:=pos(';',path);
  710. if i=0 then
  711. i:=length(path)+1;
  712. singlepathstring:=FixPath(copy(path,start,i-start));
  713. delete(path,start,i-start+1);
  714. { Check for PPL file }
  715. if not (cs_link_static in aktswitches) then
  716. begin
  717. Found:=UnitExists(target_info.unitlibext);
  718. if Found then
  719. Begin
  720. SetFileName(SinglePathString,FileName);
  721. Found:=Load_PPU(singlepathstring,filename,target_info.unitlibext);
  722. End;
  723. end;
  724. { Check for PPU file }
  725. if not (cs_link_dynamic in aktswitches) and not Found then
  726. begin
  727. Found:=UnitExists(target_info.unitext);
  728. if Found then
  729. Begin
  730. SetFileName(SinglePathString,FileName);
  731. Found:=Load_PPU(singlepathstring,filename,target_info.unitext);
  732. End;
  733. end;
  734. { Check for Sources }
  735. if not Found then
  736. begin
  737. ppufile:=nil;
  738. do_compile:=true;
  739. {Check for .pp file}
  740. Found:=UnitExists(target_os.sourceext);
  741. if Found then
  742. Ext:=target_os.sourceext
  743. else
  744. begin
  745. {Check for .pas}
  746. Found:=UnitExists(target_os.pasext);
  747. if Found then
  748. Ext:=target_os.pasext;
  749. end;
  750. stringdispose(mainsource);
  751. if Found then
  752. begin
  753. sources_avail:=true;
  754. {Load Filenames when found}
  755. mainsource:=StringDup(SinglePathString+FileName+Ext);
  756. SetFileName(SinglePathString,FileName);
  757. end
  758. else
  759. sources_avail:=false;
  760. end;
  761. until Found or (path='');
  762. end;
  763. {$endif NEWPPU}
  764. constructor tmodule.init(const s:string;_is_unit:boolean);
  765. var
  766. p : dirstr;
  767. n : namestr;
  768. e : extstr;
  769. begin
  770. FSplit(s,p,n,e);
  771. unitname:=stringdup(Upper(n));
  772. mainsource:=stringdup(s);
  773. objfilename:=nil;
  774. asmfilename:=nil;
  775. arfilename:=nil;
  776. ppufilename:=nil;
  777. setfilename(p,n);
  778. used_units.init;
  779. sourcefiles.init;
  780. linkofiles.init;
  781. linkstaticlibs.init;
  782. linksharedlibs.init;
  783. ppufile:=nil;
  784. current_inputfile:=nil;
  785. map:=nil;
  786. symtable:=nil;
  787. flags:=0;
  788. crc:=0;
  789. unitcount:=1;
  790. inc(global_unit_count);
  791. unit_index:=global_unit_count;
  792. do_assemble:=false;
  793. do_compile:=false;
  794. sources_avail:=true;
  795. compiled:=false;
  796. in_implementation:=false;
  797. in_main:=false;
  798. is_unit:=_is_unit;
  799. uses_imports:=false;
  800. imports:=new(plinkedlist,init);
  801. output_format:=commandline_output_format;
  802. { set smartlink flag }
  803. if smartlink then
  804. flags:=flags or uf_smartlink;
  805. { search the PPU file if it is an unit }
  806. if is_unit then
  807. search_unit(unitname^);
  808. end;
  809. destructor tmodule.special_done;
  810. begin
  811. if assigned(map) then
  812. dispose(map);
  813. { cannot remove that because it is linked
  814. in the global chain of used_objects
  815. used_units.done; }
  816. sourcefiles.done;
  817. linkofiles.done;
  818. linkstaticlibs.done;
  819. linksharedlibs.done;
  820. if assigned(ppufile) then
  821. dispose(ppufile,done);
  822. if assigned(imports) then
  823. dispose(imports,done);
  824. inherited done;
  825. end;
  826. {****************************************************************************
  827. TUSED_UNIT
  828. ****************************************************************************}
  829. constructor tused_unit.init(_u : pmodule;f : byte);
  830. begin
  831. u:=_u;
  832. in_interface:=false;
  833. in_uses:=false;
  834. is_stab_written:=false;
  835. unitid:=f;
  836. end;
  837. destructor tused_unit.done;
  838. begin
  839. inherited done;
  840. end;
  841. end.
  842. {
  843. $Log$
  844. Revision 1.12 1998-05-20 09:42:33 pierre
  845. + UseTokenInfo now default
  846. * unit in interface uses and implementation uses gives error now
  847. * only one error for unknown symbol (uses lastsymknown boolean)
  848. the problem came from the label code !
  849. + first inlined procedures and function work
  850. (warning there might be allowed cases were the result is still wrong !!)
  851. * UseBrower updated gives a global list of all position of all used symbols
  852. with switch -gb
  853. Revision 1.11 1998/05/12 10:46:59 peter
  854. * moved printstatus to verb_def
  855. + V_Normal which is between V_Error and V_Warning and doesn't have a
  856. prefix like error: warning: and is included in V_Default
  857. * fixed some messages
  858. * first time parameter scan is only for -v and -T
  859. - removed old style messages
  860. Revision 1.10 1998/05/11 13:07:53 peter
  861. + $ifdef NEWPPU for the new ppuformat
  862. + $define GDB not longer required
  863. * removed all warnings and stripped some log comments
  864. * no findfirst/findnext anymore to remove smartlink *.o files
  865. Revision 1.9 1998/05/06 15:04:20 pierre
  866. + when trying to find source files of a ppufile
  867. check the includepathlist for included files
  868. the main file must still be in the same directory
  869. Revision 1.8 1998/05/04 17:54:25 peter
  870. + smartlinking works (only case jumptable left todo)
  871. * redesign of systems.pas to support assemblers and linkers
  872. + Unitname is now also in the PPU-file, increased version to 14
  873. Revision 1.7 1998/05/01 16:38:44 florian
  874. * handling of private and protected fixed
  875. + change_keywords_to_tp implemented to remove
  876. keywords which aren't supported by tp
  877. * break and continue are now symbols of the system unit
  878. + widestring, longstring and ansistring type released
  879. Revision 1.6 1998/05/01 07:43:53 florian
  880. + basics for rtti implemented
  881. + switch $m (generate rtti for published sections)
  882. Revision 1.5 1998/04/30 15:59:40 pierre
  883. * GDB works again better :
  884. correct type info in one pass
  885. + UseTokenInfo for better source position
  886. * fixed one remaining bug in scanner for line counts
  887. * several little fixes
  888. Revision 1.4 1998/04/29 10:33:52 pierre
  889. + added some code for ansistring (not complete nor working yet)
  890. * corrected operator overloading
  891. * corrected nasm output
  892. + started inline procedures
  893. + added starstarn : use ** for exponentiation (^ gave problems)
  894. + started UseTokenInfo cond to get accurate positions
  895. Revision 1.3 1998/04/27 23:10:28 peter
  896. + new scanner
  897. * $makelib -> if smartlink
  898. * small filename fixes pmodule.setfilename
  899. * moved import from files.pas -> import.pas
  900. Revision 1.2 1998/04/21 10:16:47 peter
  901. * patches from strasbourg
  902. * objects is not used anymore in the fpc compiled version
  903. }