[libSyntax] Explicitly pass source file length to c parse actions

Previously, the passed in source file was implicitly terminated by the
first null character. The source file might, however, contain a null
character in the middle and we shouldn't stop parsing at it.
This commit is contained in:
Alex Hoppen
2021-03-04 18:19:39 +01:00
parent ffaf8679c0
commit dd9e831ba7
4 changed files with 24 additions and 20 deletions

View File

@@ -95,7 +95,7 @@ public:
setDiagnosticHandler(nullptr);
}
swiftparse_client_node_t parse(const char *source);
swiftparse_client_node_t parse(const char *source, size_t len);
};
class CLibParseActions : public SyntaxParseActions {
@@ -274,10 +274,10 @@ struct SynParserDiagConsumer: public DiagnosticConsumer {
}
};
swiftparse_client_node_t SynParser::parse(const char *source) {
swiftparse_client_node_t SynParser::parse(const char *source, size_t len) {
SourceManager SM;
unsigned bufID = SM.addNewSourceBuffer(
llvm::MemoryBuffer::getMemBuffer(source, "syntax_parse_source"));
unsigned bufID = SM.addNewSourceBuffer(llvm::MemoryBuffer::getMemBuffer(
StringRef(source, len), "syntax_parse_source"));
TypeCheckerOptions tyckOpts;
LangOptions langOpts;
langOpts.BuildSyntaxTree = true;
@@ -329,10 +329,11 @@ swiftparse_parser_set_node_lookup(swiftparse_parser_t c_parser,
parser->setNodeLookup(lookup);
}
swiftparse_client_node_t
swiftparse_parse_string(swiftparse_parser_t c_parser, const char *source) {
swiftparse_client_node_t swiftparse_parse_string(swiftparse_parser_t c_parser,
const char *source,
size_t len) {
SynParser *parser = static_cast<SynParser*>(c_parser);
return parser->parse(source);
return parser->parse(source, len);
}
const char* swiftparse_syntax_structure_versioning_identifier(void) {