Compare commits

..

No commits in common. "f28ae57f16800225bf0d80ebbfd952d068bfcc37" and "8f47f3b30fdf52ce04edbe9a8b66624b11723f27" have entirely different histories.

21 changed files with 1435 additions and 1249 deletions

View File

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

View File

@ -7,7 +7,7 @@ global Code Code_Global;
global Code Code_Invalid; global Code Code_Invalid;
// This serializes all the data-members in a "debug" format, where each member is printed with its associated value. // This serializes all the data-members in a "debug" format, where each member is printed with its associated value.
char const* debug_str(Code self) char const* debug_str(AST* self)
{ {
GEN_ASSERT(self != nullptr); GEN_ASSERT(self != nullptr);
String result_stack = string_make_reserve( GlobalAllocator, kilobytes(1) ); String result_stack = string_make_reserve( GlobalAllocator, kilobytes(1) );
@ -360,26 +360,26 @@ char const* debug_str(Code self)
return * result; return * result;
} }
Code duplicate(Code self) AST* duplicate(AST* self)
{ {
using namespace ECode; using namespace ECode;
Code result = make_code(); AST* result = make_code().ast;
mem_copy( result.ast, self.ast, sizeof( AST ) ); mem_copy( result, self, sizeof( AST ) );
result->Parent = { nullptr }; result->Parent = nullptr;
return result; return result;
} }
String to_string(Code self) String to_string(AST* self)
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
GEN_NS to_string( self, & result ); GEN_NS to_string( self, & result );
return result; return result;
} }
void to_string( Code self, String* result ) void to_string( AST* self, String* result )
{ {
GEN_ASSERT(self != nullptr); GEN_ASSERT(self != nullptr);
local_persist thread_local local_persist thread_local
@ -415,169 +415,169 @@ void to_string( Code self, String* result )
break; break;
case Class: case Class:
to_string_def(cast(CodeClass, self), result ); to_string_def(cast(CodeClass, {self}), result );
break; break;
case Class_Fwd: case Class_Fwd:
to_string_fwd(cast(CodeClass, self), result ); to_string_fwd(cast(CodeClass, {self}), result );
break; break;
case Constructor: case Constructor:
to_string_def(cast(CodeConstructor, self), result ); to_string_def(cast(CodeConstructor, {self}), result );
break; break;
case Constructor_Fwd: case Constructor_Fwd:
to_string_fwd(cast(CodeConstructor, self), result ); to_string_fwd(cast(CodeConstructor, {self}), result );
break; break;
case Destructor: case Destructor:
to_string_def(cast(CodeDestructor, self), result ); to_string_def(cast(CodeDestructor, {self}), result );
break; break;
case Destructor_Fwd: case Destructor_Fwd:
to_string_fwd(cast(CodeDestructor, self), result ); to_string_fwd(cast(CodeDestructor, {self}), result );
break; break;
case Enum: case Enum:
to_string_def(cast(CodeEnum, self), result ); to_string_def(cast(CodeEnum, {self}), result );
break; break;
case Enum_Fwd: case Enum_Fwd:
to_string_fwd(cast(CodeEnum, self), result ); to_string_fwd(cast(CodeEnum, {self}), result );
break; break;
case Enum_Class: case Enum_Class:
to_string_class_def(cast(CodeEnum, self), result ); to_string_class_def(cast(CodeEnum, {self}), result );
break; break;
case Enum_Class_Fwd: case Enum_Class_Fwd:
to_string_class_fwd(cast(CodeEnum, self), result ); to_string_class_fwd(cast(CodeEnum, {self}), result );
break; break;
case Export_Body: case Export_Body:
to_string_export(cast(CodeBody, self), result ); to_string_export(cast(CodeBody, {self}), result );
break; break;
case Extern_Linkage: case Extern_Linkage:
to_string(cast(CodeExtern, self), result ); to_string(cast(CodeExtern, {self}), result );
break; break;
case Friend: case Friend:
to_string(cast(CodeFriend, self), result ); to_string(cast(CodeFriend, {self}), result );
break; break;
case Function: case Function:
to_string_def(cast(CodeFn, self), result ); to_string_def(cast(CodeFn, {self}), result );
break; break;
case Function_Fwd: case Function_Fwd:
to_string_fwd(cast(CodeFn, self), result ); to_string_fwd(cast(CodeFn, {self}), result );
break; break;
case Module: case Module:
to_string(cast(CodeModule, self), result ); cast(CodeModule, {self}).to_string( * result );
break; break;
case Namespace: case Namespace:
to_string(cast(CodeNS, self), result ); cast(CodeNS, {self}).to_string( * result );
break; break;
case Operator: case Operator:
case Operator_Member: case Operator_Member:
to_string_def(cast(CodeOperator, self), result ); cast(CodeOperator, {self}).to_string_def( * result );
break; break;
case Operator_Fwd: case Operator_Fwd:
case Operator_Member_Fwd: case Operator_Member_Fwd:
to_string_fwd(cast(CodeOperator, self), result ); cast(CodeOperator, {self}).to_string_fwd( * result );
break; break;
case Operator_Cast: case Operator_Cast:
to_string_def(cast(CodeOpCast, self), result ); cast(CodeOpCast, {self}).to_string_def( * result );
break; break;
case Operator_Cast_Fwd: case Operator_Cast_Fwd:
to_string_fwd(cast(CodeOpCast, self), result ); cast(CodeOpCast, {self}).to_string_fwd( * result );
break; break;
case Parameters: case Parameters:
to_string(cast(CodeParam, self), result ); to_string(cast(CodeParam, {self}), result );
break; break;
case Preprocess_Define: case Preprocess_Define:
to_string(cast(CodeDefine, self), result ); to_string(cast(CodeDefine, {self}), result );
break; break;
case Preprocess_If: case Preprocess_If:
to_string_if(cast(CodePreprocessCond, self), result ); cast(CodePreprocessCond, {self}).to_string_if( * result );
break; break;
case Preprocess_IfDef: case Preprocess_IfDef:
to_string_ifdef(cast(CodePreprocessCond, self), result ); cast(CodePreprocessCond, {self}).to_string_ifdef( * result );
break; break;
case Preprocess_IfNotDef: case Preprocess_IfNotDef:
to_string_ifndef(cast(CodePreprocessCond, self), result ); cast(CodePreprocessCond, {self}).to_string_ifndef( * result );
break; break;
case Preprocess_Include: case Preprocess_Include:
to_string(cast(CodeInclude, self), result ); to_string(cast(CodeInclude, {self}), result );
break; break;
case Preprocess_ElIf: case Preprocess_ElIf:
to_string_elif(cast(CodePreprocessCond, self), result ); cast(CodePreprocessCond, {self}).to_string_elif( * result );
break; break;
case Preprocess_Else: case Preprocess_Else:
to_string_else(cast(CodePreprocessCond, self), result ); cast(CodePreprocessCond, {self}).to_string_else( * result );
break; break;
case Preprocess_EndIf: case Preprocess_EndIf:
to_string_endif(cast(CodePreprocessCond, self), result ); cast(CodePreprocessCond, {self}).to_string_endif( * result );
break; break;
case Preprocess_Pragma: case Preprocess_Pragma:
to_string(cast(CodePragma, self), result ); cast(CodePragma, {self}).to_string( * result );
break; break;
case Specifiers: case Specifiers:
to_string(cast(CodeSpecifiers, self), result ); to_string(cast(CodeSpecifiers, {self}), result );
break; break;
case Struct: case Struct:
to_string_def(cast(CodeStruct, self), result ); to_string_def(cast(CodeStruct, {self}), result );
break; break;
case Struct_Fwd: case Struct_Fwd:
to_string_fwd(cast(CodeStruct, self), result ); to_string_fwd(cast(CodeStruct, {self}), result );
break; break;
case Template: case Template:
to_string(cast(CodeTemplate, self), result ); cast(CodeTemplate, {self}).to_string( * result );
break; break;
case Typedef: case Typedef:
to_string(cast(CodeTypedef, self), result ); cast(CodeTypedef, {self}).to_string( * result );
break; break;
case Typename: case Typename:
to_string(cast(CodeType, self), result ); cast(CodeType, {self}).to_string( * result );
break; break;
case Union: case Union:
to_string( cast(CodeUnion, self), result ); cast(CodeUnion, {self}).to_string( * result );
break; break;
case Using: case Using:
to_string(cast(CodeUsing, self), result ); cast(CodeUsing, {self}).to_string( * result );
break; break;
case Using_Namespace: case Using_Namespace:
to_string_ns(cast(CodeUsing, self), result ); cast(CodeUsing, {self}).to_string_ns( * result );
break; break;
case Variable: case Variable:
to_string(cast(CodeVar, self), result ); cast(CodeVar, {self}).to_string( * result );
break; break;
case Enum_Body: case Enum_Body:
@ -588,12 +588,12 @@ void to_string( Code self, String* result )
case Namespace_Body: case Namespace_Body:
case Struct_Body: case Struct_Body:
case Union_Body: case Union_Body:
to_string( cast(CodeBody, self), result ); to_string( cast(CodeBody, {self}), result );
break; break;
} }
} }
bool is_equal( Code self, Code other ) bool is_equal( AST* self, AST* other )
{ {
/* /*
AST values are either some u32 value, a cached string, or a pointer to another AST. AST values are either some u32 value, a cached string, or a pointer to another AST.
@ -910,8 +910,8 @@ bool is_equal( Code self, Code other )
{ {
if ( self->NumEntries > 1 ) if ( self->NumEntries > 1 )
{ {
Code curr = self; AST* curr = self;
Code curr_other = other; AST* curr_other = other;
while ( curr != nullptr ) while ( curr != nullptr )
{ {
if ( curr ) if ( curr )
@ -1104,8 +1104,8 @@ bool is_equal( Code self, Code other )
check_member_ast( Front ); check_member_ast( Front );
check_member_ast( Back ); check_member_ast( Back );
Code curr = self->Front; AST* curr = self->Front;
Code curr_other = other->Front; AST* curr_other = other->Front;
while ( curr != nullptr ) while ( curr != nullptr )
{ {
if ( curr_other == nullptr ) if ( curr_other == nullptr )
@ -1153,14 +1153,14 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
bool validate_body(Code self) bool validate_body(AST* self)
{ {
using namespace ECode; using namespace ECode;
#define CheckEntries( Unallowed_Types ) \ #define CheckEntries( Unallowed_Types ) \
do \ do \
{ \ { \
for ( Code entry : cast(CodeBody, self) ) \ for ( Code entry : cast(CodeBody, {self}) ) \
{ \ { \
switch ( entry->Type ) \ switch ( entry->Type ) \
{ \ { \
@ -1178,7 +1178,7 @@ bool validate_body(Code self)
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
break; break;
case Enum_Body: case Enum_Body:
for ( Code entry : cast(CodeBody, self) ) for ( Code entry : cast(CodeBody, {self}) )
{ {
if ( entry->Type != Untyped ) if ( entry->Type != Untyped )
{ {
@ -1197,7 +1197,7 @@ bool validate_body(Code self)
CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES );
break; break;
case Global_Body: case Global_Body:
for (Code entry : cast(CodeBody, self)) for (Code entry : cast(CodeBody, {self}))
{ {
switch (entry->Type) switch (entry->Type)
{ {

View File

@ -152,29 +152,22 @@ Define_Code(Using);
Define_Code(Var); Define_Code(Var);
#undef Define_Code #undef Define_Code
GEN_NS_PARSER_BEGIN namespace parser
{
struct Token; struct Token;
GEN_NS_PARSER_END }
#if ! GEN_COMPILER_C #if ! GEN_COMPILER_C
template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast( Type*, & self ); } template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast( Type*, & self ); }
#endif #endif
#pragma region Code Interface
void append (Code code, Code other );
char const* debug_str (Code code); char const* debug_str (Code code);
Code duplicate (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_equal (Code code, Code other);
bool is_body (Code code);
bool is_valid (Code code); bool is_valid (Code code);
void set_global(Code code); void set_global(Code code);
String to_string (Code self ); String to_string (Code code);
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 #if ! GEN_COMPILER_C
/* /*
@ -195,6 +188,7 @@ struct Code
void set_global() { return GEN_NS set_global(* this); } void set_global() { return GEN_NS set_global(* this); }
# define Using_CodeOps( Typename ) \ # define Using_CodeOps( Typename ) \
Typename& operator = ( AST* other ); \
Typename& operator = ( Code other ); \ Typename& operator = ( Code other ); \
bool operator ==( Code other ) { return (AST*)ast == other.ast; } \ bool operator ==( Code other ) { return (AST*)ast == other.ast; } \
bool operator !=( Code other ) { return (AST*)ast != other.ast; } \ bool operator !=( Code other ) { return (AST*)ast != other.ast; } \
@ -202,13 +196,7 @@ struct Code
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( Code ); Using_Code( Code );
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); } 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 #endif
Using_CodeOps( Code ); Using_CodeOps( Code );
@ -228,11 +216,6 @@ struct Code
return *this; 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 #ifdef GEN_ENFORCE_STRONG_CODE_TYPES
# define operator explicit operator # define operator explicit operator
#endif #endif
@ -281,11 +264,33 @@ struct Code_POD
{ {
AST* ast; AST* ast;
}; };
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" ); static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
// Desired width of the AST data structure. // Desired width of the AST data structure.
constexpr int const AST_POD_Size = 128; constexpr int const AST_POD_Size = 128;
void append ( AST* self, AST* other );
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 constexpr static
int AST_ArrSpecs_Cap = int AST_ArrSpecs_Cap =
( (
@ -305,53 +310,102 @@ int AST_ArrSpecs_Cap =
*/ */
struct AST 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 { union {
struct struct
{ {
Code InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
Code Specs; // Destructor, Function, Operator, Typename, Variable AST* Specs; // Destructor, Function, Operator, Typename, Variable
union { union {
Code InitializerList; // Constructor AST* InitializerList; // Constructor
Code ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces. AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
Code ReturnType; // Function, Operator, Typename AST* ReturnType; // Function, Operator, Typename
Code UnderlyingType; // Enum, Typedef AST* UnderlyingType; // Enum, Typedef
Code ValueType; // Parameter, Variable AST* ValueType; // Parameter, Variable
}; };
union { union {
Code Macro; // Parameter AST* Macro; // Parameter
Code BitfieldSize; // Variable (Class/Struct Data Member) AST* BitfieldSize; // Variable (Class/Struct Data Member)
Code Params; // Constructor, Function, Operator, Template, Typename AST* Params; // Constructor, Function, Operator, Template, Typename
}; };
union { union {
Code ArrExpr; // Typename AST* ArrExpr; // Typename
Code Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union AST* Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union
Code Declaration; // Friend, Template AST* Declaration; // Friend, Template
Code Value; // Parameter, Variable AST* Value; // Parameter, Variable
}; };
union { union {
Code NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value ) AST* 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 ) AST* 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) AST* PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
}; };
}; };
StringCached Content; // Attributes, Comment, Execution, Include StringCached Content; // Attributes, Comment, Execution, Include
struct { struct {
SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used. AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
}; };
}; };
union { union {
Code Prev; AST* Prev;
Code Front; AST* Front;
Code Last; AST* Last;
}; };
union { union {
Code Next; AST* Next;
Code Back; AST* Back;
}; };
parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing. parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
Code Parent; AST* Parent;
StringCached Name; StringCached Name;
CodeT Type; CodeT Type;
// CodeFlag CodeFlags; // CodeFlag CodeFlags;
@ -366,16 +420,75 @@ struct AST
b32 EnumUnderlyingMacro; // Used by enums incase the user wants to wrap underlying type specification in a macro b32 EnumUnderlyingMacro; // Used by enums incase the user wants to wrap underlying type specification in a macro
}; };
}; };
static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
#if ! GEN_COMPILER_C struct AST_POD
// Uses an implicitly overloaded cast from the AST to the desired code type. {
// Necessary if the user wants GEN_ENFORCE_STRONG_CODE_TYPES union {
struct InvalidCode_ImplictCaster; struct
#define InvalidCode (InvalidCode_ImplictCaster{}) {
#else AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
#define InvalidCode Code_Invalid AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
#endif AST* 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
};
union {
AST* Macro; // Parameter
AST* BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename
};
union {
AST* ArrExpr; // Typename
AST* Body; // Class, Constructr, Destructor, Enum, Friend, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template
AST* 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)
};
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
};
};
union {
AST* Prev;
AST* Front;
AST* Last;
};
union {
AST* Next;
AST* Back;
};
parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
AST* Parent;
StringCached Name;
CodeT Type;
CodeFlag CodeFlags;
ModuleFlag ModuleFlags;
union {
b32 IsFunction; // Used by typedef to not serialize the name field.
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
OperatorT Op;
AccessSpec ParentAccess;
s32 NumEntries;
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
};
};
// 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" );
static_assert( sizeof(AST_POD) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
// Used when the its desired when omission is allowed in a definition. // Used when the its desired when omission is allowed in a definition.
#define NullCode { nullptr } #define NoCode { nullptr }
#define InvalidCode (* Code_Invalid.ast) // Uses an implicitly overloaded cast from the AST to the desired code type.

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,6 @@
#include "ast.hpp" #include "ast.hpp"
#endif #endif
#pragma region Code Type Interface
void append ( CodeBody body, Code other ); void append ( CodeBody body, Code other );
void append ( CodeBody body, CodeBody other ); void append ( CodeBody body, CodeBody other );
String to_string ( CodeBody body ); String to_string ( CodeBody body );
@ -75,58 +74,11 @@ String to_string (CodeFn self);
void to_string_def(CodeFn self, String* result); void to_string_def(CodeFn self, String* result);
void to_string_fwd(CodeFn self, String* result); void to_string_fwd(CodeFn self, String* result);
String to_string(CodeModule self);
void to_string(CodeModule self, String* result);
String to_string(CodeNS self);
void to_string(CodeNS self, String* result);
String to_string (CodeOperator self);
void to_string_fwd(CodeOperator self, String* result );
void to_string_def(CodeOperator self, String* result );
String to_string (CodeOpCast op_cast );
void to_string_def(CodeOpCast op_cast, String* result );
void to_string_fwd(CodeOpCast op_cast, String* result );
String to_string(CodePragma self);
void to_string(CodePragma self, String* result);
String to_string (CodePreprocessCond cond);
void to_string_if (CodePreprocessCond cond, String* result );
void to_string_ifdef (CodePreprocessCond cond, String* result );
void to_string_ifndef(CodePreprocessCond cond, String* result );
void to_string_elif (CodePreprocessCond cond, String* result );
void to_string_else (CodePreprocessCond cond, String* result );
void to_string_endif (CodePreprocessCond cond, String* result );
String to_string(CodeTemplate self);
void to_string(CodeTemplate self, String* result);
String to_string(CodeType self);
void to_string(CodeType self, String* result);
String to_string(CodeTypedef self);
void to_string(CodeTypedef self, String* result);
String to_string(CodeUnion self);
void to_string(CodeUnion self, String* result);
String to_string (CodeUsing op_cast );
void to_string (CodeUsing op_cast, String* result );
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 #pragma region Code Types
// These structs are not used at all by the C vairant. // These structs are not used at all by the C vairant.
#if ! GEN_COMPILER_C #if ! GEN_COMPILER_C
// stati_assert( GEN_COMPILER_C, "This should not be compiled with the C-library" ); // stati_assert( GEN_COMPILER_C, "This should not be compiled with the C-library" );
#define Verify_POD(Type) static_assert(size_of(Code##Type) == size_of(AST_##Type), "ERROR: Code##Type is not a POD")
struct CodeBody struct CodeBody
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES
@ -134,7 +86,7 @@ struct CodeBody
void append( Code other ) { return GEN_NS append( *this, other ); } void append( Code other ) { return GEN_NS append( *this, other ); }
void append( CodeBody body ) { return GEN_NS append(*this, body); } void append( CodeBody body ) { return GEN_NS append(*this, body); }
bool has_entries() { return GEN_NS has_entries(* this); } bool has_entries() { return GEN_NS has_entries(rcast( AST*, ast )); }
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 ); } void to_string( String& result ) { return GEN_NS to_string(* this, & result ); }
@ -340,10 +292,10 @@ struct CodeEnum
Using_Code( CodeEnum ); Using_Code( CodeEnum );
String to_string() { return GEN_NS to_string(* this); } String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); } void to_string_def( String& result ) { return GEN_NS to_string_def(* this); }
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); } void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); }
void to_string_class_def( String& result ) { return GEN_NS to_string_class_def(* this, & result); } void to_string_class_def( String& result ) { return GEN_NS to_string_class_def(* this); }
void to_string_class_fwd( String& result ) { return GEN_NS to_string_class_fwd(* this, & result); } void to_string_class_fwd( String& result ) { return GEN_NS to_string_class_fwd(* this); }
#endif #endif
Using_CodeOps(CodeEnum); Using_CodeOps(CodeEnum);
@ -621,8 +573,8 @@ struct CodeFn
Using_Code( CodeFn ); Using_Code( CodeFn );
String to_string() { return GEN_NS to_string(* this); } String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); } void to_string_def( String& result ) { return GEN_NS to_string_def(* this); }
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); } void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); }
#endif #endif
Using_CodeOps(CodeFn); Using_CodeOps(CodeFn);
@ -633,11 +585,11 @@ struct CodeFn
struct CodeModule struct CodeModule
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeModule ); Using_Code( CodeModule );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
#endif #endif
Using_CodeOps(CodeModule); Using_CodeOps(CodeModule);
@ -648,11 +600,11 @@ struct CodeModule
struct CodeNS struct CodeNS
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeNS ); Using_Code( CodeNS );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
#endif #endif
Using_CodeOps(CodeNS); Using_CodeOps(CodeNS);
@ -663,12 +615,12 @@ struct CodeNS
struct CodeOperator struct CodeOperator
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeOperator ); Using_Code( CodeOperator );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); } void to_string_def( String& result );
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); } void to_string_fwd( String& result );
#endif #endif
Using_CodeOps(CodeOperator); Using_CodeOps(CodeOperator);
@ -679,12 +631,12 @@ struct CodeOperator
struct CodeOpCast struct CodeOpCast
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeOpCast ); Using_Code( CodeOpCast );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); } void to_string_def( String& result );
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); } void to_string_fwd( String& result );
#endif #endif
Using_CodeOps(CodeOpCast); Using_CodeOps(CodeOpCast);
@ -698,8 +650,8 @@ struct CodePragma
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodePragma ); Using_Code( CodePragma );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
#endif #endif
Using_CodeOps( CodePragma ); Using_CodeOps( CodePragma );
@ -710,16 +662,16 @@ struct CodePragma
struct CodePreprocessCond struct CodePreprocessCond
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodePreprocessCond ); Using_Code( CodePreprocessCond );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string_if( String& result ) { return GEN_NS to_string_if(* this, & result); } void to_string_if( String& result );
void to_string_ifdef( String& result ) { return GEN_NS to_string_ifdef(* this, & result); } void to_string_ifdef( String& result );
void to_string_ifndef( String& result ) { return GEN_NS to_string_ifndef(* this, & result); } void to_string_ifndef( String& result );
void to_string_elif( String& result ) { return GEN_NS to_string_elif(* this, & result); } void to_string_elif( String& result );
void to_string_else( String& result ) { return GEN_NS to_string_else(* this, & result); } void to_string_else( String& result );
void to_string_endif( String& result ) { return GEN_NS to_string_endif(* this, & result); } void to_string_endif( String& result );
#endif #endif
Using_CodeOps( CodePreprocessCond ); Using_CodeOps( CodePreprocessCond );
@ -914,11 +866,11 @@ struct CodeStmt_While
struct CodeTemplate struct CodeTemplate
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeTemplate ); Using_Code( CodeTemplate );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
#endif #endif
Using_CodeOps( CodeTemplate ); Using_CodeOps( CodeTemplate );
@ -929,11 +881,11 @@ struct CodeTemplate
struct CodeType struct CodeType
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeType ); Using_Code( CodeType );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
#endif #endif
Using_CodeOps( CodeType ); Using_CodeOps( CodeType );
@ -944,11 +896,11 @@ struct CodeType
struct CodeTypedef struct CodeTypedef
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeTypedef ); Using_Code( CodeTypedef );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
#endif #endif
Using_CodeOps( CodeTypedef ); Using_CodeOps( CodeTypedef );
@ -962,8 +914,8 @@ struct CodeUnion
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeUnion ); Using_Code( CodeUnion );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
#endif #endif
Using_CodeOps(CodeUnion); Using_CodeOps(CodeUnion);
@ -977,9 +929,9 @@ struct CodeUsing
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeUsing ); Using_Code( CodeUsing );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
void to_string_ns( String& result ) { return GEN_NS to_string_ns(* this, & result); } void to_string_ns( String& result );
#endif #endif
Using_CodeOps(CodeUsing); Using_CodeOps(CodeUsing);
@ -993,8 +945,8 @@ struct CodeVar
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeVar ); Using_Code( CodeVar );
String to_string() { return GEN_NS to_string(* this); } String to_string();
void to_string( String& result ) { return GEN_NS to_string(* this, & result); } void to_string( String& result );
#endif #endif
Using_CodeOps(CodeVar); Using_CodeOps(CodeVar);
@ -1011,42 +963,6 @@ struct CodeVar
void to_string_export( CodeBody body, String& result ) { return to_string_export(body, & result); }; void to_string_export( CodeBody body, String& result ) { return to_string_export(body, & result); };
#endif #endif
#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 #endif //if ! GEN_COMPILER_C
#pragma endregion Code Types #pragma endregion Code Types

View File

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

View File

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

View File

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

View File

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

View File

@ -145,7 +145,7 @@ void define_constants()
# define def_constant_code_type( Type_ ) \ # define def_constant_code_type( Type_ ) \
t_##Type_ = def_type( name(Type_) ); \ t_##Type_ = def_type( name(Type_) ); \
set_global(t_##Type_); t_##Type_.set_global();
def_constant_code_type( auto ); def_constant_code_type( auto );
def_constant_code_type( void ); def_constant_code_type( void );

View File

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

View File

@ -39,9 +39,9 @@ CodeConstructor parse_constructor( StrC def )
SpecifierT specs_found[ 16 ] { ESpecifier::NumSpecifiers }; SpecifierT specs_found[ 16 ] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0; s32 NumSpecifiers = 0;
while ( left && is_specifier(currtok) ) while ( left && currtok.is_specifier() )
{ {
SpecifierT spec = ESpecifier::to_type( to_str(currtok) ); SpecifierT spec = ESpecifier::to_type( currtok );
b32 ignore_spec = false; b32 ignore_spec = false;

View File

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

View File

@ -4,7 +4,7 @@
#include "gen/etoktype.cpp" #include "gen/etoktype.cpp"
#endif #endif
GEN_NS_PARSER_BEGIN namespace parser {
enum TokFlags : u32 enum TokFlags : u32
{ {
@ -31,132 +31,137 @@ struct Token
s32 Line; s32 Line;
s32 Column; s32 Column;
u32 Flags; u32 Flags;
};
constexpr Token NullToken { nullptr, 0, TokType::Invalid, false, 0, TF_Null }; operator bool()
AccessSpec to_access_specifier(Token tok)
{ {
return scast(AccessSpec, tok.Type); return Text && Length && Type != TokType::Invalid;
} }
StrC to_str(Token tok) operator StrC()
{ {
return { tok.Length, tok.Text }; return { Length, Text };
} }
bool is_valid( Token tok ) bool is_access_operator()
{ {
return tok.Text && tok.Length && tok.Type != TokType::Invalid; return bitfield_is_equal( u32, Flags, TF_AccessOperator );
} }
bool is_access_operator(Token tok) bool is_access_specifier()
{ {
return bitfield_is_equal( u32, tok.Flags, TF_AccessOperator ); return bitfield_is_equal( u32, Flags, TF_AccessSpecifier );
} }
bool is_access_specifier(Token tok) bool is_attribute()
{ {
return bitfield_is_equal( u32, tok.Flags, TF_AccessSpecifier ); return bitfield_is_equal( u32, Flags, TF_Attribute );
} }
bool is_attribute(Token tok) bool is_operator()
{ {
return bitfield_is_equal( u32, tok.Flags, TF_Attribute ); return bitfield_is_equal( u32, Flags, TF_Operator );
} }
bool is_operator(Token tok) bool is_preprocessor()
{ {
return bitfield_is_equal( u32, tok.Flags, TF_Operator ); return bitfield_is_equal( u32, Flags, TF_Preprocess );
} }
bool is_preprocessor(Token tok) bool is_preprocess_cond()
{ {
return bitfield_is_equal( u32, tok.Flags, TF_Preprocess ); return bitfield_is_equal( u32, Flags, TF_Preprocess_Cond );
} }
bool is_preprocess_cond(Token tok) bool is_specifier()
{ {
return bitfield_is_equal( u32, tok.Flags, TF_Preprocess_Cond ); return bitfield_is_equal( u32, Flags, TF_Specifier );
} }
bool is_specifier(Token tok) bool is_end_definition()
{ {
return bitfield_is_equal( u32, tok.Flags, TF_Specifier ); return bitfield_is_equal( u32, Flags, TF_EndDefinition );
} }
bool is_end_definition(Token tok) AccessSpec to_access_specifier()
{ {
return bitfield_is_equal( u32, tok.Flags, TF_EndDefinition ); return scast(AccessSpec, Type);
} }
String to_string(Token tok) String to_string()
{ {
String result = string_make_reserve( GlobalAllocator, kilobytes(4) ); String result = string_make_reserve( GlobalAllocator, kilobytes(4) );
StrC type_str = ETokType::to_str( tok.Type ); StrC type_str = ETokType::to_str( Type );
append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s" append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s"
, tok.Line, tok.Column , Line, Column
, type_str.Len, type_str.Ptr , type_str.Len, type_str.Ptr
, tok.Length, tok.Text , Length, Text
); );
return result; return result;
} }
};
constexpr Token NullToken { nullptr, 0, TokType::Invalid, false, 0, TF_Null };
struct TokArray struct TokArray
{ {
Array(Token) Arr; Array<Token> Arr;
s32 Idx; s32 Idx;
};
bool __eat( TokType type ); bool __eat( TokType type );
Token* current(TokArray* self, bool skip_formatting ) Token& current( bool skip_formatting = true )
{ {
if ( skip_formatting ) if ( skip_formatting )
{ {
while ( self->Arr[self->Idx].Type == TokType::NewLine || self->Arr[self->Idx].Type == TokType::Comment ) while ( Arr[Idx].Type == TokType::NewLine || Arr[Idx].Type == TokType::Comment )
self->Idx++; Idx++;
} }
return & self->Arr[self->Idx]; return Arr[Idx];
} }
Token* previous(TokArray self, bool skip_formatting) Token& previous( bool skip_formatting = false )
{ {
s32 idx = self.Idx; s32 idx = this->Idx;
if ( skip_formatting ) if ( skip_formatting )
{ {
while ( self.Arr[idx].Type == TokType::NewLine ) while ( Arr[idx].Type == TokType::NewLine )
idx--; idx--;
return & self.Arr[idx]; return Arr[idx];
} }
return & self.Arr[idx - 1]; return Arr[idx - 1];
} }
Token* next(TokArray self, bool skip_formatting) Token& next( bool skip_formatting = false )
{ {
s32 idx = self.Idx; s32 idx = this->Idx;
if ( skip_formatting ) if ( skip_formatting )
{ {
while ( self.Arr[idx].Type == TokType::NewLine ) while ( Arr[idx].Type == TokType::NewLine )
idx++; idx++;
return & self.Arr[idx + 1]; return Arr[idx + 1];
} }
return & self.Arr[idx + 1]; return Arr[idx + 1];
} }
Token& operator []( s32 idx )
{
return Arr[idx];
}
};
global Arena_256KB defines_map_arena; global Arena_256KB defines_map_arena;
global HashTable(StrC) defines; global HashTable<StrC> defines;
global Array(Token) Tokens; global Array<Token> Tokens;
#define current ( * scanner ) #define current ( * scanner )
@ -229,7 +234,7 @@ s32 lex_preprocessor_directive(
token.Length++; token.Length++;
} }
token.Type = ETokType::to_type( to_str(token) ); token.Type = ETokType::to_type( token );
bool is_preprocessor = token.Type >= TokType::Preprocess_Define && token.Type <= TokType::Preprocess_Pragma; bool is_preprocessor = token.Type >= TokType::Preprocess_Define && token.Type <= TokType::Preprocess_Pragma;
if ( ! is_preprocessor ) if ( ! is_preprocessor )
@ -336,7 +341,7 @@ s32 lex_preprocessor_directive(
append( & Tokens, name ); append( & Tokens, name );
u64 key = crc32( name.Text, name.Length ); u64 key = crc32( name.Text, name.Length );
set(& defines, key, to_str(name) ); set<StrC>(& defines, key, name );
} }
Token preprocess_content = { scanner, 0, TokType::Preprocess_Content, line, column, TF_Preprocess }; Token preprocess_content = { scanner, 0, TokType::Preprocess_Content, line, column, TF_Preprocess };
@ -460,7 +465,7 @@ void lex_found_token( StrC& content
return; return;
} }
TokType type = ETokType::to_type( to_str(token) ); TokType type = ETokType::to_type( token );
if (type <= TokType::Access_Public && type >= TokType::Access_Private ) if (type <= TokType::Access_Public && type >= TokType::Access_Private )
{ {
@ -1262,4 +1267,5 @@ TokArray lex( StrC content )
#undef move_forward #undef move_forward
#undef SkipWhitespace #undef SkipWhitespace
GEN_NS_PARSER_END // namespace parser
}

File diff suppressed because it is too large Load Diff

View File

@ -385,8 +385,6 @@ bool set_capacity(Array<Type>* array, usize new_capacity)
// TODO(Ed) : This thing needs ALOT of work. // TODO(Ed) : This thing needs ALOT of work.
#pragma region HashTable #pragma region HashTable
#define HashTable(Type) HashTable<Type>
template<class Type> struct HashTable; template<class Type> struct HashTable;
struct HashTableFindResult { struct HashTableFindResult {

View File

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

View File

@ -133,16 +133,12 @@
#if GEN_DONT_USE_NAMESPACE || GEN_COMPILER_C #if GEN_DONT_USE_NAMESPACE || GEN_COMPILER_C
# if GEN_COMPILER_C # if GEN_COMPILER_C
# define GEN_NS_PARSER_BEGIN
# define GEN_NS_PARSER_END
# define GEN_NS_ENUM_BEGIN # define GEN_NS_ENUM_BEGIN
# define GEN_NS_ENUM_END # define GEN_NS_ENUM_END
# define GEN_NS # define GEN_NS
# define GEN_NS_BEGIN # define GEN_NS_BEGIN
# define GEN_NS_END # define GEN_NS_END
# else # else
# define GEN_NS_PARSER_BEGIN namespace parser {
# define GEN_NS_PARSER_END }
# define GEN_NS_ENUM_BEGIN namespace gen_internal_enums { # define GEN_NS_ENUM_BEGIN namespace gen_internal_enums {
# define GEN_NS_ENUM_END } # define GEN_NS_ENUM_END }
# define GEN_NS :: # define GEN_NS ::
@ -150,8 +146,6 @@
# define GEN_NS_END # define GEN_NS_END
# endif # endif
#else #else
# define GEN_NS_PARSER_BEGIN namespace parser {
# define GEN_NS_PARSER_END }
# define GEN_NS_ENUM_BEGIN namespace gen_internal_enums { # define GEN_NS_ENUM_BEGIN namespace gen_internal_enums {
# define GEN_NS_ENUM_END } # define GEN_NS_ENUM_END }
# define GEN_NS gen:: # define GEN_NS gen::

View File

@ -358,8 +358,8 @@ CodeBody gen_ast_inlines()
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
ast = rcast( decltype(ast), GEN_NS duplicate(other).ast); ast = rcast( decltype(ast), GEN_NS duplicate(other.ast) );
ast->Parent = { nullptr }; rcast( AST*, ast)->Parent = nullptr;
} }
ast = rcast( decltype(ast), other.ast ); ast = rcast( decltype(ast), other.ast );
@ -448,6 +448,10 @@ CodeBody gen_ast_inlines()
append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl ))); append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl )));
char const* cast_tmpl = stringize( char const* cast_tmpl = stringize(
inline AST::operator Code<typename>()
{
return { rcast( AST_<typename>*, this ) };
}
inline Code::operator Code<typename>() const inline Code::operator Code<typename>() const
{ {
return { (AST_<typename>*) ast }; return { (AST_<typename>*) ast };

View File

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

View File

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