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 --- include/slang-deprecated.h | 2 ++ include/slang.h | 5 +++++ 2 files changed, 7 insertions(+) (limited to 'include') diff --git a/include/slang-deprecated.h b/include/slang-deprecated.h index 82d81af75..df6e41488 100644 --- a/include/slang-deprecated.h +++ b/include/slang-deprecated.h @@ -659,6 +659,8 @@ extern "C" SlangSession* globalSession, char const* name); SLANG_API bool spReflectionVariable_HasDefaultValue(SlangReflectionVariable* inVar); + SLANG_API SlangResult + spReflectionVariable_GetDefaultValueInt(SlangReflectionVariable* inVar, int64_t* rs); SLANG_API SlangReflectionGeneric* spReflectionVariable_GetGenericContainer( SlangReflectionVariable* var); SLANG_API SlangReflectionVariable* spReflectionVariable_applySpecializations( diff --git a/include/slang.h b/include/slang.h index af635e3c4..54647b830 100644 --- a/include/slang.h +++ b/include/slang.h @@ -2832,6 +2832,11 @@ struct VariableReflection return spReflectionVariable_HasDefaultValue((SlangReflectionVariable*)this); } + SlangResult getDefaultValueInt(int64_t* value) + { + return spReflectionVariable_GetDefaultValueInt((SlangReflectionVariable*)this, value); + } + GenericReflection* getGenericContainer() { return (GenericReflection*)spReflectionVariable_GetGenericContainer( -- cgit v1.2.3