DIRECTORY
ConvertUnsafe USING [SubString, SubStringToRope],
LupineSymbolTable
USING [
STBase, String, SymbolHandle, SymbolID, TypeHandle, TypeID ],
Symbols
USING [Base, CTXIndex, CTXRecord,
HTIndex, HTNull, ISEIndex, ISENull, MDIndex, SEIndex, SENull];
LupineSymbolTableUtilsImpl:
PROGRAM
IMPORTS ConvertUnsafe
EXPORTS LupineSymbolTable
SHARES LupineSymbolTable
= BEGIN OPEN Symbols, ST: LupineSymbolTable;
STBase: TYPE = ST.STBase;
String: TYPE = ST.String;
General operations for types and symbols.
SymbolName:
PUBLIC
PROCEDURE [symbol:
ST.SymbolHandle]
RETURNS [String] =
BEGIN
stb: STBase = symbol.base;
IF IsAnonymous[symbol]
THEN RETURN[NIL]
ELSE RETURN[IseiString[stb, symbol.symbol]]
END;
IsAnonymous:
PUBLIC
PROCEDURE [symbol:
ST.SymbolHandle]
RETURNS [yes: BOOLEAN] =
{RETURN[symbol.base.seb[symbol.symbol].hash = HTNull]};
SymbolType:
PUBLIC
PROCEDURE [symbol:
ST.SymbolHandle]
RETURNS [type: ST.TypeHandle] = {
RETURN[ST.TypeHandle[symbol.base, SymType[symbol.base, symbol.symbol]]]};
SymType:
PUBLIC
PROCEDURE [stb: STBase, isei: ISEIndex]
RETURNS [SEIndex] =
INLINE BEGIN
RETURN[
IF stb.seb[isei].idType = SENull
THEN ERROR ELSE stb.seb[isei].idType];
END;
SymbolUniqueID:
PUBLIC
PROCEDURE [symbol:
ST.SymbolHandle]
RETURNS [uniqueID: ST.SymbolID] = {
RETURN[LOOPHOLE[@symbol.base.seb[symbol.symbol]]]};
MakeTypeID:
PUBLIC PROC [t:
ST.TypeHandle]
RETURNS [id:
ST.TypeID] = {
sei: Symbols.SEIndex ← t.type;
lastISei: Symbols.ISEIndex ← Symbols.ISENull;
defCtx: Symbols.CTXIndex;
seb: Symbols.Base = t.base.seb;
ctxb: Symbols.Base = t.base.ctxb;
mdb: Symbols.Base = t.base.mdb;
id.stamp.time𡤀 -- Denote failure, just in case
DO
WITH eb: seb[sei]
SELECT
FROM
id => {lastISei ← LOOPHOLE[sei]; sei ← eb.idInfo};
cons => EXIT;
ENDCASE;
ENDLOOP;
IF lastISei = Symbols.ISENull THEN RETURN;
id.sei ← seb[lastISei].idValue;
IF id.sei = Symbols.ISENull THEN id.sei ← lastISei;
defCtx ← seb[lastISei].idCtx;
WITH cc: ctxb[defCtx]
SELECT
FROM
simple => id.stamp ← t.base.stHandle.version;
included => id.stamp ← mdb[cc.module].stamp;
ENDCASE => ERROR;
};
IseiString:
PROCEDURE [stb: STBase, isei: ISEIndex]
RETURNS[ String] =
INLINE BEGIN
RETURN[HtiString[stb,
(IF isei=ISENull THEN HTNull ELSE stb.seb[isei].hash)]]
END;
HtiSubString:
PROCEDURE [stb: STBase, hti: HTIndex]
RETURNS[ConvertUnsafe.SubString] =
INLINE BEGIN -- hti=HTNull is OK; returns null substring.
RETURN[stb.SubStringForName[hti]];
END;
HtiString:
PROCEDURE [stb: STBase, hti: HTIndex]
RETURNS[String] =
BEGIN
RETURN[ConvertUnsafe.SubStringToRope[HtiSubString[stb, hti]]]
END;
END. -- LupineSymbolTableImpl.