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) {
|
2024-12-03 15:47:12 -08:00
|
|
|
return {(char*) duplicate( attributes->Content, GlobalAllocator ).Ptr};
|
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-03 15:47:12 -08:00
|
|
|
return {(char*) duplicate( comment->Content, GlobalAllocator ).Ptr};
|
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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "( %S )", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " : %S", to_string(self->InitializerList) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " // %SC", self->InlineCmt->Content );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}\n", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "( %S )", 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)
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " = %S", to_string(self->Body) );
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; // %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC : %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-03 16:31:26 -08:00
|
|
|
append_fmt( result, " // %SC", ast->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "class %S %SC", to_string(ast->Attributes), ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
else append_fmt( result, "class %SC", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; // %SC\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-03 16:31:26 -08:00
|
|
|
return string_fmt_buf( GlobalAllocator, "#define %SC %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "#define %SC %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC()", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "virtual ~%SC()", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "~%SC()", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "~%SC()", self->Parent->Name );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}\n", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "virtual ~%SC();\n", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "~%SC()", 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)
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " = %S;", to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "~%SC();", self->Parent->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %SC", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", to_string(self->Attributes) );
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->UnderlyingType )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC : %S\n{\n%S\n}"
|
2024-12-02 13:59:13 -08:00
|
|
|
, self->Name
|
2024-12-02 15:35:34 -08:00
|
|
|
, to_string(self->UnderlyingType)
|
2024-12-03 16:31:26 -08:00
|
|
|
, to_string(self->Body)
|
2023-11-19 17:34:46 -08:00
|
|
|
);
|
2024-12-02 13:59:13 -08:00
|
|
|
else if ( self->UnderlyingTypeMacro )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC : %S\n{\n%S\n}"
|
2024-12-02 13:59:13 -08:00
|
|
|
, self->Name
|
2024-12-03 16:31:26 -08:00
|
|
|
, to_string(self->UnderlyingTypeMacro)
|
|
|
|
, to_string(self->Body)
|
2024-12-01 02:30:37 -08:00
|
|
|
);
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
else append_fmt( result, "%SC\n{\n%S\n}", self->Name, to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
2024-12-03 16:31:26 -08:00
|
|
|
else append_fmt( result, "enum %SC\n{\n%S\n}", self->Name, 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "enum %SC : %S", self->Name, to_string(self->UnderlyingType) );
|
2024-12-01 15:50:37 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "enum %SC", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; %SC", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC : %S\n{\n%S\n}", self->Name, to_string(self->UnderlyingType), to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC\n{\n%S\n}", self->Name, to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "enum %SC\n{\n%S\n}", self->Name, 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC : %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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; %SC", 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-03 15:47:12 -08:00
|
|
|
return {(char*) duplicate( exec->Content, GlobalAllocator ).Ptr};
|
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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "extern \"%SC\"\n{\n%S\n}\n", self->Name, to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "extern \"%SC\"\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-03 16:31:26 -08:00
|
|
|
return string_fmt_buf( GlobalAllocator, "#include %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "#include %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "friend %S", to_string(self->Declaration) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 17:21:08 -08:00
|
|
|
if ( self->Declaration->Type != CT_Function && self->Declaration->Type != CT_Operator && (* 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %SC", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %S ", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC(", to_string(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC(", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Params )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S)", 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 16:31:26 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}\n", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC(", to_string(self->ReturnType), self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC(", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->Params )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S)", 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)
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " = %S;", to_string(self->Body) );
|
2024-04-17 14:40:32 -07:00
|
|
|
|
2024-12-02 13:59:13 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; %SC", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC;\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "namespace %SC\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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Attributes )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC (", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S)", 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"
|
2024-12-03 16:31:26 -08:00
|
|
|
, 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S\n", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC (", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S)", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; %SC", 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-03 15:47:12 -08:00
|
|
|
if ( self->Name && self->Name.Len )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC operator %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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}\n", to_string(self->Body) );
|
2023-11-20 12:09:01 -08:00
|
|
|
return;
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-03 15:47:12 -08:00
|
|
|
if ( self->Name && self->Name.Len )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC operator %S()\n{\n%S\n}\n", self->Name, to_string(self->ValueType), to_string(self->Body) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "operator %S()\n{\n%S\n}\n", to_string(self->ValueType), 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; %SC", 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-03 16:31:26 -08:00
|
|
|
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-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %SC", ast->Name );
|
2024-04-17 14:40:32 -07:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %S %SC", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %S", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, " = %S", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "#if %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "#ifdef %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "#ifndef %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "#elif %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "#pragma %SC\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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC : %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 08:20:31 -08:00
|
|
|
append( result, "\n" );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
|
|
|
while ( interface )
|
|
|
|
{
|
2024-12-03 16:31:26 -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 08:20:31 -08:00
|
|
|
append( result, ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ast->InlineCmt )
|
|
|
|
{
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " // %SC", ast->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
}
|
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "\n{\n%S\n}", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "struct %S %SC", to_string(ast->Attributes), ast->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
else append_fmt( result, "struct %SC", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; %SC", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "template< %S >\n%S", to_string(self->Params), to_string(self->Declaration) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "template<>\n%S", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append( result, to_string(self->UnderlyingType) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ];", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ];", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %SC", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ( %SC ) ( %S ) %S", to_string(self->ReturnType), self->Name, to_string(self->Params), to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ( %SC ) ( %S )", to_string(self->ReturnType), self->Name, to_string(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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
|
|
|
{
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC ( %S ) %S", to_string(self->ReturnType), self->Name, to_string(self->Params), to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC ( %S )", to_string(self->ReturnType), self->Name, 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", to_string(self->Attributes) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:35:34 -08:00
|
|
|
if ( self->Specs )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC %S", self->Name, to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%SC\n{\n%S\n}"
|
2024-12-02 15:58:07 -08:00
|
|
|
, 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "using %SC = %S", self->Name, 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ]", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ]", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "using %SC;", self->Name );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->InlineCmt )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %SC\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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "using namespace $SC; %SC", self->Name, self->InlineCmt->Content );
|
2023-11-19 17:34:46 -08:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "using namespace %SC;\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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ]", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ]", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "( %S ", to_string(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " = %S", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, ", %S", to_string(self->NextVar) );
|
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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S ", to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-02 15:58:07 -08:00
|
|
|
if ( self->Specs )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S\n", to_string(self->Specs) );
|
2023-11-19 17:34:46 -08:00
|
|
|
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ]", 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ]", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " : %S", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "( %S ", to_string(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " = %S", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, ", %S", to_string(self->NextVar) );
|
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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "; %SC", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC : %S", to_string(self->ValueType), self->Name, 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC[ %S ]", to_string(self->ValueType), self->Name, 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-03 16:31:26 -08:00
|
|
|
append_fmt( result, "[ %S ]", to_string(next_arr_expr) );
|
2023-11-19 17:34:46 -08:00
|
|
|
next_arr_expr = next_arr_expr->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "%S %SC", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, "( %S ", to_string(self->Value) );
|
2024-10-24 22:04:17 -07:00
|
|
|
else
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " = %S", 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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, ", %S", to_string( self->NextVar) );
|
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 )
|
2024-12-03 16:31:26 -08:00
|
|
|
append_fmt( result, " %SC", 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
|
|
|
}
|