26 Commits

Author SHA1 Message Date
Ed_
26623075ad started to work on modularizing parser code paths 2025-02-19 12:10:11 -05:00
Ed_
7ea90ef349 intellisense still broken... 2025-02-19 11:22:00 -05:00
Ed_
6d531fdf97 Fixing intellisense 2025-02-19 11:08:24 -05:00
Ed_
3b81eea688 Doing some initial prep for parser overhaul 2025-02-19 10:50:55 -05:00
Ed_
844d431e1c Setup Context's logger and fallback. (Not yet used in implementation). 2025-02-19 10:50:36 -05:00
Ed_
727b54c341 Added CodeSpecifiers::index_of for cpp, fix token bug with () operator in parse_operator_after_ret_type 2025-02-15 21:22:33 -05:00
Ed_
ef72d27f3e made optionals for c11 actually work... 2025-02-11 19:24:42 -05:00
Ed_
75b1d42cca changes based off of metadesk genc_c11 2025-02-11 18:59:09 -05:00
Ed_
878bc4c8ae Merge pull request #72 from Ed94/dev
Changes involved with getting gencpp-odin setup
2025-02-04 22:43:18 -05:00
Ed_
ec8dd1e9cd missing delete specifier (gen_unreal_engine) 2025-02-04 22:37:28 -05:00
Ed_
c0ea2ce3ff fix for edge case (running out of tokens while parsing assignment expression 2025-02-04 22:05:24 -05:00
Ed_
b5652a4dad if on c11 segmented (parsing spec defines were mising!) 2025-02-04 21:42:01 -05:00
Ed_
dda70fce36 can't use static globals on static libs 2025-02-04 21:23:51 -05:00
Ed_
3bce2e9b8a rename GEN_INTELLISENSE_DIRECTIVES -> INTELLISENSE_DIRECTIVES 2025-02-04 18:33:07 -05:00
Ed_
f3f8f2fff2 update readme with related repos 2025-02-04 17:24:03 -05:00
Ed_
c600a3e0dc add missing defines 2025-02-04 17:04:33 -05:00
Ed_
372cda734e fixes for generated c11 segemented 2025-02-04 16:17:29 -05:00
Ed_
6481313969 Various fixes and adjustments
* moved constants to components/constants.hpp (adjsuted generators accordingly)
* parser accepts include & defineas parameter identifiers (will add more flags for keywords when necessary
2025-02-04 15:35:28 -05:00
Ed_
5c17983a73 move more strbuilder functions to cpp 2025-02-04 14:53:26 -05:00
Ed_
b6d95e8d70 move strbuilder_make_space_for to strings.cpp (not inlined) 2025-02-04 14:17:15 -05:00
Ed_
6f2d81434e fixes 2025-02-04 12:57:42 -05:00
Ed_
b8695a33db added missing asserts to serialization functions 2025-02-04 11:50:15 -05:00
Ed_
1f958e121c more adjustments based on odin binding drafting 2025-02-04 01:57:23 -05:00
Ed_
e457191f5d moved seiralization inlines to inlines.hpp, more adjustments 2025-02-03 18:53:35 -05:00
Ed_
0d8f30b25c adjustments based on odin bindings drafting 2025-02-03 11:26:03 -05:00
Ed_
d08efcb5ef Corrections while implementing odin bindings 2025-02-03 09:42:31 -05:00
72 changed files with 1252 additions and 857 deletions

View File

@ -11,6 +11,14 @@ These build up a code AST to then serialize with a file builder, or can be trave
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto). This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
Its not meant to be a black box metaprogramming utility, it should be easy to integrate into a user's project domain. Its not meant to be a black box metaprogramming utility, it should be easy to integrate into a user's project domain.
## Langauge Bindings
* [gencpp-odin](https://github.com/Ed94/gencpp-odin): Bindings for the odin programming language.
## Utility Libraries
* [UnrealGencpp](https://github.com/Ed94/UnrealGencpp): Setup as a plugin to integrate into Unreal Engine or Unreal Projects.
## Documentation ## Documentation
* [docs - General](./docs/Readme.md): Overview and additional docs * [docs - General](./docs/Readme.md): Overview and additional docs

View File

@ -191,7 +191,7 @@ These require the following to be handled to the equivalent extent as the other
4. [ast.cpp](./components/ast.cpp): Need to review 4. [ast.cpp](./components/ast.cpp): Need to review
* `code_debug_str` * `code_debug_str`
* `code_is_equal` * `code_is_equal`
* `code_to_strbuilder_ptr` * `code_to_strbuilder_ref`
* `code_validate_body` * `code_validate_body`
5. [code_serialization.cpp](./components/code_serialization.cpp): Define serialization here. 5. [code_serialization.cpp](./components/code_serialization.cpp): Define serialization here.
6. [inlines.hpp](./components/inlines.hpp): Any inline definitions for the `struct Code<Name>` are defined here. 6. [inlines.hpp](./components/inlines.hpp): Any inline definitions for the `struct Code<Name>` are defined here.

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# include "builder.hpp" # include "builder.hpp"
#endif #endif

View File

@ -1,9 +1,9 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "helpers/push_ignores.inline.hpp" # include "helpers/push_ignores.inline.hpp"
# include "components/header_start.hpp" # include "components/header_start.hpp"
# include "components/types.hpp" # include "components/types.hpp"
# include "components/gen/ecode.hpp" # include "components/gen/ecodetypes.hpp"
# include "components/gen/eoperator.hpp" # include "components/gen/eoperator.hpp"
# include "components/gen/especifier.hpp" # include "components/gen/especifier.hpp"
# include "components/ast.hpp" # include "components/ast.hpp"

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "helpers/push_ignores.inline.hpp" # include "helpers/push_ignores.inline.hpp"
# include "components/header_start.hpp" # include "components/header_start.hpp"

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# include "scanner.hpp" # include "scanner.hpp"
#endif #endif
@ -24,7 +24,7 @@ Code scan_file( char const* path )
file_read( & file, str, fsize ); file_read( & file, str, fsize );
strbuilder_get_header(str)->Length = fsize; strbuilder_get_header(str)->Length = fsize;
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks // Skip INTELLISENSE_DIRECTIVES preprocessor blocks
// Its designed so that the directive should be the first thing in the file. // Its designed so that the directive should be the first thing in the file.
// Anything that comes before it will also be omitted. // Anything that comes before it will also be omitted.
{ {
@ -33,7 +33,7 @@ Code scan_file( char const* path )
#define move_fwd() do { ++ scanner; -- left; } while (0) #define move_fwd() do { ++ scanner; -- left; } while (0)
const Str directive_start = txt( "ifdef" ); const Str directive_start = txt( "ifdef" );
const Str directive_end = txt( "endif" ); const Str directive_end = txt( "endif" );
const Str def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" ); const Str def_intellisense = txt("INTELLISENSE_DIRECTIVES" );
bool found_directive = false; bool found_directive = false;
char const* scanner = (char const*)str; char const* scanner = (char const*)str;

View File

@ -1,9 +1,9 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "helpers/push_ignores.inline.hpp" # include "helpers/push_ignores.inline.hpp"
# include "components/header_start.hpp" # include "components/header_start.hpp"
# include "components/types.hpp" # include "components/types.hpp"
# include "components/gen/ecode.hpp" # include "components/gen/ecodetypes.hpp"
# include "components/gen/eoperator.hpp" # include "components/gen/eoperator.hpp"
# include "components/gen/especifier.hpp" # include "components/gen/especifier.hpp"
# include "components/ast.hpp" # include "components/ast.hpp"

View File

@ -30,7 +30,7 @@ int gen_main()
gen::init( & ctx); gen::init( & ctx);
CodeBody gen_component_header = def_global_body( args( CodeBody gen_component_header = def_global_body( args(
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ), def_preprocess_cond( PreprocessCond_IfDef, txt("INTELLISENSE_DIRECTIVES") ),
pragma_once, pragma_once,
def_include(txt("components/types.hpp")), def_include(txt("components/types.hpp")),
preprocess_endif, preprocess_endif,

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "static_data.cpp" #include "static_data.cpp"
#endif #endif
@ -379,11 +379,11 @@ Code code_duplicate(Code self)
StrBuilder code_to_strbuilder(Code self) StrBuilder code_to_strbuilder(Code self)
{ {
StrBuilder result = strbuilder_make_str( _ctx->Allocator_Temp, txt("") ); StrBuilder result = strbuilder_make_str( _ctx->Allocator_Temp, txt("") );
code_to_strbuilder_ptr( self, & result ); code_to_strbuilder_ref( self, & result );
return result; return result;
} }
void code_to_strbuilder_ptr( Code self, StrBuilder* result ) void code_to_strbuilder_ref( Code self, StrBuilder* result )
{ {
GEN_ASSERT(self != nullptr); GEN_ASSERT(self != nullptr);
local_persist thread_local local_persist thread_local

View File

@ -1,9 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "types.hpp" #include "parser_types.hpp"
#include "gen/ecode.hpp"
#include "gen/eoperator.hpp"
#include "gen/especifier.hpp"
#endif #endif
/* /*
@ -193,6 +190,7 @@ typedef AST_Stmt_If* CodeStmt_If;
typedef AST_Stmt_For* CodeStmt_For; typedef AST_Stmt_For* CodeStmt_For;
typedef AST_Stmt_Goto* CodeStmt_Goto; typedef AST_Stmt_Goto* CodeStmt_Goto;
typedef AST_Stmt_Label* CodeStmt_Label; typedef AST_Stmt_Label* CodeStmt_Label;
typedef AST_Stmt_Lambda* CodeStmt_Lambda;
typedef AST_Stmt_Switch* CodeStmt_Switch; typedef AST_Stmt_Switch* CodeStmt_Switch;
typedef AST_Stmt_While* CodeStmt_While; typedef AST_Stmt_While* CodeStmt_While;
#else #else
@ -208,6 +206,7 @@ struct CodeStmt_If;
struct CodeStmt_For; struct CodeStmt_For;
struct CodeStmt_Goto; struct CodeStmt_Goto;
struct CodeStmt_Label; struct CodeStmt_Label;
struct CodeStmt_Lambda;
struct CodeStmt_Switch; struct CodeStmt_Switch;
struct CodeStmt_While; struct CodeStmt_While;
#endif #endif
@ -239,18 +238,18 @@ template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast(
#pragma region Code C-Interface #pragma region Code C-Interface
GEN_API void code_append (Code code, Code other ); void code_append (Code code, Code other );
GEN_API Str code_debug_str (Code code); GEN_API Str code_debug_str (Code code);
GEN_API Code code_duplicate (Code code); GEN_API Code code_duplicate (Code code);
GEN_API Code* code_entry (Code code, u32 idx ); Code* code_entry (Code code, u32 idx );
GEN_API bool code_has_entries (Code code); bool code_has_entries (Code code);
GEN_API bool code_is_body (Code code); bool code_is_body (Code code);
GEN_API bool code_is_equal (Code code, Code other); GEN_API bool code_is_equal (Code code, Code other);
GEN_API bool code_is_valid (Code code); bool code_is_valid (Code code);
GEN_API void code_set_global (Code code); void code_set_global (Code code);
GEN_API StrBuilder code_to_strbuilder (Code self ); GEN_API StrBuilder code_to_strbuilder (Code self );
GEN_API void code_to_strbuilder_ptr(Code self, StrBuilder* result ); GEN_API void code_to_strbuilder_ref(Code self, StrBuilder* result );
GEN_API Str code_type_str (Code self ); Str code_type_str (Code self );
GEN_API bool code_validate_body (Code self ); GEN_API bool code_validate_body (Code self );
#pragma endregion Code C-Interface #pragma endregion Code C-Interface
@ -287,7 +286,7 @@ struct Code
forceinline Code* entry(u32 idx) { return code_entry(* this, idx); } forceinline Code* entry(u32 idx) { return code_entry(* this, idx); }
forceinline bool has_entries() { return code_has_entries(* this); } forceinline bool has_entries() { return code_has_entries(* this); }
forceinline StrBuilder to_strbuilder() { return code_to_strbuilder(* this); } forceinline StrBuilder to_strbuilder() { return code_to_strbuilder(* this); }
forceinline void to_strbuilder(StrBuilder& result) { return code_to_strbuilder_ptr(* this, & result); } forceinline void to_strbuilder(StrBuilder& result) { return code_to_strbuilder_ref(* this, & result); }
forceinline Str type_str() { return code_type_str(* this); } forceinline Str type_str() { return code_type_str(* this); }
forceinline bool validate_body() { return code_validate_body(*this); } forceinline bool validate_body() { return code_validate_body(*this); }
#endif #endif
@ -399,12 +398,13 @@ struct AST
Code Value; // Parameter, Variable Code Value; // Parameter, Variable
}; };
union { union {
Code NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value ) Code NextVar; // Variable
Code SuffixSpecs; // Typename, Function (Thanks Unreal) Code SuffixSpecs; // Typename, Function (Thanks Unreal)
Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal) Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
}; };
}; };
StrCached Content; // Attributes, Comment, Execution, Include StrCached Content; // Attributes, Comment, Execution, Include
TokenSlice ContentToks; // TODO(Ed): Use a token slice for content
struct { struct {
Specifier ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers Specifier ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used. Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
@ -420,7 +420,7 @@ struct AST
Code Next; Code Next;
Code Back; Code Back;
}; };
Token* Token; // Reference to starting token, only available if it was derived from parsing. Token* Token; // Reference to starting token, only available if it was derived from parsing. // TODO(Ed): Change this to a token slice.
Code Parent; Code Parent;
CodeType Type; CodeType Type;
// CodeFlag CodeFlags; // CodeFlag CodeFlags;

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "code_types.hpp" # include "code_types.hpp"
#endif #endif
@ -227,7 +227,7 @@ struct AST_Enum
Code Parent; Code Parent;
CodeType Type; CodeType Type;
ModuleFlag ModuleFlags; ModuleFlag ModuleFlags;
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ]; char _PAD_UNUSED_[ sizeof(u32) ];
}; };
static_assert( sizeof(AST_Enum) == sizeof(AST), "ERROR: AST_Enum is not the same size as AST"); static_assert( sizeof(AST_Enum) == sizeof(AST), "ERROR: AST_Enum is not the same size as AST");
@ -738,8 +738,8 @@ static_assert( sizeof(AST_PreprocessCond) == sizeof(AST), "ERROR: AST_Preprocess
struct AST_Specifiers struct AST_Specifiers
{ {
Specifier ArrSpecs[ AST_ArrSpecs_Cap ]; Specifier ArrSpecs[ AST_ArrSpecs_Cap ];
StrCached Name;
CodeSpecifiers NextSpecs; CodeSpecifiers NextSpecs;
StrCached Name;
Code Prev; Code Prev;
Code Next; Code Next;
Token* Tok; Token* Tok;
@ -1056,7 +1056,7 @@ struct AST_Typename
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
}; };
}; };
StrCached Name; StrCached Name;
Code Prev; Code Prev;
Code Next; Code Next;
Token* Tok; Token* Tok;
@ -1082,7 +1082,7 @@ struct AST_Typedef
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ]; char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
}; };
}; };
StrCached Name; StrCached Name;
Code Prev; Code Prev;
Code Next; Code Next;
Token* Tok; Token* Tok;

View File

@ -1,23 +1,8 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "ast.cpp" #include "ast.cpp"
#endif #endif
inline
StrBuilder attributes_to_strbuilder(CodeAttributes attributes) {
GEN_ASSERT(attributes);
char* raw = ccast(char*, str_duplicate( attributes->Content, _ctx->Allocator_Temp ).Ptr);
StrBuilder result = { raw };
return result;
}
inline
void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result) {
GEN_ASSERT(attributes);
GEN_ASSERT(result);
strbuilder_append_str(result, attributes->Content);
}
StrBuilder body_to_strbuilder(CodeBody body) StrBuilder body_to_strbuilder(CodeBody body)
{ {
GEN_ASSERT(body); GEN_ASSERT(body);
@ -47,55 +32,27 @@ StrBuilder body_to_strbuilder(CodeBody body)
return result; return result;
} }
void body_to_strbuilder_ref( CodeBody body, StrBuilder* result )
{
GEN_ASSERT(body != nullptr);
GEN_ASSERT(result != nullptr);
Code curr = body->Front;
s32 left = body->NumEntries;
while ( left -- )
{
code_to_strbuilder_ptr(curr, result);
// strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) );
++curr;
}
}
void body_to_strbuilder_export( CodeBody body, StrBuilder* result ) void body_to_strbuilder_export( CodeBody body, StrBuilder* result )
{ {
GEN_ASSERT(body != nullptr); GEN_ASSERT(body != nullptr);
GEN_ASSERT(result != nullptr); GEN_ASSERT(result != nullptr);
strbuilder_append_fmt( result, "export\n{\n" ); strbuilder_append_fmt( result, "export\n{\n" );
Code curr = cast(Code, body); Code curr = body->Front;
s32 left = body->NumEntries; s32 left = body->NumEntries;
while ( left-- ) while ( left-- )
{ {
code_to_strbuilder_ptr(curr, result); code_to_strbuilder_ref(curr, result);
// strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) ); // strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) );
++curr; curr = curr->Next;
} }
strbuilder_append_fmt( result, "};\n" ); strbuilder_append_fmt( result, "};\n" );
} }
inline
StrBuilder comment_to_strbuilder(CodeComment comment) {
GEN_ASSERT(comment);
char* raw = ccast(char*, str_duplicate( comment->Content, _ctx->Allocator_Temp ).Ptr);
StrBuilder result = { raw };
return result;
}
inline
void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result) {
GEN_ASSERT(comment);
GEN_ASSERT(result);
strbuilder_append_str(result, comment->Content);
}
StrBuilder constructor_to_strbuilder(CodeConstructor self) StrBuilder constructor_to_strbuilder(CodeConstructor self)
{ {
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
switch (self->Type) switch (self->Type)
{ {
@ -111,6 +68,8 @@ StrBuilder constructor_to_strbuilder(CodeConstructor self)
void constructor_to_strbuilder_def(CodeConstructor self, StrBuilder* result ) void constructor_to_strbuilder_def(CodeConstructor self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
Code ClassStructParent = self->Parent->Parent; Code ClassStructParent = self->Parent->Parent;
if (ClassStructParent) { if (ClassStructParent) {
strbuilder_append_str( result, ClassStructParent->Name ); strbuilder_append_str( result, ClassStructParent->Name );
@ -135,6 +94,8 @@ void constructor_to_strbuilder_def(CodeConstructor self, StrBuilder* result )
void constructor_to_strbuilder_fwd(CodeConstructor self, StrBuilder* result ) void constructor_to_strbuilder_fwd(CodeConstructor self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
Code ClassStructParent = self->Parent->Parent; Code ClassStructParent = self->Parent->Parent;
if (ClassStructParent) { if (ClassStructParent) {
strbuilder_append_str( result, ClassStructParent->Name ); strbuilder_append_str( result, ClassStructParent->Name );
@ -159,6 +120,7 @@ void constructor_to_strbuilder_fwd(CodeConstructor self, StrBuilder* result )
StrBuilder class_to_strbuilder( CodeClass self ) StrBuilder class_to_strbuilder( CodeClass self )
{ {
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
switch ( self->Type ) switch ( self->Type )
{ {
@ -175,6 +137,7 @@ StrBuilder class_to_strbuilder( CodeClass self )
void class_to_strbuilder_def( CodeClass self, StrBuilder* result ) void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -189,7 +152,7 @@ void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
if ( self->Name.Len ) if ( self->Name.Len )
strbuilder_append_str( result, self->Name ); strbuilder_append_str( result, self->Name );
if (self->Specs && specifiers_has(self->Specs, Spec_Final) > -1) if (self->Specs && specifiers_has(self->Specs, Spec_Final))
strbuilder_append_str(result, txt(" final")); strbuilder_append_str(result, txt(" final"));
if ( self->ParentType ) if ( self->ParentType )
@ -222,6 +185,7 @@ void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result ) void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -241,13 +205,6 @@ void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result )
} }
} }
StrBuilder define_to_strbuilder(CodeDefine define)
{
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
define_to_strbuilder_ref(define, & result);
return result;
}
void define_to_strbuilder_ref(CodeDefine define, StrBuilder* result ) void define_to_strbuilder_ref(CodeDefine define, StrBuilder* result )
{ {
GEN_ASSERT(define); GEN_ASSERT(define);
@ -262,14 +219,6 @@ void define_to_strbuilder_ref(CodeDefine define, StrBuilder* result )
} }
} }
StrBuilder define_params_to_strbuilder(CodeDefineParams params)
{
GEN_ASSERT(params);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
define_params_to_strbuilder_ref( params, & result );
return result;
}
void define_params_to_strbuilder_ref(CodeDefineParams self, StrBuilder* result) void define_params_to_strbuilder_ref(CodeDefineParams self, StrBuilder* result)
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
@ -289,6 +238,7 @@ void define_params_to_strbuilder_ref(CodeDefineParams self, StrBuilder* result)
StrBuilder destructor_to_strbuilder(CodeDestructor self) StrBuilder destructor_to_strbuilder(CodeDestructor self)
{ {
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
switch ( self->Type ) switch ( self->Type )
{ {
@ -304,6 +254,8 @@ StrBuilder destructor_to_strbuilder(CodeDestructor self)
void destructor_to_strbuilder_def(CodeDestructor self, StrBuilder* result ) void destructor_to_strbuilder_def(CodeDestructor self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( self->Name.Len ) if ( self->Name.Len )
{ {
strbuilder_append_fmt( result, "%S()", self->Name ); strbuilder_append_fmt( result, "%S()", self->Name );
@ -323,6 +275,8 @@ void destructor_to_strbuilder_def(CodeDestructor self, StrBuilder* result )
void destructor_to_strbuilder_fwd(CodeDestructor self, StrBuilder* result ) void destructor_to_strbuilder_fwd(CodeDestructor self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( self->Specs ) if ( self->Specs )
{ {
if ( specifiers_has(self->Specs, Spec_Virtual ) ) if ( specifiers_has(self->Specs, Spec_Virtual ) )
@ -346,6 +300,7 @@ void destructor_to_strbuilder_fwd(CodeDestructor self, StrBuilder* result )
StrBuilder enum_to_strbuilder(CodeEnum self) StrBuilder enum_to_strbuilder(CodeEnum self)
{ {
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
switch ( self->Type ) switch ( self->Type )
{ {
@ -367,6 +322,8 @@ StrBuilder enum_to_strbuilder(CodeEnum self)
void enum_to_strbuilder_def(CodeEnum self, StrBuilder* result ) void enum_to_strbuilder_def(CodeEnum self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -400,6 +357,8 @@ void enum_to_strbuilder_def(CodeEnum self, StrBuilder* result )
void enum_to_strbuilder_fwd(CodeEnum self, StrBuilder* result ) void enum_to_strbuilder_fwd(CodeEnum self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -427,6 +386,8 @@ void enum_to_strbuilder_fwd(CodeEnum self, StrBuilder* result )
void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result ) void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -459,6 +420,8 @@ void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result )
void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result ) void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -478,56 +441,9 @@ void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result )
} }
} }
StrBuilder exec_to_strbuilder(CodeExec exec)
{
GEN_ASSERT(exec);
char* raw = ccast(char*, str_duplicate( exec->Content, _ctx->Allocator_Temp ).Ptr);
StrBuilder result = { raw };
return result;
}
void extern_to_strbuilder(CodeExtern self, StrBuilder* result )
{
if ( self->Body )
strbuilder_append_fmt( result, "extern \"%S\"\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
else
strbuilder_append_fmt( result, "extern \"%S\"\n{}\n", self->Name );
}
StrBuilder include_to_strbuilder(CodeInclude include)
{
return strbuilder_fmt_buf( _ctx->Allocator_Temp, "#include %S\n", include->Content );
}
void include_to_strbuilder_ref( CodeInclude include, StrBuilder* result )
{
strbuilder_append_fmt( result, "#include %S\n", include->Content );
}
StrBuilder friend_to_strbuilder(CodeFriend self)
{
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
friend_to_strbuilder_ref( self, & result );
return result;
}
void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result )
{
strbuilder_append_fmt( result, "friend %SB", code_to_strbuilder(self->Declaration) );
if ( self->Declaration->Type != CT_Function && self->Declaration->Type != CT_Operator && (* result)[ strbuilder_length(* result) - 1 ] != ';' )
{
strbuilder_append_str( result, txt(";") );
}
if ( self->InlineCmt )
strbuilder_append_fmt( result, " %S", self->InlineCmt->Content );
else
strbuilder_append_str( result, txt("\n"));
}
StrBuilder fn_to_strbuilder(CodeFn self) StrBuilder fn_to_strbuilder(CodeFn self)
{ {
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
switch ( self->Type ) switch ( self->Type )
{ {
@ -543,6 +459,8 @@ StrBuilder fn_to_strbuilder(CodeFn self)
void fn_to_strbuilder_def(CodeFn self, StrBuilder* result ) void fn_to_strbuilder_def(CodeFn self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export") ); strbuilder_append_str( result, txt("export") );
@ -600,6 +518,8 @@ void fn_to_strbuilder_def(CodeFn self, StrBuilder* result )
void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result ) void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -649,9 +569,9 @@ void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result )
} }
} }
if ( specifiers_has(self->Specs, Spec_Pure ) >= 0 ) if ( specifiers_has(self->Specs, Spec_Pure ) )
strbuilder_append_str( result, txt(" = 0") ); strbuilder_append_str( result, txt(" = 0") );
else if ( specifiers_has(self->Specs, Spec_Delete ) >= 0 ) else if ( specifiers_has(self->Specs, Spec_Delete ) )
strbuilder_append_str( result, txt(" = delete") ); strbuilder_append_str( result, txt(" = delete") );
} }
@ -668,15 +588,10 @@ void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result )
strbuilder_append_str( result, txt(";\n") ); strbuilder_append_str( result, txt(";\n") );
} }
StrBuilder module_to_strbuilder(CodeModule self)
{
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 64 );
module_to_strbuilder_ref( self, & result );
return result;
}
void module_to_strbuilder_ref(CodeModule self, StrBuilder* result ) void module_to_strbuilder_ref(CodeModule self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if (((scast(u32, ModuleFlag_Export) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Export))) if (((scast(u32, ModuleFlag_Export) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Export)))
strbuilder_append_str( result, txt("export ")); strbuilder_append_str( result, txt("export "));
@ -686,23 +601,9 @@ void module_to_strbuilder_ref(CodeModule self, StrBuilder* result )
strbuilder_append_fmt( result, "%S;\n", self->Name ); strbuilder_append_fmt( result, "%S;\n", self->Name );
} }
StrBuilder namespace_to_strbuilder(CodeNS self)
{
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
namespace_to_strbuilder_ref( self, & result );
return result;
}
void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result )
{
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") );
strbuilder_append_fmt( result, "namespace %S\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
}
StrBuilder code_op_to_strbuilder(CodeOperator self) StrBuilder code_op_to_strbuilder(CodeOperator self)
{ {
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
switch ( self->Type ) switch ( self->Type )
{ {
@ -720,6 +621,8 @@ StrBuilder code_op_to_strbuilder(CodeOperator self)
void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result ) void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -774,6 +677,8 @@ void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result )
void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result ) void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -825,6 +730,7 @@ void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result )
StrBuilder opcast_to_strbuilder(CodeOpCast self) StrBuilder opcast_to_strbuilder(CodeOpCast self)
{ {
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
switch ( self->Type ) switch ( self->Type )
{ {
@ -840,6 +746,8 @@ StrBuilder opcast_to_strbuilder(CodeOpCast self)
void opcast_to_strbuilder_def(CodeOpCast self, StrBuilder* result ) void opcast_to_strbuilder_def(CodeOpCast self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) ) for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
@ -877,6 +785,8 @@ void opcast_to_strbuilder_def(CodeOpCast self, StrBuilder* result )
void opcast_to_strbuilder_fwd(CodeOpCast self, StrBuilder* result ) void opcast_to_strbuilder_fwd(CodeOpCast self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) ) for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
@ -912,14 +822,6 @@ void opcast_to_strbuilder_fwd(CodeOpCast self, StrBuilder* result )
strbuilder_append_fmt( result, "operator %SB();\n", typename_to_strbuilder(self->ValueType) ); strbuilder_append_fmt( result, "operator %SB();\n", typename_to_strbuilder(self->ValueType) );
} }
StrBuilder params_to_strbuilder(CodeParams self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
params_to_strbuilder_ref( self, & result );
return result;
}
void params_to_strbuilder_ref( CodeParams self, StrBuilder* result ) void params_to_strbuilder_ref( CodeParams self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
@ -987,62 +889,6 @@ StrBuilder preprocess_to_strbuilder(CodePreprocessCond self)
return result; return result;
} }
void preprocess_to_strbuilder_if(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
strbuilder_append_fmt( result, "#if %S", cond->Content );
}
void preprocess_to_strbuilder_ifdef(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
strbuilder_append_fmt( result, "#ifdef %S\n", cond->Content );
}
void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
strbuilder_append_fmt( result, "#ifndef %S", cond->Content );
}
void preprocess_to_strbuilder_elif(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
strbuilder_append_fmt( result, "#elif %S\n", cond->Content );
}
void preprocess_to_strbuilder_else(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
strbuilder_append_str( result, txt("#else\n") );
}
void preprocess_to_strbuilder_endif(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
strbuilder_append_str( result, txt("#endif\n") );
}
StrBuilder pragma_to_strbuilder(CodePragma self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
pragma_to_strbuilder_ref( self, & result );
return result;
}
void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result )
{
strbuilder_append_fmt( result, "#pragma %S\n", self->Content );
}
StrBuilder specifiers_to_strbuilder(CodeSpecifiers self)
{
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 64 );
specifiers_to_strbuilder_ref( self, & result );
return result;
}
void specifiers_to_strbuilder_ref( CodeSpecifiers self, StrBuilder* result ) void specifiers_to_strbuilder_ref( CodeSpecifiers self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
@ -1155,14 +1001,6 @@ void struct_to_strbuilder_fwd( CodeStruct self, StrBuilder* result )
} }
} }
StrBuilder template_to_strbuilder(CodeTemplate self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 1024 );
template_to_strbuilder_ref( self, & result );
return result;
}
void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result ) void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
@ -1176,15 +1014,10 @@ void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result )
strbuilder_append_fmt( result, "template<>\n%SB", code_to_strbuilder(self->Declaration) ); strbuilder_append_fmt( result, "template<>\n%SB", code_to_strbuilder(self->Declaration) );
} }
StrBuilder typedef_to_strbuilder(CodeTypedef self)
{
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
typedef_to_strbuilder_ref( self, & result );
return result;
}
void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result ) void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -1218,15 +1051,10 @@ void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result )
strbuilder_append_str( result, txt("\n")); strbuilder_append_str( result, txt("\n"));
} }
StrBuilder typename_to_strbuilder(CodeTypename self)
{
StrBuilder result = strbuilder_make_str( _ctx->Allocator_Temp, txt("") );
typename_to_strbuilder_ref( self, & result );
return result;
}
void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result ) void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
#if defined(GEN_USE_NEW_TYPENAME_PARSING) #if defined(GEN_USE_NEW_TYPENAME_PARSING)
if ( self->ReturnType && self->Params ) if ( self->ReturnType && self->Params )
{ {
@ -1283,6 +1111,7 @@ void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result )
StrBuilder union_to_strbuilder(CodeUnion self) StrBuilder union_to_strbuilder(CodeUnion self)
{ {
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
switch ( self->Type ) switch ( self->Type )
{ {
@ -1298,6 +1127,8 @@ StrBuilder union_to_strbuilder(CodeUnion self)
void union_to_strbuilder_def(CodeUnion self, StrBuilder* result ) void union_to_strbuilder_def(CodeUnion self, StrBuilder* result )
{ {
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
@ -1346,22 +1177,6 @@ void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result )
strbuilder_append_str( result, txt(";\n")); strbuilder_append_str( result, txt(";\n"));
} }
StrBuilder using_to_strbuilder(CodeUsing self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
switch ( self->Type )
{
case CT_Using:
using_to_strbuilder_ref( self, & result );
break;
case CT_Using_Namespace:
using_to_strbuilder_ns( self, & result );
break;
}
return result;
}
void using_to_strbuilder_ref(CodeUsing self, StrBuilder* result ) void using_to_strbuilder_ref(CodeUsing self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
@ -1399,26 +1214,6 @@ void using_to_strbuilder_ref(CodeUsing self, StrBuilder* result )
strbuilder_append_str( result, txt("\n")); strbuilder_append_str( result, txt("\n"));
} }
inline
void using_to_strbuilder_ns(CodeUsing self, StrBuilder* result )
{
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( self->InlineCmt )
strbuilder_append_fmt( result, "using namespace $SC; %S", self->Name, self->InlineCmt->Content );
else
strbuilder_append_fmt( result, "using namespace %S;\n", self->Name );
}
inline
StrBuilder var_to_strbuilder(CodeVar self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
var_to_strbuilder_ref( self, & result );
return result;
}
neverinline neverinline
void var_to_strbuilder_ref(CodeVar self, StrBuilder* result ) void var_to_strbuilder_ref(CodeVar self, StrBuilder* result )
{ {

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "ast.hpp" #include "ast.hpp"
#endif #endif
@ -20,58 +20,59 @@
GEN_API void body_append ( CodeBody body, Code other ); GEN_API void body_append ( CodeBody body, Code other );
GEN_API void body_append_body ( CodeBody body, CodeBody other ); GEN_API void body_append_body ( CodeBody body, CodeBody other );
GEN_API StrBuilder body_to_strbuilder ( CodeBody body ); GEN_API StrBuilder body_to_strbuilder ( CodeBody body );
GEN_API void body_to_strbuilder_ref ( CodeBody body, StrBuilder* result ); void body_to_strbuilder_ref ( CodeBody body, StrBuilder* result );
GEN_API void body_to_strbuilder_export( CodeBody body, StrBuilder* result ); GEN_API void body_to_strbuilder_export( CodeBody body, StrBuilder* result );
GEN_API Code begin_CodeBody( CodeBody body); Code begin_CodeBody( CodeBody body);
GEN_API Code end_CodeBody ( CodeBody body ); Code end_CodeBody ( CodeBody body );
GEN_API Code next_CodeBody ( CodeBody body, Code entry_iter ); Code next_CodeBody ( CodeBody body, Code entry_iter );
GEN_API void class_add_interface ( CodeClass self, CodeTypename interface ); void class_add_interface ( CodeClass self, CodeTypename interface );
GEN_API StrBuilder class_to_strbuilder ( CodeClass self ); GEN_API StrBuilder class_to_strbuilder ( CodeClass self );
GEN_API void class_to_strbuilder_def( CodeClass self, StrBuilder* result ); GEN_API void class_to_strbuilder_def( CodeClass self, StrBuilder* result );
GEN_API void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result ); GEN_API void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result );
GEN_API void define_params_append (CodeDefineParams appendee, CodeDefineParams other ); void define_params_append (CodeDefineParams appendee, CodeDefineParams other );
GEN_API CodeDefineParams define_params_get (CodeDefineParams params, s32 idx); CodeDefineParams define_params_get (CodeDefineParams params, s32 idx);
GEN_API bool define_params_has_entries (CodeDefineParams params ); bool define_params_has_entries (CodeDefineParams params );
GEN_API StrBuilder define_params_to_strbuilder (CodeDefineParams params ); StrBuilder define_params_to_strbuilder (CodeDefineParams params );
GEN_API void define_params_to_strbuilder_ref(CodeDefineParams params, StrBuilder* result ); GEN_API void define_params_to_strbuilder_ref(CodeDefineParams params, StrBuilder* result );
GEN_API CodeDefineParams begin_CodeDefineParams(CodeDefineParams params); CodeDefineParams begin_CodeDefineParams(CodeDefineParams params);
GEN_API CodeDefineParams end_CodeDefineParams (CodeDefineParams params); CodeDefineParams end_CodeDefineParams (CodeDefineParams params);
GEN_API CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter); CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter);
GEN_API void params_append (CodeParams appendee, CodeParams other ); void params_append (CodeParams appendee, CodeParams other );
GEN_API CodeParams params_get (CodeParams params, s32 idx); CodeParams params_get (CodeParams params, s32 idx);
GEN_API bool params_has_entries (CodeParams params ); bool params_has_entries (CodeParams params );
GEN_API StrBuilder params_to_strbuilder (CodeParams params ); StrBuilder params_to_strbuilder (CodeParams params );
GEN_API void params_to_strbuilder_ref(CodeParams params, StrBuilder* result ); GEN_API void params_to_strbuilder_ref(CodeParams params, StrBuilder* result );
GEN_API CodeParams begin_CodeParams(CodeParams params); CodeParams begin_CodeParams(CodeParams params);
GEN_API CodeParams end_CodeParams (CodeParams params); CodeParams end_CodeParams (CodeParams params);
GEN_API CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter); CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter);
GEN_API bool specifiers_append (CodeSpecifiers specifiers, Specifier spec); bool specifiers_append (CodeSpecifiers specifiers, Specifier spec);
GEN_API s32 specifiers_has (CodeSpecifiers specifiers, Specifier spec); bool specifiers_has (CodeSpecifiers specifiers, Specifier spec);
GEN_API s32 specifiers_remove (CodeSpecifiers specifiers, Specifier to_remove ); s32 specifiers_index_of (CodeSpecifiers specifiers, Specifier spec);
GEN_API StrBuilder specifiers_to_strbuilder (CodeSpecifiers specifiers); s32 specifiers_remove (CodeSpecifiers specifiers, Specifier to_remove );
StrBuilder specifiers_to_strbuilder (CodeSpecifiers specifiers);
GEN_API void specifiers_to_strbuilder_ref(CodeSpecifiers specifiers, StrBuilder* result); GEN_API void specifiers_to_strbuilder_ref(CodeSpecifiers specifiers, StrBuilder* result);
GEN_API Specifier* begin_CodeSpecifiers(CodeSpecifiers specifiers); Specifier* begin_CodeSpecifiers(CodeSpecifiers specifiers);
GEN_API Specifier* end_CodeSpecifiers (CodeSpecifiers specifiers); Specifier* end_CodeSpecifiers (CodeSpecifiers specifiers);
GEN_API Specifier* next_CodeSpecifiers (CodeSpecifiers specifiers, Specifier* spec_iter); Specifier* next_CodeSpecifiers (CodeSpecifiers specifiers, Specifier* spec_iter);
GEN_API void struct_add_interface (CodeStruct self, CodeTypename interface); void struct_add_interface (CodeStruct self, CodeTypename interface);
GEN_API StrBuilder struct_to_strbuilder (CodeStruct self); GEN_API StrBuilder struct_to_strbuilder (CodeStruct self);
GEN_API void struct_to_strbuilder_fwd(CodeStruct self, StrBuilder* result); GEN_API void struct_to_strbuilder_fwd(CodeStruct self, StrBuilder* result);
GEN_API void struct_to_strbuilder_def(CodeStruct self, StrBuilder* result); GEN_API void struct_to_strbuilder_def(CodeStruct self, StrBuilder* result);
GEN_API StrBuilder attributes_to_strbuilder (CodeAttributes attributes); StrBuilder attributes_to_strbuilder (CodeAttributes attributes);
GEN_API void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result); void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result);
GEN_API StrBuilder comment_to_strbuilder (CodeComment comment ); StrBuilder comment_to_strbuilder (CodeComment comment );
GEN_API void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result ); void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result );
GEN_API StrBuilder constructor_to_strbuilder (CodeConstructor constructor); GEN_API StrBuilder constructor_to_strbuilder (CodeConstructor constructor);
GEN_API void constructor_to_strbuilder_def(CodeConstructor constructor, StrBuilder* result ); GEN_API void constructor_to_strbuilder_def(CodeConstructor constructor, StrBuilder* result );
@ -90,66 +91,68 @@ GEN_API void enum_to_strbuilder_fwd (CodeEnum self, StrBuilder* resul
GEN_API void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result ); GEN_API void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result );
GEN_API void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result ); GEN_API void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result );
GEN_API StrBuilder exec_to_strbuilder (CodeExec exec); StrBuilder exec_to_strbuilder (CodeExec exec);
GEN_API void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result); void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result);
GEN_API void extern_to_strbuilder(CodeExtern self, StrBuilder* result); void extern_to_strbuilder(CodeExtern self, StrBuilder* result);
GEN_API StrBuilder include_to_strbuilder (CodeInclude self); StrBuilder include_to_strbuilder (CodeInclude self);
GEN_API void include_to_strbuilder_ref(CodeInclude self, StrBuilder* result); void include_to_strbuilder_ref(CodeInclude self, StrBuilder* result);
GEN_API StrBuilder friend_to_strbuilder (CodeFriend self); StrBuilder friend_to_strbuilder (CodeFriend self);
GEN_API void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result); void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result);
GEN_API StrBuilder fn_to_strbuilder (CodeFn self); GEN_API StrBuilder fn_to_strbuilder (CodeFn self);
GEN_API void fn_to_strbuilder_def(CodeFn self, StrBuilder* result); GEN_API void fn_to_strbuilder_def(CodeFn self, StrBuilder* result);
GEN_API void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result); GEN_API void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result);
GEN_API StrBuilder module_to_strbuilder (CodeModule self); StrBuilder module_to_strbuilder (CodeModule self);
GEN_API void module_to_strbuilder_ref(CodeModule self, StrBuilder* result); GEN_API void module_to_strbuilder_ref(CodeModule self, StrBuilder* result);
GEN_API StrBuilder namespace_to_strbuilder (CodeNS self); StrBuilder namespace_to_strbuilder (CodeNS self);
GEN_API void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result); void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result);
GEN_API StrBuilder code_op_to_strbuilder (CodeOperator self); GEN_API StrBuilder code_op_to_strbuilder (CodeOperator self);
GEN_API void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result ); GEN_API void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result );
GEN_API void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result ); GEN_API void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result );
GEN_API StrBuilder opcast_to_strbuilder (CodeOpCast op_cast ); GEN_API StrBuilder opcast_to_strbuilder (CodeOpCast op_cast );
GEN_API void opcast_to_strbuilder_def(CodeOpCast op_cast, StrBuilder* result ); GEN_API void opcast_to_strbuilder_def(CodeOpCast op_cast, StrBuilder* result );
GEN_API void opcast_to_strbuilder_fwd(CodeOpCast op_cast, StrBuilder* result ); GEN_API void opcast_to_strbuilder_fwd(CodeOpCast op_cast, StrBuilder* result );
GEN_API StrBuilder pragma_to_strbuilder (CodePragma self); StrBuilder pragma_to_strbuilder (CodePragma self);
GEN_API void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result); void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result);
GEN_API StrBuilder preprocess_to_strbuilder (CodePreprocessCond cond); GEN_API StrBuilder preprocess_to_strbuilder (CodePreprocessCond cond);
GEN_API void preprocess_to_strbuilder_if (CodePreprocessCond cond, StrBuilder* result ); void preprocess_to_strbuilder_if (CodePreprocessCond cond, StrBuilder* result );
GEN_API void preprocess_to_strbuilder_ifdef (CodePreprocessCond cond, StrBuilder* result ); void preprocess_to_strbuilder_ifdef (CodePreprocessCond cond, StrBuilder* result );
GEN_API void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result ); void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result );
GEN_API void preprocess_to_strbuilder_elif (CodePreprocessCond cond, StrBuilder* result ); void preprocess_to_strbuilder_elif (CodePreprocessCond cond, StrBuilder* result );
GEN_API void preprocess_to_strbuilder_else (CodePreprocessCond cond, StrBuilder* result ); void preprocess_to_strbuilder_else (CodePreprocessCond cond, StrBuilder* result );
GEN_API void preprocess_to_strbuilder_endif (CodePreprocessCond cond, StrBuilder* result ); void preprocess_to_strbuilder_endif (CodePreprocessCond cond, StrBuilder* result );
GEN_API StrBuilder template_to_strbuilder (CodeTemplate self); StrBuilder template_to_strbuilder (CodeTemplate self);
GEN_API void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result); GEN_API void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result);
GEN_API StrBuilder typename_to_strbuilder (CodeTypename self); StrBuilder typedef_to_strbuilder (CodeTypedef self);
GEN_API void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result);
GEN_API StrBuilder typedef_to_strbuilder (CodeTypedef self);
GEN_API void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result ); GEN_API void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result );
StrBuilder typename_to_strbuilder (CodeTypename self);
GEN_API void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result);
GEN_API StrBuilder union_to_strbuilder (CodeUnion self); GEN_API StrBuilder union_to_strbuilder (CodeUnion self);
GEN_API void union_to_strbuilder_def(CodeUnion self, StrBuilder* result); GEN_API void union_to_strbuilder_def(CodeUnion self, StrBuilder* result);
GEN_API void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result); GEN_API void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result);
GEN_API StrBuilder using_to_strbuilder (CodeUsing op_cast ); StrBuilder using_to_strbuilder (CodeUsing op_cast );
GEN_API void using_to_strbuilder_ref(CodeUsing op_cast, StrBuilder* result ); GEN_API void using_to_strbuilder_ref(CodeUsing op_cast, StrBuilder* result );
GEN_API void using_to_strbuilder_ns (CodeUsing op_cast, StrBuilder* result ); void using_to_strbuilder_ns (CodeUsing op_cast, StrBuilder* result );
GEN_API StrBuilder var_to_strbuilder (CodeVar self); StrBuilder var_to_strbuilder (CodeVar self);
GEN_API void var_to_strbuilder_ref(CodeVar self, StrBuilder* result); GEN_API void var_to_strbuilder_ref(CodeVar self, StrBuilder* result);
// TODO(Ed): Move C-Interface inlines here...
#pragma endregion Code Type C-Interface #pragma endregion Code Type C-Interface
#if GEN_COMPILER_CPP #if GEN_COMPILER_CPP
@ -250,6 +253,7 @@ struct CodeSpecifiers
Using_Code( CodeSpecifiers ); Using_Code( CodeSpecifiers );
bool append( Specifier spec ) { return specifiers_append(* this, spec); } bool append( Specifier spec ) { return specifiers_append(* this, spec); }
s32 has( Specifier spec ) { return specifiers_has(* this, spec); } s32 has( Specifier spec ) { return specifiers_has(* this, spec); }
s32 index_of( Specifier spec ) { return specifiers_index_of(* this, spec); }
s32 remove( Specifier to_remove ) { return specifiers_remove(* this, to_remove); } s32 remove( Specifier to_remove ) { return specifiers_remove(* this, to_remove); }
StrBuilder to_strbuilder() { return specifiers_to_strbuilder(* this ); } StrBuilder to_strbuilder() { return specifiers_to_strbuilder(* this ); }
void to_strbuilder( StrBuilder& result ) { return specifiers_to_strbuilder_ref(* this, & result); } void to_strbuilder( StrBuilder& result ) { return specifiers_to_strbuilder_ref(* this, & result); }

View File

@ -0,0 +1,85 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "interface.hpp"
#endif
#pragma region Constants
// Predefined typename codes. Are set to readonly and are setup during gen::init()
GEN_API extern Macro enum_underlying_macro;
GEN_API extern Code access_public;
GEN_API extern Code access_protected;
GEN_API extern Code access_private;
GEN_API extern CodeAttributes attrib_api_export;
GEN_API extern CodeAttributes attrib_api_import;
GEN_API extern Code module_global_fragment;
GEN_API extern Code module_private_fragment;
GEN_API extern Code fmt_newline;
GEN_API extern CodePragma pragma_once;
GEN_API extern CodeParams param_varadic;
GEN_API extern CodePreprocessCond preprocess_else;
GEN_API extern CodePreprocessCond preprocess_endif;
GEN_API extern CodeSpecifiers spec_const;
GEN_API extern CodeSpecifiers spec_consteval;
GEN_API extern CodeSpecifiers spec_constexpr;
GEN_API extern CodeSpecifiers spec_constinit;
GEN_API extern CodeSpecifiers spec_extern_linkage;
GEN_API extern CodeSpecifiers spec_final;
GEN_API extern CodeSpecifiers spec_forceinline;
GEN_API extern CodeSpecifiers spec_global;
GEN_API extern CodeSpecifiers spec_inline;
GEN_API extern CodeSpecifiers spec_internal_linkage;
GEN_API extern CodeSpecifiers spec_local_persist;
GEN_API extern CodeSpecifiers spec_mutable;
GEN_API extern CodeSpecifiers spec_neverinline;
GEN_API extern CodeSpecifiers spec_noexcept;
GEN_API extern CodeSpecifiers spec_override;
GEN_API extern CodeSpecifiers spec_ptr;
GEN_API extern CodeSpecifiers spec_pure;
GEN_API extern CodeSpecifiers spec_ref;
GEN_API extern CodeSpecifiers spec_register;
GEN_API extern CodeSpecifiers spec_rvalue;
GEN_API extern CodeSpecifiers spec_static_member;
GEN_API extern CodeSpecifiers spec_thread_local;
GEN_API extern CodeSpecifiers spec_virtual;
GEN_API extern CodeSpecifiers spec_volatile;
GEN_API extern CodeTypename t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
GEN_API extern CodeTypename t_auto;
GEN_API extern CodeTypename t_void;
GEN_API extern CodeTypename t_int;
GEN_API extern CodeTypename t_bool;
GEN_API extern CodeTypename t_char;
GEN_API extern CodeTypename t_wchar_t;
GEN_API extern CodeTypename t_class;
GEN_API extern CodeTypename t_typename;
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
GEN_API extern CodeTypename t_b32;
GEN_API extern CodeTypename t_s8;
GEN_API extern CodeTypename t_s16;
GEN_API extern CodeTypename t_s32;
GEN_API extern CodeTypename t_s64;
GEN_API extern CodeTypename t_u8;
GEN_API extern CodeTypename t_u16;
GEN_API extern CodeTypename t_u32;
GEN_API extern CodeTypename t_u64;
GEN_API extern CodeTypename t_ssize;
GEN_API extern CodeTypename t_usize;
GEN_API extern CodeTypename t_f32;
GEN_API extern CodeTypename t_f64;
#endif
#pragma endregion Constants

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "components/types.hpp" #include "components/types.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "components/types.hpp" #include "components/types.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "components/types.hpp" #include "components/types.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "components/types.hpp" #include "components/types.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "components/types.hpp" #include "components/types.hpp"
#endif #endif

View File

@ -1,88 +0,0 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "inlines.hpp"
#include "gen/ast_inlines.hpp"
#endif
#pragma region Constants
GEN_API extern Macro enum_underlying_macro;
GEN_API extern Code access_public;
GEN_API extern Code access_protected;
GEN_API extern Code access_private;
GEN_API extern CodeAttributes attrib_api_export;
GEN_API extern CodeAttributes attrib_api_import;
GEN_API extern Code module_global_fragment;
GEN_API extern Code module_private_fragment;
GEN_API extern Code fmt_newline;
GEN_API extern CodePragma pragma_once;
GEN_API extern CodeParams param_varadic;
GEN_API extern CodePreprocessCond preprocess_else;
GEN_API extern CodePreprocessCond preprocess_endif;
GEN_API extern CodeSpecifiers spec_const;
GEN_API extern CodeSpecifiers spec_consteval;
GEN_API extern CodeSpecifiers spec_constexpr;
GEN_API extern CodeSpecifiers spec_constinit;
GEN_API extern CodeSpecifiers spec_extern_linkage;
GEN_API extern CodeSpecifiers spec_final;
GEN_API extern CodeSpecifiers spec_forceinline;
GEN_API extern CodeSpecifiers spec_global;
GEN_API extern CodeSpecifiers spec_inline;
GEN_API extern CodeSpecifiers spec_internal_linkage;
GEN_API extern CodeSpecifiers spec_local_persist;
GEN_API extern CodeSpecifiers spec_mutable;
GEN_API extern CodeSpecifiers spec_neverinline;
GEN_API extern CodeSpecifiers spec_noexcept;
GEN_API extern CodeSpecifiers spec_override;
GEN_API extern CodeSpecifiers spec_ptr;
GEN_API extern CodeSpecifiers spec_pure;
GEN_API extern CodeSpecifiers spec_ref;
GEN_API extern CodeSpecifiers spec_register;
GEN_API extern CodeSpecifiers spec_rvalue;
GEN_API extern CodeSpecifiers spec_static_member;
GEN_API extern CodeSpecifiers spec_thread_local;
GEN_API extern CodeSpecifiers spec_virtual;
GEN_API extern CodeSpecifiers spec_volatile;
GEN_API extern CodeTypename t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
GEN_API extern CodeTypename t_auto;
GEN_API extern CodeTypename t_void;
GEN_API extern CodeTypename t_int;
GEN_API extern CodeTypename t_bool;
GEN_API extern CodeTypename t_char;
GEN_API extern CodeTypename t_wchar_t;
GEN_API extern CodeTypename t_class;
GEN_API extern CodeTypename t_typename;
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
// Predefined typename codes. Are set to readonly and are setup during gen::init()
GEN_API extern Context* _ctx;
GEN_API extern CodeTypename t_b32;
GEN_API extern CodeTypename t_s8;
GEN_API extern CodeTypename t_s16;
GEN_API extern CodeTypename t_s32;
GEN_API extern CodeTypename t_s64;
GEN_API extern CodeTypename t_u8;
GEN_API extern CodeTypename t_u16;
GEN_API extern CodeTypename t_u32;
GEN_API extern CodeTypename t_u64;
GEN_API extern CodeTypename t_ssize;
GEN_API extern CodeTypename t_usize;
GEN_API extern CodeTypename t_f32;
GEN_API extern CodeTypename t_f64;
#endif
#pragma endregion Constants

View File

@ -15,7 +15,7 @@
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l | | \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
| | | | | __} | | | | | | | __} | |
| l_l l_l {___/ | | l_l l_l {___/ |
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha | ! ----------------------------------------------------------------------- VERSION: v0.25-Alpha |
! ============================================================================================ | ! ============================================================================================ |
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION | ! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL | ! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |

View File

@ -1,8 +1,318 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "interface.hpp" #include "constants.hpp"
#endif #endif
#pragma region Serialization
inline
StrBuilder attributes_to_strbuilder(CodeAttributes attributes) {
GEN_ASSERT(attributes);
char* raw = ccast(char*, str_duplicate( attributes->Content, get_context()->Allocator_Temp ).Ptr);
StrBuilder result = { raw };
return result;
}
inline
void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result) {
GEN_ASSERT(attributes);
GEN_ASSERT(result);
strbuilder_append_str(result, attributes->Content);
}
inline
StrBuilder comment_to_strbuilder(CodeComment comment) {
GEN_ASSERT(comment);
char* raw = ccast(char*, str_duplicate( comment->Content, get_context()->Allocator_Temp ).Ptr);
StrBuilder result = { raw };
return result;
}
inline
void body_to_strbuilder_ref( CodeBody body, StrBuilder* result )
{
GEN_ASSERT(body != nullptr);
GEN_ASSERT(result != nullptr);
Code curr = body->Front;
s32 left = body->NumEntries;
while ( left -- )
{
code_to_strbuilder_ref(curr, result);
// strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) );
curr = curr->Next;
}
}
inline
void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result) {
GEN_ASSERT(comment);
GEN_ASSERT(result);
strbuilder_append_str(result, comment->Content);
}
inline
StrBuilder define_to_strbuilder(CodeDefine define)
{
GEN_ASSERT(define);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
define_to_strbuilder_ref(define, & result);
return result;
}
inline
StrBuilder define_params_to_strbuilder(CodeDefineParams params)
{
GEN_ASSERT(params);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
define_params_to_strbuilder_ref( params, & result );
return result;
}
inline
StrBuilder exec_to_strbuilder(CodeExec exec)
{
GEN_ASSERT(exec);
char* raw = ccast(char*, str_duplicate( exec->Content, _ctx->Allocator_Temp ).Ptr);
StrBuilder result = { raw };
return result;
}
inline
void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result) {
GEN_ASSERT(exec);
GEN_ASSERT(result);
strbuilder_append_str(result, exec->Content);
}
inline
void extern_to_strbuilder(CodeExtern self, StrBuilder* result )
{
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( self->Body )
strbuilder_append_fmt( result, "extern \"%S\"\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
else
strbuilder_append_fmt( result, "extern \"%S\"\n{}\n", self->Name );
}
inline
StrBuilder friend_to_strbuilder(CodeFriend self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
friend_to_strbuilder_ref( self, & result );
return result;
}
inline
void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result )
{
GEN_ASSERT(self);
GEN_ASSERT(result);
strbuilder_append_fmt( result, "friend %SB", code_to_strbuilder(self->Declaration) );
if ( self->Declaration->Type != CT_Function && self->Declaration->Type != CT_Operator && (* result)[ strbuilder_length(* result) - 1 ] != ';' )
{
strbuilder_append_str( result, txt(";") );
}
if ( self->InlineCmt )
strbuilder_append_fmt( result, " %S", self->InlineCmt->Content );
else
strbuilder_append_str( result, txt("\n"));
}
inline
StrBuilder include_to_strbuilder(CodeInclude include)
{
GEN_ASSERT(include);
return strbuilder_fmt_buf( _ctx->Allocator_Temp, "#include %S\n", include->Content );
}
inline
void include_to_strbuilder_ref( CodeInclude include, StrBuilder* result )
{
GEN_ASSERT(include);
GEN_ASSERT(result);
strbuilder_append_fmt( result, "#include %S\n", include->Content );
}
inline
StrBuilder module_to_strbuilder(CodeModule self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 64 );
module_to_strbuilder_ref( self, & result );
return result;
}
inline
StrBuilder namespace_to_strbuilder(CodeNS self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
namespace_to_strbuilder_ref( self, & result );
return result;
}
inline
void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result )
{
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") );
strbuilder_append_fmt( result, "namespace %S\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
}
inline
StrBuilder params_to_strbuilder(CodeParams self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
params_to_strbuilder_ref( self, & result );
return result;
}
inline
StrBuilder pragma_to_strbuilder(CodePragma self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
pragma_to_strbuilder_ref( self, & result );
return result;
}
inline
void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result )
{
GEN_ASSERT(self);
GEN_ASSERT(result);
strbuilder_append_fmt( result, "#pragma %S\n", self->Content );
}
inline
void preprocess_to_strbuilder_if(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
GEN_ASSERT(result);
strbuilder_append_fmt( result, "#if %S", cond->Content );
}
inline
void preprocess_to_strbuilder_ifdef(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
GEN_ASSERT(result);
strbuilder_append_fmt( result, "#ifdef %S\n", cond->Content );
}
inline
void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
GEN_ASSERT(result);
strbuilder_append_fmt( result, "#ifndef %S", cond->Content );
}
inline
void preprocess_to_strbuilder_elif(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
GEN_ASSERT(result);
strbuilder_append_fmt( result, "#elif %S\n", cond->Content );
}
inline
void preprocess_to_strbuilder_else(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
GEN_ASSERT(result);
strbuilder_append_str( result, txt("#else\n") );
}
inline
void preprocess_to_strbuilder_endif(CodePreprocessCond cond, StrBuilder* result )
{
GEN_ASSERT(cond);
GEN_ASSERT(result);
strbuilder_append_str( result, txt("#endif\n") );
}
inline
StrBuilder specifiers_to_strbuilder(CodeSpecifiers self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 64 );
specifiers_to_strbuilder_ref( self, & result );
return result;
}
inline
StrBuilder template_to_strbuilder(CodeTemplate self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 1024 );
template_to_strbuilder_ref( self, & result );
return result;
}
inline
StrBuilder typedef_to_strbuilder(CodeTypedef self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
typedef_to_strbuilder_ref( self, & result );
return result;
}
inline
StrBuilder typename_to_strbuilder(CodeTypename self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_str( _ctx->Allocator_Temp, txt("") );
typename_to_strbuilder_ref( self, & result );
return result;
}
inline
StrBuilder using_to_strbuilder(CodeUsing self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
switch ( self->Type )
{
case CT_Using:
using_to_strbuilder_ref( self, & result );
break;
case CT_Using_Namespace:
using_to_strbuilder_ns( self, & result );
break;
}
return result;
}
inline
void using_to_strbuilder_ns(CodeUsing self, StrBuilder* result )
{
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( self->InlineCmt )
strbuilder_append_fmt( result, "using namespace $S; %S", self->Name, self->InlineCmt->Content );
else
strbuilder_append_fmt( result, "using namespace %S;\n", self->Name );
}
inline
StrBuilder var_to_strbuilder(CodeVar self)
{
GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( get_context()->Allocator_Temp, 256 );
var_to_strbuilder_ref( self, & result );
return result;
}
#pragma endregion Serialization
#pragma region Code #pragma region Code
inline inline
void code_append( Code self, Code other ) void code_append( Code self, Code other )
@ -74,7 +384,7 @@ bool code_is_valid(Code self)
return self != nullptr && self->Type != CT_Invalid; return self != nullptr && self->Type != CT_Invalid;
} }
forceinline forceinline
bool code_has_entries(AST* self) bool code_has_entries(Code self)
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
return self->NumEntries > 0; return self->NumEntries > 0;
@ -169,12 +479,12 @@ void class_add_interface( CodeClass self, CodeTypename type )
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly. // then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
} }
while ( possible_slot != nullptr ) while ( possible_slot->Next != nullptr )
{ {
possible_slot = cast(CodeTypename, possible_slot->Next); possible_slot = cast(CodeTypename, possible_slot->Next);
} }
possible_slot = type; possible_slot->Next = cast(Code, type);
} }
#pragma endregion CodeClass #pragma endregion CodeClass
@ -296,7 +606,17 @@ bool specifiers_append(CodeSpecifiers self, Specifier spec )
return true; return true;
} }
inline inline
s32 specifiers_has(CodeSpecifiers self, Specifier spec) bool specifiers_has(CodeSpecifiers self, Specifier spec)
{
GEN_ASSERT(self != nullptr);
for ( s32 idx = 0; idx < self->NumEntries; idx++ ) {
if ( self->ArrSpecs[ idx ] == spec )
return true;
}
return false;
}
inline
s32 specifiers_index_of(CodeSpecifiers self, Specifier spec)
{ {
GEN_ASSERT(self != nullptr); GEN_ASSERT(self != nullptr);
for ( s32 idx = 0; idx < self->NumEntries; idx++ ) { for ( s32 idx = 0; idx < self->NumEntries; idx++ ) {
@ -378,12 +698,12 @@ void struct_add_interface(CodeStruct self, CodeTypename type )
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly. // then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
} }
while ( possible_slot != nullptr ) while ( possible_slot->Next != nullptr )
{ {
possible_slot = cast(CodeTypename, possible_slot->Next); possible_slot = cast(CodeTypename, possible_slot->Next);
} }
possible_slot = type; possible_slot->Next = cast(Code, type);
} }
#pragma endregion Code #pragma endregion Code

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "code_serialization.cpp" #include "code_serialization.cpp"
#endif #endif
@ -71,6 +71,14 @@ void* fallback_allocator_proc( void* allocator_data, AllocType type, ssize size,
return nullptr; return nullptr;
} }
internal
void fallback_logger(LogEntry entry)
{
GEN_ASSERT(entry.msg.Len > 0);
GEN_ASSERT(entry.msg.Ptr);
log_fmt("%S: %S", loglevel_to_str(entry.level), entry.msg);
}
internal internal
void define_constants() void define_constants()
{ {
@ -283,6 +291,19 @@ void init(Context* ctx)
ctx->InitSize_Fallback_Allocator_Bucket_Size = megabytes(8); ctx->InitSize_Fallback_Allocator_Bucket_Size = megabytes(8);
} }
if (ctx->InitSize_StrCacheTable == 0)
{
ctx->InitSize_StrCacheTable = kilobytes(8);
}
if (ctx->InitSize_MacrosTable == 0)
{
ctx->InitSize_MacrosTable = kilobytes(8);
}
if (ctx->Logger == nullptr) {
ctx->Logger = & fallback_logger;
}
// Override the current context (user has to put it back if unwanted). // Override the current context (user has to put it back if unwanted).
_ctx = ctx; _ctx = ctx;
@ -298,7 +319,7 @@ void init(Context* ctx)
} }
// Setup the code pool and code entries arena. // Setup the code pool and code entries arena.
{ {
Pool code_pool = pool_init( ctx->Allocator_Pool, ctx->CodePool_NumBlocks, sizeof(AST) ); Pool code_pool = pool_init( ctx->Allocator_Pool, ctx->CodePool_NumBlocks, size_of(AST) );
if ( code_pool.PhysicalStart == nullptr ) if ( code_pool.PhysicalStart == nullptr )
GEN_FATAL( "gen::init: Failed to initialize the code pool" ); GEN_FATAL( "gen::init: Failed to initialize the code pool" );
array_append( ctx->CodePools, code_pool ); array_append( ctx->CodePools, code_pool );
@ -311,11 +332,11 @@ void init(Context* ctx)
} }
// Setup the hash tables // Setup the hash tables
{ {
ctx->StrCache = hashtable_init(StrCached, ctx->Allocator_DyanmicContainers); ctx->StrCache = hashtable_init_reserve(StrCached, ctx->Allocator_DyanmicContainers, ctx->InitSize_StrCacheTable);
if ( ctx->StrCache.Entries == nullptr ) if ( ctx->StrCache.Entries == nullptr )
GEN_FATAL( "gen::init: Failed to initialize the StringCache"); GEN_FATAL( "gen::init: Failed to initialize the StringCache");
ctx->Macros = hashtable_init(Macro, ctx->Allocator_DyanmicContainers); ctx->Macros = hashtable_init_reserve(Macro, ctx->Allocator_DyanmicContainers, ctx->InitSize_MacrosTable);
if (ctx->Macros.Hashes == nullptr || ctx->Macros.Entries == nullptr) { if (ctx->Macros.Hashes == nullptr || ctx->Macros.Entries == nullptr) {
GEN_FATAL( "gen::init: Failed to initialize the PreprocessMacros table" ); GEN_FATAL( "gen::init: Failed to initialize the PreprocessMacros table" );
} }

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "ast_types.hpp" #include "ast_types.hpp"
#endif #endif
@ -15,23 +15,37 @@
\▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓
*/ */
#if 0 enum LogLevel //: u32
enum LogLevel : u32
{ {
Info, LL_Null,
Warning, LL_Note,
Panic, LL_Warning,
LL_Error,
LL_Fatal,
LL_UnderlyingType = GEN_U32_MAX,
}; };
typedef enum LogLevel LogLevel;
Str loglevel_to_str(LogLevel level)
{
local_persist
Str lookup[] = {
{ "Null", sizeof("Null") - 1 },
{ "Note", sizeof("Note") - 1 },
{ "Warning", sizeof("Info") - 1 },
{ "Error", sizeof("Error") - 1 },
{ "Fatal", sizeof("Fatal") - 1 },
};
return lookup[level];
}
struct LogEntry struct LogEntry
{ {
Str msg; Str msg;
u32 line_num; LogLevel level;
void* data;
}; };
typedef void LoggerCallback(LogEntry entry); typedef void LoggerProc(LogEntry entry);
#endif
// Note(Ed): This is subject to heavily change // Note(Ed): This is subject to heavily change
// with upcoming changes to the library's fallback (default) allocations strategy; // with upcoming changes to the library's fallback (default) allocations strategy;
@ -64,9 +78,16 @@ struct Context
u32 InitSize_LexerTokens; u32 InitSize_LexerTokens;
u32 SizePer_StringArena; u32 SizePer_StringArena;
u32 InitSize_StrCacheTable;
u32 InitSize_MacrosTable;
// TODO(Ed): Symbol Table // TODO(Ed): Symbol Table
// Keep track of all resolved symbols (naemspaced identifiers) // Keep track of all resolved symbols (naemspaced identifiers)
// Logging
LoggerProc* Logger;
// Parser // Parser
// Used by the lexer to persistently treat all these identifiers as preprocessor defines. // Used by the lexer to persistently treat all these identifiers as preprocessor defines.
@ -99,6 +120,50 @@ struct Context
s32 temp_serialize_indent; s32 temp_serialize_indent;
}; };
// TODO(Ed): Eventually this library should opt out of an implicit context for baseline implementation
// This would automatically make it viable for multi-threaded purposes among other things
// An implicit context interface will be provided instead as wrapper procedures as convience.
GEN_API extern Context* _ctx;
// By default this library will either crash or exit if an error is detected while generating codes.
// Even if set to not use GEN_FATAL, GEN_FATAL will still be used for memory failures as the library is unusable when they occur.
#ifdef GEN_DONT_USE_FATAL
#define log_failure log_fmt
#else
#define log_failure GEN_FATAL
#endif
// TODO(Ed): Swap all usage of this with logger_fmt (then rename logger_fmt to log_fmt)
inline
ssize log_fmt(char const* fmt, ...)
{
ssize res;
va_list va;
va_start(va, fmt);
res = c_str_fmt_out_va(fmt, va);
va_end(va);
return res;
}
inline
void logger_fmt(Context* ctx, LogLevel level, char const* fmt, ...)
{
local_persist thread_local
PrintF_Buffer buf = struct_zero(PrintF_Buffer);
va_list va;
va_start(va, fmt);
ssize res = c_str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va) -1;
va_end(va);
StrBuilder msg = strbuilder_make_length(ctx->Allocator_Temp, buf, res);
LogEntry entry = { strbuilder_to_str(msg), level };
ctx->Logger(entry);
}
// Initialize the library. There first ctx initialized must exist for lifetime of other contextes that come after as its the one that // Initialize the library. There first ctx initialized must exist for lifetime of other contextes that come after as its the one that
GEN_API void init(Context* ctx); GEN_API void init(Context* ctx);
@ -109,7 +174,7 @@ GEN_API void deinit(Context* ctx);
// Retrieves the active context (not usually needed, but here in case...) // Retrieves the active context (not usually needed, but here in case...)
GEN_API Context* get_context(); GEN_API Context* get_context();
// Clears the allocations, but doesn't free the memoery, then calls init() again. // Clears the allocations, but doesn't free the memory, then calls init() again.
// Ease of use. // Ease of use.
GEN_API void reset(Context* ctx); GEN_API void reset(Context* ctx);
@ -194,7 +259,7 @@ GEN_API CodeEnum def_enum( Str name, Opts_def_enum opts GEN_PARAM_DEFAULT );
GEN_API CodeExec def_execution ( Str content ); GEN_API CodeExec def_execution ( Str content );
GEN_API CodeExtern def_extern_link( Str name, CodeBody body ); GEN_API CodeExtern def_extern_link( Str name, CodeBody body );
GEN_API CodeFriend def_friend ( Code symbol ); GEN_API CodeFriend def_friend ( Code code );
struct Opts_def_function { struct Opts_def_function {
CodeParams params; CodeParams params;
@ -230,7 +295,7 @@ struct Opts_def_operator_cast {
GEN_API CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT ); GEN_API CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
struct Opts_def_param { Code value; }; struct Opts_def_param { Code value; };
GEN_API CodeParams def_param ( CodeTypename type, Str name, Opts_def_param opts GEN_PARAM_DEFAULT ); GEN_API CodeParams def_param ( CodeTypename type, Str name, Opts_def_param opts GEN_PARAM_DEFAULT );
GEN_API CodePragma def_pragma( Str directive ); GEN_API CodePragma def_pragma( Str directive );
GEN_API CodePreprocessCond def_preprocess_cond( EPreprocessCond type, Str content ); GEN_API CodePreprocessCond def_preprocess_cond( EPreprocessCond type, Str content );
@ -244,7 +309,7 @@ GEN_API CodeTemplate def_template( CodeParams params, Code definition, Opts_def_
struct Opts_def_type { struct Opts_def_type {
ETypenameTag type_tag; ETypenameTag type_tag;
Code arrayexpr; Code array_expr;
CodeSpecifiers specifiers; CodeSpecifiers specifiers;
CodeAttributes attributes; CodeAttributes attributes;
}; };
@ -280,7 +345,7 @@ struct Opts_def_variable
GEN_API CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opts GEN_PARAM_DEFAULT ); GEN_API CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opts GEN_PARAM_DEFAULT );
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries. // Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
GEN_API CodeBody def_body( CodeType type ); CodeBody def_body( CodeType type );
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num, // There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
/// or provide as an array of Code objects. /// or provide as an array of Code objects.
@ -329,37 +394,42 @@ forceinline CodeBody def_union_body ( s32 num, Code* codes )
#pragma region Parsing #pragma region Parsing
#if 0 struct ParseStackNode
struct StackNode
{ {
StackNode* Prev; ParseStackNode* Prev;
Token Start; TokenSlice Tokens;
Token Name; // The name of the AST node (if parsed) Token* Start;
Str FailedProc; // The name of the procedure that failed Str Name; // The name of the AST node (if parsed)
Str ProcName; // The name of the procedure
Code CodeRel; // Relevant AST node
// TODO(Ed): When an error occurs, the parse stack is not released and instead the scope is left dangling.
}; };
// Stack nodes are allocated the error's allocator
struct Error typedef struct ParseMessage ParseMessage;
struct ParseMessage
{ {
StrBuilder message; ParseMessage* Next;
StackNode* context_stack; ParseStackNode* Scope;
Str Log;
LogLevel Level;
}; };
struct ParseInfo struct ParseInfo
{ {
Arena FileMem; ParseMessage* messages;
Arena TokMem; LexedInfo lexed;
Arena CodeMem; Code result;
FileContents FileContent;
Array<Token> Tokens;
Array<Error> Errors;
// Errors are allocated to a dedicated general arena.
}; };
CodeBody parse_file( Str path ); struct ParseOpts
#endif {
AllocatorInfo backing_msgs;
AllocatorInfo backing_tokens;
AllocatorInfo backing_ast;
};
ParseInfo wip_parse_str( LexedInfo lexed, ParseOpts* opts GEN_PARAM_DEFAULT );
GEN_API CodeClass parse_class ( Str class_def ); GEN_API CodeClass parse_class ( Str class_def );
GEN_API CodeConstructor parse_constructor ( Str constructor_def ); GEN_API CodeConstructor parse_constructor ( Str constructor_def );
@ -388,11 +458,12 @@ GEN_API CodeVar parse_variable ( Str var_def );
GEN_API ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va ); GEN_API ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va );
//! Do not use directly. Use the token_fmt macro instead. //! Do not use directly. Use the token_fmt macro instead.
GEN_API Str token_fmt_impl( ssize, ... ); Str token_fmt_impl( ssize, ... );
GEN_API Code untyped_str( Str content); GEN_API Code untyped_str ( Str content);
GEN_API Code untyped_fmt ( char const* fmt, ... ); GEN_API Code untyped_fmt ( char const* fmt, ... );
GEN_API Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... ); GEN_API Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
GEN_API Code untyped_toks ( TokenSlice tokens );
#pragma endregion Untyped text #pragma endregion Untyped text

View File

@ -1,6 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "gen/etoktype.cpp" #include "gen/etoktype.hpp"
#include "interface.upfront.cpp" #include "interface.upfront.cpp"
#include "lexer.cpp" #include "lexer.cpp"
#include "parser.cpp" #include "parser.cpp"
@ -8,6 +8,29 @@
// Publically Exposed Interface // Publically Exposed Interface
ParseInfo wip_parse_str(LexedInfo lexed, ParseOpts* opts)
{
TokArray toks;
if (lexed.tokens.Num == 0 && lexed.tokens.Ptr == nullptr) {
check_parse_args(lexed.text);
toks = lex(lexed.text);
TokenSlice slice = { toks.Arr, scast(s32, array_num(toks.Arr)) };
lexed.tokens = slice;
}
ParseInfo info = struct_zero(ParseInfo);
info.lexed = lexed;
// TODO(Ed): ParseInfo should be set to the parser context.
_ctx->parser.Tokens = toks;
push_scope();
CodeBody result = parse_global_nspace(CT_Global_Body);
parser_pop(& _ctx->parser);
return info;
}
CodeClass parse_class( Str def ) CodeClass parse_class( Str def )
{ {
check_parse_args( def ); check_parse_args( def );

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "interface.parsing.cpp" #include "interface.parsing.cpp"
#endif #endif
@ -176,3 +176,16 @@ Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... )
return result; return result;
} }
Code untyped_toks( TokenSlice tokens )
{
if ( tokens.Num == 0 ) {
log_failure( "untyped_toks: empty token slice" );
return InvalidCode;
}
Code
result = make_code();
result->Type = CT_Untyped;
result->ContentToks = tokens;
return result;
}

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "interface.cpp" #include "interface.cpp"
#endif #endif
@ -473,8 +473,10 @@ CodeComment def_comment( Str content )
return (CodeComment) result; return (CodeComment) result;
} }
CodeConstructor def_constructor( Opts_def_constructor p ) CodeConstructor def_constructor( Opts_def_constructor opt )
{ {
Opts_def_constructor p = get_optional(opt);
if ( p.params && p.params->Type != CT_Parameters ) { if ( p.params && p.params->Type != CT_Parameters ) {
log_failure("gen::def_constructor: params must be of Parameters type - %s", code_debug_str((Code)p.params)); log_failure("gen::def_constructor: params must be of Parameters type - %s", code_debug_str((Code)p.params));
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
@ -510,8 +512,10 @@ CodeConstructor def_constructor( Opts_def_constructor p )
return result; return result;
} }
CodeClass def_class( Str name, Opts_def_struct p ) CodeClass def_class( Str name, Opts_def_struct opt )
{ {
Opts_def_struct p = get_optional(opt);
if ( ! name_check( def_class, name ) ) { if ( ! name_check( def_class, name ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -561,8 +565,10 @@ CodeClass def_class( Str name, Opts_def_struct p )
return result; return result;
} }
CodeDefine def_define( Str name, MacroType type, Opts_def_define p ) CodeDefine def_define( Str name, MacroType type, Opts_def_define opt )
{ {
Opts_def_define p = get_optional(opt);
if ( ! name_check( def_define, name ) ) { if ( ! name_check( def_define, name ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -585,8 +591,10 @@ CodeDefine def_define( Str name, MacroType type, Opts_def_define p )
return result; return result;
} }
CodeDestructor def_destructor( Opts_def_destructor p ) CodeDestructor def_destructor( Opts_def_destructor opt )
{ {
Opts_def_destructor p = get_optional(opt);
if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) { if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) {
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", code_debug_str(p.specifiers) ); log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", code_debug_str(p.specifiers) );
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
@ -619,8 +627,10 @@ CodeDestructor def_destructor( Opts_def_destructor p )
return result; return result;
} }
CodeEnum def_enum( Str name, Opts_def_enum p ) CodeEnum def_enum( Str name, Opts_def_enum opt )
{ {
Opts_def_enum p = get_optional(opt);
if ( ! name_check( def_enum, name ) ) { if ( ! name_check( def_enum, name ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -742,8 +752,10 @@ CodeFriend def_friend( Code declaration )
return result; return result;
} }
CodeFn def_function( Str name, Opts_def_function p ) CodeFn def_function( Str name, Opts_def_function opt )
{ {
Opts_def_function p = get_optional(opt);
if ( ! name_check( def_function, name )) { if ( ! name_check( def_function, name )) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -802,8 +814,10 @@ CodeFn def_function( Str name, Opts_def_function p )
return result; return result;
} }
CodeInclude def_include( Str path, Opts_def_include p ) CodeInclude def_include( Str path, Opts_def_include opt )
{ {
Opts_def_include p = get_optional(opt);
if ( path.Len <= 0 || path.Ptr == nullptr ) { if ( path.Len <= 0 || path.Ptr == nullptr ) {
log_failure( "gen::def_include: Invalid path provided - %d" ); log_failure( "gen::def_include: Invalid path provided - %d" );
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
@ -821,8 +835,10 @@ CodeInclude def_include( Str path, Opts_def_include p )
return result; return result;
} }
CodeModule def_module( Str name, Opts_def_module p ) CodeModule def_module( Str name, Opts_def_module opt )
{ {
Opts_def_module p = get_optional(opt);
if ( ! name_check( def_module, name )) { if ( ! name_check( def_module, name )) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -835,8 +851,10 @@ CodeModule def_module( Str name, Opts_def_module p )
return result; return result;
} }
CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace p ) CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace opt )
{ {
Opts_def_namespace p = get_optional(opt);
if ( ! name_check( def_namespace, name )) { if ( ! name_check( def_namespace, name )) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -859,8 +877,10 @@ CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace p )
return result; return result;
} }
CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator p ) CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator opt )
{ {
Opts_def_operator p = get_optional(opt);
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", code_debug_str(p.attributes) ); log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", code_debug_str(p.attributes) );
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
@ -926,8 +946,10 @@ CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator p )
return result; return result;
} }
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p ) CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opt )
{ {
Opts_def_operator_cast p = get_optional(opt);
if ( ! null_check( def_operator_cast, type )) { if ( ! null_check( def_operator_cast, type )) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -959,8 +981,10 @@ CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
return result; return result;
} }
CodeParams def_param( CodeTypename type, Str name, Opts_def_param p ) CodeParams def_param( CodeTypename type, Str name, Opts_def_param opt )
{ {
Opts_def_param p = get_optional(opt);
if ( ! name_check( def_param, name ) || ! null_check( def_param, type ) ) { if ( ! name_check( def_param, name ) || ! null_check( def_param, type ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -1034,8 +1058,10 @@ CodeSpecifiers def_specifier( Specifier spec )
return result; return result;
} }
CodeStruct def_struct( Str name, Opts_def_struct p ) CodeStruct def_struct( Str name, Opts_def_struct opt )
{ {
Opts_def_struct p = get_optional(opt);
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", code_debug_str(cast(Code, p.attributes)) ); log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", code_debug_str(cast(Code, p.attributes)) );
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
@ -1076,8 +1102,10 @@ CodeStruct def_struct( Str name, Opts_def_struct p )
return result; return result;
} }
CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_template p ) CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_template opt )
{ {
Opts_def_template p = get_optional(opt);
if ( ! null_check( def_template, declaration ) ) { if ( ! null_check( def_template, declaration ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -1108,13 +1136,15 @@ CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_templat
return result; return result;
} }
CodeTypename def_type( Str name, Opts_def_type p ) CodeTypename def_type( Str name, Opts_def_type opt )
{ {
Opts_def_type p = get_optional(opt);
if ( ! name_check( def_type, name )) { if ( ! name_check( def_type, name )) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
} }
Code arrayexpr = p.arrayexpr; Code array_expr = p.array_expr;
CodeSpecifiers specifiers = p.specifiers; CodeSpecifiers specifiers = p.specifiers;
CodeAttributes attributes = p.attributes; CodeAttributes attributes = p.attributes;
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
@ -1127,8 +1157,8 @@ CodeTypename def_type( Str name, Opts_def_type p )
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
} }
if ( p.arrayexpr && p.arrayexpr->Type != CT_Untyped ) { if ( p.array_expr && p.array_expr->Type != CT_Untyped ) {
log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", code_debug_str((Code)p.arrayexpr) ); log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", code_debug_str((Code)p.array_expr) );
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
} }
@ -1138,13 +1168,15 @@ CodeTypename def_type( Str name, Opts_def_type p )
result->Type = CT_Typename; result->Type = CT_Typename;
result->Attributes = p.attributes; result->Attributes = p.attributes;
result->Specs = p.specifiers; result->Specs = p.specifiers;
result->ArrExpr = p.arrayexpr; result->ArrExpr = p.array_expr;
result->TypeTag = p.type_tag; result->TypeTag = p.type_tag;
return result; return result;
} }
CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef p ) CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef opt )
{ {
Opts_def_typedef p = get_optional(opt);
if ( ! null_check( def_typedef, type ) ) { if ( ! null_check( def_typedef, type ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -1206,8 +1238,10 @@ CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef p )
return result; return result;
} }
CodeUnion def_union( Str name, CodeBody body, Opts_def_union p ) CodeUnion def_union( Str name, CodeBody body, Opts_def_union opt )
{ {
Opts_def_union p = get_optional(opt);
if ( ! null_check( def_union, body ) ) { if ( ! null_check( def_union, body ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -1233,8 +1267,10 @@ CodeUnion def_union( Str name, CodeBody body, Opts_def_union p )
return result; return result;
} }
CodeUsing def_using( Str name, CodeTypename type, Opts_def_using p ) CodeUsing def_using( Str name, CodeTypename type, Opts_def_using opt )
{ {
Opts_def_using p = get_optional(opt);
if ( ! name_check( def_using, name ) || null_check( def_using, type ) ) { if ( ! name_check( def_using, name ) || null_check( def_using, type ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
@ -1274,8 +1310,10 @@ CodeUsing def_using_namespace( Str name )
return result; return result;
} }
CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable p ) CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opt )
{ {
Opts_def_variable p = get_optional(opt);
if ( ! name_check( def_variable, name ) || ! null_check( def_variable, type ) ) { if ( ! name_check( def_variable, name ) || ! null_check( def_variable, type ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;

View File

@ -1,7 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "interface.upfront.cpp" #include "interface.upfront.cpp"
#include "gen/etoktype.cpp" #include "gen/etoktype.hpp"
#endif #endif
StrBuilder tok_to_strbuilder(Token tok) StrBuilder tok_to_strbuilder(Token tok)
@ -488,6 +488,10 @@ void lex_found_token( LexContext* ctx )
TokType type = str_to_toktype( ctx->token.Text ); TokType type = str_to_toktype( ctx->token.Text );
if (type == Tok_Preprocess_Define || type == Tok_Preprocess_Include) {
ctx->token.Flags |= TF_Identifier;
}
if (type <= Tok_Access_Public && type >= Tok_Access_Private ) { if (type <= Tok_Access_Public && type >= Tok_Access_Private ) {
ctx->token.Flags |= TF_AccessSpecifier; ctx->token.Flags |= TF_AccessSpecifier;
} }
@ -560,9 +564,12 @@ void lex_found_token( LexContext* ctx )
array_append( _ctx->Lexer_Tokens, ctx->token ); array_append( _ctx->Lexer_Tokens, ctx->token );
} }
// TODO(Ed): We should dynamically allocate the lexer's array in Allocator_DyanmicContainers.
// TODO(Ed): We need to to attempt to recover from a lex failure? // TODO(Ed): We need to to attempt to recover from a lex failure?
neverinline neverinline
// TokArray lex( Array<Token> tokens, Str content ) // void lex( Array<Token> tokens, Str content )
TokArray lex( Str content ) TokArray lex( Str content )
{ {
LexContext c; LexContext* ctx = & c; LexContext c; LexContext* ctx = & c;

View File

@ -1,6 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "gen/etoktype.cpp" #include "gen/etoktype.hpp"
#include "parser_case_macros.cpp" #include "parser_case_macros.cpp"
#include "interface.upfront.cpp" #include "interface.upfront.cpp"
#include "lexer.cpp" #include "lexer.cpp"
@ -11,7 +11,7 @@
constexpr bool lex_dont_skip_formatting = false; constexpr bool lex_dont_skip_formatting = false;
constexpr bool lex_skip_formatting = true; constexpr bool lex_skip_formatting = true;
void parser_push( ParseContext* ctx, StackNode* node ) void parser_push( ParseContext* ctx, ParseStackNode* node )
{ {
node->Prev = ctx->Scope; node->Prev = ctx->Scope;
ctx->Scope = node; ctx->Scope = node;
@ -60,7 +60,7 @@ StrBuilder parser_to_strbuilder(ParseContext ctx)
else else
strbuilder_append_fmt(& result, "\t(%d, %d)\n", last_valid.Line, last_valid.Column ); strbuilder_append_fmt(& result, "\t(%d, %d)\n", last_valid.Line, last_valid.Column );
StackNode* curr_scope = ctx.Scope; ParseStackNode* curr_scope = ctx.Scope;
s32 level = 0; s32 level = 0;
do do
{ {
@ -181,16 +181,17 @@ bool _check_parse_args( Str def, char const* func_name )
# define check_noskip( Type_ ) ( left && currtok_noskip.Type == Type_ ) # define check_noskip( Type_ ) ( left && currtok_noskip.Type == Type_ )
# define check( Type_ ) ( left && currtok.Type == Type_ ) # define check( Type_ ) ( left && currtok.Type == Type_ )
# define push_scope() \ // TODO(Ed): Don't do this anymore, we need a better initializer.
Str null_name = {}; \ # define push_scope() \
StackNode scope = { nullptr, lex_current( & _ctx->parser.Tokens, lex_dont_skip_formatting ), null_name, txt( __func__ ) }; \ Str null_name = {}; \
ParseStackNode scope = { nullptr, {nullptr, 0}, lex_current( & _ctx->parser.Tokens, lex_dont_skip_formatting ), null_name, txt( __func__ ), { nullptr} }; \
parser_push( & _ctx->parser, & scope ) parser_push( & _ctx->parser, & scope )
#pragma endregion Helper Macros #pragma endregion Helper Macros
// Procedure Forwards ( Entire parser internal parser interface ) // Procedure Forwards ( Entire parser internal parser interface )
internal Code parse_array_decl (); internal Code parse_array_decl (ParseContext* ctx);
internal CodeAttributes parse_attributes (); internal CodeAttributes parse_attributes ();
internal CodeComment parse_comment (); internal CodeComment parse_comment ();
internal Code parse_complicated_definition ( TokType which ); internal Code parse_complicated_definition ( TokType which );
@ -490,8 +491,15 @@ StrBuilder parser_strip_formatting( Str raw_text, bool preserve_newlines )
return content; return content;
} }
StrBuilder parser_strip_formatting_2(TokenSlice tokens)
{
// TODO(Ed): Use this to produce strings for validation purposes. We shouldn't serialize down from tokens once we start storing token slices for content.
StrBuilder result = struct_zero(StrBuilder);
return result;
}
internal internal
Code parse_array_decl() Code parse_array_decl(ParseContext* ctx)
{ {
push_scope(); push_scope();
@ -524,16 +532,20 @@ Code parse_array_decl()
return InvalidCode; return InvalidCode;
} }
TokenSlice tokens = { & currtok, 1 };
Token untyped_tok = currtok; Token untyped_tok = currtok;
while ( left && currtok.Type != Tok_BraceSquare_Close ) while ( left && currtok.Type != Tok_BraceSquare_Close )
{ {
eat( currtok.Type ); eat( currtok.Type );
++ tokens.Num;
} }
untyped_tok.Text.Len = ( (sptr)prevtok.Text.Ptr + prevtok.Text.Len ) - (sptr)untyped_tok.Text.Ptr; // untyped_tok.Text.Len = ( (sptr)prevtok.Text.Ptr + prevtok.Text.Len ) - (sptr)untyped_tok.Text.Ptr;
untyped_tok.Text = token_range_to_str(untyped_tok, prevtok);
Code array_expr = untyped_str( untyped_tok.Text ); Code array_expr = untyped_str( untyped_tok.Text );
// Code array_expr = untyped_toks( tokens ); // TODO(Ed): Use token slice instead of untyped strings.
// [ <Content> // [ <Content>
if ( left == 0 ) if ( left == 0 )
@ -556,7 +568,7 @@ Code parse_array_decl()
// Its a multi-dimensional array // Its a multi-dimensional array
if ( check( Tok_BraceSquare_Open )) if ( check( Tok_BraceSquare_Open ))
{ {
Code adjacent_arr_expr = parse_array_decl(); Code adjacent_arr_expr = parse_array_decl(ctx);
// [ <Content> ][ <Content> ]... // [ <Content> ][ <Content> ]...
array_expr->Next = adjacent_arr_expr; array_expr->Next = adjacent_arr_expr;
@ -1365,8 +1377,10 @@ Code parse_assignment_expression()
eat( currtok.Type ); eat( currtok.Type );
} }
expr_tok.Text.Len = ( ( sptr )currtok.Text.Ptr + currtok.Text.Len ) - ( sptr )expr_tok.Text.Ptr - 1; if (left) {
expr = untyped_str( expr_tok.Text ); expr_tok.Text.Len = ( ( sptr )currtok.Text.Ptr + currtok.Text.Len ) - ( sptr )expr_tok.Text.Ptr - 1;
}
expr = untyped_str( expr_tok.Text );
// = <Expression> // = <Expression>
return expr; return expr;
} }
@ -1441,6 +1455,22 @@ CodeFn parse_function_after_name(
} }
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers> // <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers>
// Check for trailing specifiers...
CodeAttributes post_rt_attributes = parse_attributes();
if (post_rt_attributes)
{
if (attributes)
{
StrBuilder merged = strbuilder_fmt_buf(_ctx->Allocator_Temp, "%S %S", attributes->Content, post_rt_attributes->Content);
attributes->Content = cache_str(strbuilder_to_str(merged));
}
else
{
attributes = post_rt_attributes;
}
}
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers> <Attributes>
CodeBody body = NullCode; CodeBody body = NullCode;
CodeComment inline_cmt = NullCode; CodeComment inline_cmt = NullCode;
if ( check( Tok_BraceCurly_Open ) ) if ( check( Tok_BraceCurly_Open ) )
@ -1479,17 +1509,19 @@ CodeFn parse_function_after_name(
if ( currtok_noskip.Type == Tok_Comment && currtok_noskip.Line == stmt_end.Line ) if ( currtok_noskip.Type == Tok_Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment(); inline_cmt = parse_comment();
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers>; <InlineCmt> // <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers> < = 0 or delete > ; <InlineCmt>
} }
else
if (body == nullptr)
{ {
Token stmt_end = currtok; Token stmt_end = currtok;
eat( Tok_Statement_End ); eat( Tok_Statement_End );
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers>; // <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers> <Attributes> < = 0 or delete > ;
if ( currtok_noskip.Type == Tok_Comment && currtok_noskip.Line == stmt_end.Line ) if ( currtok_noskip.Type == Tok_Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment(); inline_cmt = parse_comment();
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers>; <InlineCmt> // <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers> < = 0 or delete > ; <InlineCmt>
} }
StrBuilder StrBuilder
@ -1764,7 +1796,7 @@ CodeBody parse_global_nspace( CodeType which )
case Tok_Preprocess_Macro_Expr: case Tok_Preprocess_Macro_Expr:
{ {
if (tok_is_attribute(currtok)) if ( ! tok_is_attribute(currtok))
{ {
log_failure("Unbounded macro expression residing in class/struct body\n%S", parser_to_strbuilder(_ctx->parser)); log_failure("Unbounded macro expression residing in class/struct body\n%S", parser_to_strbuilder(_ctx->parser));
return InvalidCode; return InvalidCode;
@ -2047,11 +2079,20 @@ Token parse_identifier( bool* possible_member_function )
Macro* macro = lookup_macro(currtok.Text); Macro* macro = lookup_macro(currtok.Text);
b32 accept_as_identifier = macro && bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Identifier ); b32 accept_as_identifier = macro && bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Identifier );
b32 is_decarator = macro && bitfield_is_set(MacroFlags, macro->Flags, MF_Identifier_Decorator );
// Typename can be: '::' <name> // Typename can be: '::' <name>
// If that is the case first option will be Tok_Access_StaticSymbol below // If that is the case first option will be Tok_Access_StaticSymbol below
if (check(Tok_Identifier) || accept_as_identifier) if (check(Tok_Identifier) || accept_as_identifier)
eat( Tok_Identifier ); {
if (is_decarator) {
Code name_macro = parse_simple_preprocess(currtok.Type);
name.Text.Len = ( ( sptr )prevtok.Text.Ptr + prevtok.Text.Len ) - ( sptr )name.Text.Ptr;
}
else {
eat(Tok_Identifier);
}
}
// <Name> // <Name>
parse_template_args( & name ); parse_template_args( & name );
@ -2361,7 +2402,10 @@ CodeOperator parse_operator_after_ret_type(
case '(': case '(':
{ {
if ( currtok.Text.Ptr[1] == ')' ) if ( currtok.Text.Ptr[1] == ')' )
{
op = Op_FunctionCall; op = Op_FunctionCall;
eat(Tok_Paren_Open);
}
else else
op = Op_Invalid; op = Op_Invalid;
@ -2788,10 +2832,10 @@ CodeParams parse_params( bool use_template_capture )
} }
// ( <Macro> <ValueType> // ( <Macro> <ValueType>
if ( check( Tok_Identifier ) ) if ( check( Tok_Identifier ) || bitfield_is_set(u32, currtok.Flags, TF_Identifier) )
{ {
name = currtok; name = currtok;
eat( Tok_Identifier ); eat( currtok.Type );
// ( <Macro> <ValueType> <Name> // ( <Macro> <ValueType> <Name>
} }
@ -2899,10 +2943,10 @@ CodeParams parse_params( bool use_template_capture )
name = NullToken; name = NullToken;
if ( check( Tok_Identifier ) ) if ( check( Tok_Identifier ) || bitfield_is_set(u32, currtok.Flags, TF_Identifier) )
{ {
name = currtok; name = currtok;
eat( Tok_Identifier ); eat( currtok.Type );
// ( <Macro> <ValueType> <Name> = <Expression>, <Macro> <ValueType> <Name> // ( <Macro> <ValueType> <Name> = <Expression>, <Macro> <ValueType> <Name>
} }
@ -3258,7 +3302,7 @@ CodeVar parse_variable_after_name(
{ {
push_scope(); push_scope();
Code array_expr = parse_array_decl(); Code array_expr = parse_array_decl(& _ctx->parser);
Code expr = NullCode; Code expr = NullCode;
Code bitfield_expr = NullCode; Code bitfield_expr = NullCode;
@ -4712,21 +4756,37 @@ CodeTypename parser_parse_type( bool from_template, bool* typedef_is_function )
else if ( currtok.Type == Tok_Decl_Class || currtok.Type == Tok_Decl_Enum || currtok.Type == Tok_Decl_Struct else if ( currtok.Type == Tok_Decl_Class || currtok.Type == Tok_Decl_Enum || currtok.Type == Tok_Decl_Struct
|| currtok.Type == Tok_Decl_Union ) || currtok.Type == Tok_Decl_Union )
{ {
switch (currtok.Type) { Token next = nexttok;
case Tok_Decl_Class : tag = Tag_Class; break;
case Tok_Decl_Enum : tag = Tag_Enum; break; if (next.Type == Tok_Identifier)
case Tok_Decl_Struct : tag = Tag_Struct; break; {
case Tok_Decl_Union : tag = Tag_Union; break; switch (currtok.Type) {
default: case Tok_Decl_Class : tag = Tag_Class; break;
break; case Tok_Decl_Enum : tag = Tag_Enum; break;
case Tok_Decl_Struct : tag = Tag_Struct; break;
case Tok_Decl_Union : tag = Tag_Union; break;
default:
break;
}
eat( currtok.Type );
// <Attributes> <Specifiers> <class, enum, struct, union>
name = parse_identifier(nullptr);
// <Attributes> <Specifiers> <class, enum, struct, union> <Name>
} }
eat( currtok.Type ); else if (next.Type == Tok_BraceCurly_Open)
// <Attributes> <Specifiers> <class, enum, struct, union> {
name = currtok;
// We have an inplace definition, we need to consume that...
name = parse_identifier(nullptr); // TODO(Ed): we need to add a way for AST_CodeTypename to track an implace definition..
b32 const inplace = true;
Code indplace_def = cast(Code, parser_parse_struct(inplace));
// name.Length = ( ( sptr )currtok.Text + currtok.Length ) - ( sptr )name.Text; // For now we lose the structural information,
// eat( Tok_Identifier ); name.Text.Len = ( ( sptr )prevtok.Text.Ptr + prevtok.Text.Len ) - ( sptr )name.Text.Ptr;
// <Attributes> <Specifiers> <class, enum, struct, union> <inplace def>
}
_ctx->parser.Scope->Name = name.Text; _ctx->parser.Scope->Name = name.Text;
// <Attributes> <Specifiers> <class, enum, struct, union> <Name> // <Attributes> <Specifiers> <class, enum, struct, union> <Name>
} }
@ -5296,7 +5356,7 @@ CodeTypedef parser_parse_typedef()
return InvalidCode; return InvalidCode;
} }
array_expr = parse_array_decl(); array_expr = parse_array_decl(& _ctx->parser);
// <UnderlyingType> + <ArrayExpr> // <UnderlyingType> + <ArrayExpr>
} }
@ -5542,7 +5602,7 @@ CodeUsing parser_parse_using()
type = parser_parse_type(parser_not_from_template, nullptr); type = parser_parse_type(parser_not_from_template, nullptr);
// <ModuleFlags> using <Name> <Attributes> = <UnderlyingType> // <ModuleFlags> using <Name> <Attributes> = <UnderlyingType>
array_expr = parse_array_decl(); array_expr = parse_array_decl(& _ctx->parser);
// <UnderlyingType> + <ArrExpr> // <UnderlyingType> + <ArrExpr>
} }
} }

View File

@ -1,7 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "types.hpp" #include "types.hpp"
#include "gen/ecode.hpp" #include "gen/ecodetypes.hpp"
#include "gen/eoperator.hpp" #include "gen/eoperator.hpp"
#include "gen/especifier.hpp" #include "gen/especifier.hpp"
#include "gen/etoktype.hpp" #include "gen/etoktype.hpp"
@ -11,17 +11,18 @@ enum TokFlags : u32
{ {
TF_Operator = bit(0), TF_Operator = bit(0),
TF_Assign = bit(1), TF_Assign = bit(1),
TF_Preprocess = bit(2), TF_Identifier = bit(2),
TF_Preprocess_Cond = bit(3), TF_Preprocess = bit(3),
TF_Attribute = bit(6), TF_Preprocess_Cond = bit(4),
TF_AccessOperator = bit(7), TF_Attribute = bit(5),
TF_AccessSpecifier = bit(8), TF_AccessOperator = bit(6),
TF_Specifier = bit(9), TF_AccessSpecifier = bit(7),
TF_EndDefinition = bit(10), // Either ; or } TF_Specifier = bit(8),
TF_Formatting = bit(11), TF_EndDefinition = bit(9), // Either ; or }
TF_Literal = bit(12), TF_Formatting = bit(10),
TF_Macro_Functional = bit(13), TF_Literal = bit(11),
TF_Macro_Expects_Body = bit(14), TF_Macro_Functional = bit(12),
TF_Macro_Expects_Body = bit(13),
TF_Null = 0, TF_Null = 0,
TF_UnderlyingType = GEN_U32_MAX, TF_UnderlyingType = GEN_U32_MAX,
@ -90,6 +91,27 @@ bool tok_is_end_definition(Token tok) {
StrBuilder tok_to_strbuilder(Token tok); StrBuilder tok_to_strbuilder(Token tok);
struct TokenSlice
{
Token* Ptr;
s32 Num;
#if GEN_COMPILER_CPP
forceinline operator Token* () const { return Ptr; }
forceinline Token& operator[]( ssize index ) const { return Ptr[index]; }
#endif
};
forceinline
Str token_range_to_str(Token start, Token end)
{
Str result = {
start.Text.Ptr,
(scast(sptr, rcast(uptr, end.Text.Ptr)) + end.Text.Len) - scast(sptr, rcast(uptr, start.Text.Ptr))
};
return result;
}
struct TokArray struct TokArray
{ {
Array(Token) Arr; Array(Token) Arr;
@ -103,23 +125,21 @@ struct LexContext
char const* scanner; char const* scanner;
s32 line; s32 line;
s32 column; s32 column;
// StringTable defines;
Token token; Token token;
}; };
struct StackNode struct LexedInfo
{ {
StackNode* Prev; Str text;
TokenSlice tokens;
Token* Start;
Str Name; // The name of the AST node (if parsed)
Str ProcName; // The name of the procedure
}; };
typedef struct ParseStackNode ParseStackNode;
struct ParseContext struct ParseContext
{ {
TokArray Tokens; TokArray Tokens;
StackNode* Scope; ParseStackNode* Scope;
}; };
enum MacroType : u16 enum MacroType : u16
@ -167,26 +187,36 @@ Str macrotype_to_str( MacroType type )
enum EMacroFlags : u16 enum EMacroFlags : u16
{ {
MF_Functional = bit(0), // Macro has parameters (args expected to be passed) // Macro has parameters (args expected to be passed)
MF_Expects_Body = bit(1), // Expects to assign a braced scope to its body. MF_Functional = bit(0),
// Expects to assign a braced scope to its body.
MF_Expects_Body = bit(1),
// lex__eat wil treat this macro as an identifier if the parser attempts to consume it as one. // lex__eat wil treat this macro as an identifier if the parser attempts to consume it as one.
// ^^^ This is a kludge because we don't support push/pop macro pragmas rn. // This is a kludge because we don't support push/pop macro pragmas rn.
MF_Allow_As_Identifier = bit(2), MF_Allow_As_Identifier = bit(2),
// When parsing identifiers, it will allow the consumption of the macro parameters (as its expected to be a part of constructing the identifier)
// Example of a decarator macro from stb_sprintf.h:
// STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(sprintf)(char* buf, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(2,3);
// ^^ STB_SPRINTF_DECORATE is decorating sprintf
MF_Identifier_Decorator = bit(3),
// lex__eat wil treat this macro as an attribute if the parser attempts to consume it as one. // lex__eat wil treat this macro as an attribute if the parser attempts to consume it as one.
// ^^^ This a kludge because unreal has a macro that behaves as both a 'statement' and an attribute (UE_DEPRECATED, PRAGMA_ENABLE_DEPRECATION_WARNINGS, etc) // This a kludge because unreal has a macro that behaves as both a 'statement' and an attribute (UE_DEPRECATED, PRAGMA_ENABLE_DEPRECATION_WARNINGS, etc)
// TODO(Ed): We can keep the MF_Allow_As_Attribute flag for macros, however, we need to add the ability of AST_Attributes to chain themselves. // TODO(Ed): We can keep the MF_Allow_As_Attribute flag for macros, however, we need to add the ability of AST_Attributes to chain themselves.
// Its thats already a thing in the standard language anyway // Its thats already a thing in the standard language anyway
// & it would allow UE_DEPRECATED, (UE_PROPERTY / UE_FUNCTION) to chain themselves as attributes of a resolved member function/variable definition // & it would allow UE_DEPRECATED, (UE_PROPERTY / UE_FUNCTION) to chain themselves as attributes of a resolved member function/variable definition
MF_Allow_As_Attribute = bit(3), MF_Allow_As_Attribute = bit(4),
// When a macro is encountered after attributes and specifiers while parsing a function, or variable: // When a macro is encountered after attributes and specifiers while parsing a function, or variable:
// It will consume the macro and treat it as resolving the definition. (Yes this is for Unreal Engine) // It will consume the macro and treat it as resolving the definition.
// (MUST BE OF MT_Statement TYPE) // (MUST BE OF MT_Statement TYPE)
MF_Allow_As_Definition = bit(4), MF_Allow_As_Definition = bit(5),
MF_Allow_As_Specifier = bit(5), // Created for Unreal's PURE_VIRTUAL // Created for Unreal's PURE_VIRTUAL
MF_Allow_As_Specifier = bit(6),
MF_Null = 0, MF_Null = 0,
MF_UnderlyingType = GEN_U16_MAX, MF_UnderlyingType = GEN_U16_MAX,

View File

@ -1,6 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "../gen.hpp" #include "interface.hpp"
#endif #endif
#pragma region StaticData #pragma region StaticData

View File

@ -1,6 +1,18 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "header_start.hpp" #include "dependencies/platform.hpp"
#include "dependencies/macros.hpp"
#include "dependencies/basic_types.hpp"
#include "dependencies/debug.hpp"
#include "dependencies/memory.hpp"
#include "dependencies/string_ops.hpp"
#include "dependencies/printing.hpp"
#include "dependencies/containers.hpp"
#include "dependencies/hashing.hpp"
#include "dependencies/strings.hpp"
#include "dependencies/filesystem.hpp"
#include "dependencies/timing.hpp"
#include "dependencies/parsing.hpp"
#endif #endif
/* /*
@ -19,16 +31,6 @@
*/ */
using LogFailType = ssize(*)(char const*, ...);
// By default this library will either crash or exit if an error is detected while generating codes.
// Even if set to not use GEN_FATAL, GEN_FATAL will still be used for memory failures as the library is unusable when they occur.
#ifdef GEN_DONT_USE_FATAL
#define log_failure log_fmt
#else
#define log_failure GEN_FATAL
#endif
enum AccessSpec : u32 enum AccessSpec : u32
{ {
AccessSpec_Default, AccessSpec_Default,

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "macros.hpp" # include "macros.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "printing.hpp" # include "printing.hpp"
#endif #endif
@ -416,7 +416,7 @@ bool array_set_capacity(Array<Type>* array, usize new_capacity)
// These are intended for use in the base library of gencpp and the C-variant of the library // These are intended for use in the base library of gencpp and the C-variant of the library
// It provides a interoperability between the C++ and C implementation of arrays. (not letting these do any crazy substiution though) // It provides a interoperability between the C++ and C implementation of arrays. (not letting these do any crazy substiution though)
// They are undefined in gen.hpp and gen.cpp at the end of the files. // They are undefined in gen.hpp and gen.cpp at the end of the files.
// We cpp library expects the user to use the regular calls as they can resolve the type fine. // The cpp library expects the user to use the regular calls as they can resolve the type fine.
#define array_init(type, allocator) array_init <type> (allocator ) #define array_init(type, allocator) array_init <type> (allocator )
#define array_init_reserve(type, allocator, cap) array_init_reserve <type> (allocator, cap) #define array_init_reserve(type, allocator, cap) array_init_reserve <type> (allocator, cap)

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "src_start.cpp" # include "src_start.cpp"
#endif #endif

View File

@ -1,9 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "dependencies/platform.hpp"
# include "dependencies/macros.hpp"
# include "basic_types.hpp" # include "basic_types.hpp"
# include "macros.hpp"
#endif #endif
#pragma region Debug #pragma region Debug

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "strings.cpp" # include "strings.cpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "strings.hpp" # include "strings.hpp"
#endif #endif
@ -187,7 +187,7 @@ struct FileContents
{ {
AllocatorInfo allocator; AllocatorInfo allocator;
void* data; void* data;
ssize size; ssize size;
}; };
constexpr b32 file_zero_terminate = true; constexpr b32 file_zero_terminate = true;

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "memory.cpp" # include "memory.cpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
#pragma once #pragma once
#include "containers.hpp" #include "containers.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "platform.hpp" # include "platform.hpp"
#endif #endif
@ -26,7 +26,7 @@
#endif // GEN_API #endif // GEN_API
#ifndef global // Global variables #ifndef global // Global variables
# ifdef GEN_DYN_EXPORT # if defined(GEN_STATIC_LINK) || defined(GEN_DYN_LINK)
# define global # define global
# else # else
# define global static # define global static
@ -198,21 +198,16 @@
#ifndef forceinline #ifndef forceinline
# if GEN_COMPILER_MSVC # if GEN_COMPILER_MSVC
# define forceinline __forceinline # define forceinline __forceinline
# define neverinline __declspec( noinline )
# elif GEN_COMPILER_GCC # elif GEN_COMPILER_GCC
# define forceinline inline __attribute__((__always_inline__)) # define forceinline inline __attribute__((__always_inline__))
# define neverinline __attribute__( ( __noinline__ ) )
# elif GEN_COMPILER_CLANG # elif GEN_COMPILER_CLANG
# if __has_attribute(__always_inline__) # if __has_attribute(__always_inline__)
# define forceinline inline __attribute__((__always_inline__)) # define forceinline inline __attribute__((__always_inline__))
# define neverinline __attribute__( ( __noinline__ ) )
# else # else
# define forceinline # define forceinline
# define neverinline
# endif # endif
# else # else
# define forceinline # define forceinline
# define neverinline
# endif # endif
#endif #endif
@ -303,10 +298,20 @@
# define GEN_PARAM_DEFAULT # define GEN_PARAM_DEFAULT
#endif #endif
#if GEN_COMPILER_CPP #ifndef struct_init
#define struct_init(type, value) {value} # if GEN_COMPILER_CPP
#else # define struct_init(type, value) value
#define struct_init(type, value) {value} # else
# define struct_init(type, value) (type) value
# endif
#endif
#ifndef struct_zero
# if GEN_COMPILER_CPP
# define struct_zero(type) {}
# else
# define struct_zero(type) {0}
# endif
#endif #endif
#if 0 #if 0
@ -319,4 +324,12 @@
# define GEN_OPITMIZE_MAPPINGS_END # define GEN_OPITMIZE_MAPPINGS_END
#endif #endif
#ifndef get_optional
# if GEN_COMPILER_C
# define get_optional(opt) opt ? *opt : (typeof(*opt)){0}
# else
# define get_optional(opt) opt
# endif
#endif
#pragma endregion Macros #pragma endregion Macros

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "printing.cpp" # include "printing.cpp"
#endif #endif
@ -84,7 +84,7 @@ void heap_stats_check( void )
typedef struct _heap_alloc_info _heap_alloc_info; typedef struct _heap_alloc_info _heap_alloc_info;
struct _heap_alloc_info struct _heap_alloc_info
{ {
ssize size; ssize size;
void* physical_start; void* physical_start;
}; };

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "debug.hpp" # include "debug.hpp"
#endif #endif
@ -134,12 +134,6 @@ GEN_API void* heap_allocator_proc( void* allocator_data, AllocType type, ssize s
//! The heap allocator backed by operating system's memory manager. //! The heap allocator backed by operating system's memory manager.
constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocator_proc, nullptr }; return allocator; } constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocator_proc, nullptr }; return allocator; }
//! Helper to allocate memory using heap allocator.
#define malloc( sz ) alloc( heap(), sz )
//! Helper to free memory allocated by heap allocator.
#define mfree( ptr ) free( heap(), ptr )
struct VirtualMemory struct VirtualMemory
{ {
void* data; void* data;
@ -185,6 +179,8 @@ void arena_check (Arena* arena);
void arena_free (Arena* arena); void arena_free (Arena* arena);
ssize arena_size_remaining(Arena* arena, ssize alignment); ssize arena_size_remaining(Arena* arena, ssize alignment);
// TODO(Ed): Add arena_pos, arena_pop, and arena_pop_to
struct Arena struct Arena
{ {
AllocatorInfo Backing; AllocatorInfo Backing;

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "parsing.hpp" # include "parsing.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "timing.hpp" # include "timing.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
#endif #endif

View File

@ -1,6 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "strbuilder_ops.cpp" # include "string_ops.cpp"
#endif #endif
#pragma region Printing #pragma region Printing

View File

@ -1,6 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "strbuilder_ops.hpp" # include "string_ops.hpp"
#endif #endif
#pragma region Printing #pragma region Printing
@ -26,17 +26,4 @@ GEN_API ssize c_str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
constexpr constexpr
char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED"; char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
inline
ssize log_fmt(char const* fmt, ...)
{
ssize res;
va_list va;
va_start(va, fmt);
res = c_str_fmt_out_va(fmt, va);
va_end(va);
return res;
}
#pragma endregion Printing #pragma endregion Printing

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "header_start.hpp" # include "header_start.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "debug.cpp" # include "debug.cpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "memory.hpp" # include "memory.hpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "hashing.cpp" # include "hashing.cpp"
#endif #endif
@ -58,4 +58,120 @@ StrBuilder strbuilder_make_reserve( AllocatorInfo allocator, ssize capacity )
return result; return result;
} }
bool strbuilder_make_space_for(StrBuilder* str, char const* to_append, ssize add_len)
{
ssize available = strbuilder_avail_space(* str);
if (available >= add_len) {
return true;
}
else
{
ssize new_len, old_size, new_size;
void* ptr;
void* new_ptr;
AllocatorInfo allocator = strbuilder_get_header(* str)->Allocator;
StrBuilderHeader* header = nullptr;
new_len = strbuilder_grow_formula(strbuilder_length(* str) + add_len);
ptr = strbuilder_get_header(* str);
old_size = size_of(StrBuilderHeader) + strbuilder_length(* str) + 1;
new_size = size_of(StrBuilderHeader) + new_len + 1;
new_ptr = resize(allocator, ptr, old_size, new_size);
if (new_ptr == nullptr)
return false;
header = rcast(StrBuilderHeader*, new_ptr);
header->Allocator = allocator;
header->Capacity = new_len;
char** Data = rcast(char**, str);
* Data = rcast(char*, header + 1);
return true;
}
}
bool strbuilder_append_c_str_len(StrBuilder* str, char const* c_str_to_append, ssize append_length)
{
GEN_ASSERT(str != nullptr);
if ( rcast(sptr, c_str_to_append) > 0)
{
ssize curr_len = strbuilder_length(* str);
if ( ! strbuilder_make_space_for(str, c_str_to_append, append_length))
return false;
StrBuilderHeader* header = strbuilder_get_header(* str);
char* Data = * str;
mem_copy( Data + curr_len, c_str_to_append, append_length);
Data[curr_len + append_length] = '\0';
header->Length = curr_len + append_length;
}
return c_str_to_append != nullptr;
}
void strbuilder_trim(StrBuilder str, char const* cut_set)
{
ssize len = 0;
char* start_pos = str;
char* end_pos = scast(char*, str) + strbuilder_length(str) - 1;
while (start_pos <= end_pos && char_first_occurence(cut_set, *start_pos))
start_pos++;
while (end_pos > start_pos && char_first_occurence(cut_set, *end_pos))
end_pos--;
len = scast(ssize, (start_pos > end_pos) ? 0 : ((end_pos - start_pos) + 1));
if (str != start_pos)
mem_move(str, start_pos, len);
str[len] = '\0';
strbuilder_get_header(str)->Length = len;
}
StrBuilder strbuilder_visualize_whitespace(StrBuilder const str)
{
StrBuilderHeader* header = (StrBuilderHeader*)(scast(char const*, str) - sizeof(StrBuilderHeader));
StrBuilder result = strbuilder_make_reserve(header->Allocator, strbuilder_length(str) * 2); // Assume worst case for space requirements.
for (char const* c = strbuilder_begin(str); c != strbuilder_end(str); c = strbuilder_next(str, c))
switch ( * c )
{
case ' ':
strbuilder_append_str(& result, txt("·"));
break;
case '\t':
strbuilder_append_str(& result, txt(""));
break;
case '\n':
strbuilder_append_str(& result, txt(""));
break;
case '\r':
strbuilder_append_str(& result, txt(""));
break;
case '\v':
strbuilder_append_str(& result, txt(""));
break;
case '\f':
strbuilder_append_str(& result, txt(""));
break;
default:
strbuilder_append_char(& result, * c);
break;
}
return result;
}
#pragma endregion StrBuilder #pragma endregion StrBuilder

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "hashing.hpp" # include "hashing.hpp"
#endif #endif
@ -124,6 +124,10 @@ forceinline usize strbuilder_grow_formula(usize value);
GEN_API StrBuilder strbuilder_make_reserve (AllocatorInfo allocator, ssize capacity); GEN_API StrBuilder strbuilder_make_reserve (AllocatorInfo allocator, ssize capacity);
GEN_API StrBuilder strbuilder_make_length (AllocatorInfo allocator, char const* str, ssize length); GEN_API StrBuilder strbuilder_make_length (AllocatorInfo allocator, char const* str, ssize length);
GEN_API bool strbuilder_make_space_for (StrBuilder* str, char const* to_append, ssize add_len);
GEN_API bool strbuilder_append_c_str_len (StrBuilder* str, char const* c_str_to_append, ssize length);
GEN_API void strbuilder_trim (StrBuilder str, char const* cut_set);
GEN_API StrBuilder strbuilder_visualize_whitespace(StrBuilder const str);
StrBuilder strbuilder_make_c_str (AllocatorInfo allocator, char const* str); StrBuilder strbuilder_make_c_str (AllocatorInfo allocator, char const* str);
StrBuilder strbuilder_make_str (AllocatorInfo allocator, Str str); StrBuilder strbuilder_make_str (AllocatorInfo allocator, Str str);
@ -132,10 +136,8 @@ StrBuilder strbuilder_fmt_buf (AllocatorInfo allocator, char
StrBuilder strbuilder_join (AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue); StrBuilder strbuilder_join (AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue);
bool strbuilder_are_equal (StrBuilder const lhs, StrBuilder const rhs); bool strbuilder_are_equal (StrBuilder const lhs, StrBuilder const rhs);
bool strbuilder_are_equal_str (StrBuilder const lhs, Str rhs); bool strbuilder_are_equal_str (StrBuilder const lhs, Str rhs);
bool strbuilder_make_space_for (StrBuilder* str, char const* to_append, ssize add_len);
bool strbuilder_append_char (StrBuilder* str, char c); bool strbuilder_append_char (StrBuilder* str, char c);
bool strbuilder_append_c_str (StrBuilder* str, char const* c_str_to_append); bool strbuilder_append_c_str (StrBuilder* str, char const* c_str_to_append);
bool strbuilder_append_c_str_len (StrBuilder* str, char const* c_str_to_append, ssize length);
bool strbuilder_append_str (StrBuilder* str, Str c_str_to_append); bool strbuilder_append_str (StrBuilder* str, Str c_str_to_append);
bool strbuilder_append_string (StrBuilder* str, StrBuilder const other); bool strbuilder_append_string (StrBuilder* str, StrBuilder const other);
bool strbuilder_append_fmt (StrBuilder* str, char const* fmt, ...); bool strbuilder_append_fmt (StrBuilder* str, char const* fmt, ...);
@ -154,9 +156,7 @@ b32 strbuilder_starts_with_string (StrBuilder const str, StrBuild
void strbuilder_skip_line (StrBuilder str); void strbuilder_skip_line (StrBuilder str);
void strbuilder_strip_space (StrBuilder str); void strbuilder_strip_space (StrBuilder str);
Str strbuilder_to_str (StrBuilder str); Str strbuilder_to_str (StrBuilder str);
void strbuilder_trim (StrBuilder str, char const* cut_set);
void strbuilder_trim_space (StrBuilder str); void strbuilder_trim_space (StrBuilder str);
StrBuilder strbuilder_visualize_whitespace(StrBuilder const str);
struct StrBuilderHeader { struct StrBuilderHeader {
AllocatorInfo Allocator; AllocatorInfo Allocator;
@ -320,7 +320,7 @@ inline
StrBuilder strbuilder_fmt_buf(AllocatorInfo allocator, char const* fmt, ...) StrBuilder strbuilder_fmt_buf(AllocatorInfo allocator, char const* fmt, ...)
{ {
local_persist thread_local local_persist thread_local
PrintF_Buffer buf = struct_init(PrintF_Buffer, {0}); PrintF_Buffer buf = struct_zero(PrintF_Buffer);
va_list va; va_list va;
va_start(va, fmt); va_start(va, fmt);
@ -358,29 +358,6 @@ bool strbuilder_append_c_str(StrBuilder* str, char const* c_str_to_append) {
return strbuilder_append_c_str_len(str, c_str_to_append, c_str_len(c_str_to_append)); return strbuilder_append_c_str_len(str, c_str_to_append, c_str_len(c_str_to_append));
} }
inline
bool strbuilder_append_c_str_len(StrBuilder* str, char const* c_str_to_append, ssize append_length)
{
GEN_ASSERT(str != nullptr);
if ( rcast(sptr, c_str_to_append) > 0)
{
ssize curr_len = strbuilder_length(* str);
if ( ! strbuilder_make_space_for(str, c_str_to_append, append_length))
return false;
StrBuilderHeader* header = strbuilder_get_header(* str);
char* Data = * str;
mem_copy( Data + curr_len, c_str_to_append, append_length);
Data[curr_len + append_length] = '\0';
header->Length = curr_len + append_length;
}
return c_str_to_append != nullptr;
}
forceinline forceinline
bool strbuilder_append_str(StrBuilder* str, Str c_str_to_append) { bool strbuilder_append_str(StrBuilder* str, Str c_str_to_append) {
GEN_ASSERT(str != nullptr); GEN_ASSERT(str != nullptr);
@ -522,44 +499,6 @@ ssize strbuilder_length(StrBuilder const str)
return header->Length; return header->Length;
} }
inline
bool strbuilder_make_space_for(StrBuilder* str, char const* to_append, ssize add_len)
{
ssize available = strbuilder_avail_space(* str);
if (available >= add_len) {
return true;
}
else
{
ssize new_len, old_size, new_size;
void* ptr;
void* new_ptr;
AllocatorInfo allocator = strbuilder_get_header(* str)->Allocator;
StrBuilderHeader* header = nullptr;
new_len = strbuilder_grow_formula(strbuilder_length(* str) + add_len);
ptr = strbuilder_get_header(* str);
old_size = size_of(StrBuilderHeader) + strbuilder_length(* str) + 1;
new_size = size_of(StrBuilderHeader) + new_len + 1;
new_ptr = resize(allocator, ptr, old_size, new_size);
if (new_ptr == nullptr)
return false;
header = rcast(StrBuilderHeader*, new_ptr);
header->Allocator = allocator;
header->Capacity = new_len;
char** Data = rcast(char**, str);
* Data = rcast(char*, header + 1);
return true;
}
}
forceinline forceinline
b32 strbuilder_starts_with_str(StrBuilder const str, Str substring) { b32 strbuilder_starts_with_str(StrBuilder const str, Str substring) {
if (substring.Len > strbuilder_length(str)) if (substring.Len > strbuilder_length(str))
@ -627,69 +566,11 @@ Str strbuilder_to_str(StrBuilder str) {
return result; return result;
} }
inline
void strbuilder_trim(StrBuilder str, char const* cut_set)
{
ssize len = 0;
char* start_pos = str;
char* end_pos = scast(char*, str) + strbuilder_length(str) - 1;
while (start_pos <= end_pos && char_first_occurence(cut_set, *start_pos))
start_pos++;
while (end_pos > start_pos && char_first_occurence(cut_set, *end_pos))
end_pos--;
len = scast(ssize, (start_pos > end_pos) ? 0 : ((end_pos - start_pos) + 1));
if (str != start_pos)
mem_move(str, start_pos, len);
str[len] = '\0';
strbuilder_get_header(str)->Length = len;
}
forceinline forceinline
void strbuilder_trim_space(StrBuilder str) { void strbuilder_trim_space(StrBuilder str) {
strbuilder_trim(str, " \t\r\n\v\f"); strbuilder_trim(str, " \t\r\n\v\f");
} }
inline
StrBuilder strbuilder_visualize_whitespace(StrBuilder const str)
{
StrBuilderHeader* header = (StrBuilderHeader*)(scast(char const*, str) - sizeof(StrBuilderHeader));
StrBuilder result = strbuilder_make_reserve(header->Allocator, strbuilder_length(str) * 2); // Assume worst case for space requirements.
for (char const* c = strbuilder_begin(str); c != strbuilder_end(str); c = strbuilder_next(str, c))
switch ( * c )
{
case ' ':
strbuilder_append_str(& result, txt("·"));
break;
case '\t':
strbuilder_append_str(& result, txt(""));
break;
case '\n':
strbuilder_append_str(& result, txt(""));
break;
case '\r':
strbuilder_append_str(& result, txt(""));
break;
case '\v':
strbuilder_append_str(& result, txt(""));
break;
case '\f':
strbuilder_append_str(& result, txt(""));
break;
default:
strbuilder_append_char(& result, * c);
break;
}
return result;
}
#pragma endregion StrBuilder #pragma endregion StrBuilder
#if GEN_COMPILER_CPP #if GEN_COMPILER_CPP

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "filesystem.cpp" # include "filesystem.cpp"
#endif #endif

View File

@ -1,4 +1,4 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# pragma once # pragma once
# include "filesystem.hpp" # include "filesystem.hpp"
#endif #endif

View File

@ -11,9 +11,6 @@
#include "helpers/push_ignores.inline.hpp" #include "helpers/push_ignores.inline.hpp"
#include "components/header_start.hpp" #include "components/header_start.hpp"
// Has container defines pushed
#include "gen.dep.hpp"
GEN_NS_BEGIN GEN_NS_BEGIN
#include "components/types.hpp" #include "components/types.hpp"
@ -29,9 +26,9 @@ GEN_NS_BEGIN
#include "components/interface.hpp" #include "components/interface.hpp"
#include "components/constants.hpp"
#include "components/inlines.hpp" #include "components/inlines.hpp"
#include "components/gen/ast_inlines.hpp" #include "components/gen/ast_inlines.hpp"
#include "components/header_end.hpp"
#include "auxiliary/builder.hpp" #include "auxiliary/builder.hpp"
#include "auxiliary/scanner.hpp" #include "auxiliary/scanner.hpp"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#if GEN_INTELLISENSE_DIRECTIVES #if INTELLISENSE_DIRECTIVES
# include "../gen.hpp" # include "../gen.hpp"
# include "misc.hpp" # include "misc.hpp"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef INTELLISENSE_DIRECTIVES
# define GEN_DEFINE_LIBRARY_CODE_CONSTANTS # define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
# define GEN_ENFORCE_STRONG_CODE_TYPES # define GEN_ENFORCE_STRONG_CODE_TYPES
# define GEN_EXPOSE_BACKEND # define GEN_EXPOSE_BACKEND

View File

@ -53,7 +53,7 @@ StrBuilder <prefix>_to_strbuilder(Code code);
Where the first generates strings allocated using Allocator_StringArena and the other appends an existing strings with their backed allocator. Where the first generates strings allocated using Allocator_StringArena and the other appends an existing strings with their backed allocator.
Serialization of for the AST is defined for `Code` in [`ast.cpp`](../base/components/ast.cpp) with `code_to_strbuilder_ptr` & `code_to_strbuilder`. Serialization of for the AST is defined for `Code` in [`ast.cpp`](../base/components/ast.cpp) with `code_to_strbuilder_ref` & `code_to_strbuilder`.
Serializtion for the rest of the code types is within [`code_serialization.cpp`](../base/components/code_serialization.cpp). Serializtion for the rest of the code types is within [`code_serialization.cpp`](../base/components/code_serialization.cpp).
Gencpp's serialization does not provide coherent formatting of the code. The user should use a formatter after serializing. Gencpp's serialization does not provide coherent formatting of the code. The user should use a formatter after serializing.

View File

@ -306,7 +306,7 @@ do \
break; break;
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_memory, header_memory ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_memory, header_memory );
if (found) break; if (found) break;
header_memory.append(entry); header_memory.append(entry);
@ -334,7 +334,7 @@ do \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_printing, header_printing ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_printing, header_printing );
if (found) break; if (found) break;
header_printing.append(entry); header_printing.append(entry);
@ -391,7 +391,7 @@ do \
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_strings, header_strings ); ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_strings, header_strings );
} }
break; break;
@ -472,7 +472,7 @@ do \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_filesystem, header_filesystem ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_filesystem, header_filesystem );
if (found) break; if (found) break;
header_filesystem.append(entry); header_filesystem.append(entry);
@ -509,7 +509,7 @@ do \
case CT_Variable: case CT_Variable:
{ {
CodeVar var = cast(CodeVar, entry); CodeVar var = cast(CodeVar, entry);
if (var->Specs.has(Spec_Constexpr) > -1) if (var->Specs.has(Spec_Constexpr))
{ {
Opts_def_define opts = { {}, entry->Value->Content }; Opts_def_define opts = { {}, entry->Value->Content };
CodeDefine define = def_define(entry->Name, MT_Expression, opts); CodeDefine define = def_define(entry->Name, MT_Expression, opts);
@ -532,7 +532,7 @@ do \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_parsing, header_parsing ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_parsing, header_parsing );
if (found) break; if (found) break;
header_parsing.append(entry); header_parsing.append(entry);
@ -640,7 +640,7 @@ do \
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_types, types ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_types, types );
if (found) break; if (found) break;
types.append(entry); types.append(entry);
@ -702,7 +702,7 @@ do \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_parser_types, parser_types ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_parser_types, parser_types );
if (found) break; if (found) break;
parser_types.append(entry); parser_types.append(entry);
@ -769,7 +769,7 @@ do \
case CT_Variable: case CT_Variable:
{ {
CodeVar var = cast(CodeVar, entry); CodeVar var = cast(CodeVar, entry);
if (var->Specs && var->Specs.has(Spec_Constexpr) > -1) { if (var->Specs && var->Specs.has(Spec_Constexpr)) {
Code define_ver = untyped_str(token_fmt( Code define_ver = untyped_str(token_fmt(
"name", var->Name "name", var->Name
, "value", var->Value->Content , "value", var->Value->Content
@ -797,7 +797,7 @@ do \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast, ast ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_ast, ast );
if (found) break; if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast, ast ); found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast, ast );
@ -978,7 +978,7 @@ R"(#define AST_ArrSpecs_Cap \
++ entry; // Skip a newline... ++ entry; // Skip a newline...
break; break;
} }
found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types ); found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types );
if (found) break; if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_code_types, code_types); found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_code_types, code_types);
@ -1078,7 +1078,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
case CT_Preprocess_If: case CT_Preprocess_If:
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast_types, ast_types ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_ast_types, ast_types );
if (found) break; if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast_types, ast_types); found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast_types, ast_types);
@ -1132,7 +1132,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
case CT_Preprocess_If: case CT_Preprocess_If:
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_interface, interface ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_interface, interface );
if (found) break; if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface); found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface);
@ -1159,6 +1159,8 @@ R"(#define <interface_name>( code ) _Generic( (code), \
Str actual_name = { fn->Name.Ptr + prefix.Len, fn->Name.Len - prefix.Len }; Str actual_name = { fn->Name.Ptr + prefix.Len, fn->Name.Len - prefix.Len };
Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "def__%S", actual_name ).to_str(); Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "def__%S", actual_name ).to_str();
opt_param->ValueType->Specs = def_specifier(Spec_Ptr);
// Resolve define's arguments // Resolve define's arguments
b32 has_args = fn->Params->NumEntries > 1; b32 has_args = fn->Params->NumEntries > 1;
StrBuilder params_str = StrBuilder::make_reserve(_ctx->Allocator_Temp, 32); StrBuilder params_str = StrBuilder::make_reserve(_ctx->Allocator_Temp, 32);
@ -1172,10 +1174,10 @@ R"(#define <interface_name>( code ) _Generic( (code), \
} }
char const* tmpl_fn_macro = nullptr; char const* tmpl_fn_macro = nullptr;
if (params_str.length() > 0 ) { if (params_str.length() > 0 ) {
tmpl_fn_macro= "#define <def_name>( <params> ... ) <def__name>( <params> (<opts_type>) { __VA_ARGS__ } )\n"; tmpl_fn_macro= "#define <def_name>( <params> ... ) <def__name>( <params> & (<opts_type>) { __VA_ARGS__ } )\n";
} }
else { else {
tmpl_fn_macro= "#define <def_name>( ... ) <def__name>( (<opts_type>) { __VA_ARGS__ } )\n"; tmpl_fn_macro= "#define <def_name>( ... ) <def__name>( & (<opts_type>) { __VA_ARGS__ } )\n";
} }
Code fn_macro = untyped_str(token_fmt( Code fn_macro = untyped_str(token_fmt(
"def_name", fn->Name "def_name", fn->Name
@ -1221,7 +1223,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
case CT_Preprocess_If: case CT_Preprocess_If:
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_inlines, inlines ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_inlines, inlines );
if (found) break; if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface); found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface);
@ -1257,16 +1259,16 @@ R"(#define <interface_name>( code ) _Generic( (code), \
} }
s32 idx = 0; s32 idx = 0;
CodeBody parsed_header_end = parse_file( path_base "components/header_end.hpp" ); CodeBody parsed_constants = parse_file( path_base "components/constants.hpp" );
CodeBody header_end = def_body(CT_Global_Body); CodeBody constants = def_body(CT_Global_Body);
for ( Code entry = parsed_header_end.begin(); entry != parsed_header_end.end(); ++ entry, ++ idx ) switch( entry->Type ) for ( Code entry = parsed_constants.begin(); entry != parsed_constants.end(); ++ entry, ++ idx ) switch( entry->Type )
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_end, header_end ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_constants, constants );
if (found) break; if (found) break;
header_end.append(entry); constants.append(entry);
} }
break; break;
@ -1278,18 +1280,18 @@ R"(#define <interface_name>( code ) _Generic( (code), \
s32 constexpr_found = var->Specs.remove( Spec_Constexpr ); s32 constexpr_found = var->Specs.remove( Spec_Constexpr );
if (constexpr_found > -1) if (constexpr_found > -1)
{ {
Opts_def_define opts = { {}, entry->Value->Content }; Opts_def_define opts = { {}, entry->Value->Content };
CodeDefine define = def_define(entry->Name, MT_Expression, opts ); CodeDefine define = def_define(entry->Name, MT_Expression, opts );
header_end.append(define); constants.append(define);
continue; continue;
} }
} }
header_end.append(entry); constants.append(entry);
} }
break; break;
default: default:
header_end.append(entry); constants.append(entry);
break; break;
} }
#pragma endregion Resolve Components #pragma endregion Resolve Components
@ -1302,7 +1304,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_builder, header_builder ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_builder, header_builder );
if (found) break; if (found) break;
header_builder.append(entry); header_builder.append(entry);
@ -1446,7 +1448,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_src_ast, src_ast ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_src_ast, src_ast );
if (found) break; if (found) break;
src_ast.append(entry); src_ast.append(entry);
@ -1481,7 +1483,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_src_upfront, src_upfront ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_src_upfront, src_upfront );
if (found) break; if (found) break;
src_upfront.append(entry); src_upfront.append(entry);
@ -1504,6 +1506,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
Str actual_name = { fn->Name.Ptr + prefix.Len, fn->Name.Len - prefix.Len }; Str actual_name = { fn->Name.Ptr + prefix.Len, fn->Name.Len - prefix.Len };
Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "def__%S", actual_name ).to_str(); Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "def__%S", actual_name ).to_str();
fn->Name = cache_str(new_name); fn->Name = cache_str(new_name);
opt_param->ValueType->Specs = def_specifier(Spec_Ptr);
} }
src_upfront.append(fn); src_upfront.append(fn);
} }
@ -1520,7 +1523,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_src_lexer, src_lexer ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_src_lexer, src_lexer );
if (found) break; if (found) break;
src_lexer.append(entry); src_lexer.append(entry);
@ -1542,7 +1545,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
case CT_Variable: case CT_Variable:
{ {
CodeVar var = cast(CodeVar, entry); CodeVar var = cast(CodeVar, entry);
if (var->Specs && var->Specs.has(Spec_Constexpr) > -1) { if (var->Specs && var->Specs.has(Spec_Constexpr)) {
Code define_ver = untyped_str(token_fmt( Code define_ver = untyped_str(token_fmt(
"name", var->Name "name", var->Name
, "value", var->Value->Content , "value", var->Value->Content
@ -1569,7 +1572,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
{ {
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_src_parser, src_parser ); b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_src_parser, src_parser );
if (found) break; if (found) break;
src_parser.append(entry); src_parser.append(entry);
@ -1587,7 +1590,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
case CT_Variable: case CT_Variable:
{ {
CodeVar var = cast(CodeVar, entry); CodeVar var = cast(CodeVar, entry);
if (var->Specs && var->Specs.has(Spec_Constexpr) > -1) { if (var->Specs && var->Specs.has(Spec_Constexpr)) {
Code define_ver = untyped_str(token_fmt( Code define_ver = untyped_str(token_fmt(
"name", var->Name "name", var->Name
, "value", var->Value->Content , "value", var->Value->Content
@ -1673,11 +1676,11 @@ R"(#define <interface_name>( code ) _Generic( (code), \
Code rf_ast_types = refactor_and_format(ast_types); Code rf_ast_types = refactor_and_format(ast_types);
Code rf_interface = refactor_and_format(interface); Code rf_interface = refactor_and_format(interface);
Code rf_constants = refactor_and_format(constants);
Code rf_inlines = refactor_and_format(inlines); Code rf_inlines = refactor_and_format(inlines);
Code rf_ht_preprocessor_macro = refactor_and_format(ht_preprocessor_macro); Code rf_ht_preprocessor_macro = refactor_and_format(ht_preprocessor_macro);
Code rf_array_string_cached = refactor_and_format(array_string_cached); Code rf_array_string_cached = refactor_and_format(array_string_cached);
Code rf_header_end = refactor_and_format(header_end);
Code rf_header_builder = refactor_and_format(header_builder); Code rf_header_builder = refactor_and_format(header_builder);
Code rf_header_scanner = refactor_and_format( scan_file( path_base "auxiliary/scanner.hpp" )); Code rf_header_scanner = refactor_and_format( scan_file( path_base "auxiliary/scanner.hpp" ));
@ -1788,6 +1791,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print( rf_ht_preprocessor_macro ); header.print( rf_ht_preprocessor_macro );
header.print( rf_interface ); header.print( rf_interface );
header.print( rf_constants );
header.print(fmt_newline); header.print(fmt_newline);
header.print_fmt("#pragma region Inlines\n"); header.print_fmt("#pragma region Inlines\n");
@ -1796,7 +1800,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print(fmt_newline); header.print(fmt_newline);
header.print( rf_header_end );
header.print( rf_header_builder ); header.print( rf_header_builder );
header.print( rf_header_scanner ); header.print( rf_header_scanner );
@ -1882,6 +1885,9 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print( r_header_macros ); header.print( r_header_macros );
header.print( header_generic_macros ); header.print( header_generic_macros );
header.print_fmt( "\nGEN_API_C_BEGIN\n" );
header.print( r_header_basic_types ); header.print( r_header_basic_types );
header.print( r_header_debug ); header.print( r_header_debug );
header.print( rf_header_memory ); header.print( rf_header_memory );
@ -1895,6 +1901,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print( r_header_timing ); header.print( r_header_timing );
header.print(rf_header_parsing ); header.print(rf_header_parsing );
header.print_fmt( "\nGEN_API_C_END\n" );
header.print_fmt( "\nGEN_NS_END\n" ); header.print_fmt( "\nGEN_NS_END\n" );
header.write(); header.write();
} }
@ -1949,7 +1956,17 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print( rf_ast_types ); header.print( rf_ast_types );
header.print_fmt("\n#pragma endregion AST\n"); header.print_fmt("\n#pragma endregion AST\n");
header.print( fmt_newline);
header.print( rf_array_arena );
header.print( fmt_newline);
header.print( rf_array_pool);
header.print( fmt_newline);
header.print( rf_array_string_cached );
header.print( fmt_newline);
header.print( rf_ht_preprocessor_macro );
header.print( rf_interface ); header.print( rf_interface );
header.print( rf_constants );
header.print(fmt_newline); header.print(fmt_newline);
header.print_fmt("#pragma region Inlines\n"); header.print_fmt("#pragma region Inlines\n");
@ -1957,9 +1974,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print_fmt("#pragma endregion Inlines\n"); header.print_fmt("#pragma endregion Inlines\n");
header.print(fmt_newline); header.print(fmt_newline);
header.print( rf_array_string_cached );
header.print( rf_header_end );
header.print( rf_header_builder ); header.print( rf_header_builder );
header.print( rf_header_scanner ); header.print( rf_header_scanner );
@ -1976,11 +1991,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
builder_print( src, src_start ); builder_print( src, src_start );
src.print_fmt( "\nGEN_NS_BEGIN\n"); src.print_fmt( "\nGEN_NS_BEGIN\n");
src.print( fmt_newline);
src.print( rf_array_arena );
src.print( fmt_newline);
src.print( rf_array_pool);
src.print( r_src_static_data ); src.print( r_src_static_data );
src.print( fmt_newline); src.print( fmt_newline);
@ -1998,6 +2008,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
src.print( fmt_newline); src.print( fmt_newline);
src.print( rf_array_code_typename ); src.print( rf_array_code_typename );
src.print( fmt_newline); src.print( fmt_newline);
src.print( r_src_parser_case_macros );
src.print( rf_src_parser ); src.print( rf_src_parser );
src.print( r_src_parsing ); src.print( r_src_parsing );
src.print_fmt( "\n#pragma endregion Parsing\n" ); src.print_fmt( "\n#pragma endregion Parsing\n" );

View File

@ -53,6 +53,7 @@ word enum_underlying, gen_enum_underlying
word nullptr, gen_nullptr word nullptr, gen_nullptr
word struct_init, gen_struct_init word struct_init, gen_struct_init
word hash, gen_hash word hash, gen_hash
word txt, gen_txt
// Basic Types // Basic Types
@ -410,6 +411,8 @@ namespace var_, gen_var_
word _ctx, gen__ctx word _ctx, gen__ctx
word get_context, gen_get_context
word init, gen_init word init, gen_init
word deinit, gen_deinit word deinit, gen_deinit
word reset, gen_reset word reset, gen_reset
@ -532,7 +535,7 @@ namespace Lexer_, gen_Lexer_
word LexContext, gen_LexContext word LexContext, gen_LexContext
word lex, gen_lex word lex, gen_lex
word StackNode, gen_StackNode word ParseStackNode, gen_ParseStackNode
word ParseContext, gen_ParseContext word ParseContext, gen_ParseContext
// namespace parse_, gen_parse_ // namespace parse_, gen_parse_

View File

@ -13,7 +13,7 @@
| \_____|\___}_l |_|\___} .__/| .__/ {_____/ \__\__/_l\__. |\___/\__,_l \____}{_____}{_____} | | \_____|\___}_l |_|\___} .__/| .__/ {_____/ \__\__/_l\__. |\___/\__,_l \____}{_____}{_____} |
| | | | | __} | | | | | | | __} | |
| l_l l_l {___/ | | l_l l_l {___/ |
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha | ! ----------------------------------------------------------------------- VERSION: v0.25-Alpha |
! ============================================================================================= | ! ============================================================================================= |
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION | ! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL | ! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |

View File

@ -1,3 +1,6 @@
#define GEN_IMPLEMENTATION #define GEN_IMPLEMENTATION
#define GEN_DONT_ENFORCE_GEN_TIME_GUARD #define GEN_DONT_ENFORCE_GEN_TIME_GUARD
#define GEN_DEFINE_LIBRARY_CORE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND
#include "gen/gen_singleheader.h" #include "gen/gen_singleheader.h"

View File

@ -114,7 +114,7 @@ int gen_main()
} }
CodeBody gen_component_header = def_global_body( args( CodeBody gen_component_header = def_global_body( args(
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ), def_preprocess_cond( PreprocessCond_IfDef, txt("INTELLISENSE_DIRECTIVES") ),
pragma_once, pragma_once,
def_include(txt("components/types.hpp")), def_include(txt("components/types.hpp")),
preprocess_endif, preprocess_endif,
@ -131,8 +131,8 @@ int gen_main()
Code ast_types = scan_file( path_base "components/ast_types.hpp" ); Code ast_types = scan_file( path_base "components/ast_types.hpp" );
Code code_types = scan_file( path_base "components/code_types.hpp" ); Code code_types = scan_file( path_base "components/code_types.hpp" );
Code interface = scan_file( path_base "components/interface.hpp" ); Code interface = scan_file( path_base "components/interface.hpp" );
Code constants = scan_file( path_base "components/constants.hpp");
Code inlines = scan_file( path_base "components/inlines.hpp" ); Code inlines = scan_file( path_base "components/inlines.hpp" );
Code header_end = scan_file( path_base "components/header_end.hpp" );
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" ); CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" ); CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
@ -168,6 +168,7 @@ int gen_main()
builder_print_fmt( header, "\n#pragma endregion AST\n" ); builder_print_fmt( header, "\n#pragma endregion AST\n" );
builder_print( header, interface ); builder_print( header, interface );
builder_print( header, constants );
builder_print_fmt( header, "\n#pragma region Inlines\n" ); builder_print_fmt( header, "\n#pragma region Inlines\n" );
builder_print( header, inlines ); builder_print( header, inlines );
@ -176,7 +177,6 @@ int gen_main()
builder_print( header, fmt_newline ); builder_print( header, fmt_newline );
builder_print_fmt( header, "#pragma endregion Inlines\n" ); builder_print_fmt( header, "#pragma endregion Inlines\n" );
builder_print( header, header_end );
builder_print_fmt( header, "\nGEN_NS_END\n\n" ); builder_print_fmt( header, "\nGEN_NS_END\n\n" );
builder_print( header, pop_ignores ); builder_print( header, pop_ignores );
builder_write(header); builder_write(header);

View File

@ -15,7 +15,7 @@
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l | | \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
| Singleheader | | | | __} | | | Singleheader | | | | __} | |
| l_l l_l {___/ | | l_l l_l {___/ |
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha | ! ----------------------------------------------------------------------- VERSION: v0.25-Alpha |
! ============================================================================================ | ! ============================================================================================ |
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION | ! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL | ! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |

View File

@ -117,8 +117,8 @@ int gen_main()
Code ast_types = scan_file( path_base "components/ast_types.hpp" ); Code ast_types = scan_file( path_base "components/ast_types.hpp" );
Code code_types = scan_file( path_base "components/code_types.hpp" ); Code code_types = scan_file( path_base "components/code_types.hpp" );
Code interface = scan_file( path_base "components/interface.hpp" ); Code interface = scan_file( path_base "components/interface.hpp" );
Code constants = scan_file( path_base "components/constants.hpp" );
Code inlines = scan_file( path_base "components/inlines.hpp" ); Code inlines = scan_file( path_base "components/inlines.hpp" );
Code header_end = scan_file( path_base "components/header_end.hpp" );
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" ); CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" ); CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
@ -149,6 +149,7 @@ int gen_main()
header.print_fmt("\n#pragma endregion AST\n"); header.print_fmt("\n#pragma endregion AST\n");
header.print( interface ); header.print( interface );
header.print( constants );
header.print_fmt( "\n#pragma region Inlines\n" ); header.print_fmt( "\n#pragma region Inlines\n" );
header.print( inlines ); header.print( inlines );
@ -156,8 +157,6 @@ int gen_main()
header.print( fmt_newline ); header.print( fmt_newline );
header.print_fmt( "#pragma endregion Inlines\n" ); header.print_fmt( "#pragma endregion Inlines\n" );
header.print( header_end );
if ( generate_builder ) { if ( generate_builder ) {
header.print( scan_file( path_base "auxiliary/builder.hpp" ) ); header.print( scan_file( path_base "auxiliary/builder.hpp" ) );
} }

View File

@ -16,7 +16,7 @@
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l | | \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
| Unreal Engine | | | | __} | | | Unreal Engine | | | | __} | |
| l_l l_l {___/ | | l_l l_l {___/ |
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha | ! ----------------------------------------------------------------------- VERSION: v0.25-Alpha |
! ============================================================================================ | ! ============================================================================================ |
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION | ! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL | ! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |

View File

@ -24,4 +24,5 @@ Final, final
NoExceptions, noexcept NoExceptions, noexcept
Override, override Override, override
Pure, = 0 Pure, = 0
Delete, = delete
Volatile, volatile Volatile, volatile

1 Invalid INVALID
24 NoExceptions noexcept
25 Override override
26 Pure = 0
27 Delete = delete
28 Volatile volatile

View File

@ -224,8 +224,8 @@ int gen_main()
Code ast_types = scan_file( path_base "components/ast_types.hpp" ); Code ast_types = scan_file( path_base "components/ast_types.hpp" );
Code code_types = scan_file( path_base "components/code_types.hpp" ); Code code_types = scan_file( path_base "components/code_types.hpp" );
Code interface = scan_file( path_base "components/interface.hpp" ); Code interface = scan_file( path_base "components/interface.hpp" );
Code constants = scan_file( path_base "components/constants.hpp" );
Code inlines = scan_file( path_base "components/inlines.hpp" ); Code inlines = scan_file( path_base "components/inlines.hpp" );
Code header_end = scan_file( path_base "components/header_end.hpp" );
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" ); CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" ); CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
@ -266,6 +266,7 @@ int gen_main()
header.print_fmt( "\n#pragma endregion AST\n" ); header.print_fmt( "\n#pragma endregion AST\n" );
header.print( interface ); header.print( interface );
header.print( constants );
header.print_fmt( "\n#pragma region Inlines\n" ); header.print_fmt( "\n#pragma region Inlines\n" );
header.print( inlines ); header.print( inlines );
@ -274,7 +275,6 @@ int gen_main()
header.print( fmt_newline ); header.print( fmt_newline );
header.print_fmt( "#pragma endregion Inlines\n" ); header.print_fmt( "#pragma endregion Inlines\n" );
header.print( header_end );
header.print_fmt( "\nGEN_NS_END\n\n" ); header.print_fmt( "\nGEN_NS_END\n\n" );
header.print( pop_ignores ); header.print( pop_ignores );
header.write(); header.write();

View File

@ -172,7 +172,7 @@ if ( $segmented )
write-host `t $_ -ForegroundColor Green write-host `t $_ -ForegroundColor Green
} }
} }
write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms" write-host "`nSegmented completed in $($time_taken.TotalMilliseconds) ms"
} }
Pop-Location Pop-Location
} }
@ -263,6 +263,7 @@ if ( $c_lib_static )
$compiler_args += $flag_all_c $compiler_args += $flag_all_c
$compiler_args += $flag_updated_cpp_macro $compiler_args += $flag_updated_cpp_macro
$compiler_args += $flag_c11 $compiler_args += $flag_c11
$compiler_args += ($flag_define + 'GEN_STATIC_LINK')
$linker_args = @() $linker_args = @()
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $path_lib $result = build-simple $path_build $includes $compiler_args $linker_args $unit $path_lib

View File

@ -404,7 +404,7 @@ if ( $vendor -match "msvc" )
$flag_optimize_intrinsics = '/Oi' $flag_optimize_intrinsics = '/Oi'
$flag_optimized_debug_forceinline = '/d2Obforceinline' $flag_optimized_debug_forceinline = '/d2Obforceinline'
$flag_optimized_debug = '/Zo' $flag_optimized_debug = '/Zo'
$flag_ # $flag_
# $flag_out_name = '/OUT:' # $flag_out_name = '/OUT:'
$flag_path_interm = '/Fo' $flag_path_interm = '/Fo'
$flag_path_debug = '/Fd' $flag_path_debug = '/Fd'
@ -564,6 +564,7 @@ if ( $vendor -match "msvc" )
# Check if output is a static library # Check if output is a static library
if ( $binary -match '\.lib$' ) if ( $binary -match '\.lib$' )
{ {
write-host "Running archiver for $binary"
$lib_args = @() $lib_args = @()
$lib_args += $flag_nologo $lib_args += $flag_nologo
$lib_args += $flag_link_win_machine_64 $lib_args += $flag_link_win_machine_64

View File

@ -1,4 +1,4 @@
#if GEN_INTELLISENSE_DIRECTIVES #if INTELLISENSE_DIRECTIVES
#include "../../gen_c_library/gen/gen_singleheader.h" #include "../../gen_c_library/gen/gen_singleheader.h"
#endif #endif