files.pas 32 KB

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