2024-10-25 02:04:11 -07:00
|
|
|
// This file was generated automatially by gencpp's unreal.cpp (See: https://github.com/Ed94/gencpp)
|
2024-10-21 19:39:40 -07:00
|
|
|
|
|
|
|
#ifdef __clang__
|
2024-10-27 18:44:34 -07:00
|
|
|
# pragma clang diagnostic push
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
|
|
|
# pragma clang diagnostic ignored "-Wswitch"
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-variable"
|
|
|
|
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
|
|
|
# pragma clang diagnostic ignored "-Wvarargs"
|
|
|
|
# pragma clang diagnostic ignored "-Wunused-function"
|
2024-12-15 11:14:02 -08:00
|
|
|
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
|
|
|
# pragma clang diagnostic ignored "-W#pragma-messages"
|
|
|
|
# pragma clang diagnostic ignored "-Wstatic-in-inline"
|
2024-10-21 19:39:40 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
2024-10-27 18:44:34 -07:00
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
|
|
|
# pragma GCC diagnostic ignored "-Wcomment"
|
|
|
|
# pragma GCC diagnostic ignored "-Wswitch"
|
|
|
|
# pragma GCC diagnostic ignored "-Wunused-variable"
|
2024-10-21 19:39:40 -07:00
|
|
|
#endif
|
|
|
|
|
2024-10-25 02:04:11 -07:00
|
|
|
#include "gen.builder.hpp"
|
|
|
|
|
2024-10-21 19:39:40 -07:00
|
|
|
GEN_NS_BEGIN
|
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
#pragma region Builder
|
|
|
|
|
|
|
|
Builder builder_open( char const* path )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
|
|
|
Builder result;
|
|
|
|
|
2024-10-27 18:44:34 -07:00
|
|
|
FileError error = file_open_mode( & result.File, EFileMode_WRITE, path );
|
2024-10-21 19:39:40 -07:00
|
|
|
if ( error != EFileError_NONE )
|
|
|
|
{
|
2024-10-27 18:44:34 -07:00
|
|
|
log_failure( "gen::File::open - Could not open file: %s", path);
|
2024-10-21 19:39:40 -07:00
|
|
|
return result;
|
|
|
|
}
|
2024-10-25 02:04:11 -07:00
|
|
|
|
2024-12-15 15:22:59 -08:00
|
|
|
Context* ctx = get_context();
|
|
|
|
GEN_ASSERT_NOT_NULL(ctx);
|
|
|
|
result.Buffer = strbuilder_make_reserve( ctx->Allocator_Temp, ctx->InitSize_BuilderBuffer );
|
2024-10-21 19:39:40 -07:00
|
|
|
|
|
|
|
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
void builder_pad_lines( Builder* builder, s32 num )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 11:14:02 -08:00
|
|
|
strbuilder_append_str( & builder->Buffer, txt("\n") );
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
void builder_print( Builder* builder, Code code )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 11:14:02 -08:00
|
|
|
StrBuilder str = code_to_strbuilder(code);
|
2024-10-27 18:44:34 -07:00
|
|
|
// const ssize len = str.length();
|
2024-10-21 19:39:40 -07:00
|
|
|
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
|
2024-12-15 11:14:02 -08:00
|
|
|
strbuilder_append_string( & builder->Buffer, str );
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va )
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-10-27 18:44:34 -07:00
|
|
|
ssize res;
|
|
|
|
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
res = c_str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
strbuilder_append_c_str_len( (StrBuilder*) & (builder->Buffer), (char const*)buf, res);
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
void builder_write(Builder* builder)
|
2024-10-21 19:39:40 -07:00
|
|
|
{
|
2024-12-15 11:14:02 -08:00
|
|
|
b32 result = file_write( & builder->File, builder->Buffer, strbuilder_length(builder->Buffer) );
|
2024-10-21 19:39:40 -07:00
|
|
|
|
|
|
|
if ( result == false )
|
2024-12-15 11:14:02 -08:00
|
|
|
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & builder->File ) );
|
2024-10-21 19:39:40 -07:00
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
log_fmt( "Generated: %s\n", builder->File.filename );
|
|
|
|
file_close( & builder->File );
|
|
|
|
strbuilder_free(& builder->Buffer);
|
2024-10-21 19:39:40 -07:00
|
|
|
}
|
|
|
|
|
2024-12-15 11:14:02 -08:00
|
|
|
#pragma endregion Builder
|
|
|
|
|
2024-10-21 19:39:40 -07:00
|
|
|
GEN_NS_END
|
|
|
|
|
|
|
|
#ifdef __clang__
|
2024-10-27 18:44:34 -07:00
|
|
|
# pragma clang diagnostic pop
|
2024-10-21 19:39:40 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
2024-10-27 18:44:34 -07:00
|
|
|
# pragma GCC diagnostic pop
|
2024-10-21 19:39:40 -07:00
|
|
|
#endif
|