2023-07-26 11:21:20 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "gen.hpp"
|
|
|
|
|
2023-08-21 19:48:05 -07:00
|
|
|
GEN_NS_BEGIN
|
2023-08-03 08:01:43 -07:00
|
|
|
#include "dependencies/parsing.hpp"
|
2023-08-21 19:48:05 -07:00
|
|
|
GEN_NS_END
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2023-07-26 11:21:20 -07:00
|
|
|
using namespace gen;
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeBody gen_ecode( char const* path, bool use_c_definition = false )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
char scratch_mem[kilobytes(4)];
|
2024-11-30 14:18:49 -08:00
|
|
|
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-05 21:33:58 -08:00
|
|
|
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
|
|
|
CSV_Object csv_nodes;
|
|
|
|
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
|
|
|
Array<ADT_Node> keyword_strs = csv_nodes.nodes[1].nodes;
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
|
|
|
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
|
|
|
String to_keyword_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
for ( ssize idx = 0; idx < array_num(enum_strs); ++ idx )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
2024-12-07 14:17:02 -08:00
|
|
|
char const* code = enum_strs [idx].string;
|
|
|
|
char const* keyword = keyword_strs[idx].string;
|
2024-12-01 18:59:43 -08:00
|
|
|
|
2024-12-07 14:58:56 -08:00
|
|
|
// TODO(Ed): to_str_entries and the others in here didn't have proper sizing of the StrC slice.
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
string_append_fmt( & enum_entries, "CT_%s,\n", code );
|
|
|
|
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code );
|
2024-12-07 14:58:56 -08:00
|
|
|
string_append_fmt( & to_keyword_str_entries, "{ sizeof(\"%s\") - 1, \"%s\" },\n", keyword, keyword );
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeEnum enum_code;
|
|
|
|
if (use_c_definition)
|
|
|
|
{
|
|
|
|
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
|
|
|
"enum CodeType enum_underlying(u32) { <entries> CT_NumTypes };"
|
|
|
|
));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
|
|
|
"enum CodeType : u32 { <entries> CT_NumTypes };"
|
|
|
|
));
|
|
|
|
}
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma push_macro("local_persist")
|
2023-07-26 11:21:20 -07:00
|
|
|
#undef local_persist
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) ));
|
2024-12-07 14:17:02 -08:00
|
|
|
CodeBody to_str_fns = parse_global_body( token_fmt(
|
|
|
|
"entries", string_to_strc(to_str_entries)
|
|
|
|
, "keywords", string_to_strc(to_keyword_str_entries)
|
|
|
|
, "num", lookup_size
|
2024-12-06 02:29:17 -08:00
|
|
|
, stringize(
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC codetype_to_str( CodeType type )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
|
|
|
local_persist
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC lookup[<num>] = {
|
2023-07-26 11:21:20 -07:00
|
|
|
<entries>
|
|
|
|
};
|
2024-12-07 14:17:02 -08:00
|
|
|
return lookup[ type ];
|
|
|
|
}
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
inline
|
|
|
|
StrC codetype_to_keyword_str( CodeType type )
|
|
|
|
{
|
|
|
|
local_persist
|
|
|
|
StrC lookup[ <num> ] = {
|
|
|
|
<keywords>
|
|
|
|
};
|
2023-07-26 11:21:20 -07:00
|
|
|
return lookup[ type ];
|
|
|
|
}
|
|
|
|
)));
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma pop_macro("local_persist")
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
CodeBody result = def_body(CT_Global_Body);
|
|
|
|
body_append(result, enum_code);
|
2024-12-07 16:44:58 -08:00
|
|
|
|
|
|
|
if (use_c_definition)
|
|
|
|
{
|
|
|
|
CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; ));
|
|
|
|
body_append(result, code_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
body_append(result, to_str_fns);
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
if (! use_c_definition)
|
|
|
|
{
|
|
|
|
#pragma push_macro("forceinline")
|
|
|
|
#undef forceinline
|
|
|
|
CodeBody alias_mappings = parse_global_body(code(
|
|
|
|
forceinline StrC to_str (CodeType type) { return codetype_to_str(type); }
|
|
|
|
forceinline StrC to_keyword_str(CodeType type) { return codetype_to_keyword_str(type); }
|
|
|
|
));
|
|
|
|
#pragma pop_macro("forceinline")
|
|
|
|
body_append(result, alias_mappings);
|
|
|
|
}
|
|
|
|
return result;
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
2023-08-19 05:21:28 -07:00
|
|
|
char scratch_mem[kilobytes(4)];
|
2024-11-30 14:18:49 -08:00
|
|
|
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-05 21:33:58 -08:00
|
|
|
file_read_contents( arena_allocator_info(& scratch), file_zero_terminate, path );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
|
|
|
CSV_Object csv_nodes;
|
|
|
|
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
|
|
|
|
|
|
|
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
|
|
|
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
|
|
|
|
|
2024-12-01 00:06:30 -08:00
|
|
|
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
|
|
|
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
|
|
|
char const* enum_str = enum_strs[idx].string;
|
|
|
|
char const* entry_to_str = str_strs [idx].string;
|
|
|
|
|
2024-12-04 08:30:54 -08:00
|
|
|
string_append_fmt( & enum_entries, "Op_%s,\n", enum_str );
|
|
|
|
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeEnum enum_code;
|
|
|
|
if (use_c_definition)
|
|
|
|
{
|
|
|
|
#pragma push_macro("enum_underlying")
|
|
|
|
#undef enum_underlying
|
|
|
|
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
|
|
|
enum Operator enum_underlying(u32)
|
|
|
|
{
|
|
|
|
<entries>
|
|
|
|
NumOps
|
|
|
|
};
|
|
|
|
)));
|
|
|
|
#pragma pop_macro("enum_underlying")
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
|
|
|
enum Operator : u32
|
|
|
|
{
|
|
|
|
<entries>
|
|
|
|
NumOps
|
|
|
|
};
|
|
|
|
)));
|
|
|
|
}
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma push_macro("local_persist")
|
2023-07-26 11:21:20 -07:00
|
|
|
#undef local_persist
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) ));
|
|
|
|
CodeFn to_str = parse_function(token_fmt(
|
|
|
|
"entries", string_to_strc(to_str_entries)
|
|
|
|
, "num", lookup_size
|
|
|
|
, stringize(
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC operator_to_str( Operator op )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
|
|
|
local_persist
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC lookup[<num>] = {
|
2023-07-26 11:21:20 -07:00
|
|
|
<entries>
|
|
|
|
};
|
|
|
|
|
|
|
|
return lookup[ op ];
|
|
|
|
}
|
|
|
|
)));
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma pop_macro("local_persist")
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
CodeBody result = def_body(CT_Global_Body);
|
|
|
|
body_append(result, enum_code);
|
2024-12-07 16:44:58 -08:00
|
|
|
if ( use_c_definition )
|
|
|
|
{
|
|
|
|
CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; ));
|
|
|
|
body_append(result, operator_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
body_append(result, to_str);
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
if (! use_c_definition)
|
|
|
|
{
|
|
|
|
#pragma push_macro("forceinline")
|
|
|
|
#undef forceinline
|
|
|
|
CodeBody alias_mappings = parse_global_body(code(
|
|
|
|
forceinline StrC to_str(Operator op) { return operator_to_str(op); }
|
|
|
|
));
|
|
|
|
#pragma pop_macro("forceinline")
|
|
|
|
body_append(result, alias_mappings);
|
|
|
|
}
|
|
|
|
return result;
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
2023-08-19 05:21:28 -07:00
|
|
|
char scratch_mem[kilobytes(4)];
|
2024-11-30 14:18:49 -08:00
|
|
|
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-05 21:33:58 -08:00
|
|
|
file_read_contents( arena_allocator_info(& scratch), file_zero_terminate, path );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
|
|
|
CSV_Object csv_nodes;
|
|
|
|
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
|
|
|
|
|
|
|
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
|
|
|
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
|
|
|
|
|
2024-12-01 00:06:30 -08:00
|
|
|
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
|
|
|
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
|
|
|
char const* enum_str = enum_strs[idx].string;
|
|
|
|
char const* entry_to_str = str_strs [idx].string;
|
|
|
|
|
2024-12-04 08:30:54 -08:00
|
|
|
string_append_fmt( & enum_entries, "Spec_%s,\n", enum_str );
|
|
|
|
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
CodeEnum enum_code;
|
|
|
|
if (use_c_definition)
|
|
|
|
{
|
|
|
|
#pragma push_macro("enum_underlying")
|
|
|
|
#undef enum_underlying
|
|
|
|
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
|
|
|
enum Specifier enum_underlying(u32)
|
|
|
|
{
|
|
|
|
<entries>
|
|
|
|
Spec_NumSpecifiers
|
|
|
|
};
|
|
|
|
)));
|
|
|
|
#pragma pop_macro("enum_underlying")
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
|
|
|
enum Specifier : u32
|
|
|
|
{
|
|
|
|
<entries>
|
|
|
|
Spec_NumSpecifiers
|
|
|
|
};
|
|
|
|
)));
|
|
|
|
}
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
CodeFn is_trailing = parse_function(token_fmt("specifier", string_to_strc(to_str_entries), stringize(
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2024-12-06 02:29:17 -08:00
|
|
|
bool spec_is_trailing( Specifier specifier )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
2024-12-03 10:14:14 -08:00
|
|
|
return specifier > Spec_Virtual;
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
)));
|
|
|
|
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma push_macro("local_persist")
|
|
|
|
#pragma push_macro("do_once_start")
|
|
|
|
#pragma push_macro("do_once_end")
|
|
|
|
#pragma push_macro("forceinline")
|
|
|
|
#pragma push_macro("neverinline")
|
2023-07-26 11:21:20 -07:00
|
|
|
#undef local_persist
|
|
|
|
#undef do_once_start
|
|
|
|
#undef do_once_end
|
2023-08-21 17:30:13 -07:00
|
|
|
#undef forceinline
|
|
|
|
#undef neverinline
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) ));
|
|
|
|
CodeFn to_str = parse_function(token_fmt(
|
|
|
|
"entries", string_to_strc(to_str_entries)
|
|
|
|
, "num", lookup_size
|
|
|
|
, stringize(
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC spec_to_str( Specifier type )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
|
|
|
local_persist
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC lookup[<num>] = {
|
2023-07-26 11:21:20 -07:00
|
|
|
<entries>
|
|
|
|
};
|
|
|
|
|
|
|
|
return lookup[ type ];
|
|
|
|
}
|
|
|
|
)));
|
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
CodeFn to_type = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2024-12-06 02:29:17 -08:00
|
|
|
Specifier strc_to_specifier( StrC str )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
|
|
|
local_persist
|
2024-12-03 10:14:14 -08:00
|
|
|
u32 keymap[ Spec_NumSpecifiers ];
|
2023-07-26 11:21:20 -07:00
|
|
|
do_once_start
|
2024-12-03 10:14:14 -08:00
|
|
|
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
StrC enum_str = spec_to_str( (Specifier)index );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
|
|
|
// We subtract 1 to remove the null terminator
|
|
|
|
// This is because the tokens lexed are not null terminated.
|
|
|
|
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1);
|
|
|
|
}
|
|
|
|
do_once_end
|
|
|
|
|
|
|
|
u32 hash = crc32( str.Ptr, str.Len );
|
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
|
|
|
if ( keymap[index] == hash )
|
2024-12-03 10:14:14 -08:00
|
|
|
return (Specifier)index;
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
return Spec_Invalid;
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
)));
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma pop_macro("local_persist")
|
|
|
|
#pragma pop_macro("do_once_start")
|
|
|
|
#pragma pop_macro("do_once_end")
|
|
|
|
#pragma pop_macro("forceinline")
|
|
|
|
#pragma pop_macro("neverinline")
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
CodeBody result = def_body(CT_Global_Body);
|
|
|
|
body_append(result, enum_code);
|
2024-12-07 16:44:58 -08:00
|
|
|
if (use_c_definition)
|
|
|
|
{
|
|
|
|
CodeTypedef specifier_t = parse_typedef( code(typedef u32 Specifier; ));
|
|
|
|
body_append(result, specifier_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
body_append(result, to_str);
|
|
|
|
body_append(result, is_trailing);
|
|
|
|
body_append(result, to_type);
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
if (! use_c_definition)
|
|
|
|
{
|
|
|
|
#pragma push_macro("forceinline")
|
|
|
|
#undef forceinline
|
|
|
|
CodeBody alias_mappings = parse_global_body(code(
|
|
|
|
forceinline StrC to_str (Specifier spec) { return spec_to_str(spec); }
|
|
|
|
forceinline Specifier to_type( StrC str ) { return strc_to_specifier(str); }
|
|
|
|
forceinline bool is_trailing( Specifier specifier ) { return spec_is_trailing(specifier); }
|
|
|
|
));
|
|
|
|
#pragma pop_macro("forceinline")
|
|
|
|
body_append(result, alias_mappings);
|
|
|
|
}
|
|
|
|
return result;
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
|
|
|
|
2023-07-27 14:12:58 -07:00
|
|
|
CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
2023-07-26 11:21:20 -07:00
|
|
|
{
|
2023-08-03 08:01:43 -07:00
|
|
|
char scratch_mem[kilobytes(16)];
|
2024-11-30 14:18:49 -08:00
|
|
|
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
AllocatorInfo scratch_info = arena_allocator_info(& scratch);
|
2024-11-30 14:18:49 -08:00
|
|
|
|
2024-12-05 21:33:58 -08:00
|
|
|
FileContents enum_content = file_read_contents( scratch_info, file_zero_terminate, etok_path );
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2023-07-27 14:12:58 -07:00
|
|
|
CSV_Object csv_enum_nodes;
|
|
|
|
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), GlobalAllocator, false );
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2024-12-05 21:33:58 -08:00
|
|
|
FileContents attrib_content = file_read_contents( scratch_info, file_zero_terminate, attr_path );
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2023-07-27 14:12:58 -07:00
|
|
|
CSV_Object csv_attr_nodes;
|
|
|
|
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), GlobalAllocator, false );
|
|
|
|
|
|
|
|
Array<ADT_Node> enum_strs = csv_enum_nodes.nodes[0].nodes;
|
|
|
|
Array<ADT_Node> enum_str_strs = csv_enum_nodes.nodes[1].nodes;
|
|
|
|
Array<ADT_Node> attribute_strs = csv_attr_nodes.nodes[0].nodes;
|
|
|
|
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
|
|
|
|
|
2024-12-01 00:06:30 -08:00
|
|
|
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
|
|
|
|
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
|
|
|
String attribute_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
|
|
|
|
String to_str_attributes = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
|
|
|
String attribute_define_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
2023-07-26 23:51:36 -07:00
|
|
|
{
|
|
|
|
char const* enum_str = enum_strs[idx].string;
|
2023-07-27 14:12:58 -07:00
|
|
|
char const* entry_to_str = enum_str_strs [idx].string;
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2024-12-04 08:30:54 -08:00
|
|
|
string_append_fmt( & enum_entries, "Tok_%s,\n", enum_str );
|
|
|
|
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
2023-07-26 23:51:36 -07:00
|
|
|
}
|
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
for ( usize idx = 0; idx < array_num(attribute_strs); idx++ )
|
2023-07-27 14:12:58 -07:00
|
|
|
{
|
|
|
|
char const* attribute_str = attribute_strs[idx].string;
|
|
|
|
char const* entry_to_str = attribute_str_strs [idx].string;
|
|
|
|
|
2024-12-04 08:30:54 -08:00
|
|
|
string_append_fmt( & attribute_entries, "Tok_Attribute_%s,\n", attribute_str );
|
|
|
|
string_append_fmt( & to_str_attributes, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
|
|
|
string_append_fmt( & attribute_define_entries, "Entry( Tok_Attribute_%s, \"%s\" )", attribute_str, entry_to_str );
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
if ( idx < array_num(attribute_strs) - 1 )
|
|
|
|
string_append_strc( & attribute_define_entries, txt(" \\\n"));
|
2023-08-04 13:12:13 -07:00
|
|
|
else
|
2024-12-04 08:01:53 -08:00
|
|
|
string_append_strc( & attribute_define_entries, txt("\n"));
|
2023-07-27 14:12:58 -07:00
|
|
|
}
|
|
|
|
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma push_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
|
2023-08-03 08:01:43 -07:00
|
|
|
#undef GEN_DEFINE_ATTRIBUTE_TOKENS
|
2024-12-04 08:01:53 -08:00
|
|
|
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), string_to_strc(attribute_define_entries) );
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2024-04-17 14:40:32 -07:00
|
|
|
// We cannot parse this enum, it has Attribute names as enums
|
2024-12-04 08:01:53 -08:00
|
|
|
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), "attribute_toks", string_to_strc(attribute_entries), stringize(
|
2024-12-03 06:50:30 -08:00
|
|
|
enum TokType_Def : u32
|
2023-07-26 23:51:36 -07:00
|
|
|
{
|
|
|
|
<entries>
|
2023-07-27 14:12:58 -07:00
|
|
|
<attribute_toks>
|
2024-12-03 06:50:30 -08:00
|
|
|
Tok_NumTokens
|
2023-07-26 23:51:36 -07:00
|
|
|
};
|
|
|
|
)));
|
|
|
|
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma push_macro("local_persist")
|
|
|
|
#pragma push_macro("do_once_start")
|
|
|
|
#pragma push_macro("do_once_end")
|
2023-07-26 23:51:36 -07:00
|
|
|
#undef local_persist
|
|
|
|
#undef do_once_start
|
|
|
|
#undef do_once_end
|
2024-12-04 08:01:53 -08:00
|
|
|
CodeFn to_str = parse_function(token_fmt("entries", string_to_strc(to_str_entries), "attribute_toks", string_to_strc(to_str_attributes), stringize(
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2024-12-03 06:50:30 -08:00
|
|
|
StrC to_str( TokType type )
|
2023-07-26 23:51:36 -07:00
|
|
|
{
|
|
|
|
local_persist
|
|
|
|
StrC lookup[] {
|
|
|
|
<entries>
|
2023-07-27 14:12:58 -07:00
|
|
|
<attribute_toks>
|
2023-07-26 23:51:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return lookup[ type ];
|
|
|
|
}
|
|
|
|
)));
|
|
|
|
|
2024-12-04 08:01:53 -08:00
|
|
|
CodeFn to_type = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2024-12-03 10:14:14 -08:00
|
|
|
TokType to_toktype( StrC str )
|
2023-07-26 23:51:36 -07:00
|
|
|
{
|
|
|
|
local_persist
|
2024-12-03 06:50:30 -08:00
|
|
|
u32 keymap[ Tok_NumTokens ];
|
2023-07-26 23:51:36 -07:00
|
|
|
do_once_start
|
2024-12-03 06:50:30 -08:00
|
|
|
for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
2023-07-26 23:51:36 -07:00
|
|
|
{
|
2024-12-03 06:50:30 -08:00
|
|
|
StrC enum_str = to_str( (TokType)index );
|
2023-07-26 23:51:36 -07:00
|
|
|
|
|
|
|
// We subtract 1 to remove the null terminator
|
|
|
|
// This is because the tokens lexed are not null terminated.
|
|
|
|
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1);
|
|
|
|
}
|
|
|
|
do_once_end
|
|
|
|
|
|
|
|
u32 hash = crc32( str.Ptr, str.Len );
|
|
|
|
|
2024-12-03 06:50:30 -08:00
|
|
|
for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
2023-07-26 23:51:36 -07:00
|
|
|
{
|
|
|
|
if ( keymap[index] == hash )
|
2024-12-03 06:50:30 -08:00
|
|
|
return (TokType)index;
|
2023-07-26 23:51:36 -07:00
|
|
|
}
|
|
|
|
|
2024-12-03 06:50:30 -08:00
|
|
|
return Tok_Invalid;
|
2023-07-26 23:51:36 -07:00
|
|
|
}
|
|
|
|
)));
|
2023-10-22 18:41:36 -07:00
|
|
|
#pragma pop_macro("local_persist")
|
|
|
|
#pragma pop_macro("do_once_start")
|
|
|
|
#pragma pop_macro("do_once_end")
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2024-12-03 06:31:27 -08:00
|
|
|
//CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) );
|
2024-12-03 10:14:14 -08:00
|
|
|
CodeTypedef td_toktype = parse_typedef( code( typedef enum TokType_Def TokType; ));
|
2023-07-26 23:51:36 -07:00
|
|
|
|
2024-12-03 06:31:27 -08:00
|
|
|
return def_global_body( args(
|
2024-12-03 06:50:30 -08:00
|
|
|
attribute_entires_def,
|
|
|
|
enum_code,
|
2024-12-03 15:47:12 -08:00
|
|
|
td_toktype,
|
2024-12-03 06:50:30 -08:00
|
|
|
to_str,
|
|
|
|
to_type
|
2024-12-03 06:31:27 -08:00
|
|
|
));
|
2023-07-26 11:21:20 -07:00
|
|
|
}
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2023-08-06 11:58:43 -07:00
|
|
|
CodeBody gen_ast_inlines()
|
2023-08-03 08:01:43 -07:00
|
|
|
{
|
2024-12-01 15:50:37 -08:00
|
|
|
#pragma push_macro("GEN_NS")
|
2023-08-06 11:58:43 -07:00
|
|
|
#pragma push_macro("rcast")
|
2023-08-08 12:53:10 -07:00
|
|
|
#pragma push_macro("log_failure")
|
2024-12-01 21:03:38 -08:00
|
|
|
#pragma push_macro("CodeInvalid")
|
2024-12-01 15:50:37 -08:00
|
|
|
#undef GEN_NS
|
2023-08-06 11:58:43 -07:00
|
|
|
#undef rcast
|
2023-08-08 12:53:10 -07:00
|
|
|
#undef log_failure
|
2024-12-01 21:03:38 -08:00
|
|
|
#undef CodeInvalid
|
2023-08-06 11:58:43 -07:00
|
|
|
char const* code_impl_tmpl = stringize(
|
|
|
|
\n
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-06 11:58:43 -07:00
|
|
|
<typename>& <typename>::operator =( Code other )
|
|
|
|
{
|
2024-12-06 21:21:09 -08:00
|
|
|
if ( other.ast != nullptr && other->Parent != nullptr )
|
2023-08-06 11:58:43 -07:00
|
|
|
{
|
2024-12-06 02:29:17 -08:00
|
|
|
ast = rcast( decltype(ast), code_duplicate(other).ast);
|
2024-12-02 17:20:30 -08:00
|
|
|
ast->Parent = { nullptr };
|
2023-08-06 11:58:43 -07:00
|
|
|
}
|
|
|
|
|
2024-12-02 17:20:30 -08:00
|
|
|
ast = rcast( decltype( ast ), other.ast );
|
|
|
|
return * this;
|
2023-08-06 11:58:43 -07:00
|
|
|
}
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-06 11:58:43 -07:00
|
|
|
<typename>::operator bool()
|
|
|
|
{
|
|
|
|
return ast != nullptr;
|
|
|
|
}
|
2023-08-06 14:19:57 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
char const* codetype_impl_tmpl = stringize(
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-06 14:19:57 -07:00
|
|
|
Code<typename>::operator Code()
|
|
|
|
{
|
|
|
|
return *rcast( Code*, this );
|
|
|
|
}
|
2024-10-24 22:04:17 -07:00
|
|
|
inline
|
2023-08-06 14:19:57 -07:00
|
|
|
AST_<typename>* Code<typename>::operator->()
|
|
|
|
{
|
|
|
|
if ( ast == nullptr )
|
|
|
|
{
|
|
|
|
log_failure( "Attempt to dereference a nullptr!" );
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ast;
|
|
|
|
}
|
2023-08-06 11:58:43 -07:00
|
|
|
\n
|
|
|
|
);
|
2024-12-01 15:50:37 -08:00
|
|
|
#pragma pop_macro("GEN_NS")
|
2024-12-01 21:03:38 -08:00
|
|
|
#pragma pop_macro("CodeInvalid")
|
2023-08-06 11:58:43 -07:00
|
|
|
|
|
|
|
CodeBody impl_code = parse_global_body( token_fmt( "typename", StrC name(Code), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_body = parse_global_body( token_fmt( "typename", StrC name(CodeBody), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_attr = parse_global_body( token_fmt( "typename", StrC name(CodeAttributes), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_cmt = parse_global_body( token_fmt( "typename", StrC name(CodeComment), code_impl_tmpl ));
|
2023-08-07 00:10:45 -07:00
|
|
|
CodeBody impl_code_constr = parse_global_body( token_fmt( "typename", StrC name(CodeConstructor), code_impl_tmpl ));
|
2023-08-06 11:58:43 -07:00
|
|
|
CodeBody impl_code_class = parse_global_body( token_fmt( "typename", StrC name(CodeClass), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_define = parse_global_body( token_fmt( "typename", StrC name(CodeDefine), code_impl_tmpl ));
|
2023-08-07 00:10:45 -07:00
|
|
|
CodeBody impl_code_destruct = parse_global_body( token_fmt( "typename", StrC name(CodeDestructor), code_impl_tmpl ));
|
2023-08-06 11:58:43 -07:00
|
|
|
CodeBody impl_code_enum = parse_global_body( token_fmt( "typename", StrC name(CodeEnum), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_exec = parse_global_body( token_fmt( "typename", StrC name(CodeExec), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_extern = parse_global_body( token_fmt( "typename", StrC name(CodeExtern), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_include = parse_global_body( token_fmt( "typename", StrC name(CodeInclude), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_friend = parse_global_body( token_fmt( "typename", StrC name(CodeFriend), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_fn = parse_global_body( token_fmt( "typename", StrC name(CodeFn), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_module = parse_global_body( token_fmt( "typename", StrC name(CodeModule), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_ns = parse_global_body( token_fmt( "typename", StrC name(CodeNS), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_op = parse_global_body( token_fmt( "typename", StrC name(CodeOperator), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_opcast = parse_global_body( token_fmt( "typename", StrC name(CodeOpCast), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_param = parse_global_body( token_fmt( "typename", StrC name(CodeParam), code_impl_tmpl ));
|
2023-08-06 14:19:57 -07:00
|
|
|
CodeBody impl_code_pragma = parse_global_body( token_fmt( "typename", StrC name(CodePragma), code_impl_tmpl ));
|
2023-08-06 11:58:43 -07:00
|
|
|
CodeBody impl_code_precond = parse_global_body( token_fmt( "typename", StrC name(CodePreprocessCond), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", StrC name(CodeSpecifiers), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_struct = parse_global_body( token_fmt( "typename", StrC name(CodeStruct), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_tmpl = parse_global_body( token_fmt( "typename", StrC name(CodeTemplate), code_impl_tmpl ));
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeBody impl_code_type = parse_global_body( token_fmt( "typename", StrC name(CodeTypename), code_impl_tmpl ));
|
2023-08-06 11:58:43 -07:00
|
|
|
CodeBody impl_code_typedef = parse_global_body( token_fmt( "typename", StrC name(CodeTypedef), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_union = parse_global_body( token_fmt( "typename", StrC name(CodeUnion), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl ));
|
|
|
|
CodeBody impl_code_var = parse_global_body( token_fmt( "typename", StrC name(CodeVar), code_impl_tmpl ));
|
|
|
|
|
2024-12-06 21:21:09 -08:00
|
|
|
body_append(impl_code_attr, parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_cmt, parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_constr, parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_define, parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_destruct, parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_enum, parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_exec, parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_extern, parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_include, parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_friend, parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_fn, parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_module, parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_ns, parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_op, parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_opcast, parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Typename), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl )));
|
|
|
|
body_append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl )));
|
|
|
|
|
|
|
|
#pragma push_macro("forceinline")
|
|
|
|
#undef forceinline
|
2023-08-06 14:19:57 -07:00
|
|
|
char const* cast_tmpl = stringize(
|
2024-12-06 21:21:09 -08:00
|
|
|
forceinline Code::operator Code<typename>() const
|
2023-08-06 11:58:43 -07:00
|
|
|
{
|
2023-08-06 14:19:57 -07:00
|
|
|
return { (AST_<typename>*) ast };
|
2023-08-06 11:58:43 -07:00
|
|
|
}
|
|
|
|
);
|
2024-12-06 21:21:09 -08:00
|
|
|
#pragma pop_macro("forceinline")
|
2023-08-06 11:58:43 -07:00
|
|
|
|
2023-08-06 14:19:57 -07:00
|
|
|
CodeBody impl_cast_body = parse_global_body( token_fmt( "typename", StrC name(Body), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_attribute = parse_global_body( token_fmt( "typename", StrC name(Attributes), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_cmt = parse_global_body( token_fmt( "typename", StrC name(Comment), cast_tmpl ));
|
2023-08-07 00:10:45 -07:00
|
|
|
CodeBody impl_cast_constr = parse_global_body( token_fmt( "typename", StrC name(Constructor), cast_tmpl ));
|
2023-08-06 14:19:57 -07:00
|
|
|
CodeBody impl_cast_class = parse_global_body( token_fmt( "typename", StrC name(Class), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_define = parse_global_body( token_fmt( "typename", StrC name(Define), cast_tmpl ));
|
2023-08-07 00:10:45 -07:00
|
|
|
CodeBody impl_cast_destruct = parse_global_body( token_fmt( "typename", StrC name(Destructor), cast_tmpl ));
|
2023-08-06 14:19:57 -07:00
|
|
|
CodeBody impl_cast_enum = parse_global_body( token_fmt( "typename", StrC name(Enum), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_exec = parse_global_body( token_fmt( "typename", StrC name(Exec), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_extern = parse_global_body( token_fmt( "typename", StrC name(Extern), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_friend = parse_global_body( token_fmt( "typename", StrC name(Friend), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_fn = parse_global_body( token_fmt( "typename", StrC name(Fn), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_include = parse_global_body( token_fmt( "typename", StrC name(Include), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_module = parse_global_body( token_fmt( "typename", StrC name(Module), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_ns = parse_global_body( token_fmt( "typename", StrC name(NS), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_op = parse_global_body( token_fmt( "typename", StrC name(Operator), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_opcast = parse_global_body( token_fmt( "typename", StrC name(OpCast), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_param = parse_global_body( token_fmt( "typename", StrC name(Param), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_pragma = parse_global_body( token_fmt( "typename", StrC name(Pragma), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_precond = parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", StrC name(Specifiers), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_struct = parse_global_body( token_fmt( "typename", StrC name(Struct), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_tmpl = parse_global_body( token_fmt( "typename", StrC name(Template), cast_tmpl ));
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeBody impl_cast_type = parse_global_body( token_fmt( "typename", StrC name(Typename), cast_tmpl ));
|
2023-08-06 14:19:57 -07:00
|
|
|
CodeBody impl_cast_typedef = parse_global_body( token_fmt( "typename", StrC name(Typedef), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_union = parse_global_body( token_fmt( "typename", StrC name(Union), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_using = parse_global_body( token_fmt( "typename", StrC name(Using), cast_tmpl ));
|
|
|
|
CodeBody impl_cast_var = parse_global_body( token_fmt( "typename", StrC name(Var), cast_tmpl ));
|
2023-08-06 11:58:43 -07:00
|
|
|
|
|
|
|
CodeBody result = def_global_body( args(
|
2023-08-09 15:47:59 -07:00
|
|
|
def_pragma( txt("region generated code inline implementation")),
|
2023-08-06 11:58:43 -07:00
|
|
|
fmt_newline,
|
|
|
|
impl_code,
|
|
|
|
impl_code_body,
|
2023-08-06 14:19:57 -07:00
|
|
|
impl_code_attr,
|
2023-08-06 11:58:43 -07:00
|
|
|
impl_code_cmt,
|
2023-08-07 00:10:45 -07:00
|
|
|
impl_code_constr,
|
2023-08-06 11:58:43 -07:00
|
|
|
impl_code_class,
|
|
|
|
impl_code_define,
|
2023-08-07 00:10:45 -07:00
|
|
|
impl_code_destruct,
|
2023-08-06 11:58:43 -07:00
|
|
|
impl_code_enum,
|
|
|
|
impl_code_exec,
|
|
|
|
impl_code_extern,
|
|
|
|
impl_code_friend,
|
|
|
|
impl_code_fn,
|
2023-08-06 14:19:57 -07:00
|
|
|
impl_code_include,
|
2023-08-06 11:58:43 -07:00
|
|
|
impl_code_module,
|
|
|
|
impl_code_ns,
|
|
|
|
impl_code_op,
|
|
|
|
impl_code_opcast,
|
|
|
|
impl_code_param,
|
2023-08-06 14:19:57 -07:00
|
|
|
impl_code_pragma,
|
2023-08-06 11:58:43 -07:00
|
|
|
impl_code_precond,
|
|
|
|
impl_code_specs,
|
|
|
|
impl_code_struct,
|
|
|
|
impl_code_tmpl,
|
|
|
|
impl_code_type,
|
|
|
|
impl_code_typedef,
|
|
|
|
impl_code_union,
|
|
|
|
impl_code_using,
|
|
|
|
impl_code_var,
|
|
|
|
fmt_newline,
|
2023-08-09 15:47:59 -07:00
|
|
|
def_pragma( txt("endregion generated code inline implementation")),
|
2023-08-06 11:58:43 -07:00
|
|
|
fmt_newline,
|
2023-08-09 15:47:59 -07:00
|
|
|
def_pragma( txt("region generated AST/Code cast implementation")),
|
2024-12-06 21:21:09 -08:00
|
|
|
untyped_str(txt("GEN_OPTIMIZE_MAPPINGS_BEGIN\n")),
|
2023-08-06 11:58:43 -07:00
|
|
|
fmt_newline,
|
2023-08-06 14:19:57 -07:00
|
|
|
impl_cast_body,
|
|
|
|
impl_cast_attribute,
|
|
|
|
impl_cast_cmt,
|
2023-08-07 00:10:45 -07:00
|
|
|
impl_cast_constr,
|
2023-08-06 14:19:57 -07:00
|
|
|
impl_cast_class,
|
|
|
|
impl_cast_define,
|
2023-08-07 00:10:45 -07:00
|
|
|
impl_cast_destruct,
|
2023-08-06 14:19:57 -07:00
|
|
|
impl_cast_enum,
|
|
|
|
impl_cast_exec,
|
|
|
|
impl_cast_extern,
|
|
|
|
impl_cast_friend,
|
|
|
|
impl_cast_fn,
|
|
|
|
impl_cast_include,
|
|
|
|
impl_cast_module,
|
|
|
|
impl_cast_ns,
|
|
|
|
impl_cast_op,
|
|
|
|
impl_cast_opcast,
|
|
|
|
impl_cast_param,
|
|
|
|
impl_cast_pragma,
|
|
|
|
impl_cast_precond,
|
|
|
|
impl_cast_specs,
|
|
|
|
impl_cast_struct,
|
|
|
|
impl_cast_tmpl,
|
|
|
|
impl_cast_type,
|
|
|
|
impl_cast_typedef,
|
|
|
|
impl_cast_union,
|
|
|
|
impl_cast_using,
|
|
|
|
impl_cast_var,
|
2023-08-06 11:58:43 -07:00
|
|
|
fmt_newline,
|
2024-12-06 21:21:09 -08:00
|
|
|
untyped_str(txt("GEN_OPITMIZE_MAPPINGS_END\n")),
|
2023-08-09 15:47:59 -07:00
|
|
|
def_pragma( txt("endregion generated AST/Code cast implementation")),
|
2023-08-06 11:58:43 -07:00
|
|
|
fmt_newline
|
|
|
|
));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
#pragma pop_macro("rcast")
|
2023-08-08 12:53:10 -07:00
|
|
|
#pragma pop_macro("log_failure")
|
2023-08-03 08:01:43 -07:00
|
|
|
}
|