summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-modifier.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-07-25 10:08:28 -0700
committerGitHub <noreply@github.com>2022-07-25 10:08:28 -0700
commit9566e8af25f87ad034a984db9d847942e454a180 (patch)
tree2f295bf2bf60c39fd35b6b634b903d574b4ca99e /source/slang/slang-check-modifier.cpp
parent70147fc7ba6abe0b669363ed5adfd8d4d9545c3f (diff)
Allow `class` to implement COM interface, [DLLExport] (#2338)
* Allow `class` to implement COM interface, [DLLExport] * Fix [COM] usage in tests and examples with UUIDs. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-modifier.cpp')
-rw-r--r--source/slang/slang-check-modifier.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp
index 28164c126..16a1cae26 100644
--- a/source/slang/slang-check-modifier.cpp
+++ b/source/slang/slang-check-modifier.cpp
@@ -1,5 +1,6 @@
// slang-check-modifier.cpp
#include "slang-check-impl.h"
+#include "../core/slang-char-util.h"
// This file implements semantic checking behavior for
// modifiers.
@@ -568,7 +569,7 @@ namespace Slang
}
else if (auto dllImportAttr = as<DllImportAttribute>(attr))
{
- SLANG_ASSERT(attr->args.getCount() == 1);
+ SLANG_ASSERT(attr->args.getCount() == 1 || attr->args.getCount() == 2);
String libraryName;
if (!checkLiteralStringVal(dllImportAttr->args[0], &libraryName))
@@ -576,6 +577,13 @@ namespace Slang
return false;
}
dllImportAttr->modulePath = libraryName;
+
+ String functionName;
+ if (dllImportAttr->args.getCount() == 2 && !checkLiteralStringVal(dllImportAttr->args[1], &functionName))
+ {
+ return false;
+ }
+ dllImportAttr->functionName = functionName;
}
else if (auto rayPayloadAttr = as<VulkanRayPayloadAttribute>(attr))
{
@@ -606,6 +614,38 @@ namespace Slang
customJVPAttr->funcDeclRef = funcExpr;
}
+ else if (auto comInterfaceAttr = as<ComInterfaceAttribute>(attr))
+ {
+ SLANG_ASSERT(attr->args.getCount() == 1);
+ String guid;
+ if (!checkLiteralStringVal(comInterfaceAttr->args[0], &guid))
+ {
+ return false;
+ }
+ StringBuilder resultGUID;
+ for (auto ch : guid)
+ {
+ if (CharUtil::isHexDigit(ch))
+ {
+ resultGUID.appendChar(ch);
+ }
+ else if (ch == '-')
+ {
+ continue;
+ }
+ else
+ {
+ getSink()->diagnose(attr, Diagnostics::invalidGUID, guid);
+ return false;
+ }
+ }
+ comInterfaceAttr->guid = resultGUID.ToString();
+ if (comInterfaceAttr->guid.getLength() != 32)
+ {
+ getSink()->diagnose(attr, Diagnostics::invalidGUID, guid);
+ return false;
+ }
+ }
else
{
if(attr->args.getCount() == 0)
@@ -617,7 +657,7 @@ namespace Slang
{
// We should be special-casing the checking of any attribute
// with a non-zero number of arguments.
- SLANG_DIAGNOSE_UNEXPECTED(getSink(), attr, "unhandled attribute");
+ getSink()->diagnose(attr, Diagnostics::tooManyArguments, attr->args.getCount(), 0);
return false;
}
}