Start work on an API for querying trees

This commit is contained in:
Max Brunsfeld 2019-09-09 15:41:13 -07:00
parent 4151a428ec
commit fe7c74e7aa
10 changed files with 1430 additions and 12 deletions

25
lib/src/bits.h Normal file
View file

@ -0,0 +1,25 @@
#ifndef TREE_SITTER_BITS_H_
#define TREE_SITTER_BITS_H_
#include <stdint.h>
#ifdef _WIN32
#include <intrin.h>
static inline uint32_t count_leading_zeros(uint32_t x) {
if (x == 0) return 32;
uint32_t result;
_BitScanReverse(&reuslt, x);
return result;
}
#else
static inline uint32_t count_leading_zeros(uint32_t x) {
if (x == 0) return 32;
return __builtin_clz(x);
}
#endif
#endif // TREE_SITTER_BITS_H_