Progress & proofing of docs

This commit is contained in:
Edward R. Gonzalez 2024-12-16 11:36:09 -05:00
parent 0f95c916dd
commit 2bdd49fd19
7 changed files with 70 additions and 18 deletions

View File

@ -43,7 +43,7 @@ struct AST_Pragma;
struct AST_PreprocessCond; struct AST_PreprocessCond;
struct AST_Specifiers; struct AST_Specifiers;
#if GEN_EXECUTION_EXPRESSION_SUPPORT #ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
struct AST_Expr; struct AST_Expr;
struct AST_Expr_Assign; struct AST_Expr_Assign;
struct AST_Expr_Alignof; struct AST_Expr_Alignof;
@ -140,7 +140,7 @@ struct CodePragma;
struct CodeSpecifiers; struct CodeSpecifiers;
#endif #endif
#if GEN_EXECUTION_EXPRESSION_SUPPORT #ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
#if GEN_COMPILER_C #if GEN_COMPILER_C
typedef AST_Expr* CodeExpr; typedef AST_Expr* CodeExpr;

View File

@ -247,7 +247,7 @@ struct AST_Exec
}; };
static_assert( sizeof(AST_Exec) == sizeof(AST), "ERROR: AST_Exec is not the same size as AST"); static_assert( sizeof(AST_Exec) == sizeof(AST), "ERROR: AST_Exec is not the same size as AST");
#if GEN_EXECUTION_EXPRESSION_SUPPORT #ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
struct AST_Expr struct AST_Expr
{ {
union { union {
@ -750,7 +750,7 @@ struct AST_Specifiers
}; };
static_assert( sizeof(AST_Specifiers) == sizeof(AST), "ERROR: AST_Specifier is not the same size as AST"); static_assert( sizeof(AST_Specifiers) == sizeof(AST), "ERROR: AST_Specifier is not the same size as AST");
#if GEN_EXECUTION_EXPRESSION_SUPPORT #ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
struct AST_Stmt struct AST_Stmt
{ {
union { union {

View File

@ -362,7 +362,7 @@ struct CodeExec
AST_Exec *ast; AST_Exec *ast;
}; };
#if GEN_EXECUTION_EXPRESSION_SUPPORT #ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
struct CodeExpr struct CodeExpr
{ {
#if ! GEN_C_LIKE_CPP #if ! GEN_C_LIKE_CPP
@ -689,7 +689,7 @@ struct CodePreprocessCond
AST_PreprocessCond* ast; AST_PreprocessCond* ast;
}; };
#if GEN_EXECUTION_EXPRESSION_SUPPORT #ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
struct CodeStmt struct CodeStmt
{ {
#if ! GEN_C_LIKE_CPP #if ! GEN_C_LIKE_CPP

View File

@ -26,7 +26,7 @@ This means that the typename entry for the parameter AST would be either:
***Concepts and Constraints are not supported*** ***Concepts and Constraints are not supported***
Its a [todo](https://github.com/Ed94/gencpp/issues/21) Its a [todo](https://github.com/Ed94/gencpp/issues/21)
### Feature Macros: ### Feature Macros
* `GEN_DEFINE_ATTRIBUTE_TOKENS` : Allows user to define their own attribute macros for use in parsing. * `GEN_DEFINE_ATTRIBUTE_TOKENS` : Allows user to define their own attribute macros for use in parsing.
* This can be generated using base.cpp. * This can be generated using base.cpp.
@ -40,6 +40,18 @@ Its a [todo](https://github.com/Ed94/gencpp/issues/21)
### The Data & Interface ### The Data & Interface
The library's persistent state is managed tracked by a context struct: `global Context* _ctx;` defined within [static_data.cpp](../base/components/static_data.cpp)
https://github.com/Ed94/gencpp/blob/967a044637f1615c709cb723dc61118fcc08dcdb/base/components/interface.hpp#L39-L97
The interface for the context:
* `init`: Initializtion
* `deinit`: De-initialization.
* `reset`: Clears the allocations, but doesn't free the memoery, then calls `init()` on `_ctx` again.
* `get_context`: Retreive the currently tracked context.
* `set_context`: Swap out the current tracked context.
As mentioned in root readme, the user is provided Code objects by calling the constructor's functions to generate them or find existing matches. As mentioned in root readme, the user is provided Code objects by calling the constructor's functions to generate them or find existing matches.
The AST is managed by the library and provided to the user via its interface. The AST is managed by the library and provided to the user via its interface.
@ -47,12 +59,12 @@ However, the user may specifiy memory configuration.
[Data layout of AST struct (Subject to heavily change with upcoming todos)](../base/components/ast.hpp#L396-461) [Data layout of AST struct (Subject to heavily change with upcoming todos)](../base/components/ast.hpp#L396-461)
https://github.com/Ed94/gencpp/blob/eea4ebf5c40d5d87baa465abfb1be30845b2377e/base/components/ast.hpp#L396-L461 https://github.com/Ed94/gencpp/blob/967a044637f1615c709cb723dc61118fcc08dcdb/base/components/ast.hpp#L369-L435
*`StringCahced` is a typedef for `Str` (a string slice), to denote it is an interned string* *`StringCahced` is a typedef for `Str` (a string slice), to denote it is an interned string*
*`CodeType` is enum taggin the type of code. Has an underlying type of `u32`* *`CodeType` is enum taggin the type of code. Has an underlying type of `u32`*
*`OperatorT` is a typedef for `EOperator::Type` which has an underlying type of `u32`* *`OperatorT` is a typedef for `EOperator::Type` which has an underlying type of `u32`*
*`StrBuilder` is the dynamically allocated string type for the library* *`StrBuilder` is the dynamically allocating string builder type for the library*
AST widths are setup to be AST_POD_Size. AST widths are setup to be AST_POD_Size.
The width dictates how much the static array can hold before it must give way to using an allocated array: The width dictates how much the static array can hold before it must give way to using an allocated array:
@ -117,6 +129,7 @@ The following CodeTypes are used which the user may optionally use strong typing
* CodeClass * CodeClass
* CodeConstructor * CodeConstructor
* CodeDefine * CodeDefine
* CodeDefineParams
* CodeDestructor * CodeDestructor
* CodeEnum * CodeEnum
* CodeExec * CodeExec
@ -127,7 +140,7 @@ The following CodeTypes are used which the user may optionally use strong typing
* CodeModule * CodeModule
* CodeNS * CodeNS
* CodeOperator * CodeOperator
* CodeOpCast * CodeOpCast : User defined member operator conversion
* CodeParams : Has support for `for : range` iterating across parameters. * CodeParams : Has support for `for : range` iterating across parameters.
* CodePreprocessCond * CodePreprocessCond
* CodePragma * CodePragma
@ -140,11 +153,15 @@ The following CodeTypes are used which the user may optionally use strong typing
* CodeUsing * CodeUsing
* CodeVar * CodeVar
Each Code boy has an associated "filtered AST" with the naming convention: `AST_<CodeName>` Each `struct Code<Name>` has an associated "filtered AST" with the naming convention: `AST_<CodeName>`
Unrelated fields of the AST for that node type are omitted and only necessary padding members are defined otherwise. Unrelated fields of the AST for that node type are omitted and only necessary padding members are defined otherwise.
Retrieving a raw version of the ast can be done using the `raw()` function defined in each AST.
## There are three sets of interfaces for Code AST generation the library provides For the interface related to these code types see:
* [ast.hpp](../base/components/ast.hpp): Under the region pragma `Code C-Interface`
* [code_types.hpp](../base/components/code_types.hpp): Under the region pragma `Code C-Interface`. Additional functionlity for c++ will be within the struct definitions or at the end of the file.
## There are three categories of interfaces for Code AST generation & reflection
* Upfront * Upfront
* Parsing * Parsing
@ -164,6 +181,7 @@ Interface :``
* def_class * def_class
* def_constructor * def_constructor
* def_define * def_define
* def_define_params
* def_destructor * def_destructor
* def_enum * def_enum
* def_execution * def_execution
@ -218,6 +236,27 @@ Code <name>
``` ```
All optional parmeters are defined within `struct Opts_def_<functon name>`. This was done to setup a [macro trick](https://x.com/vkrajacic/status/1749816169736073295) for default optional parameers in the C library:
```cpp
struct gen_Opts_def_struct
{
gen_CodeBody body;
gen_CodeTypename parent;
gen_AccessSpec parent_access;
gen_CodeAttributes attributes;
gen_CodeTypename* interfaces;
gen_s32 num_interfaces;
gen_ModuleFlag mflags;
};
typedef struct gen_Opts_def_struct gen_Opts_def_struct;
GEN_API gen_CodeClass gen_def__struct( gen_Str name, gen_Opts_def_struct opts GEN_PARAM_DEFAULT );
#define gen_def_struct( name, ... ) gen_def__struct( name, ( gen_Opts_def_struct ) { __VA_ARGS__ } )
```
In the C++ library, the `def_<funtion name>` is not wrapped in a macro.
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic: When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
```cpp ```cpp
@ -228,7 +267,7 @@ def_global_body( 3, ht_entry, array_ht_entry, hashtable );
``` ```
If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty body. If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty body.
When the members have been populated use: `AST::validate_body` to verify that the members are valid entires for that type. When the members have been populated use: `code_validate_body` to verify that the members are valid entires for that type.
### Parse construction ### Parse construction
@ -244,7 +283,6 @@ Interface :
* parse_export_body * parse_export_body
* parse_extern_link * parse_extern_link
* parse_friend * parse_friend
* Purposefully are only support forward declares with this constructor.
* parse_function * parse_function
* parse_global_body * parse_global_body
* parse_namespace * parse_namespace

View File

@ -91,7 +91,7 @@ C_Expression _Generic( selector_arg, a_type_expr_pair, ... ) {
The first `arg` of _Generic behaves as the "controlling expression" or the expression that resolves to a type which will dictate which of the following expressions provided after to `_Generic` will be resolved as the one used inline for the implemenation. The first `arg` of _Generic behaves as the "controlling expression" or the expression that resolves to a type which will dictate which of the following expressions provided after to `_Generic` will be resolved as the one used inline for the implemenation.
For this library's purposes we'll be using the functional macro equivalent *(if there is an excpetion I'll link it at the end fo the section)*: For this library's purposes we'll be using the functional macro equivalent *(if there is an exception I'll link it at the end of this section)*:
```c ```c
#define macro_that_uses_selector_arg_for_resolving_a_fucntion( selecting_exp) \ #define macro_that_uses_selector_arg_for_resolving_a_fucntion( selecting_exp) \
@ -142,4 +142,4 @@ So for any given templated container interface. Expect the follwoing (taken stra
`GEN_RESOLVED_FUNCTION_CALL` is an empty define, its just to indicate that its intended to expand to a function call. `GEN_RESOLVED_FUNCTION_CALL` is an empty define, its just to indicate that its intended to expand to a function call.
To see the thea actual macro definitions used: [generic_macros.h](./components/generic_macros.h) has them. They'll be injected right after the usual macros are positioned in the header file. To see the the actual macro definitions used - see: [generic_macros.h](./components/generic_macros.h). They'll be injected right after the usual macros in the generated header file.

View File

@ -800,6 +800,9 @@ do \
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast, ast ); b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast, ast );
if (found) break; if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast, ast );
if (found) break;
ast.append(entry); ast.append(entry);
} }
break; break;
@ -978,6 +981,9 @@ R"(#define AST_ArrSpecs_Cap \
found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types ); found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types );
if (found) break; if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_code_types, code_types);
if (found) break;
code_types.append(entry); code_types.append(entry);
} }
break; break;
@ -1072,7 +1078,10 @@ R"(#define <interface_name>( code ) _Generic( (code), \
case CT_Preprocess_If: case CT_Preprocess_If:
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
{ {
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types ); b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast_types, ast_types );
if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast_types, ast_types);
if (found) break; if (found) break;
ast_types.append(entry); ast_types.append(entry);
@ -1128,6 +1137,9 @@ R"(#define <interface_name>( code ) _Generic( (code), \
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface); found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface);
if (found) break; if (found) break;
found = ignore_preprocess_cond_block(txt("0"), entry, parsed_interface, interface);
if (found) break;
interface.append(entry); interface.append(entry);
} }
break; break;

View File

@ -420,6 +420,8 @@ word make_code, gen_make_code
namespace set_allocator_, gen_set_allocator_ namespace set_allocator_, gen_set_allocator_
namespace Opts_, gen_Opts_
namespace def_, gen_def_ namespace def_, gen_def_
namespace parse_, gen_parse_ namespace parse_, gen_parse_
namespace token_, gen_token_ namespace token_, gen_token_