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

📄 codegraph.cs

📁 C#编写的c#编译器
💻 CS
📖 第 1 页 / 共 5 页
字号:
	/// An operator declartation.
	/// </summary> 
	public class OperatorDecl : MemberDecl, IDeclaration, IScope, IOverloadable  
	{
		// TODO: Operator must be overloadable. Set some custom methods that can get resolved.
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.OperatorDecl;}}

		public override MemberKind MemberKind{get{return MemberKind.Operator;}}
			#region  Type  
		private TypeRef p_type;
		/// <summary>
		/// Gets or sets the type that the operator will affect.
		/// </summary>
		[CodeElement]
		public TypeRef			Type					
		{
			get
			{
				return p_type;
			}
			set
			{
				p_type = value;
			}
		}	
	#endregion	
			#region  FirstParameter  
		/// <summary>
		/// Gets or sets the first object in a unary, binary or conversion overload.
		/// </summary>
		[CodeElement]
		public ParamDecl				FirstParameter					
		{
			get
			{
				return Parameters[0];
			}
			set
			{
				Parameters[0] = value;
			}
		}	
	#endregion
			#region  SecondParameter  
		/// <summary>
		/// Gets or sets the second object in a binary overload (not set for unary and conversion overloads).
		/// </summary>
		[CodeElement]
		public ParamDecl				SecondParameter					
		{
			get
			{
				if(Parameters.Count < 2) return null;
				return Parameters[1];
			}
			set
			{
				if(Parameters.Count == 0) Parameters.Add(null);
				Parameters[1] = value;
			}
		}	
	#endregion
			#region  Operator  
		private OverloadableOperator p_op = OverloadableOperator.Empty;
		/// <summary>
		/// Gets or sets the operator to overload. This can be 'explicit' or 'implicit' in the case of conversion. 
		/// </summary>
		[CodeElement]
		public OverloadableOperator				Operator					
		{
			get
			{
				return p_op;
			}
			set
			{
				p_op = value;
			}
		}	
	#endregion
			#region  Statements  
		private StatementCollection p_statements = new StatementCollection();
		/// <summary>
		/// Gets the collection of statements for the operator declaration.
		/// </summary>
		[CodeCollection]
		public StatementCollection				Statements					
		{
			get
			{
				return p_statements;
			}
		}	
		#endregion
		#region  Parameters  
		private ParamDeclCollection p_parameters = new ParamDeclCollection();
		/// <summary>
		/// Gets the collection of parameters - this is actually just putting the first and second (if present) parameter into a collection.
		/// </summary>
		public ParamDeclCollection				Parameters					
		{
			get
			{
				return p_parameters;
			}
		}	
	#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;
				s += "@" + FirstParameter.Direction.ToString();
				s += ":" + FirstParameter.Type.TypeName;
				s += "@" + SecondParameter.Direction.ToString();
				s += ":" + SecondParameter.Type.TypeName;
				return s;
			}
		}
		#endregion
		#region  Name 
		/// <summary>
		/// Gets the (hashed) name of the operator. This is in the form "@op:Plus" so as to avoid potential conflicts with a method or field named 'Plus'. This is not a code element, just used for type attribution.
		/// </summary>
		/// <exclude/>
		public string				Name					
		{
			get
			{
				return "@op:" + Operator.ToString();
			}
		}	
		#endregion	
		#region Text
		/// <exclude/>
		public override string Text
		{
			get
			{
				string s = this.GetType().Name;
				s = s.Substring(0, s.LastIndexOf("Decl"));
				return s; 
			}
		}
		#endregion
		/// <summary>
		/// A helper method that converts strings to operators. Note: the unary plus and negation strings should have a 'u' appened to differentiate them from addition and subtraction strings.
		/// </summary>
		/// <param name="sop">String to convert to an OverloadableOperator.</param>
		/// <returns>An OverloadableOperator.</returns>
		public static OverloadableOperator OperatorFromString(string sop)
		{
			OverloadableOperator oop = OverloadableOperator.Empty;
			switch(sop)
			{
				case "implicit" :
					oop = OverloadableOperator.Implicit;
					break;
				case "explicit" :
					oop = OverloadableOperator.Explicit;
					break;
				case "+u" :
					oop = OverloadableOperator.UnaryPlus;
					break;
				case "-u" :
					oop = OverloadableOperator.UnaryNegation;
					break;
				case "!" :
					oop = OverloadableOperator.Not;
					break;
				case "~" :
					oop = OverloadableOperator.OnesComplement;
					break;
				case "++" :
					oop = OverloadableOperator.Increment;
					break;
				case "--" :
					oop = OverloadableOperator.Decrement;
					break;
				case "true" :
					oop = OverloadableOperator.True;
					break;
				case "false" :
					oop = OverloadableOperator.False;
					break;
				case "+" :
					oop = OverloadableOperator.Addition;
					break;
				case "-" :
					oop = OverloadableOperator.Subtraction;
					break;
				case "*" :
					oop = OverloadableOperator.Multiply;
					break;
				case "/" :
					oop = OverloadableOperator.Division;
					break;
				case "%" :
					oop = OverloadableOperator.Modulus;
					break;
				case "&" :
					oop = OverloadableOperator.BitwiseAnd;
					break;
				case "|" :
					oop = OverloadableOperator.BitwiseOr;
					break;
				case "^" :
					oop = OverloadableOperator.ExclusiveOr;
					break;
				case "<<" :
					oop = OverloadableOperator.LeftShift;
					break;
				case ">>" :
					oop = OverloadableOperator.RightShift;
					break;
				case "==" :
					oop = OverloadableOperator.Equality;
					break;
				case "!=" :
					oop = OverloadableOperator.Inequality;
					break;
				case ">" :
					oop = OverloadableOperator.GreaterThan;
					break;
				case "<" :
					oop = OverloadableOperator.LessThan;
					break;
				case ">=" :
					oop = OverloadableOperator.GreaterThanOrEqual;
					break;
				case "<=" :
					oop = OverloadableOperator.LessThanOrEqual;
					break;
			}
			return oop;
		}
		/// <summary>
		/// A helper method that converts operators to strings. Note: the unary plus and negation strings returned will NOT have a 'u' appened as that usually isn't desired. 
		/// </summary>
		/// <param name="sop">OverloadableOperator to be converted to text.</param>
		/// <returns>A string representation of the input operator.</returns>
		public static string StringFromOperator(OverloadableOperator sop)
		{
			string oop = "";
			switch(sop)
			{
				case OverloadableOperator.Implicit :
					oop = "implicit";
					break;
				case OverloadableOperator.Explicit :
					oop = "explicit";
					break;
				case OverloadableOperator.UnaryPlus :
					oop = "+";
					break;
				case OverloadableOperator.UnaryNegation :
					oop = "-";
					break;
				case OverloadableOperator.Not :
					oop = "!";
					break;
				case OverloadableOperator.OnesComplement :
					oop = "~";
					break;
				case OverloadableOperator.Increment :
					oop = "++";
					break;
				case OverloadableOperator.Decrement :
					oop = "--";
					break;
				case OverloadableOperator.True :
					oop = "true";
					break;
				case OverloadableOperator.False :
					oop = "false";
					break;
				case OverloadableOperator.Addition :
					oop = "+";
					break;
				case OverloadableOperator.Subtraction :
					oop = "-";
					break;
				case OverloadableOperator.Multiply :
					oop = "*";
					break;
				case OverloadableOperator.Division :
					oop = "/";
					break;
				case OverloadableOperator.Modulus :
					oop = "%";
					break;
				case OverloadableOperator.BitwiseAnd :
					oop = "&";
					break;
				case OverloadableOperator.BitwiseOr :
					oop = "|";
					break;
				case OverloadableOperator.ExclusiveOr :
					oop = "^";
					break;
				case OverloadableOperator.LeftShift :
					oop = "<<";
					break;
				case OverloadableOperator.RightShift :
					oop = ">>";
					break;
				case OverloadableOperator.Equality :
					oop = "==";
					break;
				case OverloadableOperator.Inequality :
					oop = "!=";
					break;
				case OverloadableOperator.GreaterThan :
					oop = ">";
					break;
				case OverloadableOperator.LessThan :
					oop = "<";
					break;
				case OverloadableOperator.GreaterThanOrEqual :
					oop = ">=";
					break;
				case OverloadableOperator.LessThanOrEqual :
					oop = "<=";
					break;
			}
			return oop;
		}
	}
			#endregion
		#region  ConstructorDecl  -ds
	/// <summary>
	/// A constructor declartation.
	/// </summary> 
	public class ConstructorDecl : MemberDecl, IDeclaration, IScope, IOverloadable   
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.ConstructorDecl;}}
		public override MemberKind MemberKind{get{return MemberKind.Constructor;}}
			#region  Name 
		/// <summary>
		/// Gets or sets the name of the constructor (which matches the name of the class).
		/// </summary>
		[CodeElement]
		public string				Name					
		{
			get
			{
				return p_definition.Name;
			}
			set
			{
				p_definition.Name = value;
			}
		}	
	#endregion	
			#region  InvokeBase  
		private bool p_invokeBase = false;
		/// <summary>
		/// Gets or sets a flag that indicates the constructor specifies which base class should be called and thus requires a base call - eg MyDerived():base(i).
		/// </summary>
		[CodeElement]
		public bool				InvokeBase					
		{
			get
			{
				return p_invokeBase;
			}
			set
			{
				p_invokeBase = value;
			}
		}	
	#endregion
			#region  InvokeChain  
		private bool p_invokeChain = false;
		/// <summary>
		/// Gets or sets a flag that indicates the constructor calls a separate overloaded constructor before proceeding - eg MyDerived():this(i).
		/// </summary>
		[CodeElement]
		public bool				InvokeChain					
		{
			get
			{
				return p_invokeChain;
			}
			set
			{
				p_invokeChain = value;
			}
		}	
	#endregion
			#region  BaseParameters  
		private ParamCollection p_baseParameters = new ParamCollection();
		/// <summary>
		/// Gets a collection of parameters to be passed to the base class as the constructor is initialized (the parameters for a ':base()' call).
		/// </summary>
		[CodeCollection]
		public ParamCollection				BaseParameters					
		{
			get
			{
				return p_baseParameters;
			}
		}	
	#endregion	
			#region  ChainParameters  
		private ParamCollection p_chainParameters = new ParamCollection();
		/// <summary>
		/// Gets a collection of parameters to be passed to a separate overloaded constructor as this constructor is initialized (the parameters for a ':this()' call).
		/// </summary>
		[CodeCollection]
		public ParamCollection				ChainParameters					
		{
			get
			{
				return p_chainParameters;
			}
		}	
	#endregion
			#region  Parameters  
		private ParamDeclCollection p_parameters = new ParamDeclCollection();
		/// <summary>
		/// Gets the collection of parameters for the constructor. Each of these hold information about the type, direction etc.
		/// </summary>
		[CodeCollection]
		public ParamDeclCollection				Parameters					
		{
			get
			{
				return p_parameters;
			}
		}	
	#endregion	
			#region  Statements  
		private StatementCollection p_statements = new StatementCollection();
		/// <summary>
		/// Gets the collection of statements in the constructor.
		/// </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
	}
			#endregion
		#region  DestructorDecl  -ds
	/// <summary>
	/// A destructor declartation.
	/// </summary> 
	public class DestructorDecl : MemberDecl, IDeclaration, IScope   
	{
		/// <exclude/>
		public override GraphTypes GraphType{get{return GraphTypes.DestructorDecl;}}

		public override MemberKind MemberKind{get{return MemberKind.Destructor;}}
			#region  Name 
		/// <summary>
		/// Gets or sets the name of the destructor. This does not include the tilde ('~') character, so it matches the class name.
		/// </summary>
		[CodeElement]
		public string				Name					
		{
			get
			{
				return p_definition.Name;
			}
			set
			{
				p_definition.Name = value;
			}
		}	
	#endregion	

⌨️ 快捷键说明

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