summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-12-17 08:31:37 -0800
committerGitHub <noreply@github.com>2024-12-18 00:31:37 +0800
commitd61bba8cac1aad3c559cea73fa56d593777ad2d7 (patch)
treeb8656d10b3dbedda0cb57d3a661b6c6abcb390a1
parent9c9e1f701242b59dead94426a25f2ad5d3bcf66d (diff)
Fix `getArgumentValueFloat` when arg is int. (#5888)
* Fix `getArgumentValueFloat` when arg is int. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
-rw-r--r--source/slang/slang-reflection-api.cpp10
-rw-r--r--tools/slang-unit-test/unit-test-attribute-reflection.cpp7
2 files changed, 16 insertions, 1 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp
index d7f793d05..d235c8270 100644
--- a/source/slang/slang-reflection-api.cpp
+++ b/source/slang/slang-reflection-api.cpp
@@ -1,6 +1,7 @@
// slang-reflection-api.cpp
#include "../core/slang-basic.h"
+#include "slang-check-impl.h"
#include "slang-check.h"
#include "slang-compiler.h"
#include "slang-syntax.h"
@@ -353,6 +354,15 @@ SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueFloat(
*rs = (float)cexpr->value;
return 0;
}
+ else if (auto implicitCastExpr = as<ImplicitCastExpr>(userAttr->args[index]))
+ {
+ auto base = implicitCastExpr->arguments[0];
+ if (auto intLit = as<IntegerLiteralExpr>(base))
+ {
+ *rs = (float)intLit->value;
+ return 0;
+ }
+ }
return SLANG_E_INVALID_ARG;
}
SLANG_API const char* spReflectionUserAttribute_GetArgumentValueString(
diff --git a/tools/slang-unit-test/unit-test-attribute-reflection.cpp b/tools/slang-unit-test/unit-test-attribute-reflection.cpp
index e60eeb2d4..7a4758677 100644
--- a/tools/slang-unit-test/unit-test-attribute-reflection.cpp
+++ b/tools/slang-unit-test/unit-test-attribute-reflection.cpp
@@ -26,12 +26,13 @@ SLANG_UNIT_TEST(attributeReflection)
public struct NormalTextureAttribute
{
public E Type;
+ public float x;
};
[COM("042BE50B-CB01-4DBB-8367-3A9CDCBE2F49")]
interface IInterface { void f(); }
- [NormalTexture(E.V1)]
+ [NormalTexture(E.V1, 6)]
struct TS {};
)";
String userSource = userSourceBody;
@@ -76,4 +77,8 @@ SLANG_UNIT_TEST(attributeReflection)
int value = 0;
normalTextureAttribute->getArgumentValueInt(0, &value);
SLANG_CHECK(value == 1);
+
+ float fvalue = 0;
+ normalTextureAttribute->getArgumentValueFloat(1, &fvalue);
+ SLANG_CHECK(fvalue == 6.0);
}