2023-04-03 00:55:28 -07:00
|
|
|
/*
|
|
|
|
gencpp: A simple staged metaprogramming library for C++.
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
This library is intended for small-to midsize projects.
|
2023-04-03 00:55:28 -07:00
|
|
|
|
|
|
|
AST type checking supports only a small subset of c++.
|
|
|
|
See the 'ECode' namespace and 'gen API' region to see what is supported.
|
|
|
|
|
2023-04-04 13:18:30 -07:00
|
|
|
### *WHAT IS NOT PROVIDED*
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-04 13:18:30 -07:00
|
|
|
* Macro or template generation : This library is to avoid those, adding support for them adds unnecessary complexity.
|
|
|
|
If you desire define them outside the gen_time scopes.
|
|
|
|
* Expression validation : Execution expressions are defined using the untyped string API.
|
|
|
|
There is no parse API for validating expression (possibly will add in the future)
|
2023-04-03 23:04:19 -07:00
|
|
|
* Complete file parser DSL : This isn't like the unreal header tool.
|
2023-04-05 00:03:56 -07:00
|
|
|
Code injection to file or based off a file contents is not supported by the api. However nothing is stopping you using the library for that purpose.
|
2023-04-04 13:18:30 -07:00
|
|
|
* Modern c++ (STL library) features
|
|
|
|
|
|
|
|
The AST is managed by the library and provided the user via its interface prodedures.
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
|
2023-04-04 13:18:30 -07:00
|
|
|
* ASTs are wrapped for the user in a Code struct which essentially a warpper for a AST* type.
|
|
|
|
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
|
|
|
|
|
|
|
|
Data layout of AST struct:
|
|
|
|
|
|
|
|
CodeT Type;
|
|
|
|
bool Readonly;
|
|
|
|
AST* Parent;
|
|
|
|
string Name;
|
|
|
|
string Comment;
|
|
|
|
union {
|
|
|
|
array(AST*) Entries;
|
|
|
|
string Content;
|
|
|
|
};
|
|
|
|
|
|
|
|
*`CodeT` is a typedef for `ECode::Type` which is the type of the enum.*
|
|
|
|
|
|
|
|
ASTs can be set to readonly by calling Code's lock() member function.
|
|
|
|
Adding comments is always available even if the AST is set to readonly.
|
|
|
|
|
|
|
|
### There are four sets of interfaces for Code AST generation the library provides
|
|
|
|
|
|
|
|
* Upfront
|
|
|
|
* Incremental
|
|
|
|
* Parsing
|
2023-04-03 23:04:19 -07:00
|
|
|
* Untyped
|
|
|
|
|
2023-04-04 13:18:30 -07:00
|
|
|
### Upfront Construction
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
All component ASTs must be previously constructed, and provided on creation of the code AST.
|
|
|
|
The construction will fail and return InvalidCode otherwise.
|
|
|
|
|
2023-04-04 13:18:30 -07:00
|
|
|
Interface :
|
|
|
|
|
|
|
|
* def_class
|
2023-04-05 00:03:56 -07:00
|
|
|
* def_class_body
|
|
|
|
* def_class_fwd
|
|
|
|
* def_enum
|
|
|
|
* def_enum_class
|
|
|
|
* def_enum_body
|
2023-04-03 23:04:19 -07:00
|
|
|
* def_global_body
|
|
|
|
* def_namespace
|
|
|
|
* def_namespace_body
|
2023-04-05 00:03:56 -07:00
|
|
|
* def_operator
|
|
|
|
* def_operator_fwd
|
2023-04-03 23:04:19 -07:00
|
|
|
* def_param
|
|
|
|
* def_params
|
2023-04-05 00:03:56 -07:00
|
|
|
* def_proc
|
|
|
|
* def_proc_body
|
|
|
|
* def_proc_fwd
|
2023-04-03 23:04:19 -07:00
|
|
|
* def_specifier
|
|
|
|
* def_specifiers
|
|
|
|
* def_struct
|
|
|
|
* def_struct_body
|
2023-04-05 00:03:56 -07:00
|
|
|
* def_struct_fwd
|
2023-04-03 23:04:19 -07:00
|
|
|
* def_variable
|
|
|
|
* def_type
|
2023-04-05 00:03:56 -07:00
|
|
|
* def_typedef
|
2023-04-03 23:04:19 -07:00
|
|
|
* def_using
|
|
|
|
* def_using_namespace
|
|
|
|
|
2023-04-04 13:18:30 -07:00
|
|
|
### Incremental construction
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
A Code ast is provided but only completed upfront if all components are provided.
|
2023-04-04 13:18:30 -07:00
|
|
|
Components are then added using the AST API for adding ASTs:
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
* code.add( AST* ) // Adds AST with validation.
|
|
|
|
* code.add_entry( AST* ) // Adds AST entry without validation.
|
2023-04-04 13:18:30 -07:00
|
|
|
|
|
|
|
Code ASTs may be explictly validated at anytime using Code's check() member function.
|
|
|
|
|
|
|
|
Interface :
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
* make_class
|
2023-04-05 00:03:56 -07:00
|
|
|
* make_enum
|
|
|
|
* make_enum_class
|
2023-04-03 23:04:19 -07:00
|
|
|
* make_global_body
|
|
|
|
* make_namespace
|
|
|
|
* make_operator
|
2023-04-05 00:03:56 -07:00
|
|
|
* make_params
|
|
|
|
* make_proc
|
2023-04-03 23:04:19 -07:00
|
|
|
* make_specifiers
|
|
|
|
* make_struct
|
|
|
|
* make_variable
|
|
|
|
* make_type
|
2023-04-05 00:03:56 -07:00
|
|
|
* make_typedef
|
2023-04-03 23:04:19 -07:00
|
|
|
* make_using
|
|
|
|
|
2023-04-04 13:18:30 -07:00
|
|
|
### Parse construction
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
A string provided to the API is parsed for the intended language construct.
|
|
|
|
|
2023-04-04 13:18:30 -07:00
|
|
|
Interface :
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
* parse_class
|
2023-04-05 00:03:56 -07:00
|
|
|
* parse_classes
|
|
|
|
* parse_enum
|
|
|
|
* parse_enums
|
|
|
|
* parse_global_body
|
2023-04-03 23:04:19 -07:00
|
|
|
* parse_namespace
|
2023-04-05 00:03:56 -07:00
|
|
|
* parse_namespaces
|
2023-04-03 23:04:19 -07:00
|
|
|
* parse_operator
|
2023-04-05 00:03:56 -07:00
|
|
|
* parse_operators
|
|
|
|
* parse_proc
|
|
|
|
* parse_procs
|
2023-04-03 23:04:19 -07:00
|
|
|
* parse_struct
|
2023-04-05 00:03:56 -07:00
|
|
|
* parse_strucs
|
2023-04-03 23:04:19 -07:00
|
|
|
* parse_variable
|
2023-04-05 00:03:56 -07:00
|
|
|
* parse_variables
|
2023-04-03 23:04:19 -07:00
|
|
|
* parse_type
|
2023-04-05 00:03:56 -07:00
|
|
|
* parse_typedef
|
|
|
|
* parse_typedefs
|
2023-04-03 23:04:19 -07:00
|
|
|
* parse_using
|
2023-04-05 00:03:56 -07:00
|
|
|
* parse_usings
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
|
|
|
|
This includes the assignmetn of variables; due to the library not yet supporting c/c++ expression parsing.
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
The plural variants provide an array of codes, its up to the user to add them to a body AST
|
|
|
|
(they are not auto-added to a body)
|
|
|
|
|
2023-04-04 13:18:30 -07:00
|
|
|
### Untyped constructions
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code ASTs are constructed using unvalidated strings.
|
2023-04-04 13:18:30 -07:00
|
|
|
|
|
|
|
Interface :
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
* untyped_str
|
|
|
|
* untyped_fmt
|
|
|
|
* untyped_token_fmt
|
|
|
|
|
|
|
|
During serialization any untyped Code AST is has its string value directly injected inline of
|
|
|
|
whatever context the content existed as an entry within.
|
|
|
|
Even though thse are not validated from somewhat correct c/c++ syntax or components, it doesn't mean that
|
|
|
|
Untyped code can be added as any component of a Code AST:
|
2023-04-04 13:18:30 -07:00
|
|
|
|
|
|
|
* Untyped code cannot have children, thus there cannot be recursive injection this way.
|
|
|
|
* Untyped code can only be a child of a parent of body AST, or for values of an assignment.
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
These restrictions help prevent abuse of untyped code to some extent.
|
2023-04-03 00:55:28 -07:00
|
|
|
*/
|
|
|
|
|
2023-04-01 19:21:46 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Bloat.hpp"
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
// Temporarily here for debugging purposes.
|
|
|
|
#define gen_time
|
|
|
|
#define GEN_ENFORCE_READONLY_AST
|
2023-04-03 00:55:28 -07:00
|
|
|
// #define GEN_DEFINE_DSL
|
2023-04-03 23:04:19 -07:00
|
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
|
|
// #define GEN_BAN_CPP_TEMPLATES
|
2023-04-05 00:03:56 -07:00
|
|
|
#define GEN_USE_FATAL
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
#ifdef gen_time
|
2023-04-01 19:21:46 -07:00
|
|
|
namespace gen
|
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
using LogFailType = sw(*)(char const*, ...);
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
#ifdef GEN_BAN_CPP_TEMPLATES
|
|
|
|
#define template static_assert("Templates are banned within gen_time scope blocks")
|
|
|
|
#endif
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
#ifdef GEN_USE_FATAL
|
|
|
|
ct LogFailType log_failure = fatal;
|
|
|
|
#else
|
|
|
|
ct LogFailType log_failure = log_fmt;
|
|
|
|
#endif
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
namespace ECode
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
enum Type : u8
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
Invalid,
|
|
|
|
Untyped,
|
|
|
|
Access_Public,
|
|
|
|
Access_Private,
|
|
|
|
Access_Protected,
|
|
|
|
Class,
|
|
|
|
Enum,
|
|
|
|
Enum_Body,
|
|
|
|
Global_Body,
|
|
|
|
Namespace,
|
|
|
|
Namespace_Body,
|
|
|
|
Parameters,
|
|
|
|
Proc,
|
|
|
|
Proc_Body,
|
|
|
|
Proc_Forward,
|
|
|
|
Specifiers,
|
|
|
|
Struct,
|
|
|
|
Struct_Body,
|
|
|
|
Variable,
|
|
|
|
Typedef,
|
|
|
|
Typename,
|
|
|
|
Using,
|
2023-04-01 19:21:46 -07:00
|
|
|
|
|
|
|
Num_Types
|
|
|
|
};
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
local_persist
|
2023-04-03 00:55:28 -07:00
|
|
|
char const* str( Type type )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
static
|
|
|
|
char const* lookup[Num_Types] = {
|
|
|
|
"Invalid",
|
|
|
|
"Untyped",
|
2023-04-05 00:03:56 -07:00
|
|
|
"Access_Public",
|
|
|
|
"Access_Private",
|
|
|
|
"Access_Protected",
|
|
|
|
"Class",
|
|
|
|
"Enum",
|
|
|
|
"Enum_Body",
|
|
|
|
"Global_Body",
|
2023-04-03 00:55:28 -07:00
|
|
|
"Namespace",
|
|
|
|
"Namespace_Body",
|
|
|
|
"Parameters",
|
2023-04-05 00:03:56 -07:00
|
|
|
"Proc",
|
|
|
|
"Proc_Body",
|
|
|
|
"Proc_Forward",
|
2023-04-03 00:55:28 -07:00
|
|
|
"Specifiers",
|
|
|
|
"Struct",
|
|
|
|
"Struct_Body",
|
|
|
|
"Variable",
|
|
|
|
"Typedef",
|
|
|
|
"Typename",
|
2023-04-03 23:04:19 -07:00
|
|
|
"Using",
|
2023-04-03 00:55:28 -07:00
|
|
|
};
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
return lookup[ type ];
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
|
|
|
using CodeT = ECode::Type;
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
namespace EOperator
|
|
|
|
{
|
|
|
|
enum Type : u8
|
|
|
|
{
|
|
|
|
Add,
|
|
|
|
Subtract,
|
|
|
|
Multiply,
|
|
|
|
Divide,
|
|
|
|
Modulo,
|
|
|
|
|
|
|
|
Num_Ops
|
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
char const* str( Type op )
|
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
local_persist
|
2023-04-03 23:04:19 -07:00
|
|
|
char const* lookup[ Num_Ops ] = {
|
|
|
|
"+",
|
|
|
|
"-",
|
|
|
|
"*",
|
|
|
|
"/",
|
|
|
|
};
|
|
|
|
|
|
|
|
return lookup[ op ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
using OperatorT = EOperator::Type;
|
|
|
|
|
|
|
|
namespace ESpecifier
|
|
|
|
{
|
|
|
|
enum Type : u8
|
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
Attribute,
|
|
|
|
Alignas,
|
|
|
|
Constexpr,
|
|
|
|
Const,
|
|
|
|
Inline,
|
|
|
|
Pointer,
|
|
|
|
Reference,
|
|
|
|
RValue,
|
|
|
|
|
|
|
|
C_Linkage,
|
|
|
|
API_Import,
|
|
|
|
API_Export,
|
|
|
|
External_Linkage,
|
|
|
|
Internal_Linkage,
|
|
|
|
Static_Member,
|
|
|
|
Local_Persist,
|
|
|
|
Thread_Local,
|
|
|
|
|
|
|
|
Invalid,
|
2023-04-03 23:04:19 -07:00
|
|
|
Num_Specifiers,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Specifier to string
|
|
|
|
inline
|
|
|
|
char const* to_str( Type specifier )
|
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
local_persist
|
2023-04-03 23:04:19 -07:00
|
|
|
char const* lookup[ Num_Specifiers ] = {
|
|
|
|
"alignas",
|
|
|
|
"constexpr",
|
|
|
|
"const",
|
|
|
|
"inline",
|
2023-04-05 00:03:56 -07:00
|
|
|
"*",
|
|
|
|
"&",
|
|
|
|
"&&",
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
"extern \"C\"",
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
#if defined(ZPL_SYSTEM_WINDOWS)
|
2023-04-03 23:04:19 -07:00
|
|
|
"__declspec(dllexport)",
|
|
|
|
"__declspec(dllimport)",
|
2023-04-05 00:03:56 -07:00
|
|
|
#elif defined(ZPL_SYSTEM_MACOS)
|
2023-04-03 23:04:19 -07:00
|
|
|
"__attribute__ ((visibility (\"default\")))",
|
|
|
|
"__attribute__ ((visibility (\"default\")))",
|
|
|
|
#endif
|
|
|
|
|
|
|
|
"extern",
|
|
|
|
"static",
|
|
|
|
"static",
|
|
|
|
"static",
|
|
|
|
"thread_local"
|
|
|
|
};
|
|
|
|
|
|
|
|
return lookup[ specifier ];
|
|
|
|
}
|
|
|
|
|
|
|
|
Type to_type( char const* str, s32 length )
|
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
local_persist
|
2023-04-03 23:04:19 -07:00
|
|
|
u32 keymap[ Num_Specifiers ];
|
|
|
|
do_once_start
|
|
|
|
for ( u32 index = 0; index < Num_Specifiers; index++ )
|
|
|
|
{
|
|
|
|
char const* enum_str = to_str( (Type)index );
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
keymap[index] = crc32( enum_str, zpl_strnlen(enum_str, 42) );
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
do_once_end
|
|
|
|
|
|
|
|
u32 hash = crc32(str, length );
|
|
|
|
|
|
|
|
for ( u32 index = 0; index < Num_Specifiers; index++ )
|
|
|
|
{
|
|
|
|
if ( keymap[index] == hash )
|
|
|
|
return (Type)index;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
using SpecifierT = ESpecifier::Type;
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma region Data Structures
|
2023-04-03 00:55:28 -07:00
|
|
|
// TODO: If perf needs it, convert layout an SOA format.
|
|
|
|
/*
|
|
|
|
Simple AST POD with functionality to seralize into C++ syntax.
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
ASTs are currently stored as an AOS. They are always reconstructed on demand.
|
|
|
|
Thus redundant AST can easily occur.
|
|
|
|
Not sure if its better to store them in a hashmap.
|
|
|
|
*/
|
|
|
|
struct AST
|
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma region Member Procedures
|
|
|
|
bool add( AST* other );
|
|
|
|
|
2023-04-01 19:21:46 -07:00
|
|
|
forceinline
|
2023-04-05 00:03:56 -07:00
|
|
|
void add_entry( AST* other )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
array_append( Entries, other );
|
|
|
|
|
|
|
|
other->Parent = this;
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
forceinline
|
|
|
|
AST* body()
|
|
|
|
{
|
|
|
|
return Entries[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
forceinline
|
|
|
|
bool check();
|
|
|
|
|
2023-04-01 19:21:46 -07:00
|
|
|
forceinline
|
2023-04-03 23:04:19 -07:00
|
|
|
bool has_entries() const
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
static bool lookup[ ECode::Num_Types] = {
|
2023-04-01 19:21:46 -07:00
|
|
|
false, // Invalid
|
|
|
|
false, // Untyped
|
2023-04-05 00:03:56 -07:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
true, // Global_Body
|
2023-04-03 23:04:19 -07:00
|
|
|
true, // Parameters
|
2023-04-05 00:03:56 -07:00
|
|
|
true, // Proc
|
|
|
|
true, // Proc_Body
|
|
|
|
true, // Proc_Forward
|
2023-04-03 23:04:19 -07:00
|
|
|
false, // Specifies
|
|
|
|
true, // Struct
|
|
|
|
true, // Struct_Body
|
2023-04-01 19:21:46 -07:00
|
|
|
true, // Variable
|
2023-04-03 23:04:19 -07:00
|
|
|
true, // Typedef
|
2023-04-01 19:21:46 -07:00
|
|
|
true, // Typename
|
|
|
|
};
|
|
|
|
|
|
|
|
return lookup[Type];
|
|
|
|
}
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
forceinline
|
2023-04-03 23:04:19 -07:00
|
|
|
bool is_invalid() const
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
|
|
|
return Type != ECode::Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
forceinline
|
2023-04-03 23:04:19 -07:00
|
|
|
char const* type_str() const
|
2023-04-03 00:55:28 -07:00
|
|
|
{
|
|
|
|
return ECode::str( Type );
|
|
|
|
}
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
string to_string() const;
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma endregion Member Procedures
|
2023-04-03 00:55:28 -07:00
|
|
|
|
|
|
|
#define Using_Code_POD \
|
|
|
|
CodeT Type; \
|
|
|
|
bool Readonly; \
|
|
|
|
AST* Parent; \
|
|
|
|
string Name; \
|
|
|
|
string Comment; \
|
|
|
|
union { \
|
|
|
|
array(AST*) Entries; \
|
|
|
|
string Content; \
|
|
|
|
};
|
|
|
|
|
|
|
|
Using_Code_POD;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CodePOD
|
|
|
|
{
|
|
|
|
Using_Code_POD;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Its intended for the AST to have equivalent size to its POD.
|
|
|
|
// All extra functionality within the AST namespace should just be syntatic sugar.
|
|
|
|
static_assert( sizeof(AST) == sizeof(CodePOD), "ERROR: AST IS NOT POD" );
|
|
|
|
|
|
|
|
/*
|
|
|
|
AST* typedef as to not constantly have to add the '*' as this is written often..
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
If GEN_ENFORCE_READONLY_AST is defined, readonly assertions will be done on any member dreference,
|
2023-04-03 00:55:28 -07:00
|
|
|
and the 'gen API' related functions. will set their created ASTs to readonly before returning.
|
|
|
|
|
|
|
|
Casting to AST* will bypass.
|
|
|
|
*/
|
|
|
|
struct Code
|
|
|
|
{
|
|
|
|
AST* ast;
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code body()
|
|
|
|
{
|
|
|
|
if ( ast->Type == ECode::Invalid )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
|
|
|
log_failure("Code::body: Type is invalid, cannot get");
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
if ( ast->Entries == nullptr || array_count(ast->Entries) == 0 )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
|
|
|
log_failure("Code::body: Entries of ast not properly setup.");
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
#ifdef GEN_ENFORCE_READONLY_AST
|
|
|
|
if ( ast->Readonly )
|
|
|
|
{
|
|
|
|
log_failure("Attempted to a body AST from a readonly AST!");
|
|
|
|
return InvalidCode;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return * (Code*)( ast->body() );
|
2023-04-03 23:04:19 -07:00
|
|
|
}
|
|
|
|
|
2023-04-01 19:21:46 -07:00
|
|
|
forceinline
|
2023-04-03 23:04:19 -07:00
|
|
|
void lock()
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 23:04:19 -07:00
|
|
|
ast->Readonly = true;
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
forceinline
|
|
|
|
operator bool() const
|
|
|
|
{
|
|
|
|
return ast && ast->is_invalid();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator ==( Code other ) const
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-03 00:55:28 -07:00
|
|
|
return ast == other.ast;
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
operator AST*()
|
|
|
|
{
|
|
|
|
return ast;
|
|
|
|
}
|
|
|
|
|
|
|
|
Code& operator =( Code other )
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-05 00:03:56 -07:00
|
|
|
if ( ast == nullptr )
|
|
|
|
{
|
|
|
|
log_failure("Attempt to set with a null AST!");
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GEN_ENFORCE_READONLY_AST
|
|
|
|
if ( ast->Readonly )
|
|
|
|
{
|
|
|
|
log_failure("Attempted to set a readonly AST!");
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
ast = other.ast;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
forceinline
|
|
|
|
AST* operator ->()
|
|
|
|
{
|
|
|
|
if ( ast == nullptr )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
|
|
|
log_failure("Attempt to dereference a nullptr!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
#ifdef GEN_ENFORCE_READONLY_AST
|
2023-04-03 00:55:28 -07:00
|
|
|
if ( ast->Readonly )
|
2023-04-05 00:03:56 -07:00
|
|
|
{
|
|
|
|
log_failure("Attempted to access a member from a readonly AST!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
#endif
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
return ast;
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
|
|
|
};
|
2023-04-03 23:04:19 -07:00
|
|
|
static_assert( sizeof(Code) == sizeof(AST*), "ERROR: Code is not POD" );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
// Used when the its desired when omission is allowed in a definition.
|
|
|
|
ct Code UnusedCode = { nullptr };
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
// Used internally for the most part to identify invaidly generated code.
|
2023-04-03 23:04:19 -07:00
|
|
|
extern const Code InvalidCode;
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
/*
|
|
|
|
*/
|
|
|
|
ZPL_TABLE_DECLARE( ZPL_EXTERN, StringTable, str_tbl_, string );
|
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
/*
|
|
|
|
Type registy: Used to store Typename ASTs. Types are registered by their string literal value.
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
Purely used as a memory optimization.
|
|
|
|
Strings made with the Typename ASTs are stored in thier own arena allocator.
|
|
|
|
TODO: Implement and replace usage of def_type.
|
|
|
|
*/
|
2023-04-05 00:03:56 -07:00
|
|
|
ZPL_TABLE_DECLARE( ZPL_EXTERN, TypeTable, type_tbl_, Code );
|
|
|
|
#pragma endregion Data Structures
|
2023-04-02 09:35:14 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma region Gen Interface
|
2023-04-03 00:55:28 -07:00
|
|
|
/*
|
|
|
|
Initialize the library.
|
|
|
|
This currently just initializes the CodePool.
|
|
|
|
*/
|
2023-04-02 09:35:14 -07:00
|
|
|
void init();
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
// Use this only if you know you generated the code you needed to a file
|
|
|
|
// And rather get rid of current code asts instead of growing the pool memory.
|
|
|
|
void clear_code_pool();
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
// Set these before calling gen's init() procedure.
|
|
|
|
|
|
|
|
void set_init_reserve_code_pool ( sw size );
|
|
|
|
void set_init_reserve_string_arena( sw size );
|
|
|
|
void set_init_reserve_string_table( sw size );
|
|
|
|
void set_init_reserve_type_table ( sw size );
|
|
|
|
|
|
|
|
void set_allocator_code_pool ( allocator pool_allocator );
|
|
|
|
void set_allocator_string_arena( allocator string_allocator );
|
|
|
|
void set_allocator_string_table( allocator string_allocator );
|
|
|
|
void set_allocator_type_table ( allocator type_reg_allocator );
|
|
|
|
|
|
|
|
# pragma region Upfront
|
|
|
|
Code def_class ( char const* name, Code body, Code parent = UnusedCode, Code specifiers = UnusedCode );
|
|
|
|
Code def_class_body( s32 num, ... );
|
|
|
|
Code def_class_fwd ( char const* name );
|
|
|
|
|
|
|
|
Code def_enum( char const* name, Code type, Code body );
|
|
|
|
|
|
|
|
Code def_global_body( s32 num, ... );
|
|
|
|
|
|
|
|
Code def_namespace ( char const* name, Code body );
|
|
|
|
Code def_namespace_body( s32 num, ... );
|
|
|
|
|
|
|
|
Code def_operator( OperatorT op
|
2023-04-01 19:21:46 -07:00
|
|
|
, Code specifiers
|
|
|
|
, Code params
|
|
|
|
, Code ret_type
|
2023-04-05 00:03:56 -07:00
|
|
|
, Code body
|
2023-04-01 19:21:46 -07:00
|
|
|
);
|
2023-04-05 00:03:56 -07:00
|
|
|
Code def_operator_fwd( OperatorT op, Code specifiers, Code params, Code ret_type );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code def_param( Code type, char const* name );
|
|
|
|
Code def_params( s32 num, ... );
|
|
|
|
Code def_params( s32 num, Code* params );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code def_proc( char const* name
|
2023-04-01 19:21:46 -07:00
|
|
|
, Code specifiers
|
|
|
|
, Code params
|
|
|
|
, Code ret_type
|
|
|
|
, Code body
|
|
|
|
);
|
2023-04-02 09:35:14 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code def_proc_body( s32 num, ... );
|
|
|
|
Code def_proc_body( s32 num, Code* codes );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code def_proc_fwd( char const* name
|
|
|
|
, Code specifiers
|
|
|
|
, Code params
|
|
|
|
, Code ret_type
|
|
|
|
);
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code def_specifier( SpecifierT* specifier );
|
2023-04-03 00:55:28 -07:00
|
|
|
Code def_specifiers( s32 num , ... );
|
2023-04-03 23:04:19 -07:00
|
|
|
Code def_specifiers( s32 num, SpecifierT* specs );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-02 09:35:14 -07:00
|
|
|
Code def_struct( char const* name, Code body, Code parent = UnusedCode, Code specifiers = UnusedCode );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
Code def_struct_body( s32 num, ... );
|
2023-04-03 23:04:19 -07:00
|
|
|
Code def_struct_body( s32 num, Code* codes );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code def_sturct_fwd();
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code def_variable( Code type, char const* name, Code value = UnusedCode, Code specifiers = UnusedCode );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code def_type( char const* name, Code specifiers = UnusedCode );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code def_using ( char const* name, Code type );
|
|
|
|
Code def_using_namespace( char const* name );
|
|
|
|
# pragma endregion Upfront
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
# pragma region Incremental
|
|
|
|
Code make_class( char const* name, Code parent = UnusedCode, Code specifiers = UnusedCode );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code make_enum ( char const* name, Code type = UnusedCode, Code body = UnusedCode );
|
|
|
|
Code make_enum_class( char const* name, Code type = UnusedCode, Code body = UnusedCode );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code make_global_body( char const* name = "", s32 num = 0, ... );
|
|
|
|
|
|
|
|
Code make_namespace( char const* name );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code make_operator( OperatorT op
|
|
|
|
, Code specifiers = UnusedCode
|
|
|
|
, Code params = UnusedCode
|
|
|
|
, Code ret_type = UnusedCode
|
|
|
|
, Code body = UnusedCode
|
|
|
|
);
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code make_params( s32 num, ... );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
Code make_proc( char const* name
|
|
|
|
, Code specifiers = UnusedCode
|
|
|
|
, Code params = UnusedCode
|
|
|
|
, Code ret_type = UnusedCode
|
|
|
|
);
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code make_specifiers( s32 num , ... );
|
|
|
|
Code make_specifiers( s32 num, SpecifierT* specs );
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code make_struct( char const* name, Code parent = UnusedCode, Code specifiers = UnusedCode );
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code make_variable( char const* name, Code type = UnusedCode, Code value = UnusedCode, Code specifiers = UnusedCode );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code make_type( char const* name, Code specifiers = UnusedCode );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code make_using( char const* name, Code type = UnusedCode, Code specifiers = UnusedCode );
|
|
|
|
# pragma endregion Incremental
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
# pragma region Parsing
|
|
|
|
Code parse_class( char const* class_def, s32 length );
|
|
|
|
s32 parse_classes( char const* class_defs, s32 length, Code* out_classes );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code parse_enum( char const* enum_def, s32 length);
|
|
|
|
s32 parse_enums( char const* enum_defs, s32 length, Code* out_enums );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code parse_global_body( char const* body_def, s32 length );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
Code parse_operator( char const* operator_def, s32 length );
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Code parse_proc( char const* proc_def, s32 length );
|
2023-04-05 00:03:56 -07:00
|
|
|
s32 parse_procs( char const* proc_defs, s32 length, Code* out_procs );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
|
|
|
Code parse_struct( char const* struct_def, s32 length );
|
2023-04-05 00:03:56 -07:00
|
|
|
s32 parse_structs( char const* struct_defs, s32 length, Code* out_struct_codes );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code parse_variable( char const* var_def, s32 length );
|
|
|
|
s32 parse_variables( char const* vars_def, s32 length, Code* out_var_codes );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code parse_type( char const* type_def, s32 length );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code parse_typedef( char const* typedef_def, s32 length );
|
|
|
|
s32 parse_typedef( char const* typedef_def, s32 length, Code* out_typedef_codes );
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
Code parse_using ( char const* using_def, s32 length );
|
|
|
|
s32 parse_usings( char const* usings_def, s32 length, Code* out_using_codes );
|
|
|
|
# pragma endregion Parsing
|
|
|
|
|
|
|
|
# pragma region Untyped text
|
2023-04-03 00:55:28 -07:00
|
|
|
/*
|
|
|
|
Define an untyped code string.
|
|
|
|
|
|
|
|
Untyped code may be used in bodies of functions, namespaces, or structs
|
|
|
|
or the in places where expressions may be placed.
|
|
|
|
|
|
|
|
Because the code within it is untyped, errors will naturally not be provided.
|
|
|
|
Consider this an a preprocessor define.
|
|
|
|
*/
|
|
|
|
Code untyped_str( char const* str );
|
2023-04-03 23:04:19 -07:00
|
|
|
Code untyped_str( char const* str, s32 length);
|
2023-04-03 00:55:28 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
Define an untyped code string using traditional 'printf'.
|
|
|
|
|
|
|
|
Untyped code may be used in bodies of functions, namespaces, or structs
|
|
|
|
or the in places where expressions may be placed.
|
|
|
|
|
|
|
|
Because the code within it is untyped, errors will naturally not be provided.
|
|
|
|
Consider this an a preprocessor define.
|
|
|
|
*/
|
2023-04-02 09:35:14 -07:00
|
|
|
Code untyped_fmt( char const* fmt, ... );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
/*
|
|
|
|
Define an untyped code string using token formatting:
|
|
|
|
... { <ID> } ... Will be repalced with value of token ID.
|
|
|
|
|
|
|
|
Values are to provided as: <char const* ID>, <char const* Value>, ...
|
|
|
|
|
|
|
|
num_tokens : The number of ID-Value pairs provided.
|
|
|
|
|
|
|
|
Untyped code may be used in bodies of functions, namespaces, or structs
|
|
|
|
or the in places where expressions may be placed.
|
|
|
|
|
|
|
|
Because the code within it is untyped, errors will naturally not be provided.
|
|
|
|
Consider this an a preprocessor define.
|
|
|
|
*/
|
2023-04-03 23:04:19 -07:00
|
|
|
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
2023-04-05 00:03:56 -07:00
|
|
|
# pragma endregion Untyped text
|
2023-04-03 00:55:28 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
Used to generate the files.
|
|
|
|
This is inspired by jai's usage of the string_builder with #insert.
|
|
|
|
|
|
|
|
Its expected when using this library that Code ast will be serialized with the:
|
|
|
|
Builder::print() proc
|
|
|
|
|
|
|
|
The seralized content of the Code ast will be appended to Buffer within an empty line
|
|
|
|
prepared for a another definition or to add an empty newline to the end of the file.
|
|
|
|
|
|
|
|
Builder::write() should be called when all Code has been seralized for that file.
|
|
|
|
|
|
|
|
The #insert directive is thus represented by an #include of the generated file at your desired line
|
|
|
|
of any file in the target project.
|
|
|
|
*/
|
2023-04-01 22:07:44 -07:00
|
|
|
struct Builder
|
2023-04-01 19:21:46 -07:00
|
|
|
{
|
2023-04-01 22:07:44 -07:00
|
|
|
zpl_file File;
|
|
|
|
string Buffer;
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
void print( Code );
|
2023-04-01 19:21:46 -07:00
|
|
|
|
2023-04-01 22:07:44 -07:00
|
|
|
bool open( char const* path );
|
2023-04-01 19:21:46 -07:00
|
|
|
void write();
|
|
|
|
};
|
2023-04-05 00:03:56 -07:00
|
|
|
#pragma endregion Gen Interface
|
2023-04-01 19:21:46 -07:00
|
|
|
}
|
2023-04-01 22:07:44 -07:00
|
|
|
|
2023-04-03 00:55:28 -07:00
|
|
|
#pragma region MACROS
|
|
|
|
# define gen_main main
|
2023-04-03 23:04:19 -07:00
|
|
|
# define __ UnusedCode
|
2023-04-03 00:55:28 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
gen's Domain Specific Langauge.
|
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Completely optional, makes the code gen syntax less verbose and cumbersome...
|
|
|
|
Since its C macros ends up looking like a lisp dialect...
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Longforms auto-define the variable.
|
|
|
|
Shorthands are just the function call.
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Anything below the make() macro is intended to be syntacticall used int he follwing format:
|
|
|
|
make( <type>, <name> )
|
|
|
|
{
|
|
|
|
...
|
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
Where ... are whatever is deemed necessary to produce the definition for the def( <name> ).
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-03 23:04:19 -07:00
|
|
|
The code macros are used to embed c/c++ to insert into the desired lcoation.
|
2023-04-03 00:55:28 -07:00
|
|
|
*/
|
2023-04-03 23:04:19 -07:00
|
|
|
#ifdef GEN_DEFINE_DSL
|
|
|
|
# define untyped_code( Name_, Value_ ) Code Name_ = gen::untyped_str( txt(Value_) )
|
|
|
|
# define typename( Name_, Value_ ) Code t_##Name_ = gen::def_type( txt(Value_) )
|
|
|
|
# define typename_fmt( Name_, Fmt_, ... ) Code t_##Name_ = gen::def_type( bprintf( Fmt_, __VA_ARGS__ ) )
|
|
|
|
# define using_type( Name_, Type_ ) Code Name_ = gen::def_using( #Name_, t_##Type_ )
|
|
|
|
# define variable( Type_, Name_, ... ) Code Name_ = gen::def_variable( t_##Type_, #Name_, __VA_ARGS__ )
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
# define untyped( Value_ ) gen::untyped_str( txt_with_length(Value_) )
|
2023-04-03 23:04:19 -07:00
|
|
|
# define code_token( Fmt_, ... ) gen::untyped_token_fmt( Fmt_, VA_NARGS( __VA_ARGS__), __VA_ARGS__ )
|
|
|
|
# define code_fmt( Fmt_, ... ) gen::untyped_fmt( Fmt_, __VA_ARGS__ )
|
|
|
|
# define specifiers( ... ) gen::def_specifiers( VA_NARGS( __VA_ARGS__ ), __VA_ARGS__ )
|
|
|
|
# define type( Value_ ) gen::def_type( txt(Value_) )
|
|
|
|
# define type_fmt( Fmt_, ... ) gen::def_type( bprintf( Fmt_, __VA_ARGS__ ) )
|
|
|
|
# define using( Name_, Type_ ) gen::def_using( #Name_, Type_ )
|
|
|
|
# define var( Type_, Name_, ... ) gen::def_variable( Type_, #Name_, __VA_ARGS__ )
|
|
|
|
|
|
|
|
# define make( Type_, Name_, ... ) Code Name_ = make_##Type_( #Name_, __VA_ARGS__ );
|
2023-04-05 00:03:56 -07:00
|
|
|
# define enum( Name_, Type_, Body_ ) gen::def_enum( #Name_, t_##Type_, Body_ )
|
2023-04-03 23:04:19 -07:00
|
|
|
# define proc( Name_, Specifiers_, RetType_, Parameters_, Body_ ) Name_ = gen::def_proc( #Name_, Specifiers_, Parameters_, RetType_, Body_ )
|
|
|
|
# define proc_body( ... ) gen::def_proc_body( VA_NARGS( __VA_ARS__ ), __VA_ARGS__ )
|
|
|
|
# define params( ... ) gen::def_params( VA_NARGS( __VA_ARGS__ ) / 2, __VA_ARGS__ )
|
|
|
|
# define struct( Name_, Parent_, Specifiers_, Body_ ) Name_ = gen::def_struct( #Name_, Body_, Parent_, Specifiers_ )
|
|
|
|
# define struct_body( ... ) gen::def_struct_body( VA_NARGS( __VA_ARGS__ ), __VA_ARGS__ )
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
# define add_var( Value_ ) add( gen::parse_variable( txt_with_length(Value_)) )
|
|
|
|
# define add_untyped( Value_ ) add( gen::untyped_str( txt_with_length( Value_ ) ) )
|
|
|
|
# define add_type( Value_ ) add( gen::parse_type( txt_with_length(Value_)) )
|
|
|
|
# define add_params( Value_ ) add( gen::parse_params( txt_with_length(Value_) ))
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
# define enum_code( Def_ ) gen::parse_enum( txt( Def_ ), sizeof( txt( Def_ )) )
|
|
|
|
# define global_code( Def_ ) gen::parse_global_body( txt_with_length( Def_ ))
|
|
|
|
# define namespace_code( Def_ ) gen::parse_namespace( txt(Def_), sizeof( txt(Def_)) )
|
2023-04-03 23:04:19 -07:00
|
|
|
# define proc_code( Def_ ) gen::parse_proc( txt( Def_ ), sizeof( txt( Def_ )) )
|
|
|
|
# define struct_code( Def_ ) gen::parse_struct( txt( Def_ ), sizeof( txt( Def_ )) )
|
2023-04-05 00:03:56 -07:00
|
|
|
# define variable_code( Def_ ) gen::parse_variable( txt_with_length( Def_ ) )
|
2023-04-03 00:55:28 -07:00
|
|
|
#endif
|
|
|
|
#pragma endregion MACROS
|
|
|
|
|
|
|
|
#pragma region CONSTANTS
|
2023-04-03 23:04:19 -07:00
|
|
|
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
2023-04-03 00:55:28 -07:00
|
|
|
namespace gen
|
|
|
|
{
|
|
|
|
// Predefined typename codes.
|
2023-04-03 23:04:19 -07:00
|
|
|
// These are not set until gen::init is called.
|
|
|
|
// This just preloads a bunch of Code types into the code pool.
|
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
extern Code t_void;
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
extern Code t_bool;
|
|
|
|
extern Code t_char;
|
|
|
|
extern Code t_wchar_t;
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
extern Code t_s8;
|
|
|
|
extern Code t_s16;
|
|
|
|
extern Code t_s32;
|
|
|
|
extern Code t_s64;
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
extern Code t_u8;
|
|
|
|
extern Code t_u16;
|
|
|
|
extern Code t_u32;
|
|
|
|
extern Code t_u64;
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
extern Code t_sw;
|
|
|
|
extern Code t_uw;
|
2023-04-03 00:55:28 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
extern Code t_f32;
|
|
|
|
extern Code t_f64;
|
2023-04-03 23:04:19 -07:00
|
|
|
|
2023-04-05 00:03:56 -07:00
|
|
|
extern Code spec_constexpr;
|
|
|
|
extern Code spec_inline;
|
2023-04-03 00:55:28 -07:00
|
|
|
}
|
2023-04-03 23:04:19 -07:00
|
|
|
#endif
|
2023-04-05 00:03:56 -07:00
|
|
|
|
|
|
|
namespace gen
|
|
|
|
{
|
|
|
|
extern Code access_public;
|
|
|
|
extern Code access_protected;
|
|
|
|
extern Code access_private;
|
|
|
|
}
|
2023-04-03 00:55:28 -07:00
|
|
|
#pragma endregion CONSTANTS
|
2023-04-01 19:21:46 -07:00
|
|
|
#endif
|