fixes for running GasaGen more than once in editor

This commit is contained in:
Edward R. Gonzalez 2024-12-15 19:54:01 -05:00
parent c895772cff
commit 3109ea4641
5 changed files with 32 additions and 24 deletions

View File

@ -7,7 +7,6 @@ USTRUCT()
struct GASA_API FGasaDevOptionsCache
{
GENERATED_BODY()
UPROPERTY()
TArray<UObject*> AttributeSets;
UPROPERTY()

View File

@ -30,14 +30,7 @@ void Execute_GasaModule_Codegen()
{
Gasa::LogEditor("Executing: Gasa Module code generation.");
if (gen_ctx.Allocator_Temp.Proc) {
gen::reset(& gen_ctx);
}
else
{
gen::init( & gen_ctx);
}
gen::init( & gen_ctx);
FString ue_project_path = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
FPaths::NormalizeDirectoryName(ue_project_path);
char const* ue_ansi_project_path = TCHAR_TO_ANSI(*ue_project_path);
@ -137,6 +130,8 @@ void Execute_GasaModule_Codegen()
// generate_HostWidgetController();
change_SBlueprintActionMenu_Construct();
change_EditorContentList();
gen::deinit( & gen_ctx);
});
}

View File

@ -3401,6 +3401,9 @@ void deinit(Context* ctx)
if (_ctx == ctx)
_ctx = nullptr;
-- context_counter;
Context wipe = {};
* ctx = wipe;
}
Context* get_context() {
@ -12940,9 +12943,8 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
char const* buf_begin = buf;
ssize remaining = buf_size;
local_persist StringTable tok_map;
do_once() {
tok_map = hashtable_init(Str, _ctx->Allocator_DyanmicContainers );
if (_ctx->token_fmt_map.Hashes == nullptr) {
_ctx->token_fmt_map = hashtable_init(Str, _ctx->Allocator_DyanmicContainers );
}
// Populate token pairs
{
@ -12954,7 +12956,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
Str value = va_arg( va, Str );
u32 key = crc32( token, c_str_len(token) );
hashtable_set( tok_map, key, value );
hashtable_set( _ctx->token_fmt_map, key, value );
}
}
@ -12989,8 +12991,8 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
char const* token = fmt + 1;
u32 key = crc32( token, tok_len );
Str* value = hashtable_get(tok_map, key );
u32 key = crc32( token, tok_len );
Str* value = hashtable_get(_ctx->token_fmt_map, key );
if ( value )
{
@ -13019,7 +13021,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
current = * fmt;
}
}
hashtable_clear(tok_map);
hashtable_clear(_ctx->token_fmt_map);
ssize result = buf_size - remaining;
return result;
}

View File

@ -267,13 +267,15 @@ GEN_NS_BEGIN
#define stringize( ... ) stringize_va( __VA_ARGS__ )
#endif
#define src_line_str stringize( __LINE__ )
#ifndef do_once
#define do_once() \
static int __do_once_counter_##__LINE__ = 0; \
for ( ; __do_once_counter_##__LINE__ != 1; __do_once_counter_##__LINE__ = 1 )
#define do_once_defer( expression ) \
static int __do_once_counter_##__LINE__ = 0; \
for ( ; __do_once_counter_##__LINE__ != 1; __do_once_counter_##__LINE__ = 1, ( expression ) )
#define do_once() \
static int __do_once_counter_##src_line_str = 0; \
for ( ; __do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1 )
#define do_once_defer( expression ) \
static int __do_once_counter_##src_line_str = 0; \
for ( ; __do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1, ( expression ) )
#define do_once_start \
do \
{ \

View File

@ -3968,6 +3968,8 @@ struct Context
u32 InitSize_Fallback_Allocator_Bucket_Size;
Array(Arena) Fallback_AllocatorBuckets;
StringTable token_fmt_map;
// Array(Token) LexerTokens;
Array(Pool) CodePools;
@ -4270,12 +4272,20 @@ GEN_API Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
#ifndef name
// Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL.
#define name( Id_ ) { stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# if GEN_COMPILER_C
# define name( Id_ ) (Str){ stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# else
# define name( Id_ ) Str { stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# endif
#endif
#ifndef code
// Same as name just used to indicate intention of literal for code instead of names.
#define code( ... ) { stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# if GEN_COMPILER_C
# define code( ... ) (Str){ stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# else
# define code( ... ) Str { stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# endif
#endif
#ifndef args