diff options
| author | Yong He <yonghe@outlook.com> | 2024-11-15 00:37:58 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-15 00:37:58 -0800 |
| commit | 05903f708856a70d68bf41bbfb2b06620508dee0 (patch) | |
| tree | 7255325656c16f02652c83f2c4111b29ba503913 /tools/slang-cpp-extractor/parser.cpp | |
| parent | f0bc4642a563e2318634b38a5a7ac2c3ddd68917 (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/parser.cpp')
| -rw-r--r-- | tools/slang-cpp-extractor/parser.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
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: |
