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 " "// This file was generated automatially by gen.bootstrap.cpp "
"(See: https://github.com/Ed94/gencpp)\n\n"; "(See: https://github.com/Ed94/gencpp)\n\n";
constexpr bool DontSkipIncludes = false;
int gen_main() int gen_main()
{ {
gen::init(); gen::init();
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp" ); Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp", DontSkipIncludes );
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp" ); Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp", DontSkipIncludes );
// gen_dep.hpp // 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 macros = scan_file( "dependencies/macros.hpp" );
Code basic_types = scan_file( "dependencies/basic_types.hpp" ); Code basic_types = scan_file( "dependencies/basic_types.hpp" );
Code debug = scan_file( "dependencies/debug.hpp" ); Code debug = scan_file( "dependencies/debug.hpp" );
@ -47,7 +49,7 @@ int gen_main()
header.print_fmt( generation_notice ); 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_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( header_start );
header.print_fmt( "GEN_NS_BEGIN\n\n" ); header.print_fmt( "\nGEN_NS_BEGIN\n" );
header.print( macros ); header.print( macros );
header.print( basic_types ); header.print( basic_types );
@ -61,7 +63,7 @@ int gen_main()
header.print( filesystem ); header.print( filesystem );
header.print( timing ); header.print( timing );
header.print_fmt( "GEN_NS_END\n\n" ); header.print_fmt( "GEN_NS_END\n" );
header.write(); header.write();
} }
@ -154,7 +156,7 @@ int gen_main()
Code interface = scan_file( "components/interface.cpp" ); Code interface = scan_file( "components/interface.cpp" );
Code upfront = scan_file( "components/interface.upfront.cpp" ); Code upfront = scan_file( "components/interface.upfront.cpp" );
Code parsing = scan_file( "components/interface.parsing.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" ); CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
CodeNS parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) ); 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::Global;
Code Code::Invalid; Code Code::Invalid;
@ -45,29 +48,27 @@ String AST::to_string()
static char line[ MaxCommentLineLength ]; static char line[ MaxCommentLineLength ];
s32 left = Content.length(); char const* end = & scast(String, Content).back();
s32 index = 0; char* scanner = Content.Data;
s32 curr = 0; s32 curr = 0;
do do
{ {
s32 length = 1; char const* next = scanner;
while ( left && Content[index] != '\n' ) s32 length = 0;
while ( next != end && scanner[ length ] != '\n' )
{ {
next = scanner + length;
length++; length++;
left--;
index++;
} }
index++; length++;
str_copy( line, (char const*)Content + curr, length ); str_copy( line, scanner, length );
result.append_fmt( "//%.*s", length, line ); result.append_fmt( "//%.*s", length, line );
mem_set( line, 0, MaxCommentLineLength ); mem_set( line, 0, MaxCommentLineLength );
length++; scanner += length;
left--;
curr = index;
} }
while ( left--, left > 0 ); while ( scanner <= end );
if ( result.back() != '\n' ) if ( result.back() != '\n' )
result.append( "\n" ); result.append( "\n" );

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;
struct AST_Body; struct AST_Body;
struct AST_Attributes; struct AST_Attributes;
@ -163,10 +169,11 @@ struct AST
Code& entry ( u32 idx ); Code& entry ( u32 idx );
bool has_entries(); bool has_entries();
bool is_equal ( AST* other ); bool is_equal ( AST* other );
String to_string ();
char const* type_str(); char const* type_str();
bool validate_body(); bool validate_body();
neverinline String to_string();
template< class Type > template< class Type >
Type cast() Type cast()
{ {
@ -574,4 +581,3 @@ Define_CodeType( Var );
#undef Using_Code #undef Using_Code
#pragma endregion Code Types #pragma endregion Code Types

View File

@ -1,3 +1,6 @@
#pragma once
#include "ast.hpp"
#pragma region AST Types #pragma region AST Types
/* /*
Show only relevant members of the AST for its type. 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"); static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
#pragma endregion AST Types #pragma endregion AST Types

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,6 @@
#pragma once
#include "src_start.cpp"
#pragma region StaticData #pragma region StaticData
// TODO : Convert global allocation strategy to use a slab allocation strategy. // 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_constinit;
global CodeSpecifiers spec_extern_linkage; global CodeSpecifiers spec_extern_linkage;
global CodeSpecifiers spec_final; global CodeSpecifiers spec_final;
global CodeSpeciifers spec_forceinline;
global CodeSpecifiers spec_global; global CodeSpecifiers spec_global;
global CodeSpecifiers spec_inline; global CodeSpecifiers spec_inline;
global CodeSpecifiers spec_internal_linkage; global CodeSpecifiers spec_internal_linkage;
@ -95,4 +99,3 @@ global CodeType t_f64;
#endif #endif
#pragma endregion Constants #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. // This is the non-bootstraped version of the Common AST Implementation. This will be obsolete once bootstrap is stress tested.
#pragma region AST Common #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. // This is the non-bootstraped version of the ECode. This will be obsolete once bootstrap is stress tested.
namespace ECode 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. // This is the non-bootstraped version of the EOperator. This will be obsolete once bootstrap is stress tested.
namespace EOperator 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. // This is the non-bootstraped version of the ESpecifier. This will be obsolete once bootstrap is stress tested.
namespace ESpecifier namespace ESpecifier
@ -15,6 +17,7 @@ namespace ESpecifier
Entry( Constinit, constinit ) \ Entry( Constinit, constinit ) \
Entry( Explicit, explicit ) \ Entry( Explicit, explicit ) \
Entry( External_Linkage, extern ) \ Entry( External_Linkage, extern ) \
Entry( ForceInline, forceinline ) \
Entry( Global, global ) \ Entry( Global, global ) \
Entry( Inline, inline ) \ Entry( Inline, inline ) \
Entry( Internal_Linkage, internal ) \ Entry( Internal_Linkage, internal ) \

View File

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

View File

@ -1,3 +1,6 @@
#pragma once
#include "header_start.hpp"
using LogFailType = sw(*)(char const*, ...); using LogFailType = sw(*)(char const*, ...);
// By default this library will either crash or exit if an error is detected while generating codes. // 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_IfDef = EPreprocessCond::IfDef;
constexpr EPreprocessCond PreprocessCond_IfNotDef = EPreprocessCond::IfNotDef; constexpr EPreprocessCond PreprocessCond_IfNotDef = EPreprocessCond::IfNotDef;
constexpr EPreprocessCond PreprocessCond_ElIf = EPreprocessCond::ElIf; constexpr EPreprocessCond PreprocessCond_ElIf = EPreprocessCond::ElIf;

View File

@ -1,3 +1,6 @@
#pragma once
#include "macros.hpp"
#pragma region Basic Types #pragma region Basic Types
#define GEN_U8_MIN 0u #define GEN_U8_MIN 0u
@ -118,4 +121,3 @@ typedef s16 b16;
typedef s32 b32; typedef s32 b32;
#pragma endregion Basic Types #pragma endregion Basic Types

View File

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

View File

@ -1,3 +1,6 @@
#pragma once
#include "src_start.cpp"
#pragma region Debug #pragma region Debug
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... ) 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 #endif
#pragma endregion Debug #pragma endregion Debug

View File

@ -1,3 +1,6 @@
#pragma once
#include "basic_types.hpp"
#pragma region Debug #pragma region Debug
#if defined( _MSC_VER ) #if defined( _MSC_VER )
@ -56,4 +59,3 @@ void process_exit( u32 code );
#endif #endif
#pragma endregion Debug #pragma endregion Debug

View File

@ -1,3 +1,6 @@
#pragma once
#include "strings.cpp"
#pragma region File Handling #pragma region File Handling
#if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN ) #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 }; FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };
#pragma endregion File Handling #pragma endregion File Handling

View File

@ -1,3 +1,6 @@
#pragma once
#include "strings.hpp"
#pragma region File Handling #pragma region File Handling
typedef u32 FileMode; typedef u32 FileMode;
@ -370,4 +373,3 @@ u8* file_stream_buf( FileInfo* file, sw* size );
extern FileOperations const memory_file_operations; extern FileOperations const memory_file_operations;
#pragma endregion File Handling #pragma endregion File Handling

View File

@ -1,3 +1,6 @@
#pragma once
#include "memory.cpp"
#pragma region Hashing #pragma region Hashing
global u32 const _crc32_table[ 256 ] = { global u32 const _crc32_table[ 256 ] = {
@ -83,4 +86,3 @@ u64 crc64( void const* data, sw len )
} }
#pragma endregion Hashing #pragma endregion Hashing

View File

@ -1,7 +1,9 @@
#pragma once
#include "containers.hpp"
#pragma region Hashing #pragma region Hashing
u32 crc32( void const* data, sw len ); u32 crc32( void const* data, sw len );
u64 crc64( void const* data, sw len ); u64 crc64( void const* data, sw len );
#pragma endregion Hashing #pragma endregion Hashing

View File

@ -1,3 +1,5 @@
#pragma once
#pragma region Platform Detection #pragma region Platform Detection
/* Platform architecture */ /* Platform architecture */
@ -120,4 +122,3 @@
# define GEN_NS_BEGIN namespace gen { # define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END } # define GEN_NS_END }
#endif #endif

View File

@ -1,3 +1,6 @@
#pragma once
#include "header_start.hpp"
#pragma region Macros #pragma region Macros
#define zpl_cast( Type ) ( Type ) #define zpl_cast( Type ) ( Type )
@ -161,4 +164,3 @@ void swap( Type& a, Type& b )
} }
#pragma endregion Macros #pragma endregion Macros

View File

@ -1,3 +1,6 @@
#pragma once
#include "printing.cpp"
#pragma region Memory #pragma region Memory
void* mem_copy( void* dest, void const* source, sw n ) void* mem_copy( void* dest, void const* source, sw n )
@ -387,4 +390,3 @@ void Pool::clear()
} }
#pragma endregion Memory #pragma endregion Memory

View File

@ -1,3 +1,6 @@
#pragma once
#include "debug.hpp"
#pragma region Memory #pragma region Memory
#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) ) #define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) )
@ -484,4 +487,3 @@ struct Pool
}; };
#pragma endregion Memory #pragma endregion Memory

View File

@ -1,3 +1,6 @@
#pragma once
#include "string_ops.cpp"
#pragma region Printing #pragma region Printing
enum enum
@ -582,4 +585,3 @@ sw str_fmt_out_err( char const* fmt, ... )
} }
#pragma endregion Printing #pragma endregion Printing

View File

@ -1,3 +1,6 @@
#pragma once
#include "string_ops.hpp"
#pragma region Printing #pragma region Printing
struct FileInfo; struct FileInfo;
@ -34,4 +37,3 @@ sw log_fmt(char const* fmt, ...)
} }
#pragma endregion Printing #pragma endregion Printing

View File

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

View File

@ -1,3 +1,6 @@
#pragma once
#include "debug.cpp"
#pragma region String Ops #pragma region String Ops
internal internal
@ -207,4 +210,3 @@ f64 str_to_f64( const char* str, char** end_ptr )
} }
#pragma endregion String Ops #pragma endregion String Ops

View File

@ -1,3 +1,6 @@
#pragma once
#include "memory.hpp"
#pragma region String Ops #pragma region String Ops
GEN_DEF_INLINE const char* char_first_occurence( const char* str, char c ); 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 #pragma endregion String Ops

View File

@ -1,3 +1,6 @@
#pragma once
#include "hashing.cpp"
#pragma region String #pragma region String
String String::fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... ) 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 ); 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, ... ) String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... )
{ {
local_persist thread_local local_persist thread_local
@ -36,5 +87,42 @@ bool String::append_fmt( char const* fmt, ... )
return append( buf, res ); 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 #pragma region Strings
// Constant string with length. // Constant string with length.
@ -54,54 +57,10 @@ struct String
} }
static static
String make_reserve( AllocatorInfo allocator, sw capacity ) 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;
}
static static
String make_length( AllocatorInfo allocator, char const* str, sw length ) 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;
}
static static
String fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... ); String fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... );
@ -138,44 +97,7 @@ struct String
return true; return true;
} }
bool make_space_for( char const* str, sw add_len ) 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 append( char const* str ) bool append( char const* str )
{ {
@ -209,7 +131,7 @@ struct String
bool append( const String other ) bool append( const String other )
{ {
return append( other.Data, other.length() );; return append( other.Data, other.length() );
} }
bool append_fmt( char const* fmt, ... ); bool append_fmt( char const* fmt, ... );
@ -268,6 +190,29 @@ struct String
return header.Length; 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 ) void trim( char const* cut_set )
{ {
sw len = 0; sw len = 0;
@ -372,4 +317,3 @@ using StringTable = HashTable<String const>;
using StringCached = String const; using StringCached = String const;
#pragma endregion Strings #pragma endregion Strings

View File

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

View File

@ -1,3 +1,6 @@
#pragma once
#include "filesystem.hpp"
#pragma region Timing #pragma region Timing
#ifdef GEN_BENCHMARK #ifdef GEN_BENCHMARK
@ -12,4 +15,3 @@ u64 time_rel_ms( void );
#endif #endif
#pragma endregion Timing #pragma endregion Timing

View File

@ -4,6 +4,7 @@ Constexpr, constexpr
Constinit, constinit Constinit, constinit
Explicit, explicit Explicit, explicit
External_Linkage, extern External_Linkage, extern
ForceInline, forceinline
Global, global Global, global
Inline, inline Inline, inline
Internal_Linkage, internal 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_Explicit, "explicit"
Spec_Extern, "extern" Spec_Extern, "extern"
Spec_Final, "final" Spec_Final, "final"
Spec_ForceInline, "forceinline"
Spec_Global, "global" Spec_Global, "global"
Spec_Inline, "inline" Spec_Inline, "inline"
Spec_Internal_Linkage, "internal" 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/interface.upfront.cpp"
#include "components/temp/etoktype.cpp" #include "components/temp/etoktype.cpp"
#include "components/interface.parsing.cpp" #include "components/interface.parsing.cpp"
#include "components/untyped.cpp" #include "components/interface.untyped.cpp"
GEN_NS_END GEN_NS_END

View File

@ -157,9 +157,13 @@ CodeBody gen_especifier( char const* path )
#pragma push_macro( "local_persist" ) #pragma push_macro( "local_persist" )
#pragma push_macro( "do_once_start" ) #pragma push_macro( "do_once_start" )
#pragma push_macro( "do_once_end" ) #pragma push_macro( "do_once_end" )
#pragma push_macro( "forceinline" )
#pragma push_macro( "neverinline" )
#undef local_persist #undef local_persist
#undef do_once_start #undef do_once_start
#undef do_once_end #undef do_once_end
#undef forceinline
#undef neverinline
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize( CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
StrC to_str( Type type ) StrC to_str( Type type )
{ {
@ -202,6 +206,8 @@ CodeBody gen_especifier( char const* path )
#pragma pop_macro( "local_persist" ) #pragma pop_macro( "local_persist" )
#pragma pop_macro( "do_once_start" ) #pragma pop_macro( "do_once_start" )
#pragma pop_macro( "do_once_end" ) #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 ) ) ); 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' 'gen.hpp'
) )
$exclude = $null $exclude = $null
format-cpp $path_gen $include $exclude # format-cpp $path_gen $include $exclude
} }
if ( $test ) if ( $test )