files.pas 33 KB

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