-- PackTree.Mesa  Last edited by Lewis on  1-Apr-81 16:08:56

DIRECTORY
  CodePackProcs USING [ModuleIndex, NullModuleIndex],
  PackagerDefs USING [packtreetype],
  SemanticEntry USING [STIndex],
  SymTabDefs USING [HTIndex, HTNull],
  Table USING [Base, Finger, Limit, Selector];

Tree: DEFINITIONS = 
  BEGIN

  treeType: Table.Selector = PackagerDefs.packtreetype;

  root: Tree.Link; -- root of package description tree (exported by TreeBuild)

  Link: TYPE = RECORD [
    SELECT tag: * FROM
      subtree => [index: Tree.Index],
      hash    => [index: SymTabDefs.HTIndex],
      symbol  => [index: SemanticEntry.STIndex],
      procs   => [index: CodePackProcs.ModuleIndex], -- procs in a code pack
      ENDCASE];

  Null:      Tree.Link = [subtree[index: Tree.NullIndex]];
  NullId:    Tree.Link = [hash[index: SymTabDefs.HTNull]];
  NullProcs: Tree.Link = [procs[index: CodePackProcs.NullModuleIndex]];

  Index: TYPE = Table.Base RELATIVE POINTER [0..Table.Limit) TO Tree.Node;
    NullIndex: Tree.Index = FIRST[Tree.Index];

  Node: TYPE = MACHINE DEPENDENT RECORD [
    free:   BOOLEAN,	      -- reserved for allocator
    name:   NodeName,
    nSons:  [0..MaxNSons],
    info:   UNSPECIFIED,      -- (source file index)
    cp:     Tree.Index,       -- enclosing code pack node if component desc
    shared: BOOLEAN,
    attr1:  BOOLEAN,          -- attr1 = EXCEPT[MAIN] if code pack node
    seg:    Tree.Index,       -- enclosing segment node if component desc
    attr2, attr3: BOOLEAN,    -- attr2=superceded, 3=placed if code pack, seg
    son:    ARRAY [1..1) OF Tree.Link];

  MaxNSons: CARDINAL = 1777B; -- largest list without null terminator

  NodeName: TYPE = {
   -- general tree constructor
    list,

   -- declarations
    codeSeg,
    codePack,
    unnamedCodePack,
    discardCodePack,
    framePack,
    merge,
    mergeFP,

   -- component descriptions
    allComp,          -- ComponentDesc ::= Component
    compItems,        -- ComponentDesc ::= Component [ItemList]
    exceptItems,      -- ComponentDesc ::= Component EXCEPT [ItemList]
    exceptPacks,      -- ComponentDesc ::= Component EXCEPT PackList
    itemsExceptPacks, -- ComponentDesc ::= Component [ItemList] EXCEPT PackList
    exceptPacksItems, -- ComponentDesc ::= Component EXCEPT PackList, [ItemList]
    mainProcs,        -- ComponentDesc ::= MAIN OF PackList

   -- expressions
    component,
    main,

   -- nil
    none
    };
    

 -- tree manipulation

  Id:   TYPE = RECORD [baseP: Table.Finger, link: Tree.Link];
  Scan: TYPE = PROC [t: Tree.Link];
  Map:  TYPE = PROC [t: Tree.Link] RETURNS [v: Tree.Link];
  Test: TYPE = PROC [t: Tree.Link] RETURNS [BOOLEAN];

  END.