Fully remove Code_Index_Nest_Ptr_Array from the codebase, use Code_Index_Nest_List instead
This commit is contained in:
parent
1dfc106e8c
commit
76863fc03a
|
@ -18,32 +18,35 @@ delims_are_open_close_pair(Code_Index_Scope_Delim_Kind a, Code_Index_Scope_Delim
|
|||
////////////////////////////////
|
||||
// NOTE(allen): Lookups
|
||||
|
||||
// TODO(allen): accelerator for these nest lookups?
|
||||
// Looks like the only one I ever actually use is the file one, not the array one.
|
||||
function Code_Index_Nest*
|
||||
code_index_get_nest_(Code_Index_Nest_Ptr_Array *array, i64 pos){
|
||||
code_index_get_nest_from_list(Code_Index_Nest_List *list, i64 pos)
|
||||
{
|
||||
Code_Index_Nest *result = 0;
|
||||
i32 count = array->count;
|
||||
Code_Index_Nest **nest_ptrs = array->ptrs;
|
||||
i32 count = list->count;
|
||||
Code_Index_Nest *nest_at = list->first;
|
||||
for (i32 i = 0; i < count; i += 1){
|
||||
Code_Index_Nest *nest = nest_ptrs[i];
|
||||
if (nest->open.max <= pos && pos <= nest->close.min){
|
||||
Code_Index_Nest *sub_nest = code_index_get_nest_(&nest->nest_array, pos);
|
||||
if (sub_nest != 0){
|
||||
if (nest_at->open.max <= pos && pos <= nest_at->close.min){
|
||||
Code_Index_Nest *sub_nest = code_index_get_nest_from_list(&nest_at->nest_list, pos);
|
||||
if (sub_nest != 0)
|
||||
{
|
||||
result = sub_nest;
|
||||
}
|
||||
else{
|
||||
result = nest;
|
||||
else
|
||||
{
|
||||
result = nest_at;
|
||||
}
|
||||
break;
|
||||
}
|
||||
nest_at = nest_at->next;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
function Code_Index_Nest*
|
||||
code_index_get_nest(Code_Index_File *file, i64 pos){
|
||||
return(code_index_get_nest_(&file->nest_array, pos));
|
||||
code_index_get_nest(Code_Index_File *file, i64 pos)
|
||||
{
|
||||
Code_Index_Nest* result = code_index_get_nest_from_list(&file->nest_list, pos);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Code_Index_Note_List*
|
||||
|
@ -106,21 +109,6 @@ code_index_push_nest(Code_Index_Nest_List *list, Code_Index_Nest *nest){
|
|||
list->count += 1;
|
||||
}
|
||||
|
||||
function Code_Index_Nest_Ptr_Array
|
||||
code_index_nest_ptr_array_from_list(Arena *arena, Code_Index_Nest_List *list){
|
||||
Code_Index_Nest_Ptr_Array array = {};
|
||||
array.ptrs = push_array_zero(arena, Code_Index_Nest*, list->count);
|
||||
array.count = list->count;
|
||||
i32 counter = 0;
|
||||
for (Code_Index_Nest *node = list->first;
|
||||
node != 0;
|
||||
node = node->next){
|
||||
array.ptrs[counter] = node;
|
||||
counter += 1;
|
||||
}
|
||||
return(array);
|
||||
}
|
||||
|
||||
function Code_Index_Note_Ptr_Array
|
||||
code_index_note_ptr_array_from_list(Arena *arena, Code_Index_Note_List *list){
|
||||
Code_Index_Note_Ptr_Array array = {};
|
||||
|
@ -218,7 +206,8 @@ code_index_get_file_storage(Buffer_ID buffer){
|
|||
}
|
||||
|
||||
function Code_Index_File*
|
||||
code_index_get_file(Buffer_ID buffer){
|
||||
code_index_get_file(Buffer_ID buffer)
|
||||
{
|
||||
Code_Index_File *result = 0;
|
||||
Code_Index_File_Storage *storage = code_index_get_file_storage(buffer);
|
||||
if (storage) result = storage->file;
|
||||
|
@ -226,7 +215,8 @@ code_index_get_file(Buffer_ID buffer){
|
|||
}
|
||||
|
||||
function void
|
||||
index_shift(i64 *ptr, Range_i64 old_range, u64 new_size){
|
||||
index_shift(i64 *ptr, Range_i64 old_range, u64 new_size)
|
||||
{
|
||||
i64 i = *ptr;
|
||||
if (old_range.min <= i && i < old_range.max){
|
||||
*ptr = old_range.first;
|
||||
|
@ -237,25 +227,27 @@ index_shift(i64 *ptr, Range_i64 old_range, u64 new_size){
|
|||
}
|
||||
|
||||
function void
|
||||
code_index_shift(Code_Index_Nest_Ptr_Array *array,
|
||||
Range_i64 old_range, u64 new_size){
|
||||
i32 count = array->count;
|
||||
Code_Index_Nest **nest_ptr = array->ptrs;
|
||||
for (i32 i = 0; i < count; i += 1, nest_ptr += 1){
|
||||
Code_Index_Nest *nest = *nest_ptr;
|
||||
code_index_shift_list(Code_Index_Nest_List *list, Range_i64 old_range, u64 new_size)
|
||||
{
|
||||
i32 count = list->count;
|
||||
Code_Index_Nest *nest = list->first;
|
||||
for (i32 i = 0; i < count; i += 1, nest = nest->next)
|
||||
{
|
||||
index_shift(&nest->open.min, old_range, new_size);
|
||||
index_shift(&nest->open.max, old_range, new_size);
|
||||
if (nest->is_closed){
|
||||
if (nest->is_closed)
|
||||
{
|
||||
index_shift(&nest->close.min, old_range, new_size);
|
||||
index_shift(&nest->close.max, old_range, new_size);
|
||||
}
|
||||
code_index_shift(&nest->nest_array, old_range, new_size);
|
||||
code_index_shift_list(&nest->nest_list, old_range, new_size);
|
||||
}
|
||||
}
|
||||
|
||||
function void
|
||||
code_index_shift(Code_Index_File *file, Range_i64 old_range, u64 new_size){
|
||||
code_index_shift(&file->nest_array, old_range, new_size);
|
||||
code_index_shift(Code_Index_File *file, Range_i64 old_range, u64 new_size)
|
||||
{
|
||||
code_index_shift_list(&file->nest_list, old_range, new_size);
|
||||
}
|
||||
|
||||
|
||||
|
@ -593,8 +585,6 @@ generic_parse_preprocessor(Code_Index_File *index, Generic_Parse_State *state){
|
|||
generic_parse_inc(state);
|
||||
}
|
||||
|
||||
result->nest_array = code_index_nest_ptr_array_from_list(state->arena, &result->nest_list);
|
||||
|
||||
state->in_preprocessor = false;
|
||||
|
||||
return(result);
|
||||
|
@ -673,8 +663,6 @@ generic_parse_scope(Code_Index_File *index, Generic_Parse_State *state){
|
|||
}
|
||||
}
|
||||
|
||||
result->nest_array = code_index_nest_ptr_array_from_list(state->arena, &result->nest_list);
|
||||
|
||||
state->scope_counter -= 1;
|
||||
|
||||
return(result);
|
||||
|
@ -755,8 +743,6 @@ generic_parse_paren(Code_Index_File *index, Generic_Parse_State *state){
|
|||
generic_parse_inc(state);
|
||||
}
|
||||
|
||||
result->nest_array = code_index_nest_ptr_array_from_list(state->arena, &result->nest_list);
|
||||
|
||||
state->paren_counter -= 1;
|
||||
|
||||
return(result);
|
||||
|
@ -820,7 +806,6 @@ generic_parse_full_input_breaks(Code_Index_File *index, Generic_Parse_State *sta
|
|||
}
|
||||
|
||||
if (result){
|
||||
index->nest_array = code_index_nest_ptr_array_from_list(state->arena, &index->nest_list);
|
||||
index->note_array = code_index_note_ptr_array_from_list(state->arena, &index->note_list);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,6 @@ struct Code_Index_Nest_List{
|
|||
i32 count;
|
||||
};
|
||||
|
||||
struct Code_Index_Nest_Ptr_Array{
|
||||
struct Code_Index_Nest **ptrs;
|
||||
i32 count;
|
||||
};
|
||||
|
||||
typedef i32 Code_Index_Nest_Kind;
|
||||
enum{
|
||||
CodeIndexNest_Scope,
|
||||
|
@ -70,7 +65,6 @@ struct Code_Index_Nest{
|
|||
Code_Index_Nest *parent;
|
||||
|
||||
Code_Index_Nest_List nest_list;
|
||||
Code_Index_Nest_Ptr_Array nest_array;
|
||||
};
|
||||
|
||||
typedef i64 Code_Index_Note_Kind;
|
||||
|
@ -108,7 +102,6 @@ struct Code_Index_File{
|
|||
Code_Index_Scope_Delim_List scope_delim_list;
|
||||
Code_Index_Scope_Delim_Ptr_Array scope_delim_array;
|
||||
Code_Index_Nest_List nest_list;
|
||||
Code_Index_Nest_Ptr_Array nest_array;
|
||||
Code_Index_Note_List note_list;
|
||||
Code_Index_Note_Ptr_Array note_array;
|
||||
Buffer_ID buffer;
|
||||
|
|
|
@ -273,44 +273,6 @@ default_buffer_region(Application_Links *app, View_ID view_id, Rect_f32 region){
|
|||
return(region);
|
||||
}
|
||||
|
||||
function void
|
||||
recursive_nest_highlight(Application_Links *app, Text_Layout_ID layout_id, Range_i64 range,
|
||||
Code_Index_Nest_Ptr_Array *array, i32 counter){
|
||||
Code_Index_Nest **ptr = array->ptrs;
|
||||
Code_Index_Nest **ptr_end = ptr + array->count;
|
||||
|
||||
for (;ptr < ptr_end; ptr += 1){
|
||||
Code_Index_Nest *nest = *ptr;
|
||||
if (!nest->is_closed){
|
||||
break;
|
||||
}
|
||||
if (range.first <= nest->close.max){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ARGB_Color argb = finalize_color(defcolor_text_cycle, counter);
|
||||
|
||||
for (;ptr < ptr_end; ptr += 1){
|
||||
Code_Index_Nest *nest = *ptr;
|
||||
if (range.max <= nest->open.min){
|
||||
break;
|
||||
}
|
||||
|
||||
paint_text_color(app, layout_id, nest->open, argb);
|
||||
if (nest->is_closed){
|
||||
paint_text_color(app, layout_id, nest->close, argb);
|
||||
}
|
||||
recursive_nest_highlight(app, layout_id, range, &nest->nest_array, counter + 1);
|
||||
}
|
||||
}
|
||||
|
||||
function void
|
||||
recursive_nest_highlight(Application_Links *app, Text_Layout_ID layout_id, Range_i64 range,
|
||||
Code_Index_File *file){
|
||||
recursive_nest_highlight(app, layout_id, range, &file->nest_array, 0);
|
||||
}
|
||||
|
||||
function void default_render_buffer(
|
||||
Application_Links *app,
|
||||
View_ID view_id,
|
||||
|
|
|
@ -538,7 +538,6 @@ tree_sitter_code_index_update_complete(
|
|||
Code_Index_Nest* nest = state->nest_stack_last->nest;
|
||||
nest->close = delim_at->pos;
|
||||
nest->is_closed = true;
|
||||
nest->nest_array = code_index_nest_ptr_array_from_list(&state->index_arena, &nest->nest_list);
|
||||
|
||||
state->nest_stack_last = state->nest_stack_last->prev;
|
||||
if (state->nest_stack_last != 0) state->nest_stack_last->next = 0;
|
||||
|
@ -548,20 +547,12 @@ tree_sitter_code_index_update_complete(
|
|||
delim_at = delim_at->next;
|
||||
}
|
||||
|
||||
while (state->nest_stack_last != 0)
|
||||
{
|
||||
Code_Index_Nest* nest = state->nest_stack_last->nest;
|
||||
nest->nest_array = code_index_nest_ptr_array_from_list(&state->index_arena, &nest->nest_list);
|
||||
state->nest_stack_last = state->nest_stack_last->prev;
|
||||
}
|
||||
|
||||
for (Code_Index_Note* note = state->index->note_list.first; note != 0 && note->next != note; note = note->next)
|
||||
{
|
||||
note->text = push_string_copy(&state->index_arena, string_substring(state->buffer_contents, note->pos));
|
||||
}
|
||||
|
||||
// Finish the Index
|
||||
state->index->nest_array = code_index_nest_ptr_array_from_list(&state->index_arena, &state->index->nest_list);
|
||||
state->index->note_array = code_index_note_ptr_array_from_list(&state->index_arena, &state->index->note_list);
|
||||
|
||||
code_index_lock();
|
||||
|
|
Loading…
Reference in New Issue