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-01 15:50:37 -08:00
|
|
|
char const* debug_str(AST* 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-02 00:18:52 -08:00
|
|
|
append_fmt( result, "\n\tParent : %S %S", type_str(self->Parent), self->Name ? self->Name : "" );
|
2023-09-11 20:22:53 -07:00
|
|
|
else
|
2024-12-01 00:06:30 -08:00
|
|
|
append_fmt( result, "\n\tParent : %S", "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tName : %S", self->Name ? self->Name : "Null" );
|
|
|
|
append_fmt( result, "\n\tType : %S", type_str(self) );
|
|
|
|
append_fmt( result, "\n\tModule Flags : %S", 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
|
|
|
{
|
2023-09-11 20:22:53 -07:00
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
case Invalid:
|
|
|
|
case NewLine:
|
|
|
|
case Access_Private:
|
|
|
|
case Access_Protected:
|
|
|
|
case Access_Public:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Untyped:
|
|
|
|
case Execution:
|
|
|
|
case Comment:
|
|
|
|
case PlatformAttributes:
|
|
|
|
case Preprocess_Define:
|
|
|
|
case Preprocess_Include:
|
|
|
|
case Preprocess_Pragma:
|
|
|
|
case Preprocess_If:
|
|
|
|
case Preprocess_ElIf:
|
|
|
|
case Preprocess_Else:
|
|
|
|
case Preprocess_IfDef:
|
|
|
|
case Preprocess_IfNotDef:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tContent: %S", self->Content );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Class:
|
|
|
|
case Struct:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? to_str( self->ParentAccess ) : "No Parent" );
|
|
|
|
append_fmt( result, "\n\tParentType : %s", self->ParentType ? type_str(self->ParentType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-25 09:12:11 -07:00
|
|
|
case Class_Fwd:
|
|
|
|
case Struct_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? to_str( self->ParentAccess ) : "No Parent" );
|
|
|
|
append_fmt( result, "\n\tParentType : %s", self->ParentType ? type_str(self->ParentType) : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-11 20:22:53 -07:00
|
|
|
case Constructor:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? to_string(self->InitializerList) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-25 09:12:11 -07:00
|
|
|
case Constructor_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? to_string(self->InitializerList) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-11 20:22:53 -07:00
|
|
|
case Destructor:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-25 09:12:11 -07:00
|
|
|
case Destructor_Fwd:
|
|
|
|
break;
|
|
|
|
|
2023-09-11 20:22:53 -07:00
|
|
|
case Enum:
|
2023-09-25 09:12:11 -07:00
|
|
|
case Enum_Class:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-25 13:42:29 -07:00
|
|
|
case Enum_Fwd:
|
2023-09-25 09:12:11 -07:00
|
|
|
case Enum_Class_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
|
2023-09-25 09:12:11 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-11 20:22:53 -07:00
|
|
|
case Extern_Linkage:
|
|
|
|
case Namespace:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tBody: %S", self->Body ? debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Friend:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Function:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-08-23 18:19:31 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-25 13:42:29 -07:00
|
|
|
case Function_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-11 20:22:53 -07:00
|
|
|
case Module:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator:
|
2023-09-25 13:42:29 -07:00
|
|
|
case Operator_Member:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
|
|
|
|
append_fmt( result, "\n\tOp : %S", to_str( self->Op ) );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-25 13:42:29 -07:00
|
|
|
case Operator_Fwd:
|
|
|
|
case Operator_Member_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
|
|
|
|
append_fmt( result, "\n\tOp : %S", to_str( self->Op ) );
|
2023-09-25 13:42:29 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-11 20:22:53 -07:00
|
|
|
case Operator_Cast:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-25 13:42:29 -07:00
|
|
|
case Operator_Cast_Fwd:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
|
2023-09-25 13:42:29 -07:00
|
|
|
break;
|
|
|
|
|
2023-09-11 20:22:53 -07:00
|
|
|
case Parameters:
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
|
|
|
|
append_fmt( result, "\n\tLast : %S", self->Last->Name );
|
|
|
|
append_fmt( result, "\n\tNext : %S", self->Next->Name );
|
|
|
|
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Specifiers:
|
|
|
|
{
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
|
2024-12-01 00:06:30 -08:00
|
|
|
GEN_NS append( result, "\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-01 15:50:37 -08:00
|
|
|
StrC spec = ESpecifier::to_str( self->ArrSpecs[idx] );
|
2024-12-01 00:06:30 -08:00
|
|
|
append_fmt( result, "%.*s, ", spec.Len, spec.Ptr );
|
2023-09-11 20:22:53 -07:00
|
|
|
idx++;
|
|
|
|
}
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tNextSpecs: %S", self->NextSpecs ? debug_str(self->NextSpecs) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Template:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
|
|
|
|
append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Typedef:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Typename:
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tReturnType : %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
|
|
|
|
append_fmt( result, "\n\tArrExpr : %S", self->ArrExpr ? to_string(self->ArrExpr) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Union:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Using:
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Prev )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Variable:
|
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
if ( self->Parent && self->Parent->Type == Variable )
|
2023-09-11 20:22:53 -07:00
|
|
|
{
|
|
|
|
// Its a NextVar
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? to_string(self->BitfieldSize) : "Null" );
|
|
|
|
append_fmt( result, "\n\tNextVar : %S", self->NextVar ? 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 )
|
|
|
|
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
|
|
|
if ( self->Next )
|
|
|
|
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
2023-09-11 20:22:53 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
|
|
|
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
|
|
|
|
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
|
|
|
|
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
|
|
|
|
append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? to_string(self->BitfieldSize) : "Null" );
|
|
|
|
append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
|
|
|
|
append_fmt( result, "\n\tNextVar : %S", self->NextVar ? 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-01 15:50:37 -08:00
|
|
|
AST* duplicate(AST* self)
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
2023-07-26 11:21:20 -07:00
|
|
|
AST* result = make_code().ast;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-01 15:50:37 -08:00
|
|
|
mem_copy( result, self, sizeof( AST ) );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-07-26 11:21:20 -07:00
|
|
|
result->Parent = nullptr;
|
2023-07-24 14:45:27 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-12-02 00:18:52 -08:00
|
|
|
String to_string(AST* self)
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
2024-12-01 00:06:30 -08:00
|
|
|
String result = string_make( GlobalAllocator, "" );
|
2024-12-02 00:18:52 -08:00
|
|
|
GEN_NS to_string( self, & result );
|
2023-11-19 17:34:46 -08:00
|
|
|
return result;
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-02 00:18:52 -08:00
|
|
|
void to_string( AST* 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
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
case Invalid:
|
2023-09-11 20:22:53 -07:00
|
|
|
#ifdef GEN_DONT_ALLOW_INVALID_CODE
|
2023-08-08 19:14:58 -07:00
|
|
|
log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->debug_str() : Name );
|
2023-09-11 20:22:53 -07:00
|
|
|
#else
|
2024-12-02 00:18:52 -08:00
|
|
|
append_fmt( result, "Invalid Code!" );
|
2023-09-11 20:22:53 -07:00
|
|
|
#endif
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2023-08-04 13:12:13 -07:00
|
|
|
case NewLine:
|
2024-12-02 00:18:52 -08:00
|
|
|
append( result,"\n");
|
2023-08-04 13:12:13 -07:00
|
|
|
break;
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
case Untyped:
|
|
|
|
case Execution:
|
|
|
|
case Comment:
|
2023-09-11 20:22:53 -07:00
|
|
|
case PlatformAttributes:
|
2024-12-02 00:18:52 -08:00
|
|
|
append( result, self->Content );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Access_Private:
|
|
|
|
case Access_Protected:
|
|
|
|
case Access_Public:
|
2024-12-02 00:18:52 -08:00
|
|
|
append( result, self->Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
case Class:
|
2024-12-02 01:12:09 -08:00
|
|
|
to_string_def(cast(CodeClass, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Class_Fwd:
|
2024-12-02 01:12:09 -08:00
|
|
|
to_string_fwd(cast(CodeClass, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2023-08-07 00:10:45 -07:00
|
|
|
case Constructor:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_def(cast(CodeConstructor, {self}), result );
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Constructor_Fwd:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_fwd(cast(CodeConstructor, {self}), result );
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Destructor:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_def(cast(CodeDestructor, {self}), result );
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Destructor_Fwd:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_fwd(cast(CodeDestructor, {self}), result );
|
2023-08-07 00:10:45 -07:00
|
|
|
break;
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
case Enum:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_def(cast(CodeEnum, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Fwd:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_fwd(cast(CodeEnum, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Class:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_class_def(cast(CodeEnum, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Class_Fwd:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_class_fwd(cast(CodeEnum, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Export_Body:
|
2024-12-02 01:12:09 -08:00
|
|
|
to_string_export(cast(CodeBody, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Extern_Linkage:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string(cast(CodeExtern, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Friend:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string(cast(CodeFriend, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Function:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_def(cast(CodeFn, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Function_Fwd:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string_fwd(cast(CodeFn, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Module:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeModule, {self}).to_string( * result );
|
2023-11-19 17:34:46 -08:00
|
|
|
break;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
case Namespace:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeNS, {self}).to_string( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator:
|
|
|
|
case Operator_Member:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeOperator, {self}).to_string_def( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator_Fwd:
|
|
|
|
case Operator_Member_Fwd:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeOperator, {self}).to_string_fwd( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator_Cast:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeOpCast, {self}).to_string_def( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator_Cast_Fwd:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeOpCast, {self}).to_string_fwd( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Parameters:
|
2024-12-02 07:58:24 -08:00
|
|
|
to_string(cast(CodeParam, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
2023-11-20 12:09:01 -08:00
|
|
|
|
2023-07-29 22:21:04 -07:00
|
|
|
case Preprocess_Define:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string(cast(CodeDefine, {self}), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_If:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodePreprocessCond, {self}).to_string_if( * result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_IfDef:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodePreprocessCond, {self}).to_string_ifdef( * result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_IfNotDef:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodePreprocessCond, {self}).to_string_ifndef( * result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_Include:
|
2024-12-02 13:59:13 -08:00
|
|
|
to_string(cast(CodeInclude, {self}), result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_ElIf:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodePreprocessCond, {self}).to_string_elif( * result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_Else:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodePreprocessCond, {self}).to_string_else( * result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_EndIf:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodePreprocessCond, {self}).to_string_endif( * result );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_Pragma:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodePragma, {self}).to_string( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Specifiers:
|
2024-12-02 07:58:24 -08:00
|
|
|
to_string(cast(CodeSpecifiers, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct:
|
2024-12-02 08:20:31 -08:00
|
|
|
to_string_def(cast(CodeStruct, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct_Fwd:
|
2024-12-02 08:20:31 -08:00
|
|
|
to_string_fwd(cast(CodeStruct, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Template:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeTemplate, {self}).to_string( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Typedef:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeTypedef, {self}).to_string( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Typename:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeType, {self}).to_string( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Union:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeUnion, {self}).to_string( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Using:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeUsing, {self}).to_string( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Using_Namespace:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeUsing, {self}).to_string_ns( * result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Variable:
|
2024-12-02 00:18:52 -08:00
|
|
|
cast(CodeVar, {self}).to_string( * result );
|
2023-08-04 13:12:13 -07:00
|
|
|
break;
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
case Enum_Body:
|
2023-08-04 13:12:13 -07:00
|
|
|
case Class_Body:
|
2023-07-24 14:45:27 -07:00
|
|
|
case Extern_Linkage_Body:
|
|
|
|
case Function_Body:
|
|
|
|
case Global_Body:
|
|
|
|
case Namespace_Body:
|
|
|
|
case Struct_Body:
|
|
|
|
case Union_Body:
|
2024-12-02 01:12:09 -08:00
|
|
|
to_string( cast(CodeBody, {self}), result );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-01 21:34:40 -08:00
|
|
|
bool is_equal( AST* self, AST* 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-01 21:34:40 -08:00
|
|
|
log_fmt( "AST::is_equal: other is null\nAST: %S", 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-01 21:34:40 -08:00
|
|
|
, debug_str(self)
|
2024-12-02 00:18:52 -08:00
|
|
|
,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-08-22 13:01:50 -07:00
|
|
|
using namespace ECode;
|
|
|
|
|
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-01 21:34:40 -08:00
|
|
|
, debug_str(self) \
|
2024-12-02 00:18:52 -08:00
|
|
|
,debug_str(other) \
|
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-01 21:34:40 -08:00
|
|
|
, debug_str(self) \
|
2024-12-02 00:18:52 -08:00
|
|
|
,debug_str(other) \
|
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_content( content ) \
|
2024-12-01 21:34:40 -08:00
|
|
|
if ( self->content != other->content ) \
|
2023-09-03 17:29:45 -07:00
|
|
|
{ \
|
|
|
|
log_fmt("\nAST::is_equal: Member content - "#content " failed\n" \
|
2023-08-25 15:57:53 -07:00
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
2024-12-01 21:34:40 -08:00
|
|
|
, debug_str(self) \
|
2024-12-02 00:18:52 -08:00
|
|
|
,debug_str(other) \
|
2023-08-25 15:57:53 -07: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" \
|
2024-12-01 21:34:40 -08:00
|
|
|
, visualize_whitespace(self->content) \
|
2024-12-01 00:06:30 -08:00
|
|
|
, visualize_whitespace(other->content) \
|
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-01 21:34:40 -08:00
|
|
|
, debug_str(self) \
|
2024-12-02 00:18:52 -08:00
|
|
|
, debug_str(other) \
|
|
|
|
, debug_str(self->ast) \
|
2023-09-03 17:29:45 -07:00
|
|
|
); \
|
|
|
|
\
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
\
|
2024-12-02 00:18:52 -08:00
|
|
|
if ( ! is_equal(self->ast, other->ast ) ) \
|
2023-09-03 17:29:45 -07:00
|
|
|
{ \
|
|
|
|
log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \
|
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
|
|
|
"For ast member: %S\n" \
|
|
|
|
"other's ast member: %S\n" \
|
2024-12-01 21:34:40 -08:00
|
|
|
, debug_str(self) \
|
2024-12-02 00:18:52 -08:00
|
|
|
, debug_str(other) \
|
|
|
|
, debug_str(self->ast) \
|
|
|
|
, debug_str(other->ast) \
|
2023-09-03 17:29:45 -07:00
|
|
|
); \
|
|
|
|
\
|
|
|
|
return false; \
|
|
|
|
} \
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
|
|
|
|
2023-08-22 13:01:50 -07:00
|
|
|
case NewLine:
|
|
|
|
case Access_Public:
|
|
|
|
case Access_Protected:
|
|
|
|
case Access_Private:
|
|
|
|
case Preprocess_Else:
|
|
|
|
case Preprocess_EndIf:
|
|
|
|
return true;
|
|
|
|
|
2023-08-26 08:55:05 -07:00
|
|
|
|
|
|
|
// Comments are not validated.
|
2023-08-22 13:01:50 -07:00
|
|
|
case Comment:
|
2023-09-05 21:30:34 -07:00
|
|
|
return true;
|
2023-08-26 08:55:05 -07:00
|
|
|
|
2023-08-22 13:01:50 -07:00
|
|
|
case Execution:
|
|
|
|
case PlatformAttributes:
|
|
|
|
case Untyped:
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
case Class_Fwd:
|
|
|
|
case Struct_Fwd:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Class:
|
|
|
|
case 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;
|
|
|
|
}
|
|
|
|
|
2023-08-22 13:01:50 -07:00
|
|
|
case Constructor:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Constructor_Fwd:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Destructor:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Destructor_Fwd:
|
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_ast( Specs );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Enum:
|
|
|
|
case Enum_Class:
|
|
|
|
{
|
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 );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Enum_Fwd:
|
|
|
|
case Enum_Class_Fwd:
|
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ModuleFlags );
|
|
|
|
check_member_str( Name );
|
|
|
|
check_member_ast( Attributes );
|
|
|
|
check_member_ast( UnderlyingType );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Extern_Linkage:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Friend:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Function:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Function_Fwd:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Module:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Namespace:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Operator:
|
|
|
|
case Operator_Member:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Operator_Fwd:
|
|
|
|
case Operator_Member_Fwd:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Operator_Cast:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Operator_Cast_Fwd:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Parameters:
|
|
|
|
{
|
2024-12-01 21:34:40 -08:00
|
|
|
if ( self->NumEntries > 1 )
|
2023-08-22 13:01:50 -07:00
|
|
|
{
|
2024-12-01 21:34:40 -08:00
|
|
|
AST* curr = self;
|
2023-08-22 13:01:50 -07:00
|
|
|
AST* curr_other = other;
|
|
|
|
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"
|
2023-08-23 15:16:45 -07:00
|
|
|
"AST : %S\n"
|
|
|
|
"Other: %S\n"
|
|
|
|
"For ast member: %S\n"
|
2024-12-02 00:18:52 -08:00
|
|
|
, 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-01 21:34:40 -08:00
|
|
|
, debug_str(self)
|
2024-12-02 00:18:52 -08:00
|
|
|
, debug_str(other)
|
|
|
|
, debug_str(curr)
|
|
|
|
, debug_str(curr_other)
|
2023-09-03 17:29:45 -07:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-12-02 00:18:52 -08:00
|
|
|
if ( curr->ValueType && ! 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-01 21:34:40 -08:00
|
|
|
, debug_str(self)
|
2024-12-02 00:18:52 -08:00
|
|
|
, debug_str(other)
|
|
|
|
, debug_str(curr)
|
|
|
|
, debug_str(curr_other)
|
2023-09-03 17:29:45 -07:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-12-02 00:18:52 -08:00
|
|
|
if ( curr->Value && ! 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-01 21:34:40 -08:00
|
|
|
, debug_str(self)
|
2024-12-02 00:18:52 -08:00
|
|
|
, debug_str(other)
|
|
|
|
, debug_str(curr)
|
|
|
|
, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Preprocess_Define:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Preprocess_If:
|
|
|
|
case Preprocess_IfDef:
|
|
|
|
case Preprocess_IfNotDef:
|
|
|
|
case Preprocess_ElIf:
|
|
|
|
{
|
2023-08-25 15:57:53 -07:00
|
|
|
check_member_content( Content );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Preprocess_Include:
|
|
|
|
case Preprocess_Pragma:
|
|
|
|
{
|
2023-08-25 15:57:53 -07:00
|
|
|
check_member_content( Content );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Specifiers:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Template:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Typedef:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
case Typename:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Union:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Using:
|
|
|
|
case Using_Namespace:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Variable:
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Class_Body:
|
|
|
|
case Enum_Body:
|
|
|
|
case Export_Body:
|
|
|
|
case Global_Body:
|
|
|
|
case Namespace_Body:
|
|
|
|
case Struct_Body:
|
|
|
|
case Union_Body:
|
|
|
|
{
|
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-01 21:34:40 -08:00
|
|
|
AST* curr = self->Front;
|
2023-08-22 13:01:50 -07:00
|
|
|
AST* curr_other = other->Front;
|
|
|
|
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"
|
2023-08-23 15:16:45 -07:00
|
|
|
"AST : %S\n"
|
|
|
|
"Other: %S\n"
|
|
|
|
"For ast member: %S\n"
|
2024-12-02 00:18:52 -08:00
|
|
|
, debug_str(curr)
|
2023-08-23 15:16:45 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-12-02 00:18:52 -08:00
|
|
|
if ( ! 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-01 21:34:40 -08:00
|
|
|
, debug_str(self)
|
2024-12-02 00:18:52 -08:00
|
|
|
, debug_str(other)
|
|
|
|
, debug_str(curr)
|
|
|
|
, 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-02 00:18:52 -08:00
|
|
|
bool validate_body(AST* self)
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
2023-07-29 02:52:06 -07:00
|
|
|
#define CheckEntries( Unallowed_Types ) \
|
|
|
|
do \
|
|
|
|
{ \
|
2024-12-02 00:18:52 -08:00
|
|
|
for ( Code entry : cast(CodeBody, {self}) ) \
|
2023-07-29 02:52:06 -07:00
|
|
|
{ \
|
|
|
|
switch ( entry->Type ) \
|
|
|
|
{ \
|
|
|
|
Unallowed_Types \
|
2024-12-01 23:38:55 -08:00
|
|
|
log_failure( "AST::validate_body: Invalid entry in body %s", GEN_NS debug_str(entry) ); \
|
2023-07-29 02:52:06 -07:00
|
|
|
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
|
|
|
{
|
|
|
|
case Class_Body:
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
case Enum_Body:
|
2024-12-02 00:18:52 -08:00
|
|
|
for ( Code entry : cast(CodeBody, {self}) )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( entry->Type != Untyped )
|
|
|
|
{
|
2024-12-01 23:38:55 -08:00
|
|
|
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", GEN_NS debug_str(entry) );
|
2023-07-24 14:45:27 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Export_Body:
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
case Extern_Linkage:
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
case Function_Body:
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
case Global_Body:
|
2024-12-02 00:18:52 -08:00
|
|
|
for (Code entry : cast(CodeBody, {self}))
|
2023-08-06 11:58:43 -07:00
|
|
|
{
|
|
|
|
switch (entry->Type)
|
|
|
|
{
|
|
|
|
case Access_Public:
|
|
|
|
case Access_Protected:
|
|
|
|
case Access_Private:
|
|
|
|
case PlatformAttributes:
|
|
|
|
case Class_Body:
|
|
|
|
case Enum_Body:
|
|
|
|
case Execution:
|
|
|
|
case Friend:
|
|
|
|
case Function_Body:
|
|
|
|
case Global_Body:
|
|
|
|
case Namespace_Body:
|
|
|
|
case Operator_Member:
|
|
|
|
case Operator_Member_Fwd:
|
|
|
|
case Parameters:
|
|
|
|
case Specifiers:
|
|
|
|
case Struct_Body:
|
|
|
|
case Typename:
|
2024-12-01 23:38:55 -08:00
|
|
|
log_failure("AST::validate_body: Invalid entry in body %s", GEN_NS debug_str(entry));
|
2023-08-06 11:58:43 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
case Namespace_Body:
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
case Struct_Body:
|
2023-07-28 18:44:31 -07:00
|
|
|
CheckEntries( GEN_AST_BODY_STRUCT_UNALLOWED_TYPES );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
case Union_Body:
|
2024-12-02 00:18:52 -08:00
|
|
|
for ( Code entry : cast(CodeBody, {self->Body}) )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( entry->Type != Untyped )
|
|
|
|
{
|
2024-12-01 23:38:55 -08:00
|
|
|
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", GEN_NS debug_str(entry) );
|
2023-07-24 14:45:27 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2024-12-02 00:18:52 -08:00
|
|
|
log_failure( "AST::validate_body: Invalid this AST does not have a body %s", 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
|
|
|
}
|