2023-04-01 19:21:46 -07:00
|
|
|
#include "Bloat.hpp"
|
|
|
|
#include "gen.hpp"
|
|
|
|
|
|
|
|
#ifdef gen_time
|
|
|
|
namespace gen
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
ZPL_TABLE_DEFINE( StringTable, str_tbl_, String );
|
2023-04-05 00:03:56 -07:00
|
|
|
ZPL_TABLE_DEFINE( TypeTable, type_tbl_ , Code );
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
namespace StaticData
|
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
#ifndef GEN_CODE_USE_SOA
|
2023-04-09 10:59:39 -07:00
|
|
|
static Array(Pool) CodePools;
|
|
|
|
static Array(Pool) CodeEntriesPools;
|
2023-04-05 00:03:56 -07:00
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
#else
|
|
|
|
using DataUnion = union
|
|
|
|
{
|
|
|
|
array(AST*) Entries;
|
|
|
|
string Content;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace CodePool
|
|
|
|
{
|
|
|
|
array(CodeT) Type;
|
|
|
|
array(bool) Readonly;
|
|
|
|
array(AST*) Parent;
|
|
|
|
array(string) Name;
|
|
|
|
array(string) Comment;
|
|
|
|
array(DataUnion) Data;
|
|
|
|
|
|
|
|
forceinline
|
|
|
|
CodeT& type( sw index )
|
|
|
|
{
|
|
|
|
return Type[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
forceinline
|
|
|
|
bool& readonly( sw index )
|
|
|
|
{
|
|
|
|
return Readonly[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
forceinline
|
|
|
|
AST*& parent( sw index )
|
|
|
|
{
|
|
|
|
return Parent[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
forceinline
|
|
|
|
string& name( sw index )
|
|
|
|
{
|
|
|
|
return Name[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
forceinline
|
|
|
|
string& comment( sw index )
|
|
|
|
{
|
|
|
|
return Comment[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
forceinline
|
|
|
|
DataUnion& data( sw index )
|
|
|
|
{
|
|
|
|
return Data[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
static Array(Arena) StringArenas = nullptr;
|
2023-04-05 00:03:56 -07:00
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
static StringTable StringMap;
|
|
|
|
static TypeTable TypeMap;
|
2023-04-05 00:03:56 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
static sw InitSize_CodePool = megabytes(64);
|
2023-04-07 21:29:09 -07:00
|
|
|
static sw InitSize_CodeEntriesPool = megabytes(8);
|
2023-04-07 09:31:50 -07:00
|
|
|
static sw InitSize_StringTable = megabytes(4);
|
|
|
|
static sw InitSize_TypeTable = megabytes(4);
|
|
|
|
|
|
|
|
static sw SizePer_StringArena = megabytes(32);
|
2023-04-05 00:03:56 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
static AllocatorInfo Allocator_CodePool = heap();
|
|
|
|
static AllocatorInfo Allocator_CodeEntriesPool = heap();
|
|
|
|
static AllocatorInfo Allocator_StringArena = heap();
|
|
|
|
static AllocatorInfo Allocator_StringTable = heap();
|
|
|
|
static AllocatorInfo Allocator_TypeTable = heap();
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
#pragma region CONSTANTS
|
|
|
|
# ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
2023-04-06 16:19:11 -07:00
|
|
|
Code type_ns(void);
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
Code type_ns(bool);
|
|
|
|
Code type_ns(char);
|
|
|
|
Code type_ns(char_wide);
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
Code type_ns(s8);
|
|
|
|
Code type_ns(s16);
|
|
|
|
Code type_ns(s32);
|
|
|
|
Code type_ns(s64);
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
Code type_ns(u8);
|
|
|
|
Code type_ns(u16);
|
|
|
|
Code type_ns(u32);
|
|
|
|
Code type_ns(u64);
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
Code type_ns(sw);
|
|
|
|
Code type_ns(uw);
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
Code type_ns(f32);
|
|
|
|
Code type_ns(f64);
|
2023-04-03 23:04:19 -07:00
|
|
|
# endif
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code spec_constexpr;
|
|
|
|
Code spec_inline;
|
|
|
|
#pragma endregion CONSTANTS
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
# pragma region AST
|
|
|
|
bool AST::add( AST* other )
|
|
|
|
{
|
|
|
|
switch ( Type )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
case Untyped:
|
|
|
|
break;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
case Enum:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_FwdDecl:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Class:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Class_FwdDecl:
|
|
|
|
break;
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
case Global_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function_FwdDecl:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Namespace:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Namespace_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Parameters:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Specifiers:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Variable:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Typedef:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Typename:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Using:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_append( Entries, other );
|
|
|
|
|
|
|
|
other->Parent = this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AST::check()
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
switch ( Type )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
case Untyped:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Global_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function_FwdDecl:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Namespace:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Namespace_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Parameters:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Specifiers:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Variable:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Typedef:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Typename:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Using:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
return true;
|
2023-04-06 16:19:11 -07:00
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
AST* AST::duplicate()
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
|
|
|
|
result->Parent = Parent;
|
|
|
|
result->Name = Name;
|
|
|
|
result->Comment = Comment;
|
|
|
|
result->Type = Type;
|
|
|
|
result->Op = Op;
|
|
|
|
result->Readonly = Readonly;
|
|
|
|
|
|
|
|
switch ( Type )
|
|
|
|
{
|
|
|
|
case Untyped:
|
|
|
|
case Access_Public:
|
|
|
|
case Access_Protected:
|
|
|
|
case Access_Private:
|
|
|
|
case Class_FwdDecl:
|
|
|
|
case Enum_FwdDecl:
|
|
|
|
case Function_FwdDecl:
|
|
|
|
case Specifiers:
|
|
|
|
// Can just be the same, as its a cached string.
|
|
|
|
result->Content = Content;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// The main purpose of this is to make sure entires in the AST are unique,
|
|
|
|
// So that we can assign the new parent without corrupting the existing AST.
|
|
|
|
case Class:
|
|
|
|
case Class_Body:
|
|
|
|
case Enum:
|
|
|
|
case Enum_Body:
|
|
|
|
case Friend:
|
|
|
|
case Global_Body:
|
|
|
|
case Namespace:
|
|
|
|
case Namespace_Body:
|
|
|
|
case Parameters:
|
|
|
|
case Function:
|
|
|
|
case Function_Body:
|
|
|
|
case Struct:
|
|
|
|
case Struct_FwdDecl:
|
|
|
|
case Struct_Body:
|
|
|
|
case Variable:
|
|
|
|
case Typedef:
|
|
|
|
case Typename:
|
|
|
|
case Using:
|
|
|
|
array_init( result->Entries, StaticData::Allocator_CodePool );
|
|
|
|
s32 index = 0;
|
|
|
|
s32 left = array_count( result->Entries );
|
|
|
|
while ( left -- )
|
|
|
|
{
|
|
|
|
// This will naturally duplicate the entire chain duplicate all of the ast nodes.
|
|
|
|
// It may not be the most optimal way for memory reasons, however figuring out the heuristic
|
|
|
|
// For when it should reparent all nodes or not is not within the simple scope of this library.
|
|
|
|
result->add_entry( Entries[index]->duplicate() );
|
|
|
|
result->Entries[index]->Parent = this;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
String AST::to_string() const
|
2023-04-06 16:19:11 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
String result = string_make( g_allocator, "" );
|
2023-04-06 16:19:11 -07:00
|
|
|
|
|
|
|
if ( Comment )
|
|
|
|
result = string_append_fmt( result, "// %s\n", Comment );
|
|
|
|
|
|
|
|
switch ( Type )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
case Invalid:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("Attempted to serialize invalid code! - %s", Name);
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Untyped:
|
2023-04-09 10:59:39 -07:00
|
|
|
result = string_append_length( result, Content, string_length( ccast(String, Content)) );
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
case Access_Public:
|
|
|
|
case Access_Protected:
|
|
|
|
case Access_Private:
|
|
|
|
result = string_append_length( result, Name, string_length( ccast(String, Name)) ) ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Class:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Class_FwdDecl:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Class_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_FwdDecl:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Body:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Class:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Enum_Class_FwdDecl:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Friend:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function:
|
2023-04-06 16:19:11 -07:00
|
|
|
{
|
|
|
|
u32 index = 0;
|
|
|
|
u32 left = array_count( Entries );
|
|
|
|
|
|
|
|
if ( left <= 0 )
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
|
2023-04-06 16:19:11 -07:00
|
|
|
|
|
|
|
if ( Entries[index]->Type == Specifiers )
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
result = string_append_fmt( result, "%s", Entries[index]->to_string() );
|
2023-04-06 16:19:11 -07:00
|
|
|
index++;
|
|
|
|
left--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( left <= 0 )
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
|
2023-04-06 16:19:11 -07:00
|
|
|
|
|
|
|
result = string_append_fmt( result, "\n%s %s(", Entries[index]->to_string(), Name );
|
|
|
|
index++;
|
|
|
|
left--;
|
|
|
|
|
|
|
|
if ( left && Entries[index]->Type == Parameters )
|
|
|
|
{
|
|
|
|
result = string_append_fmt( result, "%s", Entries[index]->to_string() );
|
|
|
|
index++;
|
|
|
|
left--;
|
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
result = string_append_fmt( result, ")\n{\n%s\n}", Entries[index]->to_string() );
|
2023-04-06 16:19:11 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
case Function_FwdDecl:
|
2023-04-06 16:19:11 -07:00
|
|
|
{
|
|
|
|
u32 index = 0;
|
|
|
|
u32 left = array_count( Entries );
|
|
|
|
|
|
|
|
if ( left <= 0 )
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
|
2023-04-06 16:19:11 -07:00
|
|
|
|
|
|
|
if ( Entries[index]->Type == Specifiers )
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
result = string_append_fmt( result, "%s\n", Entries[index]->to_string() );
|
2023-04-06 16:19:11 -07:00
|
|
|
index++;
|
|
|
|
left--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( left <= 0 )
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
|
2023-04-06 16:19:11 -07:00
|
|
|
|
|
|
|
result = string_append_fmt( result, "\n%s %s(", Entries[index]->to_string(), Name );
|
|
|
|
index++;
|
|
|
|
left--;
|
|
|
|
|
|
|
|
if ( left && Entries[index]->Type == Parameters )
|
|
|
|
{
|
|
|
|
result = string_append_fmt( result, "%s", Entries[index]->to_string() );
|
|
|
|
index++;
|
|
|
|
left--;
|
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
result = string_appendc( result, ");\n" );
|
2023-04-06 16:19:11 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Function_Body:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("NOT SUPPORTED YET");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Global_Body:
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Namespace:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("NOT SUPPORTED YET");
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Namespace_Body:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("NOT SUPPORTED YET");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Operator_FwdDecl:
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Parameters:
|
|
|
|
{
|
|
|
|
result = string_append_fmt( result, "%s %s", Entries[0]->to_string(), Name );
|
|
|
|
|
|
|
|
s32 index = 1;
|
|
|
|
s32 left = array_count( Entries ) - 1;
|
|
|
|
|
|
|
|
while ( left--, left > 0 )
|
|
|
|
result = string_append_fmt( result, ", %s %s"
|
|
|
|
, Entries[index]->Entries[0]->to_string()
|
|
|
|
, Entries[index]->Name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Specifiers:
|
|
|
|
result = string_append_fmt( result, "%s", Content );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("NOT SUPPORTED YET");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct_FwdDecl:
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Struct_Body:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("NOT SUPPORTED YET");
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Variable:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("NOT SUPPORTED YET");
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Typedef:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("NOT SUPPORTED YET");
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Typename:
|
|
|
|
result = string_append_fmt( result, "%s", Name );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Using:
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("NOT SUPPORTED YET");
|
2023-04-06 16:19:11 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Code Code::Invalid;
|
|
|
|
# pragma endregion AST
|
|
|
|
|
|
|
|
#pragma region Gen Interface
|
2023-04-03 00:55:28 -07:00
|
|
|
void init()
|
2023-04-01 22:07:44 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
array_init( StaticData::CodePools, StaticData::Allocator_CodePool );
|
2023-04-05 23:21:23 -07:00
|
|
|
array_init( StaticData::StringArenas, heap() );
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Arena string_arena;
|
2023-04-07 09:31:50 -07:00
|
|
|
arena_init_from_allocator( & string_arena, StaticData::Allocator_StringArena, StaticData::SizePer_StringArena );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
str_tbl_init( & StaticData::StringMap, StaticData::Allocator_StringTable );
|
|
|
|
type_tbl_init( & StaticData::TypeMap, StaticData::Allocator_TypeTable );
|
|
|
|
|
|
|
|
Code&
|
|
|
|
InvalidCode_write = ccast( Code, Code::Invalid );
|
2023-04-03 23:04:19 -07:00
|
|
|
InvalidCode_write = make_code();
|
|
|
|
|
|
|
|
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
2023-04-05 23:21:23 -07:00
|
|
|
Code&
|
2023-04-03 23:04:19 -07:00
|
|
|
t_bool_write = ccast( Code, t_void );
|
|
|
|
t_bool_write = def_type( txt(void) );
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
# define def_constant_code_type( Type_ ) \
|
|
|
|
Code& \
|
2023-04-05 23:21:23 -07:00
|
|
|
t_##Type_ = def_type( txt(Type_) ); \
|
|
|
|
t_##Type_.lock()
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
def_constant_code_type( bool );
|
|
|
|
def_constant_code_type( char );
|
|
|
|
def_constant_code_type( wchar_t );
|
|
|
|
|
|
|
|
def_constant_code_type( s8 );
|
|
|
|
def_constant_code_type( s16 );
|
|
|
|
def_constant_code_type( s32 );
|
|
|
|
def_constant_code_type( s64 );
|
|
|
|
|
|
|
|
def_constant_code_type( u8 );
|
|
|
|
def_constant_code_type( u16 );
|
|
|
|
def_constant_code_type( u32 );
|
|
|
|
def_constant_code_type( u64 );
|
|
|
|
|
|
|
|
def_constant_code_type( sw );
|
|
|
|
def_constant_code_type( uw );
|
|
|
|
|
|
|
|
def_constant_code_type( f32 );
|
|
|
|
def_constant_code_type( f64 );
|
|
|
|
# undef def_constant_code_type
|
2023-04-05 23:21:23 -07:00
|
|
|
#endif
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code&
|
|
|
|
spec_constexpr_write = ccast( Code, spec_constexpr );
|
|
|
|
spec_constexpr_write = def_specifiers( 1, ESpecifier::Constexpr );
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
# define def_constant_spec( Type_, ... ) \
|
|
|
|
Code& \
|
2023-04-05 23:21:23 -07:00
|
|
|
spec_##Type_ = def_specifiers( macro_num_args(__VA_ARGS__), __VA_ARGS__); \
|
|
|
|
spec_##Type_.lock();
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
def_constant_spec( const, ESpecifier::Const );
|
2023-04-03 23:04:19 -07:00
|
|
|
def_constant_spec( inline, ESpecifier::Inline );
|
|
|
|
# undef def_constant_spec
|
2023-04-01 22:07:44 -07:00
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
void clear_code_pools()
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-07 21:29:09 -07:00
|
|
|
// Clear the code pools
|
|
|
|
{
|
|
|
|
s32 index = 0;
|
|
|
|
s32 left = 0;
|
|
|
|
while (( left-- ))
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
Pool* code_pool = & StaticData::CodePools[index];
|
2023-04-07 21:29:09 -07:00
|
|
|
pool_free( code_pool );
|
|
|
|
}
|
|
|
|
|
|
|
|
array_clear( StaticData::CodePools );
|
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
// Clear the code entries pools
|
|
|
|
{
|
|
|
|
s32 index = 0;
|
|
|
|
s32 left = 0;
|
|
|
|
while (( left-- ))
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
Pool* code_entries_pool = & StaticData::CodeEntriesPools[index];
|
2023-04-07 21:29:09 -07:00
|
|
|
pool_free( code_entries_pool );
|
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
array_clear( StaticData::CodeEntriesPools );
|
|
|
|
}
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
AllocatorInfo get_string_allocator( s32 str_length )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
|
|
|
using namespace StaticData;
|
|
|
|
|
|
|
|
if ( StringArenas->total_allocated + str_length > StringArenas->total_size )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
Arena new_arena;
|
2023-04-07 09:31:50 -07:00
|
|
|
arena_init_from_allocator( & new_arena, Allocator_StringArena, SizePer_StringArena );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
array_append( StringArenas, new_arena );
|
2023-04-01 22:07:44 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
return arena_allocator( StringArenas );
|
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
return arena_allocator( StringArenas );
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
// Will either make or retrive a code string.
|
2023-04-07 21:29:09 -07:00
|
|
|
string_const cached_string( char const* cstr, s32 length )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
s32 hash_length = length > kilobytes(1) ? kilobytes(1) : length;
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
u32 key = crc32( cstr, hash_length );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
String* result = str_tbl_get( & StaticData::StringMap, key );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
if ( result )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
return * result;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
* result = string_make( get_string_allocator( length ), cstr );
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
str_tbl_set( & StaticData::StringMap, key, * result );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
return * result;
|
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
/*
|
|
|
|
Used internally to retireve a Code object form the CodePool.
|
|
|
|
*/
|
|
|
|
Code make_code()
|
|
|
|
{
|
|
|
|
using namespace StaticData;
|
|
|
|
|
|
|
|
# ifndef GEN_CODE_USE_SOA
|
|
|
|
ct CodePOD Invalid = { nullptr, nullptr, nullptr, nullptr, ECode::Invalid, EOperator::Invalid, false, {0} };
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
# else
|
|
|
|
|
|
|
|
array_append( CodePool::Type, ECode::Invalid );
|
|
|
|
array_append( CodePool::Readonly, false );
|
|
|
|
array_append( CodePool::Name, nullptr );
|
|
|
|
array_append( CodePool::Comment, nullptr );
|
|
|
|
array_append( CodePool::Data, { nullptr } );
|
|
|
|
|
|
|
|
Code code { array_count( CodePool::Type) - 1 };
|
|
|
|
|
|
|
|
return code;
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Array(AST*) make_code_entries()
|
2023-04-07 21:29:09 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator_member_symbol_check( Code entry )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
void set_allocator_code_pool( AllocatorInfo pool_allocator )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
StaticData::Allocator_CodePool = pool_allocator;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
void set_allocator_string_arena( AllocatorInfo string_allocator )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
StaticData::Allocator_StringArena = string_allocator;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
void set_allocator_string_table( AllocatorInfo string_allocator )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
StaticData::Allocator_StringArena = string_allocator;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
void set_init_reserve_code_pool( sw size )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
StaticData::InitSize_CodePool = size;
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
void set_init_reserve_string_table( sw size )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
StaticData::InitSize_StringTable = size;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
void set_init_reserve_type_table( sw size )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
StaticData::InitSize_TypeTable = size;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
void set_allocator_type_table( AllocatorInfo type_reg_allocator )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
StaticData::Allocator_TypeTable = type_reg_allocator;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
void set_size_string_arena( sw size )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
StaticData::SizePer_StringArena = size;
|
2023-04-05 00:03:56 -07:00
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
# pragma region Helper Functions
|
|
|
|
// This snippet is required in nearly all the functions.
|
|
|
|
# define name_check( Context_, Length_, Name_ ) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if ( Length_ <= 0 ) \
|
|
|
|
{ \
|
|
|
|
log_failure( "gen::%s: Invalid name length provided - %d", #Context_, length ); \
|
|
|
|
return Code::Invalid; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if ( Name_ == nullptr ) \
|
|
|
|
{ \
|
|
|
|
log_failure( "gen::%s: name is null", #Context_); \
|
|
|
|
return Code::Invalid; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
|
|
|
|
# pragma endregion Helper Functions
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
# pragma region Upfront Constructors
|
2023-04-06 16:19:11 -07:00
|
|
|
Code def_class( s32 length, char const* name, Code parent, Code specifiers, Code body )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( def_class, length, name );
|
2023-04-06 16:19:11 -07:00
|
|
|
|
|
|
|
if ( parent && parent->Type != Class || parent->Type != Struct )
|
|
|
|
{
|
2023-04-07 09:31:50 -07:00
|
|
|
log_failure( "gen::def_class: parent provided is not type 'Class' or 'Struct' - Type: %s", parent->debug_str() );
|
2023-04-06 16:19:11 -07:00
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( specifiers && specifiers->Type != Specifiers )
|
|
|
|
{
|
2023-04-07 09:31:50 -07:00
|
|
|
log_failure( "gen::def_class: specifiers was not a 'Specifiers' type - Type: %s", specifiers->debug_str() );
|
2023-04-06 16:19:11 -07:00
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
2023-04-07 09:31:50 -07:00
|
|
|
result->Name = cached_string( name, length );
|
2023-04-06 16:19:11 -07:00
|
|
|
|
|
|
|
if ( body )
|
|
|
|
{
|
2023-04-07 09:31:50 -07:00
|
|
|
switch ( body->Type )
|
|
|
|
{
|
|
|
|
case Class_Body:
|
|
|
|
case Untyped:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_failure("gen::def_class: body must be either of Class_Body or Untyped type - %s", body->debug_str());
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
result->Type = Class;
|
|
|
|
result->Entries = make_code_entries();
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( body );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->Type = Class_FwdDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( parent )
|
|
|
|
result->add_entry( parent );
|
|
|
|
|
|
|
|
if ( specifiers )
|
|
|
|
result->add_entry( specifiers );
|
|
|
|
|
|
|
|
result.lock();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code def_enum( s32 length, char const* name, Code type, EnumT specifier, Code body )
|
2023-04-06 16:19:11 -07:00
|
|
|
{
|
2023-04-07 09:31:50 -07:00
|
|
|
using namespace ECode;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( def_enum, length, name );
|
2023-04-07 09:31:50 -07:00
|
|
|
|
|
|
|
if ( type && type->Type != Typename )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", type->debug_str() );
|
2023-04-06 16:19:11 -07:00
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Name = cached_string( name, length );
|
|
|
|
|
|
|
|
if ( body )
|
|
|
|
{
|
|
|
|
switch ( body->Type )
|
|
|
|
{
|
|
|
|
case Enum_Body:
|
|
|
|
case Untyped:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_failure( "gen::def_enum: body must be of Enum_Body or Untyped type %s", body->debug_str());
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
result->Type = specifier == EnumClass ?
|
|
|
|
Enum_Class : Enum;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
result->Entries = make_code_entries();
|
2023-04-07 09:31:50 -07:00
|
|
|
result->add_entry( body );
|
|
|
|
}
|
2023-04-07 21:29:09 -07:00
|
|
|
else if ( specifier == EnumClass )
|
2023-04-07 09:31:50 -07:00
|
|
|
{
|
2023-04-07 21:29:09 -07:00
|
|
|
result->Type = specifier == EnumClass ?
|
|
|
|
Enum_Class_FwdDecl : Enum_FwdDecl;
|
2023-04-07 09:31:50 -07:00
|
|
|
}
|
2023-04-06 16:19:11 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
if ( type )
|
|
|
|
{
|
|
|
|
result->add_entry( type );
|
|
|
|
}
|
|
|
|
|
|
|
|
result.lock();
|
|
|
|
return result;
|
2023-04-06 16:19:11 -07:00
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Code def_friend( Code symbol )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
if ( ! symbol )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_friend: symbol provided is null!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( symbol == Code::Invalid )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_friend: symbol provided is invalid!" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( symbol->Type )
|
|
|
|
{
|
|
|
|
case Class_FwdDecl:
|
|
|
|
case Function_FwdDecl:
|
|
|
|
case Operator_FwdDecl:
|
|
|
|
case Struct_FwdDecl:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_failure("gen::def_friend: symbol cannot be used with friend, must be a forward declare - %s", symbol->debug_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
Code def_function( s32 length, char const* name
|
2023-04-01 19:21:46 -07:00
|
|
|
, Code specifiers
|
|
|
|
, Code params
|
|
|
|
, Code ret_type
|
2023-04-05 23:21:23 -07:00
|
|
|
, Code body
|
2023-04-02 09:35:14 -07:00
|
|
|
)
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
using namespace ECode;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( def_function, length, name );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
if ( specifiers && specifiers->Type != Specifiers )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-07 09:31:50 -07:00
|
|
|
log_failure( "gen::def_function: specifiers was not a `Specifiers` type %s", specifiers->debug_str() );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
if ( params && params->Type != Parameters )
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-04-07 09:31:50 -07:00
|
|
|
log_failure( "gen::def_function: params was not a `Parameters` type %s", params->debug_str() );
|
|
|
|
return Code::Invalid;
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
if ( ret_type == nullptr || ret_type->Type != Typename )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_function: ret_type was not a Typename %s", ret_type->debug_str() );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
2023-04-05 23:21:23 -07:00
|
|
|
|
|
|
|
Code
|
2023-04-03 23:04:19 -07:00
|
|
|
result = make_code();
|
2023-04-07 09:31:50 -07:00
|
|
|
result->Name = cached_string( name, length );
|
2023-04-05 23:21:23 -07:00
|
|
|
|
|
|
|
array_init( result->Entries, StaticData::Allocator_CodePool );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
if ( body )
|
|
|
|
{
|
|
|
|
switch ( body->Type )
|
|
|
|
{
|
|
|
|
case Function_Body:
|
|
|
|
case Untyped:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
log_failure("gen::def_function: body must be either of Function_Body or Untyped type. %s", body->debug_str());
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result->Type = Function;
|
|
|
|
result->add_entry( body );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->Type = Function_FwdDecl;
|
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-01 19:21:46 -07:00
|
|
|
if ( specifiers )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( specifiers );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
if ( ret_type )
|
|
|
|
{
|
|
|
|
result->add_entry( ret_type );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->add_entry( type_ns(void) );
|
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
|
|
|
if ( params )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( params );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
result.lock();
|
2023-04-01 19:21:46 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
Code def_namespace( s32 length, char const* name, Code body )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( def_namespace, length, name );
|
2023-04-07 09:31:50 -07:00
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Type = Namespace;
|
|
|
|
result->Name = cached_string( name, length );
|
|
|
|
|
|
|
|
array_init( result->Entries, g_allocator );
|
|
|
|
|
|
|
|
if ( body->Type != Namespace_Body || body->Type != Untyped )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_namespace: body is not of namespace or untyped type %s", body->debug_str());
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
result->add_entry( body );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code def_operator( OperatorT op, Code params, Code ret_type, Code specifiers, Code body )
|
|
|
|
{
|
|
|
|
using namespace EOperator;
|
|
|
|
|
|
|
|
if ( op == Invalid )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_operator: op cannot be invalid");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( op )
|
|
|
|
{
|
|
|
|
case Assign:
|
|
|
|
case Assign_Add:
|
|
|
|
case Assign_Subtract:
|
|
|
|
case Assgin_Multiply:
|
|
|
|
case Assgin_Divide:
|
|
|
|
case Assgin_Modulo:
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code result = make_code();
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_param( Code type, s32 length, char const* name )
|
2023-04-07 09:31:50 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code def_struct( u32 length, char const* name, Code body, Code parent, Code specifiers )
|
2023-04-02 09:35:14 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
using namespace ECode;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( def_struct, length, name );
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
if ( specifiers && specifiers->Type != Specifiers )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( parent && parent->Type != Struct )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_struct: parent was not a `Struct` type" );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( body && body->Type != Struct_Body )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_struct: body was not a Struct_Body type" );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
2023-04-09 10:59:39 -07:00
|
|
|
result = make_code();
|
|
|
|
result->Type = Struct;
|
|
|
|
result->Name = cached_string( name, length );
|
|
|
|
result->Entries = make_code_entries();
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
if ( body )
|
|
|
|
result->add_entry( body );
|
|
|
|
|
|
|
|
if ( parent )
|
|
|
|
result->add_entry( parent );
|
|
|
|
|
|
|
|
if ( specifiers )
|
|
|
|
result->add_entry( specifiers );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_variable( Code type, u32 length, char const* name, Code value, Code specifiers )
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( def_variable, length, name );
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
if ( specifiers && specifiers->Type != ECode::Specifiers )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type" );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( type->Type != ECode::Typename )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_variable: type was not a Typename" );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( value && value->Type != ECode::Untyped )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_variable: value was not a `Untyped` type" );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
2023-04-09 10:59:39 -07:00
|
|
|
result = make_code();
|
|
|
|
result->Name = cached_string( name, length );
|
|
|
|
result->Type = ECode::Variable;
|
|
|
|
result->Entries = make_code_entries();
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
if ( specifiers )
|
|
|
|
result->add_entry( specifiers );
|
|
|
|
|
|
|
|
result->add_entry( type );
|
|
|
|
|
|
|
|
if ( value )
|
|
|
|
result->add_entry( value );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_type( u32 length, char const* name, Code specifiers )
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( def_type, length, name );
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Name = cached_string( name, length );
|
|
|
|
result->Type = ECode::Typename;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_using( u32 length, char const* name, Code type, UsingT specifier )
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( def_using, length, name );
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Name = cached_string( name, length );
|
|
|
|
result->Type = ECode::Using;
|
|
|
|
|
|
|
|
type->Parent = result;
|
|
|
|
result->add_entry( type );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_class_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
if ( num == 0 )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_class_body: num cannot be zero");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Entries = make_code_entries();
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = va_arg(va, Code);
|
|
|
|
|
|
|
|
switch ( entry->Type )
|
|
|
|
{
|
|
|
|
case Namespace:
|
|
|
|
case Namespace_Body:
|
|
|
|
case Parameters:
|
|
|
|
case Specifiers:
|
|
|
|
case Struct_Body:
|
|
|
|
case Typename:
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
2023-04-07 21:29:09 -07:00
|
|
|
log_failure("gen::def_class_body: Entry type is not allowed: %s", ECode::str(entry->Type) );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
case Operator:
|
|
|
|
// If an operator is getting added, we need to verify
|
|
|
|
// the definition conforms to the format required for member symbols.
|
|
|
|
if ( ! operator_member_symbol_check( entry ) )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_class_body: Operator entry was not a valid member symbol.");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
break;
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( entry );
|
2023-04-05 23:21:23 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
while ( num--, num > 0 );
|
|
|
|
va_end(va);
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
return result;
|
2023-04-02 09:35:14 -07:00
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code def_enum_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_function_body( s32 num, ... )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
if ( num <= 0 )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_function_body: num cannot zero or neg");
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Code result = make_code();
|
|
|
|
|
|
|
|
array_init( result->Entries, g_allocator );
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
2023-04-03 23:04:19 -07:00
|
|
|
do
|
|
|
|
{
|
2023-04-07 21:29:09 -07:00
|
|
|
Code entry = va_arg(va, Code);
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
if ( ! entry )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_function_body: Provided an invalid entry!");
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ( entry->Type )
|
|
|
|
{
|
2023-04-06 16:19:11 -07:00
|
|
|
case Function_FwdDecl:
|
2023-04-03 23:04:19 -07:00
|
|
|
case Namespace:
|
|
|
|
case Namespace_Body:
|
2023-04-07 21:29:09 -07:00
|
|
|
case Operator:
|
2023-04-03 23:04:19 -07:00
|
|
|
case Parameters:
|
|
|
|
case Specifiers:
|
|
|
|
case Struct_Body:
|
|
|
|
case Typename:
|
|
|
|
{
|
|
|
|
log_failure("gen::def_function_body: Entry type is not allowed: %s", entry->type_str() );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( entry );
|
2023-04-05 23:21:23 -07:00
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
while ( num--, num > 0 );
|
2023-04-07 21:29:09 -07:00
|
|
|
va_end(va);
|
2023-04-05 23:21:23 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code def_function_body( s32 num, Code* codes )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
if ( num <= 0 )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_function_body: num cannot zero or neg");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( codes == nullptr )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_function_body: Provided a null array of codes!");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code result = make_code();
|
|
|
|
|
|
|
|
array_init( result->Entries, g_allocator );
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = *codes;
|
|
|
|
|
|
|
|
if ( ! entry )
|
|
|
|
{
|
|
|
|
log_failure("gen::def_function_body: Provided an invalid entry!");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( entry->Type )
|
|
|
|
{
|
|
|
|
case Function_FwdDecl:
|
|
|
|
case Namespace:
|
|
|
|
case Namespace_Body:
|
|
|
|
case Operator:
|
|
|
|
case Parameters:
|
|
|
|
case Specifiers:
|
|
|
|
case Struct_Body:
|
|
|
|
case Typename:
|
|
|
|
{
|
|
|
|
log_failure("gen::def_function_body: Entry type is not allowed: %s", entry->type_str() );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result->add_entry( entry );
|
|
|
|
}
|
|
|
|
while ( num--, num > 0 );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_global_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_namespace_body( s32 num, ... )
|
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
if ( num <= 0 )
|
|
|
|
{
|
|
|
|
log_failure("gen::make_specifier: num cannot be zero or less");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Type = Namespace_Body;
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = va_arg(va, Code);
|
|
|
|
|
|
|
|
switch ( entry->Type )
|
|
|
|
{
|
|
|
|
case Namespace_Body:
|
|
|
|
case Parameters:
|
|
|
|
case Specifiers:
|
|
|
|
case Struct_Body:
|
|
|
|
case Typename:
|
|
|
|
log_failure("gen::def_function_body: Entry type is not allowed: %s", ECode::str(entry->Type) );
|
|
|
|
return Code::Invalid;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result->add_entry( entry );
|
|
|
|
}
|
|
|
|
while ( num--, num > 0 );
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code def_params( s32 num, ... )
|
2023-04-05 23:21:23 -07:00
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
if (num <= 0)
|
|
|
|
{
|
|
|
|
log_failure( "TT::make_paramters: num cannot be zero or neg" );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Type = Parameters;
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
|
|
|
|
Code type = va_arg(va, Code);
|
|
|
|
|
|
|
|
char const* name = va_arg(va, char const*);
|
2023-04-09 10:59:39 -07:00
|
|
|
s32 name_length = strnlen(name, MaxNameLength);
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
result->Name = cached_string( name, name_length );
|
2023-04-05 23:21:23 -07:00
|
|
|
|
|
|
|
array_init( result->Entries, g_allocator );
|
|
|
|
|
|
|
|
if ( type->Type != Typename )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_parameters: type of param %d is not a Typename", num - num + 1 );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( type );
|
2023-04-05 23:21:23 -07:00
|
|
|
|
|
|
|
while( num -= 2, num && num % 2 == 0 )
|
|
|
|
{
|
|
|
|
type = va_arg(va, Code);
|
|
|
|
|
|
|
|
name = va_arg(va, char const*);
|
2023-04-09 10:59:39 -07:00
|
|
|
name_length = strnlen(name, MaxNameLength);
|
2023-04-05 23:21:23 -07:00
|
|
|
|
|
|
|
Code
|
|
|
|
param = make_code();
|
|
|
|
param->Type = Parameters;
|
2023-04-07 09:31:50 -07:00
|
|
|
param->Name = cached_string(name, name_length);
|
2023-04-05 23:21:23 -07:00
|
|
|
|
|
|
|
array_init( param->Entries, StaticData::Allocator_CodePool );
|
|
|
|
|
|
|
|
if ( type->Type != Typename )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_parameters: type of param %d is not a Typename", num - num + 1 );
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
param->add_entry( type );
|
2023-04-05 23:21:23 -07:00
|
|
|
param.lock();
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry(param);
|
2023-04-05 23:21:23 -07:00
|
|
|
}
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
result.lock();
|
2023-04-03 23:04:19 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code def_params_macro ( s32 num, ... )
|
2023-04-02 09:35:14 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-02 09:35:14 -07:00
|
|
|
}
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
Code def_specifiers( s32 num, ... )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
|
|
|
if ( num <= 0 )
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("gen::make_specifier: num cannot be zero or less");
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
// This should be more than enough...
|
|
|
|
static u8 FixedSizedBuffer[kilobytes(1024)];
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
static Arena str_arena;
|
2023-04-07 09:31:50 -07:00
|
|
|
do_once_start
|
|
|
|
arena_init_from_memory( & str_arena, FixedSizedBuffer, kilobytes(1024) );
|
|
|
|
do_once_end
|
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
Code
|
2023-04-03 23:04:19 -07:00
|
|
|
result = make_code();
|
2023-04-03 00:55:28 -07:00
|
|
|
result->Type = ECode::Specifiers;
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
String crafted = string_make( arena_allocator( & str_arena ), "" );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
do
|
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
SpecifierT type = (SpecifierT)va_arg(va, int);
|
2023-04-01 19:21:46 -07:00
|
|
|
|
|
|
|
switch ( type )
|
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
case ESpecifier::Alignas:
|
2023-04-09 10:59:39 -07:00
|
|
|
crafted = string_append_fmt( (String)result->Content, "%s(%d)", ESpecifier::to_str(type), va_arg(va, u32) );
|
2023-04-01 19:21:46 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-04-03 23:04:19 -07:00
|
|
|
const char* str = ESpecifier::to_str(type);
|
2023-04-01 22:07:44 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
crafted = string_append_fmt( (String)result->Content, "%s", str );
|
2023-04-01 19:21:46 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-04-01 22:07:44 -07:00
|
|
|
while ( --num, num );
|
2023-04-01 19:21:46 -07:00
|
|
|
va_end(va);
|
|
|
|
|
2023-04-07 09:31:50 -07:00
|
|
|
result->Content = cached_string( crafted, string_length( crafted ) );
|
|
|
|
|
|
|
|
arena_free( & str_arena );
|
|
|
|
|
2023-04-01 19:21:46 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
Code def_struct_body( s32 num, ... )
|
2023-04-02 09:35:14 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
using namespace ECode;
|
|
|
|
|
|
|
|
if ( num == 0 )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
|
|
|
log_failure("gen::def_struct_body: num cannot be zero");
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Entries = make_code_entries();
|
2023-04-02 09:35:14 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
va_list va;
|
|
|
|
va_start(va, num);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Code entry = va_arg(va, Code);
|
|
|
|
|
|
|
|
switch ( entry->Type )
|
|
|
|
{
|
|
|
|
case Namespace:
|
|
|
|
case Namespace_Body:
|
|
|
|
case Parameters:
|
|
|
|
case Specifiers:
|
|
|
|
case Struct_Body:
|
|
|
|
case Typename:
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
|
|
|
log_failure("gen::def_struct_body: Entry type is not allowed: %s", ECode::str(entry->Type) );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
case Operator:
|
|
|
|
// If an operator is getting added, we need to verify
|
|
|
|
// the definition conforms to the format required for member symbols.
|
|
|
|
if ( ! operator_member_symbol_check( entry ) )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_struct_body: Operator entry was not a valid member symbol.");
|
|
|
|
return Code::Invalid;
|
|
|
|
}
|
|
|
|
break;
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( entry );
|
2023-04-05 23:21:23 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
while ( num--, num > 0 );
|
|
|
|
va_end(va);
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
return result;
|
2023-04-02 09:35:14 -07:00
|
|
|
}
|
2023-04-07 21:29:09 -07:00
|
|
|
# pragma endregion Upfront Constructors
|
2023-04-02 09:35:14 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
# pragma region Incremetnal Constructors
|
|
|
|
Code make_class( s32 length, char const* name, Code parent, Code specifiers )
|
2023-04-01 22:07:44 -07:00
|
|
|
{
|
2023-04-07 09:31:50 -07:00
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
}
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code make_enum( s32 length, char const* name, Code type, EnumT specifier )
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2023-04-02 09:35:14 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code make_function( s32 length, char const* name
|
2023-04-03 23:04:19 -07:00
|
|
|
, Code specifiers
|
|
|
|
, Code params
|
|
|
|
, Code ret_type
|
|
|
|
)
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
using namespace ECode;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( make_function, length, name );
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( specifiers && specifiers->Type != Specifiers )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_function: specifiers was not a `Specifiers` type" );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( params && params->Type != Parameters )
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
log_failure( "gen::def_function: params was not a `Parameters` type" );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( ret_type == nullptr || ret_type->Type != Typename )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_function: ret_type was not a Typename" );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
Code
|
2023-04-07 21:29:09 -07:00
|
|
|
result = make_code();
|
|
|
|
result->Name = string_make( g_allocator, name );
|
|
|
|
result->Type = Function;
|
|
|
|
result->Entries = make_code_entries();
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code
|
|
|
|
body = make_code();
|
|
|
|
body->Type = Function_Body;
|
|
|
|
body->Entries = make_code_entries();
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( make_code() );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( specifiers )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( specifiers );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( ret_type )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( ret_type );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
if ( params )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( params );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Code make_global_body( s32 length, char const* name, s32 num, ... )
|
2023-04-07 21:29:09 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( make_global_body, length, name );
|
2023-04-07 21:29:09 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Type = ECode::Global_Body;
|
|
|
|
result->Name = cached_string( name, length );
|
|
|
|
result->Entries = make_code_entries();
|
2023-04-07 21:29:09 -07:00
|
|
|
|
|
|
|
// Making body at entry 0;
|
|
|
|
result->add_entry( make_code() );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code make_namespace( s32 length, char const* name, Code parent, Code specifiers )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code make_operator( OperatorT op, Code params, Code ret_type, Code specifiers )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code make_params()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code make_specifiers()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Code make_struct( s32 length, char const* name, Code parent, Code specifiers )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
|
|
|
using namespace ECode;
|
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
name_check( make_struct, length, name );
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( specifiers && specifiers->Type != Specifiers )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( parent && parent->Type != Struct )
|
|
|
|
{
|
|
|
|
log_failure( "gen::def_struct: parent was not a `Struct` type" );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Code
|
2023-04-07 21:29:09 -07:00
|
|
|
result = make_code();
|
|
|
|
result->Type = Struct;
|
|
|
|
result->Name = string_make( g_allocator, name );
|
2023-04-09 10:59:39 -07:00
|
|
|
result->Entries = make_code_entries();
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code
|
|
|
|
body = make_code();
|
|
|
|
body->Type = Function_Body;
|
|
|
|
body->Entries = make_code_entries();
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( make_code() );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
if ( parent )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( parent );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
if ( specifiers )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( specifiers );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-04-07 21:29:09 -07:00
|
|
|
# pragma endregion Incremetnal Constructions
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
# pragma region Parsing Constructors
|
|
|
|
Code parse_class( s32 length, char const* def )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code parse_enum( s32 length, char const* def )
|
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code parse_friend( s32 length, char const* def )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code parse_global_body( s32 length, char const* def )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code parse_function( s32 length, char const* def )
|
2023-04-03 23:04:19 -07:00
|
|
|
{
|
|
|
|
if ( def == nullptr )
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
log_failure("gen::parse_proc: def is null!");
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
Arena mem;
|
2023-04-03 23:04:19 -07:00
|
|
|
do_once_start
|
|
|
|
{
|
|
|
|
arena_init_from_allocator( & mem, heap(), kilobytes( 10 ) );
|
|
|
|
}
|
|
|
|
do_once_end
|
|
|
|
|
|
|
|
// Pretty sure its impossible to have more than this.
|
|
|
|
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
|
|
|
|
|
|
|
|
u8 num_specifiers;
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
// Making all significant tokens have a max length of 128 for this parser.
|
|
|
|
ct sw LengthID = 128;
|
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
struct Param
|
|
|
|
{
|
|
|
|
char const Type[LengthID];
|
|
|
|
char const Name[LengthID];
|
2023-04-03 23:04:19 -07:00
|
|
|
};
|
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
static
|
2023-04-03 23:04:19 -07:00
|
|
|
Param Params[ 64 ] { 0 };
|
|
|
|
|
|
|
|
// Zero out params before a run of this func.
|
2023-04-09 10:59:39 -07:00
|
|
|
memset( Params, 0, sizeof( Params ));
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
char const* name;
|
|
|
|
s32 name_length = 0;
|
|
|
|
|
|
|
|
char const* body_str = nullptr;
|
|
|
|
s32 body_length = 0;
|
|
|
|
|
|
|
|
char const* ret_type_str = nullptr;
|
|
|
|
s32 ret_length = 0;
|
|
|
|
|
|
|
|
s32 left = length;
|
|
|
|
char const* scanner = def;
|
|
|
|
|
|
|
|
while ( left -- )
|
|
|
|
{
|
|
|
|
#define SkipWhitespace() \
|
|
|
|
while ( left && char_is_space( * scanner ) ) \
|
|
|
|
{ \
|
|
|
|
left--; \
|
2023-04-05 00:03:56 -07:00
|
|
|
scanner++ ; \
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
#define Get
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
// Find all specifiers (if any) and the return type
|
|
|
|
do
|
|
|
|
{
|
|
|
|
SkipWhitespace();
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
s32 length = 0;
|
|
|
|
char const* spec_or_type = scanner;
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
while ( char_is_alpha( * scanner) || * scanner == '_')
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
length++;
|
|
|
|
left--;
|
2023-04-03 00:55:28 -07:00
|
|
|
scanner++;
|
|
|
|
}
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
SpecifierT type = ESpecifier::to_type( spec_or_type, length );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( type != ESpecifier::Invalid )
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
specs_found[num_specifiers] = type;
|
|
|
|
num_specifiers++;
|
|
|
|
continue;
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
// Should be return type
|
|
|
|
ret_type_str = scanner;
|
|
|
|
ret_length = length;
|
|
|
|
scanner++;
|
|
|
|
break;
|
2023-04-05 23:21:23 -07:00
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
while( left );
|
|
|
|
|
|
|
|
SkipWhitespace();
|
|
|
|
|
|
|
|
// Next up should be the name if before there were specifiers
|
|
|
|
name = scanner;
|
|
|
|
|
|
|
|
while ( char_is_alpha( * scanner) || * scanner == '_')
|
|
|
|
{
|
|
|
|
ret_length++;
|
|
|
|
left--;
|
2023-04-03 00:55:28 -07:00
|
|
|
scanner++;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parameters
|
|
|
|
SkipWhitespace();
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
if ( * scanner != '(' )
|
|
|
|
{
|
|
|
|
log_failure("gen::parse_proc: Error, expected a ( in %s", string_make_length( g_allocator, scanner - 4, 100) );
|
2023-04-05 23:21:23 -07:00
|
|
|
return Code::Invalid;
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
scanner++;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
while (0);
|
|
|
|
|
|
|
|
// Get past ')'
|
|
|
|
scanner++;
|
|
|
|
|
|
|
|
SkipWhitespace()
|
|
|
|
|
|
|
|
// get end specifiers
|
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
|
|
|
|
if ( * scanner != '{')
|
|
|
|
{
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
}
|
2023-04-02 09:35:14 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code specifiers = def_specifiers( num_specifiers, specs_found );
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code params = make_code();
|
|
|
|
Code ret_type = def_type( ret_type_str );
|
2023-04-05 23:21:23 -07:00
|
|
|
Code body = untyped_str( body_length, body_str );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 23:21:23 -07:00
|
|
|
Code
|
2023-04-03 23:04:19 -07:00
|
|
|
result = make_code();
|
2023-04-07 09:31:50 -07:00
|
|
|
result->Name = cached_string( name, name_length );
|
2023-04-05 23:21:23 -07:00
|
|
|
result->Type = ECode::Function;
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
array_init( result->Entries, g_allocator );
|
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( body );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
if ( specifiers )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( specifiers );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( ret_type );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
if ( params )
|
2023-04-06 16:19:11 -07:00
|
|
|
result->add_entry( params );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
result.lock();
|
2023-04-02 09:35:14 -07:00
|
|
|
return result;
|
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code parse_namespace( s32 length, char const* def )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code parse_operator( s32 length, char const* def )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code parse_struct( s32 length, char const* def )
|
2023-04-02 09:35:14 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
Arena mem;
|
2023-04-03 23:04:19 -07:00
|
|
|
do_once_start
|
|
|
|
arena_init_from_allocator( & mem, heap(), kilobytes( 10 ) );
|
|
|
|
do_once_end
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
// Pretty sure its impossible to have more than this.
|
|
|
|
SpecifierT specs_found[16] { ESpecifier::Num_Specifiers };
|
|
|
|
|
|
|
|
u8 num_specifiers;
|
|
|
|
|
|
|
|
// Making all significant tokens have a max length of 128 for this parser.
|
|
|
|
ct sw LengthID = 128;
|
|
|
|
|
|
|
|
char const name[LengthID] { 0 };
|
|
|
|
char const parent[LengthID] { 0 };
|
2023-04-07 21:29:09 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
Code parse_variable( s32 length, char const* def )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code parse_type( s32 length, char const* def )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code parse_typdef( s32 length, char const* def )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Code parse_using( s32 length, char const* def )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_classes ( s32 length, char const* class_defs, Code* out_class_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_enums ( s32 length, char const* enum_defs, Code* out_enum_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_friends ( s32 length, char const* friend_defs, Code* out_friend_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_functions ( s32 length, char const* fn_defs, Code* out_fn_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_namespaces( s32 length, char const* namespace_defs, Code* out_namespaces_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_operators ( s32 length, char const* operator_defs, Code* out_operator_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_structs ( s32 length, char const* struct_defs, Code* out_struct_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_variables ( s32 length, char const* vars_def, Code* out_var_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_typedefs ( s32 length, char const* typedef_def, Code* out_typedef_codes )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 parse_usings ( s32 length, char const* usings_def, Code* out_using_codes )
|
|
|
|
{
|
2023-04-02 09:35:14 -07:00
|
|
|
|
|
|
|
}
|
2023-04-05 00:03:56 -07:00
|
|
|
# pragma endregion Parsing Constructors
|
|
|
|
|
|
|
|
# pragma region Untyped Constructors
|
2023-04-06 16:19:11 -07:00
|
|
|
Code untyped_str(char const* str)
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
Code
|
2023-04-05 00:03:56 -07:00
|
|
|
result = make_code();
|
2023-04-06 16:19:11 -07:00
|
|
|
result->Name = string_make( g_allocator, str );
|
2023-04-05 00:03:56 -07:00
|
|
|
result->Type = ECode::Untyped;
|
|
|
|
result->Content = result->Name;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code untyped_fmt(char const* fmt, ...)
|
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
local_persist thread_local
|
2023-04-05 00:03:56 -07:00
|
|
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2023-04-09 10:59:39 -07:00
|
|
|
snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
2023-04-05 00:03:56 -07:00
|
|
|
va_end(va);
|
2023-04-05 23:21:23 -07:00
|
|
|
|
|
|
|
Code
|
2023-04-05 00:03:56 -07:00
|
|
|
result = make_code();
|
|
|
|
result->Name = string_make( g_allocator, fmt );
|
|
|
|
result->Type = ECode::Untyped;
|
|
|
|
result->Content = string_make( g_allocator, buf );
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... )
|
|
|
|
{
|
2023-04-05 23:21:23 -07:00
|
|
|
local_persist thread_local
|
2023-04-05 00:03:56 -07:00
|
|
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
|
|
|
token_fmt_va(buf, ZPL_PRINTF_MAXLEN, fmt, num_tokens, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
Code
|
|
|
|
result = make_code();
|
|
|
|
result->Name = string_make( g_allocator, fmt );
|
|
|
|
result->Type = ECode::Untyped;
|
|
|
|
result->Content = string_make( g_allocator, buf );
|
|
|
|
|
|
|
|
result.lock();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
# pragma endregion Untyped Constructors
|
2023-04-06 16:19:11 -07:00
|
|
|
#pragma endregion Gen Interface
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-07 21:29:09 -07:00
|
|
|
#pragma region Builder
|
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
void Builder::print( Code code )
|
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
Buffer = string_append_fmt( Buffer, "%s\n\n", code->to_string() );
|
2023-04-01 22:07:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Builder::open( char const* path )
|
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
FileError error = file_open_mode( & File, EFileMode_WRITE, path );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-09 10:59:39 -07:00
|
|
|
if ( error != EFileError_NONE )
|
2023-04-01 22:07:44 -07:00
|
|
|
{
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure( "gen::File::open - Could not open file: %s", path);
|
2023-04-01 22:07:44 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer = string_make( g_allocator, "" );
|
2023-04-05 23:21:23 -07:00
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Builder::write()
|
|
|
|
{
|
|
|
|
bool result = file_write( & File, Buffer, string_length(Buffer) );
|
|
|
|
|
|
|
|
if ( result == false )
|
2023-04-09 10:59:39 -07:00
|
|
|
log_failure("gen::File::write - Failed to write to file: %s", file_name( & File ) );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-02 08:53:15 -07:00
|
|
|
// file_seek( & File, 0 );
|
2023-04-01 22:07:44 -07:00
|
|
|
file_close( & File );
|
|
|
|
}
|
2023-04-07 21:29:09 -07:00
|
|
|
#pragma endregion Builder
|
|
|
|
|
|
|
|
#pragma region Editor
|
|
|
|
#pragma endregion Editor
|
|
|
|
|
|
|
|
#pragma region Scanner
|
|
|
|
#pragma endregion Scanner
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
2023-04-01 22:07:44 -07:00
|
|
|
#endif
|