Rizin
unix-like reverse engineering framework and cli tools
binding.c File Reference
#include <emscripten.h>
#include <tree_sitter/api.h>
#include <stdio.h>
#include "array.h"
#include "point.h"

Go to the source code of this file.

Functions

void * ts_init ()
 
static uint32_t code_unit_to_byte (uint32_t unit)
 
static uint32_t byte_to_code_unit (uint32_t byte)
 
static void marshal_node (const void **buffer, TSNode node)
 
static TSNode unmarshal_node (const TSTree *tree)
 
static void marshal_cursor (const TSTreeCursor *cursor)
 
static TSTreeCursor unmarshal_cursor (const void **buffer, const TSTree *tree)
 
static void marshal_point (TSPoint point)
 
static TSPoint unmarshal_point (const void **address)
 
static void marshal_range (TSRange *range)
 
static void unmarshal_range (TSRange *range)
 
static TSInputEdit unmarshal_edit ()
 
void tree_sitter_parse_callback (char *input_buffer, uint32_t index, uint32_t row, uint32_t column, uint32_t *length_read)
 
void tree_sitter_log_callback (bool is_lex_message, const char *message)
 
static const char * call_parse_callback (void *payload, uint32_t byte, TSPoint position, uint32_t *bytes_read)
 
static void call_log_callback (void *payload, TSLogType log_type, const char *message)
 
void ts_parser_new_wasm ()
 
void ts_parser_enable_logger_wasm (TSParser *self, bool should_log)
 
TSTreets_parser_parse_wasm (TSParser *self, char *input_buffer, const TSTree *old_tree, TSRange *ranges, uint32_t range_count)
 
int ts_language_type_is_named_wasm (const TSLanguage *self, TSSymbol typeId)
 
int ts_language_type_is_visible_wasm (const TSLanguage *self, TSSymbol typeId)
 
void ts_tree_root_node_wasm (const TSTree *tree)
 
void ts_tree_edit_wasm (TSTree *tree)
 
void ts_tree_get_changed_ranges_wasm (TSTree *tree, TSTree *other)
 
void ts_tree_cursor_new_wasm (const TSTree *tree)
 
void ts_tree_cursor_delete_wasm (const TSTree *tree)
 
void ts_tree_cursor_reset_wasm (const TSTree *tree)
 
bool ts_tree_cursor_goto_first_child_wasm (const TSTree *tree)
 
bool ts_tree_cursor_goto_next_sibling_wasm (const TSTree *tree)
 
bool ts_tree_cursor_goto_parent_wasm (const TSTree *tree)
 
uint16_t ts_tree_cursor_current_node_type_id_wasm (const TSTree *tree)
 
bool ts_tree_cursor_current_node_is_named_wasm (const TSTree *tree)
 
bool ts_tree_cursor_current_node_is_missing_wasm (const TSTree *tree)
 
const uint32_t ts_tree_cursor_current_node_id_wasm (const TSTree *tree)
 
void ts_tree_cursor_start_position_wasm (const TSTree *tree)
 
void ts_tree_cursor_end_position_wasm (const TSTree *tree)
 
uint32_t ts_tree_cursor_start_index_wasm (const TSTree *tree)
 
uint32_t ts_tree_cursor_end_index_wasm (const TSTree *tree)
 
uint32_t ts_tree_cursor_current_field_id_wasm (const TSTree *tree)
 
void ts_tree_cursor_current_node_wasm (const TSTree *tree)
 
uint16_t ts_node_symbol_wasm (const TSTree *tree)
 
uint32_t ts_node_child_count_wasm (const TSTree *tree)
 
uint32_t ts_node_named_child_count_wasm (const TSTree *tree)
 
void ts_node_child_wasm (const TSTree *tree, uint32_t index)
 
void ts_node_named_child_wasm (const TSTree *tree, uint32_t index)
 
void ts_node_child_by_field_id_wasm (const TSTree *tree, uint32_t field_id)
 
void ts_node_next_sibling_wasm (const TSTree *tree)
 
void ts_node_prev_sibling_wasm (const TSTree *tree)
 
void ts_node_next_named_sibling_wasm (const TSTree *tree)
 
void ts_node_prev_named_sibling_wasm (const TSTree *tree)
 
void ts_node_parent_wasm (const TSTree *tree)
 
void ts_node_descendant_for_index_wasm (const TSTree *tree)
 
void ts_node_named_descendant_for_index_wasm (const TSTree *tree)
 
void ts_node_descendant_for_position_wasm (const TSTree *tree)
 
void ts_node_named_descendant_for_position_wasm (const TSTree *tree)
 
void ts_node_start_point_wasm (const TSTree *tree)
 
void ts_node_end_point_wasm (const TSTree *tree)
 
uint32_t ts_node_start_index_wasm (const TSTree *tree)
 
uint32_t ts_node_end_index_wasm (const TSTree *tree)
 
char * ts_node_to_string_wasm (const TSTree *tree)
 
void ts_node_children_wasm (const TSTree *tree)
 
void ts_node_named_children_wasm (const TSTree *tree)
 
bool symbols_contain (const uint32_t *set, uint32_t length, uint32_t value)
 
void ts_node_descendants_of_type_wasm (const TSTree *tree, const uint32_t *symbols, uint32_t symbol_count, uint32_t start_row, uint32_t start_column, uint32_t end_row, uint32_t end_column)
 
int ts_node_is_named_wasm (const TSTree *tree)
 
int ts_node_has_changes_wasm (const TSTree *tree)
 
int ts_node_has_error_wasm (const TSTree *tree)
 
int ts_node_is_missing_wasm (const TSTree *tree)
 
void ts_query_matches_wasm (const TSQuery *self, const TSTree *tree, uint32_t start_row, uint32_t start_column, uint32_t end_row, uint32_t end_column, uint32_t match_limit)
 
void ts_query_captures_wasm (const TSQuery *self, const TSTree *tree, uint32_t start_row, uint32_t start_column, uint32_t end_row, uint32_t end_column, uint32_t match_limit)
 

Variables

static const uint32_t INPUT_BUFFER_SIZE = 10 * 1024
 
const void * TRANSFER_BUFFER [12]
 
static TSTreeCursor scratch_cursor = {0}
 
static TSQueryCursorscratch_query_cursor = NULL
 

Function Documentation

◆ byte_to_code_unit()

static uint32_t byte_to_code_unit ( uint32_t  byte)
static

◆ call_log_callback()

static void call_log_callback ( void *  payload,
TSLogType  log_type,
const char *  message 
)
static

Definition at line 143 of file binding.c.

147  {
149 }
@ TSLogTypeLex
Definition: api.h:75
void tree_sitter_log_callback(bool is_lex_message, const char *message)
char * message
Definition: main.c:12

References message, tree_sitter_log_callback(), and TSLogTypeLex.

Referenced by ts_parser_enable_logger_wasm().

◆ call_parse_callback()

static const char* call_parse_callback ( void *  payload,
uint32_t  byte,
TSPoint  position,
uint32_t bytes_read 
)
static

Definition at line 122 of file binding.c.

127  {
128  char *buffer = (char *)payload;
130  buffer,
131  byte_to_code_unit(byte),
132  position.row,
133  byte_to_code_unit(position.column),
134  bytes_read
135  );
136  *bytes_read = code_unit_to_byte(*bytes_read);
137  if (*bytes_read >= INPUT_BUFFER_SIZE) {
138  *bytes_read = INPUT_BUFFER_SIZE - 2;
139  }
140  return buffer;
141 }
void tree_sitter_parse_callback(char *input_buffer, uint32_t index, uint32_t row, uint32_t column, uint32_t *length_read)
static const uint32_t INPUT_BUFFER_SIZE
Definition: binding.c:11
static uint32_t byte_to_code_unit(uint32_t byte)
Definition: binding.c:29
static uint32_t code_unit_to_byte(uint32_t unit)
Definition: binding.c:25
struct buffer buffer
uint32_t row
Definition: api.h:56
uint32_t column
Definition: api.h:57
Definition: buffer.h:15

References byte_to_code_unit(), code_unit_to_byte(), TSPoint::column, INPUT_BUFFER_SIZE, TSPoint::row, and tree_sitter_parse_callback().

Referenced by ts_parser_parse_wasm().

◆ code_unit_to_byte()

◆ marshal_cursor()

static void marshal_cursor ( const TSTreeCursor cursor)
inlinestatic

Definition at line 52 of file binding.c.

52  {
53  TRANSFER_BUFFER[0] = (const void *)cursor->id;
54  TRANSFER_BUFFER[1] = (const void *)cursor->context[0];
55  TRANSFER_BUFFER[2] = (const void *)cursor->context[1];
56 }
const void * TRANSFER_BUFFER[12]
Definition: binding.c:13
uint32_t context[2]
Definition: api.h:101
const void * id
Definition: api.h:100

References TSTreeCursor::context, TSTreeCursor::id, and TRANSFER_BUFFER.

Referenced by ts_tree_cursor_goto_first_child_wasm(), ts_tree_cursor_goto_next_sibling_wasm(), ts_tree_cursor_goto_parent_wasm(), ts_tree_cursor_new_wasm(), and ts_tree_cursor_reset_wasm().

◆ marshal_node()

◆ marshal_point()

static void marshal_point ( TSPoint  point)
static

Definition at line 67 of file binding.c.

67  {
68  TRANSFER_BUFFER[0] = (const void *)point.row;
69  TRANSFER_BUFFER[1] = (const void *)byte_to_code_unit(point.column);
70 }
Definition: zran.c:68

References byte_to_code_unit(), and TRANSFER_BUFFER.

Referenced by ts_node_end_point_wasm(), ts_node_start_point_wasm(), ts_tree_cursor_end_position_wasm(), and ts_tree_cursor_start_position_wasm().

◆ marshal_range()

static void marshal_range ( TSRange range)
static

Definition at line 79 of file binding.c.

79  {
80  range->start_byte = byte_to_code_unit(range->start_byte);
81  range->end_byte = byte_to_code_unit(range->end_byte);
82  range->start_point.column = byte_to_code_unit(range->start_point.column);
83  range->end_point.column = byte_to_code_unit(range->end_point.column);
84 }

References byte_to_code_unit(), and capstone::range.

Referenced by ts_tree_get_changed_ranges_wasm().

◆ symbols_contain()

bool symbols_contain ( const uint32_t set,
uint32_t  length,
uint32_t  value 
)

Definition at line 490 of file binding.c.

490  {
491  for (unsigned i = 0; i < length; i++) {
492  if (set[i] == value) return true;
493  if (set[i] > value) break;
494  }
495  return false;
496 }
lzma_index ** i
Definition: index.h:629
static int value
Definition: cmd_api.c:93
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133

References i, length, and value.

Referenced by ts_node_descendants_of_type_wasm().

◆ tree_sitter_log_callback()

void tree_sitter_log_callback ( bool  is_lex_message,
const char *  message 
)

Referenced by call_log_callback().

◆ tree_sitter_parse_callback()

void tree_sitter_parse_callback ( char *  input_buffer,
uint32_t  index,
uint32_t  row,
uint32_t  column,
uint32_t length_read 
)

Referenced by call_parse_callback().

◆ ts_init()

void* ts_init ( )

Definition at line 19 of file binding.c.

19  {
22  return TRANSFER_BUFFER;
23 }
#define TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
Definition: api.h:30
#define TREE_SITTER_LANGUAGE_VERSION
Definition: api.h:24

References TRANSFER_BUFFER, TREE_SITTER_LANGUAGE_VERSION, and TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION.

◆ ts_language_type_is_named_wasm()

int ts_language_type_is_named_wasm ( const TSLanguage self,
TSSymbol  typeId 
)

Definition at line 191 of file binding.c.

191  {
192  const TSSymbolType symbolType = ts_language_symbol_type(self, typeId);
193  return symbolType == TSSymbolTypeRegular;
194 }
TSSymbolType
Definition: api.h:49
@ TSSymbolTypeRegular
Definition: api.h:50
TSSymbolType ts_language_symbol_type(const TSLanguage *, TSSymbol)
Definition: language.c:93

References ts_language_symbol_type(), and TSSymbolTypeRegular.

◆ ts_language_type_is_visible_wasm()

int ts_language_type_is_visible_wasm ( const TSLanguage self,
TSSymbol  typeId 
)

Definition at line 196 of file binding.c.

196  {
197  const TSSymbolType symbolType = ts_language_symbol_type(self, typeId);
198  return symbolType <= TSSymbolTypeAnonymous;
199 }
@ TSSymbolTypeAnonymous
Definition: api.h:51

References ts_language_symbol_type(), and TSSymbolTypeAnonymous.

◆ ts_node_child_by_field_id_wasm()

void ts_node_child_by_field_id_wasm ( const TSTree tree,
uint32_t  field_id 
)

Definition at line 357 of file binding.c.

357  {
358  TSNode node = unmarshal_node(tree);
360 }
TSNode ts_node_child_by_field_id(TSNode, TSFieldId)
Definition: node.c:500
static TSNode unmarshal_node(const TSTree *tree)
Definition: binding.c:41
static void marshal_node(const void **buffer, TSNode node)
Definition: binding.c:33
@ field_id
Definition: parser.c:1736
Definition: api.h:92

References field_id, marshal_node(), TRANSFER_BUFFER, ts_node_child_by_field_id(), and unmarshal_node().

◆ ts_node_child_count_wasm()

uint32_t ts_node_child_count_wasm ( const TSTree tree)

Definition at line 337 of file binding.c.

337  {
338  TSNode node = unmarshal_node(tree);
339  return ts_node_child_count(node);
340 }
uint32_t ts_node_child_count(TSNode)
Definition: node.c:602

References ts_node_child_count(), and unmarshal_node().

◆ ts_node_child_wasm()

void ts_node_child_wasm ( const TSTree tree,
uint32_t  index 
)

Definition at line 347 of file binding.c.

347  {
348  TSNode node = unmarshal_node(tree);
350 }
TSNode ts_node_child(TSNode, uint32_t)
Definition: node.c:492

References marshal_node(), TRANSFER_BUFFER, ts_node_child(), and unmarshal_node().

◆ ts_node_children_wasm()

void ts_node_children_wasm ( const TSTree tree)

Definition at line 444 of file binding.c.

444  {
445  TSNode node = unmarshal_node(tree);
447  const void **result = NULL;
448  if (count > 0) {
449  result = calloc(sizeof(void *), 5 * count);
450  const void **address = result;
454  for (uint32_t i = 1; i < count; i++) {
455  address += 5;
458  marshal_node(address, child);
459  }
460  }
461  TRANSFER_BUFFER[0] = (const void *)count;
462  TRANSFER_BUFFER[1] = result;
463 }
bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *)
Definition: tree_cursor.c:206
void ts_tree_cursor_reset(TSTreeCursor *, TSNode)
Definition: tree_cursor.c:76
TSNode ts_tree_cursor_current_node(const TSTreeCursor *)
Definition: tree_cursor.c:262
bool ts_tree_cursor_goto_first_child(TSTreeCursor *)
Definition: tree_cursor.c:101
static TSTreeCursor scratch_cursor
Definition: binding.c:329
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
unsigned int uint32_t
Definition: sftypes.h:29

References calloc(), count, i, marshal_node(), NULL, scratch_cursor, TRANSFER_BUFFER, ts_node_child_count(), ts_tree_cursor_current_node(), ts_tree_cursor_goto_first_child(), ts_tree_cursor_goto_next_sibling(), ts_tree_cursor_reset(), and unmarshal_node().

◆ ts_node_descendant_for_index_wasm()

void ts_node_descendant_for_index_wasm ( const TSTree tree)

Definition at line 387 of file binding.c.

387  {
388  TSNode node = unmarshal_node(tree);
389  const void **address = TRANSFER_BUFFER + 5;
390  uint32_t start = code_unit_to_byte((uint32_t)address[0]);
391  uint32_t end = code_unit_to_byte((uint32_t)address[1]);
393 }
TSNode ts_node_descendant_for_byte_range(TSNode, uint32_t, uint32_t)
Definition: node.c:644
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133

References code_unit_to_byte(), test_evm::end, marshal_node(), start, TRANSFER_BUFFER, ts_node_descendant_for_byte_range(), and unmarshal_node().

◆ ts_node_descendant_for_position_wasm()

void ts_node_descendant_for_position_wasm ( const TSTree tree)

Definition at line 403 of file binding.c.

403  {
404  TSNode node = unmarshal_node(tree);
405  const void **address = TRANSFER_BUFFER + 5;
406  TSPoint start = unmarshal_point(address); address += 2;
407  TSPoint end = unmarshal_point(address);
409 }
TSNode ts_node_descendant_for_point_range(TSNode, TSPoint, TSPoint)
Definition: node.c:660
static TSPoint unmarshal_point(const void **address)
Definition: binding.c:72
Definition: api.h:55

References test_evm::end, marshal_node(), start, TRANSFER_BUFFER, ts_node_descendant_for_point_range(), unmarshal_node(), and unmarshal_point().

◆ ts_node_descendants_of_type_wasm()

void ts_node_descendants_of_type_wasm ( const TSTree tree,
const uint32_t symbols,
uint32_t  symbol_count,
uint32_t  start_row,
uint32_t  start_column,
uint32_t  end_row,
uint32_t  end_column 
)

Definition at line 498 of file binding.c.

506  {
507  TSNode node = unmarshal_node(tree);
508  TSPoint start_point = {start_row, code_unit_to_byte(start_column)};
509  TSPoint end_point = {end_row, code_unit_to_byte(end_column)};
510  if (end_point.row == 0 && end_point.column == 0) {
511  end_point = (TSPoint) {UINT32_MAX, UINT32_MAX};
512  }
513 
514  Array(const void *) result = array_new();
515 
516  // Walk the tree depth first looking for matching nodes.
518  bool already_visited_children = false;
519  while (true) {
521 
522  if (!already_visited_children) {
523  // If this node is before the selected range, then avoid
524  // descending into it.
525  if (point_lte(ts_node_end_point(descendant), start_point)) {
527  already_visited_children = false;
528  } else {
530  already_visited_children = true;
531  }
532  continue;
533  }
534 
535  // If this node is after the selected range, then stop walking.
536  if (point_lte(end_point, ts_node_start_point(descendant))) break;
537 
538  // Add the node to the result if its type matches one of the given
539  // node types.
540  if (symbols_contain(symbols, symbol_count, ts_node_symbol(descendant))) {
541  array_grow_by(&result, 5);
542  marshal_node(result.contents + result.size - 5, descendant);
543  }
544 
545  // Continue walking.
547  already_visited_children = false;
549  already_visited_children = false;
550  } else {
552  already_visited_children = true;
553  }
554  } else {
556  already_visited_children = false;
557  } else {
559  }
560  }
561  }
562 
563  TRANSFER_BUFFER[0] = (const void *)(result.size / 5);
564  TRANSFER_BUFFER[1] = result.contents;
565 }
TSSymbol ts_node_symbol(TSNode)
Definition: node.c:414
TSPoint ts_node_start_point(TSNode)
Definition: node.c:40
bool ts_tree_cursor_goto_parent(TSTreeCursor *)
Definition: tree_cursor.c:239
TSPoint ts_node_end_point(TSNode)
Definition: node.c:410
#define array_new()
Definition: array.h:25
#define Array(T)
Definition: array.h:15
#define array_grow_by(self, count)
Definition: array.h:49
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
bool symbols_contain(const uint32_t *set, uint32_t length, uint32_t value)
Definition: binding.c:490
static bool point_lte(TSPoint a, TSPoint b)
Definition: point.h:28
#define UINT32_MAX

References Array, array_grow_by, array_new, code_unit_to_byte(), TSPoint::column, marshal_node(), point_lte(), TSPoint::row, scratch_cursor, symbols(), symbols_contain(), TRANSFER_BUFFER, ts_node_end_point(), ts_node_start_point(), ts_node_symbol(), ts_tree_cursor_current_node(), ts_tree_cursor_goto_first_child(), ts_tree_cursor_goto_next_sibling(), ts_tree_cursor_goto_parent(), ts_tree_cursor_reset(), UINT32_MAX, and unmarshal_node().

◆ ts_node_end_index_wasm()

uint32_t ts_node_end_index_wasm ( const TSTree tree)

Definition at line 434 of file binding.c.

434  {
435  TSNode node = unmarshal_node(tree);
436  return byte_to_code_unit(ts_node_end_byte(node));
437 }
uint32_t ts_node_end_byte(TSNode)
Definition: node.c:406

References byte_to_code_unit(), ts_node_end_byte(), and unmarshal_node().

◆ ts_node_end_point_wasm()

void ts_node_end_point_wasm ( const TSTree tree)

Definition at line 424 of file binding.c.

424  {
425  TSNode node = unmarshal_node(tree);
427 }
static void marshal_point(TSPoint point)
Definition: binding.c:67

References marshal_point(), ts_node_end_point(), and unmarshal_node().

◆ ts_node_has_changes_wasm()

int ts_node_has_changes_wasm ( const TSTree tree)

Definition at line 572 of file binding.c.

572  {
573  TSNode node = unmarshal_node(tree);
574  return ts_node_has_changes(node);
575 }
bool ts_node_has_changes(TSNode)
Definition: node.c:453

References ts_node_has_changes(), and unmarshal_node().

◆ ts_node_has_error_wasm()

int ts_node_has_error_wasm ( const TSTree tree)

Definition at line 577 of file binding.c.

577  {
578  TSNode node = unmarshal_node(tree);
579  return ts_node_has_error(node);
580 }
bool ts_node_has_error(TSNode)
Definition: node.c:457

References ts_node_has_error(), and unmarshal_node().

◆ ts_node_is_missing_wasm()

int ts_node_is_missing_wasm ( const TSTree tree)

Definition at line 582 of file binding.c.

582  {
583  TSNode node = unmarshal_node(tree);
584  return ts_node_is_missing(node);
585 }
bool ts_node_is_missing(TSNode)
Definition: node.c:449

References ts_node_is_missing(), and unmarshal_node().

◆ ts_node_is_named_wasm()

int ts_node_is_named_wasm ( const TSTree tree)

Definition at line 567 of file binding.c.

567  {
568  TSNode node = unmarshal_node(tree);
569  return ts_node_is_named(node);
570 }
bool ts_node_is_named(TSNode)
Definition: node.c:442

References ts_node_is_named(), and unmarshal_node().

◆ ts_node_named_child_count_wasm()

uint32_t ts_node_named_child_count_wasm ( const TSTree tree)

Definition at line 342 of file binding.c.

342  {
343  TSNode node = unmarshal_node(tree);
344  return ts_node_named_child_count(node);
345 }
uint32_t ts_node_named_child_count(TSNode)
Definition: node.c:611

References ts_node_named_child_count(), and unmarshal_node().

◆ ts_node_named_child_wasm()

void ts_node_named_child_wasm ( const TSTree tree,
uint32_t  index 
)

Definition at line 352 of file binding.c.

352  {
353  TSNode node = unmarshal_node(tree);
355 }
TSNode ts_node_named_child(TSNode, uint32_t)
Definition: node.c:496

References marshal_node(), TRANSFER_BUFFER, ts_node_named_child(), and unmarshal_node().

◆ ts_node_named_children_wasm()

void ts_node_named_children_wasm ( const TSTree tree)

Definition at line 465 of file binding.c.

465  {
466  TSNode node = unmarshal_node(tree);
468  const void **result = NULL;
469  if (count > 0) {
470  result = calloc(sizeof(void *), 5 * count);
471  const void **address = result;
474  uint32_t i = 0;
475  for (;;) {
477  if (ts_node_is_named(child)) {
478  marshal_node(address, child);
479  address += 5;
480  i++;
481  if (i == count) break;
482  }
484  }
485  }
486  TRANSFER_BUFFER[0] = (const void *)count;
487  TRANSFER_BUFFER[1] = result;
488 }

References calloc(), count, i, marshal_node(), NULL, scratch_cursor, TRANSFER_BUFFER, ts_node_is_named(), ts_node_named_child_count(), ts_tree_cursor_current_node(), ts_tree_cursor_goto_first_child(), ts_tree_cursor_goto_next_sibling(), ts_tree_cursor_reset(), and unmarshal_node().

◆ ts_node_named_descendant_for_index_wasm()

void ts_node_named_descendant_for_index_wasm ( const TSTree tree)

Definition at line 395 of file binding.c.

395  {
396  TSNode node = unmarshal_node(tree);
397  const void **address = TRANSFER_BUFFER + 5;
398  uint32_t start = code_unit_to_byte((uint32_t)address[0]);
399  uint32_t end = code_unit_to_byte((uint32_t)address[1]);
401 }
TSNode ts_node_named_descendant_for_byte_range(TSNode, uint32_t, uint32_t)
Definition: node.c:652

References code_unit_to_byte(), test_evm::end, marshal_node(), start, TRANSFER_BUFFER, ts_node_named_descendant_for_byte_range(), and unmarshal_node().

◆ ts_node_named_descendant_for_position_wasm()

void ts_node_named_descendant_for_position_wasm ( const TSTree tree)

Definition at line 411 of file binding.c.

411  {
412  TSNode node = unmarshal_node(tree);
413  const void **address = TRANSFER_BUFFER + 5;
414  TSPoint start = unmarshal_point(address); address += 2;
415  TSPoint end = unmarshal_point(address);
417 }
TSNode ts_node_named_descendant_for_point_range(TSNode, TSPoint, TSPoint)
Definition: node.c:668

References test_evm::end, marshal_node(), start, TRANSFER_BUFFER, ts_node_named_descendant_for_point_range(), unmarshal_node(), and unmarshal_point().

◆ ts_node_next_named_sibling_wasm()

void ts_node_next_named_sibling_wasm ( const TSTree tree)

Definition at line 372 of file binding.c.

372  {
373  TSNode node = unmarshal_node(tree);
375 }
TSNode ts_node_next_named_sibling(TSNode)
Definition: node.c:624

References marshal_node(), TRANSFER_BUFFER, ts_node_next_named_sibling(), and unmarshal_node().

◆ ts_node_next_sibling_wasm()

void ts_node_next_sibling_wasm ( const TSTree tree)

Definition at line 362 of file binding.c.

362  {
363  TSNode node = unmarshal_node(tree);
365 }
TSNode ts_node_next_sibling(TSNode)
Definition: node.c:620

References marshal_node(), TRANSFER_BUFFER, ts_node_next_sibling(), and unmarshal_node().

◆ ts_node_parent_wasm()

void ts_node_parent_wasm ( const TSTree tree)

Definition at line 382 of file binding.c.

382  {
383  TSNode node = unmarshal_node(tree);
385 }
TSNode ts_node_parent(TSNode)
Definition: node.c:461

References marshal_node(), TRANSFER_BUFFER, ts_node_parent(), and unmarshal_node().

◆ ts_node_prev_named_sibling_wasm()

void ts_node_prev_named_sibling_wasm ( const TSTree tree)

Definition at line 377 of file binding.c.

377  {
378  TSNode node = unmarshal_node(tree);
380 }
TSNode ts_node_prev_named_sibling(TSNode)
Definition: node.c:632

References marshal_node(), TRANSFER_BUFFER, ts_node_prev_named_sibling(), and unmarshal_node().

◆ ts_node_prev_sibling_wasm()

void ts_node_prev_sibling_wasm ( const TSTree tree)

Definition at line 367 of file binding.c.

367  {
368  TSNode node = unmarshal_node(tree);
370 }
TSNode ts_node_prev_sibling(TSNode)
Definition: node.c:628

References marshal_node(), TRANSFER_BUFFER, ts_node_prev_sibling(), and unmarshal_node().

◆ ts_node_start_index_wasm()

uint32_t ts_node_start_index_wasm ( const TSTree tree)

Definition at line 429 of file binding.c.

429  {
430  TSNode node = unmarshal_node(tree);
432 }
uint32_t ts_node_start_byte(TSNode)
Definition: node.c:36

References byte_to_code_unit(), ts_node_start_byte(), and unmarshal_node().

◆ ts_node_start_point_wasm()

void ts_node_start_point_wasm ( const TSTree tree)

Definition at line 419 of file binding.c.

419  {
420  TSNode node = unmarshal_node(tree);
422 }

References marshal_point(), ts_node_start_point(), and unmarshal_node().

◆ ts_node_symbol_wasm()

uint16_t ts_node_symbol_wasm ( const TSTree tree)

Definition at line 332 of file binding.c.

332  {
333  TSNode node = unmarshal_node(tree);
334  return ts_node_symbol(node);
335 }

References ts_node_symbol(), and unmarshal_node().

◆ ts_node_to_string_wasm()

char* ts_node_to_string_wasm ( const TSTree tree)

Definition at line 439 of file binding.c.

439  {
440  TSNode node = unmarshal_node(tree);
441  return ts_node_string(node);
442 }
char * ts_node_string(TSNode)
Definition: node.c:426

References ts_node_string(), and unmarshal_node().

◆ ts_parser_enable_logger_wasm()

void ts_parser_enable_logger_wasm ( TSParser self,
bool  should_log 
)

Definition at line 158 of file binding.c.

158  {
159  TSLogger logger = {self, should_log ? call_log_callback : NULL};
160  ts_parser_set_logger(self, logger);
161 }
void ts_parser_set_logger(TSParser *self, TSLogger logger)
Definition: parser.c:1779
static void call_log_callback(void *payload, TSLogType log_type, const char *message)
Definition: binding.c:143
Definition: api.h:78

References call_log_callback(), NULL, and ts_parser_set_logger().

◆ ts_parser_new_wasm()

void ts_parser_new_wasm ( )

Definition at line 151 of file binding.c.

151  {
153  char *input_buffer = calloc(INPUT_BUFFER_SIZE, sizeof(char));
154  TRANSFER_BUFFER[0] = parser;
155  TRANSFER_BUFFER[1] = input_buffer;
156 }
TSParser * ts_parser_new(void)
Definition: parser.c:1704

References calloc(), INPUT_BUFFER_SIZE, cmd_descs_generate::parser, TRANSFER_BUFFER, and ts_parser_new().

◆ ts_parser_parse_wasm()

TSTree* ts_parser_parse_wasm ( TSParser self,
char *  input_buffer,
const TSTree old_tree,
TSRange ranges,
uint32_t  range_count 
)

Definition at line 163 of file binding.c.

169  {
170  TSInput input = {
171  input_buffer,
174  };
175  if (range_count) {
176  for (unsigned i = 0; i < range_count; i++) {
177  unmarshal_range(&ranges[i]);
178  }
179  ts_parser_set_included_ranges(self, ranges, range_count);
180  free(ranges);
181  } else {
183  }
184  return ts_parser_parse(self, old_tree, input);
185 }
TSTree * ts_parser_parse(TSParser *self, const TSTree *old_tree, TSInput input)
Definition: parser.c:1844
bool ts_parser_set_included_ranges(TSParser *self, const TSRange *ranges, uint32_t length)
Definition: parser.c:1811
@ TSInputEncodingUTF16
Definition: api.h:46
static void unmarshal_range(TSRange *range)
Definition: binding.c:86
static const char * call_parse_callback(void *payload, uint32_t byte, TSPoint position, uint32_t *bytes_read)
Definition: binding.c:122
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
Definition: api.h:67
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References call_parse_callback(), free(), i, input(), NULL, ts_parser_parse(), ts_parser_set_included_ranges(), TSInputEncodingUTF16, and unmarshal_range().

◆ ts_query_captures_wasm()

void ts_query_captures_wasm ( const TSQuery self,
const TSTree tree,
uint32_t  start_row,
uint32_t  start_column,
uint32_t  end_row,
uint32_t  end_column,
uint32_t  match_limit 
)

Definition at line 638 of file binding.c.

646  {
648  if (match_limit == 0) {
650  } else {
652  }
653 
654  TSNode node = unmarshal_node(tree);
655  TSPoint start_point = {start_row, code_unit_to_byte(start_column)};
656  TSPoint end_point = {end_row, code_unit_to_byte(end_column)};
657  ts_query_cursor_set_point_range(scratch_query_cursor, start_point, end_point);
659 
660  unsigned index = 0;
661  unsigned capture_count = 0;
662  Array(const void *) result = array_new();
663 
665  uint32_t capture_index;
668  &match,
669  &capture_index
670  )) {
671  capture_count++;
672 
673  array_grow_by(&result, 3 + 6 * match.capture_count);
674  result.contents[index++] = (const void *)(uint32_t)match.pattern_index;
675  result.contents[index++] = (const void *)(uint32_t)match.capture_count;
676  result.contents[index++] = (const void *)(uint32_t)capture_index;
677  for (unsigned i = 0; i < match.capture_count; i++) {
678  const TSQueryCapture *capture = &match.captures[i];
679  result.contents[index++] = (const void *)capture->index;
680  marshal_node(result.contents + index, capture->node);
681  index += 5;
682  }
683  }
684 
685  bool did_exceed_match_limit =
687  TRANSFER_BUFFER[0] = (const void *)(capture_count);
688  TRANSFER_BUFFER[1] = result.contents;
689  TRANSFER_BUFFER[2] = (const void *)(did_exceed_match_limit);
690 }
void ts_query_cursor_exec(TSQueryCursor *, const TSQuery *, TSNode)
Definition: query.c:2859
void ts_query_cursor_set_match_limit(TSQueryCursor *, uint32_t)
Definition: query.c:2855
bool ts_query_cursor_did_exceed_match_limit(const TSQueryCursor *)
Definition: query.c:2847
TSQueryCursor * ts_query_cursor_new(void)
Definition: query.c:2820
bool ts_query_cursor_next_capture(TSQueryCursor *, TSQueryMatch *match, uint32_t *capture_index)
Definition: query.c:3746
void ts_query_cursor_set_point_range(TSQueryCursor *, TSPoint, TSPoint)
Definition: query.c:2888
static TSQueryCursor * scratch_query_cursor
Definition: binding.c:330
unsigned char match[65280+2]
Definition: gun.c:165
TSNode node
Definition: api.h:105
uint32_t index
Definition: api.h:106
Definition: engine.c:71

References Array, array_grow_by, array_new, code_unit_to_byte(), i, TSQueryCapture::index, marshal_node(), match, TSQueryCapture::node, scratch_query_cursor, TRANSFER_BUFFER, ts_query_cursor_did_exceed_match_limit(), ts_query_cursor_exec(), ts_query_cursor_new(), ts_query_cursor_next_capture(), ts_query_cursor_set_match_limit(), ts_query_cursor_set_point_range(), UINT32_MAX, and unmarshal_node().

◆ ts_query_matches_wasm()

void ts_query_matches_wasm ( const TSQuery self,
const TSTree tree,
uint32_t  start_row,
uint32_t  start_column,
uint32_t  end_row,
uint32_t  end_column,
uint32_t  match_limit 
)

Definition at line 591 of file binding.c.

599  {
601  if (match_limit == 0) {
603  } else {
605  }
606 
607  TSNode node = unmarshal_node(tree);
608  TSPoint start_point = {start_row, code_unit_to_byte(start_column)};
609  TSPoint end_point = {end_row, code_unit_to_byte(end_column)};
610  ts_query_cursor_set_point_range(scratch_query_cursor, start_point, end_point);
612 
613  uint32_t index = 0;
614  uint32_t match_count = 0;
615  Array(const void *) result = array_new();
616 
619  match_count++;
620  array_grow_by(&result, 2 + 6 * match.capture_count);
621  result.contents[index++] = (const void *)(uint32_t)match.pattern_index;
622  result.contents[index++] = (const void *)(uint32_t)match.capture_count;
623  for (unsigned i = 0; i < match.capture_count; i++) {
624  const TSQueryCapture *capture = &match.captures[i];
625  result.contents[index++] = (const void *)capture->index;
626  marshal_node(result.contents + index, capture->node);
627  index += 5;
628  }
629  }
630 
631  bool did_exceed_match_limit =
633  TRANSFER_BUFFER[0] = (const void *)(match_count);
634  TRANSFER_BUFFER[1] = result.contents;
635  TRANSFER_BUFFER[2] = (const void *)(did_exceed_match_limit);
636 }
bool ts_query_cursor_next_match(TSQueryCursor *, TSQueryMatch *match)
Definition: query.c:3690

References Array, array_grow_by, array_new, code_unit_to_byte(), i, TSQueryCapture::index, marshal_node(), match, TSQueryCapture::node, scratch_query_cursor, TRANSFER_BUFFER, ts_query_cursor_did_exceed_match_limit(), ts_query_cursor_exec(), ts_query_cursor_new(), ts_query_cursor_next_match(), ts_query_cursor_set_match_limit(), ts_query_cursor_set_point_range(), UINT32_MAX, and unmarshal_node().

◆ ts_tree_cursor_current_field_id_wasm()

uint32_t ts_tree_cursor_current_field_id_wasm ( const TSTree tree)

Definition at line 315 of file binding.c.

315  {
317  return ts_tree_cursor_current_field_id(&cursor);
318 }
TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *)
Definition: tree_cursor.c:431
static TSTreeCursor unmarshal_cursor(const void **buffer, const TSTree *tree)
Definition: binding.c:58

References TRANSFER_BUFFER, ts_tree_cursor_current_field_id(), and unmarshal_cursor().

◆ ts_tree_cursor_current_node_id_wasm()

const uint32_t ts_tree_cursor_current_node_id_wasm ( const TSTree tree)

Definition at line 285 of file binding.c.

285  {
287  TSNode node = ts_tree_cursor_current_node(&cursor);
288  return (uint32_t)node.id;
289 }

References TSNode::id, TRANSFER_BUFFER, ts_tree_cursor_current_node(), and unmarshal_cursor().

◆ ts_tree_cursor_current_node_is_missing_wasm()

bool ts_tree_cursor_current_node_is_missing_wasm ( const TSTree tree)

Definition at line 279 of file binding.c.

279  {
281  TSNode node = ts_tree_cursor_current_node(&cursor);
282  return ts_node_is_missing(node);
283 }

References TRANSFER_BUFFER, ts_node_is_missing(), ts_tree_cursor_current_node(), and unmarshal_cursor().

◆ ts_tree_cursor_current_node_is_named_wasm()

bool ts_tree_cursor_current_node_is_named_wasm ( const TSTree tree)

Definition at line 273 of file binding.c.

273  {
275  TSNode node = ts_tree_cursor_current_node(&cursor);
276  return ts_node_is_named(node);
277 }

References TRANSFER_BUFFER, ts_node_is_named(), ts_tree_cursor_current_node(), and unmarshal_cursor().

◆ ts_tree_cursor_current_node_type_id_wasm()

uint16_t ts_tree_cursor_current_node_type_id_wasm ( const TSTree tree)

Definition at line 267 of file binding.c.

267  {
269  TSNode node = ts_tree_cursor_current_node(&cursor);
270  return ts_node_symbol(node);
271 }

References TRANSFER_BUFFER, ts_node_symbol(), ts_tree_cursor_current_node(), and unmarshal_cursor().

◆ ts_tree_cursor_current_node_wasm()

void ts_tree_cursor_current_node_wasm ( const TSTree tree)

◆ ts_tree_cursor_delete_wasm()

void ts_tree_cursor_delete_wasm ( const TSTree tree)

Definition at line 234 of file binding.c.

234  {
236  ts_tree_cursor_delete(&cursor);
237 }
void ts_tree_cursor_delete(TSTreeCursor *)
Definition: tree_cursor.c:94

References TRANSFER_BUFFER, ts_tree_cursor_delete(), and unmarshal_cursor().

◆ ts_tree_cursor_end_index_wasm()

uint32_t ts_tree_cursor_end_index_wasm ( const TSTree tree)

◆ ts_tree_cursor_end_position_wasm()

void ts_tree_cursor_end_position_wasm ( const TSTree tree)

◆ ts_tree_cursor_goto_first_child_wasm()

bool ts_tree_cursor_goto_first_child_wasm ( const TSTree tree)

Definition at line 246 of file binding.c.

246  {
248  bool result = ts_tree_cursor_goto_first_child(&cursor);
249  marshal_cursor(&cursor);
250  return result;
251 }
static void marshal_cursor(const TSTreeCursor *cursor)
Definition: binding.c:52

References marshal_cursor(), TRANSFER_BUFFER, ts_tree_cursor_goto_first_child(), and unmarshal_cursor().

◆ ts_tree_cursor_goto_next_sibling_wasm()

bool ts_tree_cursor_goto_next_sibling_wasm ( const TSTree tree)

Definition at line 253 of file binding.c.

253  {
255  bool result = ts_tree_cursor_goto_next_sibling(&cursor);
256  marshal_cursor(&cursor);
257  return result;
258 }

References marshal_cursor(), TRANSFER_BUFFER, ts_tree_cursor_goto_next_sibling(), and unmarshal_cursor().

◆ ts_tree_cursor_goto_parent_wasm()

bool ts_tree_cursor_goto_parent_wasm ( const TSTree tree)

Definition at line 260 of file binding.c.

260  {
262  bool result = ts_tree_cursor_goto_parent(&cursor);
263  marshal_cursor(&cursor);
264  return result;
265 }

References marshal_cursor(), TRANSFER_BUFFER, ts_tree_cursor_goto_parent(), and unmarshal_cursor().

◆ ts_tree_cursor_new_wasm()

void ts_tree_cursor_new_wasm ( const TSTree tree)

Definition at line 228 of file binding.c.

228  {
229  TSNode node = unmarshal_node(tree);
230  TSTreeCursor cursor = ts_tree_cursor_new(node);
231  marshal_cursor(&cursor);
232 }
TSTreeCursor ts_tree_cursor_new(TSNode)
Definition: tree_cursor.c:70

References marshal_cursor(), ts_tree_cursor_new(), and unmarshal_node().

◆ ts_tree_cursor_reset_wasm()

void ts_tree_cursor_reset_wasm ( const TSTree tree)

Definition at line 239 of file binding.c.

239  {
240  TSNode node = unmarshal_node(tree);
241  TSTreeCursor cursor = unmarshal_cursor(&TRANSFER_BUFFER[5], tree);
242  ts_tree_cursor_reset(&cursor, node);
243  marshal_cursor(&cursor);
244 }

References marshal_cursor(), TRANSFER_BUFFER, ts_tree_cursor_reset(), unmarshal_cursor(), and unmarshal_node().

◆ ts_tree_cursor_start_index_wasm()

uint32_t ts_tree_cursor_start_index_wasm ( const TSTree tree)

◆ ts_tree_cursor_start_position_wasm()

void ts_tree_cursor_start_position_wasm ( const TSTree tree)

◆ ts_tree_edit_wasm()

void ts_tree_edit_wasm ( TSTree tree)

Definition at line 209 of file binding.c.

209  {
210  TSInputEdit edit = unmarshal_edit();
211  ts_tree_edit(tree, &edit);
212 }
void ts_tree_edit(TSTree *self, const TSInputEdit *edit)
Definition: tree.c:44
static TSInputEdit unmarshal_edit()
Definition: binding.c:93

References ts_tree_edit(), and unmarshal_edit().

◆ ts_tree_get_changed_ranges_wasm()

void ts_tree_get_changed_ranges_wasm ( TSTree tree,
TSTree other 
)

Definition at line 214 of file binding.c.

214  {
215  unsigned range_count;
216  TSRange *ranges = ts_tree_get_changed_ranges(tree, other, &range_count);
217  for (unsigned i = 0; i < range_count; i++) {
218  marshal_range(&ranges[i]);
219  }
220  TRANSFER_BUFFER[0] = (const void *)range_count;
221  TRANSFER_BUFFER[1] = (const void *)ranges;
222 }
TSRange * ts_tree_get_changed_ranges(const TSTree *old_tree, const TSTree *new_tree, uint32_t *length)
Definition: tree.c:78
static void marshal_range(TSRange *range)
Definition: binding.c:79
Definition: api.h:60

References i, marshal_range(), TRANSFER_BUFFER, and ts_tree_get_changed_ranges().

◆ ts_tree_root_node_wasm()

void ts_tree_root_node_wasm ( const TSTree tree)

Definition at line 205 of file binding.c.

205  {
207 }
TSNode ts_tree_root_node(const TSTree *self)
Definition: tree.c:36

References marshal_node(), TRANSFER_BUFFER, and ts_tree_root_node().

◆ unmarshal_cursor()

◆ unmarshal_edit()

static TSInputEdit unmarshal_edit ( )
static

Definition at line 93 of file binding.c.

93  {
94  TSInputEdit edit;
95  const void **address = TRANSFER_BUFFER;
96  edit.start_point = unmarshal_point(address); address += 2;
97  edit.old_end_point = unmarshal_point(address); address += 2;
98  edit.new_end_point = unmarshal_point(address); address += 2;
99  edit.start_byte = code_unit_to_byte((uint32_t)*address); address += 1;
100  edit.old_end_byte = code_unit_to_byte((uint32_t)*address); address += 1;
101  edit.new_end_byte = code_unit_to_byte((uint32_t)*address); address += 1;
102  return edit;
103 }
uint32_t old_end_byte
Definition: api.h:85
uint32_t start_byte
Definition: api.h:84
uint32_t new_end_byte
Definition: api.h:86
TSPoint old_end_point
Definition: api.h:88
TSPoint start_point
Definition: api.h:87
TSPoint new_end_point
Definition: api.h:89

References code_unit_to_byte(), TSInputEdit::new_end_byte, TSInputEdit::new_end_point, TSInputEdit::old_end_byte, TSInputEdit::old_end_point, TSInputEdit::start_byte, TSInputEdit::start_point, TRANSFER_BUFFER, and unmarshal_point().

Referenced by ts_tree_edit_wasm().

◆ unmarshal_node()

static TSNode unmarshal_node ( const TSTree tree)
inlinestatic

◆ unmarshal_point()

static TSPoint unmarshal_point ( const void **  address)
static

Definition at line 72 of file binding.c.

72  {
73  TSPoint point;
74  point.row = (uint32_t)address[0];
75  point.column = code_unit_to_byte((uint32_t)address[1]);
76  return point;
77 }

References code_unit_to_byte().

Referenced by ts_node_descendant_for_position_wasm(), ts_node_named_descendant_for_position_wasm(), and unmarshal_edit().

◆ unmarshal_range()

static void unmarshal_range ( TSRange range)
static

Definition at line 86 of file binding.c.

86  {
87  range->start_byte = code_unit_to_byte(range->start_byte);
88  range->end_byte = code_unit_to_byte(range->end_byte);
89  range->start_point.column = code_unit_to_byte(range->start_point.column);
90  range->end_point.column = code_unit_to_byte(range->end_point.column);
91 }

References code_unit_to_byte(), and capstone::range.

Referenced by ts_parser_parse_wasm().

Variable Documentation

◆ INPUT_BUFFER_SIZE

const uint32_t INPUT_BUFFER_SIZE = 10 * 1024
static

Definition at line 11 of file binding.c.

Referenced by call_parse_callback(), and ts_parser_new_wasm().

◆ scratch_cursor

TSTreeCursor scratch_cursor = {0}
static

◆ scratch_query_cursor

TSQueryCursor* scratch_query_cursor = NULL
static

Definition at line 330 of file binding.c.

Referenced by ts_query_captures_wasm(), and ts_query_matches_wasm().

◆ TRANSFER_BUFFER