files.pas 36 KB

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