mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-10-30 14:30:53 -07:00 
			
		
		
		
	WIP - Broken Compile : Added pragma once and includes to all files + Parser fixes, and String improvements
Adding the pragma once and includes the files broke compilation, still diagnosing why.
- Some string functions were moved to the cpp, still need to do some more evaluation of it and the containers...
- Added support for forceinline and neverinline to parsing (untested)
- Added support for specifiers in operator cast such as explicit, inline/forceinline/neverinline, etc.
    - Before it only support const.
    - Still need to support volatile.
- Forceinline was not supported at all for tokenization, fixed that.
			
			
This commit is contained in:
		| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "macros.hpp" | ||||
|  | ||||
| #pragma region Basic Types | ||||
|  | ||||
| #define GEN_U8_MIN 0u | ||||
| @@ -118,4 +121,3 @@ typedef s16 b16; | ||||
| typedef s32 b32; | ||||
|  | ||||
| #pragma endregion Basic Types | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "printing.hpp" | ||||
|  | ||||
| #pragma region Containers | ||||
|  | ||||
| template<class Type> | ||||
| @@ -540,4 +543,3 @@ protected: | ||||
| }; | ||||
|  | ||||
| #pragma endregion Containers | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "src_start.cpp" | ||||
|  | ||||
| #pragma region Debug | ||||
|  | ||||
| void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... ) | ||||
| @@ -39,4 +42,3 @@ s32 assert_crash( char const* condition ) | ||||
| #endif | ||||
|  | ||||
| #pragma endregion Debug | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "basic_types.hpp" | ||||
|  | ||||
| #pragma region Debug | ||||
|  | ||||
| #if defined( _MSC_VER ) | ||||
| @@ -56,4 +59,3 @@ void process_exit( u32 code ); | ||||
| #endif | ||||
|  | ||||
| #pragma endregion Debug | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "strings.cpp" | ||||
|  | ||||
| #pragma region File Handling | ||||
|  | ||||
| #if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN ) | ||||
| @@ -634,4 +637,3 @@ internal GEN_FILE_CLOSE_PROC( _memory_file_close ) | ||||
| FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close }; | ||||
|  | ||||
| #pragma endregion File Handling | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "strings.hpp" | ||||
|  | ||||
| #pragma region File Handling | ||||
|  | ||||
| typedef u32 FileMode; | ||||
| @@ -370,4 +373,3 @@ u8* file_stream_buf( FileInfo* file, sw* size ); | ||||
| extern FileOperations const memory_file_operations; | ||||
|  | ||||
| #pragma endregion File Handling | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "memory.cpp" | ||||
|  | ||||
| #pragma region Hashing | ||||
|  | ||||
| global u32 const _crc32_table[ 256 ] = { | ||||
| @@ -83,4 +86,3 @@ u64 crc64( void const* data, sw len ) | ||||
| } | ||||
|  | ||||
| #pragma endregion Hashing | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,9 @@ | ||||
| #pragma once | ||||
| #include "containers.hpp" | ||||
|  | ||||
| #pragma region Hashing | ||||
|  | ||||
| u32 crc32( void const* data, sw len ); | ||||
| u64 crc64( void const* data, sw len ); | ||||
|  | ||||
| #pragma endregion Hashing | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,5 @@ | ||||
| #pragma once | ||||
|  | ||||
| #pragma region Platform Detection | ||||
|  | ||||
| /* Platform architecture */ | ||||
| @@ -120,4 +122,3 @@ | ||||
| #	define GEN_NS_BEGIN namespace gen { | ||||
| #	define GEN_NS_END   } | ||||
| #endif | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "header_start.hpp" | ||||
|  | ||||
| #pragma region Macros | ||||
|  | ||||
| #define zpl_cast( Type ) ( Type ) | ||||
| @@ -161,4 +164,3 @@ void swap( Type& a, Type& b ) | ||||
| } | ||||
|  | ||||
| #pragma endregion Macros | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "printing.cpp" | ||||
|  | ||||
| #pragma region Memory | ||||
|  | ||||
| void* mem_copy( void* dest, void const* source, sw n ) | ||||
| @@ -387,4 +390,3 @@ void Pool::clear() | ||||
| } | ||||
|  | ||||
| #pragma endregion Memory | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "debug.hpp" | ||||
|  | ||||
| #pragma region Memory | ||||
|  | ||||
| #define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) ) | ||||
| @@ -484,4 +487,3 @@ struct Pool | ||||
| }; | ||||
|  | ||||
| #pragma endregion Memory | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "string_ops.cpp" | ||||
|  | ||||
| #pragma region Printing | ||||
|  | ||||
| enum | ||||
| @@ -582,4 +585,3 @@ sw str_fmt_out_err( char const* fmt, ... ) | ||||
| } | ||||
|  | ||||
| #pragma endregion Printing | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "string_ops.hpp" | ||||
|  | ||||
| #pragma region Printing | ||||
|  | ||||
| struct FileInfo; | ||||
| @@ -34,4 +37,3 @@ sw log_fmt(char const* fmt, ...) | ||||
| } | ||||
|  | ||||
| #pragma endregion Printing | ||||
|  | ||||
|   | ||||
| @@ -78,4 +78,3 @@ | ||||
| #endif | ||||
|  | ||||
| #pragma endregion Macros and Includes | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "debug.cpp" | ||||
|  | ||||
| #pragma region String Ops | ||||
|  | ||||
| internal | ||||
| @@ -207,4 +210,3 @@ f64 str_to_f64( const char* str, char** end_ptr ) | ||||
| } | ||||
|  | ||||
| #pragma endregion String Ops | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "memory.hpp" | ||||
|  | ||||
| #pragma region String Ops | ||||
|  | ||||
| GEN_DEF_INLINE const char* char_first_occurence( const char* str, char c ); | ||||
| @@ -260,4 +263,3 @@ GEN_IMPL_INLINE void str_to_upper( char* str ) | ||||
| } | ||||
|  | ||||
| #pragma endregion String Ops | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "hashing.cpp" | ||||
|  | ||||
| #pragma region String | ||||
|  | ||||
| String String::fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... ) | ||||
| @@ -10,6 +13,54 @@ String String::fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* | ||||
| 	return make( allocator, buf ); | ||||
| } | ||||
|  | ||||
| String String::make_length( AllocatorInfo allocator, char const* str, sw length ) | ||||
| { | ||||
| 	constexpr sw header_size = sizeof( Header ); | ||||
|  | ||||
| 	s32   alloc_size = header_size + length + 1; | ||||
| 	void* allocation = alloc( allocator, alloc_size ); | ||||
|  | ||||
| 	if ( allocation == nullptr ) | ||||
| 		return { nullptr }; | ||||
|  | ||||
| 	Header& | ||||
| 	header = * rcast(Header*, allocation); | ||||
| 	header = { allocator, length, length }; | ||||
|  | ||||
| 	String  result = { rcast( char*, allocation) + header_size }; | ||||
|  | ||||
| 	if ( length && str ) | ||||
| 		mem_copy( result, str, length ); | ||||
| 	else | ||||
| 		mem_set( result, 0, alloc_size - header_size ); | ||||
|  | ||||
| 	result[ length ] = '\0'; | ||||
|  | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| String String::make_reserve( AllocatorInfo allocator, sw capacity ) | ||||
| { | ||||
| 	constexpr sw header_size = sizeof( Header ); | ||||
|  | ||||
| 	s32   alloc_size = header_size + capacity + 1; | ||||
| 	void* allocation = alloc( allocator, alloc_size ); | ||||
|  | ||||
| 	if ( allocation == nullptr ) | ||||
| 		return { nullptr }; | ||||
|  | ||||
| 	mem_set( allocation, 0, alloc_size ); | ||||
|  | ||||
| 	Header* | ||||
| 		header            = rcast(Header*, allocation); | ||||
| 	header->Allocator = allocator; | ||||
| 	header->Capacity  = capacity; | ||||
| 	header->Length    = 0; | ||||
|  | ||||
| 	String result = { rcast(char*, allocation) + header_size }; | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... ) | ||||
| { | ||||
| 	local_persist thread_local | ||||
| @@ -36,5 +87,42 @@ bool String::append_fmt( char const* fmt, ... ) | ||||
| 	return append( buf, res ); | ||||
| } | ||||
|  | ||||
| #pragma endregion String | ||||
| bool String::make_space_for( char const* str, sw add_len ) | ||||
| { | ||||
| 	sw available = avail_space(); | ||||
|  | ||||
| 	// NOTE: Return if there is enough space left | ||||
| 	if ( available >= add_len ) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		sw new_len, old_size, new_size; | ||||
|  | ||||
| 		void* ptr; | ||||
| 		void* new_ptr; | ||||
|  | ||||
| 		AllocatorInfo allocator = get_header().Allocator; | ||||
| 		Header*       header	= nullptr; | ||||
|  | ||||
| 		new_len  = grow_formula( length() + add_len ); | ||||
| 		ptr      = & get_header(); | ||||
| 		old_size = size_of( Header ) + length() + 1; | ||||
| 		new_size = size_of( Header ) + new_len + 1; | ||||
|  | ||||
| 		new_ptr = resize( allocator, ptr, old_size, new_size ); | ||||
|  | ||||
| 		if ( new_ptr == nullptr ) | ||||
| 			return false; | ||||
|  | ||||
| 		header            = zpl_cast( Header* ) new_ptr; | ||||
| 		header->Allocator = allocator; | ||||
| 		header->Capacity  = new_len; | ||||
|  | ||||
| 		Data = rcast( char*, header + 1 ); | ||||
|  | ||||
| 		return str; | ||||
| 	} | ||||
| } | ||||
| #pragma endregion String | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "hashing.hpp" | ||||
|  | ||||
| #pragma region Strings | ||||
|  | ||||
| // Constant string with length. | ||||
| @@ -54,54 +57,10 @@ struct String | ||||
| 	} | ||||
|  | ||||
| 	static | ||||
| 	String make_reserve( AllocatorInfo allocator, sw capacity ) | ||||
| 	{ | ||||
| 		constexpr sw header_size = sizeof( Header ); | ||||
|  | ||||
| 		s32   alloc_size = header_size + capacity + 1; | ||||
| 		void* allocation = alloc( allocator, alloc_size ); | ||||
|  | ||||
| 		if ( allocation == nullptr ) | ||||
| 			return { nullptr }; | ||||
|  | ||||
| 		mem_set( allocation, 0, alloc_size ); | ||||
|  | ||||
| 		Header* | ||||
| 			header            = rcast(Header*, allocation); | ||||
| 		header->Allocator = allocator; | ||||
| 		header->Capacity  = capacity; | ||||
| 		header->Length    = 0; | ||||
|  | ||||
| 		String result = { rcast(char*, allocation) + header_size }; | ||||
| 		return result; | ||||
| 	} | ||||
| 	String make_reserve( AllocatorInfo allocator, sw capacity ); | ||||
|  | ||||
| 	static | ||||
| 	String make_length( AllocatorInfo allocator, char const* str, sw length ) | ||||
| 	{ | ||||
| 		constexpr sw header_size = sizeof( Header ); | ||||
|  | ||||
| 		s32   alloc_size = header_size + length + 1; | ||||
| 		void* allocation = alloc( allocator, alloc_size ); | ||||
|  | ||||
| 		if ( allocation == nullptr ) | ||||
| 			return { nullptr }; | ||||
|  | ||||
| 		Header& | ||||
| 		header = * rcast(Header*, allocation); | ||||
| 		header = { allocator, length, length }; | ||||
|  | ||||
| 		String  result = { rcast( char*, allocation) + header_size }; | ||||
|  | ||||
| 		if ( length && str ) | ||||
| 			mem_copy( result, str, length ); | ||||
| 		else | ||||
| 			mem_set( result, 0, alloc_size - header_size ); | ||||
|  | ||||
| 		result[ length ] = '\0'; | ||||
|  | ||||
| 		return result; | ||||
| 	} | ||||
| 	String make_length( AllocatorInfo allocator, char const* str, sw length ); | ||||
|  | ||||
| 	static | ||||
| 	String fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... ); | ||||
| @@ -138,44 +97,7 @@ struct String | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	bool make_space_for( char const* str, sw add_len ) | ||||
| 	{ | ||||
| 		sw available = avail_space(); | ||||
|  | ||||
| 		// NOTE: Return if there is enough space left | ||||
| 		if ( available >= add_len ) | ||||
| 		{ | ||||
| 			return true; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			sw new_len, old_size, new_size; | ||||
|  | ||||
| 			void* ptr; | ||||
| 			void* new_ptr; | ||||
|  | ||||
| 			AllocatorInfo allocator = get_header().Allocator; | ||||
| 			Header*       header	= nullptr; | ||||
|  | ||||
| 			new_len  = grow_formula( length() + add_len ); | ||||
| 			ptr      = & get_header(); | ||||
| 			old_size = size_of( Header ) + length() + 1; | ||||
| 			new_size = size_of( Header ) + new_len + 1; | ||||
|  | ||||
| 			new_ptr = resize( allocator, ptr, old_size, new_size ); | ||||
|  | ||||
| 			if ( new_ptr == nullptr ) | ||||
| 				return false; | ||||
|  | ||||
| 			header            = zpl_cast( Header* ) new_ptr; | ||||
| 			header->Allocator = allocator; | ||||
| 			header->Capacity  = new_len; | ||||
|  | ||||
| 			Data = rcast( char*, header + 1 ); | ||||
|  | ||||
| 			return str; | ||||
| 		} | ||||
| 	} | ||||
| 	bool make_space_for( char const* str, sw add_len ); | ||||
|  | ||||
| 	bool append( char const* str ) | ||||
| 	{ | ||||
| @@ -209,7 +131,7 @@ struct String | ||||
|  | ||||
| 	bool append( const String other ) | ||||
| 	{ | ||||
| 		return append( other.Data, other.length() );; | ||||
| 		return append( other.Data, other.length() ); | ||||
| 	} | ||||
|  | ||||
| 	bool append_fmt( char const* fmt, ... ); | ||||
| @@ -268,6 +190,29 @@ struct String | ||||
| 		return header.Length; | ||||
| 	} | ||||
|  | ||||
| 	void skip_line() | ||||
| 	{ | ||||
| 	#define current (*scanner) | ||||
| 		char* scanner = Data; | ||||
| 		while ( current != '\r' && current != '\n' ) | ||||
| 		{ | ||||
| 			++ scanner; | ||||
| 		} | ||||
|  | ||||
| 		s32 new_length = scanner - Data; | ||||
|  | ||||
| 		if ( current == '\r' ) | ||||
| 		{ | ||||
| 			new_length += 1; | ||||
| 		} | ||||
|  | ||||
| 		mem_move( Data, scanner, new_length ); | ||||
|  | ||||
| 		Header* header = & get_header(); | ||||
| 		header->Length = new_length; | ||||
| 	#undef current | ||||
| 	} | ||||
|  | ||||
| 	void trim( char const* cut_set ) | ||||
| 	{ | ||||
| 		sw len = 0; | ||||
| @@ -372,4 +317,3 @@ using StringTable = HashTable<String const>; | ||||
| using StringCached = String const; | ||||
|  | ||||
| #pragma endregion Strings | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "filesystem.cpp" | ||||
|  | ||||
| #pragma region Timing | ||||
|  | ||||
| #ifdef GEN_BENCHMARK | ||||
| @@ -160,4 +163,3 @@ | ||||
| #endif | ||||
|  | ||||
| #pragma endregion Timing | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| #pragma once | ||||
| #include "filesystem.hpp" | ||||
|  | ||||
| #pragma region Timing | ||||
|  | ||||
| #ifdef GEN_BENCHMARK | ||||
| @@ -12,4 +15,3 @@ u64 time_rel_ms( void ); | ||||
| #endif | ||||
|  | ||||
| #pragma endregion Timing | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user