mirror of
https://github.com/Ed94/gencpp.git
synced 2025-07-01 11:21:04 -07:00
TokType compiles for c lbirary
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
GEN_NS_PARSER_BEGIN
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" )
|
||||
|
||||
enum TokType_Def : u32
|
||||
enum TokType : u32
|
||||
{
|
||||
Tok_Invalid,
|
||||
Tok_Access_Private,
|
||||
@ -109,9 +109,8 @@ enum TokType_Def : u32
|
||||
Tok_Attribute_API_Import,
|
||||
Tok_NumTokens
|
||||
};
|
||||
typedef enum TokType_Def TokType;
|
||||
|
||||
inline StrC to_str( TokType type )
|
||||
inline StrC toktype_to_str( TokType type )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
{ sizeof( "__invalid__" ), "__invalid__" },
|
||||
@ -215,12 +214,12 @@ inline StrC to_str( TokType type )
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline TokType to_toktype( StrC str )
|
||||
inline TokType strc_to_toktype( StrC str )
|
||||
{
|
||||
local_persist u32 keymap[Tok_NumTokens];
|
||||
do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (TokType)index );
|
||||
StrC enum_str = toktype_to_str( (TokType)index );
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
||||
|
@ -94,7 +94,7 @@ String to_string(Token tok)
|
||||
{
|
||||
String result = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
|
||||
StrC type_str = to_str( tok.Type );
|
||||
StrC type_str = toktype_to_str( tok.Type );
|
||||
|
||||
string_append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s"
|
||||
, tok.Line, tok.Column
|
||||
@ -249,7 +249,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
ctx->token.Length++;
|
||||
}
|
||||
|
||||
ctx->token.Type = to_toktype( to_str(ctx->token) );
|
||||
ctx->token.Type = strc_to_toktype( to_str(ctx->token) );
|
||||
|
||||
bool is_preprocessor = ctx->token.Type >= Tok_Preprocess_Define && ctx->token.Type <= Tok_Preprocess_Pragma;
|
||||
if ( ! is_preprocessor )
|
||||
@ -475,7 +475,7 @@ void lex_found_token( LexContext* ctx )
|
||||
return;
|
||||
}
|
||||
|
||||
TokType type = to_toktype( to_str(ctx->token) );
|
||||
TokType type = strc_to_toktype( to_str(ctx->token) );
|
||||
|
||||
if (type <= Tok_Access_Public && type >= Tok_Access_Private )
|
||||
{
|
||||
@ -1270,7 +1270,7 @@ TokArray lex( StrC content )
|
||||
{
|
||||
log_fmt( "Token %d Type: %s : %.*s\n"
|
||||
, idx
|
||||
, to_str( Tokens[ idx ].Type ).Ptr
|
||||
, toktype_to_str( Tokens[ idx ].Type ).Ptr
|
||||
, Tokens[ idx ].Length, Tokens[ idx ].Text
|
||||
);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ bool __eat(TokArray* self, TokType type )
|
||||
{
|
||||
Token tok = * current( self, skip_formatting );
|
||||
log_failure( "Parse Error, TokArray::eat, Expected: ' %s ' not ' %.*s ' (%d, %d)`\n%s"
|
||||
, to_str(type).Ptr
|
||||
, toktype_to_str(type).Ptr
|
||||
, at_idx.Length, at_idx.Text
|
||||
, tok.Line
|
||||
, tok.Column
|
||||
@ -546,7 +546,7 @@ Code parse_array_decl()
|
||||
|
||||
if ( currtok.Type != Tok_BraceSquare_Close )
|
||||
{
|
||||
log_failure( "%s: Error, expected ] in array declaration, not %s\n%s", to_str( currtok.Type ), to_string(Context) );
|
||||
log_failure( "%s: Error, expected ] in array declaration, not %s\n%s", toktype_to_str( currtok.Type ), to_string(Context) );
|
||||
pop(& Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
@ -687,7 +687,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
|
||||
{
|
||||
if ( which != Tok_Decl_Class && which != Tok_Decl_Struct )
|
||||
{
|
||||
log_failure( "Error, expected class or struct, not %s\n%s", to_str( which ), to_string(Context) );
|
||||
log_failure( "Error, expected class or struct, not %s\n%s", toktype_to_str( which ), to_string(Context) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
@ -1206,7 +1206,7 @@ Code parse_complicated_definition( TokType which )
|
||||
return result;
|
||||
}
|
||||
|
||||
log_failure( "Unsupported or bad member definition after %s declaration\n%s", to_str(which), to_string(Context) );
|
||||
log_failure( "Unsupported or bad member definition after %s declaration\n%s", toktype_to_str(which), to_string(Context) );
|
||||
pop(& Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
@ -1251,7 +1251,7 @@ Code parse_complicated_definition( TokType which )
|
||||
|
||||
if ( ! ok_to_parse )
|
||||
{
|
||||
log_failure( "Unsupported or bad member definition after %s declaration\n%s", to_str(which), to_string(Context) );
|
||||
log_failure( "Unsupported or bad member definition after %s declaration\n%s", toktype_to_str(which), to_string(Context) );
|
||||
pop(& Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
@ -1270,7 +1270,7 @@ Code parse_complicated_definition( TokType which )
|
||||
&& ( tokens.Arr[idx - 4].Type != which))
|
||||
)
|
||||
{
|
||||
log_failure( "Unsupported or bad member definition after %s declaration\n%s", to_str(which), to_string(Context) );
|
||||
log_failure( "Unsupported or bad member definition after %s declaration\n%s", toktype_to_str(which), to_string(Context) );
|
||||
pop(& Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
@ -1300,7 +1300,7 @@ Code parse_complicated_definition( TokType which )
|
||||
}
|
||||
else
|
||||
{
|
||||
log_failure( "Unsupported or bad member definition after %s declaration\n%S", to_str(which).Ptr, to_string(Context) );
|
||||
log_failure( "Unsupported or bad member definition after %s declaration\n%S", toktype_to_str(which).Ptr, to_string(Context) );
|
||||
pop(& Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
@ -2075,7 +2075,7 @@ Token parse_identifier( bool* possible_member_function )
|
||||
return name;
|
||||
}
|
||||
|
||||
log_failure( "Error, had a ~ operator after %S but not a destructor\n%s", to_str( prevtok.Type ), to_string(Context) );
|
||||
log_failure( "Error, had a ~ operator after %S but not a destructor\n%s", toktype_to_str( prevtok.Type ), to_string(Context) );
|
||||
pop(& Context);
|
||||
return { nullptr, 0, Tok_Invalid };
|
||||
}
|
||||
@ -2095,7 +2095,7 @@ Token parse_identifier( bool* possible_member_function )
|
||||
|
||||
if ( currtok.Type != Tok_Identifier )
|
||||
{
|
||||
log_failure( "Error, expected static symbol identifier, not %s\n%s", to_str( currtok.Type ), to_string(Context) );
|
||||
log_failure( "Error, expected static symbol identifier, not %s\n%s", toktype_to_str( currtok.Type ), to_string(Context) );
|
||||
pop(& Context);
|
||||
return { nullptr, 0, Tok_Invalid };
|
||||
}
|
||||
|
Reference in New Issue
Block a user