⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symboltables.cs

📁 C#编写的c#编译器
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections;
using DDW.CSharp.Dom;
using System.Reflection;

namespace DDW.CSharp.SymbolTable
{
	#region  Scope 
		public abstract class Scope
		{
		#region  EnclosingScope 
		private Scope p_enclosingScope; 
		/// <summary>
		/// Gets or sets the enclosing scope of the scope.
		/// </summary>
		public Scope				EnclosingScope					
		{
			get
			{
				return p_enclosingScope;
			}
			set
			{
				p_enclosingScope = value;
			}
		}	
		#endregion	
		#region  ChildScopes  
		private ScopeCollection p_childScopes = new ScopeCollection();
		public ScopeCollection				ChildScopes					
		{
			get
			{
				return p_childScopes;
			}
			set
			{
				p_childScopes = value;
			}
		}	
	#endregion	
			
		#region  DefinitionTable 
		private Hashtable p_defs = new Hashtable(); 
		/// <summary>
		/// Gets the hashtable that stored the declared symbol definitions.
		/// </summary>
		public Hashtable	DefinitionTable					
		{
			get
			{
				return p_defs;
			}
		}	
		#endregion			
		#region  Add 
		public void Add(IDefinition d, string name)
		{
			DefinitionTable.Add(name, d);
		}
		#endregion
		#region  AddRange 
		public void AddRange(DefinitionCollection dc)
		{
			foreach(Definition d in dc)
			{
				Add(d, d.Name);
			}
		}
		#endregion			

		#region  Lookup 
		public Definition Lookup(string s)
		{
			Definition d = (Definition)DefinitionTable[s];
			if(d != null) 
				return d;
			else if(EnclosingScope != null) 
				return EnclosingScope.Lookup(s);
			else return null;
		}
		#endregion	
		#region  Insert
		public Definition Insert(string s)
		{
			// todo..
			return null;
		}
		#endregion	
		#region  Validate
		public /*abstract*/ bool Validate()
		{
			return true;
		}
		#endregion	
	}
	#endregion	

	#region  AssemblyScope 
	public class AssemblyScope	: Scope
	{
		#region  Version  
		private string p_version;
		public string				Version					
		{
			get
			{
				return p_version;
			}
			set
			{
				p_version = value;
			}
		}	
	#endregion
	}
	#endregion	
	#region  NamespaceScope 
	public class NamespaceScope : Scope, INamedScope
	{
		#region  Imports  
		private ScopeCollection p_imports = new ScopeCollection();
		public ScopeCollection				Imports					
		{
			get
			{
				return p_imports;
			}
		}	
		#endregion
		#region Definition
		private IDefinition p_definition;
		/// <summary>
		/// Gets or sets the definition of this (named) scope.
		/// </summary>
		public IDefinition Definition
		{
			get
			{
				return p_definition;
			}
			set
			{
				p_definition = value;
			}
		}
		#endregion
	}
	#endregion	
	#region  TypeScope 
	public class TypeScope		: Scope, INamedScope
	{
		#region  Modifiers  
		private Modifiers p_modifiers = Modifiers.Empty;
		public Modifiers				Modifiers					
		{
			get
			{
				return p_modifiers;
			}
			set
			{
				p_modifiers = value;
			}
		}	
	#endregion
		#region  Imports  
		private ScopeCollection p_imports = new ScopeCollection();
		public ScopeCollection				Imports					
		{
			get
			{
				return p_imports;
			}
		}	
	#endregion
		#region  TypeKind  
		private TypeKind p_typeKind = TypeKind.Empty;
		public TypeKind				TypeKind					
		{
			get
			{
				return p_typeKind;
			}
			set
			{
				p_typeKind = value;
			}
		}	
		#endregion
		#region Definition
		private IDefinition p_definition;
		/// <summary>
		/// Gets or sets the definition of this (named) scope.
		/// </summary>
		public IDefinition Definition
		{
			get
			{
				return p_definition;
			}
			set
			{
				p_definition = value;
			}
		}
		#endregion
	}
	#endregion	
	#region  MemberScope 
	public class MemberScope	: Scope, INamedScope
	{	
		#region  Modifiers  
		private Modifiers p_modifiers = new Modifiers();
		public Modifiers				Modifiers					
		{
			get
			{
				return p_modifiers;
			}
			set
			{
				p_modifiers = value;
			}
		}	
	#endregion
		#region  Parameters  
		private DefinitionCollection p_parameters = new DefinitionCollection();
		public DefinitionCollection				Parameters					
		{
			get
			{
				return p_parameters;
			}
			set
			{
				p_parameters = value;
			}
		}	
		#endregion
		#region  MemberKind  
		private MemberKind p_memberKind = MemberKind.Empty;
		public MemberKind				MemberKind					
		{
			get
			{
				return p_memberKind;
			}
			set
			{
				p_memberKind = value;
			}
		}	
		#endregion
		#region Definition
		private IDefinition p_definition;
		/// <summary>
		/// Gets or sets the definition of this (named) scope.
		/// </summary>
		public IDefinition Definition
		{
			get
			{
				return p_definition;
			}
			set
			{
				p_definition = value;
			}
		}
		#endregion
	}
	#endregion	
	#region  BlockScope 
	public class BlockScope		: Scope
	{
	}
	#endregion	

	#region  INamedScope
	/// <summary>
	/// Interface used to differentiate between named scopes (ns, types, members) and unnamed (asm, block).
	/// </summary>
	public interface INamedScope
	{
		IDefinition Definition{get;set;}	
	}
	#endregion	


	#region  IDefinition
	/// <summary>
	/// Interface for Defintions.  Definitions may be variable declarations, or scope declarations that have names (like types or methods, but not blocks or accessors). Note: With members that can declare multiple types at once, like fields or events, the declarator is the IDefinition.
	/// </summary>
	public interface IDefinition
	{
		int Id{get;set;}
		string Name{get;set;}
		string FullName{get;}
		Scope Scope{get;set;}	
		IDeclaration SourceGraph{get;set;}	
		IDeclaration Type{get; set;}
	}
	#endregion	
	#region  Definition 
	/// <summary>
	/// Base class for Definitions. Definitions may be variables, or scopes that have names.
	/// </summary>
	public class Definition : IDefinition
	{
		private int p_id;
		public int Id{get{return p_id;}set{p_id = value;}}
		#region  Name 
		private string p_name = ""; 
		/// <summary>
		/// Gets or sets the given name of the Definition.
		/// </summary>
		public virtual string				Name					
		{
			get
			{
				return p_name;
			}
			set
			{
				p_name = value;
			}
		}	
		#endregion	
		#region  FullName 
		/// <summary>
		/// Gets the full name of the scope (namespace.class.member...).
		/// </summary>
		public string				FullName					
		{
			get
			{
				if(Scope == null) return "";
				// todo: deal with ref'd assemblies etc
				string s = "";
				//TODO: must use path so block scopes can see up
				if(Scope.EnclosingScope is INamedScope)
					s += ((INamedScope)Scope.EnclosingScope).Definition.FullName + ".";
				if(!(SourceGraph is IScope) && Scope is INamedScope)
					s += ((INamedScope)Scope).Definition.Name + ".";
				s += Name;
				return s;
			}
		}	
		#endregion	
		#region  Scope 
		private Scope p_scope; 
		/// <summary>
		/// Gets or sets the scope of the definition.
		/// </summary>
		public Scope				Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
		#endregion	
		#region  Type 
		private IDeclaration p_type;
		/// <summary>
		/// Link to the defining type. Actual types just return a ref to themselves.
		/// </summary>
		public IDeclaration				Type					
		{
			get
			{
				return p_type;
			}
			set
			{
				p_type = value;
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -