Renamed some structs

This commit is contained in:
Maieul BOYER 2024-08-31 15:36:44 +00:00
parent e91a509d4c
commit deba39ea8a
4 changed files with 265 additions and 254 deletions

View file

@ -6,39 +6,38 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/31 12:03:07 by maiboyer #+# #+# */
/* Updated: 2024/08/31 12:03:08 by maiboyer ### ########.fr */
/* Updated: 2024/08/31 15:27:32 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSE_STACK_H
#define PARSE_STACK_H
#include "me/types.h"
#include "parser/array.h"
#include "parser/subtree.h"
#include "me/types.h"
typedef struct Stack Stack;
typedef t_u32 StackVersion;
typedef struct s_stack Stack;
typedef t_u32 t_stack_version;
typedef struct s_stack_slice t_stack_slice;
typedef struct s_stack_summary_entry t_stack_summary_entry;
typedef Array(t_stack_slice) t_stack_slice_array;
typedef Array(t_stack_summary_entry) t_stack_summary;
#define STACK_VERSION_NONE ((StackVersion)-1)
#define STACK_VERSION_NONE ((t_stack_version) - 1)
typedef struct StackSlice
struct s_stack_slice
{
SubtreeArray subtrees;
StackVersion version;
} StackSlice;
typedef Array(StackSlice) StackSliceArray;
t_stack_version version;
};
typedef struct StackSummaryEntry
struct s_stack_summary_entry
{
Length position;
t_u32 depth;
TSStateId state;
} StackSummaryEntry;
typedef Array(StackSummaryEntry) StackSummary;
typedef void (*StackIterateCallback)(void *, TSStateId, t_u32);
};
// Create a stack.
Stack *ts_stack_new(/*SubtreePool **/);
@ -51,86 +50,86 @@ t_u32 ts_stack_version_count(const Stack *);
// Get the state at the top of the given version of the stack. If the stack is
// empty, this returns the initial state, 0.
TSStateId ts_stack_state(const Stack *, StackVersion);
TSStateId ts_stack_state(const Stack *, t_stack_version);
// Get the last external token associated with a given version of the stack.
Subtree ts_stack_last_external_token(const Stack *, StackVersion);
Subtree ts_stack_last_external_token(const Stack *, t_stack_version);
// Set the last external token associated with a given version of the stack.
void ts_stack_set_last_external_token(Stack *, StackVersion, Subtree);
void ts_stack_set_last_external_token(Stack *, t_stack_version, Subtree);
// Get the position of the given version of the stack within the document.
Length ts_stack_position(const Stack *, StackVersion);
Length ts_stack_position(const Stack *, t_stack_version);
// Push a tree and state onto the given version of the stack.
//
// This transfers ownership of the tree to the Stack. Callers that
// need to retain ownership of the tree for their own purposes should
// first retain the tree.
void ts_stack_push(Stack *, StackVersion, Subtree, bool, TSStateId);
void ts_stack_push(Stack *, t_stack_version, Subtree, bool, TSStateId);
// Pop the given number of entries from the given version of the stack. This
// operation can increase the number of stack versions by revealing multiple
// versions which had previously been merged. It returns an array that
// specifies the index of each revealed version and the trees that were
// removed from that version.
StackSliceArray ts_stack_pop_count(Stack *, StackVersion, t_u32 count);
t_stack_slice_array ts_stack_pop_count(Stack *, t_stack_version, t_u32 count);
// Remove an error at the top of the given version of the stack.
SubtreeArray ts_stack_pop_error(Stack *, StackVersion);
SubtreeArray ts_stack_pop_error(Stack *, t_stack_version);
// Remove any pending trees from the top of the given version of the stack.
StackSliceArray ts_stack_pop_pending(Stack *, StackVersion);
t_stack_slice_array ts_stack_pop_pending(Stack *, t_stack_version);
// Remove any all trees from the given version of the stack.
StackSliceArray ts_stack_pop_all(Stack *, StackVersion);
t_stack_slice_array ts_stack_pop_all(Stack *, t_stack_version);
// Get the maximum number of tree nodes reachable from this version of the stack
// since the last error was detected.
t_u32 ts_stack_node_count_since_error(const Stack *, StackVersion);
t_u32 ts_stack_node_count_since_error(const Stack *, t_stack_version);
int ts_stack_dynamic_precedence(Stack *, StackVersion);
int ts_stack_dynamic_precedence(Stack *, t_stack_version);
bool ts_stack_has_advanced_since_error(const Stack *, StackVersion);
bool ts_stack_has_advanced_since_error(const Stack *, t_stack_version);
// Compute a summary of all the parse states near the top of the given
// version of the stack and store the summary for later retrieval.
void ts_stack_record_summary(Stack *, StackVersion, t_u32 max_depth);
void ts_stack_record_summary(Stack *, t_stack_version, t_u32 max_depth);
// Retrieve a summary of all the parse states near the top of the
// given version of the stack.
StackSummary *ts_stack_get_summary(Stack *, StackVersion);
t_stack_summary *ts_stack_get_summary(Stack *, t_stack_version);
// Get the total cost of all errors on the given version of the stack.
t_u32 ts_stack_error_cost(const Stack *, StackVersion version);
t_u32 ts_stack_error_cost(const Stack *, t_stack_version version);
// Merge the given two stack versions if possible, returning true
// if they were successfully merged and false otherwise.
bool ts_stack_merge(Stack *, StackVersion, StackVersion);
bool ts_stack_merge(Stack *, t_stack_version, t_stack_version);
// Determine whether the given two stack versions can be merged.
bool ts_stack_can_merge(Stack *, StackVersion, StackVersion);
bool ts_stack_can_merge(Stack *, t_stack_version, t_stack_version);
Subtree ts_stack_resume(Stack *, StackVersion);
Subtree ts_stack_resume(Stack *, t_stack_version);
void ts_stack_pause(Stack *, StackVersion, Subtree);
void ts_stack_pause(Stack *, t_stack_version, Subtree);
void ts_stack_halt(Stack *, StackVersion);
void ts_stack_halt(Stack *, t_stack_version);
bool ts_stack_is_active(const Stack *, StackVersion);
bool ts_stack_is_active(const Stack *, t_stack_version);
bool ts_stack_is_paused(const Stack *, StackVersion);
bool ts_stack_is_paused(const Stack *, t_stack_version);
bool ts_stack_is_halted(const Stack *, StackVersion);
bool ts_stack_is_halted(const Stack *, t_stack_version);
void ts_stack_renumber_version(Stack *, StackVersion, StackVersion);
void ts_stack_renumber_version(Stack *, t_stack_version, t_stack_version);
void ts_stack_swap_versions(Stack *, StackVersion, StackVersion);
void ts_stack_swap_versions(Stack *, t_stack_version, t_stack_version);
StackVersion ts_stack_copy_version(Stack *, StackVersion);
t_stack_version ts_stack_copy_version(Stack *, t_stack_version);
// Remove the given version from the stack.
void ts_stack_remove_version(Stack *, StackVersion);
void ts_stack_remove_version(Stack *, t_stack_version);
void ts_stack_clear(Stack *);