diff options
author | Piotr Fusik <fox@scene.pl> | 2022-01-22 14:17:57 +0100 |
---|---|---|
committer | Piotr Fusik <fox@scene.pl> | 2022-01-22 14:17:57 +0100 |
commit | 4117b1fcb4a4dc2e505f414383240db6e63ceb9b (patch) | |
tree | 03ce05dc79e7d61ca4b01597336dca8476047e25 | |
parent | 82cce42ba5ce8f5d3e3bd727e3e2dc10d98f1d4c (diff) |
[const] Const-fold enum comparisons.
-rw-r--r-- | CiResolver.cs | 8 | ||||
-rw-r--r-- | Makefile | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/CiResolver.cs b/CiResolver.cs index 8a2cd0e..df9da3c 100644 --- a/CiResolver.cs +++ b/CiResolver.cs @@ -579,8 +579,12 @@ public class CiResolver : CiVisitor if (leftRange.Max < rightRange.Min || leftRange.Min > rightRange.Max) return expr.ToLiteral(expr.Op == CiToken.NotEqual);; } - else if (left.Type == right.Type && left is CiLiteral leftLiteral && right is CiLiteral rightLiteral) - return expr.ToLiteral((expr.Op == CiToken.NotEqual) ^ object.Equals(leftLiteral.Value, rightLiteral.Value)); + else if (left.Type == right.Type) { + if (left is CiLiteral leftLiteral && right is CiLiteral rightLiteral) + return expr.ToLiteral((expr.Op == CiToken.NotEqual) ^ object.Equals(leftLiteral.Value, rightLiteral.Value)); + if (left.IsConstEnum && right.IsConstEnum) + return expr.ToLiteral((expr.Op == CiToken.NotEqual) ^ (left.IntValue == right.IntValue)); + } if (!left.Type.IsAssignableFrom(right.Type) && !right.Type.IsAssignableFrom(left.Type)) throw StatementException(expr, "Cannot compare {0} with {1}", left.Type, right.Type); TakePtr(left); @@ -1,6 +1,6 @@ prefix := /usr/local srcdir := $(dir $(lastword $(MAKEFILE_LIST))) -CFLAGS = -Wall -Wno-tautological-compare -Werror +CFLAGS = -Wall -Werror SWIFTC = swiftc ifeq ($(OS),Windows_NT) CSC = "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/Roslyn/csc.exe" -nologo |