now running cpp lexer types through meta compiler

master
Allen Webster 2016-09-04 13:09:13 -04:00
parent a132a697b1
commit 82e836e381
11 changed files with 126 additions and 306 deletions

File diff suppressed because one or more lines are too long

View File

@ -1916,7 +1916,7 @@ CUSTOM_COMMAND_SIG(query_replace){
int32_t pos, new_pos;
bar.prompt = make_lit_string("Replace? (y)es, (n)ext, (esc)\n");
bar.string = string_zero();
bar.string = null_string;
app->start_query_bar(app, &bar, 0);

View File

@ -4,12 +4,14 @@
#ifndef FCPP_LEXER_TYPES_INC
#define FCPP_LEXER_TYPES_INC
#if 0
#ifndef ENUM
#define ENUM(type,name) typedef type name; enum name##_
#endif
/* DOC(A Cpp_Token_Type classifies a token to make parsing easier. Some types are not
actually output by the lexer, but exist because parsers will also make use of token
types in their own output.) */
ENUM(int32_t, Cpp_Token_Type){
ENUM(uint32_t, Cpp_Token_Type){
CPP_TOKEN_JUNK,
CPP_TOKEN_COMMENT,
@ -222,177 +224,6 @@ ENUM(int32_t, Cpp_Token_Type){
CPP_TOKEN_TYPE_COUNT
};
#endif
#if 1
enum Cpp_Token_Type{
CPP_TOKEN_JUNK,
CPP_TOKEN_COMMENT,
CPP_PP_INCLUDE,
CPP_PP_DEFINE,
CPP_PP_UNDEF,
CPP_PP_IF,
CPP_PP_IFDEF,
CPP_PP_IFNDEF,
CPP_PP_ELSE,
CPP_PP_ELIF,
CPP_PP_ENDIF,
CPP_PP_ERROR,
CPP_PP_IMPORT,
CPP_PP_USING,
CPP_PP_LINE,
CPP_PP_PRAGMA,
CPP_PP_STRINGIFY,
CPP_PP_CONCAT,
CPP_PP_UNKNOWN,
CPP_TOKEN_KEY_TYPE,
CPP_TOKEN_KEY_MODIFIER,
CPP_TOKEN_KEY_QUALIFIER,
CPP_TOKEN_KEY_OPERATOR, // NOTE(allen): This type is not actually stored in tokens
CPP_TOKEN_KEY_CONTROL_FLOW,
CPP_TOKEN_KEY_CAST,
CPP_TOKEN_KEY_TYPE_DECLARATION,
CPP_TOKEN_KEY_ACCESS,
CPP_TOKEN_KEY_LINKAGE,
CPP_TOKEN_KEY_OTHER,
CPP_TOKEN_IDENTIFIER,
CPP_TOKEN_INTEGER_CONSTANT,
CPP_TOKEN_CHARACTER_CONSTANT,
CPP_TOKEN_FLOATING_CONSTANT,
CPP_TOKEN_STRING_CONSTANT,
CPP_TOKEN_BOOLEAN_CONSTANT,
CPP_TOKEN_STATIC_ASSERT,
CPP_TOKEN_BRACKET_OPEN,
CPP_TOKEN_BRACKET_CLOSE,
CPP_TOKEN_PARENTHESE_OPEN,
CPP_TOKEN_PARENTHESE_CLOSE,
CPP_TOKEN_BRACE_OPEN,
CPP_TOKEN_BRACE_CLOSE,
CPP_TOKEN_SEMICOLON,
CPP_TOKEN_ELLIPSIS,
// NOTE(allen): Ambiguous tokens, lexer only,
// parser figures out the real meaning
CPP_TOKEN_STAR,
CPP_TOKEN_AMPERSAND,
CPP_TOKEN_TILDE,
CPP_TOKEN_PLUS,
CPP_TOKEN_MINUS,
CPP_TOKEN_INCREMENT,
CPP_TOKEN_DECREMENT,
// NOTE(allen): Precedence 1, LtoR
CPP_TOKEN_SCOPE,
// NOTE(allen): Precedence 2, LtoR
CPP_TOKEN_POSTINC, // from increment, parser only
CPP_TOKEN_POSTDEC, // from decrement, parser only
CPP_TOKEN_FUNC_STYLE_CAST, // parser only
CPP_TOKEN_CPP_STYLE_CAST,
CPP_TOKEN_CALL, // from open paren, parser only
CPP_TOKEN_INDEX, // from bracket open, parser only
CPP_TOKEN_DOT,
CPP_TOKEN_ARROW,
// NOTE(allen): Precedence 3, RtoL
CPP_TOKEN_PREINC, // from increment, parser only
CPP_TOKEN_PREDEC, // from decrement, parser only
CPP_TOKEN_POSITIVE, // from plus, parser only
CPP_TOKEN_NEGAITVE, // from minus, parser only
CPP_TOKEN_NOT,
CPP_TOKEN_BIT_NOT, // from tilde, direct from 'compl'
CPP_TOKEN_CAST, // from open paren, parser only
CPP_TOKEN_DEREF, // from star, parser only
CPP_TOKEN_TYPE_PTR, // from star, parser only
CPP_TOKEN_ADDRESS, // from ampersand, parser only
CPP_TOKEN_TYPE_REF, // from ampersand, parser only
CPP_TOKEN_SIZEOF,
CPP_TOKEN_ALIGNOF,
CPP_TOKEN_DECLTYPE,
CPP_TOKEN_TYPEID,
CPP_TOKEN_NEW,
CPP_TOKEN_DELETE,
CPP_TOKEN_NEW_ARRAY, // from new and bracket open, parser only
CPP_TOKEN_DELETE_ARRAY, // from delete and bracket open, parser only
// NOTE(allen): Precedence 4, LtoR
CPP_TOKEN_PTRDOT,
CPP_TOKEN_PTRARROW,
// NOTE(allen): Precedence 5, LtoR
CPP_TOKEN_MUL, // from start, parser only
CPP_TOKEN_DIV,
CPP_TOKEN_MOD,
// NOTE(allen): Precedence 6, LtoR
CPP_TOKEN_ADD, // from plus, parser only
CPP_TOKEN_SUB, // from minus, parser only
// NOTE(allen): Precedence 7, LtoR
CPP_TOKEN_LSHIFT,
CPP_TOKEN_RSHIFT,
// NOTE(allen): Precedence 8, LtoR
CPP_TOKEN_LESS,
CPP_TOKEN_GRTR,
CPP_TOKEN_GRTREQ,
CPP_TOKEN_LESSEQ,
// NOTE(allen): Precedence 9, LtoR
CPP_TOKEN_EQEQ,
CPP_TOKEN_NOTEQ,
// NOTE(allen): Precedence 10, LtoR
CPP_TOKEN_BIT_AND, // from ampersand, direct from 'bitand'
// NOTE(allen): Precedence 11, LtoR
CPP_TOKEN_BIT_XOR,
// NOTE(allen): Precedence 12, LtoR
CPP_TOKEN_BIT_OR,
// NOTE(allen): Precedence 13, LtoR
CPP_TOKEN_AND,
// NOTE(allen): Precedence 14, LtoR
CPP_TOKEN_OR,
// NOTE(allen): Precedence 15, RtoL
CPP_TOKEN_TERNARY_QMARK,
CPP_TOKEN_COLON,
CPP_TOKEN_THROW,
CPP_TOKEN_EQ,
CPP_TOKEN_ADDEQ,
CPP_TOKEN_SUBEQ,
CPP_TOKEN_MULEQ,
CPP_TOKEN_DIVEQ,
CPP_TOKEN_MODEQ,
CPP_TOKEN_LSHIFTEQ,
CPP_TOKEN_RSHIFTEQ,
CPP_TOKEN_ANDEQ,
CPP_TOKEN_OREQ,
CPP_TOKEN_XOREQ,
// NOTE(allen): Precedence 16, LtoR
CPP_TOKEN_COMMA,
CPP_TOKEN_DEFINED,
CPP_TOKEN_INCLUDE_FILE,
CPP_TOKEN_ERROR_MESSAGE,
// NOTE(allen): used in the parser
CPP_TOKEN_EOF,
CPP_TOKEN_TYPE_COUNT
};
#endif
struct Cpp_Token{
Cpp_Token_Type type;
int32_t start, size;
@ -400,18 +231,18 @@ struct Cpp_Token{
uint16_t flags;
};
enum Cpp_Token_Flag{
CPP_TFLAG_IGNORE = 1 << 0,
CPP_TFLAG_PP_DIRECTIVE = 1 << 1,
CPP_TFLAG_PP_BODY = 1 << 2,
CPP_TFLAG_BAD_ENDING = 1 << 3,
CPP_TFLAG_MULTILINE = 1 << 4,
CPP_TFLAG_PARAMETERIZED = 1 << 5,
CPP_TFLAG_IS_OPERATOR = 1 << 6,
CPP_TFLAG_IS_KEYWORD = 1 << 7
ENUM(uint16_t, Cpp_Token_Flag){
CPP_TFLAG_IGNORE = 0x1,
CPP_TFLAG_PP_DIRECTIVE = 0x2,
CPP_TFLAG_PP_BODY = 0x4,
CPP_TFLAG_BAD_ENDING = 0x8,
CPP_TFLAG_MULTILINE = 0x10,
CPP_TFLAG_PARAMETERIZED = 0x20,
CPP_TFLAG_IS_OPERATOR = 0x40,
CPP_TFLAG_IS_KEYWORD = 0x80
};
enum Cpp_Preprocessor_State{
ENUM(uint16_t, Cpp_Preprocessor_State){
CPP_LEX_PP_DEFAULT,
CPP_LEX_PP_IDENTIFIER,
CPP_LEX_PP_MACRO_IDENTIFIER,
@ -421,7 +252,6 @@ enum Cpp_Preprocessor_State{
CPP_LEX_PP_NUMBER,
CPP_LEX_PP_ERROR,
CPP_LEX_PP_JUNK,
// NEVER ADD BELOW THIS
CPP_LEX_PP_COUNT
};
@ -429,23 +259,7 @@ struct Cpp_Token_Stack{
Cpp_Token *tokens;
int32_t count, max_count;
};
inline Cpp_Token_Stack
cpp_token_stack_zero(){
Cpp_Token_Stack stack={0};
return(stack);
}
#if 0
struct Cpp_Token_Merge{
Cpp_Token new_token;
int32_t did_merge;
};
#endif
struct Seek_Result{
int32_t pos;
int32_t new_line;
};
static Cpp_Token_Stack null_cpp_token_stack = {0};
struct Cpp_Get_Token_Result{
int32_t token_index;

View File

@ -57,7 +57,6 @@ FSTRING_INLINE fstr_bool char_is_alpha(char c);
FSTRING_INLINE fstr_bool char_is_alpha_true(char c);
FSTRING_INLINE fstr_bool char_is_hex(char c);
FSTRING_INLINE fstr_bool char_is_numeric(char c);
FSTRING_INLINE String string_zero(void);
FSTRING_INLINE String make_string_cap(void *str, int32_t size, int32_t mem_size);
FSTRING_INLINE String make_string(void *str, int32_t size);
#ifndef make_lit_string
@ -246,6 +245,10 @@ FSTRING_INLINE fstr_bool string_set_match(void *str_set, int32_t item_size, in
#endif
#if !defined(FSTRING_GUARD)
static String null_string = {0};
#endif
//
// Character Helpers
//
@ -335,15 +338,6 @@ char_is_numeric(char c)
// String Making Functions
//
#if !defined(FSTRING_GUARD)
FSTRING_INLINE String
string_zero(void)
{
String str={0};
return(str);
}
#endif
#if !defined(FSTRING_GUARD)
FSTRING_INLINE String

View File

@ -1,6 +1,8 @@
#ifndef ENUM
#define ENUM(type,name) typedef type name; enum name##_
#endif
/* DOC(bool32 is an alias name to signal that an integer parameter or field is for
true/false vales.) */

View File

@ -12,7 +12,7 @@
# define FCPP_LINK static
#endif
#include "4cpp_lexer_types.h"
#include "4coder_lexer_types.h"
#include "4cpp_lexer_fsms.h"
#include "4cpp_lexer_tables.c"

View File

@ -1225,7 +1225,7 @@ file_kill_tokens(System_Functions *system,
general_memory_free(general, file->state.token_stack.tokens);
}
file->state.tokens_complete = 0;
file->state.token_stack = cpp_token_stack_zero();
file->state.token_stack = null_cpp_token_stack;
}
#if BUFFER_EXPERIMENT_SCALPEL <= 0
@ -3153,7 +3153,7 @@ internal void
init_read_only_file(System_Functions *system, Models *models, Editing_File *file){
General_Memory *general = &models->mem.general;
String val = string_zero();
String val = null_string;
file_create_from_string(system, models, file, val, 1);
if (file->settings.tokens_exist && file->state.token_stack.tokens == 0){
@ -3671,7 +3671,7 @@ get_exhaustive_info(System_Functions *system, Working_Set *working_set, Exhausti
result.name_match = (filename_match(loop->front_name, &loop->absolutes, filename, 0) != 0);
result.is_loaded = (file != 0 && file_is_ready(file));
result.message = string_zero();
result.message = null_string;
if (result.is_loaded){
switch (file_get_sync(file)){
case SYNC_GOOD: result.message = message_loaded; break;
@ -3869,7 +3869,7 @@ show_gui_line(GUI_Target *target, String *string,
append_s_char(string, ' ');
append_sc(string, follow_up);
}
gui_do_text_field(target, *string, string_zero());
gui_do_text_field(target, *string, null_string);
}
internal void
@ -3880,7 +3880,7 @@ show_gui_int(GUI_Target *target, String *string,
append_padding(string, '-', h_align);
append_s_char(string, ' ');
append_int_to_str(string, x);
gui_do_text_field(target, *string, string_zero());
gui_do_text_field(target, *string, null_string);
}
internal void
@ -3891,7 +3891,7 @@ show_gui_u64(GUI_Target *target, String *string,
append_padding(string, '-', h_align);
append_s_char(string, ' ');
append_u64_to_str(string, x);
gui_do_text_field(target, *string, string_zero());
gui_do_text_field(target, *string, null_string);
}
internal void
@ -3904,7 +3904,7 @@ show_gui_int_int(GUI_Target *target, String *string,
append_int_to_str(string, x);
append_s_char(string, '/');
append_int_to_str(string, m);
gui_do_text_field(target, *string, string_zero());
gui_do_text_field(target, *string, null_string);
}
internal void
@ -3918,7 +3918,7 @@ show_gui_id(GUI_Target *target, String *string,
append_padding(string, ' ', h_align + 26);
append_ss(string, make_lit_string(" [1]: "));
append_u64_to_str(string, id.id[1]);
gui_do_text_field(target, *string, string_zero());
gui_do_text_field(target, *string, null_string);
}
internal void
@ -3929,7 +3929,7 @@ show_gui_float(GUI_Target *target, String *string,
append_padding(string, '-', h_align);
append_s_char(string, ' ');
append_float_to_str(string, x);
gui_do_text_field(target, *string, string_zero());
gui_do_text_field(target, *string, null_string);
}
internal void
@ -3985,7 +3985,7 @@ gui_show_mouse(GUI_Target *target, String *string, i32 mx, i32 my){
append_int_to_str(string, my);
append_s_char(string, ')');
gui_do_text_field(target, *string, string_zero());
gui_do_text_field(target, *string, null_string);
}
internal View_Step_Result
@ -4491,7 +4491,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
reserved_files[reserved_top++] = file;
}
else{
message = string_zero();
message = null_string;
if (!file->settings.unimportant){
switch (file_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break;
@ -4512,7 +4512,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
for (i = 0; i < reserved_top; ++i){
Editing_File *file = reserved_files[i];
message = string_zero();
message = null_string;
if (!file->settings.unimportant){
switch (file_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break;
@ -4623,7 +4623,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
// - Command maps inspection
// - Clipboard inspection
String empty_str = string_zero();
String empty_str = null_string;
char space1[512];
String string = make_fixed_width_string(space1);

View File

@ -614,6 +614,9 @@ get_doc_string_from_prev(Parse_Context *context, String *doc_string){
if (check_and_fix_docs(doc_string)){
result = true;
}
else{
*doc_string = null_string;
}
}
}
@ -1654,7 +1657,7 @@ compile_meta_unit(Partition *part, char **files, int32_t file_count,
has_cpp_name = 0;
}
else{
cpp_name = string_zero();
cpp_name = null_string;
}
unit.parse[J].item_count = index;
@ -2225,7 +2228,8 @@ generate_custom_headers(){
// NOTE(allen): Parse the customization API types
static char *type_files[] = {
"4coder_types.h"
"4coder_types.h",
"4coder_lexer_types.h",
};
static Meta_Keywords type_keys[] = {

View File

@ -14,7 +14,7 @@
#define Assert(n) do{ if (!(n)) { *(int*)0 = 0xA11E; } }while(0)
#define ArrayCount(a) (sizeof(a)/sizeof(*a))
#include "4cpp_lexer_types.h"
#include "4coder_lexer_types.h"
#include "4cpp_lexer_fsms.h"
#include "4ed_mem_ansi.c"

View File

@ -53,6 +53,10 @@ typedef struct Offset_String{
FSTRING_DECLS
#if !defined(FSTRING_GUARD)
static String null_string = {0};
#endif
//
// Character Helpers
//
@ -122,13 +126,6 @@ char_is_numeric(char c)
// String Making Functions
//
FSTRING_INLINE String
string_zero(void)
/* DOC(This call returns a String struct of zeroed members.) */{
String str={0};
return(str);
}
CPP_NAME(make_string)
FSTRING_INLINE String
make_string_cap(void *str, int32_t size, int32_t mem_size)/*

View File

@ -2382,7 +2382,7 @@ WinMain(HINSTANCE hInstance,
input_chunk.pers.control_keys[MDFR_CAPS_INDEX] = GetKeyState(VK_CAPITAL) & 0x1;
win32vars.clipboard_contents = string_zero();
win32vars.clipboard_contents = null_string;
if (win32vars.clipboard_sequence != 0){
DWORD new_number = GetClipboardSequenceNumber();
if (new_number != win32vars.clipboard_sequence){