mirror of
https://github.com/Ed94/gencpp.git
synced 2025-07-16 10:28:58 -07:00
Compare commits
15 Commits
ef78772278
...
v0.20-Alph
Author | SHA1 | Date | |
---|---|---|---|
2a025cb073 | |||
0e782cdf99 | |||
a390e7f895 | |||
65427bd0f1 | |||
cb898595b0 | |||
9b86d84dd6 | |||
4dfb9031d7 | |||
401f85f673 | |||
caec5d8dfc | |||
44d0a9cf9d | |||
c0aa4fee95 | |||
913d9bf26b | |||
c8d6c27f07 | |||
aecc2c59dd | |||
0e32838da1 |
10
Readme.md
10
Readme.md
@ -10,18 +10,16 @@ Its not meant to be a black box metaprogramming utility, it should be easy to in
|
||||
|
||||
## Documentation
|
||||
|
||||
If your going to metaprogram, you can never have enough docs on your tooling...
|
||||
|
||||
* [docs - General](./docs/Readme.md): Overview and additional docs
|
||||
* [AST_Design](./docs/AST_Design.md): Overvie of ASTs
|
||||
* [AST Types](./docs/AST_Types.md): Listing of all AST types along with their Code type interface.
|
||||
* [Parsing](./docs/Parsing.md): Overview of the parsing interface.
|
||||
* [Parser Algo](./docs/Parser_Algo.md): In-depth breakdown of the parser's implementation.
|
||||
* [base](./base/Readme.md): Essential (base) library.
|
||||
* [gen_c_library](./gen_c_library/Readme.md): C11 library variant generation (single header and segmeented).
|
||||
* [gen_segmented](./gen_segmented/Readme.md): Segemented C++ (`gen.<hpp/cpp>`, `gen.dep.<hpp/cpp>`) generation
|
||||
* [gen_singleheader](./gen_singleheader/Readme.md): Singlehader C++ generation `gen.hpp`
|
||||
* [gen_unreal_engine](./gen_unreal_engine/Readme.md): Unreal Engine thirdparty code generation.
|
||||
* [gen_c_library](./gen_c_library/): C11 library variant generation (single header and segmeented).
|
||||
* [gen_segmented](./gen_segmented/): Segemented C++ (`gen.<hpp/cpp>`, `gen.dep.<hpp/cpp>`) generation
|
||||
* [gen_singleheader](./gen_singleheader/): Singlehader C++ generation `gen.hpp`
|
||||
* [gen_unreal_engine](./gen_unreal_engine/): Unreal Engine thirdparty code generation.
|
||||
|
||||
## Notes
|
||||
|
||||
|
@ -31,8 +31,6 @@ Standard formats:
|
||||
|
||||
Code not making up the core library is located in `auxiliary/<auxiliary_name>.<hpp/cpp>`. These are optional extensions or tools for the library.
|
||||
|
||||
*Note: A variant of the C++ library could be generated where those additonal support features are removed (see gen_c_library implementation for an idea of how)*
|
||||
|
||||
## Dependencies
|
||||
|
||||
The project has no external dependencies beyond:
|
||||
@ -71,7 +69,9 @@ This library was written in a subset of C++ where the following are not used at
|
||||
* Exceptions
|
||||
|
||||
Polymorphic & Member-functions are used as an ergonomic choice, along with a conserative use of operator overloads.
|
||||
The base library itself does not use anything but C-like features to allow for generating a derviative compatiable with C (WIP).
|
||||
The base library itself does not use anything but C-like features to allow for generating a derviative compatiable with C.
|
||||
|
||||
Member function support or free-functions with reference object passing are wrapped in `! GEN_C_LIKE CPP` preprocess conditionals.
|
||||
|
||||
## C++ template usage
|
||||
|
||||
@ -115,9 +115,9 @@ The vast majority of macros should be single-line subsitutions that either add:
|
||||
|
||||
## On base code generation
|
||||
|
||||
There are ***five*** header files which are automatically generated by [base_codegen.hpp](./helpers/base_codegen.hpp). They are all located in [components/gen](./components/gen/).
|
||||
There are ***five*** header files which are automatically generated using [base_codegen.hpp](./helpers/base_codegen.hpp) by [base.cpp](./base.cpp). They are all located in [components/gen](./components/gen/).
|
||||
|
||||
* [`ecode.hpp`](./components/gen/ecode.hpp): `CodeType` enum definition and related implementaiton. Generation is based off of [`ECodeType.csv](./enums/ECodeTypes.csv).
|
||||
* [`ecodetypes.hpp`](./components/gen/ecode.hpp): `CodeType` enum definition and related implementaiton. Generation is based off of [`ECodeType.csv](./enums/ECodeTypes.csv).
|
||||
* [`especifier.hpp`](./components/gen/especifier.hpp): `Specifier` enum definition, etc. Generated using [`ESpecifier.csv`](./enums/ESpecifier.csv).
|
||||
* [`eoperator.hpp`](./components/gen/eoperator.hpp): `Operator` enum definition, etc. Generated using [`EOperator.hpp`](./enums/EOperator.csv).
|
||||
* [`etoktype.cpp`](./components/gen/etoktype.cpp): `TokType` enum defininition, etc. Used by the lexer and parser backend. Uses two csvs:
|
||||
@ -135,7 +135,7 @@ Currently unsupported. I want the library to be *stable* and *correct*, with the
|
||||
|
||||
This library is relatively very small (for parsing C++), and can be extended without much hassle.
|
||||
|
||||
The convention you'll see used throughout the interface of the library is as follows:
|
||||
The convention you'll see used throughout the upfront interface of the library is as follows:
|
||||
|
||||
1. Check name or parameters to make sure they are valid for the construction requested
|
||||
2. Create a code object using `make_code`.
|
||||
@ -146,7 +146,7 @@ Names or Content fields are interned strings and thus showed be cached using `ge
|
||||
|
||||
`def_operator` is the most sophisticated upfront constructor as it has multiple permutations of definitions that could be created that are not trivial to determine if valid.
|
||||
|
||||
The parser is documented under `docs/Parsing.md` and `docs/Parser_Algo.md`. Extending it is more serious, but resolution of a parse for a given internal parse procedure is well documented.
|
||||
The parser is documented under [`docs/Parsing.md`](../docs/Parsing.md) and [`docs/Parser_Algo.md`](../docs/Parser_Algo.md). Extending it is more serious.
|
||||
|
||||
## A note on compilation and runtime generation speed
|
||||
|
||||
|
@ -116,4 +116,33 @@ Code scan_file( char const* path )
|
||||
return untyped_str( string_to_strc(str) );
|
||||
}
|
||||
|
||||
CodeBody parse_file( const char* path ) {
|
||||
FileContents file = file_read_contents( GlobalAllocator, true, path );
|
||||
StrC content = { file.size, (char const*)file.data };
|
||||
CodeBody code = parse_global_body( content );
|
||||
log_fmt("\nParsed: %s\n", path);
|
||||
return code;
|
||||
}
|
||||
|
||||
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
|
||||
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
|
||||
Arena csv_arena = arena_init_from_memory(content.data, content.size);
|
||||
|
||||
CSV_Column result;
|
||||
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
|
||||
result.Content = result.ADT.nodes[0].nodes;
|
||||
return result;
|
||||
}
|
||||
|
||||
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) {
|
||||
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
|
||||
Arena csv_arena = arena_init_from_memory(content.data, content.size);
|
||||
|
||||
CSV_Columns2 result;
|
||||
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
|
||||
result.Col_1 = result.ADT.nodes[0].nodes;
|
||||
result.Col_2 = result.ADT.nodes[1].nodes;
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma endregion Scanner
|
||||
|
@ -22,14 +22,7 @@
|
||||
// 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
|
||||
CodeBody parse_file( const char* path )
|
||||
{
|
||||
FileContents file = file_read_contents( GlobalAllocator, true, path );
|
||||
CodeBody code = parse_global_body( { file.size, (char const*)file.data } );
|
||||
log_fmt("\nParsed: %s\n", path);
|
||||
return code;
|
||||
}
|
||||
CodeBody parse_file( const char* path );
|
||||
|
||||
// The follow is basic support for light csv parsing (use it as an example)
|
||||
// Make something robust if its more serious.
|
||||
@ -37,41 +30,17 @@ CodeBody parse_file( const char* path )
|
||||
typedef struct CSV_Column CSV_Column;
|
||||
struct CSV_Column {
|
||||
CSV_Object ADT;
|
||||
Array<ADT_Node> Content;
|
||||
Array(ADT_Node) Content;
|
||||
};
|
||||
|
||||
typedef struct CSV_Columns2 CSV_Columns2;
|
||||
struct CSV_Columns2 {
|
||||
CSV_Object ADT;
|
||||
Array<ADT_Node> Col_1;
|
||||
Array<ADT_Node> Col_2;
|
||||
Array(ADT_Node) Col_1;
|
||||
Array(ADT_Node) Col_2;
|
||||
};
|
||||
|
||||
inline
|
||||
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
|
||||
char scratch_mem[kilobytes(32)];
|
||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
|
||||
|
||||
CSV_Column result;
|
||||
csv_parse( & result.ADT, scratch_mem, allocator, false );
|
||||
result.Content = result.ADT.nodes[0].nodes;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) {
|
||||
char scratch_mem[kilobytes(32)];
|
||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
|
||||
|
||||
CSV_Columns2 result;
|
||||
csv_parse( & result.ADT, scratch_mem, allocator, false );
|
||||
result.Col_1 = result.ADT.nodes[0].nodes;
|
||||
result.Col_2 = result.ADT.nodes[1].nodes;
|
||||
return result;
|
||||
}
|
||||
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path);
|
||||
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path);
|
||||
|
||||
#pragma endregion Scanner
|
||||
|
@ -3,7 +3,6 @@
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#define GEN_C_LIKE_CPP 1
|
||||
#include "gen.cpp"
|
||||
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -16,7 +15,7 @@ GEN_NS_END
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* path_format_style = "../scripts/.clang-format";
|
||||
constexpr char const* scratch_file = "gen/scratch.hpp";
|
||||
constexpr char const* scratch_file = "build/scratch.hpp";
|
||||
|
||||
Code format( Code code ) {
|
||||
return code_refactor_and_format(code, scratch_file, nullptr, path_format_style );
|
||||
@ -26,27 +25,25 @@ constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gencpp's bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
def_include(txt("components/types.hpp")),
|
||||
preprocess_endif,
|
||||
fmt_newline,
|
||||
untyped_str( to_strc_from_c_str(generation_notice) )
|
||||
));
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
|
||||
__debugbreak();
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
def_include(txt("components/types.hpp")),
|
||||
preprocess_endif,
|
||||
fmt_newline,
|
||||
untyped_str( to_strc_from_c_str(generation_notice) )
|
||||
));
|
||||
|
||||
CodeBody ecode = gen_ecode ( "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" );
|
||||
CodeBody ast_inlines = gen_ast_inlines();
|
||||
|
||||
Builder header_ecode = builder_open( "components/gen/ecode.hpp" );
|
||||
Builder header_ecode = builder_open( "components/gen/ecodetypes.hpp" );
|
||||
builder_print( & header_ecode, gen_component_header );
|
||||
builder_print( & header_ecode, format(ecode) );
|
||||
builder_write( & header_ecode);
|
||||
|
@ -497,7 +497,7 @@ void code_to_string_ptr( Code self, String* result )
|
||||
break;
|
||||
|
||||
case CT_Parameters:
|
||||
params_to_string_ref(cast(CodeParam, self), result );
|
||||
params_to_string_ref(cast(CodeParams, self), result );
|
||||
break;
|
||||
|
||||
case CT_Preprocess_Define:
|
||||
|
@ -37,7 +37,7 @@ struct AST_Module;
|
||||
struct AST_NS;
|
||||
struct AST_Operator;
|
||||
struct AST_OpCast;
|
||||
struct AST_Param;
|
||||
struct AST_Params;
|
||||
struct AST_Pragma;
|
||||
struct AST_PreprocessCond;
|
||||
struct AST_Specifiers;
|
||||
@ -109,7 +109,7 @@ typedef AST_Module* CodeModule;
|
||||
typedef AST_NS* CodeNS;
|
||||
typedef AST_Operator* CodeOperator;
|
||||
typedef AST_OpCast* CodeOpCast;
|
||||
typedef AST_Param* CodeParam;
|
||||
typedef AST_Params* CodeParams;
|
||||
typedef AST_PreprocessCond* CodePreprocessCond;
|
||||
typedef AST_Pragma* CodePragma;
|
||||
typedef AST_Specifiers* CodeSpecifiers;
|
||||
@ -131,7 +131,7 @@ struct CodeModule;
|
||||
struct CodeNS;
|
||||
struct CodeOperator;
|
||||
struct CodeOpCast;
|
||||
struct CodeParam;
|
||||
struct CodeParams;
|
||||
struct CodePreprocessCond;
|
||||
struct CodePragma;
|
||||
struct CodeSpecifiers;
|
||||
@ -209,6 +209,7 @@ struct CodeStmt_Switch;
|
||||
struct CodeStmt_While;
|
||||
#endif
|
||||
|
||||
// GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
@ -229,8 +230,6 @@ struct CodeUsing;
|
||||
struct CodeVar;
|
||||
#endif
|
||||
|
||||
#undef Define_Code
|
||||
|
||||
GEN_NS_PARSER_BEGIN
|
||||
|
||||
struct Token;
|
||||
@ -310,18 +309,6 @@ struct Code
|
||||
|
||||
Code& operator ++();
|
||||
|
||||
// TODO(Ed) : Remove this overload.
|
||||
auto& operator*()
|
||||
{
|
||||
local_persist thread_local
|
||||
Code NullRef = { nullptr };
|
||||
|
||||
if ( ast == nullptr )
|
||||
return NullRef;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
# define operator explicit operator
|
||||
#endif
|
||||
@ -343,7 +330,7 @@ struct Code
|
||||
operator CodeNS() const;
|
||||
operator CodeOperator() const;
|
||||
operator CodeOpCast() const;
|
||||
operator CodeParam() const;
|
||||
operator CodeParams() const;
|
||||
operator CodePragma() const;
|
||||
operator CodePreprocessCond() const;
|
||||
operator CodeSpecifiers() const;
|
||||
@ -423,7 +410,7 @@ struct AST
|
||||
union {
|
||||
Code NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
Code SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
|
||||
Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
|
||||
Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
@ -456,7 +443,7 @@ struct AST
|
||||
Operator Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
|
||||
s32 VarParenthesizedInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
|
||||
};
|
||||
};
|
||||
static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST is not size of AST_POD_Size" );
|
||||
|
@ -127,7 +127,7 @@ struct AST_Constructor
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) * 1 ];
|
||||
CodeSpecifiers Specs;
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code Body;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
};
|
||||
@ -550,7 +550,7 @@ struct AST_Fn
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
@ -613,7 +613,7 @@ struct AST_Operator
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
@ -639,9 +639,9 @@ struct AST_OpCast
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ValueType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
@ -654,7 +654,7 @@ struct AST_OpCast
|
||||
};
|
||||
static_assert( sizeof(AST_OpCast) == sizeof(AST), "ERROR: AST_OpCast is not the same size as AST");
|
||||
|
||||
struct AST_Param
|
||||
struct AST_Params
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
@ -669,15 +669,15 @@ struct AST_Param
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
CodeParam Last;
|
||||
CodeParam Next;
|
||||
CodeParams Last;
|
||||
CodeParams Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
};
|
||||
static_assert( sizeof(AST_Param) == sizeof(AST), "ERROR: AST_Param is not the same size as AST");
|
||||
static_assert( sizeof(AST_Params) == sizeof(AST), "ERROR: AST_Params is not the same size as AST");
|
||||
|
||||
struct AST_Pragma
|
||||
{
|
||||
@ -971,7 +971,7 @@ struct AST_Template
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
@ -1000,7 +1000,7 @@ struct AST_Type
|
||||
CodeSpecifiers Specs;
|
||||
Code QualifierID;
|
||||
// CodeTypename ReturnType; // Only used for function signatures
|
||||
// CodeParam Params; // Only used for function signatures
|
||||
// CodeParams Params; // Only used for function signatures
|
||||
Code ArrExpr;
|
||||
// CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
};
|
||||
@ -1017,7 +1017,6 @@ struct AST_Type
|
||||
static_assert( sizeof(AST_Type) == sizeof(AST), "ERROR: AST_Type is not the same size as AST");
|
||||
#endif
|
||||
|
||||
// TODO(Ed): Add support for preserving the typename's keyword qualifier (struct, class, enum, etc), mostly needed for C.
|
||||
struct AST_Typename
|
||||
{
|
||||
union {
|
||||
@ -1028,7 +1027,7 @@ struct AST_Typename
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType; // Only used for function signatures
|
||||
CodeParam Params; // Only used for function signatures
|
||||
CodeParams Params; // Only used for function signatures
|
||||
Code ArrExpr;
|
||||
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
};
|
||||
@ -1140,7 +1139,7 @@ struct AST_Var
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
s32 VarConstructorInit;
|
||||
s32 VarParenthesizedInit;
|
||||
};
|
||||
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
|
||||
|
||||
|
@ -197,7 +197,7 @@ void class_to_string_def( CodeClass self, String* result )
|
||||
|
||||
while ( interface )
|
||||
{
|
||||
string_append_fmt( result, ", %S", typename_to_string(interface) );
|
||||
string_append_fmt( result, ", public %S", typename_to_string(interface) );
|
||||
interface = interface->Next ? cast(CodeTypename, interface->Next) : NullCode;
|
||||
}
|
||||
}
|
||||
@ -346,7 +346,7 @@ void enum_to_string_def(CodeEnum self, String* result )
|
||||
, body_to_string(self->Body)
|
||||
);
|
||||
else if ( self->UnderlyingTypeMacro )
|
||||
string_append_fmt( result, "%SC %S\n\n{\n%S\n}"
|
||||
string_append_fmt( result, "%SC %S\n{\n%S\n}"
|
||||
, self->Name
|
||||
, code_to_string(self->UnderlyingTypeMacro)
|
||||
, body_to_string(self->Body)
|
||||
@ -863,7 +863,7 @@ void opcast_to_string_fwd(CodeOpCast self, String* result )
|
||||
string_append_fmt( result, "operator %S();\n", typename_to_string(self->ValueType) );
|
||||
}
|
||||
|
||||
String params_to_string(CodeParam self)
|
||||
String params_to_string(CodeParams self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(self);
|
||||
@ -872,7 +872,7 @@ String params_to_string(CodeParam self)
|
||||
return result;
|
||||
}
|
||||
|
||||
void params_to_string_ref( CodeParam self, String* result )
|
||||
void params_to_string_ref( CodeParams self, String* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
@ -904,7 +904,7 @@ void params_to_string_ref( CodeParam self, String* result )
|
||||
|
||||
if ( self->NumEntries - 1 > 0 )
|
||||
{
|
||||
for ( CodeParam param = begin_CodeParam(self->Next); param != end_CodeParam(self->Next); param = next_CodeParam(self->Next, param) )
|
||||
for ( CodeParams param = begin_CodeParams(self->Next); param != end_CodeParams(self->Next); param = next_CodeParams(self->Next, param) )
|
||||
{
|
||||
string_append_fmt( result, ", %S", params_to_string(param) );
|
||||
}
|
||||
@ -1385,7 +1385,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
||||
|
||||
if ( self->Value )
|
||||
{
|
||||
if ( self->VarConstructorInit )
|
||||
if ( self->VarParenthesizedInit )
|
||||
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
||||
else
|
||||
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
||||
@ -1395,7 +1395,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
||||
if ( self->NextVar )
|
||||
string_append_fmt( result, ", %S", var_to_string(self->NextVar) );
|
||||
|
||||
if ( self->VarConstructorInit )
|
||||
if ( self->VarParenthesizedInit )
|
||||
string_append_strc( result, txt(" )"));
|
||||
|
||||
return;
|
||||
@ -1431,7 +1431,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
||||
|
||||
if ( self->Value )
|
||||
{
|
||||
if ( self->VarConstructorInit )
|
||||
if ( self->VarParenthesizedInit )
|
||||
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
||||
else
|
||||
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
||||
@ -1440,7 +1440,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
||||
if ( self->NextVar )
|
||||
string_append_fmt( result, ", %S", var_to_string(self->NextVar) );
|
||||
|
||||
if ( self->VarConstructorInit )
|
||||
if ( self->VarParenthesizedInit )
|
||||
string_append_strc( result, txt(" )"));
|
||||
|
||||
if ( self->InlineCmt )
|
||||
@ -1471,7 +1471,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
||||
|
||||
if ( self->Value )
|
||||
{
|
||||
if ( self->VarConstructorInit )
|
||||
if ( self->VarParenthesizedInit )
|
||||
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
||||
else
|
||||
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
||||
@ -1480,7 +1480,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
||||
if ( self->NextVar )
|
||||
string_append_fmt( result, ", %S", var_to_string( self->NextVar) );
|
||||
|
||||
if ( self->VarConstructorInit )
|
||||
if ( self->VarParenthesizedInit )
|
||||
string_append_strc( result, txt(" )"));
|
||||
|
||||
string_append_strc( result, txt(";") );
|
||||
|
@ -32,15 +32,15 @@ String class_to_string ( CodeClass self );
|
||||
void class_to_string_def( CodeClass self, String* result );
|
||||
void class_to_string_fwd( CodeClass self, String* result );
|
||||
|
||||
void params_append (CodeParam params, CodeParam param );
|
||||
CodeParam params_get (CodeParam params, s32 idx);
|
||||
bool params_has_entries (CodeParam params );
|
||||
String params_to_string (CodeParam params );
|
||||
void params_to_string_ref(CodeParam params, String* result );
|
||||
void params_append (CodeParams params, CodeParams param );
|
||||
CodeParams params_get (CodeParams params, s32 idx);
|
||||
bool params_has_entries (CodeParams params );
|
||||
String params_to_string (CodeParams params );
|
||||
void params_to_string_ref(CodeParams params, String* result );
|
||||
|
||||
CodeParam begin_CodeParam(CodeParam params);
|
||||
CodeParam end_CodeParam (CodeParam params);
|
||||
CodeParam next_CodeParam (CodeParam params, CodeParam entry_iter);
|
||||
CodeParams begin_CodeParams(CodeParams params);
|
||||
CodeParams end_CodeParams (CodeParams params);
|
||||
CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter);
|
||||
|
||||
bool specifiers_append (CodeSpecifiers specifiers, Specifier spec);
|
||||
s32 specifiers_has (CodeSpecifiers specifiers, Specifier spec);
|
||||
@ -188,28 +188,28 @@ struct CodeClass
|
||||
AST_Class* ast;
|
||||
};
|
||||
|
||||
struct CodeParam
|
||||
struct CodeParams
|
||||
{
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
Using_Code( CodeParam );
|
||||
forceinline void append( CodeParam other );
|
||||
forceinline CodeParam get( s32 idx );
|
||||
Using_Code( CodeParams );
|
||||
forceinline void append( CodeParams other );
|
||||
forceinline CodeParams get( s32 idx );
|
||||
forceinline bool has_entries();
|
||||
forceinline String to_string();
|
||||
forceinline void to_string( String& result );
|
||||
|
||||
forceinline CodeParam begin() { return begin_CodeParam(* this); }
|
||||
forceinline CodeParam end() { return end_CodeParam(* this); }
|
||||
forceinline CodeParams begin() { return begin_CodeParams(* this); }
|
||||
forceinline CodeParams end() { return end_CodeParams(* this); }
|
||||
#endif
|
||||
Using_CodeOps( CodeParam );
|
||||
Using_CodeOps( CodeParams );
|
||||
forceinline operator Code() { return { (AST*)ast }; }
|
||||
forceinline CodeParam operator*() { return * this; }
|
||||
forceinline AST_Param* operator->() {
|
||||
forceinline CodeParams operator*() { return * this; }
|
||||
forceinline AST_Params* operator->() {
|
||||
GEN_ASSERT(ast);
|
||||
return ast;
|
||||
}
|
||||
CodeParam& operator++();
|
||||
AST_Param* ast;
|
||||
CodeParams& operator++();
|
||||
AST_Params* ast;
|
||||
};
|
||||
|
||||
struct CodeSpecifiers
|
||||
@ -951,7 +951,7 @@ struct InvalidCode_ImplictCaster
|
||||
operator CodeNS () const { return cast(CodeNS, Code_Invalid); }
|
||||
operator CodeOperator () const { return cast(CodeOperator, Code_Invalid); }
|
||||
operator CodeOpCast () const { return cast(CodeOpCast, Code_Invalid); }
|
||||
operator CodeParam () const { return cast(CodeParam, Code_Invalid); }
|
||||
operator CodeParams () const { return cast(CodeParams, Code_Invalid); }
|
||||
operator CodePragma () const { return cast(CodePragma, Code_Invalid); }
|
||||
operator CodePreprocessCond() const { return cast(CodePreprocessCond, Code_Invalid); }
|
||||
operator CodeSpecifiers () const { return cast(CodeSpecifiers, Code_Invalid); }
|
||||
@ -984,7 +984,7 @@ struct NullCode_ImplicitCaster
|
||||
operator CodeNS () const { return {nullptr}; }
|
||||
operator CodeOperator () const { return {nullptr}; }
|
||||
operator CodeOpCast () const { return {nullptr}; }
|
||||
operator CodeParam () const { return {nullptr}; }
|
||||
operator CodeParams () const { return {nullptr}; }
|
||||
operator CodePragma () const { return {nullptr}; }
|
||||
operator CodePreprocessCond() const { return {nullptr}; }
|
||||
operator CodeSpecifiers () const { return {nullptr}; }
|
||||
@ -1011,19 +1011,19 @@ forceinline Code end ( CodeBody body ) { return end_CodeBody(b
|
||||
forceinline Code next ( CodeBody body, Code entry_iter ) { return next_CodeBody(body, entry_iter); }
|
||||
|
||||
forceinline void add_interface( CodeClass self, CodeTypename interface ) { return class_add_interface(self, interface); }
|
||||
forceinline String to_string ( CodeClass self ) { return class_to_string(self); }
|
||||
forceinline void to_string_def( CodeClass self, String& result ) { return class_to_string_def(self, & result); }
|
||||
forceinline void to_string_fwd( CodeClass self, String& result ) { return class_to_string_fwd(self, & result); }
|
||||
forceinline String to_string ( CodeClass self ) { return class_to_string(self); }
|
||||
forceinline void to_string_def( CodeClass self, String& result ) { return class_to_string_def(self, & result); }
|
||||
forceinline void to_string_fwd( CodeClass self, String& result ) { return class_to_string_fwd(self, & result); }
|
||||
|
||||
forceinline void append (CodeParam params, CodeParam param ) { return params_append(params, param); }
|
||||
forceinline CodeParam get (CodeParam params, s32 idx) { return params_get(params, idx); }
|
||||
forceinline bool has_entries(CodeParam params ) { return params_has_entries(params); }
|
||||
forceinline String to_string (CodeParam params ) { return params_to_string(params); }
|
||||
forceinline void to_string (CodeParam params, String& result ) { return params_to_string_ref(params, & result); }
|
||||
|
||||
forceinline CodeParam begin(CodeParam params) { return begin_CodeParam(params); }
|
||||
forceinline CodeParam end (CodeParam params) { return end_CodeParam(params); }
|
||||
forceinline CodeParam next (CodeParam params, CodeParam entry_iter) { return next_CodeParam(params, entry_iter); }
|
||||
forceinline void append (CodeParams params, CodeParams param ) { return params_append(params, param); }
|
||||
forceinline CodeParams get (CodeParams params, s32 idx) { return params_get(params, idx); }
|
||||
forceinline bool has_entries(CodeParams params ) { return params_has_entries(params); }
|
||||
forceinline String to_string (CodeParams params ) { return params_to_string(params); }
|
||||
forceinline void to_string (CodeParams params, String& result ) { return params_to_string_ref(params, & result); }
|
||||
|
||||
forceinline CodeParams begin(CodeParams params) { return begin_CodeParams(params); }
|
||||
forceinline CodeParams end (CodeParams params) { return end_CodeParams(params); }
|
||||
forceinline CodeParams next (CodeParams params, CodeParams entry_iter) { return next_CodeParams(params, entry_iter); }
|
||||
|
||||
forceinline bool append (CodeSpecifiers specifiers, Specifier spec) { return specifiers_append(specifiers, spec); }
|
||||
forceinline s32 has (CodeSpecifiers specifiers, Specifier spec) { return specifiers_has(specifiers, spec); }
|
||||
|
@ -520,7 +520,7 @@ inline AST_OpCast* CodeOpCast::operator->()
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeParam& CodeParam::operator=( Code other )
|
||||
inline CodeParams& CodeParams::operator=( Code other )
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
@ -531,7 +531,7 @@ inline CodeParam& CodeParam::operator=( Code other )
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline CodeParam::operator bool()
|
||||
inline CodeParams::operator bool()
|
||||
{
|
||||
return ast != nullptr;
|
||||
}
|
||||
@ -906,9 +906,9 @@ forceinline Code::operator CodeOpCast() const
|
||||
return { (AST_OpCast*)ast };
|
||||
}
|
||||
|
||||
forceinline Code::operator CodeParam() const
|
||||
forceinline Code::operator CodeParams() const
|
||||
{
|
||||
return { (AST_Param*)ast };
|
||||
return { (AST_Params*)ast };
|
||||
}
|
||||
|
||||
forceinline Code::operator CodePragma() const
|
||||
|
@ -53,6 +53,8 @@ constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH;
|
||||
constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
|
||||
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
||||
|
||||
extern StrC enum_underlying_sig;
|
||||
|
||||
extern Code access_public;
|
||||
extern Code access_protected;
|
||||
extern Code access_private;
|
||||
@ -67,7 +69,7 @@ extern Code fmt_newline;
|
||||
|
||||
extern CodePragma pragma_once;
|
||||
|
||||
extern CodeParam param_varadic;
|
||||
extern CodeParams param_varadic;
|
||||
|
||||
extern CodePreprocessCond preprocess_else;
|
||||
extern CodePreprocessCond preprocess_endif;
|
||||
|
@ -178,9 +178,9 @@ void class_add_interface( CodeClass self, CodeTypename type )
|
||||
}
|
||||
#pragma endregion CodeClass
|
||||
|
||||
#pragma region CodeParam
|
||||
#pragma region CodeParams
|
||||
inline
|
||||
void params_append( CodeParam appendee, CodeParam other )
|
||||
void params_append( CodeParams appendee, CodeParams other )
|
||||
{
|
||||
GEN_ASSERT(appendee);
|
||||
GEN_ASSERT(other);
|
||||
@ -206,37 +206,37 @@ void params_append( CodeParam appendee, CodeParam other )
|
||||
self->NumEntries++;
|
||||
}
|
||||
inline
|
||||
CodeParam params_get(CodeParam self, s32 idx )
|
||||
CodeParams params_get(CodeParams self, s32 idx )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
CodeParam param = self;
|
||||
CodeParams param = self;
|
||||
do
|
||||
{
|
||||
if ( ++ param != nullptr )
|
||||
return NullCode;
|
||||
|
||||
param = cast(CodeParam, cast(Code, param)->Next);
|
||||
param = cast(CodeParams, cast(Code, param)->Next);
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return param;
|
||||
}
|
||||
forceinline
|
||||
bool params_has_entries(CodeParam self)
|
||||
bool params_has_entries(CodeParams self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
return self->NumEntries > 0;
|
||||
}
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline
|
||||
CodeParam& CodeParam::operator ++()
|
||||
CodeParams& CodeParams::operator ++()
|
||||
{
|
||||
* this = ast->Next;
|
||||
return * this;
|
||||
}
|
||||
#endif
|
||||
forceinline
|
||||
CodeParam begin_CodeParam(CodeParam params)
|
||||
CodeParams begin_CodeParams(CodeParams params)
|
||||
{
|
||||
if ( params != nullptr )
|
||||
return params;
|
||||
@ -244,18 +244,18 @@ CodeParam begin_CodeParam(CodeParam params)
|
||||
return NullCode;
|
||||
}
|
||||
forceinline
|
||||
CodeParam end_CodeParam(CodeParam params)
|
||||
CodeParams end_CodeParams(CodeParams params)
|
||||
{
|
||||
// return { (AST_Param*) rcast( AST*, ast)->Last };
|
||||
// return { (AST_Params*) rcast( AST*, ast)->Last };
|
||||
return NullCode;
|
||||
}
|
||||
forceinline
|
||||
CodeParam next_CodeParam(CodeParam params, CodeParam param_iter)
|
||||
CodeParams next_CodeParams(CodeParams params, CodeParams param_iter)
|
||||
{
|
||||
GEN_ASSERT(param_iter);
|
||||
return param_iter->Next;
|
||||
}
|
||||
#pragma endregion CodeParam
|
||||
#pragma endregion CodeParams
|
||||
|
||||
#pragma region CodeSpecifiers
|
||||
inline
|
||||
|
@ -131,7 +131,7 @@ void define_constants()
|
||||
pragma_once->Content = pragma_once->Name;
|
||||
code_set_global((Code)pragma_once);
|
||||
|
||||
param_varadic = (CodeParam) make_code();
|
||||
param_varadic = (CodeParams) make_code();
|
||||
param_varadic->Type = CT_Parameters;
|
||||
param_varadic->Name = get_cached_string( txt("...") );
|
||||
param_varadic->ValueType = t_empty;
|
||||
@ -183,7 +183,6 @@ void define_constants()
|
||||
#endif
|
||||
# undef def_constant_code_type
|
||||
|
||||
|
||||
spec_const = def_specifier( Spec_Const); code_set_global( cast(Code, spec_const ));
|
||||
spec_consteval = def_specifier( Spec_Consteval); code_set_global( cast(Code, spec_consteval ));;
|
||||
spec_constexpr = def_specifier( Spec_Constexpr); code_set_global( cast(Code, spec_constexpr ));;
|
||||
@ -212,9 +211,10 @@ void define_constants()
|
||||
spec_local_persist = def_specifiers( 1, Spec_Local_Persist );
|
||||
code_set_global(cast(Code, spec_local_persist));
|
||||
|
||||
# pragma push_macro("enum_underlying")
|
||||
array_append(PreprocessorDefines, txt("enum_underlying("));
|
||||
# pragma pop_macro("enum_underlying")
|
||||
if (enum_underlying_sig.Len == 0) {
|
||||
enum_underlying_sig = txt("enum_underlying(");
|
||||
}
|
||||
array_append(PreprocessorDefines, enum_underlying_sig);
|
||||
|
||||
# undef def_constant_spec
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ struct Opts_def_struct {
|
||||
CodeClass def_class( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_constructor {
|
||||
CodeParam params;
|
||||
CodeParams params;
|
||||
Code initializer_list;
|
||||
Code body;
|
||||
};
|
||||
@ -86,6 +86,7 @@ struct Opts_def_enum {
|
||||
EnumT specifier;
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
Code type_macro;
|
||||
};
|
||||
CodeEnum def_enum( StrC name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
||||
|
||||
@ -94,7 +95,7 @@ CodeExtern def_extern_link( StrC name, CodeBody body );
|
||||
CodeFriend def_friend ( Code symbol );
|
||||
|
||||
struct Opts_def_function {
|
||||
CodeParam params;
|
||||
CodeParams params;
|
||||
CodeTypename ret_type;
|
||||
CodeBody body;
|
||||
CodeSpecifiers specs;
|
||||
@ -111,7 +112,7 @@ CodeModule def_module ( StrC name, Opts_def_module opts GEN
|
||||
CodeNS def_namespace( StrC name, CodeBody body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_operator {
|
||||
CodeParam params;
|
||||
CodeParams params;
|
||||
CodeTypename ret_type;
|
||||
CodeBody body;
|
||||
CodeSpecifiers specifiers;
|
||||
@ -127,7 +128,7 @@ struct Opts_def_operator_cast {
|
||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_param { Code value; };
|
||||
CodeParam def_param ( CodeTypename type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
||||
CodeParams def_param ( CodeTypename type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
||||
CodePragma def_pragma( StrC directive );
|
||||
|
||||
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
|
||||
@ -137,7 +138,7 @@ CodeSpecifiers def_specifier( Specifier specifier );
|
||||
CodeStruct def_struct( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_template { ModuleFlag mflags; };
|
||||
CodeTemplate def_template( CodeParam params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
|
||||
CodeTemplate def_template( CodeParams params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_type {
|
||||
ETypenameTag type_tag;
|
||||
@ -196,8 +197,8 @@ CodeBody def_global_body ( s32 num, ... );
|
||||
CodeBody def_global_body ( s32 num, Code* codes );
|
||||
CodeBody def_namespace_body ( s32 num, ... );
|
||||
CodeBody def_namespace_body ( s32 num, Code* codes );
|
||||
CodeParam def_params ( s32 num, ... );
|
||||
CodeParam def_params ( s32 num, CodeParam* params );
|
||||
CodeParams def_params ( s32 num, ... );
|
||||
CodeParams def_params ( s32 num, CodeParams* params );
|
||||
CodeSpecifiers def_specifiers ( s32 num, ... );
|
||||
CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
|
||||
CodeBody def_struct_body ( s32 num, ... );
|
||||
|
@ -13,7 +13,7 @@ enum OpValidateResult : u32
|
||||
};
|
||||
|
||||
internal neverinline
|
||||
OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTypename ret_type, CodeSpecifiers specifier )
|
||||
OpValidateResult operator__validate( Operator op, CodeParams params_code, CodeTypename ret_type, CodeSpecifiers specifier )
|
||||
{
|
||||
if ( op == Op_Invalid )
|
||||
{
|
||||
@ -391,7 +391,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
|
||||
}
|
||||
|
||||
#define null_check( Context_, Code_ ) \
|
||||
if ( Code_ != nullptr ) \
|
||||
if ( Code_ == nullptr ) \
|
||||
{ \
|
||||
log_failure( "gen::" stringize(Context_) ": " stringize(Code_) " provided is null" ); \
|
||||
return InvalidCode; \
|
||||
@ -497,7 +497,7 @@ CodeComment def_comment( StrC content )
|
||||
|
||||
CodeConstructor def_constructor( Opts_def_constructor p )
|
||||
{
|
||||
CodeParam params = p.params;
|
||||
CodeParams params = p.params;
|
||||
Code initializer_list = p.initializer_list;
|
||||
Code body = p.body;
|
||||
|
||||
@ -700,6 +700,7 @@ CodeEnum def_enum( StrC name, Opts_def_enum p )
|
||||
EnumT specifier = p.specifier;
|
||||
CodeAttributes attributes = p.attributes;
|
||||
ModuleFlag mflags = p.mflags;
|
||||
Code type_macro = p.type_macro;
|
||||
|
||||
name_check( def_enum, name );
|
||||
|
||||
@ -751,6 +752,10 @@ CodeEnum def_enum( StrC name, Opts_def_enum p )
|
||||
{
|
||||
result->UnderlyingType = type;
|
||||
}
|
||||
else if ( type_macro )
|
||||
{
|
||||
result->UnderlyingTypeMacro = type_macro;
|
||||
}
|
||||
else if ( result->Type != CT_Enum_Class_Fwd && result->Type != CT_Enum_Fwd )
|
||||
{
|
||||
log_failure( "gen::def_enum: enum forward declaration must have an underlying type" );
|
||||
@ -829,7 +834,7 @@ CodeFriend def_friend( Code declaration )
|
||||
|
||||
CodeFn def_function( StrC name, Opts_def_function p )
|
||||
{
|
||||
CodeParam params = p.params;
|
||||
CodeParams params = p.params;
|
||||
CodeTypename ret_type = p.ret_type;
|
||||
CodeBody body = p.body;
|
||||
CodeSpecifiers specifiers = p.specs;
|
||||
@ -969,7 +974,7 @@ CodeNS def_namespace( StrC name, CodeBody body, Opts_def_namespace p )
|
||||
|
||||
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
|
||||
{
|
||||
CodeParam params_code = p.params;
|
||||
CodeParams params_code = p.params;
|
||||
CodeTypename ret_type = p.ret_type;
|
||||
CodeBody body = p.body;
|
||||
CodeSpecifiers specifiers = p.specifiers;
|
||||
@ -1093,7 +1098,7 @@ CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeParam def_param( CodeTypename type, StrC name, Opts_def_param p )
|
||||
CodeParams def_param( CodeTypename type, StrC name, Opts_def_param p )
|
||||
{
|
||||
name_check( def_param, name );
|
||||
null_check( def_param, type );
|
||||
@ -1110,8 +1115,8 @@ CodeParam def_param( CodeTypename type, StrC name, Opts_def_param p )
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
CodeParam
|
||||
result = (CodeParam) make_code();
|
||||
CodeParams
|
||||
result = (CodeParams) make_code();
|
||||
result->Type = CT_Parameters;
|
||||
result->Name = get_cached_string( name );
|
||||
|
||||
@ -1247,7 +1252,7 @@ CodeStruct def_struct( StrC name, Opts_def_struct p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeTemplate def_template( CodeParam params, Code declaration, Opts_def_template p )
|
||||
CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_template p )
|
||||
{
|
||||
null_check( def_template, declaration );
|
||||
|
||||
@ -2064,7 +2069,7 @@ CodeBody def_namespace_body( s32 num, Code* codes )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeParam def_params( s32 num, ... )
|
||||
CodeParams def_params( s32 num, ... )
|
||||
{
|
||||
def_body_start( def_params );
|
||||
|
||||
@ -2072,7 +2077,7 @@ CodeParam def_params( s32 num, ... )
|
||||
va_start(va, num);
|
||||
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
CodeParam param = pcast( CodeParam, pod );
|
||||
CodeParams param = pcast( CodeParams, pod );
|
||||
|
||||
null_check( def_params, param );
|
||||
|
||||
@ -2082,12 +2087,12 @@ CodeParam def_params( s32 num, ... )
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
CodeParam result = (CodeParam) code_duplicate(param);
|
||||
CodeParams result = (CodeParams) code_duplicate(param);
|
||||
|
||||
while ( -- num )
|
||||
{
|
||||
pod = va_arg(va, Code_POD);
|
||||
param = pcast( CodeParam, pod );
|
||||
param = pcast( CodeParams, pod );
|
||||
|
||||
if ( param->Type != CT_Parameters )
|
||||
{
|
||||
@ -2102,7 +2107,7 @@ CodeParam def_params( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeParam def_params( s32 num, CodeParam* codes )
|
||||
CodeParams def_params( s32 num, CodeParams* codes )
|
||||
{
|
||||
def_body_code_array_start( def_params );
|
||||
|
||||
@ -2119,11 +2124,11 @@ CodeParam def_params( s32 num, CodeParam* codes )
|
||||
return InvalidCode; \
|
||||
}
|
||||
|
||||
CodeParam current = (CodeParam)code_duplicate(* codes);
|
||||
CodeParams current = (CodeParams)code_duplicate(* codes);
|
||||
check_current(current);
|
||||
|
||||
CodeParam
|
||||
result = (CodeParam) make_code();
|
||||
CodeParams
|
||||
result = (CodeParams) make_code();
|
||||
result->Name = current->Name;
|
||||
result->Type = current->Type;
|
||||
result->ValueType = current->ValueType;
|
||||
|
@ -663,6 +663,10 @@ TokArray lex( StrC content )
|
||||
|
||||
switch ( current )
|
||||
{
|
||||
if (array_back(Lexer_Tokens)->Length > 100 ) {
|
||||
__debugbreak();
|
||||
}
|
||||
|
||||
case '#':
|
||||
{
|
||||
s32 result = lex_preprocessor_directive( ctx );
|
||||
|
@ -225,7 +225,7 @@ internal CodeInclude parse_include ();
|
||||
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 ();
|
||||
internal CodeParam parse_params ( bool use_template_capture );
|
||||
internal CodeParams parse_params ( bool use_template_capture );
|
||||
internal CodePreprocessCond parse_preprocess_cond ();
|
||||
internal Code parse_simple_preprocess ( TokType which, bool dont_consume_braces );
|
||||
internal Code parse_static_assert ();
|
||||
@ -797,11 +797,10 @@ Code parse_class_struct( TokType which, bool inplace_def )
|
||||
}
|
||||
|
||||
if ( which == Tok_Decl_Class )
|
||||
result = cast(Code, def_class( tok_to_str(name), def_assign( body, parent, access, attributes, nullptr, 0, mflags ) ));
|
||||
result = cast(Code, def_class( tok_to_str(name), def_assign( body, parent, access, attributes, interfaces, scast(s32, array_num(interfaces)), mflags ) ));
|
||||
|
||||
else
|
||||
result = cast(Code, def_struct( tok_to_str(name), def_assign( body, (CodeTypename)parent, access, attributes, nullptr, 0, mflags ) ));
|
||||
|
||||
result = cast(Code, def_struct( tok_to_str(name), def_assign( body, (CodeTypename)parent, access, attributes, interfaces, scast(s32, array_num(interfaces)), mflags ) ));
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = cast(Code, inline_cmt);
|
||||
@ -1479,7 +1478,7 @@ CodeFn parse_function_after_name(
|
||||
)
|
||||
{
|
||||
push_scope();
|
||||
CodeParam params = parse_params(parser_use_parenthesis);
|
||||
CodeParams params = parse_params(parser_use_parenthesis);
|
||||
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Parameters> )
|
||||
|
||||
// TODO(Ed), Review old comment : These have to be kept separate from the return type's specifiers.
|
||||
@ -2516,7 +2515,7 @@ CodeOperator parse_operator_after_ret_type(
|
||||
// <ExportFlag> <Attributes> <Specifiers> <ReturnType> <Qualifier::...> operator <Op>
|
||||
|
||||
// Parse Params
|
||||
CodeParam params = parse_params(parser_use_parenthesis);
|
||||
CodeParams params = parse_params(parser_use_parenthesis);
|
||||
// <ExportFlag> <Attributes> <Specifiers> <ReturnType> <Qualifier::...> operator <Op> ( <Parameters> )
|
||||
|
||||
if ( params == nullptr && op == Op_Multiply )
|
||||
@ -2694,7 +2693,7 @@ CodePragma parse_pragma()
|
||||
}
|
||||
|
||||
internal inline
|
||||
CodeParam parse_params( bool use_template_capture )
|
||||
CodeParams parse_params( bool use_template_capture )
|
||||
{
|
||||
push_scope();
|
||||
|
||||
@ -2823,7 +2822,7 @@ CodeParam parse_params( bool use_template_capture )
|
||||
}
|
||||
}
|
||||
|
||||
CodeParam result = ( CodeParam )make_code();
|
||||
CodeParams result = ( CodeParams )make_code();
|
||||
result->Type = CT_Parameters;
|
||||
|
||||
result->Macro = macro;
|
||||
@ -2940,7 +2939,7 @@ CodeParam parse_params( bool use_template_capture )
|
||||
// ( <Macro> <ValueType> <Name> = <Expression>, <Macro> <ValueType> <Name> = <Expression>, ..
|
||||
}
|
||||
|
||||
CodeParam param = ( CodeParam )make_code();
|
||||
CodeParams param = ( CodeParams )make_code();
|
||||
param->Type = CT_Parameters;
|
||||
|
||||
param->Macro = macro;
|
||||
@ -3372,7 +3371,7 @@ CodeVar parse_variable_after_name(
|
||||
result->NextVar->Parent = cast(Code, result);
|
||||
}
|
||||
|
||||
result->VarConstructorInit = using_constructor_initializer;
|
||||
result->VarParenthesizedInit = using_constructor_initializer;
|
||||
|
||||
parser_pop(& Context);
|
||||
return result;
|
||||
@ -3476,7 +3475,7 @@ CodeConstructor parser_parse_constructor( CodeSpecifiers specifiers )
|
||||
push_scope();
|
||||
|
||||
Token identifier = parse_identifier(nullptr);
|
||||
CodeParam params = parse_params(parser_not_from_template);
|
||||
CodeParams params = parse_params(parser_not_from_template);
|
||||
// <Name> ( <Parameters> )
|
||||
|
||||
Code initializer_list = NullCode;
|
||||
@ -3731,8 +3730,7 @@ CodeEnum parser_parse_enum( bool inplace_def )
|
||||
else if ( currtok.Type == Tok_Preprocess_Macro )
|
||||
{
|
||||
// We'll support the enum_underlying macro
|
||||
StrC sig = txt("enum_underlying(");
|
||||
if ( strc_contains( tok_to_str(currtok), sig) )
|
||||
if ( strc_contains( tok_to_str(currtok), enum_underlying_sig) )
|
||||
{
|
||||
use_macro_underlying = true;
|
||||
underlying_macro = parse_simple_preprocess( Tok_Preprocess_Macro, parser_dont_consume_braces );
|
||||
@ -4040,7 +4038,7 @@ CodeFriend parser_parse_friend()
|
||||
function = parse_function_after_name( ModuleFlag_None, NullCode, specifiers, type, name );
|
||||
|
||||
// Parameter list
|
||||
// CodeParam params = parse_params();
|
||||
// CodeParams params = parse_params();
|
||||
// friend <ReturnType> <Name> ( <Parameters> )
|
||||
|
||||
// function = make_code();
|
||||
@ -4410,7 +4408,7 @@ CodeTemplate parser_parse_template()
|
||||
eat( Tok_Decl_Template );
|
||||
// <export> template
|
||||
|
||||
CodeParam params = parse_params( UseTemplateCapture );
|
||||
CodeParams params = parse_params( UseTemplateCapture );
|
||||
if ( cast(Code, params) == Code_Invalid )
|
||||
{
|
||||
parser_pop(& Context);
|
||||
@ -4775,10 +4773,10 @@ else if ( currtok.Type == Tok_DeclType )
|
||||
|
||||
// For function type signatures
|
||||
CodeTypename return_type = NullCode;
|
||||
CodeParam params = NullCode;
|
||||
CodeParams params = NullCode;
|
||||
|
||||
#ifdef GEN_USE_NEW_TYPENAME_PARSING
|
||||
CodeParam params_nested = NullCode;
|
||||
CodeParams params_nested = NullCode;
|
||||
#endif
|
||||
|
||||
bool is_function_typename = false;
|
||||
@ -5583,6 +5581,12 @@ CodeVar parser_parse_variable()
|
||||
}
|
||||
|
||||
|
||||
internal
|
||||
CodeTypename parser_parse_type_alt( bool from_template, bool* typedef_is_functon )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GEN_NS_PARSER_END
|
||||
|
||||
#ifdef CHECK_WAS_DEFINED
|
||||
|
@ -28,6 +28,8 @@ global AllocatorInfo Allocator_TypeTable = {0};
|
||||
|
||||
#pragma region Constants
|
||||
|
||||
global StrC enum_underlying_sig;
|
||||
|
||||
global Code access_public;
|
||||
global Code access_protected;
|
||||
global Code access_private;
|
||||
@ -40,7 +42,7 @@ global Code module_private_fragment;
|
||||
|
||||
global Code fmt_newline;
|
||||
|
||||
global CodeParam param_varadic;
|
||||
global CodeParams param_varadic;
|
||||
|
||||
global CodePragma pragma_once;
|
||||
|
||||
|
@ -440,8 +440,6 @@ bool array_set_capacity(Array<Type>* array, usize new_capacity)
|
||||
|
||||
#pragma endregion Array
|
||||
|
||||
// TODO(Ed) : This thing needs ALOT of work.
|
||||
|
||||
#pragma region HashTable
|
||||
#define HashTable(Type) HashTable<Type>
|
||||
|
||||
|
@ -284,121 +284,4 @@
|
||||
# define GEN_OPITMIZE_MAPPINGS_END
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
// ____ _ ______ _ _ ____ _ __ _
|
||||
// / ___} (_) | ____} | | (_) / __ \ | | | |(_)
|
||||
// | | ___ ___ _ __ ___ _ __ _ ___ | |__ _ _ _ __ ___| |_ _ ___ _ __ | | | |_ _____ _ __ | | ___ __ _ __| | _ _ __ __ _
|
||||
// | |{__ |/ _ \ '_ \ / _ \ '__} |/ __| | __} | | | '_ \ / __} __} |/ _ \| '_ \ | | | \ \ / / _ \ '_ \| |/ _ \ / _` |/ _` || | '_ \ / _` |
|
||||
// | |__j | __/ | | | __/ | | | (__ | | | |_| | | | | (__| l_| | (_) | | | | | l__| |\ V / __/ | | | | (_) | (_| | (_| || | | | | (_| |
|
||||
// \____/ \___}_l l_l\___}_l l_l\___| l_l \__,_l_l l_l\___}\__}_l\___/l_l l_l \____/ \_/ \___}_l l_l_l\___/ \__,_l\__,_l|_|_| |_|\__, |
|
||||
// This implemnents macros for utilizing "The Naive Extendible _Generic Macro" explained in: __| |
|
||||
// https://github.com/JacksonAllan/CC/blob/main/articles/Better_C_Generics_Part_1_The_Extendible_Generic.md {___/
|
||||
// Since gencpp is used to generate the c-library, it was choosen over the more novel implementations to keep the macros as easy to understand and unobfuscated as possible.
|
||||
|
||||
#define GEN_COMMA_OPERATOR , // The comma operator is used by preprocessor macros to delimit arguments, so we have to represent it via a macro to prevent parsing incorrectly.
|
||||
|
||||
// Helper macros for argument selection
|
||||
#define GEN_SELECT_ARG_1( _1, ... ) _1 // <-- Of all th args passed pick _1.
|
||||
#define GEN_SELECT_ARG_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2.
|
||||
#define GEN_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc..
|
||||
|
||||
#define GEN_GENERIC_SEL_ENTRY_TYPE GEN_SELECT_ARG_1 // Use the arg expansion macro to select arg 1 which should have the type.
|
||||
#define GEN_GENERIC_SEL_ENTRY_FUNCTION GEN_SELECT_ARG_2 // Use the arg expansion macro to select arg 2 which should have the function.
|
||||
#define GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER GEN_SELECT_ARG_3 // Use the arg expansion macro to select arg 3 which should have the comma delimiter ','.
|
||||
|
||||
#define GEN_RESOLVED_FUNCTION_CALL // Just used to indicate where the call "occurs"
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
// GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( macro ) includes a _Generic slot only if the specified macro is defined (as type, function_name).
|
||||
// It takes advantage of the fact that if the macro is defined, then the expanded text will contain a comma.
|
||||
// Expands to ',' if it can find (type): (function) <comma_operator: ',' >
|
||||
// Where GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER is specifically looking for that <comma> ,
|
||||
#define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ) GEN_COMMA_OPERATOR, , )
|
||||
// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma
|
||||
// The slot won't exist if that comma is not found. |
|
||||
|
||||
// For the occastion where an expression didn't resolve to a selection option the "default: <value>" wilbe set to:
|
||||
typedef struct GENCPP_NO_RESOLVED_GENERIC_SELECTION GENCPP_NO_RESOLVED_GENERIC_SELECTION;
|
||||
struct GENCPP_NO_RESOLVED_GENERIC_SELECTION {
|
||||
void* _THE_VOID_SLOT_;
|
||||
};
|
||||
GENCPP_NO_RESOLVED_GENERIC_SELECTION const gen_generic_selection_fail = {0};
|
||||
// Which will provide the message: error: called object type 'struct NO_RESOLVED_GENERIC_SELECTION' is not a function or function pointer
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Below are generated on demand for an overlaod depdendent on a type:
|
||||
// -----------------------------------------------------------------------------------------------------#define GEN_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( k
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \
|
||||
(selector_arg), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg )
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Then each definiton of a function has an associated define:
|
||||
// #define <function_id_macro> GEN_GENERIC_FUNCTION_ARG_SIGNATURE( <function_id>, <arguments> )
|
||||
#define GEN_GENERIC_FUNCTION_ARG_SIGNATURE( name_of_function, type_delimiter ) type_delimiter name_of_function
|
||||
|
||||
// Then somehwere later on
|
||||
// <etc> <return_type> <function_id> ( <arguments> ) { <implementation> }
|
||||
|
||||
// Concrete example:
|
||||
|
||||
// To add support for long:
|
||||
#define GEN_EXAMPLE_HASH__ARGS_SIG_1 GEN_GENERIC_FUNCTION_ARG_SIGNATURE( hash__P_long, long long )
|
||||
size_t gen_example_hash__P_long( long val ) { return val * 2654435761ull; }
|
||||
|
||||
// To add support for long long:
|
||||
#define GEN_EXAMPLE_HASH__ARGS_SIG_2 GEN_GENERIC_FUNCTION_ARG_SIGNATURE( hash__P_long_long, long long )
|
||||
size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761ull; }
|
||||
|
||||
// If using an Editor with support for syntax hightlighting macros: HASH__ARGS_SIG_1 and HASH_ARGS_SIG_2 should show color highlighting indicating the slot is enabled,
|
||||
// or, "defined" for usage during the compilation pass that handles the _Generic instrinsic.
|
||||
#define gen_hash_example( function_arguments ) _Generic( \
|
||||
(function_arguments), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_2 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_3 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_4 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_5 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_6 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_7 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_8 ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( function_arguments )
|
||||
|
||||
// Additional Variations:
|
||||
|
||||
// If the function takes more than one argument the following is used:
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE_VARADIC( selector_arg, ... ) _Generic( \
|
||||
(selector_arg), \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_2 ) \
|
||||
/* ... */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(FunctionID__ARGS_SIG_N ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg, __VA_ARG__ )
|
||||
|
||||
// If the function does not take the arugment as a parameter:
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( selector_arg ) _Generic( \
|
||||
( GEN_TYPE_TO_EXP(selector_arg) ), \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_2 ) \
|
||||
/* ... */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(FunctionID__ARGS_SIG_N ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL()
|
||||
|
||||
// Used to keep the _Generic keyword happy as bare types are not considered "expressions"
|
||||
#define GEN_TYPE_TO_EXP(type) (* (type*)NULL)
|
||||
|
||||
// typedef void* GEN_GenericExampleType;
|
||||
// GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( GEN_GenericExampleType );
|
||||
|
||||
// END OF ------------------------ _Generic function overloading ----------------------------------------- END OF
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros
|
||||
|
@ -1111,4 +1111,6 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
||||
return output;
|
||||
}
|
||||
|
||||
#undef _adt_fprintf
|
||||
|
||||
#pragma endregion CSV
|
||||
|
@ -29,12 +29,6 @@
|
||||
# ifndef GEN_SYSTEM_MACOS
|
||||
# define GEN_SYSTEM_MACOS 1
|
||||
# endif
|
||||
# include <TargetConditionals.h>
|
||||
# if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
|
||||
# ifndef GEN_SYSTEM_IOS
|
||||
# define GEN_SYSTEM_IOS 1
|
||||
# endif
|
||||
# endif
|
||||
#elif defined( __unix__ )
|
||||
# ifndef GEN_SYSTEM_UNIX
|
||||
# define GEN_SYSTEM_UNIX 1
|
||||
|
@ -17,7 +17,7 @@
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "components/types.hpp"
|
||||
#include "components/gen/ecode.hpp"
|
||||
#include "components/gen/ecodetypes.hpp"
|
||||
#include "components/gen/eoperator.hpp"
|
||||
#include "components/gen/especifier.hpp"
|
||||
|
||||
|
@ -9,8 +9,10 @@ using namespace gen;
|
||||
|
||||
CodeBody gen_ecode( char const* path, bool use_c_definition = false )
|
||||
{
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns(GlobalAllocator, path );
|
||||
FixedArena_32KB scratch; fixed_arena_init(& scratch);
|
||||
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_keyword_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
@ -91,10 +93,12 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false )
|
||||
|
||||
CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
||||
{
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns(GlobalAllocator, path);
|
||||
FixedArena_16KB scratch; fixed_arena_init(& scratch);
|
||||
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, 32 );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, 32 );
|
||||
|
||||
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++) {
|
||||
char const* enum_str = csv_enum.Col_1[idx].string;
|
||||
@ -175,10 +179,12 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
||||
|
||||
CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
||||
{
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns(GlobalAllocator, path);
|
||||
FixedArena_16KB scratch; fixed_arena_init(& scratch);
|
||||
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
|
||||
String enum_entries = string_make_reserve( scratch_info, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( scratch_info, kilobytes(1) );
|
||||
|
||||
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++)
|
||||
{
|
||||
@ -314,31 +320,29 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
||||
|
||||
CodeBody gen_etoktype( char const* etok_path, char const* attr_path, bool use_c_definition = false )
|
||||
{
|
||||
char scratch_mem[kilobytes(16)];
|
||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
AllocatorInfo scratch_info = arena_allocator_info(& scratch);
|
||||
FixedArena_64KB scratch; fixed_arena_init(& scratch);
|
||||
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||
|
||||
FileContents enum_content = file_read_contents( scratch_info, file_zero_terminate, etok_path );
|
||||
|
||||
CSV_Object csv_enum_nodes;
|
||||
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), GlobalAllocator, false );
|
||||
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), scratch_info, false );
|
||||
|
||||
FileContents attrib_content = file_read_contents( scratch_info, file_zero_terminate, attr_path );
|
||||
|
||||
CSV_Object csv_attr_nodes;
|
||||
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), GlobalAllocator, false );
|
||||
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), scratch_info, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_enum_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> enum_str_strs = csv_enum_nodes.nodes[1].nodes;
|
||||
Array<ADT_Node> attribute_strs = csv_attr_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_attributes = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_define_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String enum_entries = string_make_reserve( scratch_info, kilobytes(2) );
|
||||
String to_str_entries = string_make_reserve( scratch_info, kilobytes(4) );
|
||||
String attribute_entries = string_make_reserve( scratch_info, kilobytes(2) );
|
||||
String to_str_attributes = string_make_reserve( scratch_info, kilobytes(4) );
|
||||
String attribute_define_entries = string_make_reserve( scratch_info, kilobytes(4) );
|
||||
|
||||
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
||||
{
|
||||
@ -532,7 +536,7 @@ CodeBody gen_ast_inlines()
|
||||
CodeBody impl_code_ns = parse_global_body( token_fmt( "typename", StrC name(CodeNS), code_impl_tmpl ));
|
||||
CodeBody impl_code_op = parse_global_body( token_fmt( "typename", StrC name(CodeOperator), code_impl_tmpl ));
|
||||
CodeBody impl_code_opcast = parse_global_body( token_fmt( "typename", StrC name(CodeOpCast), code_impl_tmpl ));
|
||||
CodeBody impl_code_param = parse_global_body( token_fmt( "typename", StrC name(CodeParam), code_impl_tmpl ));
|
||||
CodeBody impl_code_params = parse_global_body( token_fmt( "typename", StrC name(CodeParams), code_impl_tmpl ));
|
||||
CodeBody impl_code_pragma = parse_global_body( token_fmt( "typename", StrC name(CodePragma), code_impl_tmpl ));
|
||||
CodeBody impl_code_precond = parse_global_body( token_fmt( "typename", StrC name(CodePreprocessCond), code_impl_tmpl ));
|
||||
CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", StrC name(CodeSpecifiers), code_impl_tmpl ));
|
||||
@ -595,7 +599,7 @@ CodeBody gen_ast_inlines()
|
||||
CodeBody impl_cast_ns = parse_global_body( token_fmt( "typename", StrC name(NS), cast_tmpl ));
|
||||
CodeBody impl_cast_op = parse_global_body( token_fmt( "typename", StrC name(Operator), cast_tmpl ));
|
||||
CodeBody impl_cast_opcast = parse_global_body( token_fmt( "typename", StrC name(OpCast), cast_tmpl ));
|
||||
CodeBody impl_cast_param = parse_global_body( token_fmt( "typename", StrC name(Param), cast_tmpl ));
|
||||
CodeBody impl_cast_params = parse_global_body( token_fmt( "typename", StrC name(Params), cast_tmpl ));
|
||||
CodeBody impl_cast_pragma = parse_global_body( token_fmt( "typename", StrC name(Pragma), cast_tmpl ));
|
||||
CodeBody impl_cast_precond = parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), cast_tmpl ));
|
||||
CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", StrC name(Specifiers), cast_tmpl ));
|
||||
@ -628,7 +632,7 @@ CodeBody gen_ast_inlines()
|
||||
impl_code_ns,
|
||||
impl_code_op,
|
||||
impl_code_opcast,
|
||||
impl_code_param,
|
||||
impl_code_params,
|
||||
impl_code_pragma,
|
||||
impl_code_precond,
|
||||
impl_code_specs,
|
||||
@ -662,7 +666,7 @@ CodeBody gen_ast_inlines()
|
||||
impl_cast_ns,
|
||||
impl_cast_op,
|
||||
impl_cast_opcast,
|
||||
impl_cast_param,
|
||||
impl_cast_params,
|
||||
impl_cast_pragma,
|
||||
impl_cast_precond,
|
||||
impl_cast_specs,
|
||||
|
@ -22,7 +22,6 @@ void clang_format_file( char const* path, char const* style_path )
|
||||
{
|
||||
GEN_ASSERT_NOT_NULL(path);
|
||||
String resolved_path = string_make_strc(GlobalAllocator, to_strc_from_c_str(path));
|
||||
|
||||
String style_arg;
|
||||
if (style_path) {
|
||||
style_arg = string_make_strc(GlobalAllocator, txt("-style=file:"));
|
||||
@ -38,10 +37,7 @@ void clang_format_file( char const* path, char const* style_path )
|
||||
string_append_strc( & command, cf_verbose );
|
||||
string_append_string( & command, style_arg );
|
||||
string_append_string( & command, resolved_path );
|
||||
|
||||
log_fmt("\tRunning clang-format:\n");
|
||||
system( command );
|
||||
log_fmt("\tclang-format finished formatting.\n");
|
||||
}
|
||||
|
||||
// Will refactor a file with the given script at the provided path.
|
||||
@ -53,16 +49,12 @@ void refactor_file( char const* path, char const* refactor_script )
|
||||
GEN_ASSERT_NOT_NULL(refactor_script);
|
||||
|
||||
String command = string_make_strc(GlobalAllocator, txt("refactor "));
|
||||
string_append_strc( & command, txt("-debug ") );
|
||||
// string_append_strc( & command, txt("-debug ") );
|
||||
string_append_strc( & command, txt("-num=1 ") );
|
||||
string_append_fmt( & command, "-src=%s ", path );
|
||||
string_append_fmt( & command,"-spec=%s ", refactor_script );
|
||||
|
||||
log_fmt("\tBeginning refactor:\n");
|
||||
system(command);
|
||||
log_fmt("\nRefactoring complete.\n");
|
||||
|
||||
#undef refactor
|
||||
log_fmt("\n");
|
||||
}
|
||||
|
||||
// Does either of the above or both to the provided code.
|
||||
@ -71,7 +63,7 @@ Code code_refactor_and_format( Code code, char const* scratch_path, char const*
|
||||
{
|
||||
GEN_ASSERT(code);
|
||||
GEN_ASSERT_NOT_NULL(scratch_path);
|
||||
Builder scratch_file = builder_open("gen/scratch.hpp");
|
||||
Builder scratch_file = builder_open( scratch_path );
|
||||
builder_print( & scratch_file, code);
|
||||
builder_write(& scratch_file);
|
||||
|
||||
@ -83,6 +75,6 @@ Code code_refactor_and_format( Code code, char const* scratch_path, char const*
|
||||
}
|
||||
|
||||
Code result = scan_file( scratch_path );
|
||||
remove("gen/scratch.hpp");
|
||||
::remove(scratch_path);
|
||||
return result;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#if GEN_TIME
|
||||
// This undefines the macros used by the gen library but are not necessary for the user.
|
||||
// This undefines the macros used by the gen library
|
||||
#undef GEN_TIME
|
||||
|
||||
#undef GEN_ARCH_64_BIT
|
||||
#undef GEN_ARCH_32_BIT
|
||||
@ -18,21 +18,116 @@
|
||||
|
||||
#undef GEN_COMPILER_CLANG
|
||||
#undef GEN_COMPILER_GCC
|
||||
#undef GEN_COMPILER_MINGW
|
||||
#undef GEN_COMPILER_MSVC
|
||||
|
||||
#undef forceinline
|
||||
#undef neverinline
|
||||
#undef GEN_HAS_ATTRIBUTE
|
||||
|
||||
#undef GEN_COMPILER_C
|
||||
#undef GEN_COMPILER_CPP
|
||||
|
||||
#undef GEN_DONT_USE_NAMESPACE
|
||||
#undef GEN_NS_PARSER_BEGIN
|
||||
#undef GEN_NS_PARSER_END
|
||||
#undef GEN_USING_NS_PARSER
|
||||
#undef GEN_NS_PARSER
|
||||
#undef GEN_NS
|
||||
#undef GEN_NS_BEGIN
|
||||
#undef GEN_NS_END
|
||||
|
||||
#undef GEN_C_LIKE_CPP
|
||||
|
||||
#undef global
|
||||
#undef internal
|
||||
#undef local_persist
|
||||
|
||||
#undef bit
|
||||
#undef bitfield_is_equal
|
||||
|
||||
#undef cast
|
||||
|
||||
#undef ccast
|
||||
#undef scast
|
||||
#undef rcast
|
||||
#undef pcast
|
||||
|
||||
#undef stringize
|
||||
#undef do_once
|
||||
#undef do_once_start
|
||||
#undef do_once_end
|
||||
#undef labeled_scope_start
|
||||
#undef labeled_scope_end
|
||||
#undef compiler_decorated_func_name
|
||||
#undef num_args_impl
|
||||
#undef num_args
|
||||
#undef clamp
|
||||
#undef count_of
|
||||
#undef is_between
|
||||
#undef size_of
|
||||
#undef max
|
||||
#undef min
|
||||
#undef offset_of
|
||||
#undef forceinline
|
||||
#undef neverinline
|
||||
#undef static_assert
|
||||
#undef thread_local
|
||||
#undef typeof
|
||||
|
||||
#undef GEN_API_C_BEGIN
|
||||
#undef GEN_API_C_END
|
||||
|
||||
#undef enum_underlying
|
||||
#undef nullptr
|
||||
#undef GEN_PARAM_DEFAULT
|
||||
#undef struct_init
|
||||
|
||||
#undef GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||
#undef GEN_OPITMIZE_MAPPINGS_END
|
||||
|
||||
#undef GEN_U8_MIN
|
||||
#undef GEN_U8_MAX
|
||||
#undef GEN_I8_MIN
|
||||
#undef GEN_I8_MAX
|
||||
#undef GEN_U16_MIN
|
||||
#undef GEN_U16_MAX
|
||||
#undef GEN_I16_MIN
|
||||
#undef GEN_I16_MAX
|
||||
#undef GEN_U32_MIN
|
||||
#undef GEN_U32_MAX
|
||||
#undef GEN_I32_MIN
|
||||
#undef GEN_I32_MAX
|
||||
#undef GEN_U64_MIN
|
||||
#undef GEN_U64_MAX
|
||||
#undef GEN_I64_MIN
|
||||
#undef GEN_I64_MAX
|
||||
#undef GEN_USIZE_MIN
|
||||
#undef GEN_USIZE_MAX
|
||||
#undef GEN_ISIZE_MIN
|
||||
#undef GEN_ISIZE_MAX
|
||||
#undef GEN_USIZE_MIN
|
||||
#undef GEN_USIZE_MAX
|
||||
#undef GEN_ISIZE_MIN
|
||||
#undef GEN_ISIZE_MAX
|
||||
#undef GEN_F32_MIN
|
||||
#undef GEN_F32_MAX
|
||||
#undef GEN_F64_MIN
|
||||
#undef GEN_F64_MAX
|
||||
|
||||
#undef to_uptr
|
||||
#undef to_sptr
|
||||
#undef to_mem_ptr
|
||||
#undef to_mem_ptr_const
|
||||
|
||||
#undef kilobytes
|
||||
#undef megabytes
|
||||
#undef gigabytes
|
||||
#undef terabytes
|
||||
|
||||
#undef GEN__ONES
|
||||
#undef GEN__HIGHS
|
||||
#undef GEN__HAS_ZERO
|
||||
#undef GEN_DEFAULT_MEMORY_ALIGNMENT
|
||||
#undef GEN_DEFAULT_ALLOCATOR_FLAGS
|
||||
|
||||
#undef zero_item
|
||||
#undef zero_array
|
||||
|
||||
@ -42,37 +137,67 @@
|
||||
#undef malloc
|
||||
#undef mfree
|
||||
|
||||
#undef count_of
|
||||
#undef is_between
|
||||
#undef min
|
||||
#undef size_of
|
||||
#undef swap
|
||||
#undef GEN_DEBUG_TRAP
|
||||
#undef GEN_ASSERT
|
||||
#undef GEN_ASSERT_MSG
|
||||
#undef GEN_ASSERT_NOT_NULL
|
||||
#undef GEN_PANIC
|
||||
#undef GEN_FATAL
|
||||
|
||||
#undef GEN_FILE_OPEN_PROC
|
||||
#undef GEN_FILE_READ_AT_PROC
|
||||
#undef GEN_FILE_WRITE_AT_PROC
|
||||
#undef GEN_FILE_SEEK_PROC
|
||||
#undef GEN_FILE_CLOSE_PROC
|
||||
|
||||
#undef GEN_PRINTF_MAXLEN
|
||||
|
||||
#undef _strlen
|
||||
#undef _printf_err
|
||||
#undef _printf_err_va
|
||||
#undef _strlen
|
||||
#undef _printf_err
|
||||
#undef _printf_err_va
|
||||
|
||||
#undef Array
|
||||
#undef get_array_underlying_type
|
||||
#undef HashTable
|
||||
#undef get_hashtable_underlying_type
|
||||
|
||||
#undef bit
|
||||
#undef bitfield_is_equal
|
||||
#undef ccast
|
||||
#undef scast
|
||||
#undef rcast
|
||||
#undef pcast
|
||||
#undef do_once
|
||||
#undef do_once_start
|
||||
#undef do_once_end
|
||||
#undef num_args
|
||||
#undef num_args_impl
|
||||
#undef stringize
|
||||
#undef stringize
|
||||
#undef stringize_va
|
||||
#undef txt
|
||||
|
||||
#undef GEN_TIME
|
||||
#undef NOMINMAX
|
||||
#undef VC_EXTRALEAN
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
#undef WIN32_MEAN_AND_LEAN
|
||||
|
||||
#undef GEN_DEFINE_ATTRIBUTE_TOKENS
|
||||
|
||||
#undef GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
|
||||
#undef GEN_GLOBAL_BUCKET_SIZE
|
||||
#undef GEN_CODEPOOL_NUM_BLOCKS
|
||||
#undef GEN_SIZE_PER_STRING_ARENA
|
||||
#undef GEN_MAX_COMMENT_LINE_LENGTH
|
||||
#undef GEN_MAX_NAME_LENGTH
|
||||
#undef GEN_MAX_UNTYPED_STR_LENGTH
|
||||
#undef TokenMap_FixedArena
|
||||
#undef GEN_LEX_ALLOCATOR_SIZE
|
||||
#undef GEN_BUILDER_STR_BUFFER_RESERVE
|
||||
|
||||
#undef log_failure
|
||||
|
||||
#undef gen_main
|
||||
#undef __
|
||||
#undef name
|
||||
#undef code
|
||||
#undef args
|
||||
#undef code_str
|
||||
#undef code_fmt
|
||||
#undef token_fmt
|
||||
|
||||
// GEN_TIME
|
||||
#endif
|
||||
#undef parse_fmt
|
||||
#undef token_fmt
|
||||
|
@ -39,6 +39,8 @@ The full definitions of all asts are within:
|
||||
* [`ast_types.hpp`](../base/components/ast_types.hpp)
|
||||
* [`code_types.hpp`](../base/components/ast_types.hpp)
|
||||
|
||||
The C/C++ interface procedures are located with `ast.hpp` (for the Code type), and `code_types.hpp` for all others.
|
||||
|
||||
## Serialization
|
||||
|
||||
All code types can either serialize using a function of the pattern:
|
||||
@ -51,8 +53,6 @@ String <prefix>_to_string(Code code);
|
||||
|
||||
Where the first generates strings allocated using Allocator_StringArena and the other appends an existing strings with their backed allocator.
|
||||
|
||||
Serialization of for the AST is defined for `Code` in [`ast.chpp`](../base/components/ast.cpp) with `code_to_string_ptr` & `code_to_string`.
|
||||
|
||||
Serializtion for the rest of the code types is within [`code_serialization.cpp`](../base/components/code_serialization.cpp).
|
||||
|
||||
gencpp's serialization does not provide coherent formatting of the code. The user should use a formatter after.
|
||||
Serialization of for the AST is defined for `Code` in [`ast.chpp`](../base/components/ast.cpp) with `code_to_string_ptr` & `code_to_string`.
|
||||
Serializtion for the rest of the code types is within [`code_serialization.cpp`](../base/components/code_serialization.cpp).
|
||||
Gencpp's serialization does not provide coherent formatting of the code. The user should use a formatter after serializing.
|
||||
|
@ -25,11 +25,11 @@ These are containers representing a scope body of a definition that can be of th
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Name;
|
||||
Code Front;
|
||||
Code Back;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
@ -37,14 +37,15 @@ 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 ECode type for the type of defintion used.
|
||||
Parent should have a compatible CodeType 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,11 +57,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -80,11 +81,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -108,11 +109,11 @@ CodeComment InlineCmt; // Only supported by forward declarations
|
||||
CodeAttributes Attributes;
|
||||
CodeType ParentType;
|
||||
CodeBody Body;
|
||||
CodeType Prev; // Used to store references to interfaces
|
||||
CodeType Next; // Used to store references to interfaces
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Prev;
|
||||
CodeType Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
@ -131,7 +132,7 @@ Serialization:
|
||||
};
|
||||
```
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
## Constructor
|
||||
|
||||
@ -140,13 +141,13 @@ Fields:
|
||||
```cpp
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -178,11 +179,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -200,11 +201,11 @@ Fields:
|
||||
CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
Code Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -235,24 +236,28 @@ Fields:
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeType UnderlyingType;
|
||||
Code UnderlyingTypeMacro;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
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 `StrC` 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>; <InlineCmt>
|
||||
<ModuleFlags> enum class <Name> : <UnderlyingType> or <UnderlyingTypeMacro> ; <InlineCmt>
|
||||
|
||||
// Enum
|
||||
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType>
|
||||
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType> or <UnderlyingTypeMacro>
|
||||
{
|
||||
<Body>
|
||||
};
|
||||
@ -267,11 +272,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -287,11 +292,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -310,11 +315,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
parser::Token* Tok;
|
||||
StringCached Name;
|
||||
Token* Tok;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -333,11 +338,11 @@ Fields:
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
Code Declaration;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -356,13 +361,13 @@ CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -385,11 +390,11 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -406,11 +411,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -424,7 +429,7 @@ Serialization:
|
||||
}
|
||||
```
|
||||
|
||||
## Operator Overload
|
||||
## Operator Overload (Operator)
|
||||
|
||||
Fields:
|
||||
|
||||
@ -433,13 +438,13 @@ CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
OperatorT Op;
|
||||
@ -458,7 +463,7 @@ Serialization:
|
||||
}
|
||||
```
|
||||
|
||||
## Operator Cast Overload ( User-Defined Type Conversion )
|
||||
## Operator Cast Overload ( User-Defined Type Conversion, OpCast )
|
||||
|
||||
Fields:
|
||||
|
||||
@ -467,11 +472,11 @@ CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -488,7 +493,7 @@ Serialization:
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters (AST_Param)
|
||||
## Parameters (AST_Params)
|
||||
|
||||
Fields:
|
||||
|
||||
@ -496,11 +501,12 @@ Fields:
|
||||
CodeType ValueType;
|
||||
Code Macro;
|
||||
Code Value;
|
||||
CodeParam Last;
|
||||
CodeParam Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
Code PostNameMacro;
|
||||
StringCached Name;
|
||||
CodeParams Last;
|
||||
CodeParams Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
@ -510,7 +516,7 @@ Serialization:
|
||||
```cpp
|
||||
<Macro>, <Next> ... <Last>
|
||||
|
||||
<Macro> <ValueType> <Name>, <Next>... <Last>
|
||||
<Macro> <ValueType> <Name> <PostNameMacro> = <Value>, <Next>... <Last>
|
||||
```
|
||||
|
||||
## Pragma
|
||||
@ -519,11 +525,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -539,11 +545,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
paser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -560,11 +566,11 @@ Fields:
|
||||
```cpp
|
||||
SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||
CodeSpecifiers NextSpecs;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
@ -580,13 +586,13 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code Declaration;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -609,23 +615,30 @@ Fields:
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeReturnType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code ArrExpr;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
b32 IsParamPack;
|
||||
ETypenameTag TypeTag;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Attributes> <Name> <Specs> <IsParamPack ?: ...>
|
||||
<Attributes> <TypeTag> <Name> <Specs> <IsParamPack ?: ...>
|
||||
// Function
|
||||
<Attributes> <ReturnType> <Name> <Params> <Specs>
|
||||
```
|
||||
|
||||
`<Name>` currently has the full serialization of anything with
|
||||
|
||||
*Note: ArrExpr is not used in serialization by `typename_to_string_ref` its instead handled by a parent AST's serailization (variable, typedef, using).*
|
||||
|
||||
## Typedef
|
||||
|
||||
Behave as usual except function or macro typedefs.
|
||||
@ -636,11 +649,11 @@ Fields:
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
Code UnderlyingType;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parse::Token* Tok
|
||||
Token* Tok
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
@ -650,11 +663,16 @@ Serialization:
|
||||
|
||||
```cpp
|
||||
// Regular
|
||||
<ModuleFlags> typedef <UnderlyingType> <Name>; <InlineCmt>
|
||||
<ModuleFlags> typedef <UnderlyingType> <Name> <UnderlyingType-ArrExpr>; <InlineCmt>
|
||||
|
||||
// Functions
|
||||
<ModuleFlags> typedef <ReturnType> <Name>( <Parameters> ); <InlineCmt>
|
||||
<ModuleFlags> typedef <ReturnType> ( <Expression that yeilds an Identifier signature> )( <Parameters> ); <InlineCmt>
|
||||
|
||||
// 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>
|
||||
```
|
||||
|
||||
## Union
|
||||
@ -664,11 +682,11 @@ Fields:
|
||||
```cpp
|
||||
CodeAttributes Attributes;
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -690,11 +708,11 @@ Fields:
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeType UnderlyingType;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -722,14 +740,15 @@ CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
StringCached Name;
|
||||
CodeVar NextVar;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
s32 VarParenthesizedInit;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -740,4 +759,7 @@ Serialization:
|
||||
|
||||
// Bitfield
|
||||
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> : <BitfieldSize> = <Value>, NextVar ...; <InlineCmt>
|
||||
|
||||
// VarParenthesizedInit
|
||||
<Attributes> <Specs> <ValueType> <Name>( <Value>, NextVar ... ); <InlineCmt>
|
||||
```
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
|
@ -128,7 +128,7 @@ The following CodeTypes are used which the user may optionally use strong typing
|
||||
* CodeNS
|
||||
* CodeOperator
|
||||
* CodeOpCast
|
||||
* CodeParam : Has support for `for : range` iterating across parameters.
|
||||
* CodeParams : Has support for `for : range` iterating across parameters.
|
||||
* CodePreprocessCond
|
||||
* CodePragma
|
||||
* CodeSpecifiers : Has support for `for : range` iterating across specifiers.
|
||||
@ -412,4 +412,8 @@ 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`
|
||||
|
@ -3,22 +3,16 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "../project/gen.cpp"
|
||||
|
||||
#include "gen.cpp"
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
#include "helpers/helper.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "helpers/push_container_defines.inline.hpp"
|
||||
#include "dependencies/parsing.cpp"
|
||||
#include "helpers/pop_container_defines.inline.hpp"
|
||||
#include "helpers/base_codegen.hpp"
|
||||
#include "helpers/misc.hpp"
|
||||
GEN_NS_END
|
||||
|
||||
#include "auxillary/builder.hpp"
|
||||
#include "auxillary/builder.cpp"
|
||||
#include "auxillary/scanner.hpp"
|
||||
|
||||
|
||||
#include "components/memory.fixed_arena.hpp"
|
||||
#include "components/misc.hpp"
|
||||
#include "components/containers.array.hpp"
|
||||
@ -52,47 +46,22 @@ constexpr StrC implementation_guard_end = txt(R"(
|
||||
#pragma endregion GENCPP IMPLEMENTATION GUARD
|
||||
)");
|
||||
|
||||
void CHANGE_format_file( char const* path )
|
||||
{
|
||||
String resolved_path = String::make(GlobalAllocator, to_strc_from_c_str(path));
|
||||
#define path_refactor_script "./c_library.refactor"
|
||||
#define path_format_style "../scripts/.clang-format "
|
||||
#define scratch_file "gen/scratch.hpp"
|
||||
#define path_base "../base/"
|
||||
|
||||
String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
|
||||
style_arg.append("../scripts/.clang-format ");
|
||||
|
||||
// Need to execute clang format on the generated file to get it to match the original.
|
||||
#define clang_format "clang-format "
|
||||
#define cf_format_inplace "-i "
|
||||
#define cf_verbose "-verbose "
|
||||
String command = String::make( GlobalAllocator, clang_format );
|
||||
command.append( cf_format_inplace );
|
||||
command.append( cf_verbose );
|
||||
command.append( style_arg );
|
||||
command.append( resolved_path );
|
||||
log_fmt("\tRunning clang-format on file:\n");
|
||||
system( command );
|
||||
log_fmt("\tclang-format finished reformatting.\n");
|
||||
#undef cf_cmd
|
||||
#undef cf_format_inplace
|
||||
#undef cf_style
|
||||
#undef cf_verbse
|
||||
Code refactor( Code code ) {
|
||||
return code_refactor_and_format(code, scratch_file, path_refactor_script, nullptr );
|
||||
}
|
||||
|
||||
Code CHANGE_format_code_to_untyped( Code code )
|
||||
{
|
||||
Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
|
||||
ecode_file_temp.print(code);
|
||||
ecode_file_temp.write();
|
||||
format_file("gen/scratch.hpp");
|
||||
Code result = scan_file( "gen/scratch.hpp" );
|
||||
remove("gen/scratch.hpp");
|
||||
return result;
|
||||
Code refactor_and_format( Code code ) {
|
||||
return code_refactor_and_format(code, scratch_file, path_refactor_script, path_format_style );
|
||||
}
|
||||
|
||||
constexpr bool helper_use_c_definition = true;
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
#define project_dir "../project/"
|
||||
gen::init();
|
||||
|
||||
PreprocessorDefines.append(txt("GEN_API_C_BEGIN"));
|
||||
@ -109,22 +78,23 @@ int gen_main()
|
||||
PreprocessorDefines.append(txt("GEN_PARAM_DEFAULT"));
|
||||
//PreprocessorDefines.append(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"));
|
||||
|
||||
Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" );
|
||||
Code push_ignores = scan_file( path_base "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( path_base "helpers/pop_ignores.inline.hpp" );
|
||||
Code c_library_header_start = scan_file( "components/header_start.hpp" );
|
||||
|
||||
// Header Content: Reflection and Generation
|
||||
|
||||
#pragma region Resolve Dependencies
|
||||
Code header_platform = scan_file( project_dir "dependencies/platform.hpp" );
|
||||
Code header_macros = scan_file( project_dir "dependencies/macros.hpp" );
|
||||
Code header_basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
|
||||
Code header_debug = scan_file( project_dir "dependencies/debug.hpp" );
|
||||
Code header_string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
||||
Code header_hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
||||
Code header_timing = scan_file( project_dir "dependencies/timing.hpp" );
|
||||
Code header_platform = scan_file( path_base "dependencies/platform.hpp" );
|
||||
Code header_macros = scan_file( path_base "dependencies/macros.hpp" );
|
||||
Code header_generic_macros = scan_file( "components/generic_macros.hpp" );
|
||||
Code header_basic_types = scan_file( path_base "dependencies/basic_types.hpp" );
|
||||
Code header_debug = scan_file( path_base "dependencies/debug.hpp" );
|
||||
Code header_string_ops = scan_file( path_base "dependencies/string_ops.hpp" );
|
||||
Code header_hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||
Code header_timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||
|
||||
CodeBody parsed_header_memory = parse_file( project_dir "dependencies/memory.hpp" );
|
||||
CodeBody parsed_header_memory = parse_file( path_base "dependencies/memory.hpp" );
|
||||
CodeBody header_memory = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_memory.begin(); entry != parsed_header_memory.end(); ++ entry ) switch (entry->Type)
|
||||
{
|
||||
@ -168,6 +138,7 @@ int gen_main()
|
||||
CodeTemplate tmpl = cast(CodeTemplate, entry);
|
||||
if ( tmpl->Declaration->Name.contains(txt("swap")))
|
||||
{
|
||||
log_fmt("SWAPPED");
|
||||
CodeBody macro_swap = parse_global_body( txt(R"(
|
||||
#define swap( a, b ) \
|
||||
do \
|
||||
@ -253,7 +224,7 @@ do \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody parsed_header_printing = parse_file( project_dir "dependencies/printing.hpp" );
|
||||
CodeBody parsed_header_printing = parse_file( path_base "dependencies/printing.hpp" );
|
||||
CodeBody header_printing = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_printing.begin(); entry != parsed_header_printing.end(); ++ entry ) switch (entry->Type)
|
||||
{
|
||||
@ -284,7 +255,7 @@ do \
|
||||
Code array_ssize = gen_array(txt("gen_ssize"), txt("Array_gen_ssize"));
|
||||
Code array_string_cached = gen_array(txt("gen_StringCached"), txt("Array_gen_StringCached"));
|
||||
|
||||
CodeBody parsed_header_strings = parse_file( project_dir "dependencies/strings.hpp" );
|
||||
CodeBody parsed_header_strings = parse_file( path_base "dependencies/strings.hpp" );
|
||||
CodeBody header_strings = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_strings.begin(); entry != parsed_header_strings.end(); ++ entry ) switch (entry->Type)
|
||||
{
|
||||
@ -390,7 +361,7 @@ do \
|
||||
|
||||
CodeBody array_u8 = gen_array(txt("gen_u8"), txt("Array_gen_u8"));
|
||||
|
||||
CodeBody parsed_header_filesystem = parse_file( project_dir "dependencies/filesystem.hpp" );
|
||||
CodeBody parsed_header_filesystem = parse_file( path_base "dependencies/filesystem.hpp" );
|
||||
CodeBody header_filesystem = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_filesystem.begin(); entry != parsed_header_filesystem.end(); ++ entry ) switch (entry->Type)
|
||||
{
|
||||
@ -449,7 +420,7 @@ do \
|
||||
|
||||
CodeBody array_adt_node = gen_array(txt("gen_ADT_Node"), txt("Array_gen_ADT_Node"));
|
||||
|
||||
CodeBody parsed_header_parsing = parse_file( project_dir "dependencies/parsing.hpp" );
|
||||
CodeBody parsed_header_parsing = parse_file( path_base "dependencies/parsing.hpp" );
|
||||
CodeBody header_parsing = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_parsing.begin(); entry != parsed_header_parsing.end(); ++ entry ) switch (entry->Type)
|
||||
{
|
||||
@ -544,11 +515,11 @@ do \
|
||||
// Only has operator overload definitions that C doesn't need.
|
||||
// CodeBody ast_inlines = gen_ast_inlines();
|
||||
|
||||
CodeBody ecode = gen_ecode ( project_dir "enums/ECodeTypes.csv", helper_use_c_definition );
|
||||
CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv", helper_use_c_definition );
|
||||
CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv", helper_use_c_definition );
|
||||
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv", helper_use_c_definition );
|
||||
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv", helper_use_c_definition );
|
||||
CodeBody especifier = gen_especifier( path_base "enums/ESpecifier.csv", helper_use_c_definition );
|
||||
|
||||
CodeBody parsed_types = parse_file( project_dir "components/types.hpp" );
|
||||
CodeBody parsed_types = parse_file( path_base "components/types.hpp" );
|
||||
CodeBody types = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_types.begin(); entry != parsed_types.end(); ++ entry ) switch(entry->Type)
|
||||
{
|
||||
@ -620,7 +591,7 @@ do \
|
||||
// Used to track which functions need generic selectors.
|
||||
Array(CodeFn) code_c_interface = array_init_reserve<CodeFn>(GlobalAllocator, 16);
|
||||
|
||||
CodeBody parsed_ast = parse_file( project_dir "components/ast.hpp" );
|
||||
CodeBody parsed_ast = parse_file( path_base "components/ast.hpp" );
|
||||
CodeBody ast = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_ast.begin(); entry != parsed_ast.end(); ++ entry ) switch (entry->Type)
|
||||
{
|
||||
@ -778,7 +749,7 @@ R"(#define AST_ArrSpecs_Cap \
|
||||
txt("CodeOperator"),
|
||||
txt("CodeOpCast"),
|
||||
txt("CodePragma"),
|
||||
txt("CodeParam"),
|
||||
txt("CodeParams"),
|
||||
txt("CodePreprocessCond"),
|
||||
txt("CodeSpecifiers"),
|
||||
txt("CodeTemplate"),
|
||||
@ -789,7 +760,7 @@ R"(#define AST_ArrSpecs_Cap \
|
||||
txt("CodeVar"),
|
||||
};
|
||||
|
||||
CodeBody parsed_code_types = parse_file( project_dir "components/code_types.hpp" );
|
||||
CodeBody parsed_code_types = parse_file( path_base "components/code_types.hpp" );
|
||||
CodeBody code_types = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_code_types.begin(); entry != parsed_code_types.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
@ -830,7 +801,7 @@ R"(#define AST_ArrSpecs_Cap \
|
||||
// Resolve generic's arguments
|
||||
b32 has_args = fn->Params->NumEntries > 1;
|
||||
String params_str = String::make_reserve(GlobalAllocator, 32);
|
||||
for (CodeParam param = fn->Params->Next; param != fn->Params.end(); ++ param) {
|
||||
for (CodeParams param = fn->Params->Next; param != fn->Params.end(); ++ param) {
|
||||
// We skip the first parameter as its always going to be the code for selection
|
||||
if (param->Next == nullptr) {
|
||||
params_str.append_fmt( "%SC", param->Name );
|
||||
@ -891,7 +862,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody parsed_ast_types = parse_file( project_dir "components/ast_types.hpp" );
|
||||
CodeBody parsed_ast_types = parse_file( path_base "components/ast_types.hpp" );
|
||||
CodeBody ast_types = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_ast_types.begin(); entry != parsed_ast_types.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
@ -922,7 +893,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
StrC cpp_size = to_strc_from_c_str(conversion_buf);
|
||||
union_entry->ValueType->ArrExpr = untyped_str( cpp_size );
|
||||
union_entry->InlineCmt = untyped_str(token_fmt("arr_exp", arr_exp,
|
||||
"// Had to hardcode _PAD_ because (<arr_exp>) was 67 bytes in C (Injected C++ size_of(AST_<Type>::_PAD_) from C++ side)\n"
|
||||
"// Had to hardcode _PAD_ because (<arr_exp>) was 67 bytes in C\n"
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -938,7 +909,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody parsed_interface = parse_file( project_dir "components/interface.hpp" );
|
||||
CodeBody parsed_interface = parse_file( path_base "components/interface.hpp" );
|
||||
CodeBody interface = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_interface.begin(); entry != parsed_interface.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
@ -965,7 +936,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
}
|
||||
|
||||
b32 handled= false;
|
||||
for ( CodeParam opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
||||
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
||||
{
|
||||
// Convert the definition to use a default struct: https://vxtwitter.com/vkrajacic/status/1749816169736073295
|
||||
StrC prefix = txt("def_");
|
||||
@ -975,7 +946,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
// Resolve define's arguments
|
||||
b32 has_args = fn->Params->NumEntries > 1;
|
||||
String params_str = String::make_reserve(GlobalAllocator, 32);
|
||||
for (CodeParam other_param = fn->Params; other_param != opt_param; ++ other_param) {
|
||||
for (CodeParams other_param = fn->Params; other_param != opt_param; ++ other_param) {
|
||||
if ( other_param == opt_param ) {
|
||||
params_str.append_fmt( "%SC", other_param->Name );
|
||||
break;
|
||||
@ -1027,7 +998,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody parsed_inlines = parse_file( project_dir "components/inlines.hpp" );
|
||||
CodeBody parsed_inlines = parse_file( path_base "components/inlines.hpp" );
|
||||
CodeBody inlines = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_inlines.begin(); entry != parsed_inlines.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
@ -1062,7 +1033,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody parsed_header_builder = parse_file( project_dir "auxillary/builder.hpp" );
|
||||
CodeBody parsed_header_builder = parse_file( path_base "auxillary/builder.hpp" );
|
||||
CodeBody header_builder = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_builder.begin(); entry != parsed_header_builder.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
@ -1120,7 +1091,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
}
|
||||
|
||||
s32 idx = 0;
|
||||
CodeBody parsed_header_end = parse_file( project_dir "components/header_end.hpp" );
|
||||
CodeBody parsed_header_end = parse_file( path_base "components/header_end.hpp" );
|
||||
CodeBody header_end = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_end.begin(); entry != parsed_header_end.end(); ++ entry, ++ idx ) switch( entry->Type )
|
||||
{
|
||||
@ -1158,15 +1129,15 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
// Source Content : Reflection and Generation
|
||||
|
||||
#pragma region Resolve Dependencies
|
||||
Code src_impl_start = scan_file( project_dir "dependencies/src_start.cpp" );
|
||||
Code src_debug = scan_file( project_dir "dependencies/debug.cpp" );
|
||||
Code src_string_ops = scan_file( project_dir "dependencies/string_ops.cpp" );
|
||||
Code src_printing = scan_file( project_dir "dependencies/printing.cpp" );
|
||||
Code src_memory = scan_file( project_dir "dependencies/memory.cpp" );
|
||||
Code src_hashing = scan_file( project_dir "dependencies/hashing.cpp" );
|
||||
Code src_strings = scan_file( project_dir "dependencies/strings.cpp" );
|
||||
Code src_filesystem = scan_file( project_dir "dependencies/filesystem.cpp" );
|
||||
Code src_timing = scan_file( project_dir "dependencies/timing.cpp" );
|
||||
Code src_dep_start = scan_file( path_base "dependencies/src_start.cpp" );
|
||||
Code src_debug = scan_file( path_base "dependencies/debug.cpp" );
|
||||
Code src_string_ops = scan_file( path_base "dependencies/string_ops.cpp" );
|
||||
Code src_printing = scan_file( path_base "dependencies/printing.cpp" );
|
||||
Code src_memory = scan_file( path_base "dependencies/memory.cpp" );
|
||||
Code src_hashing = scan_file( path_base "dependencies/hashing.cpp" );
|
||||
Code src_strings = scan_file( path_base "dependencies/strings.cpp" );
|
||||
Code src_filesystem = scan_file( path_base "dependencies/filesystem.cpp" );
|
||||
Code src_timing = scan_file( path_base "dependencies/timing.cpp" );
|
||||
#pragma endregion Resolve Dependencies
|
||||
|
||||
#pragma region Resolve Components
|
||||
@ -1174,14 +1145,15 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
CodeBody array_pool = gen_array(txt("gen_Pool"), txt("Array_gen_Pool"));
|
||||
CodeBody array_token = gen_array(txt("gen_Token"), txt("Array_gen_Token"));
|
||||
|
||||
Code src_static_data = scan_file( project_dir "components/static_data.cpp" );
|
||||
Code src_ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" );
|
||||
Code src_code_serialization = scan_file( project_dir "components/code_serialization.cpp" );
|
||||
Code src_interface = scan_file( project_dir "components/interface.cpp" );
|
||||
Code src_parsing_interface = scan_file( project_dir "components/interface.parsing.cpp" );
|
||||
Code src_untyped = scan_file( project_dir "components/interface.untyped.cpp" );
|
||||
Code src_start = scan_file( "components/src_start.c" );
|
||||
Code src_static_data = scan_file( path_base "components/static_data.cpp" );
|
||||
Code src_ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" );
|
||||
Code src_code_serialization = scan_file( path_base "components/code_serialization.cpp" );
|
||||
Code src_interface = scan_file( path_base "components/interface.cpp" );
|
||||
Code src_parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
|
||||
Code src_untyped = scan_file( path_base "components/interface.untyped.cpp" );
|
||||
|
||||
CodeBody parsed_src_ast = parse_file( project_dir "components/ast.cpp" );
|
||||
CodeBody parsed_src_ast = parse_file( path_base "components/ast.cpp" );
|
||||
CodeBody src_ast = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_src_ast.begin(); entry != parsed_src_ast.end(); ++ entry ) switch( entry ->Type )
|
||||
{
|
||||
@ -1216,7 +1188,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody parsed_src_upfront = parse_file( project_dir "components/interface.upfront.cpp" );
|
||||
CodeBody parsed_src_upfront = parse_file( path_base "components/interface.upfront.cpp" );
|
||||
CodeBody src_upfront = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_src_upfront.begin(); entry != parsed_src_upfront.end(); ++ entry ) switch( entry ->Type )
|
||||
{
|
||||
@ -1239,7 +1211,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
CodeFn fn = cast(CodeFn, entry);
|
||||
Code prev = entry->Prev;
|
||||
|
||||
for ( CodeParam arr_param : fn->Params )
|
||||
for ( CodeParams arr_param : fn->Params )
|
||||
if ( fn->Name.starts_with(txt("def_"))
|
||||
&& ( (arr_param->ValueType->Name.starts_with(txt("Specifier")) && fn->Params->NumEntries > 1)
|
||||
|| arr_param->ValueType->Name.starts_with(txt("Code")) )
|
||||
@ -1251,7 +1223,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
postfix_arr.free();
|
||||
}
|
||||
|
||||
for ( CodeParam opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
||||
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
||||
{
|
||||
StrC prefix = txt("def_");
|
||||
StrC actual_name = { fn->Name.Len - prefix.Len, fn->Name.Ptr + prefix.Len };
|
||||
@ -1269,7 +1241,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody parsed_src_lexer = parse_file( project_dir "components/lexer.cpp" );
|
||||
CodeBody parsed_src_lexer = parse_file( path_base "components/lexer.cpp" );
|
||||
CodeBody src_lexer = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_src_lexer.begin(); entry != parsed_src_lexer.end(); ++ entry ) switch( entry ->Type )
|
||||
{
|
||||
@ -1363,7 +1335,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
|
||||
CodeBody array_code_typename = gen_array(txt("gen_CodeTypename"), txt("Array_gen_CodeTypename"));
|
||||
|
||||
CodeBody parsed_src_parser = parse_file( project_dir "components/parser.cpp" );
|
||||
CodeBody parsed_src_parser = parse_file( path_base "components/parser.cpp" );
|
||||
CodeBody src_parser = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_src_parser.begin(); entry != parsed_src_parser.end(); ++ entry ) switch( entry ->Type )
|
||||
{
|
||||
@ -1426,10 +1398,76 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
containers.append( fmt_newline);
|
||||
}
|
||||
|
||||
// Printing : Everything below is jsut serialization & formatting ot a single-file.
|
||||
// Printing : Everything below is jsut serialization & formatting to a singleheader file & segmented set of files
|
||||
|
||||
#pragma region Refactored / Formatted
|
||||
Code r_header_platform = refactor(header_platform);
|
||||
Code r_header_macros = refactor(header_macros);
|
||||
Code r_header_basic_types = refactor(header_basic_types);
|
||||
Code r_header_debug = refactor(header_debug);
|
||||
Code rf_header_memory = refactor_and_format(header_memory);
|
||||
Code rf_header_printing = refactor_and_format(header_printing);
|
||||
Code r_header_string_ops = refactor(header_string_ops);
|
||||
Code rf_containers = refactor_and_format(containers);
|
||||
Code r_header_hashing = refactor(header_hashing);
|
||||
Code rf_header_strings = refactor_and_format(header_strings);
|
||||
Code rf_header_filesystem = refactor_and_format(header_filesystem);
|
||||
Code r_header_timing = refactor(header_timing);
|
||||
Code rf_header_parsing = refactor_and_format(header_parsing);
|
||||
|
||||
Code rf_types = refactor_and_format(types);
|
||||
Code rf_ecode = refactor_and_format(ecode);
|
||||
Code rf_eoperator = refactor_and_format(eoperator);
|
||||
Code rf_especifier = refactor_and_format(especifier);
|
||||
Code rf_ast = refactor_and_format(ast);
|
||||
Code rf_code_types = refactor_and_format(code_types);
|
||||
Code rf_ast_types = refactor_and_format(ast_types);
|
||||
|
||||
Code rf_interface = refactor_and_format(interface);
|
||||
Code rf_inlines = refactor_and_format(inlines);
|
||||
|
||||
Code rf_array_string_cached = refactor_and_format(array_string_cached);
|
||||
Code rf_header_end = refactor_and_format(header_end);
|
||||
Code rf_header_builder = refactor_and_format(header_builder);
|
||||
Code rf_header_scanner = refactor_and_format( scan_file( path_base "auxillary/scanner.hpp" ));
|
||||
|
||||
Code r_src_dep_start = refactor(src_dep_start);
|
||||
Code r_src_debug = refactor(src_debug);
|
||||
Code r_src_string_ops = refactor(src_string_ops);
|
||||
Code r_src_printing = refactor(src_printing);
|
||||
Code r_src_memory = refactor(src_memory);
|
||||
Code r_src_hashing = refactor(src_hashing);
|
||||
Code r_src_strings = refactor(src_strings);
|
||||
Code r_src_filesystem = refactor(src_filesystem);
|
||||
Code r_src_timing = refactor(src_timing);
|
||||
|
||||
Code rf_src_parsing = refactor_and_format( scan_file( path_base "dependencies/parsing.cpp" ));
|
||||
|
||||
Code rf_array_arena = refactor_and_format(array_arena);
|
||||
Code rf_array_pool = refactor_and_format(array_pool);
|
||||
Code r_src_static_data = refactor(src_static_data);
|
||||
Code r_src_ast_case_macros = refactor(src_ast_case_macros);
|
||||
Code r_src_ast = refactor(src_ast);
|
||||
Code r_src_code_serialization = refactor(src_code_serialization);
|
||||
|
||||
Code r_src_interface = refactor(src_interface);
|
||||
Code r_src_upfront = refactor_and_format(src_upfront);
|
||||
Code r_src_lexer = refactor_and_format(src_lexer);
|
||||
Code rf_array_code_typename = refactor_and_format(array_code_typename);
|
||||
Code rf_src_parser = refactor_and_format(src_parser);
|
||||
Code r_src_parsing = refactor(src_parsing_interface);
|
||||
Code r_src_untyped = refactor(src_untyped);
|
||||
|
||||
CodeBody etoktype = gen_etoktype( path_base "enums/ETokType.csv", path_base "enums/AttributeTokens.csv", helper_use_c_definition );
|
||||
Code rf_etoktype = refactor_and_format(etoktype);
|
||||
|
||||
Code rf_src_builder = refactor_and_format( scan_file( path_base "auxillary/builder.cpp" ));
|
||||
Code rf_src_scanner = refactor_and_format( scan_file( path_base "auxillary/scanner.cpp" ));
|
||||
#pragma endregion Refactored / Formatted
|
||||
|
||||
#pragma region Singleheader
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.h" );
|
||||
header = Builder::open( "gen/gen_singleheader.h" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt("#pragma once\n\n");
|
||||
header.print( push_ignores );
|
||||
@ -1440,25 +1478,23 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
#pragma region Print Dependencies
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print( header_platform );
|
||||
header.print( r_header_platform );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( header_macros );
|
||||
header.print( header_basic_types );
|
||||
header.print( header_debug );
|
||||
header.print( format_code_to_untyped(header_memory) );
|
||||
header.print( format_code_to_untyped(header_printing));
|
||||
header.print( header_string_ops );
|
||||
header.print( r_header_macros );
|
||||
header.print( header_generic_macros );
|
||||
header.print( r_header_basic_types );
|
||||
header.print( r_header_debug );
|
||||
header.print( rf_header_memory );
|
||||
header.print( rf_header_printing);
|
||||
header.print( r_header_string_ops );
|
||||
header.print( fmt_newline);
|
||||
header.print( format_code_to_untyped(containers));
|
||||
header.print( header_hashing );
|
||||
header.print( format_code_to_untyped(header_strings));
|
||||
header.print( format_code_to_untyped(header_filesystem));
|
||||
header.print( header_timing );
|
||||
|
||||
header.print_fmt( "\n#pragma region Parsing\n" );
|
||||
header.print( format_code_to_untyped(header_parsing) );
|
||||
header.print_fmt( "#pragma endregion Parsing\n" );
|
||||
header.print( rf_containers);
|
||||
header.print( r_header_hashing );
|
||||
header.print( rf_header_strings);
|
||||
header.print( rf_header_filesystem);
|
||||
header.print( r_header_timing );
|
||||
header.print(rf_header_parsing );
|
||||
|
||||
header.print_fmt( "\nGEN_NS_END\n" );
|
||||
header.print_fmt( roll_own_dependencies_guard_end );
|
||||
@ -1471,36 +1507,34 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print_fmt( "GEN_API_C_BEGIN\n\n" );
|
||||
|
||||
header.print_fmt("#pragma region Types\n");
|
||||
header.print( format_code_to_untyped(types) );
|
||||
header.print( rf_types );
|
||||
header.print( fmt_newline );
|
||||
header.print( format_code_to_untyped( ecode ));
|
||||
header.print( rf_ecode );
|
||||
header.print( fmt_newline );
|
||||
header.print( format_code_to_untyped( eoperator ));
|
||||
header.print( rf_eoperator );
|
||||
header.print( fmt_newline );
|
||||
header.print( format_code_to_untyped( especifier ));
|
||||
header.print( rf_especifier );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
|
||||
header.print_fmt("#pragma region AST\n");
|
||||
header.print( format_code_to_untyped(ast) );
|
||||
header.print( format_code_to_untyped(code_types) );
|
||||
header.print( format_code_to_untyped(ast_types) );
|
||||
header.print( rf_ast );
|
||||
header.print( rf_code_types );
|
||||
header.print( rf_ast_types );
|
||||
header.print_fmt("\n#pragma endregion AST\n");
|
||||
|
||||
header.print( format_code_to_untyped(interface) );
|
||||
header.print( rf_interface );
|
||||
header.print(fmt_newline);
|
||||
|
||||
header.print_fmt("#pragma region Inlines\n");
|
||||
header.print( format_code_to_untyped(inlines) );
|
||||
header.print( rf_inlines );
|
||||
header.print_fmt("#pragma endregion Inlines\n");
|
||||
|
||||
header.print(fmt_newline);
|
||||
header.print( format_code_to_untyped(array_string_cached));
|
||||
header.print( rf_array_string_cached );
|
||||
|
||||
header.print( format_code_to_untyped(header_end) );
|
||||
|
||||
header.print_fmt( "\n#pragma region Builder\n" );
|
||||
header.print( format_code_to_untyped(header_builder) );
|
||||
header.print_fmt( "\n#pragma endregion Builder\n" );
|
||||
header.print( rf_header_end );
|
||||
header.print( rf_header_builder );
|
||||
header.print( rf_header_scanner );
|
||||
|
||||
header.print_fmt( "\nGEN_API_C_END\n" );
|
||||
header.print_fmt( "GEN_NS_END\n\n" );
|
||||
@ -1516,65 +1550,55 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print_fmt( "GEN_NS_BEGIN\n");
|
||||
header.print_fmt( "GEN_API_C_BEGIN\n" );
|
||||
|
||||
header.print( src_impl_start );
|
||||
header.print( src_debug );
|
||||
header.print( src_string_ops );
|
||||
header.print( src_printing );
|
||||
header.print( src_memory );
|
||||
header.print( src_hashing );
|
||||
header.print( src_strings );
|
||||
header.print( src_filesystem );
|
||||
header.print( src_timing );
|
||||
|
||||
header.print_fmt( "\n#pragma region Parsing\n" );
|
||||
header.print( scan_file( project_dir "dependencies/parsing.cpp" ) );
|
||||
header.print_fmt( "\n#pragma endregion Parsing\n\n" );
|
||||
header.print( r_src_dep_start );
|
||||
header.print( r_src_debug );
|
||||
header.print( r_src_string_ops );
|
||||
header.print( r_src_printing );
|
||||
header.print( r_src_memory );
|
||||
header.print( r_src_hashing );
|
||||
header.print( r_src_strings );
|
||||
header.print( r_src_filesystem );
|
||||
header.print( r_src_timing );
|
||||
header.print( rf_src_parsing );
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n");
|
||||
header.print_fmt( roll_own_dependencies_guard_end );
|
||||
#pragma endregion Print Dependencies
|
||||
|
||||
#pragma region Print Components
|
||||
CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv", helper_use_c_definition );
|
||||
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
|
||||
header.print( fmt_newline);
|
||||
header.print( format_code_to_untyped(array_arena));
|
||||
header.print( rf_array_arena );
|
||||
header.print( fmt_newline);
|
||||
header.print( format_code_to_untyped(array_pool));
|
||||
header.print( rf_array_pool);
|
||||
|
||||
header.print( src_static_data );
|
||||
header.print( r_src_static_data );
|
||||
header.print( fmt_newline);
|
||||
|
||||
header.print_fmt( "#pragma region AST\n\n" );
|
||||
header.print( src_ast_case_macros );
|
||||
header.print( src_ast );
|
||||
header.print( src_code_serialization );
|
||||
header.print( r_src_ast_case_macros );
|
||||
header.print( r_src_ast );
|
||||
header.print( r_src_code_serialization );
|
||||
header.print_fmt( "#pragma endregion AST\n\n" );
|
||||
|
||||
header.print_fmt( "#pragma region Interface\n" );
|
||||
header.print( src_interface );
|
||||
header.print( format_code_to_untyped(src_upfront) );
|
||||
header.print( r_src_interface );
|
||||
header.print( r_src_upfront );
|
||||
header.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
header.print( format_code_to_untyped(etoktype) );
|
||||
header.print( format_code_to_untyped(src_lexer) );
|
||||
header.print( rf_etoktype );
|
||||
header.print( r_src_lexer );
|
||||
header.print( fmt_newline);
|
||||
header.print( format_code_to_untyped(array_code_typename));
|
||||
header.print( rf_array_code_typename );
|
||||
header.print( fmt_newline);
|
||||
header.print( format_code_to_untyped(src_parser) );
|
||||
header.print( src_parsing_interface );
|
||||
header.print( rf_src_parser );
|
||||
header.print( r_src_parsing );
|
||||
header.print_fmt( "\n#pragma endregion Parsing\n" );
|
||||
header.print( src_untyped );
|
||||
header.print( r_src_untyped );
|
||||
header.print_fmt( "\n#pragma endregion Interface\n\n");
|
||||
|
||||
header.print_fmt( "#pragma region Builder\n" );
|
||||
header.print( scan_file( project_dir "auxillary/builder.cpp" ) );
|
||||
header.print_fmt( "#pragma endregion Builder\n\n" );
|
||||
|
||||
header.print_fmt( "\n#pragma region Scanner\n" );
|
||||
header.print( scan_file( project_dir "auxillary/scanner.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Scanner\n\n" );
|
||||
header.print( rf_src_builder );
|
||||
header.print( rf_src_scanner );
|
||||
|
||||
header.print_fmt( "GEN_API_C_END\n" );
|
||||
#pragma endregion Print Components
|
||||
@ -1583,8 +1607,149 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
}
|
||||
header.print( pop_ignores );
|
||||
header.write();
|
||||
#pragma endregion Singleheader
|
||||
|
||||
#pragma region Segmented
|
||||
// gen_dep.h
|
||||
{
|
||||
Builder header = Builder::open( "gen/gen.dep.h");
|
||||
builder_print_fmt( header, generation_notice );
|
||||
builder_print_fmt( header, "// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n" );
|
||||
header.print( r_header_platform );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( r_header_macros );
|
||||
header.print( header_generic_macros );
|
||||
header.print( r_header_basic_types );
|
||||
header.print( r_header_debug );
|
||||
header.print( rf_header_memory );
|
||||
header.print( rf_header_printing);
|
||||
header.print( r_header_string_ops );
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_containers);
|
||||
header.print( r_header_hashing );
|
||||
header.print( rf_header_strings);
|
||||
header.print( rf_header_filesystem);
|
||||
header.print( r_header_timing );
|
||||
header.print(rf_header_parsing );
|
||||
|
||||
header.print_fmt( "\nGEN_NS_END\n" );
|
||||
header.write();
|
||||
}
|
||||
// gen_dep.c
|
||||
{
|
||||
Builder src = Builder::open( "gen/gen.dep.c" );
|
||||
src.print_fmt( "GEN_NS_BEGIN\n");
|
||||
src.print_fmt( "GEN_API_C_BEGIN\n" );
|
||||
|
||||
builder_print_fmt(src, generation_notice );
|
||||
builder_print_fmt( src, "// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n" );
|
||||
src.print( r_src_dep_start );
|
||||
src.print( r_src_debug );
|
||||
src.print( r_src_string_ops );
|
||||
src.print( r_src_printing );
|
||||
src.print( r_src_memory );
|
||||
src.print( r_src_hashing );
|
||||
src.print( r_src_strings );
|
||||
src.print( r_src_filesystem );
|
||||
src.print( r_src_timing );
|
||||
src.print( rf_src_parsing );
|
||||
|
||||
src.print_fmt( "GEN_NS_END\n");
|
||||
src.write();
|
||||
}
|
||||
// gen.h
|
||||
{
|
||||
Builder header = builder_open( "gen/gen.h" );
|
||||
builder_print_fmt( header, generation_notice );
|
||||
builder_print_fmt( header, "#pragma once\n\n" );
|
||||
builder_print( header, push_ignores );
|
||||
header.print( c_library_header_start );
|
||||
header.print( scan_file( "components/header_seg_includes.h" ));
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "GEN_NS_BEGIN\n" );
|
||||
header.print_fmt( "GEN_API_C_BEGIN\n\n" );
|
||||
|
||||
header.print_fmt("#pragma region Types\n");
|
||||
header.print( rf_types );
|
||||
header.print( fmt_newline );
|
||||
header.print( rf_ecode );
|
||||
header.print( fmt_newline );
|
||||
header.print( rf_eoperator );
|
||||
header.print( fmt_newline );
|
||||
header.print( rf_especifier );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
|
||||
header.print_fmt("#pragma region AST\n");
|
||||
header.print( rf_ast );
|
||||
header.print( rf_code_types );
|
||||
header.print( rf_ast_types );
|
||||
header.print_fmt("\n#pragma endregion AST\n");
|
||||
|
||||
header.print( rf_interface );
|
||||
header.print(fmt_newline);
|
||||
|
||||
header.print_fmt("#pragma region Inlines\n");
|
||||
header.print( rf_inlines );
|
||||
header.print_fmt("#pragma endregion Inlines\n");
|
||||
|
||||
header.print(fmt_newline);
|
||||
header.print( rf_array_string_cached );
|
||||
|
||||
header.print( rf_header_end );
|
||||
header.print( rf_header_builder );
|
||||
header.print( rf_header_scanner );
|
||||
|
||||
header.print_fmt( "\nGEN_API_C_END\n" );
|
||||
header.print_fmt( "GEN_NS_END\n\n" );
|
||||
builder_print( header, pop_ignores );
|
||||
builder_write(header);
|
||||
}
|
||||
// gen.c
|
||||
{
|
||||
Builder src = Builder::open( "gen/gen.c" );
|
||||
builder_print_fmt( src, generation_notice );
|
||||
builder_print( src, push_ignores );
|
||||
builder_print( src, src_start );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
|
||||
src.print( fmt_newline);
|
||||
src.print( rf_array_arena );
|
||||
src.print( fmt_newline);
|
||||
src.print( rf_array_pool);
|
||||
|
||||
src.print( r_src_static_data );
|
||||
src.print( fmt_newline);
|
||||
|
||||
src.print_fmt( "#pragma region AST\n\n" );
|
||||
src.print( r_src_ast_case_macros );
|
||||
src.print( r_src_ast );
|
||||
src.print( r_src_code_serialization );
|
||||
src.print_fmt( "#pragma endregion AST\n\n" );
|
||||
|
||||
src.print_fmt( "#pragma region Interface\n" );
|
||||
src.print( r_src_interface );
|
||||
src.print( r_src_upfront );
|
||||
src.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
src.print( rf_etoktype );
|
||||
src.print( r_src_lexer );
|
||||
src.print( fmt_newline);
|
||||
src.print( rf_array_code_typename );
|
||||
src.print( fmt_newline);
|
||||
src.print( rf_src_parser );
|
||||
src.print( r_src_parsing );
|
||||
src.print_fmt( "\n#pragma endregion Parsing\n" );
|
||||
src.print( r_src_untyped );
|
||||
src.print_fmt( "\n#pragma endregion Interface\n\n");
|
||||
|
||||
src.print( rf_src_builder );
|
||||
src.print( rf_src_scanner );
|
||||
|
||||
src.print_fmt( "GEN_API_C_END\n" );
|
||||
src.write();
|
||||
}
|
||||
#pragma endregion Segmented
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
#undef project_dir
|
||||
}
|
||||
|
@ -56,25 +56,29 @@ word hash, gen_hash
|
||||
|
||||
// Basic Types
|
||||
|
||||
word u8, gen_u8
|
||||
word s8, gen_s8
|
||||
word u16, gen_u16
|
||||
word s16, gen_s16
|
||||
word u32, gen_u32
|
||||
word s32, gen_s32
|
||||
word u64, gen_u64
|
||||
word s64, gen_s64
|
||||
word usize, gen_usize
|
||||
word ssize, gen_ssize
|
||||
word sptr, gen_sptr
|
||||
word uptr, gen_uptr
|
||||
word f32, gen_f32
|
||||
word f64, gen_f64
|
||||
word b8, gen_b8
|
||||
word b16, gen_b16
|
||||
word b32, gen_b32
|
||||
word mem_ptr, gen_mem_ptr
|
||||
word mem_ptr_const, gen_mem_ptr_cnst
|
||||
word u8, gen_u8
|
||||
word s8, gen_s8
|
||||
word u16, gen_u16
|
||||
word s16, gen_s16
|
||||
word u32, gen_u32
|
||||
word s32, gen_s32
|
||||
word u64, gen_u64
|
||||
word s64, gen_s64
|
||||
word usize, gen_usize
|
||||
word ssize, gen_ssize
|
||||
word sptr, gen_sptr
|
||||
word uptr, gen_uptr
|
||||
word f32, gen_f32
|
||||
word f64, gen_f64
|
||||
word b8, gen_b8
|
||||
word b16, gen_b16
|
||||
word b32, gen_b32
|
||||
word mem_ptr, gen_mem_ptr
|
||||
word mem_ptr_const, gen_mem_ptr_const
|
||||
word to_uptr, gen_to_uptr
|
||||
word to_sptr, gen_to_sptr
|
||||
word to_mem_ptr, gen_to_mem_ptr
|
||||
word to_mem_ptr_const, gen_to_mem_ptr_const
|
||||
|
||||
// Debug
|
||||
|
||||
@ -315,33 +319,33 @@ namespace AST_, gen_AST_
|
||||
word Code, gen_Code
|
||||
word Token, gen_Token
|
||||
|
||||
word CodeBody, gen_CodeBody
|
||||
word CodeAttributes, gen_CodeAttributes
|
||||
word CodeComment, gen_CodeComment
|
||||
word CodeClass, gen_CodeClass
|
||||
word CodeConstructor, gen_CodeConstructor
|
||||
word CodeDefine, gen_CodeDefine
|
||||
word CodeDestructor, gen_CodeDestructor
|
||||
word CodeEnum, gen_CodeEnum
|
||||
word CodeExec, gen_CodeExec
|
||||
word CodeExtern, gen_CodeExtern
|
||||
word CodeInclude, gen_CodeInclude
|
||||
word CodeFriend, gen_CodeFriend
|
||||
word CodeFn, gen_CodeFn
|
||||
word CodeModule, gen_CodeModule
|
||||
word CodeNS, gen_CodeNS
|
||||
word CodeOperator, gen_CodeOperator
|
||||
word CodeOpCast, gen_CodeOpCast
|
||||
word CodePragma, gen_CodePragma
|
||||
word CodeParam, gen_CodeParam
|
||||
word CodePreprocessCo, gen_CodePreprocessCo
|
||||
word CodeSpecifiers, gen_CodeSpecifiers
|
||||
word CodeTemplate, gen_CodeTemplate
|
||||
word CodeTypename, gen_CodeTypename
|
||||
word CodeTypedef, gen_CodeTypedef
|
||||
word CodeUnion, gen_CodeUnion
|
||||
word CodeUsing, gen_CodeUsing
|
||||
word CodeVar, gen_CodeVar
|
||||
word CodeBody, gen_CodeBody
|
||||
word CodeAttributes, gen_CodeAttributes
|
||||
word CodeComment, gen_CodeComment
|
||||
word CodeClass, gen_CodeClass
|
||||
word CodeConstructor, gen_CodeConstructor
|
||||
word CodeDefine, gen_CodeDefine
|
||||
word CodeDestructor, gen_CodeDestructor
|
||||
word CodeEnum, gen_CodeEnum
|
||||
word CodeExec, gen_CodeExec
|
||||
word CodeExtern, gen_CodeExtern
|
||||
word CodeInclude, gen_CodeInclude
|
||||
word CodeFriend, gen_CodeFriend
|
||||
word CodeFn, gen_CodeFn
|
||||
word CodeModule, gen_CodeModule
|
||||
word CodeNS, gen_CodeNS
|
||||
word CodeOperator, gen_CodeOperator
|
||||
word CodeOpCast, gen_CodeOpCast
|
||||
word CodePragma, gen_CodePragma
|
||||
word CodeParams, gen_CodeParams
|
||||
word CodePreprocessCond, gen_CodePreprocessCond
|
||||
word CodeSpecifiers, gen_CodeSpecifiers
|
||||
word CodeTemplate, gen_CodeTemplate
|
||||
word CodeTypename, gen_CodeTypename
|
||||
word CodeTypedef, gen_CodeTypedef
|
||||
word CodeUnion, gen_CodeUnion
|
||||
word CodeUsing, gen_CodeUsing
|
||||
word CodeVar, gen_CodeVar
|
||||
|
||||
// Code Interface
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "../project/gen.hpp"
|
||||
#include "gen.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "../project/gen.hpp"
|
||||
#include "gen.hpp"
|
||||
#include "containers.array.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
115
gen_c_library/components/generic_macros.hpp
Normal file
115
gen_c_library/components/generic_macros.hpp
Normal file
@ -0,0 +1,115 @@
|
||||
|
||||
#pragma region _Generic Macros
|
||||
// ____ _ ______ _ _ ____ _ __ _
|
||||
// / ___} (_) | ____} | | (_) / __ \ | | | |(_)
|
||||
// | | ___ ___ _ __ ___ _ __ _ ___ | |__ _ _ _ __ ___| |_ _ ___ _ __ | | | |_ _____ _ __ | | ___ __ _ __| | _ _ __ __ _
|
||||
// | |{__ |/ _ \ '_ \ / _ \ '__} |/ __| | __} | | | '_ \ / __} __} |/ _ \| '_ \ | | | \ \ / / _ \ '_ \| |/ _ \ / _` |/ _` || | '_ \ / _` |
|
||||
// | |__j | __/ | | | __/ | | | (__ | | | |_| | | | | (__| l_| | (_) | | | | | l__| |\ V / __/ | | | | (_) | (_| | (_| || | | | | (_| |
|
||||
// \____/ \___}_l l_l\___}_l l_l\___| l_l \__,_l_l l_l\___}\__}_l\___/l_l l_l \____/ \_/ \___}_l l_l_l\___/ \__,_l\__,_l|_|_| |_|\__, |
|
||||
// This implemnents macros for utilizing "The Naive Extendible _Generic Macro" explained in: __| |
|
||||
// https://github.com/JacksonAllan/CC/blob/main/articles/Better_C_Generics_Part_1_The_Extendible_Generic.md {___/
|
||||
// Since gencpp is used to generate the c-library, it was choosen over the more novel implementations to keep the macros as easy to understand and unobfuscated as possible.
|
||||
|
||||
#define GEN_COMMA_OPERATOR , // The comma operator is used by preprocessor macros to delimit arguments, so we have to represent it via a macro to prevent parsing incorrectly.
|
||||
|
||||
// Helper macros for argument selection
|
||||
#define GEN_SELECT_ARG_1( _1, ... ) _1 // <-- Of all th args passed pick _1.
|
||||
#define GEN_SELECT_ARG_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2.
|
||||
#define GEN_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc..
|
||||
|
||||
#define GEN_GENERIC_SEL_ENTRY_TYPE GEN_SELECT_ARG_1 // Use the arg expansion macro to select arg 1 which should have the type.
|
||||
#define GEN_GENERIC_SEL_ENTRY_FUNCTION GEN_SELECT_ARG_2 // Use the arg expansion macro to select arg 2 which should have the function.
|
||||
#define GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER GEN_SELECT_ARG_3 // Use the arg expansion macro to select arg 3 which should have the comma delimiter ','.
|
||||
|
||||
#define GEN_RESOLVED_FUNCTION_CALL // Just used to indicate where the call "occurs"
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
// GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( macro ) includes a _Generic slot only if the specified macro is defined (as type, function_name).
|
||||
// It takes advantage of the fact that if the macro is defined, then the expanded text will contain a comma.
|
||||
// Expands to ',' if it can find (type): (function) <comma_operator: ',' >
|
||||
// Where GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER is specifically looking for that <comma> ,
|
||||
#define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ) GEN_COMMA_OPERATOR, , )
|
||||
// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma
|
||||
// The slot won't exist if that comma is not found. |
|
||||
|
||||
// For the occastion where an expression didn't resolve to a selection option the "default: <value>" will be set to:
|
||||
typedef struct GENCPP_NO_RESOLVED_GENERIC_SELECTION GENCPP_NO_RESOLVED_GENERIC_SELECTION;
|
||||
struct GENCPP_NO_RESOLVED_GENERIC_SELECTION {
|
||||
void* _THE_VOID_SLOT_;
|
||||
};
|
||||
GENCPP_NO_RESOLVED_GENERIC_SELECTION const gen_generic_selection_fail = {0};
|
||||
// Which will provide the message: error: called object type 'struct NO_RESOLVED_GENERIC_SELECTION' is not a function or function pointer
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Below are generated on demand for an overlaod depdendent on a type:
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \
|
||||
(selector_arg), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg )
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Then each definiton of a function has an associated define:
|
||||
#// #define GENERIC_SLOT_<#>_<generic identifier> <typename>, <function_to_resolve>
|
||||
|
||||
// Then somehwere later on
|
||||
// <etc> <return_type> <function_id> ( <arguments> ) { <implementation> }
|
||||
|
||||
// Concrete example:
|
||||
|
||||
// To add support for long:
|
||||
#define GENERIC_SLOT_1_gen_example_hash long, gen_example_hash__P_long
|
||||
size_t gen_example_hash__P_long( long val ) { return val * 2654435761ull; }
|
||||
|
||||
// To add support for long long:
|
||||
#define GENERIC_SLOT_2_gen_example_hash long long, gen_example_hash__P_long_long
|
||||
size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761ull; }
|
||||
|
||||
// If using an Editor with support for syntax hightlighting macros: HASH__ARGS_SIG_1 and HASH_ARGS_SIG_2 should show color highlighting indicating the slot is enabled,
|
||||
// or, "defined" for usage during the compilation pass that handles the _Generic instrinsic.
|
||||
#define gen_hash_example( function_arguments ) _Generic( \
|
||||
(function_arguments), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_2 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_3 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_4 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_5 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_6 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_7 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_8 ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( function_arguments )
|
||||
|
||||
// Additional Variations:
|
||||
|
||||
// If the function takes more than one argument the following is used:
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE_VARADIC( selector_arg, ... ) _Generic( \
|
||||
(selector_arg), \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_2 ) \
|
||||
/* ... */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(FunctionID__ARGS_SIG_N ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg, __VA_ARG__ )
|
||||
|
||||
// If the function does not take the arugment as a parameter:
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( selector_arg ) _Generic( \
|
||||
( GEN_TYPE_TO_EXP(selector_arg) ), \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_2 ) \
|
||||
/* ... */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(FunctionID__ARGS_SIG_N ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL()
|
||||
|
||||
// Used to keep the _Generic keyword happy as bare types are not considered "expressions"
|
||||
#define GEN_TYPE_TO_EXP(type) (* (type*)NULL)
|
||||
// Instead of using this macro, you'll see it directly expanded by the code generation.
|
||||
|
||||
// typedef void* GEN_GenericExampleType;
|
||||
// GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( GEN_GenericExampleType );
|
||||
#pragma endregion _Generic Macros
|
9
gen_c_library/components/header_seg_includes.h
Normal file
9
gen_c_library/components/header_seg_includes.h
Normal file
@ -0,0 +1,9 @@
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.h : GEN_TIME not defined
|
||||
#endif
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
// Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.h"
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../project/gen.hpp"
|
||||
#include "gen.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../project/gen.hpp"
|
||||
#include "gen.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
@ -174,7 +174,7 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt(""
|
||||
|
||||
// Add parameter types to create a unique signature
|
||||
bool first_param = true;
|
||||
for (CodeParam param = fn->Params; param.ast; param = param->Next)
|
||||
for (CodeParams param = fn->Params; param.ast; param = param->Next)
|
||||
{
|
||||
if (param->ValueType)
|
||||
{
|
||||
|
11
gen_c_library/components/src_start.c
Normal file
11
gen_c_library/components/src_start.c
Normal file
@ -0,0 +1,11 @@
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
#endif
|
||||
|
||||
#include "gen.h"
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.c"
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
#define GEN_IMPLEMENTATION
|
||||
#include "gen/gen.h"
|
||||
#include "gen/gen.c"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -1,11 +1,14 @@
|
||||
// Includes are exposed to base directory
|
||||
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#define GEN_C_LIKE_CPP 1
|
||||
#include "../base/gen.cpp"
|
||||
|
||||
#include "gen.cpp"
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "helpers/base_codegen.hpp"
|
||||
#include "helpers/misc.hpp"
|
||||
@ -19,9 +22,9 @@ constexpr char const* generation_notice =
|
||||
|
||||
#include <cstdlib> // for system()
|
||||
|
||||
constexpr char const* path_format_style = "../scripts/.clang-format ";
|
||||
constexpr char const* scratch_file = "gen/scratch.hpp";
|
||||
constexpr char const* path_base = "../base/";
|
||||
#define path_format_style "../scripts/.clang-format "
|
||||
#define scratch_file "gen/scratch.hpp"
|
||||
#define path_base "../base/"
|
||||
|
||||
Code format( Code code ) {
|
||||
return code_refactor_and_format(code, scratch_file, nullptr, path_format_style );
|
||||
@ -31,25 +34,26 @@ int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
|
||||
Code push_ignores = scan_file( path_base "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( path_base "helpers/pop_ignores.inline.hpp" );
|
||||
Code push_ignores = scan_file( (path_base "helpers/push_ignores.inline.hpp") );
|
||||
Code pop_ignores = scan_file( (path_base "helpers/pop_ignores.inline.hpp") );
|
||||
|
||||
// gen_dep.hpp
|
||||
{
|
||||
Code platform = scan_file( "dependencies/platform.hpp" );
|
||||
Code macros = scan_file( "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( "dependencies/timing.hpp" );
|
||||
Code platform = scan_file( path_base "dependencies/platform.hpp" );
|
||||
Code macros = scan_file( path_base "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( path_base "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( path_base "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( path_base "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( path_base "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.hpp" );
|
||||
|
||||
Builder _header = builder_open("gen/gen.dep.hpp");
|
||||
Builder _header = builder_open( "gen/gen.dep.hpp");
|
||||
Builder* header = & _header;
|
||||
builder_print_fmt( header, generation_notice );
|
||||
builder_print_fmt( header, "// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n" );
|
||||
@ -67,6 +71,7 @@ int gen_main()
|
||||
builder_print( header, strings );
|
||||
builder_print( header, filesystem );
|
||||
builder_print( header, timing );
|
||||
builder_print( header, parsing );
|
||||
|
||||
builder_print_fmt( header, "\nGEN_NS_END\n" );
|
||||
builder_write(header);
|
||||
@ -74,15 +79,16 @@ int gen_main()
|
||||
|
||||
// gen_dep.cpp
|
||||
{
|
||||
Code src_start = scan_file( "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( "dependencies/timing.cpp" );
|
||||
Code src_start = scan_file( path_base "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( path_base "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( path_base "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( path_base "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( path_base "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( path_base "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( path_base "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.cpp" );
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.cpp" );
|
||||
|
||||
Builder _src = builder_open( "gen/gen.dep.cpp" );
|
||||
Builder* src = & _src;
|
||||
@ -99,6 +105,7 @@ int gen_main()
|
||||
builder_print( src, strings );
|
||||
builder_print( src, filesystem );
|
||||
builder_print( src, timing );
|
||||
builder_print( src, parsing );
|
||||
|
||||
builder_print_fmt( src, "\nGEN_NS_END\n" );
|
||||
builder_write(src);
|
||||
@ -115,18 +122,18 @@ int gen_main()
|
||||
|
||||
// gen.hpp
|
||||
{
|
||||
Code header_start = scan_file( "components/header_start.hpp" );
|
||||
Code types = scan_file( "components/types.hpp" );
|
||||
Code ast = scan_file( "components/ast.hpp" );
|
||||
Code ast_types = scan_file( "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( "components/code_types.hpp" );
|
||||
Code interface = scan_file( "components/interface.hpp" );
|
||||
Code inlines = scan_file( "components/inlines.hpp" );
|
||||
Code header_end = scan_file( "components/header_end.hpp" );
|
||||
Code header_start = scan_file( path_base "components/header_start.hpp" );
|
||||
Code types = scan_file( path_base "components/types.hpp" );
|
||||
Code ast = scan_file( path_base "components/ast.hpp" );
|
||||
Code ast_types = scan_file( path_base "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( path_base "components/code_types.hpp" );
|
||||
Code interface = scan_file( path_base "components/interface.hpp" );
|
||||
Code inlines = scan_file( path_base "components/inlines.hpp" );
|
||||
Code header_end = scan_file( path_base "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode ( "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" );
|
||||
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( path_base "enums/ESpecifier.csv" );
|
||||
CodeBody ast_inlines = gen_ast_inlines();
|
||||
|
||||
Builder _header = builder_open( "gen/gen.hpp" );
|
||||
@ -167,43 +174,23 @@ int gen_main()
|
||||
builder_print_fmt( header, "GEN_NS_END\n\n" );
|
||||
builder_print( header, pop_ignores );
|
||||
builder_write(header);
|
||||
|
||||
Builder header_ecode = builder_open( "components/gen/ecode.hpp" );
|
||||
builder_print( & header_ecode, gen_component_header );
|
||||
builder_print( & header_ecode, format(ecode) );
|
||||
builder_write( & header_ecode);
|
||||
|
||||
Builder header_eoperator = builder_open( "components/gen/eoperator.hpp" );
|
||||
builder_print( & header_eoperator, gen_component_header );
|
||||
builder_print( & header_eoperator, format(eoperator) );
|
||||
builder_write( & header_eoperator );
|
||||
|
||||
Builder header_especifier = builder_open( "components/gen/especifier.hpp" );
|
||||
builder_print( & header_especifier, gen_component_header );
|
||||
builder_print( & header_especifier, format(especifier) );
|
||||
builder_write( & header_especifier);
|
||||
|
||||
Builder header_ast_inlines = builder_open( "components/gen/ast_inlines.hpp" );
|
||||
builder_print( & header_ast_inlines, gen_component_header );
|
||||
builder_print( & header_ast_inlines, format(ast_inlines) );
|
||||
builder_write( & header_ast_inlines);
|
||||
}
|
||||
|
||||
// gen.cpp
|
||||
{
|
||||
Code src_start = scan_file( "components/src_start.cpp" );
|
||||
Code static_data = scan_file( "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( "components/ast.cpp" );
|
||||
Code code_serialization = scan_file( "components/code_serialization.cpp" );
|
||||
Code interface = scan_file( "components/interface.cpp" );
|
||||
Code upfront = scan_file( "components/interface.upfront.cpp" );
|
||||
Code lexer = scan_file( "components/lexer.cpp" );
|
||||
Code parser = scan_file( "components/parser.cpp" );
|
||||
Code parsing_interface = scan_file( "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( "components/interface.untyped.cpp" );
|
||||
Code src_start = scan_file( path_base "components/src_start.cpp" );
|
||||
Code static_data = scan_file( path_base "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( path_base "components/ast.cpp" );
|
||||
Code code_serialization = scan_file( path_base "components/code_serialization.cpp" );
|
||||
Code interface = scan_file( path_base "components/interface.cpp" );
|
||||
Code upfront = scan_file( path_base "components/interface.upfront.cpp" );
|
||||
Code lexer = scan_file( path_base "components/lexer.cpp" );
|
||||
Code parser = scan_file( path_base "components/parser.cpp" );
|
||||
Code parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( path_base "components/interface.untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
|
||||
CodeBody etoktype = gen_etoktype( path_base "enums/ETokType.csv", path_base "enums/AttributeTokens.csv" );
|
||||
CodeBody nspaced_etoktype = def_global_body( args(
|
||||
etoktype
|
||||
));
|
||||
@ -232,23 +219,18 @@ int gen_main()
|
||||
builder_print( src, lexer );
|
||||
builder_print( src, parser );
|
||||
builder_print( src, parsing_interface );
|
||||
builder_print( src, untyped );
|
||||
builder_print_fmt( src, "\n#pragma endregion Parsing\n\n" );
|
||||
builder_print( src, untyped );
|
||||
builder_print_fmt( src, "#pragma endregion Interface\n\n" );
|
||||
|
||||
builder_print_fmt( src, "GEN_NS_END\n\n");
|
||||
builder_print( src, pop_ignores );
|
||||
builder_write(src);
|
||||
|
||||
Builder src_etoktype = builder_open( "components/gen/etoktype.cpp" );
|
||||
builder_print( & src_etoktype, gen_component_header );
|
||||
builder_print( & src_etoktype, formatted_toktype );
|
||||
builder_write( & src_etoktype);
|
||||
}
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code builder = scan_file( "auxillary/builder.hpp" );
|
||||
Code builder = scan_file( path_base "auxillary/builder.hpp" );
|
||||
|
||||
Builder header = builder_open( "gen/gen.builder.hpp" );
|
||||
builder_print_fmt( & header, generation_notice );
|
||||
@ -261,8 +243,8 @@ int gen_main()
|
||||
}
|
||||
|
||||
// gen_builder.cpp
|
||||
|
||||
Code builder = scan_file( "auxillary/builder.cpp" );
|
||||
{
|
||||
Code builder = scan_file( path_base "auxillary/builder.cpp" );
|
||||
|
||||
Builder src = builder_open( "gen/gen.builder.cpp" );
|
||||
builder_print_fmt( & src, generation_notice );
|
||||
@ -271,19 +253,17 @@ int gen_main()
|
||||
builder_print( & src, builder );
|
||||
builder_print_fmt( & src, "\nGEN_NS_END\n" );
|
||||
builder_write( & src);
|
||||
|
||||
}
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.hpp" );
|
||||
Code scanner = scan_file( "auxillary/scanner.hpp" );
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.hpp" );
|
||||
|
||||
Builder header = builder_open( "gen/gen.scanner.hpp" );
|
||||
builder_print_fmt( & header, generation_notice );
|
||||
builder_print_fmt( & header, "#pragma once\n\n" );
|
||||
builder_print( & header, def_include( txt("gen.hpp") ) );
|
||||
builder_print_fmt( & header, "\nGEN_NS_BEGIN\n" );
|
||||
builder_print( & header, parsing );
|
||||
builder_print( & header, scanner );
|
||||
builder_print_fmt( & header, "\nGEN_NS_END\n" );
|
||||
builder_write(& header);
|
||||
@ -291,14 +271,12 @@ int gen_main()
|
||||
|
||||
// gen_scanner.cpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.cpp" );
|
||||
Code scanner = scan_file( "auxillary/scanner.cpp" );
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.cpp" );
|
||||
|
||||
Builder src = builder_open( "gen/gen.scanner.cpp" );
|
||||
builder_print_fmt( & src, generation_notice );
|
||||
builder_print( & src, def_include( txt("gen.scanner.hpp") ) );
|
||||
builder_print_fmt( & src, "\nGEN_NS_BEGIN\n" );
|
||||
builder_print( & src, parsing );
|
||||
builder_print( & src, scanner );
|
||||
builder_print_fmt( & src, "GEN_NS_END\n" );
|
||||
builder_write( & src);
|
@ -15,4 +15,4 @@ If using the library's provided build scripts:
|
||||
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> singleheader
|
||||
```
|
||||
```
|
||||
|
@ -3,17 +3,23 @@
|
||||
|
||||
See Readme.md for more information from the project repository.
|
||||
|
||||
Public Address:
|
||||
https://github.com/Ed94/gencpp
|
||||
|
||||
This is a single header variant of the library.
|
||||
Define GEN_IMPLEMENTATION before including this file in a single compilation unit.
|
||||
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha !
|
||||
! ============================================================================================ !
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION !
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL !
|
||||
! ============================================================================================ !
|
||||
Public Address:
|
||||
https://github.com/Ed94/gencpp --------------------------------------------------------------.
|
||||
| _____ _____ _ _ |
|
||||
| / ____) / ____} | | | |
|
||||
| | / ___ ___ _ __ ___ _ __ _ __ | {___ | |__ _ _, __ _, ___ __| | |
|
||||
| | |{_ |/ _ \ '_ \ / __} '_ l| '_ l `\___ \| __/ _` |/ _` |/ _ \/ _` | |
|
||||
| | l__j | ___/ | | | {__; |+l } |+l | ____) | l| (_| | {_| | ___/ (_| | |
|
||||
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
|
||||
| Singleheader | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha |
|
||||
! ============================================================================================ |
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |
|
||||
! ============================================================================================ /
|
||||
*/
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
|
@ -2,20 +2,15 @@
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
#include "helpers/helper.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "dependencies/parsing.cpp"
|
||||
#include "helpers/base_codegen.hpp"
|
||||
#include "helpers/misc.hpp"
|
||||
GEN_NS_END
|
||||
|
||||
#include "auxillary/builder.hpp"
|
||||
#include "auxillary/builder.cpp"
|
||||
#include "auxillary/scanner.hpp"
|
||||
|
||||
#include <cstdlib> // for system()
|
||||
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
@ -49,49 +44,20 @@ global bool generate_builder = true;
|
||||
global bool generate_editor = true;
|
||||
global bool generate_scanner = true;
|
||||
|
||||
void format_file( char const* path )
|
||||
{
|
||||
String resolved_path = String::make(GlobalAllocator, to_str(path));
|
||||
#define path_format_style "../scripts/.clang-format "
|
||||
#define scratch_file "gen/scratch.hpp"
|
||||
#define path_base "../base/"
|
||||
|
||||
String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
|
||||
style_arg.append("../scripts/.clang-format ");
|
||||
|
||||
// Need to execute clang format on the generated file to get it to match the original.
|
||||
#define clang_format "clang-format "
|
||||
#define cf_format_inplace "-i "
|
||||
#define cf_verbose "-verbose "
|
||||
String command = String::make( GlobalAllocator, clang_format );
|
||||
command.append( cf_format_inplace );
|
||||
command.append( cf_verbose );
|
||||
command.append( style_arg );
|
||||
command.append( resolved_path );
|
||||
log_fmt("\tRunning clang-format on file:\n");
|
||||
system( command );
|
||||
log_fmt("\tclang-format finished reformatting.\n");
|
||||
#undef cf_cmd
|
||||
#undef cf_format_inplace
|
||||
#undef cf_style
|
||||
#undef cf_verbse
|
||||
}
|
||||
|
||||
Code dump_to_scratch_and_retireve( Code code )
|
||||
{
|
||||
Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
|
||||
ecode_file_temp.print(code);
|
||||
ecode_file_temp.write();
|
||||
format_file("gen/scratch.hpp");
|
||||
Code result = scan_file( "gen/scratch.hpp" );
|
||||
remove("gen/scratch.hpp");
|
||||
return result;
|
||||
Code format( Code code ) {
|
||||
return code_refactor_and_format(code, scratch_file, nullptr, path_format_style );
|
||||
}
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
#define project_dir "../project/"
|
||||
gen::init();
|
||||
|
||||
Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" );
|
||||
Code push_ignores = scan_file( path_base "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( path_base "helpers/pop_ignores.inline.hpp" );
|
||||
Code single_header_start = scan_file( "components/header_start.hpp" );
|
||||
|
||||
Builder
|
||||
@ -106,18 +72,18 @@ int gen_main()
|
||||
|
||||
if ( generate_gen_dep )
|
||||
{
|
||||
Code platform = scan_file( project_dir "dependencies/platform.hpp" );
|
||||
Code macros = scan_file( project_dir "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( project_dir "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( project_dir "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( project_dir "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.hpp" );
|
||||
Code platform = scan_file( path_base "dependencies/platform.hpp" );
|
||||
Code macros = scan_file( path_base "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( path_base "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( path_base "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( path_base "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( path_base "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print( platform );
|
||||
@ -135,11 +101,8 @@ int gen_main()
|
||||
header.print( filesystem );
|
||||
header.print( timing );
|
||||
|
||||
if ( generate_scanner )
|
||||
{
|
||||
header.print_fmt( "\n#pragma region Parsing\n" );
|
||||
header.print( scan_file( project_dir "dependencies/parsing.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Parsing\n\n" );
|
||||
if ( generate_scanner ) {
|
||||
header.print( scan_file( path_base "dependencies/parsing.hpp" ) );
|
||||
}
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
@ -147,17 +110,17 @@ int gen_main()
|
||||
header.print( fmt_newline );
|
||||
}
|
||||
|
||||
Code types = scan_file( project_dir "components/types.hpp" );
|
||||
Code ast = scan_file( project_dir "components/ast.hpp" );
|
||||
Code ast_types = scan_file( project_dir "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( project_dir "components/code_types.hpp" );
|
||||
Code interface = scan_file( project_dir "components/interface.hpp" );
|
||||
Code inlines = scan_file( project_dir "components/inlines.hpp" );
|
||||
Code header_end = scan_file( project_dir "components/header_end.hpp" );
|
||||
Code types = scan_file( path_base "components/types.hpp" );
|
||||
Code ast = scan_file( path_base "components/ast.hpp" );
|
||||
Code ast_types = scan_file( path_base "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( path_base "components/code_types.hpp" );
|
||||
Code interface = scan_file( path_base "components/interface.hpp" );
|
||||
Code inlines = scan_file( path_base "components/inlines.hpp" );
|
||||
Code header_end = scan_file( path_base "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode ( project_dir "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" );
|
||||
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( path_base "enums/ESpecifier.csv" );
|
||||
CodeBody ast_inlines = gen_ast_inlines();
|
||||
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n" );
|
||||
@ -165,11 +128,11 @@ int gen_main()
|
||||
header.print_fmt("#pragma region Types\n");
|
||||
header.print( types );
|
||||
header.print( fmt_newline );
|
||||
header.print( dump_to_scratch_and_retireve( ecode ));
|
||||
header.print( format( ecode ));
|
||||
header.print( fmt_newline );
|
||||
header.print( dump_to_scratch_and_retireve( eoperator ));
|
||||
header.print( format( eoperator ));
|
||||
header.print( fmt_newline );
|
||||
header.print( dump_to_scratch_and_retireve( especifier ));
|
||||
header.print( format( especifier ));
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
|
||||
@ -183,17 +146,14 @@ int gen_main()
|
||||
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
header.print( dump_to_scratch_and_retireve( ast_inlines ));
|
||||
header.print( format( ast_inlines ));
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
|
||||
if ( generate_builder )
|
||||
{
|
||||
header.print_fmt( "\n#pragma region Builder\n" );
|
||||
header.print( scan_file( project_dir "auxillary/builder.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Builder\n" );
|
||||
if ( generate_builder ) {
|
||||
header.print( scan_file( path_base "auxillary/builder.hpp" ) );
|
||||
}
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
@ -205,15 +165,15 @@ int gen_main()
|
||||
|
||||
if ( generate_gen_dep )
|
||||
{
|
||||
Code impl_start = scan_file( project_dir "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( project_dir "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( project_dir "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.cpp" );
|
||||
Code impl_start = scan_file( path_base "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( path_base "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( path_base "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( path_base "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( path_base "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( path_base "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( path_base "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.cpp" );
|
||||
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
@ -228,10 +188,9 @@ int gen_main()
|
||||
header.print( filesystem );
|
||||
header.print( timing );
|
||||
|
||||
if ( generate_scanner )
|
||||
{
|
||||
if ( generate_scanner ) {
|
||||
header.print_fmt( "\n#pragma region Parsing\n" );
|
||||
header.print( scan_file( project_dir "dependencies/parsing.cpp" ) );
|
||||
header.print( scan_file( path_base "dependencies/parsing.cpp" ) );
|
||||
header.print_fmt( "#pragma endregion Parsing\n\n" );
|
||||
}
|
||||
|
||||
@ -239,18 +198,18 @@ int gen_main()
|
||||
header.print_fmt( roll_own_dependencies_guard_end );
|
||||
}
|
||||
|
||||
Code static_data = scan_file( project_dir "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( project_dir "components/ast.cpp" );
|
||||
Code code = scan_file( project_dir "components/code_serialization.cpp" );
|
||||
Code interface = scan_file( project_dir "components/interface.cpp" );
|
||||
Code upfront = scan_file( project_dir "components/interface.upfront.cpp" );
|
||||
Code lexer = scan_file( project_dir "components/lexer.cpp" );
|
||||
Code parser = scan_file( project_dir "components/parser.cpp" );
|
||||
Code parsing_interface = scan_file( project_dir "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( project_dir "components/interface.untyped.cpp" );
|
||||
Code static_data = scan_file( path_base "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( path_base "components/ast.cpp" );
|
||||
Code code = scan_file( path_base "components/code_serialization.cpp" );
|
||||
Code interface = scan_file( path_base "components/interface.cpp" );
|
||||
Code upfront = scan_file( path_base "components/interface.upfront.cpp" );
|
||||
Code lexer = scan_file( path_base "components/lexer.cpp" );
|
||||
Code parser = scan_file( path_base "components/parser.cpp" );
|
||||
Code parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( path_base "components/interface.untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv" );
|
||||
CodeBody etoktype = gen_etoktype( path_base "enums/ETokType.csv", path_base "enums/AttributeTokens.csv" );
|
||||
CodeNS parser_nspace = def_namespace( name(parser), def_namespace_body( args(etoktype)) );
|
||||
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
@ -266,7 +225,7 @@ int gen_main()
|
||||
header.print( interface );
|
||||
header.print( upfront );
|
||||
header.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
header.print( dump_to_scratch_and_retireve(parser_nspace) );
|
||||
header.print( format(parser_nspace) );
|
||||
header.print( lexer );
|
||||
header.print( parser );
|
||||
header.print( parsing_interface );
|
||||
@ -274,29 +233,18 @@ int gen_main()
|
||||
header.print( untyped );
|
||||
header.print_fmt( "\n#pragma endregion Interface\n\n");
|
||||
|
||||
if ( generate_builder )
|
||||
{
|
||||
header.print_fmt( "#pragma region Builder\n" );
|
||||
header.print( scan_file( project_dir "auxillary/builder.cpp" ) );
|
||||
header.print_fmt( "\n#pragma endregion Builder\n\n" );
|
||||
if ( generate_builder ) {
|
||||
header.print( scan_file( path_base "auxillary/builder.cpp" ) );
|
||||
}
|
||||
|
||||
// Scanner header depends on implementation
|
||||
if ( generate_scanner )
|
||||
{
|
||||
header.print_fmt( "\n#pragma region Scanner\n" );
|
||||
header.print( scan_file( project_dir "auxillary/scanner.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Scanner\n\n" );
|
||||
if ( generate_scanner ) {
|
||||
header.print( scan_file( path_base "auxillary/scanner.hpp" ) );
|
||||
}
|
||||
|
||||
#if 0
|
||||
if ( generate_scanner )
|
||||
{
|
||||
header.print_fmt( "#pragma region Scanner\n\n" );
|
||||
header.print( scan_file( project_dir "auxillary/scanner.cpp" ) );
|
||||
header.print_fmt( "#pragma endregion Scanner\n\n" );
|
||||
if ( generate_scanner ) {
|
||||
header.print( scan_file( path_base "auxillary/scanner.cpp" ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n");
|
||||
|
||||
@ -308,5 +256,4 @@ int gen_main()
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
#undef project_dir
|
||||
}
|
||||
|
@ -2,22 +2,15 @@
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
#include "helpers/helper.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "helpers/push_container_defines.inline.hpp"
|
||||
#include "dependencies/parsing.cpp"
|
||||
#include "helpers/pop_container_defines.inline.hpp"
|
||||
#include "helpers/base_codegen.hpp"
|
||||
#include "helpers/misc.hpp"
|
||||
GEN_NS_END
|
||||
|
||||
#include "auxillary/builder.hpp"
|
||||
#include "auxillary/builder.cpp"
|
||||
#include "auxillary/scanner.hpp"
|
||||
|
||||
#include <cstdlib> // for system()
|
||||
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
@ -52,49 +45,20 @@ global bool generate_builder = true;
|
||||
global bool generate_editor = true;
|
||||
global bool generate_scanner = true;
|
||||
|
||||
void format_file( char const* path )
|
||||
{
|
||||
String resolved_path = String::make(GlobalAllocator, to_strc_from_c_str(path));
|
||||
#define path_format_style "../scripts/.clang-format "
|
||||
#define scratch_file "gen/scratch.hpp"
|
||||
#define path_base "../base/"
|
||||
|
||||
String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
|
||||
style_arg.append("../scripts/.clang-format ");
|
||||
|
||||
// Need to execute clang format on the generated file to get it to match the original.
|
||||
#define clang_format "clang-format "
|
||||
#define cf_format_inplace "-i "
|
||||
#define cf_verbose "-verbose "
|
||||
String command = String::make( GlobalAllocator, clang_format );
|
||||
command.append( cf_format_inplace );
|
||||
command.append( cf_verbose );
|
||||
command.append( style_arg );
|
||||
command.append( resolved_path );
|
||||
log_fmt("\tRunning clang-format on file:\n");
|
||||
system( command );
|
||||
log_fmt("\tclang-format finished reformatting.\n");
|
||||
#undef cf_cmd
|
||||
#undef cf_format_inplace
|
||||
#undef cf_style
|
||||
#undef cf_verbse
|
||||
}
|
||||
|
||||
Code dump_to_scratch_and_retireve( Code code )
|
||||
{
|
||||
Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
|
||||
ecode_file_temp.print(code);
|
||||
ecode_file_temp.write();
|
||||
format_file("gen/scratch.hpp");
|
||||
Code result = scan_file( "gen/scratch.hpp" );
|
||||
remove("gen/scratch.hpp");
|
||||
return result;
|
||||
Code format( Code code ) {
|
||||
return code_refactor_and_format(code, scratch_file, nullptr, path_format_style );
|
||||
}
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
#define project_dir "../project/"
|
||||
gen::init();
|
||||
|
||||
Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" );
|
||||
Code push_ignores = scan_file( path_base "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( path_base "helpers/pop_ignores.inline.hpp" );
|
||||
|
||||
Code ue_forceinline = code_str(FORCEINLINE);
|
||||
// Code
|
||||
@ -103,7 +67,7 @@ int gen_main()
|
||||
{
|
||||
CodeBody macros = def_body( CT_Global_Body );
|
||||
{
|
||||
FileContents content = file_read_contents( GlobalAllocator, true, project_dir "dependencies/macros.hpp" );
|
||||
FileContents content = file_read_contents( GlobalAllocator, true, path_base "dependencies/macros.hpp" );
|
||||
CodeBody ori_macros = parse_global_body( StrC { content.size, (char const*)content.data });
|
||||
|
||||
for (Code code = ori_macros.begin();
|
||||
@ -132,17 +96,17 @@ int gen_main()
|
||||
}
|
||||
}
|
||||
|
||||
Code platform = scan_file( project_dir "dependencies/platform.hpp" );
|
||||
Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( project_dir "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( project_dir "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( project_dir "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.hpp" );
|
||||
Code platform = scan_file( path_base "dependencies/platform.hpp" );
|
||||
Code basic_types = scan_file( path_base "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( path_base "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( path_base "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( path_base "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open("gen/gen.dep.hpp");
|
||||
@ -153,7 +117,7 @@ int gen_main()
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( fmt_newline);
|
||||
header.print( dump_to_scratch_and_retireve(macros) );
|
||||
header.print( format(macros) );
|
||||
header.print( basic_types );
|
||||
header.print( debug );
|
||||
header.print( memory );
|
||||
@ -173,15 +137,15 @@ int gen_main()
|
||||
|
||||
// gen_dep.cpp
|
||||
{
|
||||
Code src_start = scan_file( project_dir "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( project_dir "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( project_dir "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.cpp" );
|
||||
Code src_start = scan_file( path_base "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( path_base "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( path_base "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( path_base "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( path_base "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( path_base "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( path_base "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.dep.cpp" );
|
||||
@ -209,18 +173,18 @@ int gen_main()
|
||||
|
||||
// gen.hpp
|
||||
{
|
||||
Code header_start = scan_file( "components/header_start.hpp" );
|
||||
Code types = scan_file( project_dir "components/types.hpp" );
|
||||
Code ast = scan_file( project_dir "components/ast.hpp" );
|
||||
Code ast_types = scan_file( project_dir "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( project_dir "components/code_types.hpp" );
|
||||
Code interface = scan_file( project_dir "components/interface.hpp" );
|
||||
Code inlines = scan_file( project_dir "components/inlines.hpp" );
|
||||
Code header_end = scan_file( project_dir "components/header_end.hpp" );
|
||||
Code header_start = scan_file( "components/header_start.hpp" );
|
||||
Code types = scan_file( path_base "components/types.hpp" );
|
||||
Code ast = scan_file( path_base "components/ast.hpp" );
|
||||
Code ast_types = scan_file( path_base "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( path_base "components/code_types.hpp" );
|
||||
Code interface = scan_file( path_base "components/interface.hpp" );
|
||||
Code inlines = scan_file( path_base "components/inlines.hpp" );
|
||||
Code header_end = scan_file( path_base "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode ( project_dir "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" );
|
||||
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( path_base "enums/ESpecifier.csv" );
|
||||
CodeBody ast_inlines = gen_ast_inlines();
|
||||
|
||||
Builder
|
||||
@ -235,11 +199,11 @@ int gen_main()
|
||||
header.print_fmt( "#pragma region Types\n" );
|
||||
header.print( types );
|
||||
header.print( fmt_newline );
|
||||
header.print( dump_to_scratch_and_retireve(ecode) );
|
||||
header.print( format(ecode) );
|
||||
header.print( fmt_newline );
|
||||
header.print( dump_to_scratch_and_retireve(eoperator) );
|
||||
header.print( format(eoperator) );
|
||||
header.print( fmt_newline );
|
||||
header.print( dump_to_scratch_and_retireve(especifier) );
|
||||
header.print( format(especifier) );
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "#pragma endregion Types\n\n" );
|
||||
|
||||
@ -254,7 +218,7 @@ int gen_main()
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
header.print( fmt_newline );
|
||||
header.print( dump_to_scratch_and_retireve(ast_inlines) );
|
||||
header.print( format(ast_inlines) );
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
@ -267,22 +231,21 @@ int gen_main()
|
||||
// gen.cpp
|
||||
{
|
||||
Code src_start = scan_file( "components/src_start.cpp" );
|
||||
Code static_data = scan_file( project_dir "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( project_dir "components/ast.cpp" );
|
||||
Code code_serialization = scan_file( project_dir "components/code_serialization.cpp" );
|
||||
Code interface = scan_file( project_dir "components/interface.cpp" );
|
||||
Code upfront = scan_file( project_dir "components/interface.upfront.cpp" );
|
||||
Code lexer = scan_file( project_dir "components/lexer.cpp" );
|
||||
Code parser = scan_file( project_dir "components/parser.cpp" );
|
||||
Code parsing_interface = scan_file( project_dir "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( project_dir "components/interface.untyped.cpp" );
|
||||
Code static_data = scan_file( path_base "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( path_base "components/ast.cpp" );
|
||||
Code code_serialization = scan_file( path_base "components/code_serialization.cpp" );
|
||||
Code interface = scan_file( path_base "components/interface.cpp" );
|
||||
Code upfront = scan_file( path_base "components/interface.upfront.cpp" );
|
||||
Code lexer = scan_file( path_base "components/lexer.cpp" );
|
||||
Code parser = scan_file( path_base "components/parser.cpp" );
|
||||
Code parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( path_base "components/interface.untyped.cpp" );
|
||||
|
||||
// Note(Ed): The Attribute tokens need to be expanded and regenerated on a per-project/installation of this library for a specific codebase of Unreal.
|
||||
// We can support an arbitrary set of modules or plugin apis for parsing
|
||||
// but its up to the user to define them all (This will just provide whats I've used up till now).
|
||||
CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", "enums/AttributeTokens.csv" );
|
||||
CodeNS nspaced_etoktype = def_namespace( name(parser), def_namespace_body( args(etoktype)) );
|
||||
CodeBody etoktype = gen_etoktype( path_base "enums/ETokType.csv", "enums/AttributeTokens.csv" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.cpp" );
|
||||
@ -305,7 +268,7 @@ int gen_main()
|
||||
src.print( interface );
|
||||
src.print( upfront );
|
||||
src.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
src.print( dump_to_scratch_and_retireve(nspaced_etoktype) );
|
||||
src.print( format(etoktype) );
|
||||
src.print( lexer );
|
||||
src.print( parser );
|
||||
src.print( parsing_interface );
|
||||
@ -320,7 +283,7 @@ int gen_main()
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code builder = scan_file( project_dir "auxillary/builder.hpp" );
|
||||
Code builder = scan_file( path_base "auxillary/builder.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.builder.hpp" );
|
||||
@ -339,7 +302,7 @@ int gen_main()
|
||||
|
||||
// gen_builder.cpp
|
||||
{
|
||||
Code builder = scan_file( project_dir "auxillary/builder.cpp" );
|
||||
Code builder = scan_file( path_base "auxillary/builder.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.builder.cpp" );
|
||||
@ -357,8 +320,8 @@ int gen_main()
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code parsing = scan_file( project_dir "dependencies/parsing.hpp" );
|
||||
Code scanner = scan_file( project_dir "auxillary/scanner.hpp" );
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.hpp" );
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.scanner.hpp" );
|
||||
@ -378,8 +341,8 @@ int gen_main()
|
||||
|
||||
// gen.scanner.cpp
|
||||
{
|
||||
Code parsing = scan_file( project_dir "dependencies/parsing.cpp" );
|
||||
Code scanner = scan_file( project_dir "auxillary/scanner.cpp" );
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.cpp" );
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.scanner.cpp" );
|
||||
|
@ -1,9 +1,23 @@
|
||||
# Format Style Options - Created with Clang Power Tools
|
||||
---
|
||||
AttributeMacros: [enum_underlying]
|
||||
StatementMacros: [GEN_NS_BEGIN, GEN_NS_END, GEN_NS_PARSER_BEGIN, GEN_NS_PARSER_END, GEN_API_C_BEGIN, GEN_API_C_END]
|
||||
|
||||
# AttributeMacros: [
|
||||
# ]
|
||||
StatementMacros: [
|
||||
GEN_NS_BEGIN,
|
||||
GEN_NS_END,
|
||||
GEN_NS_PARSER_BEGIN,
|
||||
GEN_NS_PARSER_END,
|
||||
GEN_API_C_BEGIN,
|
||||
GEN_API_C_END,
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT
|
||||
]
|
||||
Macros:
|
||||
- enum_underlying(type)=type
|
||||
- gen_enum_underlying(type)=type
|
||||
|
||||
TypenameMacros: [Array, Hashtable]
|
||||
SkipMacroDefinitionBody: true
|
||||
SkipMacroDefinitionBody: false
|
||||
|
||||
AccessModifierOffset: -4
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
|
||||
$misc = Join-Path $PSScriptRoot 'helpers/misc.psm1'
|
||||
$refactor_c_library = Join-Path $PSScriptRoot 'refactor_c_library.ps1'
|
||||
$refactor_unreal = Join-Path $PSScriptRoot 'refactor_unreal.ps1'
|
||||
$incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1'
|
||||
$vendor_toolchain = Join-Path $PSScriptRoot 'helpers/vendor_toolchain.ps1'
|
||||
@ -20,7 +19,7 @@ Push-Location $path_root
|
||||
$release = $null
|
||||
$verbose = $false
|
||||
$base = $false
|
||||
[bool] $segemented = $false
|
||||
[bool] $segmented = $false
|
||||
[bool] $singleheader = $false
|
||||
[bool] $c_library = $false
|
||||
[bool] $unreal = $false
|
||||
@ -37,7 +36,7 @@ if ( $args ) { $args | ForEach-Object {
|
||||
"release" { $release = $true }
|
||||
"debug" { $release = $false }
|
||||
"base" { $base = $true }
|
||||
"segemented" { $segemented = $true }
|
||||
"segmented" { $segmented = $true }
|
||||
"singleheader" { $singleheader = $true }
|
||||
"c_library" { $c_library = $true }
|
||||
"unreal" { $unreal = $true }
|
||||
@ -115,13 +114,13 @@ if ( $base )
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$includes = @( $path_project)
|
||||
$includes = @( $path_base)
|
||||
$unit = join-path $path_base "base.cpp"
|
||||
$executable = join-path $path_build "base.exe"
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_project
|
||||
Push-Location $path_base
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning base"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
@ -129,7 +128,7 @@ if ( $base )
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`bbase completed in $($time_taken.TotalMilliseconds) ms"
|
||||
write-host "`nbase completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
@ -153,13 +152,13 @@ if ( $segmented )
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$includes = @( $path_project)
|
||||
$includes = @( $path_base)
|
||||
$unit = join-path $path_segmented "segmented.cpp"
|
||||
$executable = join-path $path_build "segmented.exe"
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_project
|
||||
Push-Location $path_segmented
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning segmented"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
@ -184,7 +183,7 @@ if ( $singleheader )
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
|
||||
$includes = @( $path_project )
|
||||
$includes = @( $path_base )
|
||||
$unit = join-path $path_singleheader "singleheader.cpp"
|
||||
$executable = join-path $path_build "singleheader.exe"
|
||||
|
||||
@ -222,7 +221,7 @@ if ( $c_library )
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
|
||||
$includes = @( $path_project )
|
||||
$includes = @( $path_base )
|
||||
$unit = join-path $path_c_library "c_library.cpp"
|
||||
$executable = join-path $path_build "c_library.exe"
|
||||
|
||||
@ -247,8 +246,7 @@ if ( $c_library )
|
||||
}
|
||||
Pop-Location
|
||||
|
||||
. $refactor_c_library
|
||||
|
||||
$includes = @( $path_c_library )
|
||||
$unit = join-path $path_c_library "gen.c"
|
||||
$executable = join-path $path_build "gen_c_library_test.exe"
|
||||
|
||||
@ -289,7 +287,7 @@ if ( $unreal )
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
|
||||
$includes = @( $path_project )
|
||||
$includes = @( $path_base )
|
||||
$unit = join-path $path_unreal "unreal.cpp"
|
||||
$executable = join-path $path_build "unreal.exe"
|
||||
|
||||
|
@ -1,10 +1,19 @@
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$misc = Join-Path $PSScriptRoot 'helpers/misc.psm1'
|
||||
Import-Module $misc
|
||||
|
||||
$path_root = Get-ScriptRepoRoot
|
||||
$path_base = Join-Path $path_root base
|
||||
$path_base_build = Join-Path $path_base build
|
||||
$path_singleheader = Join-Path $path_root singleheader
|
||||
$path_c_library = Join-Path $path_root gen_c_library
|
||||
$path_c_library_build = Join-Path $path_c_library build
|
||||
$path_c_library_gen = Join-Path $path_c_library gen
|
||||
$path_segmented = Join-Path $path_root gen_segmented
|
||||
$path_segmented_build = Join-Path $path_segmented build
|
||||
$path_segmented_gen = Join-Path $path_segmented gen
|
||||
$path_singleheader = Join-Path $path_root gen_singleheader
|
||||
$path_singleheader_build = Join-Path $path_singleheader build
|
||||
$path_singleheader_gen = Join-Path $path_singleheader gen
|
||||
$path_unreal = Join-Path $paht_root unreal
|
||||
$path_unreal = Join-Path $path_root gen_unreal_engine
|
||||
$path_unreal_build = Join-Path $path_unreal build
|
||||
$path_unreal_gen = Join-Path $path_unreal gen
|
||||
$path_test = Join-Path $path_root test
|
||||
@ -13,30 +22,45 @@ $path_test_gen = Join-Path $path_test gen
|
||||
$path_x64 = Join-Path $path_root x64
|
||||
$path_release = Join-Path $path_root release
|
||||
|
||||
if ( Test-Path $path_project_build) {
|
||||
Remove-Item $path_project_build -Recurse
|
||||
if ( Test-Path $path_base_build) {
|
||||
Remove-Item $path_base_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_project_gen ) {
|
||||
Remove-Item $path_project_gen -Recurse
|
||||
if ( Test-Path $path_segmented_build) {
|
||||
Remove-Item $path_segmented_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_c_library_build ) {
|
||||
Remove-Item $path_c_library_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_c_library_gen ) {
|
||||
Remove-Item $path_c_library_gen -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_segmented_build) {
|
||||
Remove-Item $path_segmented_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_segmented_gen ) {
|
||||
Remove-Item $path_segmented_gen -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_singleheader_build) {
|
||||
Remove-Item $path_singleheader_build -Recurse
|
||||
Remove-Item $path_singleheader_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_singleheader_gen ) {
|
||||
Remove-Item $path_singleheader_gen -Recurse
|
||||
Remove-Item $path_singleheader_gen -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_unreal ) {
|
||||
Remove-Item $path_unreal_build -Recurse
|
||||
if ( Test-Path $path_unreal_build ) {
|
||||
Remove-Item $path_unreal_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_unreal_gen ) {
|
||||
Remove-Item $path_unreal_gen -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_test_build ) {
|
||||
Remove-Item $path_test_build -Recurse
|
||||
Remove-Item $path_test_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_test_gen ) {
|
||||
Remove-Item $path_test_gen -Recurse
|
||||
Remove-Item $path_test_gen -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_x64) {
|
||||
Remove-Item $path_x64 -Recurse
|
||||
Remove-Item $path_x64 -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_release ) {
|
||||
Remove-Item $path_release -Recurse
|
||||
Remove-Item $path_release -Recurse -Verbose
|
||||
}
|
||||
|
@ -266,7 +266,7 @@
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name="gen::AST_Param">
|
||||
<Type Name="gen::AST_Params">
|
||||
<DisplayString>{Name} Type: {Type}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="ValueType">ValueType</Item>
|
||||
@ -553,7 +553,7 @@
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<Type Name="gen::CodeParam">
|
||||
<Type Name="gen::CodeParams">
|
||||
<DisplayString Condition="ast == nullptr">Null</DisplayString>
|
||||
<DisplayString Condition="ast != nullptr">{ast->Name} {ast->Type}</DisplayString>
|
||||
<Expand>
|
||||
|
@ -1,24 +1,28 @@
|
||||
cls
|
||||
$misc = Join-Path $PSScriptRoot 'helpers/misc.psm1'
|
||||
Import-Module $misc
|
||||
|
||||
$build = Join-Path $PSScriptRoot 'build.ci.ps1'
|
||||
|
||||
if ( $IsWindows ) {
|
||||
& $build release msvc bootstrap singleheader unreal msvc debug
|
||||
& $build release msvc base segmented singleheader unreal c_library msvc debug
|
||||
}
|
||||
else {
|
||||
& $build release clang bootstrap singleheader unreal msvc debug
|
||||
& $build release clang base segmented singleheader unreal c_library msvc debug
|
||||
}
|
||||
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_docs = Join-Path $path_root docs
|
||||
$path_project = Join-Path $path_root project
|
||||
$path_project_gen = Join-Path $path_project gen
|
||||
$path_singleheader = Join-Path $path_root singleheader
|
||||
$path_singleheader_gen = Join-Path $path_singleheader gen
|
||||
$path_unreal = Join-Path $path_root unreal_engine
|
||||
$path_unreal_gen = Join-Path $path_unreal gen
|
||||
$path_release = Join-Path $path_root release
|
||||
$path_release_content = Join-Path $path_release content
|
||||
$path_root = Get-ScriptRepoRoot
|
||||
$path_docs = Join-Path $path_root docs
|
||||
$path_base = Join-Path $path_root base
|
||||
$path_c_library = Join-Path $path_root gen_c_library
|
||||
$path_c_library_gen = Join-Path $path_c_library gen
|
||||
$path_segmented = Join-Path $path_root gen_segmented
|
||||
$path_segmented_gen = Join-Path $path_segmented gen
|
||||
$path_singleheader = Join-Path $path_root gen_singleheader
|
||||
$path_singleheader_gen = Join-Path $path_singleheader gen
|
||||
$path_unreal = Join-Path $path_root gen_unreal_engine
|
||||
$path_unreal_gen = Join-Path $path_unreal gen
|
||||
$path_release = Join-Path $path_root release
|
||||
$path_release_content = Join-Path $path_release content
|
||||
|
||||
if ( -not(Test-Path $path_release) ) {
|
||||
New-Item -ItemType Directory -Path $path_release
|
||||
@ -47,33 +51,53 @@ function prep-ReleaseContent()
|
||||
|
||||
# Singleheader
|
||||
prep-ReleaseContent
|
||||
Copy-Item -Path $path_singleheader_gen\gen.hpp -Destination $path_release_content\gen.hpp
|
||||
Copy-Item -Verbose -Path $path_singleheader\Readme.md -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_singleheader_gen\gen.hpp -Destination $path_release_content
|
||||
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_singleheader.zip -Force
|
||||
Remove-Item -Path $path_release_content -Recurse
|
||||
|
||||
# Segmented
|
||||
prep-ReleaseContent
|
||||
Copy-Item -Path $path_project_gen\* -Destination $path_release_content
|
||||
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_segmented.zip -Force
|
||||
Copy-Item -Verbose -Path $path_segmented\Readme.md -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_segmented_gen\* -Destination $path_release_content
|
||||
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_segmented.zip -Force
|
||||
Remove-Item -Path $path_release_content -Recurse
|
||||
|
||||
# Unreal
|
||||
prep-ReleaseContent
|
||||
Copy-Item -Path $path_unreal_gen\* -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_unreal\Readme.md -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_unreal_gen\* -Destination $path_release_content
|
||||
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_unreal.zip -Force
|
||||
Remove-Item -Path $path_release_content -Recurse
|
||||
|
||||
# As Is
|
||||
# C Library Singleheader
|
||||
prep-ReleaseContent
|
||||
Copy-Item -Verbose -Path $path_c_library\Readme.md -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_c_library_gen\gen_singleheader.h -Destination $path_release_content\gen.h
|
||||
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_c11_singleheader.zip -Force
|
||||
Remove-Item -Path $path_release_content -Recurse
|
||||
|
||||
# C Library Segmented
|
||||
prep-ReleaseContent
|
||||
Copy-Item -Verbose -Path $path_c_library\Readme.md -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_c_library_gen\gen.dep.c -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_c_library_gen\gen.dep.h -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_c_library_gen\gen.c -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_c_library_gen\gen.h -Destination $path_release_content
|
||||
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_c11_segmented.zip -Force
|
||||
Remove-Item -Path $path_release_content -Recurse
|
||||
|
||||
# Base
|
||||
|
||||
prep-ReleaseContent
|
||||
Copy-Item -Verbose -Path $path_project\gen.hpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_project\gen.cpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_project\gen.dep.hpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_project\gen.dep.cpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_project\auxillary\builder.hpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_project\auxillary\builder.cpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_project\auxillary\scanner.hpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_project\auxillary\scanner.cpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_base\gen.hpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_base\gen.cpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_base\gen.dep.hpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_base\gen.dep.cpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_base\auxillary\builder.hpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_base\auxillary\builder.cpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_base\auxillary\scanner.hpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_base\auxillary\scanner.cpp -Destination $path_release_content\auxillary
|
||||
|
||||
New-Item -ItemType Directory -Force -Path "$path_release_content\components"
|
||||
New-Item -ItemType Directory -Force -Path "$path_release_content\components\gen"
|
||||
@ -81,11 +105,11 @@ New-Item -ItemType Directory -Force -Path "$path_release_content\dependencies"
|
||||
New-Item -ItemType Directory -Force -Path "$path_release_content\enums"
|
||||
New-Item -ItemType Directory -Force -Path "$path_release_content\helpers"
|
||||
|
||||
Get-ChildItem -Verbose -Path "$path_project\components\*" -Include *.cpp,*.hpp | Copy-Item -Destination "$path_release_content\components"
|
||||
Get-ChildItem -Verbose -Path "$path_project\components\gen\*" -Include *.cpp,*.hpp | Copy-Item -Destination "$path_release_content\components\gen"
|
||||
Get-ChildItem -Verbose -Path "$path_project\dependencies\*" -Include *.cpp,*.hpp | Copy-Item -Destination "$path_release_content\dependencies"
|
||||
Get-ChildItem -Verbose -Path "$path_project\enums\*" -Include *.csv | Copy-Item -Destination "$path_release_content\enums"
|
||||
Get-ChildItem -Verbose -Path "$path_project\helpers\*" -Include *.cpp,*.hpp | Copy-Item -Destination "$path_release_content\helpers"
|
||||
Get-ChildItem -Verbose -Path "$path_base\components\*" -Include *.cpp,*.hpp | Copy-Item -Verbose -Destination "$path_release_content\components"
|
||||
Get-ChildItem -Verbose -Path "$path_base\components\gen\*" -Include *.cpp,*.hpp | Copy-Item -Verbose -Destination "$path_release_content\components\gen"
|
||||
Get-ChildItem -Verbose -Path "$path_base\dependencies\*" -Include *.cpp,*.hpp | Copy-Item -Verbose -Destination "$path_release_content\dependencies"
|
||||
Get-ChildItem -Verbose -Path "$path_base\enums\*" -Include *.csv | Copy-Item -Verbose -Destination "$path_release_content\enums"
|
||||
Get-ChildItem -Verbose -Path "$path_base\helpers\*" -Include *.cpp,*.hpp | Copy-Item -Verbose -Destination "$path_release_content\helpers"
|
||||
|
||||
Compress-Archive -Path $path_release_content\** -DestinationPath $path_release\gencpp_as_is.zip -Force
|
||||
Compress-Archive -Path $path_release_content\** -DestinationPath $path_release\gencpp_base.zip -Force
|
||||
Remove-Item -Path $path_release_content -Recurse
|
||||
|
@ -1,59 +0,0 @@
|
||||
[string] $format = $false
|
||||
|
||||
foreach ( $arg in $args )
|
||||
{
|
||||
if ( $arg -eq "format" )
|
||||
{
|
||||
$format = $true
|
||||
}
|
||||
}
|
||||
|
||||
[string[]] $include = 'gen.h'
|
||||
[string[]] $exclude
|
||||
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_project = Join-Path $path_root project
|
||||
$path_scripts = Join-Path $path_root scripts
|
||||
$path_helpers = Join-Path $path_scripts helpers
|
||||
$path_c_library = Join-Path $path_root gen_c_library
|
||||
$path_c_library_gen = Join-Path $path_c_library gen
|
||||
|
||||
$file_spec = Join-Path $path_c_library c_library.refactor
|
||||
|
||||
# Gather the files to be formatted.
|
||||
$targetFiles = @()
|
||||
$targetFiles += Get-ChildItem -Recurse -Path $path_c_library_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName
|
||||
# $targetFiles += Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName
|
||||
# $targetFiles += Get-ChildItem -Recurse -Path $path_singleheader_comp -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName
|
||||
|
||||
# Format the files.
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file:./.clang-format' # Search for a .clang-format file in the parent directory of the source file.
|
||||
'-verbose'
|
||||
)
|
||||
|
||||
write-host "Beginning refactor...`n"
|
||||
|
||||
Write-Host $targetFiles
|
||||
|
||||
$refactorParams = @(
|
||||
"-debug",
|
||||
"-num=$($targetFiles.Count)"
|
||||
"-src=$($targetFiles)",
|
||||
"-spec=$($file_spec)"
|
||||
)
|
||||
|
||||
$refactor = join-path $path_helpers refactor.exe
|
||||
write-host "& $refactor $refactorParams"
|
||||
& $refactor $refactorParams
|
||||
|
||||
Write-Host "`nRefactoring complete`n`n"
|
||||
|
||||
if ( $format -eq $true ) {
|
||||
Write-Host "Beginning format...`n"
|
||||
|
||||
& clang-format $formatParams $targetFiles
|
||||
|
||||
Write-Host "`nFormatting complete"
|
||||
}
|
@ -36,7 +36,7 @@ $formatParams = @(
|
||||
write-host "Beginning refactor...`n"
|
||||
|
||||
$refactorParams = @(
|
||||
"-debug",
|
||||
# "-debug",
|
||||
"-num=$($targetFiles.Count)"
|
||||
"-src=$($targetFiles)",
|
||||
"-spec=$($file_spec)"
|
||||
|
@ -30,15 +30,32 @@ struct AnotherTemplate {
|
||||
T value;
|
||||
};
|
||||
|
||||
typedef decltype(nullptr) (MyClass::*InsaneComplexTypeDef)
|
||||
typedef decltype(nullptr) ( MyClass:: * InsaneComplexTypeDef )
|
||||
(
|
||||
decltype((MyEnum::VAL1 == MyEnum::VAL2) ? 1 : 2.0)(TemplateStruct<decltype(OuterStruct().unionInstance.inner), 5>::*ptr)[5][alignof(double)],
|
||||
std::function<void *(TemplateStruct<int, 10>&&, void (MyClass::*memFnPtr)(TemplateStruct<decltype(OuterStruct().unionInstance.inner)>))>,
|
||||
int (MyClass::*&refToMemFnPtr)(TemplateStruct<int, 10>),
|
||||
int (TemplateStruct<int, 10>::*memberPointer)[10],
|
||||
typename std::tuple_element<0, std::tuple<AnotherTemplate<TemplateStruct<decltype(OuterStruct().unionInstance), 3>>>>::type::*complexMember,
|
||||
template<typename U> typename AnotherTemplate<U>::*templateMember
|
||||
decltype( (MyEnum::VAL1 == MyEnum::VAL2) ? 1 : 2.0 )
|
||||
( TemplateStruct< decltype(OuterStruct().unionInstance.inner), 5> :: * ptr ) [5] [ alignof(double) ],
|
||||
std::function<
|
||||
void *
|
||||
(
|
||||
TemplateStruct<int, 10> &&,
|
||||
void ( MyClass:: * memFnPtr )(
|
||||
TemplateStruct<
|
||||
decltype(OuterStruct().unionInstance.inner)
|
||||
>
|
||||
)
|
||||
)
|
||||
>,
|
||||
int ( MyClass :: * & refToMemFnPtr )( TemplateStruct<int, 10> ) ,
|
||||
int ( TemplateStruct<int, 10>:: * memberPointer) [10],
|
||||
typename std::tuple_element<
|
||||
0,
|
||||
std::tuple<
|
||||
AnotherTemplate<
|
||||
TemplateStruct< decltype(OuterStruct().unionInstance), 3 >
|
||||
>
|
||||
>
|
||||
> :: type :: * complexMember,
|
||||
template<typename U> typename AnotherTemplate<U> :: * templateMember
|
||||
char&&...,
|
||||
)
|
||||
volatile const && noexcept;
|
||||
|
Reference in New Issue
Block a user