From 95be6e3bee4eaebf5825c8c187c960037cea66f4 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 16 May 2018 16:20:33 -0700 Subject: [PATCH] Make it clear which field of TSNode can be used as a unique id --- include/tree_sitter/runtime.h | 6 ++++-- src/runtime/node.c | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index 71c8b5b3..ea52d4c2 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -66,12 +66,14 @@ typedef struct { typedef struct { uint32_t context[4]; - const void *ref[2]; + const void *id; + const void *tree; } TSNode; typedef struct { uint32_t context[2]; - void *ref[2]; + const void *id; + const void *tree; } TSTreeCursor; TSParser *ts_parser_new(); diff --git a/src/runtime/node.c b/src/runtime/node.c index 8eaaf220..31843e2a 100644 --- a/src/runtime/node.c +++ b/src/runtime/node.c @@ -17,7 +17,8 @@ typedef struct { TSNode ts_node_new(const TSTree *tree, const Subtree *subtree, Length position, TSSymbol alias) { return (TSNode) { {position.bytes, position.extent.row, position.extent.column, alias}, - {tree, subtree}, + subtree, + tree, }; } @@ -27,14 +28,6 @@ static inline TSNode ts_node__null() { // TSNode - accessors -static inline const TSTree *ts_node__tree(const TSNode *self) { - return self->ref[0]; -} - -static inline const Subtree *ts_node__subtree(TSNode self) { - return self.ref[1]; -} - static inline uint32_t ts_node__byte(const TSNode *self) { return self->context[0]; } @@ -47,6 +40,14 @@ static inline uint32_t ts_node__alias(const TSNode *self) { return self->context[3]; } +static inline const Subtree *ts_node__subtree(TSNode self) { + return self.id; +} + +static inline const TSTree *ts_node__tree(const TSNode *self) { + return self->tree; +} + // NodeChildIterator static inline NodeChildIterator ts_node_child_iterator_begin(const TSNode *node) {