4coder/4coder_api_transition_30_31...

543 lines
20 KiB
C++

/*
* Helpers for the API transition from 4.0.30 to 4.0.31
*
* In order to keep your layer on the old API you don't have to do anything, this provides wrappers
* idential to the 4.0.30 API.
* In order to transition your entire layer over to the 4.0.31 API define 'REMOVE_TRANSITION_HELPER_31' and fix errors.
* Or you can do it step by step by removing a few wrappers at a time.
* This transition helper will be removed in a future version so it is recommended to get off sooner or laster.
*
* Tips on transitioning:
*
* Wrather than just try to inline this code everywhere, you can simplify things quite a lot by storing references
* to buffers and views and Buffer_ID and View_ID instead of Buffer_Summary and View_Summary.
* Just get the summaries when you need information in those structures.
*
* You will make your code simpler if you stick to String as much as possible, but whenever you want to you can switch
* to any string type you have to String by calling make_string(char_ptr, length) or make_string_slowly(null_terminated_c_str).
* To pull the char ptr and length out of a String named "string": string.str and str.size.
* If you need a null terminated string from a String use get_null_terminated in 4coder_helper.cpp
*
*/
// TOP
#if !defined(REMOVE_TRANSITION_HELPER_31)
static char
buffer_get_char(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_get_char(app, buffer->buffer_id, pos));
}
static i32
buffer_get_line_start(Application_Links *app, Buffer_Summary *buffer, i32 line){
return(buffer==0?0:buffer_get_line_start(app, buffer->buffer_id, line));
}
static i32
buffer_get_line_end(Application_Links *app, Buffer_Summary *buffer, i32 line){
return(buffer==0?0:buffer_get_line_end(app, buffer->buffer_id, line));
}
static Cpp_Token*
get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, i32 line){
return(buffer==0?0:get_first_token_at_line(app, buffer->buffer_id, tokens, line));
}
static b32
read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 line, String *str,
Partial_Cursor *start_out, Partial_Cursor *one_past_last_out){
return(buffer==0?0:read_line(app, part, buffer->buffer_id, line, str, start_out, one_past_last_out));
}
static b32
read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 line, String *str){
return(buffer==0?0:read_line(app, part, buffer->buffer_id, line, str));
}
static b32
init_stream_chunk(Stream_Chunk *chunk, Application_Links *app, Buffer_Summary *buffer, i32 pos, char *data, u32 size){
return(buffer==0?0:init_stream_chunk(chunk, app, buffer->buffer_id, pos, data, size));
}
static b32
init_stream_tokens(Stream_Tokens_DEP *stream, Application_Links *app, Buffer_Summary *buffer, i32 pos, Cpp_Token *data, i32 count){
return(buffer==0?0:init_stream_tokens(stream, app, buffer->buffer_id, pos, data, count));
}
static String
token_get_lexeme(Application_Links *app, Buffer_Summary *buffer, Cpp_Token *token, char *out_buffer, i32 out_buffer_size){
String result = {};
if (buffer != 0){
result = token_get_lexeme(app, buffer->buffer_id, token, out_buffer, out_buffer_size);
}
return(result);
}
static String
token_get_lexeme(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token *token){
String result = {};
if (buffer != 0){
result = token_get_lexeme(app, part, buffer->buffer_id, token);
}
return(result);
}
static String
get_token_or_word_under_pos(Application_Links *app, Buffer_Summary *buffer, i32 pos, char *space, i32 capacity){
String result = {};
if (buffer != 0){
result = get_token_or_word_under_pos(app, buffer->buffer_id, pos, space, capacity);
}
return(result);
}
static i32
seek_line_end(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:seek_line_end(app, buffer->buffer_id, pos));
}
static i32
seek_line_beginning(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:seek_line_beginning(app, buffer->buffer_id, pos));
}
static void
move_past_lead_whitespace(Application_Links *app, View_Summary *view, Buffer_Summary *buffer){
if (view != 0 && buffer != 0){
move_past_lead_whitespace(app, view, buffer->buffer_id);
}
}
static i32
buffer_seek_whitespace_up(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_whitespace_up(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_whitespace_down(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_whitespace_down(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_whitespace_right(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_whitespace_right(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_whitespace_left(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_whitespace_left(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_alphanumeric_right(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_alphanumeric_right(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_alphanumeric_left(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_alphanumeric_left(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_alphanumeric_or_underscore_right(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_alphanumeric_or_underscore_right(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_alphanumeric_or_underscore_left(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_alphanumeric_or_underscore_left(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_range_camel_right(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 an_pos){
return(buffer==0?0:buffer_seek_range_camel_right(app, buffer->buffer_id, pos, an_pos));
}
static i32
buffer_seek_range_camel_left(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 an_pos){
return(buffer==0?0:buffer_seek_range_camel_left(app, buffer->buffer_id, pos, an_pos));
}
static i32
buffer_seek_alphanumeric_or_camel_right(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_alphanumeric_or_camel_right(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_alphanumeric_or_camel_left(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_seek_alphanumeric_or_camel_left(app, buffer->buffer_id, pos));
}
static i32
buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, int32_t pos){
return(buffer!=0?0:buffer_seek_alpha_numeric_end(app, buffer->buffer_id, pos));
}
static Cpp_Token_Array
buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *buffer){
Cpp_Token_Array result = {};
if (buffer != 0){
result = buffer_get_all_tokens(app, part, buffer->buffer_id);
}
return(result);
}
static i32
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){
return(buffer==0?0:buffer_boundary_seek(app, buffer->buffer_id, part, start_pos, seek_forward, flags));
}
static void
buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer, i32 pos, char delim, i32 *result){
if (buffer != 0){
buffer_seek_delimiter_forward(app, buffer->buffer_id, pos, delim, result);
}
}
static void
buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, i32 pos, char delim, i32 *result){
if (buffer != 0){
buffer_seek_delimiter_backward(app, buffer->buffer_id, pos, delim, result);
}
}
static void
buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){
if (buffer != 0){
buffer_seek_string_forward(app, buffer->buffer_id, pos, end, str, size, result);
}
}
static void
buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){
if (buffer != 0){
buffer_seek_string_backward(app, buffer->buffer_id, pos, end, str, size, result);
}
}
static void
buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){
if (buffer != 0){
buffer_seek_string_insensitive_forward(app, buffer->buffer_id, pos, end, str, size, result);
}
}
static void
buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){
if (buffer != 0){
buffer_seek_string_insensitive_backward(app, buffer->buffer_id, pos, end, str, size, result);
}
}
static void
buffer_seek_string(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, i32 min, char *str, i32 size, i32 *result, Buffer_Seek_String_Flags flags){
if (buffer != 0){
buffer_seek_string(app, buffer->buffer_id, pos, end, min, str, size, result, flags);
}
}
static b32
buffer_line_is_blank(Application_Links *app, Buffer_Summary *buffer, i32 line){
return(buffer==0?0:buffer_line_is_blank(app, buffer->buffer_id, line));
}
static String
read_identifier_at_pos(Application_Links *app, Buffer_Summary *buffer, i32 pos, char *space, i32 max, Range *range_out){
String result = {};
if (buffer != 0){
result = read_identifier_at_pos(app, buffer->buffer_id, pos, space, max, range_out);
}
return(result);
}
static i32
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, i32 dir, Seek_Boundary_Flag flags){
return(buffer==0?0:buffer_boundary_seek(app, buffer->buffer_id, start_pos, dir, flags));
}
static void
view_buffer_boundary_seek_set_pos(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, i32 dir, u32 flags){
if (buffer != 0){
view_buffer_boundary_seek_set_pos(app, view, buffer->buffer_id, dir, flags);
}
}
static Range
view_buffer_boundary_range(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, i32 dir, u32 flags){
Range result = {};
if (buffer != 0){
result = view_buffer_boundary_range(app, view, buffer->buffer_id, dir, flags);
}
return(result);
}
static Range
view_buffer_snipe_range(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, i32 dir, u32 flags){
Range result = {};
if (buffer != 0){
result = view_buffer_snipe_range(app, view, buffer->buffer_id, dir, flags);
}
return(result);
}
static void
query_replace_base(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, i32 pos, String r, String w){
if (buffer != 0){
query_replace_base(app, view, buffer->buffer_id, pos, r, w);
}
}
static Statement_Parser
make_statement_parser(Application_Links *app, Buffer_Summary *buffer, i32 token_index){
Statement_Parser parser = {};
if (buffer != 0){
parser = make_statement_parser(app, buffer->buffer_id, token_index);
}
return(parser);
}
static b32
find_whole_statement_down(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 *start_out, i32 *end_out){
return(buffer==0?false:find_whole_statement_down(app, buffer->buffer_id, pos, start_out, end_out));
}
static b32
find_scope_top(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, u32 flags, i32 *end_pos_out){
return(buffer==0?false:find_scope_top(app, buffer->buffer_id, start_pos, flags, end_pos_out));
}
static b32
find_scope_bottom(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, u32 flags, i32 *end_pos_out){
return(buffer==0?false:find_scope_bottom(app, buffer->buffer_id, start_pos, flags, end_pos_out));
}
static b32
find_scope_range(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, Range *range_out, u32 flags){
return(buffer==0?false:find_scope_range(app, buffer->buffer_id, start_pos, range_out, flags));
}
static b32
find_next_scope(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, u32 flags, i32 *end_pos_out){
return(buffer==0?false:find_next_scope(app, buffer->buffer_id, start_pos, flags, end_pos_out));
}
static b32
find_prev_scope(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, u32 flags, i32 *end_pos_out){
return(buffer==0?false:find_prev_scope(app, buffer->buffer_id, start_pos, flags, end_pos_out));
}
static Range_Array
get_enclosure_ranges(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 pos, u32 flags){
Range_Array result = {};
if (buffer != 0){
result = get_enclosure_ranges(app, part, buffer->buffer_id, pos, flags);
}
return(result);
}
static void
mark_enclosures(Application_Links *app, Partition *scratch, Managed_Scope render_scope, Buffer_Summary *buffer, i32 pos, u32 flags, Marker_Visual_Type type, int_color *back_colors, int_color *fore_colors, i32 color_count){
if (buffer != 0){
mark_enclosures(app, scratch, render_scope, buffer->buffer_id, pos, flags, type, back_colors, fore_colors, color_count);
}
}
static Hard_Start_Result
buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, i32 line_start, i32 tab_width){
Hard_Start_Result result = {};
if (buffer != 0){
buffer_find_hard_start(app, buffer->buffer_id, line_start, tab_width);
}
return(result);
}
static Buffer_Batch_Edit
make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){
Buffer_Batch_Edit result = {};
if (buffer != 0){
make_batch_from_indent_marks(app, arena, buffer->buffer_id, first_line, one_past_last_line, indent_marks, opts);
}
return(result);
}
static void
set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){
if (buffer != 0){
set_line_indents(app, part, buffer->buffer_id, first_line, one_past_last_line, indent_marks, opts);
}
}
static Indent_Anchor_Position
find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, i32 line_start, i32 tab_width){
Indent_Anchor_Position result = {};
if (buffer != 0){
result = find_anchor_token(app, buffer->buffer_id, tokens, line_start, tab_width);
}
return(result);
}
static i32*
get_indentation_marks(Application_Links *app, Partition *arena, Buffer_Summary *buffer,
Cpp_Token_Array tokens, i32 first_line, i32 one_past_last_line,
b32 exact_align, i32 tab_width){
return(buffer==0?0:get_indentation_marks(app, arena, buffer->buffer_id, tokens, first_line, one_past_last_line, exact_align, tab_width));
}
static i32
buffer_get_line_number(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_get_line_number(app, buffer->buffer_id, pos));
}
static void
get_indent_lines_minimum(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, i32 end_pos, i32 *line_start_out, i32 *line_end_out){
if (buffer != 0){
get_indent_lines_minimum(app, buffer->buffer_id, start_pos, end_pos, line_start_out, line_end_out);
}
}
static void
get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Array tokens, i32 start_pos, i32 end_pos, i32 *line_start_out, i32 *line_end_out){
if (buffer != 0){
get_indent_lines_whole_tokens(app, buffer->buffer_id, tokens, start_pos, end_pos, line_start_out, line_end_out);
}
}
static b32
buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){
return(buffer==0?0:buffer_auto_indent(app, part, buffer->buffer_id, start, end, tab_width, flags));
}
static b32
buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){
return(buffer==0?0:buffer_auto_indent(app, buffer->buffer_id, start, end, tab_width, flags));
}
static void
print_positions_buffered(Application_Links *app, Buffer_Summary *buffer, Function_Positions *positions_array, i32 positions_count, Buffered_Write_Stream *stream){
if (buffer != 0){
print_positions_buffered(app, buffer->buffer_id, positions_array, positions_count, stream);
}
}
static Get_Positions_Results
get_function_positions(Application_Links *app, Buffer_Summary *buffer, i32 first_token_index, Function_Positions *positions_array, i32 positions_max){
Get_Positions_Results result = {};
if (buffer != 0){
result = get_function_positions(app, buffer->buffer_id, first_token_index, positions_array, positions_max);
}
return(result);
}
static void
list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *optional_target_buffer){
if (optional_target_buffer != 0){
list_all_functions(app, part, optional_target_buffer->buffer_id);
}
}
static i32
get_start_of_line_at_cursor(Application_Links *app, View_Summary *view, Buffer_Summary *buffer){
return(buffer==0?0:get_start_of_line_at_cursor(app, view, buffer->buffer_id));
}
static b32
c_line_comment_starts_at_position(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:c_line_comment_starts_at_position(app, buffer->buffer_id, pos));
}
static void
write_string(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, String string){
if (buffer != 0){
write_string(app, view, buffer->buffer_id, string);
}
}
static b32
open_file(Application_Links *app, Buffer_Summary *buffer_out, char *filename, i32 filename_len, b32 background, b32 never_new){
b32 result = false;
Buffer_ID id_out = 0;
result = open_file(app, &id_out, filename, filename_len, background, never_new);
if (result && buffer_out != 0){
get_buffer_summary(app, id_out, AccessAll, buffer_out);
}
return(result);
}
static b32
get_cpp_matching_file(Application_Links *app, Buffer_Summary buffer, Buffer_Summary *buffer_out){
b32 result = false;
if (buffer.exists){
Buffer_ID id_out = 0;
result = get_cpp_matching_file(app, buffer.buffer_id, &id_out);
if (result && buffer_out != 0){
get_buffer_summary(app, id_out, AccessAll, buffer_out);
}
}
return(result);
}
static b32
get_jump_buffer(Application_Links *app, Buffer_Summary *buffer, Name_Line_Column_Location *location){
Buffer_ID id = 0;
b32 result = get_jump_buffer(app, &id, location);
if (result){
get_buffer_summary(app, id, AccessAll, buffer);
}
return(result);
}
static b32
get_jump_buffer(Application_Links *app, Buffer_Summary *buffer, ID_Pos_Jump_Location *location, Access_Flag access){
Buffer_ID id = 0;
b32 result = get_jump_buffer(app, &id, location, access);
if (result){
get_buffer_summary(app, id, AccessAll, buffer);
}
return(result);
}
static b32
get_jump_buffer(Application_Links *app, Buffer_Summary *buffer, ID_Pos_Jump_Location *location){
Buffer_ID id = 0;
b32 result = get_jump_buffer(app, &id, location);
if (result){
get_buffer_summary(app, id, AccessAll, buffer);
}
return(result);
}
static void
switch_to_existing_view(Application_Links *app, View_Summary *view, Buffer_Summary *buffer){
if (buffer != 0){
switch_to_existing_view(app, view, buffer->buffer_id);
}
}
static void
set_view_to_location(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, Buffer_Seek seek){
if (buffer != 0){
set_view_to_location(app, view, buffer->buffer_id, seek);
}
}
static void
jump_to_location(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, Name_Line_Column_Location location){
if (buffer != 0){
jump_to_location(app, view, buffer->buffer_id, location);
}
}
static void
jump_to_location(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, ID_Pos_Jump_Location location){
if (buffer != 0){
jump_to_location(app, view, buffer->buffer_id, location);
}
}
#endif
// BOTTOM