From 86669cbb781840f8de180b1f793275f4511d3b65 Mon Sep 17 00:00:00 2001 From: Alexandre Bléron Date: Wed, 26 Feb 2025 22:43:57 +0100 Subject: expose value of constant integers in module reflection (#6367) * Expose value of constant integers in module reflection This commit adds `VariableReflection::getDefaultValueInt` to get the value of a variable if it is a compile-time constant integer. TODO: currently it works only if the initializer expression is an integer literal, references to other constant values are not handled. * Update VarDecl folded constant value during DeclBodyVisitor Constant folding for integer values is already done internally by _validateCircularVarDefinition, this just reuses the result. * Address review comments & formatting * Formatting --------- Co-authored-by: Yong He --- source/slang/slang-reflection-api.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source/slang/slang-reflection-api.cpp') diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 52047a751..9295bfdf6 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -3164,6 +3164,22 @@ SLANG_API bool spReflectionVariable_HasDefaultValue(SlangReflectionVariable* inV return false; } +SLANG_API SlangResult +spReflectionVariable_GetDefaultValueInt(SlangReflectionVariable* inVar, int64_t* rs) +{ + auto decl = convert(inVar).getDecl(); + if (auto varDecl = as(decl)) + { + if (auto constantVal = as(varDecl->val)) + { + *rs = constantVal->getValue(); + return 0; + } + } + + return SLANG_E_INVALID_ARG; +} + SLANG_API SlangReflectionGeneric* spReflectionVariable_GetGenericContainer( SlangReflectionVariable* var) { -- cgit v1.2.3