mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-10-30 22:40:54 -07:00 
			
		
		
		
	WIP: Array generation test. Still need gen.cpp impl.
This commit is contained in:
		| @@ -57,6 +57,7 @@ | ||||
| #define scast( Type_, Value_ )			   static_cast< Type_ >( Value_ ) | ||||
| #define rcast( Type_, Value_ )			   reinterpret_cast< Type_ >( Value_ ) | ||||
| #define pcast( Type_, Value_ )             ( * (Type_*)( & Value_ ) ) | ||||
| #define txt( Value_ )                      ZPL_STRINGIFY_EX( Value_ ) | ||||
|  | ||||
| #define do_once()      \ | ||||
| do                     \ | ||||
| @@ -69,6 +70,19 @@ do                     \ | ||||
| }                      \ | ||||
| while(0)               \ | ||||
|  | ||||
| #define do_once_start  \ | ||||
| do                     \ | ||||
| {                      \ | ||||
| 	static             \ | ||||
| 	bool Done = false; \ | ||||
| 	if ( Done )        \ | ||||
| 		break;         \ | ||||
| 	Done = true; | ||||
|  | ||||
| #define do_once_end    \ | ||||
| }                      \ | ||||
| while(0); | ||||
|  | ||||
|  | ||||
| using Line       = char*; | ||||
| using Array_Line = array( Line ); | ||||
|   | ||||
							
								
								
									
										114
									
								
								project/gen.cpp
									
									
									
									
									
								
							
							
						
						
									
										114
									
								
								project/gen.cpp
									
									
									
									
									
								
							| @@ -1,15 +1,21 @@ | ||||
| #include "Bloat.hpp" | ||||
| #include "gen.hpp" | ||||
| #define gen_time | ||||
|  | ||||
| #ifdef gen_time | ||||
| namespace gen | ||||
| { | ||||
| 	void init() | ||||
| 	{ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	ct Code make() | ||||
| 	{ | ||||
| 		return { Code::Invalid, nullptr, nullptr, { nullptr } }; | ||||
| 	} | ||||
|  | ||||
| 	Code decl_type( char const* name, Code specifiers, Code type ) | ||||
| 	Code decl_type( char const* name, Code type, Code specifiers ) | ||||
| 	{ | ||||
| 		Code  | ||||
| 		result      = make(); | ||||
| @@ -47,7 +53,7 @@ namespace gen | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
| 	Code make_parameters( s32 num, ... ) | ||||
| 	Code def_parameters( s32 num, ... ) | ||||
| 	{ | ||||
| 		if (num <= 0) | ||||
| 			fatal("TT::make_paramters: num is %d", num); | ||||
| @@ -85,30 +91,12 @@ namespace gen | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
| 	Code make_fmt(char const* fmt, ...) | ||||
| 	{ | ||||
| 		local_persist thread_local  | ||||
| 		char buf[ZPL_PRINTF_MAXLEN] = { 0 }; | ||||
|  | ||||
| 		va_list va; | ||||
| 		va_start(va, fmt); | ||||
| 		zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va); | ||||
| 		va_end(va); | ||||
|           | ||||
| 		Code  | ||||
| 		result         = make(); | ||||
| 		result.Name    = string_make( g_allocator, fmt ); | ||||
| 		result.Type    = Code::Untyped; | ||||
| 		result.Content = string_make( g_allocator, buf ); | ||||
|  | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
| 	Code make_function( char const* name | ||||
| 	Code def_function( char const* name | ||||
| 		, Code specifiers | ||||
| 		, Code params | ||||
| 		, Code ret_type | ||||
| 		, Code body ) | ||||
| 		, Code body  | ||||
| 	) | ||||
| 	{ | ||||
| 		Code  | ||||
| 		result      = make(); | ||||
| @@ -130,7 +118,22 @@ namespace gen | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
| 	Code make_specifiers( u32 num, ... ) | ||||
| 	Code def_function_body( u32 num, ... ) | ||||
| 	{ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	Code def_namespace( char const* name, Code body ) | ||||
| 	{ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	Code def_namespace_body( u32 num, ... ) | ||||
| 	{ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	Code def_specifiers( u32 num, ... ) | ||||
| 	{ | ||||
| 		if ( num <= 0 ) | ||||
| 			fatal("gen::make_specifier: num cannot be zero."); | ||||
| @@ -165,7 +168,22 @@ namespace gen | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
| 	Code make_type( char const* name ) | ||||
| 	Code def_struct( char const* name, Code body, Code parent, Code specifiers ) | ||||
| 	{ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	Code def_struct_body( u32 num, ... ) | ||||
| 	{ | ||||
|  | ||||
| 	} | ||||
|  | ||||
| 	Code def_variable( char const* name, Code type, Code value, Code specifiers ) | ||||
| 	{ | ||||
| 		 | ||||
| 	} | ||||
|  | ||||
| 	Code def_type( char const* name ) | ||||
| 	{ | ||||
| 		Code  | ||||
| 		result      = make(); | ||||
| @@ -175,6 +193,33 @@ namespace gen | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	Code untyped_fmt(char const* fmt, ...) | ||||
| 	{ | ||||
| 		local_persist thread_local  | ||||
| 		char buf[ZPL_PRINTF_MAXLEN] = { 0 }; | ||||
|  | ||||
| 		va_list va; | ||||
| 		va_start(va, fmt); | ||||
| 		zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va); | ||||
| 		va_end(va); | ||||
|           | ||||
| 		Code  | ||||
| 		result         = make(); | ||||
| 		result.Name    = string_make( g_allocator, fmt ); | ||||
| 		result.Type    = Code::Untyped; | ||||
| 		result.Content = string_make( g_allocator, buf ); | ||||
|  | ||||
| 		return result; | ||||
| 	} | ||||
| 	 | ||||
| 	Code token_fmt( char const* fmt, ... ) | ||||
| 	{ | ||||
|  | ||||
| 	} | ||||
|  | ||||
|  | ||||
|  | ||||
| 	string Code::to_string() | ||||
| 	{ | ||||
| 		string result = string_make( g_allocator, "" ); | ||||
| @@ -232,6 +277,9 @@ namespace gen | ||||
| 			} | ||||
| 			break; | ||||
|  | ||||
| 			case Function_Body: | ||||
| 			break; | ||||
|  | ||||
| 			case Parameters:  | ||||
| 			{ | ||||
| 				result = string_append_fmt( result, "%s %s", Entries[0].to_string(), Name ); | ||||
| @@ -247,10 +295,6 @@ namespace gen | ||||
| 			} | ||||
| 			break; | ||||
|  | ||||
| 			case Struct: | ||||
| 				fatal("NOT SUPPORTED YET"); | ||||
| 			break; | ||||
|  | ||||
| 			case Function: | ||||
| 			{ | ||||
| 				u32 index = 0; | ||||
| @@ -288,8 +332,16 @@ namespace gen | ||||
| 				result = string_append_fmt( result, "%s", Content ); | ||||
| 			break; | ||||
|  | ||||
| 			case Struct: | ||||
| 				fatal("NOT SUPPORTED YET"); | ||||
| 			break; | ||||
|  | ||||
| 			case Struct_Body: | ||||
| 				fatal("NOT SUPPORTED YET"); | ||||
| 			break; | ||||
|  | ||||
| 			case Variable: | ||||
| 				// result = string_append_fmt( result, "%s", ) | ||||
| 				fatal("NOT SUPPORTED YET"); | ||||
| 			break; | ||||
|  | ||||
| 			case Typename: | ||||
| @@ -300,6 +352,8 @@ namespace gen | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
|  | ||||
|  | ||||
| 	void Builder::print( Code code ) | ||||
| 	{ | ||||
| 		Buffer = string_append_fmt( Buffer, "%s\n\n", code.to_string() ); | ||||
|   | ||||
| @@ -20,6 +20,7 @@ namespace gen | ||||
| 		API_Export,         // Vendor specific way to dynamic export | ||||
| 		External_Linkage,   // extern | ||||
| 		Internal_Linkage,   // static (within unit file) | ||||
| 		Static_Member,      // static (within sturct/class) | ||||
| 		Local_Persist,      // static (within function) | ||||
| 		Thread_Local,       // thread_local | ||||
|  | ||||
| @@ -62,7 +63,9 @@ namespace gen | ||||
| 			Decl_Function, | ||||
| 			Parameters,  // Used with functions. | ||||
| 			Struct,      | ||||
| 			Struct_Body, | ||||
| 			Function, | ||||
| 			Function_Body, | ||||
| 			Specifiers, | ||||
| 			Variable, | ||||
| 			Typename, | ||||
| @@ -172,7 +175,11 @@ namespace gen | ||||
| 		Using_Code_POD; | ||||
| 	}; | ||||
|  | ||||
| 	Code decl_type( char const* name, Code specifiers, Code type); | ||||
| 	constexpr Code UnusedCode = { Code::Unused, nullptr, nullptr, { nullptr }  }; | ||||
|  | ||||
| 	void init(); | ||||
|  | ||||
| 	Code decl_type( char const* name, Code type, Code specifiers = UnusedCode ); | ||||
|  | ||||
| 	Code decl_fn( char const* name | ||||
| 		, Code specifiers | ||||
| @@ -180,26 +187,33 @@ namespace gen | ||||
| 		, Code ret_type | ||||
| 	); | ||||
|  | ||||
| 	Code make_parameters( s32 num, ... ); | ||||
| 	 | ||||
| 	Code make_fmt( char const* fmt, ... ); | ||||
| 	Code def_parameters( s32 num, ... ); | ||||
|  | ||||
| 	Code make_function( char const* name | ||||
| 	Code def_function( char const* name | ||||
| 		, Code specifiers | ||||
| 		, Code params | ||||
| 		, Code ret_type | ||||
| 		, Code body  | ||||
| 	); | ||||
| 	Code def_function_body( u32 num, ... ); | ||||
|  | ||||
| 	Code make_specifiers( u32 num , ... ); | ||||
| 	Code def_namespace( char const* name, Code body ); | ||||
| 	Code def_namespace_body( u32 num, ... ); | ||||
|  | ||||
| 	// Code make_variable( char const* name, char const* type ); | ||||
| 	Code def_specifiers( u32 num , ... ); | ||||
|  | ||||
| 	// Code make_template( Code subject, u32 num_dependents, ... ); | ||||
| 	Code def_struct( char const* name, Code body, Code parent = UnusedCode, Code specifiers = UnusedCode ); | ||||
| 	Code def_struct_body( u32 num, ... ); | ||||
|  | ||||
| 	Code make_type( char const* name ); | ||||
| 	Code def_variable( char const* name, Code type, Code value = UnusedCode, Code specifiers = UnusedCode ); | ||||
|  | ||||
| 	// Code make_using( char const* name, char const* type ); | ||||
| 	Code def_type( char const* name ); | ||||
|  | ||||
| 	Code def_using( char const* name, Code type ); | ||||
|  | ||||
| 	Code untyped_fmt( char const* fmt, ... ); | ||||
|  | ||||
| 	Code token_fmt( char const* fmt, ... ); | ||||
|  | ||||
|  | ||||
| 	struct Builder | ||||
|   | ||||
		Reference in New Issue
	
	Block a user