mirror of
https://github.com/Ed94/gencpp.git
synced 2024-11-10 02:54:53 -08:00
Changed zpl implemenation based on latest refactor script I use, refactored code to changes.
This commit is contained in:
parent
642fb16d4f
commit
56d7aa1d72
@ -9,7 +9,9 @@ namespace Global
|
|||||||
|
|
||||||
namespace Memory
|
namespace Memory
|
||||||
{
|
{
|
||||||
arena Global_Arena {};
|
using namespace zpl;
|
||||||
|
|
||||||
|
Arena Global_Arena {};
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@ -68,10 +70,10 @@ sw token_fmt_va( char* buf, uw buf_size, char const* fmt, s32 num_tokens, va_lis
|
|||||||
TokEntry entry
|
TokEntry entry
|
||||||
{
|
{
|
||||||
value,
|
value,
|
||||||
zpl_strnlen(value, (sw)128)
|
strnlen(value, (sw)128)
|
||||||
};
|
};
|
||||||
|
|
||||||
u32 key = crc32( token, zpl_strnlen(token, 32) );
|
u32 key = crc32( token, strnlen(token, 32) );
|
||||||
|
|
||||||
tokmap_set( & tok_map, key, entry );
|
tokmap_set( & tok_map, key, entry );
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
# define ZPL_IMPLEMENTATION
|
# define ZPL_IMPLEMENTATION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO: This will be removed when making the library have zero dependencies.
|
||||||
#pragma region ZPL INCLUDE
|
#pragma region ZPL INCLUDE
|
||||||
#if __clang__
|
#if __clang__
|
||||||
# pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
@ -18,6 +18,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// # define ZPL_HEAP_ANALYSIS
|
// # define ZPL_HEAP_ANALYSIS
|
||||||
|
# define ZPL_WRAP_IN_NAMESPACE
|
||||||
# define ZPL_NO_MATH_H
|
# define ZPL_NO_MATH_H
|
||||||
# define ZPL_CUSTOM_MODULES
|
# define ZPL_CUSTOM_MODULES
|
||||||
# define ZPL_MODULE_ESSENTIALS
|
# define ZPL_MODULE_ESSENTIALS
|
||||||
@ -35,6 +36,48 @@
|
|||||||
// # define ZPL_MODULE_PARSER
|
// # define ZPL_MODULE_PARSER
|
||||||
#include "zpl.h"
|
#include "zpl.h"
|
||||||
|
|
||||||
|
using zpl::s8;
|
||||||
|
using zpl::s16;
|
||||||
|
using zpl::s32;
|
||||||
|
using zpl::s64;
|
||||||
|
using zpl::u8;
|
||||||
|
using zpl::u32;
|
||||||
|
using zpl::u64;
|
||||||
|
using zpl::uw;
|
||||||
|
using zpl::sw;
|
||||||
|
|
||||||
|
using zpl::Arena;
|
||||||
|
using zpl::AllocatorInfo;
|
||||||
|
using zpl::ArrayHeader;
|
||||||
|
using zpl::FileInfo;
|
||||||
|
using zpl::FileError;
|
||||||
|
using zpl::Pool;
|
||||||
|
using zpl::String;
|
||||||
|
// using zpl::StringHeader;
|
||||||
|
|
||||||
|
using zpl::EFileMode_WRITE;
|
||||||
|
using zpl::EFileError_NONE;
|
||||||
|
|
||||||
|
using zpl::arena_allocator;
|
||||||
|
using zpl::arena_init_from_memory;
|
||||||
|
using zpl::arena_free;
|
||||||
|
using zpl::char_is_alpha;
|
||||||
|
using zpl::char_is_space;
|
||||||
|
using zpl::crc32;
|
||||||
|
using zpl::memset;
|
||||||
|
using zpl::pool_free;
|
||||||
|
using zpl::printf_va;
|
||||||
|
using zpl::printf_err_va;
|
||||||
|
using zpl::snprintf_va;
|
||||||
|
using zpl::string_appendc;
|
||||||
|
using zpl::string_append_fmt;
|
||||||
|
using zpl::string_append_length;
|
||||||
|
using zpl::string_length;
|
||||||
|
using zpl::string_make;
|
||||||
|
using zpl::strnlen;
|
||||||
|
// using zpl::
|
||||||
|
|
||||||
|
|
||||||
#if __clang__
|
#if __clang__
|
||||||
# pragma clang diagnostic pop
|
# pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
@ -135,7 +178,7 @@ namespace Memory
|
|||||||
{
|
{
|
||||||
ct uw Initial_Reserve = megabytes(10);
|
ct uw Initial_Reserve = megabytes(10);
|
||||||
|
|
||||||
extern arena Global_Arena;
|
extern Arena Global_Arena;
|
||||||
// #define g_allocator arena_allocator( & Memory::Global_Arena)
|
// #define g_allocator arena_allocator( & Memory::Global_Arena)
|
||||||
|
|
||||||
// Heap allocator is being used for now to isolate errors from being memory related (tech debt till ready to address)
|
// Heap allocator is being used for now to isolate errors from being memory related (tech debt till ready to address)
|
||||||
@ -172,7 +215,7 @@ sw log_fmt(char const *fmt, ...)
|
|||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
res = zpl_printf_va(fmt, va);
|
res = printf_va(fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -188,17 +231,17 @@ sw fatal(char const *fmt, ...)
|
|||||||
|
|
||||||
#if Build_Debug
|
#if Build_Debug
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
zpl::snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
assert_crash(buf);
|
assert_crash(buf);
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
#else
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
zpl_printf_err_va( fmt, va);
|
printf_err_va( fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
zpl_exit(1);
|
exit(1);
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
498
project/gen.cpp
498
project/gen.cpp
@ -4,14 +4,14 @@
|
|||||||
#ifdef gen_time
|
#ifdef gen_time
|
||||||
namespace gen
|
namespace gen
|
||||||
{
|
{
|
||||||
ZPL_TABLE_DEFINE( StringTable, str_tbl_, string );
|
ZPL_TABLE_DEFINE( StringTable, str_tbl_, String );
|
||||||
ZPL_TABLE_DEFINE( TypeTable, type_tbl_ , Code );
|
ZPL_TABLE_DEFINE( TypeTable, type_tbl_ , Code );
|
||||||
|
|
||||||
namespace StaticData
|
namespace StaticData
|
||||||
{
|
{
|
||||||
#ifndef GEN_CODE_USE_SOA
|
#ifndef GEN_CODE_USE_SOA
|
||||||
static array(pool) CodePools;
|
static Array(Pool) CodePools;
|
||||||
static array(pool) CodeEntriesPools;
|
static Array(Pool) CodeEntriesPools;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
using DataUnion = union
|
using DataUnion = union
|
||||||
@ -67,7 +67,7 @@ namespace gen
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static array(arena) StringArenas = nullptr;
|
static Array(Arena) StringArenas = nullptr;
|
||||||
|
|
||||||
static StringTable StringMap;
|
static StringTable StringMap;
|
||||||
static TypeTable TypeMap;
|
static TypeTable TypeMap;
|
||||||
@ -80,11 +80,11 @@ namespace gen
|
|||||||
|
|
||||||
static sw SizePer_StringArena = megabytes(32);
|
static sw SizePer_StringArena = megabytes(32);
|
||||||
|
|
||||||
static allocator Allocator_CodePool = heap();
|
static AllocatorInfo Allocator_CodePool = heap();
|
||||||
static allocator Allocator_CodeEntriesPool = heap();
|
static AllocatorInfo Allocator_CodeEntriesPool = heap();
|
||||||
static allocator Allocator_StringArena = heap();
|
static AllocatorInfo Allocator_StringArena = heap();
|
||||||
static allocator Allocator_StringTable = heap();
|
static AllocatorInfo Allocator_StringTable = heap();
|
||||||
static allocator Allocator_TypeTable = heap();
|
static AllocatorInfo Allocator_TypeTable = heap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region CONSTANTS
|
#pragma region CONSTANTS
|
||||||
@ -126,6 +126,21 @@ namespace gen
|
|||||||
case Untyped:
|
case Untyped:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Enum:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Enum_FwdDecl:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Enum_Body:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Enum_Class:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Enum_Class_FwdDecl:
|
||||||
|
break;
|
||||||
|
|
||||||
case Global_Body:
|
case Global_Body:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -177,7 +192,58 @@ namespace gen
|
|||||||
|
|
||||||
bool AST::check()
|
bool AST::check()
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AST* AST::duplicate()
|
AST* AST::duplicate()
|
||||||
@ -244,9 +310,9 @@ namespace gen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string AST::to_string() const
|
String AST::to_string() const
|
||||||
{
|
{
|
||||||
string result = string_make( g_allocator, "" );
|
String result = string_make( g_allocator, "" );
|
||||||
|
|
||||||
if ( Comment )
|
if ( Comment )
|
||||||
result = string_append_fmt( result, "// %s\n", Comment );
|
result = string_append_fmt( result, "// %s\n", Comment );
|
||||||
@ -256,44 +322,44 @@ namespace gen
|
|||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
case Invalid:
|
case Invalid:
|
||||||
fatal("Attempted to serialize invalid code! - %s", Name);
|
log_failure("Attempted to serialize invalid code! - %s", Name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Untyped:
|
case Untyped:
|
||||||
result = string_append_length( result, Content, string_length(Content) );
|
result = string_append_length( result, Content, string_length( ccast(String, Content)) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Function_FwdDecl:
|
case Access_Public:
|
||||||
{
|
case Access_Protected:
|
||||||
u32 index = 0;
|
case Access_Private:
|
||||||
u32 left = array_count( Entries );
|
result = string_append_length( result, Name, string_length( ccast(String, Name)) ) ;
|
||||||
|
break;
|
||||||
|
|
||||||
if ( left <= 0 )
|
case Class:
|
||||||
fatal( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
|
break;
|
||||||
|
|
||||||
if ( Entries[index]->Type == Specifiers )
|
case Class_FwdDecl:
|
||||||
{
|
break;
|
||||||
result = string_append_fmt( result, "%s\n", Entries[index]->to_string() );
|
|
||||||
index++;
|
|
||||||
left--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( left <= 0 )
|
case Class_Body:
|
||||||
fatal( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
|
break;
|
||||||
|
|
||||||
result = string_append_fmt( result, "\n%s %s(", Entries[index]->to_string(), Name );
|
case Enum:
|
||||||
index++;
|
break;
|
||||||
left--;
|
|
||||||
|
|
||||||
if ( left && Entries[index]->Type == Parameters )
|
case Enum_FwdDecl:
|
||||||
{
|
break;
|
||||||
result = string_append_fmt( result, "%s", Entries[index]->to_string() );
|
|
||||||
index++;
|
|
||||||
left--;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = string_appendc( result, ");\n" );
|
case Enum_Body:
|
||||||
}
|
break;
|
||||||
|
|
||||||
|
case Enum_Class:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Enum_Class_FwdDecl:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Friend:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Function:
|
case Function:
|
||||||
@ -302,7 +368,7 @@ namespace gen
|
|||||||
u32 left = array_count( Entries );
|
u32 left = array_count( Entries );
|
||||||
|
|
||||||
if ( left <= 0 )
|
if ( left <= 0 )
|
||||||
fatal( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
|
log_failure( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
|
||||||
|
|
||||||
if ( Entries[index]->Type == Specifiers )
|
if ( Entries[index]->Type == Specifiers )
|
||||||
{
|
{
|
||||||
@ -312,7 +378,7 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( left <= 0 )
|
if ( left <= 0 )
|
||||||
fatal( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
|
log_failure( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
|
||||||
|
|
||||||
result = string_append_fmt( result, "\n%s %s(", Entries[index]->to_string(), Name );
|
result = string_append_fmt( result, "\n%s %s(", Entries[index]->to_string(), Name );
|
||||||
index++;
|
index++;
|
||||||
@ -329,16 +395,58 @@ namespace gen
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Function_FwdDecl:
|
||||||
|
{
|
||||||
|
u32 index = 0;
|
||||||
|
u32 left = array_count( Entries );
|
||||||
|
|
||||||
|
if ( left <= 0 )
|
||||||
|
log_failure( "Code::to_string - Name: %s Type: %s, expected definition", Name, Type );
|
||||||
|
|
||||||
|
if ( Entries[index]->Type == Specifiers )
|
||||||
|
{
|
||||||
|
result = string_append_fmt( result, "%s\n", Entries[index]->to_string() );
|
||||||
|
index++;
|
||||||
|
left--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( left <= 0 )
|
||||||
|
log_failure( "Code::to_string - Name: %s Type: %s, expected return type", Name, Type );
|
||||||
|
|
||||||
|
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--;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = string_appendc( result, ");\n" );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case Function_Body:
|
case Function_Body:
|
||||||
fatal("NOT SUPPORTED YET");
|
log_failure("NOT SUPPORTED YET");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Global_Body:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Namespace:
|
case Namespace:
|
||||||
fatal("NOT SUPPORTED YET");
|
log_failure("NOT SUPPORTED YET");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Namespace_Body:
|
case Namespace_Body:
|
||||||
fatal("NOT SUPPORTED YET");
|
log_failure("NOT SUPPORTED YET");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Operator:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Operator_FwdDecl:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Parameters:
|
case Parameters:
|
||||||
@ -361,19 +469,22 @@ namespace gen
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Struct:
|
case Struct:
|
||||||
fatal("NOT SUPPORTED YET");
|
log_failure("NOT SUPPORTED YET");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Struct_FwdDecl:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Struct_Body:
|
case Struct_Body:
|
||||||
fatal("NOT SUPPORTED YET");
|
log_failure("NOT SUPPORTED YET");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Variable:
|
case Variable:
|
||||||
fatal("NOT SUPPORTED YET");
|
log_failure("NOT SUPPORTED YET");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Typedef:
|
case Typedef:
|
||||||
fatal("NOT SUPPORTED YET");
|
log_failure("NOT SUPPORTED YET");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Typename:
|
case Typename:
|
||||||
@ -381,7 +492,7 @@ namespace gen
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Using:
|
case Using:
|
||||||
fatal("NOT SUPPORTED YET");
|
log_failure("NOT SUPPORTED YET");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,10 +505,10 @@ namespace gen
|
|||||||
#pragma region Gen Interface
|
#pragma region Gen Interface
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
array_init( StaticData::CodePool, StaticData::Allocator_CodePool );
|
array_init( StaticData::CodePools, StaticData::Allocator_CodePool );
|
||||||
array_init( StaticData::StringArenas, heap() );
|
array_init( StaticData::StringArenas, heap() );
|
||||||
|
|
||||||
arena string_arena;
|
Arena string_arena;
|
||||||
arena_init_from_allocator( & string_arena, StaticData::Allocator_StringArena, StaticData::SizePer_StringArena );
|
arena_init_from_allocator( & string_arena, StaticData::Allocator_StringArena, StaticData::SizePer_StringArena );
|
||||||
|
|
||||||
str_tbl_init( & StaticData::StringMap, StaticData::Allocator_StringTable );
|
str_tbl_init( & StaticData::StringMap, StaticData::Allocator_StringTable );
|
||||||
@ -443,8 +554,8 @@ namespace gen
|
|||||||
spec_constexpr_write = ccast( Code, spec_constexpr );
|
spec_constexpr_write = ccast( Code, spec_constexpr );
|
||||||
spec_constexpr_write = def_specifiers( 1, ESpecifier::Constexpr );
|
spec_constexpr_write = def_specifiers( 1, ESpecifier::Constexpr );
|
||||||
|
|
||||||
# define def_constant_spec( Type_, ... ) \
|
# define def_constant_spec( Type_, ... ) \
|
||||||
Code& \
|
Code& \
|
||||||
spec_##Type_ = def_specifiers( macro_num_args(__VA_ARGS__), __VA_ARGS__); \
|
spec_##Type_ = def_specifiers( macro_num_args(__VA_ARGS__), __VA_ARGS__); \
|
||||||
spec_##Type_.lock();
|
spec_##Type_.lock();
|
||||||
|
|
||||||
@ -461,7 +572,7 @@ namespace gen
|
|||||||
s32 left = 0;
|
s32 left = 0;
|
||||||
while (( left-- ))
|
while (( left-- ))
|
||||||
{
|
{
|
||||||
pool* code_pool = & StaticData::CodePools[index];
|
Pool* code_pool = & StaticData::CodePools[index];
|
||||||
pool_free( code_pool );
|
pool_free( code_pool );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,7 +585,7 @@ namespace gen
|
|||||||
s32 left = 0;
|
s32 left = 0;
|
||||||
while (( left-- ))
|
while (( left-- ))
|
||||||
{
|
{
|
||||||
pool* code_entries_pool = & StaticData::CodeEntriesPools[index];
|
Pool* code_entries_pool = & StaticData::CodeEntriesPools[index];
|
||||||
pool_free( code_entries_pool );
|
pool_free( code_entries_pool );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,13 +593,13 @@ namespace gen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allocator get_string_allocator( s32 str_length )
|
AllocatorInfo get_string_allocator( s32 str_length )
|
||||||
{
|
{
|
||||||
using namespace StaticData;
|
using namespace StaticData;
|
||||||
|
|
||||||
if ( StringArenas->total_allocated + str_length > StringArenas->total_size )
|
if ( StringArenas->total_allocated + str_length > StringArenas->total_size )
|
||||||
{
|
{
|
||||||
arena new_arena;
|
Arena new_arena;
|
||||||
arena_init_from_allocator( & new_arena, Allocator_StringArena, SizePer_StringArena );
|
arena_init_from_allocator( & new_arena, Allocator_StringArena, SizePer_StringArena );
|
||||||
|
|
||||||
array_append( StringArenas, new_arena );
|
array_append( StringArenas, new_arena );
|
||||||
@ -506,7 +617,7 @@ namespace gen
|
|||||||
|
|
||||||
u32 key = crc32( cstr, hash_length );
|
u32 key = crc32( cstr, hash_length );
|
||||||
|
|
||||||
string* result = str_tbl_get( & StaticData::StringMap, key );
|
String* result = str_tbl_get( & StaticData::StringMap, key );
|
||||||
|
|
||||||
if ( result )
|
if ( result )
|
||||||
{
|
{
|
||||||
@ -532,11 +643,6 @@ namespace gen
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
array_append( CodePool, Invalid );
|
|
||||||
|
|
||||||
return pcast( Code, array_back( CodePool ));
|
|
||||||
|
|
||||||
|
|
||||||
# else
|
# else
|
||||||
|
|
||||||
array_append( CodePool::Type, ECode::Invalid );
|
array_append( CodePool::Type, ECode::Invalid );
|
||||||
@ -551,7 +657,7 @@ namespace gen
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
array(AST*) make_code_entries()
|
Array(AST*) make_code_entries()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -561,16 +667,26 @@ namespace gen
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_allocator_code_pool( AllocatorInfo pool_allocator )
|
||||||
|
{
|
||||||
|
StaticData::Allocator_CodePool = pool_allocator;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_allocator_string_arena( AllocatorInfo string_allocator )
|
||||||
|
{
|
||||||
|
StaticData::Allocator_StringArena = string_allocator;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_allocator_string_table( AllocatorInfo string_allocator )
|
||||||
|
{
|
||||||
|
StaticData::Allocator_StringArena = string_allocator;
|
||||||
|
}
|
||||||
|
|
||||||
void set_init_reserve_code_pool( sw size )
|
void set_init_reserve_code_pool( sw size )
|
||||||
{
|
{
|
||||||
StaticData::InitSize_CodePool = size;
|
StaticData::InitSize_CodePool = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_init_reserve_string_arena( sw size )
|
|
||||||
{
|
|
||||||
StaticData::InitSize_StringArena = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_init_reserve_string_table( sw size )
|
void set_init_reserve_string_table( sw size )
|
||||||
{
|
{
|
||||||
StaticData::InitSize_StringTable = size;
|
StaticData::InitSize_StringTable = size;
|
||||||
@ -581,42 +697,44 @@ namespace gen
|
|||||||
StaticData::InitSize_TypeTable = size;
|
StaticData::InitSize_TypeTable = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_allocator_code_pool( allocator pool_allocator )
|
void set_allocator_type_table( AllocatorInfo type_reg_allocator )
|
||||||
{
|
|
||||||
StaticData::Allocator_CodePool = pool_allocator;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_allocator_string_arena( allocator string_allocator )
|
|
||||||
{
|
|
||||||
StaticData::Allocator_StringArena = string_allocator;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_allocator_string_table( allocator string_allocator )
|
|
||||||
{
|
|
||||||
StaticData::Allocator_StringArena = string_allocator;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_allocator_type_table( allocator type_reg_allocator )
|
|
||||||
{
|
{
|
||||||
StaticData::Allocator_TypeTable = type_reg_allocator;
|
StaticData::Allocator_TypeTable = type_reg_allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_size_string_arena( sw size )
|
||||||
|
{
|
||||||
|
StaticData::SizePer_StringArena = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# pragma region Upfront Constructors
|
# pragma region Upfront Constructors
|
||||||
Code def_class( s32 length, char const* name, Code parent, Code specifiers, Code body )
|
Code def_class( s32 length, char const* name, Code parent, Code specifiers, Code body )
|
||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
if ( length <= 0 )
|
name_check( def_class, length, name );
|
||||||
{
|
|
||||||
log_failure( "gen::def_class: Invalid name length provided - %d", length );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name == nullptr )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_class: name is null");
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( parent && parent->Type != Class || parent->Type != Struct )
|
if ( parent && parent->Type != Class || parent->Type != Struct )
|
||||||
{
|
{
|
||||||
@ -634,8 +752,6 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = cached_string( name, length );
|
result->Name = cached_string( name, length );
|
||||||
|
|
||||||
array_init( result->Entries, StaticData::Allocator_CodePool );
|
|
||||||
|
|
||||||
if ( body )
|
if ( body )
|
||||||
{
|
{
|
||||||
switch ( body->Type )
|
switch ( body->Type )
|
||||||
@ -649,7 +765,8 @@ namespace gen
|
|||||||
return Code::Invalid;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
result->Type = Class;
|
result->Type = Class;
|
||||||
|
result->Entries = make_code_entries();
|
||||||
result->add_entry( body );
|
result->add_entry( body );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -671,17 +788,7 @@ namespace gen
|
|||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
if ( length <= 0 )
|
name_check( def_enum, length, name );
|
||||||
{
|
|
||||||
log_failure( "gen::def_enum: Invalid name length provided - %d", length );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name == nullptr )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_class: name is null" );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( type && type->Type != Typename )
|
if ( type && type->Type != Typename )
|
||||||
{
|
{
|
||||||
@ -709,6 +816,7 @@ namespace gen
|
|||||||
result->Type = specifier == EnumClass ?
|
result->Type = specifier == EnumClass ?
|
||||||
Enum_Class : Enum;
|
Enum_Class : Enum;
|
||||||
|
|
||||||
|
result->Entries = make_code_entries();
|
||||||
result->add_entry( body );
|
result->add_entry( body );
|
||||||
}
|
}
|
||||||
else if ( specifier == EnumClass )
|
else if ( specifier == EnumClass )
|
||||||
@ -726,6 +834,37 @@ namespace gen
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Code def_function( s32 length, char const* name
|
Code def_function( s32 length, char const* name
|
||||||
, Code specifiers
|
, Code specifiers
|
||||||
, Code params
|
, Code params
|
||||||
@ -735,17 +874,7 @@ namespace gen
|
|||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
if ( length <= 0 )
|
name_check( def_function, length, name );
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: Invalid name length provided - %d", length );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name == nullptr )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: name is null" );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( specifiers && specifiers->Type != Specifiers )
|
if ( specifiers && specifiers->Type != Specifiers )
|
||||||
{
|
{
|
||||||
@ -817,17 +946,7 @@ namespace gen
|
|||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
if ( length <= 0 )
|
name_check( def_namespace, length, name );
|
||||||
{
|
|
||||||
log_failure( "gen::def_namespace: Invalid name length provided - %d", length );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name == nullptr )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_namespace: name is null" );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
@ -881,17 +1000,7 @@ namespace gen
|
|||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
if ( length <= 0 )
|
name_check( def_struct, length, name );
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: Invalid name length provided - %d", length );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name == nullptr )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: name is null" );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( specifiers && specifiers->Type != Specifiers )
|
if ( specifiers && specifiers->Type != Specifiers )
|
||||||
{
|
{
|
||||||
@ -912,11 +1021,10 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Struct;
|
result->Type = Struct;
|
||||||
result->Name = cached_string( name, length );
|
result->Name = cached_string( name, length );
|
||||||
|
result->Entries = make_code_entries();
|
||||||
array_init( result->Entries, g_allocator );
|
|
||||||
|
|
||||||
if ( body )
|
if ( body )
|
||||||
result->add_entry( body );
|
result->add_entry( body );
|
||||||
@ -932,17 +1040,7 @@ namespace gen
|
|||||||
|
|
||||||
Code def_variable( Code type, u32 length, char const* name, Code value, Code specifiers )
|
Code def_variable( Code type, u32 length, char const* name, Code value, Code specifiers )
|
||||||
{
|
{
|
||||||
if ( length <= 0 )
|
name_check( def_variable, length, name );
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: Invalid name length provided - %d", length );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name == nullptr )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: name is null" );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( specifiers && specifiers->Type != ECode::Specifiers )
|
if ( specifiers && specifiers->Type != ECode::Specifiers )
|
||||||
{
|
{
|
||||||
@ -963,11 +1061,10 @@ namespace gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = cached_string( name, length );
|
result->Name = cached_string( name, length );
|
||||||
result->Type = ECode::Variable;
|
result->Type = ECode::Variable;
|
||||||
|
result->Entries = make_code_entries();
|
||||||
array_init( result->Entries, g_allocator );
|
|
||||||
|
|
||||||
if ( specifiers )
|
if ( specifiers )
|
||||||
result->add_entry( specifiers );
|
result->add_entry( specifiers );
|
||||||
@ -982,17 +1079,7 @@ namespace gen
|
|||||||
|
|
||||||
Code def_type( u32 length, char const* name, Code specifiers )
|
Code def_type( u32 length, char const* name, Code specifiers )
|
||||||
{
|
{
|
||||||
if ( length <= 0 )
|
name_check( def_type, length, name );
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: Invalid name length provided - %d", length );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name == nullptr )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: name is null" );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
@ -1004,17 +1091,7 @@ namespace gen
|
|||||||
|
|
||||||
Code def_using( u32 length, char const* name, Code type, UsingT specifier )
|
Code def_using( u32 length, char const* name, Code type, UsingT specifier )
|
||||||
{
|
{
|
||||||
if ( length <= 0 )
|
name_check( def_using, length, name );
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: Invalid name length provided - %d", length );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( name == nullptr )
|
|
||||||
{
|
|
||||||
log_failure( "gen::def_function: name is null" );
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
@ -1259,7 +1336,7 @@ namespace gen
|
|||||||
Code type = va_arg(va, Code);
|
Code type = va_arg(va, Code);
|
||||||
|
|
||||||
char const* name = va_arg(va, char const*);
|
char const* name = va_arg(va, char const*);
|
||||||
s32 name_length = zpl_strnlen(name, MaxNameLength);
|
s32 name_length = strnlen(name, MaxNameLength);
|
||||||
|
|
||||||
result->Name = cached_string( name, name_length );
|
result->Name = cached_string( name, name_length );
|
||||||
|
|
||||||
@ -1278,7 +1355,7 @@ namespace gen
|
|||||||
type = va_arg(va, Code);
|
type = va_arg(va, Code);
|
||||||
|
|
||||||
name = va_arg(va, char const*);
|
name = va_arg(va, char const*);
|
||||||
name_length = zpl_strnlen(name, MaxNameLength);
|
name_length = strnlen(name, MaxNameLength);
|
||||||
|
|
||||||
Code
|
Code
|
||||||
param = make_code();
|
param = make_code();
|
||||||
@ -1312,12 +1389,12 @@ namespace gen
|
|||||||
Code def_specifiers( s32 num, ... )
|
Code def_specifiers( s32 num, ... )
|
||||||
{
|
{
|
||||||
if ( num <= 0 )
|
if ( num <= 0 )
|
||||||
fatal("gen::make_specifier: num cannot be zero or less");
|
log_failure("gen::make_specifier: num cannot be zero or less");
|
||||||
|
|
||||||
// This should be more than enough...
|
// This should be more than enough...
|
||||||
static u8 FixedSizedBuffer[kilobytes(1024)];
|
static u8 FixedSizedBuffer[kilobytes(1024)];
|
||||||
|
|
||||||
static arena str_arena;
|
static Arena str_arena;
|
||||||
do_once_start
|
do_once_start
|
||||||
arena_init_from_memory( & str_arena, FixedSizedBuffer, kilobytes(1024) );
|
arena_init_from_memory( & str_arena, FixedSizedBuffer, kilobytes(1024) );
|
||||||
do_once_end
|
do_once_end
|
||||||
@ -1326,7 +1403,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = ECode::Specifiers;
|
result->Type = ECode::Specifiers;
|
||||||
|
|
||||||
string crafted = string_make( arena_allocator( & str_arena ), "" );
|
String crafted = string_make( arena_allocator( & str_arena ), "" );
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
@ -1337,13 +1414,13 @@ namespace gen
|
|||||||
switch ( type )
|
switch ( type )
|
||||||
{
|
{
|
||||||
case ESpecifier::Alignas:
|
case ESpecifier::Alignas:
|
||||||
crafted = string_append_fmt( result->Content, "%s(%d)", ESpecifier::to_str(type), va_arg(va, u32) );
|
crafted = string_append_fmt( (String)result->Content, "%s(%d)", ESpecifier::to_str(type), va_arg(va, u32) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
const char* str = ESpecifier::to_str(type);
|
const char* str = ESpecifier::to_str(type);
|
||||||
|
|
||||||
crafted = string_append_fmt( result->Content, "%s", str );
|
crafted = string_append_fmt( (String)result->Content, "%s", str );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1429,6 +1506,8 @@ namespace gen
|
|||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
|
name_check( make_function, length, name );
|
||||||
|
|
||||||
if ( specifiers && specifiers->Type != Specifiers )
|
if ( specifiers && specifiers->Type != Specifiers )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_function: specifiers was not a `Specifiers` type" );
|
log_failure( "gen::def_function: specifiers was not a `Specifiers` type" );
|
||||||
@ -1472,14 +1551,15 @@ namespace gen
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code make_global_body( char const* name = "", s32 num = 0, ... )
|
Code make_global_body( s32 length, char const* name, s32 num, ... )
|
||||||
{
|
{
|
||||||
Code
|
name_check( make_global_body, length, name );
|
||||||
result = make_code();
|
|
||||||
result->Type = ECode::Global_Body;
|
|
||||||
result->Name = string_make( g_allocator, "");
|
|
||||||
|
|
||||||
array_init( result->Entries, g_allocator );
|
Code
|
||||||
|
result = make_code();
|
||||||
|
result->Type = ECode::Global_Body;
|
||||||
|
result->Name = cached_string( name, length );
|
||||||
|
result->Entries = make_code_entries();
|
||||||
|
|
||||||
// Making body at entry 0;
|
// Making body at entry 0;
|
||||||
result->add_entry( make_code() );
|
result->add_entry( make_code() );
|
||||||
@ -1507,10 +1587,12 @@ namespace gen
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Code make_struct( char const* name, Code parent, Code specifiers )
|
Code make_struct( s32 length, char const* name, Code parent, Code specifiers )
|
||||||
{
|
{
|
||||||
using namespace ECode;
|
using namespace ECode;
|
||||||
|
|
||||||
|
name_check( make_struct, length, name );
|
||||||
|
|
||||||
if ( specifiers && specifiers->Type != Specifiers )
|
if ( specifiers && specifiers->Type != Specifiers )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
|
log_failure( "gen::def_struct: specifiers was not a `Specifiers` type" );
|
||||||
@ -1527,7 +1609,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Struct;
|
result->Type = Struct;
|
||||||
result->Name = string_make( g_allocator, name );
|
result->Name = string_make( g_allocator, name );
|
||||||
result->Entires = make_code_entries();
|
result->Entries = make_code_entries();
|
||||||
|
|
||||||
Code
|
Code
|
||||||
body = make_code();
|
body = make_code();
|
||||||
@ -1575,7 +1657,7 @@ namespace gen
|
|||||||
return Code::Invalid;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
arena mem;
|
Arena mem;
|
||||||
do_once_start
|
do_once_start
|
||||||
{
|
{
|
||||||
arena_init_from_allocator( & mem, heap(), kilobytes( 10 ) );
|
arena_init_from_allocator( & mem, heap(), kilobytes( 10 ) );
|
||||||
@ -1600,7 +1682,7 @@ namespace gen
|
|||||||
Param Params[ 64 ] { 0 };
|
Param Params[ 64 ] { 0 };
|
||||||
|
|
||||||
// Zero out params before a run of this func.
|
// Zero out params before a run of this func.
|
||||||
zpl_memset( Params, 0, sizeof( Params ));
|
memset( Params, 0, sizeof( Params ));
|
||||||
|
|
||||||
char const* name;
|
char const* name;
|
||||||
s32 name_length = 0;
|
s32 name_length = 0;
|
||||||
@ -1741,7 +1823,7 @@ namespace gen
|
|||||||
|
|
||||||
Code parse_struct( s32 length, char const* def )
|
Code parse_struct( s32 length, char const* def )
|
||||||
{
|
{
|
||||||
arena mem;
|
Arena mem;
|
||||||
do_once_start
|
do_once_start
|
||||||
arena_init_from_allocator( & mem, heap(), kilobytes( 10 ) );
|
arena_init_from_allocator( & mem, heap(), kilobytes( 10 ) );
|
||||||
do_once_end
|
do_once_end
|
||||||
@ -1848,7 +1930,7 @@ namespace gen
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
Code
|
Code
|
||||||
@ -1892,11 +1974,11 @@ namespace gen
|
|||||||
|
|
||||||
bool Builder::open( char const* path )
|
bool Builder::open( char const* path )
|
||||||
{
|
{
|
||||||
file_error error = file_open_mode( & File, ZPL_FILE_MODE_WRITE, path );
|
FileError error = file_open_mode( & File, EFileMode_WRITE, path );
|
||||||
|
|
||||||
if ( error != ZPL_FILE_ERROR_NONE )
|
if ( error != EFileError_NONE )
|
||||||
{
|
{
|
||||||
fatal( "gen::File::open - Could not open file: %s", path);
|
log_failure( "gen::File::open - Could not open file: %s", path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1910,7 +1992,7 @@ namespace gen
|
|||||||
bool result = file_write( & File, Buffer, string_length(Buffer) );
|
bool result = file_write( & File, Buffer, string_length(Buffer) );
|
||||||
|
|
||||||
if ( result == false )
|
if ( result == false )
|
||||||
fatal("gen::File::write - Failed to write to file: %s", file_name( & File ) );
|
log_failure("gen::File::write - Failed to write to file: %s", file_name( & File ) );
|
||||||
|
|
||||||
// file_seek( & File, 0 );
|
// file_seek( & File, 0 );
|
||||||
file_close( & File );
|
file_close( & File );
|
||||||
|
116
project/gen.hpp
116
project/gen.hpp
@ -368,7 +368,7 @@ namespace gen
|
|||||||
Entry( Namespace ) \
|
Entry( Namespace ) \
|
||||||
Entry( Namespace_Body ) \
|
Entry( Namespace_Body ) \
|
||||||
Entry( Operator ) \
|
Entry( Operator ) \
|
||||||
Entry( Operator_Fwd ) \
|
Entry( Operator_FwdDecl ) \
|
||||||
Entry( Parameters ) \
|
Entry( Parameters ) \
|
||||||
Entry( Specifiers ) \
|
Entry( Specifiers ) \
|
||||||
Entry( Struct ) \
|
Entry( Struct ) \
|
||||||
@ -580,7 +580,7 @@ namespace gen
|
|||||||
{
|
{
|
||||||
char const* enum_str = to_str( (Type)index );
|
char const* enum_str = to_str( (Type)index );
|
||||||
|
|
||||||
keymap[index] = crc32( enum_str, zpl_strnlen(enum_str, 42) );
|
keymap[index] = crc32( enum_str, strnlen(enum_str, 42) );
|
||||||
}
|
}
|
||||||
do_once_end
|
do_once_end
|
||||||
|
|
||||||
@ -684,7 +684,7 @@ namespace gen
|
|||||||
// Thus if its desired to keep the debug str
|
// Thus if its desired to keep the debug str
|
||||||
// for multiple calls to bprintf,
|
// for multiple calls to bprintf,
|
||||||
// allocate this to proper string.
|
// allocate this to proper string.
|
||||||
return bprintf( fmt
|
return zpl::bprintf( fmt
|
||||||
, type_str()
|
, type_str()
|
||||||
, Readonly ? "true" : "false"
|
, Readonly ? "true" : "false"
|
||||||
, Parent ? Parent->Name : ""
|
, Parent ? Parent->Name : ""
|
||||||
@ -699,7 +699,7 @@ namespace gen
|
|||||||
return ECode::str( Type );
|
return ECode::str( Type );
|
||||||
}
|
}
|
||||||
|
|
||||||
string to_string() const;
|
String to_string() const;
|
||||||
# pragma endregion Member Functions
|
# pragma endregion Member Functions
|
||||||
|
|
||||||
# define Using_Code_POD \
|
# define Using_Code_POD \
|
||||||
@ -707,7 +707,7 @@ namespace gen
|
|||||||
string_const Name; \
|
string_const Name; \
|
||||||
string_const Comment; \
|
string_const Comment; \
|
||||||
union { \
|
union { \
|
||||||
array(AST*) Entries; \
|
Array(AST*) Entries; \
|
||||||
string_const Content; \
|
string_const Content; \
|
||||||
}; \
|
}; \
|
||||||
CodeT Type; \
|
CodeT Type; \
|
||||||
@ -851,7 +851,7 @@ namespace gen
|
|||||||
/*
|
/*
|
||||||
Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
||||||
*/
|
*/
|
||||||
ZPL_TABLE_DECLARE( ZPL_EXTERN, StringTable, str_tbl_, string );
|
ZPL_TABLE_DECLARE( ZPL_EXTERN, StringTable, str_tbl_, String );
|
||||||
|
|
||||||
// Represents strings cached with the string table.
|
// Represents strings cached with the string table.
|
||||||
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
||||||
@ -895,20 +895,21 @@ namespace gen
|
|||||||
This provides a fresh Code AST array for the entries field of the AST.
|
This provides a fresh Code AST array for the entries field of the AST.
|
||||||
This is done separately from the regular CodePool allocator.
|
This is done separately from the regular CodePool allocator.
|
||||||
*/
|
*/
|
||||||
array(AST*) make_code_entries();
|
Array(AST*) make_code_entries();
|
||||||
|
|
||||||
// Set these before calling gen's init() procedure.
|
// Set these before calling gen's init() procedure.
|
||||||
|
|
||||||
|
void set_allocator_code_pool ( AllocatorInfo pool_allocator );
|
||||||
|
void set_allocator_string_arena( AllocatorInfo string_allocator );
|
||||||
|
void set_allocator_string_table( AllocatorInfo string_allocator );
|
||||||
|
void set_allocator_type_table ( AllocatorInfo type_reg_allocator );
|
||||||
|
|
||||||
void set_init_reserve_code_pool ( sw size );
|
void set_init_reserve_code_pool ( sw size );
|
||||||
void set_init_reserve_code_entries_pool( sw size );
|
void set_init_reserve_code_entries_pool( sw size );
|
||||||
void set_init_reserve_string_arena ( sw size );
|
|
||||||
void set_init_reserve_string_table ( sw size );
|
void set_init_reserve_string_table ( sw size );
|
||||||
void set_init_reserve_type_table ( sw size );
|
void set_init_reserve_type_table ( sw size );
|
||||||
|
|
||||||
void set_allocator_code_pool ( allocator pool_allocator );
|
void set_size_string_arena( sw size );
|
||||||
void set_allocator_string_arena( allocator string_allocator );
|
|
||||||
void set_allocator_string_table( allocator string_allocator );
|
|
||||||
void set_allocator_type_table ( allocator type_reg_allocator );
|
|
||||||
|
|
||||||
# pragma region Upfront
|
# pragma region Upfront
|
||||||
Code def_class ( char const* name, Code parent = NoCode, Code specifiers = NoCode, Code body = NoCode );
|
Code def_class ( char const* name, Code parent = NoCode, Code specifiers = NoCode, Code body = NoCode );
|
||||||
@ -945,7 +946,6 @@ namespace gen
|
|||||||
Code def_function_body ( s32 num, Code* codes );
|
Code def_function_body ( s32 num, Code* codes );
|
||||||
Code def_namespace_body ( s32 num, ... );
|
Code def_namespace_body ( s32 num, ... );
|
||||||
Code def_params ( s32 num, ... );
|
Code def_params ( s32 num, ... );
|
||||||
Code def_params_macro ( s32 num, ... );
|
|
||||||
Code def_params ( s32 num, Code* params );
|
Code def_params ( s32 num, Code* params );
|
||||||
Code def_specifiers ( s32 num , ... );
|
Code def_specifiers ( s32 num , ... );
|
||||||
Code def_specifiers ( s32 num, SpecifierT* specs );
|
Code def_specifiers ( s32 num, SpecifierT* specs );
|
||||||
@ -954,21 +954,21 @@ namespace gen
|
|||||||
# pragma endregion Upfront
|
# pragma endregion Upfront
|
||||||
|
|
||||||
# pragma region Incremental
|
# pragma region Incremental
|
||||||
Code make_class ( char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
Code make_class ( char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
||||||
Code make_class ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
Code make_class ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
||||||
Code make_enum ( char const* name, Code type = NoCode, EnumT specifier = EnumRegular );
|
Code make_enum ( char const* name, Code type = NoCode, EnumT specifier = EnumRegular );
|
||||||
Code make_enum ( s32 length, char const* name, Code type = NoCode, EnumT specifier = EnumRegular );
|
Code make_enum ( s32 length, char const* name, Code type = NoCode, EnumT specifier = EnumRegular );
|
||||||
Code make_function ( char const* name, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
Code make_function ( char const* name, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
||||||
Code make_function ( s32 length, char const* name, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
Code make_function ( s32 length, char const* name, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
||||||
Code make_global_body ( char const* name = "", s32 num = 0, ... );
|
Code make_global_body ( char const* name = "", s32 num = 0, ... );
|
||||||
Code make_global_body ( s32 length, char const* name = "", s32 num = 0, ... );
|
Code make_global_body ( s32 length = 1, char const* name = "", s32 num = 0, ... );
|
||||||
Code make_namespace ( char const* name );
|
Code make_namespace ( char const* name );
|
||||||
Code make_namespace ( s32 length, char const* name );
|
Code make_namespace ( s32 length, char const* name );
|
||||||
Code make_operator ( OperatorT op, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
Code make_operator ( OperatorT op, Code params = NoCode, Code ret_type = NoCode, Code specifiers = NoCode );
|
||||||
Code make_params ();
|
Code make_params ();
|
||||||
Code make_specifiers ();
|
Code make_specifiers ();
|
||||||
Code make_struct ( char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
Code make_struct ( char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
||||||
Code make_struct ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
Code make_struct ( s32 length, char const* name, Code parent = NoCode, Code specifiers = NoCode );
|
||||||
# pragma endregion Incremental
|
# pragma endregion Incremental
|
||||||
|
|
||||||
# pragma region Parsing
|
# pragma region Parsing
|
||||||
@ -1006,8 +1006,8 @@ namespace gen
|
|||||||
|
|
||||||
struct Builder
|
struct Builder
|
||||||
{
|
{
|
||||||
zpl_file File;
|
FileInfo File;
|
||||||
string Buffer;
|
String Buffer;
|
||||||
|
|
||||||
void print( Code );
|
void print( Code );
|
||||||
|
|
||||||
@ -1054,7 +1054,7 @@ namespace gen
|
|||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
SymbolData Symbol;
|
SymbolData Symbol;
|
||||||
string Specification;
|
String Specification;
|
||||||
};
|
};
|
||||||
RequestType Type;
|
RequestType Type;
|
||||||
};
|
};
|
||||||
@ -1067,13 +1067,13 @@ namespace gen
|
|||||||
bool Result;
|
bool Result;
|
||||||
};
|
};
|
||||||
|
|
||||||
static allocator Allocator;
|
static AllocatorInfo Allocator;
|
||||||
|
|
||||||
static void set_allocator( allocator mem_allocator );
|
static void set_allocator( AllocatorInfo allocator );
|
||||||
|
|
||||||
array(zpl_file) Files;
|
Array(FileInfo) Files;
|
||||||
string Buffer;
|
String Buffer;
|
||||||
array(RequestEntry) Requests;
|
Array(RequestEntry) Requests;
|
||||||
|
|
||||||
void add_files( s32 num, char const** files );
|
void add_files( s32 num, char const** files );
|
||||||
|
|
||||||
@ -1085,7 +1085,7 @@ namespace gen
|
|||||||
void refactor( char const* file_path, char const* specification_path );
|
void refactor( char const* file_path, char const* specification_path );
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
bool process_requests( array(Receipt) out_receipts );
|
bool process_requests( Array(Receipt) out_receipts );
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1104,19 +1104,19 @@ namespace gen
|
|||||||
bool Result;
|
bool Result;
|
||||||
};
|
};
|
||||||
|
|
||||||
allocator Allocator;
|
AllocatorInfo MemAlloc;
|
||||||
|
|
||||||
static void set_allocator( allocator mem_allocator );
|
static void set_allocator( AllocatorInfo allocator );
|
||||||
|
|
||||||
array(zpl_file) Files;
|
Array(FileInfo) Files;
|
||||||
string Buffer;
|
String Buffer;
|
||||||
array(RequestEntry) Requests;
|
Array(RequestEntry) Requests;
|
||||||
|
|
||||||
void add_files( s32 num, char const** files );
|
void add_files( s32 num, char const** files );
|
||||||
|
|
||||||
void add( SymbolInfo signature, Policy policy );
|
void add( SymbolInfo signature, Policy policy );
|
||||||
|
|
||||||
bool process_requests( array(Receipt) out_receipts );
|
bool process_requests( Array(Receipt) out_receipts );
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
#pragma endregion Gen Interface
|
#pragma endregion Gen Interface
|
||||||
@ -1175,8 +1175,8 @@ namespace gen
|
|||||||
# define macrofn_chooser(_f0, _f1, _f2, _f3, _f4, _f5, _f6, _f7, _f8, _f9, _f10, _f11, _f12, _f13, _f14, _f15, _f16, ...) _f16
|
# define macrofn_chooser(_f0, _f1, _f2, _f3, _f4, _f5, _f6, _f7, _f8, _f9, _f10, _f11, _f12, _f13, _f14, _f15, _f16, ...) _f16
|
||||||
# define macrofn_recomposer(ArgsWithParentheses_) macrofn_chooser ArgsWithParentheses_
|
# define macrofn_recomposer(ArgsWithParentheses_) macrofn_chooser ArgsWithParentheses_
|
||||||
# define macrofn_chose_from_arg_num(F, ...) macrofn_recomposer((__VA_ARGS__, F##_16, F##_15, F##_14, F##_13, F##_12, F##_11, F##_10, F##_9, F##_8, F##_7, F##_6, F##_5, F##_4, F##_3, F##_2, F##_1, ))
|
# define macrofn_chose_from_arg_num(F, ...) macrofn_recomposer((__VA_ARGS__, F##_16, F##_15, F##_14, F##_13, F##_12, F##_11, F##_10, F##_9, F##_8, F##_7, F##_6, F##_5, F##_4, F##_3, F##_2, F##_1, ))
|
||||||
# define marcofn_no_arg_expander(Func) ,,,,,,,,,,,,,,,,Func_ ## _0
|
# define marcofn_no_arg_expander(Func_) ,,,,,,,,,,,,,,,,Func_ ## _0
|
||||||
# define macrofn_finder(Func_, ...) macrofn_chose_from_arg_num(Func_, tbc_marcofn_no_arg_expander __VA_ARGS__ (Func_))
|
# define macrofn_finder(Func_, ...) macrofn_chose_from_arg_num(Func_, marcofn_no_arg_expander __VA_ARGS__ (Func_))
|
||||||
# define macrofn_polymorphic(Func_, ...) macrofn_finder(Func_, __VA_ARGS__)(__VA_ARGS__)
|
# define macrofn_polymorphic(Func_, ...) macrofn_finder(Func_, __VA_ARGS__)(__VA_ARGS__)
|
||||||
|
|
||||||
# define function_5( Name_, Params_, RetType_, Specifiers_, Body_ ) gen::def_function( txt_n_len( Name_ ), macro_expand( Params_ ), type_ns(RetType_), Specifiers_, Body_ )
|
# define function_5( Name_, Params_, RetType_, Specifiers_, Body_ ) gen::def_function( txt_n_len( Name_ ), macro_expand( Params_ ), type_ns(RetType_), Specifiers_, Body_ )
|
||||||
@ -1306,91 +1306,91 @@ namespace gen
|
|||||||
forceinline
|
forceinline
|
||||||
Code def_class( char const* name, Code parent, Code specifiers, Code body )
|
Code def_class( char const* name, Code parent, Code specifiers, Code body )
|
||||||
{
|
{
|
||||||
return def_class( zpl_strnlen( name, MaxNameLength ), name, parent, specifiers, body );
|
return def_class( strnlen( name, MaxNameLength ), name, parent, specifiers, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code def_enum( char const* name, Code type, EnumT specifier, Code body )
|
Code def_enum( char const* name, Code type, EnumT specifier, Code body )
|
||||||
{
|
{
|
||||||
return def_enum( zpl_strnlen( name, MaxNameLength ), name, type, specifier, body );
|
return def_enum( strnlen( name, MaxNameLength ), name, type, specifier, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code def_function( char const* name, Code params, Code ret_type, Code specifiers, Code body )
|
Code def_function( char const* name, Code params, Code ret_type, Code specifiers, Code body )
|
||||||
{
|
{
|
||||||
return def_function( zpl_strnlen( name, MaxNameLength), name, params, ret_type, specifiers, body );
|
return def_function( strnlen( name, MaxNameLength), name, params, ret_type, specifiers, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code def_namespace( char const* name, Code body )
|
Code def_namespace( char const* name, Code body )
|
||||||
{
|
{
|
||||||
return def_namespace( zpl_strnlen( name, MaxNameLength), name, body );
|
return def_namespace( strnlen( name, MaxNameLength), name, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code def_param( Code type, char const* name )
|
Code def_param( Code type, char const* name )
|
||||||
{
|
{
|
||||||
return def_param( type, zpl_strnlen( name, MaxNameLength ), name );
|
return def_param( type, strnlen( name, MaxNameLength ), name );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code def_struct( char const* name, Code parent, Code specifiers, Code body )
|
Code def_struct( char const* name, Code parent, Code specifiers, Code body )
|
||||||
{
|
{
|
||||||
return def_struct( zpl_strnlen( name, MaxNameLength), name, parent, specifiers, body );
|
return def_struct( strnlen( name, MaxNameLength), name, parent, specifiers, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code def_type( char const* name, Code specifiers )
|
Code def_type( char const* name, Code specifiers )
|
||||||
{
|
{
|
||||||
return def_type( zpl_strnlen( name, MaxNameLength ), name, specifiers );
|
return def_type( strnlen( name, MaxNameLength ), name, specifiers );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code def_using( char const* name, Code type, UsingT specifier )
|
Code def_using( char const* name, Code type, UsingT specifier )
|
||||||
{
|
{
|
||||||
return def_using( zpl_strnlen( name, MaxNameLength ), name, type, specifier );
|
return def_using( strnlen( name, MaxNameLength ), name, type, specifier );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code def_variable( Code type, char const* name, Code value, Code specifiers )
|
Code def_variable( Code type, char const* name, Code value, Code specifiers )
|
||||||
{
|
{
|
||||||
return def_variable( type, zpl_strnlen(name, MaxNameLength ), name, value, specifiers );
|
return def_variable( type, strnlen(name, MaxNameLength ), name, value, specifiers );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code make_class( char const* name, Code parent, Code specifiers )
|
Code make_class( char const* name, Code parent, Code specifiers )
|
||||||
{
|
{
|
||||||
return make_class( zpl_strnlen(name, MaxNameLength), name, parent, specifiers );
|
return make_class( strnlen(name, MaxNameLength), name, parent, specifiers );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code make_enum( char const* name, Code type, Code specifiers )
|
Code make_enum( char const* name, Code type, Code specifiers )
|
||||||
{
|
{
|
||||||
return make_struct( zpl_strnlen(name, MaxNameLength), name, type, specifiers );
|
return make_struct( strnlen(name, MaxNameLength), name, type, specifiers );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code make_function( char const* name, Code params, Code ret_type, Code specifiers )
|
Code make_function( char const* name, Code params, Code ret_type, Code specifiers )
|
||||||
{
|
{
|
||||||
return make_function( zpl_strnlen(name, MaxNameLength), name, params, ret_type, specifiers );
|
return make_function( strnlen(name, MaxNameLength), name, params, ret_type, specifiers );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code make_namespace( char const* name )
|
Code make_namespace( char const* name )
|
||||||
{
|
{
|
||||||
return make_namespace( zpl_strnlen( name, MaxNameLength ), name );
|
return make_namespace( strnlen( name, MaxNameLength ), name );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code make_struct( char const* name, Code parent, Code specifiers )
|
Code make_struct( char const* name, Code parent, Code specifiers )
|
||||||
{
|
{
|
||||||
return make_struct( zpl_strnlen(name, MaxNameLength), name, parent, specifiers );
|
return make_struct( strnlen(name, MaxNameLength), name, parent, specifiers );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
Code untyped_str( char const* str )
|
Code untyped_str( char const* str )
|
||||||
{
|
{
|
||||||
return untyped_str( zpl_strnlen( str, MaxUntypedStrLength ), str );
|
return untyped_str( strnlen( str, MaxUntypedStrLength ), str );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma endregion Gen Interface Inlines
|
#pragma endregion Gen Interface Inlines
|
||||||
|
39145
thirdparty/zpl.h
vendored
39145
thirdparty/zpl.h
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user