summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-08-19 16:54:54 -0700
committerGitHub <noreply@github.com>2019-08-19 16:54:54 -0700
commit3e78e4654cdf9556869325f2ed2da517f252d879 (patch)
treeb4fd144f1cf9451717d92338a2540b845dd0614d /source
parent3284144312ff6b86ec6f9dd665ff216c7cd4c737 (diff)
Support shifts and a few other ops in front-end constant folding (#1027)
The set of supported operations in front-end constant folding was very limited: `+`, `-`, `*`, `/`, and `%`. This meant that enum declarations like: ``` enum MyBits { A = 1 << 0, B = 1 << 1, C = A | C, } ``` would fail to compile, with a claim that the expressions like `1 << 0` aren't compile-time constants. This change adds `<<`, `>>`, `&`, `|`, and `^` to the list of integer operations we will cosntant-fold in the front-end. It also changes one of the declarations in the existing test case for `enum`s to use the added functionality. Note that this change does *not* address the more deep-seated problems with our approach to constant-folding in the front-end. It does not change the constant folding to rely on IR machinery, or to allow for more general `constexpr` functions, and it does not address the fact that constant-folding is currently applied without paying attention to the type (and thus precision) of the original expression.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp
index 9a4a01045..464dafcd9 100644
--- a/source/slang/slang-check.cpp
+++ b/source/slang/slang-check.cpp
@@ -5359,6 +5359,11 @@ namespace Slang
CASE(+); // TODO: this can also be unary...
CASE(*);
+ CASE(<<);
+ CASE(>>);
+ CASE(&);
+ CASE(|);
+ CASE(^);
#undef CASE
// binary operators with chance of divide-by-zero