From 47b9c37e948e5e7c07fdcb30861b4062ad84c107 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 5 Dec 2024 03:41:08 -0500 Subject: [PATCH] began to setup generation of Array_ssize and StringTable in the c-library Still need to confirm if the these old templates require updates compared to the c++ impl --- gen_c_library/c_library.cpp | 22 +++++++++++++++++++ .../components/containers.hashtable.hpp | 12 ++++------ project/components/parser.cpp | 7 ++++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index c46537a..1bd99c0 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -102,6 +102,7 @@ int gen_main() PreprocessorDefines.append(txt("GEN_API_C_BEGIN")); PreprocessorDefines.append(txt("GEN_API_C_END")); + PreprocessorDefines.append(txt("HashTable(")); Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" ); Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" ); @@ -295,6 +296,11 @@ int gen_main() containers.append( gen_array_base() ); containers.append( gen_hashtable_base() ); + containers.append(fmt_newline); + + CodeBody array_ssize = gen_array(txt("ssize"), txt("Array_ssize")); + containers.append(array_ssize); + containers.append( def_pragma(code(endregion Containers))); } header.print(fmt_newline); @@ -373,6 +379,22 @@ int gen_main() } break; + case CT_Typedef: + { + StrC name_string_table = txt("StringTable"); + + CodeTypedef td = cast(CodeTypedef, entry); + if (td->Name.contains(name_string_table)) + { + CodeBody ht = gen_hashtable(name_string_table, name_string_table); + strings.append(ht); + strings.append(td); + break; + } + strings.append(td); + } + break; + default: strings.append(entry); break; diff --git a/gen_c_library/components/containers.hashtable.hpp b/gen_c_library/components/containers.hashtable.hpp index 77670b1..0266ab4 100644 --- a/gen_c_library/components/containers.hashtable.hpp +++ b/gen_c_library/components/containers.hashtable.hpp @@ -18,7 +18,7 @@ CodeBody gen_hashtable_base() )); Code define_type = untyped_str(txt( -R"(#define Hashtable(_type) HTE_##_type +R"(#define HashTable(_type) struct _type )" )); @@ -27,14 +27,10 @@ R"(#define Hashtable(_type) HTE_##_type CodeBody gen_hashtable( StrC type, StrC hashtable_name ) { - String - fn = String::make_reserve( GlobalAllocator, hashtable_name.Len + sizeof("gen") ); - fn.append_fmt( "%.*s", hashtable_name.Len, hashtable_name.Ptr ); - str_to_lower(fn.Data); - String - tbl_type = String::make_reserve( GlobalAllocator, hashtable_name.Len + sizeof("gen") ); - tbl_type.append_fmt( "%.*s", hashtable_name.Len, hashtable_name.Ptr ); + String tbl_type = {(char*) hashtable_name.duplicate(GlobalAllocator).Ptr}; + String fn = tbl_type.duplicate(GlobalAllocator); + str_to_lower(fn.Data); String name_lower = String::make( GlobalAllocator, hashtable_name ); str_to_lower( name_lower.Data ); diff --git a/project/components/parser.cpp b/project/components/parser.cpp index 614fb7c..00ce9c7 100644 --- a/project/components/parser.cpp +++ b/project/components/parser.cpp @@ -4957,6 +4957,13 @@ CodeTypedef parse_typedef() Context.Scope->Name = name; eat( Tok_Preprocess_Macro ); // typedef + + if ( currtok.Type == Tok_Identifier ) + { + type = untyped_str({ name.Length, name.Text }); + name = currtok; + eat(Tok_Identifier); + } } else {