Compare commits

...

5 Commits

21 changed files with 1246 additions and 1432 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 = entry->Body->operator CodeBody(); CodeBody body = cast(CodeBody, entry->Body);
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 = rcast(AST*, new_body.ast); entry->Body = new_body;
memory.append(entry); memory.append(entry);
} }
break; break;
@ -324,7 +324,7 @@ int gen_main()
case ECode::Struct: case ECode::Struct:
{ {
CodeBody body = entry->Body->operator CodeBody(); CodeBody body = cast(CodeBody, entry->Body);
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 = rcast(AST*, new_body.ast); entry->Body = new_body;
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(AST* self) char const* debug_str(Code 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(AST* self)
return * result; return * result;
} }
AST* duplicate(AST* self) Code duplicate(Code self)
{ {
using namespace ECode; using namespace ECode;
AST* result = make_code().ast; Code result = make_code();
mem_copy( result, self, sizeof( AST ) ); mem_copy( result.ast, self.ast, sizeof( AST ) );
result->Parent = nullptr; result->Parent = { nullptr };
return result; return result;
} }
String to_string(AST* self) String to_string(Code 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( AST* self, String* result ) void to_string( Code 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( AST* 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:
cast(CodeModule, {self}).to_string( * result ); to_string(cast(CodeModule, self), result );
break; break;
case Namespace: case Namespace:
cast(CodeNS, {self}).to_string( * result ); to_string(cast(CodeNS, self), result );
break; break;
case Operator: case Operator:
case Operator_Member: case Operator_Member:
cast(CodeOperator, {self}).to_string_def( * result ); to_string_def(cast(CodeOperator, self), result );
break; break;
case Operator_Fwd: case Operator_Fwd:
case Operator_Member_Fwd: case Operator_Member_Fwd:
cast(CodeOperator, {self}).to_string_fwd( * result ); to_string_fwd(cast(CodeOperator, self), result );
break; break;
case Operator_Cast: case Operator_Cast:
cast(CodeOpCast, {self}).to_string_def( * result ); to_string_def(cast(CodeOpCast, self), result );
break; break;
case Operator_Cast_Fwd: case Operator_Cast_Fwd:
cast(CodeOpCast, {self}).to_string_fwd( * result ); to_string_fwd(cast(CodeOpCast, self), result );
break; break;
case Parameters: case Parameters:
to_string(cast(CodeParam, {self}), result ); to_string(cast(CodeParam, self), result );
break; break;
case Preprocess_Define: case Preprocess_Define:
to_string(cast(CodeDefine, {self}), result ); to_string(cast(CodeDefine, self), result );
break; break;
case Preprocess_If: case Preprocess_If:
cast(CodePreprocessCond, {self}).to_string_if( * result ); to_string_if(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_IfDef: case Preprocess_IfDef:
cast(CodePreprocessCond, {self}).to_string_ifdef( * result ); to_string_ifdef(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_IfNotDef: case Preprocess_IfNotDef:
cast(CodePreprocessCond, {self}).to_string_ifndef( * result ); to_string_ifndef(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_Include: case Preprocess_Include:
to_string(cast(CodeInclude, {self}), result ); to_string(cast(CodeInclude, self), result );
break; break;
case Preprocess_ElIf: case Preprocess_ElIf:
cast(CodePreprocessCond, {self}).to_string_elif( * result ); to_string_elif(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_Else: case Preprocess_Else:
cast(CodePreprocessCond, {self}).to_string_else( * result ); to_string_else(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_EndIf: case Preprocess_EndIf:
cast(CodePreprocessCond, {self}).to_string_endif( * result ); to_string_endif(cast(CodePreprocessCond, self), result );
break; break;
case Preprocess_Pragma: case Preprocess_Pragma:
cast(CodePragma, {self}).to_string( * result ); to_string(cast(CodePragma, self), result );
break; break;
case Specifiers: case Specifiers:
to_string(cast(CodeSpecifiers, {self}), result ); to_string(cast(CodeSpecifiers, self), result );
break; break;
case Struct: case Struct:
to_string_def(cast(CodeStruct, {self}), result ); to_string_def(cast(CodeStruct, self), result );
break; break;
case Struct_Fwd: case Struct_Fwd:
to_string_fwd(cast(CodeStruct, {self}), result ); to_string_fwd(cast(CodeStruct, self), result );
break; break;
case Template: case Template:
cast(CodeTemplate, {self}).to_string( * result ); to_string(cast(CodeTemplate, self), result );
break; break;
case Typedef: case Typedef:
cast(CodeTypedef, {self}).to_string( * result ); to_string(cast(CodeTypedef, self), result );
break; break;
case Typename: case Typename:
cast(CodeType, {self}).to_string( * result ); to_string(cast(CodeType, self), result );
break; break;
case Union: case Union:
cast(CodeUnion, {self}).to_string( * result ); to_string( cast(CodeUnion, self), result );
break; break;
case Using: case Using:
cast(CodeUsing, {self}).to_string( * result ); to_string(cast(CodeUsing, self), result );
break; break;
case Using_Namespace: case Using_Namespace:
cast(CodeUsing, {self}).to_string_ns( * result ); to_string_ns(cast(CodeUsing, self), result );
break; break;
case Variable: case Variable:
cast(CodeVar, {self}).to_string( * result ); to_string(cast(CodeVar, self), result );
break; break;
case Enum_Body: case Enum_Body:
@ -588,12 +588,12 @@ void to_string( AST* 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( AST* self, AST* other ) bool is_equal( Code self, Code other )
{ {
/* /*
AST values are either some u32 value, a cached string, or a pointer to another AST. AST values are either some u32 value, a cached string, or a pointer to another AST.
@ -910,8 +910,8 @@ bool is_equal( AST* self, AST* other )
{ {
if ( self->NumEntries > 1 ) if ( self->NumEntries > 1 )
{ {
AST* curr = self; Code curr = self;
AST* curr_other = other; Code curr_other = other;
while ( curr != nullptr ) while ( curr != nullptr )
{ {
if ( curr ) if ( curr )
@ -1104,8 +1104,8 @@ bool is_equal( AST* self, AST* other )
check_member_ast( Front ); check_member_ast( Front );
check_member_ast( Back ); check_member_ast( Back );
AST* curr = self->Front; Code curr = self->Front;
AST* curr_other = other->Front; Code 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( AST* self, AST* other )
return true; return true;
} }
bool validate_body(AST* self) bool validate_body(Code 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(AST* 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(AST* 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,22 +152,29 @@ Define_Code(Using);
Define_Code(Var); Define_Code(Var);
#undef Define_Code #undef Define_Code
namespace parser GEN_NS_PARSER_BEGIN
{ 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
char const* debug_str (Code code); #pragma region Code Interface
Code duplicate (Code code); void append (Code code, Code other );
bool is_equal (Code code, Code other); char const* debug_str (Code code);
bool is_body (Code code); Code duplicate (Code code);
bool is_valid (Code code); Code* entry (Code code, u32 idx );
void set_global(Code code); bool has_entries (Code code);
String to_string (Code code); bool is_body (Code code);
bool is_equal (Code code, Code other);
bool is_valid (Code code);
void set_global (Code code);
String to_string (Code self );
void to_string (Code self, String* result );
char const* type_str (Code self );
bool validate_body(Code self );
#pragma endregion Code Interface
#if ! GEN_COMPILER_C #if ! GEN_COMPILER_C
/* /*
@ -188,7 +195,6 @@ 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; } \
@ -196,7 +202,13 @@ struct Code
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( Code ); Using_Code( Code );
String to_string() { return GEN_NS to_string(* this); } void append(Code other) { return GEN_NS append(* this, other); }
Code* entry(u32 idx) { return GEN_NS entry(* this, idx); }
bool has_entries() { return GEN_NS has_entries(* this); }
String to_string() { return GEN_NS to_string(* this); }
void to_string(String& result) { return GEN_NS to_string(* this, & result); }
char const* type_str() { return GEN_NS type_str(* this); }
bool validate_body() { return GEN_NS validate_body(*this); }
#endif #endif
Using_CodeOps( Code ); Using_CodeOps( Code );
@ -216,6 +228,11 @@ 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
@ -264,33 +281,11 @@ 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 =
( (
@ -310,102 +305,53 @@ 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
{ {
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable Code InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
AST* Specs; // Destructor, Function, Operator, Typename, Variable Code Specs; // Destructor, Function, Operator, Typename, Variable
union { union {
AST* InitializerList; // Constructor Code InitializerList; // Constructor
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces. Code ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
AST* ReturnType; // Function, Operator, Typename Code ReturnType; // Function, Operator, Typename
AST* UnderlyingType; // Enum, Typedef Code UnderlyingType; // Enum, Typedef
AST* ValueType; // Parameter, Variable Code ValueType; // Parameter, Variable
}; };
union { union {
AST* Macro; // Parameter Code Macro; // Parameter
AST* BitfieldSize; // Variable (Class/Struct Data Member) Code BitfieldSize; // Variable (Class/Struct Data Member)
AST* Params; // Constructor, Function, Operator, Template, Typename Code Params; // Constructor, Function, Operator, Template, Typename
}; };
union { union {
AST* ArrExpr; // Typename Code ArrExpr; // Typename
AST* Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union Code Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union
AST* Declaration; // Friend, Template Code Declaration; // Friend, Template
AST* Value; // Parameter, Variable Code Value; // Parameter, Variable
}; };
union { union {
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value ) Code 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 ) Code SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
AST* PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal) Code 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
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used. Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
}; };
}; };
union { union {
AST* Prev; Code Prev;
AST* Front; Code Front;
AST* Last; Code Last;
}; };
union { union {
AST* Next; Code Next;
AST* Back; Code 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.
AST* Parent; Code Parent;
StringCached Name; StringCached Name;
CodeT Type; CodeT Type;
// CodeFlag CodeFlags; // CodeFlag CodeFlags;
@ -420,75 +366,16 @@ 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" );
struct AST_POD #if ! GEN_COMPILER_C
{ // Uses an implicitly overloaded cast from the AST to the desired code type.
union { // Necessary if the user wants GEN_ENFORCE_STRONG_CODE_TYPES
struct struct InvalidCode_ImplictCaster;
{ #define InvalidCode (InvalidCode_ImplictCaster{})
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable #else
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable #define InvalidCode Code_Invalid
AST* Specs; // Destructor, Function, Operator, Typename, Variable #endif
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 NoCode { nullptr } #define NullCode { 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,6 +3,7 @@
#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 );
@ -74,11 +75,58 @@ 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
@ -86,7 +134,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(rcast( AST*, ast )); } 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 ); } void to_string( String& result ) { return GEN_NS to_string(* this, & result ); }
@ -292,10 +340,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); } void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); }
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); } void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); }
void to_string_class_def( String& result ) { return GEN_NS to_string_class_def(* this); } void to_string_class_def( String& result ) { return GEN_NS to_string_class_def(* this, & result); }
void to_string_class_fwd( String& result ) { return GEN_NS to_string_class_fwd(* this); } void to_string_class_fwd( String& result ) { return GEN_NS to_string_class_fwd(* this, & result); }
#endif #endif
Using_CodeOps(CodeEnum); Using_CodeOps(CodeEnum);
@ -573,8 +621,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); } void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); }
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); } void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); }
#endif #endif
Using_CodeOps(CodeFn); Using_CodeOps(CodeFn);
@ -585,11 +633,11 @@ struct CodeFn
struct CodeModule struct CodeModule
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeModule ); Using_Code( CodeModule );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps(CodeModule); Using_CodeOps(CodeModule);
@ -600,11 +648,11 @@ struct CodeModule
struct CodeNS struct CodeNS
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeNS ); Using_Code( CodeNS );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps(CodeNS); Using_CodeOps(CodeNS);
@ -615,12 +663,12 @@ struct CodeNS
struct CodeOperator struct CodeOperator
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeOperator ); Using_Code( CodeOperator );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ); void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); }
void to_string_fwd( String& result ); void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); }
#endif #endif
Using_CodeOps(CodeOperator); Using_CodeOps(CodeOperator);
@ -631,12 +679,12 @@ struct CodeOperator
struct CodeOpCast struct CodeOpCast
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeOpCast ); Using_Code( CodeOpCast );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ); void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); }
void to_string_fwd( String& result ); void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); }
#endif #endif
Using_CodeOps(CodeOpCast); Using_CodeOps(CodeOpCast);
@ -650,8 +698,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(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps( CodePragma ); Using_CodeOps( CodePragma );
@ -662,16 +710,16 @@ struct CodePragma
struct CodePreprocessCond struct CodePreprocessCond
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodePreprocessCond ); Using_Code( CodePreprocessCond );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string_if( String& result ); void to_string_if( String& result ) { return GEN_NS to_string_if(* this, & result); }
void to_string_ifdef( String& result ); void to_string_ifdef( String& result ) { return GEN_NS to_string_ifdef(* this, & result); }
void to_string_ifndef( String& result ); void to_string_ifndef( String& result ) { return GEN_NS to_string_ifndef(* this, & result); }
void to_string_elif( String& result ); void to_string_elif( String& result ) { return GEN_NS to_string_elif(* this, & result); }
void to_string_else( String& result ); void to_string_else( String& result ) { return GEN_NS to_string_else(* this, & result); }
void to_string_endif( String& result ); void to_string_endif( String& result ) { return GEN_NS to_string_endif(* this, & result); }
#endif #endif
Using_CodeOps( CodePreprocessCond ); Using_CodeOps( CodePreprocessCond );
@ -866,11 +914,11 @@ struct CodeStmt_While
struct CodeTemplate struct CodeTemplate
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeTemplate ); Using_Code( CodeTemplate );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps( CodeTemplate ); Using_CodeOps( CodeTemplate );
@ -881,11 +929,11 @@ struct CodeTemplate
struct CodeType struct CodeType
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeType ); Using_Code( CodeType );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps( CodeType ); Using_CodeOps( CodeType );
@ -896,11 +944,11 @@ struct CodeType
struct CodeTypedef struct CodeTypedef
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeTypedef ); Using_Code( CodeTypedef );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps( CodeTypedef ); Using_CodeOps( CodeTypedef );
@ -914,8 +962,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(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps(CodeUnion); Using_CodeOps(CodeUnion);
@ -929,9 +977,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(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
void to_string_ns( String& result ); void to_string_ns( String& result ) { return GEN_NS to_string_ns(* this, & result); }
#endif #endif
Using_CodeOps(CodeUsing); Using_CodeOps(CodeUsing);
@ -945,8 +993,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(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps(CodeVar); Using_CodeOps(CodeVar);
@ -963,6 +1011,42 @@ 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; 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 );
rcast( AST*, ast )->Parent = nullptr; ast->Parent = { nullptr };
} }
ast = rcast( decltype( ast ), other.ast ); ast = rcast( decltype( ast ), other.ast );
return *this; return *this;
@ -820,281 +820,141 @@ 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 __ NoCode # define __ NullCode
// 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,15 +17,3 @@
#ifndef GEN_ROLL_OWN_DEPENDENCIES #ifndef GEN_ROLL_OWN_DEPENDENCIES
# include "gen.dep.hpp" # include "gen.dep.hpp"
#endif #endif
#ifndef GEN_NS_BEGIN
# ifdef GEN_DONT_USE_NAMESPACE
# define GEN_NS
# define GEN_NS_BEGIN
# define GEN_NS_END
# else
# define GEN_NS gen::
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }
# endif
#endif

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -385,6 +385,8 @@ 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,4 +234,10 @@
# endif # endif
#endif #endif
#if ! defined(GEN_PARAM_DEFAULT) && ! GEN_COMPILER_C
# define GEN_PARAM_DEFAULT = {}
#else
# define GEN_PARAM_DEFAULT
#endif
#pragma endregion Macros #pragma endregion Macros

View File

@ -133,12 +133,16 @@
#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 ::
@ -146,6 +150,8 @@
# 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,12 +358,12 @@ 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);
rcast( AST*, ast)->Parent = nullptr; ast->Parent = { nullptr };
} }
ast = rcast( decltype(ast), other.ast ); ast = rcast( decltype( ast ), other.ast );
return *this; return * this;
} }
inline inline
<typename>::operator bool() <typename>::operator bool()
@ -448,10 +448,6 @@ CodeBody gen_ast_inlines()
append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl ))); 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 NoCode, new_name // word NullCode, 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), NoCode, t_u8 ); CodeEnum fwd = def_enum( name(ETestEnum), NullCode, 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), NoCode, t_u8, EnumClass ); CodeEnum fwd_enum_class = def_enum( name(ETestEnumClass), NullCode, t_u8, EnumClass );
gen_sanity_file.print(fwd); gen_sanity_file.print(fwd);
gen_sanity_file.print(def); gen_sanity_file.print(def);