diff options
author | Piotr Fusik <fox@scene.pl> | 2022-01-24 10:38:12 +0100 |
---|---|---|
committer | Piotr Fusik <fox@scene.pl> | 2022-01-24 10:38:12 +0100 |
commit | 67b898b44fd1e3d4234cbcbada55ef8fd9ec0378 (patch) | |
tree | 829cde2cd146d927c95f4f86aea3bed8840e8998 | |
parent | fa03f3d0a09c6102b552c434cc038205f721ef5f (diff) |
[cleanup] Don't unbox CiLiteralBool.
-rw-r--r-- | CiResolver.cs | 20 | ||||
-rw-r--r-- | CiTree.cs | 2 | ||||
-rw-r--r-- | GenCCpp.cs | 2 |
3 files changed, 13 insertions, 11 deletions
diff --git a/CiResolver.cs b/CiResolver.cs index 226078a..fc4c8f4 100644 --- a/CiResolver.cs +++ b/CiResolver.cs @@ -787,9 +787,9 @@ public class CiResolver : CiVisitor case CiToken.CondAnd: { Coerce(left, CiSystem.BoolType); Coerce(right, CiSystem.BoolType); - if (left is CiLiteral leftLiteral) - return (bool) leftLiteral.Value ? right : CiLiteral.False; - if (right is CiLiteral rightLiteral && (bool) rightLiteral.Value) + if (left is CiLiteralTrue) + return right; + if (left is CiLiteralFalse || right is CiLiteralTrue) return left; type = CiSystem.BoolType; break; @@ -797,10 +797,10 @@ public class CiResolver : CiVisitor case CiToken.CondOr: { Coerce(left, CiSystem.BoolType); Coerce(right, CiSystem.BoolType); - if (left is CiLiteral leftLiteral) - return (bool) leftLiteral.Value ? CiLiteral.True : right; - if (right is CiLiteral rightLiteral && !(bool) rightLiteral.Value) + if (left is CiLiteralTrue || right is CiLiteralFalse) return left; + if (left is CiLiteralFalse) + return right; type = CiSystem.BoolType; break; } @@ -908,8 +908,10 @@ public class CiResolver : CiVisitor CiType type = GetCommonType(onTrue, onFalse); Coerce(onTrue, type); Coerce(onFalse, type); - if (cond is CiLiteral literalCond) - return (bool) literalCond.Value ? onTrue : onFalse; + if (cond is CiLiteralTrue) + return onTrue; + if (cond is CiLiteralFalse) + return onFalse; return new CiSelectExpr { Line = expr.Line, Cond = cond, OnTrue = onTrue, OnFalse = onFalse, Type = type }; } @@ -1060,7 +1062,7 @@ public class CiResolver : CiVisitor { if (statement.Cond != null) { statement.Cond = ResolveBool(statement.Cond); - statement.SetCompletesNormally(!(statement.Cond is CiLiteral literal) || !(bool) literal.Value); + statement.SetCompletesNormally(!(statement.Cond is CiLiteralTrue)); } else statement.SetCompletesNormally(false); @@ -715,7 +715,7 @@ public class CiAssert : CiStatement { public CiExpr Cond; public CiExpr Message = null; - public override bool CompletesNormally => !(this.Cond is CiLiteral literal) || (bool) literal.Value; + public override bool CompletesNormally => !(this.Cond is CiLiteralFalse); public override void Accept(CiVisitor visitor) { visitor.Visit(this); } } @@ -224,7 +224,7 @@ public abstract class GenCCpp : GenTyped Write("assert("); if (statement.Message == null) statement.Cond.Accept(this, CiPriority.Argument); - else if (statement.Cond is CiLiteral literal && !(bool) literal.Value) { + else if (statement.Cond is CiLiteralFalse) { Write('!'); statement.Message.Accept(this, CiPriority.Primary); } |