summaryrefslogtreecommitdiffstats
path: root/tools/slang-cpp-extractor
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-11-15 00:37:58 -0800
committerGitHub <noreply@github.com>2024-11-15 00:37:58 -0800
commit05903f708856a70d68bf41bbfb2b06620508dee0 (patch)
tree7255325656c16f02652c83f2c4111b29ba503913 /tools/slang-cpp-extractor
parentf0bc4642a563e2318634b38a5a7ac2c3ddd68917 (diff)
Embed core module in wasm build. (#5569)
* Embed core module in wasm build. * format code * add uintptr_t case. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tools/slang-cpp-extractor')
-rw-r--r--tools/slang-cpp-extractor/diagnostic-defs.h5
-rw-r--r--tools/slang-cpp-extractor/parser.cpp40
2 files changed, 43 insertions, 2 deletions
diff --git a/tools/slang-cpp-extractor/diagnostic-defs.h b/tools/slang-cpp-extractor/diagnostic-defs.h
index 290036a23..03ba88dd3 100644
--- a/tools/slang-cpp-extractor/diagnostic-defs.h
+++ b/tools/slang-cpp-extractor/diagnostic-defs.h
@@ -75,6 +75,11 @@ DIAGNOSTIC(
destructorNameDoesntMatch,
"Destructor name doesn't match class name '$0'");
DIAGNOSTIC(100023, Error, cannotParseCallable, "Cannot parse callable");
+DIAGNOSTIC(
+ 100024,
+ Error,
+ cannoseUseArchDependentType,
+ "Cannot use architecture dependent type '$0' for serializable data.")
// Command line errors 100100
diff --git a/tools/slang-cpp-extractor/parser.cpp b/tools/slang-cpp-extractor/parser.cpp
index 070aea297..3a4891829 100644
--- a/tools/slang-cpp-extractor/parser.cpp
+++ b/tools/slang-cpp-extractor/parser.cpp
@@ -1524,6 +1524,11 @@ bool Parser::_isCtor()
return isCtor;
}
+bool isAlphaNumeric(char c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
+}
+
SlangResult Parser::_maybeParseContained(Node** outNode)
{
*outNode = nullptr;
@@ -1833,7 +1838,37 @@ SlangResult Parser::_maybeParseContained(Node** outNode)
fieldNode->m_name = nameToken;
fieldNode->m_reflectionType = m_currentScope->getContainedReflectionType();
fieldNode->m_isStatic = isStatic;
-
+ if (fieldNode->m_reflectionType == ReflectionType::Reflected)
+ {
+ static const char* illegalTypes[] = {
+ "size_t",
+ "Int",
+ "UInt",
+ "Index",
+ "Count",
+ "UIndex",
+ "UCount",
+ "PtrInt",
+ "intptr_t",
+ "uintptr_t"};
+ for (const auto& illegalType : illegalTypes)
+ {
+ int index = typeName.indexOf(UnownedStringSlice(illegalType));
+ if (index != -1)
+ {
+ index += UnownedStringSlice(illegalType).getLength();
+ if (index >= typeName.getLength() || !isAlphaNumeric(typeName[index]))
+ {
+ // Cannot use this type in a field (as it's arch dependent
+ m_sink->diagnose(
+ nameToken,
+ CPPDiagnostics::cannoseUseArchDependentType,
+ illegalType);
+ return SLANG_FAIL;
+ }
+ }
+ }
+ }
m_currentScope->addChild(fieldNode);
*outNode = fieldNode;
@@ -2187,7 +2222,8 @@ SlangResult Parser::parse(SourceOrigin* sourceOrigin, const Options* options)
m_sink->diagnose(m_reader.peekToken(), CPPDiagnostics::braceOpenAtEndOfFile);
return SLANG_FAIL;
}
-
+ if (m_sink->getErrorCount())
+ return SLANG_FAIL;
return SLANG_OK;
}
case TokenType::Pound: