-- RTSymbols.mesa
-- Last Modified By Paul Rovner On December 20, 1982 4:03 pm

DIRECTORY
BcdDefs USING[SGIndex, VersionStamp, NullVersion],
BcdOps USING[BcdBase],
PrincOps USING[GlobalFrameHandle],
RCMap USING[Index],
Rope USING[ROPE],
RTBasic USING[Type],
Symbols USING[MDIndex, CTXIndex, ISEIndex, RecordSEIndex, SEIndex, HTIndex, SENull,
CSEIndex, BTNull, RootBti, BTIndex, BodyRecord, MDNull, codeCHAR,
CBTIndex, ICBTIndex, ExtensionType, typeTYPE, StandardContext,
ContextLevel, lL, CTXNull, HTNull, typeANY, OwnMdi, lZ, codeINT],
SymbolSegment USING [FGTEntry, FGHeader],
SymbolTable USING[Base, Handle, nullHandle],
Tree USING[Index, Link];

RTSymbols: DEFINITIONS
= BEGIN


--TYPEs--
ROPE: TYPE = Rope.ROPE;
Type: TYPE = RTBasic.Type;
SymbolTableBase: TYPE = SymbolTable.Base;
SymbolTableHandle: TYPE = SymbolTable.Handle;
SymbolIndex: TYPE = Symbols.SEIndex;
SymbolIdIndex: TYPE = Symbols.ISEIndex;
SymbolConstructorIndex: TYPE = Symbols.CSEIndex;
SymbolRecordIndex: TYPE = Symbols.RecordSEIndex;
SymbolContextIndex: TYPE = Symbols.CTXIndex;
SymbolNameIndex: TYPE = Symbols.HTIndex;
SymbolModuleIndex: TYPE = Symbols.MDIndex;
BodyIndex: TYPE = Symbols.BTIndex;
CallableBodyIndex: TYPE = Symbols.CBTIndex;
InnerCallableBodyIndex: TYPE = Symbols.ICBTIndex;
FineGrainTableEntry: TYPE = SymbolSegment.FGTEntry;
FineGrainTableHeader: TYPE = SymbolSegment.FGHeader;
BodyTableEntry: TYPE = Symbols.BodyRecord;
ExtensionClass: TYPE = Symbols.ExtensionType;
TreeIndex: TYPE = Tree.Index;
TreeLink: TYPE = Tree.Link;
BlockContextLevel: TYPE = Symbols.ContextLevel;
StandardSymbolContextIndex: TYPE = Symbols.StandardContext;

--Constants--
AnyVersion: BcdDefs.VersionStamp = BcdDefs.NullVersion;
nullHandle: SymbolTableHandle = SymbolTable.nullHandle;
nullSymbolIndex: SymbolIndex = Symbols.SENull;
nullSymbolContextIndex: SymbolContextIndex = Symbols.CTXNull;
nullSymbolNameIndex: SymbolNameIndex = Symbols.HTNull;
symbolIndexForTYPE: SymbolConstructorIndex = Symbols.typeTYPE;
symbolIndexForANY: SymbolConstructorIndex = Symbols.typeANY;
nullBodyIndex: BodyIndex = Symbols.BTNull;
rootBodyIndex: BodyIndex = Symbols.RootBti;
nullModuleIndex: Symbols.MDIndex = Symbols.MDNull;
thisModuleIndex: Symbols.MDIndex = Symbols.OwnMdi;
contextLevelZero: BlockContextLevel = Symbols.lZ;
outerContextLevel: BlockContextLevel = Symbols.lL;
typeCodeForINT: CARDINAL = Symbols.codeINT;
typeCodeForCHAR: CARDINAL = Symbols.codeCHAR;


--PROCEDUREs--

-- STB's
AcquireSTB: PROC[sth: SymbolTableHandle, mesaSymbolsOK: BOOLEANFALSE]
RETURNS[SymbolTableBase];

ReleaseSTB: PROC[stb: SymbolTableBase];
-- BEWARE. The client is responsible for matching each AcquireSTB with exactly
-- one ReleaseSTB. In particular, one should be very careful to catch UNWIND
-- in appropriate places and ReleaseSTB. All the awfulness of dangling
-- reference problems obtain at this level in the system.

AcquireSTBFromGFH: PROC[gfh: PrincOps.GlobalFrameHandle,
mesaSymbolsOK: BOOLEANFALSE]
RETURNS[SymbolTableBase];

AcquireSTBFromMDI: PROC[stb: SymbolTableBase, mdi: SymbolModuleIndex,
mesaSymbolsOK: BOOLEANFALSE]
RETURNS[SymbolTableBase];

AcquireSTBFromSGI: PROC[bcd: BcdOps.BcdBase,
sgi: BcdDefs.SGIndex,
mesaSymbolsOK: BOOLEANFALSE]
RETURNS[SymbolTableBase];

AcquireSTBForDefs: PROC[fileName: ROPE--assumed to end with .bcd--]
RETURNS[SymbolTableBase];
-- AcquireSTBForDefs finds a file with the specified name, assumes it to be a
-- DEFS BCD, and acquires the symbol table therein.

Outer: PROC[stb: SymbolTableBase,
mdi: SymbolModuleIndex,
  inner: PROC[base: SymbolTableBase],
  mesaSymbolsOK: BOOLEANFALSE];
-- Outer uses AcquireSTBFromMDI to find the stb referenced by (stb, mdi).
-- It will then pass this stb to inner. Outer is useful when the caller
-- is unable or unwilling to make sure that the stb gets released properly.
-- mesaSymbolsOK = TRUE is an feature used only by the RPC stub generator.
-- It enables acquisition of pre-Cedar symbol tables.

-- Walking symbol table entries
EnumerateRecordIseis: PROC
[ stb: SymbolTableBase,
rsei: SymbolRecordIndex,
p: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[stop: BOOLEAN],
level: CARDINAL ← 0,
  mesaSymbolsOK: BOOLEANFALSE]
RETURNS [stopped: BOOLEAN];
-- EnumerateRecordIseis invokes p once for each record field of (stb, rsei).
-- It deals with incomplete contexts (opening other symbol tables if necesary)
-- and with the linked nature of the symbol table's representation of bound
-- variant records (it enumerates common parts in addition to the variant part).
-- EnumerateRecordIseis uses EnumerateCtxIseis
-- If rsei identifies a variant record
-- then if level = 0
-- then the union or sequence isei will be included in the enumeration
-- else the union or sequence isei will not be included in the enumeration

EnumerateCtxIseis: PROC
[ stb: SymbolTableBase,
ctx: SymbolContextIndex,
proc: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[stop: BOOLEAN],
reallyComplete: BOOLEANFALSE,
  mesaSymbolsOK: BOOLEANFALSE]
RETURNS[stopped: BOOLEAN];
-- EnumerateCtxIseis invokes proc once for each entry in the specified context.
-- It deals with incomplete contexts (opening other symbol tables if necesary).
-- It is called by EnumerateRecordIseis. It uses Outer.
-- "reallyComplete" is used to circumvent an inadequacy in the symbol table's
-- knowledge about the completeness of a context (i.e. whether it has been
-- completely copied from the original symbol table), thus avoiding unneccessary
-- access to the original symbol table via Outer.

CountComponents: PROC [stb: SymbolTable.Base, rsei: SymbolRecordIndex] RETURNS [n: NAT];

IsRC: PROC [stb: SymbolTable.Base, seIndex: SymbolIndex, checkCommon: BOOLEANTRUE]
RETURNS[BOOLEAN];

IsUnion: PROC [stb: SymbolTable.Base, seIndex: SymbolIndex] RETURNS[BOOLEAN];

IsSequence: PROC [stb: SymbolTable.Base, seIndex: SymbolIndex] RETURNS[BOOLEAN];

PeelAllButLast: PROC [stb: SymbolTable.Base, isei: SymbolIdIndex] RETURNS[SymbolIdIndex];
-- remove layers of type identifier re-definition until either a name
-- change or default initialization is specified

-- STH's
NewSymbolHandle: PROC[fileName: ROPE,
base: CARDINAL,
   pages: CARDINAL,
   version: BcdDefs.VersionStamp ← AnyVersion]
RETURNS[SymbolTableHandle];
-- If version # AnyVersion, NewSymbolHandle may
-- return a SymbolTableHandle that identifies a different
-- file and span.

STPages: PROC[sth: SymbolTableHandle] RETURNS[CARDINAL];
-- STPages returns the number of pages in the specified symbol table

-- Types
AcquireType: PROC[stb: SymbolTableBase,
seIndex: SymbolIndex,
canonicalize: BOOLEANFALSE,
rcmi: RCMap.Index ← LAST[RCMap.Index]]
RETURNS[type: Type];
-- If rcmi = LAST[RCMap.Index] THEN compute the rcmap.

AcquireSequenceType: PROC[stb: SymbolTableBase,
sei: SymbolIndex, -- of sequence part
recordSTB: SymbolTableBase, -- for the containing record
recordSEIndex: SymbolRecordIndex --ditto--]
RETURNS[type: Type];

GetTypeSymbols: PROC[type: Type] RETURNS[stb: SymbolTable.Base, sei: SymbolIndex];

GetOriginalTypeSymbols: PROC[type: Type] RETURNS[stb: SymbolTable.Base, sei: SymbolIndex];

-- ROPEs, ATOMs
AcquireRope: PROC[stb: SymbolTableBase, hti: SymbolNameIndex]
RETURNS[ROPE];

AcquireAtom: PROC[stb: SymbolTableBase, hti: SymbolNameIndex]
RETURNS[atom: ATOM];

STBToModuleName: PROC[stb: SymbolTableBase] RETURNS[ROPE];

END.