mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-10-31 06:50:53 -07:00 
			
		
		
		
	wip having nasty parser issue (fixed nasty lexer bug)
This commit is contained in:
		
							
								
								
									
										16
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							| @@ -42,7 +42,21 @@ | |||||||
| 		"gen.h": "c", | 		"gen.h": "c", | ||||||
| 		"string_ops.hpp": "c", | 		"string_ops.hpp": "c", | ||||||
| 		"assert.h": "c", | 		"assert.h": "c", | ||||||
| 		"intrin.h": "c" | 		"intrin.h": "c", | ||||||
|  | 		"bit": "cpp", | ||||||
|  | 		"cmath": "cpp", | ||||||
|  | 		"cstddef": "cpp", | ||||||
|  | 		"cstdint": "cpp", | ||||||
|  | 		"cstdio": "cpp", | ||||||
|  | 		"cstdlib": "cpp", | ||||||
|  | 		"cstring": "cpp", | ||||||
|  | 		"ctime": "cpp", | ||||||
|  | 		"cwchar": "cpp", | ||||||
|  | 		"iosfwd": "cpp", | ||||||
|  | 		"new": "cpp", | ||||||
|  | 		"typeinfo": "cpp", | ||||||
|  | 		"unordered_map": "cpp", | ||||||
|  | 		"xstddef": "cpp" | ||||||
| 	}, | 	}, | ||||||
| 	"C_Cpp.intelliSenseEngineFallback": "disabled", | 	"C_Cpp.intelliSenseEngineFallback": "disabled", | ||||||
| 	"mesonbuild.configureOnOpen": true, | 	"mesonbuild.configureOnOpen": true, | ||||||
|   | |||||||
| @@ -100,6 +100,9 @@ int gen_main() | |||||||
| #define project_dir "../project/" | #define project_dir "../project/" | ||||||
| 	gen::init(); | 	gen::init(); | ||||||
|  |  | ||||||
|  | 	PreprocessorDefines.append(txt("GEN_API_C_BEGIN")); | ||||||
|  | 	PreprocessorDefines.append(txt("GEN_API_C_END")); | ||||||
|  |  | ||||||
| 	Code push_ignores           = scan_file( project_dir "helpers/push_ignores.inline.hpp" ); | 	Code push_ignores           = scan_file( project_dir "helpers/push_ignores.inline.hpp" ); | ||||||
| 	Code pop_ignores            = scan_file( project_dir "helpers/pop_ignores.inline.hpp" ); | 	Code pop_ignores            = scan_file( project_dir "helpers/pop_ignores.inline.hpp" ); | ||||||
| 	Code c_library_header_start = scan_file( "components/header_start.hpp" ); | 	Code c_library_header_start = scan_file( "components/header_start.hpp" ); | ||||||
| @@ -127,21 +130,21 @@ int gen_main() | |||||||
| 		header.print( basic_types ); | 		header.print( basic_types ); | ||||||
| 		header.print( debug ); | 		header.print( debug ); | ||||||
|  |  | ||||||
| 		Array(StrC) to_rename = array_init_reserve(StrC, GlobalAllocator, 128); | 		// Array(StrC) to_rename = array_init_reserve(StrC, GlobalAllocator, 128); | ||||||
| 		to_rename.append(txt("align_forward")); | 		// to_rename.append(txt("align_forward")); | ||||||
| 		to_rename.append(txt("pointer_add")); | 		// to_rename.append(txt("pointer_add")); | ||||||
| 		to_rename.append(txt("allocator_info")); | 		// to_rename.append(txt("allocator_info")); | ||||||
| 		to_rename.append(txt("size_remaining")); | 		// to_rename.append(txt("size_remaining")); | ||||||
| 		to_rename.append(txt("free")); | 		// to_rename.append(txt("free")); | ||||||
| 		// to_rename.append(txt("clear")); | 		// to_rename.append(txt("clear")); | ||||||
| 		// to_rename.append(txt("init_sub")); | 		// to_rename.append(txt("init_sub")); | ||||||
| 		// to_rename.append(txt("check")); | 		// to_rename.append(txt("check")); | ||||||
|  |  | ||||||
| 		NeedsSelectors needs_selectors; | 		// NeedsSelectors needs_selectors; | ||||||
| 		needs_selectors.table = hashtable_init_reserve(Array(CodeFn), GlobalAllocator, 1024); | 		// needs_selectors.table = hashtable_init_reserve(Array(CodeFn), GlobalAllocator, 1024); | ||||||
| 		for ( StrC id : to_rename ) { | 		// for ( StrC id : to_rename ) { | ||||||
| 			needs_selectors.set(id, array_init_reserve(CodeFn, GlobalAllocator, 128)); | 		// 	needs_selectors.set(id, array_init_reserve(CodeFn, GlobalAllocator, 128)); | ||||||
| 		} | 		// } | ||||||
|  |  | ||||||
| 		CodeBody parsed_memory = parse_file( project_dir "dependencies/memory.hpp" ); | 		CodeBody parsed_memory = parse_file( project_dir "dependencies/memory.hpp" ); | ||||||
| 		CodeBody memory        = def_body(CT_Global_Body); | 		CodeBody memory        = def_body(CT_Global_Body); | ||||||
| @@ -152,7 +155,7 @@ int gen_main() | |||||||
| 			{ | 			{ | ||||||
| 				case CT_Using: | 				case CT_Using: | ||||||
| 				{ | 				{ | ||||||
| 					log_fmt("REPLACE THIS MANUALLY: %S\n", entry->Name); | 					log_fmt("REPLACE THIS MANUALLY: %SC\n", entry->Name); | ||||||
| 					CodeUsing   using_ver   = cast(CodeUsing, entry); | 					CodeUsing   using_ver   = cast(CodeUsing, entry); | ||||||
| 					CodeTypedef typedef_ver = def_typedef(using_ver->Name, using_ver->UnderlyingType); | 					CodeTypedef typedef_ver = def_typedef(using_ver->Name, using_ver->UnderlyingType); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -88,7 +88,7 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name ) | |||||||
| 		void       <fn>_remove      ( <tbl_type> self, u64 key ); | 		void       <fn>_remove      ( <tbl_type> self, u64 key ); | ||||||
| 		void       <fn>_remove_entry( <tbl_type> self, ssize idx ); | 		void       <fn>_remove_entry( <tbl_type> self, ssize idx ); | ||||||
| 		void       <fn>_set         ( <tbl_type>* self, u64 key, <type> value ); | 		void       <fn>_set         ( <tbl_type>* self, u64 key, <type> value ); | ||||||
| 		ssize         <fn>_slot        ( <tbl_type> self, u64 key ); | 		ssize      <fn>_slot        ( <tbl_type> self, u64 key ); | ||||||
|  |  | ||||||
| 		ssize            <fn>__add_entry( <tbl_type> self, u64 key ); | 		ssize            <fn>__add_entry( <tbl_type> self, u64 key ); | ||||||
| 		HT_FindResult <fn>__find     ( <tbl_type> self, u64 key ); | 		HT_FindResult <fn>__find     ( <tbl_type> self, u64 key ); | ||||||
|   | |||||||
| @@ -159,16 +159,16 @@ extern CodeTypename t_typename; | |||||||
| // Used by the lexer to persistently treat all these identifiers as preprocessor defines. | // Used by the lexer to persistently treat all these identifiers as preprocessor defines. | ||||||
| // Populate with strings via gen::get_cached_string. | // Populate with strings via gen::get_cached_string. | ||||||
| // Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments. | // Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments. | ||||||
| extern Array< StringCached > PreprocessorDefines; | extern Array(StringCached) PreprocessorDefines; | ||||||
|  |  | ||||||
| #ifdef GEN_EXPOSE_BACKEND | #ifdef GEN_EXPOSE_BACKEND | ||||||
|  |  | ||||||
| 	// Global allocator used for data with process lifetime. | 	// Global allocator used for data with process lifetime. | ||||||
| 	extern AllocatorInfo  GlobalAllocator; | 	extern AllocatorInfo  GlobalAllocator; | ||||||
| 	extern Array< Arena > Global_AllocatorBuckets; | 	extern Array(Arena) Global_AllocatorBuckets; | ||||||
|  |  | ||||||
| 	extern Array< Pool >  CodePools; | 	extern Array(Pool)  CodePools; | ||||||
| 	extern Array< Arena > StringArenas; | 	extern Array(Arena) StringArenas; | ||||||
|  |  | ||||||
| 	extern StringTable StringCache; | 	extern StringTable StringCache; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -578,16 +578,16 @@ TokArray lex( StrC content ) | |||||||
| 		return { {}, 0 }; | 		return { {}, 0 }; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for ( StringCached* entry = array_begin(PreprocessorDefines); entry != array_end(PreprocessorDefines); array_next(PreprocessorDefines, entry)) | 	for ( StringCached* entry = array_begin(PreprocessorDefines); entry != array_end(PreprocessorDefines); entry = array_next(PreprocessorDefines, entry)) | ||||||
| 	{ | 	{ | ||||||
| 		s32         length  = 0; | 		s32         length  = 0; | ||||||
| 		char const* scanner = * entry; | 		char const* entry_scanner = * entry; | ||||||
| 		while ( entry->Len > length && (char_is_alphanumeric( *scanner ) || *scanner == '_') ) | 		while ( entry->Len > length && (char_is_alphanumeric( *entry_scanner ) || *entry_scanner == '_') ) | ||||||
| 		{ | 		{ | ||||||
| 			c.scanner++; | 			entry_scanner++; | ||||||
| 			length ++; | 			length ++; | ||||||
| 		} | 		} | ||||||
| 		if ( c.scanner[0] == '(' ) | 		if ( entry_scanner[0] == '(' ) | ||||||
| 		{ | 		{ | ||||||
| 			length++; | 			length++; | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -3859,8 +3859,47 @@ CodeFriend parse_friend() | |||||||
| 	eat( Tok_Decl_Friend ); | 	eat( Tok_Decl_Friend ); | ||||||
| 	// friend | 	// friend | ||||||
|  |  | ||||||
| 	CodeFn       function = { nullptr }; | 	CodeFn         function   = { nullptr }; | ||||||
| 	CodeOperator op       = { nullptr }; | 	CodeOperator   op         = { nullptr }; | ||||||
|  | 	CodeSpecifiers specifiers = { nullptr }; | ||||||
|  |  | ||||||
|  | 	// Specifiers Parsing | ||||||
|  | 	{ | ||||||
|  | 		Specifier specs_found[ 16 ] { Spec_NumSpecifiers }; | ||||||
|  | 		s32       NumSpecifiers = 0; | ||||||
|  |  | ||||||
|  | 		while ( left && is_specifier(currtok) ) | ||||||
|  | 		{ | ||||||
|  | 			Specifier spec = to_specifier( to_str(currtok) ); | ||||||
|  |  | ||||||
|  | 			switch ( spec ) | ||||||
|  | 			{ | ||||||
|  | 				case Spec_Const : | ||||||
|  | 				case Spec_Inline : | ||||||
|  | 				case Spec_ForceInline : | ||||||
|  | 					break; | ||||||
|  |  | ||||||
|  | 				default : | ||||||
|  | 					log_failure( "Invalid specifier %s for friend definition\n%s", to_str( spec ), to_string(Context) ); | ||||||
|  | 					pop(& Context); | ||||||
|  | 					return InvalidCode; | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			// Ignore const it will be handled by the type | ||||||
|  | 			if ( spec == Spec_Const ) | ||||||
|  | 				break; | ||||||
|  |  | ||||||
|  | 			specs_found[ NumSpecifiers ] = spec; | ||||||
|  | 			NumSpecifiers++; | ||||||
|  | 			eat( currtok.Type ); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		if ( NumSpecifiers ) | ||||||
|  | 		{ | ||||||
|  | 			specifiers = def_specifiers( NumSpecifiers, specs_found ); | ||||||
|  | 		} | ||||||
|  | 		// <friend> <specifiers> | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	// Type declaration or return type | 	// Type declaration or return type | ||||||
| 	CodeTypename type = parse_type(); | 	CodeTypename type = parse_type(); | ||||||
| @@ -3879,7 +3918,7 @@ CodeFriend parse_friend() | |||||||
| 		Context.Scope->Name = name; | 		Context.Scope->Name = name; | ||||||
| 		// friend <ReturnType> <Name> | 		// friend <ReturnType> <Name> | ||||||
|  |  | ||||||
| 		function = parse_function_after_name( ModuleFlag_None, NullCode, NullCode, type, name ); | 		function = parse_function_after_name( ModuleFlag_None, NullCode, specifiers, type, name ); | ||||||
|  |  | ||||||
| 		// Parameter list | 		// Parameter list | ||||||
| 		// CodeParam params = parse_params(); | 		// CodeParam params = parse_params(); | ||||||
| @@ -3897,7 +3936,7 @@ CodeFriend parse_friend() | |||||||
| 	// Operator declaration or definition | 	// Operator declaration or definition | ||||||
| 	if ( currtok.Type == Tok_Decl_Operator ) | 	if ( currtok.Type == Tok_Decl_Operator ) | ||||||
| 	{ | 	{ | ||||||
| 		op = parse_operator_after_ret_type( ModuleFlag_None, NullCode, NullCode, type ); | 		op = parse_operator_after_ret_type( ModuleFlag_None, NullCode, specifiers, type ); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	CodeComment inline_cmt = NullCode; | 	CodeComment inline_cmt = NullCode; | ||||||
|   | |||||||
| @@ -82,7 +82,7 @@ global CodeTypename t_wchar_t; | |||||||
| global CodeTypename t_class; | global CodeTypename t_class; | ||||||
| global CodeTypename t_typename; | global CodeTypename t_typename; | ||||||
|  |  | ||||||
| global Array< StringCached > PreprocessorDefines; | global Array(StringCached) PreprocessorDefines; | ||||||
|  |  | ||||||
| #ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS | #ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS | ||||||
| global CodeTypename t_b32; | global CodeTypename t_b32; | ||||||
|   | |||||||
| @@ -114,7 +114,7 @@ template<class Type> forceinline Type* next(Array<Type>& array, Type* entry) { r | |||||||
|  |  | ||||||
| template<class Type> forceinline Type* array_begin(Array<Type> array)             { return array;      } | template<class Type> forceinline Type* array_begin(Array<Type> array)             { return array;      } | ||||||
| template<class Type> forceinline Type* array_end(Array<Type> array)               { return array + array_get_header(array)->Num; } | template<class Type> forceinline Type* array_end(Array<Type> array)               { return array + array_get_header(array)->Num; } | ||||||
| template<class Type> forceinline Type* array_next(Array<Type> array, Type* entry) { return entry + 1; } | template<class Type> forceinline Type* array_next(Array<Type> array, Type* entry) { return ++ entry; } | ||||||
|  |  | ||||||
| template<class Type> inline | template<class Type> inline | ||||||
| Array<Type> array_init(AllocatorInfo allocator) { | Array<Type> array_init(AllocatorInfo allocator) { | ||||||
|   | |||||||
| @@ -206,7 +206,7 @@ | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #ifndef GEN_API_C_BEGIN | #ifndef GEN_API_C_BEGIN | ||||||
| #	if GEN_COMPILER_C | #	if GEN_COMPILER_C || (GEN_COMPILER_CPP && GEN_SUPPORT_CPP_REFERENCES) | ||||||
| #		define GEN_API_C_BEGIN | #		define GEN_API_C_BEGIN | ||||||
| #		define GEN_API_C_END | #		define GEN_API_C_END | ||||||
| #	else | #	else | ||||||
|   | |||||||
| @@ -320,8 +320,10 @@ ssize arena_size_remaining(Arena* arena, ssize alignment) | |||||||
| } | } | ||||||
| #pragma endregion Arena | #pragma endregion Arena | ||||||
|  |  | ||||||
|  |  | ||||||
| GEN_API_C_END | GEN_API_C_END | ||||||
|  |  | ||||||
|  |  | ||||||
| #pragma region FixedArena | #pragma region FixedArena | ||||||
| template<s32 Size> | template<s32 Size> | ||||||
| struct FixedArena; | struct FixedArena; | ||||||
| @@ -384,8 +386,10 @@ using Arena_2MB   = FixedArena< megabytes( 2 ) >; | |||||||
| using Arena_4MB   = FixedArena< megabytes( 4 ) >; | using Arena_4MB   = FixedArena< megabytes( 4 ) >; | ||||||
| #pragma endregion FixedArena | #pragma endregion FixedArena | ||||||
|  |  | ||||||
|  |  | ||||||
| GEN_API_C_BEGIN | GEN_API_C_BEGIN | ||||||
|  |  | ||||||
|  |  | ||||||
| #pragma region Pool | #pragma region Pool | ||||||
| struct Pool_Def; | struct Pool_Def; | ||||||
| typedef struct Pool_Def Pool; | typedef struct Pool_Def Pool; | ||||||
|   | |||||||
| @@ -49,13 +49,14 @@ forceinline char const* strc_end  (StrC str)                   { return str.Ptr | |||||||
| forceinline char const* strc_next (StrC str, char const* iter) { return iter + 1; } | forceinline char const* strc_next (StrC str, char const* iter) { return iter + 1; } | ||||||
| GEN_API_C_END | GEN_API_C_END | ||||||
|  |  | ||||||
| #if GEN_COMPILER_CPP && 0 | #if GEN_COMPILER_CPP | ||||||
| forceinline char const* begin(StrC str)                   { return str.Ptr; } | forceinline char const* begin(StrC str)                   { return str.Ptr; } | ||||||
| forceinline char const* end  (StrC str)                   { return str.Ptr + str.Len; } | forceinline char const* end  (StrC str)                   { return str.Ptr + str.Len; } | ||||||
| forceinline char const* next (StrC str, char const* iter) { return iter + 1; } | forceinline char const* next (StrC str, char const* iter) { return iter + 1; } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| GEN_API_C_BEGIN | GEN_API_C_BEGIN | ||||||
|  |  | ||||||
| inline | inline | ||||||
| bool strc_are_equal(StrC lhs, StrC rhs) | bool strc_are_equal(StrC lhs, StrC rhs) | ||||||
| { | { | ||||||
| @@ -119,6 +120,7 @@ struct String; | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| GEN_API_C_BEGIN | GEN_API_C_BEGIN | ||||||
|  |  | ||||||
| forceinline usize string_grow_formula(usize value); | forceinline usize string_grow_formula(usize value); | ||||||
|  |  | ||||||
| String        string_make_c_str          (AllocatorInfo allocator, char const*  str); | String        string_make_c_str          (AllocatorInfo allocator, char const*  str); | ||||||
| @@ -155,6 +157,7 @@ StrC          string_to_strc             (String       str); | |||||||
| void          string_trim                (String       str, char const* cut_set); | void          string_trim                (String       str, char const* cut_set); | ||||||
| void          string_trim_space          (String       str); | void          string_trim_space          (String       str); | ||||||
| String        string_visualize_whitespace(String const str); | String        string_visualize_whitespace(String const str); | ||||||
|  |  | ||||||
| GEN_API_C_END | GEN_API_C_END | ||||||
|  |  | ||||||
| struct StringHeader { | struct StringHeader { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user