Skip to content

Commit 9f67a33

Browse files
committed
C#: Support user defined compound assignment operators.
1 parent 2383a5a commit 9f67a33

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp.Util/SymbolExtensions.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,21 @@ public static bool TryGetOperatorSymbol(this ISymbol symbol, out string operator
6565
return true;
6666
}
6767

68-
var match = CheckedRegex().Match(methodName);
69-
if (match.Success && methodToOperator.TryGetValue($"op_{match.Groups[1]}", out var uncheckedName))
68+
// Attempt to parse using a regexp.
69+
var match = OperatorRegex().Match(methodName);
70+
if (match.Success && methodToOperator.TryGetValue($"op_{match.Groups[2]}", out var rawOperatorName))
7071
{
71-
operatorName = $"checked {uncheckedName}";
72+
var prefix = match.Groups[1].Success ? "checked " : "";
73+
var postfix = match.Groups[3].Success ? "=" : "";
74+
operatorName = $"{prefix}{rawOperatorName}{postfix}";
7275
return true;
7376
}
7477

7578
operatorName = methodName;
7679
return false;
7780
}
7881

79-
[GeneratedRegex("^op_Checked(.*)$")]
80-
private static partial Regex CheckedRegex();
82+
[GeneratedRegex("^op_(Checked)?(.*?)(Assignment)?$")]
83+
private static partial Regex OperatorRegex();
8184
}
8285
}

0 commit comments

Comments
 (0)