new gui stuff 10
parent
216c597df3
commit
022f7176bf
|
@ -28,9 +28,7 @@ basic_seek(Application_Links *app, Command_ID seek_type, unsigned int flags){
|
|||
}
|
||||
|
||||
#define SEEK_COMMAND(n, dir, flags)\
|
||||
CUSTOM_COMMAND_SIG(seek_##n##_##dir){\
|
||||
basic_seek(app, cmdid_seek_##dir, flags);\
|
||||
}
|
||||
CUSTOM_COMMAND_SIG(seek_##n##_##dir){ basic_seek(app, cmdid_seek_##dir, flags); }
|
||||
|
||||
SEEK_COMMAND(whitespace, right, BoundryWhitespace)
|
||||
SEEK_COMMAND(whitespace, left, BoundryWhitespace)
|
||||
|
@ -59,7 +57,6 @@ long_braces(Application_Links *app, char *text, int size){
|
|||
push_parameter(app, par_range_start, pos);
|
||||
push_parameter(app, par_range_end, pos + size);
|
||||
push_parameter(app, par_clear_blank_lines, 0);
|
||||
push_parameter(app, par_use_tabs, 1);
|
||||
exec_command(app, cmdid_auto_tab_range);
|
||||
}
|
||||
|
||||
|
|
|
@ -317,8 +317,10 @@ query_user_general(Application_Links *app, Query_Bar *bar, int force_number){
|
|||
break;
|
||||
}
|
||||
else if (in.key.keycode == key_back){
|
||||
if (bar->string.size > 0){
|
||||
--bar->string.size;
|
||||
}
|
||||
}
|
||||
else if (good_character){
|
||||
append(&bar->string, in.key.character);
|
||||
}
|
||||
|
|
33
4ed.cpp
33
4ed.cpp
|
@ -748,6 +748,7 @@ COMMAND_DECL(delete_range){
|
|||
range = make_range(view->cursor.pos, view->mark);
|
||||
if (range.start < range.end){
|
||||
next_cursor_pos = range.start;
|
||||
Assert(range.end <= buffer_size(&file->state.buffer));
|
||||
view_replace_range(system, models, view, range.start, range.end, 0, 0, next_cursor_pos);
|
||||
view_cursor_move(view, next_cursor_pos);
|
||||
view->mark = range.start;
|
||||
|
@ -2881,9 +2882,9 @@ app_hardcode_styles(Models *models){
|
|||
style_set_name(style, make_lit_string("stb"));
|
||||
|
||||
style->main.back_color = 0xFFD6D6D6;
|
||||
style->main.margin_color = 0xFF9E9E9E;
|
||||
style->main.margin_color = 0xFF5C5C5C;
|
||||
style->main.margin_hover_color = 0xFF7E7E7E;
|
||||
style->main.margin_active_color = 0xFF5C5C5C;
|
||||
style->main.margin_active_color = 0xFF9E9E9E;
|
||||
style->main.cursor_color = 0xFF000000;
|
||||
style->main.at_cursor_color = 0xFFD6D6D6;
|
||||
style->main.mark_color = 0xFF525252;
|
||||
|
@ -3923,7 +3924,7 @@ App_Step_Sig(app_step){
|
|||
|
||||
// TOOD(allen): Deduplicate
|
||||
// TODO(allen): Allow a view to clean up however it wants after a command finishes,
|
||||
// or after transfering to another view mid command.
|
||||
// or after transfering to another view mid command?
|
||||
if (view != 0 && models->command_coroutine == 0){
|
||||
init_query_set(&view->query_set);
|
||||
}
|
||||
|
@ -3943,6 +3944,23 @@ App_Step_Sig(app_step){
|
|||
}
|
||||
ProfileStart(frame_hook);
|
||||
|
||||
ProfileStart(fill_gui_command_buffers);
|
||||
{
|
||||
Panel *panel, *used_panels;
|
||||
View *view;
|
||||
b32 active;
|
||||
|
||||
used_panels = &models->layout.used_sentinel;
|
||||
for (dll_items(panel, used_panels)){
|
||||
view = panel->view;
|
||||
active = (panel == cmd->panel);
|
||||
if (step_file_view(view, active)){
|
||||
app_result.redraw = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
ProfileStart(fill_gui_command_buffers);
|
||||
|
||||
// NOTE(allen): pass raw input to the panels
|
||||
ProfileStart(step);
|
||||
|
||||
|
@ -3998,7 +4016,7 @@ App_Step_Sig(app_step){
|
|||
if (panel == mouse_panel && !mouse->out_of_window){
|
||||
input.mouse = mouse_state;
|
||||
}
|
||||
if (step_file_view(system, exchange, view, panel->inner, active, &input)){
|
||||
if (do_input_file_view(system, exchange, view, panel->inner, active, &input)){
|
||||
app_result.redraw = 1;
|
||||
}
|
||||
}
|
||||
|
@ -4431,7 +4449,6 @@ App_Step_Sig(app_step){
|
|||
{
|
||||
if (!file && string.str){
|
||||
file = working_set_lookup_file(working_set, string);
|
||||
|
||||
if (!file){
|
||||
file = working_set_contains(system, working_set, string);
|
||||
}
|
||||
|
@ -4450,7 +4467,6 @@ App_Step_Sig(app_step){
|
|||
{
|
||||
if (!file && string.str){
|
||||
file = working_set_lookup_file(working_set, string);
|
||||
|
||||
if (!file){
|
||||
file = working_set_contains(system, working_set, string);
|
||||
}
|
||||
|
@ -4475,7 +4491,6 @@ App_Step_Sig(app_step){
|
|||
|
||||
if (!file && string.str){
|
||||
file = working_set_lookup_file(working_set, string);
|
||||
|
||||
if (!file){
|
||||
file = working_set_contains(system, working_set, string);
|
||||
}
|
||||
|
@ -4485,7 +4500,9 @@ App_Step_Sig(app_step){
|
|||
if (buffer_needs_save(file)){
|
||||
view_show_interactive(system, view, &models->map_ui,
|
||||
IAct_Sure_To_Kill, IInt_Sure_To_Kill, make_lit_string("Are you sure?"));
|
||||
#if 0
|
||||
copy(&view->dest, file->name.live_name);
|
||||
#endif
|
||||
}
|
||||
else{
|
||||
working_set_remove(system, working_set, file->name.source_path);
|
||||
|
@ -4576,7 +4593,7 @@ App_Step_Sig(app_step){
|
|||
draw_rectangle(target, full, back_color);
|
||||
|
||||
draw_push_clip(target, panel->inner);
|
||||
draw_file_view(system, exchange, view, cmd->view, panel->inner, active, target, &dead_input);
|
||||
do_render_file_view(system, exchange, view, cmd->view, panel->inner, active, target, &dead_input);
|
||||
draw_pop_clip(target);
|
||||
|
||||
u32 margin_color;
|
||||
|
|
|
@ -38,7 +38,6 @@ enum View_Widget_Type{
|
|||
};
|
||||
|
||||
struct View_Widget{
|
||||
UI_State state;
|
||||
View_Widget_Type type;
|
||||
i32 height_;
|
||||
struct{
|
||||
|
@ -77,9 +76,10 @@ struct View{
|
|||
|
||||
Editing_File *file;
|
||||
|
||||
UI_State ui_state;
|
||||
View_UI showing_ui;
|
||||
GUI_Target gui_target;
|
||||
|
||||
#if 0
|
||||
// interactive stuff
|
||||
Interactive_Interaction interaction;
|
||||
Interactive_Action action;
|
||||
|
@ -95,12 +95,11 @@ struct View{
|
|||
u32 *palette;
|
||||
i32 palette_size;
|
||||
Color_View_Mode color_mode;
|
||||
Super_Color color;
|
||||
Color_Highlight highlight;
|
||||
b32 p4c_only;
|
||||
Style_Library inspecting_styles;
|
||||
b8 import_export_check[64];
|
||||
i32 import_file_id;
|
||||
#endif
|
||||
|
||||
// file stuff
|
||||
i32 font_advance;
|
||||
|
@ -1314,7 +1313,6 @@ view_set_file(
|
|||
if (set_vui){
|
||||
// TODO(allen): Fix this! There should be a way to easily separate setting a file,
|
||||
// and switching to file mode, so that they don't cross over eachother like this.
|
||||
view->ui_state = {};
|
||||
view->showing_ui = VUI_None;
|
||||
}
|
||||
}
|
||||
|
@ -1684,6 +1682,7 @@ file_do_single_edit(System_Functions *system,
|
|||
|
||||
Assert(scratch_size > 0);
|
||||
i32 request_amount = 0;
|
||||
Assert(end <= buffer_size(&file->state.buffer));
|
||||
while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount,
|
||||
part->base + part->pos, scratch_size, &request_amount)){
|
||||
void *new_data = 0;
|
||||
|
@ -1707,6 +1706,7 @@ file_do_single_edit(System_Functions *system,
|
|||
buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount);
|
||||
buffer_remeasure_widths(buffer, font->advance_data, line_start, line_end, line_shift);
|
||||
|
||||
// NOTE(allen): update the views looking at this file
|
||||
Panel *panel, *used_panels;
|
||||
used_panels = &layout->used_sentinel;
|
||||
|
||||
|
@ -1728,8 +1728,7 @@ file_do_single_edit(System_Functions *system,
|
|||
desc.end = end;
|
||||
desc.shift_amount = shift_amount;
|
||||
|
||||
file_edit_cursor_fix(system, part, general,
|
||||
file, layout, desc);
|
||||
file_edit_cursor_fix(system, part, general, file, layout, desc);
|
||||
}
|
||||
|
||||
internal void
|
||||
|
@ -2514,6 +2513,7 @@ remeasure_file_view(System_Functions *system, View *view, i32_Rect rect){
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
internal void
|
||||
undo_shit(System_Functions *system, View *view, UI_State *state, UI_Layout *layout,
|
||||
i32 total_count, i32 undo_count, i32 scrub_max){
|
||||
|
@ -2588,19 +2588,19 @@ draw_file_view_queries(View *view, UI_State *state, UI_Layout *layout){
|
|||
}
|
||||
|
||||
inline void
|
||||
view_show_menu(View *fview, Command_Map *gui_map){
|
||||
fview->ui_state = {};
|
||||
fview->map_for_file = fview->map;
|
||||
fview->map = gui_map;
|
||||
fview->showing_ui = VUI_Menu;
|
||||
view_show_menu(View *view, Command_Map *gui_map){
|
||||
view->ui_state = {};
|
||||
view->map_for_file = view->map;
|
||||
view->map = gui_map;
|
||||
view->showing_ui = VUI_Menu;
|
||||
}
|
||||
|
||||
inline void
|
||||
view_show_config(View *fview, Command_Map *gui_map){
|
||||
fview->ui_state = {};
|
||||
fview->map_for_file = fview->map;
|
||||
fview->map = gui_map;
|
||||
fview->showing_ui = VUI_Config;
|
||||
view_show_config(View *view, Command_Map *gui_map){
|
||||
view->ui_state = {};
|
||||
view->map_for_file = view->map;
|
||||
view->map = gui_map;
|
||||
view->showing_ui = VUI_Config;
|
||||
}
|
||||
|
||||
inline void
|
||||
|
@ -2634,10 +2634,26 @@ view_show_theme(View *view, Command_Map *gui_map){
|
|||
view->color_mode = CV_Mode_Library;
|
||||
view->color = super_color_create(0xFF000000);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
inline void
|
||||
view_show_menu(View *view, Command_Map *gui_map){}
|
||||
|
||||
inline void
|
||||
view_show_config(View *view, Command_Map *gui_map){}
|
||||
|
||||
inline void
|
||||
view_show_interactive(System_Functions *system, View *view,
|
||||
Command_Map *gui_map, Interactive_Action action,
|
||||
Interactive_Interaction interaction, String query){}
|
||||
|
||||
inline void
|
||||
view_show_theme(View *view, Command_Map *gui_map){}
|
||||
|
||||
|
||||
inline void
|
||||
view_show_file(View *view, Command_Map *file_map){
|
||||
view->ui_state = {};
|
||||
if (file_map){
|
||||
view->map = file_map;
|
||||
}
|
||||
|
@ -2647,6 +2663,7 @@ view_show_file(View *view, Command_Map *file_map){
|
|||
view->showing_ui = VUI_None;
|
||||
}
|
||||
|
||||
#if 0
|
||||
internal void
|
||||
interactive_view_complete(View *view){
|
||||
Models *models = view->models;
|
||||
|
@ -2718,7 +2735,9 @@ interactive_view_complete(View *view){
|
|||
// underlying file which is a giant pain.
|
||||
view->file = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
internal void
|
||||
update_highlighting(View *view){
|
||||
View *file_view = view->hot_file_view;
|
||||
|
@ -3370,6 +3389,7 @@ config_shit(View *view, UI_State *state, UI_Layout *layout){
|
|||
models->settings.lctrl_lalt_is_altgr = !models->settings.lctrl_lalt_is_altgr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
struct File_Bar{
|
||||
f32 pos_x, pos_y;
|
||||
|
@ -3381,7 +3401,6 @@ struct File_Bar{
|
|||
internal void
|
||||
intbar_draw_string(Render_Target *target, File_Bar *bar, String str, u32 char_color){
|
||||
i16 font_id = bar->font_id;
|
||||
|
||||
draw_string(target, font_id, str,
|
||||
(i32)(bar->pos_x + bar->text_shift_x),
|
||||
(i32)(bar->pos_y + bar->text_shift_y),
|
||||
|
@ -3389,75 +3408,6 @@ intbar_draw_string(Render_Target *target, File_Bar *bar, String str, u32 char_co
|
|||
bar->pos_x += font_string_width(target, font_id, str);
|
||||
}
|
||||
|
||||
internal void
|
||||
do_file_bar(View *view, Editing_File *file, UI_Layout *layout, Render_Target *target){
|
||||
File_Bar bar;
|
||||
Models *models = view->models;
|
||||
Style_Font *font = &models->global_font;
|
||||
i32 line_height = view->font_height;
|
||||
Interactive_Style bar_style = models->style.main.file_info_style;
|
||||
|
||||
u32 back_color = bar_style.bar_color;
|
||||
u32 base_color = bar_style.base_color;
|
||||
u32 pop1_color = bar_style.pop1_color;
|
||||
u32 pop2_color = bar_style.pop2_color;
|
||||
|
||||
bar.rect = layout_rect(layout, line_height + 2);
|
||||
|
||||
if (target){
|
||||
bar.font_id = font->font_id;
|
||||
bar.pos_x = (f32)bar.rect.x0;
|
||||
bar.pos_y = (f32)bar.rect.y0;
|
||||
bar.text_shift_y = 2;
|
||||
bar.text_shift_x = 0;
|
||||
|
||||
draw_rectangle(target, bar.rect, back_color);
|
||||
intbar_draw_string(target, &bar, file->name.live_name, base_color);
|
||||
intbar_draw_string(target, &bar, make_lit_string(" -"), base_color);
|
||||
|
||||
if (file->state.is_loading){
|
||||
intbar_draw_string(target, &bar, make_lit_string(" loading"), base_color);
|
||||
}
|
||||
else{
|
||||
char line_number_space[30];
|
||||
String line_number = make_string(line_number_space, 0, 30);
|
||||
append(&line_number, " L#");
|
||||
append_int_to_str(view->cursor.line, &line_number);
|
||||
|
||||
intbar_draw_string(target, &bar, line_number, base_color);
|
||||
|
||||
intbar_draw_string(target, &bar, make_lit_string(" -"), base_color);
|
||||
|
||||
if (file->settings.dos_write_mode){
|
||||
intbar_draw_string(target, &bar, make_lit_string(" dos"), base_color);
|
||||
}
|
||||
else{
|
||||
intbar_draw_string(target, &bar, make_lit_string(" nix"), base_color);
|
||||
}
|
||||
|
||||
if (file->state.still_lexing){
|
||||
intbar_draw_string(target, &bar, make_lit_string(" parsing"), pop1_color);
|
||||
}
|
||||
|
||||
if (!file->settings.unimportant){
|
||||
switch (buffer_get_sync(file)){
|
||||
case SYNC_BEHIND_OS:
|
||||
{
|
||||
persist String out_of_sync = make_lit_string(" !");
|
||||
intbar_draw_string(target, &bar, out_of_sync, pop2_color);
|
||||
}break;
|
||||
|
||||
case SYNC_UNSAVED:
|
||||
{
|
||||
persist String out_of_sync = make_lit_string(" *");
|
||||
intbar_draw_string(target, &bar, out_of_sync, pop2_color);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
view_reinit_scrolling(View *view){
|
||||
Editing_File *file = view->file;
|
||||
|
@ -3494,83 +3444,36 @@ view_reinit_scrolling(View *view){
|
|||
}
|
||||
|
||||
internal i32
|
||||
step_file_view(System_Functions *system, Exchange *exchange, View *view, i32_Rect rect,
|
||||
b32 is_active, Input_Summary *user_input){
|
||||
|
||||
Models *models = view->models;
|
||||
file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active){
|
||||
i32 result = 0;
|
||||
Editing_File *file = view->file;
|
||||
|
||||
i32 widget_height = 0;
|
||||
{
|
||||
UI_State state =
|
||||
ui_state_init(&view->widget.state, 0, user_input,
|
||||
&models->style, models->global_font.font_id, models->font_set, 0, 1);
|
||||
|
||||
UI_Layout layout;
|
||||
begin_layout(&layout, rect);
|
||||
|
||||
switch (view->widget.type){
|
||||
case FWIDG_NONE:
|
||||
{
|
||||
if (file && view->showing_ui == VUI_None){
|
||||
do_file_bar(view, file, &layout, 0);
|
||||
}
|
||||
|
||||
draw_file_view_queries(view, &state, &layout);
|
||||
}break;
|
||||
|
||||
case FWIDG_TIMELINES:
|
||||
{
|
||||
i32 scrub_max = view->scrub_max;
|
||||
i32 undo_count = file->state.undo.undo.edit_count;
|
||||
i32 redo_count = file->state.undo.redo.edit_count;
|
||||
i32 total_count = undo_count + redo_count;
|
||||
|
||||
undo_shit(system, view, &state, &layout, total_count, undo_count, scrub_max);
|
||||
}break;
|
||||
}
|
||||
|
||||
widget_height = layout.y - rect.y0;
|
||||
if (ui_finish_frame(&view->widget.state, &state, &layout, rect, 0, 0)){
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
view->scroll_min_limit = (f32)-widget_height;
|
||||
if (view->reinit_scrolling){
|
||||
view_reinit_scrolling(view);
|
||||
}
|
||||
|
||||
// TODO(allen): Split this into passive step and step that depends on input
|
||||
if (view->showing_ui == VUI_None && file && !file->state.is_loading){
|
||||
if (file && !file->state.is_loading){
|
||||
f32 line_height = (f32)view->font_height;
|
||||
f32 cursor_y = view_get_cursor_y(view);
|
||||
f32 target_y = view->target_y;
|
||||
f32 max_y = view_compute_height(view) - line_height*2;
|
||||
i32 lowest_line = view_compute_lowest_line(view);
|
||||
f32 max_target_y = view_compute_max_target_y(lowest_line, (i32)line_height, max_y);
|
||||
|
||||
f32 delta_y = 3.f*line_height;
|
||||
f32 extra_top = (f32)widget_height;
|
||||
f32 taken_top_space = line_height + extra_top;
|
||||
|
||||
f32 max_y = (f32)(region.y1 - region.y0);
|
||||
f32 max_x = (f32)(region.x1 - region.x0);
|
||||
f32 max_target_y = view_compute_max_target_y(lowest_line, (i32)line_height, max_y);
|
||||
|
||||
if (user_input->mouse.wheel != 0){
|
||||
f32 wheel_multiplier = 3.f;
|
||||
f32 delta_target_y = delta_y*user_input->mouse.wheel*wheel_multiplier;
|
||||
target_y += delta_target_y;
|
||||
|
||||
if (target_y < -taken_top_space) target_y = -taken_top_space;
|
||||
if (target_y < view->scroll_min_limit) target_y = view->scroll_min_limit;
|
||||
if (target_y > max_target_y) target_y = max_target_y;
|
||||
|
||||
f32 old_cursor_y = cursor_y;
|
||||
if (cursor_y >= target_y + max_y) cursor_y = target_y + max_y;
|
||||
if (cursor_y < target_y + taken_top_space) cursor_y = target_y + taken_top_space;
|
||||
if (cursor_y < target_y - view->scroll_min_limit) cursor_y = target_y - view->scroll_min_limit;
|
||||
|
||||
if (cursor_y != old_cursor_y){
|
||||
view->cursor =
|
||||
view_compute_cursor_from_xy(view,
|
||||
view->preferred_x,
|
||||
cursor_y);
|
||||
view_compute_cursor_from_xy(view, view->preferred_x, cursor_y);
|
||||
}
|
||||
|
||||
result = 1;
|
||||
|
@ -3579,17 +3482,16 @@ step_file_view(System_Functions *system, Exchange *exchange, View *view, i32_Rec
|
|||
if (cursor_y > target_y + max_y){
|
||||
target_y = cursor_y - max_y + delta_y;
|
||||
}
|
||||
if (cursor_y < target_y + taken_top_space){
|
||||
target_y = cursor_y - delta_y - taken_top_space;
|
||||
if (cursor_y < target_y - view->scroll_min_limit){
|
||||
target_y = cursor_y - delta_y + view->scroll_min_limit;
|
||||
}
|
||||
|
||||
if (target_y > max_target_y) target_y = max_target_y;
|
||||
if (target_y < -extra_top) target_y = -extra_top;
|
||||
if (target_y < view->scroll_min_limit) target_y = view->scroll_min_limit;
|
||||
view->target_y = target_y;
|
||||
|
||||
f32 cursor_x = view_get_cursor_x(view);
|
||||
f32 target_x = view->target_x;
|
||||
f32 max_x = view_compute_width(view);
|
||||
if (cursor_x < target_x){
|
||||
target_x = (f32)Max(0, cursor_x - max_x/2);
|
||||
}
|
||||
|
@ -3619,11 +3521,10 @@ step_file_view(System_Functions *system, Exchange *exchange, View *view, i32_Rec
|
|||
}
|
||||
|
||||
if (user_input->mouse.press_l && is_active){
|
||||
f32 max_y = view_compute_height(view);
|
||||
f32 rx = (f32)(user_input->mouse.x - rect.x0);
|
||||
f32 ry = (f32)(user_input->mouse.y - rect.y0);
|
||||
f32 rx = (f32)(user_input->mouse.x - region.x0);
|
||||
f32 ry = (f32)(user_input->mouse.y - region.y0);
|
||||
|
||||
if (ry >= extra_top){
|
||||
if (ry >= -view->scroll_min_limit){
|
||||
view_set_widget(view, FWIDG_NONE);
|
||||
if (rx >= 0 && rx < max_x && ry >= 0 && ry < max_y){
|
||||
view_cursor_move(view, rx + view->scroll_x, ry + view->scroll_y, 1);
|
||||
|
@ -3632,10 +3533,132 @@ step_file_view(System_Functions *system, Exchange *exchange, View *view, i32_Rec
|
|||
}
|
||||
result = 1;
|
||||
}
|
||||
|
||||
if (!is_active) view_set_widget(view, FWIDG_NONE);
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal i32
|
||||
step_file_view(View *view, b32 is_active){
|
||||
gui_begin_top_level(&view->gui_target);
|
||||
{
|
||||
gui_do_top_bar(&view->gui_target);
|
||||
|
||||
gui_begin_overlap(&view->gui_target);
|
||||
{
|
||||
gui_begin_serial_section(&view->gui_target);
|
||||
{
|
||||
// do widget
|
||||
}
|
||||
gui_end_serial_section(&view->gui_target);
|
||||
|
||||
gui_begin_serial_section(&view->gui_target);
|
||||
{
|
||||
switch (view->showing_ui){
|
||||
case VUI_None:
|
||||
gui_do_file(&view->gui_target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
gui_end_serial_section(&view->gui_target);
|
||||
}
|
||||
gui_end_overlap(&view->gui_target);
|
||||
}
|
||||
gui_end_top_level(&view->gui_target);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
internal i32
|
||||
do_input_file_view(System_Functions *system, Exchange *exchange,
|
||||
View *view, i32_Rect rect, b32 is_active, Input_Summary *user_input){
|
||||
|
||||
i32 result = 0;
|
||||
|
||||
GUI_Session gui_session;
|
||||
GUI_Header *h;
|
||||
|
||||
gui_session_init(&gui_session, rect, view->font_height);
|
||||
|
||||
for (h = (GUI_Header*)view->gui_target.push.base;
|
||||
h->type;
|
||||
h = NextHeader(h)){
|
||||
if (gui_interpret(&gui_session, h)){
|
||||
switch (h->type){
|
||||
case guicom_top_bar: break;
|
||||
|
||||
case guicom_file:
|
||||
{
|
||||
view->scroll_min_limit = -(f32)(gui_session.clip_rect.y0 - gui_session.rect.y0);
|
||||
if (view->reinit_scrolling){
|
||||
view_reinit_scrolling(view);
|
||||
}
|
||||
if (file_step(view, gui_session.rect, user_input, is_active)){
|
||||
result = 1;
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
|
||||
#if 0
|
||||
Models *models = view->models;
|
||||
i32 result = 0;
|
||||
|
||||
i32 widget_height = 0;
|
||||
AllowLocal(models);
|
||||
|
||||
#if 0
|
||||
{
|
||||
UI_State state =
|
||||
ui_state_init(&view->widget.state, 0, user_input,
|
||||
&models->style, models->global_font.font_id, models->font_set, 0, 1);
|
||||
|
||||
UI_Layout layout;
|
||||
begin_layout(&layout, rect);
|
||||
|
||||
switch (view->widget.type){
|
||||
case FWIDG_NONE:
|
||||
{
|
||||
if (file && view->showing_ui == VUI_None){
|
||||
do_file_bar(view, file, &layout, 0);
|
||||
}
|
||||
draw_file_view_queries(view, &state, &layout);
|
||||
}break;
|
||||
|
||||
case FWIDG_TIMELINES:
|
||||
{
|
||||
i32 scrub_max = view->scrub_max;
|
||||
i32 undo_count = file->state.undo.undo.edit_count;
|
||||
i32 redo_count = file->state.undo.redo.edit_count;
|
||||
i32 total_count = undo_count + redo_count;
|
||||
undo_shit(system, view, &state, &layout, total_count, undo_count, scrub_max);
|
||||
}break;
|
||||
}
|
||||
|
||||
widget_height = layout.y - rect.y0;
|
||||
if (ui_finish_frame(&view->widget.state, &state, &layout, rect, 0, 0)){
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
view->scroll_min_limit = (f32)-widget_height;
|
||||
if (view->reinit_scrolling){
|
||||
view_reinit_scrolling(view);
|
||||
}
|
||||
|
||||
if (view->showing_ui == VUI_None){
|
||||
if (file_step(view, rect, user_input, is_active)){
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
UI_State state =
|
||||
ui_state_init(&view->ui_state, 0, user_input,
|
||||
|
@ -3679,8 +3702,10 @@ step_file_view(System_Functions *system, Exchange *exchange, View *view, i32_Rec
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return(result);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal i32
|
||||
|
@ -3851,16 +3876,167 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
|
|||
return(0);
|
||||
}
|
||||
|
||||
internal void
|
||||
do_render_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect rect){
|
||||
File_Bar bar;
|
||||
Models *models = view->models;
|
||||
Style_Font *font = &models->global_font;
|
||||
Interactive_Style bar_style = models->style.main.file_info_style;
|
||||
|
||||
u32 back_color = bar_style.bar_color;
|
||||
u32 base_color = bar_style.base_color;
|
||||
u32 pop1_color = bar_style.pop1_color;
|
||||
u32 pop2_color = bar_style.pop2_color;
|
||||
|
||||
bar.rect = rect;
|
||||
|
||||
if (target){
|
||||
bar.font_id = font->font_id;
|
||||
bar.pos_x = (f32)bar.rect.x0;
|
||||
bar.pos_y = (f32)bar.rect.y0;
|
||||
bar.text_shift_y = 2;
|
||||
bar.text_shift_x = 0;
|
||||
|
||||
draw_rectangle(target, bar.rect, back_color);
|
||||
if (file){
|
||||
intbar_draw_string(target, &bar, file->name.live_name, base_color);
|
||||
}
|
||||
else{
|
||||
intbar_draw_string(target, &bar, make_lit_string("*NULL*"), base_color);
|
||||
}
|
||||
intbar_draw_string(target, &bar, make_lit_string(" -"), base_color);
|
||||
|
||||
if (file){
|
||||
if (file->state.is_loading){
|
||||
intbar_draw_string(target, &bar, make_lit_string(" loading"), base_color);
|
||||
}
|
||||
else{
|
||||
char line_number_space[30];
|
||||
String line_number = make_string(line_number_space, 0, 30);
|
||||
append(&line_number, " L#");
|
||||
append_int_to_str(view->cursor.line, &line_number);
|
||||
|
||||
intbar_draw_string(target, &bar, line_number, base_color);
|
||||
|
||||
intbar_draw_string(target, &bar, make_lit_string(" -"), base_color);
|
||||
|
||||
if (file->settings.dos_write_mode){
|
||||
intbar_draw_string(target, &bar, make_lit_string(" dos"), base_color);
|
||||
}
|
||||
else{
|
||||
intbar_draw_string(target, &bar, make_lit_string(" nix"), base_color);
|
||||
}
|
||||
|
||||
if (file->state.still_lexing){
|
||||
intbar_draw_string(target, &bar, make_lit_string(" parsing"), pop1_color);
|
||||
}
|
||||
|
||||
if (!file->settings.unimportant){
|
||||
switch (buffer_get_sync(file)){
|
||||
case SYNC_BEHIND_OS:
|
||||
{
|
||||
persist String out_of_sync = make_lit_string(" !");
|
||||
intbar_draw_string(target, &bar, out_of_sync, pop2_color);
|
||||
}break;
|
||||
|
||||
case SYNC_UNSAVED:
|
||||
{
|
||||
persist String out_of_sync = make_lit_string(" *");
|
||||
intbar_draw_string(target, &bar, out_of_sync, pop2_color);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal i32
|
||||
draw_file_view(System_Functions *system, Exchange *exchange,
|
||||
do_render_file_view(System_Functions *system, Exchange *exchange,
|
||||
View *view, View *active, i32_Rect rect, b32 is_active,
|
||||
Render_Target *target, Input_Summary *user_input){
|
||||
|
||||
Editing_File *file = view->file;
|
||||
i32 result = 0;
|
||||
|
||||
GUI_Session gui_session = {0};
|
||||
GUI_Header *h;
|
||||
|
||||
gui_session_init(&gui_session, rect, view->font_height);
|
||||
|
||||
for (h = (GUI_Header*)view->gui_target.push.base;
|
||||
h->type;
|
||||
h = NextHeader(h)){
|
||||
if (gui_interpret(&gui_session, h)){
|
||||
switch (h->type){
|
||||
case guicom_top_bar:
|
||||
{
|
||||
do_render_file_bar(target, view, file, gui_session.rect);
|
||||
}
|
||||
break;
|
||||
|
||||
case guicom_file:
|
||||
{
|
||||
target->push_clip(target, gui_session.clip_rect);
|
||||
view->scroll_min_limit = -(f32)(gui_session.clip_rect.y0 - gui_session.rect.y0);
|
||||
if (view->reinit_scrolling){
|
||||
view_reinit_scrolling(view);
|
||||
}
|
||||
if (file && file_is_ready(file)){
|
||||
result = draw_file_loaded(view, gui_session.rect, is_active, target);
|
||||
}
|
||||
target->pop_clip(target);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
|
||||
#if 0
|
||||
|
||||
Editing_File *file = view->file;
|
||||
i32 result = 0;
|
||||
|
||||
{
|
||||
i32 line_height = view->font_height;
|
||||
i32_Rect bar_rect = rect;
|
||||
bar_rect.y1 = bar_rect.y0 + line_height + 2;
|
||||
do_render_file_bar(target, view, file, bar_rect);
|
||||
|
||||
rect.y0 = bar_rect.y1;
|
||||
}
|
||||
|
||||
target->push_clip(target, rect);
|
||||
if (view->gui_target.show_file){
|
||||
view->scroll_min_limit = 0;
|
||||
if (view->reinit_scrolling){
|
||||
view_reinit_scrolling(view);
|
||||
}
|
||||
|
||||
switch (view->showing_ui){
|
||||
case VUI_None:
|
||||
{
|
||||
if (file && file_is_ready(file)){
|
||||
result = draw_file_loaded(view, rect, is_active, target);
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
target->pop_clip(target);
|
||||
|
||||
return(result);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
Models *models = view->models;
|
||||
Editing_File *file = view->file;
|
||||
i32 result = 0;
|
||||
|
||||
i32 widget_height = 0;
|
||||
AllowLocal(models);
|
||||
|
||||
#if 0
|
||||
{
|
||||
UI_State state =
|
||||
ui_state_init(&view->widget.state, target, 0,
|
||||
|
@ -3896,60 +4072,30 @@ draw_file_view(System_Functions *system, Exchange *exchange,
|
|||
widget_height = layout.y - rect.y0;
|
||||
ui_finish_frame(&view->widget.state, &state, &layout, rect, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
view->scroll_min_limit = (f32)-widget_height;
|
||||
|
||||
{
|
||||
rect.y0 += widget_height;
|
||||
target->push_clip(target, rect);
|
||||
|
||||
UI_State state =
|
||||
ui_state_init(&view->ui_state, target, user_input,
|
||||
&models->style, models->global_font.font_id, models->font_set, &models->working_set, 0);
|
||||
|
||||
UI_Layout layout;
|
||||
begin_layout(&layout, rect);
|
||||
|
||||
rect.y0 -= widget_height;
|
||||
|
||||
Super_Color color = {};
|
||||
|
||||
switch (view->showing_ui){
|
||||
case VUI_None:
|
||||
{
|
||||
if (file && file_is_ready(file)){
|
||||
if (view->reinit_scrolling){
|
||||
view_reinit_scrolling(view);
|
||||
}
|
||||
result = draw_file_loaded(view, rect, is_active, target);
|
||||
}
|
||||
}break;
|
||||
|
||||
case VUI_Theme:
|
||||
{
|
||||
theme_shit(system, exchange, view, active, &state, &layout, &color);
|
||||
}break;
|
||||
|
||||
case VUI_Interactive:
|
||||
{
|
||||
interactive_shit(system, view, &state, &layout);
|
||||
}break;
|
||||
case VUI_Menu:
|
||||
{
|
||||
menu_shit(view, &state, &layout);
|
||||
}break;
|
||||
case VUI_Config:
|
||||
{
|
||||
config_shit(view, &state, &layout);
|
||||
}break;
|
||||
}
|
||||
|
||||
ui_finish_frame(&view->ui_state, &state, &layout, rect, 0, 0);
|
||||
|
||||
target->pop_clip(target);
|
||||
}
|
||||
|
||||
|
||||
return (result);
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO(allen): Passing this hook and app pointer is a hack. It can go as soon as we start
|
||||
|
@ -4200,7 +4346,7 @@ live_set_alloc_view(Live_Views *live_set, Panel *panel, Models *models){
|
|||
result.id = (i32)(result.view - live_set->views);
|
||||
|
||||
dll_remove(result.view);
|
||||
memset(result.view, 0, sizeof(View));
|
||||
memset(result.view, 0, sizeof(*result.view));
|
||||
result.view->id = result.id;
|
||||
|
||||
result.view->in_use = 1;
|
||||
|
@ -4210,12 +4356,20 @@ live_set_alloc_view(Live_Views *live_set, Panel *panel, Models *models){
|
|||
result.view->models = models;
|
||||
result.view->scrub_max = 1;
|
||||
|
||||
#if 0
|
||||
// TODO(allen): Make "interactive" mode customizable just like the query bars!
|
||||
result.view->query = make_fixed_width_string(result.view->query_);
|
||||
result.view->dest = make_fixed_width_string(result.view->dest_);
|
||||
#endif
|
||||
|
||||
init_query_set(&result.view->query_set);
|
||||
|
||||
{
|
||||
i32 gui_mem_size = Kbytes(32);
|
||||
void *gui_mem = general_memory_allocate(&models->mem.general, gui_mem_size, 0);
|
||||
result.view->gui_target.push = partition_open(gui_mem, gui_mem_size);
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
|
2280
4ed_gui.cpp
2280
4ed_gui.cpp
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -163,6 +163,7 @@ buffer_backify_next(Buffer_Backify_Loop *loop){
|
|||
internal_4tech int
|
||||
buffer_replace_range(Buffer *buffer, int start, int end, char *str, int len, int *shift_amount,
|
||||
void *scratch, int scratch_size, int *request_amount){
|
||||
|
||||
char *data;
|
||||
int result;
|
||||
int size;
|
||||
|
@ -202,6 +203,7 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Buffer *buffer, Buffer_Edit *s
|
|||
|
||||
edit = sorted_edits + i;
|
||||
for (; i < edit_count; ++i, ++edit){
|
||||
assert(edit->end + shift_total < buffer_size(buffer));
|
||||
result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total,
|
||||
strings + edit->str_start, edit->len, &shift_amount,
|
||||
scratch, scratch_size, request_amount);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
@echo off
|
||||
|
||||
"w:\4ed\misc\build_exp.bat" /Zi
|
||||
REM "w:\4ed\misc\build_all.bat" /DFRED_SUPER /DFRED_NOT_PACKAGE /Zi
|
||||
REM "w:\4ed\misc\build_exp.bat" /Zi
|
||||
"w:\4ed\misc\build_all.bat" /DFRED_SUPER /DFRED_NOT_PACKAGE /Zi
|
||||
REM "w:\4ed\misc\build_all.bat" /O2 /Zi
|
||||
|
|
|
@ -58,7 +58,9 @@ enum Lex_Int_State{
|
|||
LSINT_ul,
|
||||
LSINT_uL,
|
||||
LSINT_ll,
|
||||
LSINT_extra
|
||||
LSINT_extra,
|
||||
//
|
||||
LSINT_count
|
||||
};
|
||||
|
||||
enum Lex_INC_State{
|
||||
|
|
|
@ -10,6 +10,19 @@ unsigned char whitespace_fsm_table[] = {
|
|||
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
unsigned short int_fsm_eq_classes[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0,16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,24, 0, 0, 0, 0, 0, 0, 0, 0,16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
const int num_int_fsm_eq_classes = 4;
|
||||
|
||||
unsigned char int_fsm_table[] = {
|
||||
8, 9,10,11,12,13,14,15,
|
||||
3, 5,10, 6,12, 7,14,15,
|
||||
1, 9, 7, 7,12,13, 7,15,
|
||||
2, 4, 6,11, 7,13,14,15,
|
||||
};
|
||||
|
||||
unsigned char multiline_state_table[] = {
|
||||
0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
|
|
@ -4,13 +4,9 @@
|
|||
#ifndef FCPP_NEW_LEXER_INC
|
||||
#define FCPP_NEW_LEXER_INC
|
||||
|
||||
#include "../4cpp_lexer_types.h"
|
||||
#include "4cpp_lexer_fsms.h"
|
||||
#include "4cpp_lexer_tables.c"
|
||||
|
||||
namespace new_lex{
|
||||
//
|
||||
|
||||
#define lexer_link static
|
||||
|
||||
// TODO(allen): revisit this keyword data declaration system
|
||||
|
@ -336,7 +332,8 @@ cpp_shift_token_starts(Cpp_Token_Stack *stack, int from_token_i, int shift_amoun
|
|||
|
||||
enum Pos_Update_Rule{
|
||||
PUR_none,
|
||||
PUR_unget_whitespace
|
||||
PUR_back_one,
|
||||
PUR_unget_whitespace,
|
||||
};
|
||||
|
||||
lexer_link Lex_PP_State
|
||||
|
@ -439,470 +436,6 @@ struct Lex_Data{
|
|||
int __pc__;
|
||||
};
|
||||
|
||||
Whitespace_FSM
|
||||
whitespace_skip_fsm(Whitespace_FSM wfsm, char c){
|
||||
if (wfsm.pp_state != LSPP_default){
|
||||
if (c == '\n') wfsm.pp_state = LSPP_default;
|
||||
}
|
||||
if (!(c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '\f' || c == '\v')){
|
||||
wfsm.white_done = 1;
|
||||
}
|
||||
return(wfsm);
|
||||
}
|
||||
|
||||
Lex_FSM
|
||||
int_fsm(Lex_FSM fsm, char c){
|
||||
switch (fsm.int_state){
|
||||
case LSINT_default:
|
||||
switch (c){
|
||||
case 'u': case 'U': fsm.int_state = LSINT_u; break;
|
||||
case 'l': fsm.int_state = LSINT_l; break;
|
||||
case 'L': fsm.int_state = LSINT_L; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINT_u:
|
||||
switch (c){
|
||||
case 'l': fsm.int_state = LSINT_ul; break;
|
||||
case 'L': fsm.int_state = LSINT_uL; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINT_l:
|
||||
switch (c){
|
||||
case 'l': fsm.int_state = LSINT_ll; break;
|
||||
case 'U': case 'u': fsm.int_state = LSINT_extra; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINT_L:
|
||||
switch (c){
|
||||
case 'L': fsm.int_state = LSINT_ll; break;
|
||||
case 'U': case 'u': fsm.int_state = LSINT_extra; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINT_ul:
|
||||
switch (c){
|
||||
case 'l': fsm.int_state = LSINT_extra; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINT_uL:
|
||||
switch (c){
|
||||
case 'L': fsm.int_state = LSINT_extra; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINT_ll:
|
||||
switch (c){
|
||||
case 'u': case 'U': fsm.int_state = LSINT_extra; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINT_extra:
|
||||
fsm.emit_token = 1;
|
||||
break;
|
||||
}
|
||||
return(fsm);
|
||||
}
|
||||
|
||||
Lex_FSM
|
||||
main_fsm(Lex_FSM fsm, unsigned char pp_state, unsigned char c){
|
||||
if (c == 0) fsm.emit_token = 1;
|
||||
else
|
||||
switch (pp_state){
|
||||
case LSPP_error:
|
||||
fsm.state = LS_error_message;
|
||||
if (c == '\n') fsm.emit_token = 1;
|
||||
break;
|
||||
|
||||
case LSPP_include:
|
||||
switch (fsm.state){
|
||||
case LSINC_default:
|
||||
switch (c){
|
||||
case '"': fsm.state = LSINC_quotes; break;
|
||||
case '<': fsm.state = LSINC_pointy; break;
|
||||
default: fsm.state = LSINC_junk; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINC_quotes:
|
||||
if (c == '"') fsm.emit_token = 1;
|
||||
break;
|
||||
|
||||
case LSINC_pointy:
|
||||
if (c == '>') fsm.emit_token = 1;
|
||||
break;
|
||||
|
||||
case LSINC_junk:
|
||||
if (c == '\n') fsm.emit_token = 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
switch (fsm.state){
|
||||
case LS_default:
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'){
|
||||
fsm.state = LS_identifier;
|
||||
}
|
||||
else if (c >= '1' && c <= '9'){
|
||||
fsm.state = LS_number;
|
||||
}
|
||||
else if (c == '0'){
|
||||
fsm.state = LS_number0;
|
||||
}
|
||||
else switch (c){
|
||||
case '\'': fsm.state = LS_char; break;
|
||||
case '"': fsm.state = LS_string; break;
|
||||
|
||||
case '/': fsm.state = LS_comment_pre; break;
|
||||
|
||||
case '.': fsm.state = LS_dot; break;
|
||||
|
||||
case '<': fsm.state = LS_less; break;
|
||||
case '>': fsm.state = LS_more; break;
|
||||
|
||||
case '-': fsm.state = LS_minus; break;
|
||||
|
||||
case '&': fsm.state = LS_and; break;
|
||||
case '|': fsm.state = LS_or; break;
|
||||
|
||||
case '+': fsm.state = LS_plus; break;
|
||||
|
||||
case ':': fsm.state = LS_colon; break;
|
||||
|
||||
case '*': fsm.state = LS_star; break;
|
||||
|
||||
case '%': fsm.state = LS_modulo; break;
|
||||
case '^': fsm.state = LS_caret; break;
|
||||
|
||||
case '=': fsm.state = LS_eq; break;
|
||||
case '!': fsm.state = LS_bang; break;
|
||||
|
||||
case '#': fsm.state = LS_pound; break;
|
||||
|
||||
#define OperCase(op,type) case op: fsm.emit_token = 1; break;
|
||||
OperCase('{', CPP_TOKEN_BRACE_OPEN);
|
||||
OperCase('}', CPP_TOKEN_BRACE_CLOSE);
|
||||
|
||||
OperCase('[', CPP_TOKEN_BRACKET_OPEN);
|
||||
OperCase(']', CPP_TOKEN_BRACKET_CLOSE);
|
||||
|
||||
OperCase('(', CPP_TOKEN_PARENTHESE_OPEN);
|
||||
OperCase(')', CPP_TOKEN_PARENTHESE_CLOSE);
|
||||
|
||||
OperCase('~', CPP_TOKEN_TILDE);
|
||||
OperCase(',', CPP_TOKEN_COMMA);
|
||||
OperCase(';', CPP_TOKEN_SEMICOLON);
|
||||
OperCase('?', CPP_TOKEN_TERNARY_QMARK);
|
||||
|
||||
OperCase('@', CPP_TOKEN_JUNK);
|
||||
OperCase('$', CPP_TOKEN_JUNK);
|
||||
OperCase('\\', CPP_TOKEN_JUNK);
|
||||
#undef OperCase
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_identifier:
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_pound:
|
||||
if (pp_state == LSPP_default){
|
||||
if (c == ' ' || c == '\t' || c == '\r' || c == '\f' || c == '\v'){
|
||||
fsm.state = LS_pound;
|
||||
}
|
||||
else if (c == '\n'){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
else{
|
||||
fsm.state = LS_pp;
|
||||
}
|
||||
}
|
||||
else{
|
||||
switch (c){
|
||||
case '#': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_pp:
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_char:
|
||||
switch(c){
|
||||
case '\'': fsm.emit_token = 1; break;
|
||||
case '\\': fsm.state = LS_char_slashed; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_char_slashed:
|
||||
switch (c){
|
||||
case '\r': case '\f': case '\v': break;
|
||||
case '\n': fsm.state = LS_string; fsm.multi_line |= 1; break;
|
||||
default: fsm.state = LS_char; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_string:
|
||||
switch(c){
|
||||
case '\"': fsm.emit_token = 1; break;
|
||||
case '\\': fsm.state = LS_string_slashed; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_string_slashed:
|
||||
switch (c){
|
||||
case '\r': case '\f': case '\v': break;
|
||||
case '\n': fsm.state = LS_string; fsm.multi_line |= 1; break;
|
||||
default: fsm.state = LS_string; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_number:
|
||||
if (c >= '0' && c <= '9'){
|
||||
fsm.state = LS_number;
|
||||
}
|
||||
else{
|
||||
switch (c){
|
||||
case '.': fsm.state = LS_float; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_number0:
|
||||
if (c >= '0' && c <= '9'){
|
||||
fsm.state = LS_number;
|
||||
}
|
||||
else if (c == 'x'){
|
||||
fsm.state = LS_hex;
|
||||
}
|
||||
else if (c == '.'){
|
||||
fsm.state = LS_float;
|
||||
}
|
||||
else{
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_float:
|
||||
if (!(c >= '0' && c <= '9')){
|
||||
switch (c){
|
||||
case 'e': fsm.state = LS_crazy_float0; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_crazy_float0:
|
||||
{
|
||||
if ((c >= '0' && c <= '9') || c == '-'){
|
||||
fsm.state = LS_crazy_float1;
|
||||
}
|
||||
else{
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_crazy_float1:
|
||||
{
|
||||
if (!(c >= '0' && c <= '9')){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_hex:
|
||||
if (!(c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F')){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_dot:
|
||||
if (c >= '0' && c <= '9'){
|
||||
fsm.state = LS_float;
|
||||
}
|
||||
else
|
||||
switch (c){
|
||||
case '.': fsm.state = LS_ellipsis; break;
|
||||
case '*': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_ellipsis: fsm.emit_token = 1; break;
|
||||
|
||||
case LS_less:
|
||||
switch (c){
|
||||
case '<': fsm.state = LS_less_less; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_less_less:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_more:
|
||||
switch (c){
|
||||
case '>': fsm.state = LS_more_more; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_more_more:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment_pre:
|
||||
switch (c){
|
||||
case '/': fsm.state = LS_comment; break;
|
||||
case '*': fsm.state = LS_comment_block; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment:
|
||||
switch (c){
|
||||
case '\\': fsm.state = LS_comment_slashed; break;
|
||||
case '\n': fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment_slashed:
|
||||
switch (c){
|
||||
case '\r': case '\f': case '\v': break;
|
||||
default: fsm.state = LS_comment; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment_block:
|
||||
switch (c){
|
||||
case '*': fsm.state = LS_comment_block_ending; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment_block_ending:
|
||||
switch (c){
|
||||
case '*': fsm.state = LS_comment_block_ending; break;
|
||||
case '/': fsm.emit_token = 1; break;
|
||||
default: fsm.state = LS_comment_block; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_minus:
|
||||
switch (c){
|
||||
case '>': fsm.state = LS_arrow; break;
|
||||
case '-': fsm.emit_token = 1; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_arrow:
|
||||
switch (c){
|
||||
case '*': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_and:
|
||||
switch (c){
|
||||
case '&': fsm.emit_token = 1; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_or:
|
||||
switch (c){
|
||||
case '|': fsm.emit_token = 1; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_plus:
|
||||
switch (c){
|
||||
case '+': fsm.emit_token = 1; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_colon:
|
||||
switch (c){
|
||||
case ':': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_star:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_modulo:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_caret:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_eq:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_bang:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return(fsm);
|
||||
}
|
||||
|
||||
#define DrCase(PC) case PC: goto resumespot_##PC
|
||||
|
||||
#define DrYield(PC, n) {\
|
||||
|
@ -1002,7 +535,8 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
break;
|
||||
}
|
||||
}
|
||||
else switch (S.fsm.state){
|
||||
else{
|
||||
switch (S.fsm.state){
|
||||
case LS_default:
|
||||
switch (c){
|
||||
#define OperCase(op,t) case op: S.token.type = t; break;
|
||||
|
@ -1100,7 +634,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '#': S.token.type = CPP_PP_CONCAT; break;
|
||||
default:
|
||||
S.token.type = CPP_PP_STRINGIFY;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1135,16 +669,17 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case LS_number:
|
||||
case LS_number0:
|
||||
case LS_hex:
|
||||
S.fsm.int_state = LSINT_default;
|
||||
|
||||
{
|
||||
S.fsm.int_state = LSINT_default;
|
||||
S.fsm.emit_token = 0;
|
||||
--S.pos;
|
||||
for (;;){
|
||||
for (; S.fsm.emit_token == 0 && S.pos < end_pos;){
|
||||
for (; S.fsm.int_state < LSINT_count && S.pos < end_pos;){
|
||||
c = chunk[S.pos++];
|
||||
S.fsm = int_fsm(S.fsm, c);
|
||||
S.fsm.int_state = int_fsm_table[S.fsm.int_state + int_fsm_eq_classes[c]];
|
||||
}
|
||||
S.fsm.emit_token = (S.fsm.int_state >= LSINT_count);
|
||||
|
||||
if (S.fsm.emit_token == 0){
|
||||
DrYield(5, 1);
|
||||
}
|
||||
|
@ -1165,7 +700,9 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
switch (c){
|
||||
case 'f': case 'F':
|
||||
case 'l': case 'L':break;
|
||||
default: --S.pos; break;
|
||||
default:
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1195,7 +732,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_DIVEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_DIV;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1218,7 +755,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '*': S.token.type = CPP_TOKEN_PTRDOT; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_DOT;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1232,7 +769,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_JUNK;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1243,7 +780,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_LESSEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_LESS;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1254,7 +791,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_LSHIFTEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_LSHIFT;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1265,7 +802,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_GRTREQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_GRTR;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1276,7 +813,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_RSHIFTEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_RSHIFT;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1288,7 +825,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_SUBEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_MINUS;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1299,7 +836,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '*': S.token.type = CPP_TOKEN_PTRARROW; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_ARROW;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1311,7 +848,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_ANDEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_AMPERSAND;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1323,7 +860,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_OREQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_BIT_OR;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1335,7 +872,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_ADDEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_PLUS;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1346,7 +883,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case ':': S.token.type = CPP_TOKEN_SCOPE; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_COLON;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1357,7 +894,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_MULEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_STAR;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1368,7 +905,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_MODEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_MOD;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1379,7 +916,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_XOREQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_BIT_XOR;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1390,7 +927,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_EQEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_EQ;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -1401,13 +938,17 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
case '=': S.token.type = CPP_TOKEN_NOTEQ; break;
|
||||
default:
|
||||
S.token.type = CPP_TOKEN_NOT;
|
||||
--S.pos;
|
||||
pos_update_rule = PUR_back_one;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (pos_update_rule){
|
||||
case PUR_back_one:
|
||||
--S.pos;
|
||||
break;
|
||||
|
||||
case PUR_unget_whitespace:
|
||||
c = chunk[--S.pos];
|
||||
while (c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '\v' || c == '\f'){
|
||||
|
@ -1458,6 +999,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (S.fsm.emit_token){
|
||||
S.token.start = S.token_start;
|
||||
|
@ -1493,8 +1035,6 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
#undef DrReturn
|
||||
#undef DrCase
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// BOTTOM
|
||||
|
|
|
@ -17,7 +17,10 @@
|
|||
#include "../4cpp_lexer_types.h"
|
||||
#define FCPP_LEXER_IMPLEMENTATION
|
||||
#include "../4cpp_lexer.h"
|
||||
#include "4cpp_new_lexer.h"
|
||||
|
||||
namespace new_lex{
|
||||
# include "4cpp_new_lexer.h"
|
||||
}
|
||||
|
||||
#include <windows.h>
|
||||
#include <intrin.h>
|
||||
|
|
|
@ -528,6 +528,40 @@ struct FSM_Tables{
|
|||
unsigned short state_count;
|
||||
};
|
||||
|
||||
void
|
||||
do_table_reduction(FSM_Tables *table, unsigned short state_count){
|
||||
{
|
||||
table->eq_class_counter = 0;
|
||||
unsigned char *c_line = table->full_transition_table;
|
||||
for (unsigned short c = 0; c < 256; ++c){
|
||||
if (table->marks[c] == 0){
|
||||
table->eq_class[c] = table->eq_class_counter;
|
||||
table->eq_class_rep[table->eq_class_counter] = (unsigned char)c;
|
||||
unsigned char *c2_line = c_line + state_count;
|
||||
for (unsigned short c2 = c + 1; c2 < 256; ++c2){
|
||||
if (memcmp(c_line, c2_line, state_count) == 0){
|
||||
table->marks[c2] = 1;
|
||||
table->eq_class[c2] = table->eq_class_counter;
|
||||
}
|
||||
c2_line += state_count;
|
||||
}
|
||||
++table->eq_class_counter;
|
||||
}
|
||||
c_line += state_count;
|
||||
}
|
||||
}
|
||||
|
||||
table->reduced_transition_table = (unsigned char*)malloc(state_count * table->eq_class_counter);
|
||||
{
|
||||
unsigned char *r_line = table->reduced_transition_table;
|
||||
for (unsigned short eq = 0; eq < table->eq_class_counter; ++eq){
|
||||
unsigned char *u_line = table->full_transition_table + state_count * table->eq_class_rep[eq];
|
||||
memcpy(r_line, u_line, state_count);
|
||||
r_line += state_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FSM_Tables
|
||||
generate_whitespace_skip_table(){
|
||||
unsigned char state_count = LSPP_count;
|
||||
|
@ -551,35 +585,35 @@ generate_whitespace_skip_table(){
|
|||
}
|
||||
}
|
||||
|
||||
table.eq_class_counter = 0;
|
||||
unsigned char *c_line = table.full_transition_table;
|
||||
do_table_reduction(&table, state_count);
|
||||
|
||||
return(table);
|
||||
}
|
||||
|
||||
FSM_Tables
|
||||
generate_int_table(){
|
||||
unsigned char state_count = LSINT_count;
|
||||
FSM_Tables table;
|
||||
table.full_transition_table = (unsigned char*)malloc(state_count * 256);
|
||||
table.marks = (unsigned char*)malloc(state_count * 256);
|
||||
table.eq_class = (unsigned char*)malloc(state_count * 256);
|
||||
table.eq_class_rep = (unsigned char*)malloc(state_count * 256);
|
||||
table.state_count = state_count;
|
||||
memset(table.marks, 0, 256);
|
||||
|
||||
int i = 0;
|
||||
Lex_FSM fsm = {0};
|
||||
Lex_FSM new_fsm;
|
||||
for (unsigned short c = 0; c < 256; ++c){
|
||||
if (table.marks[c] == 0){
|
||||
table.eq_class[c] = table.eq_class_counter;
|
||||
table.eq_class_rep[table.eq_class_counter] = (unsigned char)c;
|
||||
unsigned char *c2_line = c_line + state_count;
|
||||
for (unsigned short c2 = c + 1; c2 < 256; ++c2){
|
||||
if (memcmp(c_line, c2_line, state_count) == 0){
|
||||
table.marks[c2] = 1;
|
||||
table.eq_class[c2] = table.eq_class_counter;
|
||||
for (unsigned char state = 0; state < state_count; ++state){
|
||||
fsm.int_state = state;
|
||||
fsm.emit_token = 0;
|
||||
new_fsm = int_fsm(fsm, (unsigned char)c);
|
||||
table.full_transition_table[i++] = new_fsm.int_state + state_count*new_fsm.emit_token;
|
||||
}
|
||||
c2_line += state_count;
|
||||
}
|
||||
++table.eq_class_counter;
|
||||
}
|
||||
c_line += state_count;
|
||||
}
|
||||
|
||||
table.reduced_transition_table = (unsigned char*)malloc(state_count * table.eq_class_counter);
|
||||
i = 0;
|
||||
for (unsigned short eq = 0; eq < table.eq_class_counter; ++eq){
|
||||
for (unsigned char state = 0; state < state_count; ++state){
|
||||
wfsm.pp_state = state;
|
||||
wfsm.white_done = 0;
|
||||
new_wfsm = whitespace_skip_fsm(wfsm, table.eq_class_rep[eq]);
|
||||
table.reduced_transition_table[i++] = new_wfsm.pp_state + state_count*new_wfsm.white_done;
|
||||
}
|
||||
}
|
||||
do_table_reduction(&table, state_count);
|
||||
|
||||
return(table);
|
||||
}
|
||||
|
@ -607,35 +641,7 @@ generate_fsm_table(unsigned char pp_state){
|
|||
}
|
||||
}
|
||||
|
||||
table.eq_class_counter = 0;
|
||||
unsigned char *c_line = table.full_transition_table;
|
||||
for (unsigned short c = 0; c < 256; ++c){
|
||||
if (table.marks[c] == 0){
|
||||
table.eq_class[c] = table.eq_class_counter;
|
||||
table.eq_class_rep[table.eq_class_counter] = (unsigned char)c;
|
||||
unsigned char *c2_line = c_line + state_count;
|
||||
for (unsigned short c2 = c + 1; c2 < 256; ++c2){
|
||||
if (memcmp(c_line, c2_line, state_count) == 0){
|
||||
table.marks[c2] = 1;
|
||||
table.eq_class[c2] = table.eq_class_counter;
|
||||
}
|
||||
c2_line += state_count;
|
||||
}
|
||||
++table.eq_class_counter;
|
||||
}
|
||||
c_line += state_count;
|
||||
}
|
||||
|
||||
table.reduced_transition_table = (unsigned char*)malloc(state_count * table.eq_class_counter);
|
||||
i = 0;
|
||||
for (unsigned short eq = 0; eq < table.eq_class_counter; ++eq){
|
||||
for (unsigned char state = 0; state < state_count; ++state){
|
||||
fsm.state = state;
|
||||
fsm.emit_token = 0;
|
||||
new_fsm = main_fsm(fsm, pp_state, table.eq_class_rep[eq]);
|
||||
table.reduced_transition_table[i++] = new_fsm.state + state_count*new_fsm.emit_token;
|
||||
}
|
||||
}
|
||||
do_table_reduction(&table, state_count);
|
||||
|
||||
return(table);
|
||||
}
|
||||
|
@ -686,6 +692,9 @@ int main(){
|
|||
FSM_Tables wtables = generate_whitespace_skip_table();
|
||||
render_fsm_table(file, wtables, "whitespace_fsm");
|
||||
|
||||
FSM_Tables itables = generate_int_table();
|
||||
render_fsm_table(file, itables, "int_fsm");
|
||||
|
||||
begin_table(file, "char", "multiline_state_table");
|
||||
for (unsigned char state = 0; state < LS_count; ++state){
|
||||
do_table_item(file, (state == LS_string_multiline || state == LS_char_multiline));
|
||||
|
|
Loading…
Reference in New Issue