-- FileLists.Mesa  
-- Last edited by Sandman on July 8, 1980  9:06 AM
-- Last edited by Lewis on October 7, 1980  6:30 PM
-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  BcdDefs USING [NullVersion, VersionStamp],
  SegmentDefs USING [PageCount],
  Table USING [Base, Limit];

FileLists: DEFINITIONS =
  BEGIN OPEN BcdDefs;
  
  ulb, feb, ifb, ifdb: READONLY Table.Base;
  
  tablesPages: READONLY SegmentDefs.PageCount;
  
  EnlargingTables: SIGNAL; -- allows client to unlock some segments
  DoneEnlargingTables: SIGNAL; -- allows client to again swap in segments


 -- ********** User-specified file names **********
  
  UserListPtr: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO
    UserListItem;
  ULnil: UserListPtr = LAST[UserListPtr];
  
  UserListItem: TYPE = RECORD [next: UserListPtr, name: StringBody];


 -- ********** Bcd file list **********
  
  fileList: READONLY FE; -- head of sorted file list
  
  FE: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO FileEntry;
  FEnil: FE = LAST[FE];
  
  FileEntry: TYPE = RECORD [
    obsolete: BOOLEAN ← FALSE, -- compiled by old compiler
    erroneous: BOOLEAN ← FALSE, -- compilation errors were found
    next: FE ← FEnil, -- links fe's w/ same hash value
    notAlto: BOOLEAN ← FALSE, -- true if compiled /-A
    crossJumped: BOOLEAN ← FALSE, -- true if compiled /J
    link: FE ← FEnil, -- links fe's in ascending order
    longAlto: BOOLEAN ← FALSE, -- true if compiled /L
    tableCompiled: BOOLEAN ← FALSE, -- true if table-compiled module
    includes: IncFile ← IFnil, -- files included by this one
    tag: BOOLEAN ← FALSE, -- used by list traversers
    busy: BOOLEAN ← FALSE, -- true if already seen on traversal
    includedBy: IncFile ← IFnil, -- files that include this one
    stamp: BcdDefs.VersionStamp ← NullStamp, -- bcd's compiler stamp (if on disk)
    bcdSourceTime: LONG CARDINAL ← NullTime, -- bcd's source time (if on disk)
    sourceTime: LONG CARDINAL ← NullTime, -- time of source (if on disk)
    bad: BOOLEAN ← FALSE, -- true if "bad" (see below)
    source: BOOLEAN ← FALSE, -- true if source on disk
    depth: InclusionDepth ← 1, -- depth in includes tree
    name: StringBody]; -- file name (must be last)
  
  NullStamp: BcdDefs.VersionStamp = BcdDefs.NullVersion; 
  NullTime: LONG CARDINAL = NullStamp.time;

  InclusionDepth: TYPE = [0..37777B];


 -- ********** Info on files including/included by fileList files **********
  
  IncFile: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO
    IncludeFileItem;
  IFnil: IncFile = LAST[IncFile];
  
  IncludeFileItem: TYPE = RECORD [
    link: IncFile ← IFnil,
    fileOpenedByCompiler: BOOLEAN ← TRUE, -- items were actually read for includer
    includeFileDesc: IncFileDesc ← IFDnil];


 -- ********** Included file descriptors **********
 --  (avoid duplication of information in include lists)
  
  IncFileDesc: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO
    IncFileDescItem;
  IFDnil: IncFileDesc = LAST[IncFileDesc];
  
  IncFileDescItem: TYPE = RECORD [
    next: IncFileDesc ← IFDnil, -- links ifd's w/ same hash value
    file: FE ← FEnil,
    stamp: BcdDefs.VersionStamp ← NullStamp]; -- included bcd's stamp in includer


 -- ********** Interface **********
  
  
  Initialize, Finalize: PROC [debugging: BOOLEAN];
  
  InsertInUserList: PROC [fileName: STRING];
  IsInUserList: PROC [fileName: STRING] RETURNS [BOOLEAN];
  
  InsertInFileList: PROC [name: STRING] RETURNS [fe: FE];
  
  InsertIncludeFileItem: PROC [
      incList: IncFile, 
      fe: FE, feName: STRING, stamp: BcdDefs.VersionStamp,
      fileOpenedByCompiler: BOOLEAN] 
    RETURNS [IncFile];
  
  END.