diff --git a/base/Readme.md b/base/Readme.md index 9283ebe..242abf8 100644 --- a/base/Readme.md +++ b/base/Readme.md @@ -191,7 +191,7 @@ These require the following to be handled to the equivalent extent as the other 4. [ast.cpp](./components/ast.cpp): Need to review * `code_debug_str` * `code_is_equal` - * `code_to_strbuilder_ptr` + * `code_to_strbuilder_ref` * `code_validate_body` 5. [code_serialization.cpp](./components/code_serialization.cpp): Define serialization here. 6. [inlines.hpp](./components/inlines.hpp): Any inline definitions for the `struct Code` are defined here. diff --git a/base/components/ast.cpp b/base/components/ast.cpp index 55067bf..62f9bbf 100644 --- a/base/components/ast.cpp +++ b/base/components/ast.cpp @@ -379,11 +379,11 @@ Code code_duplicate(Code self) StrBuilder code_to_strbuilder(Code self) { StrBuilder result = strbuilder_make_str( _ctx->Allocator_Temp, txt("") ); - code_to_strbuilder_ptr( self, & result ); + code_to_strbuilder_ref( self, & result ); return result; } -void code_to_strbuilder_ptr( Code self, StrBuilder* result ) +void code_to_strbuilder_ref( Code self, StrBuilder* result ) { GEN_ASSERT(self != nullptr); local_persist thread_local diff --git a/base/components/ast.hpp b/base/components/ast.hpp index e1eeb1f..68499ab 100644 --- a/base/components/ast.hpp +++ b/base/components/ast.hpp @@ -193,6 +193,7 @@ typedef AST_Stmt_If* CodeStmt_If; typedef AST_Stmt_For* CodeStmt_For; typedef AST_Stmt_Goto* CodeStmt_Goto; typedef AST_Stmt_Label* CodeStmt_Label; +typedef AST_Stmt_Lambda* CodeStmt_Lambda; typedef AST_Stmt_Switch* CodeStmt_Switch; typedef AST_Stmt_While* CodeStmt_While; #else @@ -208,6 +209,7 @@ struct CodeStmt_If; struct CodeStmt_For; struct CodeStmt_Goto; struct CodeStmt_Label; +struct CodeStmt_Lambda; struct CodeStmt_Switch; struct CodeStmt_While; #endif @@ -249,7 +251,7 @@ GEN_API bool code_is_equal (Code code, Code other); bool code_is_valid (Code code); void code_set_global (Code code); GEN_API StrBuilder code_to_strbuilder (Code self ); -GEN_API void code_to_strbuilder_ptr(Code self, StrBuilder* result ); +GEN_API void code_to_strbuilder_ref(Code self, StrBuilder* result ); Str code_type_str (Code self ); GEN_API bool code_validate_body (Code self ); @@ -287,7 +289,7 @@ struct Code forceinline Code* entry(u32 idx) { return code_entry(* this, idx); } forceinline bool has_entries() { return code_has_entries(* this); } forceinline StrBuilder to_strbuilder() { return code_to_strbuilder(* this); } - forceinline void to_strbuilder(StrBuilder& result) { return code_to_strbuilder_ptr(* this, & result); } + forceinline void to_strbuilder(StrBuilder& result) { return code_to_strbuilder_ref(* this, & result); } forceinline Str type_str() { return code_type_str(* this); } forceinline bool validate_body() { return code_validate_body(*this); } #endif diff --git a/base/components/code_serialization.cpp b/base/components/code_serialization.cpp index cf72e5b..58fcd80 100644 --- a/base/components/code_serialization.cpp +++ b/base/components/code_serialization.cpp @@ -42,7 +42,7 @@ void body_to_strbuilder_export( CodeBody body, StrBuilder* result ) s32 left = body->NumEntries; while ( left-- ) { - code_to_strbuilder_ptr(curr, result); + code_to_strbuilder_ref(curr, result); // strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) ); ++curr; } diff --git a/base/components/code_types.hpp b/base/components/code_types.hpp index 047992b..c67cd43 100644 --- a/base/components/code_types.hpp +++ b/base/components/code_types.hpp @@ -20,7 +20,7 @@ GEN_API void body_append ( CodeBody body, Code other ); GEN_API void body_append_body ( CodeBody body, CodeBody other ); GEN_API StrBuilder body_to_strbuilder ( CodeBody body ); -GEN_API void body_to_strbuilder_ref ( CodeBody body, StrBuilder* result ); + void body_to_strbuilder_ref ( CodeBody body, StrBuilder* result ); GEN_API void body_to_strbuilder_export( CodeBody body, StrBuilder* result ); Code begin_CodeBody( CodeBody body); @@ -35,7 +35,7 @@ GEN_API void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result ) void define_params_append (CodeDefineParams appendee, CodeDefineParams other ); CodeDefineParams define_params_get (CodeDefineParams params, s32 idx); bool define_params_has_entries (CodeDefineParams params ); -GEN_API StrBuilder define_params_to_strbuilder (CodeDefineParams params ); + StrBuilder define_params_to_strbuilder (CodeDefineParams params ); GEN_API void define_params_to_strbuilder_ref(CodeDefineParams params, StrBuilder* result ); CodeDefineParams begin_CodeDefineParams(CodeDefineParams params); @@ -45,7 +45,7 @@ CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParam void params_append (CodeParams appendee, CodeParams other ); CodeParams params_get (CodeParams params, s32 idx); bool params_has_entries (CodeParams params ); -GEN_API StrBuilder params_to_strbuilder (CodeParams params ); + StrBuilder params_to_strbuilder (CodeParams params ); GEN_API void params_to_strbuilder_ref(CodeParams params, StrBuilder* result ); CodeParams begin_CodeParams(CodeParams params); @@ -56,7 +56,7 @@ CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter); bool specifiers_has (CodeSpecifiers specifiers, Specifier spec); s32 specifiers_index_of (CodeSpecifiers specifiers, Specifier spec); s32 specifiers_remove (CodeSpecifiers specifiers, Specifier to_remove ); -GEN_API StrBuilder specifiers_to_strbuilder (CodeSpecifiers specifiers); + StrBuilder specifiers_to_strbuilder (CodeSpecifiers specifiers); GEN_API void specifiers_to_strbuilder_ref(CodeSpecifiers specifiers, StrBuilder* result); Specifier* begin_CodeSpecifiers(CodeSpecifiers specifiers); @@ -68,11 +68,11 @@ GEN_API StrBuilder struct_to_strbuilder (CodeStruct self); GEN_API void struct_to_strbuilder_fwd(CodeStruct self, StrBuilder* result); GEN_API void struct_to_strbuilder_def(CodeStruct self, StrBuilder* result); -GEN_API StrBuilder attributes_to_strbuilder (CodeAttributes attributes); -GEN_API void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result); + StrBuilder attributes_to_strbuilder (CodeAttributes attributes); + void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result); -GEN_API StrBuilder comment_to_strbuilder (CodeComment comment ); -GEN_API void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result ); + StrBuilder comment_to_strbuilder (CodeComment comment ); + void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result ); GEN_API StrBuilder constructor_to_strbuilder (CodeConstructor constructor); GEN_API void constructor_to_strbuilder_def(CodeConstructor constructor, StrBuilder* result ); @@ -91,60 +91,60 @@ GEN_API void enum_to_strbuilder_fwd (CodeEnum self, StrBuilder* resul GEN_API void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result ); GEN_API void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result ); -GEN_API StrBuilder exec_to_strbuilder (CodeExec exec); -GEN_API void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result); + StrBuilder exec_to_strbuilder (CodeExec exec); + void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result); -GEN_API void extern_to_strbuilder(CodeExtern self, StrBuilder* result); + void extern_to_strbuilder(CodeExtern self, StrBuilder* result); -GEN_API StrBuilder include_to_strbuilder (CodeInclude self); -GEN_API void include_to_strbuilder_ref(CodeInclude self, StrBuilder* result); + StrBuilder include_to_strbuilder (CodeInclude self); + void include_to_strbuilder_ref(CodeInclude self, StrBuilder* result); -GEN_API StrBuilder friend_to_strbuilder (CodeFriend self); -GEN_API void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result); + StrBuilder friend_to_strbuilder (CodeFriend self); + void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result); GEN_API StrBuilder fn_to_strbuilder (CodeFn self); GEN_API void fn_to_strbuilder_def(CodeFn self, StrBuilder* result); GEN_API void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result); -GEN_API StrBuilder module_to_strbuilder (CodeModule self); + StrBuilder module_to_strbuilder (CodeModule self); GEN_API void module_to_strbuilder_ref(CodeModule self, StrBuilder* result); -GEN_API StrBuilder namespace_to_strbuilder (CodeNS self); -GEN_API void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result); + StrBuilder namespace_to_strbuilder (CodeNS self); + void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result); GEN_API StrBuilder code_op_to_strbuilder (CodeOperator self); GEN_API void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result ); GEN_API void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result ); -GEN_API StrBuilder opcast_to_strbuilder (CodeOpCast op_cast ); +GEN_API StrBuilder opcast_to_strbuilder (CodeOpCast op_cast ); GEN_API void opcast_to_strbuilder_def(CodeOpCast op_cast, StrBuilder* result ); GEN_API void opcast_to_strbuilder_fwd(CodeOpCast op_cast, StrBuilder* result ); -GEN_API StrBuilder pragma_to_strbuilder (CodePragma self); -GEN_API void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result); + StrBuilder pragma_to_strbuilder (CodePragma self); + void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result); GEN_API StrBuilder preprocess_to_strbuilder (CodePreprocessCond cond); -GEN_API void preprocess_to_strbuilder_if (CodePreprocessCond cond, StrBuilder* result ); -GEN_API void preprocess_to_strbuilder_ifdef (CodePreprocessCond cond, StrBuilder* result ); -GEN_API void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result ); -GEN_API void preprocess_to_strbuilder_elif (CodePreprocessCond cond, StrBuilder* result ); -GEN_API void preprocess_to_strbuilder_else (CodePreprocessCond cond, StrBuilder* result ); -GEN_API void preprocess_to_strbuilder_endif (CodePreprocessCond cond, StrBuilder* result ); + void preprocess_to_strbuilder_if (CodePreprocessCond cond, StrBuilder* result ); + void preprocess_to_strbuilder_ifdef (CodePreprocessCond cond, StrBuilder* result ); + void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result ); + void preprocess_to_strbuilder_elif (CodePreprocessCond cond, StrBuilder* result ); + void preprocess_to_strbuilder_else (CodePreprocessCond cond, StrBuilder* result ); + void preprocess_to_strbuilder_endif (CodePreprocessCond cond, StrBuilder* result ); -GEN_API StrBuilder template_to_strbuilder (CodeTemplate self); + StrBuilder template_to_strbuilder (CodeTemplate self); GEN_API void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result); -GEN_API StrBuilder typename_to_strbuilder (CodeTypename self); + StrBuilder typename_to_strbuilder (CodeTypename self); GEN_API void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result); -GEN_API StrBuilder typedef_to_strbuilder (CodeTypedef self); + StrBuilder typedef_to_strbuilder (CodeTypedef self); GEN_API void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result ); GEN_API StrBuilder union_to_strbuilder (CodeUnion self); GEN_API void union_to_strbuilder_def(CodeUnion self, StrBuilder* result); GEN_API void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result); -GEN_API StrBuilder using_to_strbuilder (CodeUsing op_cast ); + StrBuilder using_to_strbuilder (CodeUsing op_cast ); GEN_API void using_to_strbuilder_ref(CodeUsing op_cast, StrBuilder* result ); void using_to_strbuilder_ns (CodeUsing op_cast, StrBuilder* result ); diff --git a/base/components/inlines.hpp b/base/components/inlines.hpp index 59ae1ea..160af33 100644 --- a/base/components/inlines.hpp +++ b/base/components/inlines.hpp @@ -36,7 +36,7 @@ void body_to_strbuilder_ref( CodeBody body, StrBuilder* result ) s32 left = body->NumEntries; while ( left -- ) { - code_to_strbuilder_ptr(curr, result); + code_to_strbuilder_ref(curr, result); // strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) ); ++curr; } @@ -75,6 +75,15 @@ StrBuilder exec_to_strbuilder(CodeExec exec) return result; } +inline +StrBuilder exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result) { + GEN_ASSERT(exec) + GEN_ASSERT(result) + char* raw = ccast(char*, str_duplicate( exec->Content, get_context()->Allocator_Temp ).Ptr); + StrBuilder result = { raw }; + return result; +} + inline void extern_to_strbuilder(CodeExtern self, StrBuilder* result ) { @@ -87,12 +96,15 @@ void extern_to_strbuilder(CodeExtern self, StrBuilder* result ) inline StrBuilder include_to_strbuilder(CodeInclude include) { + GEN_ASSERT(include) return strbuilder_fmt_buf( _ctx->Allocator_Temp, "#include %S\n", include->Content ); } inline void include_to_strbuilder_ref( CodeInclude include, StrBuilder* result ) { + GEN_ASSERT(include) + GEN_ASSERT(result) strbuilder_append_fmt( result, "#include %S\n", include->Content ); } diff --git a/base/dependencies/containers.hpp b/base/dependencies/containers.hpp index d6d91e1..f9d75b4 100644 --- a/base/dependencies/containers.hpp +++ b/base/dependencies/containers.hpp @@ -416,7 +416,7 @@ bool array_set_capacity(Array* array, usize new_capacity) // These are intended for use in the base library of gencpp and the C-variant of the library // It provides a interoperability between the C++ and C implementation of arrays. (not letting these do any crazy substiution though) // They are undefined in gen.hpp and gen.cpp at the end of the files. -// We cpp library expects the user to use the regular calls as they can resolve the type fine. +// The cpp library expects the user to use the regular calls as they can resolve the type fine. #define array_init(type, allocator) array_init (allocator ) #define array_init_reserve(type, allocator, cap) array_init_reserve (allocator, cap) diff --git a/docs/AST_Design.md b/docs/AST_Design.md index 487d6dd..cd59272 100644 --- a/docs/AST_Design.md +++ b/docs/AST_Design.md @@ -53,7 +53,7 @@ StrBuilder _to_strbuilder(Code code); Where the first generates strings allocated using Allocator_StringArena and the other appends an existing strings with their backed allocator. -Serialization of for the AST is defined for `Code` in [`ast.cpp`](../base/components/ast.cpp) with `code_to_strbuilder_ptr` & `code_to_strbuilder`. +Serialization of for the AST is defined for `Code` in [`ast.cpp`](../base/components/ast.cpp) with `code_to_strbuilder_ref` & `code_to_strbuilder`. Serializtion for the rest of the code types is within [`code_serialization.cpp`](../base/components/code_serialization.cpp). Gencpp's serialization does not provide coherent formatting of the code. The user should use a formatter after serializing.