Fixes from latest refactor of toktype enum.

This commit is contained in:
Edward R. Gonzalez 2023-07-27 17:12:58 -04:00
parent b00c1ae522
commit d977c82f37
16 changed files with 357 additions and 322 deletions

View File

@ -1,3 +1,4 @@
Invalid
Untyped
Comment
Access_Private

1 Untyped Invalid
1 Invalid
2 Untyped Untyped
3 Comment Comment
4 Access_Private Access_Private

View File

@ -1,3 +1,4 @@
Invalid, INVALID
Assign, "="
Assign_Add, "+="
Assign_Subtract, "-="

1 Assign Invalid = INVALID
1 Invalid INVALID
2 Assign Assign = =
3 Assign_Add Assign_Add += +=
4 Assign_Subtract Assign_Subtract -= -=

View File

@ -1,3 +1,4 @@
Invalid, "__invalid__"
Access_Private, "private"
Access_Protected, "protected"
Access_Public, "public"

1 Access_Private Invalid private __invalid__
1 Invalid __invalid__
2 Access_Private Access_Private private private
3 Access_Protected Access_Protected protected protected
4 Access_Public Access_Public public public

View File

@ -3,6 +3,7 @@
namespace ECode
{
# define Define_Types \
Entry( Invalid ) \
Entry( Untyped ) \
Entry( Comment ) \
Entry( Access_Private ) \
@ -56,8 +57,7 @@ namespace ECode
Define_Types
# undef Entry
Num_Types,
Invalid
Num_Types
};
inline

View File

@ -3,6 +3,7 @@
namespace EOperator
{
# define Define_Operators \
Entry( Invalid, INVALID ) \
Entry( Assign, = ) \
Entry( Assign_Add, += ) \
Entry( Assign_Subtract, -= ) \
@ -53,7 +54,6 @@ namespace EOperator
Comma,
Num_Ops,
Invalid
};
inline

View File

@ -38,7 +38,7 @@ namespace ESpecifier
Define_Specifiers
# undef Entry
Num_Specifiers,
NumSpecifiers,
};
inline
@ -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" )
@ -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 );
@ -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;
@ -101,4 +101,5 @@ namespace ESpecifier
# undef Define_Specifiers
}
using SpecifierT = ESpecifier::Type;

View File

@ -10,6 +10,7 @@ namespace Parser
*/
# define Define_TokType \
Entry( Invalid, "INVALID" ) \
Entry( Access_Private, "private" ) \
Entry( Access_Protected, "protected" ) \
Entry( Access_Public, "public" ) \
@ -80,39 +81,22 @@ namespace Parser
Entry( Varadic_Argument, "..." ) \
Entry( Attributes_Start, "__attrib_start__" )
enum class TokType : u32
namespace ETokType
{
enum Type : u32
{
# 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()
{
return Text && Length && Type != TokType::Invalid;
}
operator StrC()
{
return { Length, Text };
}
NumTokens,
};
internal inline
TokType get_tok_type( char const* word, s32 length )
Type to_type( StrC str_tok )
{
local_persist
StrC lookup[(u32)TokType::Num] =
StrC lookup[(u32)NumTokens] =
{
# define Entry( Name_, Str_ ) { sizeof(Str_), Str_ },
Define_TokType
@ -120,26 +104,26 @@ namespace Parser
# undef Entry
};
for ( u32 index = 0; index < (u32)TokType::Num; index++ )
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 != length )
if ( lookup_len != str_tok.Len )
continue;
if ( str_compare( word, lookup_str, lookup_len ) == 0 )
return scast(TokType, index);
if ( str_compare( str_tok.Ptr, lookup_str, lookup_len ) == 0 )
return scast(Type, index);
}
return TokType::Invalid;
return Invalid;
}
internal inline
char const* str_tok_type( TokType type )
char const* to_str( Type type )
{
local_persist
char const* lookup[(u32)TokType::Num] =
char const* lookup[(u32)NumTokens] =
{
# define Entry( Name_, Str_ ) Str_,
Define_TokType
@ -149,33 +133,9 @@ namespace Parser
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
;
}
using TokType = ETokType::Type;
internal inline
bool tok_is_access_specifier( Token const& tok )
{
return tok.Type >= TokType::Access_Private && tok.Type <= TokType::Access_Public;
}
internal inline
AccessSpec tok_to_access_specifier( Token const& tok )
{
return scast(AccessSpec, tok.Type);
}
internal inline
bool tok_is_attribute( Token const& tok )
{
return tok.Type > TokType::Attributes_Start;
}
} // Parser

View File

@ -4,6 +4,52 @@ These constructors are the most implementation intensive other than the editor o
namespace Parser
{
struct Token
{
char const* Text;
sptr Length;
TokType Type;
bool IsAssign;
operator bool()
{
return Text && Length && Type != TokType::Invalid;
}
operator StrC()
{
return { Length, Text };
}
};
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;
}
internal inline
AccessSpec tok_to_access_specifier( Token const& tok )
{
return scast(AccessSpec, tok.Type);
}
internal inline
bool tok_is_attribute( Token const& tok )
{
return tok.Type > TokType::Attributes_Start;
}
struct TokArray
{
Array<Token> Arr;
@ -14,16 +60,16 @@ namespace Parser
if ( Arr.num() - Idx <= 0 )
{
log_failure( "gen::%s: No tokens left", context );
return Code::Invalid;
return false;
}
if ( Arr[Idx].Type != type )
{
String token_str = String::make( GlobalAllocator, { Arr[Idx].Length, Arr[Idx].Text } );
log_failure( "gen::%s: expected %s, got %s", context, str_tok_type(type), str_tok_type(Arr[Idx].Type) );
log_failure( "gen::%s: expected %s, got %s", context, ETokType::to_str(type), ETokType::to_str(Arr[Idx].Type) );
return Code::Invalid;
return false;
}
Idx++;
@ -538,7 +584,7 @@ namespace Parser
continue;
}
TokType type = get_tok_type( token.Text, token.Length );
TokType type = ETokType::to_type( token );
if ( type == TokType::Invalid)
type = TokType::Identifier;
@ -649,7 +695,7 @@ Code parse_array_decl( Parser::TokArray& toks, char const* context )
if ( currtok.Type != TokType::BraceSquare_Close )
{
log_failure( "%s: Error, expected ] in type definition, not %s", stringize(parse_typedef), str_tok_type( currtok.Type ) );
log_failure( "%s: Error, expected ] in type definition, not %s", stringize(parse_typedef), ETokType::to_str( currtok.Type ) );
return Code::Invalid;
}
@ -748,7 +794,7 @@ Parser::Token parse_identifier( Parser::TokArray& toks, char const* context )
if ( currtok.Type != TokType::Identifier )
{
log_failure( "%s: Error, expected identifier in type definition, not %s", context, str_tok_type( currtok.Type ) );
log_failure( "%s: Error, expected identifier in type definition, not %s", context, ETokType::to_str( currtok.Type ) );
return { nullptr, 0, TokType::Invalid };
}
@ -909,7 +955,7 @@ CodeParam parse_params( Parser::TokArray& toks, char const* context, bool use_te
{
if ( ! check( TokType::Operator) || currtok.Text[0] != '>' )
{
log_failure("gen::parse_params: expected '<' after 'template' keyword. %s", str_tok_type( currtok.Type ));
log_failure("gen::parse_params: expected '<' after 'template' keyword. %s", ETokType::to_str( currtok.Type ));
return CodeInvalid;
}
eat( TokType::Operator );
@ -1473,8 +1519,8 @@ CodeBody parse_class_struct_body( Parser::TokType which, Parser::TokArray& toks,
case TokType::Spec_Static:
case TokType::Spec_Volatile:
{
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
s32 num_specifiers = 0;
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
while ( left && tok_is_specifier( currtok ) )
{
@ -1499,14 +1545,14 @@ CodeBody parse_class_struct_body( Parser::TokType which, Parser::TokArray& toks,
return CodeInvalid;
}
specs_found[num_specifiers] = spec;
num_specifiers++;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( num_specifiers )
if ( NumSpecifiers )
{
specifiers = def_specifiers( num_specifiers, specs_found );
specifiers = def_specifiers( NumSpecifiers, specs_found );
}
}
//! Fallthrough intentional
@ -1557,7 +1603,7 @@ Code parse_class_struct( Parser::TokType which, Parser::TokArray& toks, char con
if ( which != TokType::Decl_Class && which != TokType::Decl_Struct )
{
log_failure( "%s: Error, expected class or struct, not %s", context, str_tok_type( which ) );
log_failure( "%s: Error, expected class or struct, not %s", context, ETokType::to_str( which ) );
return CodeInvalid;
}
@ -1777,8 +1823,8 @@ CodeBody parse_global_nspace( CodeT which, Parser::TokArray& toks, char const* c
case TokType::Spec_Internal_Linkage:
case TokType::Spec_Static:
{
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
s32 num_specifiers = 0;
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
while ( left && tok_is_specifier( currtok ) )
{
@ -1803,14 +1849,14 @@ CodeBody parse_global_nspace( CodeT which, Parser::TokArray& toks, char const* c
return CodeInvalid;
}
specs_found[num_specifiers] = spec;
num_specifiers++;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( num_specifiers )
if ( NumSpecifiers )
{
specifiers = def_specifiers( num_specifiers, specs_found );
specifiers = def_specifiers( NumSpecifiers, specs_found );
}
}
//! Fallthrough intentional
@ -1867,8 +1913,8 @@ CodeEnum parse_enum( Parser::TokArray& toks, char const* context )
using namespace Parser;
using namespace ECode;
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
s32 num_specifiers = 0;
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
Token name = { nullptr, 0, TokType::Invalid };
Code array_expr = { nullptr };
@ -2111,8 +2157,8 @@ CodeFn parse_functon( Parser::TokArray& toks, char const* context )
{
using namespace Parser;
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
s32 num_specifiers = 0;
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
CodeAttributes attributes = { nullptr };
CodeSpecifiers specifiers = { nullptr };
@ -2148,14 +2194,14 @@ CodeFn parse_functon( Parser::TokArray& toks, char const* context )
if ( spec == ESpecifier::Const )
continue;
specs_found[num_specifiers] = spec;
num_specifiers++;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( num_specifiers )
if ( NumSpecifiers )
{
specifiers = def_specifiers( num_specifiers, specs_found );
specifiers = def_specifiers( NumSpecifiers, specs_found );
}
CodeType ret_type = parse_type( toks, stringize(parse_function) );
@ -2239,8 +2285,8 @@ CodeOperator parse_operator( Parser::TokArray& toks, char const* context )
CodeSpecifiers specifiers = { nullptr };
ModuleFlag mflags = ModuleFlag::None;
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
s32 num_specifiers = 0;
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
if ( check(TokType::Module_Export) )
{
@ -2270,14 +2316,14 @@ CodeOperator parse_operator( Parser::TokArray& toks, char const* context )
if ( spec == ESpecifier::Const )
continue;
specs_found[num_specifiers] = spec;
num_specifiers++;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( num_specifiers )
if ( NumSpecifiers )
{
specifiers = def_specifiers( num_specifiers, specs_found );
specifiers = def_specifiers( NumSpecifiers, specs_found );
}
// Parse Return Type
@ -2443,8 +2489,8 @@ CodeTemplate parse_template( Parser::TokArray& toks, char const* context )
bool expects_function = false;
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
s32 num_specifiers = 0;
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
attributes = parse_attributes( toks, stringize(parse_template) );
@ -2480,14 +2526,14 @@ CodeTemplate parse_template( Parser::TokArray& toks, char const* context )
if ( spec == ESpecifier::Const )
continue;
specs_found[num_specifiers] = spec;
num_specifiers++;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( num_specifiers )
if ( NumSpecifiers )
{
specifiers = def_specifiers( num_specifiers, specs_found );
specifiers = def_specifiers( NumSpecifiers, specs_found );
}
definition = parse_operator_function_or_variable( expects_function, attributes, specifiers, toks, stringize(parse_template) );
@ -2524,8 +2570,8 @@ CodeType parse_type( Parser::TokArray& toks, char const* context )
Token context_tok = prevtok;
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
s32 num_specifiers = 0;
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
Token name = { nullptr, 0, TokType::Invalid };
Token brute_sig = { currtok.Text, 0, TokType::Invalid };
@ -2542,8 +2588,8 @@ CodeType parse_type( Parser::TokArray& toks, char const* context )
return CodeInvalid;
}
specs_found[num_specifiers] = spec;
num_specifiers++;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
@ -2618,8 +2664,8 @@ CodeType parse_type( Parser::TokArray& toks, char const* context )
return CodeInvalid;
}
specs_found[num_specifiers] = spec;
num_specifiers++;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
@ -2677,9 +2723,9 @@ CodeType parse_type( Parser::TokArray& toks, char const* context )
}
else
{
if (num_specifiers)
if (NumSpecifiers)
{
Code specifiers = def_specifiers( num_specifiers, (SpecifierT*)specs_found );
Code specifiers = def_specifiers( NumSpecifiers, (SpecifierT*)specs_found );
result->Specs = specifiers;
}
}
@ -2859,7 +2905,7 @@ CodeUsing parse_using( Parser::TokArray& toks, char const* context )
using namespace Parser;
SpecifierT specs_found[16] { ESpecifier::Invalid };
s32 num_specifiers = 0;
s32 NumSpecifiers = 0;
Token name = { nullptr, 0, TokType::Invalid };
Code array_expr = { nullptr };
@ -2946,8 +2992,8 @@ CodeVar parse_variable( Parser::TokArray& toks, char const* context )
Token name = { nullptr, 0, TokType::Invalid };
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
s32 num_specifiers = 0;
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0;
ModuleFlag mflags = ModuleFlag::None;
CodeAttributes attributes = { nullptr };
@ -2989,14 +3035,14 @@ CodeVar parse_variable( Parser::TokArray& toks, char const* context )
if ( spec == ESpecifier::Const )
continue;
specs_found[num_specifiers] = spec;
num_specifiers++;
specs_found[NumSpecifiers] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( num_specifiers )
if ( NumSpecifiers )
{
specifiers = def_specifiers( num_specifiers, specs_found );
specifiers = def_specifiers( NumSpecifiers, specs_found );
}
CodeType type = parse_type( toks, context );

View File

@ -137,12 +137,12 @@ int gen_main()
header.print( nspace_macro );
header.print_fmt( "GEN_NS_BEGIN\n\n");
header.print_fmt("#pragma region Types");
header.print_fmt("#pragma region Types\n\n");
header.print( types );
header.print( ecode );
header.print( eoperator );
header.print( especifier );
header.print_fmt("#pragma endregion Types");
header.print_fmt("#pragma endregion Types\n\n");
header.print( data_structs );
header.print( interface );
@ -167,7 +167,7 @@ int gen_main()
Code parsing = scan_file( "components/gen.interface.parsing.cpp" );
Code untyped = scan_file( "components/gen.untyped.cpp" );
CodeBody etoktype = gen_etoktype( "./components/ETokType.csv" );
CodeBody etoktype = gen_etoktype( "components/ETokType.csv", "components/AttributeTokens.csv" );
CodeNamespace parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
Code builder = scan_file( "filesystem/gen.builder.cpp" );

View File

@ -157,7 +157,6 @@ CodeBody gen_especifier( char const* path )
#undef local_persist
#undef do_once_start
#undef do_once_end
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
StrC to_str( Type type )
{
@ -197,7 +196,6 @@ CodeBody gen_especifier( char const* path )
return Invalid;
}
)));
#pragma pop_macro( "local_persist" )
#pragma pop_macro( "do_once_start" )
#pragma pop_macro( "do_once_end" )
@ -209,36 +207,57 @@ CodeBody gen_especifier( char const* path )
return def_global_body( args( nspace, specifier_t ) );
}
CodeBody gen_etoktype( char const* path )
CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
{
char scratch_mem[kilobytes(4)];
char scratch_mem[kilobytes(64)];
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
file_read_contents( scratch, zero_terminate, path );
FileContents enum_content = file_read_contents( scratch, zero_terminate, etok_path );
CSV_Object csv_nodes;
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
CSV_Object csv_enum_nodes;
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), GlobalAllocator, false );
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
// memset( scratch_mem, 0, sizeof(scratch_mem) );
// scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
FileContents attrib_content = file_read_contents( scratch, zero_terminate, attr_path );
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
CSV_Object csv_attr_nodes;
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), GlobalAllocator, false );
Array<ADT_Node> enum_strs = csv_enum_nodes.nodes[0].nodes;
Array<ADT_Node> enum_str_strs = csv_enum_nodes.nodes[1].nodes;
Array<ADT_Node> attribute_strs = csv_attr_nodes.nodes[0].nodes;
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(4) );
String attribute_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
String to_str_attributes = String::make_reserve( GlobalAllocator, kilobytes(4) );
for (uw idx = 0; idx < enum_strs.num(); idx++)
{
char const* enum_str = enum_strs[idx].string;
char const* entry_to_str = str_strs [idx].string;
char const* entry_to_str = enum_str_strs [idx].string;
enum_entries.append_fmt( "%s,\n", enum_str );
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
}
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize(
for ( uw idx = 0; idx < attribute_strs.num(); idx++ )
{
char const* attribute_str = attribute_strs[idx].string;
char const* entry_to_str = attribute_str_strs [idx].string;
attribute_entries.append_fmt( "%s,\n", attribute_str );
to_str_attributes.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
}
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize(
enum Type : u32
{
<entries>
NumTokenTypes
<attribute_toks>
NumTokens
};
)));
@ -248,14 +267,13 @@ CodeBody gen_etoktype( char const* path )
#undef local_persist
#undef do_once_start
#undef do_once_end
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, "attribute_toks", (StrC)to_str_attributes, stringize(
StrC to_str( Type type )
{
local_persist
StrC lookup[] {
<entries>
NumTokens
<attribute_toks>
};
return lookup[ type ];
@ -289,49 +307,12 @@ CodeBody gen_etoktype( char const* path )
return Invalid;
}
)));
#pragma pop_macro( "local_persist" )
#pragma pop_macro( "do_once_start" )
#pragma pop_macro( "do_once_end" )
CodeFn is_specifier = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
bool tok_is_specifier( Type type )
{
return (tok.Type <= TokType::Star && tok.Type >= TokType::Spec_Alignas)
|| tok.Type == TokType::Ampersand
|| tok.Type == TokType::Ampersand_DBL
;
}
)));
CodeFn is_access_specifier = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
bool tok_is_access_specifier( Type type )
{
return tok.Type >= TokType::Access_Private && tok.Type <= TokType::Access_Public;
}
)));
#pragma push_macro( "internal" )
#pragma push_macro( "scast" )
CodeFn to_access_specifier = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
internal inline
AccessSpec tok_to_access_specifier( Type type )
{
return scast(AccessSpec, tok.Type);
}
)));
#pragma pop_macro( "internal" )
#pragma pop_macro( "scast" )
CodeFn is_attribute = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
bool tok_is_attribute( const Token type )
{
return tok.Type >= TokType::Attr_Alignas && tok.Type <= TokType::Attr_Visibility;
}
)));
CodeNamespace nspace = def_namespace( name(ETokType), def_namespace_body( args( enum_code, to_str, to_type, is_specifier, is_access_specifier, to_access_specifier, is_attribute ) ) );
CodeUsing td_toktype = def_using( name(TokTypeT), def_type( name(ETokType::Type) ) );
CodeNamespace nspace = def_namespace( name(ETokType), def_namespace_body( args( enum_code, to_str, to_type ) ) );
CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) );
return def_global_body( args( nspace, td_toktype ) );
}

View File

@ -52,10 +52,12 @@ Push-location $path_gen
& $gencpp
# Format generated files
$path_clang_format = Join-Path $path_scripts .clang-format
Write-Host `nBeginning format...
$formatParams = @(
'-i' # In-place
'-style=file' # Search for a .clang-format file in the parent directory of the source file.
"-style=file:$path_clang_format" # Search for a .clang-format file in the parent directory of the source file.
'-verbose'
)

View File

@ -0,0 +1,16 @@
cls
if ( -not( Test-Path $path_build ) ) {
New-Item -ItemType Directory -Path $path_build | Out-Null
}
if ( -not( Test-Path $path_build_interm ) ) {
New-Item -ItemType Directory -Path $path_build_interm | Out-Null
}
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_gen = Join-Path $path_test gen
$path_gen_build = Join-Path $path_gen build
$path_scripts = Join-Path $path_root scripts
$path_test = Join-Path $path_root test
$path_test_build = Join-Path $path_test build

26
scripts/msvc/devshell.ps1 Normal file
View File

@ -0,0 +1,26 @@
# This script is used to iniitate the MSVC DevShell
$vs_devshell = @()
@("enterprise", "professional", "community") | ForEach-Object {
$vs_devshell_2022 = "C:\Program Files\Microsoft Visual Studio\2022\" + $_ + "\Common7\Tools\Launch-VsDevShell.ps1"
$vs_devshell_2019 = "C:\Program Files (x86)\Microsoft Visual Studio\2019\" + $_ + "\Common7\Tools\Launch-VsDevShell.ps1"
$vs_devshell += @( $vs_devshell_2022, $vs_devshell_2019 )
}
$found = $false
foreach($path in $vs_devshell) {
if (Test-Path $path) {
write-host "Found $path"
Push-Location # Save the current path, loading the script will change it.
& $path
Pop-Location
$found = $true
break;
}
}
if (-not $found) {
write-host "MSVC DevShell: No valid path found"
}

View File

@ -126,12 +126,12 @@ int gen_main()
header.print_fmt( "GEN_NS_BEGIN\n\n" );
header.print_fmt("#pragma region Types");
header.print_fmt("#pragma region Types\n\n");
header.print( types );
header.print( ecode );
header.print( eoperator );
header.print( especifier );
header.print_fmt("#pragma endregion Types");
header.print_fmt("#pragma endregion Types\n\n");
header.print( data_structs );
header.print( interface );
@ -184,7 +184,7 @@ int gen_main()
Code parsing = scan_file( project_dir "components/gen.interface.parsing.cpp" );
Code untyped = scan_file( project_dir "components/gen.untyped.cpp" );
CodeBody etoktype = gen_etoktype( project_dir "components/ETokType.csv" );
CodeBody etoktype = gen_etoktype( project_dir "components/ETokType.csv", project_dir "components/AttributeTokens.csv" );
CodeNamespace parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
Code builder = scan_file( project_dir "filesystem/gen.builder.cpp" );