-- FileLists.Mesa  
-- Last edited by Sandman on July 8, 1980  9:06 AM
-- Last edited by Lewis on  9-Apr-81 16:09:40
-- Last edited by Paul Rovner on June 16, 1982 3:15 pm

DIRECTORY
  BcdDefs USING [NullVersion, VersionStamp],
  IncludeCheckerTable USING [Base, Limit],
  Time USING [Packed];

FileLists: DEFINITIONS =
  BEGIN OPEN BcdDefs;
  
  ulb, feb, ifb, ifdb: READONLY IncludeCheckerTable.Base;
  

 -- ********** User-specified file names **********
  
  UserListPtr: TYPE = IncludeCheckerTable.Base RELATIVE POINTER [0..IncludeCheckerTable.Limit) TO UserListItem;
  ULnil: UserListPtr = LAST[UserListPtr];
  
  UserListItem: TYPE = RECORD [
    next: UserListPtr,  -- next file name with same hash 
    link: UserListPtr,  -- next file name in list 
    name: StringBody];


 -- ********** Bcd file list **********
  
  fileList: READONLY FE; -- head of sorted file list
  
  FE: TYPE = IncludeCheckerTable.Base RELATIVE POINTER [0..IncludeCheckerTable.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
    dStar:       BOOLEAN ← TRUE,    -- 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 /A and /L
    tableCompiled: BOOLEAN ← FALSE, -- true if table-compiled
    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: Time.Packed ← NullTime, -- bcd's source time (if on disk)
    sourceTime:  Time.Packed ← NullTime,   -- time of source (if on disk)
    bad:         BOOLEAN ← FALSE,   -- true if must be recompiled
    source:      BOOLEAN ← FALSE,   -- true if source on disk
    config:      BOOLEAN ← FALSE,   -- true if config rather than module
    depth:       InclusionDepth ← 1,-- depth in includes tree
    name:        StringBody];       -- file name (must be last)
  
  NullStamp: BcdDefs.VersionStamp = BcdDefs.NullVersion; 
  NullTime: Time.Packed = [NullStamp.time];

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


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


 -- ********** Included file descriptors **********
 --  (avoid duplication of information in include lists)
  
  IncFileDesc: TYPE = IncludeCheckerTable.Base RELATIVE POINTER [0..IncludeCheckerTable.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;
  
  InsertInUserList: PROC [fileName: LONG STRING];
  IsInUserList: PROC [fileName: LONG STRING] RETURNS [BOOLEAN];
  EnumerateUserList: PROC [
    userProc: PROC [LONG STRING] RETURNS [BOOLEAN]];
  UserListLength: PROC RETURNS [count: CARDINAL];
  
  InsertInFileList: PROC [name: LONG STRING] RETURNS [fe: FE];
  
  InsertIncludeFileItem: PROC [
      incList: IncFile, 
      fe: FE, feName: LONG STRING, 
      stamp: BcdDefs.VersionStamp,
      fileOpenedByCompiler: BOOLEAN] 
    RETURNS [IncFile];
  
  END.