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
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
Code Code::Global;
|
|
|
|
Code Code::Invalid;
|
|
|
|
|
2023-08-23 18:19:31 -07:00
|
|
|
char const* AST::debug_str()
|
|
|
|
{
|
|
|
|
if ( Parent )
|
|
|
|
{
|
|
|
|
String
|
|
|
|
result = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
|
|
|
result.append_fmt(
|
2023-08-26 08:55:05 -07:00
|
|
|
"\n\tType : %s"
|
|
|
|
"\n\tParent : %s %s"
|
|
|
|
"\n\tName : %s"
|
2023-08-23 18:19:31 -07:00
|
|
|
, type_str()
|
|
|
|
, Parent->type_str()
|
|
|
|
, Parent->Name, Name ? Name : ""
|
|
|
|
);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
String
|
|
|
|
result = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
|
|
|
result.append_fmt(
|
2023-08-26 08:55:05 -07:00
|
|
|
"\n\tType : %s"
|
|
|
|
"\n\tName : %s"
|
2023-08-23 18:19:31 -07:00
|
|
|
, type_str()
|
|
|
|
, Name ? Name : ""
|
|
|
|
);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
AST* AST::duplicate()
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
2023-07-26 11:21:20 -07:00
|
|
|
AST* result = make_code().ast;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-07-26 11:21:20 -07:00
|
|
|
mem_copy( result, this, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
String AST::to_string()
|
|
|
|
{
|
|
|
|
local_persist thread_local
|
|
|
|
char SerializationLevel = 0;
|
|
|
|
|
|
|
|
// TODO : Need to refactor so that intermeidate strings are freed conviently.
|
|
|
|
String result = String::make( GlobalAllocator, "" );
|
|
|
|
|
|
|
|
switch ( Type )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
case Invalid:
|
2023-08-08 19:14:58 -07:00
|
|
|
log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->debug_str() : Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
2023-08-04 13:12:13 -07:00
|
|
|
case NewLine:
|
|
|
|
result.append("\n");
|
|
|
|
break;
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
case Untyped:
|
|
|
|
case Execution:
|
|
|
|
case Comment:
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append( Content );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Access_Private:
|
|
|
|
case Access_Protected:
|
|
|
|
case Access_Public:
|
|
|
|
result.append( Name );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PlatformAttributes:
|
|
|
|
result.append( Content );
|
|
|
|
|
|
|
|
case Class:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes || ParentType )
|
|
|
|
{
|
|
|
|
result.append( "class " );
|
|
|
|
|
|
|
|
if ( Attributes )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ParentType )
|
|
|
|
{
|
|
|
|
char const* access_level = to_str( ParentAccess );
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S : %s %S", Name, access_level, ParentType );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
CodeType interface = Next->cast< CodeType >();
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( interface )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append( "\n" );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
while ( interface )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( ", %S", interface.to_string() );
|
|
|
|
interface = interface->Next ? interface->Next->cast< CodeType >() : Code { nullptr };
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-08-08 19:14:58 -07:00
|
|
|
|
|
|
|
result.append_fmt( "\n{\n%S\n}", Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S \n{\n%S\n}", Name, Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "class %S\n{\n%S\n}", Name, Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append(";\n");
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Class_Fwd:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "class %S %S", Attributes->to_string(), Name );
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
else result.append_fmt( "class %S", Name );
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
// Check if it can have an end-statement
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-22 21:05:58 -07:00
|
|
|
{
|
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt( "; // %S\n", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append(";\n");
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-08-07 00:10:45 -07:00
|
|
|
case Constructor:
|
|
|
|
{
|
|
|
|
result.append( Parent->Name );
|
|
|
|
|
|
|
|
if ( Params )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "( %S )", Params->to_string() );
|
2023-08-07 00:10:45 -07:00
|
|
|
else
|
|
|
|
result.append( "(void)" );
|
|
|
|
|
|
|
|
if ( InitializerList )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( " : %S", InitializerList->to_string() );
|
2023-08-07 00:10:45 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "\n{\n%S\n}\n", Body->to_string() );
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Constructor_Fwd:
|
|
|
|
{
|
|
|
|
result.append( Parent->Name );
|
|
|
|
|
|
|
|
if ( Params )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "( %S )", Params->to_string() );
|
2023-08-07 00:10:45 -07:00
|
|
|
else
|
2023-08-22 21:05:58 -07:00
|
|
|
{
|
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt( "(void); // %S\n", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append( "(void);\n" );
|
|
|
|
}
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Destructor:
|
|
|
|
{
|
|
|
|
if ( Specs )
|
|
|
|
{
|
|
|
|
CodeSpecifiers specs = Specs->cast<CodeSpecifiers>();
|
|
|
|
|
|
|
|
if ( specs.has( ESpecifier::Virtual ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "virtual ~%S()", Parent->Name );
|
2023-08-07 00:10:45 -07:00
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "~%S()", Parent->Name );
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "~%S()", Parent->Name );
|
2023-08-07 00:10:45 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "\n{\n%S\n}\n", Body->to_string() );
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Destructor_Fwd:
|
|
|
|
{
|
|
|
|
if ( Specs )
|
|
|
|
{
|
|
|
|
CodeSpecifiers specs = Specs->cast<CodeSpecifiers>();
|
|
|
|
|
|
|
|
if ( specs.has( ESpecifier::Virtual ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "virtual ~%S();\n", Parent->Name );
|
2023-08-07 00:10:45 -07:00
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "~%S()", Parent->Name );
|
2023-08-07 00:10:45 -07:00
|
|
|
|
|
|
|
if ( specs.has( ESpecifier::Pure ) )
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append( " = 0;" );
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
else
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append_fmt( "~%S();", Parent->Name );
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt( " %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append("\n");
|
2023-08-07 00:10:45 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
case Enum:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes || UnderlyingType )
|
|
|
|
{
|
|
|
|
result.append( "enum " );
|
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( UnderlyingType )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S : %S\n{\n%S\n}"
|
2023-07-24 14:45:27 -07:00
|
|
|
, Name
|
|
|
|
, UnderlyingType->to_string()
|
|
|
|
, Body->to_string()
|
|
|
|
);
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
else result.append_fmt( "%S\n{\n%S\n}", Name, Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-08-08 19:14:58 -07:00
|
|
|
else result.append_fmt( "enum %S\n{\n%S\n}", Name, Body->to_string() );
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append(";\n");
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Fwd:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "enum %S : %S", Name, UnderlyingType->to_string() );
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-22 21:05:58 -07:00
|
|
|
{
|
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt("; %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append(";\n");
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Class:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes || UnderlyingType )
|
|
|
|
{
|
|
|
|
result.append( "enum class " );
|
|
|
|
|
|
|
|
if ( Attributes )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( UnderlyingType )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S : %S\n{\n%S\n}", Name, UnderlyingType->to_string(), Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S\n{\n%S\n}", Name, Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "enum class %S\n{\n%S\n}", Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append(";\n");
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Class_Fwd:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
result.append( "enum class " );
|
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S : %S", Name, UnderlyingType->to_string() );
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-22 21:05:58 -07:00
|
|
|
{
|
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt("; %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append(";\n");
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Export_Body:
|
|
|
|
{
|
|
|
|
result.append_fmt( "export\n{\n" );
|
|
|
|
|
|
|
|
Code curr = { this };
|
|
|
|
s32 left = NumEntries;
|
|
|
|
while ( left-- )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S", curr.to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
++curr;
|
|
|
|
}
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "};\n" );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Extern_Linkage:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "extern \"%S\"\n{\n%S\n}\n", Name, Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Friend:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "friend %S", Declaration->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( result[ result.length() -1 ] != ';' )
|
2023-08-22 21:05:58 -07:00
|
|
|
{
|
|
|
|
result.append( ";" );
|
|
|
|
}
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt(" %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append("\n");
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Function:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Specs )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S", Specs->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( ReturnType )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S %S(", ReturnType->to_string(), Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S(", Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Params )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S)", Params->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
else
|
2023-08-23 15:16:45 -07:00
|
|
|
result.append( ")" );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Specs )
|
|
|
|
{
|
2023-08-06 14:19:57 -07:00
|
|
|
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( ESpecifier::is_trailing( spec ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
{
|
|
|
|
StrC spec_str = ESpecifier::to_str( spec );
|
|
|
|
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "\n{\n%S\n}\n", Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function_Fwd:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Specs )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S", Specs->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( ReturnType )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S %S(", ReturnType->to_string(), Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S(", Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Params )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S)", Params->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
else
|
2023-08-23 15:16:45 -07:00
|
|
|
result.append( ")" );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Specs )
|
|
|
|
{
|
2023-08-06 14:19:57 -07:00
|
|
|
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( ESpecifier::is_trailing( spec ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
{
|
|
|
|
StrC spec_str = ESpecifier::to_str( spec );
|
|
|
|
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt( "; %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append( ";\n" );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Module:
|
|
|
|
if (((u32(ModuleFlag::Export) & u32(ModuleFlags)) == u32(ModuleFlag::Export)))
|
|
|
|
result.append("export ");
|
|
|
|
|
|
|
|
if (((u32(ModuleFlag::Import) & u32(ModuleFlags)) == u32(ModuleFlag::Import)))
|
|
|
|
result.append("import ");
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S;\n", Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Namespace:
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "namespace %S\n{\n%S\n}\n", Name , Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator:
|
|
|
|
case Operator_Member:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S\n", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( ReturnType )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S %S (", ReturnType->to_string(), Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Params )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S)", Params->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
else
|
2023-08-23 15:16:45 -07:00
|
|
|
result.append( ")" );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Specs )
|
|
|
|
{
|
2023-08-06 14:19:57 -07:00
|
|
|
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( ESpecifier::is_trailing( spec ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
{
|
|
|
|
StrC spec_str = ESpecifier::to_str( spec );
|
|
|
|
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "\n{\n%S\n}\n"
|
2023-07-24 14:45:27 -07:00
|
|
|
, Body->to_string()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator_Fwd:
|
|
|
|
case Operator_Member_Fwd:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S\n", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Specs )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S\n", Specs->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S %S (", ReturnType->to_string(), Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Params )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S)", Params->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
else
|
2023-08-23 15:16:45 -07:00
|
|
|
result.append_fmt( ")" );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Specs )
|
|
|
|
{
|
2023-08-06 14:19:57 -07:00
|
|
|
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( ESpecifier::is_trailing( spec ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
{
|
|
|
|
StrC spec_str = ESpecifier::to_str( spec );
|
|
|
|
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt( "; %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append( ";\n" );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator_Cast:
|
|
|
|
{
|
|
|
|
if ( Specs )
|
|
|
|
{
|
2023-08-22 21:05:58 -07:00
|
|
|
// TODO : Add support for specifies before the operator keyword
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-02 09:39:35 -07:00
|
|
|
if ( Name && Name.length() )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%Soperator %S()", Name, ValueType->to_string() );
|
2023-08-02 09:39:35 -07:00
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "operator %S()", ValueType->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-06 14:19:57 -07:00
|
|
|
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( ESpecifier::is_trailing( spec ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
{
|
|
|
|
StrC spec_str = ESpecifier::to_str( spec );
|
|
|
|
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "\n{\n%S\n}\n", Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-08-02 09:39:35 -07:00
|
|
|
if ( Name && Name.length() )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt("%Soperator %S()\n{\n%S\n}\n", Name, ValueType->to_string(), Body->to_string() );
|
2023-08-02 09:39:35 -07:00
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt("operator %S()\n{\n%S\n}\n", ValueType->to_string(), Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator_Cast_Fwd:
|
|
|
|
if ( Specs )
|
|
|
|
{
|
2023-08-22 21:05:58 -07:00
|
|
|
// TODO : Add support for specifies before the operator keyword
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "operator %S()", ValueType->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-06 14:19:57 -07:00
|
|
|
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( ESpecifier::is_trailing( spec ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
{
|
|
|
|
StrC spec_str = ESpecifier::to_str( spec );
|
|
|
|
result.append_fmt( " %*s", spec_str.Len, spec_str.Ptr );
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt( "; %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append( ";\n" );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt("operator %S(); %S", ValueType->to_string() );
|
|
|
|
else
|
|
|
|
result.append_fmt("operator %S();\n", ValueType->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Parameters:
|
|
|
|
{
|
2023-08-01 13:07:47 -07:00
|
|
|
if ( ValueType == nullptr )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S", Name );
|
2023-08-01 13:07:47 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( Name )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S %S", ValueType->to_string(), Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S", ValueType->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Value )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "= %S", Value->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( NumEntries - 1 > 0)
|
|
|
|
{
|
|
|
|
for ( CodeParam param : CodeParam { (AST_Param*) Next } )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( ", %S", param.to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2023-07-29 22:21:04 -07:00
|
|
|
case Preprocess_Define:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "#define %S %S\n", Name, Content );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_If:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "#if %S\n", Content );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_IfDef:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "#ifdef %S\n", Content );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_IfNotDef:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "#ifndef %S\n", Content );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_Include:
|
2023-08-23 10:17:22 -07:00
|
|
|
result.append_fmt( "#include %S\n", Content );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_ElIf:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "#elif %S\n", Content );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_Else:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "#else\n" );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_EndIf:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "#endif\n" );
|
2023-07-29 22:21:04 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Preprocess_Pragma:
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "#pragma %S\n", Content );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Specifiers:
|
|
|
|
{
|
|
|
|
s32 idx = 0;
|
|
|
|
s32 left = NumEntries;
|
|
|
|
while ( left-- )
|
|
|
|
{
|
2023-08-06 14:19:57 -07:00
|
|
|
if ( ESpecifier::is_trailing( ArrSpecs[idx]) && ArrSpecs[idx] != ESpecifier::Const )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
StrC spec = ESpecifier::to_str( ArrSpecs[idx] );
|
|
|
|
result.append_fmt( "%.*s ", spec.Len, spec.Ptr );
|
2023-07-24 14:45:27 -07:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Name == nullptr)
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "struct\n{\n%S\n};\n", Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Attributes || ParentType )
|
|
|
|
{
|
|
|
|
result.append( "struct " );
|
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( ParentType )
|
|
|
|
{
|
|
|
|
char const* access_level = to_str( ParentAccess );
|
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S : %s %S", Name, access_level, ParentType );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
CodeType interface = Next->cast< CodeType >();
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( interface )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append( "\n" );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
while ( interface )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( ", %S", interface.to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
interface = interface->Next ? interface->Next->cast< CodeType >() : Code { nullptr };
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-08-08 19:14:58 -07:00
|
|
|
|
|
|
|
result.append_fmt( "\n{\n%S\n}", Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( Name )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S \n{\n%S\n}", Name, Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "struct %S\n{\n%S\n}", Name, Body->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-22 21:05:58 -07:00
|
|
|
{
|
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt("; %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append(";\n");
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct_Fwd:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "struct %S %S", Attributes->to_string(), Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
else result.append_fmt( "struct %S", Name );
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-22 21:05:58 -07:00
|
|
|
{
|
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt("; %S", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append(";\n");
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Template:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "template< %S >\n%S", Params->to_string(), Declaration->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Typedef:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
result.append( "typedef ");
|
|
|
|
|
2023-09-04 22:44:04 -07:00
|
|
|
// Determines if the typedef is a function typename
|
|
|
|
if ( UnderlyingType->ReturnType )
|
2023-08-07 17:16:04 -07:00
|
|
|
result.append( UnderlyingType->to_string() );
|
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S %S", UnderlyingType->to_string(), Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( UnderlyingType->Type == Typename && UnderlyingType->ArrExpr )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "[%S];", UnderlyingType->ArrExpr->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append( ";" );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt(" %S", InlineCmt->Content);
|
|
|
|
else
|
|
|
|
result.append("\n");
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Typename:
|
|
|
|
{
|
2023-09-04 22:44:04 -07:00
|
|
|
#if GEN_USE_NEW_TYPENAME_PARSING
|
|
|
|
if ( ReturnType && Params )
|
2023-07-24 14:45:27 -07:00
|
|
|
{
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-09-04 22:44:04 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( Specs )
|
|
|
|
result.append_fmt( "%S ( %S ) ( %S ) %S", ReturnType->to_string(), Name, Params->to_string(), Specs->to_string() );
|
|
|
|
else
|
|
|
|
result.append_fmt( "%S ( %S ) ( %S )", ReturnType->to_string(), Name, Params->to_string() );
|
|
|
|
}
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-09-04 22:44:04 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ( ReturnType && Params )
|
|
|
|
{
|
|
|
|
if ( Attributes )
|
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
else
|
2023-09-04 22:44:04 -07:00
|
|
|
{
|
|
|
|
if ( Specs )
|
|
|
|
result.append_fmt( "%S %S ( %S ) %S", ReturnType->to_string(), Name, Params->to_string(), Specs->to_string() );
|
|
|
|
else
|
|
|
|
result.append_fmt( "%S %S ( %S )", ReturnType->to_string(), Name, Params->to_string() );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
2023-09-04 22:44:04 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( Attributes )
|
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
|
|
|
|
|
|
|
if ( Specs )
|
|
|
|
result.append_fmt( "%S %S", Name, Specs->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
else
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S", Name );
|
2023-08-23 15:16:45 -07:00
|
|
|
|
2023-08-23 08:05:49 -07:00
|
|
|
if ( IsParamPack )
|
|
|
|
result.append("...");
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Union:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
result.append( "union " );
|
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Name )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S\n{\n%S\n}"
|
2023-07-24 14:45:27 -07:00
|
|
|
, Name
|
|
|
|
, Body->to_string()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Anonymous union
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "\n{\n%S\n}"
|
2023-07-24 14:45:27 -07:00
|
|
|
, Body->to_string()
|
|
|
|
);
|
|
|
|
}
|
2023-07-31 21:42:08 -07:00
|
|
|
|
2023-08-01 17:56:00 -07:00
|
|
|
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append(";\n");
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Using:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Attributes->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( UnderlyingType )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "using %S = %S", Name, UnderlyingType->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( UnderlyingType->ArrExpr )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "[%S]", UnderlyingType->ArrExpr->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append( ";" );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
else
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append_fmt( "using %S;", Name );
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt(" %S\n", InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append("\n");
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Using_Namespace:
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt( "using namespace $S; %S", Name, InlineCmt->Content );
|
|
|
|
else
|
|
|
|
result.append_fmt( "using namespace %s;\n", Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Variable:
|
|
|
|
{
|
2023-07-29 02:52:06 -07:00
|
|
|
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
|
|
|
result.append( "export " );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Attributes || Specs )
|
|
|
|
{
|
|
|
|
if ( Attributes )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S ", Specs->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( Specs )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S\n", Specs->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S %S", ValueType->to_string(), Name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
if ( ValueType->ArrExpr )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "[%S]", ValueType->ArrExpr->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-01 02:17:24 -07:00
|
|
|
if ( BitfieldSize )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( " : %S", BitfieldSize->to_string() );
|
2023-08-01 02:17:24 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( Value )
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( " = %S", Value->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt("; %S", InlineCmt->Content);
|
|
|
|
else
|
|
|
|
result.append( ";\n" );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-08-01 02:17:24 -07:00
|
|
|
if ( BitfieldSize )
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append_fmt( "%S %S : %S;", ValueType->to_string(), Name, BitfieldSize->to_string() );
|
2023-08-01 02:17:24 -07:00
|
|
|
|
|
|
|
else if ( UnderlyingType->ArrExpr )
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append_fmt( "%S %S[%S];", UnderlyingType->to_string(), Name, UnderlyingType->ArrExpr->to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
else
|
2023-08-22 21:05:58 -07:00
|
|
|
result.append_fmt( "%S %S;", UnderlyingType->to_string(), Name );
|
2023-08-22 23:17:47 -07:00
|
|
|
|
2023-08-22 21:05:58 -07:00
|
|
|
if ( InlineCmt )
|
|
|
|
result.append_fmt(" %S", InlineCmt->Content);
|
|
|
|
else
|
|
|
|
result.append("\n");
|
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:
|
|
|
|
{
|
|
|
|
Code curr = Front->cast<Code>();
|
|
|
|
s32 left = NumEntries;
|
|
|
|
while ( left -- )
|
|
|
|
{
|
2023-08-08 19:14:58 -07:00
|
|
|
result.append_fmt( "%S", curr.to_string() );
|
2023-07-24 14:45:27 -07:00
|
|
|
++curr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AST::is_equal( AST* other )
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
log_fmt( "AST::is_equal: other is null\nAST: %S", debug_str() );
|
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
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
if ( 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"
|
|
|
|
, debug_str()
|
|
|
|
, other->debug_str()
|
|
|
|
);
|
|
|
|
|
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
|
|
|
|
|
|
|
switch ( Type )
|
|
|
|
{
|
2023-08-22 13:01:50 -07:00
|
|
|
using namespace ECode;
|
|
|
|
|
2023-09-03 17:29:45 -07:00
|
|
|
#define check_member_val( val ) \
|
|
|
|
if ( val != other->val ) \
|
|
|
|
{ \
|
|
|
|
log_fmt("\nAST::is_equal: Member - " #val " failed\n" \
|
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
|
|
|
, debug_str() \
|
|
|
|
, other->debug_str() \
|
|
|
|
); \
|
|
|
|
\
|
|
|
|
return false; \
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
|
|
|
|
2023-09-03 17:29:45 -07:00
|
|
|
#define check_member_str( str ) \
|
|
|
|
if ( str != other->str ) \
|
|
|
|
{ \
|
|
|
|
log_fmt("\nAST::is_equal: Member string - "#str " failed\n" \
|
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
|
|
|
, debug_str() \
|
|
|
|
, other->debug_str() \
|
|
|
|
); \
|
|
|
|
\
|
|
|
|
return false; \
|
2023-08-23 15:16:45 -07:00
|
|
|
}
|
|
|
|
|
2023-09-03 17:29:45 -07:00
|
|
|
#define check_member_content( content ) \
|
|
|
|
if ( content != other->content ) \
|
|
|
|
{ \
|
|
|
|
log_fmt("\nAST::is_equal: Member content - "#content " failed\n" \
|
2023-08-25 15:57:53 -07:00
|
|
|
"AST : %S\n" \
|
|
|
|
"Other: %S\n" \
|
|
|
|
, debug_str() \
|
|
|
|
, other->debug_str() \
|
|
|
|
); \
|
|
|
|
\
|
|
|
|
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" \
|
2023-09-03 17:29:45 -07:00
|
|
|
, content.visualize_whitespace() \
|
|
|
|
, other->content.visualize_whitespace() \
|
2023-08-25 15:57:53 -07:00
|
|
|
); \
|
|
|
|
}
|
|
|
|
|
2023-09-03 17:29:45 -07:00
|
|
|
#define check_member_ast( ast ) \
|
|
|
|
if ( 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" \
|
|
|
|
, debug_str() \
|
|
|
|
, other->debug_str() \
|
|
|
|
, ast->debug_str() \
|
|
|
|
); \
|
|
|
|
\
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if ( ! ast->is_equal( other->ast ) ) \
|
|
|
|
{ \
|
|
|
|
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" \
|
|
|
|
, debug_str() \
|
|
|
|
, other->debug_str() \
|
|
|
|
, ast->debug_str() \
|
|
|
|
, other->ast->debug_str() \
|
|
|
|
); \
|
|
|
|
\
|
|
|
|
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-08-26 08:55:05 -07:00
|
|
|
// return true;
|
|
|
|
|
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-08-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-08-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
2023-08-22 13:01:50 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Parameters:
|
|
|
|
{
|
|
|
|
if ( NumEntries > 1 )
|
|
|
|
{
|
|
|
|
AST* curr = this;
|
|
|
|
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"
|
|
|
|
, curr->debug_str()
|
|
|
|
);
|
|
|
|
|
|
|
|
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"
|
|
|
|
, debug_str()
|
|
|
|
, other->debug_str()
|
|
|
|
, curr->debug_str()
|
|
|
|
, curr_other->debug_str()
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( curr->ValueType && ! curr->ValueType->is_equal(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"
|
|
|
|
, debug_str()
|
|
|
|
, other->debug_str()
|
|
|
|
, curr->debug_str()
|
|
|
|
, curr_other->debug_str()
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( curr->Value && ! curr->Value->is_equal(curr_other->Value) )
|
|
|
|
{
|
|
|
|
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"
|
|
|
|
, debug_str()
|
|
|
|
, other->debug_str()
|
|
|
|
, curr->debug_str()
|
|
|
|
, curr_other->debug_str()
|
|
|
|
);
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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 );
|
2023-08-22 13:01:50 -07:00
|
|
|
for ( s32 idx = 0; idx < NumEntries; ++idx )
|
|
|
|
{
|
2023-08-23 15:16:45 -07:00
|
|
|
check_member_val( ArrSpecs[ idx ] );
|
2023-08-22 13:01:50 -07:00
|
|
|
}
|
2023-08-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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-08-25 15:40:13 -07:00
|
|
|
// check_member_ast( Prev );
|
|
|
|
// check_member_ast( Next );
|
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
|
|
|
|
|
|
|
AST* curr = Front;
|
|
|
|
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"
|
|
|
|
, curr->debug_str()
|
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-22 13:01:50 -07:00
|
|
|
if ( ! curr->is_equal( 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"
|
|
|
|
, debug_str()
|
|
|
|
, other->debug_str()
|
|
|
|
, curr->debug_str()
|
|
|
|
, curr_other->debug_str()
|
|
|
|
);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AST::validate_body()
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
2023-07-29 02:52:06 -07:00
|
|
|
#define CheckEntries( Unallowed_Types ) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
for ( Code entry : cast<CodeBody>() ) \
|
|
|
|
{ \
|
|
|
|
switch ( entry->Type ) \
|
|
|
|
{ \
|
|
|
|
Unallowed_Types \
|
|
|
|
log_failure( "AST::validate_body: Invalid entry in body %s", entry.debug_str() ); \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
2023-07-24 14:45:27 -07:00
|
|
|
while (0);
|
|
|
|
|
|
|
|
switch ( Type )
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
for ( Code entry : cast<CodeBody>() )
|
|
|
|
{
|
|
|
|
if ( entry->Type != Untyped )
|
|
|
|
{
|
|
|
|
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", entry.debug_str() );
|
|
|
|
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:
|
2023-08-06 11:58:43 -07:00
|
|
|
for (Code entry : cast<CodeBody>())
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
log_failure("AST::validate_body: Invalid entry in body %s", entry.debug_str());
|
|
|
|
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:
|
|
|
|
for ( Code entry : Body->cast<CodeBody>() )
|
|
|
|
{
|
|
|
|
if ( entry->Type != Untyped )
|
|
|
|
{
|
|
|
|
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", entry.debug_str() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_failure( "AST::validate_body: Invalid this AST does not have a body %s", debug_str() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2023-07-29 02:52:06 -07:00
|
|
|
|
|
|
|
#undef CheckEntries
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|