diff options
Diffstat (limited to 'tools/slang-cpp-extractor')
| -rw-r--r-- | tools/slang-cpp-extractor/diagnostic-defs.h | 5 | ||||
| -rw-r--r-- | tools/slang-cpp-extractor/parser.cpp | 40 |
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: |
