gencpp/project/components/ast.cpp

1278 lines
44 KiB
C++
Raw Normal View History

#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "static_data.cpp"
#endif
2024-12-01 21:03:38 -08:00
global Code Code_Global;
global Code Code_Invalid;
// This serializes all the data-members in a "debug" format, where each member is printed with its associated value.
char const* code_debug_str(Code self)
{
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;
if ( self->Parent )
string_append_fmt( result, "\n\tParent : %S %S", code_type_str(self->Parent), self->Name ? self->Name : "" );
else
string_append_fmt( result, "\n\tParent : %S", "Null" );
string_append_fmt( result, "\n\tName : %S", self->Name ? self->Name : "Null" );
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 ) );
switch ( self->Type )
{
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:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
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:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tContent: %S", self->Content );
break;
2024-12-03 12:19:39 -08:00
case CT_Class:
case CT_Struct:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Class_Fwd:
case CT_Struct_Fwd:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" );
break;
2024-12-03 12:19:39 -08:00
case CT_Constructor:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Constructor_Fwd:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Destructor:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Destructor_Fwd:
break;
2024-12-03 12:19:39 -08:00
case CT_Enum:
case CT_Enum_Class:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Enum_Fwd:
case CT_Enum_Class_Fwd:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Extern_Linkage:
case CT_Namespace:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tBody: %S", self->Body ? code_debug_str(self->Body) : "Null" );
break;
2024-12-03 12:19:39 -08:00
case CT_Friend:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? code_to_string(self->Declaration) : "Null" );
break;
2024-12-03 12:19:39 -08:00
case CT_Function:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Function_Fwd:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Module:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
break;
2024-12-03 12:19:39 -08:00
case CT_Operator:
case CT_Operator_Member:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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 ) );
break;
2024-12-03 12:19:39 -08:00
case CT_Operator_Fwd:
case CT_Operator_Member_Fwd:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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 ) );
break;
2024-12-03 12:19:39 -08:00
case CT_Operator_Cast:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "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\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
break;
2024-12-03 12:19:39 -08:00
case CT_Operator_Cast_Fwd:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Parameters:
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 );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Specifiers:
{
string_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
2024-12-04 08:30:54 -08:00
string_append_strc( result, txt("\n\tArrSpecs: ") );
s32 idx = 0;
s32 left = self->NumEntries;
while ( left-- )
{
StrC spec = spec_to_str( self->ArrSpecs[idx] );
string_append_fmt( result, "%.*s, ", spec.Len, spec.Ptr );
idx++;
}
string_append_fmt( result, "\n\tNextSpecs: %S", self->NextSpecs ? code_debug_str(self->NextSpecs) : "Null" );
}
break;
2024-12-03 12:19:39 -08:00
case CT_Template:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Typedef:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
break;
2024-12-03 12:19:39 -08:00
case CT_Typename:
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Union:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Using:
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
2024-12-03 12:19:39 -08:00
case CT_Variable:
2024-12-03 12:19:39 -08:00
if ( self->Parent && self->Parent->Type == CT_Variable )
{
// Its a NextVar
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" );
break;
}
if ( self->Prev )
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
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" );
break;
}
2024-12-01 20:35:58 -08:00
return * result;
}
Code code_duplicate(Code self)
{
Code result = make_code();
void* mem_result = rcast(void*, cast(AST*, result));
void* mem_self = rcast(void*, cast(AST*, self));
mem_copy( mem_result, mem_self, sizeof( AST ) );
result->Parent = { nullptr };
return result;
}
String code_to_string(Code self)
{
String result = string_make_strc( GlobalAllocator, txt("") );
code_to_string_ptr( self, & result );
return result;
}
void code_to_string_ptr( Code self, String* result )
{
2024-12-02 00:18:52 -08:00
GEN_ASSERT(self != nullptr);
local_persist thread_local
char SerializationLevel = 0;
2024-12-02 00:18:52 -08:00
switch ( self->Type )
{
2024-12-03 12:19:39 -08:00
case CT_Invalid:
#ifdef GEN_DONT_ALLOW_INVALID_CODE
log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->code_debug_str() : Name );
#else
2024-12-04 08:30:54 -08:00
string_append_fmt( result, "Invalid Code!" );
#endif
break;
2024-12-03 12:19:39 -08:00
case CT_NewLine:
string_append_strc( result, txt("\n"));
break;
2024-12-03 12:19:39 -08:00
case CT_Untyped:
case CT_Execution:
case CT_Comment:
case CT_PlatformAttributes:
string_append_strc( result, self->Content );
break;
2024-12-03 12:19:39 -08:00
case CT_Access_Private:
case CT_Access_Protected:
case CT_Access_Public:
string_append_strc( result, self->Name );
break;
2024-12-03 12:19:39 -08:00
case CT_Class:
class_to_string_def(cast(CodeClass, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Class_Fwd:
class_to_string_fwd(cast(CodeClass, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Constructor:
constructor_to_string_def(cast(CodeConstructor, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Constructor_Fwd:
constructor_to_string_fwd(cast(CodeConstructor, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Destructor:
destructor_to_string_def(cast(CodeDestructor, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Destructor_Fwd:
destructor_to_string_fwd(cast(CodeDestructor, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Enum:
enum_to_string_def(cast(CodeEnum, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Enum_Fwd:
enum_to_string_fwd(cast(CodeEnum, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Enum_Class:
enum_to_string_class_def(cast(CodeEnum, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Enum_Class_Fwd:
enum_to_string_class_fwd(cast(CodeEnum, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Export_Body:
body_to_string_export(cast(CodeBody, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Extern_Linkage:
extern_to_string(cast(CodeExtern, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Friend:
friend_to_string_ref(cast(CodeFriend, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Function:
fn_to_string_def(cast(CodeFn, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Function_Fwd:
fn_to_string_fwd(cast(CodeFn, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Module:
module_to_string_ref(cast(CodeModule, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Namespace:
namespace_to_string_ref(cast(CodeNS, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Operator:
case CT_Operator_Member:
code_op_to_string_def(cast(CodeOperator, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Operator_Fwd:
case CT_Operator_Member_Fwd:
code_op_to_string_fwd(cast(CodeOperator, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Operator_Cast:
opcast_to_string_def(cast(CodeOpCast, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Operator_Cast_Fwd:
opcast_to_string_fwd(cast(CodeOpCast, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Parameters:
params_to_string_ref(cast(CodeParam, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_Define:
define_to_string_ref(cast(CodeDefine, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_If:
preprocess_to_string_if(cast(CodePreprocessCond, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_IfDef:
preprocess_to_string_ifdef(cast(CodePreprocessCond, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_IfNotDef:
preprocess_to_string_ifndef(cast(CodePreprocessCond, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_Include:
include_to_string_ref(cast(CodeInclude, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_ElIf:
preprocess_to_string_elif(cast(CodePreprocessCond, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_Else:
preprocess_to_string_else(cast(CodePreprocessCond, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_EndIf:
preprocess_to_string_endif(cast(CodePreprocessCond, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Preprocess_Pragma:
pragma_to_string_ref(cast(CodePragma, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Specifiers:
specifiers_to_string_ref(cast(CodeSpecifiers, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Struct:
struct_to_string_def(cast(CodeStruct, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Struct_Fwd:
struct_to_string_fwd(cast(CodeStruct, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Template:
template_to_string_ref(cast(CodeTemplate, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Typedef:
typedef_to_string_ref(cast(CodeTypedef, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Typename:
typename_to_string_ref(cast(CodeTypename, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Union:
union_to_string_def( cast(CodeUnion, self), result );
break;
case CT_Union_Fwd:
union_to_string_fwd( cast(CodeUnion, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Using:
using_to_string_ref(cast(CodeUsing, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Using_Namespace:
using_to_string_ns(cast(CodeUsing, self), result );
break;
2024-12-03 12:19:39 -08:00
case CT_Variable:
var_to_string_ref(cast(CodeVar, self), result );
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:
body_to_string_ref( cast(CodeBody, self), result );
break;
}
}
bool code_is_equal( Code self, Code other )
{
/*
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 )
{
log_fmt( "AST::is_equal: other is null\nAST: %S", code_debug_str(self) );
return false;
}
2024-12-01 21:34:40 -08:00
if ( self->Type != other->Type )
{
log_fmt("AST::is_equal: Type check failure with other\nAST: %S\nOther: %S"
, code_debug_str(self)
,code_debug_str(other)
);
return false;
}
2024-12-01 21:34:40 -08:00
switch ( self->Type )
{
#define check_member_val( val ) \
2024-12-01 21:34:40 -08:00
if ( self->val != other->val ) \
{ \
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) \
); \
\
return false; \
}
#define check_member_str( str ) \
2024-12-01 21:34:40 -08:00
if ( self->str != other->str ) \
{ \
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) \
); \
\
return false; \
}
#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) \
); \
\
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) \
); \
}
#define check_member_ast( ast ) \
2024-12-01 21:34:40 -08:00
if ( self->ast ) \
{ \
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) \
); \
\
return false; \
} \
\
2024-12-07 14:17:02 -08:00
if ( ! code_is_equal(self->ast, other->ast ) ) \
{ \
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) \
); \
\
return false; \
} \
}
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:
return true;
// Comments are not validated.
2024-12-03 12:19:39 -08:00
case CT_Comment:
return true;
2024-12-03 12:19:39 -08:00
case CT_Execution:
case CT_PlatformAttributes:
case CT_Untyped:
{
check_member_content( Content );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Class_Fwd:
case CT_Struct_Fwd:
{
check_member_str( Name );
check_member_ast( ParentType );
check_member_val( ParentAccess );
check_member_ast( Attributes );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Class:
case CT_Struct:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( ParentType );
check_member_val( ParentAccess );
check_member_ast( Attributes );
check_member_ast( Body );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Constructor:
{
check_member_ast( InitializerList );
check_member_ast( Params );
check_member_ast( Body );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Constructor_Fwd:
{
check_member_ast( InitializerList );
check_member_ast( Params );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Destructor:
{
check_member_ast( Specs );
check_member_ast( Body );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Destructor_Fwd:
{
check_member_ast( Specs );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Enum:
case CT_Enum_Class:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( Attributes );
check_member_ast( UnderlyingType );
check_member_ast( Body );
check_member_ast( UnderlyingTypeMacro );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Enum_Fwd:
case CT_Enum_Class_Fwd:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( Attributes );
check_member_ast( UnderlyingType );
check_member_ast( UnderlyingTypeMacro );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Extern_Linkage:
{
check_member_str( Name );
check_member_ast( Body );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Friend:
{
check_member_str( Name );
check_member_ast( Declaration );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Function:
{
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 );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Function_Fwd:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( ReturnType );
check_member_ast( Attributes );
check_member_ast( Specs );
check_member_ast( Params );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Module:
{
check_member_val( ModuleFlags );
check_member_str( Name );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Namespace:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( Body );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Operator:
case CT_Operator_Member:
{
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 );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Operator_Fwd:
case CT_Operator_Member_Fwd:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( ReturnType );
check_member_ast( Attributes );
check_member_ast( Specs );
check_member_ast( Params );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Operator_Cast:
{
check_member_str( Name );
check_member_ast( Specs );
check_member_ast( ValueType );
check_member_ast( Body );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Operator_Cast_Fwd:
{
check_member_str( Name );
check_member_ast( Specs );
check_member_ast( ValueType );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Parameters:
{
2024-12-01 21:34:40 -08:00
if ( self->NumEntries > 1 )
{
Code curr = self;
Code curr_other = other;
while ( curr != nullptr )
{
if ( curr )
{
if ( curr_other == nullptr )
{
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)
);
return false;
}
if ( curr->Name != curr_other->Name )
{
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"
, code_debug_str(self)
, code_debug_str(other)
, code_debug_str(curr)
, code_debug_str(curr_other)
);
return false;
}
if ( curr->ValueType && ! code_is_equal(curr->ValueType, curr_other->ValueType) )
{
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"
, code_debug_str(self)
, code_debug_str(other)
, code_debug_str(curr)
, code_debug_str(curr_other)
);
return false;
}
if ( curr->Value && ! code_is_equal(curr->Value, curr_other->Value) )
{
log_fmt( "\nAST::is_equal: Failed for parameter value check\n"
"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(curr)
, code_debug_str(curr_other)
);
Work on AST::is_equal. The NumEntries checks need to be deferred until the end as a final unresolved check on valdiation. As if there really is a discrepancy of entires it should be revealed by the specific entry failing. Right now the latest failure with the single header check involves a define directive specifically the define does omit whitespace properly and so the check interprets the different cached content to be non-equivalent. This will happen with all unvalidated aspects of the AST ( expressions, function bodies, etc ) There are two ways to resolve, either make an AST that can tokenize all items (not realistic), or I need to strip non-syntax important whitespace and then cache the string. This would mean removing everything but a single whitespace for all content within a content string. Otherwise, I would have to somehow make sure the content of the string has the exact formatting between both files for the definitions that matter. AST types with this issue: * Define Directive * Pragma Directive * Comment * Execution * Platform Attributes * Untyped Comments can technically be left unverified as they do not matter semantically. When the serialization is first emitted, the content these strings should for the most part be equivalent. However I do see some possible failures for that if a different style of bracket placment is used (between the serialization). At that point what I could do is just leave those unverified and just emit the content to the user as warning that the ast and the other compared could not be verified. Those technically can be handled on a per-eye basis, and worst case the tests with the compiler will in the determine if any critical defintions are missing for the user.
2023-08-25 15:40:13 -07:00
return false;
}
}
curr = curr->Next;
curr_other = curr_other->Next;
}
Work on AST::is_equal. The NumEntries checks need to be deferred until the end as a final unresolved check on valdiation. As if there really is a discrepancy of entires it should be revealed by the specific entry failing. Right now the latest failure with the single header check involves a define directive specifically the define does omit whitespace properly and so the check interprets the different cached content to be non-equivalent. This will happen with all unvalidated aspects of the AST ( expressions, function bodies, etc ) There are two ways to resolve, either make an AST that can tokenize all items (not realistic), or I need to strip non-syntax important whitespace and then cache the string. This would mean removing everything but a single whitespace for all content within a content string. Otherwise, I would have to somehow make sure the content of the string has the exact formatting between both files for the definitions that matter. AST types with this issue: * Define Directive * Pragma Directive * Comment * Execution * Platform Attributes * Untyped Comments can technically be left unverified as they do not matter semantically. When the serialization is first emitted, the content these strings should for the most part be equivalent. However I do see some possible failures for that if a different style of bracket placment is used (between the serialization). At that point what I could do is just leave those unverified and just emit the content to the user as warning that the ast and the other compared could not be verified. Those technically can be handled on a per-eye basis, and worst case the tests with the compiler will in the determine if any critical defintions are missing for the user.
2023-08-25 15:40:13 -07:00
check_member_val( NumEntries );
return true;
}
check_member_str( Name );
check_member_ast( ValueType );
check_member_ast( Value );
check_member_ast( ArrExpr );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Preprocess_Define:
{
check_member_str( Name );
check_member_content( Content );
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:
{
check_member_content( Content );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Preprocess_Include:
case CT_Preprocess_Pragma:
{
check_member_content( Content );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Specifiers:
{
check_member_val( NumEntries );
check_member_str( Name );
2024-12-01 21:34:40 -08:00
for ( s32 idx = 0; idx < self->NumEntries; ++idx )
{
check_member_val( ArrSpecs[ idx ] );
}
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Template:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( Params );
check_member_ast( Declaration );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Typedef:
{
check_member_val( IsFunction );
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( Specs );
check_member_ast( UnderlyingType );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Typename:
{
check_member_val( IsParamPack );
check_member_str( Name );
check_member_ast( Specs );
check_member_ast( ArrExpr );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Union:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( Attributes );
check_member_ast( Body );
return true;
}
2024-12-07 14:17:02 -08:00
case CT_Union_Fwd:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( Attributes );
}
2024-12-03 12:19:39 -08:00
case CT_Using:
case CT_Using_Namespace:
{
check_member_val( ModuleFlags );
check_member_str( Name );
check_member_ast( UnderlyingType );
check_member_ast( Attributes );
return true;
}
2024-12-03 12:19:39 -08:00
case CT_Variable:
{
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 );
check_member_ast( NextVar );
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:
{
check_member_ast( Front );
check_member_ast( Back );
Code curr = self->Front;
Code curr_other = other->Front;
while ( curr != nullptr )
{
if ( curr_other == nullptr )
{
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)
);
return false;
}
if ( ! code_is_equal( curr, curr_other ) )
{
log_fmt( "\nAST::is_equal: Failed for body\n"
"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(curr)
, code_debug_str(curr_other)
);
return false;
}
curr = curr->Next;
curr_other = curr_other->Next;
}
Work on AST::is_equal. The NumEntries checks need to be deferred until the end as a final unresolved check on valdiation. As if there really is a discrepancy of entires it should be revealed by the specific entry failing. Right now the latest failure with the single header check involves a define directive specifically the define does omit whitespace properly and so the check interprets the different cached content to be non-equivalent. This will happen with all unvalidated aspects of the AST ( expressions, function bodies, etc ) There are two ways to resolve, either make an AST that can tokenize all items (not realistic), or I need to strip non-syntax important whitespace and then cache the string. This would mean removing everything but a single whitespace for all content within a content string. Otherwise, I would have to somehow make sure the content of the string has the exact formatting between both files for the definitions that matter. AST types with this issue: * Define Directive * Pragma Directive * Comment * Execution * Platform Attributes * Untyped Comments can technically be left unverified as they do not matter semantically. When the serialization is first emitted, the content these strings should for the most part be equivalent. However I do see some possible failures for that if a different style of bracket placment is used (between the serialization). At that point what I could do is just leave those unverified and just emit the content to the user as warning that the ast and the other compared could not be verified. Those technically can be handled on a per-eye basis, and worst case the tests with the compiler will in the determine if any critical defintions are missing for the user.
2023-08-25 15:40:13 -07:00
check_member_val( NumEntries );
return true;
}
#undef check_member_val
#undef check_member_str
#undef check_member_ast
}
return true;
}
bool code_validate_body(Code self)
{
#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; \
} \
} \
} \
while (0);
2024-12-02 00:18:52 -08:00
switch ( self->Type )
{
2024-12-03 12:19:39 -08:00
case CT_Class_Body:
{
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
}
break;
2024-12-03 12:19:39 -08:00
case CT_Enum_Body:
{
CodeBody body = cast(CodeBody, self);
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
{
2024-12-03 12:19:39 -08:00
if ( entry->Type != CT_Untyped )
{
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", GEN_NS code_debug_str(entry) );
return false;
}
}
}
break;
2024-12-03 12:19:39 -08:00
case CT_Export_Body:
{
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
}
break;
2024-12-03 12:19:39 -08:00
case CT_Extern_Linkage:
{
CheckEntries( GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES );
}
break;
2024-12-03 12:19:39 -08:00
case CT_Function_Body:
{
CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES );
}
break;
2024-12-03 12:19:39 -08:00
case CT_Global_Body:
{
CodeBody body = cast(CodeBody, self);
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
{
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:
log_failure("AST::validate_body: Invalid entry in body %s", GEN_NS code_debug_str(entry));
return false;
}
}
}
break;
2024-12-03 12:19:39 -08:00
case CT_Namespace_Body:
{
CheckEntries( GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES );
}
break;
2024-12-03 12:19:39 -08:00
case CT_Struct_Body:
{
CheckEntries( GEN_AST_BODY_STRUCT_UNALLOWED_TYPES );
}
break;
2024-12-03 12:19:39 -08:00
case CT_Union_Body:
{
CodeBody body = cast(CodeBody, self);
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
{
2024-12-03 12:19:39 -08:00
if ( entry->Type != CT_Untyped )
{
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", GEN_NS code_debug_str(entry) );
return false;
}
}
}
break;
default:
log_failure( "AST::validate_body: Invalid this AST does not have a body %s", code_debug_str(self) );
return false;
}
return false;
#undef CheckEntries
}