mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-30 19:01:02 -07:00
More dependency movement from zpl, incremental design improvements.
Made token_fmt more ergonomic, going to have to use a similar behavior with the upfront body constructors.
This commit is contained in:
@ -32,8 +32,8 @@ Code gen__array( StrC type )
|
||||
name = { name_len, name_str };
|
||||
};
|
||||
|
||||
Code array = parse_struct( token_fmt(
|
||||
txt(
|
||||
Code array = parse_struct( token_fmt( "ArrayType", name, "type", type,
|
||||
stringize(
|
||||
struct <ArrayType>
|
||||
{
|
||||
using Header = ArrayHeader;
|
||||
@ -208,11 +208,7 @@ Code gen__array( StrC type )
|
||||
return Data;
|
||||
}
|
||||
};
|
||||
),
|
||||
// Tokens
|
||||
2
|
||||
, "ArrayType", (char const*) name
|
||||
, "type", (char const*) type
|
||||
)
|
||||
));
|
||||
|
||||
return array;
|
||||
@ -226,7 +222,7 @@ struct GenArrayRequest
|
||||
};
|
||||
Array<GenArrayRequest> GenArrayRequests;
|
||||
|
||||
void gen__array_request( StrC type, sw size, StrC dep = {} )
|
||||
void gen__array_request( StrC type, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
GenArrayRequests = Array<GenArrayRequest>::init( Memory::GlobalAllocator );
|
||||
@ -247,7 +243,7 @@ void gen__array_request( StrC type, sw size, StrC dep = {} )
|
||||
GenArrayRequest request = { dep, type };
|
||||
GenArrayRequests.append( request );
|
||||
}
|
||||
#define gen_array( type ) gen__array_request( { txt_to_StrC(type) }, sizeof(type) )
|
||||
#define gen_array( type ) gen__array_request( code(type) )
|
||||
|
||||
u32 gen_array_file()
|
||||
{
|
||||
@ -255,9 +251,11 @@ u32 gen_array_file()
|
||||
gen_array_file;
|
||||
gen_array_file.open( "array.Parsed.gen.hpp" );
|
||||
|
||||
Code include_zpl = def_include( StrC::from("Bloat.hpp") );
|
||||
Code include_zpl = def_include( txt_StrC("Bloat.hpp") );
|
||||
gen_array_file.print( include_zpl );
|
||||
|
||||
gen_array_file.print( def_using_namespace( name(gen)));
|
||||
|
||||
Code array_base = gen__array_base();
|
||||
gen_array_file.print( array_base );
|
||||
|
||||
|
@ -27,8 +27,8 @@ Code gen__buffer( StrC type )
|
||||
name = { name_len, name_str };
|
||||
};
|
||||
|
||||
Code buffer = parse_struct( token_fmt(
|
||||
txt(
|
||||
Code buffer = parse_struct( token_fmt( "BufferName", name, "type", type,
|
||||
stringize(
|
||||
struct <BufferName>
|
||||
{
|
||||
using Header = BufferHeader;
|
||||
@ -123,10 +123,7 @@ Code gen__buffer( StrC type )
|
||||
|
||||
Type* Data;
|
||||
};
|
||||
),
|
||||
2
|
||||
, "BufferName", (char const*) name
|
||||
, "type", (char const*) type
|
||||
)
|
||||
));
|
||||
|
||||
return buffer;
|
||||
@ -160,7 +157,7 @@ void gen__buffer_request( StrC type, StrC dep = {} )
|
||||
GenBufferRequest request = { dep, type };
|
||||
GenBufferRequests.append( request );
|
||||
}
|
||||
#define gen_buffer( type ) gen__buffer_request( { txt_to_StrC(type) } )
|
||||
#define gen_buffer( type ) gen__buffer_request( code(type) )
|
||||
|
||||
u32 gen_buffer_file()
|
||||
{
|
||||
@ -168,7 +165,9 @@ u32 gen_buffer_file()
|
||||
gen_buffer_file;
|
||||
gen_buffer_file.open( "buffer.Parsed.gen.hpp" );
|
||||
|
||||
gen_buffer_file.print( def_include( StrC::from("Bloat.hpp")) );
|
||||
gen_buffer_file.print( def_include( txt_StrC("Bloat.hpp")) );
|
||||
gen_buffer_file.print( def_using_namespace( name(gen)));
|
||||
|
||||
gen_buffer_file.print( gen__buffer_base() );
|
||||
|
||||
GenBufferRequest* current = GenBufferRequests;
|
||||
|
@ -18,7 +18,7 @@ Code gen__hashtable_base()
|
||||
));
|
||||
}
|
||||
|
||||
Code gen__hashtable( StrC type, sw type_size )
|
||||
Code gen__hashtable( StrC type )
|
||||
{
|
||||
StringCached name;
|
||||
{
|
||||
@ -28,26 +28,23 @@ Code gen__hashtable( StrC type, sw type_size )
|
||||
name = get_cached_string({ len, name_str });
|
||||
}
|
||||
|
||||
Code ht_entry = parse_struct( token_fmt(
|
||||
txt(
|
||||
Code ht_entry = parse_struct( token_fmt( "HashTableName", (StrC)name, "type", type,
|
||||
stringize(
|
||||
struct <HashTableName>_Entry
|
||||
{
|
||||
u64 Key;
|
||||
sw Next;
|
||||
<type> Value;
|
||||
};
|
||||
),
|
||||
2
|
||||
, "HashTableName", (char const*) name
|
||||
, "type", (char const*) type
|
||||
)
|
||||
));
|
||||
|
||||
StringCached ht_entry_name = get_cached_string( token_fmt( "<HashTableName>_Entry", 1, "HashTableName", name ) );
|
||||
StringCached ht_entry_name = get_cached_string( token_fmt( "HashTableName", (StrC)name, "<HashTableName>_Entry" ));
|
||||
|
||||
Code array_ht_entry = gen__array( ht_entry_name );
|
||||
|
||||
Code hashtable = parse_struct( token_fmt(
|
||||
txt(
|
||||
Code hashtable = parse_struct( token_fmt( "HashTableName", (StrC)name, "type", type,
|
||||
stringize(
|
||||
struct <HashTableName>
|
||||
{
|
||||
using Type = <type>;
|
||||
@ -275,10 +272,7 @@ Code gen__hashtable( StrC type, sw type_size )
|
||||
return 0.75f * Hashes.num() < Entries.num();
|
||||
}
|
||||
};
|
||||
),
|
||||
2
|
||||
, "HashTableName", (char const*) name
|
||||
, "type", (char const*) type
|
||||
)
|
||||
));
|
||||
|
||||
return def_global_body( 3, ht_entry, array_ht_entry, hashtable );
|
||||
@ -288,11 +282,10 @@ struct GenHashTableRequest
|
||||
{
|
||||
StrC Dependency;
|
||||
StrC Type;
|
||||
sw TypeSize;
|
||||
};
|
||||
Array<GenHashTableRequest> GenHashTableRequests;
|
||||
|
||||
void gen__hashtable_request( StrC type, sw size, StrC dep = {} )
|
||||
void gen__hashtable_request( StrC type, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
GenHashTableRequests = Array<GenHashTableRequest>::init( Memory::GlobalAllocator );
|
||||
@ -312,21 +305,24 @@ void gen__hashtable_request( StrC type, sw size, StrC dep = {} )
|
||||
return;
|
||||
}
|
||||
|
||||
GenHashTableRequest request = { dep, type, size};
|
||||
GenHashTableRequest request = { dep, type };
|
||||
GenHashTableRequests.append( request );
|
||||
}
|
||||
#define gen_hashtable( type ) gen__hashtable_request( { txt_to_StrC(type) }, sizeof( type ))
|
||||
#define gen_hashtable( type ) gen__hashtable_request( code(type) )
|
||||
|
||||
u32 gen_hashtable_file()
|
||||
{
|
||||
Builder
|
||||
gen_buffer_file;
|
||||
gen_buffer_file.open( "hashtable.Parsed.gen.hpp" );
|
||||
gen_hashtable_file;
|
||||
gen_hashtable_file.open( "hashtable.Parsed.gen.hpp" );
|
||||
|
||||
gen_buffer_file.print( def_include( StrC::from("Bloat.hpp")) );
|
||||
gen_buffer_file.print( def_include( StrC::from("Array.Parsed.hpp")) );
|
||||
gen_buffer_file.print( def_include( StrC::from("array.Parsed.gen.hpp")) );
|
||||
gen_buffer_file.print( gen__hashtable_base());
|
||||
gen_hashtable_file.print( def_include( txt_StrC("Bloat.hpp")) );
|
||||
gen_hashtable_file.print( def_include( txt_StrC("Array.Parsed.hpp")) );
|
||||
gen_hashtable_file.print( def_include( txt_StrC("array.Parsed.gen.hpp")) );
|
||||
|
||||
gen_hashtable_file.print( def_using_namespace( name(gen)));
|
||||
|
||||
gen_hashtable_file.print( gen__hashtable_base());
|
||||
|
||||
GenHashTableRequest* current = GenHashTableRequests;
|
||||
s32 left = GenHashTableRequests.num();
|
||||
@ -334,7 +330,7 @@ u32 gen_hashtable_file()
|
||||
{
|
||||
GenHashTableRequest const& request = * current;
|
||||
|
||||
Code generated_buffer = gen__hashtable( current->Type, current->TypeSize );
|
||||
Code generated_buffer = gen__hashtable( current->Type );
|
||||
|
||||
if ( request.Dependency )
|
||||
{
|
||||
@ -344,15 +340,15 @@ u32 gen_hashtable_file()
|
||||
Code cmt = def_comment( { cmt_len, cmt_str } );
|
||||
Code include = def_include( request.Dependency );
|
||||
|
||||
gen_buffer_file.print( cmt );
|
||||
gen_buffer_file.print( include );
|
||||
gen_hashtable_file.print( cmt );
|
||||
gen_hashtable_file.print( include );
|
||||
}
|
||||
|
||||
gen_buffer_file.print( generated_buffer );
|
||||
gen_hashtable_file.print( generated_buffer );
|
||||
current++;
|
||||
}
|
||||
|
||||
gen_buffer_file.write();
|
||||
gen_hashtable_file.write();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ Code gen__ring( StrC type )
|
||||
{
|
||||
static Code t_allocator_info = def_type( name(AllocatorInfo) );
|
||||
|
||||
String name;
|
||||
StringCached name;
|
||||
{
|
||||
char const* name_str = str_fmt_buf( "Ring_%s\0", type.Ptr );
|
||||
s32 name_len = str_len( name_str );
|
||||
@ -18,8 +18,10 @@ Code gen__ring( StrC type )
|
||||
name = get_cached_string({ name_len, name_str });
|
||||
};
|
||||
|
||||
Code ring = parse_struct( token_fmt(
|
||||
txt(
|
||||
StrC buffer_name = to_StrC( str_fmt_buf( "Buffer_%s", type.Ptr ));
|
||||
|
||||
Code ring = parse_struct( token_fmt( "RingName", (StrC)name, "type", type, "BufferName", buffer_name,
|
||||
stringize(
|
||||
struct <RingName>
|
||||
{
|
||||
using Type = <type>;
|
||||
@ -87,11 +89,7 @@ Code gen__ring( StrC type )
|
||||
uw Tail;
|
||||
<BufferName> Buffer;
|
||||
};
|
||||
),
|
||||
3
|
||||
, "RingName", (char const*) name
|
||||
, "type", (char const*) type
|
||||
, "BufferName", str_fmt_buf( "Buffer_%s", type.Ptr )
|
||||
)
|
||||
));
|
||||
|
||||
return ring;
|
||||
@ -104,7 +102,7 @@ struct GenRingRequest
|
||||
};
|
||||
Array<GenRingRequest> GenRingRequests;
|
||||
|
||||
void gen__ring_request( StrC type, sw size, StrC dep = {} )
|
||||
void gen__ring_request( StrC type, StrC dep = {} )
|
||||
{
|
||||
do_once_start
|
||||
GenRingRequests = Array<GenRingRequest>::init( Memory::GlobalAllocator );
|
||||
@ -128,7 +126,7 @@ void gen__ring_request( StrC type, sw size, StrC dep = {} )
|
||||
GenRingRequest request = { dep, type };
|
||||
GenRingRequests.append( request );
|
||||
}
|
||||
#define gen_ring( type ) gen__ring_request( { txt_to_StrC(type) }, sizeof( type ))
|
||||
#define gen_ring( type ) gen__ring_request( code(type) )
|
||||
|
||||
u32 gen_ring_file()
|
||||
{
|
||||
@ -136,10 +134,12 @@ u32 gen_ring_file()
|
||||
gen_ring_file;
|
||||
gen_ring_file.open( "ring.Parsed.gen.hpp" );
|
||||
|
||||
gen_ring_file.print( def_include( StrC::from("Bloat.hpp")) );
|
||||
gen_ring_file.print( def_include( StrC::from("buffer.Parsed.gen.hpp")) );
|
||||
gen_ring_file.print( def_include( txt_StrC("Bloat.hpp")) );
|
||||
gen_ring_file.print( def_include( txt_StrC("buffer.Parsed.gen.hpp")) );
|
||||
// gen_ring_file.print( gen__ring_base() );
|
||||
|
||||
gen_ring_file.print( def_using_namespace( name(gen)));
|
||||
|
||||
GenRingRequest* current = GenRingRequests;
|
||||
s32 left = GenRingRequests.num();
|
||||
while (left--)
|
||||
|
@ -10,7 +10,7 @@ u32 gen_sanity()
|
||||
gen_sanity_file;
|
||||
gen_sanity_file.open("./sanity.Parsed.gen.hpp");
|
||||
|
||||
gen_sanity_file.print( def_comment( StrC::from(
|
||||
gen_sanity_file.print( def_comment( txt_StrC(
|
||||
"The following will show a series of base cases for the gen parsed api.\n"
|
||||
)));
|
||||
|
||||
@ -36,7 +36,7 @@ u32 gen_sanity()
|
||||
{};
|
||||
));
|
||||
|
||||
empty_body.body()->add_entry( def_comment( StrC::from("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,7 +72,7 @@ u32 gen_sanity()
|
||||
|
||||
// External Linkage
|
||||
{
|
||||
Code empty_comment = def_comment( StrC::from("Empty external linkage") );
|
||||
Code empty_comment = def_comment( txt_StrC("Empty external linkage") );
|
||||
|
||||
Code c_extern = parse_extern_link( code(
|
||||
extern "C"
|
||||
@ -118,7 +118,7 @@ u32 gen_sanity()
|
||||
}
|
||||
));
|
||||
|
||||
def.body()->add_entry( def_comment( StrC::from("Empty function body") ) );
|
||||
def.body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
|
||||
|
||||
gen_sanity_file.print(fwd);
|
||||
gen_sanity_file.print(def);
|
||||
@ -134,7 +134,7 @@ u32 gen_sanity()
|
||||
}
|
||||
));
|
||||
|
||||
def.body()->add_entry( def_comment( StrC::from("Empty namespace body") ) );
|
||||
def.body()->add_entry( def_comment( txt_StrC("Empty namespace body") ) );
|
||||
|
||||
gen_sanity_file.print(def);
|
||||
}
|
||||
@ -201,7 +201,7 @@ u32 gen_sanity()
|
||||
}
|
||||
));
|
||||
|
||||
def.body()->add_entry( def_comment( StrC::from("Empty function body") ) );
|
||||
def.body()->add_entry( def_comment( txt_StrC("Empty function body") ) );
|
||||
|
||||
gen_sanity_file.print(fwd);
|
||||
gen_sanity_file.print(def);
|
||||
@ -237,7 +237,7 @@ u32 gen_sanity()
|
||||
{};
|
||||
));
|
||||
|
||||
empty_body.body()->add_entry( def_comment( StrC::from("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);
|
||||
@ -253,7 +253,7 @@ u32 gen_sanity()
|
||||
};
|
||||
));
|
||||
|
||||
empty.body()->add_entry( def_comment( StrC::from("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; )) );
|
||||
@ -330,7 +330,7 @@ u32 gen_sanity()
|
||||
|
||||
gen_sanity_file.print_fmt("\n");
|
||||
|
||||
gen_sanity_file.print( def_comment( StrC::from(
|
||||
gen_sanity_file.print( def_comment( txt_StrC(
|
||||
"End of base case tests\n"
|
||||
)));
|
||||
|
||||
|
Reference in New Issue
Block a user