-- RTSymbolOps.mesa
-- An interface to operations that actually deal with the actual bits in an actual symbol table.
-- Bifurcation for symbol table bootstrapping occurs below this (and the RTSymbols and
-- RTSymbolDefs) level of abstraction.
-- Last Modified By Paul Rovner On January 7, 1983 2:38 pm

DIRECTORY
PrincOps USING[EPRange, MaxNGfi],
RCMap USING[Index],
Rope USING[ROPE],
RTBasic USING[Type],
RTSymbolDefs USING[SymbolTableBase, SymbolRecordIndex, SymbolIdIndex,
SymbolContextIndex, SymbolIndex, SymbolNameIndex,
SymbolConstructorIndex, SymbolTableHandle, SymbolModuleIndex,
ExtensionClass, TreeLink, BodyIndex, BlockContextLevel,
CallableBodyIndex],
Strings USING[SubString],
TimeStamp USING [Stamp];

RTSymbolOps: DEFINITIONS
= BEGIN OPEN Rope, RTBasic, RTSymbolDefs;


-- PROCS for walking symbol table entries (exported by RTWalkSymbolsImpl)
EnumerateRecordIseis: PROC
[ stb: SymbolTableBase,
rsei: SymbolRecordIndex,
p: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[stop: BOOL],
level: CARDINAL ← 0,
mesaSymbolsOK: BOOLFALSE]
RETURNS [stopped: BOOL];
-- 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: BOOL],
reallyComplete: BOOLFALSE,
mesaSymbolsOK: BOOLFALSE]
RETURNS[stopped: BOOL];
-- 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: SymbolTableBase, rsei: SymbolRecordIndex] RETURNS [n: NAT];

IsRC: PROC [stb: SymbolTableBase, seIndex: SymbolIndex, checkCommon: BOOLTRUE]
RETURNS[BOOL];

IsUnion: PROC [stb: SymbolTableBase, seIndex: SymbolIndex] RETURNS[BOOL];

IsSequence: PROC [stb: SymbolTableBase, seIndex: SymbolIndex] RETURNS[BOOL];

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

SETypeXferMode: PROC[stb: SymbolTableBase, sei: SymbolIndex]
RETURNS[Xfm];
Xfm: TYPE = {none, proc, signalOrError, other};

SETagIDP: PROC[stb: SymbolTableBase, sei: SymbolIndex] RETURNS[BOOL];
-- Is this SymbolIndex a SymbolIdIndex?

SEUnderType: PROC[stb: SymbolTableBase, sei: SymbolIndex] RETURNS[SymbolConstructorIndex];

ISEType: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[SymbolIndex];

BodyType: PROC[stb: SymbolTableBase, bti: BodyIndex] RETURNS[SymbolIndex];

CallableBodyEntryIndex: PROC[stb: SymbolTableBase, cbti: CallableBodyIndex]
RETURNS[[0..PrincOps.EPRange*PrincOps.MaxNGfi)];

SEBitsForType: PROC[stb: SymbolTableBase, sei: SymbolIndex] RETURNS[INT];

IDCardinalValue: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[CARDINAL];

IDCardinalInfo: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[CARDINAL];

BodyLevel: PROC[stb: SymbolTableBase, bti: BodyIndex] RETURNS[BlockContextLevel];

ParentBody: PROC[stb: SymbolTableBase, bti: BodyIndex] RETURNS[BodyIndex];

BodyName: PROC[stb: SymbolTableBase, cbti: CallableBodyIndex] RETURNS[SymbolNameIndex];

RootBodyType: PROC[stb: SymbolTableBase] RETURNS[SymbolIndex];

ISEInfo: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[SymbolIndex];

ISECtx: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[SymbolContextIndex];

ISEFindExtension: PROC[stb: SymbolTableBase, isei: SymbolIdIndex]
RETURNS[ExtensionClass, TreeLink];

STBDirectoryCtx: PROC[stb: SymbolTableBase] RETURNS[SymbolContextIndex];

STBVersion: PROC[stb: SymbolTableBase] RETURNS[TimeStamp.Stamp];

STBSourceVersion: PROC[stb: SymbolTableBase] RETURNS[TimeStamp.Stamp];

ISEName: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[SymbolNameIndex];

ISEPublic: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[BOOL];

ISEExtended: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[BOOL];

ISEConstant: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[BOOL];

ISEImmutable: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[BOOL];

IsTypeSEI: PROC[sei: SymbolIndex] RETURNS[BOOL];

IsTransferConstructorSEI: PROC[stb: SymbolTableBase, sei: SymbolConstructorIndex]
RETURNS[BOOL];

RSEVariant: PROC[stb: SymbolTableBase, rsei: SymbolRecordIndex] RETURNS[BOOL];

STBDirectoryCTX: PROC[stb: SymbolTableBase] RETURNS[SymbolContextIndex];

FirstCtxSe: PROC[stb: SymbolTableBase, ctx: SymbolContextIndex] RETURNS[SymbolIdIndex];

NextSe: PROC[stb: SymbolTableBase, isei: SymbolIdIndex] RETURNS[SymbolIdIndex];

NullISEI: PROC[isei: SymbolIdIndex] RETURNS[BOOL];

NullSEI: PROC[sei: SymbolIndex] RETURNS[BOOL];

NullBTI: PROC[bti: BodyIndex] RETURNS[BOOL];

CallableBTI: PROC[stb: SymbolTableBase, bti: BodyIndex] RETURNS[BOOL];

IsRootBTI: PROC[bti: BodyIndex] RETURNS[BOOL];

NullName: PROC[hti: SymbolNameIndex] RETURNS[BOOL];

NullCtx: PROC[ctx: SymbolContextIndex] RETURNS[BOOL];

NullStb: PROC[stb: SymbolTableBase] RETURNS[BOOL];

NullSth: PROC[sth: SymbolTableHandle] RETURNS[BOOL];

NullModuleIndex: PROC[mdi: SymbolModuleIndex] RETURNS[BOOL];

SubStringForHash: PROC[stb: SymbolTableBase, ss: Strings.SubString, hti: SymbolNameIndex];

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

-- PROCs for acquiring Types, ROPEs, ATOMs (exported by RTTSupportImpl)
AcquireType: PROC[stb: SymbolTableBase,
seIndex: SymbolIndex,
canonicalize: BOOLFALSE,
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];

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

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

END.