2023-08-28 20:46:50 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
2023-08-21 17:30:13 -07:00
|
|
|
#pragma once
|
2023-08-21 20:02:20 -07:00
|
|
|
#include "ast_types.hpp"
|
2023-08-28 20:46:50 -07:00
|
|
|
#endif
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2023-07-26 11:21:20 -07:00
|
|
|
#pragma region Gen Interface
|
2024-12-08 13:37:04 -08:00
|
|
|
/*
|
|
|
|
/ \ | \ | \ / \
|
|
|
|
| ▓▓▓▓▓▓\ ______ _______ \▓▓▓▓▓▓_______ _| ▓▓_ ______ ______ | ▓▓▓▓▓▓\ ______ _______ ______
|
|
|
|
| ▓▓ __\▓▓/ \| \ | ▓▓ | \| ▓▓ \ / \ / \| ▓▓_ \▓▓| \ / \/ \
|
|
|
|
| ▓▓| \ ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓\ | ▓▓ | ▓▓▓▓▓▓▓\\▓▓▓▓▓▓ | ▓▓▓▓▓▓\ ▓▓▓▓▓▓\ ▓▓ \ \▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓\
|
|
|
|
| ▓▓ \▓▓▓▓ ▓▓ ▓▓ ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ __| ▓▓ ▓▓ ▓▓ \▓▓ ▓▓▓▓ / ▓▓ ▓▓ | ▓▓ ▓▓
|
|
|
|
| ▓▓__| ▓▓ ▓▓▓▓▓▓▓▓ ▓▓ | ▓▓ _| ▓▓_| ▓▓ | ▓▓ | ▓▓| \ ▓▓▓▓▓▓▓▓ ▓▓ | ▓▓ | ▓▓▓▓▓▓▓ ▓▓_____| ▓▓▓▓▓▓▓▓
|
|
|
|
\▓▓ ▓▓\▓▓ \ ▓▓ | ▓▓ | ▓▓ \ ▓▓ | ▓▓ \▓▓ ▓▓\▓▓ \ ▓▓ | ▓▓ \▓▓ ▓▓\▓▓ \\▓▓ \
|
|
|
|
\▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓
|
|
|
|
*/
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-13 16:16:52 -08:00
|
|
|
#if 0
|
|
|
|
enum LogLevel : u32
|
|
|
|
{
|
|
|
|
Info,
|
|
|
|
Warning,
|
|
|
|
Panic,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LogEntry
|
|
|
|
{
|
|
|
|
Str msg;
|
|
|
|
u32 line_num;
|
|
|
|
void* data;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void LoggerCallback(LogEntry entry);
|
|
|
|
#endif
|
|
|
|
|
2024-12-13 17:40:18 -08:00
|
|
|
|
2024-12-13 16:16:52 -08:00
|
|
|
// Note(Ed): This is subject to heavily change
|
|
|
|
// with upcoming changes to the library's fallback (default) allocations strategy;
|
|
|
|
// and major changes to lexer/parser context usage.
|
|
|
|
struct Context
|
|
|
|
{
|
|
|
|
// User Configuration
|
|
|
|
|
|
|
|
// Persistent Data Allocation
|
|
|
|
AllocatorInfo Allocator_DyanmicContainers; // By default will use a genral slab allocator (TODO(Ed): Currently does not)
|
|
|
|
AllocatorInfo Allocator_Pool; // By default will use the growing vmem reserve (TODO(Ed): Currently does not)
|
|
|
|
AllocatorInfo Allocator_StrCache; // By default will use a dedicated slab allocator (TODO(Ed): Currently does not)
|
|
|
|
|
|
|
|
// Temporary Allocation
|
|
|
|
AllocatorInfo Allocator_Temp;
|
|
|
|
|
|
|
|
// LoggerCallaback* log_callback; // TODO(Ed): Impl user logger callback as an option.
|
|
|
|
|
|
|
|
//
|
|
|
|
u32 Max_CommentLineLength; // Used by def_comment
|
|
|
|
u32 Max_StrCacheLength; // Any cached string longer than this is always allocated again.
|
|
|
|
|
|
|
|
u32 InitSize_BuilderBuffer;
|
|
|
|
u32 InitSize_CodePoolsArray;
|
|
|
|
u32 InitSize_StringArenasArray;
|
|
|
|
|
|
|
|
u32 CodePool_NumBlocks;
|
|
|
|
|
|
|
|
// TODO(Ed): Review these... (No longer needed if using the proper allocation strategy)
|
|
|
|
u32 InitSize_LexArena;
|
|
|
|
u32 SizePer_StringArena;
|
|
|
|
|
2024-12-13 17:40:18 -08:00
|
|
|
// TODO(Ed): Symbol Table
|
|
|
|
// Keep track of all resolved symbols (naemspaced identifiers)
|
|
|
|
|
2024-12-13 16:16:52 -08:00
|
|
|
// Parser
|
|
|
|
|
|
|
|
// Used by the lexer to persistently treat all these identifiers as preprocessor defines.
|
|
|
|
// Populate with strings via gen::cache_str.
|
|
|
|
// Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments.
|
|
|
|
Array(StrCached) PreprocessorDefines;
|
|
|
|
|
|
|
|
// Backend
|
2024-12-13 17:40:18 -08:00
|
|
|
|
2024-12-13 16:16:52 -08:00
|
|
|
// The fallback allocator is utilized if any fo the three above allocators is not specified by the user.
|
|
|
|
u32 InitSize_Fallback_Allocator_Bucket_Size;
|
|
|
|
Array(Arena) Fallback_AllocatorBuckets;
|
|
|
|
|
|
|
|
// Array(Token) LexerTokens;
|
|
|
|
|
|
|
|
Array(Pool) CodePools;
|
|
|
|
Array(Arena) StringArenas;
|
|
|
|
|
2024-12-13 17:40:18 -08:00
|
|
|
StringTable StrCache;
|
|
|
|
|
|
|
|
// TODO(Ed): This needs to be just handled by a parser context
|
|
|
|
|
2024-12-13 16:16:52 -08:00
|
|
|
Arena LexArena;
|
2024-12-13 17:40:18 -08:00
|
|
|
StringTable Lexer_defines;
|
|
|
|
Array(Token) Lexer_Tokens;
|
2024-12-13 16:16:52 -08:00
|
|
|
|
2024-12-13 17:40:18 -08:00
|
|
|
// TODO(Ed): Active parse context vs a parse result need to be separated conceptually
|
|
|
|
ParseContext parser;
|
2024-12-13 16:16:52 -08:00
|
|
|
};
|
|
|
|
|
2024-12-13 17:40:18 -08:00
|
|
|
// Initialize the library. There first ctx initialized must exist for lifetime of other contextes that come after as its the one that
|
2024-12-13 16:16:52 -08:00
|
|
|
void init(Context* ctx);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
// Currently manually free's the arenas, code for checking for leaks.
|
|
|
|
// However on Windows at least, it doesn't need to occur as the OS will clean up after the process.
|
2024-12-13 16:16:52 -08:00
|
|
|
void deinit(Context* ctx);
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
// Clears the allocations, but doesn't return to the heap, the calls init() again.
|
|
|
|
// Ease of use.
|
2024-12-13 16:16:52 -08:00
|
|
|
void reset(Context* ctx);
|
|
|
|
|
|
|
|
void set_context(Context* ctx);
|
|
|
|
|
|
|
|
// Alternative way to add a preprocess define entry for the lexer & parser to utilize
|
|
|
|
// if the user doesn't want to use def_define
|
|
|
|
void set_preprocess_define( Str id, b32 is_functional );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
// Used internally to retrive or make string allocations.
|
|
|
|
// Strings are stored in a series of string arenas of fixed size (SizePer_StringArena)
|
2024-12-13 16:16:52 -08:00
|
|
|
StrCached cache_str( Str str );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
This provides a fresh Code AST.
|
|
|
|
The gen interface use this as their method from getting a new AST object from the CodePool.
|
|
|
|
Use this if you want to make your own API for formatting the supported Code Types.
|
|
|
|
*/
|
|
|
|
Code make_code();
|
|
|
|
|
|
|
|
// Set these before calling gen's init() procedure.
|
|
|
|
|
|
|
|
#pragma region Upfront
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeAttributes def_attributes( Str content );
|
|
|
|
CodeComment def_comment ( Str content );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
struct Opts_def_struct {
|
2024-12-09 11:55:02 -08:00
|
|
|
CodeBody body;
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename parent;
|
2024-12-02 21:45:30 -08:00
|
|
|
AccessSpec parent_access;
|
|
|
|
CodeAttributes attributes;
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename* interfaces;
|
2024-12-02 21:45:30 -08:00
|
|
|
s32 num_interfaces;
|
2024-12-09 11:55:02 -08:00
|
|
|
ModuleFlag mflags;
|
2024-12-02 21:45:30 -08:00
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeClass def_class( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
2024-12-02 21:45:30 -08:00
|
|
|
|
|
|
|
struct Opts_def_constructor {
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams params;
|
2024-12-02 21:45:30 -08:00
|
|
|
Code initializer_list;
|
|
|
|
Code body;
|
|
|
|
};
|
|
|
|
CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT );
|
2023-08-07 00:10:45 -07:00
|
|
|
|
2024-12-10 16:31:50 -08:00
|
|
|
struct Opts_def_define {
|
|
|
|
b32 dont_append_preprocess_defines;
|
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeDefine def_define( Str name, Str content, Opts_def_define opts GEN_PARAM_DEFAULT );
|
2023-07-29 22:21:04 -07:00
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
struct Opts_def_destructor {
|
|
|
|
Code body;
|
|
|
|
CodeSpecifiers specifiers;
|
|
|
|
};
|
|
|
|
CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
|
|
|
|
|
|
|
|
struct Opts_def_enum {
|
2024-12-09 11:55:02 -08:00
|
|
|
CodeBody body;
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename type;
|
2024-12-02 21:45:30 -08:00
|
|
|
EnumT specifier;
|
|
|
|
CodeAttributes attributes;
|
|
|
|
ModuleFlag mflags;
|
2024-12-11 10:33:35 -08:00
|
|
|
Code type_macro;
|
2024-12-02 21:45:30 -08:00
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeEnum def_enum( Str name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeExec def_execution ( Str content );
|
|
|
|
CodeExtern def_extern_link( Str name, CodeBody body );
|
2023-07-24 14:45:27 -07:00
|
|
|
CodeFriend def_friend ( Code symbol );
|
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
struct Opts_def_function {
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams params;
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename ret_type;
|
2024-12-09 11:55:02 -08:00
|
|
|
CodeBody body;
|
2024-12-02 21:45:30 -08:00
|
|
|
CodeSpecifiers specs;
|
|
|
|
CodeAttributes attrs;
|
|
|
|
ModuleFlag mflags;
|
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeFn def_function( Str name, Opts_def_function opts GEN_PARAM_DEFAULT );
|
2024-12-02 21:45:30 -08:00
|
|
|
|
|
|
|
struct Opts_def_include { b32 foreign; };
|
|
|
|
struct Opts_def_module { ModuleFlag mflags; };
|
|
|
|
struct Opts_def_namespace { ModuleFlag mflags; };
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeInclude def_include ( Str content, Opts_def_include opts GEN_PARAM_DEFAULT );
|
|
|
|
CodeModule def_module ( Str name, Opts_def_module opts GEN_PARAM_DEFAULT );
|
|
|
|
CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
|
2024-12-02 21:45:30 -08:00
|
|
|
|
|
|
|
struct Opts_def_operator {
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams params;
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeTypename ret_type;
|
2024-12-09 11:55:02 -08:00
|
|
|
CodeBody body;
|
2024-12-02 21:45:30 -08:00
|
|
|
CodeSpecifiers specifiers;
|
|
|
|
CodeAttributes attributes;
|
|
|
|
ModuleFlag mflags;
|
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
|
2024-12-02 21:45:30 -08:00
|
|
|
|
|
|
|
struct Opts_def_operator_cast {
|
2024-12-09 11:55:02 -08:00
|
|
|
CodeBody body;
|
2024-12-02 21:45:30 -08:00
|
|
|
CodeSpecifiers specs;
|
|
|
|
};
|
2024-12-03 12:19:39 -08:00
|
|
|
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
2024-12-02 21:45:30 -08:00
|
|
|
|
|
|
|
struct Opts_def_param { Code value; };
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeParams def_param ( CodeTypename type, Str name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
|
|
|
CodePragma def_pragma( Str directive );
|
2023-07-29 22:21:04 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, Str content );
|
2023-07-29 22:21:04 -07:00
|
|
|
|
2024-12-03 10:14:14 -08:00
|
|
|
CodeSpecifiers def_specifier( Specifier specifier );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeStruct def_struct( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
2024-12-02 21:45:30 -08:00
|
|
|
|
|
|
|
struct Opts_def_template { ModuleFlag mflags; };
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeTemplate def_template( CodeParams params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
struct Opts_def_type {
|
2024-12-08 17:00:16 -08:00
|
|
|
ETypenameTag type_tag;
|
2024-12-02 21:45:30 -08:00
|
|
|
Code arrayexpr;
|
|
|
|
CodeSpecifiers specifiers;
|
|
|
|
CodeAttributes attributes;
|
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeTypename def_type( Str name, Opts_def_type opts GEN_PARAM_DEFAULT );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
struct Opts_def_typedef {
|
|
|
|
CodeAttributes attributes;
|
|
|
|
ModuleFlag mflags;
|
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef opts GEN_PARAM_DEFAULT );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
struct Opts_def_union {
|
|
|
|
CodeAttributes attributes;
|
|
|
|
ModuleFlag mflags;
|
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeUnion def_union( Str name, CodeBody body, Opts_def_union opts GEN_PARAM_DEFAULT );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
struct Opts_def_using {
|
|
|
|
CodeAttributes attributes;
|
|
|
|
ModuleFlag mflags;
|
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeUsing def_using( Str name, CodeTypename type, Opts_def_using opts GEN_PARAM_DEFAULT );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeUsing def_using_namespace( Str name );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-02 21:45:30 -08:00
|
|
|
struct Opts_def_variable
|
|
|
|
{
|
|
|
|
Code value;
|
|
|
|
CodeSpecifiers specifiers;
|
|
|
|
CodeAttributes attributes;
|
|
|
|
ModuleFlag mflags;
|
|
|
|
};
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opts GEN_PARAM_DEFAULT );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
|
2024-12-08 13:37:04 -08:00
|
|
|
CodeBody def_body( CodeType type );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
|
|
|
|
/// or provide as an array of Code objects.
|
|
|
|
|
|
|
|
CodeBody def_class_body ( s32 num, ... );
|
|
|
|
CodeBody def_class_body ( s32 num, Code* codes );
|
|
|
|
CodeBody def_enum_body ( s32 num, ... );
|
|
|
|
CodeBody def_enum_body ( s32 num, Code* codes );
|
|
|
|
CodeBody def_export_body ( s32 num, ... );
|
|
|
|
CodeBody def_export_body ( s32 num, Code* codes);
|
|
|
|
CodeBody def_extern_link_body( s32 num, ... );
|
|
|
|
CodeBody def_extern_link_body( s32 num, Code* codes );
|
|
|
|
CodeBody def_function_body ( s32 num, ... );
|
|
|
|
CodeBody def_function_body ( s32 num, Code* codes );
|
|
|
|
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 );
|
2024-12-11 10:33:35 -08:00
|
|
|
CodeParams def_params ( s32 num, ... );
|
|
|
|
CodeParams def_params ( s32 num, CodeParams* params );
|
2023-07-24 14:45:27 -07:00
|
|
|
CodeSpecifiers def_specifiers ( s32 num, ... );
|
2024-12-03 10:14:14 -08:00
|
|
|
CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
|
2023-07-24 14:45:27 -07:00
|
|
|
CodeBody def_struct_body ( s32 num, ... );
|
|
|
|
CodeBody def_struct_body ( s32 num, Code* codes );
|
|
|
|
CodeBody def_union_body ( s32 num, ... );
|
|
|
|
CodeBody def_union_body ( s32 num, Code* codes );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#pragma endregion Upfront
|
|
|
|
|
|
|
|
#pragma region Parsing
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-11-22 11:23:21 -08:00
|
|
|
// TODO(Ed) : Implmeent the new parser API design.
|
|
|
|
|
|
|
|
#if 0
|
2024-12-08 13:37:04 -08:00
|
|
|
struct StackNode
|
|
|
|
{
|
|
|
|
StackNode* Prev;
|
|
|
|
|
|
|
|
Token Start;
|
|
|
|
Token Name; // The name of the AST node (if parsed)
|
2024-12-12 09:55:15 -08:00
|
|
|
Str FailedProc; // The name of the procedure that failed
|
2024-12-08 13:37:04 -08:00
|
|
|
};
|
|
|
|
// Stack nodes are allocated the error's allocator
|
|
|
|
|
|
|
|
struct Error
|
|
|
|
{
|
2024-12-12 09:55:15 -08:00
|
|
|
StrBuilder message;
|
2024-12-08 13:37:04 -08:00
|
|
|
StackNode* context_stack;
|
|
|
|
};
|
2023-11-22 11:23:21 -08:00
|
|
|
|
|
|
|
struct ParseInfo
|
2024-10-27 17:22:36 -07:00
|
|
|
{
|
2023-11-22 12:03:24 -08:00
|
|
|
Arena FileMem;
|
|
|
|
Arena TokMem;
|
|
|
|
Arena CodeMem;
|
|
|
|
|
2024-12-08 13:37:04 -08:00
|
|
|
FileContents FileContent;
|
|
|
|
Array<Token> Tokens;
|
|
|
|
Array<Error> Errors;
|
2023-11-22 11:23:21 -08:00
|
|
|
// Errors are allocated to a dedicated general arena.
|
2024-10-27 17:22:36 -07:00
|
|
|
};
|
2023-11-22 11:23:21 -08:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeBody parse_file( Str path );
|
2023-11-22 11:23:21 -08:00
|
|
|
#endif
|
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
CodeClass parse_class ( Str class_def );
|
|
|
|
CodeConstructor parse_constructor ( Str constructor_def );
|
|
|
|
CodeDestructor parse_destructor ( Str destructor_def );
|
|
|
|
CodeEnum parse_enum ( Str enum_def );
|
|
|
|
CodeBody parse_export_body ( Str export_def );
|
|
|
|
CodeExtern parse_extern_link ( Str exten_link_def );
|
|
|
|
CodeFriend parse_friend ( Str friend_def );
|
|
|
|
CodeFn parse_function ( Str fn_def );
|
|
|
|
CodeBody parse_global_body ( Str body_def );
|
|
|
|
CodeNS parse_namespace ( Str namespace_def );
|
|
|
|
CodeOperator parse_operator ( Str operator_def );
|
|
|
|
CodeOpCast parse_operator_cast( Str operator_def );
|
|
|
|
CodeStruct parse_struct ( Str struct_def );
|
|
|
|
CodeTemplate parse_template ( Str template_def );
|
|
|
|
CodeTypename parse_type ( Str type_def );
|
|
|
|
CodeTypedef parse_typedef ( Str typedef_def );
|
|
|
|
CodeUnion parse_union ( Str union_def );
|
|
|
|
CodeUsing parse_using ( Str using_def );
|
|
|
|
CodeVar parse_variable ( Str var_def );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#pragma endregion Parsing
|
|
|
|
|
|
|
|
#pragma region Untyped text
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-10-27 15:58:37 -07:00
|
|
|
ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va );
|
2023-08-03 08:01:43 -07:00
|
|
|
//! Do not use directly. Use the token_fmt macro instead.
|
2024-12-12 09:55:15 -08:00
|
|
|
Str token_fmt_impl( ssize, ... );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2024-12-12 09:55:15 -08:00
|
|
|
Code untyped_str ( Str content);
|
2023-07-24 14:45:27 -07:00
|
|
|
Code untyped_fmt ( char const* fmt, ... );
|
2024-12-09 20:19:19 -08:00
|
|
|
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#pragma endregion Untyped text
|
2023-07-26 11:21:20 -07:00
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
#pragma region Macros
|
|
|
|
|
2024-12-10 10:56:56 -08:00
|
|
|
#ifndef gen_main
|
|
|
|
#define gen_main main
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef name
|
|
|
|
// Convienence for defining any name used with the gen api.
|
|
|
|
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
2024-12-13 10:20:16 -08:00
|
|
|
#define name( Id_ ) { stringize(Id_), sizeof(stringize( Id_ )) - 1 }
|
2024-12-10 10:56:56 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef code
|
|
|
|
// Same as name just used to indicate intention of literal for code instead of names.
|
2024-12-13 11:38:27 -08:00
|
|
|
#define code( ... ) { stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
|
2024-12-10 10:56:56 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef args
|
|
|
|
// Provides the number of arguments while passing args inplace.
|
|
|
|
#define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef code_str
|
|
|
|
// Just wrappers over common untyped code definition constructions.
|
|
|
|
#define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef code_fmt
|
|
|
|
#define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef parse_fmt
|
|
|
|
#define parse_fmt( type, ... ) GEN_NS parse_##type( token_fmt( __VA_ARGS__ ) )
|
|
|
|
#endif
|
|
|
|
|
2024-12-07 14:17:02 -08:00
|
|
|
#ifndef token_fmt
|
2024-12-10 10:56:56 -08:00
|
|
|
/*
|
2024-12-12 09:55:15 -08:00
|
|
|
Takes a format string (char const*) and a list of tokens (Str) and returns a Str of the formatted string.
|
2024-12-10 10:56:56 -08:00
|
|
|
Tokens are provided in '<'identifier'>' format where '<' '>' are just angle brackets (you can change it in token_fmt_va)
|
|
|
|
---------------------------------------------------------
|
|
|
|
Example - A string with:
|
|
|
|
typedef <type> <name> <name>;
|
|
|
|
Will have a token_fmt arguments populated with:
|
2024-12-12 09:55:15 -08:00
|
|
|
"type", str_for_type,
|
|
|
|
"name", str_for_name,
|
2024-12-10 10:56:56 -08:00
|
|
|
and:
|
|
|
|
stringize( typedef <type> <name> <name>; )
|
|
|
|
-----------------------------------------------------------
|
|
|
|
So the full call for this example would be:
|
|
|
|
token_fmt(
|
2024-12-12 09:55:15 -08:00
|
|
|
"type", str_for_type
|
|
|
|
, "name", str_for_name
|
2024-12-10 10:56:56 -08:00
|
|
|
, stringize(
|
|
|
|
typedef <type> <name> <name>
|
|
|
|
));
|
|
|
|
!----------------------------------------------------------
|
|
|
|
! Note: token_fmt_va is whitespace sensitive for the tokens.
|
|
|
|
! This can be alleviated by skipping whitespace between brackets but it was choosen to not have that implementation by default.
|
|
|
|
*/
|
|
|
|
#define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
2024-12-07 14:17:02 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma endregion Macros
|
|
|
|
|
2023-07-26 11:21:20 -07:00
|
|
|
#pragma endregion Gen Interface
|