Skip to content

Commit

Permalink
add support for special methods for operators introduce in C# 11
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Dec 24, 2023
1 parent f2c7110 commit e1755d2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,36 @@ bool throwException
// unary
{ "op_UnaryPlus", MethodSpecialName.UnaryPlus },
{ "op_UnaryNegation", MethodSpecialName.UnaryNegation },
{ "op_CheckedUnaryNegation", MethodSpecialName.CheckedUnaryNegation },
{ "op_LogicalNot", MethodSpecialName.LogicalNot },
{ "op_OnesComplement", MethodSpecialName.OnesComplement },
{ "op_True", MethodSpecialName.True },
{ "op_False", MethodSpecialName.False },
{ "op_Increment", MethodSpecialName.Increment },
{ "op_CheckedIncrement", MethodSpecialName.CheckedIncrement },
{ "op_Decrement", MethodSpecialName.Decrement },
{ "op_CheckedDecrement", MethodSpecialName.CheckedDecrement },

// binary
{ "op_Addition", MethodSpecialName.Addition },
{ "op_CheckedAddition", MethodSpecialName.CheckedAddition },
{ "op_Subtraction", MethodSpecialName.Subtraction },
{ "op_CheckedSubtraction", MethodSpecialName.CheckedSubtraction },
{ "op_Multiply", MethodSpecialName.Multiply },
{ "op_CheckedMultiply", MethodSpecialName.CheckedMultiply },
{ "op_Division", MethodSpecialName.Division },
{ "op_CheckedDivision", MethodSpecialName.CheckedDivision },
{ "op_Modulus", MethodSpecialName.Modulus },
{ "op_BitwiseAnd", MethodSpecialName.BitwiseAnd },
{ "op_BitwiseOr", MethodSpecialName.BitwiseOr },
{ "op_ExclusiveOr", MethodSpecialName.ExclusiveOr },
{ "op_RightShift", MethodSpecialName.RightShift },
{ "op_UnsignedRightShift", MethodSpecialName.UnsignedRightShift },
{ "op_LeftShift", MethodSpecialName.LeftShift },

// type cast
{ "op_Explicit", MethodSpecialName.Explicit },
{ "op_CheckedExplicit", MethodSpecialName.CheckedExplicit },
{ "op_Implicit", MethodSpecialName.Implicit },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ public enum MethodSpecialName {
// type cast
Explicit,
Implicit,

// unsigned right shift (C#11)
UnsignedRightShift,

// checked (C#11)
CheckedUnaryNegation,
CheckedIncrement,
CheckedDecrement,
CheckedAddition,
CheckedSubtraction,
CheckedMultiply,
CheckedDivision,
CheckedExplicit,
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,28 +266,38 @@ public class C : IDisposable {
// unary operators
[ExpectedMethodSpecialName(MethodSpecialName.UnaryPlus)] public static C operator +(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.UnaryNegation)] public static C operator -(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedUnaryNegation)] public static C operator checked -(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.LogicalNot)] public static C operator !(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.OnesComplement)] public static C operator ~(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.True)] public static bool operator true(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.False)] public static bool operator false(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.Increment)] public static C operator ++(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedIncrement)] public static C operator checked ++(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.Decrement)] public static C operator --(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedDecrement)] public static C operator checked --(C c) => throw new NotImplementedException();

// binary operators
[ExpectedMethodSpecialName(MethodSpecialName.Addition)] public static C operator +(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedAddition)] public static C operator checked +(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.Subtraction)] public static C operator -(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedSubtraction)] public static C operator checked -(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.Multiply)] public static C operator *(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedMultiply)] public static C operator checked *(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.Division)] public static C operator /(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedDivision)] public static C operator checked /(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.Modulus)] public static C operator %(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.BitwiseAnd)] public static C operator &(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.BitwiseOr)] public static C operator |(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.ExclusiveOr)] public static C operator ^(C x, C y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.RightShift)] public static C operator >>(C x, int y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.UnsignedRightShift)] public static C operator >>>(C x, int y) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.LeftShift)] public static C operator <<(C x, int y) => throw new NotImplementedException();

// type cast
[ExpectedMethodSpecialName(MethodSpecialName.Explicit)] public static explicit operator C(V v) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedExplicit)] public static explicit operator checked C(V v) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.Explicit)] public static explicit operator V(C c) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.CheckedExplicit)] public static explicit operator checked V(C c) => throw new NotImplementedException();

[ExpectedMethodSpecialName(MethodSpecialName.Implicit)] public static implicit operator C(W w) => throw new NotImplementedException();
[ExpectedMethodSpecialName(MethodSpecialName.Implicit)] public static implicit operator W(C c) => throw new NotImplementedException();
Expand Down

0 comments on commit e1755d2

Please sign in to comment.