files.pas 34 KB

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