mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user