2
0

files.pas 36 KB

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