mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-11-03 23:36:12 -08:00 
			
		
		
		
	working to towards https://github.com/Ed94/gencpp/issues/56
This commit is contained in:
		@@ -28,7 +28,7 @@ void reset();
 | 
			
		||||
 | 
			
		||||
// Used internally to retrive or make string allocations.
 | 
			
		||||
// Strings are stored in a series of string arenas of fixed size (SizePer_StringArena)
 | 
			
		||||
StringCached get_cached_string( StrC str );
 | 
			
		||||
StringCached get_cached_string( Str str );
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
	This provides a fresh Code AST.
 | 
			
		||||
@@ -42,14 +42,14 @@ Code make_code();
 | 
			
		||||
void set_allocator_data_arrays ( AllocatorInfo data_array_allocator );
 | 
			
		||||
void set_allocator_code_pool   ( AllocatorInfo pool_allocator );
 | 
			
		||||
void set_allocator_lexer       ( AllocatorInfo lex_allocator );
 | 
			
		||||
void set_allocator_string_arena( AllocatorInfo string_allocator );
 | 
			
		||||
void set_allocator_string_table( AllocatorInfo string_allocator );
 | 
			
		||||
void set_allocator_strbuilder_arena( AllocatorInfo strbuilder_allocator );
 | 
			
		||||
void set_allocator_strbuilder_table( AllocatorInfo strbuilder_allocator );
 | 
			
		||||
void set_allocator_type_table  ( AllocatorInfo type_reg_allocator );
 | 
			
		||||
 | 
			
		||||
#pragma region Upfront
 | 
			
		||||
 | 
			
		||||
CodeAttributes def_attributes( StrC content );
 | 
			
		||||
CodeComment    def_comment   ( StrC content );
 | 
			
		||||
CodeAttributes def_attributes( Str content );
 | 
			
		||||
CodeComment    def_comment   ( Str content );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_struct {
 | 
			
		||||
	CodeBody       body;
 | 
			
		||||
@@ -60,7 +60,7 @@ struct Opts_def_struct {
 | 
			
		||||
	s32            num_interfaces;
 | 
			
		||||
	ModuleFlag     mflags;
 | 
			
		||||
};
 | 
			
		||||
CodeClass def_class( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeClass def_class( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_constructor {
 | 
			
		||||
	CodeParams params;
 | 
			
		||||
@@ -72,7 +72,7 @@ CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT );
 | 
			
		||||
struct Opts_def_define {
 | 
			
		||||
	b32 dont_append_preprocess_defines;
 | 
			
		||||
};
 | 
			
		||||
CodeDefine def_define( StrC name, StrC content, Opts_def_define opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeDefine def_define( Str name, Str content, Opts_def_define opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_destructor {
 | 
			
		||||
	Code           body;
 | 
			
		||||
@@ -88,10 +88,10 @@ struct Opts_def_enum {
 | 
			
		||||
	ModuleFlag     mflags;
 | 
			
		||||
	Code           type_macro;
 | 
			
		||||
};
 | 
			
		||||
CodeEnum def_enum( StrC name, Opts_def_enum opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeEnum def_enum( Str name, Opts_def_enum opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
CodeExec   def_execution  ( StrC content );
 | 
			
		||||
CodeExtern def_extern_link( StrC name, CodeBody body );
 | 
			
		||||
CodeExec   def_execution  ( Str content );
 | 
			
		||||
CodeExtern def_extern_link( Str name, CodeBody body );
 | 
			
		||||
CodeFriend def_friend     ( Code symbol );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_function {
 | 
			
		||||
@@ -102,14 +102,14 @@ struct Opts_def_function {
 | 
			
		||||
	CodeAttributes  attrs;
 | 
			
		||||
	ModuleFlag      mflags;
 | 
			
		||||
};
 | 
			
		||||
CodeFn def_function( StrC name, Opts_def_function opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeFn def_function( Str name, Opts_def_function opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_include   { b32        foreign; };
 | 
			
		||||
struct Opts_def_module    { ModuleFlag mflags;  };
 | 
			
		||||
struct Opts_def_namespace { ModuleFlag mflags;  };
 | 
			
		||||
CodeInclude def_include  ( StrC content,             Opts_def_include   opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeModule  def_module   ( StrC name,                Opts_def_module    opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeNS      def_namespace( StrC name, CodeBody body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
 | 
			
		||||
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 );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_operator {
 | 
			
		||||
	CodeParams      params;
 | 
			
		||||
@@ -119,7 +119,7 @@ struct Opts_def_operator {
 | 
			
		||||
	CodeAttributes  attributes;
 | 
			
		||||
	ModuleFlag      mflags;
 | 
			
		||||
};
 | 
			
		||||
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_operator_cast {
 | 
			
		||||
	CodeBody       body;
 | 
			
		||||
@@ -128,14 +128,14 @@ 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; };
 | 
			
		||||
CodeParams  def_param ( CodeTypename type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodePragma def_pragma( StrC directive );
 | 
			
		||||
CodeParams  def_param ( CodeTypename type, Str name, Opts_def_param opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodePragma def_pragma( Str directive );
 | 
			
		||||
 | 
			
		||||
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
 | 
			
		||||
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, Str content );
 | 
			
		||||
 | 
			
		||||
CodeSpecifiers def_specifier( Specifier specifier );
 | 
			
		||||
 | 
			
		||||
CodeStruct def_struct( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeStruct def_struct( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_template { ModuleFlag mflags; };
 | 
			
		||||
CodeTemplate def_template( CodeParams params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
 | 
			
		||||
@@ -146,27 +146,27 @@ struct Opts_def_type {
 | 
			
		||||
	CodeSpecifiers specifiers;
 | 
			
		||||
	CodeAttributes attributes;
 | 
			
		||||
};
 | 
			
		||||
CodeTypename def_type( StrC name, Opts_def_type opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeTypename def_type( Str name, Opts_def_type opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_typedef {
 | 
			
		||||
	CodeAttributes attributes;
 | 
			
		||||
	ModuleFlag     mflags;
 | 
			
		||||
};
 | 
			
		||||
CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_union {
 | 
			
		||||
	CodeAttributes attributes;
 | 
			
		||||
	ModuleFlag     mflags;
 | 
			
		||||
};
 | 
			
		||||
CodeUnion def_union( StrC name, CodeBody body, Opts_def_union opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeUnion def_union( Str name, CodeBody body, Opts_def_union opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_using {
 | 
			
		||||
	CodeAttributes attributes;
 | 
			
		||||
	ModuleFlag     mflags;
 | 
			
		||||
};
 | 
			
		||||
CodeUsing def_using( StrC name, CodeTypename type, Opts_def_using opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeUsing def_using( Str name, CodeTypename type, Opts_def_using opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
CodeUsing def_using_namespace( StrC name );
 | 
			
		||||
CodeUsing def_using_namespace( Str name );
 | 
			
		||||
 | 
			
		||||
struct Opts_def_variable
 | 
			
		||||
{
 | 
			
		||||
@@ -175,7 +175,7 @@ struct Opts_def_variable
 | 
			
		||||
	CodeAttributes attributes;
 | 
			
		||||
	ModuleFlag     mflags;
 | 
			
		||||
};
 | 
			
		||||
CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT );
 | 
			
		||||
CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opts GEN_PARAM_DEFAULT );
 | 
			
		||||
 | 
			
		||||
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
 | 
			
		||||
CodeBody def_body( CodeType type );
 | 
			
		||||
@@ -220,13 +220,13 @@ struct StackNode
 | 
			
		||||
 | 
			
		||||
	Token Start;
 | 
			
		||||
	Token Name;       // The name of the AST node (if parsed)
 | 
			
		||||
	StrC  FailedProc; // The name of the procedure that failed
 | 
			
		||||
	Str  FailedProc; // The name of the procedure that failed
 | 
			
		||||
};
 | 
			
		||||
// Stack nodes are allocated the error's allocator
 | 
			
		||||
 | 
			
		||||
struct Error
 | 
			
		||||
{
 | 
			
		||||
	String     message;
 | 
			
		||||
	StrBuilder     message;
 | 
			
		||||
	StackNode* context_stack;
 | 
			
		||||
};
 | 
			
		||||
GEN_NS_PARSER_END
 | 
			
		||||
@@ -243,28 +243,28 @@ struct ParseInfo
 | 
			
		||||
	// Errors are allocated to a dedicated general arena.
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
CodeBody parse_file( StrC path );
 | 
			
		||||
CodeBody parse_file( Str path );
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
CodeClass       parse_class        ( StrC class_def       );
 | 
			
		||||
CodeConstructor parse_constructor  ( StrC constructor_def );
 | 
			
		||||
CodeDestructor  parse_destructor   ( StrC destructor_def  );
 | 
			
		||||
CodeEnum        parse_enum         ( StrC enum_def        );
 | 
			
		||||
CodeBody        parse_export_body  ( StrC export_def      );
 | 
			
		||||
CodeExtern      parse_extern_link  ( StrC exten_link_def  );
 | 
			
		||||
CodeFriend      parse_friend       ( StrC friend_def      );
 | 
			
		||||
CodeFn          parse_function     ( StrC fn_def          );
 | 
			
		||||
CodeBody        parse_global_body  ( StrC body_def        );
 | 
			
		||||
CodeNS          parse_namespace    ( StrC namespace_def   );
 | 
			
		||||
CodeOperator    parse_operator     ( StrC operator_def    );
 | 
			
		||||
CodeOpCast      parse_operator_cast( StrC operator_def    );
 | 
			
		||||
CodeStruct      parse_struct       ( StrC struct_def      );
 | 
			
		||||
CodeTemplate    parse_template     ( StrC template_def    );
 | 
			
		||||
CodeTypename    parse_type         ( StrC type_def        );
 | 
			
		||||
CodeTypedef     parse_typedef      ( StrC typedef_def     );
 | 
			
		||||
CodeUnion       parse_union        ( StrC union_def       );
 | 
			
		||||
CodeUsing       parse_using        ( StrC using_def       );
 | 
			
		||||
CodeVar         parse_variable     ( StrC var_def         );
 | 
			
		||||
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         );
 | 
			
		||||
 | 
			
		||||
#pragma endregion Parsing
 | 
			
		||||
 | 
			
		||||
@@ -272,9 +272,9 @@ CodeVar         parse_variable     ( StrC var_def         );
 | 
			
		||||
 | 
			
		||||
ssize   token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va );
 | 
			
		||||
//! Do not use directly. Use the token_fmt macro instead.
 | 
			
		||||
StrC token_fmt_impl( ssize, ... );
 | 
			
		||||
Str token_fmt_impl( ssize, ... );
 | 
			
		||||
 | 
			
		||||
Code untyped_str      ( StrC content);
 | 
			
		||||
Code untyped_str      ( Str content);
 | 
			
		||||
Code untyped_fmt      ( char const* fmt, ... );
 | 
			
		||||
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
 | 
			
		||||
 | 
			
		||||
@@ -317,21 +317,21 @@ Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
 | 
			
		||||
 | 
			
		||||
#ifndef token_fmt
 | 
			
		||||
/*
 | 
			
		||||
Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
 | 
			
		||||
Takes a format string (char const*) and a list of tokens (Str) and returns a Str of the formatted string.
 | 
			
		||||
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:
 | 
			
		||||
		"type", strc_for_type,
 | 
			
		||||
		"name", strc_for_name,
 | 
			
		||||
		"type", str_for_type,
 | 
			
		||||
		"name", str_for_name,
 | 
			
		||||
	and:
 | 
			
		||||
		stringize( typedef <type> <name> <name>; )
 | 
			
		||||
-----------------------------------------------------------
 | 
			
		||||
So the full call for this example would be:
 | 
			
		||||
	token_fmt(
 | 
			
		||||
		"type", strc_for_type
 | 
			
		||||
	,	"name", strc_for_name
 | 
			
		||||
		"type", str_for_type
 | 
			
		||||
	,	"name", str_for_name
 | 
			
		||||
	,	stringize(
 | 
			
		||||
		typedef <type> <name> <name>
 | 
			
		||||
	));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user