files.pas 30 KB

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