SyntaxParser: set up a C API to get a hash value indicating the node declaration set

To ensure SwiftSyntax calls a compatible parser library, this patch sets
up a C API that returns a constant string calculated during compilation time to indicate
the version of syntax node declarations. The same hash will be calculated
in the SwiftSyntax (client) side as well by using the same algorithm.

During runtime, SwiftSyntax will verify its hash value is identical to the
result of calling swiftparse_node_declaration_hash before actual
parsing happens.

This patch only sets the API up. The actual implementation of the
hashing algorithm will come later.
This commit is contained in:
Xi Ge
2019-02-06 13:40:12 -08:00
parent 1e7fba716d
commit e07a8cf2a6
6 changed files with 29 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
#include "swift/Parse/Parser.h"
#include "swift/Parse/SyntaxParseActions.h"
#include "swift/Syntax/Serialization/SyntaxSerialization.h"
#include "swift/Syntax/SyntaxNodes.h"
#include "swift/Subsystems.h"
#include <Block.h>
@@ -230,3 +231,7 @@ swiftparse_parse_string(swiftparse_parser_t c_parser, const char *source) {
SynParser *parser = static_cast<SynParser*>(c_parser);
return parser->parse(source);
}
const char* swiftparse_syntax_structure_versioning_identifier(void) {
return getSyntaxStructureVersioningIdentifier();
}