gencpp/docs/AST_Design.md
2024-12-10 19:31:50 -05:00

1.5 KiB

Navigation

Top

<- docs - General

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*.
In order to abstract away constant use of AST* its wrapped in a Code type which can be either:

When its the C generated variant of the library

typedef AST* Code;
tyepdef AST_<name>* Code<name>;
...

or

For C++:

struct Code {
    AST* ast;
};
struct Code<name> {
    ...

    AST_<name>* ast;
};

The full definitions of all asts are within:

Serialization

All code types can either serialize using a function of the pattern:

String <prefix>_to_string(Code code);
// or
<prefix>_to_string(Code code, String& result);

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.chpp with code_to_string_ptr & code_to_string.

Serializtion for the rest of the code types is within code_serialization.cpp.

gencpp's serialization does not provide coherent formatting of the code. The user should use a formatter after.