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:
Edward R. Gonzalez 2023-08-21 20:30:13 -04:00
parent 1241f44fd4
commit 050b00f28a
45 changed files with 326 additions and 165 deletions

View File

@ -20,16 +20,18 @@ constexpr char const* generation_notice =
"// This file was generated automatially by gen.bootstrap.cpp "
"(See: https://github.com/Ed94/gencpp)\n\n";
constexpr bool DontSkipIncludes = false;
int gen_main()
{
gen::init();
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp" );
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp" );
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp", DontSkipIncludes );
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp", DontSkipIncludes );
// gen_dep.hpp
{
Code header_start = scan_file( "dependencies/header_start.hpp" );
Code header_start = scan_file( "dependencies/header_start.hpp", DontSkipIncludes );
Code macros = scan_file( "dependencies/macros.hpp" );
Code basic_types = scan_file( "dependencies/basic_types.hpp" );
Code debug = scan_file( "dependencies/debug.hpp" );
@ -47,7 +49,7 @@ int gen_main()
header.print_fmt( generation_notice );
header.print_fmt( "// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n\n" );
header.print( header_start );
header.print_fmt( "GEN_NS_BEGIN\n\n" );
header.print_fmt( "\nGEN_NS_BEGIN\n" );
header.print( macros );
header.print( basic_types );
@ -61,7 +63,7 @@ int gen_main()
header.print( filesystem );
header.print( timing );
header.print_fmt( "GEN_NS_END\n\n" );
header.print_fmt( "GEN_NS_END\n" );
header.write();
}
@ -154,7 +156,7 @@ int gen_main()
Code interface = scan_file( "components/interface.cpp" );
Code upfront = scan_file( "components/interface.upfront.cpp" );
Code parsing = scan_file( "components/interface.parsing.cpp" );
Code untyped = scan_file( "components/untyped.cpp" );
Code untyped = scan_file( "components/interface.untyped.cpp" );
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
CodeNS parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );

View File

@ -1,3 +1,6 @@
#pragma once
#include "static_data.cpp"
Code Code::Global;
Code Code::Invalid;
@ -41,36 +44,34 @@ String AST::to_string()
case Comment:
{
if ( Prev && Prev->Type != Comment && Prev->Type != NewLine )
result.append("\n");
result.append( "\n" );
static char line[MaxCommentLineLength];
static char line[ MaxCommentLineLength ];
s32 left = Content.length();
s32 index = 0;
s32 curr = 0;
char const* end = & scast(String, Content).back();
char* scanner = Content.Data;
s32 curr = 0;
do
{
s32 length = 1;
while ( left && Content[index] != '\n' )
char const* next = scanner;
s32 length = 0;
while ( next != end && scanner[ length ] != '\n' )
{
next = scanner + length;
length++;
left--;
index++;
}
index++;
str_copy( line, (char const*)Content + curr, length );
result.append_fmt( "//%.*s", length, line );
mem_set( line, 0, MaxCommentLineLength);
length++;
left--;
curr = index;
str_copy( line, scanner, length );
result.append_fmt( "//%.*s", length, line );
mem_set( line, 0, MaxCommentLineLength );
scanner += length;
}
while ( left--, left > 0 );
while ( scanner <= end );
if ( result.back() != '\n' )
result.append("\n");
result.append( "\n" );
}
break;

View File

@ -1,3 +1,9 @@
#pragma once
#include "types.hpp"
#include "temp/ecode.hpp"
#include "temp/eoperator.hpp"
#include "temp/especifier.hpp"
struct AST;
struct AST_Body;
struct AST_Attributes;
@ -163,10 +169,11 @@ struct AST
Code& entry ( u32 idx );
bool has_entries();
bool is_equal ( AST* other );
String to_string ();
char const* type_str();
bool validate_body();
neverinline String to_string();
template< class Type >
Type cast()
{
@ -574,4 +581,3 @@ Define_CodeType( Var );
#undef Using_Code
#pragma endregion Code Types

View File

@ -1,3 +1,6 @@
#pragma once
#include "ast.hpp"
#pragma region AST Types
/*
Show only relevant members of the AST for its type.
@ -539,4 +542,3 @@ struct AST_Var
};
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
#pragma endregion AST Types

View File

@ -1,3 +1,7 @@
#pragma once
#include "inlines.hpp"
#include "temp/ast_inlines.hpp"
#pragma region Constants
#ifndef GEN_GLOBAL_BUCKET_SIZE
@ -73,6 +77,7 @@ extern CodeSpecifiers spec_constexpr;
extern CodeSpecifiers spec_constinit;
extern CodeSpecifiers spec_extern_linkage;
extern CodeSpecifiers spec_final;
extern CodeSpeciifers spec_forceinline;
extern CodeSpecifiers spec_global;
extern CodeSpecifiers spec_inline;
extern CodeSpecifiers spec_internal_linkage;
@ -168,4 +173,3 @@ extern CodeType t_typename;
extern AllocatorInfo Allocator_TypeTable;
#endif

View File

@ -1,3 +1,5 @@
#pragma once
/*
gencpp: An attempt at "simple" staged metaprogramming for c/c++.
@ -16,11 +18,12 @@
# include "gen.dep.hpp"
#endif
#ifdef GEN_DONT_USE_NAMESPACE
# define GEN_NS_BEGIN
# define GEN_NS_END
#else
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }
#ifndef GEN_NS_BEGIN
# ifdef GEN_DONT_USE_NAMESPACE
# define GEN_NS_BEGIN
# define GEN_NS_END
# else
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }
# endif
#endif

View File

@ -1,3 +1,6 @@
#pragma once
#include "interface.hpp"
void AST::append( AST* other )
{
if ( other->Parent )
@ -211,4 +214,3 @@ StrC token_fmt_impl( sw num, ... )
return { result, buf };
}

View File

@ -1,3 +1,6 @@
#pragma once
#include "ast.cpp"
internal void init_parser();
internal void deinit_parser();
@ -170,10 +173,12 @@ void define_constants()
#endif
# undef def_constant_code_type
# pragma push_macro( "forceinline" )
# pragma push_macro( "global" )
# pragma push_macro( "internal" )
# pragma push_macro( "local_persist" )
# pragma push_macro( "neverinline" )
# undef forceinline
# undef global
# undef internal
# undef local_persist
@ -189,6 +194,7 @@ void define_constants()
def_constant_spec( constinit, ESpecifier::Constinit );
def_constant_spec( extern_linkage, ESpecifier::External_Linkage );
def_constant_spec( final, ESpecifier::Final );
def_constant_spec( forceinline, ESpecifier::ForceInline );
def_constant_spec( global, ESpecifier::Global );
def_constant_spec( inline, ESpecifier::Inline );
def_constant_spec( internal_linkage, ESpecifier::Internal_Linkage );
@ -209,6 +215,7 @@ void define_constants()
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
spec_local_persist.set_global();
# pragma pop_macro( "forceinline" )
# pragma pop_macro( "global" )
# pragma pop_macro( "internal" )
# pragma pop_macro( "local_persist" )
@ -443,4 +450,3 @@ void set_allocator_string_table( AllocatorInfo allocator )
{
Allocator_StringArena = allocator;
}

View File

@ -1,3 +1,6 @@
#pragma once
#include "ast_types.hpp"
#pragma region Gen Interface
// Initialize the library.
@ -175,4 +178,3 @@ Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
#pragma endregion Untyped text
#pragma endregion Gen Interface

View File

@ -1,3 +1,7 @@
#pragma once
#include "temp/etoktype.cpp"
#include "interface.upfront.cpp"
namespace Parser
{
struct Token
@ -1140,7 +1144,7 @@ internal CodeExtern parse_exten_link ();
internal CodeFriend parse_friend ();
internal CodeFn parse_function ();
internal CodeNS parse_namespace ();
internal CodeOpCast parse_operator_cast ();
internal CodeOpCast parse_operator_cast ( CodeSpecifiers specifiers = NoCode );
internal CodeStruct parse_struct ( bool inplace_def = false );
internal CodeVar parse_variable ();
internal CodeTemplate parse_template ();
@ -2259,6 +2263,27 @@ Code parse_simple_preprocess( Parser::TokType which )
}
eat( TokType::BraceCurly_Close );
StrC prev_proc = Context.Scope->Prev->ProcName;
if ( str_compare( prev_proc.Ptr, "parse_typedef", prev_proc.Len ) != 0 )
{
if ( check( TokType::Statement_End ))
{
eat( TokType::Statement_End );
}
}
tok.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)tok.Text;
}
else
{
if ( str_compare( Context.Scope->Prev->ProcName.Ptr, "parse_typedef", Context.Scope->Prev->ProcName.Len ) != 0 )
{
if ( check( TokType::Statement_End ))
{
eat( TokType::Statement_End );
}
}
tok.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)tok.Text;
}
@ -2267,14 +2292,6 @@ Code parse_simple_preprocess( Parser::TokType which )
Code result = untyped_str( to_str( content ) );
Context.Scope->Name = tok;
if ( str_compare( Context.Scope->Prev->ProcName.Ptr, "parse_typedef", Context.Scope->Prev->ProcName.Len ) != 0 )
{
if ( check( TokType::Statement_End ))
{
eat( TokType::Statement_End );
}
}
Context.pop();
return result;
}
@ -2654,8 +2671,10 @@ CodeBody parse_class_struct_body( Parser::TokType which, Parser::Token name = Pa
case TokType::Spec_Consteval:
case TokType::Spec_Constexpr:
case TokType::Spec_Constinit:
case TokType::Spec_ForceInline:
case TokType::Spec_Inline:
case TokType::Spec_Mutable:
case TokType::Spec_NeverInline:
case TokType::Spec_Static:
case TokType::Spec_Volatile:
{
@ -2671,7 +2690,9 @@ CodeBody parse_class_struct_body( Parser::TokType which, Parser::Token name = Pa
case ESpecifier::Constexpr:
case ESpecifier::Constinit:
case ESpecifier::Inline:
case ESpecifier::ForceInline:
case ESpecifier::Mutable:
case ESpecifier::NeverInline:
case ESpecifier::Static:
case ESpecifier::Volatile:
break;
@ -2701,6 +2722,12 @@ CodeBody parse_class_struct_body( Parser::TokType which, Parser::Token name = Pa
member = parse_destructor( specifiers );
break;
}
if ( currtok.Type == TokType::Decl_Operator )
{
member = parse_operator_cast( specifiers );
break;
}
}
//! Fallthrough intentional
case TokType::Identifier:
@ -3028,6 +3055,7 @@ CodeBody parse_global_nspace( CodeT which )
case TokType::Spec_Constexpr:
case TokType::Spec_Constinit:
case TokType::Spec_Extern:
case TokType::Spec_ForceInline:
case TokType::Spec_Global:
case TokType::Spec_Inline:
case TokType::Spec_Internal_Linkage:
@ -3047,6 +3075,7 @@ CodeBody parse_global_nspace( CodeT which )
{
case ESpecifier::Constexpr:
case ESpecifier::Constinit:
case ESpecifier::ForceInline:
case ESpecifier::Global:
case ESpecifier::External_Linkage:
case ESpecifier::Internal_Linkage:
@ -3696,7 +3725,9 @@ CodeFn parse_functon()
case ESpecifier::Consteval:
case ESpecifier::Constexpr:
case ESpecifier::External_Linkage:
case ESpecifier::ForceInline:
case ESpecifier::Inline:
case ESpecifier::NeverInline:
case ESpecifier::Static:
break;
@ -3840,7 +3871,9 @@ CodeOperator parse_operator()
{
case ESpecifier::Const:
case ESpecifier::Constexpr:
case ESpecifier::ForceInline:
case ESpecifier::Inline:
case ESpecifier::NeverInline:
case ESpecifier::Static:
break;
@ -3885,11 +3918,14 @@ CodeOperator parse_operator( StrC def )
return (CodeOperator) parse_operator();
}
CodeOpCast parse_operator_cast()
CodeOpCast parse_operator_cast( CodeSpecifiers specifiers )
{
using namespace Parser;
push_scope();
// Specifiers attributed to the cast
// Operator's namespace if not within same class.
Token name = NullToken;
if ( check( TokType::Identifier ) )
{
@ -3914,11 +3950,14 @@ CodeOpCast parse_operator_cast()
eat( TokType::Capture_Start );
eat( TokType::Capture_End );
CodeSpecifiers specifiers = { nullptr };
if ( check(TokType::Spec_Const))
{
specifiers = spec_const;
if ( specifiers.ast == nullptr )
specifiers = def_specifier( ESpecifier::Const );
else
specifiers.append( ESpecifier::Const );
eat( TokType::Spec_Const );
}
@ -4852,4 +4891,3 @@ CodeVar parse_variable( StrC def )
# undef left
# undef check
# undef push_scope

View File

@ -1,3 +1,6 @@
#pragma once
#include "interface.parsing.cpp"
sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
{
char const* buf_begin = buf;
@ -181,4 +184,3 @@ Code untyped_token_fmt( s32 num_tokens, ... )
return result;
}

View File

@ -1,3 +1,6 @@
#pragma once
#include "interface.cpp"
#pragma region Upfront
enum class OpValidateResult : u32
@ -2255,4 +2258,3 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
#pragma endregion Upfront

View File

@ -1,3 +1,6 @@
#pragma once
#include "src_start.cpp"
#pragma region StaticData
// TODO : Convert global allocation strategy to use a slab allocation strategy.
@ -47,6 +50,7 @@ global CodeSpecifiers spec_constexpr;
global CodeSpecifiers spec_constinit;
global CodeSpecifiers spec_extern_linkage;
global CodeSpecifiers spec_final;
global CodeSpeciifers spec_forceinline;
global CodeSpecifiers spec_global;
global CodeSpecifiers spec_inline;
global CodeSpecifiers spec_internal_linkage;
@ -95,4 +99,3 @@ global CodeType t_f64;
#endif
#pragma endregion Constants

View File

@ -1,3 +1,5 @@
#pragma once
// This is the non-bootstraped version of the Common AST Implementation. This will be obsolete once bootstrap is stress tested.
#pragma region AST Common

View File

@ -1,3 +1,5 @@
#pragma once
// This is the non-bootstraped version of the ECode. This will be obsolete once bootstrap is stress tested.
namespace ECode

View File

@ -1,3 +1,5 @@
#pragma once
// This is the non-bootstraped version of the EOperator. This will be obsolete once bootstrap is stress tested.
namespace EOperator

View File

@ -1,3 +1,5 @@
#pragma once
// This is the non-bootstraped version of the ESpecifier. This will be obsolete once bootstrap is stress tested.
namespace ESpecifier
@ -15,6 +17,7 @@ namespace ESpecifier
Entry( Constinit, constinit ) \
Entry( Explicit, explicit ) \
Entry( External_Linkage, extern ) \
Entry( ForceInline, forceinline ) \
Entry( Global, global ) \
Entry( Inline, inline ) \
Entry( Internal_Linkage, internal ) \

View File

@ -1,3 +1,5 @@
#pragma once
namespace Parser
{
/*
@ -78,6 +80,7 @@ namespace Parser
Entry( Spec_Constinit, "constinit" ) \
Entry( Spec_Explicit, "explicit" ) \
Entry( Spec_Extern, "extern" ) \
Entry( Spec_ForceInline, "forceinline" ) \
Entry( Spec_Final, "final" ) \
Entry( Spec_Global, "global" ) \
Entry( Spec_Inline, "inline" ) \

View File

@ -1,3 +1,6 @@
#pragma once
#include "header_start.hpp"
using LogFailType = sw(*)(char const*, ...);
// By default this library will either crash or exit if an error is detected while generating codes.
@ -74,4 +77,3 @@ constexpr EPreprocessCond PreprocessCond_If = EPreprocessCond::If;
constexpr EPreprocessCond PreprocessCond_IfDef = EPreprocessCond::IfDef;
constexpr EPreprocessCond PreprocessCond_IfNotDef = EPreprocessCond::IfNotDef;
constexpr EPreprocessCond PreprocessCond_ElIf = EPreprocessCond::ElIf;

View File

@ -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

View File

@ -1,3 +1,6 @@
#pragma once
#include "printing.hpp"
#pragma region Containers
template<class Type>
@ -540,4 +543,3 @@ protected:
};
#pragma endregion Containers

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -78,4 +78,3 @@
#endif
#pragma endregion Macros and Includes

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,6 @@
#pragma once
#include "filesystem.cpp"
#pragma region Timing
#ifdef GEN_BENCHMARK
@ -160,4 +163,3 @@
#endif
#pragma endregion Timing

View File

@ -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

View File

@ -4,6 +4,7 @@ Constexpr, constexpr
Constinit, constinit
Explicit, explicit
External_Linkage, extern
ForceInline, forceinline
Global, global
Inline, inline
Internal_Linkage, internal

1 Invalid INVALID
4 Constinit constinit
5 Explicit explicit
6 External_Linkage extern
7 ForceInline forceinline
8 Global global
9 Inline inline
10 Internal_Linkage internal

View File

@ -61,6 +61,7 @@ Spec_Constinit, "constinit"
Spec_Explicit, "explicit"
Spec_Extern, "extern"
Spec_Final, "final"
Spec_ForceInline, "forceinline"
Spec_Global, "global"
Spec_Inline, "inline"
Spec_Internal_Linkage, "internal"

1 Invalid __invalid__
61 Spec_Explicit explicit
62 Spec_Extern extern
63 Spec_Final final
64 Spec_ForceInline forceinline
65 Spec_Global global
66 Spec_Inline inline
67 Spec_Internal_Linkage internal

View File

@ -25,7 +25,7 @@ GEN_NS_BEGIN
#include "components/interface.upfront.cpp"
#include "components/temp/etoktype.cpp"
#include "components/interface.parsing.cpp"
#include "components/untyped.cpp"
#include "components/interface.untyped.cpp"
GEN_NS_END

View File

@ -157,9 +157,13 @@ CodeBody gen_especifier( char const* path )
#pragma push_macro( "local_persist" )
#pragma push_macro( "do_once_start" )
#pragma push_macro( "do_once_end" )
#pragma push_macro( "forceinline" )
#pragma push_macro( "neverinline" )
#undef local_persist
#undef do_once_start
#undef do_once_end
#undef forceinline
#undef neverinline
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
StrC to_str( Type type )
{
@ -202,6 +206,8 @@ CodeBody gen_especifier( char const* path )
#pragma pop_macro( "local_persist" )
#pragma pop_macro( "do_once_start" )
#pragma pop_macro( "do_once_end" )
#pragma pop_macro( "forceinline" )
#pragma pop_macro( "neverinline" )
CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) );

View File

@ -446,7 +446,7 @@ if ( $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp"))
'gen.hpp'
)
$exclude = $null
format-cpp $path_gen $include $exclude
# format-cpp $path_gen $include $exclude
}
if ( $test )