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

📄 cfold.cs

📁 C#编译器源代码。Micorsoft开放源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
								((IntConstant) right).Value);						return new IntConstant (res, left.Location);					} else if (left is DecimalConstant) {						decimal res;						if (ec.ConstantCheckState)							res = checked (((DecimalConstant) left).Value /								((DecimalConstant) right).Value);						else							res = unchecked (((DecimalConstant) left).Value /								((DecimalConstant) right).Value);						return new DecimalConstant (res, left.Location);					} else {						throw new Exception ( "Unexepected division input: " + left);					}				} catch (OverflowException){					Error_CompileTimeOverflow (loc);				} catch (DivideByZeroException) {					Report.Error (020, loc, "Division by constant zero");				}								break;							case Binary.Operator.Modulus:				DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);				if (left == null || right == null)					return null;				try {					if (left is DoubleConstant){						double res;												if (ec.ConstantCheckState)							res = checked (((DoubleConstant) left).Value %								       ((DoubleConstant) right).Value);						else							res = unchecked (((DoubleConstant) left).Value %									 ((DoubleConstant) right).Value);												return new DoubleConstant (res, left.Location);					} else if (left is FloatConstant){						float res;												if (ec.ConstantCheckState)							res = checked (((FloatConstant) left).Value %								       ((FloatConstant) right).Value);						else							res = unchecked (((FloatConstant) left).Value %									 ((FloatConstant) right).Value);												return new FloatConstant (res, left.Location);					} else if (left is ULongConstant){						ulong res;												if (ec.ConstantCheckState)							res = checked (((ULongConstant) left).Value %								       ((ULongConstant) right).Value);						else							res = unchecked (((ULongConstant) left).Value %									 ((ULongConstant) right).Value);												return new ULongConstant (res, left.Location);					} else if (left is LongConstant){						long res;												if (ec.ConstantCheckState)							res = checked (((LongConstant) left).Value %								       ((LongConstant) right).Value);						else							res = unchecked (((LongConstant) left).Value %									 ((LongConstant) right).Value);												return new LongConstant (res, left.Location);					} else if (left is UIntConstant){						uint res;												if (ec.ConstantCheckState)							res = checked (((UIntConstant) left).Value %								       ((UIntConstant) right).Value);						else							res = unchecked (((UIntConstant) left).Value %									 ((UIntConstant) right).Value);												return new UIntConstant (res, left.Location);					} else if (left is IntConstant){						int res;						if (ec.ConstantCheckState)							res = checked (((IntConstant) left).Value %								       ((IntConstant) right).Value);						else							res = unchecked (((IntConstant) left).Value %									 ((IntConstant) right).Value);						return new IntConstant (res, left.Location);					} else {						throw new Exception ( "Unexepected modulus input: " + left);					}				} catch (DivideByZeroException){					Report.Error (020, loc, "Division by constant zero");				} catch (OverflowException){					Error_CompileTimeOverflow (loc);				}				break;				//				// There is no overflow checking on left shift				//			case Binary.Operator.LeftShift:				IntConstant ic = right.ToInt (loc);				if (ic == null){					Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);					return null;				}				int lshift_val = ic.Value;				IntConstant lic;				if ((lic = left.ConvertToInt ()) != null)					return new IntConstant (lic.Value << lshift_val, left.Location);				UIntConstant luic;				if ((luic = left.ConvertToUInt ()) != null)					return new UIntConstant (luic.Value << lshift_val, left.Location);				LongConstant llc;				if ((llc = left.ConvertToLong ()) != null)					return new LongConstant (llc.Value << lshift_val, left.Location);				ULongConstant lulc;				if ((lulc = left.ConvertToULong ()) != null)					return new ULongConstant (lulc.Value << lshift_val, left.Location);				Binary.Error_OperatorCannotBeApplied (loc, "<<", lt, rt);				break;				//				// There is no overflow checking on right shift				//			case Binary.Operator.RightShift:				IntConstant sic = right.ToInt (loc);				if (sic == null){					Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);					return null;				}				int rshift_val = sic.Value;				IntConstant ric;				if ((ric = left.ConvertToInt ()) != null)					return new IntConstant (ric.Value >> rshift_val, left.Location);				UIntConstant ruic;				if ((ruic = left.ConvertToUInt ()) != null)					return new UIntConstant (ruic.Value >> rshift_val, left.Location);				LongConstant rlc;				if ((rlc = left.ConvertToLong ()) != null)					return new LongConstant (rlc.Value >> rshift_val, left.Location);				ULongConstant rulc;				if ((rulc = left.ConvertToULong ()) != null)					return new ULongConstant (rulc.Value >> rshift_val, left.Location);				Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);				break;			case Binary.Operator.LogicalAnd:				if (left is BoolConstant && right is BoolConstant){					return new BoolConstant (						((BoolConstant) left).Value &&						((BoolConstant) right).Value, left.Location);				}				break;			case Binary.Operator.LogicalOr:				if (left is BoolConstant && right is BoolConstant){					return new BoolConstant (						((BoolConstant) left).Value ||						((BoolConstant) right).Value, left.Location);				}				break;							case Binary.Operator.Equality:				if (left is BoolConstant && right is BoolConstant){					return new BoolConstant (						((BoolConstant) left).Value ==						((BoolConstant) right).Value, left.Location);								}				if (left is NullLiteral){					if (right is NullLiteral)						return new BoolConstant (true, left.Location);					else if (right is StringConstant)						return new BoolConstant (							((StringConstant) right).Value == null, left.Location);				} else if (right is NullLiteral){					if (left is NullLiteral)						return new BoolConstant (true, left.Location);					else if (left is StringConstant)						return new BoolConstant (							((StringConstant) left).Value == null, left.Location);				}				if (left is StringConstant && right is StringConstant){					return new BoolConstant (						((StringConstant) left).Value ==						((StringConstant) right).Value, left.Location);									}				DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);				if (left == null || right == null)					return null;				bool_res = false;				if (left is DoubleConstant)					bool_res = ((DoubleConstant) left).Value ==						((DoubleConstant) right).Value;				else if (left is FloatConstant)					bool_res = ((FloatConstant) left).Value ==						((FloatConstant) right).Value;				else if (left is ULongConstant)					bool_res = ((ULongConstant) left).Value ==						((ULongConstant) right).Value;				else if (left is LongConstant)					bool_res = ((LongConstant) left).Value ==						((LongConstant) right).Value;				else if (left is UIntConstant)					bool_res = ((UIntConstant) left).Value ==						((UIntConstant) right).Value;				else if (left is IntConstant)					bool_res = ((IntConstant) left).Value ==						((IntConstant) right).Value;				else					return null;				return new BoolConstant (bool_res, left.Location);			case Binary.Operator.Inequality:				if (left is BoolConstant && right is BoolConstant){					return new BoolConstant (						((BoolConstant) left).Value !=						((BoolConstant) right).Value, left.Location);				}				if (left is NullLiteral){					if (right is NullLiteral)						return new BoolConstant (false, left.Location);					else if (right is StringConstant)						return new BoolConstant (							((StringConstant) right).Value != null, left.Location);				} else if (right is NullLiteral){					if (left is NullLiteral)						return new BoolConstant (false, left.Location);					else if (left is StringConstant)						return new BoolConstant (							((StringConstant) left).Value != null, left.Location);				}				if (left is StringConstant && right is StringConstant){					return new BoolConstant (						((StringConstant) left).Value !=						((StringConstant) right).Value, left.Location);									}				DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);				if (left == null || right == null)					return null;				bool_res = false;				if (left is DoubleConstant)					bool_res = ((DoubleConstant) left).Value !=						((DoubleConstant) right).Value;				else if (left is FloatConstant)					bool_res = ((FloatConstant) left).Value !=						((FloatConstant) right).Value;				else if (left is ULongConstant)					bool_res = ((ULongConstant) left).Value !=						((ULongConstant) right).Value;				else if (left is LongConstant)					bool_res = ((LongConstant) left).Value !=						((LongConstant) right).Value;				else if (left is UIntConstant)					bool_res = ((UIntConstant) left).Value !=						((UIntConstant) right).Value;				else if (left is IntConstant)					bool_res = ((IntConstant) left).Value !=						((IntConstant) right).Value;				else					return null;				return new BoolConstant (bool_res, left.Location);			case Binary.Operator.LessThan:				DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);				if (left == null || right == null)					return null;				bool_res = false;				if (left is DoubleConstant)					bool_res = ((DoubleConstant) left).Value <						((DoubleConstant) right).Value;				else if (left is FloatConstant)					bool_res = ((FloatConstant) left).Value <						((FloatConstant) right).Value;				else if (left is ULongConstant)					bool_res = ((ULongConstant) left).Value <						((ULongConstant) right).Value;				else if (left is LongConstant)					bool_res = ((LongConstant) left).Value <						((LongConstant) right).Value;				else if (left is UIntConstant)					bool_res = ((UIntConstant) left).Value <						((UIntConstant) right).Value;				else if (left is IntConstant)					bool_res = ((IntConstant) left).Value <						((IntConstant) right).Value;				else					return null;				return new BoolConstant (bool_res, left.Location);							case Binary.Operator.GreaterThan:				DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);				if (left == null || right == null)					return null;				bool_res = false;				if (left is DoubleConstant)					bool_res = ((DoubleConstant) left).Value >						((DoubleConstant) right).Value;				else if (left is FloatConstant)					bool_res = ((FloatConstant) left).Value >						((FloatConstant) right).Value;				else if (left is ULongConstant)					bool_res = ((ULongConstant) left).Value >						((ULongConstant) right).Value;				else if (left is LongConstant)					bool_res = ((LongConstant) left).Value >						((LongConstant) right).Value;				else if (left is UIntConstant)					bool_res = ((UIntConstant) left).Value >						((UIntConstant) right).Value;				else if (left is IntConstant)					bool_res = ((IntConstant) left).Value >						((IntConstant) right).Value;				else					return null;				return new BoolConstant (bool_res, left.Location);			case Binary.Operator.GreaterThanOrEqual:				DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);				if (left == null || right == null)					return null;				bool_res = false;				if (left is DoubleConstant)					bool_res = ((DoubleConstant) left).Value >=						((DoubleConstant) right).Value;				else if (left is FloatConstant)					bool_res = ((FloatConstant) left).Value >=						((FloatConstant) right).Value;				else if (left is ULongConstant)					bool_res = ((ULongConstant) left).Value >=						((ULongConstant) right).Value;				else if (left is LongConstant)					bool_res = ((LongConstant) left).Value >=						((LongConstant) right).Value;				else if (left is UIntConstant)					bool_res = ((UIntConstant) left).Value >=						((UIntConstant) right).Value;				else if (left is IntConstant)					bool_res = ((IntConstant) left).Value >=						((IntConstant) right).Value;				else					return null;				return new BoolConstant (bool_res, left.Location);			case Binary.Operator.LessThanOrEqual:				DoConstantNumericPromotions (ec, oper, ref left, ref right, loc);				if (left == null || right == null)					return null;				bool_res = false;				if (left is DoubleConstant)					bool_res = ((DoubleConstant) left).Value <=						((DoubleConstant) right).Value;				else if (left is FloatConstant)					bool_res = ((FloatConstant) left).Value <=						((FloatConstant) right).Value;				else if (left is ULongConstant)					bool_res = ((ULongConstant) left).Value <=						((ULongConstant) right).Value;				else if (left is LongConstant)					bool_res = ((LongConstant) left).Value <=						((LongConstant) right).Value;				else if (left is UIntConstant)					bool_res = ((UIntConstant) left).Value <=						((UIntConstant) right).Value;				else if (left is IntConstant)					bool_res = ((IntConstant) left).Value <=						((IntConstant) right).Value;				else					return null;				return new BoolConstant (bool_res, left.Location);			}								return null;		}	}}

⌨️ 快捷键说明

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