diff options
| author | Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> | 2024-09-19 16:27:50 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-19 13:27:50 -0700 |
| commit | dd3d80e61b316390a468a142de2be2fb85b73d0d (patch) | |
| tree | cbfd3ddcbaed84de335818e9e618d7c3ebff6ecd /tools/slang-unit-test | |
| parent | 9d40ce4e8921ef468281c91f052dbd443ecf56e2 (diff) | |
Allow lookups of overloaded methods. (#5110)
* Allow lookups of overloaded methods.
* Update slang-reflection-api.cpp
* Update slang.cpp
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tools/slang-unit-test')
| -rw-r--r-- | tools/slang-unit-test/unit-test-function-reflection.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/slang-unit-test/unit-test-function-reflection.cpp b/tools/slang-unit-test/unit-test-function-reflection.cpp index ddcb81adc..2b52a8691 100644 --- a/tools/slang-unit-test/unit-test-function-reflection.cpp +++ b/tools/slang-unit-test/unit-test-function-reflection.cpp @@ -36,6 +36,9 @@ SLANG_UNIT_TEST(functionReflection) { return pos; } + + float foo(float x) { return x; } + float foo(float x, uint i) { return x + i; } )"; auto moduleName = "moduleG" + String(Process::getId()); @@ -90,5 +93,34 @@ SLANG_UNIT_TEST(functionReflection) SLANG_CHECK(result == SLANG_OK); SLANG_CHECK(val == 1024); SLANG_CHECK(funcReflection->findUserAttributeByName(globalSession.get(), "MyFuncProperty") == userAttribute); + + // Check overloaded method resolution + auto overloadReflection = module->getLayout()->findFunctionByName("foo"); + SLANG_CHECK(overloadReflection != nullptr); + SLANG_CHECK(overloadReflection->isOverloaded() == true); + SLANG_CHECK(overloadReflection->getOverloadCount() == 2); + + auto firstOverload = overloadReflection->getOverload(0); + SLANG_CHECK(firstOverload != nullptr); + SLANG_CHECK(UnownedStringSlice(firstOverload->getName()) == "foo"); + SLANG_CHECK(firstOverload->getParameterCount() == 2); + SLANG_CHECK(UnownedStringSlice(firstOverload->getParameterByIndex(0)->getName()) == "x"); + SLANG_CHECK(getTypeFullName(firstOverload->getParameterByIndex(0)->getType()) == "float"); + SLANG_CHECK(UnownedStringSlice(firstOverload->getParameterByIndex(1)->getName()) == "i"); + SLANG_CHECK(getTypeFullName(firstOverload->getParameterByIndex(1)->getType()) == "uint"); + + auto secondOverload = overloadReflection->getOverload(1); + SLANG_CHECK(secondOverload != nullptr); + SLANG_CHECK(UnownedStringSlice(secondOverload->getName()) == "foo"); + SLANG_CHECK(secondOverload->getParameterCount() == 1); + SLANG_CHECK(UnownedStringSlice(secondOverload->getParameterByIndex(0)->getName()) == "x"); + + // Check overload resolution via argument types. + slang::TypeReflection* argTypes[] = { + module->getLayout()->findTypeByName("float"), + module->getLayout()->findTypeByName("uint"), + }; + auto resolvedFunctionReflection = overloadReflection->specializeWithArgTypes(2, argTypes); + SLANG_CHECK(resolvedFunctionReflection == firstOverload); } |
