diff options
| author | Yong He <yonghe@outlook.com> | 2025-08-06 01:07:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-06 08:07:41 +0000 |
| commit | 68b0125226464cb3c9e9b7f50bfb53cda97723b4 (patch) | |
| tree | 5f0833c6d9aa759b2769f7f6ac9b3ca6ed9a10f0 /source/slang/slang-reflection-api.cpp | |
| parent | 83675103a1a4fefde11b314aed26f4d37860efe7 (diff) | |
Add reflection api for overload candidate filtering. (#8066)
* Add reflection api for overload candidate filtering.
* Fix API.
* Fix.
* Update build.
* Update test.
* Update formatting.
Diffstat (limited to 'source/slang/slang-reflection-api.cpp')
| -rw-r--r-- | source/slang/slang-reflection-api.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 56a82e17e..95dcc6249 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -5,6 +5,7 @@ #include "slang-check.h" #include "slang-compiler.h" #include "slang-deprecated.h" +#include "slang-lookup.h" #include "slang-syntax.h" #include "slang-type-layout.h" #include "slang.h" @@ -994,6 +995,45 @@ SLANG_API SlangReflectionFunction* spReflection_FindFunctionByNameInType( return nullptr; } + +SLANG_API SlangReflectionFunction* spReflection_TryResolveOverloadedFunction( + SlangReflection* reflection, + uint32_t candidateCount, + SlangReflectionFunction** candidates) +{ + auto programLayout = convert(reflection); + auto program = programLayout->getProgram(); + auto astBuilder = program->getLinkage()->getASTBuilder(); + SLANG_AST_BUILDER_RAII(astBuilder); + OverloadedExpr* overloadedFunc = nullptr; + if (candidateCount == 1) + { + overloadedFunc = convertToOverloadedFunc(candidates[0]); + if (!overloadedFunc) + return candidates[0]; + } + else + { + overloadedFunc = astBuilder->create<OverloadedExpr>(); + overloadedFunc->type = astBuilder->getOrCreate<OverloadGroupType>(); + for (uint32_t i = 0; i < candidateCount; i++) + { + auto func = convertToFunc(candidates[i]); + AddToLookupResult(overloadedFunc->lookupResult2, LookupResultItem(func)); + } + } + + try + { + auto result = program->tryResolveOverloadedExpr(overloadedFunc); + return tryConvertExprToFunctionReflection(astBuilder, result); + } + catch (...) + { + } + return nullptr; +} + SLANG_API SlangReflectionVariable* spReflection_FindVarByNameInType( SlangReflection* reflection, SlangReflectionType* reflType, |
