work on gettings things compiling again after restructuring

This commit is contained in:
Edward R. Gonzalez 2024-12-10 20:45:00 -05:00
parent 8891657eb1
commit ef78772278
26 changed files with 230 additions and 210 deletions

View File

@ -19,7 +19,7 @@ If your going to metaprogram, you can never have enough docs on your tooling...
* [Parser Algo](./docs/Parser_Algo.md): In-depth breakdown of the parser's implementation. * [Parser Algo](./docs/Parser_Algo.md): In-depth breakdown of the parser's implementation.
* [base](./base/Readme.md): Essential (base) library. * [base](./base/Readme.md): Essential (base) library.
* [gen_c_library](./gen_c_library/Readme.md): C11 library variant generation (single header and segmeented). * [gen_c_library](./gen_c_library/Readme.md): C11 library variant generation (single header and segmeented).
* [gen_segmented](./gen_segemented/Readme.md): Segemented C++ (`gen.<hpp/cpp>`, `gen.dep.<hpp/cpp>`) generation * [gen_segmented](./gen_segmented/Readme.md): Segemented C++ (`gen.<hpp/cpp>`, `gen.dep.<hpp/cpp>`) generation
* [gen_singleheader](./gen_singleheader/Readme.md): Singlehader C++ generation `gen.hpp` * [gen_singleheader](./gen_singleheader/Readme.md): Singlehader C++ generation `gen.hpp`
* [gen_unreal_engine](./gen_unreal_engine/Readme.md): Unreal Engine thirdparty code generation. * [gen_unreal_engine](./gen_unreal_engine/Readme.md): Unreal Engine thirdparty code generation.

View File

@ -16,7 +16,7 @@ Standard formats:
* **helpers**: Contains helper functionality used by base and other libraries to regenerate or generate the other library formats. * **helpers**: Contains helper functionality used by base and other libraries to regenerate or generate the other library formats.
* `base_codegen.hpp`: Helps with self-hosted code generation of enums, and operator overload inlines of the code types. * `base_codegen.hpp`: Helps with self-hosted code generation of enums, and operator overload inlines of the code types.
* `<push/pop>.<name>.inline.<hpp>`: macros that are meant to be injected at specific locations of the library. * `<push/pop>.<name>.inline.<hpp>`: macros that are meant to be injected at specific locations of the library.
* `misc.hpp`: * `misc.hpp`: Misc functionality used by the library generation metaprograms.
* `undef.macros.h`: Undefines all macros from library that original were intended to leak into user code. * `undef.macros.h`: Undefines all macros from library that original were intended to leak into user code.
* **auxillary**: Non-essential tooling: * **auxillary**: Non-essential tooling:
* `Builder`: Similar conceptually to Jai programming language's *builder*, just opens a file and prepares a string buffer to serialize code into (`builder_print`, `builder_print_fmt`). Then write & close the file when completed (`builder_write`). * `Builder`: Similar conceptually to Jai programming language's *builder*, just opens a file and prepares a string buffer to serialize code into (`builder_print`, `builder_print_fmt`). Then write & close the file when completed (`builder_write`).
@ -125,6 +125,8 @@ There are ***five*** header files which are automatically generated by [base_cod
* [`AttributeTokens.csv`](./enums/AttributeTokens.csv): Provides tokens entries that should be considered as attributes by the lexer and parser. Sspecfiically macro attributes such as those use for exporting symbols. * [`AttributeTokens.csv`](./enums/AttributeTokens.csv): Provides tokens entries that should be considered as attributes by the lexer and parser. Sspecfiically macro attributes such as those use for exporting symbols.
* [`ast_inlines.hpp`](./components/gen/ast_inlines.hpp): Member trivial `operator` definitions for C++ code types. Does not use a csv. * [`ast_inlines.hpp`](./components/gen/ast_inlines.hpp): Member trivial `operator` definitions for C++ code types. Does not use a csv.
[`misc.hpp`](./helpers/misc.hpp): Has shared functions used by the library generation meta-programs throughout this codebase.
## On multi-threading ## On multi-threading
Currently unsupported. I want the library to be *stable* and *correct*, with the addition of exhausting all basic single-threaded optimizations before I consider multi-threading. Currently unsupported. I want the library to be *stable* and *correct*, with the addition of exhausting all basic single-threaded optimizations before I consider multi-threading.

View File

@ -13,6 +13,7 @@
# include "components/inlines.hpp" # include "components/inlines.hpp"
# include "components/gen/ast_inlines.hpp" # include "components/gen/ast_inlines.hpp"
# include "components/header_end.hpp" # include "components/header_end.hpp"
using namespace gen;
#endif #endif
#pragma region Builder #pragma region Builder

View File

@ -2,4 +2,118 @@
# include "scanner.hpp" # include "scanner.hpp"
#endif #endif
#pragma region Scanner
Code scan_file( char const* path )
{
FileInfo file;
FileError error = file_open_mode( & file, EFileMode_READ, path );
if ( error != EFileError_NONE )
{
GEN_FATAL( "scan_file: Could not open: %s", path );
}
ssize fsize = file_size( & file );
if ( fsize <= 0 )
{
GEN_FATAL("scan_file: %s is empty", path );
}
String str = string_make_reserve( GlobalAllocator, fsize );
file_read( & file, str, fsize );
string_get_header(str)->Length = fsize;
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
// Its designed so that the directive should be the first thing in the file.
// Anything that comes before it will also be omitted.
{
#define current (*scanner)
#define matched 0
#define move_fwd() do { ++ scanner; -- left; } while (0)
const StrC directive_start = txt( "ifdef" );
const StrC directive_end = txt( "endif" );
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
bool found_directive = false;
char const* scanner = (char const*)str;
s32 left = fsize;
while ( left )
{
// Processing directive.
if ( current == '#' )
{
move_fwd();
while ( left && char_is_space( current ) )
move_fwd();
if ( ! found_directive )
{
if ( left && str_compare_len( scanner, directive_start.Ptr, directive_start.Len ) == matched )
{
scanner += directive_start.Len;
left -= directive_start.Len;
while ( left && char_is_space( current ) )
move_fwd();
if ( left && str_compare_len( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
{
scanner += def_intellisense.Len;
left -= def_intellisense.Len;
found_directive = true;
}
}
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
continue;
}
if ( left && str_compare_len( scanner, directive_end.Ptr, directive_end.Len ) == matched )
{
scanner += directive_end.Len;
left -= directive_end.Len;
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
// sptr skip_size = fsize - left;
if ( (scanner + 2) >= ( (char const*) str + fsize ) )
{
mem_move( str, scanner, left );
string_get_header(str)->Length = left;
break;
}
mem_move( str, scanner, left );
string_get_header(str)->Length = left;
break;
}
}
move_fwd();
}
#undef move_fwd
#undef matched
#undef current
}
file_close( & file );
return untyped_str( string_to_strc(str) );
}
#pragma endregion Scanner

View File

@ -20,119 +20,9 @@
// This is a simple file reader that reads the entire file into memory. // This is a simple file reader that reads the entire file into memory.
// It has an extra option to skip the first few lines for undesired includes. // It has an extra option to skip the first few lines for undesired includes.
// This is done so that includes can be kept in dependency and component files so that intellisense works. // This is done so that includes can be kept in dependency and component files so that intellisense works.
Code scan_file( char const* path );
inline inline
Code scan_file( char const* path )
{
FileInfo file;
FileError error = file_open_mode( & file, EFileMode_READ, path );
if ( error != EFileError_NONE )
{
GEN_FATAL( "scan_file: Could not open: %s", path );
}
ssize fsize = file_size( & file );
if ( fsize <= 0 )
{
GEN_FATAL("scan_file: %s is empty", path );
}
String str = string_make_reserve( GlobalAllocator, fsize );
file_read( & file, str, fsize );
string_get_header(str)->Length = fsize;
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
// Its designed so that the directive should be the first thing in the file.
// Anything that comes before it will also be omitted.
{
#define current (*scanner)
#define matched 0
#define move_fwd() do { ++ scanner; -- left; } while (0)
const StrC directive_start = txt( "ifdef" );
const StrC directive_end = txt( "endif" );
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
bool found_directive = false;
char const* scanner = (char const*)str;
s32 left = fsize;
while ( left )
{
// Processing directive.
if ( current == '#' )
{
move_fwd();
while ( left && char_is_space( current ) )
move_fwd();
if ( ! found_directive )
{
if ( left && str_compare_len( scanner, directive_start.Ptr, directive_start.Len ) == matched )
{
scanner += directive_start.Len;
left -= directive_start.Len;
while ( left && char_is_space( current ) )
move_fwd();
if ( left && str_compare_len( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
{
scanner += def_intellisense.Len;
left -= def_intellisense.Len;
found_directive = true;
}
}
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
continue;
}
if ( left && str_compare_len( scanner, directive_end.Ptr, directive_end.Len ) == matched )
{
scanner += directive_end.Len;
left -= directive_end.Len;
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
// sptr skip_size = fsize - left;
if ( (scanner + 2) >= ( (char const*) str + fsize ) )
{
mem_move( str, scanner, left );
string_get_header(str)->Length = left;
break;
}
mem_move( str, scanner, left );
string_get_header(str)->Length = left;
break;
}
}
move_fwd();
}
#undef move_fwd
#undef matched
#undef current
}
file_close( & file );
return untyped_str( string_to_strc(str) );
}
CodeBody parse_file( const char* path ) CodeBody parse_file( const char* path )
{ {
FileContents file = file_read_contents( GlobalAllocator, true, path ); FileContents file = file_read_contents( GlobalAllocator, true, path );
@ -146,17 +36,18 @@ CodeBody parse_file( const char* path )
typedef struct CSV_Column CSV_Column; typedef struct CSV_Column CSV_Column;
struct CSV_Column { struct CSV_Column {
CSV_Object Owner; CSV_Object ADT;
Array<ADT_Node> Content; Array<ADT_Node> Content;
}; };
typedef struct CSV_Columns2 CSV_Columns2; typedef struct CSV_Columns2 CSV_Columns2;
struct CSV_Columns2 { struct CSV_Columns2 {
CSV_Object Owner; CSV_Object ADT;
Array<ADT_Node> Col_1; Array<ADT_Node> Col_1;
Array<ADT_Node> Col_2; Array<ADT_Node> Col_2;
}; };
inline
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) { CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
char scratch_mem[kilobytes(32)]; char scratch_mem[kilobytes(32)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) ); Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
@ -164,11 +55,12 @@ CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path ); file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
CSV_Column result; CSV_Column result;
csv_parse( & result.owner, scratch_mem, allocator, false ); csv_parse( & result.ADT, scratch_mem, allocator, false );
result.Content = csv_nodes.nodes[0].nodes; result.Content = result.ADT.nodes[0].nodes;
return result; return result;
} }
inline
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) { CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) {
char scratch_mem[kilobytes(32)]; char scratch_mem[kilobytes(32)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) ); Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
@ -176,9 +68,9 @@ CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) {
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path ); file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
CSV_Columns2 result; CSV_Columns2 result;
csv_parse( & result.owner, scratch_mem, allocator, false ); csv_parse( & result.ADT, scratch_mem, allocator, false );
result.Col_1 = csv_nodes.nodes[0].nodes; result.Col_1 = result.ADT.nodes[0].nodes;
result.Col_2 = csv_nodes.nodes[1].nodes; result.Col_2 = result.ADT.nodes[1].nodes;
return result; return result;
} }

View File

@ -2,22 +2,17 @@
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_C_LIKE_CPP 1 #define GEN_C_LIKE_CPP 1
#include "../project/gen.cpp" #include "gen.cpp"
#include "helpers/push_ignores.inline.hpp" #include "helpers/push_ignores.inline.hpp"
#include "helpers/helper.hpp"
#include <stdlib.h>
GEN_NS_BEGIN GEN_NS_BEGIN
#include "helpers/push_container_defines.inline.hpp" #include "helpers/base_codegen.hpp"
#include "dependencies/parsing.cpp" #include "helpers/misc.hpp"
#include "helpers/pop_container_defines.inline.hpp"
GEN_NS_END GEN_NS_END
#include "auxillary/builder.hpp"
#include "auxillary/builder.cpp"
#include "auxillary/scanner.hpp"
#include "auxillary/misc.hpp"
using namespace gen; using namespace gen;
constexpr char const* path_format_style = "../scripts/.clang-format"; constexpr char const* path_format_style = "../scripts/.clang-format";
@ -27,8 +22,25 @@ Code format( Code code ) {
return code_refactor_and_format(code, scratch_file, nullptr, path_format_style ); return code_refactor_and_format(code, scratch_file, nullptr, path_format_style );
} }
constexpr char const* generation_notice =
"// This file was generated automatially by gencpp's bootstrap.cpp "
"(See: https://github.com/Ed94/gencpp)\n\n";
CodeBody gen_component_header = def_global_body( args(
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
pragma_once,
def_include(txt("components/types.hpp")),
preprocess_endif,
fmt_newline,
untyped_str( to_strc_from_c_str(generation_notice) )
));
int gen_main() int gen_main()
{ {
gen::init();
__debugbreak();
CodeBody ecode = gen_ecode ( "enums/ECodeTypes.csv" ); CodeBody ecode = gen_ecode ( "enums/ECodeTypes.csv" );
CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" ); CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" );
CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" ); CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" );
@ -53,4 +65,7 @@ int gen_main()
builder_print( & header_ast_inlines, gen_component_header ); builder_print( & header_ast_inlines, gen_component_header );
builder_print( & header_ast_inlines, format(ast_inlines) ); builder_print( & header_ast_inlines, format(ast_inlines) );
builder_write( & header_ast_inlines); builder_write( & header_ast_inlines);
gen::deinit();
return 0;
} }

View File

@ -8,8 +8,6 @@
// Publically Exposed Interface // Publically Exposed Interface
void parser_define_macro( StrC )
CodeClass parse_class( StrC def ) CodeClass parse_class( StrC def )
{ {
GEN_USING_NS_PARSER; GEN_USING_NS_PARSER;

View File

@ -644,7 +644,7 @@ CodeDefine def_define( StrC name, StrC content, Opts_def_define p )
// Add the define to PreprocessorDefines for usage in parsing // Add the define to PreprocessorDefines for usage in parsing
s32 lex_id_len = 0; s32 lex_id_len = 0;
for (; lex_id_len < result->Name.Len; ++ lex_id_len ) { for (; lex_id_len < result->Name.Len; ++ lex_id_len ) {
if ( reuslt->Name.Ptr[lex_id_len] == '(' ) if ( result->Name.Ptr[lex_id_len] == '(' )
break; break;
} }
StrC lex_id = { lex_id_len, result->Name.Ptr }; StrC lex_id = { lex_id_len, result->Name.Ptr };

View File

@ -1,6 +1,5 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "platform.hpp"
# include "macros.hpp" # include "macros.hpp"
#endif #endif

View File

@ -1,7 +1,5 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "debug.hpp"
# include "basic_types.hpp"
# include "src_start.cpp" # include "src_start.cpp"
#endif #endif

View File

@ -1,6 +1,9 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "dependencies/platform.hpp"
# include "dependencies/macros.hpp"
# include "basic_types.hpp" # include "basic_types.hpp"
# include "macros.hpp"
#endif #endif
#pragma region Debug #pragma region Debug

View File

@ -1,5 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "platform.hpp"
#endif #endif
#pragma region Macros #pragma region Macros

View File

@ -1,5 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "timing.hpp"
#endif #endif
#pragma region ADT #pragma region ADT

View File

@ -1,7 +1,5 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "filesystem.hpp"
# include "strings.hpp"
# include "string_ops.cpp" # include "string_ops.cpp"
#endif #endif

View File

@ -1,4 +1,5 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once
# include "header_start.hpp" # include "header_start.hpp"
#endif #endif

View File

@ -1,6 +1,5 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "string_ops.hpp"
# include "debug.cpp" # include "debug.cpp"
#endif #endif

View File

@ -37,6 +37,9 @@ GEN_NS_BEGIN
#include "components/interface.parsing.cpp" #include "components/interface.parsing.cpp"
#include "components/interface.untyped.cpp" #include "components/interface.untyped.cpp"
#include "auxillary/builder.cpp"
#include "auxillary/scanner.cpp"
GEN_NS_END GEN_NS_END
#include "helpers/pop_container_defines.inline.hpp" #include "helpers/pop_container_defines.inline.hpp"

View File

@ -13,5 +13,6 @@ GEN_NS_BEGIN
#include "dependencies/strings.cpp" #include "dependencies/strings.cpp"
#include "dependencies/filesystem.cpp" #include "dependencies/filesystem.cpp"
#include "dependencies/timing.cpp" #include "dependencies/timing.cpp"
#include "dependencies/parsing.cpp"
GEN_NS_END GEN_NS_END

View File

@ -16,5 +16,6 @@ GEN_NS_BEGIN
#include "dependencies/strings.hpp" #include "dependencies/strings.hpp"
#include "dependencies/filesystem.hpp" #include "dependencies/filesystem.hpp"
#include "dependencies/timing.hpp" #include "dependencies/timing.hpp"
#include "dependencies/parsing.hpp"
GEN_NS_END GEN_NS_END

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "gen.hpp" #if GEN_INTELLISENSE_DIRECTIVES
# include "../gen.hpp"
# include "misc.hpp"
using namespace gen; using namespace gen;
#endif
#include "dependencies/parsing.hpp"
#include "misc.hpp"
CodeBody gen_ecode( char const* path, bool use_c_definition = false ) CodeBody gen_ecode( char const* path, bool use_c_definition = false )
{ {
@ -182,8 +182,8 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++) for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++)
{ {
char const* enum_str = enum_strs[idx].string; char const* enum_str = csv_enum.Col_1[idx].string;
char const* entry_to_str = str_strs [idx].string; char const* entry_to_str = csv_enum.Col_2[idx].string;
string_append_fmt( & enum_entries, "Spec_%s,\n", enum_str ); string_append_fmt( & enum_entries, "Spec_%s,\n", enum_str );
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str); string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);

View File

@ -1,23 +1,19 @@
#pragma once
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
# define GEN_DEFINE_LIBRARY_CODE_CONSTANTS # define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
# define GEN_ENFORCE_STRONG_CODE_TYPES # define GEN_ENFORCE_STRONG_CODE_TYPES
# define GEN_EXPOSE_BACKEND # define GEN_EXPOSE_BACKEND
#include "../gen.cpp" # include "gen.hpp"
# include "helpers/push_ignores.inline.hpp" # include "helpers/push_ignores.inline.hpp"
# include "helpers/helper.hpp" # include "helpers/helper.hpp"
GEN_NS_BEGIN
#include "helpers/push_container_defines.inline.hpp"
#include "dependencies/parsing.cpp"
#include "helpers/pop_container_defines.inline.hpp"
GEN_NS_END
# include "auxillary/builder.hpp" # include "auxillary/builder.hpp"
# include "auxillary/builder.cpp" # include "auxillary/builder.cpp"
# include "auxillary/scanner.hpp" # include "auxillary/scanner.hpp"
#include <stdlib.h>
using namespace gen;
#endif #endif
// Will format a file with the given style at the provided path. // Will format a file with the given style at the provided path.
@ -29,13 +25,13 @@ void clang_format_file( char const* path, char const* style_path )
String style_arg; String style_arg;
if (style_path) { if (style_path) {
stle_arg = string_make_strc(GlobalAllocator, txt("-style=file:")); style_arg = string_make_strc(GlobalAllocator, txt("-style=file:"));
string_append_fmt( & style_arg, "%s ", style_path ); string_append_fmt( & style_arg, "%s ", style_path );
} }
StrC clang_format = txt("clang-format ") StrC clang_format = txt("clang-format ");
StrC cf_format_inplace = txt("-i ") StrC cf_format_inplace = txt("-i ");
StrC cf_verbose = txt("-verbose ") StrC cf_verbose = txt("-verbose ");
String command = string_make_strc( GlobalAllocator, clang_format ); String command = string_make_strc( GlobalAllocator, clang_format );
string_append_strc( & command, cf_format_inplace ); string_append_strc( & command, cf_format_inplace );
@ -53,11 +49,14 @@ void clang_format_file( char const* path, char const* style_path )
// (See: ./gencpp/scripts/build.ci.ps1 for how) // (See: ./gencpp/scripts/build.ci.ps1 for how)
void refactor_file( char const* path, char const* refactor_script ) void refactor_file( char const* path, char const* refactor_script )
{ {
GEN_ASSERT_NOT_NULL(path, refactor_script); GEN_ASSERT_NOT_NULL(path);
GEN_ASSERT_NOT_NULL(refactor_script);
#define refactor String command = string_make_strc(GlobalAllocator, txt("refactor "));
string_append_strc( & command, txt("-debug ") );
String command = string_make_strc(GlobalAllocator, txt("refactor"))); string_append_strc( & command, txt("-num=1 ") );
string_append_fmt( & command, "-src=%s ", path );
string_append_fmt( & command,"-spec=%s ", refactor_script );
log_fmt("\tBeginning refactor:\n"); log_fmt("\tBeginning refactor:\n");
system(command); system(command);
@ -68,16 +67,16 @@ void refactor_file( char const* path, char const* refactor_script )
// Does either of the above or both to the provided code. // Does either of the above or both to the provided code.
// Code returned will be untyped content (its be serialized) // Code returned will be untyped content (its be serialized)
Code code_refactor_and_format( Code code, char const* scratch_path, char const* refactor_script, char_const* clang_format_sytle_path ) Code code_refactor_and_format( Code code, char const* scratch_path, char const* refactor_script, char const* clang_format_sytle_path )
{ {
GEN_ASSERT_NOT_NULL(code); GEN_ASSERT(code);
GEN_ASSERT_NOT_NULL(scratch_path); GEN_ASSERT_NOT_NULL(scratch_path);
Builder scratch_file = builder_open("gen/scratch.hpp"); Builder scratch_file = builder_open("gen/scratch.hpp");
builder_print( & scratch_file, code); builder_print( & scratch_file, code);
builder_write(& scratch_file); builder_write(& scratch_file);
if (refactor_script) { if (refactor_script) {
refactor_file(scratch_path, refactor_script) refactor_file(scratch_path, refactor_script);
} }
if ( clang_format_sytle_path ) { if ( clang_format_sytle_path ) {
clang_format_file(scratch_path, clang_format_sytle_path); clang_format_file(scratch_path, clang_format_sytle_path);

View File

@ -2,22 +2,15 @@
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_C_LIKE_CPP 1 #define GEN_C_LIKE_CPP 1
#include "../project/gen.cpp" #include "../base/gen.cpp"
#include "helpers/push_ignores.inline.hpp" #include "helpers/push_ignores.inline.hpp"
#include "helpers/helper.hpp"
GEN_NS_BEGIN GEN_NS_BEGIN
#include "helpers/push_container_defines.inline.hpp" #include "helpers/base_codegen.hpp"
#include "dependencies/parsing.cpp" #include "helpers/misc.hpp"
#include "helpers/pop_container_defines.inline.hpp"
GEN_NS_END GEN_NS_END
#include "auxillary/builder.hpp"
#include "auxillary/builder.cpp"
#include "auxillary/scanner.hpp"
#include "auxillary/misc.hpp"
using namespace gen; using namespace gen;
constexpr char const* generation_notice = constexpr char const* generation_notice =

View File

@ -1,5 +1,10 @@
# Format Style Options - Created with Clang Power Tools # Format Style Options - Created with Clang Power Tools
--- ---
AttributeMacros: [enum_underlying]
StatementMacros: [GEN_NS_BEGIN, GEN_NS_END, GEN_NS_PARSER_BEGIN, GEN_NS_PARSER_END, GEN_API_C_BEGIN, GEN_API_C_END]
TypenameMacros: [Array, Hashtable]
SkipMacroDefinitionBody: true
AccessModifierOffset: -4 AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent AlignAfterOpenBracket: BlockIndent

View File

@ -4,23 +4,10 @@ Generation, testing, and cleanup scripts for the test directory are found here a
## Refactoring ## Refactoring
`refactor.ps1` Provides a way to run the [refactor](github.com/Ed94/refactor) program. It uses the `gencpp.refactor` script to complete a mass refactor of all content within the files of the specified within the script. `refactor.ps1` Provides a way to run the [refactor](github.com/Ed94/refactor) program. It uses the a `.refactor` script (such as [`gencpp.refactor`](../base/gencpp.refactor)) to complete a mass refactor of all content within the files of the specified within the script.
Currently `refactor` only supports naive sort of *find and replace* feature set and will not be able to rename identifiers excluisvely to a specific context (such as only renaming member names of a specific struct, etc). Currently `refactor` only supports naive sort of *find and replace* feature set and will not be able to rename identifiers excluisvely to a specific context (such as only renaming member names of a specific struct, etc).
Its main uage is the [c_library generation](../gen_c_library/).
**Note: The following macros are used with specifiers and token parsing within the library:**
* global
* internal
* local_persist
* forceinline
* neverinline
IF they are changed the following files would need adjustment:
* `./project/enums/ESpecifier.csv`
* `./project/enums/ETokType.csv`
* `./project/helpers/helper.hpp`
## Build & Run Scripts ## Build & Run Scripts
@ -28,13 +15,14 @@ IF they are changed the following files would need adjustment:
Remove any generated content from the repository. Remove any generated content from the repository.
**`build.ps1`** **`build.ps1`**
Build bootstrap, singleheader, or tests. Supports MSVC or clang, release or debug. Build c_library, segmented, singleheader, unreal. Supports msvc or clang, release or debug.
``` ```
args: args:
bootstrap c_library
segemented
singleheader singleheader
test unreal
clang clang
msvc : By default this project builds with clang, specifying msvc will build with MSVC. msvc : By default this project builds with clang, specifying msvc will build with MSVC.
debug debug
@ -42,6 +30,6 @@ args:
``` ```
**`package_release.ps1`** **`package_release.ps1`**
Will build the project as fast as possible, then package the release into a zip file. Will build the build all, then package the release into a zip file.
*Note: My env is Windows 11 with MSVC 2022 and clang 16.0.6* *Note: My env is Windows 11 with MSVC 2022 and clang 16.0.6*

View File

@ -19,6 +19,7 @@ Push-Location $path_root
$vendor = $null $vendor = $null
$release = $null $release = $null
$verbose = $false $verbose = $false
$base = $false
[bool] $segemented = $false [bool] $segemented = $false
[bool] $singleheader = $false [bool] $singleheader = $false
[bool] $c_library = $false [bool] $c_library = $false
@ -35,6 +36,7 @@ if ( $args ) { $args | ForEach-Object {
"verbose" { $verbose = $true } "verbose" { $verbose = $true }
"release" { $release = $true } "release" { $release = $true }
"debug" { $release = $false } "debug" { $release = $false }
"base" { $base = $true }
"segemented" { $segemented = $true } "segemented" { $segemented = $true }
"singleheader" { $singleheader = $true } "singleheader" { $singleheader = $true }
"c_library" { $c_library = $true } "c_library" { $c_library = $true }
@ -67,7 +69,13 @@ else {
$optimize = $true $optimize = $true
} }
if ( $segmented -eq $false -and $singleheader -eq $false -and $c_library -eq $false -and $unreal -eq $false -and $test -eq $false ) { $cannot_build = $base -eq $false
$cannot_build = $cannot_build -and $segmented -eq $false
$cannot_build = $cannot_build -and $singleheader -eq $false
$cannot_build = $cannot_build -and $c_library -eq $false
$cannot_build = $cannot_build -and $unreal -eq $false
$cannot_build = $cannot_build -and $test -eq $false
if ( $cannot_build ) {
throw "No build target specified. One must be specified, this script will not assume one" throw "No build target specified. One must be specified, this script will not assume one"
} }
@ -83,9 +91,9 @@ $path_base = Join-Path $path_root base
$path_c_library = join-Path $path_root gen_c_library $path_c_library = join-Path $path_root gen_c_library
$path_segmented = Join-Path $path_root gen_segmented $path_segmented = Join-Path $path_root gen_segmented
$path_singleheader = Join-Path $path_root gen_singleheader $path_singleheader = Join-Path $path_root gen_singleheader
$path_scripts = Join-Path $path_root scripts
$path_unreal = Join-Path $path_root gen_unreal_engine $path_unreal = Join-Path $path_root gen_unreal_engine
$path_test = Join-Path $path_root test $path_test = Join-Path $path_root test
$path_scripts = Join-Path $path_root scripts
if ( $base ) if ( $base )
{ {
@ -115,13 +123,13 @@ if ( $base )
Push-Location $path_project Push-Location $path_project
if ( Test-Path( $executable ) ) { if ( Test-Path( $executable ) ) {
write-host "`nRunning bootstrap" write-host "`nRunning base"
$time_taken = Measure-Command { & $executable $time_taken = Measure-Command { & $executable
| ForEach-Object { | ForEach-Object {
write-host `t $_ -ForegroundColor Green write-host `t $_ -ForegroundColor Green
} }
} }
write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms" write-host "`bbase completed in $($time_taken.TotalMilliseconds) ms"
} }
Pop-Location Pop-Location
} }
@ -153,7 +161,7 @@ if ( $segmented )
Push-Location $path_project Push-Location $path_project
if ( Test-Path( $executable ) ) { if ( Test-Path( $executable ) ) {
write-host "`nRunning bootstrap" write-host "`nRunning segmented"
$time_taken = Measure-Command { & $executable $time_taken = Measure-Command { & $executable
| ForEach-Object { | ForEach-Object {
write-host `t $_ -ForegroundColor Green write-host `t $_ -ForegroundColor Green