summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-08-11 11:37:38 -0400
committerGitHub <noreply@github.com>2020-08-11 11:37:38 -0400
commit96805c71696b3cce2bdd020a16574d88a80be1eb (patch)
tree20824eb8f560140c913cddf779ed465ea2ba4955 /tests
parent2903eb53ed9411d1160d2b777992ba9f36d0c746 (diff)
Improvements to Casting (#1483)
* Improve handling of cast detection when have a more complex cast than just a single identifier. * Improve comments around heuristic for casting * Added nested enum test. * Improve comments * Define function like - output change. * Use lookup for types in determining if cast or not. * Add _isCast function * Add heuristic test to nested-enum.slang that works if the type test fails. * Change hueristic based on review. Allow (..)( to always be an expression, because if it's a type it will be turned into a cast later. * Fix output of define-function-like.slang - which changes again with improved casting support. * Improve testing for type in cast - if we find a decl and it's not a type, then we know it's not a cast.
Diffstat (limited to 'tests')
-rw-r--r--tests/language-feature/enums/nested-enum.slang84
-rw-r--r--tests/language-feature/enums/nested-enum.slang.expected.txt4
2 files changed, 88 insertions, 0 deletions
diff --git a/tests/language-feature/enums/nested-enum.slang b/tests/language-feature/enums/nested-enum.slang
new file mode 100644
index 000000000..942a9e72d
--- /dev/null
+++ b/tests/language-feature/enums/nested-enum.slang
@@ -0,0 +1,84 @@
+// nested-num.slang
+
+// Test enums defined nested in a struct work as expected.
+
+//TEST(compute):COMPARE_COMPUTE:
+
+struct Outer
+{
+ enum Channel
+ {
+ Red,
+ Green,
+ Blue,
+ Alpha,
+ }
+
+ static int doSomething(int v) { return v + 1; }
+ typedef int SomeType;
+
+ static int someValue = 10;
+
+ static int getHeuristicResult()
+ {
+ // This tests that the cast heuristic works here.
+ // when the compiler cannot determine if it's a type or not at this point,
+ // because these declarations have not been seen.
+
+ // Has whitespace (between + and the next thing) -> must be an expression
+ int value = (Inner::anotherValue) + 1;
+ // No whitespace, so assumed to be a cast
+ Inner::Enum anotherValue = (Inner::Enum) +1;
+
+ return Inner::doSomethingElse(value + (int)anotherValue);
+ }
+
+ struct Inner
+ {
+ enum Enum
+ {
+ A,
+ B,
+ };
+
+ static int anotherValue = 10;
+ static int doSomethingElse(int a) { return a - 1; }
+ }
+}
+
+int test(int val)
+{
+ Outer::Channel channel = (Outer::Channel)val; // Outer::Channel(val);
+ Outer::Channel otherChannel = channel; // (Outer::Channel)val;
+
+ typedef Outer::Channel Channel;
+
+ int result = 0;
+ if(channel == Channel.Red) result += 1;
+ if(channel != Channel.Green) result += 16;
+ if(otherChannel == Channel.Blue) result += 16*16;
+ if(otherChannel != Channel.Alpha) result += 16*16*16;
+
+ return result;
+}
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int value = (Outer::someValue) + 1 + Outer::getHeuristicResult();
+ Outer::Channel anotherValue = (Outer::Channel) +1;
+
+ // These work because the type can be determined because they are already declared at this point
+ // Check can see this is a function call
+ value = (Outer::doSomething)(value);
+ // Check can see this is a cast
+ value += (Outer::SomeType)(value);
+
+ uint tid = dispatchThreadID.x;
+ int inVal = tid;
+ int outVal = test(inVal) + value * 2 + int(anotherValue) * 4;
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/language-feature/enums/nested-enum.slang.expected.txt b/tests/language-feature/enums/nested-enum.slang.expected.txt
new file mode 100644
index 000000000..9a26c2421
--- /dev/null
+++ b/tests/language-feature/enums/nested-enum.slang.expected.txt
@@ -0,0 +1,4 @@
+1071
+1060
+1170
+70