mirror of
https://github.com/Ed94/gencpp.git
synced 2025-07-30 00:46:59 -07:00
WIP Change to code types [ Broken ]
This commit is contained in:
@@ -27,16 +27,16 @@ u32 gen_sanity()
|
||||
|
||||
// Class
|
||||
{
|
||||
Code fwd = parse_class( code(
|
||||
CodeClass fwd = parse_class( code(
|
||||
class TestEmptyClass;
|
||||
));
|
||||
|
||||
Code empty_body = parse_class( code(
|
||||
CodeClass empty_body = parse_class( code(
|
||||
class TestEmptyClass
|
||||
{};
|
||||
));
|
||||
|
||||
empty_body->body()->add_entry( def_comment( txt_StrC("Empty class body") ) );
|
||||
empty_body.body()->add_entry( def_comment( txt_StrC("Empty class body") ) );
|
||||
|
||||
gen_sanity_file.print(fwd);
|
||||
gen_sanity_file.print(empty_body);
|
||||
@@ -72,15 +72,15 @@ u32 gen_sanity()
|
||||
|
||||
// External Linkage
|
||||
{
|
||||
Code empty_comment = def_comment( txt_StrC("Empty external linkage") );
|
||||
CodeComment empty_comment = def_comment( txt_StrC("Empty external linkage") );
|
||||
|
||||
Code c_extern = parse_extern_link( code(
|
||||
CodeExtern c_extern = parse_extern_link( code(
|
||||
extern "C"
|
||||
{
|
||||
};
|
||||
));
|
||||
|
||||
c_extern->body()->add_entry( empty_comment );
|
||||
c_extern.body()->add_entry( empty_comment );
|
||||
|
||||
gen_sanity_file.print(c_extern);
|
||||
}
|
||||
@@ -108,17 +108,17 @@ u32 gen_sanity()
|
||||
|
||||
// Function
|
||||
{
|
||||
Code fwd = parse_function( code(
|
||||
CodeFn fwd = parse_function( code(
|
||||
void test_function();
|
||||
));
|
||||
|
||||
Code def = parse_function( code(
|
||||
CodeFn def = parse_function( code(
|
||||
void test_function()
|
||||
{
|
||||
}
|
||||
));
|
||||
|
||||
def->body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
|
||||
def.body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
|
||||
|
||||
gen_sanity_file.print(fwd);
|
||||
gen_sanity_file.print(def);
|
||||
@@ -128,13 +128,13 @@ u32 gen_sanity()
|
||||
|
||||
// Namespace
|
||||
{
|
||||
Code def = parse_namespace( code(
|
||||
CodeNamespace def = parse_namespace( code(
|
||||
namespace TestNamespace
|
||||
{
|
||||
}
|
||||
));
|
||||
|
||||
def->body()->add_entry( def_comment( txt_StrC("Empty namespace body") ) );
|
||||
def.body()->add_entry( def_comment( txt_StrC("Empty namespace body") ) );
|
||||
|
||||
gen_sanity_file.print(def);
|
||||
}
|
||||
@@ -172,17 +172,17 @@ u32 gen_sanity()
|
||||
|
||||
// Operator cast
|
||||
{
|
||||
Code op_ptr = parse_operator_cast( code(
|
||||
CodeClass op_ptr = parse_operator_cast( code(
|
||||
operator u8* ();
|
||||
));
|
||||
|
||||
Code class_def = parse_class( code(
|
||||
CodeClass class_def = parse_class( code(
|
||||
class TestClass
|
||||
{
|
||||
};
|
||||
));
|
||||
|
||||
class_def->body()->add_entry( op_ptr );
|
||||
class_def.body()->add_entry( op_ptr );
|
||||
|
||||
gen_sanity_file.print(class_def);
|
||||
}
|
||||
@@ -191,17 +191,17 @@ u32 gen_sanity()
|
||||
|
||||
// Parameters
|
||||
{
|
||||
Code fwd = parse_function( code(
|
||||
CodeFn fwd = parse_function( code(
|
||||
void test_function_param( int a );
|
||||
));
|
||||
|
||||
Code def = parse_function( code(
|
||||
CodeFn def = parse_function( code(
|
||||
void test_function_param2( int a, int b )
|
||||
{
|
||||
}
|
||||
));
|
||||
|
||||
def->body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
|
||||
def.body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
|
||||
|
||||
gen_sanity_file.print(fwd);
|
||||
gen_sanity_file.print(def);
|
||||
@@ -228,16 +228,16 @@ u32 gen_sanity()
|
||||
|
||||
// Struct
|
||||
{
|
||||
Code fwd = parse_struct( code(
|
||||
CodeStruct fwd = parse_struct( code(
|
||||
struct TestEmptyStruct;
|
||||
));
|
||||
|
||||
Code empty_body = parse_struct( code(
|
||||
CodeStruct empty_body = parse_struct( code(
|
||||
struct TestEmptyStruct
|
||||
{};
|
||||
));
|
||||
|
||||
empty_body->body()->add_entry( def_comment( txt_StrC("Empty struct body") ) );
|
||||
empty_body.body()->add_entry( def_comment( txt_StrC("Empty struct body") ) );
|
||||
|
||||
gen_sanity_file.print(fwd);
|
||||
gen_sanity_file.print(empty_body);
|
||||
@@ -247,13 +247,13 @@ u32 gen_sanity()
|
||||
|
||||
// Union
|
||||
{
|
||||
Code empty = parse_union( code(
|
||||
CodeUnion empty = parse_union( code(
|
||||
union TestEmptyUnion
|
||||
{
|
||||
};
|
||||
));
|
||||
|
||||
empty->body()->add_entry( def_comment( txt_StrC("Empty union body") ) );
|
||||
empty.body()->add_entry( def_comment( txt_StrC("Empty union body") ) );
|
||||
|
||||
gen_sanity_file.print( parse_typedef( code( typedef unsigned short u16; )) );
|
||||
gen_sanity_file.print( parse_typedef( code( typedef unsigned long u32; )) );
|
||||
|
46
test/SOA.hpp
46
test/SOA.hpp
@@ -4,7 +4,7 @@
|
||||
#include "gen.hpp"
|
||||
using namespace gen;
|
||||
|
||||
Code gen_SOA( Code struct_def, s32 num_entries = 0 )
|
||||
Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 )
|
||||
{
|
||||
StringCached name = get_cached_string( token_fmt( "name", (StrC)struct_def->Name,
|
||||
stringize( SOA_<name> )
|
||||
@@ -22,22 +22,18 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
|
||||
var_arena = Arena::init_from_memory( var_memory, kilobytes(Num_Vars_Cap) );
|
||||
do_once_end
|
||||
|
||||
Array<Code> vars = Array<Code>::init( var_arena );;
|
||||
Array<CodeVar> vars = Array<CodeVar>::init( var_arena );;
|
||||
|
||||
Code soa = def_struct( name, def_body( ECode::Struct_Body ));
|
||||
CodeStruct soa = def_struct( name, def_body( ECode::Struct_Body ));
|
||||
{
|
||||
Code body = *struct_def->body();
|
||||
for ( s32 idx = 0; idx < body->num_entries(); idx++ )
|
||||
for ( Code struct_mem : struct_def.body() )
|
||||
{
|
||||
Code struct_mem = { body->entry( idx ) };
|
||||
|
||||
if ( struct_mem->Type == ECode::Variable )
|
||||
{
|
||||
Code var_type = { struct_mem->entry(0) };
|
||||
CodeType var_type = CodeVar(struct_mem).type();
|
||||
StrC num_entries_str = to_StrC( str_fmt_buf( "%d", num_entries ) );
|
||||
|
||||
StrC num_entries_str = to_StrC( str_fmt_buf( "%d", num_entries ) );
|
||||
|
||||
Code entry_arr = { nullptr };
|
||||
CodeVar entry_arr = { nullptr };
|
||||
if ( ! num_entries)
|
||||
{
|
||||
entry_arr = parse_variable( token_fmt( "type", (StrC)var_type->Name, "name", (StrC)struct_mem->Name,
|
||||
@@ -52,12 +48,12 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
|
||||
}
|
||||
|
||||
vars.append( entry_arr );
|
||||
soa->body()->add_entry( entry_arr );
|
||||
soa.body()->add_entry( entry_arr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Code make;
|
||||
CodeFn make;
|
||||
{
|
||||
make = parse_function( token_fmt("SOA_Type", (StrC)name,
|
||||
stringize(
|
||||
@@ -71,22 +67,20 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
|
||||
|
||||
if ( ! num_entries )
|
||||
{
|
||||
for ( s32 idx = 0; idx < vars.num(); idx++ )
|
||||
for ( CodeVar member : vars )
|
||||
{
|
||||
Code member = vars[idx];
|
||||
|
||||
Code arr_init = def_execution( token_fmt( "var_name", (StrC)member->Name, "var_type", (StrC)member->entry(0)->Name,
|
||||
stringize( soa.<var_name> = <var_type>::init( allocator ); )
|
||||
));
|
||||
|
||||
make->body()->add_entry( arr_init );
|
||||
make.body()->add_entry( arr_init );
|
||||
}
|
||||
}
|
||||
|
||||
make->body()->add_entry( def_execution( code( return soa; ) ));
|
||||
make.body()->add_entry( def_execution( code( return soa; ) ));
|
||||
}
|
||||
|
||||
Code get;
|
||||
CodeFn get;
|
||||
{
|
||||
get = parse_function( code(
|
||||
Entry get( s32 idx )
|
||||
@@ -96,10 +90,8 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
|
||||
|
||||
String content = String::make( Memory::GlobalAllocator, "return\n{\n" );
|
||||
|
||||
for ( s32 idx = 0; idx < vars.num(); idx ++ )
|
||||
for ( CodeVar member : vars )
|
||||
{
|
||||
Code member = vars[idx];
|
||||
|
||||
content.append_fmt( token_fmt( "var_name", (StrC)member->Name,
|
||||
"<var_name>[idx],"
|
||||
));
|
||||
@@ -107,14 +99,14 @@ Code gen_SOA( Code struct_def, s32 num_entries = 0 )
|
||||
|
||||
content.append( "};" );
|
||||
|
||||
Code ret = def_execution( content );
|
||||
CodeExec ret = def_execution( content );
|
||||
|
||||
get->body()->add_entry( ret );
|
||||
get.body()->add_entry( ret );
|
||||
}
|
||||
|
||||
soa->body()->add_entry( make );
|
||||
soa->body()->add_entry( get );
|
||||
soa->body()->validate_body();
|
||||
soa.body()->add_entry( make );
|
||||
soa.body()->add_entry( get );
|
||||
soa.body()->validate_body();
|
||||
vars.free();
|
||||
|
||||
return soa;
|
||||
|
@@ -27,14 +27,14 @@ Code gen__array_base()
|
||||
Code gen__array( StrC type )
|
||||
{
|
||||
static Code t_allocator_info = def_type( name(AllocatorInfo) );
|
||||
static Code v_nullptr = untyped_str( code(nullptr));
|
||||
static Code v_nullptr = code_str( code(nullptr));
|
||||
|
||||
static Code spec_ct_member = def_specifiers( 2, ESpecifier::Constexpr, ESpecifier::Static_Member );
|
||||
static Code spec_static_inline = def_specifiers( 2, ESpecifier::Static_Member, ESpecifier::Inline );
|
||||
static Code spec_static = def_specifier( ESpecifier::Static_Member );
|
||||
|
||||
static Code using_header = def_using( name(Header), def_type( name(ArrayHeader) ) );
|
||||
static Code ct_grow_formula = def_variable( t_auto, name(grow_formula), untyped_str( code( & array_grow_formula )), spec_ct_member );
|
||||
static Code ct_grow_formula = def_variable( t_auto, name(grow_formula), code_str( code( & array_grow_formula )), spec_ct_member );
|
||||
|
||||
StrC name;
|
||||
{
|
||||
@@ -134,7 +134,7 @@ Code gen__array( StrC type )
|
||||
, def_param( t_alias, name(value) )
|
||||
);
|
||||
|
||||
Code body = untyped_str( code(
|
||||
Code body = code_str( code(
|
||||
Header& header = * get_header();
|
||||
|
||||
if ( begin < 0 || end >= header.Num )
|
||||
|
@@ -140,7 +140,7 @@ Code gen__hashtable( StrC type )
|
||||
char const* tmpl = stringize(
|
||||
void (*) ( u64 key, <type> value )
|
||||
);
|
||||
Code value = untyped_str( token_fmt( "type", (StrC)t_type->to_string(), tmpl ) );
|
||||
Code value = code_str( token_fmt( "type", (StrC)t_type->to_string(), tmpl ) );
|
||||
|
||||
using_map_proc = def_using ( name(MapProc), value);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ Code gen__hashtable( StrC type )
|
||||
char const* tmpl = stringize(
|
||||
void (*) ( u64 key, <type> value )
|
||||
);
|
||||
Code value = untyped_str( token_fmt( "type", (StrC)t_type_ptr->to_string(), tmpl ) );
|
||||
Code value = code_str( token_fmt( "type", (StrC)t_type_ptr->to_string(), tmpl ) );
|
||||
|
||||
using_map_mut_proc = def_using ( name(MapMutProc), value);
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ u32 gen_sanity_upfront()
|
||||
Code fwd = def_enum( name(ETestEnum), NoCode, t_u8 );
|
||||
Code def;
|
||||
{
|
||||
Code body = untyped_str( code(
|
||||
Code body = code_str( code(
|
||||
A,
|
||||
B,
|
||||
C
|
||||
@@ -160,7 +160,7 @@ u32 gen_sanity_upfront()
|
||||
|
||||
Code bitflagtest;
|
||||
{
|
||||
Code body = def_enum_body( 1, untyped_str( code(
|
||||
Code body = def_enum_body( 1, code_str( code(
|
||||
A = 1 << 0,
|
||||
B = 1 << 1,
|
||||
C = 1 << 2
|
||||
@@ -177,7 +177,7 @@ u32 gen_sanity_upfront()
|
||||
);
|
||||
|
||||
op_fwd = def_operator( EOperator::BOr, params, t_bitflag );
|
||||
op_or = def_operator( EOperator::BOr, params, t_bitflag, untyped_str( code(
|
||||
op_or = def_operator( EOperator::BOr, params, t_bitflag, code_str( code(
|
||||
return EBitFlagtest( (u8)a | (u8)b );
|
||||
)));
|
||||
}
|
||||
@@ -299,7 +299,7 @@ u32 gen_sanity_upfront()
|
||||
// Variable
|
||||
{
|
||||
Code bss = def_variable( t_u8, name(test_variable) );
|
||||
Code data = def_variable( t_u8, name(test_variable2), untyped_str( code( 0x12 )) );
|
||||
Code data = def_variable( t_u8, name(test_variable2), code_str( code( 0x12 )) );
|
||||
|
||||
gen_sanity_file.print(bss);
|
||||
gen_sanity_file.print(data);
|
||||
|
Reference in New Issue
Block a user