fixed several small issues and added a new test for unicode files
parent
30a2a95b69
commit
9e151fd823
File diff suppressed because one or more lines are too long
|
@ -183,6 +183,14 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra
|
|||
int32_t line_start, int32_t tab_width, int32_t *current_indent_out){
|
||||
Cpp_Token *token = get_first_token_at_line(app, buffer, tokens, line_start);
|
||||
|
||||
if (token == 0 && tokens.count == 0){
|
||||
// In this case just let the null token pointer be returned.
|
||||
}
|
||||
else{
|
||||
if (token == 0){
|
||||
token = tokens.tokens + (tokens.count - 1);
|
||||
}
|
||||
|
||||
if (token != tokens.tokens){
|
||||
--token;
|
||||
for (; token > tokens.tokens; --token){
|
||||
|
@ -255,6 +263,7 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra
|
|||
}
|
||||
} while(found_safe_start_position == 0);
|
||||
*current_indent_out = current_indent;
|
||||
}
|
||||
|
||||
return(token);
|
||||
}
|
||||
|
@ -288,6 +297,12 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b
|
|||
Cpp_Token *token_ptr = find_anchor_token(app, buffer, tokens, line_start,
|
||||
tab_width, &indent.current_indent);
|
||||
|
||||
if (token_ptr == 0){
|
||||
for (int32_t line_index = line_start; line_index < line_end; ++line_index){
|
||||
indent_marks[line_index] = 0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
int32_t line_index = buffer_get_line_index(app, buffer, token_ptr->start);
|
||||
|
||||
if (line_index > line_start){
|
||||
|
@ -470,6 +485,7 @@ get_indentation_marks(Application_Links *app, Partition *part, Buffer_Summary *b
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unshift the indent_marks array.
|
||||
indent_marks += line_start;
|
||||
|
|
|
@ -556,7 +556,7 @@ static int32_t
|
|||
buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, int32_t line){
|
||||
Partial_Cursor partial_cursor;
|
||||
int32_t result = buffer->size;
|
||||
if (line < buffer->line_count){
|
||||
if (line <= buffer->line_count){
|
||||
app->buffer_compute_cursor(app, buffer, seek_line_char(line, 1), &partial_cursor);
|
||||
result = partial_cursor.pos;
|
||||
}
|
||||
|
@ -1676,7 +1676,7 @@ seek_token_left(Cpp_Token_Array *tokens, int32_t pos){
|
|||
--token;
|
||||
}
|
||||
|
||||
return token->start;
|
||||
return(token->start);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
|
@ -1690,27 +1690,45 @@ seek_token_right(Cpp_Token_Array *tokens, int32_t pos){
|
|||
}
|
||||
|
||||
Cpp_Token *token = tokens->tokens + get.token_index;
|
||||
return token->start + token->size;
|
||||
return(token->start + token->size);
|
||||
}
|
||||
|
||||
static Cpp_Token_Array
|
||||
buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *buffer){
|
||||
Cpp_Token_Array array = {0};
|
||||
|
||||
if (buffer->exists && buffer->is_lexed){
|
||||
array.count = app->buffer_token_count(app, buffer);
|
||||
array.max_count = array.count;
|
||||
array.tokens = push_array(part, Cpp_Token, array.count);
|
||||
app->buffer_read_tokens(app, buffer, 0, array.count, array.tokens);
|
||||
}
|
||||
|
||||
return(array);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, int32_t start_pos,
|
||||
bool32 seek_forward, Seek_Boundary_Flag flags)/*
|
||||
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part,
|
||||
int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags)/*
|
||||
DOC_PARAM(buffer, The buffer parameter specifies the buffer through which to seek.)
|
||||
DOC_PARAM(start_pos, The beginning position of the seek is specified by start_pos measured in absolute position.)
|
||||
DOC_PARAM(seek_forward, If this parameter is non-zero it indicates that the seek should move foward through the buffer.)
|
||||
DOC_PARAM(flags, This field specifies the types of boundaries at which the seek should stop.)
|
||||
|
||||
DOC_RETURN(This call returns the absolute position where the seek stopped.
|
||||
If the seek goes below 0 the returned value is -1.
|
||||
If the seek goes past the end the returned value is the size of the buffer.)
|
||||
|
||||
DOC_SEE(Seek_Boundary_Flag)
|
||||
DOC_SEE(4coder_Buffer_Positioning_System)
|
||||
*/{
|
||||
int32_t result = 0;
|
||||
if (buffer->exists){
|
||||
|
||||
// TODO(allen): reduce duplication?
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
if (buffer->exists){
|
||||
int32_t pos[4];
|
||||
int32_t size = buffer->size;
|
||||
int32_t pos[4] = {0};
|
||||
int32_t new_pos = 0;
|
||||
|
||||
if (start_pos < 0){
|
||||
|
@ -1721,16 +1739,17 @@ DOC_SEE(4coder_Buffer_Positioning_System)
|
|||
}
|
||||
|
||||
if (seek_forward){
|
||||
for (int32_t i = 0; i < ArrayCount(pos); ++i) pos[i] = size;
|
||||
for (int32_t i = 0; i < ArrayCount(pos); ++i){
|
||||
pos[i] = size;
|
||||
}
|
||||
|
||||
if (flags & (1)){
|
||||
if (flags & BoundaryWhitespace){
|
||||
pos[0] = buffer_seek_whitespace_right(app, buffer, start_pos);
|
||||
}
|
||||
|
||||
if (flags & (1 << 1)){
|
||||
if (flags & BoundaryToken){
|
||||
if (buffer->tokens_are_ready){
|
||||
Cpp_Token_Array array;
|
||||
// TODO(allen): Fill this array.
|
||||
Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer);
|
||||
pos[1] = seek_token_right(&array, start_pos);
|
||||
}
|
||||
else{
|
||||
|
@ -1738,32 +1757,37 @@ DOC_SEE(4coder_Buffer_Positioning_System)
|
|||
}
|
||||
}
|
||||
|
||||
if (flags & (1 << 2)){
|
||||
if (flags & BoundaryAlphanumeric){
|
||||
pos[2] = buffer_seek_alphanumeric_right(app, buffer, start_pos);
|
||||
if (flags & (1 << 3)){
|
||||
if (flags & BoundaryCamelCase){
|
||||
pos[3] = buffer_seek_range_camel_right(app, buffer, start_pos, pos[2]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (flags & (1 << 3)){
|
||||
if (flags & BoundaryCamelCase){
|
||||
pos[3] = buffer_seek_alphanumeric_or_camel_right(app, buffer, start_pos);
|
||||
}
|
||||
}
|
||||
|
||||
new_pos = size;
|
||||
for (int32_t i = 0; i < ArrayCount(pos); ++i){
|
||||
if (pos[i] < new_pos) new_pos = pos[i];
|
||||
if (pos[i] < new_pos){
|
||||
new_pos = pos[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (flags & (1)){
|
||||
for (int32_t i = 0; i < ArrayCount(pos); ++i){
|
||||
pos[i] = 0;
|
||||
}
|
||||
|
||||
if (flags & BoundaryWhitespace){
|
||||
pos[0] = buffer_seek_whitespace_left(app, buffer, start_pos);
|
||||
}
|
||||
|
||||
if (flags & (1 << 1)){
|
||||
if (flags & BoundaryToken){
|
||||
if (buffer->tokens_are_ready){
|
||||
Cpp_Token_Array array;
|
||||
// TODO(allen): Fill this array.
|
||||
Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer);
|
||||
pos[1] = seek_token_left(&array, start_pos);
|
||||
}
|
||||
else{
|
||||
|
@ -1771,29 +1795,39 @@ DOC_SEE(4coder_Buffer_Positioning_System)
|
|||
}
|
||||
}
|
||||
|
||||
if (flags & (1 << 2)){
|
||||
if (flags & BoundaryAlphanumeric){
|
||||
pos[2] = buffer_seek_alphanumeric_left(app, buffer, start_pos);
|
||||
if (flags & (1 << 3)){
|
||||
if (flags & BoundaryCamelCase){
|
||||
pos[3] = buffer_seek_range_camel_left(app, buffer, start_pos, pos[2]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (flags & (1 << 3)){
|
||||
if (flags & BoundaryCamelCase){
|
||||
pos[3] = buffer_seek_alphanumeric_or_camel_left(app, buffer, start_pos);
|
||||
}
|
||||
}
|
||||
|
||||
new_pos = 0;
|
||||
for (int32_t i = 0; i < ArrayCount(pos); ++i){
|
||||
if (pos[i] > new_pos) new_pos = pos[i];
|
||||
if (pos[i] > new_pos){
|
||||
new_pos = pos[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
result = new_pos;
|
||||
}
|
||||
end_temp_memory(temp);
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer,
|
||||
int32_t start_pos, bool32 seek_forward, Seek_Boundary_Flag flags){
|
||||
int32_t result = buffer_boundary_seek(app, buffer, &global_part, start_pos, seek_forward, flags);
|
||||
return(result);
|
||||
}
|
||||
|
||||
static void
|
||||
basic_seek(Application_Links *app, int32_t seek_type, uint32_t flags){
|
||||
uint32_t access = AccessProtected;
|
||||
|
|
|
@ -297,11 +297,11 @@ ENUM(uint32_t, Input_Type_Flag){
|
|||
EventOnRightButton = 0x8,
|
||||
/* DOC(If EventOnWheel is set, any wheel movement is included in the set.) */
|
||||
EventOnWheel = 0x10,
|
||||
/* DOC(If EventOnButton is set, all mouse button events are included in the set.) */
|
||||
EventOnButton = (EventOnLeftButton | EventOnRightButton | EventOnWheel),
|
||||
|
||||
/* DOC(This is not totally implemented yet.) */
|
||||
EventOnMouseMove = 0x20,
|
||||
|
||||
/* DOC(If EventOnButton is set, all mouse button events are included in the set.) */
|
||||
EventOnButton = (EventOnLeftButton | EventOnRightButton | EventOnWheel),
|
||||
/* DOC(This is not totally implemented yet.) */
|
||||
EventOnMouse = (EventOnButton | EventOnMouseMove),
|
||||
|
||||
|
@ -587,21 +587,15 @@ struct Buffer_Edit{
|
|||
DOC_SEE(Access_Flag)
|
||||
DOC_SEE(Dirty_State) */
|
||||
struct Buffer_Summary{
|
||||
/* DOC(
|
||||
This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder.
|
||||
When this field is false the summary is referred to as a "null summary".
|
||||
) */
|
||||
/* DOC(This field indicates whether the Buffer_Summary describes a buffer that is open in 4coder.
|
||||
When this field is false the summary is referred to as a "null summary".) */
|
||||
bool32 exists;
|
||||
/* DOC(If this is not a null summary, this field indicates whether the buffer has finished loading.) */
|
||||
bool32 ready;
|
||||
/* DOC(
|
||||
If this is not a null summary this field is the id of the associated buffer.
|
||||
If this is a null summary then buffer_id is 0.
|
||||
) */
|
||||
/* DOC(If this is not a null summary this field is the id of the associated buffer.
|
||||
If this is a null summary then buffer_id is 0.) */
|
||||
int32_t buffer_id;
|
||||
/*
|
||||
DOC(If this is not a null summary, this field contains flags describing the protection status of the buffer.)
|
||||
*/
|
||||
/*DOC(If this is not a null summary, this field contains flags describing the protection status of the buffer.)*/
|
||||
Access_Flag lock_flags;
|
||||
|
||||
/* DOC(If this is not a null summary, this field specifies the size of the text in the buffer.) */
|
||||
|
|
|
@ -288,7 +288,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz
|
|||
int32_t token_i = token_array_out->count;
|
||||
int32_t max_token_i = token_array_out->max_count;
|
||||
|
||||
char c = 0;
|
||||
uint8_t c = 0;
|
||||
|
||||
int32_t end_pos = size + S.chunk_pos;
|
||||
chunk -= S.chunk_pos;
|
||||
|
@ -330,8 +330,8 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz
|
|||
S.fsm = null_lex_fsm;
|
||||
for(;;){
|
||||
{
|
||||
unsigned short *eq_classes = get_eq_classes[S.pp_state];
|
||||
unsigned char *fsm_table = get_table[S.pp_state];
|
||||
uint16_t *eq_classes = get_eq_classes[S.pp_state];
|
||||
uint8_t *fsm_table = get_table[S.pp_state];
|
||||
|
||||
for (; S.fsm.state < LS_count && S.pos < end_pos;){
|
||||
c = chunk[S.pos++];
|
||||
|
@ -489,7 +489,7 @@ cpp_lex_nonalloc_null_end_no_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz
|
|||
String_And_Flag data = preprops[sub_match];
|
||||
S.token.type = (Cpp_Token_Type)data.flags;
|
||||
S.token.flags = CPP_TFLAG_PP_DIRECTIVE;
|
||||
S.pp_state = (unsigned char)cpp_pp_directive_to_state(S.token.type);
|
||||
S.pp_state = (uint8_t)cpp_pp_directive_to_state(S.token.type);
|
||||
}
|
||||
else{
|
||||
S.token.type = CPP_TOKEN_JUNK;
|
||||
|
|
|
@ -77,12 +77,6 @@ CUSTOM_COMMAND_SIG(reopen_test){
|
|||
//TEST_TIME_E();
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(run_all_tests){
|
||||
exec_command(app, load_lots_of_files);
|
||||
exec_command(app, reopen_test);
|
||||
}
|
||||
|
||||
#if 0
|
||||
CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){
|
||||
Buffer_Summary buffer = app->create_buffer(app, literal(LOTS_OF_FILES "/4ed.cpp"), 0);
|
||||
View_Summary view = app->get_active_view(app, AccessAll);
|
||||
|
@ -97,6 +91,18 @@ CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){
|
|||
app->buffer_compute_cursor(app, &buffer, seek_line_char(316, 29), &curs);
|
||||
fwrite(&curs.pos, 4, 1, file);
|
||||
|
||||
for (int32_t i = 0; i < 10; ++i){
|
||||
Query_Bar bar = {0};
|
||||
bar.prompt = make_lit_string("Do something to continue the test");
|
||||
if (app->start_query_bar(app, &bar, 0)){
|
||||
app->get_user_input(app, EventAll, EventAll);
|
||||
}
|
||||
refresh_buffer(app, &buffer);
|
||||
if (buffer.tokens_are_ready){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static Seek_Boundary_Flag flag_set[] = {
|
||||
BoundaryWhitespace,
|
||||
BoundaryToken,
|
||||
|
@ -111,7 +117,7 @@ CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){
|
|||
for (int32_t seek_forward = 0; seek_forward <= 1; ++seek_forward){
|
||||
pos = curs.pos;
|
||||
for (int32_t i = 0; i < 100; ++i){
|
||||
pos = app->buffer_boundary_seek(app, &buffer, pos, seek_forward, flag_set[flag_i]);
|
||||
pos = buffer_boundary_seek(app, &buffer, pos, seek_forward, flag_set[flag_i]);
|
||||
fwrite(&pos, 4, 1, file);
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +126,6 @@ CUSTOM_COMMAND_SIG(generate_stop_spots_test_data){
|
|||
fclose(file);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
fcheck(int32_t x, FILE *file){
|
||||
|
@ -143,6 +148,18 @@ CUSTOM_COMMAND_SIG(stop_spots_test){
|
|||
app->buffer_compute_cursor(app, &buffer, seek_line_char(316, 29), &curs);
|
||||
fcheck(curs.pos, file);
|
||||
|
||||
for (int32_t i = 0; i < 10; ++i){
|
||||
Query_Bar bar = {0};
|
||||
bar.prompt = make_lit_string("Do something to continue the test");
|
||||
if (app->start_query_bar(app, &bar, 0)){
|
||||
app->get_user_input(app, EventAll, EventAll);
|
||||
}
|
||||
refresh_buffer(app, &buffer);
|
||||
if (buffer.tokens_are_ready){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static Seek_Boundary_Flag flag_set[] = {
|
||||
BoundaryWhitespace,
|
||||
BoundaryToken,
|
||||
|
@ -167,13 +184,25 @@ CUSTOM_COMMAND_SIG(stop_spots_test){
|
|||
}
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(load_unicode_file){
|
||||
Buffer_Summary buffer = app->create_buffer(app, literal(TEST_FILES "/mod_markov.c"), 0);
|
||||
View_Summary view = app->get_active_view(app, AccessAll);
|
||||
app->view_set_buffer(app, &view, buffer.buffer_id, 0);
|
||||
|
||||
app->view_set_cursor(app, &view, seek_line_char(230, 25), 1);
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(run_all_tests){
|
||||
exec_command(app, load_lots_of_files);
|
||||
exec_command(app, reopen_test);
|
||||
exec_command(app, stop_spots_test);
|
||||
exec_command(app, load_unicode_file);
|
||||
}
|
||||
|
||||
static void
|
||||
test_get_bindings(Bind_Helper *context){
|
||||
begin_map(context, mapid_global);
|
||||
|
||||
//bind(context, key_f3, MDFR_NONE, run_all_tests);
|
||||
bind(context, key_f3, MDFR_NONE, stop_spots_test);
|
||||
|
||||
bind(context, key_f3, MDFR_NONE, run_all_tests);
|
||||
end_map(context);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue