Skip to content

Commit

Permalink
Fixes from latest refactor of toktype enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed94 committed Jul 27, 2023
1 parent b00c1ae commit d977c82
Show file tree
Hide file tree
Showing 16 changed files with 360 additions and 325 deletions.
1 change: 1 addition & 0 deletions project/components/ECode.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Invalid
Untyped
Comment
Access_Private
Expand Down
1 change: 1 addition & 0 deletions project/components/EOperator.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Invalid, INVALID
Assign, "="
Assign_Add, "+="
Assign_Subtract, "-="
Expand Down
139 changes: 70 additions & 69 deletions project/components/ETokType.csv
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
Access_Private, "private"
Access_Protected, "protected"
Access_Public, "public"
Access_MemberSymbol, "."
Access_StaticSymbol, "::"
Ampersand, "&"
Ampersand_DBL, "&&"
Assign_Classifer, ":"
Attribute_Open, "[["
Attribute_Close, "]]"
BraceCurly_Open, "{"
BraceCurly_Close, "}"
BraceSquare_Open, "["
BraceSquare_Close, "]"
Capture_Start, "("
Capture_End, ")"
Comment, "__comment__"
Char, "__char__"
Comma, ","
Decl_Class, "class"
Decl_GNU_Attribute, "__attribute__"
Decl_MSVC_Attribute, "__declspec"
Decl_Enum, "enum"
Decl_Extern_Linkage, "extern"
Decl_Friend, "friend"
Decl_Module, "module"
Decl_Namespace, "namespace"
Decl_Operator, "operator"
Decl_Struct, "struct"
Decl_Template, "template"
Decl_Typedef, "typedef"
Decl_Using, "using"
Decl_Union, "union"
Identifier, "__identifier__"
Module_Import, "import"
Module_Export, "export"
Number, "number"
Operator, "operator"
Preprocessor_Directive, "#"
Preprocessor_Include, "include"
Spec_Alignas, "alignas"
Spec_Const, "const"
Spec_Consteval, "consteval"
Spec_Constexpr, "constexpr"
Spec_Constinit, "constinit"
Spec_Explicit, "explicit"
Spec_Extern, "extern"
Spec_Final, "final"
Spec_Global, "global"
Spec_Inline, "inline"
Spec_Internal_Linkage, "internal"
Spec_LocalPersist, "local_persist"
Spec_Mutable, "mutable"
Spec_Override, "override"
Spec_Static, "static"
Spec_ThreadLocal, "thread_local"
Spec_Volatile, "volatile"
Star, "*"
Statement_End, ";"
String, "__string__"
Type_Unsigned, "unsigned"
Type_Signed, "signed"
Type_Short, "short"
Type_Long, "long"
Type_char, "char"
Type_int, "int"
Type_double, "double"
Varadic_Argument, "..."
Attributes_Start, "__attrib_start__"
Invalid, "__invalid__"
Access_Private, "private"
Access_Protected, "protected"
Access_Public, "public"
Access_MemberSymbol, "."
Access_StaticSymbol, "::"
Ampersand, "&"
Ampersand_DBL, "&&"
Assign_Classifer, ":"
Attribute_Open, "[["
Attribute_Close, "]]"
BraceCurly_Open, "{"
BraceCurly_Close, "}"
BraceSquare_Open, "["
BraceSquare_Close, "]"
Capture_Start, "("
Capture_End, ")"
Comment, "__comment__"
Char, "__char__"
Comma, ","
Decl_Class, "class"
Decl_GNU_Attribute, "__attribute__"
Decl_MSVC_Attribute, "__declspec"
Decl_Enum, "enum"
Decl_Extern_Linkage, "extern"
Decl_Friend, "friend"
Decl_Module, "module"
Decl_Namespace, "namespace"
Decl_Operator, "operator"
Decl_Struct, "struct"
Decl_Template, "template"
Decl_Typedef, "typedef"
Decl_Using, "using"
Decl_Union, "union"
Identifier, "__identifier__"
Module_Import, "import"
Module_Export, "export"
Number, "number"
Operator, "operator"
Preprocessor_Directive, "#"
Preprocessor_Include, "include"
Spec_Alignas, "alignas"
Spec_Const, "const"
Spec_Consteval, "consteval"
Spec_Constexpr, "constexpr"
Spec_Constinit, "constinit"
Spec_Explicit, "explicit"
Spec_Extern, "extern"
Spec_Final, "final"
Spec_Global, "global"
Spec_Inline, "inline"
Spec_Internal_Linkage, "internal"
Spec_LocalPersist, "local_persist"
Spec_Mutable, "mutable"
Spec_Override, "override"
Spec_Static, "static"
Spec_ThreadLocal, "thread_local"
Spec_Volatile, "volatile"
Star, "*"
Statement_End, ";"
String, "__string__"
Type_Unsigned, "unsigned"
Type_Signed, "signed"
Type_Short, "short"
Type_Long, "long"
Type_char, "char"
Type_int, "int"
Type_double, "double"
Varadic_Argument, "..."
Attributes_Start, "__attrib_start__"
4 changes: 2 additions & 2 deletions project/components/gen.ecode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ECode
{
# define Define_Types \
Entry( Invalid ) \
Entry( Untyped ) \
Entry( Comment ) \
Entry( Access_Private ) \
Expand Down Expand Up @@ -56,8 +57,7 @@ namespace ECode
Define_Types
# undef Entry

Num_Types,
Invalid
Num_Types
};

inline
Expand Down
2 changes: 1 addition & 1 deletion project/components/gen.eoperator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace EOperator
{
# define Define_Operators \
Entry( Invalid, INVALID ) \
Entry( Assign, = ) \
Entry( Assign_Add, += ) \
Entry( Assign_Subtract, -= ) \
Expand Down Expand Up @@ -53,7 +54,6 @@ namespace EOperator
Comma,

Num_Ops,
Invalid
};

inline
Expand Down
11 changes: 6 additions & 5 deletions project/components/gen.especifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace ESpecifier
Define_Specifiers
# undef Entry

Num_Specifiers,
NumSpecifiers,
};

inline
Expand All @@ -52,7 +52,7 @@ namespace ESpecifier
StrC to_str( Type specifier )
{
local_persist
StrC lookup[ Num_Specifiers ] = {
StrC lookup[ NumSpecifiers ] = {
# pragma push_macro( "global" )
# pragma push_macro( "internal" )
# pragma push_macro( "local_persist" )
Expand All @@ -76,9 +76,9 @@ namespace ESpecifier
Type to_type( StrC str )
{
local_persist
u32 keymap[ Num_Specifiers ];
u32 keymap[ NumSpecifiers ];
do_once_start
for ( u32 index = 0; index < Num_Specifiers; index++ )
for ( u32 index = 0; index < NumSpecifiers; index++ )
{
StrC enum_str = to_str( (Type)index );

Expand All @@ -90,7 +90,7 @@ namespace ESpecifier

u32 hash = crc32( str.Ptr, str.Len );

for ( u32 index = 0; index < Num_Specifiers; index++ )
for ( u32 index = 0; index < NumSpecifiers; index++ )
{
if ( keymap[index] == hash )
return (Type)index;
Expand All @@ -101,4 +101,5 @@ namespace ESpecifier

# undef Define_Specifiers
}

using SpecifierT = ESpecifier::Type;
132 changes: 46 additions & 86 deletions project/components/gen.etoktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Parser
*/

# define Define_TokType \
Entry( Invalid, "INVALID" ) \
Entry( Access_Private, "private" ) \
Entry( Access_Protected, "protected" ) \
Entry( Access_Public, "public" ) \
Expand Down Expand Up @@ -80,102 +81,61 @@ namespace Parser
Entry( Varadic_Argument, "..." ) \
Entry( Attributes_Start, "__attrib_start__" )

enum class TokType : u32
namespace ETokType
{
# define Entry( Name_, Str_ ) Name_,
Define_TokType
GEN_Define_Attribute_Tokens
# undef Entry
Num,
Invalid
};

struct Token
{
char const* Text;
sptr Length;
TokType Type;
bool IsAssign;

operator bool()
enum Type : u32
{
return Text && Length && Type != TokType::Invalid;
}

operator StrC()
{
return { Length, Text };
}
};

internal inline
TokType get_tok_type( char const* word, s32 length )
{
local_persist
StrC lookup[(u32)TokType::Num] =
{
# define Entry( Name_, Str_ ) { sizeof(Str_), Str_ },
# define Entry( Name_, Str_ ) Name_,
Define_TokType
GEN_Define_Attribute_Tokens
# undef Entry
NumTokens,
};

for ( u32 index = 0; index < (u32)TokType::Num; index++ )
internal inline
Type to_type( StrC str_tok )
{
s32 lookup_len = lookup[index].Len - 1;
char const* lookup_str = lookup[index].Ptr;

if ( lookup_len != length )
continue;

if ( str_compare( word, lookup_str, lookup_len ) == 0 )
return scast(TokType, index);
local_persist
StrC lookup[(u32)NumTokens] =
{
# define Entry( Name_, Str_ ) { sizeof(Str_), Str_ },
Define_TokType
GEN_Define_Attribute_Tokens
# undef Entry
};

for ( u32 index = 0; index < (u32)NumTokens; index++ )
{
s32 lookup_len = lookup[index].Len - 1;
char const* lookup_str = lookup[index].Ptr;

if ( lookup_len != str_tok.Len )
continue;

if ( str_compare( str_tok.Ptr, lookup_str, lookup_len ) == 0 )
return scast(Type, index);
}

return Invalid;
}

return TokType::Invalid;
}

internal inline
char const* str_tok_type( TokType type )
{
local_persist
char const* lookup[(u32)TokType::Num] =
internal inline
char const* to_str( Type type )
{
# define Entry( Name_, Str_ ) Str_,
Define_TokType
GEN_Define_Attribute_Tokens
# undef Entry
};

return lookup[(u32)type];
}

# undef Define_TokType

internal inline
bool tok_is_specifier( Token const& tok )
{
return (tok.Type <= TokType::Star && tok.Type >= TokType::Spec_Alignas)
|| tok.Type == TokType::Ampersand
|| tok.Type == TokType::Ampersand_DBL
;
}

internal inline
bool tok_is_access_specifier( Token const& tok )
{
return tok.Type >= TokType::Access_Private && tok.Type <= TokType::Access_Public;
}
local_persist
char const* lookup[(u32)NumTokens] =
{
# define Entry( Name_, Str_ ) Str_,
Define_TokType
GEN_Define_Attribute_Tokens
# undef Entry
};

return lookup[(u32)type];
}
# undef Define_TokType
};

internal inline
AccessSpec tok_to_access_specifier( Token const& tok )
{
return scast(AccessSpec, tok.Type);
}
using TokType = ETokType::Type;

internal inline
bool tok_is_attribute( Token const& tok )
{
return tok.Type > TokType::Attributes_Start;
}
} // Parser
} // Parser
Loading

0 comments on commit d977c82

Please sign in to comment.