Class InMemorySymbolTable
- All Implemented Interfaces:
SymbolTable
SymbolTable suitable for single-session,
in-process use.
Not thread-safe. External synchronisation is required if the table is shared across threads.
Internal structure
Relations are stored in a two-level map:
namespace (lower-cased) → canonicalName → RelationSymbol.
Functions are stored in a three-level map:
namespace → canonicalName → parameterSignature → FunctionSymbol.
The parameter signature is the ordered list of ScalarType values,
which is used as a List key (equality is value-based).
Both maps use LinkedHashMap so that iteration order reflects
registration order.
Shadow policy
When a symbol conflicts with an existing one, the existing
symbol's ShadowPolicy is consulted:
ShadowPolicy.FORBIDDEN— the new symbol is rejected; the table is unchanged.ShadowPolicy.PERMITTED— the new symbol replaces the old one silently.ShadowPolicy.WARN_AND_PERMIT— the new symbol replaces the old one, and aSymbolError.Kind.SHADOW_WARNINGis added to the result.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a snapshot of all symbols currently registered in the table, in registration order.lookupFunction(String name) Returns all overloads of the function with the givennamefrom the"default"namespace, then the"builtin"namespace.lookupFunction(String namespace, String name) Returns all overloads of the function with the givennamein the specifiednamespace.lookupFunction(String name, List<ScalarType> paramTypes) Returns the unique overload of the function namednamewhose parameter signature exactly matchesparamTypes, searching"default"then"builtin".lookupRelation(String name) Returns the relation with the givennamefrom the"default"namespace, or — if not found there — from the"builtin"namespace.lookupRelation(String namespace, String name) Returns the relation with the givennamein the specifiednamespace.Attempts to registersymbolin the table.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.darkcollective.relix.symbol.table.SymbolTable
resolveFunction, resolveRelation
-
Constructor Details
-
InMemorySymbolTable
public InMemorySymbolTable()
-
-
Method Details
-
register
Description copied from interface:SymbolTableAttempts to registersymbolin the table.If a symbol with the same namespace and canonical name (and, for functions, the same parameter signature) already exists, the existing symbol's
ShadowPolicygoverns the outcome.- Specified by:
registerin interfaceSymbolTable- Parameters:
symbol- the symbol to register; must not be null- Returns:
- a result describing whether the symbol was accepted, warned, or rejected
-
lookupRelation
Description copied from interface:SymbolTableReturns the relation with the givennamefrom the"default"namespace, or — if not found there — from the"builtin"namespace.- Specified by:
lookupRelationin interfaceSymbolTable- Parameters:
name- the relation name (case-insensitive)- Returns:
- the matching relation symbol, or empty if none found
-
lookupRelation
Description copied from interface:SymbolTableReturns the relation with the givennamein the specifiednamespace.- Specified by:
lookupRelationin interfaceSymbolTable- Parameters:
namespace- the target namespace (case-insensitive)name- the relation name (case-insensitive)- Returns:
- the matching relation symbol, or empty if none found
-
lookupFunction
Description copied from interface:SymbolTableReturns all overloads of the function with the givennamefrom the"default"namespace, then the"builtin"namespace.- Specified by:
lookupFunctionin interfaceSymbolTable- Parameters:
name- the function name (case-insensitive)- Returns:
- all matching function symbols; never null, may be empty
-
lookupFunction
Description copied from interface:SymbolTableReturns all overloads of the function with the givennamein the specifiednamespace.- Specified by:
lookupFunctionin interfaceSymbolTable- Parameters:
namespace- the target namespace (case-insensitive)name- the function name (case-insensitive)- Returns:
- all matching function symbols; never null, may be empty
-
lookupFunction
Description copied from interface:SymbolTableReturns the unique overload of the function namednamewhose parameter signature exactly matchesparamTypes, searching"default"then"builtin".- Specified by:
lookupFunctionin interfaceSymbolTable- Parameters:
name- the function name (case-insensitive)paramTypes- the ordered list of argument types to match- Returns:
- the matching overload, or empty if no exact match exists
-
allSymbols
Description copied from interface:SymbolTableReturns a snapshot of all symbols currently registered in the table, in registration order.- Specified by:
allSymbolsin interfaceSymbolTable- Returns:
- an unmodifiable collection of all symbols; never null
-