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

📄 codegraph.cs

📁 C#编写的c#编译器
💻 CS
📖 第 1 页 / 共 5 页
字号:
using System;
using System.Text;
using System.Collections;
using System.Collections.Specialized;

using DDW.CSharp.SymbolTable;

namespace DDW.CSharp.Dom
{
	#region  IGraph 
	/// <summary>
	/// An interface that all CSharpDom elements must implement.
	/// </summary>
	public interface IGraph 
	{
		/// <exclude/>
		string Text {get;}
		GraphTypes GraphType{get;}
		LinePragma LinePragma{get;}
	}
	#endregion

	#region  CSharpGraph
	/// <summary>
	/// An abstract base class for CSharpDom elements.
	/// </summary>
	public abstract class CSharpGraph : IGraph
	{
		public virtual GraphTypes GraphType{get{return GraphTypes.CSharpGraph;}}
		#region  UserData  
		private IDictionary p_userData = null;
		/// <summary>
		/// Gets or sets the user-definable data for the current object.
		/// </summary>
		public IDictionary				UserData					
		{
			get
			{
				return p_userData;
			}
			set
			{
				p_userData = value;
			}
		}	
		#endregion
		#region  LinePragma
		private LinePragma p_linePragma = new LinePragma();
		public LinePragma				LinePragma		
		{
			get
			{	
				return p_linePragma;
			}
		}
		#endregion

		#region Text
		/// <exclude/>
		public abstract string Text{get;}
		#endregion
		#region GetTypeFromString
		// different assemblies can use this to get dom types.
		public static Type GetTypeFromString(string s)
		{
			Type t = Type.GetType(s);
			if(t == null)
				throw(new Exception("Type not found: " + s) );
			return t;
		}
		#endregion
	}
	#endregion
	#region  CompileUnit  -s
	/// <summary>
	/// A C# file level unit of code. This must be a complete C# file, snippets are not valid.
	/// </summary>
	public class CompileUnit : CSharpGraph, IScope  
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.CompileUnit;}}
		#region  Imports  
		private ImportCollection p_imports = new ImportCollection();
		/// <summary>
		/// Gets the collection of imports ('using' declarations) for this Compile unit.
		/// </summary>
		[CodeCollection]
		public ImportCollection				Imports					
		{
			get
			{
				return p_imports;
			}
		}	
	#endregion	
		#region  Namespaces  
		private NamespaceDeclCollection p_namespaces = new NamespaceDeclCollection();
		/// <summary>
		/// Gets the collection of Namespace Declarations for this Compile unit.
		/// </summary>
		[CodeCollection]
		public NamespaceDeclCollection				Namespaces					
		{
			get
			{
				return p_namespaces;
			}
		}	
	#endregion	
		#region  AssemblyCustomAttributes  
		private CustomAttributeCollection p_assemblyCustomAttributes = new CustomAttributeCollection();
		/// <summary>
		/// Gets the collection of assembly level custom attributes - eg. [assembly:CLSCompliant(true)] for this Compile unit.
		/// </summary>
		[CodeCollection]
		public CustomAttributeCollection				AssemblyCustomAttributes					
		{
			get
			{
				return p_assemblyCustomAttributes;
			}
		}	
	#endregion	
		#region  ReferencedAssemblies  
		private AssemblyReferenceCollection p_referencedAssemblies = 
			new AssemblyReferenceCollection();
		/// <summary>
		/// Gets the collection of referenced assemblies - this does not come from the source code, but rather would be set when invoking the parser.
		/// </summary>
		[CodeCollection]
		public AssemblyReferenceCollection		ReferencedAssemblies	
		{
			get
			{
				return p_referencedAssemblies;
			}
		}	
	#endregion	


		#region ScopeTable
		private ScopeCollection  p_scopeTable = new ScopeCollection();
		/// </exclude>
		public ScopeCollection ScopeTable
		{
			get
			{
				return  p_scopeTable;
			}
		}
		#endregion
		#region  Scope 
		private Scope p_scope; 
		public Scope			Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
	#endregion		
		#region Text
		/// <exclude/>
		public override string Text
		{
			get
			{
				return FileName + " - Compile Unit";
			}
		}
		#endregion
		#region FileName
		private string p_fileName = "";
		/// <summary>
		/// Gets or sets the name of the file being parsed. This is not a Code Element.
		/// </summary>
		public string FileName
		{
			get
			{
				return p_fileName;
			}
			set
			{
				p_fileName = value;
			}
		}
		#endregion

	}
	#endregion
	#region  Import 
	/// <summary>
	/// An import declaration. This maps to the 'using' statement, so it can also be used to set aliases.
	/// </summary>
	public class Import : CSharpGraph  
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.Import;}}
		#region  Namespace 
		private string p_namespace;
		/// <summary>
		/// Gets or sets the namespace to be imported or aliased.
		/// </summary>
		[CodeElement]
		public string				Namespace					
		{
			get
			{
				return p_namespace;
			}
			set
			{
				p_namespace = value;
			}
		}	
	#endregion	
		#region  Alias 
		private string p_alias;
		/// <summary>
		/// Gets or sets the alias of the imported namespace, if present.
		/// </summary>
		[CodeElement]
		public string				Alias					
		{
			get
			{
				return p_alias;
			}
			set
			{
				p_alias = value;
			}
		}	
	#endregion	

		#region Text
		/// <exclude/>
		public override string Text
		{
			get
			{
				return "Import";
			}
		}
		#endregion
	}
	#endregion
	#region  NamespaceDecl  -ds
	/// <summary>
	/// A namespace declaration.
	/// </summary>
	public class NamespaceDecl : CSharpGraph, IScope, IDeclaration  
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.NamespaceDecl;}}
		#region  Imports  
		private ImportCollection p_imports = new ImportCollection();
		/// <summary>
		/// Gets the collection of imports ('using' declarations) for this namespace.
		/// </summary>
		[CodeCollection]
		public ImportCollection				Imports					
		{
			get
			{
				return p_imports;
			}
		}	
	#endregion	
		#region  Name  
		/// <summary>
		/// Gets or sets the name of the namespace. This may use dot syntax.
		/// </summary>
		[CodeElement]
		public string				Name					
		{
			get
			{
				return p_definition.Name;
			}
			set
			{
				p_definition.Name = value;
			}
		}	
	#endregion	
		#region  Types  
		private TypeDeclCollection p_types = new TypeDeclCollection();
		/// <summary>
		/// A collection of types declared in this namespace (classes, interfaces, structs, etc).
		/// </summary>
		[CodeCollection]
		public TypeDeclCollection				Types					
		{
			get
			{
				return p_types;
			}
			set
			{
				p_types = value;
			}
		}	
		#endregion	

		#region Definition
		private IDefinition p_definition = new Definition();
		/// <summary>
		/// Gets the (scoped) definition.
		/// </summary>
		public IDefinition Definition
		{
			get
			{
				return p_definition;
			}
		}
		#endregion
		#region  Scope 
		private Scope p_scope; 
		public Scope			Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
		#endregion	
		#region Text
		/// <exclude/>
		public override string Text
		{
			get
			{
				return p_definition.ToString();
			}
		}
		#endregion
	}
	#endregion

	#region  MemberDecl  
	/// <summary>
	/// An abstract class for all types (class, struct...) and type members (method, field...).
	/// </summary>
	public abstract class MemberDecl : CSharpGraph 
	{
		public abstract MemberKind MemberKind{get;}
		#region  Attributes  
		private Modifiers p_attributes = new Modifiers(); 
		/// <summary>
		/// Gets or sets the modifier flags for this member (public, private etc).
		/// </summary>
		[CodeElement]
		public Modifiers				Attributes					
		{
			get
			{
				return p_attributes;
			}
			set
			{
				p_attributes = value;
			}
		}	
	#endregion	
		#region  CustomAttributes  
		private CustomAttributeCollection p_customAttributes = new CustomAttributeCollection();
		/// <summary>
		/// Gets the collection of Custom Attributes used for this member (custom attributes are the ones declared between brackets, like [Flags]).
		/// </summary>
		[CodeCollection]
		public CustomAttributeCollection				CustomAttributes					
		{
			get
			{
				return p_customAttributes;
			}
		}	
	#endregion	
		#region  Comments  
		private CommentStmtCollection p_comments = new CommentStmtCollection();
		/// <summary>
		/// Gets the collection of comments for this member.
		/// </summary>
		[CodeCollection]
		public CommentStmtCollection				Comments					
		{
			get
			{
				return p_comments;
			}
		}	
	#endregion
		protected virtual bool				VerifyModifiers()		
		{
			return true;
		}
		#region Text
		/// <exclude/>
		public override string Text
		{
			get
			{
				string s = this.GetType().Name;
				s = s.Substring(0, s.LastIndexOf("Decl"));
				return s; //+ ": " + Name;
			}
		}
		#endregion
	}
	#endregion
		#region  MethodDecl  -ds
	/// <summary>
	/// A method declaration.
	/// </summary>
	public class MethodDecl : MemberDecl, IDeclaration, IScope, IOverloadable   
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.MethodDecl;}}
		public override MemberKind MemberKind{get{return MemberKind.Method;}}
			#region  Name 
		/// <summary>
		/// Gets or sets the name of the method. This may use dot syntax.
		/// </summary>
		[CodeElement]
		public string				Name					
		{
			get
			{
				return p_definition.Name;
			}
			set
			{
				p_definition.Name = value;
			}
		}	
	#endregion	
			#region  Parameters  
		private ParamDeclCollection p_parameters = new ParamDeclCollection();
		/// <summary>
		/// Gets the collection of parameters for the method. Each of these hold information about the type, direction etc.
		/// </summary>
		[CodeCollection]
		public ParamDeclCollection			Parameters					
		{
			get
			{
				return p_parameters;
			}
		}	
	#endregion	
			#region  ReturnType  
		private TypeRef p_returnType;
		/// <summary>
		/// Gets or sets the return type of the method.
		/// </summary>
		[CodeElement]
		public TypeRef				ReturnType					
		{
			get
			{
				return p_returnType;
			}
			set
			{
				p_returnType = value;
			}
		}	
			#endregion			
			#region  ReturnTypeCustomAttributes  
		private CustomAttributeCollection p_returnTypeCustomAttributes = 
			new CustomAttributeCollection();
		/// <summary>
		/// Gets the collection of custom attributes that apply to the return type of the method.
		/// </summary>
		[CodeCollection]
		public CustomAttributeCollection	ReturnTypeCustomAttributes		
		{
			get
			{
				return p_returnTypeCustomAttributes;
			}
		}	
			#endregion			
			#region  Statements  
		private StatementCollection p_statements = new StatementCollection();
		/// <summary>
		/// Gets the collection of statements in the method.
		/// </summary>
		[CodeCollection]
		public StatementCollection				Statements					
		{
			get
			{
				return p_statements;
			}
		}	
		#endregion		
		#region Definition
		private IDefinition p_definition = new OverloadableDefinition();
		/// <summary>
		/// Gets the (scoped) definition.
		/// </summary>
		public IDefinition Definition
		{
			get
			{
				return p_definition;
			}
		}
		#endregion
		#region  Scope 
		private Scope p_scope; 
		public Scope			Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
		#endregion	

		#region HashText
		/// <exclude/>
		/// <summary>
		/// Gets the hash string of this defintion. This is of the form Name@Out:param1@Ref:param2...
		/// </summary>
		public string HashText
		{
			get
			{
				string s = this.Name;
				foreach(ParamDecl pd in Parameters)
				{
					s += "@" + pd.Direction.ToString();
					s += ":" + pd.Type.TypeName;
				}
				return s;
			}
		}
		#endregion
		#region Text
		/// <exclude/>
		public override string Text
		{
			get
			{
				string s = this.GetType().Name;
				s = s.Substring(0, s.LastIndexOf("Decl"));
				s += " - ";
				if(Definition == null) s += this.Name;
				else s += Definition.ToString();
				return s; //+ ": " + Name;
			}
		}
		#endregion

⌨️ 快捷键说明

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