mirror of
https://github.com/Ed94/gencpp.git
synced 2025-01-10 08:53:32 -08:00
Updated c_library generation to support latest changes with context struct (also prepped for static/dynamic linkage)
This commit is contained in:
parent
16d0e0834f
commit
b5cf633e98
@ -236,19 +236,19 @@ template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast(
|
||||
|
||||
#pragma region Code C-Interface
|
||||
|
||||
void code_append (Code code, Code other );
|
||||
Str code_debug_str (Code code);
|
||||
Code code_duplicate (Code code);
|
||||
Code* code_entry (Code code, u32 idx );
|
||||
bool code_has_entries (Code code);
|
||||
bool code_is_body (Code code);
|
||||
bool code_is_equal (Code code, Code other);
|
||||
bool code_is_valid (Code code);
|
||||
void code_set_global (Code code);
|
||||
StrBuilder code_to_strbuilder (Code self );
|
||||
void code_to_strbuilder_ptr(Code self, StrBuilder* result );
|
||||
Str code_type_str (Code self );
|
||||
bool code_validate_body (Code self );
|
||||
GEN_API void code_append (Code code, Code other );
|
||||
GEN_API Str code_debug_str (Code code);
|
||||
GEN_API Code code_duplicate (Code code);
|
||||
GEN_API Code* code_entry (Code code, u32 idx );
|
||||
GEN_API bool code_has_entries (Code code);
|
||||
GEN_API bool code_is_body (Code code);
|
||||
GEN_API bool code_is_equal (Code code, Code other);
|
||||
GEN_API bool code_is_valid (Code code);
|
||||
GEN_API void code_set_global (Code code);
|
||||
GEN_API StrBuilder code_to_strbuilder (Code self );
|
||||
GEN_API void code_to_strbuilder_ptr(Code self, StrBuilder* result );
|
||||
GEN_API Str code_type_str (Code self );
|
||||
GEN_API bool code_validate_body (Code self );
|
||||
|
||||
#pragma endregion Code C-Interface
|
||||
|
||||
@ -440,7 +440,7 @@ static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST is not size of AST_POD_S
|
||||
struct InvalidCode_ImplictCaster;
|
||||
#define InvalidCode (InvalidCode_ImplictCaster{})
|
||||
#else
|
||||
#define InvalidCode (void*){ (void*)_ctx->Code_Invalid }
|
||||
#define InvalidCode (void*){ (void*)Code_Invalid }
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
|
@ -1407,7 +1407,7 @@ void var_to_strbuilder_ref(CodeVar self, StrBuilder* result )
|
||||
if ( self->Attributes || self->Specs )
|
||||
{
|
||||
if ( self->Attributes )
|
||||
strbuilder_append_fmt( result, "%SB ", specifiers_to_strbuilder(self->Specs) );
|
||||
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
||||
|
||||
if ( self->Specs )
|
||||
strbuilder_append_fmt( result, "%SB\n", specifiers_to_strbuilder(self->Specs) );
|
||||
|
@ -17,128 +17,128 @@
|
||||
|
||||
#pragma region Code Type C-Interface
|
||||
|
||||
void body_append ( CodeBody body, Code other );
|
||||
void body_append_body ( CodeBody body, CodeBody other );
|
||||
StrBuilder body_to_strbuilder ( CodeBody body );
|
||||
void body_to_strbuilder_ref ( CodeBody body, StrBuilder* result );
|
||||
void body_to_strbuilder_export( CodeBody body, StrBuilder* result );
|
||||
GEN_API void body_append ( CodeBody body, Code other );
|
||||
GEN_API void body_append_body ( CodeBody body, CodeBody other );
|
||||
GEN_API StrBuilder body_to_strbuilder ( CodeBody body );
|
||||
GEN_API void body_to_strbuilder_ref ( CodeBody body, StrBuilder* result );
|
||||
GEN_API void body_to_strbuilder_export( CodeBody body, StrBuilder* result );
|
||||
|
||||
Code begin_CodeBody( CodeBody body);
|
||||
Code end_CodeBody ( CodeBody body );
|
||||
Code next_CodeBody ( CodeBody body, Code entry_iter );
|
||||
GEN_API Code begin_CodeBody( CodeBody body);
|
||||
GEN_API Code end_CodeBody ( CodeBody body );
|
||||
GEN_API Code next_CodeBody ( CodeBody body, Code entry_iter );
|
||||
|
||||
void class_add_interface ( CodeClass self, CodeTypename interface );
|
||||
StrBuilder class_to_strbuilder ( CodeClass self );
|
||||
void class_to_strbuilder_def( CodeClass self, StrBuilder* result );
|
||||
void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result );
|
||||
GEN_API void class_add_interface ( CodeClass self, CodeTypename interface );
|
||||
GEN_API StrBuilder class_to_strbuilder ( CodeClass self );
|
||||
GEN_API void class_to_strbuilder_def( CodeClass self, StrBuilder* result );
|
||||
GEN_API void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result );
|
||||
|
||||
void params_append (CodeParams params, CodeParams param );
|
||||
CodeParams params_get (CodeParams params, s32 idx);
|
||||
bool params_has_entries (CodeParams params );
|
||||
StrBuilder params_to_strbuilder (CodeParams params );
|
||||
void params_to_strbuilder_ref(CodeParams params, StrBuilder* result );
|
||||
GEN_API void params_append (CodeParams params, CodeParams param );
|
||||
GEN_API CodeParams params_get (CodeParams params, s32 idx);
|
||||
GEN_API bool params_has_entries (CodeParams params );
|
||||
GEN_API StrBuilder params_to_strbuilder (CodeParams params );
|
||||
GEN_API void params_to_strbuilder_ref(CodeParams params, StrBuilder* result );
|
||||
|
||||
CodeParams begin_CodeParams(CodeParams params);
|
||||
CodeParams end_CodeParams (CodeParams params);
|
||||
CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter);
|
||||
GEN_API CodeParams begin_CodeParams(CodeParams params);
|
||||
GEN_API CodeParams end_CodeParams (CodeParams params);
|
||||
GEN_API CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter);
|
||||
|
||||
bool specifiers_append (CodeSpecifiers specifiers, Specifier spec);
|
||||
s32 specifiers_has (CodeSpecifiers specifiers, Specifier spec);
|
||||
s32 specifiers_remove (CodeSpecifiers specifiers, Specifier to_remove );
|
||||
StrBuilder specifiers_to_strbuilder (CodeSpecifiers specifiers);
|
||||
void specifiers_to_strbuilder_ref(CodeSpecifiers specifiers, StrBuilder* result);
|
||||
GEN_API bool specifiers_append (CodeSpecifiers specifiers, Specifier spec);
|
||||
GEN_API s32 specifiers_has (CodeSpecifiers specifiers, Specifier spec);
|
||||
GEN_API s32 specifiers_remove (CodeSpecifiers specifiers, Specifier to_remove );
|
||||
GEN_API StrBuilder specifiers_to_strbuilder (CodeSpecifiers specifiers);
|
||||
GEN_API void specifiers_to_strbuilder_ref(CodeSpecifiers specifiers, StrBuilder* result);
|
||||
|
||||
Specifier* begin_CodeSpecifiers(CodeSpecifiers specifiers);
|
||||
Specifier* end_CodeSpecifiers (CodeSpecifiers specifiers);
|
||||
Specifier* next_CodeSpecifiers (CodeSpecifiers specifiers, Specifier* spec_iter);
|
||||
GEN_API Specifier* begin_CodeSpecifiers(CodeSpecifiers specifiers);
|
||||
GEN_API Specifier* end_CodeSpecifiers (CodeSpecifiers specifiers);
|
||||
GEN_API Specifier* next_CodeSpecifiers (CodeSpecifiers specifiers, Specifier* spec_iter);
|
||||
|
||||
void struct_add_interface (CodeStruct self, CodeTypename interface);
|
||||
StrBuilder struct_to_strbuilder (CodeStruct self);
|
||||
void struct_to_strbuilder_fwd(CodeStruct self, StrBuilder* result);
|
||||
void struct_to_strbuilder_def(CodeStruct self, StrBuilder* result);
|
||||
GEN_API void struct_add_interface (CodeStruct self, CodeTypename interface);
|
||||
GEN_API StrBuilder struct_to_strbuilder (CodeStruct self);
|
||||
GEN_API void struct_to_strbuilder_fwd(CodeStruct self, StrBuilder* result);
|
||||
GEN_API void struct_to_strbuilder_def(CodeStruct self, StrBuilder* result);
|
||||
|
||||
StrBuilder attributes_to_strbuilder (CodeAttributes attributes);
|
||||
void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result);
|
||||
GEN_API StrBuilder attributes_to_strbuilder (CodeAttributes attributes);
|
||||
GEN_API void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result);
|
||||
|
||||
StrBuilder comment_to_strbuilder (CodeComment comment );
|
||||
void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result );
|
||||
GEN_API StrBuilder comment_to_strbuilder (CodeComment comment );
|
||||
GEN_API void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result );
|
||||
|
||||
StrBuilder constructor_to_strbuilder (CodeConstructor constructor);
|
||||
void constructor_to_strbuilder_def(CodeConstructor constructor, StrBuilder* result );
|
||||
void constructor_to_strbuilder_fwd(CodeConstructor constructor, StrBuilder* result );
|
||||
GEN_API StrBuilder constructor_to_strbuilder (CodeConstructor constructor);
|
||||
GEN_API void constructor_to_strbuilder_def(CodeConstructor constructor, StrBuilder* result );
|
||||
GEN_API void constructor_to_strbuilder_fwd(CodeConstructor constructor, StrBuilder* result );
|
||||
|
||||
StrBuilder define_to_strbuilder (CodeDefine self);
|
||||
void define_to_strbuilder_ref(CodeDefine self, StrBuilder* result);
|
||||
GEN_API StrBuilder define_to_strbuilder (CodeDefine self);
|
||||
GEN_API void define_to_strbuilder_ref(CodeDefine self, StrBuilder* result);
|
||||
|
||||
StrBuilder destructor_to_strbuilder (CodeDestructor destructor);
|
||||
void destructor_to_strbuilder_fwd(CodeDestructor destructor, StrBuilder* result );
|
||||
void destructor_to_strbuilder_def(CodeDestructor destructor, StrBuilder* result );
|
||||
GEN_API StrBuilder destructor_to_strbuilder (CodeDestructor destructor);
|
||||
GEN_API void destructor_to_strbuilder_fwd(CodeDestructor destructor, StrBuilder* result );
|
||||
GEN_API void destructor_to_strbuilder_def(CodeDestructor destructor, StrBuilder* result );
|
||||
|
||||
StrBuilder enum_to_strbuilder (CodeEnum self);
|
||||
void enum_to_strbuilder_def (CodeEnum self, StrBuilder* result );
|
||||
void enum_to_strbuilder_fwd (CodeEnum self, StrBuilder* result );
|
||||
void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result );
|
||||
void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result );
|
||||
GEN_API StrBuilder enum_to_strbuilder (CodeEnum self);
|
||||
GEN_API void enum_to_strbuilder_def (CodeEnum self, StrBuilder* result );
|
||||
GEN_API void enum_to_strbuilder_fwd (CodeEnum self, StrBuilder* result );
|
||||
GEN_API void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result );
|
||||
GEN_API void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result );
|
||||
|
||||
StrBuilder exec_to_strbuilder (CodeExec exec);
|
||||
void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result);
|
||||
GEN_API StrBuilder exec_to_strbuilder (CodeExec exec);
|
||||
GEN_API void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result);
|
||||
|
||||
void extern_to_strbuilder(CodeExtern self, StrBuilder* result);
|
||||
GEN_API void extern_to_strbuilder(CodeExtern self, StrBuilder* result);
|
||||
|
||||
StrBuilder include_to_strbuilder (CodeInclude self);
|
||||
void include_to_strbuilder_ref(CodeInclude self, StrBuilder* result);
|
||||
GEN_API StrBuilder include_to_strbuilder (CodeInclude self);
|
||||
GEN_API void include_to_strbuilder_ref(CodeInclude self, StrBuilder* result);
|
||||
|
||||
StrBuilder friend_to_strbuilder (CodeFriend self);
|
||||
void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result);
|
||||
GEN_API StrBuilder friend_to_strbuilder (CodeFriend self);
|
||||
GEN_API void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result);
|
||||
|
||||
StrBuilder fn_to_strbuilder (CodeFn self);
|
||||
void fn_to_strbuilder_def(CodeFn self, StrBuilder* result);
|
||||
void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result);
|
||||
GEN_API StrBuilder fn_to_strbuilder (CodeFn self);
|
||||
GEN_API void fn_to_strbuilder_def(CodeFn self, StrBuilder* result);
|
||||
GEN_API void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result);
|
||||
|
||||
StrBuilder module_to_strbuilder (CodeModule self);
|
||||
void module_to_strbuilder_ref(CodeModule self, StrBuilder* result);
|
||||
GEN_API StrBuilder module_to_strbuilder (CodeModule self);
|
||||
GEN_API void module_to_strbuilder_ref(CodeModule self, StrBuilder* result);
|
||||
|
||||
StrBuilder namespace_to_strbuilder (CodeNS self);
|
||||
void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result);
|
||||
GEN_API StrBuilder namespace_to_strbuilder (CodeNS self);
|
||||
GEN_API void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result);
|
||||
|
||||
StrBuilder code_op_to_strbuilder (CodeOperator self);
|
||||
void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result );
|
||||
void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result );
|
||||
GEN_API StrBuilder code_op_to_strbuilder (CodeOperator self);
|
||||
GEN_API void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result );
|
||||
GEN_API void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result );
|
||||
|
||||
StrBuilder opcast_to_strbuilder (CodeOpCast op_cast );
|
||||
void opcast_to_strbuilder_def(CodeOpCast op_cast, StrBuilder* result );
|
||||
void opcast_to_strbuilder_fwd(CodeOpCast op_cast, StrBuilder* result );
|
||||
GEN_API StrBuilder opcast_to_strbuilder (CodeOpCast op_cast );
|
||||
GEN_API void opcast_to_strbuilder_def(CodeOpCast op_cast, StrBuilder* result );
|
||||
GEN_API void opcast_to_strbuilder_fwd(CodeOpCast op_cast, StrBuilder* result );
|
||||
|
||||
StrBuilder pragma_to_strbuilder (CodePragma self);
|
||||
void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result);
|
||||
GEN_API StrBuilder pragma_to_strbuilder (CodePragma self);
|
||||
GEN_API void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result);
|
||||
|
||||
StrBuilder preprocess_to_strbuilder (CodePreprocessCond cond);
|
||||
void preprocess_to_strbuilder_if (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_ifdef (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_elif (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_else (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_endif (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API StrBuilder preprocess_to_strbuilder (CodePreprocessCond cond);
|
||||
GEN_API void preprocess_to_strbuilder_if (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_ifdef (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_elif (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_else (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_endif (CodePreprocessCond cond, StrBuilder* result );
|
||||
|
||||
StrBuilder template_to_strbuilder (CodeTemplate self);
|
||||
void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result);
|
||||
GEN_API StrBuilder template_to_strbuilder (CodeTemplate self);
|
||||
GEN_API void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result);
|
||||
|
||||
StrBuilder typename_to_strbuilder (CodeTypename self);
|
||||
void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result);
|
||||
GEN_API StrBuilder typename_to_strbuilder (CodeTypename self);
|
||||
GEN_API void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result);
|
||||
|
||||
StrBuilder typedef_to_strbuilder (CodeTypedef self);
|
||||
void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result );
|
||||
GEN_API StrBuilder typedef_to_strbuilder (CodeTypedef self);
|
||||
GEN_API void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result );
|
||||
|
||||
StrBuilder union_to_strbuilder (CodeUnion self);
|
||||
void union_to_strbuilder_def(CodeUnion self, StrBuilder* result);
|
||||
void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result);
|
||||
GEN_API StrBuilder union_to_strbuilder (CodeUnion self);
|
||||
GEN_API void union_to_strbuilder_def(CodeUnion self, StrBuilder* result);
|
||||
GEN_API void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result);
|
||||
|
||||
StrBuilder using_to_strbuilder (CodeUsing op_cast );
|
||||
void using_to_strbuilder_ref(CodeUsing op_cast, StrBuilder* result );
|
||||
void using_to_strbuilder_ns (CodeUsing op_cast, StrBuilder* result );
|
||||
GEN_API StrBuilder using_to_strbuilder (CodeUsing op_cast );
|
||||
GEN_API void using_to_strbuilder_ref(CodeUsing op_cast, StrBuilder* result );
|
||||
GEN_API void using_to_strbuilder_ns (CodeUsing op_cast, StrBuilder* result );
|
||||
|
||||
StrBuilder var_to_strbuilder (CodeVar self);
|
||||
void var_to_strbuilder_ref(CodeVar self, StrBuilder* result);
|
||||
GEN_API StrBuilder var_to_strbuilder (CodeVar self);
|
||||
GEN_API void var_to_strbuilder_ref(CodeVar self, StrBuilder* result);
|
||||
|
||||
#pragma endregion Code Type C-Interface
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" )
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_GEN_API, "GEN_API" )
|
||||
|
||||
enum TokType : u32
|
||||
{
|
||||
@ -104,8 +104,7 @@ enum TokType : u32
|
||||
Tok_Type_MS_W64,
|
||||
Tok_Varadic_Argument,
|
||||
Tok___Attributes_Start,
|
||||
Tok_Attribute_API_Export,
|
||||
Tok_Attribute_API_Import,
|
||||
Tok_Attribute_GEN_API,
|
||||
Tok_NumTokens
|
||||
};
|
||||
|
||||
@ -207,8 +206,7 @@ inline Str toktype_to_str( TokType type )
|
||||
{ "_W64", sizeof( "_W64" ) - 1 },
|
||||
{ "...", sizeof( "..." ) - 1 },
|
||||
{ "__attrib_start__", sizeof( "__attrib_start__" ) - 1 },
|
||||
{ "GEN_API_Export_Code", sizeof( "GEN_API_Export_Code" ) - 1 },
|
||||
{ "GEN_API_Import_Code", sizeof( "GEN_API_Import_Code" ) - 1 },
|
||||
{ "GEN_API", sizeof( "GEN_API" ) - 1 },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
@ -468,5 +468,5 @@ void set_preprocess_define( Str id, b32 is_functional ) {
|
||||
if (is_functional) {
|
||||
strbuilder_append_char( & builder, '(' );
|
||||
}
|
||||
array_append( _ctx->PreprocessorDefines, cache_str(builder) );
|
||||
array_append( _ctx->PreprocessorDefines, cache_str( strbuilder_to_str(builder)) );
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ struct LogEntry
|
||||
typedef void LoggerCallback(LogEntry entry);
|
||||
#endif
|
||||
|
||||
|
||||
// Note(Ed): This is subject to heavily change
|
||||
// with upcoming changes to the library's fallback (default) allocations strategy;
|
||||
// and major changes to lexer/parser context usage.
|
||||
@ -51,7 +50,6 @@ struct Context
|
||||
|
||||
// LoggerCallaback* log_callback; // TODO(Ed): Impl user logger callback as an option.
|
||||
|
||||
//
|
||||
u32 Max_CommentLineLength; // Used by def_comment
|
||||
u32 Max_StrCacheLength; // Any cached string longer than this is always allocated again.
|
||||
|
||||
@ -99,39 +97,39 @@ struct Context
|
||||
};
|
||||
|
||||
// Initialize the library. There first ctx initialized must exist for lifetime of other contextes that come after as its the one that
|
||||
void init(Context* ctx);
|
||||
GEN_API void init(Context* ctx);
|
||||
|
||||
// Currently manually free's the arenas, code for checking for leaks.
|
||||
// However on Windows at least, it doesn't need to occur as the OS will clean up after the process.
|
||||
void deinit(Context* ctx);
|
||||
GEN_API void deinit(Context* ctx);
|
||||
|
||||
// Clears the allocations, but doesn't return to the heap, the calls init() again.
|
||||
// Clears the allocations, but doesn't free the memoery, then calls init() again.
|
||||
// Ease of use.
|
||||
void reset(Context* ctx);
|
||||
GEN_API void reset(Context* ctx);
|
||||
|
||||
void set_context(Context* ctx);
|
||||
GEN_API void set_context(Context* ctx);
|
||||
|
||||
// Alternative way to add a preprocess define entry for the lexer & parser to utilize
|
||||
// if the user doesn't want to use def_define
|
||||
void set_preprocess_define( Str id, b32 is_functional );
|
||||
GEN_API void set_preprocess_define( Str id, b32 is_functional );
|
||||
|
||||
// Used internally to retrive or make string allocations.
|
||||
// Strings are stored in a series of string arenas of fixed size (SizePer_StringArena)
|
||||
StrCached cache_str( Str str );
|
||||
GEN_API StrCached cache_str( Str str );
|
||||
|
||||
/*
|
||||
This provides a fresh Code AST.
|
||||
The gen interface use this as their method from getting a new AST object from the CodePool.
|
||||
Use this if you want to make your own API for formatting the supported Code Types.
|
||||
*/
|
||||
Code make_code();
|
||||
GEN_API Code make_code();
|
||||
|
||||
// Set these before calling gen's init() procedure.
|
||||
|
||||
#pragma region Upfront
|
||||
|
||||
CodeAttributes def_attributes( Str content );
|
||||
CodeComment def_comment ( Str content );
|
||||
GEN_API CodeAttributes def_attributes( Str content );
|
||||
GEN_API CodeComment def_comment ( Str content );
|
||||
|
||||
struct Opts_def_struct {
|
||||
CodeBody body;
|
||||
@ -142,25 +140,25 @@ struct Opts_def_struct {
|
||||
s32 num_interfaces;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeClass def_class( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeClass def_class( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_constructor {
|
||||
CodeParams params;
|
||||
Code initializer_list;
|
||||
Code body;
|
||||
};
|
||||
CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_define {
|
||||
b32 dont_append_preprocess_defines;
|
||||
};
|
||||
CodeDefine def_define( Str name, Str content, Opts_def_define opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeDefine def_define( Str name, Str content, Opts_def_define opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_destructor {
|
||||
Code body;
|
||||
CodeSpecifiers specifiers;
|
||||
};
|
||||
CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_enum {
|
||||
CodeBody body;
|
||||
@ -170,11 +168,11 @@ struct Opts_def_enum {
|
||||
ModuleFlag mflags;
|
||||
Code type_macro;
|
||||
};
|
||||
CodeEnum def_enum( Str name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeEnum def_enum( Str name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
||||
|
||||
CodeExec def_execution ( Str content );
|
||||
CodeExtern def_extern_link( Str name, CodeBody body );
|
||||
CodeFriend def_friend ( Code symbol );
|
||||
GEN_API CodeExec def_execution ( Str content );
|
||||
GEN_API CodeExtern def_extern_link( Str name, CodeBody body );
|
||||
GEN_API CodeFriend def_friend ( Code symbol );
|
||||
|
||||
struct Opts_def_function {
|
||||
CodeParams params;
|
||||
@ -184,14 +182,14 @@ struct Opts_def_function {
|
||||
CodeAttributes attrs;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeFn def_function( Str name, Opts_def_function opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeFn def_function( Str name, Opts_def_function opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_include { b32 foreign; };
|
||||
struct Opts_def_module { ModuleFlag mflags; };
|
||||
struct Opts_def_namespace { ModuleFlag mflags; };
|
||||
CodeInclude def_include ( Str content, Opts_def_include opts GEN_PARAM_DEFAULT );
|
||||
CodeModule def_module ( Str name, Opts_def_module opts GEN_PARAM_DEFAULT );
|
||||
CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeInclude def_include ( Str content, Opts_def_include opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeModule def_module ( Str name, Opts_def_module opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_operator {
|
||||
CodeParams params;
|
||||
@ -201,26 +199,26 @@ struct Opts_def_operator {
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_operator_cast {
|
||||
CodeBody body;
|
||||
CodeSpecifiers specs;
|
||||
};
|
||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_param { Code value; };
|
||||
CodeParams def_param ( CodeTypename type, Str name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
||||
CodePragma def_pragma( Str directive );
|
||||
GEN_API CodeParams def_param ( CodeTypename type, Str name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodePragma def_pragma( Str directive );
|
||||
|
||||
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, Str content );
|
||||
GEN_API CodePreprocessCond def_preprocess_cond( EPreprocessCond type, Str content );
|
||||
|
||||
CodeSpecifiers def_specifier( Specifier specifier );
|
||||
GEN_API CodeSpecifiers def_specifier( Specifier specifier );
|
||||
|
||||
CodeStruct def_struct( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeStruct def_struct( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_template { ModuleFlag mflags; };
|
||||
CodeTemplate def_template( CodeParams params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeTemplate def_template( CodeParams params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_type {
|
||||
ETypenameTag type_tag;
|
||||
@ -228,27 +226,27 @@ struct Opts_def_type {
|
||||
CodeSpecifiers specifiers;
|
||||
CodeAttributes attributes;
|
||||
};
|
||||
CodeTypename def_type( Str name, Opts_def_type opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeTypename def_type( Str name, Opts_def_type opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_typedef {
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_union {
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeUnion def_union( Str name, CodeBody body, Opts_def_union opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeUnion def_union( Str name, CodeBody body, Opts_def_union opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_using {
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeUsing def_using( Str name, CodeTypename type, Opts_def_using opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeUsing def_using( Str name, CodeTypename type, Opts_def_using opts GEN_PARAM_DEFAULT );
|
||||
|
||||
CodeUsing def_using_namespace( Str name );
|
||||
GEN_API CodeUsing def_using_namespace( Str name );
|
||||
|
||||
struct Opts_def_variable
|
||||
{
|
||||
@ -257,36 +255,36 @@ struct Opts_def_variable
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opts GEN_PARAM_DEFAULT );
|
||||
|
||||
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
|
||||
CodeBody def_body( CodeType type );
|
||||
GEN_API CodeBody def_body( CodeType type );
|
||||
|
||||
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
|
||||
/// or provide as an array of Code objects.
|
||||
|
||||
CodeBody def_class_body ( s32 num, ... );
|
||||
CodeBody def_class_body ( s32 num, Code* codes );
|
||||
CodeBody def_enum_body ( s32 num, ... );
|
||||
CodeBody def_enum_body ( s32 num, Code* codes );
|
||||
CodeBody def_export_body ( s32 num, ... );
|
||||
CodeBody def_export_body ( s32 num, Code* codes);
|
||||
CodeBody def_extern_link_body( s32 num, ... );
|
||||
CodeBody def_extern_link_body( s32 num, Code* codes );
|
||||
CodeBody def_function_body ( s32 num, ... );
|
||||
CodeBody def_function_body ( s32 num, Code* codes );
|
||||
CodeBody def_global_body ( s32 num, ... );
|
||||
CodeBody def_global_body ( s32 num, Code* codes );
|
||||
CodeBody def_namespace_body ( s32 num, ... );
|
||||
CodeBody def_namespace_body ( s32 num, Code* codes );
|
||||
CodeParams def_params ( s32 num, ... );
|
||||
CodeParams def_params ( s32 num, CodeParams* params );
|
||||
CodeSpecifiers def_specifiers ( s32 num, ... );
|
||||
CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
|
||||
CodeBody def_struct_body ( s32 num, ... );
|
||||
CodeBody def_struct_body ( s32 num, Code* codes );
|
||||
CodeBody def_union_body ( s32 num, ... );
|
||||
CodeBody def_union_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_class_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_class_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_enum_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_enum_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_export_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_export_body ( s32 num, Code* codes);
|
||||
GEN_API CodeBody def_extern_link_body( s32 num, ... );
|
||||
GEN_API CodeBody def_extern_link_body( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_function_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_function_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_global_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_global_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_namespace_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_namespace_body ( s32 num, Code* codes );
|
||||
GEN_API CodeParams def_params ( s32 num, ... );
|
||||
GEN_API CodeParams def_params ( s32 num, CodeParams* params );
|
||||
GEN_API CodeSpecifiers def_specifiers ( s32 num, ... );
|
||||
GEN_API CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
|
||||
GEN_API CodeBody def_struct_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_struct_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_union_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_union_body ( s32 num, Code* codes );
|
||||
|
||||
#pragma endregion Upfront
|
||||
|
||||
@ -326,37 +324,37 @@ struct ParseInfo
|
||||
CodeBody parse_file( Str path );
|
||||
#endif
|
||||
|
||||
CodeClass parse_class ( Str class_def );
|
||||
CodeConstructor parse_constructor ( Str constructor_def );
|
||||
CodeDestructor parse_destructor ( Str destructor_def );
|
||||
CodeEnum parse_enum ( Str enum_def );
|
||||
CodeBody parse_export_body ( Str export_def );
|
||||
CodeExtern parse_extern_link ( Str exten_link_def );
|
||||
CodeFriend parse_friend ( Str friend_def );
|
||||
CodeFn parse_function ( Str fn_def );
|
||||
CodeBody parse_global_body ( Str body_def );
|
||||
CodeNS parse_namespace ( Str namespace_def );
|
||||
CodeOperator parse_operator ( Str operator_def );
|
||||
CodeOpCast parse_operator_cast( Str operator_def );
|
||||
CodeStruct parse_struct ( Str struct_def );
|
||||
CodeTemplate parse_template ( Str template_def );
|
||||
CodeTypename parse_type ( Str type_def );
|
||||
CodeTypedef parse_typedef ( Str typedef_def );
|
||||
CodeUnion parse_union ( Str union_def );
|
||||
CodeUsing parse_using ( Str using_def );
|
||||
CodeVar parse_variable ( Str var_def );
|
||||
GEN_API CodeClass parse_class ( Str class_def );
|
||||
GEN_API CodeConstructor parse_constructor ( Str constructor_def );
|
||||
GEN_API CodeDestructor parse_destructor ( Str destructor_def );
|
||||
GEN_API CodeEnum parse_enum ( Str enum_def );
|
||||
GEN_API CodeBody parse_export_body ( Str export_def );
|
||||
GEN_API CodeExtern parse_extern_link ( Str exten_link_def );
|
||||
GEN_API CodeFriend parse_friend ( Str friend_def );
|
||||
GEN_API CodeFn parse_function ( Str fn_def );
|
||||
GEN_API CodeBody parse_global_body ( Str body_def );
|
||||
GEN_API CodeNS parse_namespace ( Str namespace_def );
|
||||
GEN_API CodeOperator parse_operator ( Str operator_def );
|
||||
GEN_API CodeOpCast parse_operator_cast( Str operator_def );
|
||||
GEN_API CodeStruct parse_struct ( Str struct_def );
|
||||
GEN_API CodeTemplate parse_template ( Str template_def );
|
||||
GEN_API CodeTypename parse_type ( Str type_def );
|
||||
GEN_API CodeTypedef parse_typedef ( Str typedef_def );
|
||||
GEN_API CodeUnion parse_union ( Str union_def );
|
||||
GEN_API CodeUsing parse_using ( Str using_def );
|
||||
GEN_API CodeVar parse_variable ( Str var_def );
|
||||
|
||||
#pragma endregion Parsing
|
||||
|
||||
#pragma region Untyped text
|
||||
|
||||
ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va );
|
||||
GEN_API ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va );
|
||||
//! Do not use directly. Use the token_fmt macro instead.
|
||||
Str token_fmt_impl( ssize, ... );
|
||||
GEN_API Str token_fmt_impl( ssize, ... );
|
||||
|
||||
Code untyped_str ( Str content);
|
||||
Code untyped_fmt ( char const* fmt, ... );
|
||||
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
|
||||
GEN_API Code untyped_str( Str content);
|
||||
GEN_API Code untyped_fmt ( char const* fmt, ... );
|
||||
GEN_API Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
|
||||
|
||||
#pragma endregion Untyped text
|
||||
|
||||
|
@ -17,7 +17,6 @@ StrBuilder tok_to_strbuilder(Token tok)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool lex__eat( TokArray* self, TokType type );
|
||||
|
||||
Token* lex_current(TokArray* self, bool skip_formatting )
|
||||
|
@ -5,6 +5,24 @@
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#if GEN_COMPILER_MSVC
|
||||
#ifdef GEN_DYN_LINK
|
||||
#ifdef GEN_EXPORTS
|
||||
#define GEN_API __declspec(dllexport)
|
||||
#else
|
||||
#define GEN_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define GEN_API // Empty for static builds
|
||||
#endif
|
||||
#else
|
||||
#ifdef GEN_DYN_LINK
|
||||
#define GEN_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define GEN_API // Empty for static builds
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef global
|
||||
#define global static // Global variables
|
||||
#endif
|
||||
@ -69,8 +87,13 @@
|
||||
#endif
|
||||
|
||||
#ifndef do_once
|
||||
#define do_once() for ( local_persist b32 once = true; once; once = false )
|
||||
#define do_once_defer( statement ) for ( local_persist b32 once = true; once; once = false, (statement) )
|
||||
#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_start \
|
||||
do \
|
||||
|
@ -1,2 +1 @@
|
||||
API_Export, GEN_API_Export_Code
|
||||
API_Import, GEN_API_Import_Code
|
||||
GEN_API, GEN_API
|
||||
|
|
@ -62,20 +62,21 @@ constexpr bool helper_use_c_definition = true;
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
Context ctx {};
|
||||
gen::init(& ctx);
|
||||
|
||||
PreprocessorDefines.append(txt("GEN_API_C_BEGIN"));
|
||||
PreprocessorDefines.append(txt("GEN_API_C_END"));
|
||||
PreprocessorDefines.append(txt("Array("));
|
||||
PreprocessorDefines.append(txt("HashTable("));
|
||||
PreprocessorDefines.append(txt("GEN_NS_PARSER"));
|
||||
PreprocessorDefines.append(txt("GEN_NS_PARSER_BEGIN"));
|
||||
PreprocessorDefines.append(txt("GEN_NS_PARSER_END"));
|
||||
PreprocessorDefines.append(txt("Using_Code("));
|
||||
PreprocessorDefines.append(txt("Using_CodeOps("));
|
||||
PreprocessorDefines.append(txt("GEN_OPTIMIZE_MAPPINGS_BEGIN"));
|
||||
PreprocessorDefines.append(txt("GEN_OPITMIZE_MAPPINGS_END"));
|
||||
PreprocessorDefines.append(txt("GEN_PARAM_DEFAULT"));
|
||||
ctx.PreprocessorDefines.append(txt("GEN_API_C_BEGIN"));
|
||||
ctx.PreprocessorDefines.append(txt("GEN_API_C_END"));
|
||||
ctx.PreprocessorDefines.append(txt("Array("));
|
||||
ctx.PreprocessorDefines.append(txt("HashTable("));
|
||||
ctx.PreprocessorDefines.append(txt("GEN_NS_PARSER"));
|
||||
ctx.PreprocessorDefines.append(txt("GEN_NS_PARSER_BEGIN"));
|
||||
ctx.PreprocessorDefines.append(txt("GEN_NS_PARSER_END"));
|
||||
ctx.PreprocessorDefines.append(txt("Using_Code("));
|
||||
ctx.PreprocessorDefines.append(txt("Using_CodeOps("));
|
||||
ctx.PreprocessorDefines.append(txt("GEN_OPTIMIZE_MAPPINGS_BEGIN"));
|
||||
ctx.PreprocessorDefines.append(txt("GEN_OPITMIZE_MAPPINGS_END"));
|
||||
ctx.PreprocessorDefines.append(txt("GEN_PARAM_DEFAULT"));
|
||||
//PreprocessorDefines.append(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"));
|
||||
|
||||
Code push_ignores = scan_file( path_base "helpers/push_ignores.inline.hpp" );
|
||||
@ -253,7 +254,7 @@ do \
|
||||
}
|
||||
|
||||
Code array_ssize = gen_array(txt("gen_ssize"), txt("Array_gen_ssize"));
|
||||
Code array_string_cached = gen_array(txt("gen_StringCached"), txt("Array_gen_StringCached"));
|
||||
Code array_string_cached = gen_array(txt("gen_StrCached"), txt("Array_gen_StrCached"));
|
||||
|
||||
CodeBody parsed_header_strings = parse_file( path_base "dependencies/strings.hpp" );
|
||||
CodeBody header_strings = def_body(CT_Global_Body);
|
||||
@ -588,8 +589,102 @@ do \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody array_token = gen_array(txt("gen_Token"), txt("Array_gen_Token"));
|
||||
|
||||
CodeBody parsed_parser_types = parse_file( path_base "components/parser_types.hpp" );
|
||||
CodeBody parser_types = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_parser_types.begin(); entry != parsed_parser_types.end(); ++ entry ) switch(entry->Type)
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_parser_types, parser_types );
|
||||
if (found) break;
|
||||
|
||||
parser_types.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Enum:
|
||||
{
|
||||
if (entry->Name.Len)
|
||||
{
|
||||
convert_cpp_enum_to_c(cast(CodeEnum, entry), parser_types);
|
||||
break;
|
||||
}
|
||||
|
||||
parser_types.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Struct:
|
||||
{
|
||||
if ( entry->Name.is_equal(txt("Token")))
|
||||
{
|
||||
// Add struct Token forward and typedef early.
|
||||
CodeStruct token_fwd = parse_struct(code( struct Token; ));
|
||||
CodeTypedef token_typedef = parse_typedef(code( typedef struct Token Token; ));
|
||||
parser_types.append(token_fwd);
|
||||
parser_types.append(token_typedef);
|
||||
|
||||
// Skip typedef since we added it
|
||||
b32 continue_for = true;
|
||||
for (Code array_entry = array_token.begin(); continue_for && array_entry != array_token.end(); ++ array_entry) switch (array_entry->Type)
|
||||
{
|
||||
case CT_Typedef:
|
||||
{
|
||||
// pop the array entry
|
||||
array_token->NumEntries -= 1;
|
||||
Code next = array_entry->Next;
|
||||
Code prev = array_entry->Prev;
|
||||
next->Prev = array_entry->Prev;
|
||||
prev->Next = next;
|
||||
if ( array_token->Front == array_entry )
|
||||
array_token->Front = next;
|
||||
|
||||
parser_types.append(array_entry);
|
||||
continue_for = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Append the struct
|
||||
parser_types.append(entry);
|
||||
|
||||
// Append the token array
|
||||
parser_types.append(array_token);
|
||||
continue;
|
||||
}
|
||||
|
||||
CodeTypedef struct_tdef = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct <name> <name>; )));
|
||||
parser_types.append(struct_tdef);
|
||||
parser_types.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_strbuilder().to_str()
|
||||
, "#define <name> (<type>) <value>\n"
|
||||
));
|
||||
parser_types.append(define_ver);
|
||||
continue;
|
||||
}
|
||||
parser_types.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
parser_types.append(entry);
|
||||
break;
|
||||
}
|
||||
|
||||
// Used to track which functions need generic selectors.
|
||||
Array(CodeFn) code_c_interface = array_init_reserve<CodeFn>(FallbackAllocator, 16);
|
||||
Array(CodeFn) code_c_interface = array_init_reserve<CodeFn>(_ctx->Allocator_Temp, 16);
|
||||
|
||||
CodeBody parsed_ast = parse_file( path_base "components/ast.hpp" );
|
||||
CodeBody ast = def_body(CT_Global_Body);
|
||||
@ -647,7 +742,7 @@ do \
|
||||
{
|
||||
Str old_prefix = txt("code_");
|
||||
Str actual_name = { fn->Name.Ptr + old_prefix.Len, fn->Name.Len - old_prefix.Len };
|
||||
StrBuilder new_name = StrBuilder::fmt_buf(FallbackAllocator, "code__%S", actual_name );
|
||||
StrBuilder new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "code__%S", actual_name );
|
||||
|
||||
fn->Name = cache_str(new_name);
|
||||
code_c_interface.append(fn);
|
||||
@ -791,17 +886,17 @@ R"(#define AST_ArrSpecs_Cap \
|
||||
default: gen_generic_selection (Fail case) \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( code, ... ) \
|
||||
*/
|
||||
StrBuilder generic_selector = StrBuilder::make_reserve(FallbackAllocator, kilobytes(2));
|
||||
StrBuilder generic_selector = StrBuilder::make_reserve(_ctx->Allocator_Temp, kilobytes(2));
|
||||
for ( CodeFn fn : code_c_interface )
|
||||
{
|
||||
generic_selector.clear();
|
||||
Str private_prefix = txt("code__");
|
||||
Str actual_name = { fn->Name.Ptr + private_prefix.Len, fn->Name.Len - private_prefix.Len };
|
||||
StrBuilder interface_name = StrBuilder::fmt_buf(FallbackAllocator, "code_%S", actual_name );
|
||||
StrBuilder interface_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "code_%S", actual_name );
|
||||
|
||||
// Resolve generic's arguments
|
||||
b32 has_args = fn->Params->NumEntries > 1;
|
||||
StrBuilder params_str = StrBuilder::make_reserve(FallbackAllocator, 32);
|
||||
StrBuilder params_str = StrBuilder::make_reserve(_ctx->Allocator_Temp, 32);
|
||||
for (CodeParams param = fn->Params->Next; param != fn->Params.end(); ++ param) {
|
||||
// We skip the first parameter as its always going to be the code for selection
|
||||
if (param->Next == nullptr) {
|
||||
@ -910,6 +1005,9 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody array_arena = gen_array(txt("gen_Arena"), txt("Array_gen_Arena"));
|
||||
CodeBody array_pool = gen_array(txt("gen_Pool"), txt("Array_gen_Pool"));
|
||||
|
||||
CodeBody parsed_interface = parse_file( path_base "components/interface.hpp" );
|
||||
CodeBody interface = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_interface.begin(); entry != parsed_interface.end(); ++ entry ) switch( entry->Type )
|
||||
@ -931,7 +1029,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
|
||||
if (prev && prev->Name.is_equal(entry->Name)) {
|
||||
// rename second definition so there isn't a symbol conflict
|
||||
StrBuilder postfix_arr = StrBuilder::fmt_buf(FallbackAllocator, "%S_arr", entry->Name);
|
||||
StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", entry->Name);
|
||||
entry->Name = cache_str(postfix_arr.to_str());
|
||||
postfix_arr.free();
|
||||
}
|
||||
@ -942,11 +1040,11 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
// Convert the definition to use a default struct: https://vxtwitter.com/vkrajacic/status/1749816169736073295
|
||||
Str prefix = txt("def_");
|
||||
Str actual_name = { fn->Name.Ptr + prefix.Len, fn->Name.Len - prefix.Len };
|
||||
Str new_name = StrBuilder::fmt_buf(FallbackAllocator, "def__%S", actual_name ).to_str();
|
||||
Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "def__%S", actual_name ).to_str();
|
||||
|
||||
// Resolve define's arguments
|
||||
b32 has_args = fn->Params->NumEntries > 1;
|
||||
StrBuilder params_str = StrBuilder::make_reserve(FallbackAllocator, 32);
|
||||
StrBuilder params_str = StrBuilder::make_reserve(_ctx->Allocator_Temp, 32);
|
||||
for (CodeParams other_param = fn->Params; other_param != opt_param; ++ other_param) {
|
||||
if ( other_param == opt_param ) {
|
||||
params_str.append_fmt( "%S", other_param->Name );
|
||||
@ -1021,7 +1119,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
Str old_prefix = txt("code_");
|
||||
Str actual_name = { fn->Name.Ptr + old_prefix.Len, fn->Name.Len - old_prefix.Len };
|
||||
StrBuilder new_name = StrBuilder::fmt_buf(FallbackAllocator, "code__%S", actual_name );
|
||||
StrBuilder new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "code__%S", actual_name );
|
||||
|
||||
fn->Name = cache_str(new_name);
|
||||
}
|
||||
@ -1142,10 +1240,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
#pragma endregion Resolve Dependencies
|
||||
|
||||
#pragma region Resolve Components
|
||||
CodeBody array_arena = gen_array(txt("gen_Arena"), txt("Array_gen_Arena"));
|
||||
CodeBody array_pool = gen_array(txt("gen_Pool"), txt("Array_gen_Pool"));
|
||||
CodeBody array_token = gen_array(txt("gen_Token"), txt("Array_gen_Token"));
|
||||
|
||||
Code src_start = scan_file( "components/src_start.c" );
|
||||
Code src_static_data = scan_file( path_base "components/static_data.cpp" );
|
||||
Code src_ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" );
|
||||
@ -1176,7 +1270,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
Str old_prefix = txt("code_");
|
||||
Str actual_name = { fn->Name.Ptr + old_prefix.Len, fn->Name.Len - old_prefix.Len };
|
||||
StrBuilder new_name = StrBuilder::fmt_buf(FallbackAllocator, "code__%S", actual_name );
|
||||
StrBuilder new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "code__%S", actual_name );
|
||||
|
||||
fn->Name = cache_str(new_name);
|
||||
}
|
||||
@ -1219,7 +1313,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
)
|
||||
{
|
||||
// rename second definition so there isn't a symbol conflict
|
||||
StrBuilder postfix_arr = StrBuilder::fmt_buf(FallbackAllocator, "%S_arr", fn->Name);
|
||||
StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", fn->Name);
|
||||
fn->Name = cache_str(postfix_arr.to_str());
|
||||
postfix_arr.free();
|
||||
}
|
||||
@ -1228,7 +1322,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
Str prefix = txt("def_");
|
||||
Str actual_name = { fn->Name.Ptr + prefix.Len, fn->Name.Len - prefix.Len };
|
||||
Str new_name = StrBuilder::fmt_buf(FallbackAllocator, "def__%S", actual_name ).to_str();
|
||||
Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "def__%S", actual_name ).to_str();
|
||||
|
||||
fn->Name = cache_str(new_name);
|
||||
}
|
||||
@ -1267,51 +1361,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Struct:
|
||||
{
|
||||
if ( entry->Name.is_equal(txt("Token")))
|
||||
{
|
||||
// Add struct Token forward and typedef early.
|
||||
CodeStruct token_fwd = parse_struct(code( struct Token; ));
|
||||
CodeTypedef token_typedef = parse_typedef(code( typedef struct Token Token; ));
|
||||
src_lexer.append(token_fwd);
|
||||
src_lexer.append(token_typedef);
|
||||
|
||||
// Skip typedef since we added it
|
||||
b32 continue_for = true;
|
||||
for (Code array_entry = array_token.begin(); continue_for && array_entry != array_token.end(); ++ array_entry) switch (array_entry->Type)
|
||||
{
|
||||
case CT_Typedef:
|
||||
{
|
||||
// pop the array entry
|
||||
array_token->NumEntries -= 1;
|
||||
Code next = array_entry->Next;
|
||||
Code prev = array_entry->Prev;
|
||||
next->Prev = array_entry->Prev;
|
||||
prev->Next = next;
|
||||
if ( array_token->Front == array_entry )
|
||||
array_token->Front = next;
|
||||
|
||||
src_lexer.append(array_entry);
|
||||
continue_for = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Append the struct
|
||||
src_lexer.append(entry);
|
||||
|
||||
// Append the token array
|
||||
src_lexer.append(array_token);
|
||||
continue;
|
||||
}
|
||||
|
||||
CodeTypedef struct_tdef = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct <name> <name>; )));
|
||||
src_lexer.append(entry);
|
||||
src_lexer.append(struct_tdef);
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Variable:
|
||||
{
|
||||
CodeVar var = cast(CodeVar, entry);
|
||||
@ -1417,6 +1466,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
Code rf_header_parsing = refactor_and_format(header_parsing);
|
||||
|
||||
Code rf_types = refactor_and_format(types);
|
||||
Code rf_parser_types = refactor_and_format(parser_types);
|
||||
Code rf_ecode = refactor_and_format(ecode);
|
||||
Code rf_eoperator = refactor_and_format(eoperator);
|
||||
Code rf_especifier = refactor_and_format(especifier);
|
||||
@ -1481,10 +1531,11 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print( r_header_platform );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
header.print_fmt( "GEN_API_C_BEGIN\n" );
|
||||
|
||||
header.print( r_header_macros );
|
||||
header.print( header_generic_macros );
|
||||
|
||||
header.print_fmt( "GEN_API_C_BEGIN\n" );
|
||||
|
||||
header.print( r_header_basic_types );
|
||||
header.print( r_header_debug );
|
||||
header.print( rf_header_memory );
|
||||
@ -1517,6 +1568,8 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print( rf_eoperator );
|
||||
header.print( fmt_newline );
|
||||
header.print( rf_especifier );
|
||||
header.print( rf_etoktype );
|
||||
header.print( rf_parser_types );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
|
||||
header.print_fmt("#pragma region AST\n");
|
||||
@ -1525,6 +1578,13 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print( rf_ast_types );
|
||||
header.print_fmt("\n#pragma endregion AST\n");
|
||||
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_arena );
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_pool);
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_string_cached );
|
||||
|
||||
header.print( rf_interface );
|
||||
header.print(fmt_newline);
|
||||
|
||||
@ -1533,7 +1593,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print_fmt("#pragma endregion Inlines\n");
|
||||
|
||||
header.print(fmt_newline);
|
||||
header.print( rf_array_string_cached );
|
||||
|
||||
header.print( rf_header_end );
|
||||
header.print( rf_header_builder );
|
||||
@ -1573,11 +1632,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
header.print_fmt( "GEN_API_C_BEGIN\n" );
|
||||
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_arena );
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_pool);
|
||||
|
||||
header.print( r_src_static_data );
|
||||
header.print( fmt_newline);
|
||||
|
||||
@ -1591,7 +1645,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print( r_src_interface );
|
||||
header.print( r_src_upfront );
|
||||
header.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
header.print( rf_etoktype );
|
||||
header.print( r_src_lexer );
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_code_typename );
|
||||
@ -1646,7 +1699,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
Builder src = Builder::open( "gen/gen.dep.c" );
|
||||
src.print_fmt( "GEN_NS_BEGIN\n");
|
||||
src.print_fmt( "GEN_API_C_BEGIN\n" );
|
||||
|
||||
builder_print_fmt(src, generation_notice );
|
||||
builder_print_fmt( src, "// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n" );
|
||||
@ -1684,6 +1736,8 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print( rf_eoperator );
|
||||
header.print( fmt_newline );
|
||||
header.print( rf_especifier );
|
||||
header.print( rf_etoktype );
|
||||
header.print( rf_parser_types );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
|
||||
header.print_fmt("#pragma region AST\n");
|
||||
@ -1737,7 +1791,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
src.print( r_src_interface );
|
||||
src.print( r_src_upfront );
|
||||
src.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
src.print( rf_etoktype );
|
||||
src.print( r_src_lexer );
|
||||
src.print( fmt_newline);
|
||||
src.print( rf_array_code_typename );
|
||||
@ -1751,11 +1804,11 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
src.print( rf_src_builder );
|
||||
src.print( rf_src_scanner );
|
||||
|
||||
src.print_fmt( "GEN_API_C_END\n" );
|
||||
src.print_fmt( "\nGEN_NS_END\n");
|
||||
src.write();
|
||||
}
|
||||
#pragma endregion Segmented
|
||||
|
||||
gen::deinit();
|
||||
gen::deinit( & ctx);
|
||||
return 0;
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ word StrBuilder, gen_StrBuilder
|
||||
|
||||
namespace strbuilder_, gen_strbuilder_
|
||||
|
||||
word StrCached, gen_StringCached
|
||||
word StrCached, gen_StrCached
|
||||
|
||||
word StringTable, gen_StringTable
|
||||
|
||||
@ -401,7 +401,7 @@ word init, gen_init
|
||||
word deinit, gen_deinit
|
||||
word reset, gen_reset
|
||||
|
||||
word cache_str, gen_get_cached_string
|
||||
word cache_str, gen_cache_str
|
||||
|
||||
word make_code, gen_make_code
|
||||
|
||||
@ -414,20 +414,6 @@ namespace untyped_, gen_untyped_
|
||||
|
||||
// Constants
|
||||
|
||||
word TokenMap_FixedArena, gen_TokenMap_FixedArena
|
||||
word InitSize_DataArrays, gen_InitSize_DataArrays
|
||||
|
||||
word Global_BucketSize, gen_Global_BucketSize
|
||||
word CodePool_NumBlocks, gen_CodePool_NumBlocks
|
||||
word SizePer_StringArena, gen_SizePer_StringArena
|
||||
|
||||
word MaxCommentLineLength, gen_MaxCommentLineLength
|
||||
word MaxNameLength, gen_MaxNameLength
|
||||
word MaxUntypedStrLength, gen_MaxUntypedStrLength
|
||||
|
||||
word LexAllocator_Size, gen_LexAllocator_Size
|
||||
word Builder_StrBufferReserve, gen_Builder_StrBufferReserve
|
||||
|
||||
word access_public, gen_access_public
|
||||
word access_protected, gen_access_protected
|
||||
word access_private, gen_access_private
|
||||
@ -446,23 +432,8 @@ word preprocess_else, gen_preprocess_else
|
||||
namespace spec_, gen_spec_
|
||||
namespace t_, gen_t_
|
||||
|
||||
word PreprocessorDefines, gen_PreprocessorDefines
|
||||
|
||||
// Backend
|
||||
|
||||
word FallbackAllocator, gen_GlobalAllocator
|
||||
word Fallback_AllocatorBuckets, gen_Global_AllocatorBuckets
|
||||
word CodePools, gen_CodePools
|
||||
word StringArenas, gen_StringArenas
|
||||
word StringCache, gen_StringCache
|
||||
word LexArena, gen_LexArena
|
||||
word Allocator_DataArrays, gen_Allocator_DataArrays
|
||||
word Allocator_CodePool, gen_Allocator_CodePool
|
||||
word Allocator_Lexer, gen_Allocator_Lexer
|
||||
word Allocator_StringArena, gen_Allocator_StringArena
|
||||
word Allocator_StringTable, gen_Allocator_StringTable
|
||||
word Allocator_TypeTable, gen_Allocator_TypeTable
|
||||
|
||||
// Builder
|
||||
|
||||
word Builder, gen_Builder
|
||||
@ -527,7 +498,6 @@ word parser_deinit, gen_parser_deinit
|
||||
|
||||
word TokType, gen_TokType
|
||||
word toktype_to_str, gen_toktype_to_str
|
||||
// word str_to_toktype, gen_str_to_toktype
|
||||
word NullToken, gen_NullToken
|
||||
|
||||
namespace tok_, gen_tok_
|
||||
|
@ -42,8 +42,8 @@ CodeBody gen_array_base()
|
||||
|
||||
CodeBody gen_array( Str type, Str array_name )
|
||||
{
|
||||
StrBuilder array_type = StrBuilder::fmt_buf( FallbackAllocator, "%.*s", array_name.Len, array_name.Ptr );
|
||||
StrBuilder fn = StrBuilder::fmt_buf( FallbackAllocator, "%.*s", array_name.Len, array_name.Ptr );
|
||||
StrBuilder array_type = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "%.*s", array_name.Len, array_name.Ptr );
|
||||
StrBuilder fn = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "%.*s", array_name.Len, array_name.Ptr );
|
||||
// c_str_to_lower(fn.Data);
|
||||
|
||||
#pragma push_macro( "GEN_ASSERT" )
|
||||
@ -375,7 +375,7 @@ CodeBody gen_array( Str type, Str array_name )
|
||||
#pragma pop_macro( "forceinline" )
|
||||
|
||||
++ Array_DefinitionCounter;
|
||||
Str slot_str = StrBuilder::fmt_buf(FallbackAllocator, "%d", Array_DefinitionCounter).to_str();
|
||||
Str slot_str = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%d", Array_DefinitionCounter).to_str();
|
||||
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "array_type", (Str)array_type, "slot", (Str)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__array_init <type>, <array_type>_init
|
||||
@ -399,13 +399,13 @@ R"(#define GENERIC_SLOT_<slot>__array_init <type>, <array_type>_i
|
||||
));
|
||||
|
||||
return def_global_body( args(
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( FallbackAllocator, "region %SB", array_type ))),
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( _ctx->Allocator_Temp, "region %SB", array_type ))),
|
||||
fmt_newline,
|
||||
generic_interface_slot,
|
||||
fmt_newline,
|
||||
result,
|
||||
fmt_newline,
|
||||
def_pragma( strbuilder_to_str(strbuilder_fmt_buf( FallbackAllocator, "endregion %SB", array_type ))),
|
||||
def_pragma( strbuilder_to_str(strbuilder_fmt_buf( _ctx->Allocator_Temp, "endregion %SB", array_type ))),
|
||||
fmt_newline
|
||||
));
|
||||
};
|
||||
|
@ -30,16 +30,16 @@ R"(#define HashTable(_type) struct _type
|
||||
CodeBody gen_hashtable( Str type, Str hashtable_name )
|
||||
{
|
||||
|
||||
StrBuilder tbl_type = {(char*) hashtable_name.duplicate(FallbackAllocator).Ptr};
|
||||
StrBuilder fn = tbl_type.duplicate(FallbackAllocator);
|
||||
StrBuilder tbl_type = {(char*) hashtable_name.duplicate(_ctx->Allocator_Temp).Ptr};
|
||||
StrBuilder fn = tbl_type.duplicate(_ctx->Allocator_Temp);
|
||||
// c_str_to_lower(fn.Data);
|
||||
|
||||
StrBuilder name_lower = StrBuilder::make( FallbackAllocator, hashtable_name );
|
||||
StrBuilder name_lower = StrBuilder::make( _ctx->Allocator_Temp, hashtable_name );
|
||||
// c_str_to_lower( name_lower.Data );
|
||||
|
||||
StrBuilder hashtable_entry = StrBuilder::fmt_buf( FallbackAllocator, "HTE_%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
StrBuilder entry_array_name = StrBuilder::fmt_buf( FallbackAllocator, "Arr_HTE_%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
StrBuilder entry_array_fn_ns = StrBuilder::fmt_buf( FallbackAllocator, "arr_hte_%.*s", name_lower.length(), name_lower.Data );
|
||||
StrBuilder hashtable_entry = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "HTE_%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
StrBuilder entry_array_name = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "Arr_HTE_%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
StrBuilder entry_array_fn_ns = StrBuilder::fmt_buf( _ctx->Allocator_Temp, "arr_hte_%.*s", name_lower.length(), name_lower.Data );
|
||||
|
||||
CodeBody hashtable_types = parse_global_body( token_fmt(
|
||||
"type", (Str) type,
|
||||
@ -372,7 +372,7 @@ CodeBody gen_hashtable( Str type, Str hashtable_name )
|
||||
#pragma pop_macro( "forceinline" )
|
||||
|
||||
++ HashTable_DefinitionCounter;
|
||||
Str slot_str = StrBuilder::fmt_buf(FallbackAllocator, "%d", HashTable_DefinitionCounter).to_str();
|
||||
Str slot_str = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%d", HashTable_DefinitionCounter).to_str();
|
||||
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "tbl_type", (Str)tbl_type, "slot", (Str)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_init
|
||||
@ -400,7 +400,7 @@ R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_
|
||||
, type.Len, type.Ptr );
|
||||
|
||||
return def_global_body(args(
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( FallbackAllocator, "region %SB", tbl_type ))),
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( _ctx->Allocator_Temp, "region %SB", tbl_type ))),
|
||||
fmt_newline,
|
||||
generic_interface_slot,
|
||||
fmt_newline,
|
||||
@ -409,7 +409,7 @@ R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_
|
||||
entry_array,
|
||||
hashtable_def,
|
||||
fmt_newline,
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( FallbackAllocator, "endregion %SB", tbl_type ))),
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( _ctx->Allocator_Temp, "endregion %SB", tbl_type ))),
|
||||
fmt_newline
|
||||
));
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ Code gen_generic_selection_function_macro( s32 num_slots, Str macro_name, Generi
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg )
|
||||
*/
|
||||
local_persist
|
||||
StrBuilder define_builder = StrBuilder::make_reserve(FallbackAllocator, kilobytes(64));
|
||||
StrBuilder define_builder = StrBuilder::make_reserve(_ctx->Allocator_Temp, kilobytes(64));
|
||||
define_builder.clear();
|
||||
|
||||
Str macro_begin;
|
||||
@ -104,7 +104,7 @@ R"(#define <macro_name>(selector_arg, ...) _Generic( (selector_arg), \
|
||||
|
||||
for ( s32 slot = 1; slot <= num_slots; ++ slot )
|
||||
{
|
||||
Str slot_str = StrBuilder::fmt_buf(FallbackAllocator, "%d", slot).to_str();
|
||||
Str slot_str = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%d", slot).to_str();
|
||||
define_builder.append( token_fmt( "macro_name", macro_name, "slot", slot_str,
|
||||
R"(GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_<slot>__<macro_name> ) \
|
||||
)"
|
||||
@ -147,9 +147,9 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, Str optional_prefix = txt("")
|
||||
|
||||
// Add prefix if provided
|
||||
if (optional_prefix.Len)
|
||||
new_name = strbuilder_fmt_buf(FallbackAllocator, "%S_%S_", optional_prefix, old_name);
|
||||
new_name = strbuilder_fmt_buf(_ctx->Allocator_Temp, "%S_%S_", optional_prefix, old_name);
|
||||
else
|
||||
new_name = strbuilder_fmt_buf(FallbackAllocator, "%S_", old_name);
|
||||
new_name = strbuilder_fmt_buf(_ctx->Allocator_Temp, "%S_", old_name);
|
||||
|
||||
// Add return type to the signature
|
||||
if (fn->ReturnType)
|
||||
@ -211,8 +211,8 @@ bool swap_pragma_region_implementation( Str region_name, SwapContentProc* swap_c
|
||||
bool found = false;
|
||||
CodePragma possible_region = cast(CodePragma, entry_iter);
|
||||
|
||||
StrBuilder region_sig = strbuilder_fmt_buf(FallbackAllocator, "region %s", region_name.Ptr);
|
||||
StrBuilder endregion_sig = strbuilder_fmt_buf(FallbackAllocator, "endregion %s", region_name.Ptr);
|
||||
StrBuilder region_sig = strbuilder_fmt_buf(_ctx->Allocator_Temp, "region %s", region_name.Ptr);
|
||||
StrBuilder endregion_sig = strbuilder_fmt_buf(_ctx->Allocator_Temp, "endregion %s", region_name.Ptr);
|
||||
if ( possible_region->Content.contains(region_sig))
|
||||
{
|
||||
found = true;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#define GEN_IMPLEMENTATION
|
||||
#include "gen/gen.c"
|
||||
#include "gen/gen_singleheader.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -223,6 +223,7 @@ int gen_main()
|
||||
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
header.print( static_data );
|
||||
header.print( fmt_newline);
|
||||
|
||||
header.print_fmt( "#pragma region AST\n\n" );
|
||||
header.print( ast_case_macros );
|
||||
@ -238,7 +239,9 @@ int gen_main()
|
||||
header.print( parser );
|
||||
header.print( parsing_interface );
|
||||
header.print_fmt( "\n#pragma endregion Parsing\n" );
|
||||
header.print_fmt("\n#pragma region Untyped\n");
|
||||
header.print( untyped );
|
||||
header.print_fmt("\n#pragma endregion Untyped\n");
|
||||
header.print_fmt( "\n#pragma endregion Interface\n");
|
||||
|
||||
if ( generate_builder ) {
|
||||
|
@ -1,8 +1,9 @@
|
||||
# Format Style Options - Created with Clang Power Tools
|
||||
---
|
||||
|
||||
# AttributeMacros: [
|
||||
# ]
|
||||
AttributeMacros: [
|
||||
GEN_API
|
||||
]
|
||||
StatementMacros: [
|
||||
GEN_NS_BEGIN,
|
||||
GEN_NS_END,
|
||||
|
@ -17,8 +17,10 @@ Push-Location $path_root
|
||||
#region Arguments
|
||||
$vendor = $null
|
||||
$release = $null
|
||||
$verbose = $false
|
||||
$base = $false
|
||||
[bool] $verbose = $false
|
||||
[bool] $shared = $false
|
||||
[bool] $dyn_link = $false
|
||||
[bool] $base = $false
|
||||
[bool] $segmented = $false
|
||||
[bool] $singleheader = $false
|
||||
[bool] $c_library = $false
|
||||
@ -35,6 +37,8 @@ if ( $args ) { $args | ForEach-Object {
|
||||
"verbose" { $verbose = $true }
|
||||
"release" { $release = $true }
|
||||
"debug" { $release = $false }
|
||||
"shared" { $shared = $true }
|
||||
"dyn_link" { $dyn_link = $true }
|
||||
"base" { $base = $true }
|
||||
"segmented" { $segmented = $true }
|
||||
"singleheader" { $singleheader = $true }
|
||||
|
Loading…
Reference in New Issue
Block a user