mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
Compare commits
No commits in common. "0ccffe3f80b7455c158ef3ed2da4e3d492941b43" and "79a19518613b9caf2031f93d9453192c23bacfec" have entirely different histories.
0ccffe3f80
...
79a1951861
@ -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")) && fn->Params->NumEntries > 1)
|
||||
&& ( arr_param->ValueType->Name.starts_with(txt("Specifier"))
|
||||
|| arr_param->ValueType->Name.starts_with(txt("Code")) )
|
||||
)
|
||||
{
|
||||
@ -1311,8 +1311,6 @@ 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 )
|
||||
@ -1329,27 +1327,9 @@ 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);
|
||||
@ -1504,13 +1484,10 @@ 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( src_parsing_interface );
|
||||
// header.print( parsing_interface );
|
||||
header.print_fmt( "\n#pragma endregion Parsing\n" );
|
||||
header.print( src_untyped );
|
||||
// header.print( untyped );
|
||||
header.print_fmt( "\n#pragma endregion Interface\n\n");
|
||||
|
||||
// header.print_fmt( "#pragma region Builder\n" );
|
||||
|
@ -29,11 +29,6 @@ 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 ));
|
||||
@ -89,7 +84,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)"), txt("( (AllocatorInfo) { arena_allocator_proc, & (fixed_arena)->arena } )"));
|
||||
CodeDefine def = def_define(txt("fixed_arena_allocator_info(fixed_arena)"), code({ arena_allocator_proc, & fixed_arena.arena }) );
|
||||
result.append(def);
|
||||
result.append(fmt_newline);
|
||||
|
||||
@ -108,23 +103,7 @@ 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)
|
||||
|
||||
#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)
|
||||
) GEN_RESOLVED_FUNCTION_CALL(& expr)
|
||||
|
||||
#define fixed_arena_size_remaining(expr, alignment) _Generic((expr), \
|
||||
FixedArena_1KB* : fixed_arena_size_remaining_1KB, \
|
||||
@ -140,7 +119,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 TokenMap_FixedArena
|
||||
# define TokenMap_FixedArena FixedArena_8KB
|
||||
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(8)
|
||||
#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( s32 num_tokens, char const* fmt, ... );
|
||||
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
||||
|
||||
#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, parser_not_inplace_def );
|
||||
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class );
|
||||
parser_pop(& Context);
|
||||
return result;
|
||||
}
|
||||
@ -35,8 +35,8 @@ CodeConstructor parse_constructor( StrC def )
|
||||
|
||||
// TODO(Ed): Constructors can have prefix attributes
|
||||
|
||||
CodeSpecifiers specifiers = NullCode;
|
||||
Specifier specs_found[ 16 ] = { Spec_NumSpecifiers };
|
||||
CodeSpecifiers specifiers;
|
||||
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 = parser_parse_constructor( specifiers );
|
||||
CodeConstructor result = 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 = parser_parse_destructor(NullCode);
|
||||
CodeDestructor result = parse_destructor();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ CodeEnum parse_enum( StrC def )
|
||||
}
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parser_parse_enum( parser_not_inplace_def);
|
||||
return 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 parser_parse_export_body();
|
||||
return 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 parser_parse_extern_link();
|
||||
return parse_extern_link();
|
||||
}
|
||||
|
||||
CodeFriend parse_friend( StrC def )
|
||||
@ -153,7 +153,7 @@ CodeFriend parse_friend( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parser_parse_friend();
|
||||
return parse_friend();
|
||||
}
|
||||
|
||||
CodeFn parse_function( StrC def )
|
||||
@ -166,7 +166,7 @@ CodeFn parse_function( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return (CodeFn) parser_parse_function();
|
||||
return (CodeFn) parse_function();
|
||||
}
|
||||
|
||||
CodeBody parse_global_body( StrC def )
|
||||
@ -195,7 +195,7 @@ CodeNS parse_namespace( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parser_parse_namespace();
|
||||
return parse_namespace();
|
||||
}
|
||||
|
||||
CodeOperator parse_operator( StrC def )
|
||||
@ -208,7 +208,7 @@ CodeOperator parse_operator( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return (CodeOperator) parser_parse_operator();
|
||||
return (CodeOperator) parse_operator();
|
||||
}
|
||||
|
||||
CodeOpCast parse_operator_cast( StrC def )
|
||||
@ -221,7 +221,7 @@ CodeOpCast parse_operator_cast( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parser_parse_operator_cast(NullCode);
|
||||
return parse_operator_cast();
|
||||
}
|
||||
|
||||
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, parser_not_inplace_def );
|
||||
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct );
|
||||
parser_pop(& Context);
|
||||
return result;
|
||||
}
|
||||
@ -250,7 +250,7 @@ CodeTemplate parse_template( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parser_parse_template();
|
||||
return parse_template();
|
||||
}
|
||||
|
||||
CodeTypename parse_type( StrC def )
|
||||
@ -263,7 +263,7 @@ CodeTypename parse_type( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parser_parse_type( parser_not_from_template, nullptr);
|
||||
return 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 parser_parse_typedef();
|
||||
return parse_typedef();
|
||||
}
|
||||
|
||||
CodeUnion parse_union( StrC def )
|
||||
@ -289,7 +289,7 @@ CodeUnion parse_union( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parser_parse_union( parser_not_inplace_def);
|
||||
return 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 parser_parse_using();
|
||||
return parse_using();
|
||||
}
|
||||
|
||||
CodeVar parse_variable( StrC def )
|
||||
@ -315,19 +315,15 @@ CodeVar parse_variable( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parser_parse_variable();
|
||||
return 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
|
||||
TokenMap_FixedArena tok_map_arena;
|
||||
FixedArena<TokenFmt_TokenMap_MemSize> tok_map_arena;
|
||||
fixed_arena_init( & tok_map_arena);
|
||||
|
||||
local_persist
|
||||
StringTable tok_map;
|
||||
HashTable(StrC) 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.Len == 0 )
|
||||
if ( result->Name == nullptr )
|
||||
{
|
||||
log_failure( "untyped_str: could not cache string" );
|
||||
return InvalidCode;
|
||||
@ -138,16 +138,13 @@ 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( buf_str );
|
||||
result->Name = get_cached_string( { str_len_capped(fmt, MaxNameLength), fmt } );
|
||||
result->Type = CT_Untyped;
|
||||
result->Content = get_cached_string( uncapped_str );
|
||||
result->Content = get_cached_string( { length, buf } );
|
||||
|
||||
if ( result->Name.Len == 0 )
|
||||
if ( result->Name == nullptr )
|
||||
{
|
||||
log_failure( "untyped_fmt: could not cache string" );
|
||||
return InvalidCode;
|
||||
@ -156,7 +153,7 @@ Code untyped_fmt( char const* fmt, ...)
|
||||
return result;
|
||||
}
|
||||
|
||||
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... )
|
||||
Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
{
|
||||
if ( num_tokens == 0 )
|
||||
{
|
||||
@ -168,19 +165,17 @@ Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... )
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
va_start(va, num_tokens);
|
||||
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( buf_str );
|
||||
result->Name = get_cached_string( { length, buf } );
|
||||
result->Type = CT_Untyped;
|
||||
result->Content = result->Name;
|
||||
|
||||
if ( result->Name.Len == 0 )
|
||||
if ( result->Name == nullptr )
|
||||
{
|
||||
log_failure( "untyped_fmt: could not cache string" );
|
||||
return InvalidCode;
|
||||
|
@ -113,7 +113,7 @@ struct TokArray
|
||||
s32 Idx;
|
||||
};
|
||||
|
||||
bool lex__eat( TokArray* self, TokType type );
|
||||
bool lex__eat( TokType type );
|
||||
|
||||
Token* lex_current(TokArray* self, bool skip_formatting )
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -319,7 +319,6 @@ 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