Finished AST/Code member inferface usage elimination in base library.

Now the lexer and parser need to be elimination...
This commit is contained in:
Edward R. Gonzalez 2024-12-02 20:20:30 -05:00
parent defe42c15c
commit 69a9abcd59
13 changed files with 277 additions and 492 deletions

View File

@ -157,7 +157,7 @@ int gen_main()
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());
log_fmt("Found constexpr: %S\n", entry.to_string());
fn->Specs.append(ESpecifier::Inline);
}
if ( fn->Name.is_equal(txt("free")) )
@ -189,7 +189,7 @@ int gen_main()
case ECode::Class:
case ECode::Struct:
{
CodeBody body = entry->Body->operator CodeBody();
CodeBody body = cast(CodeBody, entry->Body);
CodeBody new_body = def_body( entry->Body->Type );
for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch
(body_entry->Type) {
@ -204,7 +204,7 @@ int gen_main()
break;
}
entry->Body = rcast(AST*, new_body.ast);
entry->Body = new_body;
memory.append(entry);
}
break;
@ -324,7 +324,7 @@ int gen_main()
case ECode::Struct:
{
CodeBody body = entry->Body->operator CodeBody();
CodeBody body = cast(CodeBody, entry->Body);
CodeBody new_body = def_body( entry->Body->Type );
for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch
(body_entry->Type) {
@ -340,7 +340,7 @@ int gen_main()
new_body.append(body_entry);
break;
}
entry->Body = rcast(AST*, new_body.ast);
entry->Body = new_body;
strings.append(entry);
}
break;

View File

@ -7,7 +7,7 @@ global Code Code_Global;
global Code Code_Invalid;
// This serializes all the data-members in a "debug" format, where each member is printed with its associated value.
char const* debug_str(AST* self)
char const* debug_str(Code self)
{
GEN_ASSERT(self != nullptr);
String result_stack = string_make_reserve( GlobalAllocator, kilobytes(1) );
@ -360,26 +360,26 @@ char const* debug_str(AST* self)
return * result;
}
AST* duplicate(AST* self)
Code duplicate(Code self)
{
using namespace ECode;
AST* result = make_code().ast;
Code result = make_code();
mem_copy( result, self, sizeof( AST ) );
mem_copy( result.ast, self.ast, sizeof( AST ) );
result->Parent = nullptr;
result->Parent = { nullptr };
return result;
}
String to_string(AST* self)
String to_string(Code self)
{
String result = string_make( GlobalAllocator, "" );
GEN_NS to_string( self, & result );
return result;
}
void to_string( AST* self, String* result )
void to_string( Code self, String* result )
{
GEN_ASSERT(self != nullptr);
local_persist thread_local
@ -593,7 +593,7 @@ void to_string( AST* self, String* result )
}
}
bool is_equal( AST* self, AST* other )
bool is_equal( Code self, Code other )
{
/*
AST values are either some u32 value, a cached string, or a pointer to another AST.
@ -910,8 +910,8 @@ bool is_equal( AST* self, AST* other )
{
if ( self->NumEntries > 1 )
{
AST* curr = self;
AST* curr_other = other;
Code curr = self;
Code curr_other = other;
while ( curr != nullptr )
{
if ( curr )
@ -1104,8 +1104,8 @@ bool is_equal( AST* self, AST* other )
check_member_ast( Front );
check_member_ast( Back );
AST* curr = self->Front;
AST* curr_other = other->Front;
Code curr = self->Front;
Code curr_other = other->Front;
while ( curr != nullptr )
{
if ( curr_other == nullptr )
@ -1153,7 +1153,7 @@ bool is_equal( AST* self, AST* other )
return true;
}
bool validate_body(AST* self)
bool validate_body(Code self)
{
using namespace ECode;

View File

@ -161,13 +161,21 @@ namespace parser
template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast( Type*, & self ); }
#endif
char const* debug_str (Code code);
Code duplicate (Code code);
bool is_equal (Code code, Code other);
bool is_body (Code code);
bool is_valid (Code code);
void set_global(Code code);
String to_string (Code code);
#pragma region Code Interface
void append (Code code, Code other );
char const* debug_str (Code code);
Code duplicate (Code code);
Code* entry (Code code, u32 idx );
bool has_entries (Code code);
bool is_body (Code code);
bool is_equal (Code code, Code other);
bool is_valid (Code code);
void set_global (Code code);
String to_string (Code self );
void to_string (Code self, String* result );
char const* type_str (Code self );
bool validate_body(Code self );
#pragma endregion Code Interface
#if ! GEN_COMPILER_C
/*
@ -188,7 +196,6 @@ struct Code
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; } \
@ -196,7 +203,13 @@ struct Code
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( Code );
String to_string() { return GEN_NS to_string(* this); }
void append(Code other) { return GEN_NS append(* this, other); }
Code* entry(u32 idx) { return GEN_NS entry(* this, idx); }
bool has_entries() { return GEN_NS has_entries(* this); }
String to_string() { return GEN_NS to_string(* this); }
void to_string(String& result) { return GEN_NS to_string(* this, & result); }
char const* type_str() { return GEN_NS type_str(* this); }
bool validate_body() { return GEN_NS validate_body(*this); }
#endif
Using_CodeOps( Code );
@ -216,6 +229,11 @@ struct Code
return *this;
}
bool operator==(std::nullptr_t) const { return ast == nullptr; }
bool operator!=(std::nullptr_t) const { return ast != nullptr; }
friend bool operator==(std::nullptr_t, const Code code) { return code.ast == nullptr; }
friend bool operator!=(std::nullptr_t, const Code code) { return code.ast != nullptr; }
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
# define operator explicit operator
#endif
@ -269,27 +287,6 @@ static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
// Desired width of the AST data structure.
constexpr int const AST_POD_Size = 128;
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 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); }
bool is_body ( AST& self ) { return is_body(& self); }
bool is_equal ( AST& self, AST& other ) { return is_equal(& self, & other); }
char const* debug_str( AST& self ) { return debug_str( & self ); }
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 =
(
@ -309,102 +306,53 @@ int AST_ArrSpecs_Cap =
*/
struct AST
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
# pragma region Member Functions
void append ( AST* other ) { GEN_NS append(this, other); }
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() { 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() { return GEN_NS validate_body(this); }
String to_string() { return GEN_NS to_string(this); }
void to_string( String& result ) { return GEN_NS to_string(this, & result); }
# pragma endregion Member Functions
#endif
operator Code();
operator CodeBody();
operator CodeAttributes();
// operator CodeBaseClass();
operator CodeComment();
operator CodeConstructor();
operator CodeDestructor();
operator CodeClass();
operator CodeDefine();
operator CodeEnum();
operator CodeExec();
operator CodeExtern();
operator CodeInclude();
operator CodeFriend();
operator CodeFn();
operator CodeModule();
operator CodeNS();
operator CodeOperator();
operator CodeOpCast();
operator CodeParam();
operator CodePragma();
operator CodePreprocessCond();
operator CodeSpecifiers();
operator CodeStruct();
operator CodeTemplate();
operator CodeType();
operator CodeTypedef();
operator CodeUnion();
operator CodeUsing();
operator CodeVar();
union {
struct
{
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
AST* Specs; // Destructor, Function, Operator, Typename, Variable
Code InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
Code Specs; // Destructor, Function, Operator, Typename, Variable
union {
AST* InitializerList; // Constructor
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
AST* ReturnType; // Function, Operator, Typename
AST* UnderlyingType; // Enum, Typedef
AST* ValueType; // Parameter, Variable
Code InitializerList; // Constructor
Code ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
Code ReturnType; // Function, Operator, Typename
Code UnderlyingType; // Enum, Typedef
Code ValueType; // Parameter, Variable
};
union {
AST* Macro; // Parameter
AST* BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename
Code Macro; // Parameter
Code BitfieldSize; // Variable (Class/Struct Data Member)
Code Params; // Constructor, Function, Operator, Template, Typename
};
union {
AST* ArrExpr; // Typename
AST* Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template
AST* Value; // Parameter, Variable
Code ArrExpr; // Typename
Code Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union
Code Declaration; // Friend, Template
Code Value; // Parameter, Variable
};
union {
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
AST* PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
Code NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
Code SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
};
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
};
};
union {
AST* Prev;
AST* Front;
AST* Last;
Code Prev;
Code Front;
Code Last;
};
union {
AST* Next;
AST* Back;
Code Next;
Code Back;
};
parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
AST* Parent;
Code Parent;
StringCached Name;
CodeT Type;
// CodeFlag CodeFlags;
@ -419,11 +367,16 @@ struct AST
b32 EnumUnderlyingMacro; // Used by enums incase the user wants to wrap underlying type specification in a macro
};
};
// 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) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
#if ! GEN_COMPILER_C
// Uses an implicitly overloaded cast from the AST to the desired code type.
// Necessary if the user wants GEN_ENFORCE_STRONG_CODE_TYPES
struct InvalidCode_ImplictCaster;
#define InvalidCode (InvalidCode_ImplictCaster{})
#else
#define InvalidCode Code_Invalid
#endif
// Used when the its desired when omission is allowed in a definition.
#define NoCode { nullptr }
#define InvalidCode (* Code_Invalid.ast) // Uses an implicitly overloaded cast from the AST to the desired code type.
#define NullCode { nullptr }

View File

@ -3,16 +3,6 @@
#include "ast.cpp"
#endif
String to_string(Code self)
{
if ( self.ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return to_string( self.ast );
}
String to_string(CodeAttributes attributes) {
return GEN_NS duplicate( attributes->Content, GlobalAllocator );
}
@ -100,7 +90,7 @@ String to_string(CodeConstructor self)
void to_string_def(CodeConstructor self, String* result )
{
AST* ClassStructParent = self->Parent->Parent;
Code ClassStructParent = self->Parent->Parent;
if (ClassStructParent) {
append( result, ClassStructParent->Name );
}
@ -124,7 +114,7 @@ void to_string_def(CodeConstructor self, String* result )
void to_string_fwd(CodeConstructor self, String* result )
{
AST* ClassStructParent = self->Parent->Parent;
Code ClassStructParent = self->Parent->Parent;
if (ClassStructParent) {
append( result, ClassStructParent->Name );
}
@ -1117,7 +1107,7 @@ void to_string(CodeTypedef self, String* result )
{
append_fmt( result, "[ %S ];", GEN_NS to_string(self->UnderlyingType->ArrExpr) );
AST* next_arr_expr = self->UnderlyingType->ArrExpr->Next;
Code next_arr_expr = self->UnderlyingType->ArrExpr->Next;
while ( next_arr_expr )
{
append_fmt( result, "[ %S ];", GEN_NS to_string(next_arr_expr) );
@ -1256,7 +1246,7 @@ void to_string(CodeUsing self, String* result )
{
append_fmt( result, "[ %S ]", GEN_NS to_string(self->UnderlyingType->ArrExpr) );
AST* next_arr_expr = self->UnderlyingType->ArrExpr->Next;
Code next_arr_expr = self->UnderlyingType->ArrExpr->Next;
while ( next_arr_expr )
{
append_fmt( result, "[ %S ]", GEN_NS to_string(next_arr_expr) );
@ -1305,7 +1295,7 @@ void to_string(CodeVar self, String* result )
{
append_fmt( result, "[ %S ]", GEN_NS to_string(self->ValueType->ArrExpr) );
AST* next_arr_expr = self->ValueType->ArrExpr->Next;
Code next_arr_expr = self->ValueType->ArrExpr->Next;
while ( next_arr_expr )
{
append_fmt( result, "[ %S ]", GEN_NS to_string(next_arr_expr) );
@ -1348,7 +1338,7 @@ void to_string(CodeVar self, String* result )
{
append_fmt( result, "[ %S ]", GEN_NS to_string(self->ValueType->ArrExpr) );
AST* next_arr_expr = self->ValueType->ArrExpr->Next;
Code next_arr_expr = self->ValueType->ArrExpr->Next;
while ( next_arr_expr )
{
append_fmt( result, "[ %S ]", GEN_NS to_string(next_arr_expr) );
@ -1388,7 +1378,7 @@ void to_string(CodeVar self, String* result )
{
append_fmt( result, "%S %S[ %S ]", GEN_NS to_string(self->ValueType), self->Name, GEN_NS to_string(self->ValueType->ArrExpr) );
AST* next_arr_expr = self->ValueType->ArrExpr->Next;
Code next_arr_expr = self->ValueType->ArrExpr->Next;
while ( next_arr_expr )
{
append_fmt( result, "[ %S ]", GEN_NS to_string(next_arr_expr) );

View File

@ -3,6 +3,7 @@
#include "ast.hpp"
#endif
#pragma region Code Type Interface
void append ( CodeBody body, Code other );
void append ( CodeBody body, CodeBody other );
String to_string ( CodeBody body );
@ -117,6 +118,7 @@ void to_string_ns(CodeUsing op_cast, String* result );
String to_string(CodeVar self);
void to_string(CodeVar self, String* result);
#pragma endregion Code Type Interface
#pragma region Code Types
// These structs are not used at all by the C vairant.
@ -132,7 +134,7 @@ struct CodeBody
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 )); }
bool has_entries() { return GEN_NS has_entries(* this); }
String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ) { return GEN_NS to_string(* this, & result ); }
@ -1011,6 +1013,40 @@ void to_string_export( CodeBody body, String& result ) { return to_string_export
#undef Verify_POD
struct InvalidCode_ImplictCaster
{
// operator CodeBaseClass() const;
operator Code () const { return Code_Invalid; }
operator CodeBody () const { return cast(CodeBody, Code_Invalid); }
operator CodeAttributes () const { return cast(CodeAttributes, Code_Invalid); }
operator CodeComment () const { return cast(CodeComment, Code_Invalid); }
operator CodeClass () const { return cast(CodeClass, Code_Invalid); }
operator CodeConstructor () const { return cast(CodeConstructor, Code_Invalid); }
operator CodeDefine () const { return cast(CodeDefine, Code_Invalid); }
operator CodeDestructor () const { return cast(CodeDestructor, Code_Invalid); }
operator CodeExec () const { return cast(CodeExec, Code_Invalid); }
operator CodeEnum () const { return cast(CodeEnum, Code_Invalid); }
operator CodeExtern () const { return cast(CodeExtern, Code_Invalid); }
operator CodeInclude () const { return cast(CodeInclude, Code_Invalid); }
operator CodeFriend () const { return cast(CodeFriend, Code_Invalid); }
operator CodeFn () const { return cast(CodeFn, Code_Invalid); }
operator CodeModule () const { return cast(CodeModule, Code_Invalid); }
operator CodeNS () const { return cast(CodeNS, Code_Invalid); }
operator CodeOperator () const { return cast(CodeOperator, Code_Invalid); }
operator CodeOpCast () const { return cast(CodeOpCast, Code_Invalid); }
operator CodeParam () const { return cast(CodeParam, Code_Invalid); }
operator CodePragma () const { return cast(CodePragma, Code_Invalid); }
operator CodePreprocessCond() const { return cast(CodePreprocessCond, Code_Invalid); }
operator CodeSpecifiers () const { return cast(CodeSpecifiers, Code_Invalid); }
operator CodeStruct () const { return cast(CodeStruct, Code_Invalid); }
operator CodeTemplate () const { return cast(CodeTemplate, Code_Invalid); }
operator CodeType () const { return cast(CodeType, Code_Invalid); }
operator CodeTypedef () const { return cast(CodeTypedef, Code_Invalid); }
operator CodeUnion () const { return cast(CodeUnion, Code_Invalid); }
operator CodeUsing () const { return cast(CodeUsing, Code_Invalid); }
operator CodeVar () const { return cast(CodeVar, Code_Invalid); }
};
#endif //if ! GEN_COMPILER_C
#pragma endregion Code Types

View File

@ -11,8 +11,8 @@ inline Code& Code::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -27,8 +27,8 @@ inline CodeBody& CodeBody::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -43,8 +43,8 @@ inline CodeAttributes& CodeAttributes::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -74,8 +74,8 @@ inline CodeComment& CodeComment::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -105,8 +105,8 @@ inline CodeConstructor& CodeConstructor::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -136,8 +136,8 @@ inline CodeClass& CodeClass::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -152,8 +152,8 @@ inline CodeDefine& CodeDefine::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -183,8 +183,8 @@ inline CodeDestructor& CodeDestructor::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -214,8 +214,8 @@ inline CodeEnum& CodeEnum::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -245,8 +245,8 @@ inline CodeExec& CodeExec::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -276,8 +276,8 @@ inline CodeExtern& CodeExtern::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -307,8 +307,8 @@ inline CodeFriend& CodeFriend::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -338,8 +338,8 @@ inline CodeFn& CodeFn::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -369,8 +369,8 @@ inline CodeInclude& CodeInclude::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -400,8 +400,8 @@ inline CodeModule& CodeModule::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -431,8 +431,8 @@ inline CodeNS& CodeNS::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -462,8 +462,8 @@ inline CodeOperator& CodeOperator::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -493,8 +493,8 @@ inline CodeOpCast& CodeOpCast::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -524,8 +524,8 @@ inline CodeParam& CodeParam::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -540,8 +540,8 @@ inline CodePragma& CodePragma::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -571,8 +571,8 @@ inline CodePreprocessCond& CodePreprocessCond::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -602,8 +602,8 @@ inline CodeSpecifiers& CodeSpecifiers::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -618,8 +618,8 @@ inline CodeStruct& CodeStruct::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -634,8 +634,8 @@ inline CodeTemplate& CodeTemplate::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -665,8 +665,8 @@ inline CodeType& CodeType::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -696,8 +696,8 @@ inline CodeTypedef& CodeTypedef::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -727,8 +727,8 @@ inline CodeUnion& CodeUnion::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -758,8 +758,8 @@ inline CodeUsing& CodeUsing::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -789,8 +789,8 @@ inline CodeVar& CodeVar::operator=( Code other )
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype( ast ), GEN_NS duplicate( other.ast ) );
rcast( AST*, ast )->Parent = nullptr;
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
ast->Parent = { nullptr };
}
ast = rcast( decltype( ast ), other.ast );
return *this;
@ -820,281 +820,141 @@ inline AST_Var* CodeVar::operator->()
#pragma region generated AST/Code cast implementation
inline AST::operator CodeBody()
{
return { rcast( AST_Body*, this ) };
}
inline Code::operator CodeBody() const
{
return { (AST_Body*)ast };
}
inline AST::operator CodeAttributes()
{
return { rcast( AST_Attributes*, this ) };
}
inline Code::operator CodeAttributes() const
{
return { (AST_Attributes*)ast };
}
inline AST::operator CodeComment()
{
return { rcast( AST_Comment*, this ) };
}
inline Code::operator CodeComment() const
{
return { (AST_Comment*)ast };
}
inline AST::operator CodeConstructor()
{
return { rcast( AST_Constructor*, this ) };
}
inline Code::operator CodeConstructor() const
{
return { (AST_Constructor*)ast };
}
inline AST::operator CodeClass()
{
return { rcast( AST_Class*, this ) };
}
inline Code::operator CodeClass() const
{
return { (AST_Class*)ast };
}
inline AST::operator CodeDefine()
{
return { rcast( AST_Define*, this ) };
}
inline Code::operator CodeDefine() const
{
return { (AST_Define*)ast };
}
inline AST::operator CodeDestructor()
{
return { rcast( AST_Destructor*, this ) };
}
inline Code::operator CodeDestructor() const
{
return { (AST_Destructor*)ast };
}
inline AST::operator CodeEnum()
{
return { rcast( AST_Enum*, this ) };
}
inline Code::operator CodeEnum() const
{
return { (AST_Enum*)ast };
}
inline AST::operator CodeExec()
{
return { rcast( AST_Exec*, this ) };
}
inline Code::operator CodeExec() const
{
return { (AST_Exec*)ast };
}
inline AST::operator CodeExtern()
{
return { rcast( AST_Extern*, this ) };
}
inline Code::operator CodeExtern() const
{
return { (AST_Extern*)ast };
}
inline AST::operator CodeFriend()
{
return { rcast( AST_Friend*, this ) };
}
inline Code::operator CodeFriend() const
{
return { (AST_Friend*)ast };
}
inline AST::operator CodeFn()
{
return { rcast( AST_Fn*, this ) };
}
inline Code::operator CodeFn() const
{
return { (AST_Fn*)ast };
}
inline AST::operator CodeInclude()
{
return { rcast( AST_Include*, this ) };
}
inline Code::operator CodeInclude() const
{
return { (AST_Include*)ast };
}
inline AST::operator CodeModule()
{
return { rcast( AST_Module*, this ) };
}
inline Code::operator CodeModule() const
{
return { (AST_Module*)ast };
}
inline AST::operator CodeNS()
{
return { rcast( AST_NS*, this ) };
}
inline Code::operator CodeNS() const
{
return { (AST_NS*)ast };
}
inline AST::operator CodeOperator()
{
return { rcast( AST_Operator*, this ) };
}
inline Code::operator CodeOperator() const
{
return { (AST_Operator*)ast };
}
inline AST::operator CodeOpCast()
{
return { rcast( AST_OpCast*, this ) };
}
inline Code::operator CodeOpCast() const
{
return { (AST_OpCast*)ast };
}
inline AST::operator CodeParam()
{
return { rcast( AST_Param*, this ) };
}
inline Code::operator CodeParam() const
{
return { (AST_Param*)ast };
}
inline AST::operator CodePragma()
{
return { rcast( AST_Pragma*, this ) };
}
inline Code::operator CodePragma() const
{
return { (AST_Pragma*)ast };
}
inline AST::operator CodePreprocessCond()
{
return { rcast( AST_PreprocessCond*, this ) };
}
inline Code::operator CodePreprocessCond() const
{
return { (AST_PreprocessCond*)ast };
}
inline AST::operator CodeSpecifiers()
{
return { rcast( AST_Specifiers*, this ) };
}
inline Code::operator CodeSpecifiers() const
{
return { (AST_Specifiers*)ast };
}
inline AST::operator CodeStruct()
{
return { rcast( AST_Struct*, this ) };
}
inline Code::operator CodeStruct() const
{
return { (AST_Struct*)ast };
}
inline AST::operator CodeTemplate()
{
return { rcast( AST_Template*, this ) };
}
inline Code::operator CodeTemplate() const
{
return { (AST_Template*)ast };
}
inline AST::operator CodeType()
{
return { rcast( AST_Type*, this ) };
}
inline Code::operator CodeType() const
{
return { (AST_Type*)ast };
}
inline AST::operator CodeTypedef()
{
return { rcast( AST_Typedef*, this ) };
}
inline Code::operator CodeTypedef() const
{
return { (AST_Typedef*)ast };
}
inline AST::operator CodeUnion()
{
return { rcast( AST_Union*, this ) };
}
inline Code::operator CodeUnion() const
{
return { (AST_Union*)ast };
}
inline AST::operator CodeUsing()
{
return { rcast( AST_Using*, this ) };
}
inline Code::operator CodeUsing() const
{
return { (AST_Using*)ast };
}
inline AST::operator CodeVar()
{
return { rcast( AST_Var*, this ) };
}
inline Code::operator CodeVar() const
{
return { (AST_Var*)ast };

View File

@ -136,7 +136,7 @@ extern CodeType t_typename;
#ifndef token_fmt
# define gen_main main
# define __ NoCode
# define __ NullCode
// Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL.

View File

@ -3,11 +3,12 @@
#include "interface.hpp"
#endif
#pragma region Code
inline
void append( AST* self, AST* other )
void append( Code self, Code other )
{
GEN_ASSERT(self != nullptr);
GEN_ASSERT(other != nullptr);
GEN_ASSERT(self.ast != nullptr);
GEN_ASSERT(other.ast != nullptr);
if ( other->Parent )
other = duplicate(other);
@ -23,40 +24,15 @@ void append( AST* self, AST* other )
return;
}
AST*
Code
Current = self->Back;
Current->Next = other;
other->Prev = Current;
self->Back = other;
self->NumEntries++;
}
inline
Code* entry( AST* self, u32 idx )
{
GEN_ASSERT(self != nullptr);
AST** current = & self->Front;
while ( idx >= 0 && current != nullptr )
{
if ( idx == 0 )
return rcast( Code*, current);
current = & ( * current )->Next;
idx--;
}
return rcast( Code*, current);
}
inline
bool has_entries(AST* self)
{
GEN_ASSERT(self != nullptr);
return self->NumEntries > 0;
}
inline
bool is_body(AST* self)
bool is_body(Code self)
{
GEN_ASSERT(self != nullptr);
switch (self->Type)
@ -74,59 +50,21 @@ bool is_body(AST* self)
}
return false;
}
inline
char const* type_str(AST* self)
Code* entry( Code self, u32 idx )
{
GEN_ASSERT(self != nullptr);
return ECode::to_str( self->Type );
}
inline
AST::operator Code()
{
return { this };
}
#pragma region Code
inline
char const* debug_str( Code code )
{
if ( code.ast == nullptr )
return "Code::debug_str: AST is null!";
return debug_str( code.ast );
}
inline
Code duplicate( Code code )
{
if ( code.ast == nullptr )
GEN_ASSERT(self.ast != nullptr);
Code* current = & self->Front;
while ( idx >= 0 && current != nullptr )
{
log_failure("Code::duplicate: Cannot duplicate code, AST is null!");
return Code_Invalid;
if ( idx == 0 )
return rcast( Code*, current);
current = & ( * current )->Next;
idx--;
}
return { duplicate(code.ast) };
}
inline
bool is_body(Code code)
{
if ( code.ast == nullptr )
{
return is_body(code.ast);
}
return false;
}
inline
bool is_equal( Code self, Code other )
{
if ( self.ast == nullptr || other.ast == nullptr )
{
// Just check if they're both null.
// log_failure( "Code::is_equal: Cannot compare code, AST is null!" );
return self.ast == nullptr && other.ast == nullptr;
}
return is_equal( self.ast, other.ast );
return rcast( Code*, current);
}
inline
bool is_valid(Code self)
@ -134,6 +72,12 @@ bool is_valid(Code self)
return self.ast != nullptr && self.ast->Type != CodeT::Invalid;
}
inline
bool has_entries(AST* self)
{
GEN_ASSERT(self != nullptr);
return self->NumEntries > 0;
}
inline
void set_global(Code self)
{
if ( self.ast == nullptr )
@ -142,15 +86,21 @@ void set_global(Code self)
return;
}
self->Parent = Code_Global.ast;
self->Parent.ast = Code_Global.ast;
}
inline
Code& Code::operator ++()
{
if ( ast )
ast = ast->Next;
ast = ast->Next.ast;
return *this;
return * this;
}
inline
char const* type_str(Code self)
{
GEN_ASSERT(self != nullptr);
return ECode::to_str( self->Type );
}
#pragma endregion Code
@ -165,7 +115,7 @@ void append( CodeBody self, Code other )
return;
}
append( rcast(AST*, self.ast), other.ast );
append( cast(Code, self), other );
}
inline
void append( CodeBody self, CodeBody body )
@ -216,8 +166,8 @@ inline
void append( CodeParam appendee, CodeParam other )
{
GEN_ASSERT(appendee.ast != nullptr);
AST* self = cast(Code, appendee).ast;
AST* entry = (AST*) other.ast;
Code self = cast(Code, appendee);
Code entry = cast(Code, other);
if ( entry->Parent )
entry = GEN_NS duplicate( entry );
@ -246,7 +196,7 @@ CodeParam get(CodeParam self, s32 idx )
if ( ! ++ param )
return { nullptr };
param = { (AST_Param*) cast(Code, param)->Next };
param = cast(Code, param)->Next;
}
while ( --idx );

View File

@ -43,21 +43,21 @@ CodeAttributes def_attributes( StrC content );
CodeComment def_comment ( StrC content );
CodeClass def_class( StrC name
, Code body = NoCode
, CodeType parent = NoCode, AccessSpec access = AccessSpec_Default
, CodeAttributes attributes = NoCode
, Code body = NullCode
, CodeType parent = NullCode, AccessSpec access = AccessSpec_Default
, CodeAttributes attributes = NullCode
, ModuleFlag mflags = ModuleFlag_None
, CodeType* interfaces = nullptr, s32 num_interfaces = 0 );
CodeConstructor def_constructor( CodeParam params = NoCode, Code initializer_list = NoCode, Code body = NoCode );
CodeConstructor def_constructor( CodeParam params = NullCode, Code initializer_list = NullCode, Code body = NullCode );
CodeDefine def_define( StrC name, StrC content );
CodeDestructor def_destructor( Code body = NoCode, CodeSpecifiers specifiers = NoCode );
CodeDestructor def_destructor( Code body = NullCode, CodeSpecifiers specifiers = NullCode );
CodeEnum def_enum( StrC name
, Code body = NoCode, CodeType type = NoCode
, EnumT specifier = EnumDecl_Regular, CodeAttributes attributes = NoCode
, Code body = NullCode, CodeType type = NullCode
, EnumT specifier = EnumDecl_Regular, CodeAttributes attributes = NullCode
, ModuleFlag mflags = ModuleFlag_None );
CodeExec def_execution ( StrC content );
@ -65,8 +65,8 @@ CodeExtern def_extern_link( StrC name, Code body );
CodeFriend def_friend ( Code symbol );
CodeFn def_function( StrC name
, CodeParam params = NoCode, CodeType ret_type = NoCode, Code body = NoCode
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
, CodeParam params = NullCode, CodeType ret_type = NullCode, Code body = NullCode
, CodeSpecifiers specifiers = NullCode, CodeAttributes attributes = NullCode
, ModuleFlag mflags = ModuleFlag_None );
CodeInclude def_include ( StrC content, bool foreign = false );
@ -74,13 +74,13 @@ CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFla
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag_None );
CodeOperator def_operator( OperatorT op, StrC nspace
, CodeParam params = NoCode, CodeType ret_type = NoCode, Code body = NoCode
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
, CodeParam params = NullCode, CodeType ret_type = NullCode, Code body = NullCode
, CodeSpecifiers specifiers = NullCode, CodeAttributes attributes = NullCode
, ModuleFlag mflags = ModuleFlag_None );
CodeOpCast def_operator_cast( CodeType type, Code body = NoCode, CodeSpecifiers specs = NoCode );
CodeOpCast def_operator_cast( CodeType type, Code body = NullCode, CodeSpecifiers specs = NullCode );
CodeParam def_param ( CodeType type, StrC name, Code value = NoCode );
CodeParam def_param ( CodeType type, StrC name, Code value = NullCode );
CodePragma def_pragma( StrC directive );
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
@ -88,27 +88,27 @@ CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
CodeSpecifiers def_specifier( SpecifierT specifier );
CodeStruct def_struct( StrC name
, Code body = NoCode
, CodeType parent = NoCode, AccessSpec access = AccessSpec_Default
, CodeAttributes attributes = NoCode
, Code body = NullCode
, CodeType parent = NullCode, AccessSpec access = AccessSpec_Default
, CodeAttributes attributes = NullCode
, ModuleFlag mflags = ModuleFlag_None
, CodeType* interfaces = nullptr, s32 num_interfaces = 0 );
CodeTemplate def_template( CodeParam params, Code definition, ModuleFlag mflags = ModuleFlag_None );
CodeType def_type ( StrC name, Code arrayexpr = NoCode, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode );
CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes = NoCode, ModuleFlag mflags = ModuleFlag_None );
CodeType def_type ( StrC name, Code arrayexpr = NullCode, CodeSpecifiers specifiers = NullCode, CodeAttributes attributes = NullCode );
CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes = NullCode, ModuleFlag mflags = ModuleFlag_None );
CodeUnion def_union( StrC name, Code body, CodeAttributes attributes = NoCode, ModuleFlag mflags = ModuleFlag_None );
CodeUnion def_union( StrC name, Code body, CodeAttributes attributes = NullCode, ModuleFlag mflags = ModuleFlag_None );
CodeUsing def_using( StrC name, CodeType type = NoCode
, CodeAttributes attributess = NoCode
CodeUsing def_using( StrC name, CodeType type = NullCode
, CodeAttributes attributess = NullCode
, ModuleFlag mflags = ModuleFlag_None );
CodeUsing def_using_namespace( StrC name );
CodeVar def_variable( CodeType type, StrC name, Code value = NoCode
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
CodeVar def_variable( CodeType type, StrC name, Code value = NullCode
, CodeSpecifiers specifiers = NullCode, CodeAttributes attributes = NullCode
, ModuleFlag mflags = ModuleFlag_None );
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.

View File

@ -214,7 +214,7 @@ internal CodeVar parse_variable_declaration_list ();
internal CodeClass parse_class ( bool inplace_def = false );
internal CodeConstructor parse_constructor ( CodeSpecifiers specifiers );
internal CodeDestructor parse_destructor ( CodeSpecifiers specifiers = NoCode );
internal CodeDestructor parse_destructor ( CodeSpecifiers specifiers = NullCode );
internal CodeEnum parse_enum ( bool inplace_def = false );
internal CodeBody parse_export_body ();
internal CodeBody parse_extern_link_body();
@ -222,7 +222,7 @@ internal CodeExtern parse_extern_link ();
internal CodeFriend parse_friend ();
internal CodeFn parse_function ();
internal CodeNS parse_namespace ();
internal CodeOpCast parse_operator_cast ( CodeSpecifiers specifiers = NoCode );
internal CodeOpCast parse_operator_cast ( CodeSpecifiers specifiers = NullCode );
internal CodeStruct parse_struct ( bool inplace_def = false );
internal CodeVar parse_variable ();
internal CodeTemplate parse_template ();
@ -550,7 +550,7 @@ Code parse_array_decl()
Code adjacent_arr_expr = parse_array_decl();
// [ <Content> ][ <Content> ]...
array_expr->Next = adjacent_arr_expr.ast;
array_expr->Next.ast = adjacent_arr_expr.ast;
}
Context.pop();
@ -757,7 +757,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
}
// <ModuleFlags> <class/struct> <Attributes> <Name> : <Access Specifier> <Name>, ... { <Body> }
CodeComment inline_cmt = NoCode;
CodeComment inline_cmt = NullCode;
if ( ! inplace_def )
{
Token stmt_end = currtok;
@ -1445,8 +1445,8 @@ CodeFn parse_function_after_name(
}
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers>
CodeBody body = NoCode;
CodeComment inline_cmt = NoCode;
CodeBody body = NullCode;
CodeComment inline_cmt = NullCode;
if ( check( TokType::BraceCurly_Open ) )
{
body = parse_function_body();
@ -2450,7 +2450,7 @@ CodeOperator parse_operator_after_ret_type(
// Parse Body
CodeBody body = { nullptr };
CodeComment inline_cmt = NoCode;
CodeComment inline_cmt = NullCode;
if ( check( TokType::BraceCurly_Open ) )
{
body = parse_function_body();
@ -3181,9 +3181,9 @@ CodeVar parse_variable_after_name(
// <Attributes> <Specifiers> <ValueType> <Name> : <Expression>
}
CodeVar next_var = NoCode;
CodeVar next_var = NullCode;
Token stmt_end = NullToken;
CodeComment inline_cmt = NoCode;
CodeComment inline_cmt = NullCode;
if ( type )
{
if ( currtok.Type == TokType::Comma )
@ -3266,14 +3266,14 @@ CodeVar parse_variable_declaration_list()
{
push_scope();
CodeVar result = NoCode;
CodeVar last_var = NoCode;
CodeVar result = NullCode;
CodeVar last_var = NullCode;
while ( check( TokType::Comma ) )
{
eat( TokType::Comma );
// ,
CodeSpecifiers specifiers = NoCode;
CodeSpecifiers specifiers = NullCode;
while ( left && currtok.is_specifier() )
{
@ -3320,7 +3320,7 @@ CodeVar parse_variable_declaration_list()
eat( TokType::Identifier );
// , <Specifiers> <Name>
CodeVar var = parse_variable_after_name( ModuleFlag_None, NoCode, specifiers, NoCode, name );
CodeVar var = parse_variable_after_name( ModuleFlag_None, NullCode, specifiers, NullCode, name );
// , <Specifiers> <Name> ...
if ( ! result )
@ -3358,9 +3358,9 @@ CodeConstructor parse_constructor( CodeSpecifiers specifiers )
CodeParam params = parse_params();
// <Name> ( <Parameters> )
Code initializer_list = NoCode;
CodeBody body = NoCode;
CodeComment inline_cmt = NoCode;
Code initializer_list = NullCode;
CodeBody body = NullCode;
CodeComment inline_cmt = NullCode;
// TODO(Ed) : Need to support postfix specifiers
@ -3472,7 +3472,7 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
Token identifier = parse_identifier();
CodeBody body = { nullptr };
CodeComment inline_cmt = NoCode;
CodeComment inline_cmt = NullCode;
// <Virtual Specifier> ~<Name>
eat( TokType::Capture_Start );
@ -3750,7 +3750,7 @@ CodeEnum parse_enum( bool inplace_def )
// enum <class> <Attributes> <Name> : <UnderlyingType> { <Body> }
}
CodeComment inline_cmt = NoCode;
CodeComment inline_cmt = NullCode;
if ( ! inplace_def )
{
@ -3881,7 +3881,7 @@ CodeFriend parse_friend()
Context.Scope->Name = name;
// friend <ReturnType> <Name>
function = parse_function_after_name( ModuleFlag_None, NoCode, NoCode, type, name );
function = parse_function_after_name( ModuleFlag_None, NullCode, NullCode, type, name );
// Parameter list
// CodeParam params = parse_params();
@ -3896,7 +3896,7 @@ CodeFriend parse_friend()
// function->Params = params;
}
CodeComment inline_cmt = NoCode;
CodeComment inline_cmt = NullCode;
if ( function && function->Type == ECode::Function_Fwd )
{
Token stmt_end = currtok;
@ -4154,8 +4154,8 @@ CodeOpCast parse_operator_cast( CodeSpecifiers specifiers )
}
// <Specifiers> <Qualifier> :: ... operator <UnderlyingType>() <const>
Code body = NoCode;
CodeComment inline_cmt = NoCode;
Code body = NullCode;
CodeComment inline_cmt = NullCode;
if ( check( TokType::BraceCurly_Open) )
{
@ -4595,11 +4595,11 @@ else if ( currtok.Type == TokType::DeclType )
// <Attributes> <Specifiers> <Identifier> <Specifiers>
// For function type signatures
CodeType return_type = NoCode;
CodeParam params = NoCode;
CodeType return_type = NullCode;
CodeParam params = NullCode;
#ifdef GEN_USE_NEW_TYPENAME_PARSING
CodeParam params_nested = NoCode;
CodeParam params_nested = NullCode;
#endif
bool is_function_typename = false;
@ -5036,7 +5036,7 @@ CodeTypedef parse_typedef()
eat( TokType::Statement_End );
// <ModuleFalgs> typedef <UnderlyingType> <Name>;
CodeComment inline_cmt = NoCode;
CodeComment inline_cmt = NullCode;
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment();
// <ModuleFalgs> typedef <UnderlyingType> <Name> <ArrayExpr>; <InlineCmt>
@ -5061,8 +5061,8 @@ CodeTypedef parse_typedef()
if ( type )
{
result->UnderlyingType = type;
result->UnderlyingType->Parent = rcast(AST*, result.ast);
result->UnderlyingType = type;
result->UnderlyingType->Parent.ast = rcast(AST*, result.ast);
}
// Type needs to be aware of its parent so that it can be serialized properly.
@ -5277,7 +5277,7 @@ CodeUsing parse_using()
eat( TokType::Statement_End );
// <ModuleFlags> using <namespace> <Attributes> <Name> = <UnderlyingType>;
CodeComment inline_cmt = NoCode;
CodeComment inline_cmt = NullCode;
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
{
inline_cmt = parse_comment();

View File

@ -358,12 +358,12 @@ CodeBody gen_ast_inlines()
{
if ( other.ast && other->Parent )
{
ast = rcast( decltype(ast), GEN_NS duplicate(other.ast) );
rcast( AST*, ast)->Parent = nullptr;
ast = rcast( decltype(ast), GEN_NS duplicate(other).ast);
ast->Parent = { nullptr };
}
ast = rcast( decltype(ast), other.ast );
return *this;
ast = rcast( decltype( ast ), other.ast );
return * this;
}
inline
<typename>::operator bool()
@ -448,10 +448,6 @@ CodeBody gen_ast_inlines()
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>()
{
return { rcast( AST_<typename>*, this ) };
}
inline Code::operator Code<typename>() const
{
return { (AST_<typename>*) ast };

View File

@ -253,7 +253,7 @@
// word log_failure, new_name
// word NoCode, new_name
// word NullCode, new_name
// word CodeInvalid, new_name
// ------------ gencpp common

View File

@ -50,7 +50,7 @@ u32 gen_sanity_upfront()
// Enum
{
CodeEnum fwd = def_enum( name(ETestEnum), NoCode, t_u8 );
CodeEnum fwd = def_enum( name(ETestEnum), NullCode, t_u8 );
CodeEnum def;
{
Code body = untyped_str( code(
@ -62,7 +62,7 @@ u32 gen_sanity_upfront()
def = def_enum( name(ETestEnum), body, t_u8 );
}
CodeEnum fwd_enum_class = def_enum( name(ETestEnumClass), NoCode, t_u8, EnumClass );
CodeEnum fwd_enum_class = def_enum( name(ETestEnumClass), NullCode, t_u8, EnumClass );
gen_sanity_file.print(fwd);
gen_sanity_file.print(def);