2024-12-10 16:31:50 -08:00
|
|
|
## Navigation
|
|
|
|
|
|
|
|
[Top](../Readme.md)
|
|
|
|
|
|
|
|
<- [docs - General](Readme.md)
|
|
|
|
|
2023-09-25 09:12:11 -07:00
|
|
|
## Current Design
|
|
|
|
|
|
|
|
`AST` is the actual managed node object for the library.
|
|
|
|
Its raw and really not meant to be used directly.
|
|
|
|
|
|
|
|
All user interaction must be with its pointer so the type they deal with is `AST*`.
|
2024-12-10 16:31:50 -08:00
|
|
|
In order to abstract away constant use of `AST*` its wrapped in a Code type which can be either:
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
When its the [C generated variant of the library](../gen_c_library/)
|
|
|
|
```c
|
|
|
|
typedef AST* Code;
|
|
|
|
tyepdef AST_<name>* Code<name>;
|
|
|
|
...
|
|
|
|
```
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
**or**
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
For C++:
|
2023-09-25 09:12:11 -07:00
|
|
|
```cpp
|
2024-12-10 16:31:50 -08:00
|
|
|
struct Code {
|
|
|
|
AST* ast;
|
|
|
|
};
|
|
|
|
struct Code<name> {
|
|
|
|
...
|
|
|
|
|
|
|
|
AST_<name>* ast;
|
|
|
|
};
|
2023-09-25 09:12:11 -07:00
|
|
|
```
|
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
The full definitions of all asts are within:
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
* [`ast.hpp`](../base/components/ast.hpp)
|
|
|
|
* [`ast_types.hpp`](../base/components/ast_types.hpp)
|
2024-12-12 07:24:21 -08:00
|
|
|
* [`code_types.hpp`](../base/components/code_types.hpp)
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
The C/C++ interface procedures are located with `ast.hpp` (for the Code type), and `code_types.hpp` for all others.
|
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
## Serialization
|
2023-09-25 09:12:11 -07:00
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
All code types can either serialize using a function of the pattern:
|
|
|
|
|
|
|
|
```c
|
|
|
|
String <prefix>_to_string(Code code);
|
|
|
|
// or
|
|
|
|
<prefix>_to_string(Code code, String& result);
|
2023-09-25 09:12:11 -07:00
|
|
|
```
|
2023-11-21 18:27:33 -08:00
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
Where the first generates strings allocated using Allocator_StringArena and the other appends an existing strings with their backed allocator.
|
2023-11-21 18:27:33 -08:00
|
|
|
|
2024-12-11 10:33:35 -08:00
|
|
|
Serialization of for the AST is defined for `Code` in [`ast.chpp`](../base/components/ast.cpp) with `code_to_string_ptr` & `code_to_string`.
|
|
|
|
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.
|