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

📄 codegraph.cs

📁 C#编写的c#编译器
💻 CS
📖 第 1 页 / 共 5 页
字号:
			#region  Statements  
		private StatementCollection p_statements = new StatementCollection();
		/// <summary>
		/// Gets the collection of statements in the destructor.
		/// </summary>
		[CodeCollection]
		public StatementCollection				Statements					
		{
			get
			{
				return p_statements;
			}
		}	
		#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
			{
				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
	}
			#endregion
		#region  AccessorDecl  -s
	/// <summary>
	/// An accessor declartation.
	/// </summary> 
	public class AccessorDecl : MemberDecl, IScope   
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.AccessorDecl;}}

		public override MemberKind MemberKind{get{return MemberKind.Accessor;}}
			#region  AccessorModifier  
		private AccessorModifiers p_accessorModifier = AccessorModifiers.Empty;
		/// <summary>
		/// Gets or sets the type of accessor (get, set, add, or remove).
		/// </summary>
		[CodeElement]
		public AccessorModifiers	AccessorModifier	
		{
			get
			{
				return p_accessorModifier;
			}
			set
			{
				p_accessorModifier = value;
			}
		}	
			#endregion
			#region  Statements  
		private StatementCollection p_statements = new StatementCollection();
		/// <summary>
		/// Gets the collection of statements in the accessor.
		/// </summary>
		[CodeCollection]
		public StatementCollection				Statements					
		{
			get
			{
				return p_statements;
			}
		}	
		#endregion
		#region  Scope 
		private Scope p_scope; 
		public Scope			Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
		#endregion	
	}
	#endregion
		#region  EnumMemberDecl  -d
	/// <summary>
	/// An enum declartation.
	/// </summary> 
	public class EnumMemberDecl : MemberDecl, IDeclaration  
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.EnumMemberDecl;}}
		public override MemberKind MemberKind{get{return MemberKind.EnumMember;}}
			#region  Name 
		/// <summary>
		/// Gets or sets the name of the enum.
		/// </summary> 
		[CodeElement]
		public string				Name					
		{
			get
			{
				return p_definition.Name;
			}
			set
			{
				p_definition.Name = value;
			}
		}	
	#endregion	
			#region  Value  
		private Expression p_value;
		/// <summary>
		/// Gets or sets the value of the enum member, if specified.
		/// </summary>
		[CodeElement]
		public Expression				Value					
		{
			get
			{
				return p_value;
			}
			set
			{
				p_value = 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 Text
		/// <exclude/>
		public override string Text
		{
			get
			{
				string s = this.GetType().Name;
				s = s.Substring(0, s.LastIndexOf("Decl"));
				s += " - " + this.Name;
				return s; //+ ": " + Name;
			}
		}
		#endregion
	}
			#endregion

		#region  TypeDecl  
	/// <summary>
	/// An abstract base class for types (classes, structs, interfaces etc). 
	/// </summary> 
	public abstract class TypeDecl : MemberDecl, IDeclaration  
	{
			public abstract TypeKind TypeKind{get;}
			public override MemberKind MemberKind{get{return MemberKind.Type;}}
			#region  TypeAttributes 
		// does this have to go..? From codeDom
		private TypeModifiers p_typeAttributes;
		/// <summary>
		/// Gets or sets the modifiers for the type (public, sealed etc). These values can be or'ed with each other. This was derived from the CodeDom, it may be changed for something more suitable.
		/// </summary>
		[CodeElement]
		public TypeModifiers		TypeAttributes	
		{
			get
			{
				return p_typeAttributes;
			}
			set
			{
				p_typeAttributes = value;
			}
		}	
			#endregion
			#region  BaseTypes  
		private TypeRefCollection p_baseTypes = new TypeRefCollection();
		/// <summary>
		/// Gets or sets the base types that are inherited by this type.
		/// </summary>
		[CodeCollection]
		public TypeRefCollection				BaseTypes					
		{
			get
			{
				return p_baseTypes;
			}
			set
			{
				p_baseTypes = value;
			}
		}	
			#endregion
			#region  Members  
		private MemberDeclCollection p_members = new MemberDeclCollection();
		/// <summary>
		/// Gets a collection of type members in the current type (methods, fields etc.).
		/// </summary>
		[CodeCollection]
		public MemberDeclCollection				Members					
		{
			get
			{
				return p_members;
			}
		}	
			#endregion
			#region  Name 
		[CodeElement]
		public string				Name					
		{
			get
			{
				return p_definition.Name;
			}
			set
			{
				p_definition.Name = 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 Text
		/// <exclude/>
		public override string Text
		{
			get
			{
//				string s = this.GetType().Name;
//				s = s.Substring(0, s.LastIndexOf("Decl"));
//				s += " - " + this.Name;
//				return s; //+ ": " + Name;
				return Definition.ToString();
			}
		}
		#endregion
		#region DistanceToType
		/// <summary>
		/// Determines if this type is a subtype of the passed type.
		/// </summary>
		/// <param name="baseType">Base type to check.</param>
		/// <returns>True if this is a subtype.</returns>
		public abstract int DistanceToType(IDefinition baseType, int distance);
		#endregion

	}
		#endregion
			#region  ClassDecl  -ds
	/// <summary>
	/// A class declartation.
	/// </summary> 
	public class ClassDecl : TypeDecl, IScope
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.ClassDecl;}}
		public override TypeKind TypeKind{get{return TypeKind.Class;}}
		#region  Scope 
		private Scope p_scope; 
		public Scope			Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
		#endregion	
		#region  Constructors 
		public OverloadableDefinition	Constructors					
		{
			get
			{
				if(Scope == null) return null;
				return (OverloadableDefinition)Scope.DefinitionTable[this.Name];
			}
		}	
		#endregion	
		#region DistanceToType
		public override int DistanceToType(IDefinition baseType, int distance)
		{
			if(baseType == Definition) return distance;
			distance++;
			foreach(TypeRef tr in BaseTypes)
			{
				if(tr == baseType) return distance;
			}
			foreach(TypeRef tr in BaseTypes)
			{
				int gpDist = 
					((TypeDecl)tr.Definition.SourceGraph).DistanceToType(baseType, distance);
				if(gpDist < Int32.MaxValue) return gpDist;
			}
			if(baseType.Name.ToLower() == "object" && 
				(BaseTypes.Count == 0 || BaseTypes[0].GraphType == GraphTypes.InterfaceDecl))
				return distance;
			return Int32.MaxValue;
		}
    	#endregion

	}
			#endregion
			#region  InterfaceDecl  -ds 
	/// <summary>
	/// An interface declartation.
	/// </summary> 
	public class InterfaceDecl : TypeDecl, IScope
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.InterfaceDecl;}}
		public override TypeKind TypeKind{get{return TypeKind.Interface;}}
		#region  Scope 
		private Scope p_scope; 
		public Scope			Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
		#endregion	
		#region DistanceToType
		public override int DistanceToType(IDefinition baseType, int distance)
		{
			if(baseType == Definition) return distance;
			distance++;
			foreach(TypeRef tr in BaseTypes)
			{
				if(tr == baseType) return distance;
			}
			foreach(TypeRef tr in BaseTypes)
			{
				int gpDist = 
					((TypeDecl)tr.Definition.SourceGraph).DistanceToType(baseType, distance);
				if(gpDist < Int32.MaxValue) return gpDist;
			}
			if(baseType.Name.ToLower() == "object" && 
				(BaseTypes.Count == 0 || BaseTypes[0].GraphType == GraphTypes.InterfaceDecl))
				return distance;
			return Int32.MaxValue;
		}
    	#endregion
	}
			#endregion
			#region  StructDecl  -ds 
	/// <summary>
	/// A struct declartation.
	/// </summary> 
	public class StructDecl : TypeDecl, IScope
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.StructDecl;}}
		public override TypeKind TypeKind{get{return TypeKind.Struct;}}
		#region  Scope 
		private Scope p_scope; 
		public Scope			Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
		#endregion	
		#region  Constructors 
		public OverloadableDefinition	Constructors					
		{
			get
			{
				if(Scope == null) return null;
				return (OverloadableDefinition)Scope.DefinitionTable[this.Name];
			}
		}	
		#endregion	
		#region DistanceToType
		public override int DistanceToType(IDefinition baseType, int distance)
		{
			if(baseType == Definition) return distance;
			distance++;
			foreach(TypeRef tr in BaseTypes)
			{
				if(tr == baseType) return distance;
			}
			foreach(TypeRef tr in BaseTypes)
			{
				int gpDist = 
					((TypeDecl)tr.Definition.SourceGraph).DistanceToType(baseType, distance);
				if(gpDist < Int32.MaxValue) return gpDist;
			}
			if(baseType.Name.ToLower() == "object" && 
				(BaseTypes.Count == 0 || BaseTypes[0].GraphType == GraphTypes.InterfaceDecl))
				return distance;
			return Int32.MaxValue;
		}
    	#endregion
	}
			#endregion
			#region  EnumDecl  -ds 
	/// <summary>
	/// An enum declartation.
	/// </summary> 
	public class EnumDecl : TypeDecl, IScope 
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.EnumDecl;}}
		public override TypeKind TypeKind{get{return TypeKind.Enum;}}
		#region  Scope 
		private Scope p_scope; 
		public Scope			Scope					
		{
			get
			{
				return p_scope;
			}
			set
			{
				p_scope = value;
			}
		}	
		#endregion	
		#region DistanceToType
		public override int DistanceToType(IDefinition baseType, int distance)
		{
			if(baseType == Definition) return distance;
			if(baseType.Name.ToLower() == "object") return 3; // enum ValueType object
			return Int32.MaxValue;
		}
    	#endregion
	}
	#endregion
			#region  DelegateDecl  -d 
	/// <summary>
	/// A delegate declartation.
	/// </summary> 
	public class DelegateDecl : TypeDecl
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.DelegateDecl;}}
		public override TypeKind TypeKind{get{return TypeKind.Delegate;}}

				#region  Parameters  
		private ParamDeclCollection p_parameters = new ParamDeclCollection();
		/// <summary>
		/// Gets the collection of parameters for the delegate. 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 delegate.
		/// </summary>
		[CodeElement]
		public TypeRef				ReturnType					
		{
			get
			{
				return p_returnType;
			}
			set
			{
				p_returnType = value;
			}
		}	
		#endregion
		#region DistanceToType
		public override int DistanceToType(IDefinition baseType, int distance)
		{
			if(baseType == Definition) return distance;
			if(baseType.Name.ToLower() == "object") return 1; // delegate object
			return Int32.MaxValue;
		}
    	#endregion
	}
    		#endregion

	#region  Statement  
	/// <summary>
	/// An abstract base class for statements.
	/// </summary>
	public abstract class Statement : CSharpGraph  
	{
		#region Text
		/// <exclude/>
		public override string Text
		{
			get
			{
				return this.GetType().Name.ToString();
			}
		}
		#endregion
	}
	#endregion
		#region  ExprStmt  
	/// <summary>
	/// A code expression that can be treated as a code statement.
	/// </summary>
	public class ExprStmt : Statement  
	{
		/// <exclude/>

⌨️ 快捷键说明

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