summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-06-05 19:34:55 -0700
committerGitHub <noreply@github.com>2020-06-05 19:34:55 -0700
commit7d4432ba5ca007b18dfa6e0c19b4598e42c1e505 (patch)
treed439487223ee8ec4a2052d8855db310da878c001
parent43c146794aab638924d2ab838d10f8af2ebf02a7 (diff)
parent52026c7c26e48921fdf18b3f8cdacad77a792643 (diff)
Merge pull request #1375 from csyonghe/findtypebynamefix
Fix FindTypeByName reflection API not finding stdlib types.
-rw-r--r--source/slang/slang-check-shader.cpp2
-rw-r--r--tools/slang-test/slang-test.vcxproj1
-rw-r--r--tools/slang-test/slang-test.vcxproj.filters3
-rw-r--r--tools/slang-test/test-reporter.h8
-rw-r--r--tools/slang-test/unit-test-find-type-by-name.cpp56
5 files changed, 68 insertions, 2 deletions
diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp
index fcb9b1618..4af6a4328 100644
--- a/source/slang/slang-check-shader.cpp
+++ b/source/slang/slang-check-shader.cpp
@@ -1290,7 +1290,7 @@ namespace Slang
// it defines keywords like `true` and `false`).
//
RefPtr<Scope> scope = new Scope();
- scope->parent = getLinkage()->getSessionImpl()->baseLanguageScope;
+ scope->parent = getLinkage()->getSessionImpl()->slangLanguageScope;
//
// Next, the scope needs to include all of the
// modules in the program as peers, as if they
diff --git a/tools/slang-test/slang-test.vcxproj b/tools/slang-test/slang-test.vcxproj
index a7e925ffd..bf79af2f1 100644
--- a/tools/slang-test/slang-test.vcxproj
+++ b/tools/slang-test/slang-test.vcxproj
@@ -177,6 +177,7 @@
<ClCompile Include="test-reporter.cpp" />
<ClCompile Include="unit-offset-container.cpp" />
<ClCompile Include="unit-test-byte-encode.cpp" />
+ <ClCompile Include="unit-test-find-type-by-name.cpp" />
<ClCompile Include="unit-test-free-list.cpp" />
<ClCompile Include="unit-test-memory-arena.cpp" />
<ClCompile Include="unit-test-path.cpp" />
diff --git a/tools/slang-test/slang-test.vcxproj.filters b/tools/slang-test/slang-test.vcxproj.filters
index afb5b091a..27477f268 100644
--- a/tools/slang-test/slang-test.vcxproj.filters
+++ b/tools/slang-test/slang-test.vcxproj.filters
@@ -65,5 +65,8 @@
<ClCompile Include="unit-test-string.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="unit-test-find-type-by-name.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/tools/slang-test/test-reporter.h b/tools/slang-test/test-reporter.h
index cb4d5e985..6a862afef 100644
--- a/tools/slang-test/test-reporter.h
+++ b/tools/slang-test/test-reporter.h
@@ -9,7 +9,13 @@
#include "../../source/core/slang-dictionary.h"
-#define SLANG_CHECK(x) TestReporter::get()->addResultWithLocation((x), #x, __FILE__, __LINE__);
+#define SLANG_CHECK(x) TestReporter::get()->addResultWithLocation((x), #x, __FILE__, __LINE__);
+#define SLANG_CHECK_ABORT(x) \
+ { \
+ bool _slang_check_result = (x); \
+ TestReporter::get()->addResultWithLocation(_slang_check_result, #x, __FILE__, __LINE__); \
+ if (!_slang_check_result) return; \
+ }
struct TestRegister
{
diff --git a/tools/slang-test/unit-test-find-type-by-name.cpp b/tools/slang-test/unit-test-find-type-by-name.cpp
new file mode 100644
index 000000000..ebe5f746b
--- /dev/null
+++ b/tools/slang-test/unit-test-find-type-by-name.cpp
@@ -0,0 +1,56 @@
+// unit-test-byte-encode.cpp
+
+#include "../../slang.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "test-context.h"
+
+using namespace Slang;
+
+static void findTypeByNameTest()
+{
+ const char* testSource =
+ "struct TestStruct {"
+ " int member0;"
+ " Texture2D texture1;"
+ "};";
+ auto session = spCreateSession();
+ auto request = spCreateCompileRequest(session);
+ spAddCodeGenTarget(request, SLANG_DXBC);
+ int tuIndex = spAddTranslationUnit(request, SLANG_SOURCE_LANGUAGE_SLANG, "tu1");
+ spAddTranslationUnitSourceString(request, tuIndex, "internalFile", testSource);
+ spCompile(request);
+
+ auto testBody = [&]()
+ {
+ auto reflection = slang::ShaderReflection::get(request);
+ auto testStruct = reflection->findTypeByName("TestStruct");
+ SLANG_CHECK_ABORT(testStruct->getFieldCount() == 2);
+ auto field0Name = testStruct->getFieldByIndex(0)->getName();
+ SLANG_CHECK_ABORT(field0Name != nullptr && strcmp(field0Name, "member0") == 0);
+ auto field1Name = testStruct->getFieldByIndex(1)->getName();
+ SLANG_CHECK_ABORT(field1Name != nullptr && strcmp(field1Name, "texture1") == 0);
+
+ auto intType = reflection->findTypeByName("int");
+ auto intTypeName = intType->getName();
+ SLANG_CHECK_ABORT(intTypeName && strcmp(intTypeName, "int") == 0);
+
+ auto paramBlockType = reflection->findTypeByName("ParameterBlock<TestStruct>");
+ SLANG_CHECK_ABORT(paramBlockType != nullptr);
+ auto paramBlockTypeName = paramBlockType->getName();
+ SLANG_CHECK_ABORT(paramBlockTypeName && strcmp(paramBlockTypeName, "ParameterBlock") == 0);
+ auto paramBlockElementType = paramBlockType->getElementType();
+ SLANG_CHECK_ABORT(paramBlockElementType != nullptr);
+ auto paramBlockElementTypeName = paramBlockElementType->getName();
+ SLANG_CHECK_ABORT(paramBlockElementTypeName && strcmp(paramBlockElementTypeName, "TestStruct") == 0);
+ };
+
+ testBody();
+
+ spDestroyCompileRequest(request);
+ spDestroySession(session);
+}
+
+SLANG_UNIT_TEST("findTypeByName", findTypeByNameTest);