From 050b00f28abf9c9c14a0868814934b5221384129 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 21 Aug 2023 20:30:13 -0400 Subject: [PATCH] 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. --- project/bootstrap.cpp | 14 ++- project/components/ast.cpp | 39 +++--- project/components/ast.hpp | 10 +- project/components/ast_types.hpp | 4 +- project/components/header_end.hpp | 6 +- project/components/header_start.hpp | 17 +-- project/components/inlines.hpp | 4 +- project/components/interface.cpp | 8 +- project/components/interface.hpp | 4 +- project/components/interface.parsing.cpp | 66 +++++++--- .../{untyped.cpp => interface.untyped.cpp} | 4 +- project/components/interface.upfront.cpp | 4 +- project/components/static_data.cpp | 5 +- project/components/temp/ast_inlines.hpp | 2 + project/components/temp/ecode.hpp | 2 + project/components/temp/eoperator.hpp | 2 + project/components/temp/especifier.hpp | 3 + project/components/temp/etoktype.cpp | 3 + project/components/types.hpp | 4 +- project/dependencies/basic_types.hpp | 4 +- project/dependencies/containers.hpp | 4 +- project/dependencies/debug.cpp | 4 +- project/dependencies/debug.hpp | 4 +- project/dependencies/filesystem.cpp | 4 +- project/dependencies/filesystem.hpp | 4 +- project/dependencies/hashing.cpp | 4 +- project/dependencies/hashing.hpp | 4 +- project/dependencies/header_start.hpp | 3 +- project/dependencies/macros.hpp | 4 +- project/dependencies/memory.cpp | 4 +- project/dependencies/memory.hpp | 4 +- project/dependencies/printing.cpp | 4 +- project/dependencies/printing.hpp | 4 +- project/dependencies/src_start.cpp | 1 - project/dependencies/string_ops.cpp | 4 +- project/dependencies/string_ops.hpp | 4 +- project/dependencies/strings.cpp | 90 +++++++++++++- project/dependencies/strings.hpp | 116 +++++------------- project/dependencies/timing.cpp | 4 +- project/dependencies/timing.hpp | 4 +- project/enums/ESpecifier.csv | 1 + project/enums/ETokType.csv | 1 + project/gen.cpp | 2 +- project/helpers/helper.hpp | 6 + scripts/build.ci.ps1 | 2 +- 45 files changed, 326 insertions(+), 165 deletions(-) rename project/components/{untyped.cpp => interface.untyped.cpp} (98%) diff --git a/project/bootstrap.cpp b/project/bootstrap.cpp index 9cf1ab1..1076aec 100644 --- a/project/bootstrap.cpp +++ b/project/bootstrap.cpp @@ -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)) ); diff --git a/project/components/ast.cpp b/project/components/ast.cpp index e6f238a..0fd04f3 100644 --- a/project/components/ast.cpp +++ b/project/components/ast.cpp @@ -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; diff --git a/project/components/ast.hpp b/project/components/ast.hpp index af5e014..580f4d7 100644 --- a/project/components/ast.hpp +++ b/project/components/ast.hpp @@ -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 - diff --git a/project/components/ast_types.hpp b/project/components/ast_types.hpp index 7a01151..8a8c54c 100644 --- a/project/components/ast_types.hpp +++ b/project/components/ast_types.hpp @@ -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 - diff --git a/project/components/header_end.hpp b/project/components/header_end.hpp index 520fac1..d194cd7 100644 --- a/project/components/header_end.hpp +++ b/project/components/header_end.hpp @@ -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 - diff --git a/project/components/header_start.hpp b/project/components/header_start.hpp index a7587f1..2d7c4ed 100644 --- a/project/components/header_start.hpp +++ b/project/components/header_start.hpp @@ -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 - diff --git a/project/components/inlines.hpp b/project/components/inlines.hpp index d15b79c..06b0d51 100644 --- a/project/components/inlines.hpp +++ b/project/components/inlines.hpp @@ -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 }; } - diff --git a/project/components/interface.cpp b/project/components/interface.cpp index 2c19432..f3f3ae1 100644 --- a/project/components/interface.cpp +++ b/project/components/interface.cpp @@ -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; } - diff --git a/project/components/interface.hpp b/project/components/interface.hpp index f62cc7c..4b90046 100644 --- a/project/components/interface.hpp +++ b/project/components/interface.hpp @@ -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 - diff --git a/project/components/interface.parsing.cpp b/project/components/interface.parsing.cpp index 74c8d77..1760041 100644 --- a/project/components/interface.parsing.cpp +++ b/project/components/interface.parsing.cpp @@ -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 - diff --git a/project/components/untyped.cpp b/project/components/interface.untyped.cpp similarity index 98% rename from project/components/untyped.cpp rename to project/components/interface.untyped.cpp index e9ab823..ceb65b2 100644 --- a/project/components/untyped.cpp +++ b/project/components/interface.untyped.cpp @@ -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; } - diff --git a/project/components/interface.upfront.cpp b/project/components/interface.upfront.cpp index 4913ace..4e49d41 100644 --- a/project/components/interface.upfront.cpp +++ b/project/components/interface.upfront.cpp @@ -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 - diff --git a/project/components/static_data.cpp b/project/components/static_data.cpp index edcc7f6..b2701d9 100644 --- a/project/components/static_data.cpp +++ b/project/components/static_data.cpp @@ -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 - diff --git a/project/components/temp/ast_inlines.hpp b/project/components/temp/ast_inlines.hpp index 37ecca3..5563b82 100644 --- a/project/components/temp/ast_inlines.hpp +++ b/project/components/temp/ast_inlines.hpp @@ -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 diff --git a/project/components/temp/ecode.hpp b/project/components/temp/ecode.hpp index 26428f7..fc076fe 100644 --- a/project/components/temp/ecode.hpp +++ b/project/components/temp/ecode.hpp @@ -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 diff --git a/project/components/temp/eoperator.hpp b/project/components/temp/eoperator.hpp index 3fb0b46..eea9de8 100644 --- a/project/components/temp/eoperator.hpp +++ b/project/components/temp/eoperator.hpp @@ -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 diff --git a/project/components/temp/especifier.hpp b/project/components/temp/especifier.hpp index d0672e2..d246768 100644 --- a/project/components/temp/especifier.hpp +++ b/project/components/temp/especifier.hpp @@ -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 ) \ diff --git a/project/components/temp/etoktype.cpp b/project/components/temp/etoktype.cpp index edfeba6..cc888e0 100644 --- a/project/components/temp/etoktype.cpp +++ b/project/components/temp/etoktype.cpp @@ -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" ) \ diff --git a/project/components/types.hpp b/project/components/types.hpp index 8caadd1..7f16a2f 100644 --- a/project/components/types.hpp +++ b/project/components/types.hpp @@ -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; - diff --git a/project/dependencies/basic_types.hpp b/project/dependencies/basic_types.hpp index 66d54e2..6dc3693 100644 --- a/project/dependencies/basic_types.hpp +++ b/project/dependencies/basic_types.hpp @@ -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 - diff --git a/project/dependencies/containers.hpp b/project/dependencies/containers.hpp index cae7045..1c77aea 100644 --- a/project/dependencies/containers.hpp +++ b/project/dependencies/containers.hpp @@ -1,3 +1,6 @@ +#pragma once +#include "printing.hpp" + #pragma region Containers template @@ -540,4 +543,3 @@ protected: }; #pragma endregion Containers - diff --git a/project/dependencies/debug.cpp b/project/dependencies/debug.cpp index 5f7e28f..a3d044b 100644 --- a/project/dependencies/debug.cpp +++ b/project/dependencies/debug.cpp @@ -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 - diff --git a/project/dependencies/debug.hpp b/project/dependencies/debug.hpp index d9750e8..8e8fba1 100644 --- a/project/dependencies/debug.hpp +++ b/project/dependencies/debug.hpp @@ -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 - diff --git a/project/dependencies/filesystem.cpp b/project/dependencies/filesystem.cpp index 542593a..1861e9a 100644 --- a/project/dependencies/filesystem.cpp +++ b/project/dependencies/filesystem.cpp @@ -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 - diff --git a/project/dependencies/filesystem.hpp b/project/dependencies/filesystem.hpp index faadb53..113f839 100644 --- a/project/dependencies/filesystem.hpp +++ b/project/dependencies/filesystem.hpp @@ -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 - diff --git a/project/dependencies/hashing.cpp b/project/dependencies/hashing.cpp index c2a306e..2294810 100644 --- a/project/dependencies/hashing.cpp +++ b/project/dependencies/hashing.cpp @@ -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 - diff --git a/project/dependencies/hashing.hpp b/project/dependencies/hashing.hpp index f59b028..4b70f4a 100644 --- a/project/dependencies/hashing.hpp +++ b/project/dependencies/hashing.hpp @@ -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 - diff --git a/project/dependencies/header_start.hpp b/project/dependencies/header_start.hpp index 95853c0..e7c1379 100644 --- a/project/dependencies/header_start.hpp +++ b/project/dependencies/header_start.hpp @@ -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 - diff --git a/project/dependencies/macros.hpp b/project/dependencies/macros.hpp index 61d08c0..b28ec65 100644 --- a/project/dependencies/macros.hpp +++ b/project/dependencies/macros.hpp @@ -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 - diff --git a/project/dependencies/memory.cpp b/project/dependencies/memory.cpp index 911bf08..9d7a17c 100644 --- a/project/dependencies/memory.cpp +++ b/project/dependencies/memory.cpp @@ -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 - diff --git a/project/dependencies/memory.hpp b/project/dependencies/memory.hpp index 8b9b15b..d8335db 100644 --- a/project/dependencies/memory.hpp +++ b/project/dependencies/memory.hpp @@ -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 - diff --git a/project/dependencies/printing.cpp b/project/dependencies/printing.cpp index 2767cb2..d8342ff 100644 --- a/project/dependencies/printing.cpp +++ b/project/dependencies/printing.cpp @@ -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 - diff --git a/project/dependencies/printing.hpp b/project/dependencies/printing.hpp index 23a3808..8c7b895 100644 --- a/project/dependencies/printing.hpp +++ b/project/dependencies/printing.hpp @@ -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 - diff --git a/project/dependencies/src_start.cpp b/project/dependencies/src_start.cpp index 7582c0d..dda2e1d 100644 --- a/project/dependencies/src_start.cpp +++ b/project/dependencies/src_start.cpp @@ -78,4 +78,3 @@ #endif #pragma endregion Macros and Includes - diff --git a/project/dependencies/string_ops.cpp b/project/dependencies/string_ops.cpp index c1317d7..4fb578d 100644 --- a/project/dependencies/string_ops.cpp +++ b/project/dependencies/string_ops.cpp @@ -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 - diff --git a/project/dependencies/string_ops.hpp b/project/dependencies/string_ops.hpp index 0393fe0..7bb61d3 100644 --- a/project/dependencies/string_ops.hpp +++ b/project/dependencies/string_ops.hpp @@ -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 - diff --git a/project/dependencies/strings.cpp b/project/dependencies/strings.cpp index 623fda0..7b323f0 100644 --- a/project/dependencies/strings.cpp +++ b/project/dependencies/strings.cpp @@ -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 diff --git a/project/dependencies/strings.hpp b/project/dependencies/strings.hpp index 16a8ffc..2e82a2c 100644 --- a/project/dependencies/strings.hpp +++ b/project/dependencies/strings.hpp @@ -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; using StringCached = String const; #pragma endregion Strings - diff --git a/project/dependencies/timing.cpp b/project/dependencies/timing.cpp index 05a7db1..1062b0b 100644 --- a/project/dependencies/timing.cpp +++ b/project/dependencies/timing.cpp @@ -1,3 +1,6 @@ +#pragma once +#include "filesystem.cpp" + #pragma region Timing #ifdef GEN_BENCHMARK @@ -160,4 +163,3 @@ #endif #pragma endregion Timing - diff --git a/project/dependencies/timing.hpp b/project/dependencies/timing.hpp index 6ba8427..30390c7 100644 --- a/project/dependencies/timing.hpp +++ b/project/dependencies/timing.hpp @@ -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 - diff --git a/project/enums/ESpecifier.csv b/project/enums/ESpecifier.csv index 954a883..d7c1181 100644 --- a/project/enums/ESpecifier.csv +++ b/project/enums/ESpecifier.csv @@ -4,6 +4,7 @@ Constexpr, constexpr Constinit, constinit Explicit, explicit External_Linkage, extern +ForceInline, forceinline Global, global Inline, inline Internal_Linkage, internal diff --git a/project/enums/ETokType.csv b/project/enums/ETokType.csv index a816fae..49a2fe3 100644 --- a/project/enums/ETokType.csv +++ b/project/enums/ETokType.csv @@ -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" diff --git a/project/gen.cpp b/project/gen.cpp index c19f207..693acc6 100644 --- a/project/gen.cpp +++ b/project/gen.cpp @@ -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 diff --git a/project/helpers/helper.hpp b/project/helpers/helper.hpp index 3913d3b..675bc51 100644 --- a/project/helpers/helper.hpp +++ b/project/helpers/helper.hpp @@ -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 ) ) ); diff --git a/scripts/build.ci.ps1 b/scripts/build.ci.ps1 index f91ce98..c7d0bce 100644 --- a/scripts/build.ci.ps1 +++ b/scripts/build.ci.ps1 @@ -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 )