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:
@@ -136,17 +136,18 @@ makeNode(const swiftparse_syntax_node_t *raw_node, StringRef source) {
|
||||
}
|
||||
|
||||
static swiftparse_client_node_t
|
||||
parse(const char *source, swiftparse_node_handler_t node_handler,
|
||||
parse(StringRef source, swiftparse_node_handler_t node_handler,
|
||||
swiftparse_diagnostic_handler_t diag_handler = nullptr) {
|
||||
swiftparse_parser_t parser = swiftparse_parser_create();
|
||||
swiftparse_parser_set_node_handler(parser, node_handler);
|
||||
swiftparse_parser_set_diagnostic_handler(parser, diag_handler);
|
||||
swiftparse_client_node_t top = swiftparse_parse_string(parser, source);
|
||||
swiftparse_client_node_t top =
|
||||
swiftparse_parse_string(parser, source.data(), source.size());
|
||||
swiftparse_parser_dispose(parser);
|
||||
return top;
|
||||
}
|
||||
|
||||
static int dumpTree(const char *source) {
|
||||
static int dumpTree(StringRef source) {
|
||||
swiftparse_node_handler_t nodeHandler =
|
||||
^swiftparse_client_node_t(const swiftparse_syntax_node_t *raw_node) {
|
||||
return makeNode(raw_node, source);
|
||||
@@ -216,7 +217,7 @@ static void printDiagInfo(const swiftparser_diagnostic_t diag,
|
||||
}
|
||||
}
|
||||
|
||||
static int dumpDiagnostics(const char* source, llvm::SourceMgr &SM,
|
||||
static int dumpDiagnostics(StringRef source, llvm::SourceMgr &SM,
|
||||
unsigned BufferId) {
|
||||
swiftparse_node_handler_t nodeHandler =
|
||||
^swiftparse_client_node_t(const swiftparse_syntax_node_t *raw_node) {
|
||||
@@ -255,7 +256,7 @@ static void printTimeRecord(unsigned numInvoks, const TimeRecord &total,
|
||||
OS << '\n';
|
||||
}
|
||||
|
||||
static int timeParsing(const char *source, unsigned numInvoks) {
|
||||
static int timeParsing(StringRef source, unsigned numInvoks) {
|
||||
swiftparse_node_handler_t nodeHandler =
|
||||
^swiftparse_client_node_t(const swiftparse_syntax_node_t *raw_node) {
|
||||
return nullptr;
|
||||
@@ -288,10 +289,10 @@ int main(int argc, char *argv[]) {
|
||||
auto BufferId = SM.AddNewSourceBuffer(std::move(*fileBufOrErr), SMLoc());
|
||||
switch (options::Action) {
|
||||
case ActionType::DumpTree:
|
||||
return dumpTree(source.data());
|
||||
return dumpTree(source);
|
||||
case ActionType::Time:
|
||||
return timeParsing(source.data(), options::NumParses);
|
||||
return timeParsing(source, options::NumParses);
|
||||
case ActionType::Diagnostics:
|
||||
return dumpDiagnostics(source.data(), SM, BufferId);
|
||||
return dumpDiagnostics(source, SM, BufferId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user