mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-10-30 22:40:54 -07:00 
			
		
		
		
	work on gettings things compiling again after restructuring
This commit is contained in:
		| @@ -16,7 +16,7 @@ Standard 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. | ||||
|     * `<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. | ||||
|   * **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`). | ||||
| @@ -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. | ||||
| * [`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 | ||||
|  | ||||
| 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. | ||||
|   | ||||
| @@ -13,6 +13,7 @@ | ||||
| #	include "components/inlines.hpp" | ||||
| #	include "components/gen/ast_inlines.hpp" | ||||
| #	include "components/header_end.hpp" | ||||
| using namespace gen; | ||||
| #endif | ||||
|  | ||||
| #pragma region Builder | ||||
|   | ||||
| @@ -2,4 +2,118 @@ | ||||
| #	include "scanner.hpp" | ||||
| #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 | ||||
|   | ||||
| @@ -20,119 +20,9 @@ | ||||
| // 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. | ||||
| // 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 | ||||
| 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 ) | ||||
| { | ||||
| 	FileContents file = file_read_contents( GlobalAllocator, true, path ); | ||||
| @@ -146,17 +36,18 @@ CodeBody parse_file( const char* path ) | ||||
|  | ||||
| typedef struct CSV_Column CSV_Column; | ||||
| struct CSV_Column { | ||||
| 	CSV_Object Owner; | ||||
| 	CSV_Object      ADT; | ||||
| 	Array<ADT_Node> Content; | ||||
| }; | ||||
|  | ||||
| typedef struct CSV_Columns2 CSV_Columns2; | ||||
| struct CSV_Columns2 { | ||||
| 	CSV_Object Owner; | ||||
| 	CSV_Object      ADT; | ||||
| 	Array<ADT_Node> Col_1; | ||||
| 	Array<ADT_Node> Col_2; | ||||
| }; | ||||
|  | ||||
| inline | ||||
| CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) { | ||||
| 	char scratch_mem[kilobytes(32)]; | ||||
| 	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 ); | ||||
|  | ||||
| 	CSV_Column result; | ||||
| 	csv_parse( & result.owner, scratch_mem, allocator, false ); | ||||
| 	result.Content = csv_nodes.nodes[0].nodes; | ||||
| 	csv_parse( & result.ADT, scratch_mem, allocator, false ); | ||||
| 	result.Content = result.ADT.nodes[0].nodes; | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| inline | ||||
| CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) { | ||||
| 	char scratch_mem[kilobytes(32)]; | ||||
| 	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 ); | ||||
|  | ||||
| 	CSV_Columns2 result; | ||||
| 	csv_parse( & result.owner, scratch_mem, allocator, false ); | ||||
| 	result.Col_1 = csv_nodes.nodes[0].nodes; | ||||
| 	result.Col_2 = csv_nodes.nodes[1].nodes; | ||||
| 	csv_parse( & result.ADT, scratch_mem, allocator, false ); | ||||
| 	result.Col_1 = result.ADT.nodes[0].nodes; | ||||
| 	result.Col_2 = result.ADT.nodes[1].nodes; | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -2,22 +2,17 @@ | ||||
| #define GEN_ENFORCE_STRONG_CODE_TYPES | ||||
| #define GEN_EXPOSE_BACKEND | ||||
| #define GEN_C_LIKE_CPP 1 | ||||
| #include "../project/gen.cpp" | ||||
| #include "gen.cpp" | ||||
|  | ||||
| #include "helpers/push_ignores.inline.hpp" | ||||
| #include "helpers/helper.hpp" | ||||
|  | ||||
| #include <stdlib.h> | ||||
|  | ||||
| GEN_NS_BEGIN | ||||
| #include "helpers/push_container_defines.inline.hpp" | ||||
| #include "dependencies/parsing.cpp" | ||||
| #include "helpers/pop_container_defines.inline.hpp" | ||||
| #include "helpers/base_codegen.hpp" | ||||
| #include "helpers/misc.hpp" | ||||
| GEN_NS_END | ||||
|  | ||||
| #include "auxillary/builder.hpp" | ||||
| #include "auxillary/builder.cpp" | ||||
| #include "auxillary/scanner.hpp" | ||||
| #include "auxillary/misc.hpp" | ||||
|  | ||||
| using namespace gen; | ||||
|  | ||||
| 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 ); | ||||
| } | ||||
|  | ||||
| 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() | ||||
| { | ||||
| 	gen::init(); | ||||
|  | ||||
| 	__debugbreak(); | ||||
|  | ||||
| 	CodeBody ecode       = gen_ecode     ( "enums/ECodeTypes.csv" ); | ||||
| 	CodeBody eoperator   = gen_eoperator ( "enums/EOperator.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, format(ast_inlines) ); | ||||
| 	builder_write( & header_ast_inlines); | ||||
| } | ||||
|  | ||||
| 	gen::deinit(); | ||||
| 	return 0; | ||||
| } | ||||
|   | ||||
| @@ -8,8 +8,6 @@ | ||||
|  | ||||
| // Publically Exposed Interface | ||||
|  | ||||
| void parser_define_macro( StrC ) | ||||
|  | ||||
| CodeClass parse_class( StrC def ) | ||||
| { | ||||
| 	GEN_USING_NS_PARSER; | ||||
|   | ||||
| @@ -644,7 +644,7 @@ CodeDefine def_define( StrC name, StrC content, Opts_def_define p ) | ||||
| 		// Add the define to PreprocessorDefines for usage in parsing | ||||
| 		s32 lex_id_len = 0; | ||||
| 		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; | ||||
| 		} | ||||
| 		StrC lex_id = { lex_id_len, result->Name.Ptr }; | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #	pragma once | ||||
| #	include "platform.hpp" | ||||
| #	include "macros.hpp" | ||||
| #endif | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,5 @@ | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #	pragma once | ||||
| #	include "debug.hpp" | ||||
| #	include "basic_types.hpp" | ||||
| #   include "src_start.cpp" | ||||
| #endif | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,9 @@ | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #	pragma once | ||||
| #	include "dependencies/platform.hpp" | ||||
| #	include "dependencies/macros.hpp" | ||||
| #	include "basic_types.hpp" | ||||
| #	include "macros.hpp" | ||||
| #endif | ||||
|  | ||||
| #pragma region Debug | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #   pragma once | ||||
| #	include "platform.hpp" | ||||
| #endif | ||||
|  | ||||
| #pragma region Macros | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #	pragma once | ||||
| #	include "timing.hpp" | ||||
| #endif | ||||
|  | ||||
| #pragma region ADT | ||||
|   | ||||
| @@ -1,7 +1,5 @@ | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #	pragma once | ||||
| #	include "filesystem.hpp" | ||||
| #	include "strings.hpp" | ||||
| #	include "string_ops.cpp" | ||||
| #endif | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #	pragma once | ||||
| #	include "header_start.hpp" | ||||
| #endif | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #	pragma once | ||||
| #	include "string_ops.hpp" | ||||
| #	include "debug.cpp" | ||||
| #endif | ||||
|  | ||||
|   | ||||
| @@ -37,6 +37,9 @@ GEN_NS_BEGIN | ||||
| #include "components/interface.parsing.cpp" | ||||
| #include "components/interface.untyped.cpp" | ||||
|  | ||||
| #include "auxillary/builder.cpp" | ||||
| #include "auxillary/scanner.cpp" | ||||
|  | ||||
| GEN_NS_END | ||||
|  | ||||
| #include "helpers/pop_container_defines.inline.hpp" | ||||
|   | ||||
| @@ -13,5 +13,6 @@ GEN_NS_BEGIN | ||||
| #include "dependencies/strings.cpp" | ||||
| #include "dependencies/filesystem.cpp" | ||||
| #include "dependencies/timing.cpp" | ||||
| #include "dependencies/parsing.cpp" | ||||
|  | ||||
| GEN_NS_END | ||||
|   | ||||
| @@ -16,5 +16,6 @@ GEN_NS_BEGIN | ||||
| #include "dependencies/strings.hpp" | ||||
| #include "dependencies/filesystem.hpp" | ||||
| #include "dependencies/timing.hpp" | ||||
| #include "dependencies/parsing.hpp" | ||||
|  | ||||
| GEN_NS_END | ||||
|   | ||||
| @@ -1,11 +1,11 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "gen.hpp" | ||||
| #if GEN_INTELLISENSE_DIRECTIVES | ||||
| #	include "../gen.hpp" | ||||
| #	include "misc.hpp" | ||||
|  | ||||
| using namespace gen; | ||||
|  | ||||
| #include "dependencies/parsing.hpp" | ||||
| #include "misc.hpp" | ||||
| #endif | ||||
|  | ||||
| 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++) | ||||
| 	{ | ||||
| 		char const* enum_str     = enum_strs[idx].string; | ||||
| 		char const* entry_to_str = str_strs [idx].string; | ||||
| 		char const* enum_str     = csv_enum.Col_1[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( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str); | ||||
|   | ||||
| @@ -1,23 +1,19 @@ | ||||
| #pragma once | ||||
|  | ||||
| #ifdef GEN_INTELLISENSE_DIRECTIVES | ||||
| #pragma once | ||||
| #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS | ||||
| #define GEN_ENFORCE_STRONG_CODE_TYPES | ||||
| #define GEN_EXPOSE_BACKEND | ||||
| #include "../gen.cpp" | ||||
| #	define GEN_DEFINE_LIBRARY_CODE_CONSTANTS | ||||
| #	define GEN_ENFORCE_STRONG_CODE_TYPES | ||||
| #	define GEN_EXPOSE_BACKEND | ||||
| #	include "gen.hpp" | ||||
| #	include "helpers/push_ignores.inline.hpp" | ||||
| #	include "helpers/helper.hpp" | ||||
| #	include "auxillary/builder.hpp" | ||||
| #	include "auxillary/builder.cpp" | ||||
| #	include "auxillary/scanner.hpp" | ||||
|  | ||||
| #include "helpers/push_ignores.inline.hpp" | ||||
| #include "helpers/helper.hpp" | ||||
| #include <stdlib.h> | ||||
|  | ||||
| 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.cpp" | ||||
| #include "auxillary/scanner.hpp" | ||||
| using namespace gen; | ||||
| #endif | ||||
|  | ||||
| // 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; | ||||
| 	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 ); | ||||
| 	} | ||||
|  | ||||
| 	StrC clang_format      = txt("clang-format ") | ||||
| 	StrC cf_format_inplace = txt("-i ") | ||||
| 	StrC cf_verbose        = txt("-verbose ") | ||||
| 	StrC clang_format      = txt("clang-format "); | ||||
| 	StrC cf_format_inplace = txt("-i "); | ||||
| 	StrC cf_verbose        = txt("-verbose "); | ||||
|  | ||||
| 	String command = string_make_strc( GlobalAllocator, clang_format ); | ||||
| 	string_append_strc( & command, cf_format_inplace ); | ||||
| @@ -53,31 +49,34 @@ void clang_format_file( char const* path, char const* style_path ) | ||||
| // (See: ./gencpp/scripts/build.ci.ps1 for how) | ||||
| 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 command = string_make_strc(GlobalAllocator, txt("refactor ")); | ||||
| 	string_append_strc( & command, txt("-debug ") ); | ||||
| 	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"); | ||||
| 	system(command); | ||||
| 		log_fmt("\nRefactoring complete.\n"); | ||||
| 	log_fmt("\nRefactoring complete.\n"); | ||||
|  | ||||
| 	#undef refactor | ||||
| } | ||||
|  | ||||
| // Does either of the above or both to the provided code. | ||||
| // 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); | ||||
| 	Builder scratch_file = builder_open("gen/scratch.hpp"); | ||||
| 	builder_print( & scratch_file, code); | ||||
| 	builder_write(& scratch_file); | ||||
|  | ||||
| 	if (refactor_script) { | ||||
| 		refactor_file(scratch_path, refactor_script) | ||||
| 		refactor_file(scratch_path, refactor_script); | ||||
| 	} | ||||
| 	if ( clang_format_sytle_path ) { | ||||
| 		clang_format_file(scratch_path, clang_format_sytle_path); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user