files.pas 34 KB

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