Finished cleanup of old token streaming stuff

master
Allen Webster 2019-02-01 16:58:44 -08:00
parent 3b06664f2b
commit 375fab3d2c
5 changed files with 44 additions and 514 deletions

View File

@ -179,218 +179,6 @@ get_function_positions(Application_Links *app, Buffer_Summary *buffer, int32_t t
return(result);
}
#if 0
static Get_Positions_Results
get_function_positions(Application_Links *app, Buffer_Summary *buffer, int32_t token_index, Function_Positions *positions_array, int32_t positions_max){
Get_Positions_Results result = {};
static const int32_t token_chunk_size = 512;
Cpp_Token token_chunk[token_chunk_size];
Stream_Tokens token_stream = {};
if (init_stream_tokens(&token_stream, app, buffer, token_index, token_chunk, token_chunk_size)){
int32_t nest_level = 0;
int32_t paren_nest_level = 0;
int32_t first_paren_index = 0;
int32_t first_paren_position = 0;
int32_t last_paren_index = 0;
bool32 still_looping = false;
// Look for the next token at global scope that might need to be printed.
mode1:
Assert(nest_level == 0);
Assert(paren_nest_level == 0);
first_paren_index = 0;
first_paren_position = 0;
last_paren_index = 0;
do{
for (; token_index < token_stream.end; ++token_index){
Cpp_Token *token = &token_stream.tokens[token_index];
if (!(token->flags & CPP_TFLAG_PP_BODY)){
switch (token->type){
case CPP_TOKEN_BRACE_OPEN:
{
++nest_level;
}break;
case CPP_TOKEN_BRACE_CLOSE:
{
if (nest_level > 0){
--nest_level;
}
}break;
case CPP_TOKEN_PARENTHESE_OPEN:
{
if (nest_level == 0){
first_paren_index = token_index;
first_paren_position = token->start;
goto paren_mode1;
}
}break;
}
}
}
still_looping = forward_stream_tokens(&token_stream);
}while(still_looping);
goto end;
// Look for a closing parenthese to mark the end of a function signature.
paren_mode1:
paren_nest_level = 0;
do{
for (; token_index < token_stream.end; ++token_index){
Cpp_Token *token = &token_stream.tokens[token_index];
if (!(token->flags & CPP_TFLAG_PP_BODY)){
switch (token->type){
case CPP_TOKEN_PARENTHESE_OPEN:
{
++paren_nest_level;
}break;
case CPP_TOKEN_PARENTHESE_CLOSE:
{
--paren_nest_level;
if (paren_nest_level == 0){
last_paren_index = token_index;
goto paren_mode2;
}
}break;
}
}
}
still_looping = forward_stream_tokens(&token_stream);
}while(still_looping);
goto end;
// Look backwards from an open parenthese to find the start of a function signature.
paren_mode2: {
Stream_Tokens backward_stream_temp = begin_temp_stream_token(&token_stream);
int32_t local_index = first_paren_index;
int32_t signature_start_index = 0;
do{
for (; local_index >= token_stream.start; --local_index){
Cpp_Token *token = &token_stream.tokens[local_index];
if ((token->flags & CPP_TFLAG_PP_BODY) || (token->flags & CPP_TFLAG_PP_DIRECTIVE) || token->type == CPP_TOKEN_BRACE_CLOSE || token->type == CPP_TOKEN_SEMICOLON || token->type == CPP_TOKEN_PARENTHESE_CLOSE){
++local_index;
signature_start_index = local_index;
goto paren_mode2_done;
}
}
still_looping = backward_stream_tokens(&token_stream);
}while(still_looping);
// When this loop ends by going all the way back to the beginning set the signature start to 0 and fall through to the printing phase.
signature_start_index = 0;
paren_mode2_done:;
{
Function_Positions positions;
positions.sig_start_index = signature_start_index;
positions.sig_end_index = last_paren_index;
positions.open_paren_pos = first_paren_position;
positions_array[result.positions_count++] = positions;
}
end_temp_stream_token(&token_stream, backward_stream_temp);
if (result.positions_count >= positions_max){
result.next_token_index = token_index;
result.still_looping = true;
goto end;
}
goto mode1;
}
end:;
}
return(result);
}
#endif
#if 0
static void
print_positions_buffered(Application_Links *app, Buffer_Summary *buffer, Function_Positions *positions_array, int32_t positions_count, Buffered_Write_Stream *stream){
String buffer_name = make_string(buffer->buffer_name, buffer->buffer_name_len);
for (int32_t i = 0; i < positions_count; ++i){
Function_Positions *positions = &positions_array[i];
int32_t local_index = positions->sig_start_index;
int32_t end_index = positions->sig_end_index;
int32_t open_paren_pos = positions->open_paren_pos;
int32_t line_number = buffer_get_line_number(app, buffer, open_paren_pos);
Assert(end_index > local_index);
static const int32_t sig_chunk_size = 64;
Cpp_Token sig_chunk[sig_chunk_size];
Stream_Tokens sig_stream = {};
if (init_stream_tokens(&sig_stream, app, buffer, local_index, sig_chunk, sig_chunk_size)){
buffered_write_stream_write(app, stream, buffer_name);
buffered_write_stream_write(app, stream, make_lit_string(":"));
{
char space[64];
String integer_string = make_fixed_width_string(space);
append_int_to_str(&integer_string, line_number);
buffered_write_stream_write(app, stream, integer_string);
}
buffered_write_stream_write(app, stream, make_lit_string(": "));
bool32 still_looping = false;
do{
Cpp_Token prev_token = {};
for (; local_index < sig_stream.end; ++local_index){
Cpp_Token *token = &sig_stream.tokens[local_index];
if ((token->flags & CPP_TFLAG_PP_BODY) == 0 && token->type != CPP_TOKEN_COMMENT){
char space[2 << 10];
int32_t token_size = token->size;
if (token_size > sizeof(space)){
token_size = sizeof(space);
}
buffer_read_range(app, buffer, token->start, token->start + token_size, space);
bool32 insert_space = (/**/
(prev_token.type == CPP_TOKEN_IDENTIFIER ||
prev_token.type == CPP_TOKEN_STAR ||
prev_token.type == CPP_TOKEN_COMMA ||
(prev_token.flags & CPP_TFLAG_IS_KEYWORD) != 0
) &&
!(token->type == CPP_TOKEN_PARENTHESE_OPEN ||
token->type == CPP_TOKEN_PARENTHESE_CLOSE ||
token->type == CPP_TOKEN_COMMA
)
);
if (insert_space){
buffered_write_stream_write(app, stream, make_lit_string(" "));
}
buffered_write_stream_write(app, stream, make_string(space, token_size));
prev_token = *token;
}
if (local_index == end_index){
goto doublebreak;
}
}
still_looping = forward_stream_tokens(&sig_stream);
}while(still_looping);
doublebreak:;
buffered_write_stream_write(app, stream, make_lit_string("\n"));
}
}
}
#endif
static void
print_positions_buffered(Application_Links *app, Buffer_Summary *buffer, Function_Positions *positions_array, int32_t positions_count, Buffered_Write_Stream *stream){

View File

@ -271,7 +271,7 @@ static Command_Metadata fcoder_metacmd_table[220] = {
{ PROC_LINKS(decrease_face_size, 0), "decrease_face_size", 18, "Decrease the size of the face used by the current buffer.", 57, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 574 },
{ PROC_LINKS(decrease_line_wrap, 0), "decrease_line_wrap", 18, "Decrases the current buffer's width for line wrapping.", 54, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 551 },
{ PROC_LINKS(delete_char, 0), "delete_char", 11, "Deletes the character to the right of the cursor.", 49, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 51 },
{ PROC_LINKS(delete_current_scope, 0), "delete_current_scope", 20, "Deletes the braces surrounding the currently selected scope. Leaves the contents within the scope.", 99, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 796 },
{ PROC_LINKS(delete_current_scope, 0), "delete_current_scope", 20, "Deletes the braces surrounding the currently selected scope. Leaves the contents within the scope.", 99, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 512 },
{ PROC_LINKS(delete_file_query, 0), "delete_file_query", 17, "Deletes the file of the current buffer if 4coder has the appropriate access rights. Will ask the user for confirmation first.", 125, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1135 },
{ PROC_LINKS(delete_line, 0), "delete_line", 11, "Delete the line the on which the cursor sits.", 45, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1387 },
{ PROC_LINKS(delete_range, 0), "delete_range", 12, "Deletes the text in the range between the cursor and the mark.", 62, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 106 },
@ -312,10 +312,10 @@ static Command_Metadata fcoder_metacmd_table[220] = {
{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "c:\\4ed\\code\\4coder_lists.cpp", 28, 765 },
{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1557 },
{ PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 133 },
{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 542 },
{ PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 548 },
{ PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 519 },
{ PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 529 },
{ PROC_LINKS(list_all_functions_all_buffers, 0), "list_all_functions_all_buffers", 30, "Creates a jump list of lines from all buffers that appear to define or declare functions.", 89, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 330 },
{ PROC_LINKS(list_all_functions_all_buffers_lister, 0), "list_all_functions_all_buffers_lister", 37, "Creates a lister of locations that look like function definitions and declarations all buffers.", 95, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 336 },
{ PROC_LINKS(list_all_functions_current_buffer, 0), "list_all_functions_current_buffer", 33, "Creates a jump list of lines of the current buffer that appear to define or declare functions.", 94, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 307 },
{ PROC_LINKS(list_all_functions_current_buffer_lister, 0), "list_all_functions_current_buffer_lister", 40, "Creates a lister of locations that look like function definitions and declarations in the buffer.", 97, "c:\\4ed\\code\\4coder_function_list.cpp", 36, 317 },
{ PROC_LINKS(list_all_locations, 0), "list_all_locations", 18, "Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.", 99, "c:\\4ed\\code\\4coder_search.cpp", 29, 769 },
{ PROC_LINKS(list_all_locations_case_insensitive, 0), "list_all_locations_case_insensitive", 35, "Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.", 101, "c:\\4ed\\code\\4coder_search.cpp", 29, 783 },
{ PROC_LINKS(list_all_locations_of_identifier, 0), "list_all_locations_of_identifier", 32, "Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.", 102, "c:\\4ed\\code\\4coder_search.cpp", 29, 797 },
@ -377,7 +377,7 @@ static Command_Metadata fcoder_metacmd_table[220] = {
{ PROC_LINKS(paste_and_indent, 0), "paste_and_indent", 16, "Paste from the top of clipboard and run auto-indent on the newly pasted text.", 77, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 134 },
{ PROC_LINKS(paste_next, 0), "paste_next", 10, "If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.", 156, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 85 },
{ PROC_LINKS(paste_next_and_indent, 0), "paste_next_and_indent", 21, "Paste the next item on the clipboard and run auto-indent on the newly pasted text.", 82, "c:\\4ed\\code\\4coder_clipboard.cpp", 32, 141 },
{ PROC_LINKS(place_in_scope, 0), "place_in_scope", 14, "Wraps the code contained in the range between cursor and mark with a new curly brace scope.", 91, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 790 },
{ PROC_LINKS(place_in_scope, 0), "place_in_scope", 14, "Wraps the code contained in the range between cursor and mark with a new curly brace scope.", 91, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 506 },
{ PROC_LINKS(project_command_lister, 0), "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1527 },
{ PROC_LINKS(project_fkey_command, 0), "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1090 },
{ PROC_LINKS(project_go_to_root_directory, 0), "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "c:\\4ed\\code\\4coder_project_commands.cpp", 39, 1113 },
@ -395,7 +395,7 @@ static Command_Metadata fcoder_metacmd_table[220] = {
{ PROC_LINKS(save, 0), "save", 4, "Saves the current buffer.", 25, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1564 },
{ PROC_LINKS(save_all_dirty_buffers, 0), "save_all_dirty_buffers", 22, "Saves all buffers marked dirty (showing the '*' indicator).", 59, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1105 },
{ PROC_LINKS(save_to_query, 0), "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 1161 },
{ PROC_LINKS(scope_absorb_down, 0), "scope_absorb_down", 17, "If a scope is currently selected, and a statement or block statement is present below the current scope, the statement is moved into the scope.", 143, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 1039 },
{ PROC_LINKS(scope_absorb_down, 0), "scope_absorb_down", 17, "If a scope is currently selected, and a statement or block statement is present below the current scope, the statement is moved into the scope.", 143, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 751 },
{ PROC_LINKS(search, 0), "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 864 },
{ PROC_LINKS(search_identifier, 0), "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 878 },
{ PROC_LINKS(seek_alphanumeric_left, 0), "seek_alphanumeric_left", 22, "Seek left for boundary between alphanumeric characters and non-alphanumeric characters.", 87, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1238 },
@ -417,9 +417,9 @@ static Command_Metadata fcoder_metacmd_table[220] = {
{ PROC_LINKS(seek_whitespace_up, 0), "seek_whitespace_up", 18, "Seeks the cursor up to the next blank line.", 43, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1091 },
{ PROC_LINKS(seek_whitespace_up_end_line, 0), "seek_whitespace_up_end_line", 27, "Seeks the cursor up to the next blank line and places it at the end of the line.", 80, "c:\\4ed\\code\\4coder_seek.cpp", 27, 1155 },
{ PROC_LINKS(select_all, 0), "select_all", 10, "Puts the cursor at the top of the file, and the mark at the bottom of the file.", 79, "c:\\4ed\\code\\4coder_base_commands.cpp", 36, 359 },
{ PROC_LINKS(select_next_scope_absolute, 0), "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 671 },
{ PROC_LINKS(select_prev_scope_absolute, 0), "select_prev_scope_absolute", 26, "Finds the first scope started by '{' before the cursor and puts the cursor and mark on the '{' and '}'.", 103, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 691 },
{ PROC_LINKS(select_surrounding_scope, 0), "select_surrounding_scope", 24, "Finds the scope enclosed by '{' '}' surrounding the cursor and puts the cursor and mark on the '{' and '}'.", 107, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 655 },
{ PROC_LINKS(select_next_scope_absolute, 0), "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 387 },
{ PROC_LINKS(select_prev_scope_absolute, 0), "select_prev_scope_absolute", 26, "Finds the first scope started by '{' before the cursor and puts the cursor and mark on the '{' and '}'.", 103, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 407 },
{ PROC_LINKS(select_surrounding_scope, 0), "select_surrounding_scope", 24, "Finds the scope enclosed by '{' '}' surrounding the cursor and puts the cursor and mark on the '{' and '}'.", 107, "c:\\4ed\\code\\4coder_scope_commands.cpp", 37, 371 },
{ PROC_LINKS(set_bindings_choose, 0), "set_bindings_choose", 19, "Remap keybindings using the 'choose' mapping rule.", 50, "c:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 47 },
{ PROC_LINKS(set_bindings_default, 0), "set_bindings_default", 20, "Remap keybindings using the 'default' mapping rule.", 51, "c:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 61 },
{ PROC_LINKS(set_bindings_mac_default, 0), "set_bindings_mac_default", 24, "Remap keybindings using the 'mac-default' mapping rule.", 55, "c:\\4ed\\code\\4coder_remapping_commands.cpp", 41, 75 },

View File

@ -1122,6 +1122,33 @@ token_iterator_goto_prev_raw(Token_Iterator *iterator){
return(result);
}
static String
token_get_lexeme(Application_Links *app, Buffer_Summary *buffer, Cpp_Token *token, char *out_buffer, int32_t out_buffer_size){
String result = {};
if (out_buffer_size > 1){
int32_t read_size = token->size;
if (read_size >= out_buffer_size){
read_size = out_buffer_size - 1;
}
if (buffer_read_range(app, buffer, token->start, token->start + read_size, out_buffer)){
result = make_string(out_buffer, read_size, out_buffer_size);
out_buffer[read_size] = 0;
}
}
return(result);
}
static String
token_get_lexeme(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token *token){
String result = {};
Temp_Memory restore_point = begin_temp_memory(part);
char *s = push_array(part, char, token->size);
if (s != 0){
result = token_get_lexeme(app, buffer, token, s, token->size);
}
return(result);
}
////////////////////////////////
static String

View File

@ -115,6 +115,9 @@ struct Stream_Chunk{
char *data;
};
// NOTE(allen|4.0.31): Stream_Tokens has been deprecated in favor of the Token_Iterator below.
// For examples of usage: 4coder_function_list.cpp 4coder_scope_commands.cpp
// If you want to keep your code working easily uncomment the typedef for Stream_Tokens.
struct Stream_Tokens_DEP{
Application_Links *app;
Buffer_Summary *buffer;
@ -147,4 +150,4 @@ struct Sort_Pair_i32{
#endif
// BOTTOM
// BOTTOM

View File

@ -39,67 +39,6 @@ find_scope_get_token_type(uint32_t flags, Cpp_Token_Type token_type){
return(type);
}
#if 0
static bool32
find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){
Cpp_Get_Token_Result get_result = {};
bool32 success = false;
int32_t position = 0;
if (buffer_get_token_index(app, buffer, start_pos, &get_result)){
int32_t token_index = get_result.token_index;
if (flags & FindScope_Parent){
--token_index;
if (get_result.in_whitespace){
++token_index;
}
}
if (token_index >= 0){
static const int32_t chunk_cap = 512;
Cpp_Token chunk[chunk_cap];
Stream_Tokens stream = {};
if (init_stream_tokens(&stream, app, buffer, token_index, chunk, chunk_cap)){int32_t nest_level = 0;
bool32 still_looping = false;
do{
for (; token_index >= stream.start; --token_index){
Cpp_Token *token = &stream.tokens[token_index];
Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type);
switch (type){
case FindScopeTokenType_Open:
{
if (nest_level == 0){
success = true;
position = token->start;
if (flags & FindScope_EndOfToken){
position += token->size;
}
goto finished;
}
else{
--nest_level;
}
}break;
case FindScopeTokenType_Close:
{
++nest_level;
}break;
}
}
still_looping = backward_stream_tokens(&stream);
}while(still_looping);
}
}
}
finished:;
*end_pos_out = position;
return(success);
}
#endif
static bool32
find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){
Cpp_Get_Token_Result get_result = {};
@ -157,68 +96,6 @@ find_scope_top(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos
return(success);
}
#if 0
static bool32
find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){
Cpp_Get_Token_Result get_result = {};
bool32 success = false;
int32_t position = 0;
if (buffer_get_token_index(app, buffer, start_pos, &get_result)){
int32_t token_index = get_result.token_index+1;
if (flags & FindScope_Parent){
--token_index;
if (get_result.in_whitespace){
++token_index;
}
}
if (token_index >= 0){
static const int32_t chunk_cap = 512;
Cpp_Token chunk[chunk_cap];
Stream_Tokens stream = {};
if (init_stream_tokens(&stream, app, buffer, token_index, chunk, chunk_cap)){
int32_t nest_level = 0;
bool32 still_looping = false;
do{
for (; token_index < stream.end; ++token_index){
Cpp_Token *token = &stream.tokens[token_index];
Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type);
switch (type){
case FindScopeTokenType_Open:
{
++nest_level;
}break;
case FindScopeTokenType_Close:
{
if (nest_level == 0){
success = true;
position = token->start;
if (flags & FindScope_EndOfToken){
position += token->size;
}
goto finished;
}
else{
--nest_level;
}
}break;
}
}
still_looping = forward_stream_tokens(&stream);
}while(still_looping);
}
}
}
finished:;
*end_pos_out = position;
return(success);
}
#endif
static bool32
find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){
Cpp_Get_Token_Result get_result = {};
@ -276,87 +153,6 @@ find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, int32_t start_
return(success);
}
#if 0
static bool32
find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){
Cpp_Get_Token_Result get_result = {};
bool32 success = 0;
int32_t position = 0;
if (buffer_get_token_index(app, buffer, start_pos, &get_result)){
int32_t token_index = get_result.token_index+1;
if (token_index >= 0){
static const int32_t chunk_cap = 512;
Cpp_Token chunk[chunk_cap];
Stream_Tokens stream = {};
if (init_stream_tokens(&stream, app, buffer, token_index, chunk, chunk_cap)){
if (flags & FindScope_NextSibling){
int32_t nest_level = 1;
bool32 still_looping = false;
do{
for (; token_index < stream.end; ++token_index){
Cpp_Token *token = &stream.tokens[token_index];
Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type);
switch (type){
case FindScopeTokenType_Open:
{
if (nest_level == 0){
success = 1;
position = token->start;
if (flags & FindScope_EndOfToken){
position += token->size;
}
goto finished;
}
else{
++nest_level;
}
}break;
case FindScopeTokenType_Close:
{
--nest_level;
if (nest_level == -1){
position = start_pos;
goto finished;
}
}break;
}
}
still_looping = forward_stream_tokens(&stream);
}while(still_looping);
}
else{
bool32 still_looping = false;
do{
for (; token_index < stream.end; ++token_index){
Cpp_Token *token = &stream.tokens[token_index];
Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type);
if (type == FindScopeTokenType_Open){
success = 1;
position = token->start;
if (flags & FindScope_EndOfToken){
position += token->size;
}
goto finished;
}
}
still_looping = forward_stream_tokens(&stream);
}while(still_looping);
}
}
}
}
finished:;
*end_pos_out = position;
return(success);
}
#endif
static bool32
find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){
Cpp_Get_Token_Result get_result = {};
@ -431,86 +227,6 @@ find_next_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_po
return(success);
}
#if 0
static bool32
find_prev_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){
Cpp_Get_Token_Result get_result = {};
bool32 success = 0;
int32_t position = 0;
if (buffer_get_token_index(app, buffer, start_pos, &get_result)){
int32_t token_index = get_result.token_index-1;
if (token_index >= 0){
static const int32_t chunk_cap = 512;
Cpp_Token chunk[chunk_cap];
Stream_Tokens stream = {};
if (init_stream_tokens(&stream, app, buffer, token_index, chunk, chunk_cap)){
if (flags & FindScope_NextSibling){
int32_t nest_level = -1;
bool32 still_looping = 0;
do{
for (; token_index >= stream.start; --token_index){
Cpp_Token *token = &stream.tokens[token_index];
Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type);
switch (type){
case FindScopeTokenType_Open:
{
if (nest_level == -1){
position = start_pos;
goto finished;
}
else if (nest_level == 0){
success = 1;
position = token->start;
if (flags & FindScope_EndOfToken){
position += token->size;
}
goto finished;
}
else{
--nest_level;
}
}break;
case FindScopeTokenType_Close:
{
++nest_level;
}break;
}
}
still_looping = backward_stream_tokens(&stream);
}while(still_looping);
}
else{
bool32 still_looping = 0;
do{
for (; token_index >= stream.start; --token_index){
Cpp_Token *token = &stream.tokens[token_index];
Find_Scope_Token_Type type = find_scope_get_token_type(flags, token->type);
if (type == FindScopeTokenType_Open){
success = 1;
position = token->start;
if (flags & FindScope_EndOfToken){
position += token->size;
}
goto finished;
}
}
still_looping = backward_stream_tokens(&stream);
}while(still_looping);
}
}
}
}
finished:;
*end_pos_out = position;
return(success);
}
#endif
static bool32
find_prev_scope(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos, uint32_t flags, int32_t *end_pos_out){
Cpp_Get_Token_Result get_result = {};
@ -886,13 +602,9 @@ parse_if_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token
token = parser_next_token(parser);
if (token != 0 && token->type == CPP_TOKEN_KEY_CONTROL_FLOW){
char lexeme[32];
if (sizeof(lexeme)-1 >= token->size){
if (buffer_read_range(app, parser->buffer, token->start, token->start + token->size, lexeme)){
lexeme[token->size] = 0;
if (match(lexeme, "else")){
success = parse_statement_down(app, parser, token_out);
}
}
token_get_lexeme(app, parser->buffer, token, lexeme, sizeof(lexeme));
if (match(lexeme, "else")){
success = parse_statement_down(app, parser, token_out);
}
}
}