Class Context
- Namespace
- EzrSquared.Runtime
- Assembly
- ezrSquared-lib.dll
Stores all user defined variables/constant references, called symbols.
public class Context
- Inheritance
-
objectContext
Constructors
Context(string, bool, Position, Context?, Context?, int)
Creates a new Context.
public Context(string name, bool isStatic, Position startPosition, Context? parent = null, Context? staticContext = null, int linkedContexts = 0)
Parameters
namestringThe name of the Context.
isStaticboolIs this a static Context?
startPositionPositionparentContextstaticContextContextThe static Context in relation to this Context. Can be null.
linkedContextsintThe number of other Contexts which are linked to this. See LinkedContexts.
Exceptions
- ArgumentException
Raised if
isStaticis true and a static Context asstaticContextwas provided at the same time. This is invalid as a Context can either be static or have a static Context related to it, but not both.
Fields
Empty
An empty context.
public static readonly Context Empty
Field Value
Id
The unique identifier of the Context.
public readonly long Id
Field Value
- long
IsStatic
Is this a static Context?
public readonly bool IsStatic
Field Value
- bool
Name
The name of the Context.
public readonly string Name
Field Value
- string
_symbols
The symbols of this Context.
private Dictionary<string, Reference> _symbols
Field Value
- Dictionary<string, Reference>
Properties
Count
The number of symbols in the context.
public int Count { get; }
Property Value
- int
LinkedContexts
Other Contexts which are linked to this.
public Context[] LinkedContexts { get; private set; }
Property Value
- Context[]
Remarks
This allowed the Interpreter to access variables from multiple Contexts while in a local scope.
Parent
public Context? Parent { get; private set; }
Property Value
StartPosition
public Position StartPosition { get; private set; }
Property Value
StaticContext
public Context? StaticContext { get; private set; }
Property Value
Methods
DeepCopy(RuntimeResult, IEzrObject[])
Creates a deep copy of the context.
public Context? DeepCopy(RuntimeResult result, IEzrObject[] excludedSymbols)
Parameters
resultRuntimeResultRuntime result for raising errors/
excludedSymbolsIEzrObject[]Symbols to exclude when copying.
Returns
Remarks
It is the caller's responsibility to handle linked contexts.
~Context()
Destructor.
protected ~Context()
Get(Context?, string, out Reference, AccessMod, bool)
Retrieves the Reference of the requested symbol.
public Context.GetStatus Get(Context? callingContext, string symbol, out Reference objectReference, AccessMod accessibilityModifiers = AccessMod.None, bool ignoreLinkedContexts = false)
Parameters
callingContextContextThe Context from which the operation is being called.
symbolstringThe symbol to retrieve.
objectReferenceReferenceThe resulting Reference.
accessibilityModifiersAccessModAccessibility modifiers of the operation, None by default.
ignoreLinkedContextsboolShould the Context ignore its linked contexts? (Used mainly for retrieving a reference before symbol assignment)
Returns
- Context.GetStatus
The Context.GetStatus, representing the result of the operation.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<KeyValuePair<string, Reference>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<string, Reference>>
An enumerator that can be used to iterate through the collection.
IsContextParent(Context)
private bool IsContextParent(Context context)
Parameters
Returns
IsDefined(string)
Checks if a symbol has been defined in this Context/
public bool IsDefined(string name)
Parameters
namestringThe name of the symbol to check.
Returns
Release()
Releases all references in the context and clears the symbols dictionary.
public void Release()
Set(Context?, string, Reference)
Sets the Reference to a new symbol.
public Context.SetStatus Set(Context? callingContext, string symbol, Reference objectReference)
Parameters
callingContextContextThe Context from which the operation is being called.
symbolstringThe symbol to assign.
objectReferenceReferenceThe reference to assign to the symbol.
Returns
- Context.SetStatus
The Context.SetStatus, representing the result of the operation.
Set(Context?, (IEzrObject Object, string Name), Reference, AccessMod)
Sets a new IEzrObject to an existing Reference.
public (Context.SetStatus, Reference) Set(Context? callingContext, (IEzrObject Object, string Name) newObject, Reference oldReference, AccessMod accessibilityModifiers = AccessMod.None)
Parameters
callingContextContextThe Context from which the operation is being called.
newObject(IEzrObject Object, string Name)The new IEzrObject to be assigned and the name of the symbol, in the format (IEzrObject Object, string Name).
oldReferenceReferenceThe old reference to assign to.
accessibilityModifiersAccessModAccessibility modifiers of the operation, None by default.
Returns
- (Context.SetStatus, Reference)
The Context.SetStatus, representing the result of the operation, and the reference to the set symbol.
Remarks
If oldReference is Empty, the operation is passed onto Set(Context?, string, Reference).
SetNewLinkedContexts(int)
Clears the existing LinkedContexts and creates a new empty System.Array of Contexts.
public void SetNewLinkedContexts(int contexts)
Parameters
contextsintThe number of Contexts to allocate the System.Array for.
UpdateParent(Context)
Updates the parent of this Context/
public void UpdateParent(Context newParent)
Parameters
UpdatePosition(Position)
public void UpdatePosition(Position startPosition)
Parameters
UpdateStaticContext(Context?)
Updates the StaticContext to a new one.
public void UpdateStaticContext(Context? newStaticContext)