Exemplo n.º 1
0
		/// <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;
		}
Exemplo n.º 2
0
		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);
		}
Exemplo n.º 3
0
		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);
		}
Exemplo n.º 4
0
		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);
		}
Exemplo n.º 5
0
		internal bool Contains (string ns, Symbol key)
		{
			IdentificationTable symbols = (IdentificationTable) namespaces [ns];

			if (symbols == null)
				return false;

			return symbols.Contains (key);
		}
Exemplo n.º 6
0
		internal object Get (string ns, Symbol key)
		{
			IdentificationTable symbols = (IdentificationTable) namespaces [ns];

			if (symbols == null)
				return null;

			return symbols.Get (key);
		}
Exemplo n.º 7
0
		/// <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;
		}
Exemplo n.º 8
0
		internal bool InCurrentScope (Symbol id) 
		{
			Hashtable hash = (Hashtable) locals.Peek ();
			return hash.ContainsKey (id.Value) && hash [id.Value] != null;
		}
Exemplo n.º 9
0
		/// <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);
		}
Exemplo n.º 10
0
		/// <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++;
		}
Exemplo n.º 11
0
		/// <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;
		}
Exemplo n.º 12
0
		/// <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;
		}
Exemplo n.º 13
0
		internal bool Contains (Symbol key)
		{
			Binder e = (Binder) dict [key];
			return e != null;
		}
Exemplo n.º 14
0
		internal Binder (object value, Symbol prev_top, Binder tail)
		{
			this.value = value;
			this.prev_top = prev_top;
			this.tail = tail;
		}
Exemplo n.º 15
0
 internal Identifier(AST parent, string id, Location location)
     : base(parent, location)
 {
     this.name = Symbol.CreateSymbol (id);
 }