2023-08-28 21:03:08 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
2023-08-21 17:30:13 -07:00
|
|
|
#pragma once
|
2023-08-21 20:02:20 -07:00
|
|
|
#include "static_data.cpp"
|
2023-08-28 20:46:50 -07:00
|
|
|
#endif
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2024-12-01 21:03:38 -08:00
|
|
|
global Code Code_Global;
|
|
|
|
global Code Code_Invalid;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-09-11 20:22:53 -07:00
|
|
|
// This serializes all the data-members in a "debug" format, where each member is printed with its associated value.
|
2024-12-06 02:29:17 -08:00
|
|
|
char const* code_debug_str(Code self)
|
2023-08-23 18:19:31 -07:00
|
|
|
{
|
2024-12-01 15:50:37 -08:00
|
|
|
GEN_ASSERT(self != nullptr);
|
2024-12-01 20:35:58 -08:00
|
|
|
String result_stack = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
|
|
|
String* result = & result_stack;
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Parent )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tParent : %S %S", code_type_str(self->Parent), self->Name ? self->Name : "" );
|
2023-09-11 20:22:53 -07:00
|
|
|
else
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tParent : %S", "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tName : %S", self->Name ? self->Name : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tType : %S", code_type_str(self) );
|
2024-12-07 14:17:02 -08:00
|
|
|
string_append_fmt( result, "\n\tModule Flags : %S", module_flag_to_str( self->ModuleFlags ) );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
switch ( self->Type )
|
2023-08-23 18:19:31 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Invalid:
|
|
|
|
case CT_NewLine:
|
|
|
|
case CT_Access_Private:
|
|
|
|
case CT_Access_Protected:
|
|
|
|
case CT_Access_Public:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Untyped:
|
|
|
|
case CT_Execution:
|
|
|
|
case CT_Comment:
|
|
|
|
case CT_PlatformAttributes:
|
|
|
|
case CT_Preprocess_Define:
|
|
|
|
case CT_Preprocess_Include:
|
|
|
|
case CT_Preprocess_Pragma:
|
|
|
|
case CT_Preprocess_If:
|
|
|
|
case CT_Preprocess_ElIf:
|
|
|
|
case CT_Preprocess_Else:
|
|
|
|
case CT_Preprocess_IfDef:
|
|
|
|
case CT_Preprocess_IfNotDef:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tContent: %S", self->Content );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class:
|
|
|
|
case CT_Struct:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
2024-12-07 14:17:02 -08:00
|
|
|
string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? access_spec_to_str( self->ParentAccess ) : "No Parent" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class_Fwd:
|
|
|
|
case CT_Struct_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
2024-12-07 14:17:02 -08:00
|
|
|
string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? access_spec_to_str( self->ParentAccess ) : "No Parent" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Constructor:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? code_to_string(self->InitializerList) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Constructor_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? code_to_string(self->InitializerList) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Destructor:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Destructor_Fwd:
|
2023-09-25 09:12:11 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum:
|
|
|
|
case CT_Enum_Class:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Fwd:
|
|
|
|
case CT_Enum_Class_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Extern_Linkage:
|
|
|
|
case CT_Namespace:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tBody: %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Friend:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? code_to_string(self->Declaration) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-08-23 18:19:31 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Module:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator:
|
|
|
|
case CT_Operator_Member:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tOp : %S", operator_to_str( self->Op ) );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Fwd:
|
|
|
|
case CT_Operator_Member_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tOp : %S", operator_to_str( self->Op ) );
|
2023-09-25 13:42:29 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Cast:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? code_to_string(self->ValueType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Cast_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? code_to_string(self->ValueType) : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Parameters:
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
|
|
|
|
string_append_fmt( result, "\n\tLast : %S", self->Last->Name );
|
|
|
|
string_append_fmt( result, "\n\tNext : %S", self->Next->Name );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? code_to_string(self->ValueType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tValue : %S", self->Value ? code_to_string(self->Value) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Specifiers:
|
2023-09-11 20:22:53 -07:00
|
|
|
{
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
|
2024-12-04 08:30:54 -08:00
|
|
|
string_append_strc( result, txt("\n\tArrSpecs: ") );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
|
|
|
s32 idx = 0;
|
2024-12-01 15:50:37 -08:00
|
|
|
s32 left = self->NumEntries;
|
2023-09-11 20:22:53 -07:00
|
|
|
while ( left-- )
|
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC spec = spec_to_str( self->ArrSpecs[idx] );
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "%.*s, ", spec.Len, spec.Ptr );
|
2023-09-11 20:22:53 -07:00
|
|
|
idx++;
|
|
|
|
}
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNextSpecs: %S", self->NextSpecs ? code_debug_str(self->NextSpecs) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Template:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? code_to_string(self->Declaration) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Typedef:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Typename:
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tReturnType : %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tArrExpr : %S", self->ArrExpr ? code_to_string(self->ArrExpr) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Union:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Using:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Variable:
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( self->Parent && self->Parent->Type == CT_Variable )
|
2023-09-11 20:22:53 -07:00
|
|
|
{
|
|
|
|
// Its a NextVar
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tValue : %S", self->Value ? code_to_string(self->Value) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? code_to_string(self->BitfieldSize) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tNextVar : %S", self->NextVar ? code_debug_str(self->NextVar) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Next )
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
2024-12-06 02:29:17 -08:00
|
|
|
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? code_to_string(self->ValueType) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? code_to_string(self->BitfieldSize) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tValue : %S", self->Value ? code_to_string(self->Value) : "Null" );
|
|
|
|
string_append_fmt( result, "\n\tNextVar : %S", self->NextVar ? code_debug_str(self->NextVar) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
}
|
2023-08-23 18:19:31 -07:00
|
|
|
|
2024-12-01 20:35:58 -08:00
|
|
|
return * result;
|
2023-08-23 18:19:31 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
Code code_duplicate(Code self)
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-02 17:20:30 -08:00
|
|
|
Code result = make_code();
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
void* mem_result = rcast(void*, cast(AST*, result));
|
|
|
|
void* mem_self = rcast(void*, cast(AST*, self));
|
|
|
|
mem_copy( mem_result, mem_self, sizeof( AST ) );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-02 17:20:30 -08:00
|
|
|
result->Parent = { nullptr };
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
String code_to_string(Code self)
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-04 08:01:53 -08:00
|
|
|
String result = string_make_strc( GlobalAllocator, txt("") );
|
2024-12-06 02:29:17 -08:00
|
|
|
code_to_string_ptr( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
void code_to_string_ptr( Code self, String* result )
|
2023-11-19 17:34:46 -08:00
|
|
|
{
|
2024-12-02 00:18:52 -08:00
|
|
|
GEN_ASSERT(self != nullptr);
|
2023-11-19 17:34:46 -08:00
|
|
|
local_persist thread_local
|
|
|
|
char SerializationLevel = 0;
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-02 00:18:52 -08:00
|
|
|
switch ( self->Type )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Invalid:
|
2023-09-11 20:22:53 -07:00
|
|
|
#ifdef GEN_DONT_ALLOW_INVALID_CODE
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->code_debug_str() : Name );
|
2023-09-11 20:22:53 -07:00
|
|
|
#else
|
2024-12-04 08:30:54 -08:00
|
|
|
string_append_fmt( result, "Invalid Code!" );
|
2023-09-11 20:22:53 -07:00
|
|
|
#endif
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_NewLine:
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_strc( result, txt("\n"));
|
2023-08-04 13:12:13 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Untyped:
|
|
|
|
case CT_Execution:
|
|
|
|
case CT_Comment:
|
|
|
|
case CT_PlatformAttributes:
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_strc( result, self->Content );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Access_Private:
|
|
|
|
case CT_Access_Protected:
|
|
|
|
case CT_Access_Public:
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_strc( result, self->Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class:
|
2024-12-06 21:21:09 -08:00
|
|
|
class_to_string_def(cast(CodeClass, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
class_to_string_fwd(cast(CodeClass, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Constructor:
|
2024-12-06 21:21:09 -08:00
|
|
|
constructor_to_string_def(cast(CodeConstructor, self), result );
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Constructor_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
constructor_to_string_fwd(cast(CodeConstructor, self), result );
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Destructor:
|
2024-12-06 21:21:09 -08:00
|
|
|
destructor_to_string_def(cast(CodeDestructor, self), result );
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Destructor_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
destructor_to_string_fwd(cast(CodeDestructor, self), result );
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum:
|
2024-12-06 21:21:09 -08:00
|
|
|
enum_to_string_def(cast(CodeEnum, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
enum_to_string_fwd(cast(CodeEnum, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Class:
|
2024-12-06 21:21:09 -08:00
|
|
|
enum_to_string_class_def(cast(CodeEnum, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Class_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
enum_to_string_class_fwd(cast(CodeEnum, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Export_Body:
|
2024-12-06 21:21:09 -08:00
|
|
|
body_to_string_export(cast(CodeBody, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Extern_Linkage:
|
2024-12-06 21:21:09 -08:00
|
|
|
extern_to_string(cast(CodeExtern, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Friend:
|
2024-12-06 21:21:09 -08:00
|
|
|
friend_to_string_ref(cast(CodeFriend, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function:
|
2024-12-06 21:21:09 -08:00
|
|
|
fn_to_string_def(cast(CodeFn, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
fn_to_string_fwd(cast(CodeFn, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Module:
|
2024-12-06 21:21:09 -08:00
|
|
|
module_to_string_ref(cast(CodeModule, self), result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Namespace:
|
2024-12-06 21:21:09 -08:00
|
|
|
namespace_to_string_ref(cast(CodeNS, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator:
|
|
|
|
case CT_Operator_Member:
|
2024-12-06 21:21:09 -08:00
|
|
|
code_op_to_string_def(cast(CodeOperator, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Fwd:
|
|
|
|
case CT_Operator_Member_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
code_op_to_string_fwd(cast(CodeOperator, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Cast:
|
2024-12-06 21:21:09 -08:00
|
|
|
opcast_to_string_def(cast(CodeOpCast, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Cast_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
opcast_to_string_fwd(cast(CodeOpCast, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Parameters:
|
2024-12-06 21:21:09 -08:00
|
|
|
params_to_string_ref(cast(CodeParam, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_Define:
|
2024-12-06 21:21:09 -08:00
|
|
|
define_to_string_ref(cast(CodeDefine, self), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_If:
|
2024-12-06 21:21:09 -08:00
|
|
|
preprocess_to_string_if(cast(CodePreprocessCond, self), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_IfDef:
|
2024-12-06 21:21:09 -08:00
|
|
|
preprocess_to_string_ifdef(cast(CodePreprocessCond, self), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_IfNotDef:
|
2024-12-06 21:21:09 -08:00
|
|
|
preprocess_to_string_ifndef(cast(CodePreprocessCond, self), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_Include:
|
2024-12-06 21:21:09 -08:00
|
|
|
include_to_string_ref(cast(CodeInclude, self), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_ElIf:
|
2024-12-06 21:21:09 -08:00
|
|
|
preprocess_to_string_elif(cast(CodePreprocessCond, self), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_Else:
|
2024-12-06 21:21:09 -08:00
|
|
|
preprocess_to_string_else(cast(CodePreprocessCond, self), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_EndIf:
|
2024-12-06 21:21:09 -08:00
|
|
|
preprocess_to_string_endif(cast(CodePreprocessCond, self), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_Pragma:
|
2024-12-06 21:21:09 -08:00
|
|
|
pragma_to_string_ref(cast(CodePragma, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Specifiers:
|
2024-12-06 21:21:09 -08:00
|
|
|
specifiers_to_string_ref(cast(CodeSpecifiers, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Struct:
|
2024-12-06 21:21:09 -08:00
|
|
|
struct_to_string_def(cast(CodeStruct, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Struct_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
struct_to_string_fwd(cast(CodeStruct, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Template:
|
2024-12-06 21:21:09 -08:00
|
|
|
template_to_string_ref(cast(CodeTemplate, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Typedef:
|
2024-12-06 21:21:09 -08:00
|
|
|
typedef_to_string_ref(cast(CodeTypedef, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Typename:
|
2024-12-06 21:21:09 -08:00
|
|
|
typename_to_string_ref(cast(CodeTypename, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Union:
|
2024-12-06 21:21:09 -08:00
|
|
|
union_to_string_def( cast(CodeUnion, self), result );
|
2024-12-05 21:33:53 -08:00
|
|
|
break;
|
2024-12-06 02:29:17 -08:00
|
|
|
|
2024-12-05 21:33:53 -08:00
|
|
|
case CT_Union_Fwd:
|
2024-12-06 21:21:09 -08:00
|
|
|
union_to_string_fwd( cast(CodeUnion, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Using:
|
2024-12-06 21:21:09 -08:00
|
|
|
using_to_string_ref(cast(CodeUsing, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Using_Namespace:
|
2024-12-06 21:21:09 -08:00
|
|
|
using_to_string_ns(cast(CodeUsing, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Variable:
|
2024-12-06 21:21:09 -08:00
|
|
|
var_to_string_ref(cast(CodeVar, self), result );
|
2023-08-04 13:12:13 -07: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-06 21:21:09 -08:00
|
|
|
body_to_string_ref( cast(CodeBody, self), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
bool code_is_equal( Code self, Code other )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2023-08-22 13:01:50 -07:00
|
|
|
/*
|
|
|
|
AST values are either some u32 value, a cached string, or a pointer to another AST.
|
|
|
|
|
|
|
|
u32 values are compared by value.
|
|
|
|
Cached strings are compared by pointer.
|
|
|
|
AST nodes are compared with AST::is_equal.
|
|
|
|
*/
|
|
|
|
if ( other == nullptr )
|
2023-08-23 15:16:45 -07:00
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
log_fmt( "AST::is_equal: other is null\nAST: %S", code_debug_str(self) );
|
2023-08-22 13:01:50 -07:00
|
|
|
return false;
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
2023-08-22 13:01:50 -07:00
|
|
|
|
2024-12-01 21:34:40 -08:00
|
|
|
if ( self->Type != other->Type )
|
2023-08-23 15:16:45 -07:00
|
|
|
{
|
|
|
|
log_fmt("AST::is_equal: Type check failure with other\nAST: %S\nOther: %S"
|
2024-12-06 02:29:17 -08:00
|
|
|
, code_debug_str(self)
|
|
|
|
,code_debug_str(other)
|
2023-08-23 15:16:45 -07:00
|
|
|
);
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
return false;
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-01 21:34:40 -08:00
|
|
|
switch ( self->Type )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2023-09-03 17:29:45 -07:00
|
|
|
#define check_member_val( val ) \
|
2024-12-01 21:34:40 -08:00
|
|
|
if ( self->val != other->val ) \
|
2023-09-03 17:29:45 -07:00
|
|
|
{ \
|
|
|
|
log_fmt("\nAST::is_equal: Member - " #val " failed\n" \
|
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
2024-12-07 14:17:02 -08:00
|
|
|
, code_debug_str(self) \
|
|
|
|
,code_debug_str(other) \
|
2023-09-03 17:29:45 -07:00
|
|
|
); \
|
2024-12-03 15:47:12 -08:00
|
|
|
\
|
2023-09-03 17:29:45 -07:00
|
|
|
return false; \
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
|
|
|
|
2023-09-03 17:29:45 -07:00
|
|
|
#define check_member_str( str ) \
|
2024-12-01 21:34:40 -08:00
|
|
|
if ( self->str != other->str ) \
|
2023-09-03 17:29:45 -07:00
|
|
|
{ \
|
|
|
|
log_fmt("\nAST::is_equal: Member string - "#str " failed\n" \
|
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
2024-12-07 14:17:02 -08:00
|
|
|
, code_debug_str(self) \
|
|
|
|
,code_debug_str(other) \
|
2023-09-03 17:29:45 -07:00
|
|
|
); \
|
|
|
|
\
|
|
|
|
return false; \
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
#define check_member_content( content ) \
|
|
|
|
if ( self->content != other->content ) \
|
|
|
|
{ \
|
|
|
|
log_fmt("\nAST::is_equal: Member content - "#content " failed\n" \
|
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
2024-12-07 14:17:02 -08:00
|
|
|
, code_debug_str(self) \
|
|
|
|
, code_debug_str(other) \
|
2024-12-04 08:01:53 -08:00
|
|
|
); \
|
|
|
|
\
|
|
|
|
log_fmt("Content cannot be trusted to be unique with this check " \
|
|
|
|
"so it must be verified by eye for now\n" \
|
|
|
|
"AST Content:\n%S\n" \
|
|
|
|
"Other Content:\n%S\n" \
|
|
|
|
, strc_visualize_whitespace(self->content, GlobalAllocator) \
|
|
|
|
, strc_visualize_whitespace(other->content, GlobalAllocator) \
|
|
|
|
); \
|
2023-08-25 15:57:53 -07:00
|
|
|
}
|
|
|
|
|
2023-09-03 17:29:45 -07:00
|
|
|
#define check_member_ast( ast ) \
|
2024-12-01 21:34:40 -08:00
|
|
|
if ( self->ast ) \
|
2023-09-03 17:29:45 -07:00
|
|
|
{ \
|
|
|
|
if ( other->ast == nullptr ) \
|
|
|
|
{ \
|
|
|
|
log_fmt("\nAST::is_equal: Failed for member " #ast " other equivalent param is null\n" \
|
|
|
|
"AST : %s\n" \
|
|
|
|
"Other: %s\n" \
|
|
|
|
"For ast member: %s\n" \
|
2024-12-07 14:17:02 -08:00
|
|
|
, code_debug_str(self) \
|
|
|
|
, code_debug_str(other) \
|
|
|
|
, code_debug_str(self->ast) \
|
2023-09-03 17:29:45 -07:00
|
|
|
); \
|
|
|
|
\
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
\
|
2024-12-07 14:17:02 -08:00
|
|
|
if ( ! code_is_equal(self->ast, other->ast ) ) \
|
2023-09-03 17:29:45 -07:00
|
|
|
{ \
|
|
|
|
log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \
|
2024-12-07 14:17:02 -08:00
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
|
|
|
"For ast member: %S\n" \
|
|
|
|
"other's ast member: %S\n" \
|
|
|
|
, code_debug_str(self) \
|
|
|
|
, code_debug_str(other) \
|
|
|
|
, code_debug_str(self->ast) \
|
|
|
|
, code_debug_str(other->ast) \
|
2023-09-03 17:29:45 -07:00
|
|
|
); \
|
|
|
|
\
|
|
|
|
return false; \
|
|
|
|
} \
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_NewLine:
|
|
|
|
case CT_Access_Public:
|
|
|
|
case CT_Access_Protected:
|
|
|
|
case CT_Access_Private:
|
|
|
|
case CT_Preprocess_Else:
|
|
|
|
case CT_Preprocess_EndIf:
|
2023-08-22 13:01:50 -07:00
|
|
|
return true;
|
|
|
|
|
2023-08-26 08:55:05 -07:00
|
|
|
|
|
|
|
// Comments are not validated.
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Comment:
|
2023-09-05 21:30:34 -07:00
|
|
|
return true;
|
2023-08-26 08:55:05 -07:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Execution:
|
|
|
|
case CT_PlatformAttributes:
|
|
|
|
case CT_Untyped:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-25 15:57:53 -07:00
|
|
|
check_member_content( Content );
|
2023-09-05 21:30:34 -07:00
|
|
|
return true;
|
2023-08-22 13:01:50 -07:00
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class_Fwd:
|
|
|
|
case CT_Struct_Fwd:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( ParentType );
|
|
|
|
check_member_val( ParentAccess );
|
|
|
|
check_member_ast( Attributes );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class:
|
|
|
|
case CT_Struct:
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( ParentType );
|
|
|
|
check_member_val( ParentAccess );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( Body );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Constructor:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_ast( InitializerList );
|
|
|
|
check_member_ast( Params );
|
|
|
|
check_member_ast( Body );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Constructor_Fwd:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_ast( InitializerList );
|
|
|
|
check_member_ast( Params );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Destructor:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( Body );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Destructor_Fwd:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_ast( Specs );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum:
|
|
|
|
case CT_Enum_Class:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( UnderlyingType );
|
|
|
|
check_member_ast( Body );
|
2024-12-05 21:33:53 -08:00
|
|
|
check_member_ast( UnderlyingTypeMacro );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Fwd:
|
|
|
|
case CT_Enum_Class_Fwd:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( UnderlyingType );
|
2024-12-05 21:33:53 -08:00
|
|
|
check_member_ast( UnderlyingTypeMacro );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Extern_Linkage:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Body );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Friend:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Declaration );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( ReturnType );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( Params );
|
|
|
|
check_member_ast( Body );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Fwd:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( ReturnType );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( Params );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Module:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Namespace:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Body );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator:
|
|
|
|
case CT_Operator_Member:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( ReturnType );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( Params );
|
|
|
|
check_member_ast( Body );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Fwd:
|
|
|
|
case CT_Operator_Member_Fwd:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( ReturnType );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( Params );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Cast:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( ValueType );
|
|
|
|
check_member_ast( Body );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Operator_Cast_Fwd:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( ValueType );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Parameters:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2024-12-01 21:34:40 -08:00
|
|
|
if ( self->NumEntries > 1 )
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2024-12-02 17:20:30 -08:00
|
|
|
Code curr = self;
|
|
|
|
Code curr_other = other;
|
2023-08-22 13:01:50 -07:00
|
|
|
while ( curr != nullptr )
|
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
if ( curr )
|
|
|
|
{
|
|
|
|
if ( curr_other == nullptr )
|
|
|
|
{
|
2023-09-03 17:29:45 -07:00
|
|
|
log_fmt("\nAST::is_equal: Failed for parameter, other equivalent param is null\n"
|
2024-12-07 14:17:02 -08:00
|
|
|
"AST : %S\n"
|
|
|
|
"Other: %S\n"
|
|
|
|
"For ast member: %S\n"
|
|
|
|
, code_debug_str(curr)
|
2023-08-23 15:16:45 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-03 17:34:27 -07:00
|
|
|
if ( curr->Name != curr_other->Name )
|
2023-08-23 15:16:45 -07:00
|
|
|
{
|
2023-09-03 17:29:45 -07:00
|
|
|
log_fmt( "\nAST::is_equal: Failed for parameter name check\n"
|
|
|
|
"AST : %S\n"
|
|
|
|
"Other: %S\n"
|
|
|
|
"For ast member: %S\n"
|
|
|
|
"other's ast member: %S\n"
|
2024-12-06 02:29:17 -08:00
|
|
|
, code_debug_str(self)
|
|
|
|
, code_debug_str(other)
|
|
|
|
, code_debug_str(curr)
|
|
|
|
, code_debug_str(curr_other)
|
2023-09-03 17:29:45 -07:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
if ( curr->ValueType && ! code_is_equal(curr->ValueType, curr_other->ValueType) )
|
2023-09-03 17:29:45 -07:00
|
|
|
{
|
|
|
|
log_fmt( "\nAST::is_equal: Failed for parameter value type check\n"
|
|
|
|
"AST : %S\n"
|
|
|
|
"Other: %S\n"
|
|
|
|
"For ast member: %S\n"
|
|
|
|
"other's ast member: %S\n"
|
2024-12-06 02:29:17 -08:00
|
|
|
, code_debug_str(self)
|
|
|
|
, code_debug_str(other)
|
|
|
|
, code_debug_str(curr)
|
|
|
|
, code_debug_str(curr_other)
|
2023-09-03 17:29:45 -07:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
if ( curr->Value && ! code_is_equal(curr->Value, curr_other->Value) )
|
2023-09-03 17:29:45 -07:00
|
|
|
{
|
|
|
|
log_fmt( "\nAST::is_equal: Failed for parameter value check\n"
|
2023-08-23 15:16:45 -07:00
|
|
|
"AST : %S\n"
|
|
|
|
"Other: %S\n"
|
|
|
|
"For ast member: %S\n"
|
|
|
|
"other's ast member: %S\n"
|
2024-12-06 02:29:17 -08:00
|
|
|
, code_debug_str(self)
|
|
|
|
, code_debug_str(other)
|
|
|
|
, code_debug_str(curr)
|
|
|
|
, code_debug_str(curr_other)
|
2023-08-23 15:16:45 -07:00
|
|
|
);
|
2023-08-25 15:40:13 -07:00
|
|
|
return false;
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
|
|
|
}
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
curr = curr->Next;
|
|
|
|
curr_other = curr_other->Next;
|
|
|
|
}
|
|
|
|
|
2023-08-25 15:40:13 -07:00
|
|
|
check_member_val( NumEntries );
|
|
|
|
|
2023-08-22 13:01:50 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( ValueType );
|
|
|
|
check_member_ast( Value );
|
|
|
|
check_member_ast( ArrExpr );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_Define:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_str( Name );
|
2023-08-25 15:57:53 -07:00
|
|
|
check_member_content( Content );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_If:
|
|
|
|
case CT_Preprocess_IfDef:
|
|
|
|
case CT_Preprocess_IfNotDef:
|
|
|
|
case CT_Preprocess_ElIf:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-25 15:57:53 -07:00
|
|
|
check_member_content( Content );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Preprocess_Include:
|
|
|
|
case CT_Preprocess_Pragma:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-25 15:57:53 -07:00
|
|
|
check_member_content( Content );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Specifiers:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( NumEntries );
|
|
|
|
check_member_str( Name );
|
2024-12-01 21:34:40 -08:00
|
|
|
for ( s32 idx = 0; idx < self->NumEntries; ++idx )
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ArrSpecs[ idx ] );
|
2023-08-22 13:01:50 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Template:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Params );
|
|
|
|
check_member_ast( Declaration );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Typedef:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( IsFunction );
|
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( UnderlyingType );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Typename:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( IsParamPack );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Specs );
|
|
|
|
check_member_ast( ArrExpr );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Union:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( Body );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2024-12-07 14:17:02 -08:00
|
|
|
|
2024-12-05 21:33:53 -08:00
|
|
|
case CT_Union_Fwd:
|
|
|
|
{
|
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
}
|
2023-08-22 13:01:50 -07:00
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Using:
|
|
|
|
case CT_Using_Namespace:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( UnderlyingType );
|
|
|
|
check_member_ast( Attributes );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Variable:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( ValueType );
|
|
|
|
check_member_ast( BitfieldSize );
|
|
|
|
check_member_ast( Value );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( Specs );
|
2023-09-06 00:06:30 -07:00
|
|
|
check_member_ast( NextVar );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class_Body:
|
|
|
|
case CT_Enum_Body:
|
|
|
|
case CT_Export_Body:
|
|
|
|
case CT_Global_Body:
|
|
|
|
case CT_Namespace_Body:
|
|
|
|
case CT_Struct_Body:
|
|
|
|
case CT_Union_Body:
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_ast( Front );
|
|
|
|
check_member_ast( Back );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
2024-12-02 17:20:30 -08:00
|
|
|
Code curr = self->Front;
|
|
|
|
Code curr_other = other->Front;
|
2023-08-22 13:01:50 -07:00
|
|
|
while ( curr != nullptr )
|
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
if ( curr_other == nullptr )
|
|
|
|
{
|
2023-09-03 17:29:45 -07:00
|
|
|
log_fmt("\nAST::is_equal: Failed for body, other equivalent param is null\n"
|
2024-12-07 14:17:02 -08:00
|
|
|
"AST : %S\n"
|
|
|
|
"Other: %S\n"
|
|
|
|
"For ast member: %S\n"
|
|
|
|
, code_debug_str(curr)
|
2023-08-23 15:16:45 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
if ( ! code_is_equal( curr, curr_other ) )
|
2023-08-23 15:16:45 -07:00
|
|
|
{
|
2023-09-03 17:29:45 -07:00
|
|
|
log_fmt( "\nAST::is_equal: Failed for body\n"
|
2023-08-23 15:16:45 -07:00
|
|
|
"AST : %S\n"
|
|
|
|
"Other: %S\n"
|
|
|
|
"For ast member: %S\n"
|
|
|
|
"other's ast member: %S\n"
|
2024-12-06 02:29:17 -08:00
|
|
|
, code_debug_str(self)
|
|
|
|
, code_debug_str(other)
|
|
|
|
, code_debug_str(curr)
|
|
|
|
, code_debug_str(curr_other)
|
2023-08-23 15:16:45 -07:00
|
|
|
);
|
|
|
|
|
2023-08-22 13:01:50 -07:00
|
|
|
return false;
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
curr = curr->Next;
|
|
|
|
curr_other = curr_other->Next;
|
|
|
|
}
|
|
|
|
|
2023-08-25 15:40:13 -07:00
|
|
|
check_member_val( NumEntries );
|
|
|
|
|
2023-08-22 13:01:50 -07:00
|
|
|
return true;
|
|
|
|
}
|
2023-08-23 15:16:45 -07:00
|
|
|
|
|
|
|
#undef check_member_val
|
|
|
|
#undef check_member_str
|
|
|
|
#undef check_member_ast
|
2023-08-22 13:01:50 -07:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:29:17 -08:00
|
|
|
bool code_validate_body(Code self)
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
#define CheckEntries( Unallowed_Types ) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
CodeBody body = cast(CodeBody, self); \
|
|
|
|
for ( Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry) ) \
|
|
|
|
{ \
|
|
|
|
switch ( code_entry->Type ) \
|
|
|
|
{ \
|
|
|
|
Unallowed_Types \
|
|
|
|
log_failure( "AST::validate_body: Invalid entry in body %s", code_debug_str(code_entry) ); \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
2023-07-24 14:45:27 -07:00
|
|
|
while (0);
|
|
|
|
|
2024-12-02 00:18:52 -08:00
|
|
|
switch ( self->Type )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Class_Body:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Enum_Body:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
|
|
|
CodeBody body = cast(CodeBody, self);
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( entry->Type != CT_Untyped )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", GEN_NS code_debug_str(entry) );
|
2023-07-24 14:45:27 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Export_Body:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Extern_Linkage:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES );
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Function_Body:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES );
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Global_Body:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
|
|
|
CodeBody body = cast(CodeBody, self);
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
|
2023-08-06 11:58:43 -07:00
|
|
|
{
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Access_Public:
|
|
|
|
case CT_Access_Protected:
|
|
|
|
case CT_Access_Private:
|
|
|
|
case CT_PlatformAttributes:
|
|
|
|
case CT_Class_Body:
|
|
|
|
case CT_Enum_Body:
|
|
|
|
case CT_Execution:
|
|
|
|
case CT_Friend:
|
|
|
|
case CT_Function_Body:
|
|
|
|
case CT_Global_Body:
|
|
|
|
case CT_Namespace_Body:
|
|
|
|
case CT_Operator_Member:
|
|
|
|
case CT_Operator_Member_Fwd:
|
|
|
|
case CT_Parameters:
|
|
|
|
case CT_Specifiers:
|
|
|
|
case CT_Struct_Body:
|
|
|
|
case CT_Typename:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure("AST::validate_body: Invalid entry in body %s", GEN_NS code_debug_str(entry));
|
2023-08-06 11:58:43 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Namespace_Body:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES );
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Struct_Body:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_STRUCT_UNALLOWED_TYPES );
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2024-12-03 12:19:39 -08:00
|
|
|
case CT_Union_Body:
|
2024-12-06 02:29:17 -08:00
|
|
|
{
|
|
|
|
CodeBody body = cast(CodeBody, self);
|
2024-12-06 21:21:09 -08:00
|
|
|
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-03 12:19:39 -08:00
|
|
|
if ( entry->Type != CT_Untyped )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", GEN_NS code_debug_str(entry) );
|
2023-07-24 14:45:27 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-12-06 02:29:17 -08:00
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-06 02:29:17 -08:00
|
|
|
log_failure( "AST::validate_body: Invalid this AST does not have a body %s", code_debug_str(self) );
|
2023-07-24 14:45:27 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2023-07-29 02:52:06 -07:00
|
|
|
|
|
|
|
#undef CheckEntries
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|