files.pas 32 KB

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