mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
gen.h compiles with interface.upfront.cpp injected
This commit is contained in:
@ -402,7 +402,7 @@ static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST is not size of AST_POD_S
|
||||
struct InvalidCode_ImplictCaster;
|
||||
#define InvalidCode (InvalidCode_ImplictCaster{})
|
||||
#else
|
||||
#define InvalidCode { (void*)Code_Invalid }
|
||||
#define InvalidCode (void*){ (void*)Code_Invalid }
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
|
@ -197,6 +197,9 @@ struct CodeParam
|
||||
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); }
|
||||
#endif
|
||||
Using_CodeOps( CodeParam );
|
||||
forceinline operator Code() { return { (AST*)ast }; }
|
||||
|
@ -4,8 +4,8 @@
|
||||
#endif
|
||||
|
||||
GEN_NS_PARSER_BEGIN
|
||||
internal void init();
|
||||
internal void deinit();
|
||||
internal void parser_init();
|
||||
internal void parser_deinit();
|
||||
GEN_NS_PARSER_END
|
||||
|
||||
internal
|
||||
@ -148,9 +148,8 @@ void define_constants()
|
||||
# define def_constant_code_type( Type_ ) \
|
||||
do \
|
||||
{ \
|
||||
Opts_def_type ops = {}; \
|
||||
StrC name_str = name(Type_); \
|
||||
t_##Type_ = def_type( name_str, ops ); \
|
||||
t_##Type_ = def_type( name_str ); \
|
||||
code_set_global( cast(Code, t_##Type_)); \
|
||||
} while(0)
|
||||
|
||||
@ -323,7 +322,7 @@ void init()
|
||||
PreprocessorDefines = array_init_reserve(StringCached, GlobalAllocator, kilobytes(1) );
|
||||
|
||||
define_constants();
|
||||
GEN_NS_PARSER init();
|
||||
GEN_NS_PARSER parser_init();
|
||||
}
|
||||
|
||||
void deinit()
|
||||
@ -368,7 +367,7 @@ void deinit()
|
||||
while ( left--, left );
|
||||
|
||||
array_free(Global_AllocatorBuckets);
|
||||
GEN_NS_PARSER deinit();
|
||||
GEN_NS_PARSER parser_deinit();
|
||||
}
|
||||
|
||||
void reset()
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
// Initialize the library.
|
||||
// This currently just initializes the CodePool.
|
||||
void init();
|
||||
|
||||
// Currently manually free's the arenas, code for checking for leaks.
|
||||
@ -53,13 +52,13 @@ CodeAttributes def_attributes( StrC content );
|
||||
CodeComment def_comment ( StrC content );
|
||||
|
||||
struct Opts_def_struct {
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeTypename parent;
|
||||
AccessSpec parent_access;
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
CodeTypename* interfaces;
|
||||
s32 num_interfaces;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeClass def_class( StrC name, Opts_def_struct otps GEN_PARAM_DEFAULT );
|
||||
|
||||
@ -79,7 +78,7 @@ struct Opts_def_destructor {
|
||||
CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_enum {
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeTypename type;
|
||||
EnumT specifier;
|
||||
CodeAttributes attributes;
|
||||
@ -88,13 +87,13 @@ struct Opts_def_enum {
|
||||
CodeEnum def_enum( StrC name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
||||
|
||||
CodeExec def_execution ( StrC content );
|
||||
CodeExtern def_extern_link( StrC name, Code body );
|
||||
CodeExtern def_extern_link( StrC name, CodeBody body );
|
||||
CodeFriend def_friend ( Code symbol );
|
||||
|
||||
struct Opts_def_function {
|
||||
CodeParam params;
|
||||
CodeTypename ret_type;
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeSpecifiers specs;
|
||||
CodeAttributes attrs;
|
||||
ModuleFlag mflags;
|
||||
@ -104,14 +103,14 @@ CodeFn def_function( StrC 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, Code body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
|
||||
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 );
|
||||
|
||||
struct Opts_def_operator {
|
||||
CodeParam params;
|
||||
CodeTypename ret_type;
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeSpecifiers specifiers;
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
@ -119,7 +118,7 @@ struct Opts_def_operator {
|
||||
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_operator_cast {
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeSpecifiers specs;
|
||||
};
|
||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
||||
@ -155,13 +154,13 @@ struct Opts_def_union {
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeUnion def_union( StrC name, Code body, Opts_def_union opts GEN_PARAM_DEFAULT );
|
||||
CodeUnion def_union( StrC name, CodeBody body, Opts_def_union opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_using {
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeUsing def_using( StrC name, Code type, Opts_def_using opts GEN_PARAM_DEFAULT );
|
||||
CodeUsing def_using( StrC name, CodeTypename type, Opts_def_using opts GEN_PARAM_DEFAULT );
|
||||
|
||||
CodeUsing def_using_namespace( StrC name );
|
||||
|
||||
|
@ -482,10 +482,12 @@ CodeComment def_comment( StrC content )
|
||||
if ( * string_back(cmt_formatted) != '\n' )
|
||||
string_append_strc( & cmt_formatted, txt("\n") );
|
||||
|
||||
StrC name = { string_length(cmt_formatted), cmt_formatted };
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = CT_Comment;
|
||||
result->Name = get_cached_string( { string_length(cmt_formatted), cmt_formatted } );
|
||||
result->Name = get_cached_string( name );
|
||||
result->Content = result->Name;
|
||||
|
||||
string_free(& cmt_formatted);
|
||||
@ -546,7 +548,7 @@ CodeClass def_class( StrC name, Opts_def_struct p )
|
||||
{
|
||||
name_check( def_class, name );
|
||||
|
||||
Code body = p.body;
|
||||
CodeBody body = p.body;
|
||||
CodeTypename parent = p.parent;
|
||||
AccessSpec parent_access = p.parent_access;
|
||||
CodeAttributes attributes = p.attributes;
|
||||
@ -586,7 +588,7 @@ CodeClass def_class( StrC name, Opts_def_struct p )
|
||||
|
||||
result->Type = CT_Class;
|
||||
result->Body = body;
|
||||
result->Body->Parent = result; // TODO(Ed): Review this?
|
||||
result->Body->Parent = cast(Code, result); // TODO(Ed): Review this?
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -682,7 +684,7 @@ CodeDestructor def_destructor( Opts_def_destructor p )
|
||||
|
||||
CodeEnum def_enum( StrC name, Opts_def_enum p )
|
||||
{
|
||||
Code body = p.body;
|
||||
CodeBody body = p.body;
|
||||
CodeTypename type = p.type;
|
||||
EnumT specifier = p.specifier;
|
||||
CodeAttributes attributes = p.attributes;
|
||||
@ -764,7 +766,7 @@ CodeExec def_execution( StrC content )
|
||||
return (CodeExec) result;
|
||||
}
|
||||
|
||||
CodeExtern def_extern_link( StrC name, Code body )
|
||||
CodeExtern def_extern_link( StrC name, CodeBody body )
|
||||
{
|
||||
name_check( def_extern_linkage, name );
|
||||
null_check( def_extern_linkage, body );
|
||||
@ -818,7 +820,7 @@ CodeFn def_function( StrC name, Opts_def_function p )
|
||||
{
|
||||
CodeParam params = p.params;
|
||||
CodeTypename ret_type = p.ret_type;
|
||||
Code body = p.body;
|
||||
CodeBody body = p.body;
|
||||
CodeSpecifiers specifiers = p.specs;
|
||||
CodeAttributes attributes = p.attrs;
|
||||
ModuleFlag mflags = p.mflags;
|
||||
@ -934,7 +936,7 @@ CodeModule def_module( StrC name, Opts_def_module p )
|
||||
return (CodeModule) result;
|
||||
}
|
||||
|
||||
CodeNS def_namespace( StrC name, Code body, Opts_def_namespace p )
|
||||
CodeNS def_namespace( StrC name, CodeBody body, Opts_def_namespace p )
|
||||
{
|
||||
name_check( def_namespace, name );
|
||||
null_check( def_namespace, body);
|
||||
@ -958,7 +960,7 @@ CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
|
||||
{
|
||||
CodeParam params_code = p.params;
|
||||
CodeTypename ret_type = p.ret_type;
|
||||
Code body = p.body;
|
||||
CodeBody body = p.body;
|
||||
CodeSpecifiers specifiers = p.specifiers;
|
||||
CodeAttributes attributes = p.attributes;
|
||||
ModuleFlag mflags = p.mflags;
|
||||
@ -989,9 +991,12 @@ CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
|
||||
name = str_fmt_buf( "%.*soperator %.*s", nspace.Len, nspace.Ptr, op_str.Len, op_str.Ptr );
|
||||
else
|
||||
name = str_fmt_buf( "operator %.*s", op_str.Len, op_str.Ptr );
|
||||
|
||||
StrC name_resolved = { str_len(name), name };
|
||||
|
||||
CodeOperator
|
||||
result = (CodeOperator) make_code();
|
||||
result->Name = get_cached_string( { str_len(name), name } );
|
||||
result->Name = get_cached_string( name_resolved );
|
||||
result->ModuleFlags = mflags;
|
||||
result->Op = op;
|
||||
|
||||
@ -1038,7 +1043,7 @@ CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
|
||||
|
||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
|
||||
{
|
||||
Code body = p.body;
|
||||
CodeBody body = p.body;
|
||||
CodeSpecifiers const_spec = p.specs;
|
||||
|
||||
null_check( def_operator_cast, type );
|
||||
@ -1168,7 +1173,7 @@ CodeSpecifiers def_specifier( Specifier spec )
|
||||
|
||||
CodeStruct def_struct( StrC name, Opts_def_struct p )
|
||||
{
|
||||
Code body = p.body;
|
||||
CodeBody body = p.body;
|
||||
CodeTypename parent = p.parent;
|
||||
AccessSpec parent_access = p.parent_access;
|
||||
CodeAttributes attributes = p.attributes;
|
||||
@ -1198,7 +1203,7 @@ CodeStruct def_struct( StrC name, Opts_def_struct p )
|
||||
result = (CodeStruct) make_code();
|
||||
result->ModuleFlags = mflags;
|
||||
|
||||
if ( name )
|
||||
if ( name.Len )
|
||||
result->Name = get_cached_string( name );
|
||||
|
||||
if ( body )
|
||||
@ -1338,7 +1343,7 @@ CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p )
|
||||
}
|
||||
|
||||
// Registering the type.
|
||||
Code registered_type = def_type( name );
|
||||
CodeTypename registered_type = def_type( name );
|
||||
|
||||
if ( ! registered_type )
|
||||
{
|
||||
@ -1373,7 +1378,7 @@ CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeUnion def_union( StrC name, Code body, Opts_def_union p )
|
||||
CodeUnion def_union( StrC name, CodeBody body, Opts_def_union p )
|
||||
{
|
||||
null_check( def_union, body );
|
||||
|
||||
@ -1405,12 +1410,12 @@ CodeUnion def_union( StrC name, Code body, Opts_def_union p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeUsing def_using( StrC name, Code type, Opts_def_using p )
|
||||
CodeUsing def_using( StrC name, CodeTypename type, Opts_def_using p )
|
||||
{
|
||||
name_check( def_using, name );
|
||||
null_check( def_using, type );
|
||||
|
||||
Code register_type = def_type( name );
|
||||
CodeTypename register_type = def_type( name );
|
||||
|
||||
if ( ! register_type )
|
||||
{
|
||||
@ -1451,7 +1456,7 @@ CodeUsing def_using_namespace( StrC name )
|
||||
return (CodeUsing) result;
|
||||
}
|
||||
|
||||
CodeVar def_variable( CodeTypename type, StrC name, Code value, Opts_def_variable p )
|
||||
CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable p )
|
||||
{
|
||||
name_check( def_variable, name );
|
||||
null_check( def_variable, type );
|
||||
@ -1474,9 +1479,9 @@ CodeVar def_variable( CodeTypename type, StrC name, Code value, Opts_def_variabl
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
if ( value && value->Type != CT_Untyped )
|
||||
if ( p.value && p.value->Type != CT_Untyped )
|
||||
{
|
||||
log_failure( "gen::def_variable: value was not a `Untyped` type - %s", code_debug_str(value) );
|
||||
log_failure( "gen::def_variable: value was not a `Untyped` type - %s", code_debug_str(p.value) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
@ -1494,8 +1499,8 @@ CodeVar def_variable( CodeTypename type, StrC name, Code value, Opts_def_variabl
|
||||
if ( p.specifiers )
|
||||
result->Specs = p.specifiers;
|
||||
|
||||
if ( value )
|
||||
result->Value = value;
|
||||
if ( p.value )
|
||||
result->Value = p.value;
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1915,7 +1920,7 @@ CodeBody def_global_body( s32 num, ... )
|
||||
{
|
||||
case CT_Global_Body:
|
||||
// result.body_append( entry.code_cast<CodeBody>() ) ;
|
||||
body_append( result, cast(CodeBody, entry) );
|
||||
body_append_body( result, cast(CodeBody, entry) );
|
||||
continue;
|
||||
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
@ -1956,7 +1961,7 @@ CodeBody def_global_body( s32 num, Code* codes )
|
||||
switch (entry->Type)
|
||||
{
|
||||
case CT_Global_Body:
|
||||
body_append(result, cast(CodeBody, entry) );
|
||||
body_append_body(result, cast(CodeBody, entry) );
|
||||
continue;
|
||||
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
@ -2090,21 +2095,21 @@ CodeParam def_params( s32 num, CodeParam* codes )
|
||||
{
|
||||
def_body_code_array_start( def_params );
|
||||
|
||||
# define check_current() \
|
||||
if ( current.ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("gen::def_params: Provide a null code in codes array"); \
|
||||
return InvalidCode; \
|
||||
} \
|
||||
\
|
||||
if (current->Type != CT_Parameters ) \
|
||||
{ \
|
||||
log_failure("gen::def_params: Code in coes array is not of paramter type - %s", code_debug_str(current) ); \
|
||||
return InvalidCode; \
|
||||
# define check_current(current) \
|
||||
if ( current == nullptr ) \
|
||||
{ \
|
||||
log_failure("gen::def_params: Provide a null code in codes array"); \
|
||||
return InvalidCode; \
|
||||
} \
|
||||
\
|
||||
if (current->Type != CT_Parameters ) \
|
||||
{ \
|
||||
log_failure("gen::def_params: Code in coes array is not of paramter type - %s", code_debug_str(current) ); \
|
||||
return InvalidCode; \
|
||||
}
|
||||
|
||||
CodeParam current = (CodeParam)code_duplicate(* codes);
|
||||
check_current();
|
||||
check_current(current);
|
||||
|
||||
CodeParam
|
||||
result = (CodeParam) make_code();
|
||||
@ -2114,7 +2119,7 @@ CodeParam def_params( s32 num, CodeParam* codes )
|
||||
|
||||
while( codes++, current = * codes, num--, num > 0 )
|
||||
{
|
||||
check_current();
|
||||
check_current(current);
|
||||
params_append(result, current );
|
||||
}
|
||||
# undef check_current
|
||||
@ -2293,7 +2298,7 @@ CodeBody def_union_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_union_body( s32 num, CodeUnion* codes )
|
||||
CodeBody def_union_body( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_union_body );
|
||||
|
||||
|
@ -134,7 +134,7 @@ bool __eat(TokArray* self, TokType type )
|
||||
}
|
||||
|
||||
internal
|
||||
void init()
|
||||
void parser_init()
|
||||
{
|
||||
Tokens = array_init_reserve(Token, arena_allocator_info( & LexArena)
|
||||
, ( LexAllocator_Size - sizeof( ArrayHeader ) ) / sizeof(Token)
|
||||
@ -145,7 +145,7 @@ void init()
|
||||
}
|
||||
|
||||
internal
|
||||
void deinit()
|
||||
void parser_deinit()
|
||||
{
|
||||
parser::Tokens = { nullptr };
|
||||
}
|
||||
@ -780,10 +780,10 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
|
||||
}
|
||||
|
||||
if ( which == Tok_Decl_Class )
|
||||
result = def_class( to_str(name), { body, parent, access, attributes, mflags } );
|
||||
result = def_class( to_str(name), { body, parent, access, attributes, nullptr, 0, mflags } );
|
||||
|
||||
else
|
||||
result = def_struct( to_str(name), { body, (CodeTypename)parent, access, attributes, mflags } );
|
||||
result = def_struct( to_str(name), { body, (CodeTypename)parent, access, attributes, nullptr, 0, mflags } );
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
Reference in New Issue
Block a user