files.pas 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  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. procedure search_unit(const n : string);
  118. end;
  119. pused_unit = ^tused_unit;
  120. tused_unit = object(tlinkedlist_item)
  121. u : pmodule;
  122. in_uses,
  123. in_interface,
  124. is_stab_written : boolean;
  125. unitid : word;
  126. constructor init(_u : pmodule;f : byte);
  127. destructor done;virtual;
  128. end;
  129. {$ifndef NEWPPU}
  130. type
  131. tunitheader = array[0..19] of char;
  132. const
  133. { compiler version }
  134. { format | }
  135. { signature | | }
  136. { | | | }
  137. { /-------\ /-------\ /----\ }
  138. unitheader : tunitheader = ('P','P','U','0','1','4',#0,#99,
  139. #0,#0,#0,#0,#0,#0,#255,#255,
  140. { | | \---------/ \-------/ }
  141. { | | | | }
  142. { | | check sum | }
  143. { | \--flags unused }
  144. { target system }
  145. #0,#0,#0,#0);
  146. {\---------/ }
  147. { | }
  148. { start of machine language }
  149. ibloadunit = 1;
  150. iborddef = 2;
  151. ibpointerdef = 3;
  152. ibtypesym = 4;
  153. ibarraydef = 5;
  154. ibprocdef = 6;
  155. ibprocsym = 7;
  156. iblinkofile = 8;
  157. ibstringdef = 9;
  158. ibvarsym = 10;
  159. ibconstsym = 11;
  160. ibinitunit = 12;
  161. ibenumsym = 13;
  162. ibtypedconstsym = 14;
  163. ibrecorddef = 15;
  164. ibfiledef = 16;
  165. ibformaldef = 17;
  166. ibobjectdef = 18;
  167. ibenumdef = 19;
  168. ibsetdef = 20;
  169. ibprocvardef = 21;
  170. ibsourcefile = 22;
  171. ibdbxcount = 23;
  172. ibfloatdef = 24;
  173. ibref = 25;
  174. ibextsymref = 26;
  175. ibextdefref = 27;
  176. ibabsolutesym = 28;
  177. ibclassrefdef = 29;
  178. ibpropertysym = 30;
  179. ibsharedlibs = 31;
  180. iblongstringdef = 32;
  181. ibansistringdef = 33;
  182. ibunitname = 34;
  183. ibwidestringdef = 35;
  184. ibstaticlibs = 36;
  185. 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. procedure tmodule.search_unit(const n : string);
  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. end;
  535. {$else NEWPPU}
  536. function tmodule.load_ppu(const unit_path,n,ext : string):boolean;
  537. var
  538. header : tunitheader;
  539. count : longint;
  540. temp,hs : string;
  541. b : byte;
  542. incfile_found : boolean;
  543. code : word;
  544. ppuversion,
  545. objfiletime,
  546. ppufiletime,
  547. asmfiletime,
  548. source_time : longint;
  549. {$ifdef UseBrowser}
  550. hp : pextfile;
  551. _d : dirstr;
  552. _n : namestr;
  553. _e : extstr;
  554. {$endif UseBrowser}
  555. begin
  556. load_ppu:=false;
  557. { Get ppufile time (also check if the file exists) }
  558. ppufiletime:=getnamedfiletime(ppufilename^);
  559. if ppufiletime=-1 then
  560. exit;
  561. Message1(unit_u_ppu_loading,ppufilename^);
  562. ppufile:=new(pextfile,init(unit_path,n,ext));
  563. ppufile^.reset;
  564. ppufile^.flush;
  565. { load the header }
  566. ppufile^.read_data(header,sizeof(header),count);
  567. if count<>sizeof(header) then
  568. begin
  569. ppufile^.done;
  570. Message(unit_d_ppu_file_too_short);
  571. exit;
  572. end;
  573. { check for a valid PPU file }
  574. if (header[0]<>'P') or (header[1]<>'P') or (header[2]<>'U') then
  575. begin
  576. ppufile^.done;
  577. Message(unit_d_ppu_invalid_header);
  578. exit;
  579. end;
  580. { load ppu version }
  581. val(header[3]+header[4]+header[5],ppuversion,code);
  582. if not(ppuversion in [13..14]) then
  583. begin
  584. ppufile^.done;
  585. Message1(unit_d_ppu_invalid_version,tostr(ppuversion));
  586. exit;
  587. end;
  588. flags:=byte(header[9]);
  589. crc:=plongint(@header[10])^;
  590. {Get ppufile time}
  591. ppufiletime:=getnamedfiletime(ppufilename^);
  592. {Show Debug info}
  593. Message1(unit_d_ppu_time,filetimestring(ppufiletime));
  594. Message1(unit_d_ppu_flags,tostr(flags));
  595. Message1(unit_d_ppu_crc,tostr(crc));
  596. { read name if its there }
  597. ppufile^.read_data(b,1,count);
  598. if b=ibunitname then
  599. begin
  600. ppufile^.read_data(hs[0],1,count);
  601. ppufile^.read_data(hs[1],ord(hs[0]),count);
  602. stringdispose(modulename);
  603. modulename:=stringdup(hs);
  604. ppufile^.read_data(b,1,count);
  605. end;
  606. { search source files there is at least one source file }
  607. do_compile:=false;
  608. sources_avail:=true;
  609. while b<>ibend do
  610. begin
  611. ppufile^.read_data(hs[0],1,count);
  612. ppufile^.read_data(hs[1],ord(hs[0]),count);
  613. ppufile^.read_data(b,1,count);
  614. temp:='';
  615. if (flags and uf_in_library)<>0 then
  616. begin
  617. sources_avail:=false;
  618. temp:=' library';
  619. end
  620. else
  621. begin
  622. { check the date of the source files }
  623. Source_Time:=GetNamedFileTime(unit_path+hs);
  624. if Source_Time=-1 then
  625. begin
  626. { search for include files in the includepathlist }
  627. if b<>ibend then
  628. begin
  629. temp:=search(hs,includesearchpath,incfile_found);
  630. if incfile_found then
  631. begin
  632. hs:=temp+hs;
  633. Source_Time:=GetNamedFileTime(hs);
  634. end;
  635. end;
  636. end
  637. else
  638. hs:=unit_path+hs;
  639. if Source_Time=-1 then
  640. begin
  641. sources_avail:=false;
  642. temp:=' not found';
  643. end
  644. else
  645. begin
  646. temp:=' time '+filetimestring(source_time);
  647. if (source_time>ppufiletime) then
  648. begin
  649. do_compile:=true;
  650. temp:=temp+' *'
  651. end;
  652. end;
  653. end;
  654. Message1(unit_t_ppu_source,hs+temp);
  655. {$ifdef UseBrowser}
  656. fsplit(hs,_d,_n,_e);
  657. new(hp,init(_d,_n,_e));
  658. { the indexing should match what is done in writeasunit }
  659. sourcefiles.register_file(hp);
  660. {$endif UseBrowser}
  661. end;
  662. { main source is always the last }
  663. stringdispose(mainsource);
  664. mainsource:=stringdup(hs);
  665. { check the object and assembler file if not a library }
  666. if (flags and uf_smartlink)<>0 then
  667. begin
  668. objfiletime:=getnamedfiletime(libfilename^);
  669. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  670. do_compile:=true;
  671. end
  672. else
  673. begin
  674. if (flags and uf_in_library)=0 then
  675. begin
  676. { the objectfile should be newer than the ppu file }
  677. objfiletime:=getnamedfiletime(objfilename^);
  678. if (ppufiletime<0) or (objfiletime<0) or (ppufiletime>objfiletime) then
  679. begin
  680. { check if assembler file is older than ppu file }
  681. asmfileTime:=GetNamedFileTime(asmfilename^);
  682. if (asmfiletime<0) or (ppufiletime>asmfiletime) then
  683. begin
  684. Message(unit_d_obj_and_asm_are_older_than_ppu);
  685. do_compile:=true;
  686. end
  687. else
  688. begin
  689. Message(unit_d_obj_is_older_than_asm);
  690. do_assemble:=true;
  691. end;
  692. end;
  693. end;
  694. end;
  695. load_ppu:=true;
  696. end;
  697. procedure tmodule.search_unit(const n : string);
  698. var
  699. ext : string[8];
  700. singlepathstring,
  701. Path,
  702. filename : string;
  703. found : boolean;
  704. start,i : longint;
  705. Function UnitExists(const ext:string):boolean;
  706. begin
  707. Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
  708. UnitExists:=FileExists(Singlepathstring+FileName+ext);
  709. end;
  710. begin
  711. start:=1;
  712. filename:=FixFileName(n);
  713. path:=UnitSearchPath;
  714. Found:=false;
  715. repeat
  716. {Create current path to check}
  717. i:=pos(';',path);
  718. if i=0 then
  719. i:=length(path)+1;
  720. singlepathstring:=FixPath(copy(path,start,i-start));
  721. delete(path,start,i-start+1);
  722. { Check for PPL file }
  723. if not (cs_link_static in aktswitches) then
  724. begin
  725. Found:=UnitExists(target_info.unitlibext);
  726. if Found then
  727. Begin
  728. SetFileName(SinglePathString,FileName);
  729. Found:=Load_PPU(singlepathstring,filename,target_info.unitlibext);
  730. End;
  731. end;
  732. { Check for PPU file }
  733. if not (cs_link_dynamic in aktswitches) and not Found then
  734. begin
  735. Found:=UnitExists(target_info.unitext);
  736. if Found then
  737. Begin
  738. SetFileName(SinglePathString,FileName);
  739. Found:=Load_PPU(singlepathstring,filename,target_info.unitext);
  740. End;
  741. end;
  742. { Check for Sources }
  743. if not Found then
  744. begin
  745. ppufile:=nil;
  746. do_compile:=true;
  747. {Check for .pp file}
  748. Found:=UnitExists(target_os.sourceext);
  749. if Found then
  750. Ext:=target_os.sourceext
  751. else
  752. begin
  753. {Check for .pas}
  754. Found:=UnitExists(target_os.pasext);
  755. if Found then
  756. Ext:=target_os.pasext;
  757. end;
  758. stringdispose(mainsource);
  759. if Found then
  760. begin
  761. sources_avail:=true;
  762. {Load Filenames when found}
  763. mainsource:=StringDup(SinglePathString+FileName+Ext);
  764. SetFileName(SinglePathString,FileName);
  765. end
  766. else
  767. sources_avail:=false;
  768. end;
  769. until Found or (path='');
  770. end;
  771. {$endif NEWPPU}
  772. constructor tmodule.init(const s:string;_is_unit:boolean);
  773. var
  774. p : dirstr;
  775. n : namestr;
  776. e : extstr;
  777. begin
  778. FSplit(s,p,n,e);
  779. { Programs have the name program to don't conflict with dup id's }
  780. if _is_unit then
  781. modulename:=stringdup(Upper(n))
  782. else
  783. modulename:=stringdup('PROGRAM');
  784. mainsource:=stringdup(s);
  785. objfilename:=nil;
  786. asmfilename:=nil;
  787. libfilename:=nil;
  788. ppufilename:=nil;
  789. setfilename(p,n);
  790. used_units.init;
  791. sourcefiles.init;
  792. linkofiles.init;
  793. linkstaticlibs.init;
  794. linksharedlibs.init;
  795. ppufile:=nil;
  796. current_inputfile:=nil;
  797. map:=nil;
  798. symtable:=nil;
  799. flags:=0;
  800. crc:=0;
  801. unitcount:=1;
  802. inc(global_unit_count);
  803. unit_index:=global_unit_count;
  804. do_assemble:=false;
  805. do_compile:=false;
  806. sources_avail:=true;
  807. compiled:=false;
  808. in_implementation:=false;
  809. in_main:=false;
  810. is_unit:=_is_unit;
  811. uses_imports:=false;
  812. imports:=new(plinkedlist,init);
  813. { set smartlink flag }
  814. if (cs_smartlink in aktswitches) then
  815. flags:=flags or uf_smartlink;
  816. { search the PPU file if it is an unit }
  817. if is_unit then
  818. search_unit(modulename^);
  819. end;
  820. destructor tmodule.special_done;
  821. begin
  822. if assigned(map) then
  823. dispose(map);
  824. { cannot remove that because it is linked
  825. in the global chain of used_objects
  826. used_units.done; }
  827. sourcefiles.done;
  828. linkofiles.done;
  829. linkstaticlibs.done;
  830. linksharedlibs.done;
  831. if assigned(ppufile) then
  832. dispose(ppufile,done);
  833. if assigned(imports) then
  834. dispose(imports,done);
  835. inherited done;
  836. end;
  837. {****************************************************************************
  838. TUSED_UNIT
  839. ****************************************************************************}
  840. constructor tused_unit.init(_u : pmodule;f : byte);
  841. begin
  842. u:=_u;
  843. in_interface:=false;
  844. in_uses:=false;
  845. is_stab_written:=false;
  846. unitid:=f;
  847. end;
  848. destructor tused_unit.done;
  849. begin
  850. inherited done;
  851. end;
  852. end.
  853. {
  854. $Log$
  855. Revision 1.19 1998-06-12 10:32:26 pierre
  856. * column problem hopefully solved
  857. + C vars declaration changed
  858. Revision 1.18 1998/06/11 13:58:07 peter
  859. * small fix to let newppu compile
  860. Revision 1.17 1998/06/09 16:01:40 pierre
  861. + added procedure directive parsing for procvars
  862. (accepted are popstack cdecl and pascal)
  863. + added C vars with the following syntax
  864. var C calias 'true_c_name';(can be followed by external)
  865. reason is that you must add the Cprefix
  866. which is target dependent
  867. Revision 1.16 1998/06/04 10:42:19 pierre
  868. * small bug fix in load_ppu or openppu
  869. Revision 1.15 1998/05/28 14:37:53 peter
  870. * default programname is PROGRAM (like TP7) to avoid dup id's
  871. Revision 1.14 1998/05/27 19:45:02 peter
  872. * symtable.pas splitted into includefiles
  873. * symtable adapted for $ifdef NEWPPU
  874. Revision 1.13 1998/05/23 01:21:05 peter
  875. + aktasmmode, aktoptprocessor, aktoutputformat
  876. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  877. + $LIBNAME to set the library name where the unit will be put in
  878. * splitted cgi386 a bit (codeseg to large for bp7)
  879. * nasm, tasm works again. nasm moved to ag386nsm.pas
  880. Revision 1.12 1998/05/20 09:42:33 pierre
  881. + UseTokenInfo now default
  882. * unit in interface uses and implementation uses gives error now
  883. * only one error for unknown symbol (uses lastsymknown boolean)
  884. the problem came from the label code !
  885. + first inlined procedures and function work
  886. (warning there might be allowed cases were the result is still wrong !!)
  887. * UseBrower updated gives a global list of all position of all used symbols
  888. with switch -gb
  889. Revision 1.11 1998/05/12 10:46:59 peter
  890. * moved printstatus to verb_def
  891. + V_Normal which is between V_Error and V_Warning and doesn't have a
  892. prefix like error: warning: and is included in V_Default
  893. * fixed some messages
  894. * first time parameter scan is only for -v and -T
  895. - removed old style messages
  896. Revision 1.10 1998/05/11 13:07:53 peter
  897. + $ifdef NEWPPU for the new ppuformat
  898. + $define GDB not longer required
  899. * removed all warnings and stripped some log comments
  900. * no findfirst/findnext anymore to remove smartlink *.o files
  901. Revision 1.9 1998/05/06 15:04:20 pierre
  902. + when trying to find source files of a ppufile
  903. check the includepathlist for included files
  904. the main file must still be in the same directory
  905. Revision 1.8 1998/05/04 17:54:25 peter
  906. + smartlinking works (only case jumptable left todo)
  907. * redesign of systems.pas to support assemblers and linkers
  908. + Unitname is now also in the PPU-file, increased version to 14
  909. Revision 1.7 1998/05/01 16:38:44 florian
  910. * handling of private and protected fixed
  911. + change_keywords_to_tp implemented to remove
  912. keywords which aren't supported by tp
  913. * break and continue are now symbols of the system unit
  914. + widestring, longstring and ansistring type released
  915. Revision 1.6 1998/05/01 07:43:53 florian
  916. + basics for rtti implemented
  917. + switch $m (generate rtti for published sections)
  918. Revision 1.5 1998/04/30 15:59:40 pierre
  919. * GDB works again better :
  920. correct type info in one pass
  921. + UseTokenInfo for better source position
  922. * fixed one remaining bug in scanner for line counts
  923. * several little fixes
  924. Revision 1.4 1998/04/29 10:33:52 pierre
  925. + added some code for ansistring (not complete nor working yet)
  926. * corrected operator overloading
  927. * corrected nasm output
  928. + started inline procedures
  929. + added starstarn : use ** for exponentiation (^ gave problems)
  930. + started UseTokenInfo cond to get accurate positions
  931. Revision 1.3 1998/04/27 23:10:28 peter
  932. + new scanner
  933. * $makelib -> if smartlink
  934. * small filename fixes pmodule.setfilename
  935. * moved import from files.pas -> import.pas
  936. Revision 1.2 1998/04/21 10:16:47 peter
  937. * patches from strasbourg
  938. * objects is not used anymore in the fpc compiled version
  939. }