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

@@ -221,6 +221,17 @@ swiftparse_parser_set_node_lookup(swiftparse_parser_t,
SWIFTPARSE_PUBLIC swiftparse_client_node_t
swiftparse_parse_string(swiftparse_parser_t, const char *source);
/// Returns a constant string pointer for verification purposes.
///
/// Working as a hash value, the constant string is calculated during compilation
/// time from syntax node declarations.
///
/// During runtime, SwiftSyntax client can compare its own version of the hash
/// value with the result of the function call. Mismatch indicates the parser
/// library isn't compatible with the client side, e.g. added/removed node
/// declarations, etc.
SWIFTPARSE_PUBLIC const char* swiftparse_syntax_structure_versioning_identifier(void);
SWIFTPARSE_END_DECLS
#endif