2024-12-10 16:31:50 -08:00
## Navigation
[Top ](../Readme.md )
< - [docs - General ](Readme.md )
2023-09-25 09:12:11 -07:00
# AST Types Documentation
2023-08-22 23:17:47 -07:00
2024-12-16 18:48:01 -08:00
While the Readme for docs covers the data layout per AST, this will focus on the AST types available, and their nuances.
2023-08-22 23:17:47 -07:00
## Body
2024-12-10 16:31:50 -08:00
These are containers representing a scope body of a definition that can be of the following `CodeType` type:
2023-08-22 23:17:47 -07:00
* Class_Body
* Enum_Body
* Export_Body
* Extern_Linkage_Body
* Function_Body
* Global_Body
* Namespace_Body
* Struct_Body
* Union_Body
Fields:
```cpp
2024-12-16 09:26:17 -08:00
StrCached Name;
Code Front;
Code Back;
Token* Tok;
Code Parent;
CodeType Type;
s32 NumEntries;
2023-08-22 23:17:47 -07:00
```
The `Front` member represents the start of the link list and `Back` the end.
NumEntries is the number of entries in the body.
2024-12-16 18:48:01 -08:00
Parent should have a compatible CodeType type for the type of definition used.
2023-08-22 23:17:47 -07:00
Serialization:
Will output only the entries, the braces are handled by the parent.
```cpp
2024-12-11 10:33:35 -08:00
< Front >
...
2023-08-22 23:17:47 -07:00
< Back >
```
## Attributes
Represent standard or vendor specific C/C++ attributes.
Fields:
```cpp
2024-12-16 09:26:17 -08:00
StrCached Content;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
< Content >
```
While the parser supports the `__declspec` and `__attribute__` syntax, the upfront constructor ( def_attributes ) must have the user specify the entire attribute, including the `[[]]` , `__declspec` or `__attribute__` parts.
## Comment
Stores a comment.
Fields:
```cpp
2024-12-16 09:26:17 -08:00
StrCached Content;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
< Content >
```
2024-12-16 18:48:01 -08:00
The parser will preserve comments found if residing with a body or in accepted inline-to-definition locations.
2023-08-22 23:17:47 -07:00
Otherwise they will be skipped by the TokArray::__eat and TokArray::current( skip foramtting enabled ) functions.
The upfront constructor: `def_comment` expects to recieve a comment without the `//` or `/* */` parts. It will add them during construction.
## Class & Struct
Fields:
```cpp
2023-09-25 09:12:11 -07:00
CodeComment InlineCmt; // Only supported by forward declarations
2023-08-22 23:17:47 -07:00
CodeAttributes Attributes;
CodeType ParentType;
CodeBody Body;
2024-12-16 09:26:17 -08:00
StrCached Name;
2024-12-11 10:33:35 -08:00
CodeType Prev;
CodeType Next;
Token* Tok;
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-08-22 23:17:47 -07:00
ModuleFlag ModuleFlags;
AccessSpec ParentAccess;
```
Serialization:
```cpp
// Class_Fwd
< ModuleFlags > < class / struct > < Name > ; < InlineCmt >
// Class
2023-09-25 09:12:11 -07:00
< ModuleFlags > < class / struct > < Attributes > < Name > : < ParentAccess > < ParentType > , public < ParentType- > Next>, ... < InlineCmt >
2023-08-22 23:17:47 -07:00
{
< Body >
};
```
2024-12-11 10:33:35 -08:00
You'll notice that only one parent type is supported only with parent access. This library only supports single inheritance, the rest are assumed to be interfaces and are given public acess specifiers.
2023-08-22 23:17:47 -07:00
## Constructor
Fields:
```cpp
2024-12-16 09:26:17 -08:00
CodeComment InlineCmt; // Only supported by forward declarations
Code InitializerList;
CodeParams Params;
Code Body;
2024-12-13 16:16:52 -08:00
StrCached Name;
2024-12-16 09:26:17 -08:00
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
// Constructor_Fwd
< Specs > < Parent- > Name>( < Params > ); < InlineCmt >
// Constructor
2023-09-25 09:12:11 -07:00
< Specs > < Parent- > Name>( < Params > ) < InlineCmt >
: < InitializerList >
2023-08-22 23:17:47 -07:00
{
< Body >
}
2024-04-17 15:29:30 -07:00
// Constructor Source Implementation
< Specs > < Parent > ::~< Parent- > Name>( < Params > ) < Specs >
{
< Body >
}
2023-08-22 23:17:47 -07:00
```
## Define
Represents a preprocessor define
Fields:
```cpp
2024-12-16 09:26:17 -08:00
CodeDefineParams Params;
Code Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
#define <Name> <Content>
```
2024-12-16 09:26:17 -08:00
## DefineParams
Preprocessor define's parameters.
Fields:
```cpp
StrCached Name;
Code Last;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
s32 NumEntries;
```
Serialization:
```cpp
< Name > , < Next > ...
```
2023-08-22 23:17:47 -07:00
## Destructor
Fields:
```cpp
CodeComment InlineCmt;
CodeSpecifiers Specs;
Code Body;
2024-12-16 09:26:17 -08:00
StrCached Name;
2023-08-22 23:17:47 -07:00
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-08-22 23:17:47 -07:00
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
// Destructor_Fwd
< Specs > ~< Parent- > Name>( < Params > ) < Specs > ; < InlineCmt >
// Destructor
< Specs > ~< Parent- > Name>( < Params > ) < Specs >
{
< Body >
}
2024-04-17 15:29:30 -07:00
// Destructor Source Implementation
< Specs > < Parent > ::~< Parent- > Name>( < Params > ) < Specs >
{
< Body >
}
2023-08-22 23:17:47 -07:00
```
## Enum
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeType UnderlyingType;
2024-12-11 10:33:35 -08:00
Code UnderlyingTypeMacro;
2023-08-22 23:17:47 -07:00
CodeBody Body;
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-08-22 23:17:47 -07:00
Code Parent;
2024-12-16 09:26:17 -08:00
StrCached Name;
CodeType Type;
2023-08-22 23:17:47 -07:00
ModuleFlag ModuleFlags;
```
2024-12-11 10:33:35 -08:00
UnderlyingTypeMacro is a macro the library natively supports: `enum_underlying(type)` that is meant to behave as a wrapper for underlying type assignment.
2024-12-12 09:55:15 -08:00
The `enum_underlying_sig` is a `Str` global var that can be set which will be defined within `PreprocessorDefines` and used in `parser_parse_enum` to identify a valid macro.
2024-12-11 10:33:35 -08:00
2023-08-22 23:17:47 -07:00
Serialization:
```cpp
// Enum_Fwd
2024-12-11 10:33:35 -08:00
< ModuleFlags > enum class < Name > : < UnderlyingType > or < UnderlyingTypeMacro > ; < InlineCmt >
2023-08-22 23:17:47 -07:00
// Enum
2024-12-11 10:33:35 -08:00
< ModuleFlags > < enum or enum class > < Name > : < UnderlyingType > or < UnderlyingTypeMacro >
2023-08-22 23:17:47 -07:00
{
< Body >
};
```
## Execution
Just represents an execution body. Equivalent to an untyped body.
2024-12-16 18:48:01 -08:00
Will be obsolete when function body parsing is implemented.
2023-08-22 23:17:47 -07:00
Fields:
```cpp
2024-12-16 09:26:17 -08:00
StrCached Content;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
< Content >
```
2024-12-16 09:26:17 -08:00
## External Linkage (Extern)
2023-08-22 23:17:47 -07:00
Fields:
```cpp
2024-12-16 09:26:17 -08:00
CodeBody Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
extern "< Name > "
{
< Body >
}
```
## Include
Fields:
```cpp
2024-12-16 09:26:17 -08:00
StrCached Content;
StrCached Name;
Code Prev;
Code Next;
Code Parent;
Token* Tok;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
#include <Content>
```
## Friend
This library (until its necessary become some third-party library to do otherwise) does not support friend declarations with in-statment function definitions.
Fields:
```cpp
2024-12-16 09:26:17 -08:00
CodeComment InlineCmt;
Code Declaration;
2024-12-13 16:16:52 -08:00
StrCached Name;
2024-12-16 09:26:17 -08:00
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
friend < Declaration > ; < InlineCmt >
```
## Function
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeType ReturnType;
2024-12-11 10:33:35 -08:00
CodeParams Params;
2023-08-22 23:17:47 -07:00
CodeBody Body;
2024-12-16 09:26:17 -08:00
StrCached Name;
2023-08-22 23:17:47 -07:00
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-11-22 12:03:24 -08:00
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-08-22 23:17:47 -07:00
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
// Function_Fwd
< ModuleFlags > < Attributes > < Specs > < ReturnType > < Name > ( < Params > ) < Specs > ; < InlineCmt >
// Function
< ModuleFlags > < Attributes > < Specs > < ReturnType > < Name > ( < Params > ) < Specs >
{
< Body >
}
```
## Module
Fields:
```cpp
2024-12-16 09:26:17 -08:00
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
ModuleFlag ModuleFlags;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
< ModuleFlags > module < Name > ;
```
## Namespace
Fields:
```cpp
2024-12-16 09:26:17 -08:00
CodeBody Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
ModuleFlag ModuleFlags;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
< ModuleFlags > namespace < Name >
{
< Body >
}
```
2024-12-11 10:33:35 -08:00
## Operator Overload (Operator)
2023-08-22 23:17:47 -07:00
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeType ReturnType;
2024-12-11 10:33:35 -08:00
CodeParams Params;
2023-08-22 23:17:47 -07:00
CodeBody Body;
2024-12-16 09:26:17 -08:00
StrCached Name;
2023-08-22 23:17:47 -07:00
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-08-22 23:17:47 -07:00
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-08-22 23:17:47 -07:00
ModuleFlag ModuleFlags;
OperatorT Op;
```
Serialization:
```cpp
// Operator_Fwd
< ModuleFlags > < Attributes > < Specs > < ReturnType > operator < Op > ( < Params > ) < Specs > ; < InlineCmt >
// Operator
< ModuleFlags > < Attributes > < Specs > < ReturnType > < Name > operator < Op > ( < Params > ) < Specs >
{
< Body >
}
```
2024-12-11 10:33:35 -08:00
## Operator Cast Overload ( User-Defined Type Conversion, OpCast )
2023-08-22 23:17:47 -07:00
Fields:
```cpp
CodeComment InlineCmt;
CodeSpecifiers Specs;
CodeType ValueType;
CodeBody Body;
2024-12-16 09:26:17 -08:00
StrCached Name;
2023-08-22 23:17:47 -07:00
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-08-22 23:17:47 -07:00
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
// Operator_Cast_Fwd
< Specs > operator < ValueType > () < Specs > ; < InlineCmt >
// Operator_Cast
< Specs > < Name > operator < ValueType > () < Specs >
{
< Body >
}
```
2024-12-11 10:33:35 -08:00
## Parameters (AST_Params)
2023-08-22 23:17:47 -07:00
Fields:
```cpp
2024-12-16 09:26:17 -08:00
CodeType ValueType;
Code Macro;
Code Value;
Code PostNameMacro;
StrCached Name;
CodeParams Last;
CodeParams Next;
Token* Tok;
Code Parent;
CodeType Type;
s32 NumEntries;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
2024-04-17 15:29:30 -07:00
< Macro > , < Next > ... < Last >
2024-12-11 10:33:35 -08:00
< Macro > < ValueType > < Name > < PostNameMacro > = < Value > , < Next > ... < Last >
2023-08-22 23:17:47 -07:00
```
## Pragma
Fields:
```cpp
2024-12-16 09:26:17 -08:00
StrCached Content;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
#pragma <Content>
```
## Preprocessor Conditional
Fields:
```cpp
2024-12-16 09:26:17 -08:00
StrCached Content;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
#<based off Type> <Content>
```
## Specifiers
Fields:
```cpp
2024-12-02 00:18:52 -08:00
SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
2023-11-22 12:03:24 -08:00
CodeSpecifiers NextSpecs;
2024-12-16 09:26:17 -08:00
StrCached Name;
2023-11-22 12:03:24 -08:00
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-11-22 12:03:24 -08:00
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-11-22 12:03:24 -08:00
s32 NumEntries;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
< Spec > , ...
```
## Template
Fields:
```cpp
2024-12-16 09:26:17 -08:00
CodeParams Params;
Code Declaration;
2024-12-13 16:16:52 -08:00
StrCached Name;
2024-12-16 09:26:17 -08:00
Code Prev;
Code Next;
Token* Tok;
Code Parent;
CodeType Type;
ModuleFlag ModuleFlags;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
< ModuleFlags >
template< < Params > >
< Declaration >
```
## Typename
Typenames represent the type "symbol".
Fields:
```cpp
CodeAttributes Attributes;
CodeSpecifiers Specs;
2023-09-04 22:44:04 -07:00
CodeReturnType ReturnType;
2024-12-11 10:33:35 -08:00
CodeParams Params;
2023-08-22 23:17:47 -07:00
Code ArrExpr;
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-08-22 23:17:47 -07:00
Code Parent;
2024-12-16 09:26:17 -08:00
StrCached Name;
CodeType Type;
2023-08-23 10:17:30 -07:00
b32 IsParamPack;
2024-12-11 10:33:35 -08:00
ETypenameTag TypeTag;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
2024-12-11 10:33:35 -08:00
< Attributes > < TypeTag > < Name > < Specs > < IsParamPack ? : . . . >
// Function
< Attributes > < ReturnType > < Name > < Params > < Specs >
2023-08-22 23:17:47 -07:00
```
2024-12-11 10:33:35 -08:00
`<Name>` currently has the full serialization of anything with
2024-12-12 09:55:15 -08:00
*Note: ArrExpr is not used in serialization by `typename_to_strbuilder_ref` its instead handled by a parent AST's serailization (variable, typedef, using).*
2024-12-11 10:33:35 -08:00
2023-08-22 23:17:47 -07:00
## Typedef
Behave as usual except function or macro typedefs.
2023-11-21 18:27:33 -08:00
Those (macros) don't use the underlying type field as everything was serialized under the Name field.
2023-08-22 23:17:47 -07:00
Fields:
```cpp
2024-12-16 09:26:17 -08:00
CodeComment InlineCmt;
Code UnderlyingType;
StrCached Name;
Code Prev;
Code Next;
Token* Tok
Code Parent;
CodeType Type;
ModuleFlag ModuleFlags;
b32 IsFunction;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
// Regular
2024-12-11 10:33:35 -08:00
< ModuleFlags > typedef < UnderlyingType > < Name > < UnderlyingType-ArrExpr > ; < InlineCmt >
2023-08-22 23:17:47 -07:00
// Functions
2024-12-11 10:33:35 -08:00
// Currently:
< ModuleFlags > typedef < UnderlyingType ( Serialized expression ) > ; < InlineCmt >
// Desired: Not handled yet
< ModuleFlags > typedef < UnderlyingType- > ReturnType> UnderlyingType->Name> < UnderlyingType-ArrExpr > ( < UnderlyingType- > Parameters> ); < InlineCmt >
< ModuleFlags > typedef < UnderlyingType- > ReturnType> ( < Name- > Namespace> for< Specs- > has(Spec_Ptr) ?: *> < UnderlyingType- > Name> < UnderlyingType-ArrExpr > ) ( < UnderlyingType- > Parameters> ); < InlineCmt >
2023-08-22 23:17:47 -07:00
```
## Union
Fields:
```cpp
CodeAttributes Attributes;
CodeBody Body;
2024-12-16 09:26:17 -08:00
StrCached Name;
2023-08-22 23:17:47 -07:00
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-08-22 23:17:47 -07:00
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-08-22 23:17:47 -07:00
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
< ModuleFlags > union < Attributes > < Name >
{
< Body >
}
```
## Using
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeType UnderlyingType;
2024-12-16 09:26:17 -08:00
StrCached Name;
2023-08-22 23:17:47 -07:00
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-08-22 23:17:47 -07:00
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-08-22 23:17:47 -07:00
ModuleFlag ModuleFlags;
```
Serialization:
```cpp
// Regular
< ModuleFlags > using < Attributes > < Name > = < UnderlyingType > ; < InlineCmt >
// Namespace
< ModuleFlags > using namespace < Name > ; < InlineCmt >
```
## Variable
2023-11-21 18:27:33 -08:00
[Algo ](./Parser_Algo.md: )
2023-08-22 23:17:47 -07:00
Fields:
```cpp
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeType ValueType;
Code BitfieldSize;
Code Value;
2024-12-16 09:26:17 -08:00
StrCached Name;
2023-11-21 18:27:33 -08:00
CodeVar NextVar;
2023-08-22 23:17:47 -07:00
Code Prev;
Code Next;
2024-12-11 10:33:35 -08:00
Token* Tok;
2023-08-22 23:17:47 -07:00
Code Parent;
2024-12-16 09:26:17 -08:00
CodeType Type;
2023-08-22 23:17:47 -07:00
ModuleFlag ModuleFlags;
2024-12-11 10:33:35 -08:00
s32 VarParenthesizedInit;
2023-08-22 23:17:47 -07:00
```
Serialization:
```cpp
// Regular
2023-11-21 18:27:33 -08:00
< ModuleFlags > < Attributes > < Specs > < ValueType > < Name > = < Value > , NextVar ...; < InlineCmt >
2023-08-22 23:17:47 -07:00
// Bitfield
2023-11-21 18:27:33 -08:00
< ModuleFlags > < Attributes > < Specs > < ValueType > < Name > : < BitfieldSize > = < Value > , NextVar ...; < InlineCmt >
2024-12-11 10:33:35 -08:00
// VarParenthesizedInit
< Attributes > < Specs > < ValueType > < Name > ( < Value > , NextVar ... ); < InlineCmt >
2023-08-22 23:17:47 -07:00
```