mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08:00
bugfixes while testing with unreal (still more needs fixing
This commit is contained in:
parent
0b03b3cd92
commit
868b93cdd0
@ -15,7 +15,9 @@ Builder builder_open( char const* path )
|
||||
return result;
|
||||
}
|
||||
|
||||
result.Buffer = strbuilder_make_reserve( _ctx->Allocator_Temp, _ctx->InitSize_BuilderBuffer );
|
||||
Context* ctx = get_context();
|
||||
GEN_ASSERT_NOT_NULL(ctx);
|
||||
result.Buffer = strbuilder_make_reserve( ctx->Allocator_Temp, ctx->InitSize_BuilderBuffer );
|
||||
|
||||
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
|
||||
return result;
|
||||
|
@ -25,13 +25,14 @@ Builder builder_open ( char const* path );
|
||||
void builder_pad_lines ( Builder* builder, s32 num );
|
||||
void builder_print ( Builder* builder, Code code );
|
||||
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va );
|
||||
void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
|
||||
void builder_write ( Builder* builder );
|
||||
|
||||
forceinline void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
builder_print_fmt_va( builder, fmt, va );
|
||||
va_end( va );
|
||||
}
|
||||
void builder_write( Builder* builder );
|
||||
|
||||
struct Builder
|
||||
{
|
||||
@ -56,10 +57,10 @@ struct Builder
|
||||
};
|
||||
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
|
||||
void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
|
||||
void builder_write ( Builder& builder ) { return builder_write(& builder ); }
|
||||
void builder_print_fmt( Builder& builder, char const* fmt, ...) {
|
||||
forceinline void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
|
||||
forceinline void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
|
||||
forceinline void builder_write ( Builder& builder ) { return builder_write(& builder ); }
|
||||
forceinline void builder_print_fmt( Builder& builder, char const* fmt, ...) {
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
builder_print_fmt_va( & builder, fmt, va );
|
||||
|
@ -20,7 +20,7 @@ Code scan_file( char const* path )
|
||||
GEN_FATAL("scan_file: %s is empty", path );
|
||||
}
|
||||
|
||||
StrBuilder str = strbuilder_make_reserve( _ctx->Allocator_Temp, fsize );
|
||||
StrBuilder str = strbuilder_make_reserve( get_context()->Allocator_Temp, fsize );
|
||||
file_read( & file, str, fsize );
|
||||
strbuilder_get_header(str)->Length = fsize;
|
||||
|
||||
@ -117,7 +117,7 @@ Code scan_file( char const* path )
|
||||
}
|
||||
|
||||
CodeBody parse_file( const char* path ) {
|
||||
FileContents file = file_read_contents( _ctx->Allocator_Temp, true, path );
|
||||
FileContents file = file_read_contents( get_context()->Allocator_Temp, true, path );
|
||||
Str content = { (char const*)file.data, file.size };
|
||||
CodeBody code = parse_global_body( content );
|
||||
log_fmt("\nParsed: %s\n", path);
|
||||
|
@ -262,9 +262,9 @@ forceinline void define_params_append (CodeDefineParams appendee
|
||||
forceinline CodeDefineParams define_params_get (CodeDefineParams self, s32 idx ) { return (CodeDefineParams) (Code) params_get( cast(CodeParams, self), idx); }
|
||||
forceinline bool define_params_has_entries(CodeDefineParams self) { return params_has_entries( cast(CodeParams, self)); }
|
||||
|
||||
CodeDefineParams begin_CodeDefineParams(CodeDefineParams params) { return (CodeDefineParams) (Code) begin_CodeParams( cast(CodeParams, (Code)params)); }
|
||||
CodeDefineParams end_CodeDefineParams (CodeDefineParams params) { return (CodeDefineParams) (Code) end_CodeParams ( cast(CodeParams, (Code)params)); }
|
||||
CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter) { return (CodeDefineParams) (Code) next_CodeParams ( cast(CodeParams, (Code)params), cast(CodeParams, (Code)entry_iter)); }
|
||||
forceinline CodeDefineParams begin_CodeDefineParams(CodeDefineParams params) { return (CodeDefineParams) (Code) begin_CodeParams( cast(CodeParams, (Code)params)); }
|
||||
forceinline CodeDefineParams end_CodeDefineParams (CodeDefineParams params) { return (CodeDefineParams) (Code) end_CodeParams ( cast(CodeParams, (Code)params)); }
|
||||
forceinline CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter) { return (CodeDefineParams) (Code) next_CodeParams ( cast(CodeParams, (Code)params), cast(CodeParams, (Code)entry_iter)); }
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline
|
||||
|
@ -378,6 +378,10 @@ void deinit(Context* ctx)
|
||||
-- context_counter;
|
||||
}
|
||||
|
||||
Context* get_context() {
|
||||
return _ctx;
|
||||
}
|
||||
|
||||
void reset(Context* ctx)
|
||||
{
|
||||
s32 index = 0;
|
||||
|
@ -100,6 +100,9 @@ GEN_API void init(Context* ctx);
|
||||
// However on Windows at least, it doesn't need to occur as the OS will clean up after the process.
|
||||
GEN_API void deinit(Context* ctx);
|
||||
|
||||
// Retrieves the active context (not usually needed, but here in case...)
|
||||
GEN_API Context* get_context();
|
||||
|
||||
// Clears the allocations, but doesn't free the memoery, then calls init() again.
|
||||
// Ease of use.
|
||||
GEN_API void reset(Context* ctx);
|
||||
|
@ -155,7 +155,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
array_append( _ctx->Lexer_Tokens, opening_paren );
|
||||
move_forward();
|
||||
|
||||
Token last_parameter;
|
||||
Token last_parameter = {};
|
||||
// We need to tokenize the define's arguments now:
|
||||
while( ctx->left && * ctx->scanner != ')')
|
||||
{
|
||||
|
@ -2490,7 +2490,40 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
|
||||
// Example : <Capture_Start> <Value> <Comma>
|
||||
// idx +1 +2
|
||||
bool detected_comma = _ctx->parser.Tokens.Arr[ _ctx->parser.Tokens.Idx + 2 ].Type == Tok_Comma;
|
||||
if ( detected_capture && ! detected_comma )
|
||||
|
||||
b32 detected_non_varadic_unpaired_param = detected_comma && nexttok.Type != Tok_Varadic_Argument;
|
||||
if (! detected_non_varadic_unpaired_param && nexttok.Type == Tok_Preprocess_Macro_Expr) for( s32 break_scope = 0; break_scope == 0; ++ break_scope)
|
||||
{
|
||||
Macro* macro = lookup_macro( nexttok.Text );
|
||||
if (macro == nullptr || ! macro_is_functional(* macro))
|
||||
break;
|
||||
|
||||
// ( <Macro_Expr> (
|
||||
// Idx +1 +2
|
||||
s32 idx = _ctx->parser.Tokens.Idx + 1;
|
||||
s32 level = 0;
|
||||
|
||||
// Find end of the token expression
|
||||
for ( ; idx < array_num(_ctx->parser.Tokens.Arr); idx++ )
|
||||
{
|
||||
Token tok = _ctx->parser.Tokens.Arr[ idx ];
|
||||
|
||||
if ( tok.Type == Tok_Capture_Start )
|
||||
level++;
|
||||
else if ( tok.Type == Tok_Capture_End && level > 0 )
|
||||
level--;
|
||||
if (level == 0 && tok.Type == Tok_Capture_End)
|
||||
break;
|
||||
}
|
||||
++ idx; // Will incremnt to possible comma position
|
||||
|
||||
if ( _ctx->parser.Tokens.Arr[ idx ].Type != Tok_Comma )
|
||||
break;
|
||||
|
||||
detected_non_varadic_unpaired_param = true;
|
||||
}
|
||||
|
||||
if ( detected_capture && ! detected_non_varadic_unpaired_param )
|
||||
{
|
||||
// Dealing with a function
|
||||
result = cast(Code, parse_function_after_name( ModuleFlag_None, attributes, specifiers, type, name ));
|
||||
@ -3002,7 +3035,7 @@ Code parse_simple_preprocess( TokType which )
|
||||
|| str_contains(calling_proc, txt("parse_class_struct_body"))
|
||||
)
|
||||
{
|
||||
if (peektok.Type == Tok_Statement_End)
|
||||
if (left && peektok.Type == Tok_Statement_End)
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( Tok_Statement_End );
|
||||
@ -5015,7 +5048,6 @@ CodeTypedef parser_parse_typedef()
|
||||
// valid_macro |= macro && macro_expects_body(* macro));
|
||||
// }
|
||||
|
||||
Code macro;
|
||||
if ( valid_macro )
|
||||
#endif
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
enum TokFlags : u32
|
||||
{
|
||||
TF_Operator = bit(0),
|
||||
TF_Operator = bit(0),
|
||||
TF_Assign = bit(1),
|
||||
TF_Preprocess = bit(2),
|
||||
TF_Preprocess_Cond = bit(3),
|
||||
@ -152,6 +152,7 @@ TokType macrotype_to_toktype( MacroType type ) {
|
||||
return Tok_Invalid;
|
||||
}
|
||||
|
||||
inline
|
||||
Str macrotype_to_str( MacroType type )
|
||||
{
|
||||
local_persist
|
||||
@ -216,4 +217,9 @@ b32 macro_expects_body( Macro macro ) {
|
||||
return bitfield_is_set( b16, macro.Flags, MF_Expects_Body );
|
||||
}
|
||||
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline b32 is_functional( Macro macro ) { return bitfield_is_set( b16, macro.Flags, MF_Functional ); }
|
||||
forceinline b32 expects_body ( Macro macro ) { return bitfield_is_set( b16, macro.Flags, MF_Expects_Body ); }
|
||||
#endif
|
||||
|
||||
typedef HashTable(Macro) MacroTable;
|
||||
|
@ -143,6 +143,7 @@ Array<Type> array_init_reserve(AllocatorInfo allocator, ssize capacity)
|
||||
return {rcast(Type*, header + 1)};
|
||||
}
|
||||
|
||||
forceinline
|
||||
usize array_grow_formula(ssize value) {
|
||||
return 2 * value + 8;
|
||||
}
|
||||
@ -202,7 +203,7 @@ bool array_append_at(Array<Type>* array, Type item, usize idx)
|
||||
ArrayHeader* header = array_get_header(* array);
|
||||
|
||||
ssize slot = idx;
|
||||
if (slot >= header->Num)
|
||||
if (slot >= (ssize)(header->Num))
|
||||
slot = header->Num - 1;
|
||||
|
||||
if (slot < 0)
|
||||
@ -354,7 +355,6 @@ bool array_reserve(Array<Type>* array, usize new_capacity)
|
||||
{
|
||||
GEN_ASSERT( array != nullptr);
|
||||
GEN_ASSERT(* array != nullptr);
|
||||
GEN_ASSERT(num > 0)
|
||||
ArrayHeader* header = array_get_header(array);
|
||||
|
||||
if (header->Capacity < new_capacity)
|
||||
@ -763,7 +763,7 @@ HashTableFindResult hashtable__find(HashTable<Type> table, u64 key)
|
||||
}
|
||||
|
||||
template<typename Type> forceinline
|
||||
bool hashtable_full(HashTable<Type> table) {
|
||||
b32 hashtable_full(HashTable<Type> table) {
|
||||
GEN_ASSERT_NOT_NULL(table.Hashes);
|
||||
GEN_ASSERT_NOT_NULL(table.Entries);
|
||||
usize critical_load = usize(HashTable_CriticalLoadScale * f32(array_num(table.Hashes)));
|
||||
|
@ -44,7 +44,7 @@
|
||||
// NOTE: Things that shouldn't happen with a message!
|
||||
#define GEN_PANIC( msg, ... ) GEN_ASSERT_MSG( 0, msg, ##__VA_ARGS__ )
|
||||
|
||||
#if GEN_BULD_DEBUG
|
||||
#if GEN_BUILD_DEBUG
|
||||
#define GEN_FATAL( ... ) \
|
||||
do \
|
||||
{ \
|
||||
|
@ -346,25 +346,25 @@ void* arena_allocator_proc( void* allocator_data, AllocType type, ssize size, ss
|
||||
switch ( type )
|
||||
{
|
||||
case EAllocation_ALLOC :
|
||||
{
|
||||
void* end = pointer_add( arena->PhysicalStart, arena->TotalUsed );
|
||||
ssize total_size = align_forward_s64( size, alignment );
|
||||
|
||||
// NOTE: Out of memory
|
||||
if ( arena->TotalUsed + total_size > (ssize) arena->TotalSize )
|
||||
{
|
||||
void* end = pointer_add( arena->PhysicalStart, arena->TotalUsed );
|
||||
ssize total_size = align_forward_s64( size, alignment );
|
||||
|
||||
// NOTE: Out of memory
|
||||
if ( arena->TotalUsed + total_size > (ssize) arena->TotalSize )
|
||||
{
|
||||
// zpl__printf_err("%s", "Arena out of memory\n");
|
||||
GEN_FATAL("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ptr = align_forward( end, alignment );
|
||||
arena->TotalUsed += total_size;
|
||||
|
||||
if ( flags & ALLOCATOR_FLAG_CLEAR_TO_ZERO )
|
||||
zero_size( ptr, size );
|
||||
// zpl__printf_err("%s", "Arena out of memory\n");
|
||||
GEN_FATAL("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
ptr = align_forward( end, alignment );
|
||||
arena->TotalUsed += total_size;
|
||||
|
||||
if ( flags & ALLOCATOR_FLAG_CLEAR_TO_ZERO )
|
||||
zero_size( ptr, size );
|
||||
}
|
||||
break;
|
||||
|
||||
case EAllocation_FREE :
|
||||
// NOTE: Free all at once
|
||||
|
@ -229,7 +229,6 @@ forceinline void check(Arena& arena) { return arena_check(& arena); }
|
||||
#pragma pop_macro("check")
|
||||
#endif
|
||||
|
||||
|
||||
inline
|
||||
AllocatorInfo arena_allocator_info( Arena* arena ) {
|
||||
GEN_ASSERT(arena != nullptr);
|
||||
@ -392,9 +391,9 @@ void pool_clear(Pool* pool);
|
||||
void pool_free(Pool* pool);
|
||||
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); }
|
||||
void clear(Pool& pool) { return pool_clear(& pool); }
|
||||
void free(Pool& pool) { return pool_free(& pool); }
|
||||
forceinline AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); }
|
||||
forceinline void clear(Pool& pool) { return pool_clear(& pool); }
|
||||
forceinline void free(Pool& pool) { return pool_free(& pool); }
|
||||
#endif
|
||||
|
||||
struct Pool
|
||||
|
@ -392,6 +392,7 @@ bool strbuilder_append_string(StrBuilder* str, StrBuilder const other) {
|
||||
return strbuilder_append_c_str_len(str, (char const*)other, strbuilder_length(other));
|
||||
}
|
||||
|
||||
inline
|
||||
bool strbuilder_append_fmt(StrBuilder* str, char const* fmt, ...) {
|
||||
GEN_ASSERT(str != nullptr);
|
||||
ssize res;
|
||||
|
@ -147,6 +147,7 @@ int gen_main()
|
||||
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open("gen/gen.dep.hpp");
|
||||
@ -168,6 +169,7 @@ int gen_main()
|
||||
header.print( strings );
|
||||
header.print( filesystem );
|
||||
header.print( timing );
|
||||
header.print(parsing);
|
||||
|
||||
header.print_fmt( "\nGEN_NS_END\n" );
|
||||
header.print( fmt_newline );
|
||||
@ -186,6 +188,7 @@ int gen_main()
|
||||
Code strings = scan_file( path_base "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.cpp" );
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.dep.cpp" );
|
||||
@ -204,6 +207,7 @@ int gen_main()
|
||||
src.print( strings );
|
||||
src.print( filesystem );
|
||||
src.print( timing );
|
||||
src.print( parsing );
|
||||
|
||||
src.print_fmt( "\nGEN_NS_END\n" );
|
||||
src.print( fmt_newline );
|
||||
@ -310,14 +314,20 @@ int gen_main()
|
||||
|
||||
src.print_fmt( "\n#pragma region Interface\n" );
|
||||
src.print( interface );
|
||||
|
||||
src.print( upfront );
|
||||
|
||||
src.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
src.print( lexer );
|
||||
src.print( parser_case_macros );
|
||||
src.print( parser );
|
||||
src.print( parsing_interface );
|
||||
src.print( untyped );
|
||||
src.print_fmt( "\n#pragma endregion Parsing\n\n" );
|
||||
|
||||
src.print_fmt( "\n#pragma region Untyped\n\n" );
|
||||
src.print( untyped );
|
||||
src.print_fmt( "#pragma endregion \n\n" );
|
||||
|
||||
src.print_fmt( "#pragma endregion Interface\n\n" );
|
||||
|
||||
src.print_fmt( "GEN_NS_END\n\n");
|
||||
@ -364,7 +374,6 @@ int gen_main()
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.hpp" );
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.hpp" );
|
||||
|
||||
Builder
|
||||
@ -375,7 +384,6 @@ int gen_main()
|
||||
header.print( fmt_newline );
|
||||
header.print( def_include( txt("gen.hpp") ) );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
header.print( parsing );
|
||||
header.print( scanner );
|
||||
header.print_fmt( "\nGEN_NS_END\n" );
|
||||
header.print( fmt_newline );
|
||||
@ -385,7 +393,6 @@ int gen_main()
|
||||
|
||||
// gen.scanner.cpp
|
||||
{
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.cpp" );
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.cpp" );
|
||||
|
||||
Builder
|
||||
@ -395,8 +402,7 @@ int gen_main()
|
||||
src.print( fmt_newline );
|
||||
src.print( def_include( txt("gen.scanner.hpp") ) );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
src.print( parsing );
|
||||
// src.print( scanner );
|
||||
src.print( scanner );
|
||||
src.print_fmt( "\nGEN_NS_END\n" );
|
||||
src.print( fmt_newline );
|
||||
src.print( pop_ignores );
|
||||
|
Loading…
Reference in New Issue
Block a user