files.pas 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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. ibvarsym_C = 37;
  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:=lower(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(libfilename);
  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. libfilename:=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=ibmodulename then
  356. begin
  357. stringdispose(modulename);
  358. modulename:=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=ibsourcefiles then
  365. begin
  366. while not ppufile^.endofentry do
  367. begin
  368. hs:=ppufile^.getstring;
  369. temp:='';
  370. if (flags and uf_in_library)<>0 then
  371. begin
  372. sources_avail:=false;
  373. temp:=' library';
  374. end
  375. else if pos('Macro ',hs)=1 then
  376. begin
  377. { we don't want to find this file }
  378. { but there is a problem with file indexing !! }
  379. temp:='';
  380. end
  381. else
  382. begin
  383. { check the date of the source files }
  384. Source_Time:=GetNamedFileTime(unit_path+hs);
  385. if Source_Time=-1 then
  386. begin
  387. { search for include files in the includepathlist }
  388. if b<>ibend then
  389. begin
  390. temp:=search(hs,includesearchpath,incfile_found);
  391. if incfile_found then
  392. begin
  393. hs:=temp+hs;
  394. Source_Time:=GetNamedFileTime(hs);
  395. end;
  396. end;
  397. end
  398. else
  399. hs:=unit_path+hs;
  400. if Source_Time=-1 then
  401. begin
  402. sources_avail:=false;
  403. temp:=' not found';
  404. end
  405. else
  406. begin
  407. temp:=' time '+filetimestring(source_time);
  408. if (source_time>ppufiletime) then
  409. begin
  410. do_compile:=true;
  411. temp:=temp+' *'
  412. end;
  413. end;
  414. end;
  415. Message1(unit_t_ppu_source,hs+temp);
  416. {$ifdef UseBrowser}
  417. fsplit(hs,_d,_n,_e);
  418. new(hp,init(_d,_n,_e));
  419. { the indexing should match what is done in writeasunit }
  420. sourcefiles.register_file(hp);
  421. {$endif UseBrowser}
  422. end;
  423. end;
  424. { main source is always the last }
  425. stringdispose(mainsource);
  426. mainsource:=stringdup(hs);
  427. { check the object and assembler file if not a library }
  428. if (flags and uf_in_library)=0 then
  429. begin
  430. if (flags and uf_smartlink)<>0 then
  431. begin
  432. objfiletime:=getnamedfiletime(libfilename^);
  433. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  434. do_compile:=true;
  435. end
  436. else
  437. begin
  438. { the objectfile should be newer than the ppu file }
  439. objfiletime:=getnamedfiletime(objfilename^);
  440. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  441. begin
  442. { check if assembler file is older than ppu file }
  443. asmfileTime:=GetNamedFileTime(asmfilename^);
  444. if (asmfiletime<0) or (ppufiletime>asmfiletime) then
  445. begin
  446. Message(unit_d_obj_and_asm_are_older_than_ppu);
  447. do_compile:=true;
  448. end
  449. else
  450. begin
  451. Message(unit_d_obj_is_older_than_asm);
  452. do_assemble:=true;
  453. end;
  454. end;
  455. end;
  456. end;
  457. openppu:=true;
  458. end;
  459. procedure tmodule.search_unit(const n : string);
  460. var
  461. ext : string[8];
  462. singlepathstring,
  463. Path,
  464. filename : string;
  465. found : boolean;
  466. start,i : longint;
  467. Function UnitExists(const ext:string):boolean;
  468. begin
  469. Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
  470. UnitExists:=FileExists(Singlepathstring+FileName+ext);
  471. end;
  472. begin
  473. start:=1;
  474. filename:=FixFileName(n);
  475. path:=UnitSearchPath;
  476. Found:=false;
  477. repeat
  478. { Create current path to check }
  479. i:=pos(';',path);
  480. if i=0 then
  481. i:=length(path)+1;
  482. singlepathstring:=FixPath(copy(path,start,i-start));
  483. delete(path,start,i-start+1);
  484. { Check for PPL file }
  485. if not (cs_link_static in aktswitches) then
  486. begin
  487. Found:=UnitExists(target_info.unitlibext);
  488. if Found then
  489. Begin
  490. SetFileName(SinglePathString,FileName);
  491. Found:=OpenPPU(singlepathstring);
  492. End;
  493. end;
  494. { Check for PPU file }
  495. if not (cs_link_dynamic in aktswitches) and not Found then
  496. begin
  497. Found:=UnitExists(target_info.unitext);
  498. if Found then
  499. Begin
  500. SetFileName(SinglePathString,FileName);
  501. Found:=OpenPPU(singlepathstring);
  502. End;
  503. end;
  504. { Check for Sources }
  505. if not Found then
  506. begin
  507. ppufile:=nil;
  508. do_compile:=true;
  509. {Check for .pp file}
  510. Found:=UnitExists(target_os.sourceext);
  511. if Found then
  512. Ext:=target_os.sourceext
  513. else
  514. begin
  515. {Check for .pas}
  516. Found:=UnitExists(target_os.pasext);
  517. if Found then
  518. Ext:=target_os.pasext;
  519. end;
  520. stringdispose(mainsource);
  521. if Found then
  522. begin
  523. sources_avail:=true;
  524. {Load Filenames when found}
  525. mainsource:=StringDup(SinglePathString+FileName+Ext);
  526. SetFileName(SinglePathString,FileName);
  527. end
  528. else
  529. sources_avail:=false;
  530. end;
  531. until Found or (path='');
  532. end;
  533. {$else NEWPPU}
  534. function tmodule.load_ppu(const unit_path,n,ext : string):boolean;
  535. var
  536. header : tunitheader;
  537. count : longint;
  538. temp,hs : string;
  539. b : byte;
  540. incfile_found : boolean;
  541. code : word;
  542. ppuversion,
  543. objfiletime,
  544. ppufiletime,
  545. asmfiletime,
  546. source_time : longint;
  547. {$ifdef UseBrowser}
  548. hp : pextfile;
  549. _d : dirstr;
  550. _n : namestr;
  551. _e : extstr;
  552. {$endif UseBrowser}
  553. begin
  554. load_ppu:=false;
  555. { Get ppufile time (also check if the file exists) }
  556. ppufiletime:=getnamedfiletime(ppufilename^);
  557. if ppufiletime=-1 then
  558. exit;
  559. Message1(unit_u_ppu_loading,ppufilename^);
  560. ppufile:=new(pextfile,init(unit_path,n,ext));
  561. ppufile^.reset;
  562. ppufile^.flush;
  563. { load the header }
  564. ppufile^.read_data(header,sizeof(header),count);
  565. if count<>sizeof(header) then
  566. begin
  567. ppufile^.done;
  568. Message(unit_d_ppu_file_too_short);
  569. exit;
  570. end;
  571. { check for a valid PPU file }
  572. if (header[0]<>'P') or (header[1]<>'P') or (header[2]<>'U') then
  573. begin
  574. ppufile^.done;
  575. Message(unit_d_ppu_invalid_header);
  576. exit;
  577. end;
  578. { load ppu version }
  579. val(header[3]+header[4]+header[5],ppuversion,code);
  580. if not(ppuversion in [13..14]) then
  581. begin
  582. ppufile^.done;
  583. Message1(unit_d_ppu_invalid_version,tostr(ppuversion));
  584. exit;
  585. end;
  586. flags:=byte(header[9]);
  587. crc:=plongint(@header[10])^;
  588. {Get ppufile time}
  589. ppufiletime:=getnamedfiletime(ppufilename^);
  590. {Show Debug info}
  591. Message1(unit_d_ppu_time,filetimestring(ppufiletime));
  592. Message1(unit_d_ppu_flags,tostr(flags));
  593. Message1(unit_d_ppu_crc,tostr(crc));
  594. { read name if its there }
  595. ppufile^.read_data(b,1,count);
  596. if b=ibunitname then
  597. begin
  598. ppufile^.read_data(hs[0],1,count);
  599. ppufile^.read_data(hs[1],ord(hs[0]),count);
  600. stringdispose(modulename);
  601. modulename:=stringdup(hs);
  602. ppufile^.read_data(b,1,count);
  603. end;
  604. { search source files there is at least one source file }
  605. do_compile:=false;
  606. sources_avail:=true;
  607. while b<>ibend do
  608. begin
  609. ppufile^.read_data(hs[0],1,count);
  610. ppufile^.read_data(hs[1],ord(hs[0]),count);
  611. ppufile^.read_data(b,1,count);
  612. temp:='';
  613. if (flags and uf_in_library)<>0 then
  614. begin
  615. sources_avail:=false;
  616. temp:=' library';
  617. end
  618. else
  619. begin
  620. { check the date of the source files }
  621. Source_Time:=GetNamedFileTime(unit_path+hs);
  622. if Source_Time=-1 then
  623. begin
  624. { search for include files in the includepathlist }
  625. if b<>ibend then
  626. begin
  627. temp:=search(hs,includesearchpath,incfile_found);
  628. if incfile_found then
  629. begin
  630. hs:=temp+hs;
  631. Source_Time:=GetNamedFileTime(hs);
  632. end;
  633. end;
  634. end
  635. else
  636. hs:=unit_path+hs;
  637. if Source_Time=-1 then
  638. begin
  639. sources_avail:=false;
  640. temp:=' not found';
  641. end
  642. else
  643. begin
  644. temp:=' time '+filetimestring(source_time);
  645. if (source_time>ppufiletime) then
  646. begin
  647. do_compile:=true;
  648. temp:=temp+' *'
  649. end;
  650. end;
  651. end;
  652. Message1(unit_t_ppu_source,hs+temp);
  653. {$ifdef UseBrowser}
  654. fsplit(hs,_d,_n,_e);
  655. new(hp,init(_d,_n,_e));
  656. { the indexing should match what is done in writeasunit }
  657. sourcefiles.register_file(hp);
  658. {$endif UseBrowser}
  659. end;
  660. { main source is always the last }
  661. stringdispose(mainsource);
  662. mainsource:=stringdup(hs);
  663. { check the object and assembler file if not a library }
  664. if (flags and uf_smartlink)<>0 then
  665. begin
  666. objfiletime:=getnamedfiletime(libfilename^);
  667. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  668. do_compile:=true;
  669. end
  670. else
  671. begin
  672. if (flags and uf_in_library)=0 then
  673. begin
  674. { the objectfile should be newer than the ppu file }
  675. objfiletime:=getnamedfiletime(objfilename^);
  676. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  677. begin
  678. { check if assembler file is older than ppu file }
  679. asmfileTime:=GetNamedFileTime(asmfilename^);
  680. if (asmfiletime<0) or (ppufiletime>asmfiletime) then
  681. begin
  682. Message(unit_d_obj_and_asm_are_older_than_ppu);
  683. do_compile:=true;
  684. end
  685. else
  686. begin
  687. Message(unit_d_obj_is_older_than_asm);
  688. do_assemble:=true;
  689. end;
  690. end;
  691. end;
  692. end;
  693. load_ppu:=true;
  694. end;
  695. procedure tmodule.search_unit(const n : string);
  696. var
  697. ext : string[8];
  698. singlepathstring,
  699. Path,
  700. filename : string;
  701. found : boolean;
  702. start,i : longint;
  703. Function UnitExists(const ext:string):boolean;
  704. begin
  705. Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
  706. UnitExists:=FileExists(Singlepathstring+FileName+ext);
  707. end;
  708. begin
  709. start:=1;
  710. filename:=FixFileName(n);
  711. path:=UnitSearchPath;
  712. Found:=false;
  713. repeat
  714. {Create current path to check}
  715. i:=pos(';',path);
  716. if i=0 then
  717. i:=length(path)+1;
  718. singlepathstring:=FixPath(copy(path,start,i-start));
  719. delete(path,start,i-start+1);
  720. { Check for PPL file }
  721. if not (cs_link_static in aktswitches) then
  722. begin
  723. Found:=UnitExists(target_info.unitlibext);
  724. if Found then
  725. Begin
  726. SetFileName(SinglePathString,FileName);
  727. Found:=Load_PPU(singlepathstring,filename,target_info.unitlibext);
  728. End;
  729. end;
  730. { Check for PPU file }
  731. if not (cs_link_dynamic in aktswitches) and not Found then
  732. begin
  733. Found:=UnitExists(target_info.unitext);
  734. if Found then
  735. Begin
  736. SetFileName(SinglePathString,FileName);
  737. Found:=Load_PPU(singlepathstring,filename,target_info.unitext);
  738. End;
  739. end;
  740. { Check for Sources }
  741. if not Found then
  742. begin
  743. ppufile:=nil;
  744. do_compile:=true;
  745. {Check for .pp file}
  746. Found:=UnitExists(target_os.sourceext);
  747. if Found then
  748. Ext:=target_os.sourceext
  749. else
  750. begin
  751. {Check for .pas}
  752. Found:=UnitExists(target_os.pasext);
  753. if Found then
  754. Ext:=target_os.pasext;
  755. end;
  756. stringdispose(mainsource);
  757. if Found then
  758. begin
  759. sources_avail:=true;
  760. {Load Filenames when found}
  761. mainsource:=StringDup(SinglePathString+FileName+Ext);
  762. SetFileName(SinglePathString,FileName);
  763. end
  764. else
  765. sources_avail:=false;
  766. end;
  767. until Found or (path='');
  768. end;
  769. {$endif NEWPPU}
  770. constructor tmodule.init(const s:string;_is_unit:boolean);
  771. var
  772. p : dirstr;
  773. n : namestr;
  774. e : extstr;
  775. begin
  776. FSplit(s,p,n,e);
  777. { Programs have the name program to don't conflict with dup id's }
  778. if _is_unit then
  779. modulename:=stringdup(Upper(n))
  780. else
  781. modulename:=stringdup('PROGRAM');
  782. mainsource:=stringdup(s);
  783. objfilename:=nil;
  784. asmfilename:=nil;
  785. libfilename:=nil;
  786. ppufilename:=nil;
  787. setfilename(p,n);
  788. used_units.init;
  789. sourcefiles.init;
  790. linkofiles.init;
  791. linkstaticlibs.init;
  792. linksharedlibs.init;
  793. ppufile:=nil;
  794. current_inputfile:=nil;
  795. map:=nil;
  796. symtable:=nil;
  797. flags:=0;
  798. crc:=0;
  799. unitcount:=1;
  800. inc(global_unit_count);
  801. unit_index:=global_unit_count;
  802. do_assemble:=false;
  803. do_compile:=false;
  804. sources_avail:=true;
  805. compiled:=false;
  806. in_implementation:=false;
  807. in_main:=false;
  808. is_unit:=_is_unit;
  809. uses_imports:=false;
  810. imports:=new(plinkedlist,init);
  811. { set smartlink flag }
  812. if (cs_smartlink in aktswitches) then
  813. flags:=flags or uf_smartlink;
  814. { search the PPU file if it is an unit }
  815. if is_unit then
  816. search_unit(modulename^);
  817. end;
  818. destructor tmodule.special_done;
  819. begin
  820. if assigned(map) then
  821. dispose(map);
  822. { cannot remove that because it is linked
  823. in the global chain of used_objects
  824. used_units.done; }
  825. sourcefiles.done;
  826. linkofiles.done;
  827. linkstaticlibs.done;
  828. linksharedlibs.done;
  829. if assigned(ppufile) then
  830. dispose(ppufile,done);
  831. if assigned(imports) then
  832. dispose(imports,done);
  833. inherited done;
  834. end;
  835. {****************************************************************************
  836. TUSED_UNIT
  837. ****************************************************************************}
  838. constructor tused_unit.init(_u : pmodule;f : byte);
  839. begin
  840. u:=_u;
  841. in_interface:=false;
  842. in_uses:=false;
  843. is_stab_written:=false;
  844. unitid:=f;
  845. end;
  846. destructor tused_unit.done;
  847. begin
  848. inherited done;
  849. end;
  850. end.
  851. {
  852. $Log$
  853. Revision 1.18 1998-06-11 13:58:07 peter
  854. * small fix to let newppu compile
  855. Revision 1.17 1998/06/09 16:01:40 pierre
  856. + added procedure directive parsing for procvars
  857. (accepted are popstack cdecl and pascal)
  858. + added C vars with the following syntax
  859. var C calias 'true_c_name';(can be followed by external)
  860. reason is that you must add the Cprefix
  861. which is target dependent
  862. Revision 1.16 1998/06/04 10:42:19 pierre
  863. * small bug fix in load_ppu or openppu
  864. Revision 1.15 1998/05/28 14:37:53 peter
  865. * default programname is PROGRAM (like TP7) to avoid dup id's
  866. Revision 1.14 1998/05/27 19:45:02 peter
  867. * symtable.pas splitted into includefiles
  868. * symtable adapted for $ifdef NEWPPU
  869. Revision 1.13 1998/05/23 01:21:05 peter
  870. + aktasmmode, aktoptprocessor, aktoutputformat
  871. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  872. + $LIBNAME to set the library name where the unit will be put in
  873. * splitted cgi386 a bit (codeseg to large for bp7)
  874. * nasm, tasm works again. nasm moved to ag386nsm.pas
  875. Revision 1.12 1998/05/20 09:42:33 pierre
  876. + UseTokenInfo now default
  877. * unit in interface uses and implementation uses gives error now
  878. * only one error for unknown symbol (uses lastsymknown boolean)
  879. the problem came from the label code !
  880. + first inlined procedures and function work
  881. (warning there might be allowed cases were the result is still wrong !!)
  882. * UseBrower updated gives a global list of all position of all used symbols
  883. with switch -gb
  884. Revision 1.11 1998/05/12 10:46:59 peter
  885. * moved printstatus to verb_def
  886. + V_Normal which is between V_Error and V_Warning and doesn't have a
  887. prefix like error: warning: and is included in V_Default
  888. * fixed some messages
  889. * first time parameter scan is only for -v and -T
  890. - removed old style messages
  891. Revision 1.10 1998/05/11 13:07:53 peter
  892. + $ifdef NEWPPU for the new ppuformat
  893. + $define GDB not longer required
  894. * removed all warnings and stripped some log comments
  895. * no findfirst/findnext anymore to remove smartlink *.o files
  896. Revision 1.9 1998/05/06 15:04:20 pierre
  897. + when trying to find source files of a ppufile
  898. check the includepathlist for included files
  899. the main file must still be in the same directory
  900. Revision 1.8 1998/05/04 17:54:25 peter
  901. + smartlinking works (only case jumptable left todo)
  902. * redesign of systems.pas to support assemblers and linkers
  903. + Unitname is now also in the PPU-file, increased version to 14
  904. Revision 1.7 1998/05/01 16:38:44 florian
  905. * handling of private and protected fixed
  906. + change_keywords_to_tp implemented to remove
  907. keywords which aren't supported by tp
  908. * break and continue are now symbols of the system unit
  909. + widestring, longstring and ansistring type released
  910. Revision 1.6 1998/05/01 07:43:53 florian
  911. + basics for rtti implemented
  912. + switch $m (generate rtti for published sections)
  913. Revision 1.5 1998/04/30 15:59:40 pierre
  914. * GDB works again better :
  915. correct type info in one pass
  916. + UseTokenInfo for better source position
  917. * fixed one remaining bug in scanner for line counts
  918. * several little fixes
  919. Revision 1.4 1998/04/29 10:33:52 pierre
  920. + added some code for ansistring (not complete nor working yet)
  921. * corrected operator overloading
  922. * corrected nasm output
  923. + started inline procedures
  924. + added starstarn : use ** for exponentiation (^ gave problems)
  925. + started UseTokenInfo cond to get accurate positions
  926. Revision 1.3 1998/04/27 23:10:28 peter
  927. + new scanner
  928. * $makelib -> if smartlink
  929. * small filename fixes pmodule.setfilename
  930. * moved import from files.pas -> import.pas
  931. Revision 1.2 1998/04/21 10:16:47 peter
  932. * patches from strasbourg
  933. * objects is not used anymore in the fpc compiled version
  934. }