Compare commits

...

5 Commits

19 changed files with 808 additions and 631 deletions

View File

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

View File

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

View File

@ -136,7 +136,7 @@ int gen_main()
case ECode::Using:
{
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);
memory.append(typedef_ver);
@ -144,7 +144,7 @@ int gen_main()
break;
case ECode::Function_Fwd:
{
CodeFn fn = entry.code_cast<CodeFn>();
CodeFn fn = cast(CodeFn, entry);
if ( fn->Name.is_equal(txt("free")) )
{
fn->Name = get_cached_string(txt("gen_free_ptr"));
@ -154,7 +154,7 @@ int gen_main()
break;
case ECode::Function:
{
CodeFn fn = entry.code_cast<CodeFn>();
CodeFn fn = cast(CodeFn, entry);
s32 constexpr_found = fn->Specs.remove( ESpecifier::Constexpr );
if (constexpr_found > -1) {
log_fmt("Found constexpr: %S\n", entry->to_string());
@ -169,7 +169,7 @@ int gen_main()
break;
case ECode::Template:
{
CodeTemplate tmpl = entry.code_cast<CodeTemplate>();
CodeTemplate tmpl = cast(CodeTemplate, entry);
if ( tmpl->Declaration->Name.contains(txt("swap")))
{
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 found = false;
CodePreprocessCond cond = entry_iter.code_cast<CodePreprocessCond>();
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
if ( cond->Content.contains(cond_sig) )
{
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 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 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) {
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) ) {
// body.append(possible_end_region);
continue_for = false;

View File

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

View File

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

View File

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

View File

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

View File

@ -73,82 +73,92 @@ struct AST_Union;
struct AST_Using;
struct AST_Var;
struct Code;
struct CodeBody;
// These are to offer ease of use and optionally strong type safety for the AST.
struct CodeAttributes;
// 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;
#if GEN_COMPILER_C
#define Define_Code(Type) typedef AST_##Type* Code##Type
#else
#define Define_Code(Type) struct Code##Type
#endif
struct CodeStruct;
struct CodeTemplate;
struct CodeType;
struct CodeTypedef;
struct CodeUnion;
struct CodeUsing;
struct CodeVar;
#if GEN_COMPILER_C
typedef AST* code;
#else
struct Code;
#endif
Define_Code(Body);
// 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
{
struct Token;
}
template< class Type> forceinline Type tmpl_cast( Code* self ) { return * rcast( Type*, self ); }
#if ! GEN_COMPILER_C && 0
template< class Type> forceinline Type tmpl_cast( Code& self ) { return * rcast( Type*, & self ); }
#if ! GEN_COMPILER_C
template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast( Type*, & self ); }
#endif
char const* debug_str (Code code);
@ -159,6 +169,7 @@ bool is_valid (Code code);
void set_global(Code code);
String to_string (Code code);
#if ! GEN_COMPILER_C
/*
AST* wrapper
- Not constantly have to append the '*' as this is written often..
@ -174,26 +185,23 @@ struct Code
bool is_equal( Code other ) { return GEN_NS is_equal(* this, other); } \
bool is_body() { return GEN_NS is_body(* this); } \
bool is_valid() { return GEN_NS is_valid(* this); } \
void set_global() { return GEN_NS set_global(* this); } \
String to_string(); \
void set_global() { return GEN_NS set_global(* this); }
# define Using_CodeOps( Typename ) \
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; } \
operator bool();
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( Code );
String to_string() { return GEN_NS to_string(* this); }
#endif
template< class Type >
forceinline Type code_cast()
{
return * rcast( Type*, this );
}
Using_CodeOps( Code );
AST* operator ->()
{
return ast;
}
AST* operator ->() { return ast; }
Code& operator ++();
// TODO(Ed) : Remove this overload.
@ -242,6 +250,7 @@ struct Code
operator CodeVar() const;
#undef operator
};
#endif
#pragma region Statics
// Used to identify ASTs that should always be duplicated. (Global constant ASTs)
@ -265,11 +274,13 @@ void append ( AST* self, AST* other );
char const* debug_str ( AST* self );
AST* duplicate ( AST* self );
Code* entry ( AST* self, u32 idx );
bool has_entries( AST* self );
bool has_entries ( AST* self );
bool is_body ( AST* self );
bool is_equal ( AST* self, AST* other );
String to_string ( 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
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 ); }
#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.
*/
@ -291,22 +316,15 @@ struct AST
char const* debug_str () { return GEN_NS debug_str(this); }
AST* duplicate () { return GEN_NS duplicate(this); }
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_body() { return GEN_NS is_body(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
#endif
@ -341,20 +359,6 @@ struct AST
operator CodeUsing();
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 {
struct
{
@ -387,7 +391,7 @@ struct AST
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[ArrSpecs_Cap]; // Specifiers
SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
};
};
@ -451,7 +455,7 @@ struct AST_POD
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
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.
// All extra functionality within the AST namespace should just be syntatic sugar.
static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" );

View File

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

View File

@ -3,14 +3,14 @@
#include "ast.cpp"
#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!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
return to_string( self.ast );
}
String CodeAttributes::to_string()
@ -18,15 +18,16 @@ String CodeAttributes::to_string()
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, "" );
switch ( ast->Type )
switch ( body.ast->Type )
{
using namespace ECode;
case Untyped:
case Execution:
GEN_NS append( & result, raw()->Content );
append( & result, rcast(AST*, body.ast)->Content );
break;
case Enum_Body:
@ -37,40 +38,44 @@ String CodeBody::to_string()
case Namespace_Body:
case Struct_Body:
case Union_Body:
to_string( result );
to_string( body, & result );
break;
case Export_Body:
to_string_export( result );
to_string_export( body, & result );
break;
}
return result;
}
void CodeBody::to_string( String& result )
void to_string( CodeBody body, String* result )
{
Code curr = ast->Front;
s32 left = ast->NumEntries;
GEN_ASSERT(body.ast != nullptr);
GEN_ASSERT(result != nullptr);
Code curr = body.ast->Front;
s32 left = body.ast->NumEntries;
while ( left -- )
{
append_fmt( & result, "%S", curr.to_string() );
append_fmt( result, "%S", GEN_NS to_string(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;
s32 left = ast->NumEntries;
Code curr = body;
s32 left = body.ast->NumEntries;
while ( left-- )
{
append_fmt( & result, "%S", curr.to_string() );
append_fmt( result, "%S", to_string(curr) );
++curr;
}
append_fmt( & result, "};\n" );
append_fmt( result, "};\n" );
}
String CodeComment::to_string()
@ -110,12 +115,12 @@ void CodeConstructor::to_string_def( String& result )
append( & result, "()" );
if ( ast->InitializerList )
append_fmt( & result, " : %S", ast->InitializerList.to_string() );
append_fmt( & result, " : %S", GEN_NS to_string(ast->InitializerList) );
if ( ast->InlineCmt )
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 )
@ -134,7 +139,7 @@ void CodeConstructor::to_string_fwd( String& result )
append_fmt( & result, "()");
if (ast->Body)
append_fmt( & result, " = %S", ast->Body.to_string() );
append_fmt( & result, " = %S", GEN_NS to_string(ast->Body) );
if ( ast->InlineCmt )
append_fmt( & result, "; // %S\n", ast->InlineCmt->Content );
@ -142,83 +147,89 @@ void CodeConstructor::to_string_fwd( String& result )
append( & result, ";\n" );
}
String CodeClass::to_string()
String to_string( CodeClass self )
{
String result = string_make( GlobalAllocator, "" );
switch ( ast->Type )
switch ( self->Type )
{
using namespace ECode;
case Class:
to_string_def( result );
to_string_def(self, & result );
break;
case Class_Fwd:
to_string_fwd( result );
to_string_fwd(self, & result );
break;
}
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 ))
append( & result, "export " );
GEN_ASSERT(self.ast != nullptr);
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 )
{
append_fmt( & result, "%S ", ast->Attributes.to_string() );
append_fmt( result, "%S ", ast->Attributes.to_string() );
}
if ( ast->ParentType )
{
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 )
append( & result, "\n" );
append( result, "\n" );
while ( interface )
{
append_fmt( & result, ", %S", interface.to_string() );
interface = interface->Next ? interface->Next->code_cast< CodeType >() : CodeType { nullptr };
append_fmt( result, ", %S", interface.to_string() );
interface = interface->Next ? cast(CodeType, interface->Next) : CodeType { nullptr };
}
}
else if ( ast->Name )
{
append( & result, ast->Name );
append( result, ast->Name );
}
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 ) )
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 ))
append( & result, "export " );
append( result, "export " );
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
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
{
if ( ast->InlineCmt )
append_fmt( & result, "; // %S\n", ast->InlineCmt->Content );
append_fmt( result, "; // %S\n", ast->InlineCmt->Content );
else
append( & result,";\n");
append( result,";\n");
}
}
@ -264,7 +275,7 @@ void CodeDestructor::to_string_def( String& result )
else
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 )
@ -279,7 +290,7 @@ void CodeDestructor::to_string_fwd( String& result )
if ( ast->Specs.has( ESpecifier::Pure ) )
append( & result, " = 0;" );
else if (ast->Body)
append_fmt( & result, " = %S;", ast->Body.to_string() );
append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) );
}
else
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}"
, ast->Name
, ast->UnderlyingType.to_string()
, ast->Body.to_string()
, GEN_NS to_string(ast->Body)
);
else if ( ast->UnderlyingTypeMacro )
append_fmt( & result, "%S : %S\n{\n%S\n}"
, ast->Name
, ast->UnderlyingTypeMacro.to_string()
, ast->Body.to_string()
, GEN_NS to_string(ast->UnderlyingTypeMacro)
, 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 ) )
append( & result, ";\n");
@ -383,16 +394,16 @@ void CodeEnum::to_string_class_def( String& result )
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
{
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
{
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 ) )
@ -428,7 +439,7 @@ String CodeExec::to_string()
void CodeExtern::to_string( String& result )
{
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
append_fmt( & result, "extern \"%S\"\n{}\n", ast->Name );
}
@ -452,7 +463,7 @@ String CodeFriend::to_string()
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 ] != ';' )
{
@ -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 )
@ -589,7 +600,7 @@ void CodeFn::to_string_fwd( String& result )
if ( ast->Specs && ast->Specs.has( ESpecifier::Pure ) >= 0 )
append( & result, " = 0;" );
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 )
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 ))
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()
@ -698,7 +709,7 @@ void CodeOperator::to_string_def( String& result )
}
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;
}
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
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 )
@ -872,11 +883,11 @@ void CodeParam::to_string( String& result )
if ( ast->PostNameMacro )
{
append_fmt( & result, " %S", ast->PostNameMacro.to_string() );
append_fmt( & result, " %S", GEN_NS to_string(ast->PostNameMacro) );
}
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 )
{
@ -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() );
CodeType interface = ast->ParentType->Next->code_cast< CodeType >();
CodeType interface = cast(CodeType, ast->ParentType->Next);
if ( interface )
append( & result, "\n" );
while ( interface )
{
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 )
@ -1030,7 +1041,7 @@ void CodeStruct::to_string_def( String& result )
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 ) )
append( & result, ";\n");
@ -1068,9 +1079,9 @@ void CodeTemplate::to_string( String& result )
append( & result, "export " );
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
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()
@ -1089,18 +1100,18 @@ void CodeTypedef::to_string( String& result )
// Determines if the typedef is a function typename
if ( ast->UnderlyingType->ReturnType )
append( & result, ast->UnderlyingType.to_string() );
append( & result, GEN_NS to_string(ast->UnderlyingType) );
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 )
{
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;
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;
}
}
@ -1189,14 +1200,14 @@ void CodeUnion::to_string( String& result )
{
append_fmt( & result, "%S\n{\n%S\n}"
, ast->Name
, ast->Body.to_string()
, GEN_NS to_string(ast->Body)
);
}
else
{
// Anonymous union
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 )
{
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;
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;
}
}
@ -1283,12 +1294,12 @@ void CodeVar::to_string( String& result )
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;
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;
}
}
@ -1296,9 +1307,9 @@ void CodeVar::to_string( String& result )
if ( ast->Value )
{
if ( ast->VarConstructorInit )
append_fmt( & result, "( %S ", ast->Value.to_string() );
append_fmt( & result, "( %S ", GEN_NS to_string(ast->Value) );
else
append_fmt( & result, " = %S", ast->Value.to_string() );
append_fmt( & result, " = %S", GEN_NS to_string(ast->Value) );
}
// Keep the chain going...
@ -1326,25 +1337,25 @@ void CodeVar::to_string( String& result )
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;
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;
}
}
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->VarConstructorInit )
append_fmt( & result, "( %S ", ast->Value.to_string() );
append_fmt( & result, "( %S ", GEN_NS to_string(ast->Value) );
else
append_fmt( & result, " = %S", ast->Value.to_string() );
append_fmt( & result, " = %S", GEN_NS to_string(ast->Value) );
}
if ( ast->NextVar )
@ -1362,16 +1373,16 @@ void CodeVar::to_string( String& result )
}
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 )
{
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;
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;
}
}
@ -1382,9 +1393,9 @@ void CodeVar::to_string( String& result )
if ( ast->Value )
{
if ( ast->VarConstructorInit )
append_fmt( & result, "( %S ", ast->Value.to_string() );
append_fmt( & result, "( %S ", GEN_NS to_string(ast->Value) );
else
append_fmt( & result, " = %S", ast->Value.to_string() );
append_fmt( & result, " = %S", GEN_NS to_string(ast->Value) );
}
if ( ast->NextVar )

View File

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

View File

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

View File

@ -163,13 +163,35 @@ Code& Code::operator ++()
#pragma endregion Code
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 )
{
// 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,
// 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;
Code_Invalid = make_code();
Code_Invalid.set_global();
set_global(Code_Invalid);
t_empty = (CodeType) make_code();
t_empty->Type = ECode::Typename;
t_empty->Name = get_cached_string( txt("") );
t_empty.set_global();
set_global(t_empty);
access_private = make_code();
access_private->Type = ECode::Access_Private;
access_private->Name = get_cached_string( txt("private:\n") );
access_private.set_global();
set_global(access_private);
access_protected = make_code();
access_protected->Type = ECode::Access_Protected;
access_protected->Name = get_cached_string( txt("protected:\n") );
access_protected.set_global();
set_global(access_protected);
access_public = make_code();
access_public->Type = ECode::Access_Public;
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.set_global();
set_global(attrib_api_export);
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->Type = ECode::Untyped;
module_global_fragment->Name = get_cached_string( txt("module;") );
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->Type = ECode::Untyped;
module_private_fragment->Name = get_cached_string( txt("module : private;") );
module_private_fragment->Content = module_private_fragment->Name;
module_private_fragment.set_global();
set_global(module_private_fragment);
fmt_newline = make_code();
fmt_newline->Type = ECode::NewLine;
fmt_newline.set_global();
set_global(fmt_newline);
pragma_once = (CodePragma) make_code();
pragma_once->Type = ECode::Preprocess_Pragma;
pragma_once->Name = get_cached_string( txt("once") );
pragma_once->Content = pragma_once->Name;
pragma_once.set_global();
set_global(pragma_once);
param_varadic = (CodeType) make_code();
param_varadic->Type = ECode::Parameters;
param_varadic->Name = get_cached_string( txt("...") );
param_varadic->ValueType = t_empty;
param_varadic.set_global();
set_global(param_varadic);
preprocess_else = (CodePreprocessCond) make_code();
preprocess_else->Type = ECode::Preprocess_Else;
preprocess_else.set_global();
set_global(preprocess_else);
preprocess_endif = (CodePreprocessCond) make_code();
preprocess_endif->Type = ECode::Preprocess_EndIf;
preprocess_endif.set_global();
set_global(preprocess_endif);
# define def_constant_code_type( Type_ ) \
t_##Type_ = def_type( name(Type_) ); \

View File

@ -527,7 +527,7 @@ CodeConstructor def_constructor( CodeParam params, Code initializer_list, Code b
break;
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;
}
@ -579,7 +579,7 @@ CodeClass def_class( StrC name
break;
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;
}
@ -605,7 +605,7 @@ CodeClass def_class( StrC name
{
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;
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;
}
@ -715,7 +715,7 @@ CodeEnum def_enum( StrC name
break;
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;
}
@ -772,7 +772,7 @@ CodeExtern def_extern_link( StrC name, Code body )
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;
}
@ -804,7 +804,7 @@ CodeFriend def_friend( Code declaration )
break;
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;
}
@ -866,7 +866,7 @@ CodeFn def_function( StrC name
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;
}
}
@ -944,7 +944,7 @@ CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags )
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;
}
@ -1008,7 +1008,7 @@ CodeOperator def_operator( OperatorT op, StrC nspace
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;
}
}
@ -1057,7 +1057,7 @@ CodeOpCast def_operator_cast( CodeType type, Code body, CodeSpecifiers const_spe
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;
}
@ -1086,13 +1086,13 @@ CodeParam def_param( CodeType type, StrC name, Code value )
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;
}
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;
}
@ -1189,13 +1189,13 @@ CodeStruct def_struct( StrC name
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;
}
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;
}
@ -1256,7 +1256,7 @@ CodeTemplate def_template( CodeParam params, Code declaration, ModuleFlag mflags
break;
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
@ -1275,19 +1275,19 @@ CodeType def_type( StrC name, Code arrayexpr, CodeSpecifiers specifiers, CodeAtt
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;
}
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;
}
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;
}
@ -1329,13 +1329,13 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
case Typename:
break;
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;
}
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;
}
@ -1359,7 +1359,7 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
{
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;
}
@ -1381,7 +1381,7 @@ CodeUnion def_union( StrC name, Code body, CodeAttributes attributes, ModuleFlag
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;
}
@ -1482,7 +1482,7 @@ CodeVar def_variable( CodeType type, StrC name, Code value
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;
}
@ -1558,14 +1558,14 @@ CodeBody def_class_body( s32 num, ... )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
va_end(va);
@ -1595,14 +1595,14 @@ CodeBody def_class_body( s32 num, Code* codes )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
@ -1632,11 +1632,11 @@ CodeBody def_enum_body( s32 num, ... )
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;
}
result.append( entry );
append(result, entry );
}
while ( num--, num > 0 );
va_end(va);
@ -1664,11 +1664,11 @@ CodeBody def_enum_body( s32 num, Code* codes )
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;
}
result.append( entry );
append(result, entry );
}
while ( codes++, num--, num > 0 );
@ -1699,14 +1699,14 @@ CodeBody def_export_body( s32 num, ... )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
va_end(va);
@ -1736,14 +1736,14 @@ CodeBody def_export_body( s32 num, Code* codes )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
@ -1774,14 +1774,14 @@ CodeBody def_extern_link_body( s32 num, ... )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
va_end(va);
@ -1811,14 +1811,14 @@ CodeBody def_extern_link_body( s32 num, Code* codes )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
@ -1851,14 +1851,14 @@ CodeBody def_function_body( s32 num, ... )
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
va_end(va);
@ -1888,13 +1888,13 @@ CodeBody def_function_body( s32 num, Code* codes )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
@ -1925,18 +1925,19 @@ CodeBody def_global_body( s32 num, ... )
switch (entry->Type)
{
case Global_Body:
result.append( entry.code_cast<CodeBody>() ) ;
// result.append( entry.code_cast<CodeBody>() ) ;
append( result, cast(CodeBody, entry) );
continue;
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
va_end(va);
@ -1966,18 +1967,18 @@ CodeBody def_global_body( s32 num, Code* codes )
switch (entry->Type)
{
case Global_Body:
result.append( entry.code_cast<CodeBody>() ) ;
append(result, cast(CodeBody, entry) );
continue;
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
@ -2008,14 +2009,14 @@ CodeBody def_namespace_body( s32 num, ... )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
va_end(va);
@ -2045,13 +2046,13 @@ CodeBody def_namespace_body( s32 num, Code* codes )
switch (entry->Type)
{
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;
default: break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
@ -2140,7 +2141,7 @@ CodeSpecifiers def_specifiers( s32 num, ... )
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);
return InvalidCode;
@ -2172,7 +2173,7 @@ CodeSpecifiers def_specifiers( s32 num, SpecifierT* specs )
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);
return InvalidCode;
@ -2217,14 +2218,14 @@ CodeBody def_struct_body( s32 num, ... )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
va_end(va);
@ -2254,14 +2255,14 @@ CodeBody def_struct_body( s32 num, Code* codes )
switch (entry->Type)
{
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;
default:
break;
}
result.append(entry);
append(result, entry);
}
while (num--, num > 0);
@ -2291,11 +2292,11 @@ CodeBody def_union_body( s32 num, ... )
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;
}
result.append( entry );
append(result, entry );
}
while ( num--, num > 0 );
va_end(va);
@ -2323,11 +2324,11 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
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;
}
result.append( entry );
append(result, entry );
}
while ( codes++, num--, num > 0 );

View File

@ -1115,7 +1115,7 @@ CodeBody parse_class_struct_body( TokType which, Token name )
return InvalidCode;
}
result.append( member );
append(result, member );
}
eat( TokType::BraceCurly_Close );
@ -1503,7 +1503,7 @@ CodeFn parse_function_after_name(
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();
return InvalidCode;
}
@ -1568,7 +1568,7 @@ Code parse_function_body()
if ( len > 0 )
{
result.append( def_execution( { len, start.Text } ) );
append( result, def_execution( { len, start.Text } ) );
}
eat( TokType::BraceCurly_Close );
@ -1878,7 +1878,7 @@ CodeBody parse_global_nspace( CodeT which )
}
// log_fmt("Global Body Member: %s", member->debug_str());
result.append( member );
append(result, member );
}
if ( which != Global_Body )
@ -3743,7 +3743,7 @@ CodeEnum parse_enum( bool inplace_def )
return InvalidCode;
}
body.append( member );
append(body, member );
}
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.
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 )
result->InlineCmt = inline_cmt;
@ -5187,7 +5187,7 @@ CodeUnion parse_union( bool inplace_def )
}
if ( member )
body.append( member );
append(body, member );
}
// <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);
}
Type* target = array->Data + slot;
Type* target = &(*array)[slot];
mem_move(target + 1, target, (header->Num - slot) * sizeof(Type));
header->Num++;
@ -278,7 +278,8 @@ void free(Array<Type>* array) {
GEN_ASSERT(array != nullptr);
ArrayHeader* header = get_header(* array);
GEN_NS free(header->Allocator, header);
array->Data = nullptr;
Type** Data = (Type**)array;
*Data = nullptr;
}
template<class Type> forceinline
@ -374,7 +375,8 @@ bool set_capacity(Array<Type>* array, usize new_capacity)
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;
}

View File

@ -358,7 +358,7 @@ CodeBody gen_ast_inlines()
{
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;
}
@ -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_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 )));
impl_code_cmt. append( 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 )));
impl_code_define. append( 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 )));
impl_code_enum. append( 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 )));
impl_code_extern. append( 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 )));
impl_code_friend. append( 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 )));
impl_code_module. append( 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 )));
impl_code_op. append( 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 )));
impl_code_pragma . append( 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 )));
impl_code_tmpl. append( 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 )));
impl_code_typedef. append( 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 )));
impl_code_using. append( 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_attr, parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl )));
append(impl_code_cmt, parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl )));
append(impl_code_constr, parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl )));
append(impl_code_define, parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl )));
append(impl_code_destruct, parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl )));
append(impl_code_enum, parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl )));
append(impl_code_exec, parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl )));
append(impl_code_extern, parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl )));
append(impl_code_include, parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl )));
append(impl_code_friend, parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl )));
append(impl_code_fn, parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl )));
append(impl_code_module, parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl )));
append(impl_code_ns, parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl )));
append(impl_code_op, parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl )));
append(impl_code_opcast, parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl )));
append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl )));
append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl )));
append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl )));
append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Type), codetype_impl_tmpl )));
append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl )));
append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl )));
append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl )));
append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl )));
char const* cast_tmpl = stringize(
inline AST::operator Code<typename>()