mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08:00
Compare commits
2 Commits
79a1951861
...
0ccffe3f80
Author | SHA1 | Date | |
---|---|---|---|
0ccffe3f80 | |||
cd7548c3d4 |
@ -1189,7 +1189,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
|
||||
for ( CodeParam arr_param : fn->Params )
|
||||
if ( fn->Name.starts_with(txt("def_"))
|
||||
&& ( arr_param->ValueType->Name.starts_with(txt("Specifier"))
|
||||
&& ( (arr_param->ValueType->Name.starts_with(txt("Specifier")) && fn->Params->NumEntries > 1)
|
||||
|| arr_param->ValueType->Name.starts_with(txt("Code")) )
|
||||
)
|
||||
{
|
||||
@ -1311,6 +1311,8 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody array_code_typename = gen_array(txt("CodeTypename"), txt("Array_CodeTypename"));
|
||||
|
||||
CodeBody parsed_src_parser = parse_file( project_dir "components/parser.cpp" );
|
||||
CodeBody src_parser = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_src_parser.begin(); entry != parsed_src_parser.end(); ++ entry ) switch( entry ->Type )
|
||||
@ -1327,9 +1329,27 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
case CT_Struct:
|
||||
{
|
||||
CodeTypedef tdef = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct <name> <name>; )));
|
||||
src_parser.append(entry);
|
||||
src_parser.append(tdef);
|
||||
src_parser.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Variable:
|
||||
{
|
||||
CodeVar var = cast(CodeVar, entry);
|
||||
if (var->Specs && var->Specs.has(Spec_Constexpr) > -1) {
|
||||
Code define_ver = untyped_str(token_fmt(
|
||||
"name", var->Name
|
||||
, "value", var->Value->Content
|
||||
, "type", var->ValueType.to_string().to_strc()
|
||||
, "#define <name> (<type>) <value>\n"
|
||||
));
|
||||
src_parser.append(define_ver);
|
||||
continue;
|
||||
}
|
||||
src_parser.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
src_parser.append(entry);
|
||||
@ -1484,10 +1504,13 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
header.print( format_code_to_untyped(etoktype) );
|
||||
header.print( format_code_to_untyped(src_lexer) );
|
||||
header.print( fmt_newline);
|
||||
header.print( format_code_to_untyped(array_code_typename));
|
||||
header.print( fmt_newline);
|
||||
header.print( format_code_to_untyped(src_parser) );
|
||||
// header.print( parsing_interface );
|
||||
header.print( src_parsing_interface );
|
||||
header.print_fmt( "\n#pragma endregion Parsing\n" );
|
||||
// header.print( untyped );
|
||||
header.print( src_untyped );
|
||||
header.print_fmt( "\n#pragma endregion Interface\n\n");
|
||||
|
||||
// header.print_fmt( "#pragma region Builder\n" );
|
||||
|
@ -29,6 +29,11 @@ CodeBody gen_fixed_arenas()
|
||||
{
|
||||
return arena_size_remaining( & fixed_arena->arena, alignment);
|
||||
}
|
||||
|
||||
inline
|
||||
void fixed_arena_free_<Name>(FixedArena_<Name>* fixed_arena) {
|
||||
arena_free( & fixed_arena->arena);
|
||||
}
|
||||
);
|
||||
|
||||
CodeBody arena_struct_1kb = parse_global_body( token_fmt_impl( 3, "Name", txt("1KB"), "Size", txt("kilobytes(1)"), template_struct ));
|
||||
@ -84,7 +89,7 @@ CodeBody gen_fixed_arenas()
|
||||
result.append(arena_interface_2mb);
|
||||
result.append(arena_interface_4mb);
|
||||
|
||||
CodeDefine def = def_define(txt("fixed_arena_allocator_info(fixed_arena)"), code({ arena_allocator_proc, & fixed_arena.arena }) );
|
||||
CodeDefine def = def_define(txt("fixed_arena_allocator_info(fixed_arena)"), txt("( (AllocatorInfo) { arena_allocator_proc, & (fixed_arena)->arena } )"));
|
||||
result.append(def);
|
||||
result.append(fmt_newline);
|
||||
|
||||
@ -103,7 +108,23 @@ CodeBody gen_fixed_arenas()
|
||||
FixedArena_2MB* : fixed_arena_init_2MB, \
|
||||
FixedArena_4MB* : fixed_arena_init_4MB, \
|
||||
default : gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL(& expr)
|
||||
) GEN_RESOLVED_FUNCTION_CALL(expr)
|
||||
|
||||
#define fixed_arena_free(expr) _Generic((expr), \
|
||||
FixedArena_1KB* : fixed_arena_free_1KB, \
|
||||
FixedArena_4KB* : fixed_arena_free_4KB, \
|
||||
FixedArena_8KB* : fixed_arena_free_8KB, \
|
||||
FixedArena_16KB* : fixed_arena_free_16KB, \
|
||||
FixedArena_32KB* : fixed_arena_free_32KB, \
|
||||
FixedArena_64KB* : fixed_arena_free_64KB, \
|
||||
FixedArena_128KB* : fixed_arena_free_128KB, \
|
||||
FixedArena_256KB* : fixed_arena_free_256KB, \
|
||||
FixedArena_512KB* : fixed_arena_free_512KB, \
|
||||
FixedArena_1MB* : fixed_arena_free_1MB, \
|
||||
FixedArena_2MB* : fixed_arena_free_2MB, \
|
||||
FixedArena_4MB* : fixed_arena_free_4MB, \
|
||||
default : gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL(expr)
|
||||
|
||||
#define fixed_arena_size_remaining(expr, alignment) _Generic((expr), \
|
||||
FixedArena_1KB* : fixed_arena_size_remaining_1KB, \
|
||||
@ -119,7 +140,7 @@ CodeBody gen_fixed_arenas()
|
||||
FixedArena_2MB* : fixed_arena_size_remaining_2MB, \
|
||||
FixedArena_4MB* : fixed_arena_size_remaining_4MB, \
|
||||
default : gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL(& expr, alignment)
|
||||
) GEN_RESOLVED_FUNCTION_CALL(expr, alignment)
|
||||
)"
|
||||
)));
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
||||
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
||||
#endif
|
||||
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(8)
|
||||
#ifndef TokenMap_FixedArena
|
||||
# define TokenMap_FixedArena FixedArena_8KB
|
||||
#endif
|
||||
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
||||
@ -49,7 +49,7 @@ constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
|
||||
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
|
||||
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
||||
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH;
|
||||
constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
|
||||
// constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
|
||||
constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
|
||||
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
||||
|
||||
|
@ -272,7 +272,7 @@ StrC token_fmt_impl( ssize, ... );
|
||||
|
||||
Code untyped_str ( StrC content);
|
||||
Code untyped_fmt ( char const* fmt, ... );
|
||||
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
||||
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
|
||||
|
||||
#pragma endregion Untyped text
|
||||
|
||||
|
@ -19,7 +19,7 @@ CodeClass parse_class( StrC def )
|
||||
|
||||
Context.Tokens = toks;
|
||||
push_scope();
|
||||
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class );
|
||||
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class, parser_not_inplace_def );
|
||||
parser_pop(& Context);
|
||||
return result;
|
||||
}
|
||||
@ -35,8 +35,8 @@ CodeConstructor parse_constructor( StrC def )
|
||||
|
||||
// TODO(Ed): Constructors can have prefix attributes
|
||||
|
||||
CodeSpecifiers specifiers;
|
||||
Specifier specs_found[ 16 ] { Spec_NumSpecifiers };
|
||||
CodeSpecifiers specifiers = NullCode;
|
||||
Specifier specs_found[ 16 ] = { Spec_NumSpecifiers };
|
||||
s32 NumSpecifiers = 0;
|
||||
|
||||
while ( left && tok_is_specifier(currtok) )
|
||||
@ -80,7 +80,7 @@ CodeConstructor parse_constructor( StrC def )
|
||||
}
|
||||
|
||||
Context.Tokens = toks;
|
||||
CodeConstructor result = parse_constructor( specifiers );
|
||||
CodeConstructor result = parser_parse_constructor( specifiers );
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ CodeDestructor parse_destructor( StrC def )
|
||||
// TODO(Ed): Destructors can have virtual
|
||||
|
||||
Context.Tokens = toks;
|
||||
CodeDestructor result = parse_destructor();
|
||||
CodeDestructor result = parser_parse_destructor(NullCode);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ CodeEnum parse_enum( StrC def )
|
||||
}
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_enum( parser_not_inplace_def);
|
||||
return parser_parse_enum( parser_not_inplace_def);
|
||||
}
|
||||
|
||||
CodeBody parse_export_body( StrC def )
|
||||
@ -127,7 +127,7 @@ CodeBody parse_export_body( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_export_body();
|
||||
return parser_parse_export_body();
|
||||
}
|
||||
|
||||
CodeExtern parse_extern_link( StrC def )
|
||||
@ -140,7 +140,7 @@ CodeExtern parse_extern_link( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_extern_link();
|
||||
return parser_parse_extern_link();
|
||||
}
|
||||
|
||||
CodeFriend parse_friend( StrC def )
|
||||
@ -153,7 +153,7 @@ CodeFriend parse_friend( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_friend();
|
||||
return parser_parse_friend();
|
||||
}
|
||||
|
||||
CodeFn parse_function( StrC def )
|
||||
@ -166,7 +166,7 @@ CodeFn parse_function( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return (CodeFn) parse_function();
|
||||
return (CodeFn) parser_parse_function();
|
||||
}
|
||||
|
||||
CodeBody parse_global_body( StrC def )
|
||||
@ -195,7 +195,7 @@ CodeNS parse_namespace( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_namespace();
|
||||
return parser_parse_namespace();
|
||||
}
|
||||
|
||||
CodeOperator parse_operator( StrC def )
|
||||
@ -208,7 +208,7 @@ CodeOperator parse_operator( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return (CodeOperator) parse_operator();
|
||||
return (CodeOperator) parser_parse_operator();
|
||||
}
|
||||
|
||||
CodeOpCast parse_operator_cast( StrC def )
|
||||
@ -221,7 +221,7 @@ CodeOpCast parse_operator_cast( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_operator_cast();
|
||||
return parser_parse_operator_cast(NullCode);
|
||||
}
|
||||
|
||||
CodeStruct parse_struct( StrC def )
|
||||
@ -235,7 +235,7 @@ CodeStruct parse_struct( StrC def )
|
||||
|
||||
Context.Tokens = toks;
|
||||
push_scope();
|
||||
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct );
|
||||
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct, parser_not_inplace_def );
|
||||
parser_pop(& Context);
|
||||
return result;
|
||||
}
|
||||
@ -250,7 +250,7 @@ CodeTemplate parse_template( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_template();
|
||||
return parser_parse_template();
|
||||
}
|
||||
|
||||
CodeTypename parse_type( StrC def )
|
||||
@ -263,7 +263,7 @@ CodeTypename parse_type( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_type( parser_not_from_template, nullptr);
|
||||
return parser_parse_type( parser_not_from_template, nullptr);
|
||||
}
|
||||
|
||||
CodeTypedef parse_typedef( StrC def )
|
||||
@ -276,7 +276,7 @@ CodeTypedef parse_typedef( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_typedef();
|
||||
return parser_parse_typedef();
|
||||
}
|
||||
|
||||
CodeUnion parse_union( StrC def )
|
||||
@ -289,7 +289,7 @@ CodeUnion parse_union( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_union( parser_not_inplace_def);
|
||||
return parser_parse_union( parser_not_inplace_def);
|
||||
}
|
||||
|
||||
CodeUsing parse_using( StrC def )
|
||||
@ -302,7 +302,7 @@ CodeUsing parse_using( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_using();
|
||||
return parser_parse_using();
|
||||
}
|
||||
|
||||
CodeVar parse_variable( StrC def )
|
||||
@ -315,15 +315,19 @@ CodeVar parse_variable( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_variable();
|
||||
return parser_parse_variable();
|
||||
}
|
||||
|
||||
// Undef helper macros
|
||||
# undef check_parse_args
|
||||
# undef currtok_noskip
|
||||
# undef currtok
|
||||
# undef peektok
|
||||
# undef prevtok
|
||||
# undef nexttok
|
||||
# undef nexttok_noskip
|
||||
# undef eat
|
||||
# undef left
|
||||
# undef check
|
||||
# undef push_scope
|
||||
# undef def_assign
|
||||
|
@ -9,11 +9,11 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
||||
ssize remaining = buf_size;
|
||||
|
||||
local_persist
|
||||
FixedArena<TokenFmt_TokenMap_MemSize> tok_map_arena;
|
||||
TokenMap_FixedArena tok_map_arena;
|
||||
fixed_arena_init( & tok_map_arena);
|
||||
|
||||
local_persist
|
||||
HashTable(StrC) tok_map;
|
||||
StringTable tok_map;
|
||||
{
|
||||
tok_map = hashtable_init(StrC, fixed_arena_allocator_info(& tok_map_arena) );
|
||||
|
||||
@ -113,7 +113,7 @@ Code untyped_str( StrC content )
|
||||
result->Type = CT_Untyped;
|
||||
result->Content = result->Name;
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
if ( result->Name.Len == 0 )
|
||||
{
|
||||
log_failure( "untyped_str: could not cache string" );
|
||||
return InvalidCode;
|
||||
@ -138,13 +138,16 @@ Code untyped_fmt( char const* fmt, ...)
|
||||
ssize length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
StrC buf_str = { str_len_capped(fmt, MaxNameLength), fmt };
|
||||
StrC uncapped_str = { length, buf };
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Name = get_cached_string( { str_len_capped(fmt, MaxNameLength), fmt } );
|
||||
result->Name = get_cached_string( buf_str );
|
||||
result->Type = CT_Untyped;
|
||||
result->Content = get_cached_string( { length, buf } );
|
||||
result->Content = get_cached_string( uncapped_str );
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
if ( result->Name.Len == 0 )
|
||||
{
|
||||
log_failure( "untyped_fmt: could not cache string" );
|
||||
return InvalidCode;
|
||||
@ -153,7 +156,7 @@ Code untyped_fmt( char const* fmt, ...)
|
||||
return result;
|
||||
}
|
||||
|
||||
Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... )
|
||||
{
|
||||
if ( num_tokens == 0 )
|
||||
{
|
||||
@ -165,17 +168,19 @@ Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start(va, num_tokens);
|
||||
va_start(va, fmt);
|
||||
ssize length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va);
|
||||
va_end(va);
|
||||
|
||||
StrC buf_str = { length, buf };
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Name = get_cached_string( { length, buf } );
|
||||
result->Name = get_cached_string( buf_str );
|
||||
result->Type = CT_Untyped;
|
||||
result->Content = result->Name;
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
if ( result->Name.Len == 0 )
|
||||
{
|
||||
log_failure( "untyped_fmt: could not cache string" );
|
||||
return InvalidCode;
|
||||
|
@ -113,7 +113,7 @@ struct TokArray
|
||||
s32 Idx;
|
||||
};
|
||||
|
||||
bool lex__eat( TokType type );
|
||||
bool lex__eat( TokArray* self, TokType type );
|
||||
|
||||
Token* lex_current(TokArray* self, bool skip_formatting )
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -319,6 +319,7 @@ struct FixedArena;
|
||||
template<s32 Size> FixedArena<Size> fixed_arena_init();
|
||||
template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena );
|
||||
template<s32 Size> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment);
|
||||
template<s32 Size> void fixed_arena_free(FixedArena<Size>* fixed_arena);
|
||||
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
template<s32 Size> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); }
|
||||
|
Loading…
Reference in New Issue
Block a user