Additions and fixes based off genc repo

Typedef parses enum namespaced types properly (C typedefs of enums to expose to global scope).
This commit is contained in:
Edward R. Gonzalez 2023-07-16 23:18:00 -04:00
parent 41dc0e3fbb
commit 2a319ed6db
4 changed files with 88 additions and 0 deletions

View File

@ -687,3 +687,4 @@ Names or Content fields are interned strings and thus showed be cached using `ge
* Suffix specifiers for functions (const, override, final)
* Implement the Scanner
* Implement the Editor
* Support parsing full enum definitions inside a typedef. (For C patterns)

View File

@ -5754,6 +5754,7 @@ namespace gen
}
if ( currtok.Type == TokType::Decl_Class
|| currtok.Type == TokType::Decl_Enum
|| currtok.Type == TokType::Decl_Struct )
{
name = currtok;

View File

@ -1626,6 +1626,19 @@ namespace gen
return err;
}
s64 file_size( FileInfo* f )
{
s64 size = 0;
s64 prev_offset = file_tell( f );
file_seek_to_end( f );
size = file_tell( f );
file_seek( f, prev_offset );
return size;
}
#pragma endregion File Handling
#pragma region String

View File

@ -2015,6 +2015,41 @@ namespace gen
*/
FileError file_open_mode( FileInfo* file, FileMode mode, char const* filename );
/**
* Reads from a file
* @param file
* @param buffer Buffer to read to
* @param size Size to read
*/
GEN_DEF_INLINE b32 file_read( FileInfo* file, void* buffer, sw size );
/**
* Reads file at a specific offset
* @param file
* @param buffer Buffer to read to
* @param size Size to read
* @param offset Offset to read from
* @param bytes_read How much data we've actually read
*/
GEN_DEF_INLINE b32 file_read_at( FileInfo* file, void* buffer, sw size, s64 offset );
/**
* Reads file safely
* @param file
* @param buffer Buffer to read to
* @param size Size to read
* @param offset Offset to read from
* @param bytes_read How much data we've actually read
*/
GEN_DEF_INLINE b32 file_read_at_check( FileInfo* file, void* buffer, sw size, s64 offset, sw* bytes_read );
/**
* Returns a size of the file
* @param file
* @return File size
*/
s64 file_size( FileInfo* file );
/**
* Seeks the file cursor from the beginning of file to a specific position
* @param file
@ -2022,6 +2057,12 @@ namespace gen
*/
GEN_DEF_INLINE s64 file_seek( FileInfo* file, s64 offset );
/**
* Seeks the file cursor to the end of the file
* @param file
*/
GEN_DEF_INLINE s64 file_seek_to_end( FileInfo* file );
/**
* Returns the length from the beginning of the file we've read so far
* @param file
@ -2069,6 +2110,18 @@ namespace gen
return new_offset;
}
GEN_IMPL_INLINE s64 file_seek_to_end( FileInfo* f )
{
s64 new_offset = 0;
if ( ! f->Ops.read_at )
f->Ops = default_file_operations;
f->Ops.seek( f->FD, 0, ESeekWhence_END, &new_offset );
return new_offset;
}
GEN_IMPL_INLINE s64 file_tell( FileInfo* f )
{
s64 new_offset = 0;
@ -2081,6 +2134,26 @@ namespace gen
return new_offset;
}
GEN_IMPL_INLINE b32 file_read( FileInfo* f, void* buffer, sw size )
{
s64 cur_offset = file_tell( f );
b32 result = file_read_at( f, buffer, size, file_tell( f ) );
file_seek( f, cur_offset + size );
return result;
}
GEN_IMPL_INLINE b32 file_read_at( FileInfo* f, void* buffer, sw size, s64 offset )
{
return file_read_at_check( f, buffer, size, offset, NULL );
}
GEN_IMPL_INLINE b32 file_read_at_check( FileInfo* f, void* buffer, sw size, s64 offset, sw* bytes_read )
{
if ( ! f->Ops.read_at )
f->Ops = default_file_operations;
return f->Ops.read_at( f->FD, buffer, size, offset, bytes_read, false );
}
GEN_IMPL_INLINE b32 file_write( FileInfo* f, void const* buffer, sw size )
{
s64 cur_offset = file_tell( f );