c_library refacotring works, and compiles with all content from the base project.

I need to make the refactor step happen before formatting with clang-format in the metaprogram instead of calling it from powershell
This commit is contained in:
Edward R. Gonzalez 2024-12-10 13:56:56 -05:00
parent 5aaef0f1a2
commit 0046c4a223
19 changed files with 793 additions and 196 deletions

View File

@ -98,6 +98,8 @@ CodeBody parse_file( const char* path )
constexpr bool helper_use_c_definition = true; constexpr bool helper_use_c_definition = true;
constexpr bool will_refactor_to_gen_namespace = true;
int gen_main() int gen_main()
{ {
#define project_dir "../project/" #define project_dir "../project/"
@ -231,7 +233,7 @@ do \
break; break;
case CT_Preprocess_If: case CT_Preprocess_If:
{ {
b32 found = ignore_preprocess_cond_block(txt("! GEN_C_LIKE_CPP"), entry, parsed_header_memory, header_memory ); b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), entry, parsed_header_memory, header_memory );
if (found) break; if (found) break;
header_memory.append(entry); header_memory.append(entry);
@ -289,8 +291,8 @@ do \
break; break;
} }
Code array_ssize = gen_array(txt("ssize"), txt("Array_ssize")); Code array_ssize = gen_array(txt("gen_ssize"), txt("Array_gen_ssize"));
Code array_string_cached = gen_array(txt("StringCached"), txt("Array_StringCached")); Code array_string_cached = gen_array(txt("gen_StringCached"), txt("Array_gen_StringCached"));
CodeBody parsed_header_strings = parse_file( project_dir "dependencies/strings.hpp" ); CodeBody parsed_header_strings = parse_file( project_dir "dependencies/strings.hpp" );
CodeBody header_strings = def_body(CT_Global_Body); CodeBody header_strings = def_body(CT_Global_Body);
@ -383,7 +385,7 @@ do \
CodeTypedef td = cast(CodeTypedef, entry); CodeTypedef td = cast(CodeTypedef, entry);
if (td->Name.contains(name_string_table)) if (td->Name.contains(name_string_table))
{ {
CodeBody ht = gen_hashtable(txt("StrC"), name_string_table); CodeBody ht = gen_hashtable(txt("gen_StrC"), name_string_table);
header_strings.append(ht); header_strings.append(ht);
break; break;
} }
@ -396,7 +398,7 @@ do \
break; break;
} }
CodeBody array_u8 = gen_array(txt("u8"), txt("Array_u8")); CodeBody array_u8 = gen_array(txt("gen_u8"), txt("Array_gen_u8"));
CodeBody parsed_header_filesystem = parse_file( project_dir "dependencies/filesystem.hpp" ); CodeBody parsed_header_filesystem = parse_file( project_dir "dependencies/filesystem.hpp" );
CodeBody header_filesystem = def_body(CT_Global_Body); CodeBody header_filesystem = def_body(CT_Global_Body);
@ -455,7 +457,7 @@ do \
break; break;
} }
CodeBody array_adt_node = gen_array(txt("ADT_Node"), txt("Array_ADT_Node")); CodeBody array_adt_node = gen_array(txt("gen_ADT_Node"), txt("Array_gen_ADT_Node"));
CodeBody parsed_header_parsing = parse_file( project_dir "dependencies/parsing.hpp" ); CodeBody parsed_header_parsing = parse_file( project_dir "dependencies/parsing.hpp" );
CodeBody header_parsing = def_body(CT_Global_Body); CodeBody header_parsing = def_body(CT_Global_Body);
@ -478,8 +480,8 @@ do \
header_parsing.append(fmt_newline); header_parsing.append(fmt_newline);
// Add ADT_Node forward and typedef early. // Add ADT_Node forward and typedef early.
CodeStruct adt_node_fwd = parse_struct(code( struct ADT_Node; )); CodeStruct adt_node_fwd = parse_struct(code( struct gen_ADT_Node; ));
CodeTypedef adt_node_typedef = parse_typedef(code( typedef struct ADT_Node ADT_Node; )); CodeTypedef adt_node_typedef = parse_typedef(code( typedef struct gen_ADT_Node gen_ADT_Node; ));
header_parsing.append(adt_node_fwd); header_parsing.append(adt_node_fwd);
header_parsing.append(adt_node_typedef); header_parsing.append(adt_node_typedef);
@ -644,12 +646,15 @@ do \
case CT_Preprocess_If: case CT_Preprocess_If:
{ {
CodePreprocessCond cond = cast(CodePreprocessCond, entry); CodePreprocessCond cond = cast(CodePreprocessCond, entry);
if (cond->Content.contains(txt("GEN_COMPILER_C"))) if (cond->Content.is_equal(txt("GEN_COMPILER_C")))
{ {
//++ entry; // ++ entry; // #if
//ast.append(entry) // typedef for ( ; entry != parsed_ast.end() && entry->Type != CT_Preprocess_Else; ++ entry) {
//for ( ; entry != parsed_ast.end() && entry->Type != CT_Preprocess_EndIf; ++ entry) {} ast.append(entry);
//++ entry; // Consume endif }
for ( ; entry != parsed_ast.end() && entry->Type != CT_Preprocess_EndIf; ++ entry) {}
++ entry; // Consume endif
continue;
} }
b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_ast, ast); b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_ast, ast);
@ -1096,7 +1101,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
{ {
CodeBody body = cast(CodeBody, entry->Body); CodeBody body = cast(CodeBody, entry->Body);
CodeBody new_body = def_body(CT_Struct_Body); CodeBody new_body = def_body(CT_Struct_Body);
for ( Code body_entry = body.begin(); body.end(); ++ body_entry ) switch(body_entry->Type) for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch(body_entry->Type)
{ {
case CT_Preprocess_If: case CT_Preprocess_If:
{ {
@ -1124,7 +1129,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
break; break;
} }
s32 idx = 0; s32 idx = 0;
CodeBody parsed_header_end = parse_file( project_dir "components/header_end.hpp" ); CodeBody parsed_header_end = parse_file( project_dir "components/header_end.hpp" );
CodeBody header_end = def_body(CT_Global_Body); CodeBody header_end = def_body(CT_Global_Body);
@ -1176,9 +1180,9 @@ R"(#define <interface_name>( code ) _Generic( (code), \
#pragma endregion Resolve Dependencies #pragma endregion Resolve Dependencies
#pragma region Resolve Components #pragma region Resolve Components
CodeBody array_arena = gen_array(txt("Arena"), txt("Array_Arena")); CodeBody array_arena = gen_array(txt("gen_Arena"), txt("Array_gen_Arena"));
CodeBody array_pool = gen_array(txt("Pool"), txt("Array_Pool")); CodeBody array_pool = gen_array(txt("gen_Pool"), txt("Array_gen_Pool"));
CodeBody array_token = gen_array(txt("Token"), txt("Array_Token")); CodeBody array_token = gen_array(txt("gen_Token"), txt("Array_gen_Token"));
Code src_static_data = scan_file( project_dir "components/static_data.cpp" ); Code src_static_data = scan_file( project_dir "components/static_data.cpp" );
Code src_ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" ); Code src_ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" );
@ -1367,7 +1371,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
break; break;
} }
CodeBody array_code_typename = gen_array(txt("CodeTypename"), txt("Array_CodeTypename")); CodeBody array_code_typename = gen_array(txt("gen_CodeTypename"), txt("Array_gen_CodeTypename"));
CodeBody parsed_src_parser = parse_file( project_dir "components/parser.cpp" ); CodeBody parsed_src_parser = parse_file( project_dir "components/parser.cpp" );
CodeBody src_parser = def_body(CT_Global_Body); CodeBody src_parser = def_body(CT_Global_Body);
@ -1464,7 +1468,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print_fmt( "\n#pragma region Parsing\n" ); header.print_fmt( "\n#pragma region Parsing\n" );
header.print( format_code_to_untyped(header_parsing) ); header.print( format_code_to_untyped(header_parsing) );
header.print_fmt( "#pragma endregion Parsing\n\n" ); header.print_fmt( "#pragma endregion Parsing\n" );
header.print_fmt( "\nGEN_NS_END\n" ); header.print_fmt( "\nGEN_NS_END\n" );
header.print_fmt( roll_own_dependencies_guard_end ); header.print_fmt( roll_own_dependencies_guard_end );
@ -1493,6 +1497,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print_fmt("\n#pragma endregion AST\n"); header.print_fmt("\n#pragma endregion AST\n");
header.print( format_code_to_untyped(interface) ); header.print( format_code_to_untyped(interface) );
header.print(fmt_newline);
header.print_fmt("#pragma region Inlines\n"); header.print_fmt("#pragma region Inlines\n");
header.print( format_code_to_untyped(inlines) ); header.print( format_code_to_untyped(inlines) );
@ -1500,16 +1505,14 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print(fmt_newline); header.print(fmt_newline);
header.print( format_code_to_untyped(array_string_cached)); header.print( format_code_to_untyped(array_string_cached));
header.print(fmt_newline);
header.print( format_code_to_untyped(header_end) ); header.print( format_code_to_untyped(header_end) );
header.print_fmt( "\n#pragma region Builder\n" ); header.print_fmt( "\n#pragma region Builder\n" );
header.print( format_code_to_untyped(header_builder) ); header.print( format_code_to_untyped(header_builder) );
header.print_fmt( "#pragma endregion Builder\n" ); header.print_fmt( "\n#pragma endregion Builder\n" );
header.print_fmt( "\nGEN_API_C_END\n" ); header.print_fmt( "\nGEN_API_C_END\n" );
header.print_fmt( "GEN_NS_END\n\n" ); header.print_fmt( "GEN_NS_END\n\n" );
#pragma endregion Print Compoennts #pragma endregion Print Compoennts
} }
@ -1520,8 +1523,8 @@ R"(#define <interface_name>( code ) _Generic( (code), \
#pragma region Print Dependencies #pragma region Print Dependencies
header.print_fmt( roll_own_dependencies_guard_start ); header.print_fmt( roll_own_dependencies_guard_start );
header.print_fmt( "GEN_NS_BEGIN\n\n"); header.print_fmt( "GEN_NS_BEGIN\n");
header.print_fmt( "GEN_API_C_BEGIN\n\n" ); header.print_fmt( "GEN_API_C_BEGIN\n" );
header.print( src_impl_start ); header.print( src_impl_start );
header.print( src_debug ); header.print( src_debug );
@ -1535,7 +1538,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print_fmt( "\n#pragma region Parsing\n" ); header.print_fmt( "\n#pragma region Parsing\n" );
header.print( scan_file( project_dir "dependencies/parsing.cpp" ) ); header.print( scan_file( project_dir "dependencies/parsing.cpp" ) );
header.print_fmt( "#pragma endregion Parsing\n\n" ); header.print_fmt( "\n#pragma endregion Parsing\n\n" );
header.print_fmt( "GEN_NS_END\n"); header.print_fmt( "GEN_NS_END\n");
header.print_fmt( roll_own_dependencies_guard_end ); header.print_fmt( roll_own_dependencies_guard_end );
@ -1546,6 +1549,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print_fmt( "\nGEN_NS_BEGIN\n"); header.print_fmt( "\nGEN_NS_BEGIN\n");
header.print( fmt_newline);
header.print( format_code_to_untyped(array_arena)); header.print( format_code_to_untyped(array_arena));
header.print( fmt_newline); header.print( fmt_newline);
header.print( format_code_to_untyped(array_pool)); header.print( format_code_to_untyped(array_pool));
@ -1572,17 +1576,17 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print( src_parsing_interface ); header.print( src_parsing_interface );
header.print_fmt( "\n#pragma endregion Parsing\n" ); header.print_fmt( "\n#pragma endregion Parsing\n" );
header.print( src_untyped ); header.print( src_untyped );
header.print_fmt( "\n#pragma endregion Interface\n\n"); header.print_fmt( "\n#pragma endregion Interface\n\n");
header.print_fmt( "#pragma region Builder\n" ); header.print_fmt( "#pragma region Builder\n" );
header.print( scan_file( project_dir "auxillary/builder.cpp" ) ); header.print( scan_file( project_dir "auxillary/builder.cpp" ) );
header.print_fmt( "\n#pragma endregion Builder\n\n" ); header.print_fmt( "#pragma endregion Builder\n\n" );
// header.print_fmt( "\n#pragma region Scanner\n" ); header.print_fmt( "\n#pragma region Scanner\n" );
// header.print( scan_file( project_dir "auxillary/scanner.hpp" ) ); header.print( scan_file( project_dir "auxillary/scanner.hpp" ) );
// header.print_fmt( "#pragma endregion Scanner\n\n" ); header.print_fmt( "#pragma endregion Scanner\n\n" );
header.print_fmt( "\nGEN_API_C_END\n" ); header.print_fmt( "GEN_API_C_END\n" );
#pragma endregion Print Components #pragma endregion Print Components
header.print_fmt( implementation_guard_end ); header.print_fmt( implementation_guard_end );

View File

@ -0,0 +1,545 @@
__VERSION 1
// This is a example template to be used with the refactor program
// Use it to refactor the naming convention of this library to your own.
// Can be used as an aid to help use use your project's implementation if it fullfills the dependencies of this project.
// Example: Most likely have a memory and string library already, just rename the functions and make sure the args are the same.
// Program: https://github.com/Ed94/refactor
// NOTE: Due to the current limitations of the program, not every symbol in the library can be renamed.
// This is due to the program not actually parsing C/C++.
// not : Ignore
// include : #includes
// word : Alphanumeric or underscore
// namespace : Prefix search and replace (c-namspaces).
// regex : Unavailable in __VERSION 1.
// Precedence (highest to lowest):
// word, namespace, regex
// Gen Macro namespace
// namespace GEN_, new_namespace_
// Macros
word global, gen_global
word internal, gen_internal
word local_persist, gen_local_persist
word bit, gen_bit
word bitfield_is_equal, gen_bitfield_is_equal
word cast, gen_cast
word ccast, gen_ccast
word pcast, gen_pcast
word rcast, gen_rcast
word scast, gen_scast
word stringize_va, gen_stringize_va
word stringize, gen_stringize
word do_once, gen_do_once
word do_once_start, gen_do_once_start
word do_once_end, gen_do_once_end
word labeled_scope_start, gen_labeled_scope_start
word labeled_scope_end, gen_labeled_scope_end
word compiler_decorated_func_name, gen_compiler_decorated_func_name
word num_args_impl, gen_num_args_impl
word num_args, gen_num_args
word clamp, gen_clamp
word count_of, gen_count_of
word is_between, gen_is_between
word size_of, gen_size_of
word max, gen_max
word min, gen_min
word offset_of, gen_offset_of
word forceinline, gen_forceinline
word neverinline, gen_neverinline
word static_assert, gen_static_assert
word thread_local, gen_thread_local
word typeof, gen_typeof
word enum_underlying, gen_enum_underlying
word nullptr, gen_nullptr
word struct_init, gen_struct_init
word hash, gen_hash
// Basic Types
word u8, gen_u8
word s8, gen_s8
word u16, gen_u16
word s16, gen_s16
word u32, gen_u32
word s32, gen_s32
word u64, gen_u64
word s64, gen_s64
word usize, gen_usize
word ssize, gen_ssize
word sptr, gen_sptr
word uptr, gen_uptr
word f32, gen_f32
word f64, gen_f64
word b8, gen_b8
word b16, gen_b16
word b32, gen_b32
word mem_ptr, gen_mem_ptr
word mem_ptr_const, gen_mem_ptr_cnst
// Debug
word assert_handler, gen_assert_handler
word assert_crash, gen_assert_crash
word process_exit, gen_process_exit
// Memory
word kilobytes, gen_kilobytes
word megabytes, gen_megabytes
word gigabytes, gen_gigabytes
word terabytes, gen_terabytes
word swap, gen_swap
word is_power_of_two, gen_is_power_of_two
word align_forward, gen_align_forward
word align_forward_by_value, gen_align_forward_by_value
word pointer_add, gen_pointer_add
word pointer_add_const, gen_pointer_add_const
word pointer_diff, gen_pointer_diff
word mem_copy, gen_mem_copy
word mem_find, gen_mem_find
word mem_move, gen_mem_move
word mem_set, gen_mem_set
word zero_size, gen_zero_size
word zero_item, gen_zero_item
word zero_array, gen_zero_array
word AllocType, gen_AllocType
word AllocatorProc, gen_AllocatorProc
word AllocatorInfo, gen_AllocatorInfo
word AllocFlag, gen_AllocFlag
word alloc, gen_alloc
word alloc_align, gen_alloc_align
word allocator_free, gen_allocator_free
word free_all, gen_free_all
word resize, gen_resize
word resize_align, gen_resize_align
word alloc_item, gen_alloc_item
word alloc_array, gen_alloc_array
word heap_stats_init, gen_heap_stats_init
word heap_stats_used_memory, gen_heap_stats_used_memory
word heap_stats_alloc_count, gen_heap_stats_alloc_count
word heap_stats_check, gen_heap_stats_check
word default_resize_align, gen_default_resize_align
word heap_allocator_proc, gen_heap_allocator_proc
word heap, gen_heap
word malloc, gen_malloc
word mfree, gen_mfree
word VirtualMemory, gen_VirtualMemory
word vm_from_memory, gen_vm_from_memory
word vm_alloc, gen_vm_alloc
word vm_free, gen_vm_free
word vm_trim, gen_vm_trim
word vm_purge, gen_vm_purge
word virtual_memory_page_size, gen_virtual_memory_page_size
// Memory: Arena
word Arena, gen_Arena
namespace arena_, gen_arena_
// word arena_allocator_info
// word arena_init_from_memory
// word arena_init_from_allocator
// word arena_init_sub
// word arena_alignment_of
// word arena_check
// word arena_size_remaining
// Memory: FixedArena
namespace FixedArena_, gen_FixedArena_
namespace fixed_arena_, gen_fixed_arena_
// Memory: Pool
word Pool, gen_Pool
namespace pool_, gen_pool_
// Printing
namespace str_, gen_str_
word PrintF_Buffer, gen_PrintF_Buffer
word Msg_Invalid_Value, gen_Msg_Invalid_Value
word log_fmt, gen_log_fmt
// String Ops
namespace char_, gen_char_
word digit_to_int, gen_digit_to_int
word hex_digit_to_init, gen_hex_digit_to_init
word i64_to_str, gen_i64_to_str
word u64_to_str, gen_u64_to_str
// Containers
namespace GENERIC_SLOT_, GEN_GENERIC_SLOT_
word Array, gen_Array
word Array_ssize, gen_Array_gen_ssize
word ArrayHeader, gen_ArrayHeader
namespace Array_, gen_Array_
namespace array_, gen_array_
word HashTable, gen_HashTable
namespace HashTable_, gen_HashTable_
namespace hashtable_, gen_hashtable_
namespace HT_, gen_HT_
namespace HTE_, gen_HTE_
namespace arr_hte_, gen_arr_hte_
namespace Arr_HTE_, gen_Arr_HTE_
// Hashing
word crc32, gen_crc32
word crc64, gen_crc64
// Strings
word StrC, gen_StrC
word to_strc_from_c_str, gen_to_strc_from_c_str
namespace strc_, gen_strc_
word cast_to_strc, gen_cast_to_strc
word StringHeader, gen_StringHeader
word String, gen_String
namespace string_, gen_string_
word StringCached, gen_StringCached
word StringTable, gen_StringTable
namespace StringTable_, gen_StringTable_
// File Handling
word FileModeFlag, gen_FileModeFlag
word SeekWhenceType, gen_SeekWhenceType
word FileError, gen_FileError
word FileDescriptor, gen_FileDescriptor
word FileMode, gen_FileMode
word FileOperations, gen_FileOperations
word FileOperations, gen_FileOperations
default_file_operations
word FileTime, word FileTime
word DirType, gen_DirType
word DirInfo, gen_DirInfo
word DirEntry, gen_DirEntry
word DirInfo, gen_DirInfo
word FileInfo, gen_FileInfo
word FileStandardType, gen_FileStandardType
namespace file_, gen_file_
word gen_FileContents, gen_FileContents
// Timing
word read_cpu_time_stamp_counter, gen_read_cpu_time_stamp_counter
word time_rel, gen_time_rel
word time_rel_ms, gen_time_rel_ms
// Parsing
// Parsing: ADT
word ADT_Node, gen_ADT_Node
word ADT_Type, gen_ADT_Type
word ADT_Props, gen_ADT_Props
word ADT_NamingStyle, gen_ADT_NamingStyle
word ADT_AssignStyle, gen_ADT_AssignStyle
word ADT_DelimStyle, gen_ADT_DelimStyle
word ADT_Error, gen_ADT_Error
word ADT_Node, gen_ADT_Node
namespace adt_, gen_adt_
word CSV_Error, gen_CSV_Error
word CSV_Object, gen_CSV_Object
namespace csv_, gen_csv_
// Types.hpp
word log_failure, gen_log_failure
word AccessSpec, gen_AccessSpec
word access_spec_to_str, gen_access_spec_to_str
word CodeFlag, gen_CodeFlag
word EnumDecl, gen_EnumDecl
word ModuleFlag, gen_ModuleFlag
word module_flag_to_str, gen_module_flag_to_str
word EPreprocessCond, gen_EPreprocessCOnd
word ETypenameTag, gen_ETypenameTag
word CodeType, gen_CodeType
word codetype_to_str, gen_codetype_to_str
word codetype_to_keyword_str, gen_codetype_to_keyword_str
word Operator, gen_Operator
word operator_to_str, gen_operator_to_str
word Specifier, gen_Specifier
word spec_to_str, gen_spec_to_str
word spec_is_trailing, gen_spec_is_trailing
// word strc_to_specifier, gen_strc_to_specifier
// AST
word AST, gen_AST
namespace AST_, gen_AST_
word Code, gen_Code
word Token, gen_Token
word CodeBody, gen_CodeBody
word CodeAttributes, gen_CodeAttributes
word CodeComment, gen_CodeComment
word CodeClass, gen_CodeClass
word CodeConstructor, gen_CodeConstructor
word CodeDefine, gen_CodeDefine
word CodeDestructor, gen_CodeDestructor
word CodeEnum, gen_CodeEnum
word CodeExec, gen_CodeExec
word CodeExtern, gen_CodeExtern
word CodeInclude, gen_CodeInclude
word CodeFriend, gen_CodeFriend
word CodeFn, gen_CodeFn
word CodeModule, gen_CodeModule
word CodeNS, gen_CodeNS
word CodeOperator, gen_CodeOperator
word CodeOpCast, gen_CodeOpCast
word CodePragma, gen_CodePragma
word CodeParam, gen_CodeParam
word CodePreprocessCo, gen_CodePreprocessCo
word CodeSpecifiers, gen_CodeSpecifiers
word CodeTemplate, gen_CodeTemplate
word CodeTypename, gen_CodeTypename
word CodeTypedef, gen_CodeTypedef
word CodeUnion, gen_CodeUnion
word CodeUsing, gen_CodeUsing
word CodeVar, gen_CodeVar
// Code Interface
namespace code_, gen_code_
word Code_Global, gen_Code_Global
word Code_Invalid, gen_Code_Invalid
word Code_POD, gen_Code_POD
word AST_POD_Size, gen_AST_POD_Size
word AST_ArrSpecs_Cap, gen_AST_ArrSpecs_Cap
word InvalidCode, gen_InvalidCode
word NullCode, gen_NullCode
namespace begin_, gen_begin_
namespace end_, gen_end_
namespace next_, gen_next_
namespace body_, gen_body_
namespace class_, gen_class_
namespace params_, gen_params_
namespace specifiers_, gen_specifiers_
namespace struct_, gen_struct_
namespace attributes_, gen_attributes_
namespace comment_, gen_comment_
namespace constructor, gen_constructor_
namespace define_, gen_define_
namespace destructor, gen_destructor_
namespace enum_, gen_enum_
namespace exec_, gen_exec_
namespace extern_, gen_extern_
namespace include_, gen_include_
namespace friend_, gen_friend_
namespace fn_, gen_fn_
namespace module_, gen_module_
namespace code_op, gen_code_op_
namespace opcast_, gen_opcast_
namespace pragma_, gen_pragma_
namespace preprocess_, gen_preprocess_
namespace template_, gen_template_
namespace typename_, gen_typename_
namespace typedef_, gen_typedef_
namesapce union_, gen_union_
namespace using_, gen_using_
namespace var_, gen_var_
// Gen Interface
word init, gen_init
word deinit, gen_deinit
word reset, gen_reset
word get_cached_string, gen_get_cached_string
word make_code, gen_make_code
namespace set_allocator_, gen_set_allocator_
namespace def_, gen_def_
namespace parse_, gen_parse_
namespace token_, gen_token_
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
word attrib_api_export, gen_attrib_api_export
word attrib_api_import, gen_attrib_api_import
word module_global_fragment, gen_module_global_fragment
word module_private_fragment, gen_module_private_fragment
word fmt_newline, gen_fmt_newline
word pragma_once, gen_pragma_once
word param_varadic, gen_param_varadic
word preprocess_else, gen_preprocess_else
namespace spec_, gen_spec_
namespace t_, gen_t_
word PreprocessorDefines, gen_PreprocessorDefines
// Backend
word GlobalAllocator, gen_GlobalAllocator
word Global_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
namespace builder_, gen_builder_
// Implementation (prviate)
word _format_info, gen__format_info
namespace _print_, gen__print_
word _heap_stats, gen__heap_stats
word _heap_alloc_info, gen__heap_alloc_info
word _crc32_table, gen__crc32_table
word _crc64_table, gen__crc64_table
word _alloc_utf8_to_ucs2, gen__alloc_utf8_to_ucs2
word _win32_file_seek, gen__win32_file_seek
word _win32_file_read, gen__win32_file_read
word _win32_file_write, gen__win32_file_write
word _win32_file_close, gen__win32_file_close
word _win32_file_open, gen__win32_file_open
word _posix_file_seek, gen__posix_file_seek
word _posix_file_read, gen__posix_file_read
word _posix_file_write, gen__posix_file_write
word _posix_file_close, gen__posix_file_close
word _posix_file_open, gen__posix_file_open
word _dirinfo_free_entry, gen__dirinfo_free_entry
word _std_file_set, gen__std_file_set
word _memory_fd, gen__memory_fd
word _file_stream_fd_make, gen__file_stream_fd_make
word _file_stream_from_fd, gen__file_stream_from_fd
word _memory_file_seek, gen__memory_file_seek
word _memory_file_read, gen__memory_file_read
word _memory_file_write, gen__memory_file_write
word _memory_file_close, gen__memory_file_close
word _unix_gettime, gen__unix_gettime
word _adt_fprintf, gen__adt_fprintf
word _adt_get_value, gen__adt_get_value
word _adt_get_field, gen__adt_get_field
word _csv_write_record, gen__csv_write_record
word _csv_write_header, gen__csv_write_header
word Global_Allocator_Proc, gen_Global_Allocator_Proc
word define_constants, gen_define_constants
word operator__validate, gen_operator__validate
word parser_init, gen_parser_init
word parser_deinit, gen_parser_deinit
word TokType, gen_TokType
word toktype_to_str, gen_toktype_to_str
// word strc_to_toktype, gen_strc_to_toktype
word NullToken, gen_NullToken
namespace tok_, gen_tok_
word TokArray, gen_TokArray
namespace lex_, gen_lex_
namespace Lexer_, gen_Lexer_
word LexContext, gen_LexContext
word lex, gen_lex
word StackNode, gen_StackNode
word ParseContext, gen_ParseContext
// namespace parse_, gen_parse_
namespace parser_, gen_parser_

View File

@ -21,7 +21,7 @@ CodeBody gen_array_base()
Code grow_formula = untyped_str( txt( "#define array_grow_formula( value ) ( 2 * value + 8 )\n" )); Code grow_formula = untyped_str( txt( "#define array_grow_formula( value ) ( 2 * value + 8 )\n" ));
Code get_header = untyped_str( txt( "#define array_get_header( self ) ( (ArrayHeader*)( self ) - 1)\n" )); Code get_header = untyped_str( txt( "#define array_get_header( self ) ( (ArrayHeader*)( self ) - 1)\n" ));
Code type_define = untyped_str( txt( "#define Array(Type) Array_##Type\n")); Code type_define = untyped_str( txt( "#define Array(Type) gen_Array_##Type\n"));
Code array_begin = def_define(txt("array_begin(array)"), code( (array) )); Code array_begin = def_define(txt("array_begin(array)"), code( (array) ));
Code array_end = def_define(txt("array_end(array)"), code( (array + array_get_header(array)->Num ) )); Code array_end = def_define(txt("array_end(array)"), code( (array + array_get_header(array)->Num ) ));

View File

@ -4,4 +4,5 @@
int main() int main()
{ {
// init(); // init();
__debugbreak();
} }

View File

@ -1,8 +1,8 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<N10X> <N10X>
<Workspace> <Workspace>
<IncludeFilter>*.*,</IncludeFilter> <IncludeFilter>&amp;apos;.&amp;apos;,**/project/**,</IncludeFilter>
<ExcludeFilter>*.obj,*.lib,*.pch,*.dll,*.pdb,.vs,Debug,Release,x64,obj,*.user,Intermediate,**/sanity.gen.hpp,</ExcludeFilter> <ExcludeFilter>*.obj,*.lib,*.pch,*.dll,*.pdb,.vs,Debug,Release,x64,obj,*.user,Intermediate,**/sanity.gen.hpp,**/gen_c_library,**/gen_segmented,**/gen_singlheader,**/test,**/gen_unreal_engine,**/scripts,**/docs,</ExcludeFilter>
<SyncFiles>true</SyncFiles> <SyncFiles>true</SyncFiles>
<Recursive>true</Recursive> <Recursive>true</Recursive>
<ShowEmptyFolders>true</ShowEmptyFolders> <ShowEmptyFolders>true</ShowEmptyFolders>

View File

@ -39,7 +39,7 @@ void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va )
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1; res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
string_append_c_str_len( (String*) & builder->Buffer, (char const*)buf, res); string_append_c_str_len( (String*) & (builder->Buffer), (char const*)buf, res);
} }
void builder_write(Builder* builder) void builder_write(Builder* builder)

View File

@ -30,7 +30,10 @@ struct Builder
forceinline void print( Code code ) { return builder_print(this, code); } forceinline void print( Code code ) { return builder_print(this, code); }
forceinline void print_fmt( char const* fmt, ... ) { forceinline void print_fmt( char const* fmt, ... ) {
va_list va;
va_start( va, fmt );
builder_print_fmt_va( this, fmt, va );
va_end( va );
} }
forceinline void write() { return builder_write(this); } forceinline void write() { return builder_write(this); }

View File

@ -206,22 +206,22 @@ int gen_main()
Builder header_ecode = builder_open( "components/gen/ecode.hpp" ); Builder header_ecode = builder_open( "components/gen/ecode.hpp" );
builder_print( & header_ecode, gen_component_header ); builder_print( & header_ecode, gen_component_header );
builder_print( & header_ecode, ecode ); builder_print( & header_ecode, dump_to_scratch_and_retireve(ecode) );
builder_write( & header_ecode); builder_write( & header_ecode);
Builder header_eoperator = builder_open( "components/gen/eoperator.hpp" ); Builder header_eoperator = builder_open( "components/gen/eoperator.hpp" );
builder_print( & header_eoperator, gen_component_header ); builder_print( & header_eoperator, gen_component_header );
builder_print( & header_eoperator, eoperator ); builder_print( & header_eoperator, dump_to_scratch_and_retireve(eoperator) );
builder_write( & header_eoperator ); builder_write( & header_eoperator );
Builder header_especifier = builder_open( "components/gen/especifier.hpp" ); Builder header_especifier = builder_open( "components/gen/especifier.hpp" );
builder_print( & header_especifier, gen_component_header ); builder_print( & header_especifier, gen_component_header );
builder_print( & header_especifier, especifier ); builder_print( & header_especifier, dump_to_scratch_and_retireve(especifier) );
builder_write( & header_especifier); builder_write( & header_especifier);
Builder header_ast_inlines = builder_open( "components/gen/ast_inlines.hpp" ); Builder header_ast_inlines = builder_open( "components/gen/ast_inlines.hpp" );
builder_print( & header_ast_inlines, gen_component_header ); builder_print( & header_ast_inlines, gen_component_header );
builder_print( & header_ast_inlines, ast_inlines ); builder_print( & header_ast_inlines, dump_to_scratch_and_retireve(ast_inlines) );
builder_write( & header_ast_inlines); builder_write( & header_ast_inlines);
} }
@ -244,6 +244,7 @@ int gen_main()
CodeBody nspaced_etoktype = def_global_body( args( CodeBody nspaced_etoktype = def_global_body( args(
etoktype etoktype
)); ));
Code formatted_toktype = dump_to_scratch_and_retireve(nspaced_etoktype);
Builder _src = builder_open( "gen/gen.cpp" ); Builder _src = builder_open( "gen/gen.cpp" );
Builder* src = & _src; Builder* src = & _src;
@ -264,7 +265,7 @@ int gen_main()
builder_print( src, interface ); builder_print( src, interface );
builder_print( src, upfront ); builder_print( src, upfront );
builder_print_fmt( src, "\n#pragma region Parsing\n\n" ); builder_print_fmt( src, "\n#pragma region Parsing\n\n" );
builder_print( src, dump_to_scratch_and_retireve(nspaced_etoktype) ); builder_print( src, formatted_toktype );
builder_print( src, lexer ); builder_print( src, lexer );
builder_print( src, parser ); builder_print( src, parser );
builder_print( src, parsing_interface ); builder_print( src, parsing_interface );
@ -278,7 +279,7 @@ int gen_main()
Builder src_etoktype = builder_open( "components/gen/etoktype.cpp" ); Builder src_etoktype = builder_open( "components/gen/etoktype.cpp" );
builder_print( & src_etoktype, gen_component_header ); builder_print( & src_etoktype, gen_component_header );
builder_print( & src_etoktype, nspaced_etoktype ); builder_print( & src_etoktype, formatted_toktype );
builder_write( & src_etoktype); builder_write( & src_etoktype);
} }

View File

@ -92,27 +92,27 @@ struct Code;
#endif #endif
#if GEN_COMPILER_C #if GEN_COMPILER_C
typdef AST_Body* CodeBody; typedef AST_Body* CodeBody;
typdef AST_Attributes* CodeAttributes; typedef AST_Attributes* CodeAttributes;
typdef AST_Comment* CodeComment; typedef AST_Comment* CodeComment;
typdef AST_Class* CodeClass; typedef AST_Class* CodeClass;
typdef AST_Constructor* CodeConstructor; typedef AST_Constructor* CodeConstructor;
typdef AST_Define* CodeDefine; typedef AST_Define* CodeDefine;
typdef AST_Destructor* CodeDestructor; typedef AST_Destructor* CodeDestructor;
typdef AST_Enum* CodeEnum; typedef AST_Enum* CodeEnum;
typdef AST_Exec* CodeExec; typedef AST_Exec* CodeExec;
typdef AST_Extern* CodeExtern; typedef AST_Extern* CodeExtern;
typdef AST_Include* CodeInclude; typedef AST_Include* CodeInclude;
typdef AST_Friend* CodeFriend; typedef AST_Friend* CodeFriend;
typdef AST_Fn* CodeFn; typedef AST_Fn* CodeFn;
typdef AST_Module* CodeModule; typedef AST_Module* CodeModule;
typdef AST_NS* CodeNS; typedef AST_NS* CodeNS;
typdef AST_Operator* CodeOperator; typedef AST_Operator* CodeOperator;
typdef AST_OpCast* CodeOpCast; typedef AST_OpCast* CodeOpCast;
typdef AST_Param* CodeParam; typedef AST_Param* CodeParam;
typdef AST_PreprocessCond* CodePreprocessCond; typedef AST_PreprocessCond* CodePreprocessCond;
typdef AST_Pragma* CodePragma; typedef AST_Pragma* CodePragma;
typdef AST_Specifiers* CodeSpecifiers; typedef AST_Specifiers* CodeSpecifiers;
#else #else
struct CodeBody; struct CodeBody;
struct CodeAttributes; struct CodeAttributes;

View File

@ -184,54 +184,34 @@ void define_constants()
# undef def_constant_code_type # undef def_constant_code_type
# define def_constant_spec( Type_, ... ) \ spec_const = def_specifier( Spec_Const); code_set_global( cast(Code, spec_const ));
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \ spec_consteval = def_specifier( Spec_Consteval); code_set_global( cast(Code, spec_consteval ));;
code_set_global( cast(Code, spec_##Type_)); spec_constexpr = def_specifier( Spec_Constexpr); code_set_global( cast(Code, spec_constexpr ));;
spec_constinit = def_specifier( Spec_Constinit); code_set_global( cast(Code, spec_constinit ));;
# pragma push_macro("forceinline") spec_extern_linkage = def_specifier( Spec_External_Linkage); code_set_global( cast(Code, spec_extern_linkage ));;
# pragma push_macro("global") spec_final = def_specifier( Spec_Final); code_set_global( cast(Code, spec_final ));;
# pragma push_macro("internal") spec_forceinline = def_specifier( Spec_ForceInline); code_set_global( cast(Code, spec_forceinline ));;
# pragma push_macro("local_persist") spec_global = def_specifier( Spec_Global); code_set_global( cast(Code, spec_global ));;
# pragma push_macro("neverinline") spec_inline = def_specifier( Spec_Inline); code_set_global( cast(Code, spec_inline ));;
# undef forceinline spec_internal_linkage = def_specifier( Spec_Internal_Linkage); code_set_global( cast(Code, spec_internal_linkage ));;
# undef global spec_local_persist = def_specifier( Spec_Local_Persist); code_set_global( cast(Code, spec_local_persist ));;
# undef internal spec_mutable = def_specifier( Spec_Mutable); code_set_global( cast(Code, spec_mutable ));;
# undef local_persist spec_neverinline = def_specifier( Spec_NeverInline); code_set_global( cast(Code, spec_neverinline ));;
# undef neverinline spec_noexcept = def_specifier( Spec_NoExceptions); code_set_global( cast(Code, spec_noexcept ));;
def_constant_spec( const, Spec_Const ); spec_override = def_specifier( Spec_Override); code_set_global( cast(Code, spec_override ));;
def_constant_spec( consteval, Spec_Consteval ); spec_ptr = def_specifier( Spec_Ptr); code_set_global( cast(Code, spec_ptr ));;
def_constant_spec( constexpr, Spec_Constexpr ); spec_pure = def_specifier( Spec_Pure); code_set_global( cast(Code, spec_pure ));
def_constant_spec( constinit, Spec_Constinit ); spec_ref = def_specifier( Spec_Ref); code_set_global( cast(Code, spec_ref ));;
def_constant_spec( extern_linkage, Spec_External_Linkage ); spec_register = def_specifier( Spec_Register); code_set_global( cast(Code, spec_register ));;
def_constant_spec( final, Spec_Final ); spec_rvalue = def_specifier( Spec_RValue); code_set_global( cast(Code, spec_rvalue ));;
def_constant_spec( forceinline, Spec_ForceInline ); spec_static_member = def_specifier( Spec_Static); code_set_global( cast(Code, spec_static_member ));;
def_constant_spec( global, Spec_Global ); spec_thread_local = def_specifier( Spec_Thread_Local); code_set_global( cast(Code, spec_thread_local ));;
def_constant_spec( inline, Spec_Inline ); spec_virtual = def_specifier( Spec_Virtual); code_set_global( cast(Code, spec_virtual ));;
def_constant_spec( internal_linkage, Spec_Internal_Linkage ); spec_volatile = def_specifier( Spec_Volatile); code_set_global( cast(Code, spec_volatile ));
def_constant_spec( local_persist, Spec_Local_Persist );
def_constant_spec( mutable, Spec_Mutable );
def_constant_spec( neverinline, Spec_NeverInline );
def_constant_spec( noexcept, Spec_NoExceptions );
def_constant_spec( override, Spec_Override );
def_constant_spec( ptr, Spec_Ptr );
def_constant_spec( pure, Spec_Pure )
def_constant_spec( ref, Spec_Ref );
def_constant_spec( register, Spec_Register );
def_constant_spec( rvalue, Spec_RValue );
def_constant_spec( static_member, Spec_Static );
def_constant_spec( thread_local, Spec_Thread_Local );
def_constant_spec( virtual, Spec_Virtual );
def_constant_spec( volatile, Spec_Volatile)
spec_local_persist = def_specifiers( 1, Spec_Local_Persist ); spec_local_persist = def_specifiers( 1, Spec_Local_Persist );
code_set_global(cast(Code, spec_local_persist)); code_set_global(cast(Code, spec_local_persist));
# pragma pop_macro("forceinline")
# pragma pop_macro("global")
# pragma pop_macro("internal")
# pragma pop_macro("local_persist")
# pragma pop_macro("neverinline")
# pragma push_macro("enum_underlying") # pragma push_macro("enum_underlying")
array_append(PreprocessorDefines, txt("enum_underlying(")); array_append(PreprocessorDefines, txt("enum_underlying("));
# pragma pop_macro("enum_underlying") # pragma pop_macro("enum_underlying")

View File

@ -278,51 +278,64 @@ Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
#pragma region Macros #pragma region Macros
#ifndef gen_main
#define gen_main main
#endif
#ifndef name
// Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL.
#define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
#endif
#ifndef code
// Same as name just used to indicate intention of literal for code instead of names.
#define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
#endif
#ifndef args
// Provides the number of arguments while passing args inplace.
#define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
#endif
#ifndef code_str
// Just wrappers over common untyped code definition constructions.
#define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
#endif
#ifndef code_fmt
#define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
#endif
#ifndef parse_fmt
#define parse_fmt( type, ... ) GEN_NS parse_##type( token_fmt( __VA_ARGS__ ) )
#endif
#ifndef token_fmt #ifndef token_fmt
# define gen_main main /*
Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
# define __ NullCode Tokens are provided in '<'identifier'>' format where '<' '>' are just angle brackets (you can change it in token_fmt_va)
---------------------------------------------------------
// Convienence for defining any name used with the gen api. Example - A string with:
// Lets you provide the length and string literal to the functions without the need for the DSL. typedef <type> <name> <name>;
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) } Will have a token_fmt arguments populated with:
"type", strc_for_type,
// Same as name just used to indicate intention of literal for code instead of names. "name", strc_for_name,
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) } and:
stringize( typedef <type> <name> <name>; )
// Provides the number of arguments while passing args inplace. -----------------------------------------------------------
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__ So the full call for this example would be:
token_fmt(
// Just wrappers over common untyped code definition constructions. "type", strc_for_type
# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) ) , "name", strc_for_name
# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) ) , stringize(
typedef <type> <name> <name>
# define parse_fmt( type, ... ) GEN_NS parse_##type( token_fmt( __VA_ARGS__ ) ) ));
!----------------------------------------------------------
/* ! Note: token_fmt_va is whitespace sensitive for the tokens.
Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string. ! This can be alleviated by skipping whitespace between brackets but it was choosen to not have that implementation by default.
Tokens are provided in '<'identifier'>' format where '<' '>' are just angle brackets (you can change it in token_fmt_va) */
--------------------------------------------------------- #define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
Example - A string with:
typedef <type> <name> <name>;
Will have a token_fmt arguments populated with:
"type", strc_for_type,
"name", strc_for_name,
and:
stringize( typedef <type> <name> <name>; )
-----------------------------------------------------------
So the full call for this example would be:
token_fmt(
"type", strc_for_type
, "name", strc_for_name
, stringize(
typedef <type> <name> <name>
));
!----------------------------------------------------------
! Note: token_fmt_va is whitespace sensitive for the tokens.
! This can be alleviated by skipping whitespace between brackets but it was choosen to not have that implementation by default.
*/
# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
#endif #endif
#pragma endregion Macros #pragma endregion Macros

View File

@ -319,15 +319,27 @@ CodeVar parse_variable( StrC def )
} }
// Undef helper macros // Undef helper macros
# undef check_parse_args #undef check_parse_args
# undef currtok_noskip #undef currtok_noskip
# undef currtok #undef currtok
# undef peektok #undef peektok
# undef prevtok #undef prevtok
# undef nexttok #undef nexttok
# undef nexttok_noskip #undef nexttok_noskip
# undef eat #undef eat
# undef left #undef left
# undef check #undef check
# undef push_scope #undef push_scope
# undef def_assign #undef def_assign
// Here for C Variant
#undef lex_dont_skip_formatting
#undef lex_skip_formatting
#undef parser_inplace_def
#undef parser_not_inplace_def
#undef parser_dont_consume_braces
#undef parser_consume_braces
#undef parser_not_from_template
#undef parser_use_parenthesis
#undef parser_strip_formatting_dont_preserve_newlines

View File

@ -12,6 +12,7 @@ enum OpValidateResult : u32
OpValResult_Member OpValResult_Member
}; };
internal neverinline
OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTypename ret_type, CodeSpecifiers specifier ) OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTypename ret_type, CodeSpecifiers specifier )
{ {
if ( op == Op_Invalid ) if ( op == Op_Invalid )

View File

@ -355,7 +355,7 @@ size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761u
// If using an Editor with support for syntax hightlighting macros: HASH__ARGS_SIG_1 and HASH_ARGS_SIG_2 should show color highlighting indicating the slot is enabled, // If using an Editor with support for syntax hightlighting macros: HASH__ARGS_SIG_1 and HASH_ARGS_SIG_2 should show color highlighting indicating the slot is enabled,
// or, "defined" for usage during the compilation pass that handles the _Generic instrinsic. // or, "defined" for usage during the compilation pass that handles the _Generic instrinsic.
#define hash( function_arguments ) _Generic( \ #define gen_hash_example( function_arguments ) _Generic( \
(function_arguments), /* Select Via Expression*/ \ (function_arguments), /* Select Via Expression*/ \
/* Extendibility slots: */ \ /* Extendibility slots: */ \
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \ GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \

View File

@ -215,7 +215,7 @@ struct Arena
#endif #endif
}; };
#if GEN_COMPILER_CPP && ! GEN_C_LIKECPP #if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
forceinline AllocatorInfo allocator_info(Arena& arena ) { return arena_allocator_info(& arena); } forceinline AllocatorInfo allocator_info(Arena& arena ) { return arena_allocator_info(& arena); }
forceinline Arena init_sub (Arena& parent, ssize size) { return arena_init_sub( & parent, size); } forceinline Arena init_sub (Arena& parent, ssize size) { return arena_init_sub( & parent, size); }
forceinline ssize alignment_of (Arena& arena, ssize alignment) { return arena_alignment_of( & arena, alignment); } forceinline ssize alignment_of (Arena& arena, ssize alignment) { return arena_alignment_of( & arena, alignment); }

View File

@ -626,7 +626,7 @@ StrC string_to_strc(String str) {
} }
inline inline
void trim(String str, char const* cut_set) void string_trim(String str, char const* cut_set)
{ {
ssize len = 0; ssize len = 0;
@ -650,12 +650,12 @@ void trim(String str, char const* cut_set)
} }
forceinline forceinline
void trim_space(String str) { void string_trim_space(String str) {
trim(str, " \t\r\n\v\f"); string_trim(str, " \t\r\n\v\f");
} }
inline inline
String visualize_whitespace(String const str) String string_visualize_whitespace(String const str)
{ {
StringHeader* header = (StringHeader*)(scast(char const*, str) - sizeof(StringHeader)); StringHeader* header = (StringHeader*)(scast(char const*, str) - sizeof(StringHeader));
String result = string_make_reserve(header->Allocator, string_length(str) * 2); // Assume worst case for space requirements. String result = string_make_reserve(header->Allocator, string_length(str) * 2); // Assume worst case for space requirements.

View File

@ -4,6 +4,7 @@
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1' $devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
$format_cpp = Join-Path $PSScriptRoot 'helpers/format_cpp.psm1' $format_cpp = Join-Path $PSScriptRoot 'helpers/format_cpp.psm1'
$refactor_c_library = Join-Path $PSScriptRoot 'refactor_c_library.ps1'
$refactor_unreal = Join-Path $PSScriptRoot 'refactor_unreal.ps1' $refactor_unreal = Join-Path $PSScriptRoot 'refactor_unreal.ps1'
$incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1' $incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1'
$vendor_toolchain = Join-Path $PSScriptRoot 'helpers/vendor_toolchain.ps1' $vendor_toolchain = Join-Path $PSScriptRoot 'helpers/vendor_toolchain.ps1'
@ -223,6 +224,8 @@ if ( $c_library )
} }
Pop-Location Pop-Location
. $refactor_c_library
$unit = join-path $path_c_library "gen.c" $unit = join-path $path_c_library "gen.c"
$executable = join-path $path_build "gen_c_library_test.exe" $executable = join-path $path_build "gen_c_library_test.exe"
@ -355,7 +358,7 @@ if ( $test )
#region Formatting #region Formatting
push-location $path_scripts push-location $path_scripts
if ( $true -and $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) ) if ( $false -and $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
{ {
$path_gen = join-path $path_project gen $path_gen = join-path $path_project gen
$include = @( $include = @(
@ -367,7 +370,6 @@ if ( $true -and $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp
$exclude = $null $exclude = $null
# format-cpp $path_gen $include $exclude # format-cpp $path_gen $include $exclude
format-cpp $path_comp_gen @( 'ast_inlines.hpp', 'ecode.hpp', 'especifier.hpp', 'eoperator.hpp', 'etoktype.cpp' ) $null format-cpp $path_comp_gen @( 'ast_inlines.hpp', 'ecode.hpp', 'especifier.hpp', 'eoperator.hpp', 'etoktype.cpp' ) $null
} }
if ( $false -and $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp")) ) if ( $false -and $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp")) )

View File

@ -1,24 +0,0 @@
__VERSION 1
// This is a example template to be used with the refactor program
// Use it to refactor the naming convention of this library to your own.
// Can be used as an aid to help use use your project's implementation if it fullfills the dependencies of this project.
// Example: Most likely have a memory and string library already, just rename the functions and make sure the args are the same.
// Program: https://github.com/Ed94/refactor
// NOTE: Due to the current limitations of the program, not every symbol in the library can be renamed.
// This is due to the program not actually parsing C/C++.
// not : Ignore
// include : #includes
// word : Alphanumeric or underscore
// namespace : Prefix search and replace (c-namspaces).
// regex : Unavailable in __VERSION 1.
// Precedence (highest to lowest):
// word, namespace, regex
// Gen Macro namespace
// namespace GEN_, new_namespace_
// TODO(Ed): This will be large as nearly all symbols will need to optionally support getting prefixed with gen_ or something else the user wants.

View File

@ -0,0 +1,59 @@
[string] $format = $false
foreach ( $arg in $args )
{
if ( $arg -eq "format" )
{
$format = $true
}
}
[string[]] $include = 'gen.h'
[string[]] $exclude
$path_root = git rev-parse --show-toplevel
$path_project = Join-Path $path_root project
$path_scripts = Join-Path $path_root scripts
$path_helpers = Join-Path $path_scripts helpers
$path_c_library = Join-Path $path_root gen_c_library
$path_c_library_gen = Join-Path $path_c_library gen
$file_spec = Join-Path $path_c_library c_library.refactor
# Gather the files to be formatted.
$targetFiles = @()
$targetFiles += Get-ChildItem -Recurse -Path $path_c_library_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName
# $targetFiles += Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName
# $targetFiles += Get-ChildItem -Recurse -Path $path_singleheader_comp -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName
# Format the files.
$formatParams = @(
'-i' # In-place
'-style=file:./.clang-format' # Search for a .clang-format file in the parent directory of the source file.
'-verbose'
)
write-host "Beginning refactor...`n"
Write-Host $targetFiles
$refactorParams = @(
"-debug",
"-num=$($targetFiles.Count)"
"-src=$($targetFiles)",
"-spec=$($file_spec)"
)
$refactor = join-path $path_helpers refactor.exe
write-host "& $refactor $refactorParams"
& $refactor $refactorParams
Write-Host "`nRefactoring complete`n`n"
if ( $format -eq $true ) {
Write-Host "Beginning format...`n"
& clang-format $formatParams $targetFiles
Write-Host "`nFormatting complete"
}