Compare commits

..

No commits in common. "e4f564b165caeb1550da4ba44be8580b21585592" and "3c249d2fae1d52133063d66a3fc287d5562c558e" have entirely different histories.

60 changed files with 1230 additions and 2154 deletions

2
.gitignore vendored
View File

@ -39,5 +39,3 @@ gen_c_library/gen
**/*.vcxproj **/*.vcxproj
**/*.vcxproj.filters **/*.vcxproj.filters
**/*.vcxproj.user **/*.vcxproj.user
test/c_library/gen
test/cpp_library/gen

View File

@ -28,28 +28,6 @@
"/FC" "/FC"
] ]
}, },
{
"name": "Win32 clang",
"includePath": [
"${workspaceFolder}/base/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"GEN_TIME",
"GEN_IMPLEMENTATION",
// "GEN_DONT_USE_NAMESPACE"
"GEN_INTELLISENSE_DIRECTIVES",
"INTELLISENSE_DIRECTIVES"
],
"cStandard": "c11",
"cppStandard": "c++17",
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "clang++.exe",
"intelliSenseMode": "windows-clang-x64",
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
},
{ {
"name": "Win32 msvc c_library", "name": "Win32 msvc c_library",
"includePath": [ "includePath": [
@ -65,7 +43,6 @@
"GEN_INTELLISENSE_DIRECTIVES", "GEN_INTELLISENSE_DIRECTIVES",
"INTELLISENSE_DIRECTIVES" "INTELLISENSE_DIRECTIVES"
], ],
"cStandard": "c11",
"cppStandard": "c++17", "cppStandard": "c++17",
"windowsSdkVersion": "10.0.19041.0", "windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe", "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
@ -73,10 +50,9 @@
"compileCommands": "${workspaceFolder}/.vscode/tasks.json" "compileCommands": "${workspaceFolder}/.vscode/tasks.json"
}, },
{ {
"name": "Win32 msvc c_library test", "name": "Win32 clang",
"includePath": [ "includePath": [
"${workspaceFolder}/test/c_library/**", "${workspaceFolder}/base/**"
"${workspaceFolder}/gen_c_library/gen/**"
], ],
"defines": [ "defines": [
"_DEBUG", "_DEBUG",
@ -88,10 +64,9 @@
"GEN_INTELLISENSE_DIRECTIVES", "GEN_INTELLISENSE_DIRECTIVES",
"INTELLISENSE_DIRECTIVES" "INTELLISENSE_DIRECTIVES"
], ],
"cStandard": "c11",
"windowsSdkVersion": "10.0.19041.0", "windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe", "compilerPath": "clang++.exe",
"intelliSenseMode": "msvc-x64", "intelliSenseMode": "windows-clang-x64",
"compileCommands": "${workspaceFolder}/.vscode/tasks.json" "compileCommands": "${workspaceFolder}/.vscode/tasks.json"
} }
], ],

View File

@ -1,9 +1,6 @@
# gencpp # gencpp
An attempt at simple staged metaprogramming for C/C++. Reflect and generate code for your codebase at runtime! An attempt at simple staged metaprogramming for C/C++.
![splash-cpp](./docs/assets/Code_-_Insiders_2024-12-15_23-04-07.gif)
![splash-c](./docs/assets/Code_-_Insiders_2024-12-15_22-57-58.gif)
The library API is a composition of code element constructors, and a non-standards-compliant single-pass C/C++ parser. The library API is a composition of code element constructors, and a non-standards-compliant single-pass C/C++ parser.
These build up a code AST to then serialize with a file builder, or can be traversed for staged-reflection of C/C++ code. These build up a code AST to then serialize with a file builder, or can be traversed for staged-reflection of C/C++ code.
@ -52,11 +49,7 @@ Within `program.cpp` :
u32 gen_main() u32 gen_main()
{ {
gen::Context ctx;
gen::init(& ctx);
... ...
gen::deinit(& ctx);
return 0;
} }
#endif #endif

View File

@ -15,9 +15,7 @@ Builder builder_open( char const* path )
return result; return result;
} }
Context* ctx = get_context(); result.Buffer = strbuilder_make_reserve( _ctx->Allocator_Temp, _ctx->InitSize_BuilderBuffer );
GEN_ASSERT_NOT_NULL(ctx);
result.Buffer = strbuilder_make_reserve( ctx->Allocator_Temp, ctx->InitSize_BuilderBuffer );
// log_fmt("$Builder - Opened file: %s\n", result.File.filename ); // log_fmt("$Builder - Opened file: %s\n", result.File.filename );
return result; return result;

View File

@ -25,14 +25,13 @@ Builder builder_open ( char const* path );
void builder_pad_lines ( Builder* builder, s32 num ); void builder_pad_lines ( Builder* builder, s32 num );
void builder_print ( Builder* builder, Code code ); void builder_print ( Builder* builder, Code code );
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va ); void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va );
void builder_write ( Builder* builder ); void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
forceinline void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
va_list va; va_list va;
va_start( va, fmt ); va_start( va, fmt );
builder_print_fmt_va( builder, fmt, va ); builder_print_fmt_va( builder, fmt, va );
va_end( va ); va_end( va );
} }
void builder_write( Builder* builder );
struct Builder struct Builder
{ {
@ -57,10 +56,10 @@ struct Builder
}; };
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP #if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
forceinline void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); } void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
forceinline void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); } void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
forceinline void builder_write ( Builder& builder ) { return builder_write(& builder ); } void builder_write ( Builder& builder ) { return builder_write(& builder ); }
forceinline void builder_print_fmt( Builder& builder, char const* fmt, ...) { void builder_print_fmt( Builder& builder, char const* fmt, ...) {
va_list va; va_list va;
va_start( va, fmt ); va_start( va, fmt );
builder_print_fmt_va( & builder, fmt, va ); builder_print_fmt_va( & builder, fmt, va );

View File

@ -20,7 +20,7 @@ Code scan_file( char const* path )
GEN_FATAL("scan_file: %s is empty", path ); GEN_FATAL("scan_file: %s is empty", path );
} }
StrBuilder str = strbuilder_make_reserve( get_context()->Allocator_Temp, fsize ); StrBuilder str = strbuilder_make_reserve( _ctx->Allocator_Temp, fsize );
file_read( & file, str, fsize ); file_read( & file, str, fsize );
strbuilder_get_header(str)->Length = fsize; strbuilder_get_header(str)->Length = fsize;
@ -117,7 +117,7 @@ Code scan_file( char const* path )
} }
CodeBody parse_file( const char* path ) { CodeBody parse_file( const char* path ) {
FileContents file = file_read_contents( get_context()->Allocator_Temp, true, path ); FileContents file = file_read_contents( _ctx->Allocator_Temp, true, path );
Str content = { (char const*)file.data, file.size }; Str content = { (char const*)file.data, file.size };
CodeBody code = parse_global_body( content ); CodeBody code = parse_global_body( content );
log_fmt("\nParsed: %s\n", path); log_fmt("\nParsed: %s\n", path);

View File

@ -36,6 +36,7 @@ Str code_debug_str(Code self)
case CT_Execution: case CT_Execution:
case CT_Comment: case CT_Comment:
case CT_PlatformAttributes: case CT_PlatformAttributes:
case CT_Preprocess_Define:
case CT_Preprocess_Include: case CT_Preprocess_Include:
case CT_Preprocess_Pragma: case CT_Preprocess_Pragma:
case CT_Preprocess_If: case CT_Preprocess_If:
@ -51,11 +52,6 @@ Str code_debug_str(Code self)
strbuilder_append_fmt( result, "\n\tContent: %S", self->Content ); strbuilder_append_fmt( result, "\n\tContent: %S", self->Content );
break; break;
case CT_Preprocess_Define:
// TODO(ED): Needs implementaton
log_failure("code_debug_str: NOT IMPLEMENTED for CT_Preprocess_Define");
break;
case CT_Class: case CT_Class:
case CT_Struct: case CT_Struct:
if ( self->Prev ) if ( self->Prev )
@ -263,11 +259,6 @@ Str code_debug_str(Code self)
strbuilder_append_fmt( result, "\n\tValue : %S", self->Value ? strbuilder_to_str( code_to_strbuilder(self->Value)) : txt("Null") ); strbuilder_append_fmt( result, "\n\tValue : %S", self->Value ? strbuilder_to_str( code_to_strbuilder(self->Value)) : txt("Null") );
break; break;
case CT_Parameters_Define:
// TODO(ED): Needs implementaton
log_failure("code_debug_str: NOT IMPLEMENTED for CT_Parameters_Define");
break;
case CT_Specifiers: case CT_Specifiers:
{ {
strbuilder_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries ); strbuilder_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
@ -506,10 +497,6 @@ void code_to_strbuilder_ptr( Code self, StrBuilder* result )
params_to_strbuilder_ref(cast(CodeParams, self), result ); params_to_strbuilder_ref(cast(CodeParams, self), result );
break; break;
case CT_Parameters_Define:
define_params_to_strbuilder_ref(cast(CodeDefineParams, self), result);
break;
case CT_Preprocess_Define: case CT_Preprocess_Define:
define_to_strbuilder_ref(cast(CodeDefine, self), result ); define_to_strbuilder_ref(cast(CodeDefine, self), result );
break; break;
@ -1000,17 +987,11 @@ bool code_is_equal( Code self, Code other )
return true; return true;
} }
case CT_Parameters_Define:
{
// TODO(ED): Needs implementaton
log_failure("code_is_equal: NOT IMPLEMENTED for CT_Parameters_Define");
return false;
}
case CT_Preprocess_Define: case CT_Preprocess_Define:
{ {
check_member_str( Name ); check_member_str( Name );
check_member_content( Body->Content ); check_member_content( Content );
return true; return true;
} }

View File

@ -26,7 +26,6 @@ struct AST_Constructor;
// struct AST_BaseClass; // struct AST_BaseClass;
struct AST_Class; struct AST_Class;
struct AST_Define; struct AST_Define;
struct AST_DefineParams;
struct AST_Destructor; struct AST_Destructor;
struct AST_Enum; struct AST_Enum;
struct AST_Exec; struct AST_Exec;
@ -99,7 +98,6 @@ typedef AST_Comment* CodeComment;
typedef AST_Class* CodeClass; typedef AST_Class* CodeClass;
typedef AST_Constructor* CodeConstructor; typedef AST_Constructor* CodeConstructor;
typedef AST_Define* CodeDefine; typedef AST_Define* CodeDefine;
typedef AST_DefineParams* CodeDefineParams;
typedef AST_Destructor* CodeDestructor; typedef AST_Destructor* CodeDestructor;
typedef AST_Enum* CodeEnum; typedef AST_Enum* CodeEnum;
typedef AST_Exec* CodeExec; typedef AST_Exec* CodeExec;
@ -122,7 +120,6 @@ struct CodeComment;
struct CodeClass; struct CodeClass;
struct CodeConstructor; struct CodeConstructor;
struct CodeDefine; struct CodeDefine;
struct CodeDefineParams;
struct CodeDestructor; struct CodeDestructor;
struct CodeEnum; struct CodeEnum;
struct CodeExec; struct CodeExec;
@ -308,7 +305,6 @@ struct Code
operator CodeClass() const; operator CodeClass() const;
operator CodeConstructor() const; operator CodeConstructor() const;
operator CodeDefine() const; operator CodeDefine() const;
operator CodeDefineParams() const;
operator CodeDestructor() const; operator CodeDestructor() const;
operator CodeExec() const; operator CodeExec() const;
operator CodeEnum() const; operator CodeEnum() const;
@ -369,7 +365,6 @@ int AST_ArrSpecs_Cap =
/* /*
Simple AST POD with functionality to seralize into C++ syntax. Simple AST POD with functionality to seralize into C++ syntax.
TODO(Ed): Eventually haven't a transparent AST like this will longer be viable once statements & expressions are in (most likely....)
*/ */
struct AST struct AST
{ {
@ -377,7 +372,7 @@ struct AST
struct struct
{ {
Code InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable Code InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable // TODO(Ed): Parameters can have attributes Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
Code Specs; // Destructor, Function, Operator, Typename, Variable Code Specs; // Destructor, Function, Operator, Typename, Variable
union { union {
Code InitializerList; // Constructor Code InitializerList; // Constructor
@ -389,12 +384,12 @@ struct AST
union { union {
Code Macro; // Parameter Code Macro; // Parameter
Code BitfieldSize; // Variable (Class/Struct Data Member) Code BitfieldSize; // Variable (Class/Struct Data Member)
Code Params; // Constructor, Define, Function, Operator, Template, Typename Code Params; // Constructor, Function, Operator, Template, Typename
Code UnderlyingTypeMacro; // Enum Code UnderlyingTypeMacro; // Enum
}; };
union { union {
Code ArrExpr; // Typename Code ArrExpr; // Typename
Code Body; // Class, Constructor, Define, Destructor, Enum, Friend, Function, Namespace, Struct, Union Code Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union
Code Declaration; // Friend, Template Code Declaration; // Friend, Template
Code Value; // Parameter, Variable Code Value; // Parameter, Variable
}; };

View File

@ -42,14 +42,13 @@ struct AST_Body
}; };
static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Body is not the same size as AST"); static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Body is not the same size as AST");
// TODO(Ed): Support chaining attributes (Use parameter linkage pattern)
struct AST_Attributes struct AST_Attributes
{ {
union { union {
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StrCached Content; StrCached Content;
}; };
StrCached Name; StrCached Name;
Code Prev; Code Prev;
Code Next; Code Next;
Token* Tok; Token* Tok;
@ -147,15 +146,9 @@ struct AST_Define
{ {
union { union {
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct StrCached Content;
{
char _PAD_PROPERTIES_ [ sizeof(AST*) * 4 ];
CodeDefineParams Params;
Code Body; // Should be completely serialized for now to a: StrCached Content.
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 1 ];
};
}; };
StrCached Name; StrCached Name;
Code Prev; Code Prev;
Code Next; Code Next;
Token* Tok; Token* Tok;
@ -165,22 +158,6 @@ struct AST_Define
}; };
static_assert( sizeof(AST_Define) == sizeof(AST), "ERROR: AST_Define is not the same size as AST"); static_assert( sizeof(AST_Define) == sizeof(AST), "ERROR: AST_Define is not the same size as AST");
struct AST_DefineParams
{
union {
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
};
StrCached Name;
CodeDefineParams Last;
CodeDefineParams Next;
Token* Tok;
Code Parent;
CodeType Type;
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
s32 NumEntries;
};
static_assert( sizeof(AST_DefineParams) == sizeof(AST), "ERROR: AST_DefineParams is not the same size as AST");
struct AST_Destructor struct AST_Destructor
{ {
union { union {
@ -683,7 +660,6 @@ struct AST_Params
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
// TODO(Ed): Support attributes for parameters (Some prefix macros can be converted to that...)
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ]; char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
CodeTypename ValueType; CodeTypename ValueType;
Code Macro; Code Macro;
@ -692,7 +668,7 @@ struct AST_Params
// char _PAD_PROPERTIES_3_[sizeof( AST* )]; // char _PAD_PROPERTIES_3_[sizeof( AST* )];
}; };
}; };
StrCached Name; StrCached Name;
CodeParams Last; CodeParams Last;
CodeParams Next; CodeParams Next;
Token* Tok; Token* Tok;

View File

@ -176,7 +176,7 @@ void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
strbuilder_append_str( result, txt("class ") ); strbuilder_append_str( result, txt("class ") );
@ -221,7 +221,7 @@ void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes ) if ( self->Attributes )
@ -241,48 +241,12 @@ void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result )
StrBuilder define_to_strbuilder(CodeDefine define) StrBuilder define_to_strbuilder(CodeDefine define)
{ {
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 ); return strbuilder_fmt_buf( _ctx->Allocator_Temp, "#define %S %S", define->Name, define->Content );
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); strbuilder_append_fmt( result, "#define %S %S", define->Name, define->Content );
GEN_ASSERT(define->Body);
GEN_ASSERT(define->Body->Content.Ptr && define->Body->Content.Len > 0);
if (define->Params) {
StrBuilder params_builder = define_params_to_strbuilder(define->Params);
strbuilder_append_fmt( result, "#define %S(%S) %S", define->Name, strbuilder_to_str(params_builder), define->Body->Content );
}
else {
strbuilder_append_fmt( result, "#define %S %S", define->Name, define->Body->Content );
}
}
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)
{
GEN_ASSERT(self);
GEN_ASSERT(result);
if ( self->Name.Ptr && self->Name.Len )
{
strbuilder_append_fmt( result, " %S", self->Name );
}
if ( self->NumEntries - 1 > 0 )
{
for ( CodeDefineParams param = begin_CodeDefineParams(self->Next); param != end_CodeDefineParams(self->Next); param = next_CodeDefineParams(self->Next, param) )
{
strbuilder_append_fmt( result, ", %SB", define_params_to_strbuilder(param) );
}
}
} }
StrBuilder destructor_to_strbuilder(CodeDestructor self) StrBuilder destructor_to_strbuilder(CodeDestructor self)
@ -365,7 +329,7 @@ StrBuilder enum_to_strbuilder(CodeEnum self)
void enum_to_strbuilder_def(CodeEnum self, StrBuilder* result ) void enum_to_strbuilder_def(CodeEnum self, StrBuilder* result )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes || self->UnderlyingType || self->UnderlyingTypeMacro ) if ( self->Attributes || self->UnderlyingType || self->UnderlyingTypeMacro )
@ -398,7 +362,7 @@ 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 )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes ) if ( self->Attributes )
@ -425,7 +389,7 @@ 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 )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes || self->UnderlyingType ) if ( self->Attributes || self->UnderlyingType )
@ -457,7 +421,7 @@ 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 )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
strbuilder_append_str( result, txt("enum class ") ); strbuilder_append_str( result, txt("enum class ") );
@ -541,7 +505,7 @@ StrBuilder fn_to_strbuilder(CodeFn self)
void fn_to_strbuilder_def(CodeFn self, StrBuilder* result ) void fn_to_strbuilder_def(CodeFn self, StrBuilder* result )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export") ); strbuilder_append_str( result, txt("export") );
if ( self->Attributes ) if ( self->Attributes )
@ -594,7 +558,7 @@ 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 )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes ) if ( self->Attributes )
@ -682,7 +646,7 @@ StrBuilder namespace_to_strbuilder(CodeNS self)
void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result ) void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("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_append_fmt( result, "namespace %S\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
@ -707,7 +671,7 @@ 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 )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes ) if ( self->Attributes )
@ -761,7 +725,7 @@ 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 )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes ) if ( self->Attributes )
@ -901,6 +865,7 @@ void opcast_to_strbuilder_fwd(CodeOpCast self, StrBuilder* result )
StrBuilder params_to_strbuilder(CodeParams self) StrBuilder params_to_strbuilder(CodeParams self)
{ {
GEN_ASSERT(self);
GEN_ASSERT(self); GEN_ASSERT(self);
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 ); StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
params_to_strbuilder_ref( self, & result ); params_to_strbuilder_ref( self, & result );
@ -1036,24 +1001,12 @@ void specifiers_to_strbuilder_ref( CodeSpecifiers self, StrBuilder* result )
GEN_ASSERT(result); GEN_ASSERT(result);
s32 idx = 0; s32 idx = 0;
s32 left = self->NumEntries; s32 left = self->NumEntries;
while ( left -- ) while ( left-- )
{ {
Specifier spec = self->ArrSpecs[idx]; Str spec = spec_to_str( self->ArrSpecs[idx] );
Str spec_str = spec_to_str( spec ); strbuilder_append_fmt( result, "%.*s ", spec.Len, spec.Ptr );
if ( idx > 0 ) switch (spec) {
case Spec_Ptr:
case Spec_Ref:
case Spec_RValue:
break;
default:
strbuilder_append_str(result, txt(" "));
break;
}
strbuilder_append_fmt( result, "%S", spec_str );
idx++; idx++;
} }
strbuilder_append_str(result, txt(" "));
} }
StrBuilder struct_to_strbuilder(CodeStruct self) StrBuilder struct_to_strbuilder(CodeStruct self)
@ -1077,7 +1030,7 @@ void struct_to_strbuilder_def( CodeStruct self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
GEN_ASSERT(result); GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
strbuilder_append_str( result, txt("struct ") ); strbuilder_append_str( result, txt("struct ") );
@ -1123,7 +1076,7 @@ void struct_to_strbuilder_fwd( CodeStruct self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
GEN_ASSERT(result); GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes ) if ( self->Attributes )
@ -1152,7 +1105,7 @@ void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
GEN_ASSERT(result); GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Params ) if ( self->Params )
@ -1170,7 +1123,7 @@ StrBuilder typedef_to_strbuilder(CodeTypedef self)
void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result ) void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
strbuilder_append_str( result, txt("typedef ")); strbuilder_append_str( result, txt("typedef "));
@ -1283,7 +1236,7 @@ StrBuilder union_to_strbuilder(CodeUnion self)
void union_to_strbuilder_def(CodeUnion self, StrBuilder* result ) void union_to_strbuilder_def(CodeUnion self, StrBuilder* result )
{ {
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
strbuilder_append_str( result, txt("union ") ); strbuilder_append_str( result, txt("union ") );
@ -1314,7 +1267,7 @@ void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
GEN_ASSERT(result); GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
strbuilder_append_str( result, txt("union ") ); strbuilder_append_str( result, txt("union ") );
@ -1351,7 +1304,7 @@ void using_to_strbuilder_ref(CodeUsing self, StrBuilder* result )
{ {
GEN_ASSERT(self); GEN_ASSERT(self);
GEN_ASSERT(result); GEN_ASSERT(result);
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes ) if ( self->Attributes )
@ -1448,7 +1401,7 @@ void var_to_strbuilder_ref(CodeVar self, StrBuilder* result )
return; return;
} }
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
strbuilder_append_str( result, txt("export ") ); strbuilder_append_str( result, txt("export ") );
if ( self->Attributes || self->Specs ) if ( self->Attributes || self->Specs )
@ -1457,7 +1410,7 @@ void var_to_strbuilder_ref(CodeVar self, StrBuilder* result )
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) ); strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
if ( self->Specs ) if ( self->Specs )
strbuilder_append_fmt( result, "%SB", specifiers_to_strbuilder(self->Specs) ); strbuilder_append_fmt( result, "%SB\n", specifiers_to_strbuilder(self->Specs) );
strbuilder_append_fmt( result, "%SB %S", typename_to_strbuilder(self->ValueType), self->Name ); strbuilder_append_fmt( result, "%SB %S", typename_to_strbuilder(self->ValueType), self->Name );

View File

@ -32,17 +32,7 @@ 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 ); GEN_API void params_append (CodeParams params, CodeParams param );
GEN_API CodeDefineParams define_params_get (CodeDefineParams params, s32 idx);
GEN_API bool define_params_has_entries (CodeDefineParams params );
GEN_API StrBuilder define_params_to_strbuilder (CodeDefineParams params );
GEN_API void define_params_to_strbuilder_ref(CodeDefineParams params, StrBuilder* result );
GEN_API CodeDefineParams begin_CodeDefineParams(CodeDefineParams params);
GEN_API CodeDefineParams end_CodeDefineParams (CodeDefineParams params);
GEN_API CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter);
GEN_API void params_append (CodeParams appendee, CodeParams other );
GEN_API CodeParams params_get (CodeParams params, s32 idx); GEN_API CodeParams params_get (CodeParams params, s32 idx);
GEN_API bool params_has_entries (CodeParams params ); GEN_API bool params_has_entries (CodeParams params );
GEN_API StrBuilder params_to_strbuilder (CodeParams params ); GEN_API StrBuilder params_to_strbuilder (CodeParams params );
@ -202,11 +192,12 @@ struct CodeParams
{ {
#if ! GEN_C_LIKE_CPP #if ! GEN_C_LIKE_CPP
Using_Code( CodeParams ); Using_Code( CodeParams );
forceinline void append( CodeParams other ) { return params_append(* this, other); } forceinline void append( CodeParams other );
forceinline CodeParams get( s32 idx ) { return params_get( * this, idx); } forceinline CodeParams get( s32 idx );
forceinline bool has_entries() { return params_has_entries(* this); } forceinline bool has_entries();
forceinline StrBuilder to_strbuilder() { return params_to_strbuilder(* this); } forceinline StrBuilder to_strbuilder();
forceinline void to_strbuilder( StrBuilder& result ) { return params_to_strbuilder_ref(*this, & result); } forceinline void to_strbuilder( StrBuilder& result );
#endif #endif
Using_CodeOps( CodeParams ); Using_CodeOps( CodeParams );
forceinline CodeParams begin() { return begin_CodeParams(* this); } forceinline CodeParams begin() { return begin_CodeParams(* this); }
@ -221,29 +212,6 @@ struct CodeParams
AST_Params* ast; AST_Params* ast;
}; };
struct CodeDefineParams
{
#if ! GEN_C_LIKE_CPP
Using_Code( CodeDefineParams );
forceinline void append( CodeDefineParams other ) { return params_append( cast(CodeParams, * this), cast(CodeParams, other)); }
forceinline CodeDefineParams get( s32 idx ) { return (CodeDefineParams) (Code) params_get( cast(CodeParams, * this), idx); }
forceinline bool has_entries() { return params_has_entries( cast(CodeParams, * this)); }
forceinline StrBuilder to_strbuilder() { return define_params_to_strbuilder(* this); }
forceinline void to_strbuilder( StrBuilder& result ) { return define_params_to_strbuilder_ref(* this, & result); }
#endif
Using_CodeOps( CodeDefineParams );
forceinline CodeDefineParams begin() { return (CodeDefineParams) (Code) begin_CodeParams( cast(CodeParams, * this)); }
forceinline CodeDefineParams end() { return (CodeDefineParams) (Code) end_CodeParams( cast(CodeParams, * this)); }
forceinline operator Code() { return { (AST*)ast }; }
forceinline CodeDefineParams operator *() { return * this; } // Required to support for-range iteration.
forceinline AST_DefineParams* operator->() {
GEN_ASSERT(ast);
return ast;
}
forceinline CodeDefineParams& operator++();
AST_DefineParams* ast;
};
struct CodeSpecifiers struct CodeSpecifiers
{ {
#if ! GEN_C_LIKE_CPP #if ! GEN_C_LIKE_CPP
@ -973,7 +941,6 @@ struct InvalidCode_ImplictCaster
operator CodeClass () const { return cast(CodeClass, Code_Invalid); } operator CodeClass () const { return cast(CodeClass, Code_Invalid); }
operator CodeConstructor () const { return cast(CodeConstructor, Code_Invalid); } operator CodeConstructor () const { return cast(CodeConstructor, Code_Invalid); }
operator CodeDefine () const { return cast(CodeDefine, Code_Invalid); } operator CodeDefine () const { return cast(CodeDefine, Code_Invalid); }
operator CodeDefineParams () const { return cast(CodeDefineParams, Code_Invalid); }
operator CodeDestructor () const { return cast(CodeDestructor, Code_Invalid); } operator CodeDestructor () const { return cast(CodeDestructor, Code_Invalid); }
operator CodeExec () const { return cast(CodeExec, Code_Invalid); } operator CodeExec () const { return cast(CodeExec, Code_Invalid); }
operator CodeEnum () const { return cast(CodeEnum, Code_Invalid); } operator CodeEnum () const { return cast(CodeEnum, Code_Invalid); }
@ -1007,7 +974,6 @@ struct NullCode_ImplicitCaster
operator CodeClass () const { return {nullptr}; } operator CodeClass () const { return {nullptr}; }
operator CodeConstructor () const { return {nullptr}; } operator CodeConstructor () const { return {nullptr}; }
operator CodeDefine () const { return {nullptr}; } operator CodeDefine () const { return {nullptr}; }
operator CodeDefineParams () const { return {nullptr}; }
operator CodeDestructor () const { return {nullptr}; } operator CodeDestructor () const { return {nullptr}; }
operator CodeExec () const { return {nullptr}; } operator CodeExec () const { return {nullptr}; }
operator CodeEnum () const { return {nullptr}; } operator CodeEnum () const { return {nullptr}; }
@ -1058,23 +1024,17 @@ forceinline StrBuilder to_strbuilder ( CodeClass self )
forceinline void to_strbuilder_def( CodeClass self, StrBuilder& result ) { return class_to_strbuilder_def(self, & result); } forceinline void to_strbuilder_def( CodeClass self, StrBuilder& result ) { return class_to_strbuilder_def(self, & result); }
forceinline void to_strbuilder_fwd( CodeClass self, StrBuilder& result ) { return class_to_strbuilder_fwd(self, & result); } forceinline void to_strbuilder_fwd( CodeClass self, StrBuilder& result ) { return class_to_strbuilder_fwd(self, & result); }
forceinline void append (CodeDefineParams appendee, CodeDefineParams other ) { params_append(cast(CodeParams, appendee), cast(CodeParams, other)); } forceinline void append (CodeParams params, CodeParams param ) { return params_append(params, param); }
forceinline CodeDefineParams get (CodeDefineParams params, s32 idx) { return (CodeDefineParams) (Code) params_get(cast(CodeParams, params), idx); } forceinline CodeParams get (CodeParams params, s32 idx) { return params_get(params, idx); }
forceinline bool has_entries (CodeDefineParams params ) { return params_has_entries(cast(CodeParams, params)); } forceinline bool has_entries (CodeParams params ) { return params_has_entries(params); }
forceinline StrBuilder to_strbuilder(CodeDefineParams params ) { return define_params_to_strbuilder(params); } forceinline StrBuilder to_strbuilder(CodeParams params ) { return params_to_strbuilder(params); }
forceinline void to_strbuilder(CodeDefineParams params, StrBuilder& result ) { return define_params_to_strbuilder_ref(params, & result); } forceinline void to_strbuilder(CodeParams params, StrBuilder& result ) { return params_to_strbuilder_ref(params, & result); }
forceinline void append (CodeParams appendee, CodeParams other ) { return params_append(appendee, other); }
forceinline CodeParams get (CodeParams params, s32 idx) { return params_get(params, idx); }
forceinline bool has_entries (CodeParams params ) { return params_has_entries(params); }
forceinline StrBuilder to_strbuilder(CodeParams params ) { return params_to_strbuilder(params); }
forceinline void to_strbuilder(CodeParams params, StrBuilder& result ) { return params_to_strbuilder_ref(params, & result); }
forceinline bool append (CodeSpecifiers specifiers, Specifier spec) { return specifiers_append(specifiers, spec); } forceinline bool append (CodeSpecifiers specifiers, Specifier spec) { return specifiers_append(specifiers, spec); }
forceinline s32 has (CodeSpecifiers specifiers, Specifier spec) { return specifiers_has(specifiers, spec); } forceinline s32 has (CodeSpecifiers specifiers, Specifier spec) { return specifiers_has(specifiers, spec); }
forceinline s32 remove (CodeSpecifiers specifiers, Specifier to_remove ) { return specifiers_remove(specifiers, to_remove); } forceinline s32 remove (CodeSpecifiers specifiers, Specifier to_remove ) { return specifiers_remove(specifiers, to_remove); }
forceinline StrBuilder to_strbuilder(CodeSpecifiers specifiers) { return specifiers_to_strbuilder(specifiers); } forceinline StrBuilder to_strbuilder(CodeSpecifiers specifiers) { return specifiers_to_strbuilder(specifiers); }
forceinline void to_strbuilder(CodeSpecifiers specifiers, StrBuilder& result) { return specifiers_to_strbuilder_ref(specifiers, & result); } forceinline void to_strbuilder(CodeSpecifiers specifiers, StrBuilder& result) { return specifiers_to_strbuilder_ref(specifiers, & result); }
forceinline void add_interface (CodeStruct self, CodeTypename interface) { return struct_add_interface(self, interface); } forceinline void add_interface (CodeStruct self, CodeTypename interface) { return struct_add_interface(self, interface); }
forceinline StrBuilder to_strbuilder (CodeStruct self) { return struct_to_strbuilder(self); } forceinline StrBuilder to_strbuilder (CodeStruct self) { return struct_to_strbuilder(self); }

View File

@ -179,22 +179,6 @@ inline AST_Define* CodeDefine::operator->()
return ast; return ast;
} }
inline CodeDefineParams& CodeDefineParams::operator=( Code other )
{
if ( other.ast != nullptr && other->Parent != nullptr )
{
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
}
inline CodeDefineParams::operator bool()
{
return ast != nullptr;
}
inline CodeDestructor& CodeDestructor::operator=( Code other ) inline CodeDestructor& CodeDestructor::operator=( Code other )
{ {
if ( other.ast != nullptr && other->Parent != nullptr ) if ( other.ast != nullptr && other->Parent != nullptr )
@ -867,11 +851,6 @@ forceinline Code::operator CodeDefine() const
return { (AST_Define*)ast }; return { (AST_Define*)ast };
} }
forceinline Code::operator CodeDefineParams() const
{
return { (AST_DefineParams*)ast };
}
forceinline Code::operator CodeDestructor() const forceinline Code::operator CodeDestructor() const
{ {
return { (AST_Destructor*)ast }; return { (AST_Destructor*)ast };

View File

@ -46,7 +46,6 @@ enum CodeType : u32
CT_Operator_Cast, CT_Operator_Cast,
CT_Operator_Cast_Fwd, CT_Operator_Cast_Fwd,
CT_Parameters, CT_Parameters,
CT_Parameters_Define,
CT_Preprocess_Define, CT_Preprocess_Define,
CT_Preprocess_Include, CT_Preprocess_Include,
CT_Preprocess_If, CT_Preprocess_If,
@ -75,7 +74,7 @@ enum CodeType : u32
inline Str codetype_to_str( CodeType type ) inline Str codetype_to_str( CodeType type )
{ {
local_persist Str lookup[] = { local_persist Str lookup[61] = {
{ "Invalid", sizeof( "Invalid" ) - 1 }, { "Invalid", sizeof( "Invalid" ) - 1 },
{ "Untyped", sizeof( "Untyped" ) - 1 }, { "Untyped", sizeof( "Untyped" ) - 1 },
{ "NewLine", sizeof( "NewLine" ) - 1 }, { "NewLine", sizeof( "NewLine" ) - 1 },
@ -115,7 +114,6 @@ inline Str codetype_to_str( CodeType type )
{ "Operator_Cast", sizeof( "Operator_Cast" ) - 1 }, { "Operator_Cast", sizeof( "Operator_Cast" ) - 1 },
{ "Operator_Cast_Fwd", sizeof( "Operator_Cast_Fwd" ) - 1 }, { "Operator_Cast_Fwd", sizeof( "Operator_Cast_Fwd" ) - 1 },
{ "Parameters", sizeof( "Parameters" ) - 1 }, { "Parameters", sizeof( "Parameters" ) - 1 },
{ "Parameters_Define", sizeof( "Parameters_Define" ) - 1 },
{ "Preprocess_Define", sizeof( "Preprocess_Define" ) - 1 }, { "Preprocess_Define", sizeof( "Preprocess_Define" ) - 1 },
{ "Preprocess_Include", sizeof( "Preprocess_Include" ) - 1 }, { "Preprocess_Include", sizeof( "Preprocess_Include" ) - 1 },
{ "Preprocess_If", sizeof( "Preprocess_If" ) - 1 }, { "Preprocess_If", sizeof( "Preprocess_If" ) - 1 },
@ -144,7 +142,7 @@ inline Str codetype_to_str( CodeType type )
inline Str codetype_to_keyword_str( CodeType type ) inline Str codetype_to_keyword_str( CodeType type )
{ {
local_persist Str lookup[] = { local_persist Str lookup[61] = {
{ "__NA__", sizeof( "__NA__" ) - 1 }, { "__NA__", sizeof( "__NA__" ) - 1 },
{ "__NA__", sizeof( "__NA__" ) - 1 }, { "__NA__", sizeof( "__NA__" ) - 1 },
{ "__NA__", sizeof( "__NA__" ) - 1 }, { "__NA__", sizeof( "__NA__" ) - 1 },
@ -184,7 +182,6 @@ inline Str codetype_to_keyword_str( CodeType type )
{ "operator", sizeof( "operator" ) - 1 }, { "operator", sizeof( "operator" ) - 1 },
{ "operator", sizeof( "operator" ) - 1 }, { "operator", sizeof( "operator" ) - 1 },
{ "__NA__", sizeof( "__NA__" ) - 1 }, { "__NA__", sizeof( "__NA__" ) - 1 },
{ "__NA__", sizeof( "__NA__" ) - 1 },
{ "define", sizeof( "define" ) - 1 }, { "define", sizeof( "define" ) - 1 },
{ "include", sizeof( "include" ) - 1 }, { "include", sizeof( "include" ) - 1 },
{ "if", sizeof( "if" ) - 1 }, { "if", sizeof( "if" ) - 1 },

View File

@ -60,7 +60,7 @@ enum Operator : u32
inline Str operator_to_str( Operator op ) inline Str operator_to_str( Operator op )
{ {
local_persist Str lookup[] = { local_persist Str lookup[47] = {
{ "INVALID", sizeof( "INVALID" ) - 1 }, { "INVALID", sizeof( "INVALID" ) - 1 },
{ "=", sizeof( "=" ) - 1 }, { "=", sizeof( "=" ) - 1 },
{ "+=", sizeof( "+=" ) - 1 }, { "+=", sizeof( "+=" ) - 1 },

View File

@ -39,7 +39,7 @@ enum Specifier : u32
inline Str spec_to_str( Specifier type ) inline Str spec_to_str( Specifier type )
{ {
local_persist Str lookup[] = { local_persist Str lookup[26] = {
{ "INVALID", sizeof( "INVALID" ) - 1 }, { "INVALID", sizeof( "INVALID" ) - 1 },
{ "consteval", sizeof( "consteval" ) - 1 }, { "consteval", sizeof( "consteval" ) - 1 },
{ "constexpr", sizeof( "constexpr" ) - 1 }, { "constexpr", sizeof( "constexpr" ) - 1 },

View File

@ -24,8 +24,8 @@ enum TokType : u32
Tok_BraceCurly_Close, Tok_BraceCurly_Close,
Tok_BraceSquare_Open, Tok_BraceSquare_Open,
Tok_BraceSquare_Close, Tok_BraceSquare_Close,
Tok_Paren_Open, Tok_Capture_Start,
Tok_Paren_Close, Tok_Capture_End,
Tok_Comment, Tok_Comment,
Tok_Comment_End, Tok_Comment_End,
Tok_Comment_Start, Tok_Comment_Start,
@ -53,7 +53,6 @@ enum TokType : u32
Tok_Operator, Tok_Operator,
Tok_Preprocess_Hash, Tok_Preprocess_Hash,
Tok_Preprocess_Define, Tok_Preprocess_Define,
Tok_Preprocess_Define_Param,
Tok_Preprocess_If, Tok_Preprocess_If,
Tok_Preprocess_IfDef, Tok_Preprocess_IfDef,
Tok_Preprocess_IfNotDef, Tok_Preprocess_IfNotDef,
@ -63,9 +62,7 @@ enum TokType : u32
Tok_Preprocess_Include, Tok_Preprocess_Include,
Tok_Preprocess_Pragma, Tok_Preprocess_Pragma,
Tok_Preprocess_Content, Tok_Preprocess_Content,
Tok_Preprocess_Macro_Expr, Tok_Preprocess_Macro,
Tok_Preprocess_Macro_Stmt,
Tok_Preprocess_Macro_Typename,
Tok_Preprocess_Unsupported, Tok_Preprocess_Unsupported,
Tok_Spec_Alignas, Tok_Spec_Alignas,
Tok_Spec_Const, Tok_Spec_Const,
@ -114,105 +111,102 @@ enum TokType : u32
inline Str toktype_to_str( TokType type ) inline Str toktype_to_str( TokType type )
{ {
local_persist Str lookup[] = { local_persist Str lookup[] = {
{ "__invalid__", sizeof( "__invalid__" ) - 1 }, { "__invalid__", sizeof( "__invalid__" ) - 1 },
{ "private", sizeof( "private" ) - 1 }, { "private", sizeof( "private" ) - 1 },
{ "protected", sizeof( "protected" ) - 1 }, { "protected", sizeof( "protected" ) - 1 },
{ "public", sizeof( "public" ) - 1 }, { "public", sizeof( "public" ) - 1 },
{ ".", sizeof( "." ) - 1 }, { ".", sizeof( "." ) - 1 },
{ "::", sizeof( "::" ) - 1 }, { "::", sizeof( "::" ) - 1 },
{ "&", sizeof( "&" ) - 1 }, { "&", sizeof( "&" ) - 1 },
{ "&&", sizeof( "&&" ) - 1 }, { "&&", sizeof( "&&" ) - 1 },
{ ":", sizeof( ":" ) - 1 }, { ":", sizeof( ":" ) - 1 },
{ "[[", sizeof( "[[" ) - 1 }, { "[[", sizeof( "[[" ) - 1 },
{ "]]", sizeof( "]]" ) - 1 }, { "]]", sizeof( "]]" ) - 1 },
{ "{", sizeof( "{" ) - 1 }, { "{", sizeof( "{" ) - 1 },
{ "}", sizeof( "}" ) - 1 }, { "}", sizeof( "}" ) - 1 },
{ "[", sizeof( "[" ) - 1 }, { "[", sizeof( "[" ) - 1 },
{ "]", sizeof( "]" ) - 1 }, { "]", sizeof( "]" ) - 1 },
{ "(", sizeof( "(" ) - 1 }, { "(", sizeof( "(" ) - 1 },
{ ")", sizeof( ")" ) - 1 }, { ")", sizeof( ")" ) - 1 },
{ "__comment__", sizeof( "__comment__" ) - 1 }, { "__comment__", sizeof( "__comment__" ) - 1 },
{ "__comment_end__", sizeof( "__comment_end__" ) - 1 }, { "__comment_end__", sizeof( "__comment_end__" ) - 1 },
{ "__comment_start__", sizeof( "__comment_start__" ) - 1 }, { "__comment_start__", sizeof( "__comment_start__" ) - 1 },
{ "__character__", sizeof( "__character__" ) - 1 }, { "__character__", sizeof( "__character__" ) - 1 },
{ ",", sizeof( "," ) - 1 }, { ",", sizeof( "," ) - 1 },
{ "class", sizeof( "class" ) - 1 }, { "class", sizeof( "class" ) - 1 },
{ "__attribute__", sizeof( "__attribute__" ) - 1 }, { "__attribute__", sizeof( "__attribute__" ) - 1 },
{ "__declspec", sizeof( "__declspec" ) - 1 }, { "__declspec", sizeof( "__declspec" ) - 1 },
{ "enum", sizeof( "enum" ) - 1 }, { "enum", sizeof( "enum" ) - 1 },
{ "extern", sizeof( "extern" ) - 1 }, { "extern", sizeof( "extern" ) - 1 },
{ "friend", sizeof( "friend" ) - 1 }, { "friend", sizeof( "friend" ) - 1 },
{ "module", sizeof( "module" ) - 1 }, { "module", sizeof( "module" ) - 1 },
{ "namespace", sizeof( "namespace" ) - 1 }, { "namespace", sizeof( "namespace" ) - 1 },
{ "operator", sizeof( "operator" ) - 1 }, { "operator", sizeof( "operator" ) - 1 },
{ "struct", sizeof( "struct" ) - 1 }, { "struct", sizeof( "struct" ) - 1 },
{ "template", sizeof( "template" ) - 1 }, { "template", sizeof( "template" ) - 1 },
{ "typedef", sizeof( "typedef" ) - 1 }, { "typedef", sizeof( "typedef" ) - 1 },
{ "using", sizeof( "using" ) - 1 }, { "using", sizeof( "using" ) - 1 },
{ "union", sizeof( "union" ) - 1 }, { "union", sizeof( "union" ) - 1 },
{ "__identifier__", sizeof( "__identifier__" ) - 1 }, { "__identifier__", sizeof( "__identifier__" ) - 1 },
{ "import", sizeof( "import" ) - 1 }, { "import", sizeof( "import" ) - 1 },
{ "export", sizeof( "export" ) - 1 }, { "export", sizeof( "export" ) - 1 },
{ "__new_line__", sizeof( "__new_line__" ) - 1 }, { "__new_line__", sizeof( "__new_line__" ) - 1 },
{ "__number__", sizeof( "__number__" ) - 1 }, { "__number__", sizeof( "__number__" ) - 1 },
{ "__operator__", sizeof( "__operator__" ) - 1 }, { "__operator__", sizeof( "__operator__" ) - 1 },
{ "#", sizeof( "#" ) - 1 }, { "#", sizeof( "#" ) - 1 },
{ "define", sizeof( "define" ) - 1 }, { "define", sizeof( "define" ) - 1 },
{ "__define_param__", sizeof( "__define_param__" ) - 1 }, { "if", sizeof( "if" ) - 1 },
{ "if", sizeof( "if" ) - 1 }, { "ifdef", sizeof( "ifdef" ) - 1 },
{ "ifdef", sizeof( "ifdef" ) - 1 }, { "ifndef", sizeof( "ifndef" ) - 1 },
{ "ifndef", sizeof( "ifndef" ) - 1 }, { "elif", sizeof( "elif" ) - 1 },
{ "elif", sizeof( "elif" ) - 1 }, { "else", sizeof( "else" ) - 1 },
{ "else", sizeof( "else" ) - 1 }, { "endif", sizeof( "endif" ) - 1 },
{ "endif", sizeof( "endif" ) - 1 }, { "include", sizeof( "include" ) - 1 },
{ "include", sizeof( "include" ) - 1 }, { "pragma", sizeof( "pragma" ) - 1 },
{ "pragma", sizeof( "pragma" ) - 1 }, { "__macro_content__", sizeof( "__macro_content__" ) - 1 },
{ "__macro_content__", sizeof( "__macro_content__" ) - 1 }, { "__macro__", sizeof( "__macro__" ) - 1 },
{ "__macro_expression__", sizeof( "__macro_expression__" ) - 1 }, { "__unsupported__", sizeof( "__unsupported__" ) - 1 },
{ "__macro_statment__", sizeof( "__macro_statment__" ) - 1 }, { "alignas", sizeof( "alignas" ) - 1 },
{ "__macro_typename__", sizeof( "__macro_typename__" ) - 1 }, { "const", sizeof( "const" ) - 1 },
{ "__unsupported__", sizeof( "__unsupported__" ) - 1 }, { "consteval", sizeof( "consteval" ) - 1 },
{ "alignas", sizeof( "alignas" ) - 1 }, { "constexpr", sizeof( "constexpr" ) - 1 },
{ "const", sizeof( "const" ) - 1 }, { "constinit", sizeof( "constinit" ) - 1 },
{ "consteval", sizeof( "consteval" ) - 1 }, { "explicit", sizeof( "explicit" ) - 1 },
{ "constexpr", sizeof( "constexpr" ) - 1 }, { "extern", sizeof( "extern" ) - 1 },
{ "constinit", sizeof( "constinit" ) - 1 }, { "final", sizeof( "final" ) - 1 },
{ "explicit", sizeof( "explicit" ) - 1 }, { "forceinline", sizeof( "forceinline" ) - 1 },
{ "extern", sizeof( "extern" ) - 1 }, { "global", sizeof( "global" ) - 1 },
{ "final", sizeof( "final" ) - 1 }, { "inline", sizeof( "inline" ) - 1 },
{ "forceinline", sizeof( "forceinline" ) - 1 }, { "internal", sizeof( "internal" ) - 1 },
{ "global", sizeof( "global" ) - 1 }, { "local_persist", sizeof( "local_persist" ) - 1 },
{ "inline", sizeof( "inline" ) - 1 }, { "mutable", sizeof( "mutable" ) - 1 },
{ "internal", sizeof( "internal" ) - 1 }, { "neverinline", sizeof( "neverinline" ) - 1 },
{ "local_persist", sizeof( "local_persist" ) - 1 }, { "override", sizeof( "override" ) - 1 },
{ "mutable", sizeof( "mutable" ) - 1 }, { "static", sizeof( "static" ) - 1 },
{ "neverinline", sizeof( "neverinline" ) - 1 }, { "thread_local", sizeof( "thread_local" ) - 1 },
{ "override", sizeof( "override" ) - 1 }, { "volatile", sizeof( "volatile" ) - 1 },
{ "static", sizeof( "static" ) - 1 }, { "virtual", sizeof( "virtual" ) - 1 },
{ "thread_local", sizeof( "thread_local" ) - 1 }, { "*", sizeof( "*" ) - 1 },
{ "volatile", sizeof( "volatile" ) - 1 }, { ";", sizeof( ";" ) - 1 },
{ "virtual", sizeof( "virtual" ) - 1 }, { "static_assert", sizeof( "static_assert" ) - 1 },
{ "*", sizeof( "*" ) - 1 }, { "__string__", sizeof( "__string__" ) - 1 },
{ ";", sizeof( ";" ) - 1 }, { "typename", sizeof( "typename" ) - 1 },
{ "static_assert", sizeof( "static_assert" ) - 1 }, { "unsigned", sizeof( "unsigned" ) - 1 },
{ "__string__", sizeof( "__string__" ) - 1 }, { "signed", sizeof( "signed" ) - 1 },
{ "typename", sizeof( "typename" ) - 1 }, { "short", sizeof( "short" ) - 1 },
{ "unsigned", sizeof( "unsigned" ) - 1 }, { "long", sizeof( "long" ) - 1 },
{ "signed", sizeof( "signed" ) - 1 }, { "bool", sizeof( "bool" ) - 1 },
{ "short", sizeof( "short" ) - 1 }, { "char", sizeof( "char" ) - 1 },
{ "long", sizeof( "long" ) - 1 }, { "int", sizeof( "int" ) - 1 },
{ "bool", sizeof( "bool" ) - 1 }, { "double", sizeof( "double" ) - 1 },
{ "char", sizeof( "char" ) - 1 }, { "__int8", sizeof( "__int8" ) - 1 },
{ "int", sizeof( "int" ) - 1 }, { "__int16", sizeof( "__int16" ) - 1 },
{ "double", sizeof( "double" ) - 1 }, { "__int32", sizeof( "__int32" ) - 1 },
{ "__int8", sizeof( "__int8" ) - 1 }, { "__int64", sizeof( "__int64" ) - 1 },
{ "__int16", sizeof( "__int16" ) - 1 }, { "_W64", sizeof( "_W64" ) - 1 },
{ "__int32", sizeof( "__int32" ) - 1 }, { "...", sizeof( "..." ) - 1 },
{ "__int64", sizeof( "__int64" ) - 1 }, { "__attrib_start__", sizeof( "__attrib_start__" ) - 1 },
{ "_W64", sizeof( "_W64" ) - 1 }, { "GEN_API", sizeof( "GEN_API" ) - 1 },
{ "...", sizeof( "..." ) - 1 },
{ "__attrib_start__", sizeof( "__attrib_start__" ) - 1 },
{ "GEN_API", sizeof( "GEN_API" ) - 1 },
}; };
return lookup[type]; return lookup[type];
} }

View File

@ -6,7 +6,7 @@
#pragma region Constants #pragma region Constants
extern Macro enum_underlying_macro; extern Str enum_underlying_sig;
extern Code access_public; extern Code access_public;
extern Code access_protected; extern Code access_protected;

View File

@ -15,7 +15,7 @@
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l | | \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
| | | | | __} | | | | | | | __} | |
| l_l l_l {___/ | | l_l l_l {___/ |
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha | ! ----------------------------------------------------------------------- VERSION: v0.20-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

@ -257,25 +257,6 @@ CodeParams next_CodeParams(CodeParams params, CodeParams param_iter)
} }
#pragma endregion CodeParams #pragma endregion CodeParams
#pragma region CodeDefineParams
forceinline void define_params_append (CodeDefineParams appendee, CodeDefineParams other ) { params_append( cast(CodeParams, appendee), cast(CodeParams, other) ); }
forceinline CodeDefineParams define_params_get (CodeDefineParams self, s32 idx ) { return (CodeDefineParams) (Code) params_get( cast(CodeParams, self), idx); }
forceinline bool define_params_has_entries(CodeDefineParams self) { return params_has_entries( cast(CodeParams, self)); }
forceinline CodeDefineParams begin_CodeDefineParams(CodeDefineParams params) { return (CodeDefineParams) (Code) begin_CodeParams( cast(CodeParams, (Code)params)); }
forceinline CodeDefineParams end_CodeDefineParams (CodeDefineParams params) { return (CodeDefineParams) (Code) end_CodeParams ( cast(CodeParams, (Code)params)); }
forceinline CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter) { return (CodeDefineParams) (Code) next_CodeParams ( cast(CodeParams, (Code)params), cast(CodeParams, (Code)entry_iter)); }
#if GEN_COMPILER_CPP
forceinline
CodeDefineParams& CodeDefineParams::operator ++()
{
* this = ast->Next;
return * this;
}
#endif
#pragma endregion CodeDefineParams
#pragma region CodeSpecifiers #pragma region CodeSpecifiers
inline inline
bool specifiers_append(CodeSpecifiers self, Specifier spec ) bool specifiers_append(CodeSpecifiers self, Specifier spec )

View File

@ -179,39 +179,37 @@ void define_constants()
#endif #endif
spec_const = def_specifier( Spec_Const); code_set_global( cast(Code, spec_const )); spec_const = def_specifier( Spec_Const); code_set_global( cast(Code, spec_const ));
spec_consteval = def_specifier( Spec_Consteval); code_set_global( cast(Code, spec_consteval )); spec_consteval = def_specifier( Spec_Consteval); code_set_global( cast(Code, spec_consteval ));;
spec_constexpr = def_specifier( Spec_Constexpr); code_set_global( cast(Code, spec_constexpr )); spec_constexpr = def_specifier( Spec_Constexpr); code_set_global( cast(Code, spec_constexpr ));;
spec_constinit = def_specifier( Spec_Constinit); code_set_global( cast(Code, spec_constinit )); spec_constinit = def_specifier( Spec_Constinit); code_set_global( cast(Code, spec_constinit ));;
spec_extern_linkage = def_specifier( Spec_External_Linkage); code_set_global( cast(Code, spec_extern_linkage )); spec_extern_linkage = def_specifier( Spec_External_Linkage); code_set_global( cast(Code, spec_extern_linkage ));;
spec_final = def_specifier( Spec_Final); code_set_global( cast(Code, spec_final )); spec_final = def_specifier( Spec_Final); code_set_global( cast(Code, spec_final ));;
spec_forceinline = def_specifier( Spec_ForceInline); code_set_global( cast(Code, spec_forceinline )); spec_forceinline = def_specifier( Spec_ForceInline); code_set_global( cast(Code, spec_forceinline ));;
spec_global = def_specifier( Spec_Global); code_set_global( cast(Code, spec_global )); spec_global = def_specifier( Spec_Global); code_set_global( cast(Code, spec_global ));;
spec_inline = def_specifier( Spec_Inline); code_set_global( cast(Code, spec_inline )); spec_inline = def_specifier( Spec_Inline); code_set_global( cast(Code, spec_inline ));;
spec_internal_linkage = def_specifier( Spec_Internal_Linkage); code_set_global( cast(Code, spec_internal_linkage )); spec_internal_linkage = def_specifier( Spec_Internal_Linkage); code_set_global( cast(Code, spec_internal_linkage ));;
spec_local_persist = def_specifier( Spec_Local_Persist); code_set_global( cast(Code, spec_local_persist )); spec_local_persist = def_specifier( Spec_Local_Persist); code_set_global( cast(Code, spec_local_persist ));;
spec_mutable = def_specifier( Spec_Mutable); code_set_global( cast(Code, spec_mutable )); spec_mutable = def_specifier( Spec_Mutable); code_set_global( cast(Code, spec_mutable ));;
spec_neverinline = def_specifier( Spec_NeverInline); code_set_global( cast(Code, spec_neverinline )); spec_neverinline = def_specifier( Spec_NeverInline); code_set_global( cast(Code, spec_neverinline ));;
spec_noexcept = def_specifier( Spec_NoExceptions); code_set_global( cast(Code, spec_noexcept )); spec_noexcept = def_specifier( Spec_NoExceptions); code_set_global( cast(Code, spec_noexcept ));;
spec_override = def_specifier( Spec_Override); code_set_global( cast(Code, spec_override )); spec_override = def_specifier( Spec_Override); code_set_global( cast(Code, spec_override ));;
spec_ptr = def_specifier( Spec_Ptr); code_set_global( cast(Code, spec_ptr )); spec_ptr = def_specifier( Spec_Ptr); code_set_global( cast(Code, spec_ptr ));;
spec_pure = def_specifier( Spec_Pure); code_set_global( cast(Code, spec_pure )); spec_pure = def_specifier( Spec_Pure); code_set_global( cast(Code, spec_pure ));
spec_ref = def_specifier( Spec_Ref); code_set_global( cast(Code, spec_ref )); spec_ref = def_specifier( Spec_Ref); code_set_global( cast(Code, spec_ref ));;
spec_register = def_specifier( Spec_Register); code_set_global( cast(Code, spec_register )); spec_register = def_specifier( Spec_Register); code_set_global( cast(Code, spec_register ));;
spec_rvalue = def_specifier( Spec_RValue); code_set_global( cast(Code, spec_rvalue )); spec_rvalue = def_specifier( Spec_RValue); code_set_global( cast(Code, spec_rvalue ));;
spec_static_member = def_specifier( Spec_Static); code_set_global( cast(Code, spec_static_member )); spec_static_member = def_specifier( Spec_Static); code_set_global( cast(Code, spec_static_member ));;
spec_thread_local = def_specifier( Spec_Thread_Local); code_set_global( cast(Code, spec_thread_local )); spec_thread_local = def_specifier( Spec_Thread_Local); code_set_global( cast(Code, spec_thread_local ));;
spec_virtual = def_specifier( Spec_Virtual); code_set_global( cast(Code, spec_virtual )); spec_virtual = def_specifier( Spec_Virtual); code_set_global( cast(Code, spec_virtual ));;
spec_volatile = def_specifier( Spec_Volatile); code_set_global( cast(Code, spec_volatile )); spec_volatile = def_specifier( Spec_Volatile); code_set_global( cast(Code, spec_volatile ));
spec_local_persist = def_specifiers( 1, Spec_Local_Persist ); spec_local_persist = def_specifiers( 1, Spec_Local_Persist );
code_set_global(cast(Code, spec_local_persist)); code_set_global(cast(Code, spec_local_persist));
if (enum_underlying_macro.Name.Len == 0) { if (enum_underlying_sig.Len == 0) {
enum_underlying_macro.Name = txt("enum_underlying"); enum_underlying_sig = txt("enum_underlying(");
enum_underlying_macro.Type = MT_Expression;
enum_underlying_macro.Flags = MF_Functional;
} }
register_macro(enum_underlying_macro); array_append( _ctx->PreprocessorDefines, enum_underlying_sig);
} }
void init(Context* ctx) void init(Context* ctx)
@ -272,8 +270,8 @@ void init(Context* ctx)
ctx->CodePool_NumBlocks = kilobytes(16); ctx->CodePool_NumBlocks = kilobytes(16);
} }
if (ctx->InitSize_LexerTokens == 0 ) { if (ctx->InitSize_LexArena == 0 ) {
ctx->InitSize_LexerTokens = kilobytes(64); ctx->InitSize_LexArena = megabytes(4);
} }
if (ctx->SizePer_StringArena == 0) { if (ctx->SizePer_StringArena == 0) {
ctx->SizePer_StringArena = megabytes(1); ctx->SizePer_StringArena = megabytes(1);
@ -303,6 +301,9 @@ void init(Context* ctx)
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 );
// TODO(Ed): This is going to be phased out most likely.
ctx->LexArena = arena_init_from_allocator( ctx->Allocator_DyanmicContainers, ctx->InitSize_LexArena );
// TODO(Ed): Eventually the string arenas needs to be phased out for a dedicated string slab allocator // TODO(Ed): Eventually the string arenas needs to be phased out for a dedicated string slab allocator
Arena strbuilder_arena = arena_init_from_allocator( ctx->Allocator_StrCache, ctx->SizePer_StringArena ); Arena strbuilder_arena = arena_init_from_allocator( ctx->Allocator_StrCache, ctx->SizePer_StringArena );
if ( strbuilder_arena.PhysicalStart == nullptr ) if ( strbuilder_arena.PhysicalStart == nullptr )
@ -314,12 +315,9 @@ void init(Context* ctx)
ctx->StrCache = hashtable_init(StrCached, ctx->Allocator_DyanmicContainers); ctx->StrCache = hashtable_init(StrCached, ctx->Allocator_DyanmicContainers);
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);
if (ctx->Macros.Hashes == nullptr || ctx->Macros.Entries == nullptr) {
GEN_FATAL( "gen::init: Failed to initialize the PreprocessMacros table" );
}
} }
// Preprocessor Defines
ctx->PreprocessorDefines = array_init_reserve(StrCached, ctx->Allocator_DyanmicContainers, kilobytes(1) );
define_constants(); define_constants();
parser_init(); parser_init();
@ -356,7 +354,9 @@ void deinit(Context* ctx)
array_free( ctx->CodePools); array_free( ctx->CodePools);
array_free( ctx->StringArenas); array_free( ctx->StringArenas);
hashtable_destroy(ctx->Macros); arena_free(& ctx->LexArena);
array_free(ctx->PreprocessorDefines);
left = array_num( ctx->Fallback_AllocatorBuckets); left = array_num( ctx->Fallback_AllocatorBuckets);
if (left) if (left)
@ -376,13 +376,6 @@ void deinit(Context* ctx)
if (_ctx == ctx) if (_ctx == ctx)
_ctx = nullptr; _ctx = nullptr;
-- context_counter; -- context_counter;
Context wipe = {};
* ctx = wipe;
}
Context* get_context() {
return _ctx;
} }
void reset(Context* ctx) void reset(Context* ctx)
@ -408,7 +401,6 @@ void reset(Context* ctx)
while ( left--, left ); while ( left--, left );
hashtable_clear(ctx->StrCache); hashtable_clear(ctx->StrCache);
hashtable_clear(ctx->Macros);
define_constants(); define_constants();
} }
@ -471,51 +463,10 @@ Code make_code()
return result; return result;
} }
Macro* lookup_macro( Str name ) { void set_preprocess_define( Str id, b32 is_functional ) {
u32 key = crc32( name.Ptr, name.Len ); StrBuilder builder = strbuilder_make_str( _ctx->Allocator_Temp, id );
return hashtable_get( _ctx->Macros, key ); if (is_functional) {
} strbuilder_append_char( & builder, '(' );
void register_macro( Macro macro ) {
GEN_ASSERT_NOT_NULL(macro.Name.Ptr);
GEN_ASSERT(macro.Name.Len > 0);
u32 key = crc32( macro.Name.Ptr, macro.Name.Len );
macro.Name = cache_str(macro.Name);
hashtable_set( _ctx->Macros, key, macro );
}
void register_macros( s32 num, ... )
{
GEN_ASSERT(num > 0);
va_list va;
va_start(va, num);
do
{
Macro macro = va_arg(va, Macro);
GEN_ASSERT_NOT_NULL(macro.Name.Ptr);
GEN_ASSERT(macro.Name.Len > 0);
macro.Name = cache_str(macro.Name);
u32 key = crc32( macro.Name.Ptr, macro.Name.Len );
hashtable_set( _ctx->Macros, key, macro );
} }
while (num--, num > 0); array_append( _ctx->PreprocessorDefines, cache_str( strbuilder_to_str(builder)) );
va_end(va);
}
void register_macros_arr( s32 num, Macro* macros )
{
GEN_ASSERT(num > 0);
do
{
Macro macro = * macros;
GEN_ASSERT_NOT_NULL(macro.Name.Ptr);
GEN_ASSERT(macro.Name.Len > 0);
macro.Name = cache_str(macro.Name);
u32 key = crc32( macro.Name.Ptr, macro.Name.Len );
hashtable_set( _ctx->Macros, key, macro );
++ macros;
}
while (num--, num > 0);
} }

View File

@ -60,7 +60,7 @@ struct Context
u32 CodePool_NumBlocks; u32 CodePool_NumBlocks;
// TODO(Ed): Review these... (No longer needed if using the proper allocation strategy) // TODO(Ed): Review these... (No longer needed if using the proper allocation strategy)
u32 InitSize_LexerTokens; u32 InitSize_LexArena;
u32 SizePer_StringArena; u32 SizePer_StringArena;
// TODO(Ed): Symbol Table // TODO(Ed): Symbol Table
@ -71,7 +71,7 @@ struct Context
// 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.
// Populate with strings via gen::cache_str. // Populate with strings via gen::cache_str.
// Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments. // Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments.
MacroTable Macros; Array(StrCached) PreprocessorDefines;
// Backend // Backend
@ -79,8 +79,6 @@ struct Context
u32 InitSize_Fallback_Allocator_Bucket_Size; u32 InitSize_Fallback_Allocator_Bucket_Size;
Array(Arena) Fallback_AllocatorBuckets; Array(Arena) Fallback_AllocatorBuckets;
StringTable token_fmt_map;
// Array(Token) LexerTokens; // Array(Token) LexerTokens;
Array(Pool) CodePools; Array(Pool) CodePools;
@ -89,13 +87,13 @@ struct Context
StringTable StrCache; StringTable StrCache;
// TODO(Ed): This needs to be just handled by a parser context // TODO(Ed): This needs to be just handled by a parser context
Arena LexArena;
StringTable Lexer_defines;
Array(Token) Lexer_Tokens; Array(Token) Lexer_Tokens;
// TODO(Ed): Active parse context vs a parse result need to be separated conceptually // TODO(Ed): Active parse context vs a parse result need to be separated conceptually
ParseContext parser; ParseContext parser;
// TODO(Ed): Formatting - This will eventually be in a separate struct when in the process of serialization of the builder.
s32 temp_serialize_indent;
}; };
// 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
@ -105,30 +103,15 @@ GEN_API void init(Context* ctx);
// However on Windows at least, it doesn't need to occur as the OS will clean up after the process. // However on Windows at least, it doesn't need to occur as the OS will clean up after the process.
GEN_API void deinit(Context* ctx); GEN_API void deinit(Context* ctx);
// Retrieves the active context (not usually needed, but here in case...)
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 memoery, then calls init() again.
// Ease of use. // Ease of use.
GEN_API void reset(Context* ctx); GEN_API void reset(Context* ctx);
GEN_API void set_context(Context* ctx); GEN_API void set_context(Context* ctx);
// Mostly intended for the parser
GEN_API Macro* lookup_macro( Str Name );
// Alternative way to add a preprocess define entry for the lexer & parser to utilize // Alternative way to add a preprocess define entry for the lexer & parser to utilize
// if the user doesn't want to use def_define // if the user doesn't want to use def_define
// Macros are tracked by name so if the name already exists the entry will be overwritten. GEN_API void set_preprocess_define( Str id, b32 is_functional );
GEN_API void register_macro( Macro macro );
// Ease of use batch registration
GEN_API void register_macros( s32 num, ... );
GEN_API void register_macros_arr( s32 num, Macro* macros );
#if GEN_COMPILER_CPP
forceinline void register_macros( s32 num, Macro* macros ) { return register_macros_arr(num, macros); }
#endif
// Used internally to retrive or make string allocations. // Used internally to retrive or make string allocations.
// Strings are stored in a series of string arenas of fixed size (SizePer_StringArena) // Strings are stored in a series of string arenas of fixed size (SizePer_StringArena)
@ -167,12 +150,9 @@ struct Opts_def_constructor {
GEN_API CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT ); GEN_API CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT );
struct Opts_def_define { struct Opts_def_define {
CodeDefineParams params; b32 dont_append_preprocess_defines;
Str content;
MacroFlags flags;
b32 dont_register_to_preprocess_macros;
}; };
GEN_API CodeDefine def_define( Str name, MacroType type, Opts_def_define opts GEN_PARAM_DEFAULT ); GEN_API CodeDefine def_define( Str name, Str content, Opts_def_define opts GEN_PARAM_DEFAULT );
struct Opts_def_destructor { struct Opts_def_destructor {
Code body; Code body;
@ -283,45 +263,28 @@ GEN_API 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.
GEN_API CodeBody def_class_body ( s32 num, ... ); GEN_API CodeBody def_class_body ( s32 num, ... );
GEN_API CodeBody def_class_body_arr ( s32 num, Code* codes ); GEN_API CodeBody def_class_body ( s32 num, Code* codes );
GEN_API CodeDefineParams def_define_params ( s32 num, ... ); GEN_API CodeBody def_enum_body ( s32 num, ... );
GEN_API CodeDefineParams def_define_params_arr ( s32 num, CodeDefineParams* codes ); GEN_API CodeBody def_enum_body ( s32 num, Code* codes );
GEN_API CodeBody def_enum_body ( s32 num, ... ); GEN_API CodeBody def_export_body ( s32 num, ... );
GEN_API CodeBody def_enum_body_arr ( s32 num, Code* codes ); GEN_API CodeBody def_export_body ( s32 num, Code* codes);
GEN_API CodeBody def_export_body ( s32 num, ... ); GEN_API CodeBody def_extern_link_body( s32 num, ... );
GEN_API CodeBody def_export_body_arr ( s32 num, Code* codes); GEN_API CodeBody def_extern_link_body( s32 num, Code* codes );
GEN_API CodeBody def_extern_link_body ( s32 num, ... ); GEN_API CodeBody def_function_body ( s32 num, ... );
GEN_API CodeBody def_extern_link_body_arr ( s32 num, Code* codes ); GEN_API CodeBody def_function_body ( s32 num, Code* codes );
GEN_API CodeBody def_function_body ( s32 num, ... ); GEN_API CodeBody def_global_body ( s32 num, ... );
GEN_API CodeBody def_function_body_arr ( s32 num, Code* codes ); GEN_API CodeBody def_global_body ( s32 num, Code* codes );
GEN_API CodeBody def_global_body ( s32 num, ... ); GEN_API CodeBody def_namespace_body ( s32 num, ... );
GEN_API CodeBody def_global_body_arr ( s32 num, Code* codes ); GEN_API CodeBody def_namespace_body ( s32 num, Code* codes );
GEN_API CodeBody def_namespace_body ( s32 num, ... ); GEN_API CodeParams def_params ( s32 num, ... );
GEN_API CodeBody def_namespace_body_arr ( s32 num, Code* codes ); GEN_API CodeParams def_params ( s32 num, CodeParams* params );
GEN_API CodeParams def_params ( s32 num, ... ); GEN_API CodeSpecifiers def_specifiers ( s32 num, ... );
GEN_API CodeParams def_params_arr ( s32 num, CodeParams* params ); GEN_API CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
GEN_API CodeSpecifiers def_specifiers ( s32 num, ... ); GEN_API CodeBody def_struct_body ( s32 num, ... );
GEN_API CodeSpecifiers def_specifiers_arr ( s32 num, Specifier* specs ); GEN_API CodeBody def_struct_body ( s32 num, Code* codes );
GEN_API CodeBody def_struct_body ( s32 num, ... ); GEN_API CodeBody def_union_body ( s32 num, ... );
GEN_API CodeBody def_struct_body_arr ( s32 num, Code* codes ); GEN_API CodeBody def_union_body ( s32 num, Code* codes );
GEN_API CodeBody def_union_body ( s32 num, ... );
GEN_API CodeBody def_union_body_arr ( s32 num, Code* codes );
#if GEN_COMPILER_CPP
forceinline CodeBody def_class_body ( s32 num, Code* codes ) { return def_class_body_arr(num, codes); }
forceinline CodeDefineParams def_define_params ( s32 num, CodeDefineParams* codes ) { return def_define_params_arr(num, codes); }
forceinline CodeBody def_enum_body ( s32 num, Code* codes ) { return def_enum_body_arr(num, codes); }
forceinline CodeBody def_export_body ( s32 num, Code* codes) { return def_export_body_arr(num, codes); }
forceinline CodeBody def_extern_link_body( s32 num, Code* codes ) { return def_extern_link_body_arr(num, codes); }
forceinline CodeBody def_function_body ( s32 num, Code* codes ) { return def_function_body_arr(num, codes); }
forceinline CodeBody def_global_body ( s32 num, Code* codes ) { return def_global_body_arr(num, codes); }
forceinline CodeBody def_namespace_body ( s32 num, Code* codes ) { return def_namespace_body_arr(num, codes); }
forceinline CodeParams def_params ( s32 num, CodeParams* params ) { return def_params_arr(num, params); }
forceinline CodeSpecifiers def_specifiers ( s32 num, Specifier* specs ) { return def_specifiers_arr(num, specs); }
forceinline CodeBody def_struct_body ( s32 num, Code* codes ) { return def_struct_body_arr(num, codes); }
forceinline CodeBody def_union_body ( s32 num, Code* codes ) { return def_union_body_arr(num, codes); }
#endif
#pragma endregion Upfront #pragma endregion Upfront
@ -363,7 +326,6 @@ CodeBody parse_file( Str path );
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 );
GEN_API CodeDefine parse_define ( Str define_def );
GEN_API CodeDestructor parse_destructor ( Str destructor_def ); GEN_API CodeDestructor parse_destructor ( Str destructor_def );
GEN_API CodeEnum parse_enum ( Str enum_def ); GEN_API CodeEnum parse_enum ( Str enum_def );
GEN_API CodeBody parse_export_body ( Str export_def ); GEN_API CodeBody parse_export_body ( Str export_def );
@ -405,20 +367,12 @@ GEN_API Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
#ifndef name #ifndef name
// Convienence for defining any name used with the gen api. // Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL. // Lets you provide the length and string literal to the functions without the need for the DSL.
# if GEN_COMPILER_C #define name( Id_ ) { stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# define name( Id_ ) (Str){ stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# else
# define name( Id_ ) Str { stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# endif
#endif #endif
#ifndef code #ifndef code
// Same as name just used to indicate intention of literal for code instead of names. // Same as name just used to indicate intention of literal for code instead of names.
# if GEN_COMPILER_C #define code( ... ) { stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# define code( ... ) (Str){ stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# else
# define code( ... ) Str { stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# endif
#endif #endif
#ifndef args #ifndef args

View File

@ -73,7 +73,7 @@ CodeConstructor parse_constructor( Str def )
if ( NumSpecifiers ) if ( NumSpecifiers )
{ {
specifiers = def_specifiers_arr( NumSpecifiers, specs_found ); specifiers = def_specifiers( NumSpecifiers, specs_found );
// <specifiers> ... // <specifiers> ...
} }
@ -82,21 +82,6 @@ CodeConstructor parse_constructor( Str def )
return result; return result;
} }
CodeDefine parse_define( Str def )
{
check_parse_args( def );
TokArray toks = lex( def );
if ( toks.Arr == nullptr )
return InvalidCode;
_ctx->parser.Tokens = toks;
push_scope();
CodeDefine result = parser_parse_define();
parser_pop(& _ctx->parser);
return result;
}
CodeDestructor parse_destructor( Str def ) CodeDestructor parse_destructor( Str def )
{ {
check_parse_args( def ); check_parse_args( def );

View File

@ -8,8 +8,9 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
char const* buf_begin = buf; char const* buf_begin = buf;
ssize remaining = buf_size; ssize remaining = buf_size;
if (_ctx->token_fmt_map.Hashes == nullptr) { local_persist StringTable tok_map;
_ctx->token_fmt_map = hashtable_init(Str, _ctx->Allocator_DyanmicContainers ); do_once() {
tok_map = hashtable_init(Str, _ctx->Allocator_DyanmicContainers );
} }
// Populate token pairs // Populate token pairs
{ {
@ -21,7 +22,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
Str value = va_arg( va, Str ); Str value = va_arg( va, Str );
u32 key = crc32( token, c_str_len(token) ); u32 key = crc32( token, c_str_len(token) );
hashtable_set( _ctx->token_fmt_map, key, value ); hashtable_set( tok_map, key, value );
} }
} }
@ -56,8 +57,8 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
char const* token = fmt + 1; char const* token = fmt + 1;
u32 key = crc32( token, tok_len ); u32 key = crc32( token, tok_len );
Str* value = hashtable_get(_ctx->token_fmt_map, key ); Str* value = hashtable_get(tok_map, key );
if ( value ) if ( value )
{ {
@ -86,7 +87,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
current = * fmt; current = * fmt;
} }
} }
hashtable_clear(_ctx->token_fmt_map); hashtable_clear(tok_map);
ssize result = buf_size - remaining; ssize result = buf_size - remaining;
return result; return result;
} }

View File

@ -516,6 +516,7 @@ CodeClass def_class( Str name, Opts_def_struct p )
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
} }
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", code_debug_str(p.attributes) ); log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", code_debug_str(p.attributes) );
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
@ -528,12 +529,9 @@ CodeClass def_class( Str name, Opts_def_struct p )
} }
CodeClass CodeClass
result = (CodeClass) make_code(); result = (CodeClass) make_code();
result->Name = cache_str( name ); result->Name = cache_str( name );
result->ModuleFlags = p.mflags; result->ModuleFlags = p.mflags;
result->Attributes = p.attributes;
result->ParentAccess = p.parent_access;
result->ParentType = p.parent;
if ( p.body ) if ( p.body )
{ {
switch ( p.body->Type ) switch ( p.body->Type )
@ -554,32 +552,44 @@ CodeClass def_class( Str name, Opts_def_struct p )
else { else {
result->Type = CT_Class_Fwd; result->Type = CT_Class_Fwd;
} }
result->Attributes = p.attributes;
result->ParentAccess = p.parent_access;
result->ParentType = p.parent;
for (s32 idx = 0; idx < p.num_interfaces; idx++ ) { for (s32 idx = 0; idx < p.num_interfaces; idx++ ) {
class_add_interface(result, p.interfaces[idx] ); class_add_interface(result, p.interfaces[idx] );
} }
return result; return result;
} }
CodeDefine def_define( Str name, MacroType type, Opts_def_define p ) CodeDefine def_define( Str name, Str content, Opts_def_define p )
{ {
if ( ! name_check( def_define, name ) ) { if ( ! name_check( def_define, name ) ) {
GEN_DEBUG_TRAP(); GEN_DEBUG_TRAP();
return InvalidCode; return InvalidCode;
} }
CodeDefine CodeDefine
result = (CodeDefine) make_code(); result = (CodeDefine) make_code();
result->Type = CT_Preprocess_Define; result->Type = CT_Preprocess_Define;
result->Name = cache_str( name ); result->Name = cache_str( name );
result->Params = p.params;
if ( p.content.Len <= 0 || p.content.Ptr == nullptr )
result->Body = untyped_str( txt("\n") );
else
result->Body = untyped_str( strbuilder_to_str(strbuilder_fmt_buf(_ctx->Allocator_Temp, "%S\n", p.content)) );
b32 register_define = ! p.dont_register_to_preprocess_macros; if ( content.Len <= 0 || content.Ptr == nullptr )
if ( register_define ) { result->Content = cache_str( txt("") );
Macro macro_entry = { result->Name, type, p.flags }; else
register_macro(macro_entry); result->Content = cache_str( strbuilder_to_str(strbuilder_fmt_buf(_ctx->Allocator_Temp, "%S\n", content)) );
b32 append_preprocess_defines = ! p.dont_append_preprocess_defines;
if ( append_preprocess_defines ) {
// Add the define to PreprocessorDefines for usage in parsing
s32 lex_id_len = 0;
for (; lex_id_len < result->Name.Len; ++ lex_id_len ) {
if ( result->Name.Ptr[lex_id_len] == '(' )
break;
}
Str lex_id = { result->Name.Ptr, lex_id_len };
array_append(_ctx->PreprocessorDefines, cache_str(lex_id) );
} }
return result; return result;
} }
@ -1274,7 +1284,7 @@ CodeUsing def_using_namespace( Str name )
CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable p ) CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable p )
{ {
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;
} }
@ -1369,7 +1379,7 @@ CodeBody def_class_body( s32 num, ... )
return result; return result;
} }
CodeBody def_class_body_arr( s32 num, Code* codes ) CodeBody def_class_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_class_body ); def_body_code_array_start( def_class_body );
@ -1400,67 +1410,6 @@ CodeBody def_class_body_arr( s32 num, Code* codes )
return result; return result;
} }
CodeDefineParams def_define_params( s32 num, ... )
{
def_body_start( def_define_params );
va_list va;
va_start(va, num);
Code_POD pod = va_arg(va, Code_POD);
CodeDefineParams param = pcast( CodeDefineParams, pod );
null_check( def_define_params, param );
if ( param->Type != CT_Parameters_Define ) {
log_failure( "gen::def_define_params: param %d is not a parameter for a preprocessor define", num - num + 1 );
return InvalidCode;
}
CodeDefineParams result = (CodeDefineParams) code_duplicate(param);
while ( -- num )
{
pod = va_arg(va, Code_POD);
param = pcast( CodeDefineParams, pod );
if ( param->Type != CT_Parameters_Define ) {
log_failure( "gen::def_define_params: param %d is not a parameter for a preprocessor define", num - num + 1 );
return InvalidCode;
}
define_params_append(result, param );
}
va_end(va);
return result;
}
CodeDefineParams def_define_params_arr( s32 num, CodeDefineParams* codes )
{
def_body_code_array_start( def_define_params );
# define check_current(current) \
if ( current == nullptr ) { \
log_failure("gen::def_define_params: Provide a null code in codes array"); \
return InvalidCode; \
} \
if (current->Type != CT_Parameters_Define ) { \
log_failure("gen::def_define_params: Code in coes array is not of paramter for preprocessor define type - %s", code_debug_str(current) ); \
return InvalidCode; \
}
CodeDefineParams current = (CodeDefineParams)code_duplicate(* codes);
check_current(current);
CodeDefineParams
result = (CodeDefineParams) make_code();
result->Name = current->Name;
result->Type = current->Type;
while( codes++, current = * codes, num--, num > 0 ) {
check_current(current);
define_params_append(result, current );
}
# undef check_current
return result;
}
CodeBody def_enum_body( s32 num, ... ) CodeBody def_enum_body( s32 num, ... )
{ {
def_body_start( def_enum_body ); def_body_start( def_enum_body );
@ -1491,7 +1440,7 @@ CodeBody def_enum_body( s32 num, ... )
return (CodeBody) result; return (CodeBody) result;
} }
CodeBody def_enum_body_arr( s32 num, Code* codes ) CodeBody def_enum_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_enum_body ); def_body_code_array_start( def_enum_body );
@ -1552,7 +1501,7 @@ CodeBody def_export_body( s32 num, ... )
return result; return result;
} }
CodeBody def_export_body_arr( s32 num, Code* codes ) CodeBody def_export_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_export_body ); def_body_code_array_start( def_export_body );
@ -1618,7 +1567,7 @@ CodeBody def_extern_link_body( s32 num, ... )
return result; return result;
} }
CodeBody def_extern_link_body_arr( s32 num, Code* codes ) CodeBody def_extern_link_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_extern_linkage_body ); def_body_code_array_start( def_extern_linkage_body );
@ -1685,7 +1634,7 @@ CodeBody def_function_body( s32 num, ... )
return result; return result;
} }
CodeBody def_function_body_arr( s32 num, Code* codes ) CodeBody def_function_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_function_body ); def_body_code_array_start( def_function_body );
@ -1756,7 +1705,7 @@ CodeBody def_global_body( s32 num, ... )
return result; return result;
} }
CodeBody def_global_body_arr( s32 num, Code* codes ) CodeBody def_global_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_global_body ); def_body_code_array_start( def_global_body );
@ -1827,7 +1776,7 @@ CodeBody def_namespace_body( s32 num, ... )
return result; return result;
} }
CodeBody def_namespace_body_arr( s32 num, Code* codes ) CodeBody def_namespace_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_namespace_body ); def_body_code_array_start( def_namespace_body );
@ -1889,7 +1838,7 @@ CodeParams def_params( s32 num, ... )
return result; return result;
} }
CodeParams def_params_arr( s32 num, CodeParams* codes ) CodeParams def_params( s32 num, CodeParams* codes )
{ {
def_body_code_array_start( def_params ); def_body_code_array_start( def_params );
@ -1945,7 +1894,7 @@ CodeSpecifiers def_specifiers( s32 num, ... )
return result; return result;
} }
CodeSpecifiers def_specifiers_arr( s32 num, Specifier* specs ) CodeSpecifiers def_specifiers( s32 num, Specifier* specs )
{ {
if ( num <= 0 ) { if ( num <= 0 ) {
log_failure("gen::def_specifiers: num cannot be zero or less"); log_failure("gen::def_specifiers: num cannot be zero or less");
@ -2004,7 +1953,7 @@ CodeBody def_struct_body( s32 num, ... )
return result; return result;
} }
CodeBody def_struct_body_arr( s32 num, Code* codes ) CodeBody def_struct_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_struct_body ); def_body_code_array_start( def_struct_body );
@ -2065,7 +2014,7 @@ CodeBody def_union_body( s32 num, ... )
return result; return result;
} }
CodeBody def_union_body_arr( s32 num, Code* codes ) CodeBody def_union_body( s32 num, Code* codes )
{ {
def_body_code_array_start( def_union_body ); def_body_code_array_start( def_union_body );

View File

@ -112,158 +112,6 @@ void lexer_end_line( LexContext* ctx )
} }
#define end_line() lexer_end_line(ctx) #define end_line() lexer_end_line(ctx)
// TODO(Ed): We need to to attempt to recover from a lex failure?
s32 lex_preprocessor_define( LexContext* ctx )
{
Token name = { { ctx->scanner, 1 }, Tok_Identifier, ctx->line, ctx->column, TF_Preprocess };
move_forward();
while ( ctx->left && ( char_is_alphanumeric((* ctx->scanner)) || (* ctx->scanner) == '_' ) ) {
move_forward();
name.Text.Len++;
}
Specifier spec = str_to_specifier( name.Text );
TokType attrib = str_to_toktype( name.Text );
b32 not_specifier = spec == Spec_Invalid;
b32 not_attribute = attrib <= Tok___Attributes_Start;
Macro macro = { name.Text, MT_Expression, (MacroFlags)0 };
Macro* registered_macro = lookup_macro(name.Text);
if ( registered_macro == nullptr && not_specifier && not_attribute ) {
log_fmt("Warning: '%S' was not registered before the lexer processed its #define directive, it will be registered as a expression macro\n"
, name.Text
);
// GEN_DEBUG_TRAP();
}
array_append( _ctx->Lexer_Tokens, name );
if ( ctx->left && (* ctx->scanner) == '(' )
{
if (registered_macro && ! macro_is_functional(* registered_macro)) {
log_fmt("Warning: %S registered macro is not flagged as functional yet the definition detects opening parenthesis '(' for arguments\n"
, name.Text
);
// GEN_DEBUG_TRAP();
}
else {
macro.Flags |= MF_Functional;
}
Token opening_paren = { { ctx->scanner, 1 }, Tok_Paren_Open, ctx->line, ctx->column, TF_Preprocess };
array_append( _ctx->Lexer_Tokens, opening_paren );
move_forward();
Token last_parameter = {};
// We need to tokenize the define's arguments now:
while( ctx->left && * ctx->scanner != ')')
{
skip_whitespace();
Str possible_varadic = { ctx->scanner, 3 };
if ( ctx->left > 3 && str_are_equal( txt("..."), possible_varadic ) ) {
Token parameter = { { ctx->scanner, 3 }, Tok_Preprocess_Define_Param, ctx->line, ctx->column, TF_Preprocess };
move_forward();
move_forward();
move_forward();
array_append(_ctx->Lexer_Tokens, parameter);
skip_whitespace();
last_parameter = parameter;
while ( (* ctx->scanner) == '\\' ) {
move_forward();
skip_whitespace();
}
if (* ctx->scanner != ')' )
{
log_failure("lex_preprocessor_define(%d, %d): Expected a ')' after '...' (varaidc macro param) %S\n"
, ctx->line
, ctx->column
, name.Text
);
return Lex_ReturnNull;
}
break;
}
else if ( (* ctx->scanner) == '\\' ) {
move_forward();
skip_whitespace();
continue;
}
else if ( char_is_alpha( (* ctx->scanner) ) || (* ctx->scanner) == '_' )
{
Token parameter = { { ctx->scanner, 1 }, Tok_Preprocess_Define_Param, ctx->line, ctx->column, TF_Preprocess };
move_forward();
while ( ctx->left && ( char_is_alphanumeric((* ctx->scanner)) || (* ctx->scanner) == '_' ) )
{
move_forward();
parameter.Text.Len++;
}
array_append(_ctx->Lexer_Tokens, parameter);
skip_whitespace();
last_parameter = parameter;
}
else {
log_failure("lex_preprocessor_define(%d, %d): Expected a '_' or alpha character for a parameter name for %S\n"
, ctx->line
, ctx->column
, name.Text
);
return Lex_ReturnNull;
}
if (* ctx->scanner == ')' )
break;
// There should be a comma
if ( * ctx->scanner != ',' ) {
log_failure("lex_preprocessor_define(%d, %d): Expected a comma after parameter %S for %S\n"
, ctx->line
, ctx->column
, last_parameter.Text
, name.Text
);
return Lex_ReturnNull;
}
Token comma = { { ctx->scanner, 1 }, Tok_Comma, ctx->line, ctx->column, TF_Preprocess };
array_append(_ctx->Lexer_Tokens, comma);
move_forward();
}
if ( * ctx->scanner != ')' ) {
log_failure("lex_preprocessor_define(%d, %d): Expected a ')' after last_parameter %S for %S (ran out of characters...)\n"
, ctx->line
, ctx->column
, last_parameter.Text
, name.Text
);
return Lex_ReturnNull;
}
Token closing_paren = { { ctx->scanner, 1 }, Tok_Paren_Close, ctx->line, ctx->column, TF_Preprocess };
array_append(_ctx->Lexer_Tokens, closing_paren);
move_forward();
}
else if ( registered_macro && macro_is_functional( * registered_macro) ) {
if (registered_macro && ! macro_is_functional(* registered_macro)) {
log_fmt("Warning: %S registered macro is flagged as functional yet the definition detects no opening parenthesis '(' for arguments\n"
, name.Text
);
GEN_DEBUG_TRAP();
}
}
if ( registered_macro == nullptr ) {
register_macro(macro);
}
// Define's content handled by lex_preprocessor_directive (the original caller of this)
return Lex_Continue;
}
// TODO(Ed): We need to to attempt to recover from a lex failure?
forceinline forceinline
s32 lex_preprocessor_directive( LexContext* ctx ) s32 lex_preprocessor_directive( LexContext* ctx )
{ {
@ -367,9 +215,28 @@ s32 lex_preprocessor_directive( LexContext* ctx )
if ( ctx->token.Type == Tok_Preprocess_Define ) if ( ctx->token.Type == Tok_Preprocess_Define )
{ {
u32 result = lex_preprocessor_define(ctx); // handles: #define <name>( <params> ) - define's content handled later on within this scope. Token name = { { ctx->scanner, 0 }, Tok_Identifier, ctx->line, ctx->column, TF_Preprocess };
if (result != Lex_Continue)
return Lex_ReturnNull; name.Text.Ptr = ctx->scanner;
name.Text.Len = 1;
move_forward();
while ( ctx->left && ( char_is_alphanumeric((* ctx->scanner)) || (* ctx->scanner) == '_' ) )
{
move_forward();
name.Text.Len++;
}
if ( ctx->left && (* ctx->scanner) == '(' )
{
move_forward();
name.Text.Len++;
}
array_append( _ctx->Lexer_Tokens, name );
u64 key = crc32( name.Text.Ptr, name.Text.Len );
hashtable_set(ctx->defines, key, tok_to_str(name) );
} }
Token preprocess_content = { { ctx->scanner, 0 }, Tok_Preprocess_Content, ctx->line, ctx->column, TF_Preprocess }; Token preprocess_content = { { ctx->scanner, 0 }, Tok_Preprocess_Content, ctx->line, ctx->column, TF_Preprocess };
@ -419,7 +286,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
s32 within_string = false; s32 within_string = false;
s32 within_char = false; s32 within_char = false;
// Consume preprocess content // SkipWhitespace();
while ( ctx->left ) while ( ctx->left )
{ {
if ( (* ctx->scanner) == '"' && ! within_char ) if ( (* ctx->scanner) == '"' && ! within_char )
@ -455,7 +322,6 @@ s32 lex_preprocessor_directive( LexContext* ctx )
, (* ctx->scanner), ctx->line, ctx->column , (* ctx->scanner), ctx->line, ctx->column
, directive_str, preprocess_content.Line, preprocess_content.Column , directive_str, preprocess_content.Line, preprocess_content.Column
, content_str ); , content_str );
return Lex_ReturnNull;
break; break;
} }
} }
@ -483,24 +349,30 @@ s32 lex_preprocessor_directive( LexContext* ctx )
forceinline forceinline
void lex_found_token( LexContext* ctx ) void lex_found_token( LexContext* ctx )
{ {
if ( ctx->token.Type != Tok_Invalid ) { if ( ctx->token.Type != Tok_Invalid )
{
array_append( _ctx->Lexer_Tokens, ctx->token ); array_append( _ctx->Lexer_Tokens, ctx->token );
return; return;
} }
TokType type = str_to_toktype( tok_to_str(ctx->token) ); TokType type = str_to_toktype( tok_to_str(ctx->token) );
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;
} }
if ( type > Tok___Attributes_Start ) {
if ( type > Tok___Attributes_Start )
{
ctx->token.Flags |= TF_Attribute; ctx->token.Flags |= TF_Attribute;
} }
if ( type == Tok_Decl_Extern_Linkage ) if ( type == Tok_Decl_Extern_Linkage )
{ {
skip_whitespace(); skip_whitespace();
if ( (* ctx->scanner) != '"' ) { if ( (* ctx->scanner) != '"' )
{
type = Tok_Spec_Extern; type = Tok_Spec_Extern;
ctx->token.Flags |= TF_Specifier; ctx->token.Flags |= TF_Specifier;
} }
@ -509,6 +381,7 @@ void lex_found_token( LexContext* ctx )
array_append( _ctx->Lexer_Tokens, ctx->token ); array_append( _ctx->Lexer_Tokens, ctx->token );
return; return;
} }
if ( ( type <= Tok_Star && type >= Tok_Spec_Alignas) if ( ( type <= Tok_Star && type >= Tok_Spec_Alignas)
|| type == Tok_Ampersand || type == Tok_Ampersand
|| type == Tok_Ampersand_DBL ) || type == Tok_Ampersand_DBL )
@ -518,6 +391,8 @@ void lex_found_token( LexContext* ctx )
array_append( _ctx->Lexer_Tokens, ctx->token ); array_append( _ctx->Lexer_Tokens, ctx->token );
return; return;
} }
if ( type != Tok_Invalid ) if ( type != Tok_Invalid )
{ {
ctx->token.Type = type; ctx->token.Type = type;
@ -525,31 +400,50 @@ void lex_found_token( LexContext* ctx )
return; return;
} }
Macro* macro = lookup_macro( ctx->token.Text ); u64 key = 0;
b32 has_args = ctx->left && (* ctx->scanner) == '('; if ( (* ctx->scanner) == '(')
b32 resolved_to_macro = false; key = crc32( ctx->token.Text.Ptr, ctx->token.Text.Len + 1 );
if (macro) { else
ctx->token.Type = macrotype_to_toktype(macro->Type); key = crc32( ctx->token.Text.Ptr, ctx->token.Text.Len );
b32 is_functional = macro_is_functional(* macro);
resolved_to_macro = has_args ? is_functional : ! is_functional; Str* define = hashtable_get(ctx->defines, key );
if ( ! resolved_to_macro && GEN_BUILD_DEBUG ) { if ( define )
log_fmt("Info(%d, %d): %S identified as a macro but usage here does not resolve to one (interpreting as identifier)\n"
, ctx->token.Line
, ctx->token.Line
, macro->Name
);
}
}
if ( resolved_to_macro )
{ {
// TODO(Ed): When we introduce a macro AST (and expression support), we'll properly lex this section. ctx->token.Type = Tok_Preprocess_Macro;
// Want to ignore any arguments the define may have as they can be execution expressions. // Want to ignore any arguments the define may have as they can be execution expressions.
if ( has_args ) { if ( ctx->left && (* ctx->scanner) == '(' )
ctx->token.Flags |= TF_Macro_Functional; {
} move_forward();
if ( bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Attribute) ) { ctx->token.Text.Len++;
ctx->token.Flags |= TF_Attribute;
s32 level = 0;
while ( ctx->left && ((* ctx->scanner) != ')' || level > 0) )
{
if ( (* ctx->scanner) == '(' )
level++;
else if ( (* ctx->scanner) == ')' && level > 0 )
level--;
move_forward();
ctx->token.Text.Len++;
}
move_forward();
ctx->token.Text.Len++;
} }
//if ( (* ctx->scanner) == '\r' && ctx->scanner[1] == '\n' )
//{
// move_forward();
// ctx->token..Text.Length++;
//}
//else if ( (* ctx->scanner) == '\n' )
//{
// move_forward();
// ctx->token..Text.Length++;
//}
} }
else else
{ {
@ -559,7 +453,6 @@ void lex_found_token( LexContext* ctx )
array_append( _ctx->Lexer_Tokens, ctx->token ); array_append( _ctx->Lexer_Tokens, ctx->token );
} }
// TODO(Ed): We need to to attempt to recover from a lex failure?
neverinline neverinline
// TokArray lex( Array<Token> tokens, Str content ) // TokArray lex( Array<Token> tokens, Str content )
TokArray lex( Str content ) TokArray lex( Str content )
@ -568,6 +461,7 @@ TokArray lex( Str content )
c.content = content; c.content = content;
c.left = content.Len; c.left = content.Len;
c.scanner = content.Ptr; c.scanner = content.Ptr;
c.defines = _ctx->Lexer_defines;
char const* word = c.scanner; char const* word = c.scanner;
s32 word_length = 0; s32 word_length = 0;
@ -583,9 +477,25 @@ TokArray lex( Str content )
return null_array; return null_array;
} }
array_clear(_ctx->Lexer_Tokens); for ( StrCached* entry = array_begin(_ctx->PreprocessorDefines); entry != array_end(_ctx->PreprocessorDefines); entry = array_next(_ctx->PreprocessorDefines, entry))
{
s32 length = 0;
char const* entry_scanner = (*entry).Ptr;
while ( entry->Len > length && (char_is_alphanumeric( *entry_scanner ) || *entry_scanner == '_') )
{
entry_scanner++;
length ++;
}
if ( entry_scanner[0] == '(' )
{
length++;
}
b32 preprocess_args = true; u64 key = crc32( entry->Ptr, length );
hashtable_set(c.defines, key, * entry );
}
array_clear(_ctx->Lexer_Tokens);
while (c.left ) while (c.left )
{ {
@ -797,7 +707,7 @@ TokArray lex( Str content )
{ {
Str text = { c.scanner, 1 }; Str text = { c.scanner, 1 };
c.token.Text = text; c.token.Text = text;
c.token.Type = Tok_Paren_Open; c.token.Type = Tok_Capture_Start;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -807,7 +717,7 @@ TokArray lex( Str content )
{ {
Str text = { c.scanner, 1 }; Str text = { c.scanner, 1 };
c.token.Text = text; c.token.Text = text;
c.token.Type = Tok_Paren_Close; c.token.Type = Tok_Capture_End;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -1028,7 +938,7 @@ TokArray lex( Str content )
goto FoundToken; goto FoundToken;
} }
// Dash is unfortunately a bit more complicated... // Dash is unfortunatlly a bit more complicated...
case '-': case '-':
{ {
Str text = { c.scanner, 1 }; Str text = { c.scanner, 1 };
@ -1165,7 +1075,8 @@ TokArray lex( Str content )
c.token.Text = text; c.token.Text = text;
move_forward(); move_forward();
while ( c.left && ( char_is_alphanumeric((* ctx->scanner)) || (* ctx->scanner) == '_' ) ) { while ( c.left && ( char_is_alphanumeric((* ctx->scanner)) || (* ctx->scanner) == '_' ) )
{
move_forward(); move_forward();
c.token.Text.Len++; c.token.Text.Len++;
} }
@ -1191,7 +1102,8 @@ TokArray lex( Str content )
move_forward(); move_forward();
c.token.Text.Len++; c.token.Text.Len++;
while ( c.left && char_is_hex_digit((* ctx->scanner)) ) { while ( c.left && char_is_hex_digit((* ctx->scanner)) )
{
move_forward(); move_forward();
c.token.Text.Len++; c.token.Text.Len++;
} }
@ -1199,7 +1111,8 @@ TokArray lex( Str content )
goto FoundToken; goto FoundToken;
} }
while ( c.left && char_is_digit((* ctx->scanner)) ) { while ( c.left && char_is_digit((* ctx->scanner)) )
{
move_forward(); move_forward();
c.token.Text.Len++; c.token.Text.Len++;
} }
@ -1209,7 +1122,8 @@ TokArray lex( Str content )
move_forward(); move_forward();
c.token.Text.Len++; c.token.Text.Len++;
while ( c.left && char_is_digit((* ctx->scanner)) ) { while ( c.left && char_is_digit((* ctx->scanner)) )
{
move_forward(); move_forward();
c.token.Text.Len++; c.token.Text.Len++;
} }
@ -1227,7 +1141,8 @@ TokArray lex( Str content )
c.token.Text.Len++; c.token.Text.Len++;
// Handle 'll'/'LL' as a special case when we just processed an 'l'/'L' // Handle 'll'/'LL' as a special case when we just processed an 'l'/'L'
if (c.left && (prev == 'l' || prev == 'L') && ((* ctx->scanner) == 'l' || (* ctx->scanner) == 'L')) { if (c.left && (prev == 'l' || prev == 'L') && ((* ctx->scanner) == 'l' || (* ctx->scanner) == 'L'))
{
move_forward(); move_forward();
c.token.Text.Len++; c.token.Text.Len++;
} }
@ -1253,7 +1168,8 @@ TokArray lex( Str content )
log_failure( "Failed to lex token '%c' (%d, %d)\n%s", (* ctx->scanner), c.line, c.column, context_str ); log_failure( "Failed to lex token '%c' (%d, %d)\n%s", (* ctx->scanner), c.line, c.column, context_str );
// Skip to next whitespace since we can't know if anything else is valid until then. // Skip to next whitespace since we can't know if anything else is valid until then.
while ( c.left && ! char_is_space( (* ctx->scanner) ) ) { while ( c.left && ! char_is_space( (* ctx->scanner) ) )
{
move_forward(); move_forward();
} }
} }
@ -1262,14 +1178,16 @@ TokArray lex( Str content )
{ {
lex_found_token( ctx ); lex_found_token( ctx );
TokType last_type = array_back(_ctx->Lexer_Tokens)->Type; TokType last_type = array_back(_ctx->Lexer_Tokens)->Type;
if ( last_type == Tok_Preprocess_Macro_Stmt || last_type == Tok_Preprocess_Macro_Expr ) if ( last_type == Tok_Preprocess_Macro )
{ {
Token thanks_c = { { c.scanner, 0 }, Tok_Invalid, c.line, c.column, TF_Null }; Token thanks_c = { { c.scanner, 0 }, Tok_Invalid, c.line, c.column, TF_Null };
c.token = thanks_c; c.token = thanks_c;
if ( (* ctx->scanner) == '\r') { if ( (* ctx->scanner) == '\r')
{
move_forward(); move_forward();
c.token.Text.Len = 1; c.token.Text.Len = 1;
} }
if ( (* ctx->scanner) == '\n' ) if ( (* ctx->scanner) == '\n' )
{ {
c.token.Type = Tok_NewLine; c.token.Type = Tok_NewLine;
@ -1283,16 +1201,20 @@ TokArray lex( Str content )
} }
} }
if ( array_num(_ctx->Lexer_Tokens) == 0 ) { if ( array_num(_ctx->Lexer_Tokens) == 0 )
{
log_failure( "Failed to lex any tokens" ); log_failure( "Failed to lex any tokens" );
TokArray tok_array = {}; {
return tok_array; TokArray tok_array = {};
return tok_array;
}
} }
hashtable_clear(_ctx->Lexer_defines);
// defines_map_arena.free();
TokArray result = { _ctx->Lexer_Tokens, 0 }; TokArray result = { _ctx->Lexer_Tokens, 0 };
return result; return result;
} }
#undef move_forward #undef move_forward
#undef skip_whitespace #undef skip_whitespace
#undef end_line #undef end_line

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@ case Spec_Static: \
case Spec_Volatile: \ case Spec_Volatile: \
case Spec_Virtual case Spec_Virtual
#define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_TOK_SPECIFIER_CASES \ #define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_TOK_SPECIFIERS_CASES \
case Tok_Spec_Consteval: \ case Tok_Spec_Consteval: \
case Tok_Spec_Constexpr: \ case Tok_Spec_Constexpr: \
case Tok_Spec_Constinit: \ case Tok_Spec_Constinit: \
@ -37,7 +37,7 @@ case Tok_Spec_Internal_Linkage: \
case Tok_Spec_NeverInline: \ case Tok_Spec_NeverInline: \
case Tok_Spec_Static case Tok_Spec_Static
#define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_SPECIFIER_CASES \ #define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_SPECIFIERS_CASES \
case Spec_Constexpr: \ case Spec_Constexpr: \
case Spec_Constinit: \ case Spec_Constinit: \
case Spec_ForceInline: \ case Spec_ForceInline: \

View File

@ -4,24 +4,39 @@
#include "gen/ecode.hpp" #include "gen/ecode.hpp"
#include "gen/eoperator.hpp" #include "gen/eoperator.hpp"
#include "gen/especifier.hpp" #include "gen/especifier.hpp"
#include "gen/etoktype.hpp"
#endif #endif
enum MacroFlags : u32
{
// Can only be one of these at a time (required)
MF_Block_Start = bit(0), // Start of a "block" scope
MF_Block_End = bit(1), // End of a "block" scope
MF_Case_Statement = bit(2), // Used as a case statement (not utilized by the parser yet)
MF_Expression = bit(3), // Used as an expresssion (not utilized by the parser yet)
MF_Statement = bit(4), // Used a statement (will expect to be a lone macro)
MF_Expects_Body = bit(5), // Expects to consume a braced scope
MF_Typename = bit(6), // Behaves as a typename
// Optional
MF_Functional = bit(7),
MF_Null = 0,
MF_UnderlyingType = GEN_U32_MAX,
};
enum TokFlags : u32 enum TokFlags : u32
{ {
TF_Operator = bit(0), TF_Operator = bit(0),
TF_Assign = bit(1), TF_Assign = bit(1),
TF_Preprocess = bit(2), TF_Preprocess = bit(2),
TF_Preprocess_Cond = bit(3), TF_Preprocess_Cond = bit(3),
TF_Attribute = bit(6), TF_Attribute = bit(6),
TF_AccessOperator = bit(7), TF_AccessOperator = bit( 7 ),
TF_AccessSpecifier = bit(8), TF_AccessSpecifier = bit( 8 ),
TF_Specifier = bit(9), TF_Specifier = bit( 9 ),
TF_EndDefinition = bit(10), // Either ; or } TF_EndDefinition = bit( 10 ), // Either ; or }
TF_Formatting = bit(11), TF_Formatting = bit( 11 ),
TF_Literal = bit(12), TF_Literal = bit( 12 ),
TF_Macro_Functional = bit(13),
TF_Macro_Expects_Body = bit(14),
TF_Null = 0, TF_Null = 0,
TF_UnderlyingType = GEN_U32_MAX, TF_UnderlyingType = GEN_U32_MAX,
@ -55,42 +70,42 @@ bool tok_is_valid( Token tok ) {
forceinline forceinline
bool tok_is_access_operator(Token tok) { bool tok_is_access_operator(Token tok) {
return bitfield_is_set( u32, tok.Flags, TF_AccessOperator ); return bitfield_is_equal( u32, tok.Flags, TF_AccessOperator );
} }
forceinline forceinline
bool tok_is_access_specifier(Token tok) { bool tok_is_access_specifier(Token tok) {
return bitfield_is_set( u32, tok.Flags, TF_AccessSpecifier ); return bitfield_is_equal( u32, tok.Flags, TF_AccessSpecifier );
} }
forceinline forceinline
bool tok_is_attribute(Token tok) { bool tok_is_attribute(Token tok) {
return bitfield_is_set( u32, tok.Flags, TF_Attribute ); return bitfield_is_equal( u32, tok.Flags, TF_Attribute );
} }
forceinline forceinline
bool tok_is_operator(Token tok) { bool tok_is_operator(Token tok) {
return bitfield_is_set( u32, tok.Flags, TF_Operator ); return bitfield_is_equal( u32, tok.Flags, TF_Operator );
} }
forceinline forceinline
bool tok_is_preprocessor(Token tok) { bool tok_is_preprocessor(Token tok) {
return bitfield_is_set( u32, tok.Flags, TF_Preprocess ); return bitfield_is_equal( u32, tok.Flags, TF_Preprocess );
} }
forceinline forceinline
bool tok_is_preprocess_cond(Token tok) { bool tok_is_preprocess_cond(Token tok) {
return bitfield_is_set( u32, tok.Flags, TF_Preprocess_Cond ); return bitfield_is_equal( u32, tok.Flags, TF_Preprocess_Cond );
} }
forceinline forceinline
bool tok_is_specifier(Token tok) { bool tok_is_specifier(Token tok) {
return bitfield_is_set( u32, tok.Flags, TF_Specifier ); return bitfield_is_equal( u32, tok.Flags, TF_Specifier );
} }
forceinline forceinline
bool tok_is_end_definition(Token tok) { bool tok_is_end_definition(Token tok) {
return bitfield_is_set( u32, tok.Flags, TF_EndDefinition ); return bitfield_is_equal( u32, tok.Flags, TF_EndDefinition );
} }
StrBuilder tok_to_strbuilder(Token tok); StrBuilder tok_to_strbuilder(Token tok);
@ -108,7 +123,7 @@ struct LexContext
char const* scanner; char const* scanner;
s32 line; s32 line;
s32 column; s32 column;
// StringTable defines; StringTable defines;
Token token; Token token;
}; };
@ -126,100 +141,3 @@ struct ParseContext
TokArray Tokens; TokArray Tokens;
StackNode* Scope; StackNode* Scope;
}; };
enum MacroType : u16
{
MT_Expression, // A macro is assumed to be a expression if not resolved.
MT_Statement,
MT_Typename,
MT_Attribute, // More of a note to the parser than anythign else (attributes should be defined in the user attribues def).
MT_Specifier, // More of a note to the parser than anythign else (specifiers should be defined in the user attribues def).
MT_Block_Start, // Not Supported yet
MT_Block_End, // Not Supported yet
MT_Case_Statement, // Not Supported yet
MT_UnderlyingType = GEN_U16_MAX,
};
forceinline
TokType macrotype_to_toktype( MacroType type ) {
switch ( type ) {
case MT_Statement : return Tok_Preprocess_Macro_Stmt;
case MT_Expression : return Tok_Preprocess_Macro_Expr;
case MT_Typename : return Tok_Preprocess_Macro_Typename;
}
// All others unsupported for now.
return Tok_Invalid;
}
inline
Str macrotype_to_str( MacroType type )
{
local_persist
Str lookup[] = {
{ "Statement", sizeof("Statement") - 1 },
{ "Expression", sizeof("Expression") - 1 },
{ "Typename", sizeof("Typename") - 1 },
{ "Attribute(Macro)", sizeof("Attribute(Macro)") - 1 },
{ "Specifier(Macro)", sizeof("Specifier(Macro)") - 1 },
{ "Block_Start", sizeof("Block_Start") - 1 },
{ "Block_End", sizeof("Block_End") - 1 },
{ "Case_Statement", sizeof("Case_Statement") - 1 },
};
local_persist
Str invalid = { "Invalid", sizeof("Invalid") };
if ( type > MT_Case_Statement )
return invalid;
return lookup[ type ];
}
enum EMacroFlags : u16
{
MF_Functional = bit(0), // Macro has parameters (args expected to be passed)
MF_Expects_Body = bit(1), // Expects to assign a braced scope to its body.
// 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.
MF_Allow_As_Identifier = bit(2),
// 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)
// 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
// & it would allow UE_DEPRECATED, (UE_PROPERTY / UE_FUNCTION) to chain themselves as attributes of a resolved member function/varaible definition
MF_Allow_As_Attribute = bit(3),
// When a macro is encountered after attributs 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)
// (MUST BE OF MT_Statement TYPE)
MF_Allow_As_Definition = bit(4),
MF_Null = 0,
MF_UnderlyingType = GEN_U16_MAX,
};
typedef u16 MacroFlags;
struct Macro
{
StrCached Name;
MacroType Type;
MacroFlags Flags;
};
forceinline
b32 macro_is_functional( Macro macro ) {
return bitfield_is_set( b16, macro.Flags, MF_Functional );
}
forceinline
b32 macro_expects_body( Macro macro ) {
return bitfield_is_set( b16, macro.Flags, MF_Expects_Body );
}
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
forceinline b32 is_functional( Macro macro ) { return bitfield_is_set( b16, macro.Flags, MF_Functional ); }
forceinline b32 expects_body ( Macro macro ) { return bitfield_is_set( b16, macro.Flags, MF_Expects_Body ); }
#endif
typedef HashTable(Macro) MacroTable;

View File

@ -5,10 +5,11 @@
#pragma region StaticData #pragma region StaticData
global Context* _ctx; global Context* _ctx;
global u32 context_counter;
#pragma region Constants #pragma region Constants
global Macro enum_underlying_macro; global u32 context_counter;
global Str enum_underlying_sig;
global Code Code_Global; global Code Code_Global;
global Code Code_Invalid; global Code Code_Invalid;

View File

@ -143,7 +143,6 @@ Array<Type> array_init_reserve(AllocatorInfo allocator, ssize capacity)
return {rcast(Type*, header + 1)}; return {rcast(Type*, header + 1)};
} }
forceinline
usize array_grow_formula(ssize value) { usize array_grow_formula(ssize value) {
return 2 * value + 8; return 2 * value + 8;
} }
@ -203,7 +202,7 @@ bool array_append_at(Array<Type>* array, Type item, usize idx)
ArrayHeader* header = array_get_header(* array); ArrayHeader* header = array_get_header(* array);
ssize slot = idx; ssize slot = idx;
if (slot >= (ssize)(header->Num)) if (slot >= header->Num)
slot = header->Num - 1; slot = header->Num - 1;
if (slot < 0) if (slot < 0)
@ -282,9 +281,10 @@ bool array_fill(Array<Type> array, usize begin, usize end, Type value)
ArrayHeader* header = array_get_header(array); ArrayHeader* header = array_get_header(array);
if (begin < 0 || end > header->Num) if (begin < 0 || end > header->Num)
return false; return false;
for (ssize idx = ssize(begin); idx < ssize(end); idx++) { for (ssize idx = ssize(begin); idx < ssize(end); idx++)
{
array[idx] = value; array[idx] = value;
} }
@ -354,6 +354,7 @@ bool array_reserve(Array<Type>* array, usize new_capacity)
{ {
GEN_ASSERT( array != nullptr); GEN_ASSERT( array != nullptr);
GEN_ASSERT(* array != nullptr); GEN_ASSERT(* array != nullptr);
GEN_ASSERT(num > 0)
ArrayHeader* header = array_get_header(array); ArrayHeader* header = array_get_header(array);
if (header->Capacity < new_capacity) if (header->Capacity < new_capacity)
@ -753,7 +754,7 @@ HashTableFindResult hashtable__find(HashTable<Type> table, u64 key)
if (table.Entries[result.EntryIndex].Key == key) if (table.Entries[result.EntryIndex].Key == key)
break; break;
result.PrevIndex = result.EntryIndex; result.PrevIndex = result.EntryIndex;
result.EntryIndex = table.Entries[result.EntryIndex].Next; result.EntryIndex = table.Entries[result.EntryIndex].Next;
} }
} }
@ -762,7 +763,7 @@ HashTableFindResult hashtable__find(HashTable<Type> table, u64 key)
} }
template<typename Type> forceinline template<typename Type> forceinline
b32 hashtable_full(HashTable<Type> table) { bool hashtable_full(HashTable<Type> table) {
GEN_ASSERT_NOT_NULL(table.Hashes); GEN_ASSERT_NOT_NULL(table.Hashes);
GEN_ASSERT_NOT_NULL(table.Entries); GEN_ASSERT_NOT_NULL(table.Entries);
usize critical_load = usize(HashTable_CriticalLoadScale * f32(array_num(table.Hashes))); usize critical_load = usize(HashTable_CriticalLoadScale * f32(array_num(table.Hashes)));

View File

@ -11,10 +11,10 @@
#if GEN_BUILD_DEBUG #if GEN_BUILD_DEBUG
# if defined( GEN_COMPILER_MSVC ) # if defined( GEN_COMPILER_MSVC )
# if _MSC_VER < 1300 # if _MSC_VER < 1300
// #pragma message("GEN_BUILD_DEBUG: __asm int 3") #pragma message("GEN_BUILD_DEBUG: __asm int 3")
# define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */ # define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */
# else # else
// #pragma message("GEN_BUILD_DEBUG: __debugbreak()") #pragma message("GEN_BUILD_DEBUG: __debugbreak()")
# define GEN_DEBUG_TRAP() __debugbreak() # define GEN_DEBUG_TRAP() __debugbreak()
# endif # endif
# elif defined( GEN_COMPILER_TINYC ) # elif defined( GEN_COMPILER_TINYC )
@ -23,7 +23,7 @@
# define GEN_DEBUG_TRAP() __builtin_trap() # define GEN_DEBUG_TRAP() __builtin_trap()
# endif # endif
#else #else
// #pragma message("GEN_BUILD_DEBUG: omitted") #pragma message("GEN_BUILD_DEBUG: omitted")
# define GEN_DEBUG_TRAP() # define GEN_DEBUG_TRAP()
#endif #endif
@ -44,7 +44,7 @@
// NOTE: Things that shouldn't happen with a message! // NOTE: Things that shouldn't happen with a message!
#define GEN_PANIC( msg, ... ) GEN_ASSERT_MSG( 0, msg, ##__VA_ARGS__ ) #define GEN_PANIC( msg, ... ) GEN_ASSERT_MSG( 0, msg, ##__VA_ARGS__ )
#if GEN_BUILD_DEBUG #if GEN_BULD_DEBUG
#define GEN_FATAL( ... ) \ #define GEN_FATAL( ... ) \
do \ do \
{ \ { \

View File

@ -34,8 +34,8 @@
#endif #endif
#ifndef bit #ifndef bit
#define bit( Value ) ( 1 << Value ) #define bit( Value ) ( 1 << Value )
#define bitfield_is_set( Type, Field, Mask ) ( (scast(Type, Mask) & scast(Type, Field)) == scast(Type, Mask) ) #define bitfield_is_equal( Type, Field, Mask ) ( (scast(Type, Mask) & scast(Type, Field)) == scast(Type, Mask) )
#endif #endif
// Mainly intended for forcing the base library to utilize only C-valid constructs or type coercion // Mainly intended for forcing the base library to utilize only C-valid constructs or type coercion
@ -86,16 +86,14 @@
#define stringize( ... ) stringize_va( __VA_ARGS__ ) #define stringize( ... ) stringize_va( __VA_ARGS__ )
#endif #endif
#define src_line_str stringize(__LINE__)
#ifndef do_once #ifndef do_once
#define do_once() \ #define do_once() \
local_persist int __do_once_counter_##src_line_str = 0; \ static int __do_once_counter_##__LINE__ = 0; \
for(; __do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1 ) \ for(; __do_once_counter_##__LINE__ != 1; __do_once_counter_##__LINE__ = 1 ) \
#define do_once_defer( expression ) \ #define do_once_defer( expression ) \
local_persist int __do_once_counter_##src_line_str = 0; \ static int __do_once_counter_##__LINE__ = 0; \
for(;__do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1, (expression)) \ for(; __do_once_counter_##__LINE__ != 1; __do_once_counter_##__LINE__ = 1, (expression)) \
#define do_once_start \ #define do_once_start \
do \ do \
@ -250,9 +248,9 @@
# if ! GEN_COMPILER_C # if ! GEN_COMPILER_C
# define typeof decltype # define typeof decltype
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
# define typeof __typeof__ # define typeof(x) __typeof__(x)
# elif defined(__GNUC__) || defined(__clang__) # elif defined(__GNUC__) || defined(__clang__)
# define typeof __typeof__ # define typeof(x) __typeof__(x)
# else # else
# error "Compiler not supported" # error "Compiler not supported"
# endif # endif

View File

@ -346,25 +346,25 @@ void* arena_allocator_proc( void* allocator_data, AllocType type, ssize size, ss
switch ( type ) switch ( type )
{ {
case EAllocation_ALLOC : case EAllocation_ALLOC :
{
void* end = pointer_add( arena->PhysicalStart, arena->TotalUsed );
ssize total_size = align_forward_s64( size, alignment );
// NOTE: Out of memory
if ( arena->TotalUsed + total_size > (ssize) arena->TotalSize )
{ {
// zpl__printf_err("%s", "Arena out of memory\n"); void* end = pointer_add( arena->PhysicalStart, arena->TotalUsed );
GEN_FATAL("Arena out of memory! (Possibly could not fit for the largest size Arena!!)"); ssize total_size = align_forward_s64( size, alignment );
// NOTE: Out of memory
if ( arena->TotalUsed + total_size > (ssize) arena->TotalSize )
{
// zpl__printf_err("%s", "Arena out of memory\n");
GEN_FATAL("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
return nullptr;
}
ptr = align_forward( end, alignment );
arena->TotalUsed += total_size;
if ( flags & ALLOCATOR_FLAG_CLEAR_TO_ZERO )
zero_size( ptr, size );
} }
break;
ptr = align_forward( end, alignment );
arena->TotalUsed += total_size;
if ( flags & ALLOCATOR_FLAG_CLEAR_TO_ZERO )
zero_size( ptr, size );
}
break;
case EAllocation_FREE : case EAllocation_FREE :
// NOTE: Free all at once // NOTE: Free all at once

View File

@ -225,10 +225,11 @@ forceinline ssize size_remaining(Arena& arena, ssize alignment) { return
// This id is defined by Unreal for asserts // This id is defined by Unreal for asserts
#pragma push_macro("check") #pragma push_macro("check")
#undef check #undef check
forceinline void check(Arena& arena) { return arena_check(& arena); } forceinline void check(Arena& arena) { return arena_check(& arena); };
#pragma pop_macro("check") #pragma pop_macro("check")
#endif #endif
inline inline
AllocatorInfo arena_allocator_info( Arena* arena ) { AllocatorInfo arena_allocator_info( Arena* arena ) {
GEN_ASSERT(arena != nullptr); GEN_ASSERT(arena != nullptr);
@ -391,9 +392,9 @@ void pool_clear(Pool* pool);
void pool_free(Pool* pool); void pool_free(Pool* pool);
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP #if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
forceinline AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); } AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); }
forceinline void clear(Pool& pool) { return pool_clear(& pool); } void clear(Pool& pool) { return pool_clear(& pool); }
forceinline void free(Pool& pool) { return pool_free(& pool); } void free(Pool& pool) { return pool_free(& pool); }
#endif #endif
struct Pool struct Pool

View File

@ -40,9 +40,9 @@ struct Str
#ifndef txt #ifndef txt
# if GEN_COMPILER_CPP # if GEN_COMPILER_CPP
# define txt( text ) GEN_NS Str { ( text ), sizeof( text ) - 1 } # define txt( text ) Str { ( text ), sizeof( text ) - 1 }
# else # else
# define txt( text ) (GEN_NS Str){ ( text ), sizeof( text ) - 1 } # define txt( text ) (Str){ ( text ), sizeof( text ) - 1 }
# endif # endif
#endif #endif
@ -392,7 +392,6 @@ bool strbuilder_append_string(StrBuilder* str, StrBuilder const other) {
return strbuilder_append_c_str_len(str, (char const*)other, strbuilder_length(other)); return strbuilder_append_c_str_len(str, (char const*)other, strbuilder_length(other));
} }
inline
bool strbuilder_append_fmt(StrBuilder* str, char const* fmt, ...) { bool strbuilder_append_fmt(StrBuilder* str, char const* fmt, ...) {
GEN_ASSERT(str != nullptr); GEN_ASSERT(str != nullptr);
ssize res; ssize res;

View File

@ -37,7 +37,6 @@ Operator_Member_Fwd, "operator"
Operator_Cast, "operator" Operator_Cast, "operator"
Operator_Cast_Fwd, "operator" Operator_Cast_Fwd, "operator"
Parameters, "__NA__" Parameters, "__NA__"
Parameters_Define, "__NA__"
Preprocess_Define, "define" Preprocess_Define, "define"
Preprocess_Include, "include" Preprocess_Include, "include"
Preprocess_If, "if" Preprocess_If, "if"

1 Invalid __NA__
37 Operator_Cast operator
38 Operator_Cast_Fwd operator
39 Parameters __NA__
Parameters_Define __NA__
40 Preprocess_Define define
41 Preprocess_Include include
42 Preprocess_If if

View File

@ -1,98 +1,95 @@
Invalid, "__invalid__" Invalid, "__invalid__"
Access_Private, "private" Access_Private, "private"
Access_Protected, "protected" Access_Protected, "protected"
Access_Public, "public" Access_Public, "public"
Access_MemberSymbol, "." Access_MemberSymbol, "."
Access_StaticSymbol, "::" Access_StaticSymbol, "::"
Ampersand, "&" Ampersand, "&"
Ampersand_DBL, "&&" Ampersand_DBL, "&&"
Assign_Classifer, ":" Assign_Classifer, ":"
Attribute_Open, "[[" Attribute_Open, "[["
Attribute_Close, "]]" Attribute_Close, "]]"
BraceCurly_Open, "{" BraceCurly_Open, "{"
BraceCurly_Close, "}" BraceCurly_Close, "}"
BraceSquare_Open, "[" BraceSquare_Open, "["
BraceSquare_Close, "]" BraceSquare_Close, "]"
Paren_Open, "(" Capture_Start, "("
Paren_Close, ")" Capture_End, ")"
Comment, "__comment__" Comment, "__comment__"
Comment_End, "__comment_end__" Comment_End, "__comment_end__"
Comment_Start, "__comment_start__" Comment_Start, "__comment_start__"
Char, "__character__" Char, "__character__"
Comma, "," Comma, ","
Decl_Class, "class" Decl_Class, "class"
Decl_GNU_Attribute, "__attribute__" Decl_GNU_Attribute, "__attribute__"
Decl_MSVC_Attribute, "__declspec" Decl_MSVC_Attribute, "__declspec"
Decl_Enum, "enum" Decl_Enum, "enum"
Decl_Extern_Linkage, "extern" Decl_Extern_Linkage, "extern"
Decl_Friend, "friend" Decl_Friend, "friend"
Decl_Module, "module" Decl_Module, "module"
Decl_Namespace, "namespace" Decl_Namespace, "namespace"
Decl_Operator, "operator" Decl_Operator, "operator"
Decl_Struct, "struct" Decl_Struct, "struct"
Decl_Template, "template" Decl_Template, "template"
Decl_Typedef, "typedef" Decl_Typedef, "typedef"
Decl_Using, "using" Decl_Using, "using"
Decl_Union, "union" Decl_Union, "union"
Identifier, "__identifier__" Identifier, "__identifier__"
Module_Import, "import" Module_Import, "import"
Module_Export, "export" Module_Export, "export"
NewLine, "__new_line__" NewLine, "__new_line__"
Number, "__number__" Number, "__number__"
Operator, "__operator__" Operator, "__operator__"
Preprocess_Hash, "#" Preprocess_Hash, "#"
Preprocess_Define, "define" Preprocess_Define, "define"
Preprocess_Define_Param, "__define_param__" Preprocess_If, "if"
Preprocess_If, "if" Preprocess_IfDef, "ifdef"
Preprocess_IfDef, "ifdef" Preprocess_IfNotDef, "ifndef"
Preprocess_IfNotDef, "ifndef" Preprocess_ElIf, "elif"
Preprocess_ElIf, "elif" Preprocess_Else, "else"
Preprocess_Else, "else" Preprocess_EndIf, "endif"
Preprocess_EndIf, "endif" Preprocess_Include, "include"
Preprocess_Include, "include" Preprocess_Pragma, "pragma"
Preprocess_Pragma, "pragma" Preprocess_Content, "__macro_content__"
Preprocess_Content, "__macro_content__" Preprocess_Macro, "__macro__"
Preprocess_Macro_Expr, "__macro_expression__" Preprocess_Unsupported, "__unsupported__"
Preprocess_Macro_Stmt, "__macro_statment__" Spec_Alignas, "alignas"
Preprocess_Macro_Typename, "__macro_typename__" Spec_Const, "const"
Preprocess_Unsupported, "__unsupported__" Spec_Consteval, "consteval"
Spec_Alignas, "alignas" Spec_Constexpr, "constexpr"
Spec_Const, "const" Spec_Constinit, "constinit"
Spec_Consteval, "consteval" Spec_Explicit, "explicit"
Spec_Constexpr, "constexpr" Spec_Extern, "extern"
Spec_Constinit, "constinit" Spec_Final, "final"
Spec_Explicit, "explicit" Spec_ForceInline, "forceinline"
Spec_Extern, "extern" Spec_Global, "global"
Spec_Final, "final" Spec_Inline, "inline"
Spec_ForceInline, "forceinline" Spec_Internal_Linkage, "internal"
Spec_Global, "global" Spec_LocalPersist, "local_persist"
Spec_Inline, "inline" Spec_Mutable, "mutable"
Spec_Internal_Linkage, "internal" Spec_NeverInline, "neverinline"
Spec_LocalPersist, "local_persist" Spec_Override, "override"
Spec_Mutable, "mutable" Spec_Static, "static"
Spec_NeverInline, "neverinline" Spec_ThreadLocal, "thread_local"
Spec_Override, "override" Spec_Volatile, "volatile"
Spec_Static, "static" Spec_Virtual, "virtual"
Spec_ThreadLocal, "thread_local" Star, "*"
Spec_Volatile, "volatile" Statement_End, ";"
Spec_Virtual, "virtual" StaticAssert, "static_assert"
Star, "*" String, "__string__"
Statement_End, ";" Type_Typename, "typename"
StaticAssert, "static_assert" Type_Unsigned, "unsigned"
String, "__string__" Type_Signed, "signed"
Type_Typename, "typename" Type_Short, "short"
Type_Unsigned, "unsigned" Type_Long, "long"
Type_Signed, "signed" Type_bool, "bool"
Type_Short, "short" Type_char, "char"
Type_Long, "long" Type_int, "int"
Type_bool, "bool" Type_double, "double"
Type_char, "char" Type_MS_int8, "__int8"
Type_int, "int" Type_MS_int16, "__int16"
Type_double, "double" Type_MS_int32, "__int32"
Type_MS_int8, "__int8" Type_MS_int64, "__int64"
Type_MS_int16, "__int16" Type_MS_W64, "_W64"
Type_MS_int32, "__int32" Varadic_Argument, "..."
Type_MS_int64, "__int64" __Attributes_Start, "__attrib_start__"
Type_MS_W64, "_W64"
Varadic_Argument, "..."
__Attributes_Start, "__attrib_start__"

1 Invalid __invalid__
2 Access_Private private
3 Access_Protected protected
4 Access_Public public
5 Access_MemberSymbol .
6 Access_StaticSymbol ::
7 Ampersand &
8 Ampersand_DBL &&
9 Assign_Classifer :
10 Attribute_Open [[
11 Attribute_Close ]]
12 BraceCurly_Open {
13 BraceCurly_Close }
14 BraceSquare_Open [
15 BraceSquare_Close ]
16 Paren_Open Capture_Start (
17 Paren_Close Capture_End )
18 Comment __comment__
19 Comment_End __comment_end__
20 Comment_Start __comment_start__
21 Char __character__
22 Comma ,
23 Decl_Class class
24 Decl_GNU_Attribute __attribute__
25 Decl_MSVC_Attribute __declspec
26 Decl_Enum enum
27 Decl_Extern_Linkage extern
28 Decl_Friend friend
29 Decl_Module module
30 Decl_Namespace namespace
31 Decl_Operator operator
32 Decl_Struct struct
33 Decl_Template template
34 Decl_Typedef typedef
35 Decl_Using using
36 Decl_Union union
37 Identifier __identifier__
38 Module_Import import
39 Module_Export export
40 NewLine __new_line__
41 Number __number__
42 Operator __operator__
43 Preprocess_Hash #
44 Preprocess_Define define
45 Preprocess_Define_Param Preprocess_If __define_param__ if
46 Preprocess_If Preprocess_IfDef if ifdef
47 Preprocess_IfDef Preprocess_IfNotDef ifdef ifndef
48 Preprocess_IfNotDef Preprocess_ElIf ifndef elif
49 Preprocess_ElIf Preprocess_Else elif else
50 Preprocess_Else Preprocess_EndIf else endif
51 Preprocess_EndIf Preprocess_Include endif include
52 Preprocess_Include Preprocess_Pragma include pragma
53 Preprocess_Pragma Preprocess_Content pragma __macro_content__
54 Preprocess_Content Preprocess_Macro __macro_content__ __macro__
55 Preprocess_Macro_Expr Preprocess_Unsupported __macro_expression__ __unsupported__
56 Preprocess_Macro_Stmt Spec_Alignas __macro_statment__ alignas
57 Preprocess_Macro_Typename Spec_Const __macro_typename__ const
58 Preprocess_Unsupported Spec_Consteval __unsupported__ consteval
59 Spec_Alignas Spec_Constexpr alignas constexpr
60 Spec_Const Spec_Constinit const constinit
61 Spec_Consteval Spec_Explicit consteval explicit
62 Spec_Constexpr Spec_Extern constexpr extern
63 Spec_Constinit Spec_Final constinit final
64 Spec_Explicit Spec_ForceInline explicit forceinline
65 Spec_Extern Spec_Global extern global
66 Spec_Final Spec_Inline final inline
67 Spec_ForceInline Spec_Internal_Linkage forceinline internal
68 Spec_Global Spec_LocalPersist global local_persist
69 Spec_Inline Spec_Mutable inline mutable
70 Spec_Internal_Linkage Spec_NeverInline internal neverinline
71 Spec_LocalPersist Spec_Override local_persist override
72 Spec_Mutable Spec_Static mutable static
73 Spec_NeverInline Spec_ThreadLocal neverinline thread_local
74 Spec_Override Spec_Volatile override volatile
75 Spec_Static Spec_Virtual static virtual
76 Spec_ThreadLocal Star thread_local *
77 Spec_Volatile Statement_End volatile ;
78 Spec_Virtual StaticAssert virtual static_assert
79 Star String * __string__
80 Statement_End Type_Typename ; typename
81 StaticAssert Type_Unsigned static_assert unsigned
82 String Type_Signed __string__ signed
83 Type_Typename Type_Short typename short
84 Type_Unsigned Type_Long unsigned long
85 Type_Signed Type_bool signed bool
86 Type_Short Type_char short char
87 Type_Long Type_int long int
88 Type_bool Type_double bool double
89 Type_char Type_MS_int8 char __int8
90 Type_int Type_MS_int16 int __int16
91 Type_double Type_MS_int32 double __int32
92 Type_MS_int8 Type_MS_int64 __int8 __int64
93 Type_MS_int16 Type_MS_W64 __int16 _W64
94 Type_MS_int32 Varadic_Argument __int32 ...
95 Type_MS_int64 __Attributes_Start __int64 __attrib_start__
Type_MS_W64 _W64
Varadic_Argument ...
__Attributes_Start __attrib_start__

View File

@ -47,7 +47,7 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false )
Str codetype_to_str( CodeType type ) Str codetype_to_str( CodeType type )
{ {
local_persist local_persist
Str lookup[] = { Str lookup[<num>] = {
<entries> <entries>
}; };
return lookup[ type ]; return lookup[ type ];
@ -57,7 +57,7 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false )
Str codetype_to_keyword_str( CodeType type ) Str codetype_to_keyword_str( CodeType type )
{ {
local_persist local_persist
Str lookup[] = { Str lookup[ <num> ] = {
<keywords> <keywords>
}; };
return lookup[ type ]; return lookup[ type ];
@ -139,7 +139,7 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
Str operator_to_str( Operator op ) Str operator_to_str( Operator op )
{ {
local_persist local_persist
Str lookup[] = { Str lookup[<num>] = {
<entries> <entries>
}; };
@ -237,7 +237,7 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
Str spec_to_str( Specifier type ) Str spec_to_str( Specifier type )
{ {
local_persist local_persist
Str lookup[] = { Str lookup[<num>] = {
<entries> <entries>
}; };
@ -283,7 +283,7 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
body_append(result, enum_code); body_append(result, enum_code);
if (use_c_definition) if (use_c_definition)
{ {
CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier Specifier; )); CodeTypedef specifier_t = parse_typedef( code(typedef u32 Specifier; ));
body_append(result, specifier_t); body_append(result, specifier_t);
} }
@ -353,7 +353,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path, bool use_c_
#pragma push_macro("GEN_DEFINE_ATTRIBUTE_TOKENS") #pragma push_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
#undef GEN_DEFINE_ATTRIBUTE_TOKENS #undef GEN_DEFINE_ATTRIBUTE_TOKENS
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), MT_Statement, { {}, strbuilder_to_str(attribute_define_entries) } ); CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), strbuilder_to_str(attribute_define_entries) );
#pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS") #pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
// We cannot parse this enum, it has Attribute names as enums // We cannot parse this enum, it has Attribute names as enums
@ -499,60 +499,59 @@ CodeBody gen_ast_inlines()
#pragma pop_macro("GEN_NS") #pragma pop_macro("GEN_NS")
#pragma pop_macro("CodeInvalid") #pragma pop_macro("CodeInvalid")
CodeBody impl_code = parse_global_body( token_fmt( "typename", name(Code), code_impl_tmpl )); CodeBody impl_code = parse_global_body( token_fmt( "typename", Str name(Code), code_impl_tmpl ));
CodeBody impl_code_body = parse_global_body( token_fmt( "typename", name(CodeBody), code_impl_tmpl )); CodeBody impl_code_body = parse_global_body( token_fmt( "typename", Str name(CodeBody), code_impl_tmpl ));
CodeBody impl_code_attr = parse_global_body( token_fmt( "typename", name(CodeAttributes), code_impl_tmpl )); CodeBody impl_code_attr = parse_global_body( token_fmt( "typename", Str name(CodeAttributes), code_impl_tmpl ));
CodeBody impl_code_cmt = parse_global_body( token_fmt( "typename", name(CodeComment), code_impl_tmpl )); CodeBody impl_code_cmt = parse_global_body( token_fmt( "typename", Str name(CodeComment), code_impl_tmpl ));
CodeBody impl_code_constr = parse_global_body( token_fmt( "typename", name(CodeConstructor), code_impl_tmpl )); CodeBody impl_code_constr = parse_global_body( token_fmt( "typename", Str name(CodeConstructor), code_impl_tmpl ));
CodeBody impl_code_class = parse_global_body( token_fmt( "typename", name(CodeClass), code_impl_tmpl )); CodeBody impl_code_class = parse_global_body( token_fmt( "typename", Str name(CodeClass), code_impl_tmpl ));
CodeBody impl_code_define = parse_global_body( token_fmt( "typename", name(CodeDefine), code_impl_tmpl )); CodeBody impl_code_define = parse_global_body( token_fmt( "typename", Str name(CodeDefine), code_impl_tmpl ));
CodeBody impl_code_define_params = parse_global_body( token_fmt( "typename", name(CodeDefineParams), code_impl_tmpl )); CodeBody impl_code_destruct = parse_global_body( token_fmt( "typename", Str name(CodeDestructor), code_impl_tmpl ));
CodeBody impl_code_destruct = parse_global_body( token_fmt( "typename", name(CodeDestructor), code_impl_tmpl )); CodeBody impl_code_enum = parse_global_body( token_fmt( "typename", Str name(CodeEnum), code_impl_tmpl ));
CodeBody impl_code_enum = parse_global_body( token_fmt( "typename", name(CodeEnum), code_impl_tmpl )); CodeBody impl_code_exec = parse_global_body( token_fmt( "typename", Str name(CodeExec), code_impl_tmpl ));
CodeBody impl_code_exec = parse_global_body( token_fmt( "typename", name(CodeExec), code_impl_tmpl )); CodeBody impl_code_extern = parse_global_body( token_fmt( "typename", Str name(CodeExtern), code_impl_tmpl ));
CodeBody impl_code_extern = parse_global_body( token_fmt( "typename", name(CodeExtern), code_impl_tmpl )); CodeBody impl_code_include = parse_global_body( token_fmt( "typename", Str name(CodeInclude), code_impl_tmpl ));
CodeBody impl_code_include = parse_global_body( token_fmt( "typename", name(CodeInclude), code_impl_tmpl )); CodeBody impl_code_friend = parse_global_body( token_fmt( "typename", Str name(CodeFriend), code_impl_tmpl ));
CodeBody impl_code_friend = parse_global_body( token_fmt( "typename", name(CodeFriend), code_impl_tmpl )); CodeBody impl_code_fn = parse_global_body( token_fmt( "typename", Str name(CodeFn), code_impl_tmpl ));
CodeBody impl_code_fn = parse_global_body( token_fmt( "typename", name(CodeFn), code_impl_tmpl )); CodeBody impl_code_module = parse_global_body( token_fmt( "typename", Str name(CodeModule), code_impl_tmpl ));
CodeBody impl_code_module = parse_global_body( token_fmt( "typename", name(CodeModule), code_impl_tmpl )); CodeBody impl_code_ns = parse_global_body( token_fmt( "typename", Str name(CodeNS), code_impl_tmpl ));
CodeBody impl_code_ns = parse_global_body( token_fmt( "typename", name(CodeNS), code_impl_tmpl )); CodeBody impl_code_op = parse_global_body( token_fmt( "typename", Str name(CodeOperator), code_impl_tmpl ));
CodeBody impl_code_op = parse_global_body( token_fmt( "typename", name(CodeOperator), code_impl_tmpl )); CodeBody impl_code_opcast = parse_global_body( token_fmt( "typename", Str name(CodeOpCast), code_impl_tmpl ));
CodeBody impl_code_opcast = parse_global_body( token_fmt( "typename", name(CodeOpCast), code_impl_tmpl )); CodeBody impl_code_params = parse_global_body( token_fmt( "typename", Str name(CodeParams), code_impl_tmpl ));
CodeBody impl_code_params = parse_global_body( token_fmt( "typename", name(CodeParams), code_impl_tmpl )); CodeBody impl_code_pragma = parse_global_body( token_fmt( "typename", Str name(CodePragma), code_impl_tmpl ));
CodeBody impl_code_pragma = parse_global_body( token_fmt( "typename", name(CodePragma), code_impl_tmpl )); CodeBody impl_code_precond = parse_global_body( token_fmt( "typename", Str name(CodePreprocessCond), code_impl_tmpl ));
CodeBody impl_code_precond = parse_global_body( token_fmt( "typename", name(CodePreprocessCond), code_impl_tmpl )); CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", Str name(CodeSpecifiers), code_impl_tmpl ));
CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", name(CodeSpecifiers), code_impl_tmpl )); CodeBody impl_code_struct = parse_global_body( token_fmt( "typename", Str name(CodeStruct), code_impl_tmpl ));
CodeBody impl_code_struct = parse_global_body( token_fmt( "typename", name(CodeStruct), code_impl_tmpl )); CodeBody impl_code_tmpl = parse_global_body( token_fmt( "typename", Str name(CodeTemplate), code_impl_tmpl ));
CodeBody impl_code_tmpl = parse_global_body( token_fmt( "typename", name(CodeTemplate), code_impl_tmpl )); CodeBody impl_code_type = parse_global_body( token_fmt( "typename", Str name(CodeTypename), code_impl_tmpl ));
CodeBody impl_code_type = parse_global_body( token_fmt( "typename", name(CodeTypename), code_impl_tmpl )); CodeBody impl_code_typedef = parse_global_body( token_fmt( "typename", Str name(CodeTypedef), code_impl_tmpl ));
CodeBody impl_code_typedef = parse_global_body( token_fmt( "typename", name(CodeTypedef), code_impl_tmpl )); CodeBody impl_code_union = parse_global_body( token_fmt( "typename", Str name(CodeUnion), code_impl_tmpl ));
CodeBody impl_code_union = parse_global_body( token_fmt( "typename", name(CodeUnion), code_impl_tmpl )); CodeBody impl_code_using = parse_global_body( token_fmt( "typename", Str name(CodeUsing), code_impl_tmpl ));
CodeBody impl_code_using = parse_global_body( token_fmt( "typename", name(CodeUsing), code_impl_tmpl )); CodeBody impl_code_var = parse_global_body( token_fmt( "typename", Str name(CodeVar), code_impl_tmpl ));
CodeBody impl_code_var = parse_global_body( token_fmt( "typename", name(CodeVar), code_impl_tmpl ));
body_append(impl_code_attr, parse_global_body( token_fmt( "typename", name(Attributes), codetype_impl_tmpl ))); body_append(impl_code_attr, parse_global_body( token_fmt( "typename", Str name(Attributes), codetype_impl_tmpl )));
body_append(impl_code_cmt, parse_global_body( token_fmt( "typename", name(Comment), codetype_impl_tmpl ))); body_append(impl_code_cmt, parse_global_body( token_fmt( "typename", Str name(Comment), codetype_impl_tmpl )));
body_append(impl_code_constr, parse_global_body( token_fmt( "typename", name(Constructor), codetype_impl_tmpl ))); body_append(impl_code_constr, parse_global_body( token_fmt( "typename", Str name(Constructor), codetype_impl_tmpl )));
body_append(impl_code_define, parse_global_body( token_fmt( "typename", name(Define), codetype_impl_tmpl ))); body_append(impl_code_define, parse_global_body( token_fmt( "typename", Str name(Define), codetype_impl_tmpl )));
body_append(impl_code_destruct, parse_global_body( token_fmt( "typename", name(Destructor), codetype_impl_tmpl ))); body_append(impl_code_destruct, parse_global_body( token_fmt( "typename", Str name(Destructor), codetype_impl_tmpl )));
body_append(impl_code_enum, parse_global_body( token_fmt( "typename", name(Enum), codetype_impl_tmpl ))); body_append(impl_code_enum, parse_global_body( token_fmt( "typename", Str name(Enum), codetype_impl_tmpl )));
body_append(impl_code_exec, parse_global_body( token_fmt( "typename", name(Exec), codetype_impl_tmpl ))); body_append(impl_code_exec, parse_global_body( token_fmt( "typename", Str name(Exec), codetype_impl_tmpl )));
body_append(impl_code_extern, parse_global_body( token_fmt( "typename", name(Extern), codetype_impl_tmpl ))); body_append(impl_code_extern, parse_global_body( token_fmt( "typename", Str name(Extern), codetype_impl_tmpl )));
body_append(impl_code_include, parse_global_body( token_fmt( "typename", name(Include), codetype_impl_tmpl ))); body_append(impl_code_include, parse_global_body( token_fmt( "typename", Str name(Include), codetype_impl_tmpl )));
body_append(impl_code_friend, parse_global_body( token_fmt( "typename", name(Friend), codetype_impl_tmpl ))); body_append(impl_code_friend, parse_global_body( token_fmt( "typename", Str name(Friend), codetype_impl_tmpl )));
body_append(impl_code_fn, parse_global_body( token_fmt( "typename", name(Fn), codetype_impl_tmpl ))); body_append(impl_code_fn, parse_global_body( token_fmt( "typename", Str name(Fn), codetype_impl_tmpl )));
body_append(impl_code_module, parse_global_body( token_fmt( "typename", name(Module), codetype_impl_tmpl ))); body_append(impl_code_module, parse_global_body( token_fmt( "typename", Str name(Module), codetype_impl_tmpl )));
body_append(impl_code_ns, parse_global_body( token_fmt( "typename", name(NS), codetype_impl_tmpl ))); body_append(impl_code_ns, parse_global_body( token_fmt( "typename", Str name(NS), codetype_impl_tmpl )));
body_append(impl_code_op, parse_global_body( token_fmt( "typename", name(Operator), codetype_impl_tmpl ))); body_append(impl_code_op, parse_global_body( token_fmt( "typename", Str name(Operator), codetype_impl_tmpl )));
body_append(impl_code_opcast, parse_global_body( token_fmt( "typename", name(OpCast), codetype_impl_tmpl ))); body_append(impl_code_opcast, parse_global_body( token_fmt( "typename", Str name(OpCast), codetype_impl_tmpl )));
body_append(impl_code_pragma, parse_global_body( token_fmt( "typename", name(Pragma), codetype_impl_tmpl ))); body_append(impl_code_pragma, parse_global_body( token_fmt( "typename", Str name(Pragma), codetype_impl_tmpl )));
body_append(impl_code_precond, parse_global_body( token_fmt( "typename", name(PreprocessCond), codetype_impl_tmpl ))); body_append(impl_code_precond, parse_global_body( token_fmt( "typename", Str name(PreprocessCond), codetype_impl_tmpl )));
body_append(impl_code_tmpl, parse_global_body( token_fmt( "typename", name(Template), codetype_impl_tmpl ))); body_append(impl_code_tmpl, parse_global_body( token_fmt( "typename", Str name(Template), codetype_impl_tmpl )));
body_append(impl_code_type, parse_global_body( token_fmt( "typename", name(Typename), codetype_impl_tmpl ))); body_append(impl_code_type, parse_global_body( token_fmt( "typename", Str name(Typename), codetype_impl_tmpl )));
body_append(impl_code_typedef, parse_global_body( token_fmt( "typename", name(Typedef), codetype_impl_tmpl ))); body_append(impl_code_typedef, parse_global_body( token_fmt( "typename", Str name(Typedef), codetype_impl_tmpl )));
body_append(impl_code_union, parse_global_body( token_fmt( "typename", name(Union), codetype_impl_tmpl ))); body_append(impl_code_union, parse_global_body( token_fmt( "typename", Str name(Union), codetype_impl_tmpl )));
body_append(impl_code_using, parse_global_body( token_fmt( "typename", name(Using), codetype_impl_tmpl ))); body_append(impl_code_using, parse_global_body( token_fmt( "typename", Str name(Using), codetype_impl_tmpl )));
body_append(impl_code_var, parse_global_body( token_fmt( "typename", name(Var), codetype_impl_tmpl ))); body_append(impl_code_var, parse_global_body( token_fmt( "typename", Str name(Var), codetype_impl_tmpl )));
#pragma push_macro("forceinline") #pragma push_macro("forceinline")
#undef forceinline #undef forceinline
@ -564,35 +563,34 @@ CodeBody gen_ast_inlines()
); );
#pragma pop_macro("forceinline") #pragma pop_macro("forceinline")
CodeBody impl_cast_body = parse_global_body( token_fmt( "typename", name(Body), cast_tmpl )); CodeBody impl_cast_body = parse_global_body( token_fmt( "typename", Str name(Body), cast_tmpl ));
CodeBody impl_cast_attribute = parse_global_body( token_fmt( "typename", name(Attributes), cast_tmpl )); CodeBody impl_cast_attribute = parse_global_body( token_fmt( "typename", Str name(Attributes), cast_tmpl ));
CodeBody impl_cast_cmt = parse_global_body( token_fmt( "typename", name(Comment), cast_tmpl )); CodeBody impl_cast_cmt = parse_global_body( token_fmt( "typename", Str name(Comment), cast_tmpl ));
CodeBody impl_cast_constr = parse_global_body( token_fmt( "typename", name(Constructor), cast_tmpl )); CodeBody impl_cast_constr = parse_global_body( token_fmt( "typename", Str name(Constructor), cast_tmpl ));
CodeBody impl_cast_class = parse_global_body( token_fmt( "typename", name(Class), cast_tmpl )); CodeBody impl_cast_class = parse_global_body( token_fmt( "typename", Str name(Class), cast_tmpl ));
CodeBody impl_cast_define = parse_global_body( token_fmt( "typename", name(Define), cast_tmpl )); CodeBody impl_cast_define = parse_global_body( token_fmt( "typename", Str name(Define), cast_tmpl ));
CodeBody impl_cast_define_params = parse_global_body( token_fmt( "typename", name(DefineParams), cast_tmpl )); CodeBody impl_cast_destruct = parse_global_body( token_fmt( "typename", Str name(Destructor), cast_tmpl ));
CodeBody impl_cast_destruct = parse_global_body( token_fmt( "typename", name(Destructor), cast_tmpl )); CodeBody impl_cast_enum = parse_global_body( token_fmt( "typename", Str name(Enum), cast_tmpl ));
CodeBody impl_cast_enum = parse_global_body( token_fmt( "typename", name(Enum), cast_tmpl )); CodeBody impl_cast_exec = parse_global_body( token_fmt( "typename", Str name(Exec), cast_tmpl ));
CodeBody impl_cast_exec = parse_global_body( token_fmt( "typename", name(Exec), cast_tmpl )); CodeBody impl_cast_extern = parse_global_body( token_fmt( "typename", Str name(Extern), cast_tmpl ));
CodeBody impl_cast_extern = parse_global_body( token_fmt( "typename", name(Extern), cast_tmpl )); CodeBody impl_cast_friend = parse_global_body( token_fmt( "typename", Str name(Friend), cast_tmpl ));
CodeBody impl_cast_friend = parse_global_body( token_fmt( "typename", name(Friend), cast_tmpl )); CodeBody impl_cast_fn = parse_global_body( token_fmt( "typename", Str name(Fn), cast_tmpl ));
CodeBody impl_cast_fn = parse_global_body( token_fmt( "typename", name(Fn), cast_tmpl )); CodeBody impl_cast_include = parse_global_body( token_fmt( "typename", Str name(Include), cast_tmpl ));
CodeBody impl_cast_include = parse_global_body( token_fmt( "typename", name(Include), cast_tmpl )); CodeBody impl_cast_module = parse_global_body( token_fmt( "typename", Str name(Module), cast_tmpl ));
CodeBody impl_cast_module = parse_global_body( token_fmt( "typename", name(Module), cast_tmpl )); CodeBody impl_cast_ns = parse_global_body( token_fmt( "typename", Str name(NS), cast_tmpl ));
CodeBody impl_cast_ns = parse_global_body( token_fmt( "typename", name(NS), cast_tmpl )); CodeBody impl_cast_op = parse_global_body( token_fmt( "typename", Str name(Operator), cast_tmpl ));
CodeBody impl_cast_op = parse_global_body( token_fmt( "typename", name(Operator), cast_tmpl )); CodeBody impl_cast_opcast = parse_global_body( token_fmt( "typename", Str name(OpCast), cast_tmpl ));
CodeBody impl_cast_opcast = parse_global_body( token_fmt( "typename", name(OpCast), cast_tmpl )); CodeBody impl_cast_params = parse_global_body( token_fmt( "typename", Str name(Params), cast_tmpl ));
CodeBody impl_cast_params = parse_global_body( token_fmt( "typename", name(Params), cast_tmpl )); CodeBody impl_cast_pragma = parse_global_body( token_fmt( "typename", Str name(Pragma), cast_tmpl ));
CodeBody impl_cast_pragma = parse_global_body( token_fmt( "typename", name(Pragma), cast_tmpl )); CodeBody impl_cast_precond = parse_global_body( token_fmt( "typename", Str name(PreprocessCond), cast_tmpl ));
CodeBody impl_cast_precond = parse_global_body( token_fmt( "typename", name(PreprocessCond), cast_tmpl )); CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", Str name(Specifiers), cast_tmpl ));
CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", name(Specifiers), cast_tmpl )); CodeBody impl_cast_struct = parse_global_body( token_fmt( "typename", Str name(Struct), cast_tmpl ));
CodeBody impl_cast_struct = parse_global_body( token_fmt( "typename", name(Struct), cast_tmpl )); CodeBody impl_cast_tmpl = parse_global_body( token_fmt( "typename", Str name(Template), cast_tmpl ));
CodeBody impl_cast_tmpl = parse_global_body( token_fmt( "typename", name(Template), cast_tmpl )); CodeBody impl_cast_type = parse_global_body( token_fmt( "typename", Str name(Typename), cast_tmpl ));
CodeBody impl_cast_type = parse_global_body( token_fmt( "typename", name(Typename), cast_tmpl )); CodeBody impl_cast_typedef = parse_global_body( token_fmt( "typename", Str name(Typedef), cast_tmpl ));
CodeBody impl_cast_typedef = parse_global_body( token_fmt( "typename", name(Typedef), cast_tmpl )); CodeBody impl_cast_union = parse_global_body( token_fmt( "typename", Str name(Union), cast_tmpl ));
CodeBody impl_cast_union = parse_global_body( token_fmt( "typename", name(Union), cast_tmpl )); CodeBody impl_cast_using = parse_global_body( token_fmt( "typename", Str name(Using), cast_tmpl ));
CodeBody impl_cast_using = parse_global_body( token_fmt( "typename", name(Using), cast_tmpl )); CodeBody impl_cast_var = parse_global_body( token_fmt( "typename", Str name(Var), cast_tmpl ));
CodeBody impl_cast_var = parse_global_body( token_fmt( "typename", name(Var), cast_tmpl ));
CodeBody result = def_global_body( args( CodeBody result = def_global_body( args(
def_pragma( txt("region generated code inline implementation")), def_pragma( txt("region generated code inline implementation")),
@ -604,7 +602,6 @@ CodeBody gen_ast_inlines()
impl_code_constr, impl_code_constr,
impl_code_class, impl_code_class,
impl_code_define, impl_code_define,
impl_code_define_params,
impl_code_destruct, impl_code_destruct,
impl_code_enum, impl_code_enum,
impl_code_exec, impl_code_exec,
@ -639,7 +636,6 @@ CodeBody gen_ast_inlines()
impl_cast_constr, impl_cast_constr,
impl_cast_class, impl_cast_class,
impl_cast_define, impl_cast_define,
impl_cast_define_params,
impl_cast_destruct, impl_cast_destruct,
impl_cast_enum, impl_cast_enum,
impl_cast_exec, impl_cast_exec,

View File

@ -41,7 +41,7 @@
#undef local_persist #undef local_persist
#undef bit #undef bit
#undef bitfield_is_set #undef bitfield_is_equal
#undef cast #undef cast

View File

@ -238,7 +238,6 @@ Interface :
* parse_class * parse_class
* parse_constructor * parse_constructor
* parse_define
* parse_destructor * parse_destructor
* parse_enum * parse_enum
* parse_export_body * parse_export_body
@ -323,7 +322,6 @@ Code <name> = parse_<function name>( gen_code_str );
The following are provided predefined by the library as they are commonly used: The following are provided predefined by the library as they are commonly used:
* `enum_underlying_macro`
* `access_public` * `access_public`
* `access_protected` * `access_protected`
* `access_private` * `access_private`

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 175 KiB

View File

@ -65,123 +65,19 @@ int gen_main()
Context ctx {}; Context ctx {};
gen::init(& ctx); gen::init(& ctx);
register_macros( args( ctx.PreprocessorDefines.append(txt("GEN_API_C_BEGIN"));
(Macro { txt("bit"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("GEN_API_C_END"));
(Macro { txt("bitfield_is_set"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("Array("));
(Macro { txt("GEN_C_LIKE_CPP"), MT_Expression, MF_Null }), ctx.PreprocessorDefines.append(txt("HashTable("));
(Macro { txt("cast"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("GEN_NS_PARSER"));
(Macro { txt("ccast"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("GEN_NS_PARSER_BEGIN"));
(Macro { txt("rcast"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("GEN_NS_PARSER_END"));
(Macro { txt("pcast"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("Using_Code("));
(Macro { txt("scast"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("Using_CodeOps("));
(Macro { txt("stringize_va"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("GEN_OPTIMIZE_MAPPINGS_BEGIN"));
(Macro { txt("stringize"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("GEN_OPITMIZE_MAPPINGS_END"));
(Macro { txt("do_once"), MT_Expression, MF_Functional }), ctx.PreprocessorDefines.append(txt("GEN_PARAM_DEFAULT"));
(Macro { txt("do_once_defer"), MT_Expression, MF_Functional }), //PreprocessorDefines.append(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"));
(Macro { txt("do_once_start"), MT_Statement, MF_Null }),
(Macro { txt("do_once_end"), MT_Statement, MF_Null }),
(Macro { txt("labeled_scope_start"), MT_Statement, MF_Null }),
(Macro { txt("labeled_scope_end"), MT_Statement, MF_Null }),
(Macro { txt("compiler_decorated_func_name"), MT_Expression, MF_Null }),
(Macro { txt("num_args_impl"), MT_Expression, MF_Functional }),
(Macro { txt("num_args"), MT_Expression, MF_Functional }),
(Macro { txt("count_of"), MT_Expression, MF_Functional }),
(Macro { txt("clamp"), MT_Expression, MF_Functional }),
(Macro { txt("is_between"), MT_Expression, MF_Functional }),
(Macro { txt("size_of"), MT_Expression, MF_Functional }),
(Macro { txt("min"), MT_Expression, MF_Functional }),
(Macro { txt("max"), MT_Expression, MF_Functional }),
(Macro { txt("offset_of"), MT_Expression, MF_Functional }),
(Macro { txt("static_assert"), MT_Statement, MF_Functional }),
(Macro { txt("typeof"), MT_Expression, MF_Null }),
(Macro { txt("GEN_API_C_BEGIN"), MT_Statement, MF_Null }),
(Macro { txt("GEN_API_C_END"), MT_Statement, MF_Null }),
(Macro { txt("nullptr"), MT_Expression, MF_Null }),
(Macro { txt("GEN_REMOVE_PTR"), MT_Expression, MF_Functional }),
(Macro { txt("GEN_PARAM_DEFAULT"), MT_Expression, MF_Null }),
(Macro { txt("struct_init"), MT_Expression, MF_Functional }),
(Macro { txt("GEN_OPTIMIZE_MAPPINGS_BEGIN"), MT_Statement, MF_Null }),
(Macro { txt("GEN_OPITMIZE_MAPPINGS_END"), MT_Statement, MF_Null }),
(Macro { txt("Array"), MT_Typename, MF_Functional }),
(Macro { txt("HashTable"), MT_Typename, MF_Functional }),
(Macro { txt("Using_Code"), MT_Statement, MF_Functional }),
(Macro { txt("Using_CodeOps"), MT_Statement, MF_Functional }),
(Macro { txt("kilobytes"), MT_Expression, MF_Functional }),
(Macro { txt("megabytes"), MT_Expression, MF_Functional }),
(Macro { txt("gigabytes"), MT_Expression, MF_Functional }),
(Macro { txt("terabytes"), MT_Expression, MF_Functional }),
(Macro { txt("GEN__ONES"), MT_Expression, MF_Null }),
(Macro { txt("GEN__HIGHS"), MT_Expression, MF_Null }),
(Macro { txt("GEN__HAS_ZERO"), MT_Expression, MF_Functional }),
(Macro { txt("zero_item"), MT_Expression, MF_Functional }),
(Macro { txt("zero_array"), MT_Expression, MF_Functional }),
(Macro { txt("GEN_DEFAULT_MEMORY_ALIGNMENT"), MT_Expression, MF_Null }),
(Macro { txt("GEN_DEFAULT_ALLOCATOR_FLAGS"), MT_Expression, MF_Null }),
(Macro { txt("alloc_item"), MT_Expression, MF_Functional }),
(Macro { txt("alloc_array"), MT_Expression, MF_Functional }),
(Macro { txt("malloc"), MT_Expression, MF_Functional }),
(Macro { txt("mfree"), MT_Expression, MF_Functional }),
(Macro { txt("GEN_PRINTF_MAXLEN"), MT_Expression, MF_Null }),
(Macro { txt("cast_to_str"), MT_Expression, MF_Functional }),
(Macro { txt("current"), MT_Expression, MF_Null }),
(Macro { txt("txt"), MT_Expression, MF_Functional }),
(Macro { txt("GEN_FILE_OPEN_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
(Macro { txt("GEN_FILE_READ_AT_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
(Macro { txt("GEN_FILE_WRITE_AT_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
(Macro { txt("GEN_FILE_SEEK_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
(Macro { txt("GEN_FILE_CLOSE_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
(Macro { txt("log_failure"), MT_Expression, MF_Null }),
(Macro { txt("operator"), MT_Expression, MF_Null }),
(Macro { txt("InvalidCode"), MT_Expression, MF_Null }),
(Macro { txt("NullCode"), MT_Expression, MF_Null }),
(Macro { txt("Verify_POD"), MT_Expression, MF_Functional }),
(Macro { txt("gen_main"), MT_Statement, MF_Null })
));
register_macros( args(
(Macro { txt("name"), MT_Expression, MF_Functional }),
(Macro { txt("code"), MT_Expression, MF_Functional }),
(Macro { txt("args"), MT_Expression, MF_Functional }),
(Macro { txt("code_str"), MT_Expression, MF_Functional }),
(Macro { txt("code_fmt"), MT_Expression, MF_Functional }),
(Macro { txt("parse_fmt"), MT_Expression, MF_Functional }),
(Macro { txt("token_fmt"), MT_Expression, MF_Functional }),
(Macro { txt("check_member_val"), MT_Expression, MF_Functional }),
(Macro { txt("check_member_str"), MT_Expression, MF_Functional }),
(Macro { txt("check_member_content"), MT_Expression, MF_Functional }),
(Macro { txt("check_member_ast"), MT_Expression, MF_Functional }),
(Macro { txt("check_params"), MT_Expression, MF_Functional }),
(Macro { txt("check_param_eq_ret"), MT_Expression, MF_Functional }),
(Macro { txt("specs"), MT_Expression, MF_Functional | MF_Allow_As_Identifier }),
(Macro { txt("name_check"), MT_Expression, MF_Functional }),
(Macro { txt("null_check"), MT_Expression, MF_Functional }),
(Macro { txt("def_body_start"), MT_Expression, MF_Functional }),
(Macro { txt("def_body_code_array_start"), MT_Expression, MF_Functional }),
(Macro { txt("move_forward"), MT_Expression, MF_Functional }),
(Macro { txt("skip_whitespace"), MT_Expression, MF_Functional }),
(Macro { txt("end_line"), MT_Expression, MF_Functional }),
(Macro { txt("check_parse_args"), MT_Expression, MF_Functional }),
(Macro { txt("currtok_noskip"), MT_Expression, MF_Null }),
(Macro { txt("currtok"), MT_Expression, MF_Null }),
(Macro { txt("peektok"), MT_Expression, MF_Null }),
(Macro { txt("prevtok"), MT_Expression, MF_Null }),
(Macro { txt("nexttok"), MT_Expression, MF_Null }),
(Macro { txt("nexttok_noskip"), MT_Expression, MF_Null }),
(Macro { txt("eat"), MT_Expression, MF_Functional }),
(Macro { txt("left"), MT_Expression, MF_Null | MF_Allow_As_Identifier }),
(Macro { txt("def_assign"), MT_Expression, MF_Functional }),
(Macro { txt("CHECK_WAS_DEFINED"), MT_Expression, MF_Null }),
(Macro { txt("check_noskip"), MT_Expression, MF_Functional }),
(Macro { txt("check"), MT_Expression, MF_Functional | MF_Allow_As_Identifier }),
(Macro { txt("push_scope"), MT_Expression, MF_Functional }),
(Macro { txt("cut_length"), MT_Expression, MF_Null }),
(Macro { txt("cut_ptr"), MT_Expression, MF_Null }),
(Macro { txt("pos"), MT_Expression, MF_Null }),
(Macro { txt("move_fwd"), MT_Expression, MF_Functional }),
(Macro { txt("Entry"), MT_Expression, MF_Functional }),
(Macro { txt("CheckEndParams"), MT_Expression, MF_Functional }),
(Macro { txt("UseTemplateCapture"), MT_Expression, MF_Null }),
(Macro { txt("check_current"), MT_Expression, MF_Functional })
));
Code push_ignores = scan_file( path_base "helpers/push_ignores.inline.hpp" ); Code push_ignores = scan_file( path_base "helpers/push_ignores.inline.hpp" );
Code pop_ignores = scan_file( path_base "helpers/pop_ignores.inline.hpp" ); Code pop_ignores = scan_file( path_base "helpers/pop_ignores.inline.hpp" );
@ -243,8 +139,8 @@ int gen_main()
CodeTemplate tmpl = cast(CodeTemplate, entry); CodeTemplate tmpl = cast(CodeTemplate, entry);
if ( tmpl->Declaration->Name.contains(txt("swap"))) if ( tmpl->Declaration->Name.contains(txt("swap")))
{ {
register_macro({ txt("swap"), MT_Expression, MF_Functional }); log_fmt("SWAPPED");
CodeDefine macro_swap = parse_define( txt(R"( CodeBody macro_swap = parse_global_body( txt(R"(
#define swap( a, b ) \ #define swap( a, b ) \
do \ do \
{ \ { \
@ -345,8 +241,7 @@ do \
{ {
if ( str_contains(entry->Name, txt("Msg_Invalid_Value"))) if ( str_contains(entry->Name, txt("Msg_Invalid_Value")))
{ {
Opts_def_define opts = { {}, entry->Value->Content }; CodeDefine define = def_define(entry->Name, entry->Value->Content);
CodeDefine define = def_define(entry->Name, MT_Expression, opts );
header_printing.append(define); header_printing.append(define);
continue; continue;
} }
@ -512,8 +407,7 @@ do \
CodeVar var = cast(CodeVar, entry); CodeVar var = cast(CodeVar, entry);
if (var->Specs.has(Spec_Constexpr) > -1) if (var->Specs.has(Spec_Constexpr) > -1)
{ {
Opts_def_define opts = { {}, entry->Value->Content }; CodeDefine define = def_define(entry->Name, entry->Value->Content);
CodeDefine define = def_define(entry->Name, MT_Expression, opts);
header_filesystem.append(define); header_filesystem.append(define);
continue; continue;
} }
@ -917,8 +811,7 @@ R"(#define AST_ArrSpecs_Cap \
ast.append(def); ast.append(def);
break; break;
} }
Opts_def_define opts = { {}, var->Value.to_strbuilder() }; CodeDefine def = def_define(var->Name, var->Value.to_strbuilder());
CodeDefine def = def_define(var->Name, MT_Expression, opts );
ast.append(def); ast.append(def);
break; break;
} }
@ -939,7 +832,6 @@ R"(#define AST_ArrSpecs_Cap \
txt("CodeClass"), txt("CodeClass"),
txt("CodeConstructor"), txt("CodeConstructor"),
txt("CodeDefine"), txt("CodeDefine"),
txt("CodeDefineParams"),
txt("CodeDestructor"), txt("CodeDestructor"),
txt("CodeEnum"), txt("CodeEnum"),
txt("CodeExec"), txt("CodeExec"),
@ -1113,9 +1005,8 @@ R"(#define <interface_name>( code ) _Generic( (code), \
break; break;
} }
CodeBody array_arena = gen_array(txt("gen_Arena"), txt("Array_gen_Arena")); CodeBody array_arena = gen_array(txt("gen_Arena"), txt("Array_gen_Arena"));
CodeBody array_pool = gen_array(txt("gen_Pool"), txt("Array_gen_Pool")); CodeBody array_pool = gen_array(txt("gen_Pool"), txt("Array_gen_Pool"));
CodeBody ht_preprocessor_macro = gen_hashtable(txt("gen_Macro"), txt("MacroTable"));
CodeBody parsed_interface = parse_file( path_base "components/interface.hpp" ); CodeBody parsed_interface = parse_file( path_base "components/interface.hpp" );
CodeBody interface = def_body(CT_Global_Body); CodeBody interface = def_body(CT_Global_Body);
@ -1126,9 +1017,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_interface, interface ); b32 found = ignore_preprocess_cond_block(txt("GEN_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);
if (found) break;
interface.append(entry); interface.append(entry);
} }
break; break;
@ -1139,14 +1027,12 @@ R"(#define <interface_name>( code ) _Generic( (code), \
CodeFn fn = cast(CodeFn, entry); CodeFn fn = cast(CodeFn, entry);
Code prev = entry->Prev; Code prev = entry->Prev;
#if 0
if (prev && prev->Name.is_equal(entry->Name)) { if (prev && prev->Name.is_equal(entry->Name)) {
// rename second definition so there isn't a symbol conflict // rename second definition so there isn't a symbol conflict
StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", entry->Name); StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", entry->Name);
entry->Name = cache_str(postfix_arr.to_str()); entry->Name = cache_str(postfix_arr.to_str());
postfix_arr.free(); postfix_arr.free();
} }
#endif
b32 handled= false; b32 handled= false;
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_"))) for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
@ -1323,10 +1209,8 @@ R"(#define <interface_name>( code ) _Generic( (code), \
if (var->Specs) if (var->Specs)
{ {
s32 constexpr_found = var->Specs.remove( Spec_Constexpr ); s32 constexpr_found = var->Specs.remove( Spec_Constexpr );
if (constexpr_found > -1) if (constexpr_found > -1) {
{ CodeDefine define = def_define(entry->Name, entry->Value->Content);
Opts_def_define opts = { {}, entry->Value->Content };
CodeDefine define = def_define(entry->Name, MT_Expression, opts );
header_end.append(define); header_end.append(define);
continue; continue;
} }
@ -1360,39 +1244,11 @@ R"(#define <interface_name>( code ) _Generic( (code), \
Code src_static_data = scan_file( path_base "components/static_data.cpp" ); Code src_static_data = scan_file( path_base "components/static_data.cpp" );
Code src_ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" ); Code src_ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" );
Code src_code_serialization = scan_file( path_base "components/code_serialization.cpp" ); Code src_code_serialization = scan_file( path_base "components/code_serialization.cpp" );
Code src_interface = scan_file( path_base "components/interface.cpp" );
Code src_parsing_interface = scan_file( path_base "components/interface.parsing.cpp" ); Code src_parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
Code src_untyped = scan_file( path_base "components/interface.untyped.cpp" ); Code src_untyped = scan_file( path_base "components/interface.untyped.cpp" );
Code src_parser_case_macros = scan_file( path_base "components/parser_case_macros.cpp" ); Code src_parser_case_macros = scan_file( path_base "components/parser_case_macros.cpp" );
CodeBody parsed_src_interface = parse_file( path_base "components/interface.cpp" );
CodeBody src_interface = def_body(CT_Global_Body);
for ( Code entry = parsed_src_interface.begin(); entry != parsed_src_interface.end(); ++ entry ) switch( entry ->Type )
{
case CT_Function:
{
CodeFn fn = cast(CodeFn, entry);
Code prev = entry->Prev;
#if 0
for ( CodeParams arr_param : fn->Params )
{
b32 repeat_register_macros = fn->Name.is_equal(txt("register_macros")) && arr_param->Name.is_equal(txt("num")) && ! arr_param->Next->Name.is_equal(txt("..."));
if ( repeat_register_macros ) {
// rename second definition so there isn't a symbol conflict
StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", fn->Name);
fn->Name = cache_str(postfix_arr.to_str());
}
}
#endif
src_interface.append(fn);
}
break;
default:
src_interface.append(entry);
break;
}
CodeBody parsed_src_ast = parse_file( path_base "components/ast.cpp" ); CodeBody parsed_src_ast = parse_file( path_base "components/ast.cpp" );
CodeBody src_ast = def_body(CT_Global_Body); CodeBody src_ast = def_body(CT_Global_Body);
for ( Code entry = parsed_src_ast.begin(); entry != parsed_src_ast.end(); ++ entry ) switch( entry ->Type ) for ( Code entry = parsed_src_ast.begin(); entry != parsed_src_ast.end(); ++ entry ) switch( entry ->Type )
@ -1451,25 +1307,27 @@ R"(#define <interface_name>( code ) _Generic( (code), \
CodeFn fn = cast(CodeFn, entry); CodeFn fn = cast(CodeFn, entry);
Code prev = entry->Prev; Code prev = entry->Prev;
#if 0
for ( CodeParams arr_param : fn->Params ) for ( CodeParams arr_param : fn->Params )
{ if ( fn->Name.starts_with(txt("def_"))
b32 repeat_def_array = fn->Name.starts_with(txt("def_")) && arr_param->Name.is_equal(txt("num")) && ! arr_param->Next->Name.is_equal(txt("...")); && ( (arr_param->ValueType->Name.starts_with(txt("Specifier")) && fn->Params->NumEntries > 1)
if ( repeat_def_array ) { || arr_param->ValueType->Name.starts_with(txt("Code")) )
)
{
// rename second definition so there isn't a symbol conflict // rename second definition so there isn't a symbol conflict
StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", fn->Name); StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", fn->Name);
fn->Name = cache_str(postfix_arr.to_str()); fn->Name = cache_str(postfix_arr.to_str());
postfix_arr.free();
} }
}
#endif
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_"))) for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
{ {
// The frontend names are warapped in macros so we need to give it the intenral symbol name
Str prefix = txt("def_"); Str prefix = txt("def_");
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);
} }
src_upfront.append(fn); src_upfront.append(fn);
} }
break; break;
@ -1620,11 +1478,10 @@ R"(#define <interface_name>( code ) _Generic( (code), \
Code rf_interface = refactor_and_format(interface); Code rf_interface = refactor_and_format(interface);
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_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_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 "auxillary/scanner.hpp" ));
Code rf_header_scanner = refactor_and_format( scan_file( path_base "auxillary/scanner.hpp" ));
Code r_src_dep_start = refactor(src_dep_start); Code r_src_dep_start = refactor(src_dep_start);
Code r_src_debug = refactor(src_debug); Code r_src_debug = refactor(src_debug);
@ -1646,7 +1503,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
Code r_src_code_serialization = refactor(src_code_serialization); Code r_src_code_serialization = refactor(src_code_serialization);
Code r_src_parser_case_macros = refactor(src_parser_case_macros); Code r_src_parser_case_macros = refactor(src_parser_case_macros);
Code r_src_interface = refactor_and_format(src_interface); Code r_src_interface = refactor(src_interface);
Code r_src_upfront = refactor_and_format(src_upfront); Code r_src_upfront = refactor_and_format(src_upfront);
Code r_src_lexer = refactor_and_format(src_lexer); Code r_src_lexer = refactor_and_format(src_lexer);
Code rf_array_code_typename = refactor_and_format(array_code_typename); Code rf_array_code_typename = refactor_and_format(array_code_typename);
@ -1729,8 +1586,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
header.print( rf_array_pool); header.print( rf_array_pool);
header.print( fmt_newline); header.print( fmt_newline);
header.print( rf_array_string_cached ); 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(fmt_newline); header.print(fmt_newline);

View File

@ -21,7 +21,7 @@ word global, gen_global
word internal, gen_internal word internal, gen_internal
word local_persist, gen_local_persist word local_persist, gen_local_persist
word bit, gen_bit word bit, gen_bit
word bitfield_is_set, gen_bitfield_is_set word bitfield_is_equal, gen_bitfield_is_equal
word cast, gen_cast word cast, gen_cast
word ccast, gen_ccast word ccast, gen_ccast
word pcast, gen_pcast word pcast, gen_pcast
@ -310,14 +310,6 @@ word spec_to_str, gen_spec_to_str
word spec_is_trailing, gen_spec_is_trailing word spec_is_trailing, gen_spec_is_trailing
// word str_to_specifier, gen_str_to_specifier // word str_to_specifier, gen_str_to_specifier
word MacroType, gen_MacroType
word EMacroFlags, gen_EMacroFlags
word MacroFlags, gen_MacroFlags
word Macro, gen_Macro
namespace macro_, gen_macro_
namespace macrotype, gen_macrotype_
// AST // AST
word AST, gen_AST word AST, gen_AST
@ -333,7 +325,6 @@ word CodeComment, gen_CodeComment
word CodeClass, gen_CodeClass word CodeClass, gen_CodeClass
word CodeConstructor, gen_CodeConstructor word CodeConstructor, gen_CodeConstructor
word CodeDefine, gen_CodeDefine word CodeDefine, gen_CodeDefine
word CodeDefineParams, gen_CodeDefineParams
word CodeDestructor, gen_CodeDestructor word CodeDestructor, gen_CodeDestructor
word CodeEnum, gen_CodeEnum word CodeEnum, gen_CodeEnum
word CodeExec, gen_CodeExec word CodeExec, gen_CodeExec
@ -408,8 +399,6 @@ namespace var_, gen_var_
// Gen Interface // Gen Interface
word _ctx, gen__ctx
word init, gen_init word init, gen_init
word deinit, gen_deinit word deinit, gen_deinit
word reset, gen_reset word reset, gen_reset

View File

@ -22,9 +22,9 @@ CodeBody gen_array_base()
Code get_header = untyped_str( txt( "#define array_get_header( self ) ( (ArrayHeader*)( self ) - 1)\n" )); Code get_header = untyped_str( txt( "#define array_get_header( self ) ( (ArrayHeader*)( self ) - 1)\n" ));
Code type_define = untyped_str( txt( "#define Array(Type) gen_Array_##Type\n")); Code type_define = untyped_str( txt( "#define Array(Type) gen_Array_##Type\n"));
Code array_begin = def_define(txt("array_begin(array)"), MT_Expression, { {}, code( (array) ) } ); Code array_begin = def_define(txt("array_begin(array)"), code( (array) ));
Code array_end = def_define(txt("array_end(array)"), MT_Expression, { {}, code( (array + array_get_header(array)->Num ) ) } ); Code array_end = def_define(txt("array_end(array)"), code( (array + array_get_header(array)->Num ) ));
Code array_next = def_define(txt("array_next(array, entry)"), MT_Expression, { {}, code( (entry + 1) ) } ); Code array_next = def_define(txt("array_next(array, entry)"), code( (entry + 1) ));
return def_global_body( args( return def_global_body( args(
fmt_newline, fmt_newline,
@ -238,10 +238,10 @@ CodeBody gen_array( Str type, Str array_name )
GEN_ASSERT(begin <= end); GEN_ASSERT(begin <= end);
ArrayHeader* header = array_get_header( self ); ArrayHeader* header = array_get_header( self );
if ( begin < 0 || end > header->Num ) if ( begin < 0 || end >= header->Num )
return false; return false;
for ( ssize idx = (ssize)begin; idx < (ssize)end; idx ++ ) for ( ssize idx = begin; idx < end; idx ++ )
self[ idx ] = value; self[ idx ] = value;
return true; return true;

View File

@ -19,7 +19,7 @@ CodeBody gen_hashtable_base()
)); ));
Code define_type = untyped_str(txt( Code define_type = untyped_str(txt(
R"(#define HashTable(_type) struct gen_HashTable_##_type R"(#define HashTable(_type) struct _type
)" )"
)); ));

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.20-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

@ -89,14 +89,7 @@ CodeBody gen_fixed_arenas()
result.append(arena_interface_2mb); result.append(arena_interface_2mb);
result.append(arena_interface_4mb); result.append(arena_interface_4mb);
register_macros( args( CodeDefine def = def_define(txt("fixed_arena_allocator_info(fixed_arena)"), txt("( (AllocatorInfo) { arena_allocator_proc, & (fixed_arena)->arena } )"));
( Macro { txt("fixed_arena_allocator_info"), MT_Expression, MF_Functional }),
( Macro { txt("fixed_arena_init"), MT_Expression, MF_Functional }),
( Macro { txt("fixed_arena_free"), MT_Expression, MF_Functional }),
( Macro { txt("fixed_arena_size_remaining"), MT_Expression, MF_Functional })
));
CodeDefine def = parse_define(txt("#define fixed_arena_allocator_info(fixed_arena) ( (AllocatorInfo) { arena_allocator_proc, & (fixed_arena)->arena } )\n"));
result.append(def); result.append(def);
result.append(fmt_newline); result.append(fmt_newline);

View File

@ -7,13 +7,12 @@ void convert_cpp_enum_to_c( CodeEnum to_convert, CodeBody to_append )
{ {
#pragma push_macro("enum_underlying") #pragma push_macro("enum_underlying")
#undef enum_underlying #undef enum_underlying
StrCached type = to_convert->UnderlyingType ? to_convert->UnderlyingType.to_strbuilder().to_str() : to_convert->Name;
CodeTypedef tdef = parse_typedef(token_fmt("type", type, "name", to_convert->Name, stringize( typedef enum <type> <name>; )));
if (to_convert->UnderlyingType) if (to_convert->UnderlyingType)
{ {
to_convert->UnderlyingTypeMacro = untyped_str(token_fmt("type", to_convert->UnderlyingType->Name, stringize(enum_underlying(<type>)))); to_convert->UnderlyingTypeMacro = untyped_str(token_fmt("type", to_convert->UnderlyingType->Name, stringize(enum_underlying(<type>))));
to_convert->UnderlyingType = CodeTypename{nullptr}; to_convert->UnderlyingType = CodeTypename{nullptr};
} }
CodeTypedef tdef = parse_typedef(token_fmt("name", to_convert->Name, stringize( typedef enum <name> <name>; )));
to_append.append(to_convert); to_append.append(to_convert);
to_append.append(tdef); to_append.append(tdef);
#pragma pop_macro("enum_underlying") #pragma pop_macro("enum_underlying")

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.20-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

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

@ -27,7 +27,7 @@ case Spec_Static: \
case Spec_Volatile: \ case Spec_Volatile: \
case Spec_Virtual case Spec_Virtual
#define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_TOK_SPECIFIER_CASES \ #define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_TOK_SPECIFIERS_CASES \
case Tok_Spec_Consteval: \ case Tok_Spec_Consteval: \
case Tok_Spec_Constexpr: \ case Tok_Spec_Constexpr: \
case Tok_Spec_Constinit: \ case Tok_Spec_Constinit: \
@ -40,7 +40,7 @@ case Tok_Spec_Internal_Linkage: \
case Tok_Spec_NeverInline: \ case Tok_Spec_NeverInline: \
case Tok_Spec_Static case Tok_Spec_Static
#define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_SPECIFIER_CASES \ #define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_SPECIFIERS_CASES \
case Spec_Constexpr: \ case Spec_Constexpr: \
case Spec_Constinit: \ case Spec_Constinit: \
case Spec_ForceInline: \ case Spec_ForceInline: \

View File

@ -4,4 +4,4 @@ COREUOBJECT_API, COREUOBJECT_API
ENGINE_API, ENGINE_API ENGINE_API, ENGINE_API
GAMEPLAYABILITIES_API, GAMEPLAYABILITIES_API GAMEPLAYABILITIES_API, GAMEPLAYABILITIES_API
UMG_API, UMG_API UMG_API, UMG_API
GASA_API, GASA_API UE_DEPRECATED, UE_DEPRECATED

1 API_Export GEN_API_Export_Code
4 ENGINE_API ENGINE_API
5 GAMEPLAYABILITIES_API GAMEPLAYABILITIES_API
6 UMG_API UMG_API
7 GASA_API UE_DEPRECATED GASA_API UE_DEPRECATED

View File

@ -42,7 +42,6 @@ Number, "__number__"
Operator, "__operator__" Operator, "__operator__"
Preprocess_Hash, "#" Preprocess_Hash, "#"
Preprocess_Define, "define" Preprocess_Define, "define"
Preprocess_Define_Param, "__define_param__"
Preprocess_If, "if" Preprocess_If, "if"
Preprocess_IfDef, "ifdef" Preprocess_IfDef, "ifdef"
Preprocess_IfNotDef, "ifndef" Preprocess_IfNotDef, "ifndef"
@ -52,9 +51,7 @@ Preprocess_EndIf, "endif"
Preprocess_Include, "include" Preprocess_Include, "include"
Preprocess_Pragma, "pragma" Preprocess_Pragma, "pragma"
Preprocess_Content, "__macro_content__" Preprocess_Content, "__macro_content__"
Preprocess_Macro_Expr, "__macro_expression__" Preprocess_Macro, "__macro__"
Preprocess_Macro_Stmt, "__macro_statment__"
Preprocess_Macro_Typename, "__macro_typename__"
Preprocess_Unsupported, "__unsupported__" Preprocess_Unsupported, "__unsupported__"
Spec_Alignas, "alignas" Spec_Alignas, "alignas"
Spec_Const, "const" Spec_Const, "const"

1 Invalid __invalid__
42 Operator __operator__
43 Preprocess_Hash #
44 Preprocess_Define define
Preprocess_Define_Param __define_param__
45 Preprocess_If if
46 Preprocess_IfDef ifdef
47 Preprocess_IfNotDef ifndef
51 Preprocess_Include include
52 Preprocess_Pragma pragma
53 Preprocess_Content __macro_content__
54 Preprocess_Macro_Expr Preprocess_Macro __macro_expression__ __macro__
Preprocess_Macro_Stmt __macro_statment__
Preprocess_Macro_Typename __macro_typename__
55 Preprocess_Unsupported __unsupported__
56 Spec_Alignas alignas
57 Spec_Const const

View File

@ -64,46 +64,6 @@ int gen_main()
Code ue_forceinline = code_str(FORCEINLINE); Code ue_forceinline = code_str(FORCEINLINE);
// Code // Code
register_macros( args(
(Macro { txt("bit"), MT_Expression, MF_Functional }),
(Macro { txt("bitfield_is_set"), MT_Expression, MF_Functional }),
(Macro { txt("GEN_C_LIKE_CPP"), MT_Expression, MF_Null }),
(Macro { txt("cast"), MT_Expression, MF_Functional }),
(Macro { txt("ccast"), MT_Expression, MF_Functional }),
(Macro { txt("rcast"), MT_Expression, MF_Functional }),
(Macro { txt("pcast"), MT_Expression, MF_Functional }),
(Macro { txt("scast"), MT_Expression, MF_Functional }),
(Macro { txt("stringize_va"), MT_Expression, MF_Functional }),
(Macro { txt("stringize"), MT_Expression, MF_Functional }),
(Macro { txt("do_once"), MT_Expression, MF_Functional }),
(Macro { txt("do_once_defer"), MT_Expression, MF_Functional }),
(Macro { txt("do_once_start"), MT_Statement, MF_Null }),
(Macro { txt("do_once_end"), MT_Statement, MF_Null }),
(Macro { txt("labeled_scope_start"), MT_Statement, MF_Null }),
(Macro { txt("labeled_scope_end"), MT_Statement, MF_Null }),
(Macro { txt("compiler_decorated_func_name"), MT_Expression, MF_Null }),
(Macro { txt("num_args_impl"), MT_Expression, MF_Functional }),
(Macro { txt("num_args"), MT_Expression, MF_Functional }),
(Macro { txt("count_of"), MT_Expression, MF_Functional }),
(Macro { txt("clamp"), MT_Expression, MF_Functional }),
(Macro { txt("is_between"), MT_Expression, MF_Functional }),
(Macro { txt("size_of"), MT_Expression, MF_Functional }),
(Macro { txt("min"), MT_Expression, MF_Functional }),
(Macro { txt("max"), MT_Expression, MF_Functional }),
(Macro { txt("offset_of"), MT_Expression, MF_Functional }),
(Macro { txt("static_assert"), MT_Statement, MF_Functional }),
(Macro { txt("typeof"), MT_Expression, MF_Null }),
(Macro { txt("GEN_API_C_BEGIN"), MT_Statement, MF_Null }),
(Macro { txt("GEN_API_C_END"), MT_Statement, MF_Null }),
(Macro { txt("nullptr"), MT_Expression, MF_Null }),
(Macro { txt("GEN_REMOVE_PTR"), MT_Expression, MF_Functional }),
(Macro { txt("GEN_PARAM_DEFAULT"), MT_Expression, MF_Null }),
(Macro { txt("struct_init"), MT_Expression, MF_Functional }),
(Macro { txt("GEN_OPTIMIZE_MAPPINGS_BEGIN"), MT_Statement, MF_Null }),
(Macro { txt("GEN_OPITMIZE_MAPPINGS_END"), MT_Statement, MF_Null }),
(Macro { txt("src_line_str"), MT_Expression, MF_Null })
));
// gen_dep.hpp // gen_dep.hpp
{ {
CodeBody macros = def_body( CT_Global_Body ); CodeBody macros = def_body( CT_Global_Body );
@ -148,7 +108,6 @@ int gen_main()
Code strings = scan_file( path_base "dependencies/strings.hpp" ); Code strings = scan_file( path_base "dependencies/strings.hpp" );
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" ); Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
Code timing = scan_file( path_base "dependencies/timing.hpp" ); Code timing = scan_file( path_base "dependencies/timing.hpp" );
Code parsing = scan_file( path_base "dependencies/parsing.hpp" );
Builder Builder
header = Builder::open("gen/gen.dep.hpp"); header = Builder::open("gen/gen.dep.hpp");
@ -170,7 +129,6 @@ int gen_main()
header.print( strings ); header.print( strings );
header.print( filesystem ); header.print( filesystem );
header.print( timing ); header.print( timing );
header.print(parsing);
header.print_fmt( "\nGEN_NS_END\n" ); header.print_fmt( "\nGEN_NS_END\n" );
header.print( fmt_newline ); header.print( fmt_newline );
@ -189,7 +147,6 @@ int gen_main()
Code strings = scan_file( path_base "dependencies/strings.cpp" ); Code strings = scan_file( path_base "dependencies/strings.cpp" );
Code filesystem = scan_file( path_base "dependencies/filesystem.cpp" ); Code filesystem = scan_file( path_base "dependencies/filesystem.cpp" );
Code timing = scan_file( path_base "dependencies/timing.cpp" ); Code timing = scan_file( path_base "dependencies/timing.cpp" );
Code parsing = scan_file( path_base "dependencies/parsing.cpp" );
Builder Builder
src = Builder::open( "gen/gen.dep.cpp" ); src = Builder::open( "gen/gen.dep.cpp" );
@ -208,7 +165,6 @@ int gen_main()
src.print( strings ); src.print( strings );
src.print( filesystem ); src.print( filesystem );
src.print( timing ); src.print( timing );
src.print( parsing );
src.print_fmt( "\nGEN_NS_END\n" ); src.print_fmt( "\nGEN_NS_END\n" );
src.print( fmt_newline ); src.print( fmt_newline );
@ -315,20 +271,14 @@ int gen_main()
src.print_fmt( "\n#pragma region Interface\n" ); src.print_fmt( "\n#pragma region Interface\n" );
src.print( interface ); src.print( interface );
src.print( upfront ); src.print( upfront );
src.print_fmt( "\n#pragma region Parsing\n\n" ); src.print_fmt( "\n#pragma region Parsing\n\n" );
src.print( lexer ); src.print( lexer );
src.print( parser_case_macros ); src.print( parser_case_macros );
src.print( parser ); src.print( parser );
src.print( parsing_interface ); src.print( parsing_interface );
src.print_fmt( "\n#pragma endregion Parsing\n\n" );
src.print_fmt( "\n#pragma region Untyped\n\n" );
src.print( untyped ); src.print( untyped );
src.print_fmt( "#pragma endregion \n\n" ); src.print_fmt( "\n#pragma endregion Parsing\n\n" );
src.print_fmt( "#pragma endregion Interface\n\n" ); src.print_fmt( "#pragma endregion Interface\n\n" );
src.print_fmt( "GEN_NS_END\n\n"); src.print_fmt( "GEN_NS_END\n\n");
@ -375,6 +325,7 @@ int gen_main()
// gen_scanner.hpp // gen_scanner.hpp
{ {
Code parsing = scan_file( path_base "dependencies/parsing.hpp" );
Code scanner = scan_file( path_base "auxillary/scanner.hpp" ); Code scanner = scan_file( path_base "auxillary/scanner.hpp" );
Builder Builder
@ -385,6 +336,7 @@ int gen_main()
header.print( fmt_newline ); header.print( fmt_newline );
header.print( def_include( txt("gen.hpp") ) ); header.print( def_include( txt("gen.hpp") ) );
header.print_fmt( "\nGEN_NS_BEGIN\n" ); header.print_fmt( "\nGEN_NS_BEGIN\n" );
header.print( parsing );
header.print( scanner ); header.print( scanner );
header.print_fmt( "\nGEN_NS_END\n" ); header.print_fmt( "\nGEN_NS_END\n" );
header.print( fmt_newline ); header.print( fmt_newline );
@ -394,6 +346,7 @@ int gen_main()
// gen.scanner.cpp // gen.scanner.cpp
{ {
Code parsing = scan_file( path_base "dependencies/parsing.cpp" );
Code scanner = scan_file( path_base "auxillary/scanner.cpp" ); Code scanner = scan_file( path_base "auxillary/scanner.cpp" );
Builder Builder
@ -403,7 +356,8 @@ int gen_main()
src.print( fmt_newline ); src.print( fmt_newline );
src.print( def_include( txt("gen.scanner.hpp") ) ); src.print( def_include( txt("gen.scanner.hpp") ) );
src.print_fmt( "\nGEN_NS_BEGIN\n" ); src.print_fmt( "\nGEN_NS_BEGIN\n" );
src.print( scanner ); src.print( parsing );
// src.print( scanner );
src.print_fmt( "\nGEN_NS_END\n" ); src.print_fmt( "\nGEN_NS_END\n" );
src.print( fmt_newline ); src.print( fmt_newline );
src.print( pop_ignores ); src.print( pop_ignores );

View File

@ -325,23 +325,18 @@ if ( $unreal )
. $refactor_unreal . $refactor_unreal
} }
# C Library testing if ( $test )
if ( $test -and $false )
{ {
$path_test_c = join-path $path_test c_library $path_test_c_lib = join-path $path_test c_library
$path_build = join-path $path_test_c build $path_build = join-path $path_test_c_lib build
$path_gen = join-path $path_test_c gen
if ( -not(Test-Path($path_build) )) { if ( -not(Test-Path($path_build) )) {
New-Item -ItemType Directory -Path $path_build New-Item -ItemType Directory -Path $path_build
} }
if ( -not(Test-Path($path_gen) )) {
New-Item -ItemType Directory -Path $path_gen
}
$path_singleheader_include = join-path $path_c_library gen $includes = @( $path_c_library )
$includes = @( $path_singleheader_include ) $unit = join-path $path_test_c_lib "gen.c"
$unit = join-path $path_test_c "test.c" $executable = join-path $path_build "gen_c_library_test.exe"
$executable = join-path $path_build "test.exe"
$compiler_args = @() $compiler_args = @()
$compiler_args += ( $flag_define + 'GEN_TIME' ) $compiler_args += ( $flag_define + 'GEN_TIME' )
@ -355,7 +350,7 @@ if ( $test -and $false )
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable $result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
Push-Location $path_test_c Push-Location $path_test_c_lib
if ( Test-Path( $executable ) ) { if ( Test-Path( $executable ) ) {
write-host "`nRunning c_library test" write-host "`nRunning c_library test"
$time_taken = Measure-Command { & $executable $time_taken = Measure-Command { & $executable
@ -367,45 +362,6 @@ if ( $test -and $false )
} }
Pop-Location Pop-Location
} }
if ($test -and $true)
{
$path_test_cpp = join-path $path_test cpp_library
$path_build = join-path $path_test_cpp build
$path_gen = join-path $path_test_cpp gen
if ( -not(Test-Path($path_build) )) {
New-Item -ItemType Directory -Path $path_build
}
if ( -not(Test-Path($path_gen) )) {
New-Item -ItemType Directory -Path $path_gen
}
$path_singleheader_include = join-path $path_singleheader gen
$includes = @( $path_singleheader_include )
$unit = join-path $path_test_cpp "test.cpp"
$executable = join-path $path_build "test.exe"
$compiler_args = @()
$compiler_args += ( $flag_define + 'GEN_TIME' )
$linker_args = @(
$flag_link_win_subsystem_console
)
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
Push-Location $path_test_cpp
if ( Test-Path( $executable ) ) {
write-host "`nRunning cpp_library test"
$time_taken = Measure-Command { & $executable
| ForEach-Object {
write-host `t $_ -ForegroundColor Green
}
}
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
}
Pop-Location
}
#endregion Building #endregion Building
Pop-Location # $path_root Pop-Location # $path_root

9
test/c_library/gen.c Normal file
View File

@ -0,0 +1,9 @@
#define GEN_IMPLEMENTATION
#include "gen/gen_singleheader.h"
int gen_main()
{
// init();
__debugbreak();
return 0;
}

View File

@ -1,33 +0,0 @@
#define GEN_IMPLEMENTATION
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES
#include "gen_singleheader.h"
#define gen_iterator( Type, container, iter ) \
gen_begin_ ## Type(container); \
iter != gen_end_ ## Type(container); \
code = gen_next_ ## Type(container, iter)
int main()
{
gen_Context ctx = {0};
gen_init(& ctx);
gen_Builder src_hello = gen_builder_open("gen/hello.c");
gen_CodeVar hello_var = gen_parse_variable(code(
char const* hello_gencpp_str = "HELLO GENCPP C11 !";
));
gen_builder_print( & src_hello, (gen_Code)hello_var );
gen_builder_write(& src_hello);
gen_CodeBody body = gen_parse_file("gen/hello.c");
for (gen_Code code = gen_iterator(CodeBody, body, code)) switch (code->Type) {
case CT_Variable:
gen_CodeVar var = (gen_CodeVar) code;
gen_log_fmt("%S", var->Value);
break;
}
gen_deinit(& ctx);
return 0;
}

View File

@ -1,29 +0,0 @@
#define GEN_IMPLEMENTATION
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES
#include "gen.hpp"
int main()
{
using namespace gen;
Context ctx = {};
gen::init( & ctx);
Builder src_hello = builder_open("gen/hello.cpp");
CodeVar hello_var = parse_variable( code(
constexpr char const* hello_gencpp_str = "HELLO GENCPP !";
));
src_hello.print(hello_var);
src_hello.write();
CodeBody body = parse_file("gen/hello.cpp");
for ( Code code : body ) switch (code->Type) {
case CT_Variable:
CodeVar var = cast(CodeVar, code);
log_fmt("%S", var->Value);
break;
}
gen::deinit(& ctx);
return 0;
}