files.pas 35 KB

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