2
0

files.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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. 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.28 1998-06-25 08:48:12 florian
  882. * first version of rtti support
  883. Revision 1.27 1998/06/24 14:48:34 peter
  884. * ifdef newppu -> ifndef oldppu
  885. Revision 1.26 1998/06/17 14:36:19 peter
  886. * forgot an $ifndef OLDPPU :(
  887. Revision 1.25 1998/06/17 14:10:11 peter
  888. * small os2 fixes
  889. * fixed interdependent units with newppu (remake3 under linux works now)
  890. Revision 1.24 1998/06/16 08:56:20 peter
  891. + targetcpu
  892. * cleaner pmodules for newppu
  893. Revision 1.23 1998/06/15 14:44:36 daniel
  894. * BP updates.
  895. Revision 1.22 1998/06/14 18:25:41 peter
  896. * small fix with crc in newppu
  897. Revision 1.21 1998/06/13 00:10:05 peter
  898. * working browser and newppu
  899. * some small fixes against crashes which occured in bp7 (but not in
  900. fpc?!)
  901. Revision 1.20 1998/06/12 14:50:48 peter
  902. * removed the tree dependency to types.pas
  903. * long_fil.pas support (not fully tested yet)
  904. Revision 1.19 1998/06/12 10:32:26 pierre
  905. * column problem hopefully solved
  906. + C vars declaration changed
  907. Revision 1.18 1998/06/11 13:58:07 peter
  908. * small fix to let newppu compile
  909. Revision 1.17 1998/06/09 16:01:40 pierre
  910. + added procedure directive parsing for procvars
  911. (accepted are popstack cdecl and pascal)
  912. + added C vars with the following syntax
  913. var C calias 'true_c_name';(can be followed by external)
  914. reason is that you must add the Cprefix
  915. which is target dependent
  916. Revision 1.16 1998/06/04 10:42:19 pierre
  917. * small bug fix in load_ppu or openppu
  918. Revision 1.15 1998/05/28 14:37:53 peter
  919. * default programname is PROGRAM (like TP7) to avoid dup id's
  920. Revision 1.14 1998/05/27 19:45:02 peter
  921. * symtable.pas splitted into includefiles
  922. * symtable adapted for $ifndef OLDPPU
  923. Revision 1.13 1998/05/23 01:21:05 peter
  924. + aktasmmode, aktoptprocessor, aktoutputformat
  925. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  926. + $LIBNAME to set the library name where the unit will be put in
  927. * splitted cgi386 a bit (codeseg to large for bp7)
  928. * nasm, tasm works again. nasm moved to ag386nsm.pas
  929. Revision 1.12 1998/05/20 09:42:33 pierre
  930. + UseTokenInfo now default
  931. * unit in interface uses and implementation uses gives error now
  932. * only one error for unknown symbol (uses lastsymknown boolean)
  933. the problem came from the label code !
  934. + first inlined procedures and function work
  935. (warning there might be allowed cases were the result is still wrong !!)
  936. * UseBrower updated gives a global list of all position of all used symbols
  937. with switch -gb
  938. Revision 1.11 1998/05/12 10:46:59 peter
  939. * moved printstatus to verb_def
  940. + V_Normal which is between V_Error and V_Warning and doesn't have a
  941. prefix like error: warning: and is included in V_Default
  942. * fixed some messages
  943. * first time parameter scan is only for -v and -T
  944. - removed old style messages
  945. Revision 1.10 1998/05/11 13:07:53 peter
  946. + $ifndef OLDPPU for the new ppuformat
  947. + $define GDB not longer required
  948. * removed all warnings and stripped some log comments
  949. * no findfirst/findnext anymore to remove smartlink *.o files
  950. Revision 1.9 1998/05/06 15:04:20 pierre
  951. + when trying to find source files of a ppufile
  952. check the includepathlist for included files
  953. the main file must still be in the same directory
  954. Revision 1.8 1998/05/04 17:54:25 peter
  955. + smartlinking works (only case jumptable left todo)
  956. * redesign of systems.pas to support assemblers and linkers
  957. + Unitname is now also in the PPU-file, increased version to 14
  958. Revision 1.7 1998/05/01 16:38:44 florian
  959. * handling of private and protected fixed
  960. + change_keywords_to_tp implemented to remove
  961. keywords which aren't supported by tp
  962. * break and continue are now symbols of the system unit
  963. + widestring, longstring and ansistring type released
  964. Revision 1.6 1998/05/01 07:43:53 florian
  965. + basics for rtti implemented
  966. + switch $m (generate rtti for published sections)
  967. Revision 1.5 1998/04/30 15:59:40 pierre
  968. * GDB works again better :
  969. correct type info in one pass
  970. + UseTokenInfo for better source position
  971. * fixed one remaining bug in scanner for line counts
  972. * several little fixes
  973. Revision 1.4 1998/04/29 10:33:52 pierre
  974. + added some code for ansistring (not complete nor working yet)
  975. * corrected operator overloading
  976. * corrected nasm output
  977. + started inline procedures
  978. + added starstarn : use ** for exponentiation (^ gave problems)
  979. + started UseTokenInfo cond to get accurate positions
  980. Revision 1.3 1998/04/27 23:10:28 peter
  981. + new scanner
  982. * $makelib -> if smartlink
  983. * small filename fixes pmodule.setfilename
  984. * moved import from files.pas -> import.pas
  985. Revision 1.2 1998/04/21 10:16:47 peter
  986. * patches from strasbourg
  987. * objects is not used anymore in the fpc compiled version
  988. }