Compare commits

...

5 Commits

19 changed files with 808 additions and 631 deletions

View File

@ -552,7 +552,7 @@ Serialization:
Fields: Fields:
```cpp ```cpp
SpecifierT ArrSpecs[ AST::ArrSpecs_Cap ]; SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
CodeSpecifiers NextSpecs; CodeSpecifiers NextSpecs;
Code Prev; Code Prev;
Code Next; Code Next;

View File

@ -101,7 +101,7 @@ union {
}; };
StringCached Content; // Attributes, Comment, Execution, Include StringCached Content; // Attributes, Comment, Execution, Include
struct { struct {
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers AST* NextSpecs; // Specifiers
}; };
}; };

View File

@ -136,7 +136,7 @@ int gen_main()
case ECode::Using: case ECode::Using:
{ {
log_fmt("REPLACE THIS MANUALLY: %S\n", entry->Name); log_fmt("REPLACE THIS MANUALLY: %S\n", entry->Name);
CodeUsing using_ver = entry.code_cast<CodeUsing>(); CodeUsing using_ver = cast(CodeUsing, entry);
CodeTypedef typedef_ver = def_typedef(using_ver->Name, using_ver->UnderlyingType); CodeTypedef typedef_ver = def_typedef(using_ver->Name, using_ver->UnderlyingType);
memory.append(typedef_ver); memory.append(typedef_ver);
@ -144,7 +144,7 @@ int gen_main()
break; break;
case ECode::Function_Fwd: case ECode::Function_Fwd:
{ {
CodeFn fn = entry.code_cast<CodeFn>(); CodeFn fn = cast(CodeFn, entry);
if ( fn->Name.is_equal(txt("free")) ) if ( fn->Name.is_equal(txt("free")) )
{ {
fn->Name = get_cached_string(txt("gen_free_ptr")); fn->Name = get_cached_string(txt("gen_free_ptr"));
@ -154,7 +154,7 @@ int gen_main()
break; break;
case ECode::Function: case ECode::Function:
{ {
CodeFn fn = entry.code_cast<CodeFn>(); CodeFn fn = cast(CodeFn, entry);
s32 constexpr_found = fn->Specs.remove( ESpecifier::Constexpr ); s32 constexpr_found = fn->Specs.remove( ESpecifier::Constexpr );
if (constexpr_found > -1) { if (constexpr_found > -1) {
log_fmt("Found constexpr: %S\n", entry->to_string()); log_fmt("Found constexpr: %S\n", entry->to_string());
@ -169,7 +169,7 @@ int gen_main()
break; break;
case ECode::Template: case ECode::Template:
{ {
CodeTemplate tmpl = entry.code_cast<CodeTemplate>(); CodeTemplate tmpl = cast(CodeTemplate, entry);
if ( tmpl->Declaration->Name.contains(txt("swap"))) if ( tmpl->Declaration->Name.contains(txt("swap")))
{ {
CodeBody macro_swap = parse_global_body( txt(R"( CodeBody macro_swap = parse_global_body( txt(R"(

View File

@ -8,7 +8,7 @@ using SwapContentProc = CodeBody(void);
b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& body ) b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& body )
{ {
b32 found = false; b32 found = false;
CodePreprocessCond cond = entry_iter.code_cast<CodePreprocessCond>(); CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
if ( cond->Content.contains(cond_sig) ) if ( cond->Content.contains(cond_sig) )
{ {
log_fmt("Preprocess cond found: %S\n", cond->Content); log_fmt("Preprocess cond found: %S\n", cond->Content);
@ -44,7 +44,7 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& bod
bool swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_content, Code& entry_iter, CodeBody& body ) bool swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_content, Code& entry_iter, CodeBody& body )
{ {
bool found = false; bool found = false;
CodePragma possible_region = entry_iter.code_cast<CodePragma>(); CodePragma possible_region = cast(CodePragma, entry_iter);
String region_sig = string_fmt_buf(GlobalAllocator, "region %s", region_name.Ptr); String region_sig = string_fmt_buf(GlobalAllocator, "region %s", region_name.Ptr);
String endregion_sig = string_fmt_buf(GlobalAllocator, "endregion %s", region_name.Ptr); String endregion_sig = string_fmt_buf(GlobalAllocator, "endregion %s", region_name.Ptr);
@ -58,7 +58,7 @@ bool swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_
(entry_iter->Type) { (entry_iter->Type) {
case ECode::Preprocess_Pragma: case ECode::Preprocess_Pragma:
{ {
CodePragma possible_end_region = entry_iter.code_cast<CodePragma>(); CodePragma possible_end_region = cast(CodePragma, entry_iter);
if ( possible_end_region->Content.contains(endregion_sig) ) { if ( possible_end_region->Content.contains(endregion_sig) ) {
// body.append(possible_end_region); // body.append(possible_end_region);
continue_for = false; continue_for = false;

View File

@ -1,6 +1,8 @@
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_SUPPORT_CPP_MEMBER_FEATURES 1
#define GEN_SUPPORT_CPP_REFERENCES 0
#include "gen.cpp" #include "gen.cpp"
#include "helpers/push_ignores.inline.hpp" #include "helpers/push_ignores.inline.hpp"

View File

@ -26,7 +26,7 @@ void Builder::pad_lines( s32 num )
void Builder::print( Code code ) void Builder::print( Code code )
{ {
String str = code->to_string(); String str = to_string(code);
// const ssize len = str.length(); // const ssize len = str.length();
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data ); // log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
append( & Buffer, str ); append( & Buffer, str );

View File

@ -1,7 +1,7 @@
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_SUPPORT_CPP_MEMBER_FEATURES 1 #define GEN_SUPPORT_CPP_MEMBER_FEATURES 0
#define GEN_SUPPORT_CPP_REFERENCES 0 #define GEN_SUPPORT_CPP_REFERENCES 0
#include "gen.cpp" #include "gen.cpp"

View File

@ -14,7 +14,7 @@ char const* debug_str(AST* self)
String* result = & result_stack; String* result = & result_stack;
if ( self->Parent ) if ( self->Parent )
append_fmt( result, "\n\tParent : %S %S", self->Parent->type_str(), self->Name ? self->Name : "" ); append_fmt( result, "\n\tParent : %S %S", type_str(self->Parent), self->Name ? self->Name : "" );
else else
append_fmt( result, "\n\tParent : %S", "Null" ); append_fmt( result, "\n\tParent : %S", "Null" );
@ -372,19 +372,20 @@ AST* duplicate(AST* self)
return result; return result;
} }
String AST::to_string() String to_string(AST* self)
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
to_string( result ); GEN_NS to_string( self, & result );
return result; return result;
} }
void AST::to_string( String& result ) void to_string( AST* self, String* result )
{ {
GEN_ASSERT(self != nullptr);
local_persist thread_local local_persist thread_local
char SerializationLevel = 0; char SerializationLevel = 0;
switch ( Type ) switch ( self->Type )
{ {
using namespace ECode; using namespace ECode;
@ -392,191 +393,191 @@ void AST::to_string( String& result )
#ifdef GEN_DONT_ALLOW_INVALID_CODE #ifdef GEN_DONT_ALLOW_INVALID_CODE
log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->debug_str() : Name ); log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->debug_str() : Name );
#else #else
GEN_NS append_fmt( & result, "Invalid Code!" ); append_fmt( result, "Invalid Code!" );
#endif #endif
break; break;
case NewLine: case NewLine:
GEN_NS append( & result,"\n"); append( result,"\n");
break; break;
case Untyped: case Untyped:
case Execution: case Execution:
case Comment: case Comment:
case PlatformAttributes: case PlatformAttributes:
GEN_NS append( & result, Content ); append( result, self->Content );
break; break;
case Access_Private: case Access_Private:
case Access_Protected: case Access_Protected:
case Access_Public: case Access_Public:
GEN_NS append( & result, Name ); append( result, self->Name );
break; break;
case Class: case Class:
code_cast<CodeClass>().to_string_def( result ); to_string_def(cast(CodeClass, {self}), result );
break; break;
case Class_Fwd: case Class_Fwd:
code_cast<CodeClass>().to_string_fwd( result ); to_string_fwd(cast(CodeClass, {self}), result );
break; break;
case Constructor: case Constructor:
code_cast<CodeConstructor>().to_string_def( result ); cast(CodeConstructor, {self}).to_string_def( * result );
break; break;
case Constructor_Fwd: case Constructor_Fwd:
code_cast<CodeConstructor>().to_string_fwd( result ); cast(CodeConstructor, {self}).to_string_fwd( * result );
break; break;
case Destructor: case Destructor:
code_cast<CodeDestructor>().to_string_def( result ); cast(CodeDestructor, {self}).to_string_def( * result );
break; break;
case Destructor_Fwd: case Destructor_Fwd:
code_cast<CodeDestructor>().to_string_fwd( result ); cast(CodeDestructor, {self}).to_string_fwd( * result );
break; break;
case Enum: case Enum:
code_cast<CodeEnum>().to_string_def( result ); cast(CodeEnum, {self}).to_string_def( * result );
break; break;
case Enum_Fwd: case Enum_Fwd:
code_cast<CodeEnum>().to_string_fwd( result ); cast(CodeEnum, {self}).to_string_fwd( * result );
break; break;
case Enum_Class: case Enum_Class:
code_cast<CodeEnum>().to_string_class_def( result ); cast(CodeEnum, {self}).to_string_class_def( * result );
break; break;
case Enum_Class_Fwd: case Enum_Class_Fwd:
code_cast<CodeEnum>().to_string_class_fwd( result ); cast(CodeEnum, {self}).to_string_class_fwd( * result );
break; break;
case Export_Body: case Export_Body:
code_cast<CodeBody>().to_string_export( result ); to_string_export(cast(CodeBody, {self}), result );
break; break;
case Extern_Linkage: case Extern_Linkage:
code_cast<CodeExtern>().to_string( result ); cast(CodeExtern, {self}).to_string( * result );
break; break;
case Friend: case Friend:
code_cast<CodeFriend>().to_string( result ); cast(CodeFriend, {self}).to_string( * result );
break; break;
case Function: case Function:
code_cast<CodeFn>().to_string_def( result ); cast(CodeFn, {self}).to_string_def( * result );
break; break;
case Function_Fwd: case Function_Fwd:
code_cast<CodeFn>().to_string_fwd( result ); cast(CodeFn, {self}).to_string_fwd( * result );
break; break;
case Module: case Module:
code_cast<CodeModule>().to_string( result ); cast(CodeModule, {self}).to_string( * result );
break; break;
case Namespace: case Namespace:
code_cast<CodeNS>().to_string( result ); cast(CodeNS, {self}).to_string( * result );
break; break;
case Operator: case Operator:
case Operator_Member: case Operator_Member:
code_cast<CodeOperator>().to_string_def( result ); cast(CodeOperator, {self}).to_string_def( * result );
break; break;
case Operator_Fwd: case Operator_Fwd:
case Operator_Member_Fwd: case Operator_Member_Fwd:
code_cast<CodeOperator>().to_string_fwd( result ); cast(CodeOperator, {self}).to_string_fwd( * result );
break; break;
case Operator_Cast: case Operator_Cast:
code_cast<CodeOpCast>().to_string_def( result ); cast(CodeOpCast, {self}).to_string_def( * result );
break; break;
case Operator_Cast_Fwd: case Operator_Cast_Fwd:
code_cast<CodeOpCast>().to_string_fwd( result ); cast(CodeOpCast, {self}).to_string_fwd( * result );
break; break;
case Parameters: case Parameters:
code_cast<CodeParam>().to_string( result ); cast(CodeParam, {self}).to_string( * result );
break; break;
case Preprocess_Define: case Preprocess_Define:
code_cast<CodeDefine>().to_string( result ); cast(CodeDefine, {self}).to_string( * result );
break; break;
case Preprocess_If: case Preprocess_If:
code_cast<CodePreprocessCond>().to_string_if( result ); cast(CodePreprocessCond, {self}).to_string_if( * result );
break; break;
case Preprocess_IfDef: case Preprocess_IfDef:
code_cast<CodePreprocessCond>().to_string_ifdef( result ); cast(CodePreprocessCond, {self}).to_string_ifdef( * result );
break; break;
case Preprocess_IfNotDef: case Preprocess_IfNotDef:
code_cast<CodePreprocessCond>().to_string_ifndef( result ); cast(CodePreprocessCond, {self}).to_string_ifndef( * result );
break; break;
case Preprocess_Include: case Preprocess_Include:
code_cast<CodeInclude>().to_string( result ); cast(CodeInclude, {self}).to_string( * result );
break; break;
case Preprocess_ElIf: case Preprocess_ElIf:
code_cast<CodePreprocessCond>().to_string_elif( result ); cast(CodePreprocessCond, {self}).to_string_elif( * result );
break; break;
case Preprocess_Else: case Preprocess_Else:
code_cast<CodePreprocessCond>().to_string_else( result ); cast(CodePreprocessCond, {self}).to_string_else( * result );
break; break;
case Preprocess_EndIf: case Preprocess_EndIf:
code_cast<CodePreprocessCond>().to_string_endif( result ); cast(CodePreprocessCond, {self}).to_string_endif( * result );
break; break;
case Preprocess_Pragma: case Preprocess_Pragma:
code_cast<CodePragma>().to_string( result ); cast(CodePragma, {self}).to_string( * result );
break; break;
case Specifiers: case Specifiers:
code_cast<CodeSpecifiers>().to_string( result ); cast(CodeSpecifiers, {self}).to_string( * result );
break; break;
case Struct: case Struct:
code_cast<CodeStruct>().to_string_def( result ); cast(CodeStruct, {self}).to_string_def( * result );
break; break;
case Struct_Fwd: case Struct_Fwd:
code_cast<CodeStruct>().to_string_fwd( result ); cast(CodeStruct, {self}).to_string_fwd( * result );
break; break;
case Template: case Template:
code_cast<CodeTemplate>().to_string( result ); cast(CodeTemplate, {self}).to_string( * result );
break; break;
case Typedef: case Typedef:
code_cast<CodeTypedef>().to_string( result ); cast(CodeTypedef, {self}).to_string( * result );
break; break;
case Typename: case Typename:
code_cast<CodeType>().to_string( result ); cast(CodeType, {self}).to_string( * result );
break; break;
case Union: case Union:
code_cast<CodeUnion>().to_string( result ); cast(CodeUnion, {self}).to_string( * result );
break; break;
case Using: case Using:
code_cast<CodeUsing>().to_string( result ); cast(CodeUsing, {self}).to_string( * result );
break; break;
case Using_Namespace: case Using_Namespace:
code_cast<CodeUsing>().to_string_ns( result ); cast(CodeUsing, {self}).to_string_ns( * result );
break; break;
case Variable: case Variable:
code_cast<CodeVar>().to_string( result ); cast(CodeVar, {self}).to_string( * result );
break; break;
case Enum_Body: case Enum_Body:
@ -587,7 +588,7 @@ void AST::to_string( String& result )
case Namespace_Body: case Namespace_Body:
case Struct_Body: case Struct_Body:
case Union_Body: case Union_Body:
code_cast<CodeBody>().to_string( result ); to_string( cast(CodeBody, {self}), result );
break; break;
} }
} }
@ -611,7 +612,7 @@ bool is_equal( AST* self, AST* other )
{ {
log_fmt("AST::is_equal: Type check failure with other\nAST: %S\nOther: %S" log_fmt("AST::is_equal: Type check failure with other\nAST: %S\nOther: %S"
, debug_str(self) , debug_str(self)
, other->debug_str() ,debug_str(other)
); );
return false; return false;
@ -628,7 +629,7 @@ bool is_equal( AST* self, AST* other )
"AST : %S\n" \ "AST : %S\n" \
"Other: %S\n" \ "Other: %S\n" \
, debug_str(self) \ , debug_str(self) \
, other->debug_str() \ ,debug_str(other) \
); \ ); \
\ \
return false; \ return false; \
@ -641,7 +642,7 @@ bool is_equal( AST* self, AST* other )
"AST : %S\n" \ "AST : %S\n" \
"Other: %S\n" \ "Other: %S\n" \
, debug_str(self) \ , debug_str(self) \
, other->debug_str() \ ,debug_str(other) \
); \ ); \
\ \
return false; \ return false; \
@ -654,7 +655,7 @@ bool is_equal( AST* self, AST* other )
"AST : %S\n" \ "AST : %S\n" \
"Other: %S\n" \ "Other: %S\n" \
, debug_str(self) \ , debug_str(self) \
, other->debug_str() \ ,debug_str(other) \
); \ ); \
\ \
log_fmt("Content cannot be trusted to be unique with this check " \ log_fmt("Content cannot be trusted to be unique with this check " \
@ -676,14 +677,14 @@ bool is_equal( AST* self, AST* other )
"Other: %s\n" \ "Other: %s\n" \
"For ast member: %s\n" \ "For ast member: %s\n" \
, debug_str(self) \ , debug_str(self) \
, other->debug_str() \ , debug_str(other) \
, self->ast->debug_str() \ , debug_str(self->ast) \
); \ ); \
\ \
return false; \ return false; \
} \ } \
\ \
if ( ! self->ast->is_equal( other->ast ) ) \ if ( ! is_equal(self->ast, other->ast ) ) \
{ \ { \
log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \ log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \
"AST : %S\n" \ "AST : %S\n" \
@ -691,9 +692,9 @@ bool is_equal( AST* self, AST* other )
"For ast member: %S\n" \ "For ast member: %S\n" \
"other's ast member: %S\n" \ "other's ast member: %S\n" \
, debug_str(self) \ , debug_str(self) \
, other->debug_str() \ , debug_str(other) \
, self->ast->debug_str() \ , debug_str(self->ast) \
, other->ast->debug_str() \ , debug_str(other->ast) \
); \ ); \
\ \
return false; \ return false; \
@ -921,7 +922,7 @@ bool is_equal( AST* self, AST* other )
"AST : %S\n" "AST : %S\n"
"Other: %S\n" "Other: %S\n"
"For ast member: %S\n" "For ast member: %S\n"
, curr->debug_str() , debug_str(curr)
); );
return false; return false;
@ -935,14 +936,14 @@ bool is_equal( AST* self, AST* other )
"For ast member: %S\n" "For ast member: %S\n"
"other's ast member: %S\n" "other's ast member: %S\n"
, debug_str(self) , debug_str(self)
, other->debug_str() , debug_str(other)
, curr->debug_str() , debug_str(curr)
, curr_other->debug_str() , debug_str(curr_other)
); );
return false; return false;
} }
if ( curr->ValueType && ! curr->ValueType->is_equal(curr_other->ValueType) ) if ( curr->ValueType && ! is_equal(curr->ValueType, curr_other->ValueType) )
{ {
log_fmt( "\nAST::is_equal: Failed for parameter value type check\n" log_fmt( "\nAST::is_equal: Failed for parameter value type check\n"
"AST : %S\n" "AST : %S\n"
@ -950,14 +951,14 @@ bool is_equal( AST* self, AST* other )
"For ast member: %S\n" "For ast member: %S\n"
"other's ast member: %S\n" "other's ast member: %S\n"
, debug_str(self) , debug_str(self)
, other->debug_str() , debug_str(other)
, curr->debug_str() , debug_str(curr)
, curr_other->debug_str() , debug_str(curr_other)
); );
return false; return false;
} }
if ( curr->Value && ! curr->Value->is_equal(curr_other->Value) ) if ( curr->Value && ! is_equal(curr->Value, curr_other->Value) )
{ {
log_fmt( "\nAST::is_equal: Failed for parameter value check\n" log_fmt( "\nAST::is_equal: Failed for parameter value check\n"
"AST : %S\n" "AST : %S\n"
@ -965,9 +966,9 @@ bool is_equal( AST* self, AST* other )
"For ast member: %S\n" "For ast member: %S\n"
"other's ast member: %S\n" "other's ast member: %S\n"
, debug_str(self) , debug_str(self)
, other->debug_str() , debug_str(other)
, curr->debug_str() , debug_str(curr)
, curr_other->debug_str() , debug_str(curr_other)
); );
return false; return false;
} }
@ -1113,13 +1114,13 @@ bool is_equal( AST* self, AST* other )
"AST : %S\n" "AST : %S\n"
"Other: %S\n" "Other: %S\n"
"For ast member: %S\n" "For ast member: %S\n"
, curr->debug_str() , debug_str(curr)
); );
return false; return false;
} }
if ( ! curr->is_equal( curr_other ) ) if ( ! is_equal( curr, curr_other ) )
{ {
log_fmt( "\nAST::is_equal: Failed for body\n" log_fmt( "\nAST::is_equal: Failed for body\n"
"AST : %S\n" "AST : %S\n"
@ -1127,9 +1128,9 @@ bool is_equal( AST* self, AST* other )
"For ast member: %S\n" "For ast member: %S\n"
"other's ast member: %S\n" "other's ast member: %S\n"
, debug_str(self) , debug_str(self)
, other->debug_str() , debug_str(other)
, curr->debug_str() , debug_str(curr)
, curr_other->debug_str() , debug_str(curr_other)
); );
return false; return false;
@ -1152,36 +1153,36 @@ bool is_equal( AST* self, AST* other )
return true; return true;
} }
bool AST::validate_body() bool validate_body(AST* self)
{ {
using namespace ECode; using namespace ECode;
#define CheckEntries( Unallowed_Types ) \ #define CheckEntries( Unallowed_Types ) \
do \ do \
{ \ { \
for ( Code entry : code_cast<CodeBody>() ) \ for ( Code entry : cast(CodeBody, {self}) ) \
{ \ { \
switch ( entry->Type ) \ switch ( entry->Type ) \
{ \ { \
Unallowed_Types \ Unallowed_Types \
log_failure( "AST::validate_body: Invalid entry in body %s", entry.debug_str() ); \ log_failure( "AST::validate_body: Invalid entry in body %s", GEN_NS debug_str(entry) ); \
return false; \ return false; \
} \ } \
} \ } \
} \ } \
while (0); while (0);
switch ( Type ) switch ( self->Type )
{ {
case Class_Body: case Class_Body:
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 : code_cast<CodeBody>() ) for ( Code entry : cast(CodeBody, {self}) )
{ {
if ( entry->Type != Untyped ) if ( entry->Type != Untyped )
{ {
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", entry.debug_str() ); log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", GEN_NS debug_str(entry) );
return false; return false;
} }
} }
@ -1196,7 +1197,7 @@ bool AST::validate_body()
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 : code_cast<CodeBody>()) for (Code entry : cast(CodeBody, {self}))
{ {
switch (entry->Type) switch (entry->Type)
{ {
@ -1217,7 +1218,7 @@ bool AST::validate_body()
case Specifiers: case Specifiers:
case Struct_Body: case Struct_Body:
case Typename: case Typename:
log_failure("AST::validate_body: Invalid entry in body %s", entry.debug_str()); log_failure("AST::validate_body: Invalid entry in body %s", GEN_NS debug_str(entry));
return false; return false;
} }
} }
@ -1229,18 +1230,18 @@ bool AST::validate_body()
CheckEntries( GEN_AST_BODY_STRUCT_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_STRUCT_UNALLOWED_TYPES );
break; break;
case Union_Body: case Union_Body:
for ( Code entry : Body->code_cast<CodeBody>() ) for ( Code entry : cast(CodeBody, {self->Body}) )
{ {
if ( entry->Type != Untyped ) if ( entry->Type != Untyped )
{ {
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", entry.debug_str() ); log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", GEN_NS debug_str(entry) );
return false; return false;
} }
} }
break; break;
default: default:
log_failure( "AST::validate_body: Invalid this AST does not have a body %s", debug_str() ); log_failure( "AST::validate_body: Invalid this AST does not have a body %s", debug_str(self) );
return false; return false;
} }

View File

@ -73,82 +73,92 @@ struct AST_Union;
struct AST_Using; struct AST_Using;
struct AST_Var; struct AST_Var;
struct Code; #if GEN_COMPILER_C
struct CodeBody; #define Define_Code(Type) typedef AST_##Type* Code##Type
// These are to offer ease of use and optionally strong type safety for the AST. #else
struct CodeAttributes; #define Define_Code(Type) struct Code##Type
// struct CodeBaseClass;
struct CodeComment;
struct CodeClass;
struct CodeConstructor;
struct CodeDefine;
struct CodeDestructor;
struct CodeEnum;
struct CodeExec;
struct CodeExtern;
struct CodeInclude;
struct CodeFriend;
struct CodeFn;
struct CodeModule;
struct CodeNS;
struct CodeOperator;
struct CodeOpCast;
struct CodeParam;
struct CodePreprocessCond;
struct CodePragma;
struct CodeSpecifiers;
#if GEN_EXECUTION_EXPRESSION_SUPPORT
struct CodeExpr;
struct CodeExpr_Assign;
struct CodeExpr_Alignof;
struct CodeExpr_Binary;
struct CodeExpr_CStyleCast;
struct CodeExpr_FunctionalCast;
struct CodeExpr_CppCast;
struct CodeExpr_Element;
struct CodeExpr_ProcCall;
struct CodeExpr_Decltype;
struct CodeExpr_Comma;
struct CodeExpr_AMS; // Access Member Symbol
struct CodeExpr_Sizeof;
struct CodeExpr_Subscript;
struct CodeExpr_Ternary;
struct CodeExpr_UnaryPrefix;
struct CodeExpr_UnaryPostfix;
struct CodeStmt;
struct CodeStmt_Break;
struct CodeStmt_Case;
struct CodeStmt_Continue;
struct CodeStmt_Decl;
struct CodeStmt_Do;
struct CodeStmt_Expr;
struct CodeStmt_Else;
struct CodeStmt_If;
struct CodeStmt_For;
struct CodeStmt_Goto;
struct CodeStmt_Label;
struct CodeStmt_Switch;
struct CodeStmt_While;
#endif #endif
struct CodeStruct; #if GEN_COMPILER_C
struct CodeTemplate; typedef AST* code;
struct CodeType; #else
struct CodeTypedef; struct Code;
struct CodeUnion; #endif
struct CodeUsing; Define_Code(Body);
struct CodeVar; // These are to offer ease of use and optionally strong type safety for the AST.
Define_Code(Attributes);
// struct CodeBaseClass;
Define_Code(Comment);
Define_Code(Class);
Define_Code(Constructor);
Define_Code(Define);
Define_Code(Destructor);
Define_Code(Enum);
Define_Code(Exec);
Define_Code(Extern);
Define_Code(Include);
Define_Code(Friend);
Define_Code(Fn);
Define_Code(Module);
Define_Code(NS);
Define_Code(Operator);
Define_Code(OpCast);
Define_Code(Param);
Define_Code(PreprocessCond);
Define_Code(Pragma);
Define_Code(Specifiers);
#if GEN_EXECUTION_EXPRESSION_SUPPORT
Define_Code(Expr);
Define_Code(Expr_Assign);
Define_Code(Expr_Alignof);
Define_Code(Expr_Binary);
Define_Code(Expr_CStyleCast);
Define_Code(Expr_FunctionalCast);
Define_Code(Expr_CppCast);
Define_Code(Expr_Element);
Define_Code(Expr_ProcCall);
Define_Code(Expr_Decltype);
Define_Code(Expr_Comma);
Define_Code(Expr_AMS); // Access Member Symbol
Define_Code(Expr_Sizeof);
Define_Code(Expr_Subscript);
Define_Code(Expr_Ternary);
Define_Code(Expr_UnaryPrefix);
Define_Code(Expr_UnaryPostfix);
Define_Code(Stmt);
Define_Code(Stmt_Break);
Define_Code(Stmt_Case);
Define_Code(Stmt_Continue);
Define_Code(Stmt_Decl);
Define_Code(Stmt_Do);
Define_Code(Stmt_Expr);
Define_Code(Stmt_Else);
Define_Code(Stmt_If);
Define_Code(Stmt_For);
Define_Code(Stmt_Goto);
Define_Code(Stmt_Label);
Define_Code(Stmt_Switch);
Define_Code(Stmt_While);
#endif
Define_Code(Struct);
Define_Code(Template);
Define_Code(Type);
Define_Code(Typedef);
Define_Code(Union);
Define_Code(Using);
Define_Code(Var);
#undef Define_Code
namespace parser namespace parser
{ {
struct Token; struct Token;
} }
template< class Type> forceinline Type tmpl_cast( Code* self ) { return * rcast( Type*, self ); } #if ! GEN_COMPILER_C
#if ! GEN_COMPILER_C && 0 template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast( Type*, & self ); }
template< class Type> forceinline Type tmpl_cast( Code& self ) { return * rcast( Type*, & self ); }
#endif #endif
char const* debug_str (Code code); char const* debug_str (Code code);
@ -159,6 +169,7 @@ bool is_valid (Code code);
void set_global(Code code); void set_global(Code code);
String to_string (Code code); String to_string (Code code);
#if ! GEN_COMPILER_C
/* /*
AST* wrapper AST* wrapper
- Not constantly have to append the '*' as this is written often.. - Not constantly have to append the '*' as this is written often..
@ -168,32 +179,29 @@ struct Code
{ {
AST* ast; AST* ast;
# define Using_Code( Typename ) \ # define Using_Code( Typename ) \
char const* debug_str() { return GEN_NS debug_str(* this); } \ char const* debug_str() { return GEN_NS debug_str(* this); } \
Code duplicate() { return GEN_NS duplicate(* this); } \ Code duplicate() { return GEN_NS duplicate(* this); } \
bool is_equal( Code other ) { return GEN_NS is_equal(* this, other); } \ bool is_equal( Code other ) { return GEN_NS is_equal(* this, other); } \
bool is_body() { return GEN_NS is_body(* this); } \ bool is_body() { return GEN_NS is_body(* this); } \
bool is_valid() { return GEN_NS is_valid(* this); } \ bool is_valid() { return GEN_NS is_valid(* this); } \
void set_global() { return GEN_NS set_global(* this); } \ void set_global() { return GEN_NS set_global(* this); }
String to_string(); \
Typename& operator = ( AST* other ); \ # define Using_CodeOps( Typename ) \
Typename& operator = ( Code other ); \ Typename& operator = ( AST* other ); \
Typename& operator = ( Code other ); \
bool operator ==( Code other ) { return (AST*)ast == other.ast; } \ bool operator ==( Code other ) { return (AST*)ast == other.ast; } \
bool operator !=( Code other ) { return (AST*)ast != other.ast; } \ bool operator !=( Code other ) { return (AST*)ast != other.ast; } \
operator bool(); operator bool();
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( Code ); Using_Code( Code );
String to_string() { return GEN_NS to_string(* this); }
#endif
template< class Type > Using_CodeOps( Code );
forceinline Type code_cast()
{
return * rcast( Type*, this );
}
AST* operator ->() AST* operator ->() { return ast; }
{
return ast;
}
Code& operator ++(); Code& operator ++();
// TODO(Ed) : Remove this overload. // TODO(Ed) : Remove this overload.
@ -242,6 +250,7 @@ struct Code
operator CodeVar() const; operator CodeVar() const;
#undef operator #undef operator
}; };
#endif
#pragma region Statics #pragma region Statics
// Used to identify ASTs that should always be duplicated. (Global constant ASTs) // Used to identify ASTs that should always be duplicated. (Global constant ASTs)
@ -261,15 +270,17 @@ static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
// Desired width of the AST data structure. // Desired width of the AST data structure.
constexpr int const AST_POD_Size = 128; constexpr int const AST_POD_Size = 128;
void append ( AST* self, AST* other ); void append ( AST* self, AST* other );
char const* debug_str ( AST* self ); char const* debug_str ( AST* self );
AST* duplicate ( AST* self ); AST* duplicate ( AST* self );
Code* entry ( AST* self, u32 idx ); Code* entry ( AST* self, u32 idx );
bool has_entries( AST* self ); bool has_entries ( AST* self );
bool is_body ( AST* self ); bool is_body ( AST* self );
bool is_equal ( AST* self, AST* other ); bool is_equal ( AST* self, AST* other );
String to_string ( AST* self ); String to_string ( AST* self );
char const* type_str ( AST* self ); void to_string ( AST* self, String* result );
char const* type_str ( AST* self );
bool validate_body( AST* self );
#if GEN_CPP_SUPPORT_REFERENCES #if GEN_CPP_SUPPORT_REFERENCES
void append ( AST& self, AST& other ) { return append(& self, & other); } void append ( AST& self, AST& other ) { return append(& self, & other); }
@ -280,6 +291,20 @@ String to_string( AST& self ) { return to_string( & self ); }
char const* type_str ( AST& self ) { return type_str( & self ); } char const* type_str ( AST& self ) { return type_str( & self ); }
#endif #endif
constexpr static
int AST_ArrSpecs_Cap =
(
AST_POD_Size
- sizeof(AST*) * 3
- sizeof(parser::Token*)
- sizeof(AST*)
- sizeof(StringCached)
- sizeof(CodeT)
- sizeof(ModuleFlag)
- sizeof(int)
)
/ sizeof(int) - 1; // -1 for 4 extra bytes
/* /*
Simple AST POD with functionality to seralize into C++ syntax. Simple AST POD with functionality to seralize into C++ syntax.
*/ */
@ -287,26 +312,19 @@ struct AST
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES
# pragma region Member Functions # pragma region Member Functions
void append ( AST* other ) { GEN_NS append(this, other); } void append ( AST* other ) { GEN_NS append(this, other); }
char const* debug_str () { return GEN_NS debug_str(this); } char const* debug_str () { return GEN_NS debug_str(this); }
AST* duplicate () { return GEN_NS duplicate(this); } AST* duplicate () { return GEN_NS duplicate(this); }
Code* entry ( u32 idx ) { return GEN_NS entry(this, idx); } Code* entry ( u32 idx ) { return GEN_NS entry(this, idx); }
bool has_entries(); bool has_entries() { return GEN_NS has_entries(this); }
bool is_equal ( AST* other ) { return GEN_NS is_equal(this, other); } bool is_equal ( AST* other ) { return GEN_NS is_equal(this, other); }
bool is_body() { return GEN_NS is_body(this); } bool is_body() { return GEN_NS is_body(this); }
char const* type_str() { return GEN_NS type_str(this); } char const* type_str() { return GEN_NS type_str(this); }
bool validate_body(); bool validate_body() { return GEN_NS validate_body(this); }
String to_string(); //{ return GEN_NS to_string(this); } String to_string() { return GEN_NS to_string(this); }
void to_string( String& result ) { return GEN_NS to_string(this, & result); }
template< class Type >
forceinline Type code_cast()
{
return * this;
}
neverinline
void to_string( String& result );
# pragma endregion Member Functions # pragma endregion Member Functions
#endif #endif
@ -341,20 +359,6 @@ struct AST
operator CodeUsing(); operator CodeUsing();
operator CodeVar(); operator CodeVar();
constexpr static
int ArrSpecs_Cap =
(
AST_POD_Size
- sizeof(AST*) * 3
- sizeof(parser::Token*)
- sizeof(AST*)
- sizeof(StringCached)
- sizeof(CodeT)
- sizeof(ModuleFlag)
- sizeof(int)
)
/ sizeof(int) - 1; // -1 for 4 extra bytes
union { union {
struct struct
{ {
@ -387,7 +391,7 @@ struct AST
}; };
StringCached Content; // Attributes, Comment, Execution, Include StringCached Content; // Attributes, Comment, Execution, Include
struct { struct {
SpecifierT ArrSpecs[ArrSpecs_Cap]; // Specifiers SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used. AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
}; };
}; };
@ -451,7 +455,7 @@ struct AST_POD
}; };
StringCached Content; // Attributes, Comment, Execution, Include StringCached Content; // Attributes, Comment, Execution, Include
struct { struct {
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used. AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
}; };
}; };
@ -480,10 +484,6 @@ struct AST_POD
}; };
}; };
// TODO(Ed): Convert
String to_string ( AST* self ) { return self->to_string(); }
// Its intended for the AST to have equivalent size to its POD. // Its intended for the AST to have equivalent size to its POD.
// All extra functionality within the AST namespace should just be syntatic sugar. // All extra functionality within the AST namespace should just be syntatic sugar.
static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" ); static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" );

View File

@ -12,7 +12,7 @@
struct AST_Body struct AST_Body
{ {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
Code Front; Code Front;
Code Back; Code Back;
parser::Token* Tok; parser::Token* Tok;
@ -27,7 +27,7 @@ static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Body is not the same
struct AST_Attributes struct AST_Attributes
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StringCached Content; StringCached Content;
}; };
Code Prev; Code Prev;
@ -44,7 +44,7 @@ static_assert( sizeof(AST_Attributes) == sizeof(AST), "ERROR: AST_Attributes is
struct AST_BaseClass struct AST_BaseClass
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
Code Prev; Code Prev;
Code Next; Code Next;
@ -60,7 +60,7 @@ static_assert( sizeof(AST_BaseClass) == sizeof(AST), "ERROR: AST_BaseClass is no
struct AST_Comment struct AST_Comment
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StringCached Content; StringCached Content;
}; };
Code Prev; Code Prev;
@ -76,7 +76,7 @@ static_assert( sizeof(AST_Comment) == sizeof(AST), "ERROR: AST_Comment is not th
struct AST_Class struct AST_Class
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; // Only supported by forward declarations CodeComment InlineCmt; // Only supported by forward declarations
@ -102,7 +102,7 @@ static_assert( sizeof(AST_Class) == sizeof(AST), "ERROR: AST_Class is not the sa
struct AST_Constructor struct AST_Constructor
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; // Only supported by forward declarations CodeComment InlineCmt; // Only supported by forward declarations
@ -127,7 +127,7 @@ static_assert( sizeof(AST_Constructor) == sizeof(AST), "ERROR: AST_Constructor i
struct AST_Define struct AST_Define
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StringCached Content; StringCached Content;
}; };
Code Prev; Code Prev;
@ -143,7 +143,7 @@ static_assert( sizeof(AST_Define) == sizeof(AST), "ERROR: AST_Define is not the
struct AST_Destructor struct AST_Destructor
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -167,7 +167,7 @@ static_assert( sizeof(AST_Destructor) == sizeof(AST), "ERROR: AST_Destructor is
struct AST_Enum struct AST_Enum
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -193,7 +193,7 @@ static_assert( sizeof(AST_Enum) == sizeof(AST), "ERROR: AST_Enum is not the same
struct AST_Exec struct AST_Exec
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StringCached Content; StringCached Content;
}; };
Code Prev; Code Prev;
@ -210,7 +210,7 @@ static_assert( sizeof(AST_Exec) == sizeof(AST), "ERROR: AST_Exec is not the same
struct AST_Expr struct AST_Expr
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -225,7 +225,7 @@ static_assert( sizeof(AST_Expr) == sizeof(AST), "ERROR: AST_Expr is not the same
struct AST_Expr_Assign struct AST_Expr_Assign
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -240,7 +240,7 @@ static_assert( sizeof(AST_Expr_Assign) == sizeof(AST), "ERROR: AST_Expr_Assign i
struct AST_Expr_Alignof struct AST_Expr_Alignof
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -255,7 +255,7 @@ static_assert( sizeof(AST_Expr_Alignof) == sizeof(AST), "ERROR: AST_Expr_Alignof
struct AST_Expr_Binary struct AST_Expr_Binary
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -270,7 +270,7 @@ static_assert( sizeof(AST_Expr_Binary) == sizeof(AST), "ERROR: AST_Expr_Binary i
struct AST_Expr_CStyleCast struct AST_Expr_CStyleCast
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -285,7 +285,7 @@ static_assert( sizeof(AST_Expr_CStyleCast) == sizeof(AST), "ERROR: AST_Expr_CSty
struct AST_Expr_FunctionalCast struct AST_Expr_FunctionalCast
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -300,7 +300,7 @@ static_assert( sizeof(AST_Expr_FunctionalCast) == sizeof(AST), "ERROR: AST_Expr_
struct AST_Expr_CppCast struct AST_Expr_CppCast
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -315,7 +315,7 @@ static_assert( sizeof(AST_Expr_CppCast) == sizeof(AST), "ERROR: AST_Expr_CppCast
struct AST_Expr_ProcCall struct AST_Expr_ProcCall
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -330,7 +330,7 @@ static_assert( sizeof(AST_Expr_ProcCall) == sizeof(AST), "ERROR: AST_Expr_Identi
struct AST_Expr_Decltype struct AST_Expr_Decltype
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -345,7 +345,7 @@ static_assert( sizeof(AST_Expr_Decltype) == sizeof(AST), "ERROR: AST_Expr_Declty
struct AST_Expr_Comma struct AST_Expr_Comma
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -360,7 +360,7 @@ static_assert( sizeof(AST_Expr_Comma) == sizeof(AST), "ERROR: AST_Expr_Comma is
struct AST_Expr_AMS struct AST_Expr_AMS
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -375,7 +375,7 @@ static_assert( sizeof(AST_Expr_AMS) == sizeof(AST), "ERROR: AST_Expr_AMS is not
struct AST_Expr_Sizeof struct AST_Expr_Sizeof
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -390,7 +390,7 @@ static_assert( sizeof(AST_Expr_Sizeof) == sizeof(AST), "ERROR: AST_Expr_Sizeof i
struct AST_Expr_Subscript struct AST_Expr_Subscript
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -405,7 +405,7 @@ static_assert( sizeof(AST_Expr_Subscript) == sizeof(AST), "ERROR: AST_Expr_Subsc
struct AST_Expr_Ternary struct AST_Expr_Ternary
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -420,7 +420,7 @@ static_assert( sizeof(AST_Expr_Ternary) == sizeof(AST), "ERROR: AST_Expr_Ternary
struct AST_Expr_UnaryPrefix struct AST_Expr_UnaryPrefix
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -435,7 +435,7 @@ static_assert( sizeof(AST_Expr_UnaryPrefix) == sizeof(AST), "ERROR: AST_Expr_Una
struct AST_Expr_UnaryPostfix struct AST_Expr_UnaryPostfix
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -450,7 +450,7 @@ static_assert( sizeof(AST_Expr_UnaryPostfix) == sizeof(AST), "ERROR: AST_Expr_Un
struct AST_Expr_Element struct AST_Expr_Element
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -466,7 +466,7 @@ static_assert( sizeof(AST_Expr_Element) == sizeof(AST), "ERROR: AST_Expr_Element
struct AST_Extern struct AST_Extern
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ]; char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
@ -487,7 +487,7 @@ static_assert( sizeof(AST_Extern) == sizeof(AST), "ERROR: AST_Extern is not the
struct AST_Include struct AST_Include
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StringCached Content; StringCached Content;
}; };
Code Prev; Code Prev;
@ -503,7 +503,7 @@ static_assert( sizeof(AST_Include) == sizeof(AST), "ERROR: AST_Include is not th
struct AST_Friend struct AST_Friend
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -525,7 +525,7 @@ static_assert( sizeof(AST_Friend) == sizeof(AST), "ERROR: AST_Friend is not the
struct AST_Fn struct AST_Fn
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -550,7 +550,7 @@ static_assert( sizeof(AST_Fn) == sizeof(AST), "ERROR: AST_Fn is not the same siz
struct AST_Module struct AST_Module
{ {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
Code Prev; Code Prev;
Code Next; Code Next;
parser::Token* Tok; parser::Token* Tok;
@ -565,7 +565,7 @@ static_assert( sizeof(AST_Module) == sizeof(AST), "ERROR: AST_Module is not the
struct AST_NS struct AST_NS
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct { struct {
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ]; char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
CodeBody Body; CodeBody Body;
@ -586,7 +586,7 @@ static_assert( sizeof(AST_NS) == sizeof(AST), "ERROR: AST_NS is not the same siz
struct AST_Operator struct AST_Operator
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -612,7 +612,7 @@ static_assert( sizeof(AST_Operator) == sizeof(AST), "ERROR: AST_Operator is not
struct AST_OpCast struct AST_OpCast
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -637,7 +637,7 @@ static_assert( sizeof(AST_OpCast) == sizeof(AST), "ERROR: AST_OpCast is not the
struct AST_Param struct AST_Param
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ]; char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
@ -662,7 +662,7 @@ static_assert( sizeof(AST_Param) == sizeof(AST), "ERROR: AST_Param is not the sa
struct AST_Pragma struct AST_Pragma
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StringCached Content; StringCached Content;
}; };
Code Prev; Code Prev;
@ -678,7 +678,7 @@ static_assert( sizeof(AST_Pragma) == sizeof(AST), "ERROR: AST_Pragma is not the
struct AST_PreprocessCond struct AST_PreprocessCond
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
StringCached Content; StringCached Content;
}; };
Code Prev; Code Prev;
@ -693,7 +693,7 @@ static_assert( sizeof(AST_PreprocessCond) == sizeof(AST), "ERROR: AST_Preprocess
struct AST_Specifiers struct AST_Specifiers
{ {
SpecifierT ArrSpecs[ AST::ArrSpecs_Cap ]; SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
CodeSpecifiers NextSpecs; CodeSpecifiers NextSpecs;
Code Prev; Code Prev;
Code Next; Code Next;
@ -710,7 +710,7 @@ static_assert( sizeof(AST_Specifiers) == sizeof(AST), "ERROR: AST_Specifier is n
struct AST_Stmt struct AST_Stmt
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -725,7 +725,7 @@ static_assert( sizeof(AST_Stmt) == sizeof(AST), "ERROR: AST_Stmt is not the same
struct AST_Stmt_Break struct AST_Stmt_Break
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -740,7 +740,7 @@ static_assert( sizeof(AST_Stmt_Break) == sizeof(AST), "ERROR: AST_Stmt_Break is
struct AST_Stmt_Case struct AST_Stmt_Case
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -755,7 +755,7 @@ static_assert( sizeof(AST_Stmt_Case) == sizeof(AST), "ERROR: AST_Stmt_Case is no
struct AST_Stmt_Continue struct AST_Stmt_Continue
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -770,7 +770,7 @@ static_assert( sizeof(AST_Stmt_Continue) == sizeof(AST), "ERROR: AST_Stmt_Contin
struct AST_Stmt_Decl struct AST_Stmt_Decl
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -785,7 +785,7 @@ static_assert( sizeof(AST_Stmt_Decl) == sizeof(AST), "ERROR: AST_Stmt_Decl is no
struct AST_Stmt_Do struct AST_Stmt_Do
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -800,7 +800,7 @@ static_assert( sizeof(AST_Stmt_Do) == sizeof(AST), "ERROR: AST_Stmt_Do is not th
struct AST_Stmt_Expr struct AST_Stmt_Expr
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -815,7 +815,7 @@ static_assert( sizeof(AST_Stmt_Expr) == sizeof(AST), "ERROR: AST_Stmt_Expr is no
struct AST_Stmt_Else struct AST_Stmt_Else
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -830,7 +830,7 @@ static_assert( sizeof(AST_Stmt_Else) == sizeof(AST), "ERROR: AST_Stmt_Else is no
struct AST_Stmt_If struct AST_Stmt_If
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -845,7 +845,7 @@ static_assert( sizeof(AST_Stmt_If) == sizeof(AST), "ERROR: AST_Stmt_If is not th
struct AST_Stmt_For struct AST_Stmt_For
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -860,7 +860,7 @@ static_assert( sizeof(AST_Stmt_For) == sizeof(AST), "ERROR: AST_Stmt_For is not
struct AST_Stmt_Goto struct AST_Stmt_Goto
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -875,7 +875,7 @@ static_assert( sizeof(AST_Stmt_Goto) == sizeof(AST), "ERROR: AST_Stmt_Goto is no
struct AST_Stmt_Label struct AST_Stmt_Label
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -890,7 +890,7 @@ static_assert( sizeof(AST_Stmt_Label) == sizeof(AST), "ERROR: AST_Stmt_Label is
struct AST_Stmt_Switch struct AST_Stmt_Switch
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -905,7 +905,7 @@ static_assert( sizeof(AST_Stmt_Switch) == sizeof(AST), "ERROR: AST_Stmt_Switch i
struct AST_Stmt_While struct AST_Stmt_While
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
}; };
CodeExpr Prev; CodeExpr Prev;
CodeExpr Next; CodeExpr Next;
@ -921,7 +921,7 @@ static_assert( sizeof(AST_Stmt_While) == sizeof(AST), "ERROR: AST_Stmt_While is
struct AST_Struct struct AST_Struct
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -947,7 +947,7 @@ static_assert( sizeof(AST_Struct) == sizeof(AST), "ERROR: AST_Struct is not the
struct AST_Template struct AST_Template
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ]; char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
@ -972,7 +972,7 @@ static_assert( sizeof(AST_Template) == sizeof(AST), "ERROR: AST_Template is not
struct AST_Type struct AST_Type
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
char _PAD_INLINE_CMT_[ sizeof(AST*) ]; char _PAD_INLINE_CMT_[ sizeof(AST*) ];
@ -1000,7 +1000,7 @@ static_assert( sizeof(AST_Type) == sizeof(AST), "ERROR: AST_Type is not the same
struct AST_Type struct AST_Type
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
char _PAD_INLINE_CMT_[ sizeof(AST*) ]; char _PAD_INLINE_CMT_[ sizeof(AST*) ];
@ -1026,7 +1026,7 @@ static_assert( sizeof(AST_Type) == sizeof(AST), "ERROR: AST_Type is not the same
struct AST_Typedef struct AST_Typedef
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -1049,7 +1049,7 @@ static_assert( sizeof(AST_Typedef) == sizeof(AST), "ERROR: AST_Typedef is not th
struct AST_Union struct AST_Union
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
char _PAD_INLINE_CMT_[ sizeof(AST*) ]; char _PAD_INLINE_CMT_[ sizeof(AST*) ];
@ -1073,7 +1073,7 @@ static_assert( sizeof(AST_Union) == sizeof(AST), "ERROR: AST_Union is not the sa
struct AST_Using struct AST_Using
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;
@ -1097,7 +1097,7 @@ static_assert( sizeof(AST_Using) == sizeof(AST), "ERROR: AST_Using is not the sa
struct AST_Var struct AST_Var
{ {
union { union {
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ]; char _PAD_[ sizeof(SpecifierT) * AST_ArrSpecs_Cap + sizeof(AST*) ];
struct struct
{ {
CodeComment InlineCmt; CodeComment InlineCmt;

View File

@ -3,14 +3,14 @@
#include "ast.cpp" #include "ast.cpp"
#endif #endif
String Code::to_string() String to_string(Code self)
{ {
if ( ast == nullptr ) if ( self.ast == nullptr )
{ {
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" ); log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr }; return { nullptr };
} }
return rcast( AST*, ast )->to_string(); return to_string( self.ast );
} }
String CodeAttributes::to_string() String CodeAttributes::to_string()
@ -18,15 +18,16 @@ String CodeAttributes::to_string()
return GEN_NS duplicate( ast->Content, GlobalAllocator ); return GEN_NS duplicate( ast->Content, GlobalAllocator );
} }
String CodeBody::to_string() String to_string(CodeBody body)
{ {
GEN_ASSERT(body.ast != nullptr);
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( ast->Type ) switch ( body.ast->Type )
{ {
using namespace ECode; using namespace ECode;
case Untyped: case Untyped:
case Execution: case Execution:
GEN_NS append( & result, raw()->Content ); append( & result, rcast(AST*, body.ast)->Content );
break; break;
case Enum_Body: case Enum_Body:
@ -37,40 +38,44 @@ String CodeBody::to_string()
case Namespace_Body: case Namespace_Body:
case Struct_Body: case Struct_Body:
case Union_Body: case Union_Body:
to_string( result ); to_string( body, & result );
break; break;
case Export_Body: case Export_Body:
to_string_export( result ); to_string_export( body, & result );
break; break;
} }
return result; return result;
} }
void CodeBody::to_string( String& result ) void to_string( CodeBody body, String* result )
{ {
Code curr = ast->Front; GEN_ASSERT(body.ast != nullptr);
s32 left = ast->NumEntries; GEN_ASSERT(result != nullptr);
Code curr = body.ast->Front;
s32 left = body.ast->NumEntries;
while ( left -- ) while ( left -- )
{ {
append_fmt( & result, "%S", curr.to_string() ); append_fmt( result, "%S", GEN_NS to_string(curr) );
++curr; ++curr;
} }
} }
void CodeBody::to_string_export( String& result ) void to_string_export( CodeBody body, String* result )
{ {
append_fmt( & result, "export\n{\n" ); GEN_ASSERT(body.ast != nullptr);
GEN_ASSERT(result != nullptr);
append_fmt( result, "export\n{\n" );
Code curr = *this; Code curr = body;
s32 left = ast->NumEntries; s32 left = body.ast->NumEntries;
while ( left-- ) while ( left-- )
{ {
append_fmt( & result, "%S", curr.to_string() ); append_fmt( result, "%S", to_string(curr) );
++curr; ++curr;
} }
append_fmt( & result, "};\n" ); append_fmt( result, "};\n" );
} }
String CodeComment::to_string() String CodeComment::to_string()
@ -110,12 +115,12 @@ void CodeConstructor::to_string_def( String& result )
append( & result, "()" ); append( & result, "()" );
if ( ast->InitializerList ) if ( ast->InitializerList )
append_fmt( & result, " : %S", ast->InitializerList.to_string() ); append_fmt( & result, " : %S", GEN_NS to_string(ast->InitializerList) );
if ( ast->InlineCmt ) if ( ast->InlineCmt )
append_fmt( & result, " // %S", ast->InlineCmt->Content ); append_fmt( & result, " // %S", ast->InlineCmt->Content );
append_fmt( & result, "\n{\n%S\n}\n", ast->Body.to_string() ); append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) );
} }
void CodeConstructor::to_string_fwd( String& result ) void CodeConstructor::to_string_fwd( String& result )
@ -134,7 +139,7 @@ void CodeConstructor::to_string_fwd( String& result )
append_fmt( & result, "()"); append_fmt( & result, "()");
if (ast->Body) if (ast->Body)
append_fmt( & result, " = %S", ast->Body.to_string() ); append_fmt( & result, " = %S", GEN_NS to_string(ast->Body) );
if ( ast->InlineCmt ) if ( ast->InlineCmt )
append_fmt( & result, "; // %S\n", ast->InlineCmt->Content ); append_fmt( & result, "; // %S\n", ast->InlineCmt->Content );
@ -142,83 +147,89 @@ void CodeConstructor::to_string_fwd( String& result )
append( & result, ";\n" ); append( & result, ";\n" );
} }
String CodeClass::to_string() String to_string( CodeClass self )
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( ast->Type ) switch ( self->Type )
{ {
using namespace ECode; using namespace ECode;
case Class: case Class:
to_string_def( result ); to_string_def(self, & result );
break; break;
case Class_Fwd: case Class_Fwd:
to_string_fwd( result ); to_string_fwd(self, & result );
break; break;
} }
return result; return result;
} }
void CodeClass::to_string_def( String& result ) void to_string_def( CodeClass self, String* result )
{ {
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) GEN_ASSERT(self.ast != nullptr);
append( & result, "export " ); AST_Class* ast = self.ast;
append( & result, "class " ); if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( result, "export " );
append( result, "class " );
if ( ast->Attributes ) if ( ast->Attributes )
{ {
append_fmt( & result, "%S ", ast->Attributes.to_string() ); append_fmt( result, "%S ", ast->Attributes.to_string() );
} }
if ( ast->ParentType ) if ( ast->ParentType )
{ {
char const* access_level = to_str( ast->ParentAccess ); char const* access_level = to_str( ast->ParentAccess );
append_fmt( & result, "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() ); append_fmt( result, "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() );
CodeType interface = ast->ParentType->Next->code_cast< CodeType >(); CodeType interface = cast(CodeType, ast->ParentType->Next);
if ( interface ) if ( interface )
append( & result, "\n" ); append( result, "\n" );
while ( interface ) while ( interface )
{ {
append_fmt( & result, ", %S", interface.to_string() ); append_fmt( result, ", %S", interface.to_string() );
interface = interface->Next ? interface->Next->code_cast< CodeType >() : CodeType { nullptr }; interface = interface->Next ? cast(CodeType, interface->Next) : CodeType { nullptr };
} }
} }
else if ( ast->Name ) else if ( ast->Name )
{ {
append( & result, ast->Name ); append( result, ast->Name );
} }
if ( ast->InlineCmt ) if ( ast->InlineCmt )
{ {
append_fmt( & result, " // %S", ast->InlineCmt->Content ); append_fmt( result, " // %S", ast->InlineCmt->Content );
} }
append_fmt( & result, "\n{\n%S\n}", ast->Body.to_string() ); append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
append( & result, ";\n"); append( result, ";\n");
} }
void CodeClass::to_string_fwd( String& result ) void to_string_fwd( CodeClass self, String* result )
{ {
GEN_ASSERT(self.ast != nullptr);
AST_Class* ast = self.ast;
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " ); append( result, "export " );
if ( ast->Attributes ) if ( ast->Attributes )
append_fmt( & result, "class %S %S", ast->Attributes.to_string(), ast->Name ); append_fmt( result, "class %S %S", ast->Attributes.to_string(), ast->Name );
else append_fmt( & result, "class %S", ast->Name ); else append_fmt( result, "class %S", ast->Name );
// Check if it can have an end-statement // Check if it can have an end-statement
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
{ {
if ( ast->InlineCmt ) if ( ast->InlineCmt )
append_fmt( & result, "; // %S\n", ast->InlineCmt->Content ); append_fmt( result, "; // %S\n", ast->InlineCmt->Content );
else else
append( & result,";\n"); append( result,";\n");
} }
} }
@ -264,7 +275,7 @@ void CodeDestructor::to_string_def( String& result )
else else
append_fmt( & result, "~%S()", ast->Parent->Name ); append_fmt( & result, "~%S()", ast->Parent->Name );
append_fmt( & result, "\n{\n%S\n}\n", ast->Body.to_string() ); append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) );
} }
void CodeDestructor::to_string_fwd( String& result ) void CodeDestructor::to_string_fwd( String& result )
@ -279,7 +290,7 @@ void CodeDestructor::to_string_fwd( String& result )
if ( ast->Specs.has( ESpecifier::Pure ) ) if ( ast->Specs.has( ESpecifier::Pure ) )
append( & result, " = 0;" ); append( & result, " = 0;" );
else if (ast->Body) else if (ast->Body)
append_fmt( & result, " = %S;", ast->Body.to_string() ); append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) );
} }
else else
append_fmt( & result, "~%S();", ast->Parent->Name ); append_fmt( & result, "~%S();", ast->Parent->Name );
@ -328,18 +339,18 @@ void CodeEnum::to_string_def( String& result )
append_fmt( & result, "%S : %S\n{\n%S\n}" append_fmt( & result, "%S : %S\n{\n%S\n}"
, ast->Name , ast->Name
, ast->UnderlyingType.to_string() , ast->UnderlyingType.to_string()
, ast->Body.to_string() , GEN_NS to_string(ast->Body)
); );
else if ( ast->UnderlyingTypeMacro ) else if ( ast->UnderlyingTypeMacro )
append_fmt( & result, "%S : %S\n{\n%S\n}" append_fmt( & result, "%S : %S\n{\n%S\n}"
, ast->Name , ast->Name
, ast->UnderlyingTypeMacro.to_string() , GEN_NS to_string(ast->UnderlyingTypeMacro)
, ast->Body.to_string() , GEN_NS to_string(ast->Body)
); );
else append_fmt( & result, "%S\n{\n%S\n}", ast->Name, ast->Body.to_string() ); else append_fmt( & result, "%S\n{\n%S\n}", ast->Name, GEN_NS to_string(ast->Body) );
} }
else append_fmt( & result, "enum %S\n{\n%S\n}", ast->Name, ast->Body.to_string() ); else append_fmt( & result, "enum %S\n{\n%S\n}", ast->Name, GEN_NS to_string(ast->Body) );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
append( & result, ";\n"); append( & result, ";\n");
@ -383,16 +394,16 @@ void CodeEnum::to_string_class_def( String& result )
if ( ast->UnderlyingType ) if ( ast->UnderlyingType )
{ {
append_fmt( & result, "%S : %S\n{\n%S\n}", ast->Name, ast->UnderlyingType.to_string(), ast->Body.to_string() ); append_fmt( & result, "%S : %S\n{\n%S\n}", ast->Name, ast->UnderlyingType.to_string(), GEN_NS to_string(ast->Body) );
} }
else else
{ {
append_fmt( & result, "%S\n{\n%S\n}", ast->Name, ast->Body.to_string() ); append_fmt( & result, "%S\n{\n%S\n}", ast->Name, GEN_NS to_string(ast->Body) );
} }
} }
else else
{ {
append_fmt( & result, "enum class %S\n{\n%S\n}", ast->Body.to_string() ); append_fmt( & result, "enum class %S\n{\n%S\n}", GEN_NS to_string(ast->Body) );
} }
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
@ -428,7 +439,7 @@ String CodeExec::to_string()
void CodeExtern::to_string( String& result ) void CodeExtern::to_string( String& result )
{ {
if ( ast->Body ) if ( ast->Body )
append_fmt( & result, "extern \"%S\"\n{\n%S\n}\n", ast->Name, ast->Body.to_string() ); append_fmt( & result, "extern \"%S\"\n{\n%S\n}\n", ast->Name, GEN_NS to_string(ast->Body) );
else else
append_fmt( & result, "extern \"%S\"\n{}\n", ast->Name ); append_fmt( & result, "extern \"%S\"\n{}\n", ast->Name );
} }
@ -452,7 +463,7 @@ String CodeFriend::to_string()
void CodeFriend::to_string( String& result ) void CodeFriend::to_string( String& result )
{ {
append_fmt( & result, "friend %S", ast->Declaration->to_string() ); append_fmt( & result, "friend %S", GEN_NS to_string(ast->Declaration) );
if ( ast->Declaration->Type != ECode::Function && result[ length(result) - 1 ] != ';' ) if ( ast->Declaration->Type != ECode::Function && result[ length(result) - 1 ] != ';' )
{ {
@ -531,7 +542,7 @@ void CodeFn::to_string_def( String& result )
} }
} }
append_fmt( & result, "\n{\n%S\n}\n", ast->Body.to_string() ); append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) );
} }
void CodeFn::to_string_fwd( String& result ) void CodeFn::to_string_fwd( String& result )
@ -589,7 +600,7 @@ void CodeFn::to_string_fwd( String& result )
if ( ast->Specs && ast->Specs.has( ESpecifier::Pure ) >= 0 ) if ( ast->Specs && ast->Specs.has( ESpecifier::Pure ) >= 0 )
append( & result, " = 0;" ); append( & result, " = 0;" );
else if (ast->Body) else if (ast->Body)
append_fmt( & result, " = %S;", ast->Body.to_string() ); append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) );
if ( ast->InlineCmt ) if ( ast->InlineCmt )
append_fmt( & result, "; %S", ast->InlineCmt->Content ); append_fmt( & result, "; %S", ast->InlineCmt->Content );
@ -627,7 +638,7 @@ void CodeNS::to_string( String& result )
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " ); append( & result, "export " );
append_fmt( & result, "namespace %S\n{\n%S\n}\n", ast->Name , ast->Body.to_string() ); append_fmt( & result, "namespace %S\n{\n%S\n}\n", ast->Name , GEN_NS to_string(ast->Body) );
} }
String CodeOperator::to_string() String CodeOperator::to_string()
@ -698,7 +709,7 @@ void CodeOperator::to_string_def( String& result )
} }
append_fmt( & result, "\n{\n%S\n}\n" append_fmt( & result, "\n{\n%S\n}\n"
, ast->Body.to_string() , GEN_NS to_string(ast->Body)
); );
} }
@ -796,14 +807,14 @@ void CodeOpCast::to_string_def( String& result )
} }
} }
append_fmt( & result, "\n{\n%S\n}\n", ast->Body.to_string() ); append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) );
return; return;
} }
if ( ast->Name && length(ast->Name) ) if ( ast->Name && length(ast->Name) )
append_fmt( & result, "%Soperator %S()\n{\n%S\n}\n", ast->Name, ast->ValueType.to_string(), ast->Body.to_string() ); append_fmt( & result, "%Soperator %S()\n{\n%S\n}\n", ast->Name, ast->ValueType.to_string(), GEN_NS to_string(ast->Body) );
else else
append_fmt( & result, "operator %S()\n{\n%S\n}\n", ast->ValueType.to_string(), ast->Body.to_string() ); append_fmt( & result, "operator %S()\n{\n%S\n}\n", ast->ValueType.to_string(), GEN_NS to_string(ast->Body) );
} }
void CodeOpCast::to_string_fwd( String& result ) void CodeOpCast::to_string_fwd( String& result )
@ -872,11 +883,11 @@ void CodeParam::to_string( String& result )
if ( ast->PostNameMacro ) if ( ast->PostNameMacro )
{ {
append_fmt( & result, " %S", ast->PostNameMacro.to_string() ); append_fmt( & result, " %S", GEN_NS to_string(ast->PostNameMacro) );
} }
if ( ast->Value ) if ( ast->Value )
append_fmt( & result, " = %S", ast->Value.to_string() ); append_fmt( & result, " = %S", GEN_NS to_string(ast->Value) );
if ( ast->NumEntries - 1 > 0 ) if ( ast->NumEntries - 1 > 0 )
{ {
@ -1010,14 +1021,14 @@ void CodeStruct::to_string_def( String& result )
append_fmt( & result, "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() ); append_fmt( & result, "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() );
CodeType interface = ast->ParentType->Next->code_cast< CodeType >(); CodeType interface = cast(CodeType, ast->ParentType->Next);
if ( interface ) if ( interface )
append( & result, "\n" ); append( & result, "\n" );
while ( interface ) while ( interface )
{ {
append_fmt( & result, ", %S", interface.to_string() ); append_fmt( & result, ", %S", interface.to_string() );
interface = interface->Next ? interface->Next->code_cast< CodeType >() : CodeType { nullptr }; interface = interface->Next ? cast( CodeType, interface->Next) : CodeType { nullptr };
} }
} }
else if ( ast->Name ) else if ( ast->Name )
@ -1030,7 +1041,7 @@ void CodeStruct::to_string_def( String& result )
append_fmt( & result, " // %S", ast->InlineCmt->Content ); append_fmt( & result, " // %S", ast->InlineCmt->Content );
} }
append_fmt( & result, "\n{\n%S\n}", ast->Body.to_string() ); append_fmt( & result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
append( & result, ";\n"); append( & result, ";\n");
@ -1068,9 +1079,9 @@ void CodeTemplate::to_string( String& result )
append( & result, "export " ); append( & result, "export " );
if ( ast->Params ) if ( ast->Params )
append_fmt( & result, "template< %S >\n%S", ast->Params.to_string(), ast->Declaration.to_string() ); append_fmt( & result, "template< %S >\n%S", GEN_NS to_string(ast->Params), GEN_NS to_string(ast->Declaration) );
else else
append_fmt( & result, "template<>\n%S", ast->Declaration.to_string() ); append_fmt( & result, "template<>\n%S", GEN_NS to_string(ast->Declaration) );
} }
String CodeTypedef::to_string() String CodeTypedef::to_string()
@ -1089,18 +1100,18 @@ void CodeTypedef::to_string( String& result )
// Determines if the typedef is a function typename // Determines if the typedef is a function typename
if ( ast->UnderlyingType->ReturnType ) if ( ast->UnderlyingType->ReturnType )
append( & result, ast->UnderlyingType.to_string() ); append( & result, GEN_NS to_string(ast->UnderlyingType) );
else else
append_fmt( & result, "%S %S", ast->UnderlyingType.to_string(), ast->Name ); append_fmt( & result, "%S %S", GEN_NS to_string(ast->UnderlyingType), ast->Name );
if ( ast->UnderlyingType->Type == ECode::Typename && ast->UnderlyingType->ArrExpr ) if ( ast->UnderlyingType->Type == ECode::Typename && ast->UnderlyingType->ArrExpr )
{ {
append_fmt( & result, "[ %S ];", ast->UnderlyingType->ArrExpr->to_string() ); append_fmt( & result, "[ %S ];", GEN_NS to_string(ast->UnderlyingType->ArrExpr) );
AST* next_arr_expr = ast->UnderlyingType->ArrExpr->Next; AST* next_arr_expr = ast->UnderlyingType->ArrExpr->Next;
while ( next_arr_expr ) while ( next_arr_expr )
{ {
append_fmt( & result, "[ %S ];", next_arr_expr->to_string() ); append_fmt( & result, "[ %S ];", GEN_NS to_string(next_arr_expr) );
next_arr_expr = next_arr_expr->Next; next_arr_expr = next_arr_expr->Next;
} }
} }
@ -1189,14 +1200,14 @@ void CodeUnion::to_string( String& result )
{ {
append_fmt( & result, "%S\n{\n%S\n}" append_fmt( & result, "%S\n{\n%S\n}"
, ast->Name , ast->Name
, ast->Body.to_string() , GEN_NS to_string(ast->Body)
); );
} }
else else
{ {
// Anonymous union // Anonymous union
append_fmt( & result, "\n{\n%S\n}" append_fmt( & result, "\n{\n%S\n}"
, ast->Body.to_string() , GEN_NS to_string(ast->Body)
); );
} }
@ -1234,12 +1245,12 @@ void CodeUsing::to_string( String& result )
if ( ast->UnderlyingType->ArrExpr ) if ( ast->UnderlyingType->ArrExpr )
{ {
append_fmt( & result, "[ %S ]", ast->UnderlyingType->ArrExpr.to_string() ); append_fmt( & result, "[ %S ]", GEN_NS to_string(ast->UnderlyingType->ArrExpr) );
AST* next_arr_expr = ast->UnderlyingType->ArrExpr->Next; AST* next_arr_expr = ast->UnderlyingType->ArrExpr->Next;
while ( next_arr_expr ) while ( next_arr_expr )
{ {
append_fmt( & result, "[ %S ]", next_arr_expr->to_string() ); append_fmt( & result, "[ %S ]", GEN_NS to_string(next_arr_expr) );
next_arr_expr = next_arr_expr->Next; next_arr_expr = next_arr_expr->Next;
} }
} }
@ -1283,12 +1294,12 @@ void CodeVar::to_string( String& result )
if ( ast->ValueType->ArrExpr ) if ( ast->ValueType->ArrExpr )
{ {
append_fmt( & result, "[ %S ]", ast->ValueType->ArrExpr.to_string() ); append_fmt( & result, "[ %S ]", GEN_NS to_string(ast->ValueType->ArrExpr) );
AST* next_arr_expr = ast->ValueType->ArrExpr->Next; AST* next_arr_expr = ast->ValueType->ArrExpr->Next;
while ( next_arr_expr ) while ( next_arr_expr )
{ {
append_fmt( & result, "[ %S ]", next_arr_expr->to_string() ); append_fmt( & result, "[ %S ]", GEN_NS to_string(next_arr_expr) );
next_arr_expr = next_arr_expr->Next; next_arr_expr = next_arr_expr->Next;
} }
} }
@ -1296,9 +1307,9 @@ void CodeVar::to_string( String& result )
if ( ast->Value ) if ( ast->Value )
{ {
if ( ast->VarConstructorInit ) if ( ast->VarConstructorInit )
append_fmt( & result, "( %S ", ast->Value.to_string() ); append_fmt( & result, "( %S ", GEN_NS to_string(ast->Value) );
else else
append_fmt( & result, " = %S", ast->Value.to_string() ); append_fmt( & result, " = %S", GEN_NS to_string(ast->Value) );
} }
// Keep the chain going... // Keep the chain going...
@ -1326,25 +1337,25 @@ void CodeVar::to_string( String& result )
if ( ast->ValueType->ArrExpr ) if ( ast->ValueType->ArrExpr )
{ {
append_fmt( & result, "[ %S ]", ast->ValueType->ArrExpr.to_string() ); append_fmt( & result, "[ %S ]", GEN_NS to_string(ast->ValueType->ArrExpr) );
AST* next_arr_expr = ast->ValueType->ArrExpr->Next; AST* next_arr_expr = ast->ValueType->ArrExpr->Next;
while ( next_arr_expr ) while ( next_arr_expr )
{ {
append_fmt( & result, "[ %S ]", next_arr_expr->to_string() ); append_fmt( & result, "[ %S ]", GEN_NS to_string(next_arr_expr) );
next_arr_expr = next_arr_expr->Next; next_arr_expr = next_arr_expr->Next;
} }
} }
if ( ast->BitfieldSize ) if ( ast->BitfieldSize )
append_fmt( & result, " : %S", ast->BitfieldSize.to_string() ); append_fmt( & result, " : %S", GEN_NS to_string(ast->BitfieldSize) );
if ( ast->Value ) if ( ast->Value )
{ {
if ( ast->VarConstructorInit ) if ( ast->VarConstructorInit )
append_fmt( & result, "( %S ", ast->Value.to_string() ); append_fmt( & result, "( %S ", GEN_NS to_string(ast->Value) );
else else
append_fmt( & result, " = %S", ast->Value.to_string() ); append_fmt( & result, " = %S", GEN_NS to_string(ast->Value) );
} }
if ( ast->NextVar ) if ( ast->NextVar )
@ -1362,16 +1373,16 @@ void CodeVar::to_string( String& result )
} }
if ( ast->BitfieldSize ) if ( ast->BitfieldSize )
append_fmt( & result, "%S %S : %S", ast->ValueType.to_string(), ast->Name, ast->BitfieldSize.to_string() ); append_fmt( & result, "%S %S : %S", ast->ValueType.to_string(), ast->Name, GEN_NS to_string(ast->BitfieldSize) );
else if ( ast->ValueType->ArrExpr ) else if ( ast->ValueType->ArrExpr )
{ {
append_fmt( & result, "%S %S[ %S ]", ast->ValueType.to_string(), ast->Name, ast->ValueType->ArrExpr.to_string() ); append_fmt( & result, "%S %S[ %S ]", ast->ValueType.to_string(), ast->Name, GEN_NS to_string(ast->ValueType->ArrExpr) );
AST* next_arr_expr = ast->ValueType->ArrExpr->Next; AST* next_arr_expr = ast->ValueType->ArrExpr->Next;
while ( next_arr_expr ) while ( next_arr_expr )
{ {
append_fmt( & result, "[ %S ]", next_arr_expr->to_string() ); append_fmt( & result, "[ %S ]", GEN_NS to_string(next_arr_expr) );
next_arr_expr = next_arr_expr->Next; next_arr_expr = next_arr_expr->Next;
} }
} }
@ -1382,9 +1393,9 @@ void CodeVar::to_string( String& result )
if ( ast->Value ) if ( ast->Value )
{ {
if ( ast->VarConstructorInit ) if ( ast->VarConstructorInit )
append_fmt( & result, "( %S ", ast->Value.to_string() ); append_fmt( & result, "( %S ", GEN_NS to_string(ast->Value) );
else else
append_fmt( & result, " = %S", ast->Value.to_string() ); append_fmt( & result, " = %S", GEN_NS to_string(ast->Value) );
} }
if ( ast->NextVar ) if ( ast->NextVar )

View File

@ -3,44 +3,45 @@
#include "ast.hpp" #include "ast.hpp"
#endif #endif
void append ( CodeBody body, Code other );
void append ( CodeBody body, CodeBody other );
String to_string ( CodeBody body );
void to_string ( CodeBody body, String* result );
void to_string_export ( CodeBody body, String* result );
void add_interface( CodeClass self, CodeType interface );
String to_string ( CodeClass self );
void to_string_def( CodeClass self, String* result );
void to_string_fwd( CodeClass self, String* result );
#pragma region Code Types #pragma region Code Types
// These structs are not used at all by the C vairant.
#if ! GEN_COMPILER_C
// stati_assert( GEN_COMPILER_C, "This should not be compiled with the C-library" );
struct CodeBody struct CodeBody
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeBody ); Using_Code( CodeBody );
void append( Code other ) void append( Code other ) { return GEN_NS append( *this, other ); }
{ void append( CodeBody body ) { return GEN_NS append(*this, body); }
GEN_ASSERT(other.ast != nullptr); bool has_entries() { return GEN_NS has_entries(rcast( AST*, ast )); }
if (other.is_body()) { String to_string() { return GEN_NS to_string(* this); }
append( cast(CodeBody, & other) ); void to_string( String& result ) { return GEN_NS to_string(* this, & result ); }
} void to_string_export( String& result ) { return GEN_NS to_string_export(* this, & result); }
#endif
GEN_NS append( raw(), other.ast );
}
void append( CodeBody body )
{
for ( Code entry : body ) {
append( entry );
}
}
bool has_entries() { return GEN_NS has_entries(rcast( AST*, ast )); }
AST* raw() { return rcast( AST*, ast ); }
void to_string( String& result );
void to_string_export( String& result );
AST_Body* operator->() { return ast; }
Using_CodeOps( CodeBody );
operator Code() { return * rcast( Code*, this ); } operator Code() { return * rcast( Code*, this ); }
AST_Body* operator->() { return ast; }
#pragma region Iterator #pragma region Iterator
Code begin() Code begin()
{ {
if ( ast ) if ( ast )
return { rcast( AST*, ast)->Front }; return { rcast( AST*, ast)->Front };
return { nullptr }; return { nullptr };
} }
Code end() Code end()
@ -54,21 +55,18 @@ struct CodeBody
struct CodeClass struct CodeClass
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 0
Using_Code( CodeClass ); Using_Code( CodeClass );
void add_interface( CodeType interface ); void add_interface( CodeType interface );
void to_string_def( String& result ); String to_string();
void to_string_fwd( String& result ); void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
AST* raw() Using_CodeOps( CodeClass );
{ operator Code() { return * rcast( Code*, this ); }
return rcast( AST*, ast );
}
operator Code()
{
return * rcast( Code*, this );
}
AST_Class* operator->() AST_Class* operator->()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -83,13 +81,17 @@ struct CodeClass
struct CodeParam struct CodeParam
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeParam ); Using_Code( CodeParam );
void append( CodeParam other ); void append( CodeParam other );
CodeParam get( s32 idx ); CodeParam get( s32 idx );
bool has_entries(); bool has_entries();
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps( CodeParam );
AST* raw() AST* raw()
{ {
return rcast( AST*, ast ); return rcast( AST*, ast );
@ -132,6 +134,7 @@ struct CodeParam
struct CodeSpecifiers struct CodeSpecifiers
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeSpecifiers ); Using_Code( CodeSpecifiers );
bool append( SpecifierT spec ) bool append( SpecifierT spec )
@ -142,9 +145,9 @@ struct CodeSpecifiers
return false; return false;
} }
if ( raw()->NumEntries == AST::ArrSpecs_Cap ) if ( raw()->NumEntries == AST_ArrSpecs_Cap )
{ {
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap ); log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST_ArrSpecs_Cap );
return false; return false;
} }
@ -170,9 +173,9 @@ struct CodeSpecifiers
return -1; return -1;
} }
if ( raw()->NumEntries == AST::ArrSpecs_Cap ) if ( raw()->NumEntries == AST_ArrSpecs_Cap )
{ {
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap ); log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST_ArrSpecs_Cap );
return -1; return -1;
} }
@ -202,7 +205,11 @@ struct CodeSpecifiers
} }
return result; return result;
} }
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeSpecifiers);
AST* raw() AST* raw()
{ {
return rcast( AST*, ast ); return rcast( AST*, ast );
@ -239,13 +246,17 @@ struct CodeSpecifiers
struct CodeStruct struct CodeStruct
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeStruct ); Using_Code( CodeStruct );
void add_interface( CodeType interface ); void add_interface( CodeType interface );
void to_string_def( String& result ); String to_string();
void to_string_fwd( String& result ); void to_string_fwd( String& result );
void to_string_def( String& result );
#endif
Using_CodeOps( CodeStruct );
AST* raw() AST* raw()
{ {
return rcast( AST*, ast ); return rcast( AST*, ast );
@ -266,27 +277,47 @@ struct CodeStruct
AST_Struct* ast; AST_Struct* ast;
}; };
#define Define_CodeType( Typename ) \ struct CodeAttributes
struct Code##Typename \ {
{ \ #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( Code ## Typename ); \ Using_Code(CodeAttributes);
AST* raw(); \ String to_string();
operator Code(); \ #endif
AST_##Typename* operator->(); \
AST_##Typename* ast; \ Using_CodeOps(CodeAttributes);
} AST *raw();
operator Code();
AST_Attributes *operator->();
AST_Attributes *ast;
};
Define_CodeType( Attributes );
// Define_CodeType( BaseClass ); // Define_CodeType( BaseClass );
Define_CodeType( Comment );
struct CodeComment
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code(CodeComment);
String to_string();
#endif
Using_CodeOps(CodeComment);
AST *raw();
operator Code();
AST_Comment *operator->();
AST_Comment *ast;
};
struct CodeConstructor struct CodeConstructor
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeConstructor ); Using_Code( CodeConstructor );
void to_string_def( String& result ); String to_string();
void to_string_fwd( String& result ); void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
Using_CodeOps(CodeConstructor);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Constructor* operator->(); AST_Constructor* operator->();
@ -295,10 +326,14 @@ struct CodeConstructor
struct CodeDefine struct CodeDefine
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeDefine ); Using_Code( CodeDefine );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeDefine);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Define* operator->(); AST_Define* operator->();
@ -307,11 +342,15 @@ struct CodeDefine
struct CodeDestructor struct CodeDestructor
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeDestructor ); Using_Code( CodeDestructor );
void to_string_def( String& result ); String to_string();
void to_string_fwd( String& result ); void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
Using_CodeOps(CodeDestructor);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Destructor* operator->(); AST_Destructor* operator->();
@ -320,20 +359,36 @@ struct CodeDestructor
struct CodeEnum struct CodeEnum
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeEnum ); Using_Code( CodeEnum );
void to_string_def( String& result ); String to_string();
void to_string_fwd( String& result ); void to_string_def( String& result );
void to_string_class_def( String& result ); void to_string_fwd( String& result );
void to_string_class_fwd( String& result ); void to_string_class_def( String& result );
void to_string_class_fwd( String& result );
#endif
Using_CodeOps(CodeEnum);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Enum* operator->(); AST_Enum* operator->();
AST_Enum* ast; AST_Enum* ast;
}; };
Define_CodeType( Exec ); struct CodeExec
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code(CodeExec);
String to_string();
#endif
Using_CodeOps(CodeExec);
AST *raw();
operator Code();
AST_Exec *operator->();
AST_Exec *ast;
};
#if GEN_EXECUTION_EXPRESSION_SUPPORT #if GEN_EXECUTION_EXPRESSION_SUPPORT
struct CodeExpr struct CodeExpr
@ -543,10 +598,13 @@ struct CodeExpr_UnaryPostfix
struct CodeExtern struct CodeExtern
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeExtern ); Using_Code( CodeExtern );
void to_string( String& result ); void to_string( String& result );
#endif
Using_CodeOps(CodeExtern);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Extern* operator->(); AST_Extern* operator->();
@ -555,10 +613,14 @@ struct CodeExtern
struct CodeInclude struct CodeInclude
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeInclude ); Using_Code( CodeInclude );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeInclude);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Include* operator->(); AST_Include* operator->();
@ -567,10 +629,14 @@ struct CodeInclude
struct CodeFriend struct CodeFriend
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeFriend ); Using_Code( CodeFriend );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeFriend);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Friend* operator->(); AST_Friend* operator->();
@ -579,11 +645,15 @@ struct CodeFriend
struct CodeFn struct CodeFn
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeFn ); Using_Code( CodeFn );
void to_string_def( String& result ); String to_string();
void to_string_fwd( String& result ); void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
Using_CodeOps(CodeFn);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Fn* operator->(); AST_Fn* operator->();
@ -592,10 +662,14 @@ struct CodeFn
struct CodeModule struct CodeModule
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeModule ); Using_Code( CodeModule );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeModule);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Module* operator->(); AST_Module* operator->();
@ -604,10 +678,14 @@ struct CodeModule
struct CodeNS struct CodeNS
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeNS ); Using_Code( CodeNS );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeNS);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_NS* operator->(); AST_NS* operator->();
@ -616,11 +694,15 @@ struct CodeNS
struct CodeOperator struct CodeOperator
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeOperator ); Using_Code( CodeOperator );
void to_string_def( String& result ); String to_string();
void to_string_fwd( String& result ); void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
Using_CodeOps(CodeOperator);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Operator* operator->(); AST_Operator* operator->();
@ -629,11 +711,15 @@ struct CodeOperator
struct CodeOpCast struct CodeOpCast
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeOpCast ); Using_Code( CodeOpCast );
void to_string_def( String& result ); String to_string();
void to_string_fwd( String& result ); void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
Using_CodeOps(CodeOpCast);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_OpCast* operator->(); AST_OpCast* operator->();
@ -642,10 +728,14 @@ struct CodeOpCast
struct CodePragma struct CodePragma
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodePragma ); Using_Code( CodePragma );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps( CodePragma );
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Pragma* operator->(); AST_Pragma* operator->();
@ -654,15 +744,19 @@ struct CodePragma
struct CodePreprocessCond struct CodePreprocessCond
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodePreprocessCond ); Using_Code( CodePreprocessCond );
void to_string_if( String& result ); String to_string();
void to_string_ifdef( String& result ); void to_string_if( String& result );
void to_string_ifndef( String& result ); void to_string_ifdef( String& result );
void to_string_elif( String& result ); void to_string_ifndef( String& result );
void to_string_else( String& result ); void to_string_elif( String& result );
void to_string_endif( String& result ); void to_string_else( String& result );
void to_string_endif( String& result );
#endif
Using_CodeOps( CodePreprocessCond );
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_PreprocessCond* operator->(); AST_PreprocessCond* operator->();
@ -674,7 +768,8 @@ struct CodeStmt
{ {
Using_Code( CodeStmt ); Using_Code( CodeStmt );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -686,7 +781,8 @@ struct CodeStmt_Break
{ {
Using_Code( CodeStmt_Break ); Using_Code( CodeStmt_Break );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -698,7 +794,8 @@ struct CodeStmt_Case
{ {
Using_Code( CodeStmt_Case ); Using_Code( CodeStmt_Case );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -710,7 +807,8 @@ struct CodeStmt_Continue
{ {
Using_Code( CodeStmt_Continue ); Using_Code( CodeStmt_Continue );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -722,7 +820,8 @@ struct CodeStmt_Decl
{ {
Using_Code( CodeStmt_Decl ); Using_Code( CodeStmt_Decl );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -734,7 +833,8 @@ struct CodeStmt_Do
{ {
Using_Code( CodeStmt_Do ); Using_Code( CodeStmt_Do );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -746,7 +846,8 @@ struct CodeStmt_Expr
{ {
Using_Code( CodeStmt_Expr ); Using_Code( CodeStmt_Expr );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -758,7 +859,8 @@ struct CodeStmt_Else
{ {
Using_Code( CodeStmt_Else ); Using_Code( CodeStmt_Else );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -770,7 +872,8 @@ struct CodeStmt_If
{ {
Using_Code( CodeStmt_If ); Using_Code( CodeStmt_If );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -782,7 +885,8 @@ struct CodeStmt_For
{ {
Using_Code( CodeStmt_For ); Using_Code( CodeStmt_For );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -794,7 +898,8 @@ struct CodeStmt_Goto
{ {
Using_Code( CodeStmt_Goto ); Using_Code( CodeStmt_Goto );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -806,7 +911,8 @@ struct CodeStmt_Label
{ {
Using_Code( CodeStmt_Label ); Using_Code( CodeStmt_Label );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -818,7 +924,8 @@ struct CodeStmt_Switch
{ {
Using_Code( CodeStmt_Switch ); Using_Code( CodeStmt_Switch );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -830,7 +937,8 @@ struct CodeStmt_While
{ {
Using_Code( CodeStmt_While ); Using_Code( CodeStmt_While );
void to_string( String& result ); String to_string();
void to_string( String& result );
AST* raw(); AST* raw();
operator Code(); operator Code();
@ -841,10 +949,14 @@ struct CodeStmt_While
struct CodeTemplate struct CodeTemplate
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeTemplate ); Using_Code( CodeTemplate );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps( CodeTemplate );
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Template* operator->(); AST_Template* operator->();
@ -853,10 +965,14 @@ struct CodeTemplate
struct CodeType struct CodeType
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeType ); Using_Code( CodeType );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps( CodeType );
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Type* operator->(); AST_Type* operator->();
@ -865,10 +981,14 @@ struct CodeType
struct CodeTypedef struct CodeTypedef
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeTypedef ); Using_Code( CodeTypedef );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps( CodeTypedef );
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Typedef* operator->(); AST_Typedef* operator->();
@ -877,10 +997,14 @@ struct CodeTypedef
struct CodeUnion struct CodeUnion
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeUnion ); Using_Code( CodeUnion );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeUnion);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Union* operator->(); AST_Union* operator->();
@ -889,11 +1013,15 @@ struct CodeUnion
struct CodeUsing struct CodeUsing
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeUsing ); Using_Code( CodeUsing );
void to_string( String& result ); String to_string();
void to_string_ns( String& result ); void to_string( String& result );
void to_string_ns( String& result );
#endif
Using_CodeOps(CodeUsing);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Using* operator->(); AST_Using* operator->();
@ -902,10 +1030,14 @@ struct CodeUsing
struct CodeVar struct CodeVar
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeVar ); Using_Code( CodeVar );
void to_string( String& result ); String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeVar);
AST* raw(); AST* raw();
operator Code(); operator Code();
AST_Var* operator->(); AST_Var* operator->();
@ -914,5 +1046,11 @@ struct CodeVar
#undef Define_CodeType #undef Define_CodeType
#undef Using_Code #undef Using_Code
#undef Using_CodeOps
#if GEN_SUPPORT_CPP_REFERENCES
void to_string_export( CodeBody body, String& result ) { return to_string_export(body, & result); };
#endif
#endif //if ! GEN_COMPILER_C
#pragma endregion Code Types #pragma endregion Code Types

View File

@ -11,7 +11,7 @@ inline Code& Code::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -27,7 +27,7 @@ inline CodeBody& CodeBody::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -43,7 +43,7 @@ inline CodeAttributes& CodeAttributes::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -79,7 +79,7 @@ inline CodeComment& CodeComment::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -115,7 +115,7 @@ inline CodeConstructor& CodeConstructor::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -151,7 +151,7 @@ inline CodeClass& CodeClass::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -167,7 +167,7 @@ inline CodeDefine& CodeDefine::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -203,7 +203,7 @@ inline CodeDestructor& CodeDestructor::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -239,7 +239,7 @@ inline CodeEnum& CodeEnum::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -275,7 +275,7 @@ inline CodeExec& CodeExec::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -311,7 +311,7 @@ inline CodeExtern& CodeExtern::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -347,7 +347,7 @@ inline CodeFriend& CodeFriend::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -383,7 +383,7 @@ inline CodeFn& CodeFn::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -419,7 +419,7 @@ inline CodeInclude& CodeInclude::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -455,7 +455,7 @@ inline CodeModule& CodeModule::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -491,7 +491,7 @@ inline CodeNS& CodeNS::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -527,7 +527,7 @@ inline CodeOperator& CodeOperator::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -563,7 +563,7 @@ inline CodeOpCast& CodeOpCast::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -599,7 +599,7 @@ inline CodeParam& CodeParam::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -615,7 +615,7 @@ inline CodePragma& CodePragma::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -651,7 +651,7 @@ inline CodePreprocessCond& CodePreprocessCond::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -687,7 +687,7 @@ inline CodeSpecifiers& CodeSpecifiers::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -703,7 +703,7 @@ inline CodeStruct& CodeStruct::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -719,7 +719,7 @@ inline CodeTemplate& CodeTemplate::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -755,7 +755,7 @@ inline CodeType& CodeType::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -791,7 +791,7 @@ inline CodeTypedef& CodeTypedef::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -827,7 +827,7 @@ inline CodeUnion& CodeUnion::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -863,7 +863,7 @@ inline CodeUsing& CodeUsing::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
@ -899,7 +899,7 @@ inline CodeVar& CodeVar::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype( ast ), other.ast->duplicate() ); ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr; rcast( AST*, ast )->Parent = nullptr;
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );

View File

@ -163,13 +163,35 @@ Code& Code::operator ++()
#pragma endregion Code #pragma endregion Code
inline inline
void CodeClass::add_interface( CodeType type ) void append( CodeBody self, Code other )
{ {
CodeType possible_slot = ast->ParentType; GEN_ASSERT(other.ast != nullptr);
if (is_body(other)) {
append( self, cast(CodeBody, other) );
return;
}
append( rcast(AST*, self.ast), other.ast );
}
inline
void append( CodeBody self, CodeBody body )
{
for ( Code entry : body ) {
append( self, entry );
}
}
inline
void add_interface( CodeClass self, CodeType type )
{
GEN_ASSERT(self.ast !=nullptr);
CodeType possible_slot = self->ParentType;
if ( possible_slot.ast ) if ( possible_slot.ast )
{ {
// Were adding an interface to parent type, so we need to make sure the parent type is public. // Were adding an interface to parent type, so we need to make sure the parent type is public.
ast->ParentAccess = AccessSpec_Public; self->ParentAccess = AccessSpec_Public;
// If your planning on adding a proper parent, // If your planning on adding a proper parent,
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly. // then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
} }

View File

@ -79,69 +79,69 @@ void define_constants()
scast(String, Code_Global->Content) = Code_Global->Name; scast(String, Code_Global->Content) = Code_Global->Name;
Code_Invalid = make_code(); Code_Invalid = make_code();
Code_Invalid.set_global(); set_global(Code_Invalid);
t_empty = (CodeType) make_code(); t_empty = (CodeType) make_code();
t_empty->Type = ECode::Typename; t_empty->Type = ECode::Typename;
t_empty->Name = get_cached_string( txt("") ); t_empty->Name = get_cached_string( txt("") );
t_empty.set_global(); set_global(t_empty);
access_private = make_code(); access_private = make_code();
access_private->Type = ECode::Access_Private; access_private->Type = ECode::Access_Private;
access_private->Name = get_cached_string( txt("private:\n") ); access_private->Name = get_cached_string( txt("private:\n") );
access_private.set_global(); set_global(access_private);
access_protected = make_code(); access_protected = make_code();
access_protected->Type = ECode::Access_Protected; access_protected->Type = ECode::Access_Protected;
access_protected->Name = get_cached_string( txt("protected:\n") ); access_protected->Name = get_cached_string( txt("protected:\n") );
access_protected.set_global(); set_global(access_protected);
access_public = make_code(); access_public = make_code();
access_public->Type = ECode::Access_Public; access_public->Type = ECode::Access_Public;
access_public->Name = get_cached_string( txt("public:\n") ); access_public->Name = get_cached_string( txt("public:\n") );
access_public.set_global(); set_global(access_public);
attrib_api_export = def_attributes( code(GEN_API_Export_Code)); attrib_api_export = def_attributes( code(GEN_API_Export_Code));
attrib_api_export.set_global(); set_global(attrib_api_export);
attrib_api_import = def_attributes( code(GEN_API_Import_Code)); attrib_api_import = def_attributes( code(GEN_API_Import_Code));
attrib_api_import.set_global(); set_global(attrib_api_import);
module_global_fragment = make_code(); module_global_fragment = make_code();
module_global_fragment->Type = ECode::Untyped; module_global_fragment->Type = ECode::Untyped;
module_global_fragment->Name = get_cached_string( txt("module;") ); module_global_fragment->Name = get_cached_string( txt("module;") );
module_global_fragment->Content = module_global_fragment->Name; module_global_fragment->Content = module_global_fragment->Name;
module_global_fragment.set_global(); set_global(module_global_fragment);
module_private_fragment = make_code(); module_private_fragment = make_code();
module_private_fragment->Type = ECode::Untyped; module_private_fragment->Type = ECode::Untyped;
module_private_fragment->Name = get_cached_string( txt("module : private;") ); module_private_fragment->Name = get_cached_string( txt("module : private;") );
module_private_fragment->Content = module_private_fragment->Name; module_private_fragment->Content = module_private_fragment->Name;
module_private_fragment.set_global(); set_global(module_private_fragment);
fmt_newline = make_code(); fmt_newline = make_code();
fmt_newline->Type = ECode::NewLine; fmt_newline->Type = ECode::NewLine;
fmt_newline.set_global(); set_global(fmt_newline);
pragma_once = (CodePragma) make_code(); pragma_once = (CodePragma) make_code();
pragma_once->Type = ECode::Preprocess_Pragma; pragma_once->Type = ECode::Preprocess_Pragma;
pragma_once->Name = get_cached_string( txt("once") ); pragma_once->Name = get_cached_string( txt("once") );
pragma_once->Content = pragma_once->Name; pragma_once->Content = pragma_once->Name;
pragma_once.set_global(); set_global(pragma_once);
param_varadic = (CodeType) make_code(); param_varadic = (CodeType) make_code();
param_varadic->Type = ECode::Parameters; param_varadic->Type = ECode::Parameters;
param_varadic->Name = get_cached_string( txt("...") ); param_varadic->Name = get_cached_string( txt("...") );
param_varadic->ValueType = t_empty; param_varadic->ValueType = t_empty;
param_varadic.set_global(); set_global(param_varadic);
preprocess_else = (CodePreprocessCond) make_code(); preprocess_else = (CodePreprocessCond) make_code();
preprocess_else->Type = ECode::Preprocess_Else; preprocess_else->Type = ECode::Preprocess_Else;
preprocess_else.set_global(); set_global(preprocess_else);
preprocess_endif = (CodePreprocessCond) make_code(); preprocess_endif = (CodePreprocessCond) make_code();
preprocess_endif->Type = ECode::Preprocess_EndIf; preprocess_endif->Type = ECode::Preprocess_EndIf;
preprocess_endif.set_global(); set_global(preprocess_endif);
# define def_constant_code_type( Type_ ) \ # define def_constant_code_type( Type_ ) \
t_##Type_ = def_type( name(Type_) ); \ t_##Type_ = def_type( name(Type_) ); \

View File

@ -527,7 +527,7 @@ CodeConstructor def_constructor( CodeParam params, Code initializer_list, Code b
break; break;
default: default:
log_failure("gen::def_constructor: body must be either of Function_Body or Untyped type - %s", body.debug_str()); log_failure("gen::def_constructor: body must be either of Function_Body or Untyped type - %s", debug_str(body));
return InvalidCode; return InvalidCode;
} }
@ -579,7 +579,7 @@ CodeClass def_class( StrC name
break; break;
default: default:
log_failure("gen::def_class: body must be either of Class_Body or Untyped type - %s", body.debug_str()); log_failure("gen::def_class: body must be either of Class_Body or Untyped type - %s", debug_str(body));
return InvalidCode; return InvalidCode;
} }
@ -605,7 +605,7 @@ CodeClass def_class( StrC name
{ {
for (s32 idx = 0; idx < num_interfaces; idx++ ) for (s32 idx = 0; idx < num_interfaces; idx++ )
{ {
result.add_interface( interfaces[idx] ); add_interface(result, interfaces[idx] );
} }
} }
@ -665,7 +665,7 @@ CodeDestructor def_destructor( Code body, CodeSpecifiers specifiers )
break; break;
default: default:
log_failure("gen::def_destructor: body must be either of Function_Body or Untyped type - %s", body.debug_str()); log_failure("gen::def_destructor: body must be either of Function_Body or Untyped type - %s", debug_str(body));
return InvalidCode; return InvalidCode;
} }
@ -715,7 +715,7 @@ CodeEnum def_enum( StrC name
break; break;
default: default:
log_failure( "gen::def_enum: body must be of Enum_Body or Untyped type %s", body.debug_str()); log_failure( "gen::def_enum: body must be of Enum_Body or Untyped type %s", debug_str(body));
return InvalidCode; return InvalidCode;
} }
@ -772,7 +772,7 @@ CodeExtern def_extern_link( StrC name, Code body )
if ( body->Type != Extern_Linkage_Body && body->Type != Untyped ) if ( body->Type != Extern_Linkage_Body && body->Type != Untyped )
{ {
log_failure("gen::def_extern_linkage: body is not of extern_linkage or untyped type %s", body->debug_str()); log_failure("gen::def_extern_linkage: body is not of extern_linkage or untyped type %s", debug_str(body));
return InvalidCode; return InvalidCode;
} }
@ -804,7 +804,7 @@ CodeFriend def_friend( Code declaration )
break; break;
default: default:
log_failure("gen::def_friend: requires declartion to have class, function, operator, or struct - %s", declaration->debug_str()); log_failure("gen::def_friend: requires declartion to have class, function, operator, or struct - %s", debug_str(declaration));
return InvalidCode; return InvalidCode;
} }
@ -866,7 +866,7 @@ CodeFn def_function( StrC name
default: default:
{ {
log_failure("gen::def_function: body must be either of Function_Body, Execution, or Untyped type. %s", body->debug_str()); log_failure("gen::def_function: body must be either of Function_Body, Execution, or Untyped type. %s", debug_str(body));
return InvalidCode; return InvalidCode;
} }
} }
@ -944,7 +944,7 @@ CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags )
if ( body->Type != Namespace_Body && body->Type != Untyped ) if ( body->Type != Namespace_Body && body->Type != Untyped )
{ {
log_failure("gen::def_namespace: body is not of namespace or untyped type %s", body.debug_str()); log_failure("gen::def_namespace: body is not of namespace or untyped type %s", debug_str(body));
return InvalidCode; return InvalidCode;
} }
@ -1008,7 +1008,7 @@ CodeOperator def_operator( OperatorT op, StrC nspace
default: default:
{ {
log_failure("gen::def_operator: body must be either of Function_Body, Execution, or Untyped type. %s", body->debug_str()); log_failure("gen::def_operator: body must be either of Function_Body, Execution, or Untyped type. %s", debug_str(body));
return InvalidCode; return InvalidCode;
} }
} }
@ -1057,7 +1057,7 @@ CodeOpCast def_operator_cast( CodeType type, Code body, CodeSpecifiers const_spe
if ( body->Type != Function_Body && body->Type != Execution ) if ( body->Type != Function_Body && body->Type != Execution )
{ {
log_failure( "gen::def_operator_cast: body is not of function body or execution type - %s", body.debug_str() ); log_failure( "gen::def_operator_cast: body is not of function body or execution type - %s", debug_str(body) );
return InvalidCode; return InvalidCode;
} }
@ -1086,13 +1086,13 @@ CodeParam def_param( CodeType type, StrC name, Code value )
if ( type->Type != Typename ) if ( type->Type != Typename )
{ {
log_failure( "gen::def_param: type is not a typename - %s", type.debug_str() ); log_failure( "gen::def_param: type is not a typename - %s", debug_str(type) );
return InvalidCode; return InvalidCode;
} }
if ( value && value->Type != Untyped ) if ( value && value->Type != Untyped )
{ {
log_failure( "gen::def_param: value is not untyped - %s", value.debug_str() ); log_failure( "gen::def_param: value is not untyped - %s", debug_str(value) );
return InvalidCode; return InvalidCode;
} }
@ -1189,13 +1189,13 @@ CodeStruct def_struct( StrC name
if ( parent && parent->Type != Typename ) if ( parent && parent->Type != Typename )
{ {
log_failure( "gen::def_struct: parent was not a `Struct` type - %s", parent.debug_str() ); 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 != Struct_Body )
{ {
log_failure( "gen::def_struct: body was not a Struct_Body type - %s", body.debug_str() ); log_failure( "gen::def_struct: body was not a Struct_Body type - %s", debug_str(body) );
return InvalidCode; return InvalidCode;
} }
@ -1256,7 +1256,7 @@ CodeTemplate def_template( CodeParam params, Code declaration, ModuleFlag mflags
break; break;
default: default:
log_failure( "gen::def_template: declaration is not of class, function, struct, variable, or using type - %s", declaration.debug_str() ); log_failure( "gen::def_template: declaration is not of class, function, struct, variable, or using type - %s", debug_str(declaration) );
} }
CodeTemplate CodeTemplate
@ -1275,19 +1275,19 @@ CodeType def_type( StrC name, Code arrayexpr, CodeSpecifiers specifiers, CodeAtt
if ( attributes && attributes->Type != ECode::PlatformAttributes ) if ( attributes && attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_type: attributes is not of attributes type - %s", attributes.debug_str() ); log_failure( "gen::def_type: attributes is not of attributes type - %s", debug_str(attributes) );
return InvalidCode; return InvalidCode;
} }
if ( specifiers && specifiers->Type != ECode::Specifiers ) if ( specifiers && specifiers->Type != ECode::Specifiers )
{ {
log_failure( "gen::def_type: specifiers is not of specifiers type - %s", specifiers.debug_str() ); log_failure( "gen::def_type: specifiers is not of specifiers type - %s", debug_str(specifiers) );
return InvalidCode; return InvalidCode;
} }
if ( arrayexpr && arrayexpr->Type != ECode::Untyped ) if ( arrayexpr && arrayexpr->Type != ECode::Untyped )
{ {
log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", arrayexpr->debug_str() ); log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", debug_str(arrayexpr) );
return InvalidCode; return InvalidCode;
} }
@ -1329,13 +1329,13 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
case Typename: case Typename:
break; break;
default: default:
log_failure( "gen::def_typedef: type was not a Class, Enum, Function Forward, Struct, Typename, or Union - %s", type.debug_str() ); 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 ( attributes && attributes->Type != ECode::PlatformAttributes )
{ {
log_failure( "gen::def_typedef: attributes was not a PlatformAttributes - %s", attributes.debug_str() ); log_failure( "gen::def_typedef: attributes was not a PlatformAttributes - %s", debug_str(attributes) );
return InvalidCode; return InvalidCode;
} }
@ -1359,7 +1359,7 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
{ {
if (type->Type != Untyped) if (type->Type != Untyped)
{ {
log_failure( "gen::def_typedef: name was empty and type was not untyped (indicating its a function typedef) - %s", type.debug_str() ); 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;
} }
@ -1381,7 +1381,7 @@ CodeUnion def_union( StrC name, Code body, CodeAttributes attributes, ModuleFlag
if ( body->Type != ECode::Union_Body ) if ( body->Type != ECode::Union_Body )
{ {
log_failure( "gen::def_union: body was not a Union_Body type - %s", body.debug_str() ); log_failure( "gen::def_union: body was not a Union_Body type - %s", debug_str(body) );
return InvalidCode; return InvalidCode;
} }
@ -1482,7 +1482,7 @@ CodeVar def_variable( CodeType type, StrC name, Code value
if ( value && value->Type != ECode::Untyped ) if ( value && value->Type != ECode::Untyped )
{ {
log_failure( "gen::def_variable: value was not a `Untyped` type - %s", value.debug_str() ); log_failure( "gen::def_variable: value was not a `Untyped` type - %s", debug_str(value) );
return InvalidCode; return InvalidCode;
} }
@ -1558,14 +1558,14 @@ CodeBody def_class_body( s32 num, ... )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_CLASS_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1595,14 +1595,14 @@ CodeBody def_class_body( s32 num, Code* codes )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_CLASS_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -1632,11 +1632,11 @@ CodeBody def_enum_body( s32 num, ... )
if ( entry->Type != Untyped && entry->Type != Comment ) if ( entry->Type != Untyped && entry->Type != Comment )
{ {
log_failure("gen::def_enum_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() ); log_failure("gen::def_enum_body: Entry type is not allowed - %s. Must be of untyped or comment type.", debug_str(entry) );
return InvalidCode; return InvalidCode;
} }
result.append( entry ); append(result, entry );
} }
while ( num--, num > 0 ); while ( num--, num > 0 );
va_end(va); va_end(va);
@ -1664,11 +1664,11 @@ CodeBody def_enum_body( s32 num, Code* codes )
if ( entry->Type != Untyped && entry->Type != Comment ) if ( entry->Type != Untyped && entry->Type != Comment )
{ {
log_failure("gen::def_enum_body: Entry type is not allowed: %s", entry.debug_str() ); log_failure("gen::def_enum_body: Entry type is not allowed: %s", debug_str(entry) );
return InvalidCode; return InvalidCode;
} }
result.append( entry ); append(result, entry );
} }
while ( codes++, num--, num > 0 ); while ( codes++, num--, num > 0 );
@ -1699,14 +1699,14 @@ CodeBody def_export_body( s32 num, ... )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1736,14 +1736,14 @@ CodeBody def_export_body( s32 num, Code* codes )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -1774,14 +1774,14 @@ CodeBody def_extern_link_body( s32 num, ... )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1811,14 +1811,14 @@ CodeBody def_extern_link_body( s32 num, Code* codes )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -1851,14 +1851,14 @@ CodeBody def_function_body( s32 num, ... )
{ {
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
log_failure("gen::" stringize(def_function_body) ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" stringize(def_function_body) ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1888,13 +1888,13 @@ CodeBody def_function_body( s32 num, Code* codes )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
log_failure("gen::" "def_function_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_function_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -1925,18 +1925,19 @@ CodeBody def_global_body( s32 num, ... )
switch (entry->Type) switch (entry->Type)
{ {
case Global_Body: case Global_Body:
result.append( entry.code_cast<CodeBody>() ) ; // result.append( entry.code_cast<CodeBody>() ) ;
append( result, cast(CodeBody, entry) );
continue; continue;
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1966,18 +1967,18 @@ CodeBody def_global_body( s32 num, Code* codes )
switch (entry->Type) switch (entry->Type)
{ {
case Global_Body: case Global_Body:
result.append( entry.code_cast<CodeBody>() ) ; append(result, cast(CodeBody, entry) );
continue; continue;
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -2008,14 +2009,14 @@ CodeBody def_namespace_body( s32 num, ... )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -2045,13 +2046,13 @@ CodeBody def_namespace_body( s32 num, Code* codes )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", entry.debug_str() ); log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", debug_str(entry) );
return InvalidCode; return InvalidCode;
default: break; default: break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -2140,7 +2141,7 @@ CodeSpecifiers def_specifiers( s32 num, ... )
return InvalidCode; return InvalidCode;
} }
if ( num > AST::ArrSpecs_Cap ) if ( num > AST_ArrSpecs_Cap )
{ {
log_failure("gen::def_specifiers: num of speciifers to define AST larger than AST specicifier capacity - %d", num); log_failure("gen::def_specifiers: num of speciifers to define AST larger than AST specicifier capacity - %d", num);
return InvalidCode; return InvalidCode;
@ -2172,7 +2173,7 @@ CodeSpecifiers def_specifiers( s32 num, SpecifierT* specs )
return InvalidCode; return InvalidCode;
} }
if ( num > AST::ArrSpecs_Cap ) if ( num > AST_ArrSpecs_Cap )
{ {
log_failure("gen::def_specifiers: num of speciifers to define AST larger than AST specicifier capacity - %d", num); log_failure("gen::def_specifiers: num of speciifers to define AST larger than AST specicifier capacity - %d", num);
return InvalidCode; return InvalidCode;
@ -2217,14 +2218,14 @@ CodeBody def_struct_body( s32 num, ... )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", entry.debug_str()); log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", debug_str(entry));
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -2254,14 +2255,14 @@ CodeBody def_struct_body( s32 num, Code* codes )
switch (entry->Type) switch (entry->Type)
{ {
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", entry.debug_str() ); log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", debug_str(entry) );
return InvalidCode; return InvalidCode;
default: default:
break; break;
} }
result.append(entry); append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -2291,11 +2292,11 @@ CodeBody def_union_body( s32 num, ... )
if ( entry->Type != Untyped && entry->Type != Comment ) if ( entry->Type != Untyped && entry->Type != Comment )
{ {
log_failure("gen::def_union_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() ); log_failure("gen::def_union_body: Entry type is not allowed - %s. Must be of untyped or comment type.", debug_str(entry) );
return InvalidCode; return InvalidCode;
} }
result.append( entry ); append(result, entry );
} }
while ( num--, num > 0 ); while ( num--, num > 0 );
va_end(va); va_end(va);
@ -2323,11 +2324,11 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
if ( entry->Type != Untyped && entry->Type != Comment ) if ( entry->Type != Untyped && entry->Type != Comment )
{ {
log_failure("gen::def_union_body: Entry type is not allowed: %s", entry.debug_str() ); log_failure("gen::def_union_body: Entry type is not allowed: %s", debug_str(entry) );
return InvalidCode; return InvalidCode;
} }
result.append( entry ); append(result, entry );
} }
while ( codes++, num--, num > 0 ); while ( codes++, num--, num > 0 );

View File

@ -1115,7 +1115,7 @@ CodeBody parse_class_struct_body( TokType which, Token name )
return InvalidCode; return InvalidCode;
} }
result.append( member ); append(result, member );
} }
eat( TokType::BraceCurly_Close ); eat( TokType::BraceCurly_Close );
@ -1503,7 +1503,7 @@ CodeFn parse_function_after_name(
default: default:
{ {
log_failure("Body must be either of Function_Body or Untyped type, %s\n%s", body.debug_str(), Context.to_string()); log_failure("Body must be either of Function_Body or Untyped type, %s\n%s", debug_str(body), Context.to_string());
Context.pop(); Context.pop();
return InvalidCode; return InvalidCode;
} }
@ -1568,7 +1568,7 @@ Code parse_function_body()
if ( len > 0 ) if ( len > 0 )
{ {
result.append( def_execution( { len, start.Text } ) ); append( result, def_execution( { len, start.Text } ) );
} }
eat( TokType::BraceCurly_Close ); eat( TokType::BraceCurly_Close );
@ -1878,7 +1878,7 @@ CodeBody parse_global_nspace( CodeT which )
} }
// log_fmt("Global Body Member: %s", member->debug_str()); // log_fmt("Global Body Member: %s", member->debug_str());
result.append( member ); append(result, member );
} }
if ( which != Global_Body ) if ( which != Global_Body )
@ -3743,7 +3743,7 @@ CodeEnum parse_enum( bool inplace_def )
return InvalidCode; return InvalidCode;
} }
body.append( member ); append(body, member );
} }
eat( TokType::BraceCurly_Close ); eat( TokType::BraceCurly_Close );
@ -5067,7 +5067,7 @@ CodeTypedef parse_typedef()
// Type needs to be aware of its parent so that it can be serialized properly. // Type needs to be aware of its parent so that it can be serialized properly.
if ( type->Type == Typename && array_expr && array_expr->Type != Invalid ) if ( type->Type == Typename && array_expr && array_expr->Type != Invalid )
type.code_cast<CodeType>()->ArrExpr = array_expr; cast(CodeType, type)->ArrExpr = array_expr;
if ( inline_cmt ) if ( inline_cmt )
result->InlineCmt = inline_cmt; result->InlineCmt = inline_cmt;
@ -5187,7 +5187,7 @@ CodeUnion parse_union( bool inplace_def )
} }
if ( member ) if ( member )
body.append( member ); append(body, member );
} }
// <ModuleFlags> union <Attributes> <Name> { <Body> // <ModuleFlags> union <Attributes> <Name> { <Body>

View File

@ -201,7 +201,7 @@ bool append_at(Array<Type>* array, Type item, usize idx)
header = get_header(* array); header = get_header(* array);
} }
Type* target = array->Data + slot; Type* target = &(*array)[slot];
mem_move(target + 1, target, (header->Num - slot) * sizeof(Type)); mem_move(target + 1, target, (header->Num - slot) * sizeof(Type));
header->Num++; header->Num++;
@ -278,7 +278,8 @@ void free(Array<Type>* array) {
GEN_ASSERT(array != nullptr); GEN_ASSERT(array != nullptr);
ArrayHeader* header = get_header(* array); ArrayHeader* header = get_header(* array);
GEN_NS free(header->Allocator, header); GEN_NS free(header->Allocator, header);
array->Data = nullptr; Type** Data = (Type**)array;
*Data = nullptr;
} }
template<class Type> forceinline template<class Type> forceinline
@ -374,7 +375,8 @@ bool set_capacity(Array<Type>* array, usize new_capacity)
GEN_NS free(header->Allocator, header); GEN_NS free(header->Allocator, header);
array->Data = rcast(Type*, new_header + 1); Type** Data = (Type**)array;
* Data = rcast(Type*, new_header + 1);
return true; return true;
} }

View File

@ -358,7 +358,7 @@ CodeBody gen_ast_inlines()
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype(ast), other.ast->duplicate() ); ast = rcast( decltype(ast), GEN_NS duplicate(other.ast) );
rcast( AST*, ast)->Parent = nullptr; rcast( AST*, ast)->Parent = nullptr;
} }
@ -428,29 +428,29 @@ CodeBody gen_ast_inlines()
CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl )); CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl ));
CodeBody impl_code_var = parse_global_body( token_fmt( "typename", StrC name(CodeVar), code_impl_tmpl )); CodeBody impl_code_var = parse_global_body( token_fmt( "typename", StrC name(CodeVar), code_impl_tmpl ));
impl_code_attr. append( parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl ))); append(impl_code_attr, parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl )));
impl_code_cmt. append( parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl ))); append(impl_code_cmt, parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl )));
impl_code_constr. append( parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl ))); append(impl_code_constr, parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl )));
impl_code_define. append( parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl ))); append(impl_code_define, parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl )));
impl_code_destruct.append( parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl ))); append(impl_code_destruct, parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl )));
impl_code_enum. append( parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl ))); append(impl_code_enum, parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl )));
impl_code_exec. append( parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl ))); append(impl_code_exec, parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl )));
impl_code_extern. append( parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl ))); append(impl_code_extern, parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl )));
impl_code_include. append( parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl ))); append(impl_code_include, parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl )));
impl_code_friend. append( parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl ))); append(impl_code_friend, parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl )));
impl_code_fn. append( parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl ))); append(impl_code_fn, parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl )));
impl_code_module. append( parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl ))); append(impl_code_module, parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl )));
impl_code_ns. append( parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl ))); append(impl_code_ns, parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl )));
impl_code_op. append( parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl ))); append(impl_code_op, parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl )));
impl_code_opcast. append( parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl ))); append(impl_code_opcast, parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl )));
impl_code_pragma . append( parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl ))); append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl )));
impl_code_precond. append( parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl ))); append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl )));
impl_code_tmpl. append( parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl ))); append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl )));
impl_code_type. append( parse_global_body( token_fmt( "typename", StrC name(Type), codetype_impl_tmpl ))); append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Type), codetype_impl_tmpl )));
impl_code_typedef. append( parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl ))); append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl )));
impl_code_union. append( parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl ))); append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl )));
impl_code_using. append( parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl ))); append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl )));
impl_code_var. append( parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl ))); append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl )));
char const* cast_tmpl = stringize( char const* cast_tmpl = stringize(
inline AST::operator Code<typename>() inline AST::operator Code<typename>()