Compare commits

..

No commits in common. "f55e96ec6a5ac46d392cc60ed9787b468190ae15" and "2cf78790dbf719adb328485e24f30c8b59a8fed4" have entirely different histories.

28 changed files with 11684 additions and 12123 deletions

View File

@ -70,7 +70,7 @@ void AGasaCharacter::ApplyEffectToSelf(TSubclassOf<UGameplayEffect> GE, float Le
UAbilitySystemComponent* ASC = GetAbilitySystemComponent();
ensure(ASC);
ensure(GE);
FGameplayEffectContextHandle Context = ASC->MakeEffectContext(); Context.AddSourceObject(this);
FGameplayEffectContextHandle Context = ASC->MakeEffectContext();
FGameplayEffectSpecHandle Spec = ASC->MakeOutgoingSpec(GE, Level, Context );
ASC->ApplyGameplayEffectSpecToTarget( * Spec.Data, ASC );
}

View File

@ -4,11 +4,9 @@
#include "GasaCommon.generated.h"
#ifndef global
#define global
#define internal static
#define local_persist static
#endif
#ifndef ccast
#define ccast( Type, Value ) ( *const_cast<(Type)*>( &( Value ) ) )
@ -17,9 +15,7 @@
#define scast( Type, Value ) static_cast<Type>( Value )
#endif
#ifndef bit
#define bit(position) (1 << position)
#endif
#pragma region Math
#define m_pow2( value ) (value * value)
@ -49,10 +45,8 @@ class UCameraComponent;
class UGameplayEffect;
class UInputAction;
class UInputMappingContext;
class UNamedSlot;
class USphereComponent;
class USpringArmComponent;
class UTextBlock;
class UTexture2D;
#pragma endregion Engine Forwards
@ -74,9 +68,6 @@ class AGasaPlayerController;
class AGasaPlayerState;
class APlayerCharacter;
class UAttributeMenu;
class UAttributeMenu_FramedValue;
class UAttributeMenu_TextValueRow;
class UGasaAbilitySystemComp;
class UGasaAttributeSet;
class UGasaDevOptions;

View File

@ -1,3 +0,0 @@
#include "AttributeMenu.h"

View File

@ -1,14 +0,0 @@
#pragma once
#include "UI/GasaUserWidget.h"
#include "AttributeMenu.generated.h"
UCLASS(Blueprintable)
class GASA_API UAttributeMenu : public UGasaUserWidget
{
GENERATED_BODY()
public:
};

View File

@ -1,26 +0,0 @@
#include "FramedValue.h"
#include "UI/GasaImage.h"
#include "Components/TextBlock.h"
#include "UI/GasaSizeBox.h"
void UAttributeMenu_FramedValue::SetBackgroundBrush(FSlateBrush Brush)
{
BG->SetBrush(Brush);
}
void UAttributeMenu_FramedValue::SetBorderBrush(FSlateBrush Brush)
{
Border->SetBrush(Brush);
}
void UAttributeMenu_FramedValue::SetBoxSize(float Width, float Height)
{
SB_Root->SetWidthOverride(Width);
SB_Root->SetHeightOverride(Height);
}
void UAttributeMenu_FramedValue::SetText(FText Content)
{
Value->SetText(Content);
}

View File

@ -1,42 +0,0 @@
#pragma once
#include "UI/GasaUserWidget.h"
#include "FramedValue.generated.h"
UCLASS(Blueprintable)
class GASA_API UAttributeMenu_FramedValue : public UGasaUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame", meta=(BindWidget))
UGasaSizeBox* SB_Root;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame", meta=(BindWidget))
UGasaImage* BG;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame", meta=(BindWidget))
UGasaImage* Border;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame", meta=(BindWidget))
UTextBlock* Value;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame")
float BoxHeight;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame")
float BoxWidth;
UFUNCTION(BlueprintCallable)
void SetBackgroundBrush(FSlateBrush Brush);
UFUNCTION(BlueprintCallable)
void SetBorderBrush(FSlateBrush Brush);
UFUNCTION(BlueprintCallable)
void SetBoxSize(float Width, float Height);
UFUNCTION(BlueprintCallable)
void SetText(FText Content);
};

View File

@ -1,21 +0,0 @@
#include "TextValueRow.h"
#include "Components/TextBlock.h"
#include "UI/GasaSizeBox.h"
void UAttributeMenu_TextValueRow::SetAttributeName(FText Name)
{
TB_AttributeName->SetText(Name);
}
void UAttributeMenu_TextValueRow::SetBoxSize(float Width, float Height)
{
SB_Root->SetWidthOverride(Width);
SB_Root->SetHeightOverride(Height);
}
void UAttributeMenu_TextValueRow::NativePreConstruct()
{
Super::NativePreConstruct();
}

View File

@ -1,43 +0,0 @@
#pragma once
#include "UI/GasaUserWidget.h"
#include "TextValueRow.generated.h"
UCLASS(Blueprintable)
class GASA_API UAttributeMenu_TextValueRow : public UGasaUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame", meta=(BindWidget))
UGasaSizeBox* SB_Root;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame", meta=(BindWidget))
UTextBlock* TB_AttributeName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame", meta=(BindWidget))
UAttributeMenu_FramedValue* Value;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame", meta=(BindWidget))
UNamedSlot* NSlot;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame")
FText AttributeName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame")
float BoxHeight;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Frame")
float BoxWidth;
UFUNCTION(BlueprintCallable)
void SetAttributeName(FText Name);
UFUNCTION(BlueprintCallable)
void SetBoxSize(float Width, float Height);
#pragma region UserWidget
void NativePreConstruct() override;
#pragma endregion UserWidget
};

View File

@ -196,3 +196,4 @@ void UGlobeProgressBar::Serialize(FStructuredArchive::FRecord Record)
Super::Serialize(Record);
}
#pragma endregion UserWidget

View File

@ -1,58 +1,44 @@
## Navigation
[Top](../Readme.md)
<- [docs - General](Readme.md)
## 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:
For user-facing code, they should never be giveen a nullptr. Instead, they should be given a designated `Invalid` AST node.
When its the [C generated variant of the library](../gen_c_library/)
```c
typedef AST* Code;
tyepdef AST_<name>* Code<name>;
...
```
In order to abstract away constant use of `AST*`, I wanted to provide a wrapper for it.
**or**
The simpliest being just a type alias.
For C++:
```cpp
struct Code {
AST* ast;
};
struct Code<name> {
...
AST_<name>* ast;
};
using Code = AST*;
```
The full definitions of all asts are within:
This is what the genc library would have to use due to its constraints of a langauge.
The actual content per type of AST is covered within [AST_Types.md](AST_Types.md).
* [`ast.hpp`](../base/components/ast.hpp)
* [`ast_types.hpp`](../base/components/ast_types.hpp)
* [`code_types.hpp`](../base/components/code_types.hpp)
These are pure PODS that just have the lay members relevant to the type of AST node they represent.
Each of them has a Code type alias specific to it.
The C/C++ interface procedures are located with `ast.hpp` (for the Code type), and `code_types.hpp` for all others.
Again, the simpliest case for these would be a type alias.
## Serialization
All code types can either serialize using a function of the pattern:
```c
StrBuilder <prefix>_to_strbuilder(Code code);
// or
<prefix>_to_strbuilder(Code code, StrBuilder& result);
```cpp
using struct AST_Typedef CodeTypedef;
```
Where the first generates strings allocated using Allocator_StringArena and the other appends an existing strings with their backed allocator.
As of November 21st, 2023, the AST has had a strict layout for how its content is laid out.
This will be abandoned during its redesign that will occur starting with support for statments & expressions for either execution and type declarations.
Having a strict layout is too resctrictive vs allowing each AST type to have maximum control over the layout.
The redesign will occur after the following todos are addressed:
* [Improvements Lexer & Token struct#27](https://github.com/Ed94/gencpp/issues/27)
* [Generalize AST Flags to a single 4-byte flag#42](https://github.com/Ed94/gencpp/issues/42)
* [AST-Code Object Redesign.#38](https://github.com/Ed94/gencpp/issues/38)
* [Code-AST Documentation#40](https://github.com/Ed94/gencpp/issues/40)
* [AST::debug_str() improvements#33](https://github.com/Ed94/gencpp/issues/33)
* [AST::is_equal implemented and works with singleheader-test#31](https://github.com/Ed94/gencpp/issues/31)
* [Parser : Add ability to have a parse failure and continue with errors recorded.#35](https://github.com/Ed94/gencpp/issues/35)
* [Scanner : Add CodeFile#29](https://github.com/Ed94/gencpp/issues/29)
* [Auxiliary : AST visual debugger#36](https://github.com/Ed94/gencpp/issues/36)
Serialization of for the AST is defined for `Code` in [`ast.chpp`](../base/components/ast.cpp) with `code_to_strbuilder_ptr` & `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.

View File

@ -1,16 +1,10 @@
## Navigation
[Top](../Readme.md)
<- [docs - General](Readme.md)
# AST Types Documentation
While the Readme for docs covers the data layout per AST, this will focus on the AST types avaialble, and their nuances.
## Body
These are containers representing a scope body of a definition that can be of the following `CodeType` type:
These are containers representing a scope body of a definition that can be of the following `ECode` type:
* Class_Body
* Enum_Body
@ -25,11 +19,11 @@ These are containers representing a scope body of a definition that can be of th
Fields:
```cpp
StrCached Name;
Code Front;
Code Back;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
s32 NumEntries;
```
@ -37,15 +31,14 @@ s32 NumEntries;
The `Front` member represents the start of the link list and `Back` the end.
NumEntries is the number of entries in the body.
Parent should have a compatible CodeType type for the type of defintion used.
Parent should have a compatible ECode type for the type of defintion used.
Serialization:
Will output only the entries, the braces are handled by the parent.
```cpp
<Front>
...
<Front>...
<Back>
```
@ -56,12 +49,12 @@ Represent standard or vendor specific C/C++ attributes.
Fields:
```cpp
StrCached Content;
StrCached Name;
StringCached Content;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -80,12 +73,12 @@ Stores a comment.
Fields:
```cpp
StrCached Content;
StrCached Name;
StringCached Content;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -109,11 +102,11 @@ CodeComment InlineCmt; // Only supported by forward declarations
CodeAttributes Attributes;
CodeType ParentType;
CodeBody Body;
StrCached Name;
CodeType Prev;
CodeType Next;
Token* Tok;
CodeType Prev; // Used to store references to interfaces
CodeType Next; // Used to store references to interfaces
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
AccessSpec ParentAccess;
@ -132,7 +125,7 @@ Serialization:
};
```
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.
You'll notice that only one parent type is supported only with parent access. This library only supports single inheritance, the rest must be done through interfaces.
## Constructor
@ -141,13 +134,13 @@ Fields:
```cpp
CodeComment InlineCmt; // Only supported by forward declarations
Code InitializerList;
CodeParams Params;
CodeParam Params;
Code Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -178,12 +171,12 @@ Represents a preprocessor define
Fields:
```cpp
StrCached Content;
StrCached Name;
StringCached Content;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -201,11 +194,11 @@ Fields:
CodeComment InlineCmt;
CodeSpecifiers Specs;
Code Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -236,28 +229,24 @@ Fields:
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeType UnderlyingType;
Code UnderlyingTypeMacro;
CodeBody Body;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StrCached Name;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
UnderlyingTypeMacro is a macro the library natively supports: `enum_underlying(type)` that is meant to behave as a wrapper for underlying type assignment.
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.
Serialization:
```cpp
// Enum_Fwd
<ModuleFlags> enum class <Name> : <UnderlyingType> or <UnderlyingTypeMacro> ; <InlineCmt>
<ModuleFlags> enum class <Name> : <UnderlyingType>; <InlineCmt>
// Enum
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType> or <UnderlyingTypeMacro>
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType>
{
<Body>
};
@ -271,12 +260,12 @@ Will be obsolute when function body parsing is implemented.
Fields:
```cpp
StrCached Content;
StrCached Name;
StringCached Content;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -292,11 +281,11 @@ Fields:
```cpp
CodeBody Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -314,12 +303,12 @@ extern "<Name>"
Fields:
```cpp
StrCached Content;
StrCached Name;
StringCached Content;
Code Prev;
Code Next;
Code Parent;
Token* Tok;
parser::Token* Tok;
StringCached Name;
CodeT Type;
```
@ -338,11 +327,11 @@ Fields:
```cpp
CodeComment InlineCmt;
Code Declaration;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -361,13 +350,13 @@ CodeComment InlineCmt;
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeType ReturnType;
CodeParams Params;
CodeParam Params;
CodeBody Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
@ -390,11 +379,11 @@ Serialization:
Fields:
```cpp
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
@ -411,11 +400,11 @@ Fields:
```cpp
CodeBody Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
@ -429,7 +418,7 @@ Serialization:
}
```
## Operator Overload (Operator)
## Operator Overload
Fields:
@ -438,13 +427,13 @@ CodeComment InlineCmt;
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeType ReturnType;
CodeParams Params;
CodeParam Params;
CodeBody Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
OperatorT Op;
@ -463,7 +452,7 @@ Serialization:
}
```
## Operator Cast Overload ( User-Defined Type Conversion, OpCast )
## Operator Cast Overload ( User-Defined Type Conversion )
Fields:
@ -472,11 +461,11 @@ CodeComment InlineCmt;
CodeSpecifiers Specs;
CodeType ValueType;
CodeBody Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -493,7 +482,7 @@ Serialization:
}
```
## Parameters (AST_Params)
## Parameters (AST_Param)
Fields:
@ -501,12 +490,11 @@ Fields:
CodeType ValueType;
Code Macro;
Code Value;
Code PostNameMacro;
StrCached Name;
CodeParams Last;
CodeParams Next;
Token* Tok;
CodeParam Last;
CodeParam Next;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
s32 NumEntries;
```
@ -516,7 +504,7 @@ Serialization:
```cpp
<Macro>, <Next> ... <Last>
<Macro> <ValueType> <Name> <PostNameMacro> = <Value>, <Next>... <Last>
<Macro> <ValueType> <Name>, <Next>... <Last>
```
## Pragma
@ -524,12 +512,12 @@ Serialization:
Fields:
```cpp
StrCached Content;
StrCached Name;
StringCached Content;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -544,12 +532,12 @@ Serialization:
Fields:
```cpp
StrCached Content;
StrCached Name;
StringCached Content;
Code Prev;
Code Next;
Token* Tok;
paser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
```
@ -564,13 +552,13 @@ Serialization:
Fields:
```cpp
SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
SpecifierT ArrSpecs[ AST::ArrSpecs_Cap ];
CodeSpecifiers NextSpecs;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
s32 NumEntries;
```
@ -586,13 +574,13 @@ Serialization:
Fields:
```cpp
CodeParams Params;
CodeParam Params;
Code Declaration;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
@ -615,30 +603,23 @@ Fields:
CodeAttributes Attributes;
CodeSpecifiers Specs;
CodeReturnType ReturnType;
CodeParams Params;
CodeParam Params;
Code ArrExpr;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StrCached Name;
StringCached Name;
CodeT Type;
b32 IsParamPack;
ETypenameTag TypeTag;
```
Serialization:
```cpp
<Attributes> <TypeTag> <Name> <Specs> <IsParamPack ?: ...>
// Function
<Attributes> <ReturnType> <Name> <Params> <Specs>
<Attributes> <Name> <Specs> <IsParamPack ?: ...>
```
`<Name>` currently has the full serialization of anything with
*Note: ArrExpr is not used in serialization by `typename_to_strbuilder_ref` its instead handled by a parent AST's serailization (variable, typedef, using).*
## Typedef
Behave as usual except function or macro typedefs.
@ -649,11 +630,11 @@ Fields:
```cpp
CodeComment InlineCmt;
Code UnderlyingType;
StrCached Name;
Code Prev;
Code Next;
Token* Tok
parse::Token* Tok
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
b32 IsFunction;
@ -663,16 +644,11 @@ Serialization:
```cpp
// Regular
<ModuleFlags> typedef <UnderlyingType> <Name> <UnderlyingType-ArrExpr>; <InlineCmt>
<ModuleFlags> typedef <UnderlyingType> <Name>; <InlineCmt>
// Functions
// 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>
<ModuleFlags> typedef <ReturnType> <Name>( <Parameters> ); <InlineCmt>
<ModuleFlags> typedef <ReturnType> ( <Expression that yeilds an Identifier signature> )( <Parameters> ); <InlineCmt>
```
## Union
@ -682,11 +658,11 @@ Fields:
```cpp
CodeAttributes Attributes;
CodeBody Body;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
@ -708,11 +684,11 @@ Fields:
CodeComment InlineCmt;
CodeAttributes Attributes;
CodeType UnderlyingType;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
```
@ -740,15 +716,14 @@ CodeSpecifiers Specs;
CodeType ValueType;
Code BitfieldSize;
Code Value;
StrCached Name;
CodeVar NextVar;
Code Prev;
Code Next;
Token* Tok;
parser::Token* Tok;
Code Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
s32 VarParenthesizedInit;
```
Serialization:
@ -759,7 +734,4 @@ Serialization:
// Bitfield
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> : <BitfieldSize> = <Value>, NextVar ...; <InlineCmt>
// VarParenthesizedInit
<Attributes> <Specs> <ValueType> <Name>( <Value>, NextVar ... ); <InlineCmt>
```

View File

@ -1,9 +1,3 @@
## Navigation
[Top](../Readme.md)
<- [docs - General](Readme.md)
# Parser's Algorithim
gencpp uses a hand-written recursive descent parser. Both the lexer and parser currently handle a full C/C++ file in a single pass.
@ -12,8 +6,8 @@ gencpp uses a hand-written recursive descent parser. Both the lexer and parser c
### Lexer
The lex procedure does the lexical pass of content provided as a `Str` type.
The tokens are stored (for now) in `Lexer_Tokens`.
The lex procedure does the lexical pass of content provided as a `StrC` type.
The tokens are stored (for now) in `gen::parser::Tokens`.
Fields:
@ -22,7 +16,7 @@ Array<Token> Arr;
s32 Idx;
```
What token types are supported can be found in [ETokType.csv](../base/enums/ETokType.csv) you can also find the token types in [ETokType.h](../base/components/gen/etoktype.cpp) , which is the generated enum from the csv file.
What token types are supported can be found in [ETokType.csv](../project/enums/ETokType.csv) you can also find the token types in [ETokType.h](../project/components/gen/etoktype.cpp) , which is the generated enum from the csv file.
Tokens are defined with the struct `gen::parser::Token`:
@ -75,7 +69,7 @@ The parser has a limited user interface, only specific types of definitions or s
Each public user interface procedure has the following format:
```cpp
<code type> parse_<definition type>( Str def )
<code type> parse_<definition type>( StrC def )
{
check_parse_args( def );
using namespace Parser;
@ -287,7 +281,7 @@ In the future statements and expressions will be parsed.
1. Attributes ( Standard, GNU, MSVC, Macro ) : `parse_attributes`
2. Specifiers ( consteval, constexpr, constinit, extern, forceinline, global, inline, internal_linkage, neverinline, static )
3. Is either ( identifier, const specifier, long, short, signed, unsigned, bool, char, double, int)
1. Attempt to parse as construtor or destructor : `parse_global_nspace_constructor_destructor`
1. Attempt to parse as constrcutor or destructor : `parse_global_nspace_constructor_destructor`
2. If its an operator cast (definition outside class) : `parse_operator_cast`
3. Its an operator, function, or varaible : `parse_operator_function_or_varaible`
4. If its not a global body, consume the closing curly brace

View File

@ -1,39 +1,33 @@
## Navigation
[Top](../Readme.md)
<- [docs - General](Readme.md)
# Parsing
The library features a naive single-pass parser tailored for only what the library needs to construct the supported syntax of C++ into its AST for *"front-end"* meta-programming purposes.
The library features a naive parser tailored for only what the library needs to construct the supported syntax of C++ into its AST.
This parser does not, and should not do the compiler's job. By only supporting this minimal set of features, the parser is kept (so far) around ~7000 loc. I hope to keep it under 10k loc worst case.
This parser does not, and should not do the compiler's job. By only supporting this minimal set of features, the parser is kept (so far) around ~5600 loc. I hope to keep it under 10k loc worst case.
You can think of this parser as *frontend parser* vs a *semantic parser*. Its intuitively similar to WYSIWYG. What you ***precerive*** as the syntax from the user-side before the compiler gets a hold of it, is what you get.
You can think of this parser of a frontend parser vs a semantic parser. Its intuitively similar to WYSIWYG. What you precerive as the syntax from the user-side before the compiler gets a hold of it, is what you get.
User exposed interface:
```cpp
CodeClass parse_class ( Str class_def );
CodeConstructor parse_constructor ( Str constructor_def );
CodeDestructor parse_destructor ( Str destructor_def );
CodeEnum parse_enum ( Str enum_def );
CodeBody parse_export_body ( Str export_def );
CodeExtern parse_extern_link ( Str exten_link_def );
CodeFriend parse_friend ( Str friend_def );
CodeFn parse_function ( Str fn_def );
CodeBody parse_global_body ( Str body_def );
CodeNS parse_namespace ( Str namespace_def );
CodeOperator parse_operator ( Str operator_def );
CodeOpCast parse_operator_cast( Str operator_def );
CodeStruct parse_struct ( Str struct_def );
CodeTemplate parse_template ( Str template_def );
CodeType parse_type ( Str type_def );
CodeTypedef parse_typedef ( Str typedef_def );
CodeUnion parse_union ( Str union_def );
CodeUsing parse_using ( Str using_def );
CodeVar parse_variable ( Str var_def );
CodeClass parse_class ( StrC class_def );
CodeConstructor parse_constructor ( StrC constructor_def );
CodeDestructor parse_destructor ( StrC destructor_def );
CodeEnum parse_enum ( StrC enum_def );
CodeBody parse_export_body ( StrC export_def );
CodeExtern parse_extern_link ( StrC exten_link_def );
CodeFriend parse_friend ( StrC friend_def );
CodeFn parse_function ( StrC fn_def );
CodeBody parse_global_body ( StrC body_def );
CodeNS parse_namespace ( StrC namespace_def );
CodeOperator parse_operator ( StrC operator_def );
CodeOpCast parse_operator_cast( StrC operator_def );
CodeStruct parse_struct ( StrC struct_def );
CodeTemplate parse_template ( StrC template_def );
CodeType parse_type ( StrC type_def );
CodeTypedef parse_typedef ( StrC typedef_def );
CodeUnion parse_union ( StrC union_def );
CodeUsing parse_using ( StrC using_def );
CodeVar parse_variable ( StrC var_def );
```
To parse file buffers, use the `parse_global_body` function.
@ -53,11 +47,10 @@ The keywords supported for the preprocessor are:
* endif
* pragma
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST.
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST. *These ASTs will be considered members or entries of braced scope they reside within*.
If a directive is used with an unsupported keyword its will be processed as an untyped AST.
The preprocessor lines are stored as members of their associated scope they are parsed within. ( Global, Namespace, Class/Struct )
***Again (Its not standard): These ASTs will be considered members or entries of braced scope they reside within***
Any preprocessor definition abuse that changes the syntax of the core language is unsupported and will fail to parse if not kept within an execution scope (function body, or expression assignment).
Exceptions:
@ -66,8 +59,6 @@ Exceptions:
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES`
* typedefs allow for a preprocessed macro: `typedef MACRO();`
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_TYPEDEF`
* Macros can behave as typenames
* There is some macro support in paramters for functions or templates *(Specifically added to support parsing Unreal Engine source)*.
*(Exceptions are added on an on-demand basis)*
*(See functions `parse_operator_function_or_variable` and `parse_typedef` )*
@ -76,23 +67,15 @@ Adding your own exceptions is possible by simply modifying the parser to allow f
*Note: You could interpret this strictness as a feature. This would allow the user to see if their codebase or a third-party's codebase some some egregious preprocessor abuse.*
If a macro is not defined withint e scope of parsing a set of files, it can be defined beforehand by:
* Appending the [`PreprocessorDefines`](https://github.com/Ed94/gencpp/blob/a18b5b97aa5cfd20242065cbf53462a623cd18fa/base/components/header_end.hpp#L137) array.
* For functional macros a "(" just needs to be added after the name like: `<name>(` so that it will tokenize its arguments as part of the token during lexing.
* Defining a CodeDefine using `def_define`. The definition will be processed by the interface for user into `PreprocessorDefines`.
* This can be prevented by setting the optional prameter `dont_append_preprocess_defines`.
The lexing and parsing takes shortcuts from whats expected in the standard.
* Numeric literals are not checked for validity.
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs. (There is a [todo](https://github.com/Ed94/gencpp/issues/49) to add support)
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
* *This includes the assignment of variables.*
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
* Assumed to *come before specifiers* (`const`, `constexpr`, `extern`, `static`, etc) for a function or right afterthe return type.
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
* typedefs have attributes with the type (`parse_type`)
* Parsing attributes can be extended to support user defined macros by defining `GEN_DEFINE_ATTRIBUTE_TOKENS` (see `gen.hpp` for the formatting)
* This is useful for example: parsing Unreal `Module_API` macros.
Empty lines used throughout the file are preserved for formatting purposes during ast serialization.

View File

@ -1,17 +1,137 @@
## Navigation
# gencpp
# base
An attempt at simple staged metaprogramming for c/c++.
[Top](../Readme.md)
The library API is a composition of code element constructors.
These build up a code AST to then serialize with a file builder.
* [docs](../docs/Readme.md)
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
Its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain.
# Unreal Engine Version Generator
## Notes
This generates a variant of gencpp thats compatiable with use as a thirdparty module within a plugin or module of an Unreal Project or the Engine itself.
**On Partial Hiatus: Life has got me tackling other issues..**
I will be passively updating the library with bug fixes and minor improvements as I use it for my personal projects.
There won't be any major reworks or features to this thing for a while.
If using the library's provided build scripts:
This project is still in development (very much an alpha state), so expect bugs and missing features.
See [issues](https://github.com/Ed94/gencpp/issues) for a list of known bugs or todos.
The library can already be used to generate code just fine, but the parser is where the most work is needed. If your C++ isn't "down to earth" expect issues.
A `natvis` and `natstepfilter` are provided in the scripts directory (its outdated, I'll update this readme when its not).
***The editor and scanner have not been implemented yet. The scanner will come first, then the editor.***
A C variant is hosted [here](https://github.com/Ed94/genc); I will complete it when this library is feature complete, it should be easier to make than this...
## Usage
A metaprogram is built to generate files before the main program is built. We'll term runtime for this program as `GEN_TIME`. The metaprogram's core implementation are within `gen.hpp` and `gen.cpp` in the project directory.
`gen.cpp` \`s `main()` is defined as `gen_main()` which the user will have to define once for their program. There they will dictate everything that should be generated.
In order to keep the locality of this code within the same files the following pattern may be used (although this pattern isn't required at all):
Within `program.cpp` :
```cpp
#ifdef GEN_TIME
#include "gen.hpp"
...
u32 gen_main()
{
...
}
#endif
// "Stage" agnostic code.
#ifndef GEN_TIME
#include "program.gen.cpp"
// Regular runtime dependent on the generated code here.
#endif
```ps1
.\build.ps1 <compiler> <debug or omit> unreal
```
The design uses a constructive builder API for the code to generate.
The user is provided `Code` objects that are used to build up the AST.
Example using each construction interface:
### Upfront
Validation and construction through a functional interface.
```cpp
Code t_uw = def_type( name(usize) );
Code t_allocator = def_type( name(allocator) );
Code t_string_const = def_type( name(char), def_specifiers( args( ESpecifier::Const, ESpecifier::Ptr ) ));
Code header;
{
Code num = def_variable( t_uw, name(Num) );
Code cap = def_variable( t_uw, name(Capacity) );
Code mem_alloc = def_variable( t_allocator, name(Allocator) );
Code body = def_struct_body( args( num, cap, mem_alloc ) );
header = def_struct( name(ArrayHeader), __, __, body );
}
```
### Parse
Validation through ast construction.
```cpp
Code header = parse_struct( code(
struct ArrayHeader
{
usize Num;
usize Capacity;
allocator Allocator;
};
));
```
### Untyped
No validation, just glorified text injection.
```cpp
Code header = code_str(
struct ArrayHeader
{
usize Num;
usize Capacity;
allocator Allocator;
};
);
```
`name` is a helper macro for providing a string literal with its size, intended for the name parameter of functions.
`code` is a helper macro for providing a string literal with its size, but intended for code string parameters.
`args` is a helper macro for providing the number of arguments to varadic constructors.
`code_str` is a helper macro for writting `untyped_str( code( <content> ))`
All three constrcuton interfaces will generate the following C code:
```cpp
struct ArrayHeader
{
usize Num;
usize Capacity;
allocator Allocator;
};
```
**Note: The formatting shown here is not how it will look. For your desired formatting its recommended to run a pass through the files with an auto-formatter.**
*(The library currently uses clang-format for formatting, beware its pretty slow...)*
## Building
See the [scripts directory](scripts/).

View File

@ -1,18 +1,48 @@
# General Docs
## Documentation
[Top](../Readme.md)
The project has no external dependencies beyond:
Contains:
* `errno.h`
* `stat.h`
* `stdarg.h`
* `stddef.h`
* `stdio.h`
* `copyfile.h` (Mac)
* `types.h` (Linux)
* `unistd.h` (Linux/Mac)
* `intrin.h` (Windows)
* `io.h` (Windows with gcc)
* `windows.h` (Windows)
* [AST_Design](./AST_Design.md): Overview of ASTs
* [AST Types](./AST_Types.md): Listing of all AST types along with their Code type interface.
* [Parsing](./Parsing.md): Overview of the parsing interface.
* [Parser Algo](./Parser_Algo.md): In-depth breakdown of the parser's implementation.
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
### *CURRENTLY UNSUPPORTED*
This library was written in a subset of C++ where the following are not used at all:
* RAII (Constructors/Destructors), lifetimes are managed using named static or regular functions.
* Language provide dynamic dispatch, RTTI
* Object-Oriented Inheritance
* Exceptions
Polymorphic & Member-functions are used as an ergonomic choice, along with a conserative use of operator overloads.
There are only 4 template definitions in the entire library. (`Array<Type>`, `Hashtable<Type>`, `swap<Type>`, and `AST/Code::cast<Type>`)
Two generic templated containers are used throughout the library:
* `template< class Type> struct Array`
* `template< class Type> struct HashTable`
Both Code and AST definitions have a `template< class Type> Code/AST :: cast()`. Its just an alternative way to explicitly cast to each other.
`template< class Type> swap( Type& a, Type& b)` is used over a macro.
Otherwise the library is free of any templates.
### *WHAT IS NOT PROVIDED*
**There is no support for validating expressions.**
Its a [todo](https://github.com/Ed94/gencpp/issues/49)
Its difficult to parse without enough benefits (At the metaprogramming level).
I plan to add this only at the tail of the project parsing milestone.
**Only trivial template support is provided.**
The intention is for only simple, non-recursive substitution.
@ -23,20 +53,10 @@ This means that the typename entry for the parameter AST would be either:
* `typename`
* A fundamental type, function, or pointer type.
***Concepts and Constraints are not supported***
Its a [todo](https://github.com/Ed94/gencpp/issues/21)
Anything beyond this usage is not supported by parse_template for arguments (at least not intentionally).
Use at your own mental peril.
### Feature Macros:
* `GEN_DEFINE_ATTRIBUTE_TOKENS` : Allows user to define their own attribute macros for use in parsing.
* This can be generated using base.cpp.
* `GEN_DEFINE_LIBRARY_CORE_CONSTANTS` : Optional typename codes as they are non-standard to C/C++ and not necessary to library usage
* `GEN_DONT_ENFORCE_GEN_TIME_GUARD` : By default, the library ( gen.hpp/ gen.cpp ) expects the macro `GEN_TIME` to be defined, this disables that.
* `GEN_ENFORCE_STRONG_CODE_TYPES` : Enforces casts to filtered code types.
* `GEN_EXPOSE_BACKEND` : Will expose symbols meant for internal use only.
* `GEN_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
* `GEN_DONT_ALLOW_INVALID_CODE` (Not implemented yet) : Will fail when an invalid code is constructed, parsed, or serialized.
* `GEN_C_LIKE_PP` : Setting to `<true or 1>` Will prevent usage of function defnitions using references and structs with member functions. Structs will still have user-defined operator conversions, for-range support, and other operator overloads
*Concepts and Constraints are not supported, its usage is non-trivial substitution.*
### The Data & Interface
@ -45,33 +65,87 @@ As mentioned in root readme, the user is provided Code objects by calling the co
The AST is managed by the library and provided to the user via its interface.
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 redesign):
https://github.com/Ed94/gencpp/blob/eea4ebf5c40d5d87baa465abfb1be30845b2377e/base/components/ast.hpp#L396-L461
```cpp
union {
struct
{
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
AST* Specs; // Destructor, Function, Operator, Typename, Variable
union {
AST* InitializerList; // Constructor
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
AST* ReturnType; // Function, Operator, Typename
AST* UnderlyingType; // Enum, Typedef
AST* ValueType; // Parameter, Variable
};
union {
AST* Macro; // Parameters
AST* BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename
};
union {
AST* ArrExpr; // Typename
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template
AST* Value; // Parameter, Variable
};
union {
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
};
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers
};
};
union {
AST* Prev;
AST* Front;
AST* Last;
};
union {
AST* Next;
AST* Back;
};
AST* Parent;
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
union {
b32 IsFunction; // Used by typedef to not serialize the name field.
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
OperatorT Op;
AccessSpec ParentAccess;
s32 NumEntries;
};
s32 Token; // Handle to the token, stored in the CodeFile (Otherwise unretrivable)
```
*`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`*
*`CodeT` is a typedef for `ECode::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*
*`StringCahced` is a typedef for `String const`, to denote it is an interned string*
*`String` is the dynamically allocated string type for the library*
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:
```cpp
constexpr static
int AST_ArrSpecs_Cap =
usize ArrSpecs_Cap =
(
AST_POD_Size
- sizeof(Code)
- sizeof(StrCached)
- sizeof(Code) * 2
- sizeof(Token*)
- sizeof(Code)
- sizeof(CodeType)
- sizeof(AST*) * 3
- sizeof(StringCached)
- sizeof(CodeT)
- sizeof(ModuleFlag)
- sizeof(u32)
)
/ sizeof(Specifier) - 1;
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes (Odd num of AST*)
```
*Ex: If the AST_POD_Size is 128 the capacity of the static array is 20.*
@ -79,8 +153,8 @@ int AST_ArrSpecs_Cap =
Data Notes:
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
* You'll find the memory handling in `init`, `deinit`, `reset`, `gen_strbuilder_allocator`, `cache_str`, `make_code`.
* Allocators are defined with the `AllocatorInfo` structure found in [`memory.hpp`](../base/dependencies/memory.hpp)
* You'll find the memory handling in `init`, `deinit`, `reset`, `gen_string_allocator`, `get_cached_string`, `make_code`.
* Allocators are defined with the `AllocatorInfo` structure found in `dependencies\memory.hpp`
* Most of the work is just defining the allocation procedure:
```cpp
@ -88,30 +162,30 @@ Data Notes:
```
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
* Code types have member symbols but their data layout is enforced to be POD types.
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
* This library treats memory failures as fatal.
* Cached Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content.
* `StringArenas`, `StringCache`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators.
* Strings used for serialization and file buffers are not contained by those used for cached strings.
* They are currently using `FallbackAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
* They are currently using `GlobalAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
* Memory within the buckets is not reused, so its inherently wasteful.
* I will be augmenting the default allocator with virtual memory & a slab allocator in the [future](https://github.com/Ed94/gencpp/issues/12)
* Intrusive linked lists used children nodes on bodies, and parameters.
* I will be augmenting the single arena with a simple slag allocator.
* Linked lists used children nodes on bodies, and parameters.
* Its intended to generate the AST in one go and serialize after. The constructors and serializer are designed to be a "one pass, front to back" setup.
* Allocations can be tuned by defining the folloiwng macros (will be moved to runtime configuration in the future):
* Allocations can be tuned by defining the folloiwng macros:
* `GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
* `GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
* `TokenMap_FixedArena` : token_fmt_va uses local_persit memory of this arena type for the hashtable.
* `GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE` : token_fmt_va uses local_persit memory of this size for the hashtable.
* `GEN_LEX_ALLOCATOR_SIZE`
* `GEN_BUILDER_STR_BUFFER_RESERVE`
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
* CodeBody : Has support for `for : range` iterating across Code objects.
* CodeBody : Has support for `for-range` iterating across Code objects.
* CodeAttributes
* CodeComment
* CodeClass
@ -128,13 +202,13 @@ The following CodeTypes are used which the user may optionally use strong typing
* CodeNS
* CodeOperator
* CodeOpCast
* CodeParams : Has support for `for : range` iterating across parameters.
* CodeParam : Has support for `for-range` iterating across parameters.
* CodePreprocessCond
* CodePragma
* CodeSpecifiers : Has support for `for : range` iterating across specifiers.
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
* CodeStruct
* CodeTemplate
* CodeTypename
* CodeType
* CodeTypedef
* CodeUnion
* CodeUsing
@ -219,7 +293,6 @@ Code <name>
```
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
```cpp
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
@ -300,7 +373,6 @@ Code <name> = untyped_str( code(
```
Optionally, `code_str`, and `code_fmt` macros can be used so that the code macro doesn't have to be used:
```cpp
Code <name> = code_str( <some code without "" quotes > )
```
@ -308,7 +380,7 @@ Code <name> = code_str( <some code without "" quotes > )
Template metaprogramming in the traditional sense becomes possible with the use of `token_fmt` and parse constructors:
```cpp
Str value = txt("Something");
StrC value = txt("Something");
char const* template_str = txt(
Code with <key> to replace with token_values
@ -330,8 +402,8 @@ The following are provided predefined by the library as they are commonly used:
* `module_global_fragment`
* `module_private_fragment`
* `fmt_newline`
* `pragma_once`
* `param_varaidc` (Used for varadic definitions)
* `pragma_once`
* `preprocess_else`
* `preprocess_endif`
* `spec_const`
@ -347,7 +419,6 @@ The following are provided predefined by the library as they are commonly used:
* `spec_local_persist` (local_persist macro)
* `spec_mutable`
* `spec_neverinline`
* `spec_noexcept`
* `spec_override`
* `spec_ptr`
* `spec_pure`
@ -379,8 +450,8 @@ Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` i
* `t_u16`
* `t_u32`
* `t_u64`
* `t_ssize` (ssize_t)
* `t_usize` (size_t)
* `t_sw` (ssize_t)
* `t_uw` (size_t)
* `t_f32`
* `t_f64`
@ -398,12 +469,15 @@ and have the desired specifiers assigned to them beforehand.
## Code generation and modification
There are two provided auxillary interfaces:
There are three provided auxillary interfaces:
* Builder
* Editor
* Scanner
### Builder is a similar object to the jai language's strbuilder_builder
Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FEATURE_SCANNER` to enable them.
### Builder is a similar object to the jai language's string_builder
* The purpose of it is to generate a file.
* A file is specified and opened for writing using the open( file_path) function.
@ -412,8 +486,4 @@ There are two provided auxillary interfaces:
### Scanner Auxillary Interface
* The purpose is to scan or parse files
* Some with two basic functions to convert a fil to code: `scan_file` and `parse_file`
* `scan_file`: Merely grabs the file and stores it in an untyped Code.
* `parse_file`: Will parse the file using `parse_global_body` and return a `CodeBody`.
* Two basic functions for grabbing columns from a CSV: `parse_csv_one_column` and `parse_csv_two_columns`
Provides *(eventually)* `scan_file` to automatically populate a CodeFile which contains a parsed AST (`Code`) of the file, with any contextual failures that are reported from the parser.

View File

@ -9,9 +9,6 @@
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wvarargs"
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
# pragma clang diagnostic ignored "-W#pragma-messages"
# pragma clang diagnostic ignored "-Wstatic-in-inline"
#endif
#ifdef __GNUC__
@ -26,9 +23,7 @@
GEN_NS_BEGIN
#pragma region Builder
Builder builder_open( char const* path )
Builder Builder::open( char const* path )
{
Builder result;
@ -39,49 +34,51 @@ Builder builder_open( char const* path )
return result;
}
result.Buffer = strbuilder_make_reserve( _ctx->Allocator_Temp, _ctx->InitSize_BuilderBuffer );
result.Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
return result;
}
void builder_pad_lines( Builder* builder, s32 num )
void Builder::pad_lines( s32 num )
{
strbuilder_append_str( & builder->Buffer, txt("\n") );
Buffer.append( "\n" );
}
void builder_print( Builder* builder, Code code )
void Builder::print( Code code )
{
StrBuilder str = code_to_strbuilder(code);
String str = code->to_string();
// const ssize len = str.length();
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
strbuilder_append_string( & builder->Buffer, str );
Buffer.append( str );
}
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va )
void Builder::print_fmt( char const* fmt, ... )
{
ssize res;
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
res = c_str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_list va;
va_start( va, fmt );
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_end( va );
strbuilder_append_c_str_len( (StrBuilder*) & (builder->Buffer), (char const*)buf, res);
// log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
Buffer.append( buf, res );
}
void builder_write(Builder* builder)
void Builder::write()
{
b32 result = file_write( & builder->File, builder->Buffer, strbuilder_length(builder->Buffer) );
b32 result = file_write( & File, Buffer, Buffer.length() );
if ( result == false )
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & builder->File ) );
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
log_fmt( "Generated: %s\n", builder->File.filename );
file_close( & builder->File );
strbuilder_free(& builder->Buffer);
log_fmt( "Generated: %s\n", File.filename );
file_close( & File );
Buffer.free();
}
#pragma endregion Builder
GEN_NS_END
#ifdef __clang__

View File

@ -9,9 +9,6 @@
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wvarargs"
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
# pragma clang diagnostic ignored "-W#pragma-messages"
# pragma clang diagnostic ignored "-Wstatic-in-inline"
#endif
#ifdef __GNUC__
@ -28,59 +25,21 @@
GEN_NS_BEGIN
#pragma region Builder
struct Builder;
typedef struct Builder Builder;
Builder builder_open ( char const* path );
void builder_pad_lines ( Builder* builder, s32 num );
void builder_print ( Builder* builder, Code code );
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va );
void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
va_list va;
va_start( va, fmt );
builder_print_fmt_va( builder, fmt, va );
va_end( va );
}
void builder_write( Builder* builder );
struct Builder
{
FileInfo File;
StrBuilder Buffer;
String Buffer;
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
FORCEINLINE static Builder open( char const* path ) { return builder_open(path); }
static Builder open( char const* path );
FORCEINLINE void pad_lines( s32 num ) { return builder_pad_lines(this, num); }
void pad_lines( s32 num );
FORCEINLINE void print( Code code ) { return builder_print(this, code); }
FORCEINLINE void print_fmt( char const* fmt, ... ) {
va_list va;
va_start( va, fmt );
builder_print_fmt_va( this, fmt, va );
va_end( va );
}
void print( Code );
void print_fmt( char const* fmt, ... );
FORCEINLINE void write() { return builder_write(this); }
#endif
void write();
};
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
void builder_write ( Builder& builder ) { return builder_write(& builder ); }
void builder_print_fmt( Builder& builder, char const* fmt, ...) {
va_list va;
va_start( va, fmt );
builder_print_fmt_va( & builder, fmt, va );
va_end( va );
}
#endif
#pragma endregion Builder
GEN_NS_END
#ifdef __clang__

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,6 @@
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wvarargs"
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
# pragma clang diagnostic ignored "-W#pragma-messages"
# pragma clang diagnostic ignored "-Wstatic-in-inline"
#endif
#ifdef __GNUC__
@ -34,9 +31,9 @@
# define _printf_err( fmt, ... ) fprintf( stderr, fmt, __VA_ARGS__ )
# define _printf_err_va( fmt, va ) vfprintf( stderr, fmt, va )
# else
# define _strlen c_str_len
# define _printf_err( fmt, ... ) c_str_fmt_out_err( fmt, __VA_ARGS__ )
# define _printf_err_va( fmt, va ) c_str_fmt_out_err_va( fmt, va )
# define _strlen str_len
# define _printf_err( fmt, ... ) str_fmt_out_err( fmt, __VA_ARGS__ )
# define _printf_err_va( fmt, va ) str_fmt_out_err_va( fmt, va )
# endif
# endif
#
@ -109,9 +106,9 @@ GEN_NS_BEGIN
#pragma region Debug
void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... )
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
{
_printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line );
_printf_err( "%s:(%d): Assert Failure: ", file, line );
if ( condition )
_printf_err( "`%s` \n", condition );
@ -164,7 +161,7 @@ ssize _scan_zpl_i64( const char* text, s32 base, s64* value )
text++;
}
if ( base == 16 && c_str_compare_len( text, "0x", 2 ) == 0 )
if ( base == 16 && str_compare( text, "0x", 2 ) == 0 )
text += 2;
for ( ;; )
@ -199,14 +196,14 @@ global const char _num_to_char_table[] =
"abcdefghijklmnopqrstuvwxyz"
"@$";
s64 c_str_to_i64( const char* str, char** end_ptr, s32 base )
s64 str_to_i64( const char* str, char** end_ptr, s32 base )
{
ssize len;
s64 value;
if ( ! base )
{
if ( ( c_str_len( str ) > 2 ) && ( c_str_compare_len( str, "0x", 2 ) == 0 ) )
if ( ( str_len( str ) > 2 ) && ( str_compare( str, "0x", 2 ) == 0 ) )
base = 16;
else
base = 10;
@ -246,7 +243,7 @@ void i64_to_str( s64 value, char* string, s32 base )
if ( negative )
*buf++ = '-';
*buf = '\0';
c_str_reverse( string );
str_reverse( string );
}
void u64_to_str( u64 value, char* string, s32 base )
@ -267,10 +264,10 @@ void u64_to_str( u64 value, char* string, s32 base )
}
*buf = '\0';
c_str_reverse( string );
str_reverse( string );
}
f64 c_str_to_f64( const char* str, char** end_ptr )
f64 str_to_f64( const char* str, char** end_ptr )
{
f64 result, value, sign, scale;
s32 frac;
@ -387,7 +384,6 @@ enum
GEN_FMT_INTS = GEN_FMT_CHAR | GEN_FMT_SHORT | GEN_FMT_INT | GEN_FMT_LONG | GEN_FMT_LLONG | GEN_FMT_SIZE | GEN_FMT_INTPTR
};
typedef struct _format_info _format_info;
struct _format_info
{
s32 base;
@ -398,13 +394,13 @@ struct _format_info
internal ssize _print_string( char* text, ssize max_len, _format_info* info, char const* str )
{
ssize res = 0, len = 0;
ssize remaining = max_len;
ssize res = 0, len = 0;
ssize remaining = max_len;
char* begin = text;
if ( str == NULL && max_len >= 6 )
{
res += c_str_copy_nulpad( text, "(null)", 6 );
res += str_copy_nulpad( text, "(null)", 6 );
return res;
}
@ -412,7 +408,7 @@ internal ssize _print_string( char* text, ssize max_len, _format_info* info, cha
// Made the design decision for this library that precision is the length of the string.
len = info->precision;
else
len = c_str_len( str );
len = str_len( str );
if ( info && ( info->width == 0 && info->flags & GEN_FMT_WIDTH ) )
{
@ -425,7 +421,7 @@ internal ssize _print_string( char* text, ssize max_len, _format_info* info, cha
len = info->precision < len ? info->precision : len;
if ( res + len > max_len )
return res;
res += c_str_copy_nulpad( text, str, len );
res += str_copy_nulpad( text, str, len );
text += res;
if ( info->width > res )
@ -449,15 +445,15 @@ internal ssize _print_string( char* text, ssize max_len, _format_info* info, cha
if ( res + len > max_len )
return res;
res += c_str_copy_nulpad( text, str, len );
res += str_copy_nulpad( text, str, len );
}
if ( info )
{
if ( info->flags & GEN_FMT_UPPER )
c_str_to_upper( begin );
str_to_upper( begin );
else if ( info->flags & GEN_FMT_LOWER )
c_str_to_lower( begin );
str_to_lower( begin );
}
return res;
@ -594,7 +590,7 @@ internal ssize _print_f64( char* text, ssize max_len, _format_info* info, b32 is
return ( text - text_begin );
}
neverinline ssize c_str_fmt_va( char* text, ssize max_len, char const* fmt, va_list va )
neverinline ssize str_fmt_va( char* text, ssize max_len, char const* fmt, va_list va )
{
char const* text_begin = text;
ssize remaining = max_len, res;
@ -602,7 +598,7 @@ neverinline ssize c_str_fmt_va( char* text, ssize max_len, char const* fmt, va_l
while ( *fmt )
{
_format_info info = { 0 };
ssize len = 0;
ssize len = 0;
info.precision = -1;
while ( *fmt && *fmt != '%' && remaining )
@ -666,7 +662,7 @@ neverinline ssize c_str_fmt_va( char* text, ssize max_len, char const* fmt, va_l
}
else
{
info.width = scast( s32, c_str_to_i64( fmt, ccast( char**, & fmt), 10 ));
info.width = scast( s32, str_to_i64( fmt, ccast( char**, & fmt), 10 ));
if ( info.width != 0 )
{
info.flags |= GEN_FMT_WIDTH;
@ -684,7 +680,7 @@ neverinline ssize c_str_fmt_va( char* text, ssize max_len, char const* fmt, va_l
}
else
{
info.precision = scast( s32, c_str_to_i64( fmt, ccast( char**, & fmt), 10 ));
info.precision = scast( s32, str_to_i64( fmt, ccast( char**, & fmt), 10 ));
}
info.flags &= ~GEN_FMT_ZERO;
}
@ -775,20 +771,10 @@ neverinline ssize c_str_fmt_va( char* text, ssize max_len, char const* fmt, va_l
case 'S':
{
if ( *(fmt + 1) == 'B' )
{
String gen_str = String { va_arg( va, char*) };
++ fmt;
StrBuilder gen_str = { va_arg( va, char*) };
info.precision = strbuilder_length(gen_str);
len = _print_string( text, remaining, &info, gen_str );
break;
}
Str gen_str = va_arg( va, Str);
info.precision = gen_str.Len;
len = _print_string( text, remaining, &info, gen_str.Ptr );
info.precision = gen_str.length();
len = _print_string( text, remaining, &info, gen_str );
}
break;
@ -888,67 +874,67 @@ neverinline ssize c_str_fmt_va( char* text, ssize max_len, char const* fmt, va_l
return ( res >= max_len || res < 0 ) ? -1 : res;
}
char* c_str_fmt_buf_va( char const* fmt, va_list va )
char* str_fmt_buf_va( char const* fmt, va_list va )
{
local_persist thread_local char buffer[ GEN_PRINTF_MAXLEN ];
c_str_fmt_va( buffer, size_of( buffer ), fmt, va );
str_fmt_va( buffer, size_of( buffer ), fmt, va );
return buffer;
}
char* c_str_fmt_buf( char const* fmt, ... )
char* str_fmt_buf( char const* fmt, ... )
{
va_list va;
char* str;
va_start( va, fmt );
str = c_str_fmt_buf_va( fmt, va );
str = str_fmt_buf_va( fmt, va );
va_end( va );
return str;
}
ssize c_str_fmt_file_va( FileInfo* f, char const* fmt, va_list va )
ssize str_fmt_file_va( struct FileInfo* f, char const* fmt, va_list va )
{
local_persist thread_local char buf[ GEN_PRINTF_MAXLEN ];
ssize len = c_str_fmt_va( buf, size_of( buf ), fmt, va );
ssize len = str_fmt_va( buf, size_of( buf ), fmt, va );
b32 res = file_write( f, buf, len - 1 ); // NOTE: prevent extra whitespace
return res ? len : -1;
}
ssize c_str_fmt_file( FileInfo* f, char const* fmt, ... )
ssize str_fmt_file( struct FileInfo* f, char const* fmt, ... )
{
ssize res;
va_list va;
va_start( va, fmt );
res = c_str_fmt_file_va( f, fmt, va );
res = str_fmt_file_va( f, fmt, va );
va_end( va );
return res;
}
ssize c_str_fmt( char* str, ssize n, char const* fmt, ... )
ssize str_fmt( char* str, ssize n, char const* fmt, ... )
{
ssize res;
va_list va;
va_start( va, fmt );
res = c_str_fmt_va( str, n, fmt, va );
res = str_fmt_va( str, n, fmt, va );
va_end( va );
return res;
}
ssize c_str_fmt_out_va( char const* fmt, va_list va )
ssize str_fmt_out_va( char const* fmt, va_list va )
{
return c_str_fmt_file_va( file_get_standard( EFileStandard_OUTPUT ), fmt, va );
return str_fmt_file_va( file_get_standard( EFileStandard_OUTPUT ), fmt, va );
}
ssize c_str_fmt_out_err_va( char const* fmt, va_list va )
ssize str_fmt_out_err_va( char const* fmt, va_list va )
{
return c_str_fmt_file_va( file_get_standard( EFileStandard_ERROR ), fmt, va );
return str_fmt_file_va( file_get_standard( EFileStandard_ERROR ), fmt, va );
}
ssize c_str_fmt_out_err( char const* fmt, ... )
ssize str_fmt_out_err( char const* fmt, ... )
{
ssize res;
va_list va;
va_start( va, fmt );
res = c_str_fmt_out_err_va( fmt, va );
res = str_fmt_out_err_va( fmt, va );
va_end( va );
return res;
}
@ -1045,9 +1031,9 @@ u64 crc64( void const* data, ssize len )
void* mem_copy( void* dest, void const* source, ssize n )
{
if ( dest == nullptr )
if ( dest == NULL )
{
return nullptr;
return NULL;
}
return memcpy( dest, source, n );
@ -1084,7 +1070,6 @@ void const* mem_find( void const* data, u8 c, ssize n )
#define GEN_HEAP_STATS_MAGIC 0xDEADC0DE
typedef struct _heap_stats _heap_stats;
struct _heap_stats
{
u32 magic;
@ -1119,7 +1104,6 @@ void heap_stats_check( void )
GEN_ASSERT( _heap_stats_info.alloc_count == 0 );
}
typedef struct _heap_alloc_info _heap_alloc_info;
struct _heap_alloc_info
{
ssize size;
@ -1374,7 +1358,7 @@ ssize virtual_memory_page_size( ssize* alignment_out )
#pragma endregion VirtualMemory
void* arena_allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
void* Arena::allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
{
Arena* arena = rcast(Arena*, allocator_data);
void* ptr = NULL;
@ -1386,7 +1370,7 @@ void* arena_allocator_proc( void* allocator_data, AllocType type, ssize size, ss
case EAllocation_ALLOC :
{
void* end = pointer_add( arena->PhysicalStart, arena->TotalUsed );
ssize total_size = align_forward_s64( size, alignment );
ssize total_size = align_forward_i64( size, alignment );
// NOTE: Out of memory
if ( arena->TotalUsed + total_size > (ssize) arena->TotalSize )
@ -1424,7 +1408,7 @@ void* arena_allocator_proc( void* allocator_data, AllocType type, ssize size, ss
return ptr;
}
void* pool_allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
void* Pool::allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
{
Pool* pool = rcast( Pool*, allocator_data);
void* ptr = NULL;
@ -1497,7 +1481,7 @@ void* pool_allocator_proc( void* allocator_data, AllocType type, ssize size, ssi
return ptr;
}
Pool pool_init_align( AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align )
Pool Pool::init_align( AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align )
{
Pool pool = {};
@ -1535,16 +1519,16 @@ Pool pool_init_align( AllocatorInfo backing, ssize num_blocks, ssize block_size,
return pool;
}
void pool_clear(Pool* pool)
void Pool::clear()
{
ssize actual_block_size, block_index;
ssize actual_block_size, block_index;
void* curr;
uptr* end;
actual_block_size = pool->BlockSize + pool->BlockAlign;
actual_block_size = BlockSize + BlockAlign;
curr = pool->PhysicalStart;
for ( block_index = 0; block_index < pool->NumBlocks - 1; block_index++ )
curr = PhysicalStart;
for ( block_index = 0; block_index < NumBlocks - 1; block_index++ )
{
uptr* next = ( uptr* ) curr;
*next = ( uptr ) curr + actual_block_size;
@ -1554,32 +1538,38 @@ void pool_clear(Pool* pool)
end = ( uptr* ) curr;
*end = ( uptr ) NULL;
pool->FreeList = pool->PhysicalStart;
FreeList = PhysicalStart;
}
#pragma endregion Memory
#pragma region StrBuilder
#pragma region String
StrBuilder strbuilder_make_length( AllocatorInfo allocator, char const* str, ssize length )
String String::fmt( AllocatorInfo allocator, char* buf, ssize buf_size, char const* fmt, ... )
{
ssize const header_size = sizeof( StrBuilderHeader );
va_list va;
va_start( va, fmt );
str_fmt_va( buf, buf_size, fmt, va );
va_end( va );
return make( allocator, buf );
}
String String::make_length( AllocatorInfo allocator, char const* str, ssize length )
{
constexpr ssize header_size = sizeof( Header );
s32 alloc_size = header_size + length + 1;
void* allocation = alloc( allocator, alloc_size );
if ( allocation == nullptr ) {
StrBuilder null_string = {nullptr};
return null_string;
}
if ( allocation == nullptr )
return { nullptr };
StrBuilderHeader*
header = rcast(StrBuilderHeader*, allocation);
header->Allocator = allocator;
header->Capacity = length;
header->Length = length;
Header&
header = * rcast(Header*, allocation);
header = { allocator, length, length };
StrBuilder result = { rcast( char*, allocation) + header_size };
String result = { rcast( char*, allocation) + header_size };
if ( length && str )
mem_copy( result, str, length );
@ -1591,30 +1581,93 @@ StrBuilder strbuilder_make_length( AllocatorInfo allocator, char const* str, ssi
return result;
}
StrBuilder strbuilder_make_reserve( AllocatorInfo allocator, ssize capacity )
String String::make_reserve( AllocatorInfo allocator, ssize capacity )
{
ssize const header_size = sizeof( StrBuilderHeader );
constexpr ssize header_size = sizeof( Header );
s32 alloc_size = header_size + capacity + 1;
void* allocation = alloc( allocator, alloc_size );
if ( allocation == nullptr ) {
StrBuilder null_string = {nullptr};
return null_string;
}
if ( allocation == nullptr )
return { nullptr };
mem_set( allocation, 0, alloc_size );
StrBuilderHeader*
header = rcast(StrBuilderHeader*, allocation);
Header*
header = rcast(Header*, allocation);
header->Allocator = allocator;
header->Capacity = capacity;
header->Length = 0;
StrBuilder result = { rcast(char*, allocation) + header_size };
String result = { rcast(char*, allocation) + header_size };
return result;
}
#pragma endregion StrBuilder
String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... )
{
local_persist thread_local
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
str_fmt_va( buf, GEN_PRINTF_MAXLEN, fmt, va );
va_end( va );
return make( allocator, buf );
}
bool String::append_fmt( char const* fmt, ... )
{
ssize res;
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_end( va );
return append( buf, res );
}
bool String::make_space_for( char const* str, ssize add_len )
{
ssize available = avail_space();
// NOTE: Return if there is enough space left
if ( available >= add_len )
{
return true;
}
else
{
ssize new_len, old_size, new_size;
void* ptr;
void* new_ptr;
AllocatorInfo allocator = get_header().Allocator;
Header* header = nullptr;
new_len = grow_formula( length() + add_len );
ptr = & get_header();
old_size = size_of( Header ) + length() + 1;
new_size = size_of( Header ) + new_len + 1;
new_ptr = resize( allocator, ptr, old_size, new_size );
if ( new_ptr == nullptr )
return false;
header = rcast( Header*, new_ptr);
header->Allocator = allocator;
header->Capacity = new_len;
Data = rcast( char*, header + 1 );
return true;
}
}
#pragma endregion String
#pragma region File Handling
@ -1631,7 +1684,7 @@ wchar_t* _alloc_utf8_to_ucs2( AllocatorInfo a, char const* text, ssize* w_len_ )
*w_len_ = w_len;
return NULL;
}
len = c_str_len( text );
len = str_len( text );
if ( len == 0 )
{
if ( w_len_ )
@ -1649,7 +1702,7 @@ wchar_t* _alloc_utf8_to_ucs2( AllocatorInfo a, char const* text, ssize* w_len_ )
w_len1 = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, text, scast( int, len), w_text, scast( int, w_len) );
if ( w_len1 == 0 )
{
allocator_free( a, w_text );
free( a, w_text );
if ( w_len_ )
*w_len_ = 0;
return NULL;
@ -1758,7 +1811,7 @@ GEN_FILE_OPEN_PROC( _win32_file_open )
w_text = _alloc_utf8_to_ucs2( heap(), filename, NULL );
handle = CreateFileW( w_text, desired_access, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL );
allocator_free( heap(), w_text );
free( heap(), w_text );
if ( handle == INVALID_HANDLE_VALUE )
{
@ -1897,7 +1950,7 @@ GEN_FILE_OPEN_PROC( _posix_file_open )
internal void _dirinfo_free_entry( DirEntry* entry );
// TODO(zpl) : Is this a bad idea?
// TODO : Is this a bad idea?
global b32 _std_file_set = false;
global FileInfo _std_files[ EFileStandard_COUNT ] = {
{
@ -1953,7 +2006,7 @@ FileError file_close( FileInfo* f )
return EFileError_INVALID;
if ( f->filename )
allocator_free( heap(), ccast( char*, f->filename ));
free( heap(), ccast( char*, f->filename ));
#if defined( GEN_SYSTEM_WINDOWS )
if ( f->fd.p == INVALID_HANDLE_VALUE )
@ -1988,7 +2041,7 @@ FileError file_close( FileInfo* f )
FileError file_new( FileInfo* f, FileDescriptor fd, FileOperations ops, char const* filename )
{
FileError err = EFileError_NONE;
ssize len = c_str_len( filename );
ssize len = str_len( filename );
f->ops = ops;
f->fd = fd;
@ -2072,7 +2125,6 @@ FileContents file_read_contents( AllocatorInfo a, b32 zero_terminate, char const
return result;
}
typedef struct _memory_fd _memory_fd;
struct _memory_fd
{
u8 magic;
@ -2119,7 +2171,7 @@ b8 file_stream_new( FileInfo* file, AllocatorInfo allocator )
d->allocator = allocator;
d->flags = EFileStream_CLONE_WRITABLE;
d->cap = 0;
d->buf = array_init( u8, allocator );
d->buf = Array<u8>::init( allocator );
if ( ! d->buf )
return false;
@ -2145,7 +2197,7 @@ b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize
d->flags = flags;
if ( d->flags & EFileStream_CLONE_WRITABLE )
{
Array(u8) arr = array_init_reserve(u8, allocator, size );
Array<u8> arr = Array<u8>::init_reserve( allocator, size );
d->buf = arr;
if ( ! d->buf )
@ -2154,7 +2206,7 @@ b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize
mem_copy( d->buf, buffer, size );
d->cap = size;
array_get_header(arr)->Num = size;
arr.get_header()->Num = size;
}
else
{
@ -2222,11 +2274,11 @@ GEN_FILE_WRITE_AT_PROC( _memory_file_write )
if ( d->flags & EFileStream_CLONE_WRITABLE )
{
Array(u8) arr = { d->buf };
Array<u8> arr = { d->buf };
if ( array_get_header(arr)->Capacity < scast(usize, new_cap) )
if ( arr.get_header()->Capacity < usize(new_cap) )
{
if ( ! array_grow( & arr, ( s64 )( new_cap ) ) )
if ( ! arr.grow( ( s64 )( new_cap ) ) )
return false;
d->buf = arr;
}
@ -2236,11 +2288,11 @@ GEN_FILE_WRITE_AT_PROC( _memory_file_write )
if ( ( d->flags & EFileStream_CLONE_WRITABLE ) && extralen > 0 )
{
Array(u8) arr = { d->buf };
Array<u8> arr = { d->buf };
mem_copy( d->buf + offset + rwlen, pointer_add_const( buffer, rwlen ), extralen );
d->cap = new_cap;
array_get_header(arr)->Capacity = new_cap;
arr.get_header()->Capacity = new_cap;
}
else
{
@ -2260,11 +2312,11 @@ GEN_FILE_CLOSE_PROC( _memory_file_close )
if ( d->flags & EFileStream_CLONE_WRITABLE )
{
Array(u8) arr = { d->buf };
array_free(arr);
Array<u8> arr = { d->buf };
arr.free();
}
allocator_free( allocator, d );
free( allocator, d );
}
FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -9,9 +9,6 @@
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wvarargs"
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
# pragma clang diagnostic ignored "-W#pragma-messages"
# pragma clang diagnostic ignored "-Wstatic-in-inline"
#endif
#ifdef __GNUC__
@ -31,7 +28,7 @@ GEN_NS_BEGIN
#define _adt_fprintf( s_, fmt_, ... ) \
do \
{ \
if ( c_str_fmt_file( s_, fmt_, ##__VA_ARGS__ ) < 0 ) \
if ( str_fmt_file( s_, fmt_, ##__VA_ARGS__ ) < 0 ) \
return EADT_ERROR_OUT_OF_MEMORY; \
} while ( 0 )
@ -47,7 +44,7 @@ u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32
node->type = type;
node->name = name;
node->parent = parent;
node->nodes = array_init(ADT_Node, backing );
node->nodes = Array<ADT_Node>::init( backing );
if ( ! node->nodes )
return EADT_ERROR_OUT_OF_MEMORY;
@ -60,12 +57,12 @@ u8 adt_destroy_branch( ADT_Node* node )
GEN_ASSERT_NOT_NULL( node );
if ( ( node->type == EADT_TYPE_OBJECT || node->type == EADT_TYPE_ARRAY ) && node->nodes )
{
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); ++i )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); ++i )
{
adt_destroy_branch( node->nodes + i );
}
array_free(node->nodes);
node->nodes.free();
}
return 0;
}
@ -90,9 +87,9 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search )
return NULL;
}
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
if ( ! c_str_compare( node->nodes[ i ].name, name ) )
if ( ! str_compare( node->nodes[ i ].name, name ) )
{
return ( node->nodes + i );
}
@ -100,7 +97,7 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search )
if ( deep_search )
{
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
ADT_Node* res = adt_find( node->nodes + i, name, deep_search );
@ -119,7 +116,7 @@ internal ADT_Node* _adt_get_value( ADT_Node* node, char const* value )
case EADT_TYPE_MULTISTRING :
case EADT_TYPE_STRING :
{
if ( node->string && ! c_str_compare( node->string, value ) )
if ( node->string && ! str_compare( node->string, value ) )
{
return node;
}
@ -138,7 +135,7 @@ internal ADT_Node* _adt_get_value( ADT_Node* node, char const* value )
ssize fsize = 0;
u8* buf = file_stream_buf( &tmp, &fsize );
if ( ! c_str_compare( ( char const* )buf, value ) )
if ( ! str_compare( ( char const* )buf, value ) )
{
file_close( &tmp );
return node;
@ -156,9 +153,9 @@ internal ADT_Node* _adt_get_value( ADT_Node* node, char const* value )
internal ADT_Node* _adt_get_field( ADT_Node* node, char* name, char* value )
{
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
if ( ! c_str_compare( node->nodes[ i ].name, name ) )
if ( ! str_compare( node->nodes[ i ].name, name ) )
{
ADT_Node* child = &node->nodes[ i ];
if ( _adt_get_value( child, value ) )
@ -191,22 +188,22 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
}
#if defined EADT_URI_DEBUG || 0
c_str_fmt_out( "uri: %s\n", uri );
str_fmt_out( "uri: %s\n", uri );
#endif
char * p = ( char* )uri, *b = p, *e = p;
ADT_Node* found_node = NULL;
b = p;
p = e = ( char* )c_str_skip( p, '/' );
char* buf = c_str_fmt_buf( "%.*s", ( int )( e - b ), b );
p = e = ( char* )str_skip( p, '/' );
char* buf = str_fmt_buf( "%.*s", ( int )( e - b ), b );
/* handle field value lookup */
if ( *b == '[' )
{
char *l_p = buf + 1, *l_b = l_p, *l_e = l_p, *l_b2 = l_p, *l_e2 = l_p;
l_e = ( char* )c_str_skip( l_p, '=' );
l_e2 = ( char* )c_str_skip( l_p, ']' );
l_e = ( char* )str_skip( l_p, '=' );
l_e2 = ( char* )str_skip( l_p, ']' );
if ( ( ! *l_e && node->type != EADT_TYPE_ARRAY ) || ! *l_e2 )
{
@ -231,7 +228,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
/* run a value comparison against any child that is an object node */
else if ( node->type == EADT_TYPE_ARRAY )
{
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
ADT_Node* child = &node->nodes[ i ];
if ( child->type != EADT_TYPE_OBJECT )
@ -249,7 +246,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
/* [value] */
else
{
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
{
ADT_Node* child = &node->nodes[ i ];
if ( _adt_get_value( child, l_b2 ) )
@ -280,8 +277,8 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
/* handle array index lookup */
else
{
ssize idx = ( ssize )c_str_to_i64( buf, NULL, 10 );
if ( idx >= 0 && idx < scast(ssize, array_num(node->nodes)) )
ssize idx = ( ssize )str_to_i64( buf, NULL, 10 );
if ( idx >= 0 && idx < scast(ssize, node->nodes.num()) )
{
found_node = &node->nodes[ idx ];
@ -306,16 +303,15 @@ ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index )
if ( ! parent->nodes )
return NULL;
if ( index < 0 || index > scast(ssize, array_num(parent->nodes)) )
if ( index < 0 || index > scast(ssize, parent->nodes.num()) )
return NULL;
ADT_Node o = { 0 };
o.parent = parent;
if ( ! array_append_at( parent->nodes, o, index ) )
if ( ! parent->nodes.append_at( o, index ) )
return NULL;
ADT_Node* node = & parent->nodes[index];
return node;
return parent->nodes + index;
}
ADT_Node* adt_alloc( ADT_Node* parent )
@ -328,7 +324,7 @@ ADT_Node* adt_alloc( ADT_Node* parent )
if ( ! parent->nodes )
return NULL;
return adt_alloc_at( parent, array_num(parent->nodes) );
return adt_alloc_at( parent, parent->nodes.num() );
}
b8 adt_set_obj( ADT_Node* obj, char const* name, AllocatorInfo backing )
@ -382,7 +378,7 @@ ADT_Node* adt_move_node( ADT_Node* node, ADT_Node* new_parent )
GEN_ASSERT_NOT_NULL( node );
GEN_ASSERT_NOT_NULL( new_parent );
GEN_ASSERT( new_parent->type == EADT_TYPE_ARRAY || new_parent->type == EADT_TYPE_OBJECT );
return adt_move_node_at( node, new_parent, array_num(new_parent->nodes) );
return adt_move_node_at( node, new_parent, new_parent->nodes.num() );
}
void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node )
@ -406,7 +402,7 @@ void adt_remove_node( ADT_Node* node )
GEN_ASSERT_NOT_NULL( node->parent );
ADT_Node* parent = node->parent;
ssize index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
array_remove_at( parent->nodes, index );
parent->nodes.remove_at( index );
}
ADT_Node* adt_append_obj( ADT_Node* parent, char const* name )
@ -414,7 +410,7 @@ ADT_Node* adt_append_obj( ADT_Node* parent, char const* name )
ADT_Node* o = adt_alloc( parent );
if ( ! o )
return NULL;
if ( adt_set_obj( o, name, array_get_header(parent->nodes)->Allocator ) )
if ( adt_set_obj( o, name, parent->nodes.get_header()->Allocator ) )
{
adt_remove_node( o );
return NULL;
@ -427,9 +423,7 @@ ADT_Node* adt_append_arr( ADT_Node* parent, char const* name )
ADT_Node* o = adt_alloc( parent );
if ( ! o )
return NULL;
ArrayHeader* node_header = array_get_header(parent->nodes);
if ( adt_set_arr( o, name, node_header->Allocator ) )
if ( adt_set_arr( o, name, parent->nodes.get_header()->Allocator ) )
{
adt_remove_node( o );
return NULL;
@ -474,7 +468,7 @@ char* adt_parse_number_strict( ADT_Node* node, char* base_str )
while ( *e )
++e;
while ( *p && ( char_first_occurence( "eE.+-", *p ) || char_is_hex_digit( *p ) ) )
while ( *p && ( str_find( "eE.+-", *p ) || char_is_hex_digit( *p ) ) )
{
++p;
}
@ -503,7 +497,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
u8 node_props = 0;
/* skip false positives and special cases */
if ( ! ! char_first_occurence( "eE", *p ) || ( ! ! char_first_occurence( ".+-", *p ) && ! char_is_hex_digit( *( p + 1 ) ) && *( p + 1 ) != '.' ) )
if ( ! ! str_find( "eE", *p ) || ( ! ! str_find( ".+-", *p ) && ! char_is_hex_digit( *( p + 1 ) ) && *( p + 1 ) != '.' ) )
{
return ++base_str;
}
@ -534,7 +528,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
}
else
{
if ( ! c_str_compare_len( e, "0x", 2 ) || ! c_str_compare_len( e, "0X", 2 ) )
if ( ! str_compare( e, "0x", 2 ) || ! str_compare( e, "0X", 2 ) )
{
node_props = EADT_PROPS_IS_HEX;
}
@ -579,7 +573,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
char expbuf[ 6 ] = { 0 };
ssize expi = 0;
if ( *e && ! ! char_first_occurence( "eE", *e ) )
if ( *e && ! ! str_find( "eE", *e ) )
{
++e;
if ( *e == '+' || *e == '-' || char_is_digit( *e ) )
@ -598,12 +592,12 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
}
}
orig_exp = exp = ( u8 )c_str_to_i64( expbuf, NULL, 10 );
orig_exp = exp = ( u8 )str_to_i64( expbuf, NULL, 10 );
}
if ( node_type == EADT_TYPE_INTEGER )
{
node->integer = c_str_to_i64( buf, 0, 0 );
node->integer = str_to_i64( buf, 0, 0 );
#ifndef GEN_PARSER_DISABLE_ANALYSIS
/* special case: negative zero */
if ( node->integer == 0 && buf[ 0 ] == '-' )
@ -618,19 +612,19 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
}
else
{
node->real = c_str_to_f64( buf, 0 );
node->real = str_to_f64( buf, 0 );
#ifndef GEN_PARSER_DISABLE_ANALYSIS
char *q = buf, *base_string = q, *base_string2 = q;
base_string = ccast( char*, c_str_skip( base_string, '.' ));
base_string = ccast( char*, str_skip( base_string, '.' ));
*base_string = '\0';
base_string2 = base_string + 1;
char* base_strbuilder_off = base_string2;
while ( *base_strbuilder_off++ == '0' )
char* base_string_off = base_string2;
while ( *base_string_off++ == '0' )
base2_offset++;
base = ( s32 )c_str_to_i64( q, 0, 0 );
base2 = ( s32 )c_str_to_i64( base_string2, 0, 0 );
base = ( s32 )str_to_i64( q, 0, 0 );
base2 = ( s32 )str_to_i64( base_string2, 0, 0 );
if ( exp )
{
exp = exp * ( ! ( eb == 10.0f ) ? -1 : 1 );
@ -773,9 +767,9 @@ ADT_Error adt_print_string( FileInfo* file, ADT_Node* node, char const* escaped_
do
{
p = c_str_skip_any( p, escaped_chars );
p = str_skip_any( p, escaped_chars );
_adt_fprintf( file, "%.*s", pointer_diff( b, p ), b );
if ( *p && ! ! char_first_occurence( escaped_chars, *p ) )
if ( *p && ! ! str_find( escaped_chars, *p ) )
{
_adt_fprintf( file, "%s%c", escape_symbol, *p );
p++;
@ -786,7 +780,7 @@ ADT_Error adt_print_string( FileInfo* file, ADT_Node* node, char const* escaped_
return EADT_ERROR_NONE;
}
ADT_Error adt_c_str_to_number( ADT_Node* node )
ADT_Error adt_str_to_number( ADT_Node* node )
{
GEN_ASSERT( node );
@ -802,7 +796,7 @@ ADT_Error adt_c_str_to_number( ADT_Node* node )
return EADT_ERROR_NONE;
}
ADT_Error adt_c_str_to_number_strict( ADT_Node* node )
ADT_Error adt_str_to_number_strict( ADT_Node* node )
{
GEN_ASSERT( node );
@ -849,7 +843,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
do
{
char delimiter = 0;
currentChar = ccast( char*, c_str_trim( currentChar, false ));
currentChar = ccast( char*, str_trim( currentChar, false ));
if ( *currentChar == 0 )
break;
@ -873,7 +867,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
#endif
do
{
endChar = ccast( char*, c_str_skip( endChar, '"' ));
endChar = ccast( char*, str_skip( endChar, '"' ));
if ( *endChar && *( endChar + 1 ) == '"' )
{
@ -892,7 +886,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
}
*endChar = 0;
currentChar = ccast( char*, c_str_trim( endChar + 1, true ));
currentChar = ccast( char*, str_trim( endChar + 1, true ));
delimiter = * currentChar;
/* unescape escaped quotes (so that unescaped text escapes :) */
@ -902,7 +896,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
{
if ( *escapedChar == '"' && *( escapedChar + 1 ) == '"' )
{
mem_move( escapedChar, escapedChar + 1, c_str_len( escapedChar ) );
mem_move( escapedChar, escapedChar + 1, str_len( escapedChar ) );
}
escapedChar++;
}
@ -929,7 +923,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
if ( * endChar )
{
currentChar = ccast( char*, c_str_trim( endChar, true ));
currentChar = ccast( char*, str_trim( endChar, true ));
while ( char_is_space( *( endChar - 1 ) ) )
{
@ -950,7 +944,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
char* num_p = beginChar;
// We only consider hexadecimal values if they start with 0x
if ( c_str_len(num_p) > 2 && num_p[0] == '0' && (num_p[1] == 'x' || num_p[1] == 'X') )
if ( str_len(num_p) > 2 && num_p[0] == '0' && (num_p[1] == 'x' || num_p[1] == 'X') )
{
num_p += 2; // skip '0x' prefix
do
@ -969,16 +963,16 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
if (!skip_number)
{
adt_c_str_to_number(&rowItem);
adt_str_to_number(&rowItem);
}
}
if ( columnIndex >= scast(ssize, array_num(root->nodes)) )
if ( columnIndex >= scast(ssize, root->nodes.num()) )
{
adt_append_arr( root, NULL );
}
array_append( root->nodes[ columnIndex ].nodes, rowItem );
root->nodes[ columnIndex ].nodes.append( rowItem );
if ( delimiter == delim )
{
@ -1006,7 +1000,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
}
while ( *currentChar );
if (array_num( root->nodes) == 0 )
if ( root->nodes.num() == 0 )
{
GEN_CSV_ASSERT( "unexpected end of input. stream is empty." );
error = ECSV_Error__UNEXPECTED_END_OF_INPUT;
@ -1016,12 +1010,12 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
/* consider first row as a header. */
if ( has_header )
{
for ( ssize i = 0; i < scast(ssize, array_num(root->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, root->nodes.num()); i++ )
{
CSV_Object* col = root->nodes + i;
CSV_Object* hdr = col->nodes;
col->name = hdr->string;
array_remove_at(col->nodes, 0 );
col->nodes.remove_at( 0 );
}
}
@ -1044,16 +1038,16 @@ void _csv_write_record( FileInfo* file, CSV_Object* node )
{
case EADT_NAME_STYLE_DOUBLE_QUOTE :
{
c_str_fmt_file( file, "\"" );
str_fmt_file( file, "\"" );
adt_print_string( file, node, "\"", "\"" );
c_str_fmt_file( file, "\"" );
str_fmt_file( file, "\"" );
}
break;
case EADT_NAME_STYLE_NO_QUOTES :
{
#endif
c_str_fmt_file( file, "%s", node->string );
str_fmt_file( file, "%s", node->string );
#ifndef GEN_PARSER_DISABLE_ANALYSIS
}
break;
@ -1084,11 +1078,11 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
GEN_ASSERT_NOT_NULL( file );
GEN_ASSERT_NOT_NULL( obj );
GEN_ASSERT( obj->nodes );
ssize cols = array_num(obj->nodes);
ssize cols = obj->nodes.num();
if ( cols == 0 )
return;
ssize rows = array_num(obj->nodes[ 0 ].nodes);
ssize rows = obj->nodes[ 0 ].nodes.num();
if ( rows == 0 )
return;
@ -1101,10 +1095,10 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
_csv_write_header( file, &obj->nodes[ i ] );
if ( i + 1 != cols )
{
c_str_fmt_file( file, "%c", delimiter );
str_fmt_file( file, "%c", delimiter );
}
}
c_str_fmt_file( file, "\n" );
str_fmt_file( file, "\n" );
}
for ( ssize r = 0; r < rows; r++ )
@ -1114,14 +1108,14 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
_csv_write_record( file, &obj->nodes[ i ].nodes[ r ] );
if ( i + 1 != cols )
{
c_str_fmt_file( file, "%c", delimiter );
str_fmt_file( file, "%c", delimiter );
}
}
c_str_fmt_file( file, "\n" );
str_fmt_file( file, "\n" );
}
}
StrBuilder csv_write_strbuilder_delimiter( AllocatorInfo a, CSV_Object* obj, char delimiter )
String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimiter )
{
FileInfo tmp;
file_stream_new( &tmp, a );
@ -1129,13 +1123,11 @@ StrBuilder csv_write_strbuilder_delimiter( AllocatorInfo a, CSV_Object* obj, cha
ssize fsize;
u8* buf = file_stream_buf( &tmp, &fsize );
StrBuilder output = strbuilder_make_length( a, ( char* )buf, fsize );
String output = String::make_length( a, ( char* )buf, fsize );
file_close( &tmp );
return output;
}
#undef _adt_fprintf
#pragma endregion CSV
GEN_NS_END

View File

@ -11,9 +11,6 @@
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wvarargs"
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
# pragma clang diagnostic ignored "-W#pragma-messages"
# pragma clang diagnostic ignored "-Wstatic-in-inline"
#endif
#ifdef __GNUC__
@ -109,7 +106,7 @@ struct ADT_Node
union
{
char const* string;
Array(ADT_Node) nodes; ///< zpl_array
Array<ADT_Node> nodes; ///< zpl_array
struct
{
@ -375,7 +372,7 @@ char* adt_parse_number_strict( ADT_Node* node, char* base_str );
* @param node
* @return
*/
ADT_Error adt_c_str_to_number( ADT_Node* node );
ADT_Error adt_str_to_number( ADT_Node* node );
/**
* @brief Parses and converts an existing string node into a number.
@ -384,7 +381,7 @@ ADT_Error adt_c_str_to_number( ADT_Node* node );
* @param node
* @return
*/
ADT_Error adt_c_str_to_number_strict( ADT_Node* node );
ADT_Error adt_str_to_number_strict( ADT_Node* node );
/**
* @brief Prints a number into a file stream.
@ -431,9 +428,9 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator,
void csv_free( CSV_Object* obj );
void csv_write( FileInfo* file, CSV_Object* obj );
StrBuilder csv_write_string( AllocatorInfo a, CSV_Object* obj );
String csv_write_string( AllocatorInfo a, CSV_Object* obj );
void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delim );
StrBuilder csv_write_strbuilder_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
/* inline */
@ -450,43 +447,168 @@ void csv_write( FileInfo* file, CSV_Object* obj )
}
inline
StrBuilder csv_write_string( AllocatorInfo a, CSV_Object* obj )
String csv_write_string( AllocatorInfo a, CSV_Object* obj )
{
return csv_write_strbuilder_delimiter( a, obj, ',' );
return csv_write_string_delimiter( a, obj, ',' );
}
#pragma endregion CSV
#pragma region Scanner
// This is a simple file reader that reads the entire file into memory.
// It has an extra option to skip the first few lines for undesired includes.
// This is done so that includes can be kept in dependency and component files so that intellisense works.
Code scan_file( char const* path );
inline
Code scan_file( char const* path )
{
FileInfo file;
CodeBody parse_file( const char* path );
FileError error = file_open_mode( & file, EFileMode_READ, path );
if ( error != EFileError_NONE )
{
GEN_FATAL( "scan_file: Could not open: %s", path );
}
// The follow is basic support for light csv parsing (use it as an example)
// Make something robust if its more serious.
ssize fsize = file_size( & file );
if ( fsize <= 0 )
{
GEN_FATAL("scan_file: %s is empty", path );
}
typedef struct CSV_Column CSV_Column;
struct CSV_Column {
CSV_Object ADT;
Array(ADT_Node) Content;
String str = String::make_reserve( GlobalAllocator, fsize );
file_read( & file, str, fsize );
str.get_header().Length = fsize;
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
// Its designed so that the directive should be the first thing in the file.
// Anything that comes before it will also be omitted.
{
#define current (*scanner)
#define matched 0
#define move_fwd() do { ++ scanner; -- left; } while (0)
const StrC directive_start = txt( "ifdef" );
const StrC directive_end = txt( "endif" );
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
bool found_directive = false;
char const* scanner = str.Data;
s32 left = fsize;
while ( left )
{
// Processing directive.
if ( current == '#' )
{
move_fwd();
while ( left && char_is_space( current ) )
move_fwd();
if ( ! found_directive )
{
if ( left && str_compare( scanner, directive_start.Ptr, directive_start.Len ) == matched )
{
scanner += directive_start.Len;
left -= directive_start.Len;
while ( left && char_is_space( current ) )
move_fwd();
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
{
scanner += def_intellisense.Len;
left -= def_intellisense.Len;
found_directive = true;
}
}
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
continue;
}
if ( left && str_compare( scanner, directive_end.Ptr, directive_end.Len ) == matched )
{
scanner += directive_end.Len;
left -= directive_end.Len;
// Skip to end of line
while ( left && current != '\r' && current != '\n' )
move_fwd();
move_fwd();
if ( left && current == '\n' )
move_fwd();
// sptr skip_size = fsize - left;
if ( (scanner + 2) >= ( str.Data + fsize ) )
{
mem_move( str, scanner, left );
str.get_header().Length = left;
break;
}
mem_move( str, scanner, left );
str.get_header().Length = left;
break;
}
}
move_fwd();
}
#undef move_fwd
#undef matched
#undef current
}
file_close( & file );
return untyped_str( str );
}
#if 0
struct CodeFile
{
using namespace Parser;
String FilePath;
TokArray Tokens;
Array<ParseFailure> ParseFailures;
Code CodeRoot;
};
typedef struct CSV_Columns2 CSV_Columns2;
struct CSV_Columns2 {
CSV_Object ADT;
Array(ADT_Node) Col_1;
Array(ADT_Node) Col_2;
};
namespace Parser
{
struct ParseFailure
{
String Reason;
Code Node;
};
}
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path);
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path);
CodeFile scan_file( char const* path )
{
using namespace Parser;
#pragma endregion Scanner
CodeFile
result = {};
result.FilePath = String::make( GlobalAllocator, path );
Code code = scan_file( path );
result.CodeRoot = code;
ParseContext context = parser_get_last_context();
result.Tokens = context.Tokens;
result.ParseFailures = context.Failures;
return result;
}
#endif
GEN_NS_END
#ifdef __clang__

View File

@ -27,6 +27,8 @@ int gen_main()
gen::init(& ctx);
log_fmt("Generating code for the Gasa module\n");
Array(StrCached)& PreprocessorDefines = ctx.PreprocessorDefines;
// Initialize Globals
{
UHT_UCLASS = code_str( UCLASS() );
@ -37,60 +39,52 @@ int gen_main()
}
// Populate Defines
register_macros( args(
(Macro { str_DECLARE_CLASS, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DELEGATE_RetVal_OneParam, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DELEGATE_RetVal_ThreeParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DELEGATE_SixParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FourParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_NineParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SevenParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_TwoParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_EVENT_ThreeParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_EVENT_TwoParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_FUNCTION, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_LOG_CATEGORY_EXTERN, MT_Statement, MF_Functional | MF_Allow_As_Definition }),
(Macro { str_DECLARE_MULTICAST_DELEGATE_OneParam, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_MULTICAST_DELEGATE_ThreeParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_MULTICAST_DELEGATE_TwoParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_TS_MULTICAST_DELEGATE_OneParam, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_TS_MULTICAST_DELEGATE_TwoParams, MT_Statement, MF_Functional }),
(Macro { str_DECLARE_TS_MULTICAST_DELEGATE_ThreeParams, MT_Statement, MF_Functional }),
(Macro { str_DEFINE_ACTORDESC_TYPE, MT_Statement, MF_Functional }),
(Macro { str_DEFINE_DEFAULT_OBJECT_INITIALIZER_CONSTRUCTOR_CALL, MT_Statement, MF_Functional }),
(Macro { str_ENUM_CLASS_FLAGS, MT_Statement, MF_Functional }),
(Macro { str_GENERATED_BODY, MT_Statement, MF_Functional }),
(Macro { str_GENERATED_UCLASS_BODY, MT_Statement, MF_Functional }),
(Macro { str_GENERATED_USTRUCT_BODY, MT_Statement, MF_Functional }),
(Macro { str_PRAGMA_DISABLE_DEPRECATION_WARNINGS, MT_Statement, MF_Null | MF_Allow_As_Attribute }),
(Macro { str_PRAGMA_ENABLE_DEPRECATION_WARNINGS, MT_Statement, MF_Null | MF_Allow_As_Attribute }),
(Macro { str_PROPERTY_BINDING_IMPLEMENTATION, MT_Statement, MF_Functional }),
(Macro { str_RESULT_DECL, MT_Expression, MF_Functional }),
(Macro { str_SLATE_BEGIN_ARGS, MT_Statement, MF_Functional }),
(Macro { str_SLATE_END_ARGS, MT_Statement, MF_Functional }),
(Macro { str_TEXT, MT_Expression, MF_Functional }),
(Macro { str_UCLASS, MT_Statement, MF_Functional }),
(Macro { str_UENUM, MT_Statement, MF_Functional }),
(Macro { str_UFUNCTION, MT_Statement, MF_Functional }),
(Macro { str_UMETA, MT_Expression, MF_Functional }),
(Macro { str_UPARAM, MT_Expression, MF_Functional }),
(Macro { str_UPROPERTY, MT_Statement, MF_Functional }),
(Macro { str_USTRUCT, MT_Statement, MF_Functional }),
(Macro { str_UE_REQUIRES, MT_Expression, MF_Functional }),
(Macro { str_UE_DEPRECATED, MT_Statement, MF_Functional | MF_Allow_As_Attribute }),
(Macro { str_ACTOR_HAS_LABELS, MT_Expression, MF_Null }),
(Macro { str_HIDE_ACTOR_TRANSFORM_FUNCTIONS, MT_Statement, MF_Functional }),
(Macro { str_SCENECOMPONENT_QUAT_TOLERANCE, MT_Expression, MF_Null }),
(Macro { str_SCENECOMPONENT_ROTATOR_TOLERANCE, MT_Expression, MF_Null }),
(Macro { str_GAMEPLAYATTRIBUTE_REPNOTIFY, MT_Statement, MF_Functional }),
(Macro { str_GAMEPLAYATTRIBUTE_PROPERTY_GETTER, MT_Statement, MF_Functional }),
(Macro { str_GAMEPLAYATTRIBUTE_VALUE_GETTER, MT_Statement, MF_Functional }),
(Macro { str_GAMEPLAYATTRIBUTE_VALUE_SETTER, MT_Statement, MF_Functional }),
(Macro { str_GAMEPLAYATTRIBUTE_VALUE_INITTER, MT_Statement, MF_Functional })
));
{
PreprocessorDefines.append( cache_str(str_DECLARE_CLASS));
PreprocessorDefines.append( cache_str(str_DECLARE_DELEGATE_RetVal_OneParam));
PreprocessorDefines.append( cache_str(str_DECLARE_DELEGATE_RetVal_ThreeParams));
PreprocessorDefines.append( cache_str(str_DECLARE_DELEGATE_SixParams));
PreprocessorDefines.append( cache_str(str_DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam));
PreprocessorDefines.append( cache_str(str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams));
PreprocessorDefines.append( cache_str(str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FourParams));
PreprocessorDefines.append( cache_str(str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_NineParams));
PreprocessorDefines.append( cache_str(str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam));
PreprocessorDefines.append( cache_str(str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SevenParams));
PreprocessorDefines.append( cache_str(str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_TwoParams));
PreprocessorDefines.append( cache_str(str_DECLARE_EVENT_ThreeParams));
PreprocessorDefines.append( cache_str(str_DECLARE_EVENT_TwoParams));
PreprocessorDefines.append( cache_str(str_DECLARE_FUNCTION));
PreprocessorDefines.append( cache_str(str_DECLARE_LOG_CATEGORY_EXTERN));
PreprocessorDefines.append( cache_str(str_DECLARE_MULTICAST_DELEGATE_OneParam));
PreprocessorDefines.append( cache_str(str_DECLARE_MULTICAST_DELEGATE_ThreeParams));
PreprocessorDefines.append( cache_str(str_DECLARE_MULTICAST_DELEGATE_TwoParams));
PreprocessorDefines.append( cache_str(str_DECLARE_TS_MULTICAST_DELEGATE_OneParam));
PreprocessorDefines.append( cache_str(str_DECLARE_TS_MULTICAST_DELEGATE_TwoParams));
PreprocessorDefines.append( cache_str(str_DECLARE_TS_MULTICAST_DELEGATE_ThreeParams));
PreprocessorDefines.append( cache_str(str_DEFINE_ACTORDESC_TYPE));
PreprocessorDefines.append( cache_str(str_DEFINE_DEFAULT_OBJECT_INITIALIZER_CONSTRUCTOR_CALL));
PreprocessorDefines.append( cache_str(str_ENUM_CLASS_FLAGS));
PreprocessorDefines.append( cache_str(str_FORCEINLINE_DEBUGGABLE));
// PreprocessorDefines.append( get_cached_string(str_FORCEINLINE));
PreprocessorDefines.append( cache_str(str_GENERATED_BODY));
PreprocessorDefines.append( cache_str(str_GENERATED_UCLASS_BODY));
PreprocessorDefines.append( cache_str(str_GENERATED_USTRUCT_BODY));
PreprocessorDefines.append( cache_str(str_PRAGMA_DISABLE_DEPRECATION_WARNINGS));
PreprocessorDefines.append( cache_str(str_PRAGMA_ENABLE_DEPRECATION_WARNINGS));
PreprocessorDefines.append( cache_str(str_PROPERTY_BINDING_IMPLEMENTATION));
PreprocessorDefines.append( cache_str(str_RESULT_DECL));
PreprocessorDefines.append( cache_str(str_SLATE_BEGIN_ARGS));
PreprocessorDefines.append( cache_str(str_SLATE_END_ARGS));
PreprocessorDefines.append( cache_str(str_TEXT));
PreprocessorDefines.append( cache_str(str_UCLASS));
PreprocessorDefines.append( cache_str(str_UENUM));
PreprocessorDefines.append( cache_str(str_UFUNCTION));
PreprocessorDefines.append( cache_str(str_UMETA));
PreprocessorDefines.append( cache_str(str_UPARAM));
PreprocessorDefines.append( cache_str(str_UPROPERTY));
PreprocessorDefines.append( cache_str(str_USTRUCT));
PreprocessorDefines.append( cache_str(str_UE_REQUIRES));
}
// gen_UGasaAttributeSet();
// gen_FGasaDevOptionsCache();

View File

@ -18,58 +18,50 @@ using namespace gen;
#define path_gasa_game path_module_gasa "Game/"
#define path_gasa_ui path_module_gasa "UI/"
constexpr Str str_DECLARE_CLASS = txt("DECLARE_CLASS");
constexpr Str str_DECLARE_DELEGATE_RetVal_OneParam = txt("DECLARE_DELEGATE_RetVal_OneParam");
constexpr Str str_DECLARE_DELEGATE_RetVal_ThreeParams = txt("DECLARE_DELEGATE_RetVal_ThreeParams");
constexpr Str str_DECLARE_DELEGATE_SixParams = txt("DECLARE_DELEGATE_SixParams");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam = txt("DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FourParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FourParams");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_NineParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_NineParams");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SevenParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SevenParams");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_TwoParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_TwoParams");
constexpr Str str_DECLARE_EVENT_ThreeParams = txt("DECLARE_EVENT_ThreeParams");
constexpr Str str_DECLARE_EVENT_TwoParams = txt("DECLARE_EVENT_TwoParams");
constexpr Str str_DECLARE_FUNCTION = txt("DECLARE_FUNCTION");
constexpr Str str_DECLARE_LOG_CATEGORY_EXTERN = txt("DECLARE_LOG_CATEGORY_EXTERN");
constexpr Str str_DECLARE_MULTICAST_DELEGATE_OneParam = txt("DECLARE_MULTICAST_DELEGATE_OneParam");
constexpr Str str_DECLARE_MULTICAST_DELEGATE_ThreeParams = txt("DECLARE_MULTICAST_DELEGATE_ThreeParams");
constexpr Str str_DECLARE_MULTICAST_DELEGATE_TwoParams = txt("DECLARE_MULTICAST_DELEGATE_TwoParams");
constexpr Str str_DECLARE_TS_MULTICAST_DELEGATE_OneParam = txt("DECLARE_TS_MULTICAST_DELEGATE_OneParam");
constexpr Str str_DECLARE_TS_MULTICAST_DELEGATE_TwoParams = txt("DECLARE_TS_MULTICAST_DELEGATE_TwoParams");
constexpr Str str_DECLARE_TS_MULTICAST_DELEGATE_ThreeParams = txt("DECLARE_TS_MULTICAST_DELEGATE_ThreeParams");
constexpr Str str_DEFINE_ACTORDESC_TYPE = txt("DEFINE_ACTORDESC_TYPE");
constexpr Str str_DEFINE_DEFAULT_OBJECT_INITIALIZER_CONSTRUCTOR_CALL = txt("DEFINE_DEFAULT_OBJECT_INITIALIZER_CONSTRUCTOR_CALL");
constexpr Str str_ENUM_CLASS_FLAGS = txt("ENUM_CLASS_FLAGS");
constexpr Str str_GENERATED_BODY = txt("GENERATED_BODY");
constexpr Str str_GENERATED_UCLASS_BODY = txt("GENERATED_UCLASS_BODY");
constexpr Str str_GENERATED_USTRUCT_BODY = txt("GENERATED_USTRUCT_BODY");
constexpr Str str_DECLARE_CLASS = txt("DECLARE_CLASS(");
constexpr Str str_DECLARE_DELEGATE_RetVal_OneParam = txt("DECLARE_DELEGATE_RetVal_OneParam(");
constexpr Str str_DECLARE_DELEGATE_RetVal_ThreeParams = txt("DECLARE_DELEGATE_RetVal_ThreeParams(");
constexpr Str str_DECLARE_DELEGATE_SixParams = txt("DECLARE_DELEGATE_SixParams(");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam = txt("DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams(");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FourParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FourParams(");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_NineParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_NineParams(");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam(");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SevenParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SevenParams(");
constexpr Str str_DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_TwoParams = txt("DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_TwoParams(");
constexpr Str str_DECLARE_EVENT_ThreeParams = txt("DECLARE_EVENT_ThreeParams(");
constexpr Str str_DECLARE_EVENT_TwoParams = txt("DECLARE_EVENT_TwoParams(");
constexpr Str str_DECLARE_FUNCTION = txt("DECLARE_FUNCTION(");
constexpr Str str_DECLARE_LOG_CATEGORY_EXTERN = txt("DECLARE_LOG_CATEGORY_EXTERN(");
constexpr Str str_DECLARE_MULTICAST_DELEGATE_OneParam = txt("DECLARE_MULTICAST_DELEGATE_OneParam(");
constexpr Str str_DECLARE_MULTICAST_DELEGATE_ThreeParams = txt("DECLARE_MULTICAST_DELEGATE_ThreeParams(");
constexpr Str str_DECLARE_MULTICAST_DELEGATE_TwoParams = txt("DECLARE_MULTICAST_DELEGATE_TwoParams(");
constexpr Str str_DECLARE_TS_MULTICAST_DELEGATE_OneParam = txt("DECLARE_TS_MULTICAST_DELEGATE_OneParam(");
constexpr Str str_DECLARE_TS_MULTICAST_DELEGATE_TwoParams = txt("DECLARE_TS_MULTICAST_DELEGATE_TwoParams(");
constexpr Str str_DECLARE_TS_MULTICAST_DELEGATE_ThreeParams = txt("DECLARE_TS_MULTICAST_DELEGATE_ThreeParams(");
constexpr Str str_DEFINE_ACTORDESC_TYPE = txt("DEFINE_ACTORDESC_TYPE(");
constexpr Str str_DEFINE_DEFAULT_OBJECT_INITIALIZER_CONSTRUCTOR_CALL = txt("DEFINE_DEFAULT_OBJECT_INITIALIZER_CONSTRUCTOR_CALL(");
constexpr Str str_ENUM_CLASS_FLAGS = txt("ENUM_CLASS_FLAGS(");
// constexpr StrC str_FORCEINLINE = txt("FORCEINLINE");
constexpr Str str_FORCEINLINE_DEBUGGABLE = txt("FORCEINLINE_DEBUGGABLE");
constexpr Str str_GENERATED_BODY = txt("GENERATED_BODY(");
constexpr Str str_GENERATED_UCLASS_BODY = txt("GENERATED_UCLASS_BODY(");
constexpr Str str_GENERATED_USTRUCT_BODY = txt("GENERATED_USTRUCT_BODY(");
constexpr Str str_PRAGMA_DISABLE_DEPRECATION_WARNINGS = txt("PRAGMA_DISABLE_DEPRECATION_WARNINGS");
constexpr Str str_PRAGMA_ENABLE_DEPRECATION_WARNINGS = txt("PRAGMA_ENABLE_DEPRECATION_WARNINGS");
constexpr Str str_PROPERTY_BINDING_IMPLEMENTATION = txt("PROPERTY_BINDING_IMPLEMENTATION");
constexpr Str str_PROPERTY_BINDING_IMPLEMENTATION = txt("PROPERTY_BINDING_IMPLEMENTATION(");
constexpr Str str_RESULT_DECL = txt("RESULT_DECL");
constexpr Str str_SLATE_BEGIN_ARGS = txt("SLATE_BEGIN_ARGS");
constexpr Str str_SLATE_END_ARGS = txt("SLATE_END_ARGS");
constexpr Str str_TEXT = txt("TEXT");
constexpr Str str_UCLASS = txt("UCLASS");
constexpr Str str_UENUM = txt("UENUM");
constexpr Str str_UFUNCTION = txt("UFUNCTION");
constexpr Str str_UMETA = txt("UMETA");
constexpr Str str_UPARAM = txt("UPARAM");
constexpr Str str_UPROPERTY = txt("UPROPERTY");
constexpr Str str_USTRUCT = txt("USTRUCT");
constexpr Str str_UE_REQUIRES = txt("UE_REQUIRES");
constexpr Str str_UE_DEPRECATED = txt("UE_DEPRECATED");
constexpr Str str_ACTOR_HAS_LABELS = txt("ACTOR_HAS_LABELS");
constexpr Str str_HIDE_ACTOR_TRANSFORM_FUNCTIONS = txt("HIDE_ACTOR_TRANSFORM_FUNCTIONS");
constexpr Str str_SCENECOMPONENT_QUAT_TOLERANCE = txt("SCENECOMPONENT_QUAT_TOLERANCE");
constexpr Str str_SCENECOMPONENT_ROTATOR_TOLERANCE = txt("SCENECOMPONENT_ROTATOR_TOLERANCE");
constexpr Str str_GAMEPLAYATTRIBUTE_REPNOTIFY = txt("GAMEPLAYATTRIBUTE_REPNOTIFY");
constexpr Str str_GAMEPLAYATTRIBUTE_PROPERTY_GETTER = txt("GAMEPLAYATTRIBUTE_PROPERTY_GETTER");
constexpr Str str_GAMEPLAYATTRIBUTE_VALUE_GETTER = txt("GAMEPLAYATTRIBUTE_VALUE_GETTER");
constexpr Str str_GAMEPLAYATTRIBUTE_VALUE_SETTER = txt("GAMEPLAYATTRIBUTE_VALUE_SETTER");
constexpr Str str_GAMEPLAYATTRIBUTE_VALUE_INITTER = txt("GAMEPLAYATTRIBUTE_VALUE_INITTER");
constexpr Str str_SLATE_BEGIN_ARGS = txt("SLATE_BEGIN_ARGS(");
constexpr Str str_SLATE_END_ARGS = txt("SLATE_END_ARGS(");
constexpr Str str_TEXT = txt("TEXT(");
constexpr Str str_UCLASS = txt("UCLASS(");
constexpr Str str_UENUM = txt("UENUM(");
constexpr Str str_UFUNCTION = txt("UFUNCTION(");
constexpr Str str_UMETA = txt("UMETA(");
constexpr Str str_UPARAM = txt("UPARAM(");
constexpr Str str_UPROPERTY = txt("UPROPERTY(");
constexpr Str str_USTRUCT = txt("USTRUCT(");
constexpr Str str_UE_REQUIRES = txt("UE_REQUIRES(");
constexpr Str str_GASA_API = txt("GASA_API");

View File

@ -36,7 +36,7 @@ void ue_parse_testing()
case CT_Function_Fwd:
if ( class_code->Name )
{
log_fmt("%S\n", class_code->Name );
log_fmt("%s\n", class_code->Name );
// log_fmt("%s\n", class_code->to_string() );
}
break;
@ -74,7 +74,7 @@ void ue_parse_testing()
case CT_Function_Fwd:
if ( class_code->Name )
{
log_fmt("%S\n", class_code->Name );
log_fmt("%s\n", class_code->Name );
// log_fmt("%s\n", class_code->to_string() );
}
break;
@ -109,7 +109,7 @@ void ue_parse_testing()
case CT_Function_Fwd:
if ( class_code->Name )
{
log_fmt("%S\n", class_code->Name );
log_fmt("%s\n", class_code->Name );
}
break;
}
@ -143,7 +143,7 @@ void ue_parse_testing()
case CT_Function_Fwd:
if ( class_code->Name )
{
log_fmt("%S\n", class_code->Name );
log_fmt("%s\n", class_code->Name );
}
break;
}
@ -177,7 +177,7 @@ void ue_parse_testing()
case CT_Function_Fwd:
if ( class_code->Name )
{
log_fmt("%S\n", class_code->Name );
log_fmt("%s\n", class_code->Name );
}
break;
}
@ -211,7 +211,7 @@ void ue_parse_testing()
case CT_Function_Fwd:
if ( class_code->Name )
{
log_fmt("%S\n", class_code->Name );
log_fmt("%s\n", class_code->Name );
}
break;
}

View File

@ -3498,7 +3498,6 @@ void register_macro( Macro macro ) {
GEN_ASSERT_NOT_NULL(macro.Name.Ptr);
GEN_ASSERT(macro.Name.Len > 0);
u32 key = crc32( macro.Name.Ptr, macro.Name.Len );
macro.Name = cache_str(macro.Name);
hashtable_set( _ctx->Macros, key, macro );
}
@ -3512,7 +3511,6 @@ void register_macros( s32 num, ... )
Macro macro = va_arg(va, Macro);
GEN_ASSERT_NOT_NULL(macro.Name.Ptr);
GEN_ASSERT(macro.Name.Len > 0);
macro.Name = cache_str(macro.Name);
u32 key = crc32( macro.Name.Ptr, macro.Name.Len );
hashtable_set( _ctx->Macros, key, macro );
@ -3529,7 +3527,6 @@ void register_macros( s32 num, Macro* macros )
Macro macro = * macros;
GEN_ASSERT_NOT_NULL(macro.Name.Ptr);
GEN_ASSERT(macro.Name.Len > 0);
macro.Name = cache_str(macro.Name);
u32 key = crc32( macro.Name.Ptr, macro.Name.Len );
hashtable_set( _ctx->Macros, key, macro );
@ -6163,24 +6160,45 @@ void lex_found_token( LexContext* ctx )
ctx->token.Type = macrotype_to_toktype(macro->Type);
b32 is_functional = macro_is_functional(* macro);
resolved_to_macro = has_args ? is_functional : ! is_functional;
if ( ! resolved_to_macro ) {
log_fmt("Info(%d, %d): %S identified as a macro but usage here does not resolve to one (interpreting as identifier)\n"
, ctx->token.Line
, ctx->token.Line
, macro->Name
);
}
}
if ( resolved_to_macro )
{
// TODO(Ed): When we introduce a macro AST (and expression support), we'll properly lex this section.
// Want to ignore any arguments the define may have as they can be execution expressions.
if ( has_args ) {
if ( has_args )
{
ctx->token.Flags |= TF_Macro_Functional;
// move_forward();
// ctx->token.Text.Len++;
// s32 level = 0;
// while ( ctx->left && ((* ctx->scanner) != ')' || level > 0) )
// {
// if ( (* ctx->scanner) == '(' )
// level++;
// else if ( (* ctx->scanner) == ')' && level > 0 )
// level--;
// move_forward();
// ctx->token.Text.Len++;
// }
// move_forward();
// ctx->token.Text.Len++;
}
if ( bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Attribute) ) {
ctx->token.Flags |= TF_Attribute;
}
//if ( (* ctx->scanner) == '\r' && ctx->scanner[1] == '\n' )
//{
// move_forward();
// ctx->token..Text.Length++;
//}
//else if ( (* ctx->scanner) == '\n' )
//{
// move_forward();
// ctx->token..Text.Length++;
//}
}
else
{
@ -7234,7 +7252,6 @@ internal CodeBody parse_global_nspace ( CodeType which
internal Code parse_global_nspace_constructor_destructor( CodeSpecifiers specifiers );
internal Token parse_identifier ( bool* possible_member_function );
internal CodeInclude parse_include ();
internal Code parse_macro_as_definiton ( CodeAttributes attributes, CodeSpecifiers specifiers );
internal CodeOperator parse_operator_after_ret_type ( ModuleFlag mflags, CodeAttributes attributes, CodeSpecifiers specifiers, CodeTypename ret_type );
internal Code parse_operator_function_or_variable( bool expects_function, CodeAttributes attributes, CodeSpecifiers specifiers );
internal CodePragma parse_pragma ();
@ -7609,7 +7626,7 @@ CodeAttributes parse_attributes()
s32 len = 0;
// There can be more than one attribute. If there is flatten them to a single string.
// TODO(Ed): Support chaining attributes (Use parameter linkage pattern)
// TODO(Ed): Support keeping an linked list of attributes similar to parameters
while ( left && tok_is_attribute(currtok) )
{
if ( check( Tok_Attribute_Open ) )
@ -9465,12 +9482,6 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
Code result = InvalidCode;
Code macro_stmt = parse_macro_as_definiton(attributes, specifiers);
if (macro_stmt) {
parser_pop(& _ctx->parser);
return macro_stmt;
}
CodeTypename type = parser_parse_type( parser_not_from_template, nullptr );
// <Attributes> <Specifiers> <ReturnType/ValueType>
@ -9543,36 +9554,6 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
return result;
}
internal
Code parse_macro_as_definiton( CodeAttributes attributes, CodeSpecifiers specifiers )
{
push_scope();
if (currtok.Type != Tok_Preprocess_Macro_Stmt ) {
parser_pop(& _ctx->parser);
return NullCode;
}
Macro* macro = lookup_macro(currtok.Text);
b32 can_resolve_to_definition = macro && bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Definition);
if ( ! can_resolve_to_definition) {
parser_pop(& _ctx->parser);
return NullCode;
}
// TODO(Ed): When AST_Macro is made, have it support attributs and specifiers for when its behaving as a declaration/definition.
Code code = parse_simple_preprocess( Tok_Preprocess_Macro_Stmt );
// Attributes and sepcifiers will be collapsed into the macro's serialization.
StrBuilder resolved_definition = strbuilder_fmt_buf(_ctx->Allocator_Temp, "%S %S %S"
, attributes ? strbuilder_to_str( attributes_to_strbuilder(attributes)) : txt("")
, specifiers ? strbuilder_to_str( specifiers_to_strbuilder(specifiers)) : txt("")
, code->Content
);
Code result = untyped_str( strbuilder_to_str(resolved_definition) );
parser_pop(& _ctx->parser);
return result;
}
internal
CodePragma parse_pragma()
{
@ -10828,11 +10809,8 @@ CodeEnum parser_parse_enum( bool inplace_def )
// Unreal UMETA macro support
if ( currtok.Type == Tok_Preprocess_Macro_Expr ) {
Code macro = parse_simple_preprocess( Tok_Preprocess_Macro_Expr );
eat( Tok_Preprocess_Macro_Expr );
// <Name> = <Expression> <Macro>
// We're intentially ignoring this code as its going to be serialized as an untyped string with the rest of the enum "entry".
// TODO(Ed): We need a CodeEnumEntry, AST_EnumEntry types
}
if ( currtok.Type == Tok_Comma )
@ -11130,13 +11108,6 @@ CodeFn parser_parse_function()
}
// <export> <Attributes> <Specifiers>
// Note(Ed): We're enforcing that using this codepath requires non-macro jank.
// Code macro_stmt = parse_macro_as_definiton(attributes, specifiers);
// if (macro_stmt) {
// parser_pop(& _ctx->parser);
// return macro_stmt;
// }
CodeTypename ret_type = parser_parse_type(parser_not_from_template, nullptr);
if ( cast(Code, ret_type) == Code_Invalid ) {
parser_pop(& _ctx->parser);
@ -12525,13 +12496,6 @@ CodeVar parser_parse_variable()
}
// <ModuleFlags> <Attributes> <Specifiers>
// Note(Ed): We're enforcing that using this codepath requires non-macro jank.
// Code macro_stmt = parse_macro_as_definiton(attributes, specifiers);
// if (macro_stmt) {
// parser_pop(& _ctx->parser);
// return macro_stmt;
// }
CodeTypename type = parser_parse_type(parser_not_from_template, nullptr);
// <ModuleFlags> <Attributes> <Specifiers> <ValueType>

View File

@ -640,10 +640,11 @@ FORCEINLINE bool is_trailing( Specifier specifier )
return spec_is_trailing( specifier );
}
#define GEN_DEFINE_ATTRIBUTE_TOKENS \
Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" ) \
Entry( Tok_Attribute_COREUOBJECT_API, "COREUOBJECT_API" ) Entry( Tok_Attribute_ENGINE_API, "ENGINE_API" ) \
Entry( Tok_Attribute_GAMEPLAYABILITIES_API, "GAMEPLAYABILITIES_API" ) Entry( Tok_Attribute_UMG_API, "UMG_API" )
#define GEN_DEFINE_ATTRIBUTE_TOKENS \
Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" ) \
Entry( Tok_Attribute_COREUOBJECT_API, "COREUOBJECT_API" ) Entry( Tok_Attribute_ENGINE_API, "ENGINE_API" ) \
Entry( Tok_Attribute_GAMEPLAYABILITIES_API, "GAMEPLAYABILITIES_API" ) Entry( Tok_Attribute_UMG_API, "UMG_API" ) \
Entry( Tok_Attribute_UE_DEPRECATED, "UE_DEPRECATED" )
enum TokType : u32
{
@ -691,7 +692,6 @@ enum TokType : u32
Tok_Operator,
Tok_Preprocess_Hash,
Tok_Preprocess_Define,
Tok_Preprocess_Define_Param,
Tok_Preprocess_If,
Tok_Preprocess_IfDef,
Tok_Preprocess_IfNotDef,
@ -752,6 +752,7 @@ enum TokType : u32
Tok_Attribute_ENGINE_API,
Tok_Attribute_GAMEPLAYABILITIES_API,
Tok_Attribute_UMG_API,
Tok_Attribute_UE_DEPRECATED,
Tok_NumTokens
};
@ -802,7 +803,6 @@ inline Str toktype_to_str( TokType type )
{ "__operator__", sizeof( "__operator__" ) - 1 },
{ "#", sizeof( "#" ) - 1 },
{ "define", sizeof( "define" ) - 1 },
{ "__define_param__", sizeof( "__define_param__" ) - 1 },
{ "if", sizeof( "if" ) - 1 },
{ "ifdef", sizeof( "ifdef" ) - 1 },
{ "ifndef", sizeof( "ifndef" ) - 1 },
@ -863,6 +863,7 @@ inline Str toktype_to_str( TokType type )
{ "ENGINE_API", sizeof( "ENGINE_API" ) - 1 },
{ "GAMEPLAYABILITIES_API", sizeof( "GAMEPLAYABILITIES_API" ) - 1 },
{ "UMG_API", sizeof( "UMG_API" ) - 1 },
{ "UE_DEPRECATED", sizeof( "UE_DEPRECATED" ) - 1 },
};
return lookup[type];
}
@ -1054,22 +1055,8 @@ enum EMacroFlags : u16
{
MF_Functional = bit(0), // Macro has parameters (args expected to be passed)
MF_Expects_Body = bit(1), // Expects to assign a braced scope to its body.
// lex__eat wil treat this macro as an identifier if the parser attempts to consume it as one.
// ^^^ This is a kludge because we don't support push/pop macro pragmas rn.
MF_Allow_As_Identifier = bit(2),
// lex__eat wil treat this macro as an attribute if the parser attempts to consume it as one.
// ^^^ This a kludge because unreal has a macro that behaves as both a 'statement' and an attribute (UE_DEPRECATED, PRAGMA_ENABLE_DEPRECATION_WARNINGS, etc)
// TODO(Ed): We can keep the MF_Allow_As_Attribute flag for macros, however, we need to add the ability of AST_Attributes to chain themselves.
// Its thats already a thing in the standard language anyway
// & it would allow UE_DEPRECATED, (UE_PROPERTY / UE_FUNCTION) to chain themselves as attributes of a resolved member function/varaible definition
MF_Allow_As_Attribute = bit(3),
// When a macro is encountered after attributs and specifiers while parsing a function, or variable:
// It will consume the macro and treat it as resolving the definition. (Yes this is for Unreal Engine)
// (MUST BE OF MT_Statement TYPE)
MF_Allow_As_Definition = bit(4),
MF_Allow_As_Identifier = bit(2), // lex__eat wil treat this macro as an identifier if the parser attempts to consume it as one.
// ^^^ This is a sort of kludge because we don't support push/pop macro programs rn. ^^^
MF_Null = 0,
MF_UnderlyingType = GEN_U16_MAX,
@ -2754,14 +2741,13 @@ struct AST_Body
};
static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Body is not the same size as AST");
// TODO(Ed): Support chaining attributes (Use parameter linkage pattern)
struct AST_Attributes
{
union {
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StrCached Content;
};
StrCached Name;
StrCached Name;
Code Prev;
Code Next;
Token* Tok;