diff options
Diffstat (limited to 'vendor/github.com/mitjafelicijan/go-tree-sitter/length.h')
| -rw-r--r-- | vendor/github.com/mitjafelicijan/go-tree-sitter/length.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/github.com/mitjafelicijan/go-tree-sitter/length.h b/vendor/github.com/mitjafelicijan/go-tree-sitter/length.h new file mode 100644 index 0000000..dbae5ce --- /dev/null +++ b/vendor/github.com/mitjafelicijan/go-tree-sitter/length.h | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #ifndef TREE_SITTER_LENGTH_H_ | ||
| 2 | #define TREE_SITTER_LENGTH_H_ | ||
| 3 | |||
| 4 | #include <stdlib.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | #include "./point.h" | ||
| 7 | #include "api.h" | ||
| 8 | |||
| 9 | typedef struct { | ||
| 10 | uint32_t bytes; | ||
| 11 | TSPoint extent; | ||
| 12 | } Length; | ||
| 13 | |||
| 14 | static const Length LENGTH_UNDEFINED = {0, {0, 1}}; | ||
| 15 | static const Length LENGTH_MAX = {UINT32_MAX, {UINT32_MAX, UINT32_MAX}}; | ||
| 16 | |||
| 17 | static inline bool length_is_undefined(Length length) { | ||
| 18 | return length.bytes == 0 && length.extent.column != 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | static inline Length length_min(Length len1, Length len2) { | ||
| 22 | return (len1.bytes < len2.bytes) ? len1 : len2; | ||
| 23 | } | ||
| 24 | |||
| 25 | static inline Length length_add(Length len1, Length len2) { | ||
| 26 | Length result; | ||
| 27 | result.bytes = len1.bytes + len2.bytes; | ||
| 28 | result.extent = point_add(len1.extent, len2.extent); | ||
| 29 | return result; | ||
| 30 | } | ||
| 31 | |||
| 32 | static inline Length length_sub(Length len1, Length len2) { | ||
| 33 | Length result; | ||
| 34 | result.bytes = len1.bytes - len2.bytes; | ||
| 35 | result.extent = point_sub(len1.extent, len2.extent); | ||
| 36 | return result; | ||
| 37 | } | ||
| 38 | |||
| 39 | static inline Length length_zero(void) { | ||
| 40 | Length result = {0, {0, 0}}; | ||
| 41 | return result; | ||
| 42 | } | ||
| 43 | |||
| 44 | static inline Length length_saturating_sub(Length len1, Length len2) { | ||
| 45 | if (len1.bytes > len2.bytes) { | ||
| 46 | return length_sub(len1, len2); | ||
| 47 | } else { | ||
| 48 | return length_zero(); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | #endif | ||
