/// <summary> /// Return the unique symbol associated with a /// string. Repeated calls to CreateSymbol will return the /// same Symbol. /// </summary> internal static Symbol CreateSymbol (string n) { n = LateBinding.MapToInternalName (n); string u = String.Intern (n); Symbol s = (Symbol) dict [u]; if (s == null) { s = new Symbol (u); dict [u] = s; } return s; }
internal bool InCurrentScope (string ns, Symbol id) { IdentificationTable symbols = (IdentificationTable) namespaces [ns]; if (symbols == null) throw new Exception (ns + " does not exist"); return symbols.InCurrentScope (id); }
internal void Enter (string ns, Symbol key, object value) { IdentificationTable symbols = (IdentificationTable) namespaces [ns]; if (symbols == null) throw new Exception (ns + " does not exist"); symbols.Enter (key, value); }
internal void Remove (string ns, Symbol key) { IdentificationTable symbols = (IdentificationTable) namespaces [ns]; if (symbols == null) throw new Exception (ns + " does not exist"); symbols.Remove (key); }
internal bool Contains (string ns, Symbol key) { IdentificationTable symbols = (IdentificationTable) namespaces [ns]; if (symbols == null) return false; return symbols.Contains (key); }
internal object Get (string ns, Symbol key) { IdentificationTable symbols = (IdentificationTable) namespaces [ns]; if (symbols == null) return null; return symbols.Get (key); }
/// <summary> /// Restores the table to what it was at the most recent BeginScope /// that has not already been ended /// </summary> internal void EndScope () { // // Delete all the elements until we find // that top is null, that occurs when we find // the scope marker. // while (top != null) { Binder e = (Binder) dict [top]; // // If there's a chain we delete the first // element of it, otherwise remove the symbol // from the table. // if (e.Tail != null) dict [top] = e.Tail; else dict.Remove (top); top = e.PrevTop; } // // marks.PrevTop always contains the latest symbol // which was bound before the new scope was created. // top = marks.PrevTop; // // delete the latest scope mark // marks = marks.Tail; locals.Pop (); depth--; catch_scope = previous_scope; }
internal bool InCurrentScope (Symbol id) { Hashtable hash = (Hashtable) locals.Peek (); return hash.ContainsKey (id.Value) && hash [id.Value] != null; }
/// <summary> /// Delete symbol from the table /// </summary> internal void Remove (Symbol key) { Binder e = (Binder) dict [key]; if (e != null) if (e.Tail != null) dict [key] = e.Tail; else dict.Remove (key); }
/// <summary> /// Remembers the current state of the table /// </summary> internal void BeginScope (bool catchScope) { previous_scope = catch_scope; catch_scope = catchScope; marks = new Binder (null, top, marks); top = null; locals.Push (new Hashtable ()); depth++; }
/// <summary> /// Bind a key /// </summary> internal void Enter (Symbol key, object value) { Binder e = (Binder) dict [key]; /// <remarks> /// If a Binder's Value is null means that it /// represents a in-transit binding, we must /// set its value to something useful. /// </remarks> if (e != null && e.Value == null) e.Value = value; else { // // If 'key' is already on the table we form a // Binder's chain, otherwise we include the new key // represented with its association object. // dict [key] = new Binder (value, top, (Binder) dict [key]); // // make 'key' the most recent symbol bound // top = key; } Hashtable top_ht = (Hashtable) locals.Peek (); string val = key.Value; top_ht[val] = value; }
/// <summary> /// Gets the object associated to the symbol in the table /// </summary> internal object Get (Symbol key) { Binder e = (Binder) dict [key]; if (e == null) return null; else return e.Value; }
internal bool Contains (Symbol key) { Binder e = (Binder) dict [key]; return e != null; }
internal Binder (object value, Symbol prev_top, Binder tail) { this.value = value; this.prev_top = prev_top; this.tail = tail; }
internal Identifier(AST parent, string id, Location location) : base(parent, location) { this.name = Symbol.CreateSymbol (id); }