Rizin
unix-like reverse engineering framework and cli tools
stack.h
Go to the documentation of this file.
1 #ifndef TREE_SITTER_PARSE_STACK_H_
2 #define TREE_SITTER_PARSE_STACK_H_
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include "./array.h"
9 #include "./subtree.h"
10 #include "./error_costs.h"
11 #include <stdio.h>
12 
13 typedef struct Stack Stack;
14 
15 typedef unsigned StackVersion;
16 #define STACK_VERSION_NONE ((StackVersion)-1)
17 
18 typedef struct {
19  SubtreeArray subtrees;
21 } StackSlice;
22 typedef Array(StackSlice) StackSliceArray;
23 
24 typedef struct {
26  unsigned depth;
29 typedef Array(StackSummaryEntry) StackSummary;
30 
31 // Create a stack.
33 
34 // Release the memory reserved for a given stack.
35 void ts_stack_delete(Stack *);
36 
37 // Get the stack's current number of versions.
39 
40 // Get the state at the top of the given version of the stack. If the stack is
41 // empty, this returns the initial state, 0.
43 
44 // Get the last external token associated with a given version of the stack.
46 
47 // Set the last external token associated with a given version of the stack.
49 
50 // Get the position of the given version of the stack within the document.
52 
53 // Push a tree and state onto the given version of the stack.
54 //
55 // This transfers ownership of the tree to the Stack. Callers that
56 // need to retain ownership of the tree for their own purposes should
57 // first retain the tree.
59 
60 // Pop the given number of entries from the given version of the stack. This
61 // operation can increase the number of stack versions by revealing multiple
62 // versions which had previously been merged. It returns an array that
63 // specifies the index of each revealed version and the trees that were
64 // removed from that version.
66 
67 // Remove an error at the top of the given version of the stack.
68 SubtreeArray ts_stack_pop_error(Stack *, StackVersion);
69 
70 // Remove any pending trees from the top of the given version of the stack.
71 StackSliceArray ts_stack_pop_pending(Stack *, StackVersion);
72 
73 // Remove any all trees from the given version of the stack.
74 StackSliceArray ts_stack_pop_all(Stack *, StackVersion);
75 
76 // Get the maximum number of tree nodes reachable from this version of the stack
77 // since the last error was detected.
79 
81 
83 
84 // Compute a summary of all the parse states near the top of the given
85 // version of the stack and store the summary for later retrieval.
86 void ts_stack_record_summary(Stack *, StackVersion, unsigned max_depth);
87 
88 // Retrieve a summary of all the parse states near the top of the
89 // given version of the stack.
90 StackSummary *ts_stack_get_summary(Stack *, StackVersion);
91 
92 // Get the total cost of all errors on the given version of the stack.
94 
95 // Merge the given two stack versions if possible, returning true
96 // if they were successfully merged and false otherwise.
98 
99 // Determine whether the given two stack versions can be merged.
101 
103 
105 
107 
108 bool ts_stack_is_active(const Stack *, StackVersion);
109 
110 bool ts_stack_is_paused(const Stack *, StackVersion);
111 
112 bool ts_stack_is_halted(const Stack *, StackVersion);
113 
115 
117 
119 
120 // Remove the given version from the stack.
122 
123 void ts_stack_clear(Stack *);
124 
125 bool ts_stack_print_dot_graph(Stack *, const TSLanguage *, FILE *);
126 
127 typedef void (*StackIterateCallback)(void *, TSStateId, uint32_t);
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #endif // TREE_SITTER_PARSE_STACK_H_
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
string FILE
Definition: benchmark.py:21
uint16_t TSStateId
Definition: parser.h:16
unsigned int uint32_t
Definition: sftypes.h:29
StackSliceArray ts_stack_pop_count(Stack *, StackVersion, uint32_t count)
Definition: stack.c:507
void ts_stack_record_summary(Stack *, StackVersion, unsigned max_depth)
Definition: stack.c:596
void ts_stack_renumber_version(Stack *, StackVersion, StackVersion)
Definition: stack.c:648
void ts_stack_set_last_external_token(Stack *, StackVersion, Subtree)
Definition: stack.c:459
bool ts_stack_merge(Stack *, StackVersion, StackVersion)
Definition: stack.c:679
Subtree ts_stack_last_external_token(const Stack *, StackVersion)
Definition: stack.c:455
int ts_stack_dynamic_precedence(Stack *, StackVersion)
Definition: stack.c:615
bool ts_stack_is_halted(const Stack *, StackVersion)
Definition: stack.c:720
SubtreeArray ts_stack_pop_error(Stack *, StackVersion)
Definition: stack.c:547
typedef Array(StackSlice) StackSliceArray
bool ts_stack_has_advanced_since_error(const Stack *, StackVersion)
Definition: stack.c:619
StackSummary * ts_stack_get_summary(Stack *, StackVersion)
Definition: stack.c:611
Length ts_stack_position(const Stack *, StackVersion)
Definition: stack.c:451
uint32_t ts_stack_version_count(const Stack *)
Definition: stack.c:443
bool ts_stack_can_merge(Stack *, StackVersion, StackVersion)
Definition: stack.c:693
void ts_stack_swap_versions(Stack *, StackVersion, StackVersion)
Definition: stack.c:663
void ts_stack_push(Stack *, StackVersion, Subtree, bool, TSStateId)
Definition: stack.c:485
StackVersion ts_stack_copy_version(Stack *, StackVersion)
Definition: stack.c:669
unsigned StackVersion
Definition: stack.h:15
void ts_stack_delete(Stack *)
Definition: stack.c:424
void(* StackIterateCallback)(void *, TSStateId, uint32_t)
Definition: stack.h:127
void ts_stack_remove_version(Stack *, StackVersion)
Definition: stack.c:643
Subtree ts_stack_resume(Stack *, StackVersion)
Definition: stack.c:728
void ts_stack_halt(Stack *, StackVersion)
Definition: stack.c:705
unsigned ts_stack_error_cost(const Stack *, StackVersion version)
Definition: stack.c:466
void ts_stack_clear(Stack *)
Definition: stack.c:737
unsigned ts_stack_node_count_since_error(const Stack *, StackVersion)
Definition: stack.c:477
Stack * ts_stack_new(SubtreePool *)
Definition: stack.c:405
StackSliceArray ts_stack_pop_all(Stack *, StackVersion)
Definition: stack.c:569
bool ts_stack_is_active(const Stack *, StackVersion)
Definition: stack.c:716
StackSliceArray ts_stack_pop_pending(Stack *, StackVersion)
Definition: stack.c:524
TSStateId ts_stack_state(const Stack *, StackVersion)
Definition: stack.c:447
void ts_stack_pause(Stack *, StackVersion, Subtree)
Definition: stack.c:709
bool ts_stack_is_paused(const Stack *, StackVersion)
Definition: stack.c:724
bool ts_stack_print_dot_graph(Stack *, const TSLanguage *, FILE *)
Definition: stack.c:751
Definition: length.h:9
SubtreeArray subtrees
Definition: stack.h:19
StackVersion version
Definition: stack.h:20
TSStateId state
Definition: stack.h:27
Length position
Definition: stack.h:25
unsigned depth
Definition: stack.h:26
Definition: stack.c:63