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-02 08:20:31 -08:00
|
|
|
String to_string(CodeAttributes attributes) {
|
|
|
|
return GEN_NS duplicate( attributes->Content, GlobalAllocator );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
String to_string(CodeBody body)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
GEN_ASSERT(body.ast != nullptr);
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 01:12:09 -08:00
|
|
|
switch ( body.ast->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-02 01:12:09 -08:00
|
|
|
append( & result, rcast(AST*, body.ast)->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-02 01:12:09 -08:00
|
|
|
to_string( 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-02 01:12:09 -08:00
|
|
|
to_string_export( body, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
void to_string( CodeBody body, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
GEN_ASSERT(body.ast != nullptr);
|
|
|
|
GEN_ASSERT(result != nullptr);
|
|
|
|
Code curr = body.ast->Front;
|
|
|
|
s32 left = body.ast->NumEntries;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( left -- )
|
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
append_fmt( result, "%S", GEN_NS to_string(curr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
++curr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
void to_string_export( CodeBody body, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
GEN_ASSERT(body.ast != nullptr);
|
|
|
|
GEN_ASSERT(result != nullptr);
|
|
|
|
append_fmt( result, "export\n{\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
Code curr = body;
|
|
|
|
s32 left = body.ast->NumEntries;
|
2023-11-19 17:34:46 -08:00
|
|
|
while ( left-- )
|
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
append_fmt( result, "%S", to_string(curr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
++curr;
|
|
|
|
}
|
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
append_fmt( result, "};\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeComment comment)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
return GEN_NS duplicate( comment->Content, GlobalAllocator );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeConstructor self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 13:59:13 -08:00
|
|
|
to_string_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-02 13:59:13 -08:00
|
|
|
to_string_fwd( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_def(CodeConstructor self, String* 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-02 13:59:13 -08:00
|
|
|
append( result, ClassStructParent->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
|
|
|
else {
|
2024-12-02 13:59:13 -08:00
|
|
|
append( 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 )
|
|
|
|
append_fmt( result, "( %S )", GEN_NS to_string(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, "()" );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InitializerList )
|
|
|
|
append_fmt( result, " : %S", GEN_NS to_string(self->InitializerList) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
|
|
|
append_fmt( result, " // %S", self->InlineCmt->Content );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_fwd(CodeConstructor self, String* 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-02 13:59:13 -08:00
|
|
|
append( result, ClassStructParent->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
|
|
|
else {
|
2024-12-02 13:59:13 -08:00
|
|
|
append( 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 )
|
|
|
|
append_fmt( result, "( %S )", GEN_NS to_string(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "()");
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if (self->Body)
|
|
|
|
append_fmt( result, " = %S", GEN_NS to_string(self->Body) );
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
|
|
|
append_fmt( result, "; // %S\n", self->InlineCmt->Content );
|
2024-04-17 14:40:32 -07:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, ";\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
String to_string( CodeClass self )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 01:12:09 -08:00
|
|
|
to_string_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-02 01:12:09 -08:00
|
|
|
to_string_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
void to_string_def( CodeClass self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
GEN_ASSERT(self.ast != nullptr);
|
|
|
|
AST_Class* ast = self.ast;
|
|
|
|
|
2024-12-01 02:30:37 -08:00
|
|
|
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
|
2024-12-02 01:12:09 -08:00
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
append( result, "class " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
if ( ast->Attributes )
|
|
|
|
{
|
2024-12-02 08:20:31 -08:00
|
|
|
append_fmt( result, "%S ", GEN_NS to_string(ast->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ast->ParentType )
|
|
|
|
{
|
|
|
|
char const* access_level = to_str( ast->ParentAccess );
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S : %s %S", ast->Name, access_level, to_string(ast->ParentType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename interface = cast(CodeTypename, ast->ParentType->Next);
|
2023-11-19 17:34:46 -08:00
|
|
|
if ( interface )
|
2024-12-02 01:12:09 -08:00
|
|
|
append( result, "\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
while ( interface )
|
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, ", %S", to_string(interface) );
|
2024-12-03 12:19:39 -08:00
|
|
|
interface = interface->Next ? cast(CodeTypename, interface->Next) : CodeTypename { nullptr };
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( ast->Name )
|
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
append( result, ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ast->InlineCmt )
|
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
append_fmt( result, " // %S", ast->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != CT_Typedef && ast->Parent->Type != CT_Variable ) )
|
2024-12-02 01:12:09 -08:00
|
|
|
append( result, ";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
void to_string_fwd( CodeClass self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 01:12:09 -08:00
|
|
|
GEN_ASSERT(self.ast != nullptr);
|
|
|
|
AST_Class* ast = self.ast;
|
|
|
|
|
2024-12-01 02:30:37 -08:00
|
|
|
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
|
2024-12-02 01:12:09 -08:00
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
if ( ast->Attributes )
|
2024-12-02 08:20:31 -08:00
|
|
|
append_fmt( result, "class %S %S", to_string(ast->Attributes), ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 01:12:09 -08:00
|
|
|
else append_fmt( result, "class %S", ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
// Check if it can have an end-statement
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != CT_Typedef && ast->Parent->Type != CT_Variable ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
|
|
|
if ( ast->InlineCmt )
|
2024-12-02 01:12:09 -08:00
|
|
|
append_fmt( result, "; // %S\n", ast->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 01:12:09 -08:00
|
|
|
append( result,";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeDefine define)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
return string_fmt_buf( GlobalAllocator, "#define %S %S\n", define->Name, define->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string(CodeDefine define, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "#define %S %S\n", define->Name, define->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeDestructor self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 13:59:13 -08:00
|
|
|
to_string_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-02 13:59:13 -08:00
|
|
|
to_string_fwd( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_def(CodeDestructor self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Name )
|
2024-04-17 14:40:32 -07:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
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-03 10:14:14 -08:00
|
|
|
if ( has(self->Specs, Spec_Virtual ) )
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "virtual ~%S()", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "~%S()", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "~%S()", self->Parent->Name );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_fwd(CodeDestructor self, String* 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-03 10:14:14 -08:00
|
|
|
if ( has(self->Specs, Spec_Virtual ) )
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "virtual ~%S();\n", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "~%S()", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( has(self->Specs, Spec_Pure ) )
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, " = 0;" );
|
|
|
|
else if (self->Body)
|
|
|
|
append_fmt( result, " = %S;", GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
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 )
|
|
|
|
append_fmt( result, " %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, "\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeEnum self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 13:59:13 -08:00
|
|
|
to_string_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-02 13:59:13 -08:00
|
|
|
to_string_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-02 13:59:13 -08:00
|
|
|
to_string_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-02 13:59:13 -08:00
|
|
|
to_string_class_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_def(CodeEnum self, String* 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 ))
|
|
|
|
append( result, "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-02 13:59:13 -08:00
|
|
|
append( result, "enum " );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S ", GEN_NS to_string(self->Attributes) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->UnderlyingType )
|
|
|
|
append_fmt( result, "%S : %S\n{\n%S\n}"
|
|
|
|
, self->Name
|
2024-12-02 15:35:34 -08:00
|
|
|
, to_string(self->UnderlyingType)
|
2024-12-02 13:59:13 -08:00
|
|
|
, GEN_NS to_string(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
2024-12-02 13:59:13 -08:00
|
|
|
else if ( self->UnderlyingTypeMacro )
|
|
|
|
append_fmt( result, "%S : %S\n{\n%S\n}"
|
|
|
|
, self->Name
|
|
|
|
, GEN_NS to_string(self->UnderlyingTypeMacro)
|
|
|
|
, GEN_NS to_string(self->Body)
|
2024-12-01 02:30:37 -08:00
|
|
|
);
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
else append_fmt( result, "%S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
2024-12-02 13:59:13 -08:00
|
|
|
else append_fmt( result, "enum %S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->Parent.ast == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, ";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_fwd(CodeEnum self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->UnderlyingType )
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "enum %S : %S", self->Name, to_string(self->UnderlyingType) );
|
2024-12-01 15:50:37 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "enum %S", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->Parent.ast == 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 )
|
|
|
|
append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, ";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_class_def(CodeEnum self, String* 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 ))
|
|
|
|
append( result, "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-02 13:59:13 -08:00
|
|
|
append( result, "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-02 13:59:13 -08:00
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(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-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S : %S\n{\n%S\n}", self->Name, to_string(self->UnderlyingType), GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "%S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "enum class %S\n{\n%S\n}", GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->Parent.ast == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, ";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_class_fwd(CodeEnum self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, "enum class " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S : %S", self->Name, to_string(self->UnderlyingType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->Parent.ast == 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 )
|
|
|
|
append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, ";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeExec exec)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
return GEN_NS duplicate( exec->Content, GlobalAllocator );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string(CodeExtern self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Body )
|
|
|
|
append_fmt( result, "extern \"%S\"\n{\n%S\n}\n", self->Name, GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "extern \"%S\"\n{}\n", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeInclude include)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
return string_fmt_buf( GlobalAllocator, "#include %S\n", include->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string( CodeInclude include, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "#include %S\n", include->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeFriend self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string(CodeFriend self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "friend %S", GEN_NS to_string(self->Declaration) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->Declaration->Type != CT_Function && (* result)[ length(* result) - 1 ] != ';' )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, ";" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
|
|
|
append_fmt( result, " %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, "\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
String to_string(CodeFn self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 13:59:13 -08:00
|
|
|
to_string_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-02 13:59:13 -08:00
|
|
|
to_string_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_def(CodeFn self, String* 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 ))
|
|
|
|
append( result, "export" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, " %S ",GEN_NS to_string(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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( ! is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 13:59:13 -08:00
|
|
|
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 )
|
|
|
|
append( result, "\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->ReturnType )
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S %S(", to_string(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
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 )
|
|
|
|
append_fmt( result, "%S)", GEN_NS to_string(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( 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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
void to_string_fwd(CodeFn self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( ! is_trailing( spec ) || ! (spec != Spec_Pure) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 13:59:13 -08:00
|
|
|
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-02 13:59:13 -08:00
|
|
|
append( result, "\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->ReturnType )
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S %S(", to_string(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
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 )
|
|
|
|
append_fmt( result, "%S)", GEN_NS to_string(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( 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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 13:59:13 -08:00
|
|
|
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( self->Specs && has(self->Specs, Spec_Pure ) >= 0 )
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, " = 0;" );
|
|
|
|
else if (self->Body)
|
|
|
|
append_fmt( result, " = %S;", GEN_NS to_string(self->Body) );
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
|
|
|
append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 13:59:13 -08:00
|
|
|
append( result, ";\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
String to_string(CodeModule self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 15:35:34 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string(CodeModule self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if (((u32(ModuleFlag_Export) & u32(self->ModuleFlags)) == u32(ModuleFlag_Export)))
|
|
|
|
append( result, "export ");
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if (((u32(ModuleFlag_Import) & u32(self->ModuleFlags)) == u32(ModuleFlag_Import)))
|
|
|
|
append( result, "import ");
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S;\n", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
String to_string(CodeNS self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 15:35:34 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string(CodeNS self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "namespace %S\n{\n%S\n}\n", self->Name, to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
String to_string(CodeOperator self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 15:35:34 -08:00
|
|
|
to_string_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-02 15:35:34 -08:00
|
|
|
to_string_fwd( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_def(CodeOperator self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( ! is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 15:35:34 -08:00
|
|
|
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-02 15:35:34 -08:00
|
|
|
append( result, "\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->ReturnType )
|
|
|
|
append_fmt( result, "%S %S (", GEN_NS to_string(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Params )
|
|
|
|
append_fmt( result, "%S)", GEN_NS to_string(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append( 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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 15:35:34 -08:00
|
|
|
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
|
|
|
append_fmt( result, "\n{\n%S\n}\n"
|
|
|
|
, GEN_NS to_string(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_fwd(CodeOperator self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S\n",GEN_NS to_string(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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( ! is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 15:35:34 -08:00
|
|
|
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-02 15:35:34 -08:00
|
|
|
append( result, "\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S %S (", to_string(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Params )
|
|
|
|
append_fmt( result, "%S)", GEN_NS to_string(self->Params) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 15:35:34 -08:00
|
|
|
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 )
|
|
|
|
append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append( result, ";\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
String to_string(CodeOpCast self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 15:35:34 -08:00
|
|
|
to_string_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-02 15:35:34 -08:00
|
|
|
to_string_fwd(self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_def(CodeOpCast self, String* 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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2024-10-25 01:08:20 -07:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( ! is_trailing( spec ) )
|
2024-10-25 01:08:20 -07:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 15:35:34 -08:00
|
|
|
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-02 15:35:34 -08:00
|
|
|
if ( self->Name && length(self->Name) )
|
|
|
|
append_fmt( result, "%Soperator %S()", self->Name, to_string(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "operator %S()", to_string(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 15:35:34 -08:00
|
|
|
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
|
|
|
append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
|
2023-11-20 12:09:01 -08:00
|
|
|
return;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Name && length(self->Name) )
|
|
|
|
append_fmt( result, "%Soperator %S()\n{\n%S\n}\n", self->Name, to_string(self->ValueType), GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "operator %S()\n{\n%S\n}\n", to_string(self->ValueType), GEN_NS to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_fwd(CodeOpCast self, String* 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-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2024-10-25 01:08:20 -07:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( ! is_trailing( spec ) )
|
2024-10-25 01:08:20 -07:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 15:35:34 -08:00
|
|
|
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-02 15:35:34 -08:00
|
|
|
append_fmt( result, "operator %S()", to_string(self->ValueType) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
for ( Specifier spec : self->Specs )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
if ( is_trailing( spec ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
StrC spec_str = to_str( spec );
|
2024-12-02 15:35:34 -08:00
|
|
|
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 )
|
|
|
|
append_fmt( result, "; %S", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append( result, ";\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 )
|
|
|
|
append_fmt( result, "operator %S(); %S", to_string(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "operator %S();\n", to_string(self->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 07:58:24 -08:00
|
|
|
String to_string(CodeParam self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 07:58:24 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 07:58:24 -08:00
|
|
|
void to_string( CodeParam self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 07:58:24 -08:00
|
|
|
AST_Param* ast = self.ast;
|
2024-04-17 14:40:32 -07:00
|
|
|
if ( ast->Macro )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-04-17 14:40:32 -07:00
|
|
|
// Related to parsing: ( <macro>, ... )
|
2024-12-02 07:58:24 -08:00
|
|
|
GEN_NS append( result, ast->Macro.ast->Content );
|
2024-04-17 14:40:32 -07:00
|
|
|
// Could also be: ( <macro> <type <name>, ... )
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ast->Name )
|
2024-04-17 14:40:32 -07:00
|
|
|
{
|
|
|
|
if ( ast->ValueType.ast == nullptr )
|
2024-12-02 07:58:24 -08:00
|
|
|
append_fmt( result, " %S", ast->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, " %S %S", to_string(ast->ValueType), ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-04-17 14:40:32 -07:00
|
|
|
}
|
|
|
|
else if ( ast->ValueType )
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, " %S", to_string(ast->ValueType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-10-24 22:04:17 -07:00
|
|
|
if ( ast->PostNameMacro )
|
|
|
|
{
|
2024-12-02 07:58:24 -08:00
|
|
|
append_fmt( result, " %S", GEN_NS to_string(ast->PostNameMacro) );
|
2024-10-24 22:04:17 -07:00
|
|
|
}
|
|
|
|
|
2023-11-19 17:34:46 -08:00
|
|
|
if ( ast->Value )
|
2024-12-02 07:58:24 -08:00
|
|
|
append_fmt( result, " = %S", GEN_NS to_string(ast->Value) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-04-17 14:40:32 -07:00
|
|
|
if ( ast->NumEntries - 1 > 0 )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-04-17 14:40:32 -07:00
|
|
|
for ( CodeParam param : ast->Next )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 07:58:24 -08:00
|
|
|
append_fmt( result, ", %S", to_string(param) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
String to_string(CodePreprocessCond self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 15:35:34 -08:00
|
|
|
to_string_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-02 15:35:34 -08:00
|
|
|
to_string_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-02 15:35:34 -08:00
|
|
|
to_string_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-02 15:35:34 -08:00
|
|
|
to_string_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-02 15:35:34 -08:00
|
|
|
to_string_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-02 15:35:34 -08:00
|
|
|
to_string_endif( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_if(CodePreprocessCond cond, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "#if %S\n", cond->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_ifdef(CodePreprocessCond cond, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "#ifdef %S\n", cond->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_ifndef(CodePreprocessCond cond, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "#ifndef %S\n", cond->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_elif(CodePreprocessCond cond, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "#elif %S\n", cond->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_else(CodePreprocessCond cond, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "#else\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string_endif(CodePreprocessCond cond, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "#endif\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
String to_string(CodePragma self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 15:35:34 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string(CodePragma self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "#pragma %S\n", self->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 07:58:24 -08:00
|
|
|
String to_string(CodeSpecifiers self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 07:58:24 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 07:58:24 -08:00
|
|
|
void to_string( CodeSpecifiers self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 07:58:24 -08:00
|
|
|
GEN_ASSERT(self.ast != nullptr);
|
|
|
|
GEN_ASSERT(result != nullptr);
|
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-03 10:14:14 -08:00
|
|
|
StrC spec = to_str( self->ArrSpecs[idx] );
|
2024-12-02 07:58:24 -08:00
|
|
|
append_fmt( result, "%.*s ", spec.Len, spec.Ptr );
|
2023-11-19 17:34:46 -08:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 08:20:31 -08:00
|
|
|
String to_string(CodeStruct self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 08:20:31 -08:00
|
|
|
GEN_ASSERT(self.ast != nullptr);
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 08:20:31 -08:00
|
|
|
to_string_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-02 08:20:31 -08:00
|
|
|
to_string_fwd( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 08:20:31 -08:00
|
|
|
void to_string_def( CodeStruct self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 08:20:31 -08:00
|
|
|
GEN_ASSERT(self.ast != nullptr);
|
|
|
|
AST_Struct* ast = self.ast;
|
|
|
|
|
2024-12-01 02:30:37 -08:00
|
|
|
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
|
2024-12-02 08:20:31 -08:00
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 08:20:31 -08:00
|
|
|
append( result, "struct " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
if ( ast->Attributes )
|
|
|
|
{
|
2024-12-02 08:20:31 -08:00
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(ast->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ast->ParentType )
|
|
|
|
{
|
|
|
|
char const* access_level = to_str( ast->ParentAccess );
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S : %s %S", ast->Name, access_level, GEN_NS to_string(ast->ParentType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename interface = cast(CodeTypename, ast->ParentType->Next);
|
2023-11-19 17:34:46 -08:00
|
|
|
if ( interface )
|
2024-12-02 08:20:31 -08:00
|
|
|
append( result, "\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
while ( interface )
|
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, ", %S", GEN_NS to_string(interface) );
|
2024-12-03 12:19:39 -08:00
|
|
|
interface = interface->Next ? cast( CodeTypename, interface->Next) : CodeTypename { nullptr };
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( ast->Name )
|
|
|
|
{
|
2024-12-02 08:20:31 -08:00
|
|
|
append( result, ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ast->InlineCmt )
|
|
|
|
{
|
2024-12-02 08:20:31 -08:00
|
|
|
append_fmt( result, " // %S", ast->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 08:20:31 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != CT_Typedef && ast->Parent->Type != CT_Variable ) )
|
2024-12-02 08:20:31 -08:00
|
|
|
append( result, ";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 08:20:31 -08:00
|
|
|
void to_string_fwd( CodeStruct self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 08:20:31 -08:00
|
|
|
GEN_ASSERT(self.ast != nullptr);
|
|
|
|
AST_Struct* ast = self.ast;
|
|
|
|
|
2024-12-01 02:30:37 -08:00
|
|
|
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
|
2024-12-02 08:20:31 -08:00
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
if ( ast->Attributes )
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "struct %S %S", GEN_NS to_string(ast->Attributes), ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 08:20:31 -08:00
|
|
|
else append_fmt( result, "struct %S", ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != CT_Typedef && ast->Parent->Type != CT_Variable ) )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
|
|
|
if ( ast->InlineCmt )
|
2024-12-02 08:20:31 -08:00
|
|
|
append_fmt( result, "; %S", ast->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 08:20:31 -08:00
|
|
|
append( result, ";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
String to_string(CodeTemplate self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 15:35:34 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
void to_string(CodeTemplate self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Params )
|
|
|
|
append_fmt( result, "template< %S >\n%S", GEN_NS to_string(self->Params), GEN_NS to_string(self->Declaration) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "template<>\n%S", GEN_NS to_string(self->Declaration) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
String to_string(CodeTypedef self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 15:58:07 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
void to_string(CodeTypedef self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, "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 )
|
|
|
|
append( result, GEN_NS to_string(self->UnderlyingType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, "%S %S", GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ];", GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ];", GEN_NS to_string(next_arr_expr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
next_arr_expr = next_arr_expr->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, ";" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
|
|
|
append_fmt( result, " %S", self->InlineCmt->Content);
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, "\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
String to_string(CodeTypename self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 15:35:34 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
void to_string(CodeTypename self, String* 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 )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
|
|
|
append_fmt( result, "%S ( %S ) ( %S ) %S", self->ReturnType.to_string(), self->Name, self->Params.to_string(), self->Specs.to_string() );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S ( %S ) ( %S )", self->ReturnType.to_string(), self->Name, self->Params.to_string() );
|
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 )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
|
|
|
append_fmt( result, "%S %S ( %S ) %S", GEN_NS to_string(self->ReturnType), self->Name, GEN_NS to_string(self->Params), GEN_NS to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
append_fmt( result, "%S %S ( %S )", GEN_NS to_string(self->ReturnType), self->Name, GEN_NS to_string(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 )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
|
|
|
append_fmt( result, "%S %S", self->Name, GEN_NS to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:35:34 -08:00
|
|
|
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 )
|
|
|
|
append( result, "...");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
String to_string(CodeUnion self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 15:58:07 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
void to_string(CodeUnion self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, "union " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Name )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, "%S\n{\n%S\n}"
|
|
|
|
, self->Name
|
|
|
|
, GEN_NS to_string(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Anonymous union
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}"
|
|
|
|
, GEN_NS to_string(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->Parent.ast == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) )
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, ";\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
String to_string(CodeUsing self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
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-02 15:58:07 -08:00
|
|
|
to_string( 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-02 15:58:07 -08:00
|
|
|
to_string_ns( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
void to_string(CodeUsing self, String* 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 ))
|
|
|
|
append( result, "export " );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Attributes )
|
|
|
|
append_fmt( result, "%S ",GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "using %S = %S", self->Name, GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ]", GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ]", GEN_NS to_string(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
|
|
|
append( result, ";" );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
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 )
|
|
|
|
append_fmt( result, " %S\n", self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, "\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
void to_string_ns(CodeUsing self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
|
|
|
append_fmt( result, "using namespace $S; %S", self->Name, self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, "using namespace %s;\n", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
String to_string(CodeVar self)
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 15:58:07 -08:00
|
|
|
to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
void to_string(CodeVar self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
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 )
|
|
|
|
append_fmt( result, "%S ", GEN_NS to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
append( 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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ]", GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ]", GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
if ( self->VarConstructorInit )
|
|
|
|
append_fmt( result, "( %S ", GEN_NS to_string(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, " = %S", GEN_NS to_string(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 )
|
|
|
|
append_fmt( result, ", %S", self->NextVar.to_string() );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->VarConstructorInit )
|
|
|
|
append( result, " )");
|
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 ))
|
|
|
|
append( result, "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 )
|
|
|
|
append_fmt( result, "%S ", GEN_NS to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Specs )
|
|
|
|
append_fmt( result, "%S\n", GEN_NS to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, "%S %S", GEN_NS to_string(self->ValueType), 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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ]", GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ]", GEN_NS to_string(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 )
|
|
|
|
append_fmt( result, " : %S", GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
if ( self->VarConstructorInit )
|
|
|
|
append_fmt( result, "( %S ", GEN_NS to_string(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, " = %S", GEN_NS to_string(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 )
|
|
|
|
append_fmt( result, ", %S", self->NextVar.to_string() );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->VarConstructorInit )
|
|
|
|
append( result, " )");
|
2024-10-24 22:04:17 -07:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
|
|
|
append_fmt( result, "; %S", self->InlineCmt->Content);
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, ";\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 )
|
|
|
|
append_fmt( result, "%S %S : %S", GEN_NS to_string(self->ValueType), self->Name, GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "%S %S[ %S ]", GEN_NS to_string(self->ValueType), self->Name, GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
append_fmt( result, "[ %S ]", GEN_NS to_string(next_arr_expr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
next_arr_expr = next_arr_expr->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, "%S %S", GEN_NS to_string(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-02 15:58:07 -08:00
|
|
|
if ( self->VarConstructorInit )
|
|
|
|
append_fmt( result, "( %S ", GEN_NS to_string(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append_fmt( result, " = %S", GEN_NS to_string(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 )
|
|
|
|
append_fmt( result, ", %S", self->NextVar.to_string() );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->VarConstructorInit )
|
|
|
|
append( result, " )");
|
2024-10-24 22:04:17 -07:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, ";" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
|
|
|
append_fmt( result, " %S", self->InlineCmt->Content);
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-02 15:58:07 -08:00
|
|
|
append( result, "\n");
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|