2023-11-20 12:09:01 -08:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
2023-11-19 17:34:46 -08:00
|
|
|
#pragma once
|
|
|
|
#include "ast.cpp"
|
|
|
|
#endif
|
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
inline
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder attributes_to_strbuilder(CodeAttributes attributes) {
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(attributes);
|
2024-12-12 09:55:15 -08:00
|
|
|
char* raw = ccast(char*, str_duplicate( attributes->Content, GlobalAllocator ).Ptr);
|
|
|
|
StrBuilder result = { raw };
|
2024-12-08 22:33:37 -08:00
|
|
|
return result;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
inline
|
2024-12-12 09:55:15 -08:00
|
|
|
void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result) {
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(attributes);
|
|
|
|
GEN_ASSERT(result);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str(result, attributes->Content);
|
2024-12-06 21:21:09 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder body_to_strbuilder(CodeBody body)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(body);
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 128 );
|
2024-12-06 21:21:09 -08:00
|
|
|
switch ( body->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Untyped:
|
|
|
|
case CT_Execution:
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( & result, cast(Code, body)->Content );
|
2023-11-20 12:09:01 -08:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Body:
|
|
|
|
case CT_Class_Body:
|
|
|
|
case CT_Extern_Linkage_Body:
|
|
|
|
case CT_Function_Body:
|
|
|
|
case CT_Global_Body:
|
|
|
|
case CT_Namespace_Body:
|
|
|
|
case CT_Struct_Body:
|
|
|
|
case CT_Union_Body:
|
2024-12-12 09:55:15 -08:00
|
|
|
body_to_strbuilder_ref( body, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Export_Body:
|
2024-12-12 09:55:15 -08:00
|
|
|
body_to_strbuilder_export( body, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void body_to_strbuilder_ref( CodeBody body, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(body != nullptr);
|
|
|
|
GEN_ASSERT(result != nullptr);
|
|
|
|
Code curr = body->Front;
|
|
|
|
s32 left = body->NumEntries;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( left -- )
|
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
code_to_strbuilder_ptr(curr, result);
|
2024-12-13 11:38:27 -08:00
|
|
|
// strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
++curr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void body_to_strbuilder_export( CodeBody body, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(body != nullptr);
|
|
|
|
GEN_ASSERT(result != nullptr);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "export\n{\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
Code curr = cast(Code, body);
|
|
|
|
s32 left = body->NumEntries;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( left-- )
|
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
code_to_strbuilder_ptr(curr, result);
|
2024-12-13 11:38:27 -08:00
|
|
|
// strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
++curr;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "};\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
inline
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder comment_to_strbuilder(CodeComment comment) {
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(comment);
|
2024-12-12 09:55:15 -08:00
|
|
|
char* raw = ccast(char*, str_duplicate( comment->Content, GlobalAllocator ).Ptr);
|
|
|
|
StrBuilder result = { raw };
|
2024-12-08 22:33:37 -08:00
|
|
|
return result;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
inline
|
2024-12-12 09:55:15 -08:00
|
|
|
void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result) {
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(comment);
|
|
|
|
GEN_ASSERT(result);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str(result, comment->Content);
|
2024-12-06 21:21:09 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder constructor_to_strbuilder(CodeConstructor self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 128 );
|
2024-12-02 13:59:13 -08:00
|
|
|
switch (self->Type)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Constructor:
|
2024-12-12 09:55:15 -08:00
|
|
|
constructor_to_strbuilder_def( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Constructor_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
constructor_to_strbuilder_fwd( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void constructor_to_strbuilder_def(CodeConstructor self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 17:20:30 -08:00
|
|
|
Code ClassStructParent = self->Parent->Parent;
|
2024-04-17 14:40:32 -07:00
|
|
|
if (ClassStructParent) {
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, ClassStructParent->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
|
|
|
else {
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, self->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Params )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "( %SB )", params_to_strbuilder(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("()") );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InitializerList )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " : %SB", code_to_strbuilder(self->InitializerList) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " // %S", self->InlineCmt->Content );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "\n{\n%SB\n}\n", code_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void constructor_to_strbuilder_fwd(CodeConstructor self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 17:20:30 -08:00
|
|
|
Code ClassStructParent = self->Parent->Parent;
|
2024-04-17 14:40:32 -07:00
|
|
|
if (ClassStructParent) {
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, ClassStructParent->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
|
|
|
else {
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, self->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Params )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "( %SB )", params_to_strbuilder(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "()");
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if (self->Body)
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " = %SB", code_to_strbuilder(self->Body) );
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; // %S\n", self->InlineCmt->Content );
|
2024-04-17 14:40:32 -07:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder class_to_strbuilder( CodeClass self )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 512 );
|
2024-12-02 01:12:09 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class:
|
2024-12-12 09:55:15 -08:00
|
|
|
class_to_strbuilder_def(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
class_to_strbuilder_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
2024-12-02 01:12:09 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("class ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Attributes )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->ParentType )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str access_level = access_spec_to_str( self->ParentAccess );
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%S : %S %SB", self->Name, access_level, typename_to_strbuilder(self->ParentType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeTypename interface = cast(CodeTypename, self->ParentType->Next);
|
2023-11-19 17:34:46 -08:00
|
|
|
if ( interface )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
while ( interface )
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, ", public %SB", typename_to_strbuilder(interface) );
|
2024-12-08 22:33:37 -08:00
|
|
|
interface = interface->Next ? cast(CodeTypename, interface->Next) : NullCode;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
2024-12-08 22:33:37 -08:00
|
|
|
else if ( self->Name.Len )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->InlineCmt )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " // %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "\n{\n%SB\n}", body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
2024-12-02 01:12:09 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "class %SB %S", attributes_to_strbuilder(self->Attributes), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
else strbuilder_append_fmt( result, "class %S", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
// Check if it can have an end-statement
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; // %S\n", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder define_to_strbuilder(CodeDefine define)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
return strbuilder_fmt_buf( GlobalAllocator, "#define %S %S", define->Name, define->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void define_to_strbuilder_ref(CodeDefine define, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "#define %S %S", define->Name, define->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder destructor_to_strbuilder(CodeDestructor self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 128 );
|
2024-12-02 13:59:13 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Destructor:
|
2024-12-12 09:55:15 -08:00
|
|
|
destructor_to_strbuilder_def( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Destructor_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
destructor_to_strbuilder_fwd( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void destructor_to_strbuilder_def(CodeDestructor self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-08 22:33:37 -08:00
|
|
|
if ( self->Name.Len )
|
2024-04-17 14:40:32 -07:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S()", self->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
2024-12-02 13:59:13 -08:00
|
|
|
else if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( specifiers_has(self->Specs, Spec_Virtual ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "virtual ~%S()", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "~%S()", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "~%S()", self->Parent->Name );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "\n{\n%SB\n}\n", code_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void destructor_to_strbuilder_fwd(CodeDestructor self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( specifiers_has(self->Specs, Spec_Virtual ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "virtual ~%S();\n", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "~%S()", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( specifiers_has(self->Specs, Spec_Pure ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(" = 0;") );
|
2024-12-02 13:59:13 -08:00
|
|
|
else if (self->Body)
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " = %SB;", code_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "~%S();", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder enum_to_strbuilder(CodeEnum self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 512 );
|
2024-12-02 13:59:13 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum:
|
2024-12-12 09:55:15 -08:00
|
|
|
enum_to_strbuilder_def(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
enum_to_strbuilder_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Class:
|
2024-12-12 09:55:15 -08:00
|
|
|
enum_to_strbuilder_class_def(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Class_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
enum_to_strbuilder_class_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void enum_to_strbuilder_def(CodeEnum self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
if ( self->Attributes || self->UnderlyingType || self->UnderlyingTypeMacro )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("enum ") );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->UnderlyingType )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S : %SB\n{\n%SB\n}"
|
2024-12-02 13:59:13 -08:00
|
|
|
, self->Name
|
2024-12-13 11:38:27 -08:00
|
|
|
, typename_to_strbuilder(self->UnderlyingType)
|
|
|
|
, body_to_strbuilder(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
2024-12-02 13:59:13 -08:00
|
|
|
else if ( self->UnderlyingTypeMacro )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S %SB\n{\n%SB\n}"
|
2024-12-02 13:59:13 -08:00
|
|
|
, self->Name
|
2024-12-13 11:38:27 -08:00
|
|
|
, code_to_strbuilder(self->UnderlyingTypeMacro)
|
|
|
|
, body_to_strbuilder(self->Body)
|
2024-12-01 02:30:37 -08:00
|
|
|
);
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
else strbuilder_append_fmt( result, "%S\n{\n%SB\n}", self->Name, body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
2024-12-13 11:38:27 -08:00
|
|
|
else strbuilder_append_fmt( result, "enum %S\n{\n%SB\n}", self->Name, body_to_strbuilder(self->Body) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void enum_to_strbuilder_fwd(CodeEnum self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->UnderlyingType )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "enum %S : %SB", self->Name, typename_to_strbuilder(self->UnderlyingType) );
|
2024-12-05 21:33:53 -08:00
|
|
|
else if (self->UnderlyingTypeMacro)
|
2024-12-07 14:17:02 -08:00
|
|
|
{
|
|
|
|
log_fmt("IDENTIFIED A UNDERLYING ENUM MACRO");
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "enum %S %SB", self->Name, code_to_strbuilder(self->UnderlyingTypeMacro) );
|
2024-12-07 14:17:02 -08:00
|
|
|
}
|
2024-12-01 15:50:37 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "enum %S", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes || self->UnderlyingType )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("enum class ") );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->UnderlyingType )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%S : %SB\n{\n%SB\n}", self->Name, typename_to_strbuilder(self->UnderlyingType), body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%S\n{\n%SB\n}", self->Name, body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "enum %S\n{\n%SB\n}", self->Name, body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("enum class ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%S : %SB", self->Name, typename_to_strbuilder(self->UnderlyingType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder exec_to_strbuilder(CodeExec exec)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-08 22:33:37 -08:00
|
|
|
GEN_ASSERT(exec);
|
2024-12-12 09:55:15 -08:00
|
|
|
char* raw = ccast(char*, str_duplicate( exec->Content, GlobalAllocator ).Ptr);
|
|
|
|
StrBuilder result = { raw };
|
2024-12-08 22:33:37 -08:00
|
|
|
return result;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
void extern_to_strbuilder(CodeExtern self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Body )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "extern \"%S\"\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "extern \"%S\"\n{}\n", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder include_to_strbuilder(CodeInclude include)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
return strbuilder_fmt_buf( GlobalAllocator, "#include %S\n", include->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void include_to_strbuilder_ref( CodeInclude include, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "#include %S\n", include->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder friend_to_strbuilder(CodeFriend self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 256 );
|
|
|
|
friend_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "friend %SB", code_to_strbuilder(self->Declaration) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
if ( self->Declaration->Type != CT_Function && self->Declaration->Type != CT_Operator && (* result)[ strbuilder_length(* result) - 1 ] != ';' )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder fn_to_strbuilder(CodeFn self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 512 );
|
2024-12-02 13:59:13 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function:
|
2024-12-12 09:55:15 -08:00
|
|
|
fn_to_strbuilder_def(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
fn_to_strbuilder_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void fn_to_strbuilder_def(CodeFn self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " %SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
bool prefix_specs = false;
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( ! spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2024-05-05 18:53:22 -07:00
|
|
|
|
|
|
|
prefix_specs = true;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes || prefix_specs )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->ReturnType )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S(", typename_to_strbuilder(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S(", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Params )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB)", params_to_strbuilder(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(")") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "\n{\n%SB\n}\n", body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-05-05 18:53:22 -07:00
|
|
|
b32 prefix_specs = false;
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( ! spec_is_trailing( * spec ) || ! ( * spec != Spec_Pure) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2024-05-05 18:53:22 -07:00
|
|
|
|
|
|
|
prefix_specs = true;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes || prefix_specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->ReturnType )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S(", typename_to_strbuilder(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S(", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Params )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB)", params_to_strbuilder(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(")") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Specs && specifiers_has(self->Specs, Spec_Pure ) >= 0 )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(" = 0;") );
|
2024-12-02 13:59:13 -08:00
|
|
|
else if (self->Body)
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " = %SB;", body_to_strbuilder(self->Body) );
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder module_to_strbuilder(CodeModule self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 64 );
|
|
|
|
module_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void module_to_strbuilder_ref(CodeModule self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-08 22:33:37 -08:00
|
|
|
if (((scast(u32, ModuleFlag_Export) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Export)))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export "));
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
if (((scast(u32, ModuleFlag_Import) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Import)))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("import "));
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S;\n", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder namespace_to_strbuilder(CodeNS self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 512 );
|
|
|
|
namespace_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "namespace %S\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder code_op_to_strbuilder(CodeOperator self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 512 );
|
2024-12-02 15:35:34 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator:
|
|
|
|
case CT_Operator_Member:
|
2024-12-12 09:55:15 -08:00
|
|
|
code_op_to_strbuilder_def( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Fwd:
|
|
|
|
case CT_Operator_Member_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
code_op_to_strbuilder_fwd( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( ! spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes || self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->ReturnType )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S (", typename_to_strbuilder(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Params )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB)", params_to_strbuilder(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(")") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "\n{\n%SB\n}\n"
|
2024-12-13 11:38:27 -08:00
|
|
|
, body_to_strbuilder(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB\n", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( ! spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes || self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S (", typename_to_strbuilder(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Params )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB)", params_to_strbuilder(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, ")" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder opcast_to_strbuilder(CodeOpCast self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 128 );
|
2024-12-02 15:35:34 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Cast:
|
2024-12-12 09:55:15 -08:00
|
|
|
opcast_to_strbuilder_def(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Cast_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
opcast_to_strbuilder_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void opcast_to_strbuilder_def(CodeOpCast self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2024-10-25 01:08:20 -07:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( ! spec_is_trailing( * spec ) )
|
2024-10-25 01:08:20 -07:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, "%*s ", spec_str.Len, spec_str.Ptr );
|
2024-10-25 01:08:20 -07:00
|
|
|
}
|
|
|
|
}
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
if ( self->Name.Ptr && self->Name.Len )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%S operator %SB()", self->Name, typename_to_strbuilder(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "operator %SB()", typename_to_strbuilder(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "\n{\n%SB\n}\n", body_to_strbuilder(self->Body) );
|
2023-11-20 12:09:01 -08:00
|
|
|
return;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
if ( self->Name.Ptr && self->Name.Len )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%S operator %SB()\n{\n%SB\n}\n", self->Name, typename_to_strbuilder(self->ValueType), body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "operator %SB()\n{\n%SB\n}\n", typename_to_strbuilder(self->ValueType), body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void opcast_to_strbuilder_fwd(CodeOpCast self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2024-10-25 01:08:20 -07:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( ! spec_is_trailing( * spec ) )
|
2024-10-25 01:08:20 -07:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, "%*s ", spec_str.Len, spec_str.Ptr );
|
2024-10-25 01:08:20 -07:00
|
|
|
}
|
|
|
|
}
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "operator %SB()", typename_to_strbuilder(self->ValueType) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( spec_is_trailing( * spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec_str = spec_to_str( * spec );
|
|
|
|
strbuilder_append_fmt( result, " %*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n") );
|
2023-11-20 12:09:01 -08:00
|
|
|
return;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "operator %SB(); %SB", typename_to_strbuilder(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "operator %SB();\n", typename_to_strbuilder(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder params_to_strbuilder(CodeParams self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(self);
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 128 );
|
|
|
|
params_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void params_to_strbuilder_ref( CodeParams self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
|
|
|
if ( self->Macro )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-04-17 14:40:32 -07:00
|
|
|
// Related to parsing: ( <macro>, ... )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, self->Macro->Content );
|
2024-04-17 14:40:32 -07:00
|
|
|
// Could also be: ( <macro> <type <name>, ... )
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
if ( self->Name.Ptr && self->Name.Len )
|
2024-04-17 14:40:32 -07:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->ValueType == nullptr )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " %S", self->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " %SB %S", typename_to_strbuilder(self->ValueType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
2024-12-06 21:21:09 -08:00
|
|
|
else if ( self->ValueType )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " %SB", typename_to_strbuilder(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->PostNameMacro )
|
2024-10-24 22:04:17 -07:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " %SB", code_to_strbuilder(self->PostNameMacro) );
|
2024-10-24 22:04:17 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Value )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " = %SB", code_to_strbuilder(self->Value) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->NumEntries - 1 > 0 )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-11 10:33:35 -08:00
|
|
|
for ( CodeParams param = begin_CodeParams(self->Next); param != end_CodeParams(self->Next); param = next_CodeParams(self->Next, param) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, ", %SB", params_to_strbuilder(param) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder preprocess_to_strbuilder(CodePreprocessCond self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 256 );
|
2024-12-02 15:35:34 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_If:
|
2024-12-12 09:55:15 -08:00
|
|
|
preprocess_to_strbuilder_if( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_IfDef:
|
2024-12-12 09:55:15 -08:00
|
|
|
preprocess_to_strbuilder_ifdef( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_IfNotDef:
|
2024-12-12 09:55:15 -08:00
|
|
|
preprocess_to_strbuilder_ifndef( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_ElIf:
|
2024-12-12 09:55:15 -08:00
|
|
|
preprocess_to_strbuilder_elif( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_Else:
|
2024-12-12 09:55:15 -08:00
|
|
|
preprocess_to_strbuilder_else( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_EndIf:
|
2024-12-12 09:55:15 -08:00
|
|
|
preprocess_to_strbuilder_endif( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void preprocess_to_strbuilder_if(CodePreprocessCond cond, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(cond);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "#if %S", cond->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void preprocess_to_strbuilder_ifdef(CodePreprocessCond cond, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(cond);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "#ifdef %S\n", cond->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(cond);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "#ifndef %S", cond->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void preprocess_to_strbuilder_elif(CodePreprocessCond cond, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(cond);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "#elif %S\n", cond->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void preprocess_to_strbuilder_else(CodePreprocessCond cond, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(cond);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("#else\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void preprocess_to_strbuilder_endif(CodePreprocessCond cond, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(cond);
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("#endif\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder pragma_to_strbuilder(CodePragma self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 256 );
|
|
|
|
pragma_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "#pragma %S\n", self->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder specifiers_to_strbuilder(CodeSpecifiers self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 64 );
|
|
|
|
specifiers_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void specifiers_to_strbuilder_ref( CodeSpecifiers self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
2023-11-19 17:34:46 -08:00
|
|
|
s32 idx = 0;
|
2024-12-02 07:58:24 -08:00
|
|
|
s32 left = self->NumEntries;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( left-- )
|
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str spec = spec_to_str( self->ArrSpecs[idx] );
|
|
|
|
strbuilder_append_fmt( result, "%.*s ", spec.Len, spec.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder struct_to_strbuilder(CodeStruct self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(self);
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 512 );
|
2024-12-02 08:20:31 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Struct:
|
2024-12-12 09:55:15 -08:00
|
|
|
struct_to_strbuilder_def( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Struct_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
struct_to_strbuilder_fwd( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void struct_to_strbuilder_def( CodeStruct self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("struct ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Attributes )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->ParentType )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
Str access_level = access_spec_to_str( self->ParentAccess );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%S : %S %SB", self->Name, access_level, typename_to_strbuilder(self->ParentType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeTypename interface = cast(CodeTypename, self->ParentType->Next);
|
2023-11-19 17:34:46 -08:00
|
|
|
if ( interface )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
while ( interface )
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, ", %SB", typename_to_strbuilder(interface) );
|
2024-12-08 22:33:37 -08:00
|
|
|
interface = interface->Next ? cast( CodeTypename, interface->Next) : NullCode;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
2024-12-08 22:33:37 -08:00
|
|
|
else if ( self->Name.Len )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->InlineCmt )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " // %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "\n{\n%SB\n}", body_to_strbuilder(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void struct_to_strbuilder_fwd( CodeStruct self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "struct %SB %S", attributes_to_strbuilder(self->Attributes), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
else strbuilder_append_fmt( result, "struct %S", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt( ";\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder template_to_strbuilder(CodeTemplate self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 1024 );
|
|
|
|
template_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Params )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "template< %SB >\n%SB", params_to_strbuilder(self->Params), code_to_strbuilder(self->Declaration) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "template<>\n%SB", code_to_strbuilder(self->Declaration) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder typedef_to_strbuilder(CodeTypedef self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 128 );
|
|
|
|
typedef_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("typedef "));
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
// Determines if the typedef is a function typename
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->UnderlyingType->ReturnType )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_string( result, code_to_strbuilder(self->UnderlyingType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S", code_to_strbuilder(self->UnderlyingType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->UnderlyingType->Type == CT_Typename && self->UnderlyingType->ArrExpr )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ];", code_to_strbuilder(self->UnderlyingType->ArrExpr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 17:20:30 -08:00
|
|
|
Code next_arr_expr = self->UnderlyingType->ArrExpr->Next;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( next_arr_expr )
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ];", code_to_strbuilder(next_arr_expr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
next_arr_expr = next_arr_expr->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " %S", self->InlineCmt->Content);
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder typename_to_strbuilder(CodeTypename self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_str( GlobalAllocator, txt("") );
|
|
|
|
typename_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-10-24 22:04:17 -07:00
|
|
|
#if defined(GEN_USE_NEW_TYPENAME_PARSING)
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->ReturnType && self->Params )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ( %S ) ( %SB ) %SB", typename_to_strbuilder(self->ReturnType), self->Name, params_to_strbuilder(self->Params), specifiers_to_strbuilder(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ( %S ) ( %SB )", typename_to_strbuilder(self->ReturnType), self->Name, params_to_strbuilder(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->ReturnType && self->Params )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S ( %SB ) %SB", typename_to_strbuilder(self->ReturnType), self->Name, params_to_strbuilder(self->Params), specifiers_to_strbuilder(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S ( %SB )", typename_to_strbuilder(self->ReturnType), self->Name, params_to_strbuilder(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
return;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-08 17:00:16 -08:00
|
|
|
switch ( self->TypeTag )
|
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
case Tag_Class : strbuilder_append_str( result, txt("class ")); break;
|
|
|
|
case Tag_Enum : strbuilder_append_str( result, txt("enum ")); break;
|
|
|
|
case Tag_Struct : strbuilder_append_str( result, txt("struct ")); break;
|
|
|
|
case Tag_Union : strbuilder_append_str( result, txt("union ")); break;
|
2024-12-08 17:00:16 -08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%S %SB", self->Name, specifiers_to_strbuilder(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->IsParamPack )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("..."));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder union_to_strbuilder(CodeUnion self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 512 );
|
2024-12-05 21:33:53 -08:00
|
|
|
switch ( self->Type )
|
|
|
|
{
|
|
|
|
case CT_Union:
|
2024-12-12 09:55:15 -08:00
|
|
|
union_to_strbuilder_def( self, & result );
|
2024-12-05 21:33:53 -08:00
|
|
|
break;
|
|
|
|
case CT_Union_Fwd:
|
2024-12-12 09:55:15 -08:00
|
|
|
union_to_strbuilder_fwd( self, & result );
|
2024-12-05 21:33:53 -08:00
|
|
|
break;
|
|
|
|
}
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void union_to_strbuilder_def(CodeUnion self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("union ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
if ( self->Name.Len )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S\n{\n%SB\n}"
|
2024-12-02 15:58:07 -08:00
|
|
|
, self->Name
|
2024-12-13 11:38:27 -08:00
|
|
|
, body_to_strbuilder(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Anonymous union
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "\n{\n%SB\n}"
|
2024-12-13 11:38:27 -08:00
|
|
|
, body_to_strbuilder(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result )
|
2024-12-05 21:33:53 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
2024-12-05 21:33:53 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2024-12-05 21:33:53 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("union ") );
|
2024-12-05 21:33:53 -08:00
|
|
|
|
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2024-12-05 21:33:53 -08:00
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
if ( self->Name.Len )
|
2024-12-05 21:33:53 -08:00
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "%S", self->Name);
|
2024-12-05 21:33:53 -08:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( self->Parent == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n"));
|
2024-12-05 21:33:53 -08:00
|
|
|
}
|
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder using_to_strbuilder(CodeUsing self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 128 );
|
2024-12-02 15:58:07 -08:00
|
|
|
switch ( self->Type )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Using:
|
2024-12-12 09:55:15 -08:00
|
|
|
using_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Using_Namespace:
|
2024-12-12 09:55:15 -08:00
|
|
|
using_to_strbuilder_ns( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
void using_to_strbuilder_ref(CodeUsing self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->UnderlyingType )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "using %S = %SB", self->Name, typename_to_strbuilder(self->UnderlyingType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->UnderlyingType->ArrExpr )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ]", code_to_strbuilder(self->UnderlyingType->ArrExpr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 17:20:30 -08:00
|
|
|
Code next_arr_expr = self->UnderlyingType->ArrExpr->Next;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( next_arr_expr )
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ]", code_to_strbuilder(next_arr_expr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
next_arr_expr = next_arr_expr->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";") );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "using %S;", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " %S\n", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
inline
|
2024-12-12 09:55:15 -08:00
|
|
|
void using_to_strbuilder_ns(CodeUsing self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "using namespace $SC; %S", self->Name, self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "using namespace %S;\n", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-08 22:33:37 -08:00
|
|
|
inline
|
2024-12-13 11:38:27 -08:00
|
|
|
StrBuilder var_to_strbuilder(CodeVar self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder result = strbuilder_make_reserve( GlobalAllocator, 256 );
|
|
|
|
var_to_strbuilder_ref( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
neverinline
|
2024-12-12 09:55:15 -08:00
|
|
|
void var_to_strbuilder_ref(CodeVar self, StrBuilder* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
GEN_ASSERT(self);
|
|
|
|
GEN_ASSERT(result);
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->Parent && self->Parent->Type == CT_Variable )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
|
|
|
// Its a comma-separated variable ( a NextVar )
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Specs )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", specifiers_to_strbuilder(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->ValueType->ArrExpr )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ]", code_to_strbuilder(self->ValueType->ArrExpr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 17:20:30 -08:00
|
|
|
Code next_arr_expr = self->ValueType->ArrExpr->Next;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( next_arr_expr )
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ]", code_to_strbuilder(next_arr_expr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
next_arr_expr = next_arr_expr->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Value )
|
2024-10-24 22:04:17 -07:00
|
|
|
{
|
2024-12-11 10:33:35 -08:00
|
|
|
if ( self->VarParenthesizedInit )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "( %SB ", code_to_strbuilder(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " = %SB", code_to_strbuilder(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
}
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
// Keep the chain going...
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->NextVar )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, ", %SB", var_to_strbuilder(self->NextVar) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
if ( self->VarParenthesizedInit )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(" )"));
|
2024-10-24 22:04:17 -07:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
return;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("export ") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Attributes || self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB ", specifiers_to_strbuilder(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Specs )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB\n", specifiers_to_strbuilder(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S", typename_to_strbuilder(self->ValueType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-13 08:56:07 -08:00
|
|
|
if ( self->ValueType && self->ValueType->ArrExpr )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ]", code_to_strbuilder(self->ValueType->ArrExpr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 17:20:30 -08:00
|
|
|
Code next_arr_expr = self->ValueType->ArrExpr->Next;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( next_arr_expr )
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ]", code_to_strbuilder(next_arr_expr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
next_arr_expr = next_arr_expr->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->BitfieldSize )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " : %SB", code_to_strbuilder(self->BitfieldSize) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Value )
|
2024-10-24 22:04:17 -07:00
|
|
|
{
|
2024-12-11 10:33:35 -08:00
|
|
|
if ( self->VarParenthesizedInit )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "( %SB ", code_to_strbuilder(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " = %SB", code_to_strbuilder(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
}
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->NextVar )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, ", %SB", var_to_strbuilder(self->NextVar) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
if ( self->VarParenthesizedInit )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(" )"));
|
2024-10-24 22:04:17 -07:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, "; %S", self->InlineCmt->Content);
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";\n") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2023-11-20 12:09:01 -08:00
|
|
|
return;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->BitfieldSize )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S : %SB", typename_to_strbuilder(self->ValueType), self->Name, code_to_strbuilder(self->BitfieldSize) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
else if ( self->ValueType->ArrExpr )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S[ %SB ]", typename_to_strbuilder(self->ValueType), self->Name, code_to_strbuilder(self->ValueType->ArrExpr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 17:20:30 -08:00
|
|
|
Code next_arr_expr = self->ValueType->ArrExpr->Next;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( next_arr_expr )
|
|
|
|
{
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "[ %SB ]", code_to_strbuilder(next_arr_expr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
next_arr_expr = next_arr_expr->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "%SB %S", typename_to_strbuilder(self->ValueType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Value )
|
2024-10-24 22:04:17 -07:00
|
|
|
{
|
2024-12-11 10:33:35 -08:00
|
|
|
if ( self->VarParenthesizedInit )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, "( %SB ", code_to_strbuilder(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, " = %SB", code_to_strbuilder(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
}
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->NextVar )
|
2024-12-13 11:38:27 -08:00
|
|
|
strbuilder_append_fmt( result, ", %SB", var_to_strbuilder( self->NextVar) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
if ( self->VarParenthesizedInit )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(" )"));
|
2024-10-24 22:04:17 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt(";") );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_fmt( result, " %S", self->InlineCmt->Content);
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-12 09:55:15 -08:00
|
|
|
strbuilder_append_str( result, txt("\n"));
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|