Rizin
unix-like reverse engineering framework and cli tools
language.c
Go to the documentation of this file.
1 #include "./language.h"
2 #include "./subtree.h"
3 #include "./error_costs.h"
4 #include <string.h>
5 
7  return self->symbol_count + self->alias_count;
8 }
9 
11  return self->version;
12 }
13 
15  return self->field_count;
16 }
17 
19  const TSLanguage *self,
21  TSSymbol symbol,
22  TableEntry *result
23 ) {
24  if (symbol == ts_builtin_sym_error || symbol == ts_builtin_sym_error_repeat) {
25  result->action_count = 0;
26  result->is_reusable = false;
27  result->actions = NULL;
28  } else {
29  assert(symbol < self->token_count);
30  uint32_t action_index = ts_language_lookup(self, state, symbol);
31  const TSParseActionEntry *entry = &self->parse_actions[action_index];
32  result->action_count = entry->entry.count;
33  result->is_reusable = entry->entry.reusable;
34  result->actions = (const TSParseAction *)(entry + 1);
35  }
36 }
37 
39  const TSLanguage *self,
40  TSSymbol symbol
41 ) {
42  if (symbol == ts_builtin_sym_error) {
43  return (TSSymbolMetadata) {.visible = true, .named = true};
44  } else if (symbol == ts_builtin_sym_error_repeat) {
45  return (TSSymbolMetadata) {.visible = false, .named = false};
46  } else {
47  return self->symbol_metadata[symbol];
48  }
49 }
50 
52  const TSLanguage *self,
53  TSSymbol symbol
54 ) {
55  if (symbol == ts_builtin_sym_error) return symbol;
56  return self->public_symbol_map[symbol];
57 }
58 
60  const TSLanguage *self,
61  TSSymbol symbol
62 ) {
63  if (symbol == ts_builtin_sym_error) {
64  return "ERROR";
65  } else if (symbol == ts_builtin_sym_error_repeat) {
66  return "_ERROR";
67  } else if (symbol < ts_language_symbol_count(self)) {
68  return self->symbol_names[symbol];
69  } else {
70  return NULL;
71  }
72 }
73 
75  const TSLanguage *self,
76  const char *string,
78  bool is_named
79 ) {
80  if (!strncmp(string, "ERROR", length)) return ts_builtin_sym_error;
82  for (TSSymbol i = 0; i < count; i++) {
84  if ((!metadata.visible && !metadata.supertype) || metadata.named != is_named) continue;
85  const char *symbol_name = self->symbol_names[i];
86  if (!strncmp(symbol_name, string, length) && !symbol_name[length]) {
87  return self->public_symbol_map[i];
88  }
89  }
90  return 0;
91 }
92 
94  const TSLanguage *self,
95  TSSymbol symbol
96 ) {
97  TSSymbolMetadata metadata = ts_language_symbol_metadata(self, symbol);
98  if (metadata.named && metadata.visible) {
99  return TSSymbolTypeRegular;
100  } else if (metadata.visible) {
101  return TSSymbolTypeAnonymous;
102  } else {
103  return TSSymbolTypeAuxiliary;
104  }
105 }
106 
108  const TSLanguage *self,
109  TSFieldId id
110 ) {
112  if (count && id <= count) {
113  return self->field_names[id];
114  } else {
115  return NULL;
116  }
117 }
118 
120  const TSLanguage *self,
121  const char *name,
122  uint32_t name_length
123 ) {
125  for (TSSymbol i = 1; i < count + 1; i++) {
126  switch (strncmp(name, self->field_names[i], name_length)) {
127  case 0:
128  if (self->field_names[i][name_length] == 0) return i;
129  break;
130  case -1:
131  return 0;
132  default:
133  break;
134  }
135  }
136  return 0;
137 }
lzma_index ** i
Definition: index.h:629
TSSymbolType
Definition: api.h:49
@ TSSymbolTypeAuxiliary
Definition: api.h:52
@ TSSymbolTypeRegular
Definition: api.h:50
@ TSSymbolTypeAnonymous
Definition: api.h:51
#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
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
const char * ts_language_symbol_name(const TSLanguage *self, TSSymbol symbol)
Definition: language.c:59
TSSymbol ts_language_public_symbol(const TSLanguage *self, TSSymbol symbol)
Definition: language.c:51
TSSymbolType ts_language_symbol_type(const TSLanguage *self, TSSymbol symbol)
Definition: language.c:93
const char * ts_language_field_name_for_id(const TSLanguage *self, TSFieldId id)
Definition: language.c:107
uint32_t ts_language_version(const TSLanguage *self)
Definition: language.c:10
uint32_t ts_language_symbol_count(const TSLanguage *self)
Definition: language.c:6
void ts_language_table_entry(const TSLanguage *self, TSStateId state, TSSymbol symbol, TableEntry *result)
Definition: language.c:18
TSSymbolMetadata ts_language_symbol_metadata(const TSLanguage *self, TSSymbol symbol)
Definition: language.c:38
TSFieldId ts_language_field_id_for_name(const TSLanguage *self, const char *name, uint32_t name_length)
Definition: language.c:119
TSSymbol ts_language_symbol_for_name(const TSLanguage *self, const char *string, uint32_t length, bool is_named)
Definition: language.c:74
uint32_t ts_language_field_count(const TSLanguage *self)
Definition: language.c:14
static uint16_t ts_language_lookup(const TSLanguage *self, TSStateId state, TSSymbol symbol)
Definition: language.h:74
#define ts_builtin_sym_error_repeat
Definition: language.h:11
assert(limit<=UINT32_MAX/2)
int id
Definition: op.c:540
uint16_t TSStateId
Definition: parser.h:16
uint16_t TSFieldId
Definition: parser.h:20
uint16_t TSSymbol
Definition: parser.h:19
#define ts_builtin_sym_error
Definition: parser.h:12
unsigned int uint32_t
Definition: sftypes.h:29
bool visible
Definition: parser.h:36
bool supertype
Definition: parser.h:38
bool is_reusable
Definition: language.h:16
uint32_t action_count
Definition: language.h:15
const TSParseAction * actions
Definition: language.h:14
Definition: zipcmp.c:77
Definition: z80asm.h:102
Definition: dis.h:43