mirror of
https://github.com/Ed94/gencpp.git
synced 2024-11-10 02:54:53 -08:00
Added spec_auto to constants, finished Array.NonParsed.hpp
Adjusted the generated array to the desired design for now. Moving on to making the next container
This commit is contained in:
parent
352da126ca
commit
5006449665
@ -26,6 +26,7 @@ namespace gen
|
|||||||
|
|
||||||
#pragma region Constants
|
#pragma region Constants
|
||||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||||
|
Code type_ns(auto);
|
||||||
Code type_ns(void);
|
Code type_ns(void);
|
||||||
Code type_ns(int);
|
Code type_ns(int);
|
||||||
Code type_ns(bool);
|
Code type_ns(bool);
|
||||||
@ -1089,6 +1090,8 @@ namespace gen
|
|||||||
Code::Invalid = make_code();
|
Code::Invalid = make_code();
|
||||||
Code::Invalid.lock();
|
Code::Invalid.lock();
|
||||||
|
|
||||||
|
type_ns(auto) = def_type( name(auto) );
|
||||||
|
|
||||||
Code&
|
Code&
|
||||||
t_void_write = ccast( Code, t_void );
|
t_void_write = ccast( Code, t_void );
|
||||||
t_void_write = def_type( name(void) );
|
t_void_write = def_type( name(void) );
|
||||||
@ -2905,56 +2908,34 @@ namespace gen
|
|||||||
{
|
{
|
||||||
def_body_start( def_params );
|
def_body_start( def_params );
|
||||||
|
|
||||||
if ( num % 3 != 0 )
|
|
||||||
{
|
|
||||||
log_failure("gen::def_params: number of arguments must be a multiple of 3 (Code, s32, char const*) - %d", num);
|
|
||||||
return Code::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
Code
|
|
||||||
result = make_code();
|
|
||||||
result->Type = Parameters;
|
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
|
|
||||||
Code_POD pod = va_arg(va, Code_POD);
|
Code_POD pod = va_arg(va, Code_POD);
|
||||||
Code type = pcast( Code, pod );
|
Code param = pcast( Code, pod );
|
||||||
s32 name_length = va_arg(va, s32 );
|
|
||||||
char const* name = va_arg(va, char const*);
|
|
||||||
|
|
||||||
result->Name = get_cached_string( { name_length, name } );
|
null_check( def_params, param );
|
||||||
|
|
||||||
if ( type->Type != Typename )
|
if ( param->Type != Parameters )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_params: type of param %d is not a Typename", num - num + 1 );
|
log_failure( "gen::def_params: param %d is not a Parameters", num - num + 1 );
|
||||||
return Code::Invalid;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
result->add_entry( type );
|
Code result = { param->duplicate() };
|
||||||
|
|
||||||
while( num -= 3, num && num % 3 == 0 )
|
while ( -- num )
|
||||||
{
|
{
|
||||||
pod = va_arg(va, Code_POD);
|
pod = va_arg(va, Code_POD);
|
||||||
type = pcast( Code, pod );
|
param = pcast( Code, pod );
|
||||||
name_length = va_arg(va, u32);
|
|
||||||
name = va_arg(va, char const*);
|
|
||||||
|
|
||||||
Code
|
if ( param->Type != Parameters )
|
||||||
param = make_code();
|
|
||||||
param->Type = Parameters;
|
|
||||||
param->Name = get_cached_string( { name_length, name } );
|
|
||||||
|
|
||||||
if ( type->Type != Typename )
|
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_params: type of param %d is not a Typename", num - num + 1 );
|
log_failure( "gen::def_params: param %d is not a Parameters", num - num + 1 );
|
||||||
return Code::Invalid;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
param->add_entry( type );
|
result->add_entry( param );
|
||||||
param.lock();
|
|
||||||
|
|
||||||
result->add_entry(param);
|
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
@ -1067,6 +1067,7 @@ namespace gen
|
|||||||
|
|
||||||
// Predefined Codes. Are set to readonly and are setup during gen::init()
|
// Predefined Codes. Are set to readonly and are setup during gen::init()
|
||||||
|
|
||||||
|
extern Code type_ns( auto );
|
||||||
extern Code type_ns( void );
|
extern Code type_ns( void );
|
||||||
extern Code type_ns( int );
|
extern Code type_ns( int );
|
||||||
extern Code type_ns( bool );
|
extern Code type_ns( bool );
|
||||||
|
@ -8,30 +8,19 @@ using namespace gen;
|
|||||||
Code gen__array_base()
|
Code gen__array_base()
|
||||||
{
|
{
|
||||||
Code t_allocator_info = def_type( name(AllocatorInfo) );
|
Code t_allocator_info = def_type( name(AllocatorInfo) );
|
||||||
Code header;
|
|
||||||
{
|
|
||||||
Code allocator = def_variable( t_allocator_info, name(Allocator) );
|
|
||||||
Code capacity = def_variable( t_uw, name(Capacity) );
|
|
||||||
Code num = def_variable( t_uw, name(Num) );
|
|
||||||
|
|
||||||
Code body = def_struct_body( 3, allocator, capacity, num );
|
Code header = def_struct( name(ArrayHeader), def_struct_body( 3
|
||||||
header = def_struct( name(Header), body );
|
, def_variable( t_allocator_info, name(Allocator) )
|
||||||
}
|
, def_variable( t_uw, name(Capacity) )
|
||||||
|
, def_variable( t_uw, name(Num) )
|
||||||
|
));
|
||||||
|
|
||||||
Code grow_formula;
|
Code grow_formula = def_function( name(array_grow_formula), def_param( t_uw, name(value)), t_uw
|
||||||
{
|
, untyped_str( code( return 2 * value * 8; ) )
|
||||||
Code params = def_param( t_uw, name(value));
|
, def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline )
|
||||||
Code body = untyped_str( code( return 2 * value * 8; ));
|
);
|
||||||
|
|
||||||
Code spec = def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline );
|
return def_global_body( code_args( 2, header, grow_formula ) );
|
||||||
|
|
||||||
grow_formula = def_function( name(grow_formula), params, t_uw, body, spec );
|
|
||||||
}
|
|
||||||
|
|
||||||
Code body = def_struct_body( 2, header, grow_formula );
|
|
||||||
Code array_base = def_struct( name(ArrayBase), body );
|
|
||||||
|
|
||||||
return array_base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Code gen__array( StrC type, sw type_size )
|
Code gen__array( StrC type, sw type_size )
|
||||||
@ -39,26 +28,12 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
static Code t_allocator_info = def_type( name(AllocatorInfo) );
|
static Code t_allocator_info = def_type( name(AllocatorInfo) );
|
||||||
static Code v_nullptr = untyped_str( code(nullptr));
|
static Code v_nullptr = untyped_str( code(nullptr));
|
||||||
|
|
||||||
// static Code array_base = def_type( name(ArrayBase) );
|
static Code spec_ct_member = def_specifiers( 2, ESpecifier::Constexpr, ESpecifier::Static_Member );
|
||||||
static Code header;
|
static Code spec_static_inline = def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline );
|
||||||
do_once_start
|
static Code spec_static = def_specifier( ESpecifier::Static_Member );
|
||||||
Code allocator = def_variable( t_allocator_info, name(Allocator) );
|
|
||||||
Code capacity = def_variable( t_uw, name(Capacity) );
|
|
||||||
Code num = def_variable( t_uw, name(Num) );
|
|
||||||
|
|
||||||
Code body = def_struct_body( 3, allocator, capacity, num );
|
static Code using_header = def_using( name(Header), def_type( name(ArrayHeader) ) );
|
||||||
header = def_struct( name(Header), body );
|
static Code ct_grow_formula = def_variable( t_auto, name(grow_formula), untyped_str( code( & array_grow_formula )), spec_ct_member );
|
||||||
do_once_end
|
|
||||||
|
|
||||||
static Code grow_formula;
|
|
||||||
do_once_start
|
|
||||||
Code params = def_param( t_uw, name(value));
|
|
||||||
Code body = untyped_str( code( return 2 * value * 8; ));
|
|
||||||
|
|
||||||
Code spec = def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline );
|
|
||||||
|
|
||||||
grow_formula = def_function( name(grow_formula), params, t_uw, body, spec );
|
|
||||||
do_once_end
|
|
||||||
|
|
||||||
StrC name;
|
StrC name;
|
||||||
{
|
{
|
||||||
@ -78,9 +53,6 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
Code t_header_ptr = def_type( name(Header), __, spec_ptr );
|
Code t_header_ptr = def_type( name(Header), __, spec_ptr );
|
||||||
Code t_header_ref = def_type( name(Header), __, spec_ref );
|
Code t_header_ref = def_type( name(Header), __, spec_ref );
|
||||||
|
|
||||||
static Code spec_static_inline = def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline );
|
|
||||||
static Code spec_static = def_specifier( ESpecifier::Static_Member );
|
|
||||||
|
|
||||||
Code array;
|
Code array;
|
||||||
{
|
{
|
||||||
Code using_type = def_using( name(Type), t_type );
|
Code using_type = def_using( name(Type), t_type );
|
||||||
@ -98,34 +70,29 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
|
|
||||||
Code init_reserve;
|
Code init_reserve;
|
||||||
{
|
{
|
||||||
Code params = def_params( 2, (Code[2]){
|
Code params = def_params( 2
|
||||||
def_param( t_allocator_info, name(allocator) ),
|
, def_param( t_allocator_info, name(allocator) )
|
||||||
def_param( t_sw, name(capacity) )
|
, def_param( t_sw, name(capacity) )
|
||||||
});
|
);
|
||||||
|
|
||||||
char const* tmpl = txt(
|
Code body = untyped_str( code(
|
||||||
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + sizeof(Type) ));
|
Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + sizeof(Type) ));
|
||||||
|
|
||||||
if ( header == nullptr )
|
if ( header == nullptr )
|
||||||
return (<type>){ nullptr };
|
return { nullptr };
|
||||||
|
|
||||||
header->Allocator = allocator;
|
header->Allocator = allocator;
|
||||||
header->Capacity = capacity;
|
header->Capacity = capacity;
|
||||||
header->Num = 0;
|
header->Num = 0;
|
||||||
|
|
||||||
return (<type>){ rcast( Type*, header + 1) };
|
return { rcast( Type*, header + 1) };
|
||||||
);
|
));
|
||||||
|
|
||||||
Code body = untyped_str( token_fmt( tmpl, 1, "type", (char const*)t_array_type->Name) );
|
|
||||||
|
|
||||||
init_reserve = def_function( name(init_reserve), params, t_array_type, body, spec_static );
|
init_reserve = def_function( name(init_reserve), params, t_array_type, body, spec_static );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code append;
|
Code append = def_function( name(append), def_param(t_type, name(value)), t_bool
|
||||||
{
|
, untyped_str( code(
|
||||||
Code params = def_param( t_type, name(value));
|
|
||||||
|
|
||||||
Code body = untyped_str( code(
|
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
|
|
||||||
if ( header.Num == header.Capacity )
|
if ( header.Num == header.Capacity )
|
||||||
@ -138,10 +105,8 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
header.Num++;
|
header.Num++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
));
|
))
|
||||||
|
);
|
||||||
append = def_function( name(append), params, t_bool, body );
|
|
||||||
}
|
|
||||||
|
|
||||||
Code back;
|
Code back;
|
||||||
{
|
{
|
||||||
@ -153,18 +118,21 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
back = def_function( name(back), __, t_type_ref, body, spec_inline );
|
back = def_function( name(back), __, t_type_ref, body, spec_inline );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code clear = def_function( name(clear), __, t_void, untyped_str( code(
|
Code clear = def_function( name(clear), __, t_void
|
||||||
|
, untyped_str( code(
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
header.Num = 0;
|
header.Num = 0;
|
||||||
)), spec_inline );
|
))
|
||||||
|
, spec_inline
|
||||||
|
);
|
||||||
|
|
||||||
Code fill;
|
Code fill;
|
||||||
{
|
{
|
||||||
Code params = def_params( 3, (Code[3]){
|
Code params = def_params( 3
|
||||||
def_param( t_uw, name(begin) ),
|
, def_param( t_uw, name(begin) )
|
||||||
def_param( t_uw, name(end) ),
|
, def_param( t_uw, name(end) )
|
||||||
def_param( t_type, name(value) )
|
, def_param( t_type, name(value) )
|
||||||
});
|
);
|
||||||
|
|
||||||
Code body = untyped_str( code(
|
Code body = untyped_str( code(
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
@ -183,25 +151,20 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
fill = def_function( name(fill), params, t_bool, body );
|
fill = def_function( name(fill), params, t_bool, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code free;
|
Code free = def_function( name(free), __, t_void
|
||||||
{
|
, untyped_str( code(
|
||||||
Code body = untyped_str( code(
|
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
::free( header.Allocator, & header );
|
zpl::free( header.Allocator, & header );
|
||||||
));
|
))
|
||||||
|
, spec_inline
|
||||||
free = def_function( name(free), __, t_void, body, spec_inline );
|
);
|
||||||
}
|
|
||||||
|
|
||||||
Code get_header = def_function( name(get_header), __, t_header_ref, untyped_str( code(
|
Code get_header = def_function( name(get_header), __, t_header_ref, untyped_str( code(
|
||||||
return * ( rcast( Header*, Data ) - 1 );
|
return * ( rcast( Header*, Data ) - 1 );
|
||||||
)));
|
)));
|
||||||
|
|
||||||
Code grow;
|
Code grow = def_function( name(grow), def_param( t_uw, name(min_capacity)), t_bool
|
||||||
{
|
, untyped_str( code(
|
||||||
Code param = def_param( t_uw, name(min_capacity) );
|
|
||||||
|
|
||||||
Code body = untyped_str( code(
|
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
|
|
||||||
uw new_capacity = grow_formula( header.Capacity );
|
uw new_capacity = grow_formula( header.Capacity );
|
||||||
@ -210,10 +173,8 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
new_capacity = 8;
|
new_capacity = 8;
|
||||||
|
|
||||||
return set_capacity( new_capacity );
|
return set_capacity( new_capacity );
|
||||||
));
|
))
|
||||||
|
);
|
||||||
grow = def_function( name(grow), param, t_bool, body );
|
|
||||||
}
|
|
||||||
|
|
||||||
Code pop;
|
Code pop;
|
||||||
{
|
{
|
||||||
@ -227,27 +188,19 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
pop = def_function( name(pop), __, t_bool, body, spec_inline );
|
pop = def_function( name(pop), __, t_bool, body, spec_inline );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code reserve;
|
Code reserve = def_function( name(reserve), def_param( t_uw, name(new_capacity)), t_bool
|
||||||
{
|
, untyped_str( code(
|
||||||
Code param = def_param( t_uw, name(new_capacity) );
|
|
||||||
|
|
||||||
Code body = untyped_str( code(
|
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
|
|
||||||
if ( header.Capacity < new_capacity )
|
if ( header.Capacity < new_capacity )
|
||||||
return set_capacity( new_capacity );
|
return set_capacity( new_capacity );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
));
|
))
|
||||||
|
);
|
||||||
|
|
||||||
reserve = def_function( name(reserve), param, t_bool, body );
|
Code resize = def_function( name(resize), def_param( t_uw, name(num)), t_bool
|
||||||
}
|
, untyped_str( code(
|
||||||
|
|
||||||
Code resize;
|
|
||||||
{
|
|
||||||
Code param = def_param( t_uw, name( num ));
|
|
||||||
|
|
||||||
Code body = untyped_str( code(
|
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
|
|
||||||
if ( num > header.Capacity )
|
if ( num > header.Capacity )
|
||||||
@ -258,15 +211,11 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
|
|
||||||
header.Num = num;
|
header.Num = num;
|
||||||
return true;
|
return true;
|
||||||
));
|
))
|
||||||
|
);
|
||||||
resize = def_function( name(resize), param, t_bool, body );
|
|
||||||
}
|
|
||||||
|
|
||||||
Code set_capacity;
|
Code set_capacity;
|
||||||
{
|
{
|
||||||
Code param = def_param( t_uw, name(new_capacity) );
|
|
||||||
|
|
||||||
Code body = untyped_str( code(
|
Code body = untyped_str( code(
|
||||||
Header& header = get_header();
|
Header& header = get_header();
|
||||||
|
|
||||||
@ -288,20 +237,20 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
new_header->Num = header.Num;
|
new_header->Num = header.Num;
|
||||||
new_header->Capacity = new_capacity;
|
new_header->Capacity = new_capacity;
|
||||||
|
|
||||||
::free( header.Allocator, & header );
|
zpl::free( header.Allocator, & header );
|
||||||
|
|
||||||
Data = (u8*) new_header + 1;
|
Data = (u8*) new_header + 1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
));
|
));
|
||||||
|
|
||||||
set_capacity = def_function( name(set_capacity), param, t_bool, body );
|
set_capacity = def_function( name(set_capacity), def_param( t_uw, name(new_capacity)), t_bool, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code body = def_struct_body( 17
|
Code body = def_struct_body( 17
|
||||||
, header
|
, using_header
|
||||||
, grow_formula
|
|
||||||
, using_type
|
, using_type
|
||||||
|
, ct_grow_formula
|
||||||
|
|
||||||
, init
|
, init
|
||||||
, init_reserve
|
, init_reserve
|
||||||
@ -320,7 +269,6 @@ Code gen__array( StrC type, sw type_size )
|
|||||||
|
|
||||||
, data
|
, data
|
||||||
);
|
);
|
||||||
|
|
||||||
array = def_struct( name, body );
|
array = def_struct( name, body );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,11 +301,11 @@ u32 gen_array_file()
|
|||||||
gen_array_file;
|
gen_array_file;
|
||||||
gen_array_file.open( "array.gen.hpp" );
|
gen_array_file.open( "array.gen.hpp" );
|
||||||
|
|
||||||
Code include_zpl = def_include( StrC::from("../../thirdparty/zpl.h") );
|
Code include_zpl = def_include( StrC::from("Bloat.hpp") );
|
||||||
gen_array_file.print( include_zpl );
|
gen_array_file.print( include_zpl );
|
||||||
|
|
||||||
// Code array_base = gen__array_base();
|
Code array_base = gen__array_base();
|
||||||
// gen_array_file.print( array_base );
|
gen_array_file.print( array_base );
|
||||||
|
|
||||||
GenArrayRequest* current = GenArrayRequests;
|
GenArrayRequest* current = GenArrayRequests;
|
||||||
s32 left = array_count( GenArrayRequests );
|
s32 left = array_count( GenArrayRequests );
|
||||||
|
Loading…
Reference in New Issue
Block a user