files.pas 35 KB

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