setup upfront interface to have optional vars in structs (for C later)

This commit is contained in:
Edward R. Gonzalez 2024-12-03 00:45:30 -05:00
parent 2fe708e4be
commit f28ae57f16
6 changed files with 327 additions and 287 deletions

View File

@ -415,169 +415,169 @@ void to_string( Code self, String* result )
break; break;
case Class: case Class:
to_string_def(cast(CodeClass, {self}), result ); to_string_def(cast(CodeClass, self), result );
break; break;
case Class_Fwd: case Class_Fwd:
to_string_fwd(cast(CodeClass, {self}), result ); to_string_fwd(cast(CodeClass, self), result );
break; break;
case Constructor: case Constructor:
to_string_def(cast(CodeConstructor, {self}), result ); to_string_def(cast(CodeConstructor, self), result );
break; break;
case Constructor_Fwd: case Constructor_Fwd:
to_string_fwd(cast(CodeConstructor, {self}), result ); to_string_fwd(cast(CodeConstructor, self), result );
break; break;
case Destructor: case Destructor:
to_string_def(cast(CodeDestructor, {self}), result ); to_string_def(cast(CodeDestructor, self), result );
break; break;
case Destructor_Fwd: case Destructor_Fwd:
to_string_fwd(cast(CodeDestructor, {self}), result ); to_string_fwd(cast(CodeDestructor, self), result );
break; break;
case Enum: case Enum:
to_string_def(cast(CodeEnum, {self}), result ); to_string_def(cast(CodeEnum, self), result );
break; break;
case Enum_Fwd: case Enum_Fwd:
to_string_fwd(cast(CodeEnum, {self}), result ); to_string_fwd(cast(CodeEnum, self), result );
break; break;
case Enum_Class: case Enum_Class:
to_string_class_def(cast(CodeEnum, {self}), result ); to_string_class_def(cast(CodeEnum, self), result );
break; break;
case Enum_Class_Fwd: case Enum_Class_Fwd:
to_string_class_fwd(cast(CodeEnum, {self}), result ); to_string_class_fwd(cast(CodeEnum, self), result );
break; break;
case Export_Body: case Export_Body:
to_string_export(cast(CodeBody, {self}), result ); to_string_export(cast(CodeBody, self), result );
break; break;
case Extern_Linkage: case Extern_Linkage:
to_string(cast(CodeExtern, {self}), result ); to_string(cast(CodeExtern, self), result );
break; break;
case Friend: case Friend:
to_string(cast(CodeFriend, {self}), result ); to_string(cast(CodeFriend, self), result );
break; break;
case Function: case Function:
to_string_def(cast(CodeFn, {self}), result ); to_string_def(cast(CodeFn, self), result );
break; break;
case Function_Fwd: case Function_Fwd:
to_string_fwd(cast(CodeFn, {self}), result ); to_string_fwd(cast(CodeFn, self), result );
break; break;
case Module: case Module:
to_string(cast(CodeModule, {self}), result ); to_string(cast(CodeModule, self), result );
break; break;
case Namespace: case Namespace:
to_string(cast(CodeNS, {self}), result ); to_string(cast(CodeNS, self), result );
break; break;
case Operator: case Operator:
case Operator_Member: case Operator_Member:
to_string_def(cast(CodeOperator, {self}), result ); to_string_def(cast(CodeOperator, self), result );
break; break;
case Operator_Fwd: case Operator_Fwd:
case Operator_Member_Fwd: case Operator_Member_Fwd:
to_string_fwd(cast(CodeOperator, {self}), result ); to_string_fwd(cast(CodeOperator, self), result );
break; break;
case Operator_Cast: case Operator_Cast:
to_string_def(cast(CodeOpCast, {self}), result ); to_string_def(cast(CodeOpCast, self), result );
break; break;
case Operator_Cast_Fwd: case Operator_Cast_Fwd:
to_string_fwd(cast(CodeOpCast, {self}), result ); to_string_fwd(cast(CodeOpCast, self), result );
break; break;
case Parameters: case Parameters:
to_string(cast(CodeParam, {self}), result ); to_string(cast(CodeParam, self), result );
break; break;
case Preprocess_Define: case Preprocess_Define:
to_string(cast(CodeDefine, {self}), result ); to_string(cast(CodeDefine, self), result );
break; break;
case Preprocess_If: case Preprocess_If:
to_string_if(cast(CodePreprocessCond, {self}), result ); to_string_if(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_IfDef: case Preprocess_IfDef:
to_string_ifdef(cast(CodePreprocessCond, {self}), result ); to_string_ifdef(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_IfNotDef: case Preprocess_IfNotDef:
to_string_ifndef(cast(CodePreprocessCond, {self}), result ); to_string_ifndef(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_Include: case Preprocess_Include:
to_string(cast(CodeInclude, {self}), result ); to_string(cast(CodeInclude, self), result );
break; break;
case Preprocess_ElIf: case Preprocess_ElIf:
to_string_elif(cast(CodePreprocessCond, {self}), result ); to_string_elif(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_Else: case Preprocess_Else:
to_string_else(cast(CodePreprocessCond, {self}), result ); to_string_else(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_EndIf: case Preprocess_EndIf:
to_string_endif(cast(CodePreprocessCond, {self}), result ); to_string_endif(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_Pragma: case Preprocess_Pragma:
to_string(cast(CodePragma, {self}), result ); to_string(cast(CodePragma, self), result );
break; break;
case Specifiers: case Specifiers:
to_string(cast(CodeSpecifiers, {self}), result ); to_string(cast(CodeSpecifiers, self), result );
break; break;
case Struct: case Struct:
to_string_def(cast(CodeStruct, {self}), result ); to_string_def(cast(CodeStruct, self), result );
break; break;
case Struct_Fwd: case Struct_Fwd:
to_string_fwd(cast(CodeStruct, {self}), result ); to_string_fwd(cast(CodeStruct, self), result );
break; break;
case Template: case Template:
to_string(cast(CodeTemplate, {self}), result ); to_string(cast(CodeTemplate, self), result );
break; break;
case Typedef: case Typedef:
to_string(cast(CodeTypedef, {self}), result ); to_string(cast(CodeTypedef, self), result );
break; break;
case Typename: case Typename:
to_string(cast(CodeType, {self}), result ); to_string(cast(CodeType, self), result );
break; break;
case Union: case Union:
to_string( cast(CodeUnion, {self}), result ); to_string( cast(CodeUnion, self), result );
break; break;
case Using: case Using:
to_string(cast(CodeUsing, {self}), result ); to_string(cast(CodeUsing, self), result );
break; break;
case Using_Namespace: case Using_Namespace:
to_string_ns(cast(CodeUsing, {self}), result ); to_string_ns(cast(CodeUsing, self), result );
break; break;
case Variable: case Variable:
to_string(cast(CodeVar, {self}), result ); to_string(cast(CodeVar, self), result );
break; break;
case Enum_Body: case Enum_Body:
@ -588,7 +588,7 @@ void to_string( Code self, String* result )
case Namespace_Body: case Namespace_Body:
case Struct_Body: case Struct_Body:
case Union_Body: case Union_Body:
to_string( cast(CodeBody, {self}), result ); to_string( cast(CodeBody, self), result );
break; break;
} }
} }
@ -1160,7 +1160,7 @@ bool validate_body(Code self)
#define CheckEntries( Unallowed_Types ) \ #define CheckEntries( Unallowed_Types ) \
do \ do \
{ \ { \
for ( Code entry : cast(CodeBody, {self}) ) \ for ( Code entry : cast(CodeBody, self) ) \
{ \ { \
switch ( entry->Type ) \ switch ( entry->Type ) \
{ \ { \
@ -1178,7 +1178,7 @@ bool validate_body(Code self)
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
break; break;
case Enum_Body: case Enum_Body:
for ( Code entry : cast(CodeBody, {self}) ) for ( Code entry : cast(CodeBody, self) )
{ {
if ( entry->Type != Untyped ) if ( entry->Type != Untyped )
{ {
@ -1197,7 +1197,7 @@ bool validate_body(Code self)
CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES );
break; break;
case Global_Body: case Global_Body:
for (Code entry : cast(CodeBody, {self})) for (Code entry : cast(CodeBody, self))
{ {
switch (entry->Type) switch (entry->Type)
{ {

View File

@ -17,15 +17,3 @@
#ifndef GEN_ROLL_OWN_DEPENDENCIES #ifndef GEN_ROLL_OWN_DEPENDENCIES
# include "gen.dep.hpp" # include "gen.dep.hpp"
#endif #endif
#ifndef GEN_NS_BEGIN
# ifdef GEN_DONT_USE_NAMESPACE
# define GEN_NS
# define GEN_NS_BEGIN
# define GEN_NS_END
# else
# define GEN_NS gen::
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }
# endif
#endif

View File

@ -42,74 +42,126 @@ void set_allocator_type_table ( AllocatorInfo type_reg_allocator );
CodeAttributes def_attributes( StrC content ); CodeAttributes def_attributes( StrC content );
CodeComment def_comment ( StrC content ); CodeComment def_comment ( StrC content );
CodeClass def_class( StrC name struct Opts_def_struct {
, Code body = NullCode Code body;
, CodeType parent = NullCode, AccessSpec access = AccessSpec_Default CodeType parent;
, CodeAttributes attributes = NullCode AccessSpec parent_access;
, ModuleFlag mflags = ModuleFlag_None CodeAttributes attributes;
, CodeType* interfaces = nullptr, s32 num_interfaces = 0 ); ModuleFlag mflags;
CodeType* interfaces;
s32 num_interfaces;
};
CodeClass def_class( StrC name, Opts_def_struct otps GEN_PARAM_DEFAULT );
CodeConstructor def_constructor( CodeParam params = NullCode, Code initializer_list = NullCode, Code body = NullCode ); struct Opts_def_constructor {
CodeParam params;
Code initializer_list;
Code body;
};
CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT );
CodeDefine def_define( StrC name, StrC content ); CodeDefine def_define( StrC name, StrC content );
CodeDestructor def_destructor( Code body = NullCode, CodeSpecifiers specifiers = NullCode ); struct Opts_def_destructor {
Code body;
CodeSpecifiers specifiers;
};
CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
CodeEnum def_enum( StrC name struct Opts_def_enum {
, Code body = NullCode, CodeType type = NullCode Code body;
, EnumT specifier = EnumDecl_Regular, CodeAttributes attributes = NullCode CodeType type;
, ModuleFlag mflags = ModuleFlag_None ); EnumT specifier;
CodeAttributes attributes;
ModuleFlag mflags;
};
CodeEnum def_enum( StrC name, Opts_def_enum opts GEN_PARAM_DEFAULT );
CodeExec def_execution ( StrC content ); CodeExec def_execution ( StrC content );
CodeExtern def_extern_link( StrC name, Code body ); CodeExtern def_extern_link( StrC name, Code body );
CodeFriend def_friend ( Code symbol ); CodeFriend def_friend ( Code symbol );
CodeFn def_function( StrC name struct Opts_def_function {
, CodeParam params = NullCode, CodeType ret_type = NullCode, Code body = NullCode CodeParam params;
, CodeSpecifiers specifiers = NullCode, CodeAttributes attributes = NullCode CodeType ret_type;
, ModuleFlag mflags = ModuleFlag_None ); Code body;
CodeSpecifiers specs;
CodeAttributes attrs;
ModuleFlag mflags;
};
CodeFn def_function( StrC name, Opts_def_function opts GEN_PARAM_DEFAULT );
CodeInclude def_include ( StrC content, bool foreign = false ); struct Opts_def_include { b32 foreign; };
CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFlag_None ); struct Opts_def_module { ModuleFlag mflags; };
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag_None ); 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 );
CodeOperator def_operator( OperatorT op, StrC nspace struct Opts_def_operator {
, CodeParam params = NullCode, CodeType ret_type = NullCode, Code body = NullCode CodeParam params;
, CodeSpecifiers specifiers = NullCode, CodeAttributes attributes = NullCode CodeType ret_type;
, ModuleFlag mflags = ModuleFlag_None ); Code body;
CodeSpecifiers specifiers;
CodeAttributes attributes;
ModuleFlag mflags;
};
CodeOperator def_operator( OperatorT op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
CodeOpCast def_operator_cast( CodeType type, Code body = NullCode, CodeSpecifiers specs = NullCode ); struct Opts_def_operator_cast {
Code body;
CodeSpecifiers specs;
};
CodeOpCast def_operator_cast( CodeType type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
CodeParam def_param ( CodeType type, StrC name, Code value = NullCode ); struct Opts_def_param { Code value; };
CodeParam def_param ( CodeType type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT );
CodePragma def_pragma( StrC directive ); CodePragma def_pragma( StrC directive );
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content ); CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
CodeSpecifiers def_specifier( SpecifierT specifier ); CodeSpecifiers def_specifier( SpecifierT specifier );
CodeStruct def_struct( StrC name CodeStruct def_struct( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
, Code body = NullCode
, CodeType parent = NullCode, AccessSpec access = AccessSpec_Default
, CodeAttributes attributes = NullCode
, ModuleFlag mflags = ModuleFlag_None
, CodeType* interfaces = nullptr, s32 num_interfaces = 0 );
CodeTemplate def_template( CodeParam params, Code definition, ModuleFlag mflags = ModuleFlag_None ); struct Opts_def_template { ModuleFlag mflags; };
CodeTemplate def_template( CodeParam params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
CodeType def_type ( StrC name, Code arrayexpr = NullCode, CodeSpecifiers specifiers = NullCode, CodeAttributes attributes = NullCode ); struct Opts_def_type {
CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes = NullCode, ModuleFlag mflags = ModuleFlag_None ); Code arrayexpr;
CodeSpecifiers specifiers;
CodeAttributes attributes;
};
CodeType def_type( StrC name, Opts_def_type opts GEN_PARAM_DEFAULT );
CodeUnion def_union( StrC name, Code body, CodeAttributes attributes = NullCode, ModuleFlag mflags = ModuleFlag_None ); struct Opts_def_typedef {
CodeAttributes attributes;
ModuleFlag mflags;
};
CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef opts GEN_PARAM_DEFAULT );
CodeUsing def_using( StrC name, CodeType type = NullCode struct Opts_def_union {
, CodeAttributes attributess = NullCode CodeAttributes attributes;
, ModuleFlag mflags = ModuleFlag_None ); ModuleFlag mflags;
};
CodeUnion def_union( StrC name, Code 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_namespace( StrC name ); CodeUsing def_using_namespace( StrC name );
CodeVar def_variable( CodeType type, StrC name, Code value = NullCode struct Opts_def_variable
, CodeSpecifiers specifiers = NullCode, CodeAttributes attributes = NullCode {
, ModuleFlag mflags = ModuleFlag_None ); Code value;
CodeSpecifiers specifiers;
CodeAttributes attributes;
ModuleFlag mflags;
};
CodeVar def_variable( CodeType type, StrC 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. // Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
CodeBody def_body( CodeT type ); CodeBody def_body( CodeT type );

View File

@ -495,11 +495,13 @@ CodeComment def_comment( StrC content )
return (CodeComment) result; return (CodeComment) result;
} }
CodeConstructor def_constructor( CodeParam params, Code initializer_list, Code body ) CodeConstructor def_constructor( Opts_def_constructor p )
{ {
using namespace ECode; CodeParam params = p.params;
Code initializer_list = p.initializer_list;
Code body = p.body;
if ( params && params->Type != Parameters ) if ( params && params->Type != ECode::Parameters )
{ {
log_failure("gen::def_constructor: params must be of Parameters type - %s", debug_str(params)); log_failure("gen::def_constructor: params must be of Parameters type - %s", debug_str(params));
return InvalidCode; return InvalidCode;
@ -522,8 +524,8 @@ CodeConstructor def_constructor( CodeParam params, Code initializer_list, Code b
{ {
switch ( body->Type ) switch ( body->Type )
{ {
case Function_Body: case ECode::Function_Body:
case Untyped: case ECode::Untyped:
break; break;
default: default:
@ -531,35 +533,36 @@ CodeConstructor def_constructor( CodeParam params, Code initializer_list, Code b
return InvalidCode; return InvalidCode;
} }
result->Type = Constructor; result->Type = ECode::Constructor;
result->Body = body; result->Body = body;
} }
else else
{ {
result->Type = Constructor_Fwd; result->Type = ECode::Constructor_Fwd;
} }
return result; return result;
} }
CodeClass def_class( StrC name CodeClass def_class( StrC name, Opts_def_struct p )
, Code body
, CodeType parent, AccessSpec parent_access
, CodeAttributes attributes
, ModuleFlag mflags
, CodeType* interfaces, s32 num_interfaces )
{ {
using namespace ECode;
name_check( def_class, name ); name_check( def_class, name );
if ( attributes && attributes->Type != PlatformAttributes ) Code body = p.body;
CodeType parent = p.parent;
AccessSpec parent_access = p.parent_access;
CodeAttributes attributes = p.attributes;
ModuleFlag mflags = p.mflags;
CodeType* interfaces = p.interfaces;
s32 num_interfaces = p.num_interfaces;
if ( attributes && attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", debug_str(attributes) ); log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", debug_str(attributes) );
return InvalidCode; return InvalidCode;
} }
if ( parent && ( parent->Type != Class && parent->Type != Struct && parent->Type != Typename && parent->Type != Untyped ) ) if ( parent && ( parent->Type != ECode::Class && parent->Type != ECode::Struct && parent->Type != ECode::Typename && parent->Type != ECode::Untyped ) )
{ {
log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", debug_str(parent) ); log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", debug_str(parent) );
return InvalidCode; return InvalidCode;
@ -574,8 +577,8 @@ CodeClass def_class( StrC name
{ {
switch ( body->Type ) switch ( body->Type )
{ {
case Class_Body: case ECode::Class_Body:
case Untyped: case ECode::Untyped:
break; break;
default: default:
@ -583,13 +586,13 @@ CodeClass def_class( StrC name
return InvalidCode; return InvalidCode;
} }
result->Type = Class; result->Type = ECode::Class;
result->Body = body; result->Body = body;
result->Body->Parent = result; // TODO(Ed): Review this? result->Body->Parent = result; // TODO(Ed): Review this?
} }
else else
{ {
result->Type = Class_Fwd; result->Type = ECode::Class_Fwd;
} }
if ( attributes ) if ( attributes )
@ -614,8 +617,6 @@ CodeClass def_class( StrC name
CodeDefine def_define( StrC name, StrC content ) CodeDefine def_define( StrC name, StrC content )
{ {
using namespace ECode;
name_check( def_define, name ); name_check( def_define, name );
// Defines can be empty definitions // Defines can be empty definitions
@ -629,7 +630,7 @@ CodeDefine def_define( StrC name, StrC content )
CodeDefine CodeDefine
result = (CodeDefine) make_code(); result = (CodeDefine) make_code();
result->Type = Preprocess_Define; result->Type = ECode::Preprocess_Define;
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
if ( content.Len <= 0 || content.Ptr == nullptr ) if ( content.Len <= 0 || content.Ptr == nullptr )
{ {
@ -641,11 +642,12 @@ CodeDefine def_define( StrC name, StrC content )
return result; return result;
} }
CodeDestructor def_destructor( Code body, CodeSpecifiers specifiers ) CodeDestructor def_destructor( Opts_def_destructor p )
{ {
using namespace ECode; Code body = p.body;
CodeSpecifiers specifiers = p.specifiers;
if ( specifiers && specifiers->Type != Specifiers ) if ( specifiers && specifiers->Type != ECode::Specifiers )
{ {
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", debug_str(specifiers) ); log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", debug_str(specifiers) );
return InvalidCode; return InvalidCode;
@ -660,8 +662,8 @@ CodeDestructor def_destructor( Code body, CodeSpecifiers specifiers )
{ {
switch ( body->Type ) switch ( body->Type )
{ {
case Function_Body: case ECode::Function_Body:
case Untyped: case ECode::Untyped:
break; break;
default: default:
@ -669,33 +671,34 @@ CodeDestructor def_destructor( Code body, CodeSpecifiers specifiers )
return InvalidCode; return InvalidCode;
} }
result->Type = Destructor; result->Type = ECode::Destructor;
result->Body = body; result->Body = body;
} }
else else
{ {
result->Type = Destructor_Fwd; result->Type = ECode::Destructor_Fwd;
} }
return result; return result;
} }
CodeEnum def_enum( StrC name CodeEnum def_enum( StrC name, Opts_def_enum p )
, Code body, CodeType type
, EnumT specifier, CodeAttributes attributes
, ModuleFlag mflags )
{ {
using namespace ECode; Code body = p.body;
CodeType type = p.type;
EnumT specifier = p.specifier;
CodeAttributes attributes = p.attributes;
ModuleFlag mflags = p.mflags;
name_check( def_enum, name ); name_check( def_enum, name );
if ( type && type->Type != Typename ) if ( type && type->Type != ECode::Typename )
{ {
log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", debug_str(type) ); log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", debug_str(type) );
return InvalidCode; return InvalidCode;
} }
if ( attributes && attributes->Type != PlatformAttributes ) if ( attributes && attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", debug_str(attributes) ); log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", debug_str(attributes) );
return InvalidCode; return InvalidCode;
@ -710,8 +713,8 @@ CodeEnum def_enum( StrC name
{ {
switch ( body->Type ) switch ( body->Type )
{ {
case Enum_Body: case ECode::Enum_Body:
case Untyped: case ECode::Untyped:
break; break;
default: default:
@ -720,14 +723,14 @@ CodeEnum def_enum( StrC name
} }
result->Type = specifier == EnumDecl_Class ? result->Type = specifier == EnumDecl_Class ?
Enum_Class : Enum; ECode::Enum_Class : ECode::Enum;
result->Body = body; result->Body = body;
} }
else else
{ {
result->Type = specifier == EnumDecl_Class ? result->Type = specifier == EnumDecl_Class ?
Enum_Class_Fwd : Enum_Fwd; ECode::Enum_Class_Fwd : ECode::Enum_Fwd;
} }
if ( attributes ) if ( attributes )
@ -737,7 +740,7 @@ CodeEnum def_enum( StrC name
{ {
result->UnderlyingType = type; result->UnderlyingType = type;
} }
else if ( result->Type != Enum_Class_Fwd && result->Type != Enum_Fwd ) else if ( result->Type != ECode::Enum_Class_Fwd && result->Type != ECode::Enum_Fwd )
{ {
log_failure( "gen::def_enum: enum forward declaration must have an underlying type" ); log_failure( "gen::def_enum: enum forward declaration must have an underlying type" );
return InvalidCode; return InvalidCode;
@ -765,12 +768,10 @@ CodeExec def_execution( StrC content )
CodeExtern def_extern_link( StrC name, Code body ) CodeExtern def_extern_link( StrC name, Code body )
{ {
using namespace ECode;
name_check( def_extern_linkage, name ); name_check( def_extern_linkage, name );
null_check( def_extern_linkage, body ); null_check( def_extern_linkage, body );
if ( body->Type != Extern_Linkage_Body && body->Type != Untyped ) if ( body->Type != ECode::Extern_Linkage_Body && body->Type != ECode::Untyped )
{ {
log_failure("gen::def_extern_linkage: body is not of extern_linkage or untyped type %s", debug_str(body)); log_failure("gen::def_extern_linkage: body is not of extern_linkage or untyped type %s", debug_str(body));
return InvalidCode; return InvalidCode;
@ -778,7 +779,7 @@ CodeExtern def_extern_link( StrC name, Code body )
CodeExtern CodeExtern
result = (CodeExtern)make_code(); result = (CodeExtern)make_code();
result->Type = Extern_Linkage; result->Type = ECode::Extern_Linkage;
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
result->Body = body; result->Body = body;
@ -787,20 +788,18 @@ CodeExtern def_extern_link( StrC name, Code body )
CodeFriend def_friend( Code declaration ) CodeFriend def_friend( Code declaration )
{ {
using namespace ECode;
null_check( def_friend, declaration ); null_check( def_friend, declaration );
switch ( declaration->Type ) switch ( declaration->Type )
{ {
case Class_Fwd: case ECode::Class_Fwd:
case Function_Fwd: case ECode::Function_Fwd:
case Operator_Fwd: case ECode::Operator_Fwd:
case Struct_Fwd: case ECode::Struct_Fwd:
case Class: case ECode::Class:
case Function: case ECode::Function:
case Operator: case ECode::Operator:
case Struct: case ECode::Struct:
break; break;
default: default:
@ -810,41 +809,43 @@ CodeFriend def_friend( Code declaration )
CodeFriend CodeFriend
result = (CodeFriend) make_code(); result = (CodeFriend) make_code();
result->Type = Friend; result->Type = ECode::Friend;
result->Declaration = declaration; result->Declaration = declaration;
return result; return result;
} }
CodeFn def_function( StrC name CodeFn def_function( StrC name, Opts_def_function p )
, CodeParam params , CodeType ret_type, Code body
, CodeSpecifiers specifiers, CodeAttributes attributes
, ModuleFlag mflags )
{ {
using namespace ECode; CodeParam params = p.params;
CodeType ret_type = p.ret_type;
Code body = p.body;
CodeSpecifiers specifiers = p.specs;
CodeAttributes attributes = p.attrs;
ModuleFlag mflags = p.mflags;
name_check( def_function, name ); name_check( def_function, name );
if ( params && params->Type != Parameters ) if ( params && params->Type != ECode::Parameters )
{ {
log_failure( "gen::def_function: params was not a `Parameters` type: %s", debug_str(params) ); log_failure( "gen::def_function: params was not a `Parameters` type: %s", debug_str(params) );
return InvalidCode; return InvalidCode;
} }
if ( ret_type && ret_type->Type != Typename ) if ( ret_type && ret_type->Type != ECode::Typename )
{ {
log_failure( "gen::def_function: ret_type was not a Typename: %s", debug_str(ret_type) ); log_failure( "gen::def_function: ret_type was not a Typename: %s", debug_str(ret_type) );
return InvalidCode; return InvalidCode;
} }
if ( specifiers && specifiers->Type != Specifiers ) if ( specifiers && specifiers->Type != ECode::Specifiers )
{ {
log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", debug_str(specifiers) ); log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", debug_str(specifiers) );
return InvalidCode; return InvalidCode;
} }
if ( attributes && attributes->Type != PlatformAttributes ) if ( attributes && attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_function: attributes was not a `PlatformAttributes` type: %s", debug_str(attributes) ); log_failure( "gen::def_function: attributes was not a `PlatformAttributes` type: %s", debug_str(attributes) );
return InvalidCode; return InvalidCode;
@ -859,9 +860,9 @@ CodeFn def_function( StrC name
{ {
switch ( body->Type ) switch ( body->Type )
{ {
case Function_Body: case ECode::Function_Body:
case Execution: case ECode::Execution:
case Untyped: case ECode::Untyped:
break; break;
default: default:
@ -871,12 +872,12 @@ CodeFn def_function( StrC name
} }
} }
result->Type = Function; result->Type = ECode::Function;
result->Body = body; result->Body = body;
} }
else else
{ {
result->Type = Function_Fwd; result->Type = ECode::Function_Fwd;
} }
if ( attributes ) if ( attributes )
@ -900,7 +901,7 @@ CodeFn def_function( StrC name
return result; return result;
} }
CodeInclude def_include( StrC path, bool foreign ) CodeInclude def_include( StrC path, Opts_def_include p )
{ {
if ( path.Len <= 0 || path.Ptr == nullptr ) if ( path.Len <= 0 || path.Ptr == nullptr )
{ {
@ -908,7 +909,7 @@ CodeInclude def_include( StrC path, bool foreign )
return InvalidCode; return InvalidCode;
} }
StrC content = foreign ? StrC content = p.foreign ?
to_str( str_fmt_buf( "<%.*s>", path.Len, path.Ptr )) to_str( str_fmt_buf( "<%.*s>", path.Len, path.Ptr ))
: to_str( str_fmt_buf( "\"%.*s\"", path.Len, path.Ptr )); : to_str( str_fmt_buf( "\"%.*s\"", path.Len, path.Ptr ));
@ -921,7 +922,7 @@ CodeInclude def_include( StrC path, bool foreign )
return (CodeInclude) result; return (CodeInclude) result;
} }
CodeModule def_module( StrC name, ModuleFlag mflags ) CodeModule def_module( StrC name, Opts_def_module p )
{ {
name_check( def_module, name ); name_check( def_module, name );
@ -930,19 +931,17 @@ CodeModule def_module( StrC name, ModuleFlag mflags )
result->Type = ECode::Module; result->Type = ECode::Module;
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
result->Content = result->Name; result->Content = result->Name;
result->ModuleFlags = mflags; result->ModuleFlags = p.mflags;
return (CodeModule) result; return (CodeModule) result;
} }
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags ) CodeNS def_namespace( StrC name, Code body, Opts_def_namespace p )
{ {
using namespace ECode;
name_check( def_namespace, name ); name_check( def_namespace, name );
null_check( def_namespace, body ); null_check( def_namespace, body);
if ( body->Type != Namespace_Body && body->Type != Untyped ) if ( body && body->Type != ECode::Namespace_Body && body->Type != ECode::Untyped )
{ {
log_failure("gen::def_namespace: body is not of namespace or untyped type %s", debug_str(body)); log_failure("gen::def_namespace: body is not of namespace or untyped type %s", debug_str(body));
return InvalidCode; return InvalidCode;
@ -950,28 +949,29 @@ CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags )
CodeNS CodeNS
result = (CodeNS) make_code(); result = (CodeNS) make_code();
result->Type = Namespace; result->Type = ECode::Namespace;
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
result->ModuleFlags = mflags; result->ModuleFlags = p.mflags;
result->Body = body; result->Body = body;
return result; return result;
} }
CodeOperator def_operator( OperatorT op, StrC nspace CodeOperator def_operator( OperatorT op, StrC nspace, Opts_def_operator p )
, CodeParam params_code, CodeType ret_type, Code body
, CodeSpecifiers specifiers, CodeAttributes attributes
, ModuleFlag mflags )
{ {
using namespace ECode; CodeParam params_code = p.params;
CodeType ret_type = p.ret_type;
Code body = p.body;
CodeSpecifiers specifiers = p.specifiers;
CodeAttributes attributes = p.attributes;
ModuleFlag mflags = p.mflags;
if ( attributes && attributes->Type != PlatformAttributes ) if ( attributes && attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", debug_str(attributes) ); log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", debug_str(attributes) );
return InvalidCode; return InvalidCode;
} }
if ( specifiers && specifiers->Type != Specifiers ) if ( specifiers && specifiers->Type != ECode::Specifiers )
{ {
log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", debug_str(specifiers) ); log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", debug_str(specifiers) );
return InvalidCode; return InvalidCode;
@ -1001,9 +1001,9 @@ CodeOperator def_operator( OperatorT op, StrC nspace
{ {
switch ( body->Type ) switch ( body->Type )
{ {
case Function_Body: case ECode::Function_Body:
case Execution: case ECode::Execution:
case Untyped: case ECode::Untyped:
break; break;
default: default:
@ -1014,14 +1014,14 @@ CodeOperator def_operator( OperatorT op, StrC nspace
} }
result->Type = check_result == OpValidateResult::Global ? result->Type = check_result == OpValidateResult::Global ?
Operator : Operator_Member; ECode::Operator : ECode::Operator_Member;
result->Body = body; result->Body = body;
} }
else else
{ {
result->Type = check_result == OpValidateResult::Global ? result->Type = check_result == OpValidateResult::Global ?
Operator_Fwd : Operator_Member_Fwd; ECode::Operator_Fwd : ECode::Operator_Member_Fwd;
} }
if ( attributes ) if ( attributes )
@ -1038,12 +1038,14 @@ CodeOperator def_operator( OperatorT op, StrC nspace
return result; return result;
} }
CodeOpCast def_operator_cast( CodeType type, Code body, CodeSpecifiers const_spec ) CodeOpCast def_operator_cast( CodeType type, Opts_def_operator_cast p )
{ {
using namespace ECode; Code body = p.body;
CodeSpecifiers const_spec = p.specs;
null_check( def_operator_cast, type ); null_check( def_operator_cast, type );
if ( type->Type != Typename ) if ( type->Type != ECode::Typename )
{ {
log_failure( "gen::def_operator_cast: type is not a typename - %s", debug_str(type) ); log_failure( "gen::def_operator_cast: type is not a typename - %s", debug_str(type) );
return InvalidCode; return InvalidCode;
@ -1053,9 +1055,9 @@ CodeOpCast def_operator_cast( CodeType type, Code body, CodeSpecifiers const_spe
if (body) if (body)
{ {
result->Type = Operator_Cast; result->Type = ECode::Operator_Cast;
if ( body->Type != Function_Body && body->Type != Execution ) if ( body->Type != ECode::Function_Body && body->Type != ECode::Execution )
{ {
log_failure( "gen::def_operator_cast: body is not of function body or execution type - %s", debug_str(body) ); log_failure( "gen::def_operator_cast: body is not of function body or execution type - %s", debug_str(body) );
return InvalidCode; return InvalidCode;
@ -1065,7 +1067,7 @@ CodeOpCast def_operator_cast( CodeType type, Code body, CodeSpecifiers const_spe
} }
else else
{ {
result->Type = Operator_Cast_Fwd; result->Type = ECode::Operator_Cast_Fwd;
} }
if ( const_spec ) if ( const_spec )
@ -1077,34 +1079,32 @@ CodeOpCast def_operator_cast( CodeType type, Code body, CodeSpecifiers const_spe
return result; return result;
} }
CodeParam def_param( CodeType type, StrC name, Code value ) CodeParam def_param( CodeType type, StrC name, Opts_def_param p )
{ {
using namespace ECode;
name_check( def_param, name ); name_check( def_param, name );
null_check( def_param, type ); null_check( def_param, type );
if ( type->Type != Typename ) if ( type->Type != ECode::Typename )
{ {
log_failure( "gen::def_param: type is not a typename - %s", debug_str(type) ); log_failure( "gen::def_param: type is not a typename - %s", debug_str(type) );
return InvalidCode; return InvalidCode;
} }
if ( value && value->Type != Untyped ) if ( p.value && p.value->Type != ECode::Untyped )
{ {
log_failure( "gen::def_param: value is not untyped - %s", debug_str(value) ); log_failure( "gen::def_param: value is not untyped - %s", debug_str(p.value) );
return InvalidCode; return InvalidCode;
} }
CodeParam CodeParam
result = (CodeParam) make_code(); result = (CodeParam) make_code();
result->Type = Parameters; result->Type = ECode::Parameters;
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
result->ValueType = type; result->ValueType = type;
if ( value ) if ( p.value )
result->Value = value; result->Value = p.value;
result->NumEntries++; result->NumEntries++;
@ -1113,8 +1113,6 @@ CodeParam def_param( CodeType type, StrC name, Code value )
CodePragma def_pragma( StrC directive ) CodePragma def_pragma( StrC directive )
{ {
using namespace ECode;
if ( directive.Len <= 0 || directive.Ptr == nullptr ) if ( directive.Len <= 0 || directive.Ptr == nullptr )
{ {
log_failure( "gen::def_comment: Invalid comment provided:" ); log_failure( "gen::def_comment: Invalid comment provided:" );
@ -1123,7 +1121,7 @@ CodePragma def_pragma( StrC directive )
CodePragma CodePragma
result = (CodePragma) make_code(); result = (CodePragma) make_code();
result->Type = Preprocess_Pragma; result->Type = ECode::Preprocess_Pragma;
result->Content = get_cached_string( directive ); result->Content = get_cached_string( directive );
return result; return result;
@ -1131,8 +1129,6 @@ CodePragma def_pragma( StrC directive )
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC expr ) CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC expr )
{ {
using namespace ECode;
if ( expr.Len <= 0 || expr.Ptr == nullptr ) if ( expr.Len <= 0 || expr.Ptr == nullptr )
{ {
log_failure( "gen::def_comment: Invalid comment provided:" ); log_failure( "gen::def_comment: Invalid comment provided:" );
@ -1146,16 +1142,16 @@ CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC expr )
switch (type) switch (type)
{ {
case PreprocessCond_If: case PreprocessCond_If:
result->Type = Preprocess_If; result->Type = ECode::Preprocess_If;
break; break;
case PreprocessCond_IfDef: case PreprocessCond_IfDef:
result->Type = Preprocess_IfDef; result->Type = ECode::Preprocess_IfDef;
break; break;
case PreprocessCond_IfNotDef: case PreprocessCond_IfNotDef:
result->Type = Preprocess_IfNotDef; result->Type = ECode::Preprocess_IfNotDef;
break; break;
case PreprocessCond_ElIf: case PreprocessCond_ElIf:
result->Type = Preprocess_ElIf; result->Type = ECode::Preprocess_ElIf;
break; break;
} }
@ -1172,28 +1168,29 @@ CodeSpecifiers def_specifier( SpecifierT spec )
return result; return result;
} }
CodeStruct def_struct( StrC name CodeStruct def_struct( StrC name, Opts_def_struct p )
, Code body
, CodeType parent, AccessSpec parent_access
, CodeAttributes attributes
, ModuleFlag mflags
, CodeType* interfaces, s32 num_interfaces )
{ {
using namespace ECode; Code body = p.body;
CodeType parent = p.parent;
AccessSpec parent_access = p.parent_access;
CodeAttributes attributes = p.attributes;
ModuleFlag mflags = p.mflags;
CodeType* interfaces = p.interfaces;
s32 num_interfaces = p.num_interfaces;
if ( attributes && attributes->Type != PlatformAttributes ) if ( attributes && attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", debug_str(attributes) ); log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", debug_str(attributes) );
return InvalidCode; return InvalidCode;
} }
if ( parent && parent->Type != Typename ) if ( parent && parent->Type != ECode::Typename )
{ {
log_failure( "gen::def_struct: parent was not a `Struct` type - %s", debug_str(parent) ); log_failure( "gen::def_struct: parent was not a `Struct` type - %s", debug_str(parent) );
return InvalidCode; return InvalidCode;
} }
if ( body && body->Type != Struct_Body ) if ( body && body->Type != ECode::Struct_Body )
{ {
log_failure( "gen::def_struct: body was not a Struct_Body type - %s", debug_str(body) ); log_failure( "gen::def_struct: body was not a Struct_Body type - %s", debug_str(body) );
return InvalidCode; return InvalidCode;
@ -1208,12 +1205,12 @@ CodeStruct def_struct( StrC name
if ( body ) if ( body )
{ {
result->Type = Struct; result->Type = ECode::Struct;
result->Body = body; result->Body = body;
} }
else else
{ {
result->Type = Struct_Fwd; result->Type = ECode::Struct_Fwd;
} }
if ( attributes ) if ( attributes )
@ -1236,7 +1233,7 @@ CodeStruct def_struct( StrC name
return result; return result;
} }
CodeTemplate def_template( CodeParam params, Code declaration, ModuleFlag mflags ) CodeTemplate def_template( CodeParam params, Code declaration, Opts_def_template p )
{ {
null_check( def_template, declaration ); null_check( def_template, declaration );
@ -1262,17 +1259,20 @@ CodeTemplate def_template( CodeParam params, Code declaration, ModuleFlag mflags
CodeTemplate CodeTemplate
result = (CodeTemplate) make_code(); result = (CodeTemplate) make_code();
result->Type = ECode::Template; result->Type = ECode::Template;
result->ModuleFlags = mflags; result->ModuleFlags = p.mflags;
result->Params = params; result->Params = params;
result->Declaration = declaration; result->Declaration = declaration;
return result; return result;
} }
CodeType def_type( StrC name, Code arrayexpr, CodeSpecifiers specifiers, CodeAttributes attributes ) CodeType def_type( StrC name, Opts_def_type p )
{ {
name_check( def_type, name ); name_check( def_type, name );
Code arrayexpr = p.arrayexpr;
CodeSpecifiers specifiers = p.specifiers;
CodeAttributes attributes = p.attributes;
if ( attributes && attributes->Type != ECode::PlatformAttributes ) if ( attributes && attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_type: attributes is not of attributes type - %s", debug_str(attributes) ); log_failure( "gen::def_type: attributes is not of attributes type - %s", debug_str(attributes) );
@ -1308,34 +1308,32 @@ CodeType def_type( StrC name, Code arrayexpr, CodeSpecifiers specifiers, CodeAtt
return result; return result;
} }
CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, ModuleFlag mflags ) CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p )
{ {
using namespace ECode;
null_check( def_typedef, type ); null_check( def_typedef, type );
switch ( type->Type ) switch ( type->Type )
{ {
case Class: case ECode::Class:
case Class_Fwd: case ECode::Class_Fwd:
case Enum: case ECode::Enum:
case Enum_Fwd: case ECode::Enum_Fwd:
case Enum_Class: case ECode::Enum_Class:
case Enum_Class_Fwd: case ECode::Enum_Class_Fwd:
case Function_Fwd: case ECode::Function_Fwd:
case Struct: case ECode::Struct:
case Struct_Fwd: case ECode::Struct_Fwd:
case Union: case ECode::Union:
case Typename: case ECode::Typename:
break; break;
default: default:
log_failure( "gen::def_typedef: type was not a Class, Enum, Function Forward, Struct, Typename, or Union - %s", debug_str(type) ); log_failure( "gen::def_typedef: type was not a Class, Enum, Function Forward, Struct, Typename, or Union - %s", debug_str(type) );
return InvalidCode; return InvalidCode;
} }
if ( attributes && attributes->Type != ECode::PlatformAttributes ) if ( p.attributes && p.attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_typedef: attributes was not a PlatformAttributes - %s", debug_str(attributes) ); log_failure( "gen::def_typedef: attributes was not a PlatformAttributes - %s", debug_str(p.attributes) );
return InvalidCode; return InvalidCode;
} }
@ -1351,13 +1349,13 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
CodeTypedef CodeTypedef
result = (CodeTypedef) make_code(); result = (CodeTypedef) make_code();
result->Type = ECode::Typedef; result->Type = ECode::Typedef;
result->ModuleFlags = mflags; result->ModuleFlags = p.mflags;
result->UnderlyingType = type; result->UnderlyingType = type;
if ( name.Len <= 0 ) if ( name.Len <= 0 )
{ {
if (type->Type != Untyped) if (type->Type != ECode::Untyped)
{ {
log_failure( "gen::def_typedef: name was empty and type was not untyped (indicating its a function typedef) - %s", debug_str(type) ); log_failure( "gen::def_typedef: name was empty and type was not untyped (indicating its a function typedef) - %s", debug_str(type) );
return InvalidCode; return InvalidCode;
@ -1375,7 +1373,7 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
return result; return result;
} }
CodeUnion def_union( StrC name, Code body, CodeAttributes attributes, ModuleFlag mflags ) CodeUnion def_union( StrC name, Code body, Opts_def_union p )
{ {
null_check( def_union, body ); null_check( def_union, body );
@ -1385,15 +1383,15 @@ CodeUnion def_union( StrC name, Code body, CodeAttributes attributes, ModuleFlag
return InvalidCode; return InvalidCode;
} }
if ( attributes && attributes->Type != ECode::PlatformAttributes ) if ( p.attributes && p.attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_union: attributes was not a PlatformAttributes type - %s", debug_str(attributes) ); log_failure( "gen::def_union: attributes was not a PlatformAttributes type - %s", debug_str(p.attributes) );
return InvalidCode; return InvalidCode;
} }
CodeUnion CodeUnion
result = (CodeUnion) make_code(); result = (CodeUnion) make_code();
result->ModuleFlags = mflags; result->ModuleFlags = p.mflags;
result->Type = ECode::Union; result->Type = ECode::Union;
if ( name.Ptr ) if ( name.Ptr )
@ -1401,15 +1399,13 @@ CodeUnion def_union( StrC name, Code body, CodeAttributes attributes, ModuleFlag
result->Body = body; result->Body = body;
if ( attributes ) if ( p.attributes )
result->Attributes = attributes; result->Attributes = p.attributes;
return result; return result;
} }
CodeUsing def_using( StrC name, CodeType type CodeUsing def_using( StrC name, Code type, Opts_def_using p )
, CodeAttributes attributes
, ModuleFlag mflags )
{ {
name_check( def_using, name ); name_check( def_using, name );
null_check( def_using, type ); null_check( def_using, type );
@ -1422,22 +1418,22 @@ CodeUsing def_using( StrC name, CodeType type
return InvalidCode; return InvalidCode;
} }
if ( attributes && attributes->Type != ECode::PlatformAttributes ) if ( p.attributes && p.attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_using: attributes was not a PlatformAttributes type - %s", debug_str(attributes) ); log_failure( "gen::def_using: attributes was not a PlatformAttributes type - %s", debug_str(p.attributes) );
return InvalidCode; return InvalidCode;
} }
CodeUsing CodeUsing
result = (CodeUsing) make_code(); result = (CodeUsing) make_code();
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
result->ModuleFlags = mflags; result->ModuleFlags = p.mflags;
result->Type = ECode::Using; result->Type = ECode::Using;
result->UnderlyingType = type; result->UnderlyingType = type;
if ( attributes ) if ( p.attributes )
result->Attributes = attributes; result->Attributes = p.attributes;
return result; return result;
} }
@ -1455,22 +1451,20 @@ CodeUsing def_using_namespace( StrC name )
return (CodeUsing) result; return (CodeUsing) result;
} }
CodeVar def_variable( CodeType type, StrC name, Code value CodeVar def_variable( CodeType type, StrC name, Code value, Opts_def_variable p )
, CodeSpecifiers specifiers, CodeAttributes attributes
, ModuleFlag mflags )
{ {
name_check( def_variable, name ); name_check( def_variable, name );
null_check( def_variable, type ); null_check( def_variable, type );
if ( attributes && attributes->Type != ECode::PlatformAttributes ) if ( p.attributes && p.attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_variable: attributes was not a `PlatformAttributes` type - %s", debug_str(attributes) ); log_failure( "gen::def_variable: attributes was not a `PlatformAttributes` type - %s", debug_str(p.attributes) );
return InvalidCode; return InvalidCode;
} }
if ( specifiers && specifiers->Type != ECode::Specifiers ) if ( p.specifiers && p.specifiers->Type != ECode::Specifiers )
{ {
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type - %s", debug_str(specifiers) ); log_failure( "gen::def_variable: specifiers was not a `Specifiers` type - %s", debug_str(p.specifiers) );
return InvalidCode; return InvalidCode;
} }
@ -1490,15 +1484,15 @@ CodeVar def_variable( CodeType type, StrC name, Code value
result = (CodeVar) make_code(); result = (CodeVar) make_code();
result->Name = get_cached_string( name ); result->Name = get_cached_string( name );
result->Type = ECode::Variable; result->Type = ECode::Variable;
result->ModuleFlags = mflags; result->ModuleFlags = p.mflags;
result->ValueType = type; result->ValueType = type;
if ( attributes ) if ( p.attributes )
result->Attributes = attributes; result->Attributes = p.attributes;
if ( specifiers ) if ( p.specifiers )
result->Specs = specifiers; result->Specs = p.specifiers;
if ( value ) if ( value )
result->Value = value; result->Value = value;

View File

@ -716,7 +716,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
// <ModuleFlags> <class/struct> <Attributes> <Name> // <ModuleFlags> <class/struct> <Attributes> <Name>
local_persist local_persist
char interface_arr_mem[ kilobytes(4) ] {0}; char interface_arr_mem[ kilobytes(4) ] {0};
Array<CodeType> interfaces; { Array<CodeType> interfaces; {
Arena arena = arena_init_from_memory( interface_arr_mem, kilobytes(4) ); Arena arena = arena_init_from_memory( interface_arr_mem, kilobytes(4) );
interfaces = array_init_reserve<CodeType>( allocator_info(& arena), 4 ); interfaces = array_init_reserve<CodeType>( allocator_info(& arena), 4 );
@ -770,14 +770,14 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line ) if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment(); inline_cmt = parse_comment();
// <ModuleFlags> <class/struct> <Attributes> <Name> : <Access Specifier> <Name>, ... { <Body> }; <InlineCmt> // <ModuleFlags> <class/struct> <Attributes> <Name> : <Access Specifier> <Name>, ... { <Body> }; <InlineCmt>
} }
if ( which == TokType::Decl_Class ) if ( which == TokType::Decl_Class )
result = def_class( to_str(name), body, parent, access, attributes, mflags ); result = def_class( to_str(name), { body, parent, access, attributes, mflags } );
else else
result = def_struct( to_str(name), body, (CodeType)parent, access, attributes, mflags ); result = def_struct( to_str(name), { body, (CodeType)parent, access, attributes, mflags } );
if ( inline_cmt ) if ( inline_cmt )
result->InlineCmt = inline_cmt; result->InlineCmt = inline_cmt;
@ -2477,7 +2477,7 @@ CodeOperator parse_operator_after_ret_type(
} }
// OpValidateResult check_result = operator__validate( op, params, ret_type, specifiers ); // OpValidateResult check_result = operator__validate( op, params, ret_type, specifiers );
CodeOperator result = def_operator( op, to_str(nspace), params, ret_type, body, specifiers, attributes, mflags ); CodeOperator result = def_operator( op, to_str(nspace), { params, ret_type, body, specifiers, attributes, mflags } );
if ( inline_cmt ) if ( inline_cmt )
result->InlineCmt = inline_cmt; result->InlineCmt = inline_cmt;

View File

@ -234,4 +234,10 @@
# endif # endif
#endif #endif
#if ! defined(GEN_PARAM_DEFAULT) && ! GEN_COMPILER_C
# define GEN_PARAM_DEFAULT = {}
#else
# define GEN_PARAM_DEFAULT
#endif
#pragma endregion Macros #pragma endregion Macros