files.pas 33 KB

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