files.pas 33 KB

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