files.pas 31 KB

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