Compare commits

..

No commits in common. "d91d3c6b6fe50281b74a15ce88429f2b07cb839b" and "177820cd6e27ab10ce615862be52c61685bf2883" have entirely different histories.

6 changed files with 64 additions and 229 deletions

View File

@ -50,7 +50,6 @@ struct Context
// LoggerCallaback* log_callback; // TODO(Ed): Impl user logger callback as an option.
// Initalization config
u32 Max_CommentLineLength; // Used by def_comment
u32 Max_StrCacheLength; // Any cached string longer than this is always allocated again.

View File

@ -54,13 +54,11 @@ A simple `<container>_DefinitionCounter` is used to know how many instantiations
## Macro Usage
For the most part macros are kept minimal with exception to `_Generic`...
*(I will be explaining this thing for the rest of this seciton along with gencpp c library's usage of it)*
The `_Generic` macro plays a key role in reducing direct need of the user to wrangle with mangled definition identifiers of 'templated' containers or for type coercion to map distinct data types to a common code path.
Many C11 libraries don't use it.. and, of those that do. they usually end up obfuscate it with excessive preprocessor abuse; Effort was put into minimizing how much of these macros are handled by the preprocessor vs gencpp itself.
*(I will be explaining this thing for the rest of this seciton along with gencpp c library's usage of it)*
Because of its lack of use in many C11 libraries.. and, of those that do; they usually end up obfuscate it with excessive preprocessor abuse; Effort was put into minimizing how much of these macros are handled by the preprocessor vs gencpp itself.
The usual presentation (done bare) is the following:
@ -97,7 +95,7 @@ For this library's purposes we'll be using the functional macro equivalent *(if
```c
#define macro_that_uses_selector_arg_for_resolving_a_fucntion( selecting_exp) \
_Generic( (selecting_exp), \
_Generic( (arg), \
int : func_use_int, \
double : func_use_double, \
struct Whatnot : func_use_Whatnot, \

View File

@ -1256,6 +1256,63 @@ R"(#define <interface_name>( code ) _Generic( (code), \
break;
}
CodeBody parsed_header_builder = parse_file( path_base "auxiliary/builder.hpp" );
CodeBody header_builder = def_body(CT_Global_Body);
for ( Code entry = parsed_header_builder.begin(); entry != parsed_header_builder.end(); ++ entry ) switch( entry->Type )
{
case CT_Preprocess_IfDef:
{
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_builder, header_builder );
if (found) break;
header_builder.append(entry);
}
break;
case CT_Preprocess_If:
{
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_header_builder, header_builder );
if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), entry, parsed_header_builder, header_builder );
if (found) break;
header_builder.append(entry);
}
break;
case CT_Struct:
{
CodeBody body = cast(CodeBody, entry->Body);
CodeBody new_body = def_body(CT_Struct_Body);
for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch(body_entry->Type)
{
case CT_Preprocess_If:
{
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), body_entry, body, new_body );
if (found) break;
new_body.append(body_entry);
}
break;
default:
new_body.append(body_entry);
break;
}
if ( new_body->NumEntries > 0 ) {
entry->Body = new_body;
}
header_builder.append(entry);
}
break;
default:
header_builder.append(entry);
break;
}
s32 idx = 0;
CodeBody parsed_header_end = parse_file( path_base "components/header_end.hpp" );
CodeBody header_end = def_body(CT_Global_Body);
@ -1294,111 +1351,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
}
#pragma endregion Resolve Components
#pragma region Resolve Aux
CodeDefine gsel_builder_print = NullCode;
CodeBody parsed_header_builder = parse_file( path_base "auxiliary/builder.hpp" );
CodeBody header_builder = def_body(CT_Global_Body);
for ( Code entry = parsed_header_builder.begin(); entry != parsed_header_builder.end(); ++ entry ) switch( entry->Type )
{
case CT_Preprocess_IfDef:
{
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_builder, header_builder );
if (found) break;
header_builder.append(entry);
}
break;
case CT_Preprocess_If:
{
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_header_builder, header_builder );
if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), entry, parsed_header_builder, header_builder );
if (found) break;
header_builder.append(entry);
}
break;
case CT_Function_Fwd:
{
CodeFn fn = cast(CodeFn, entry);
if (! fn->Name.is_equal(txt("builder_print")) ) {
header_builder.append(fn);
continue;
}
fn->Name = cache_str(txt("builder__print"));
StrBuilder generic_selector = StrBuilder::make(_ctx->Allocator_Temp,
"#define builder_print(builder, code) _Generic( (code), \\\n"
);
// Append slots
for(Str type : code_typenames ) {
generic_selector.append_fmt("%S : %S,\\\n", type, fn->Name );
}
generic_selector.append(txt("default: gen_generic_selection_fail \\\n"));
generic_selector.append(txt("\t)\tGEN_RESOLVED_FUNCTION_CALL( builder, (Code)code )"));
// We need to register this as an identifier macro now sot that parsing the source wont break.
register_macro({ txt("builder_print"), MT_Statement, MF_Functional | MF_Allow_As_Identifier });
// We'll be adding this selector after builder_print_fmt
gsel_builder_print = parse_define(generic_selector);
header_builder.append(fn);
}
break;
case CT_Function:
{
CodeFn fn = cast(CodeFn, entry);
if ( fn->Name.is_equal(txt("builder_print_fmt")) ) {
header_builder.append(fn);
// Add the selector right after
header_builder.append(fmt_newline);
header_builder.append(gsel_builder_print);
}
}
break;
case CT_Struct:
{
CodeBody body = cast(CodeBody, entry->Body);
CodeBody new_body = def_body(CT_Struct_Body);
for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch(body_entry->Type)
{
case CT_Preprocess_If:
{
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), body_entry, body, new_body );
if (found) break;
new_body.append(body_entry);
}
break;
default:
new_body.append(body_entry);
break;
}
if ( new_body->NumEntries > 0 ) {
entry->Body = new_body;
}
header_builder.append(entry);
}
break;
default:
header_builder.append(entry);
break;
}
#pragma endregion Aux
// Source Content : Reflection and Generation
#pragma region Resolve Dependencies
@ -1607,26 +1559,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
}
#pragma endregion Resolve Components
#pragma region Resolve Aux
CodeBody parsed_src_builder = parse_file( path_base "auxiliary/builder.cpp" );
CodeBody src_builder = def_body(CT_Global_Body);
for ( Code entry = parsed_src_builder.begin(); entry != parsed_src_builder.end(); ++ entry ) switch( entry->Type )
{
case CT_Function:
{
if (entry->Name.is_equal(txt("builder_print"))) {
entry->Name = cache_str(txt("builder__print"));
}
src_builder.append(entry);
}
break;
default:
src_builder.append(entry);
break;
}
#pragma endregion ResolveAux
// THERE SHOULD BE NO NEW GENERIC CONTAINER DEFINITIONS PAST THIS POINT (It will not have slots for the generic selection generated macros)
CodeBody containers = def_body(CT_Global_Body);
{
@ -1712,7 +1644,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
CodeBody etoktype = gen_etoktype( path_base "enums/ETokType.csv", path_base "enums/AttributeTokens.csv", helper_use_c_definition );
Code rf_etoktype = refactor_and_format(etoktype);
Code rf_src_builder = refactor_and_format( src_builder );
Code rf_src_builder = refactor_and_format( scan_file( path_base "auxiliary/builder.cpp" ));
Code rf_src_scanner = refactor_and_format( scan_file( path_base "auxiliary/scanner.cpp" ));
#pragma endregion Refactored / Formatted

View File

@ -326,7 +326,7 @@ if ( $unreal )
}
# C Library testing
if ( $test -and $true )
if ( $test -and $false )
{
$path_test_c = join-path $path_test c_library
$path_build = join-path $path_test_c build
@ -368,7 +368,7 @@ if ( $test -and $true )
Pop-Location
}
if ( $test -and $false )
if ( $test -and $true )
{
$path_test_c = join-path $path_test c_library
$path_build = join-path $path_test_c build

View File

@ -1,90 +0,0 @@
# Basic indentation settings
indent_columns = 4
indent_with_tabs = 1
indent_case_brace = 0
indent_switch_case = 4
indent_col1_comment = true
indent_namespace = true
indent_class = true
indent_extern = true
# Alignment settings
align_assign_span = 1
align_assign_thresh = 0
align_enum_equ_span = 1
align_var_def_span = 1
align_var_def_thresh = 0
align_var_def_inline = true
align_right_cmt_span = 1
align_pp_define_span = 1
align_typedef_span = 1
align_typedef_gap = 0
# Spacing settings
sp_before_square = remove
sp_inside_square = remove
sp_after_comma = force
sp_before_comma = remove
sp_after_cast = remove
sp_inside_paren = remove
sp_inside_fparen = remove
sp_inside_sparen = remove
sp_before_sparen = force
sp_after_operator = remove
sp_after_operator_sym = remove
sp_after_ptr_star = remove
sp_before_ptr_star = force
sp_between_ptr_star = remove
# Code style settings
mod_full_brace_do = force
mod_full_brace_for = force
mod_full_brace_if = force
mod_full_brace_while = force
mod_paren_on_return = remove
mod_full_brace_nl = 1
mod_remove_extra_semicolon = true
# Line breaking
nl_after_brace_open = true
nl_after_brace_close = true
nl_after_return = true
nl_before_case = true
nl_fcall_brace = force
nl_enum_brace = force
nl_struct_brace = force
nl_union_brace = force
nl_if_brace = force
nl_brace_else = force
nl_elseif_brace = force
nl_else_brace = force
nl_else_if = remove
nl_while_brace = force
nl_do_brace = force
nl_for_brace = force
nl_max = 4
nl_after_func_proto = 2
nl_after_func_body = 2
# Template settings
sp_inside_angle = remove
sp_after_angle = force
sp_angle_paren = remove
sp_angle_word = force
# Other settings
cmt_indent_multi = true
cmt_c_group = false
cmt_cpp_group = false
indent_func_call_param = true
indent_func_def_param = true
indent_func_proto_param = true
indent_template_param = true
indent_relative_single_line_comments = true
# Preprocessor settings
pp_indent = remove
pp_space = remove
# Column limit
code_width = 160

View File

@ -1,7 +1,3 @@
#if GEN_INTELLISENSE_DIRECTIVES
#include "../../gen_c_library/gen/gen_singleheader.h"
#endif
#define GEN_IMPLEMENTATION
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#include "gen_singleheader.h"
@ -20,7 +16,7 @@ int main()
gen_CodeVar hello_var = gen_parse_variable(code(
char const* hello_gencpp_str = "HELLO GENCPP C11 !";
));
gen_builder_print( & src_hello, hello_var );
gen_builder_print( & src_hello, (gen_Code)hello_var );
gen_builder_write(& src_hello);
gen_CodeBody body = gen_parse_file("gen/hello.c");