Apply De Morgan's to simplify negations

This commit is contained in:
Yoshi Askharoun
2025-07-24 22:59:49 -05:00
parent 6c679f7a0f
commit 0e71917f34
2 changed files with 14 additions and 3 deletions
+13 -2
View File
@@ -418,7 +418,9 @@ partial class Decompiler
goto defaultCase; goto defaultCase;
SyntaxKind notOperatorToken; SyntaxKind notOperatorToken;
switch (binaryExpression.OperatorToken.Kind()) var operatorToken = binaryExpression.OperatorToken.Kind();
switch (operatorToken)
{ {
case SyntaxKind.EqualsEqualsToken: case SyntaxKind.EqualsEqualsToken:
notOperatorToken = SyntaxKind.ExclamationEqualsToken; notOperatorToken = SyntaxKind.ExclamationEqualsToken;
@@ -440,6 +442,15 @@ partial class Decompiler
notOperatorToken = SyntaxKind.LessThanToken; notOperatorToken = SyntaxKind.LessThanToken;
break; break;
case SyntaxKind.AmpersandAmpersandToken:
case SyntaxKind.BarBarToken:
// Apply De Morgan's laws
notOperatorToken = operatorToken is SyntaxKind.AmpersandAmpersandToken
? SyntaxKind.LogicalOrExpression : SyntaxKind.LogicalAndExpression;
return BinaryExpression(notOperatorToken,
LogicalNotOf(binaryExpression.Left),
LogicalNotOf(binaryExpression.Right));
default: default:
goto defaultCase; goto defaultCase;
} }
@@ -447,7 +458,7 @@ partial class Decompiler
return binaryExpression.WithOperatorToken(Token(notOperatorToken)); return binaryExpression.WithOperatorToken(Token(notOperatorToken));
defaultCase: defaultCase:
return PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, originalExpression); return PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, ParenthesizedExpression(originalExpression));
} }
private static SyntaxKind OperationToSyntaxKind(OperationType operation) private static SyntaxKind OperationToSyntaxKind(OperationType operation)
+1 -1
View File
@@ -837,7 +837,7 @@
} }
} }
if (!zuneUI:ZuneShell.DefaultInstance.CurrentPage is zuneUI:QuickplayPage || zuneUI:ZuneShell.DefaultInstance.CurrentPage is zuneUI:StartupPage && string.IsNullOrEmpty(zuneUI:Shell.SessionStartupPath) && configuration:ClientConfiguration.Shell.StartupPage == zuneUI:Shell.MainFrame.Quickplay.DefaultUIPath) if (zuneUI:ZuneShell.DefaultInstance.CurrentPage is not zuneUI:QuickplayPage && zuneUI:ZuneShell.DefaultInstance.CurrentPage is not zuneUI:StartupPage || !(string.IsNullOrEmpty(zuneUI:Shell.SessionStartupPath)) || configuration:ClientConfiguration.Shell.StartupPage != zuneUI:Shell.MainFrame.Quickplay.DefaultUIPath)
{ {
if (zuneUI:ZuneShell.DefaultInstance.CurrentPage is zuneUI:StartupPage) if (zuneUI:ZuneShell.DefaultInstance.CurrentPage is zuneUI:StartupPage)
{ {