mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
WIP: Broken af
This commit is contained in:
@ -20,7 +20,7 @@ char const* code_debug_str(Code self)
|
||||
|
||||
string_append_fmt( result, "\n\tName : %S", self->Name ? self->Name : "Null" );
|
||||
string_append_fmt( result, "\n\tType : %S", code_type_str(self) );
|
||||
string_append_fmt( result, "\n\tModule Flags : %S", to_str( self->ModuleFlags ) );
|
||||
string_append_fmt( result, "\n\tModule Flags : %S", module_flag_to_str( self->ModuleFlags ) );
|
||||
|
||||
switch ( self->Type )
|
||||
{
|
||||
@ -64,7 +64,7 @@ char const* code_debug_str(Code self)
|
||||
|
||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
||||
string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? to_str( self->ParentAccess ) : "No Parent" );
|
||||
string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? access_spec_to_str( self->ParentAccess ) : "No Parent" );
|
||||
string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" );
|
||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
||||
break;
|
||||
@ -78,7 +78,7 @@ char const* code_debug_str(Code self)
|
||||
|
||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
||||
string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? to_str( self->ParentAccess ) : "No Parent" );
|
||||
string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? access_spec_to_str( self->ParentAccess ) : "No Parent" );
|
||||
string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" );
|
||||
break;
|
||||
|
||||
@ -626,8 +626,8 @@ bool code_is_equal( Code self, Code other )
|
||||
log_fmt("\nAST::is_equal: Member - " #val " failed\n" \
|
||||
"AST : %S\n" \
|
||||
"Other: %S\n" \
|
||||
, code_debug_str(self) \
|
||||
,code_debug_str(other) \
|
||||
, code_debug_str(self) \
|
||||
,code_debug_str(other) \
|
||||
); \
|
||||
\
|
||||
return false; \
|
||||
@ -639,8 +639,8 @@ bool code_is_equal( Code self, Code other )
|
||||
log_fmt("\nAST::is_equal: Member string - "#str " failed\n" \
|
||||
"AST : %S\n" \
|
||||
"Other: %S\n" \
|
||||
, code_debug_str(self) \
|
||||
,code_debug_str(other) \
|
||||
, code_debug_str(self) \
|
||||
,code_debug_str(other) \
|
||||
); \
|
||||
\
|
||||
return false; \
|
||||
@ -652,8 +652,8 @@ bool code_is_equal( Code self, Code other )
|
||||
log_fmt("\nAST::is_equal: Member content - "#content " failed\n" \
|
||||
"AST : %S\n" \
|
||||
"Other: %S\n" \
|
||||
, code_debug_str(self) \
|
||||
, code_debug_str(other) \
|
||||
, code_debug_str(self) \
|
||||
, code_debug_str(other) \
|
||||
); \
|
||||
\
|
||||
log_fmt("Content cannot be trusted to be unique with this check " \
|
||||
@ -674,25 +674,25 @@ bool code_is_equal( Code self, Code other )
|
||||
"AST : %s\n" \
|
||||
"Other: %s\n" \
|
||||
"For ast member: %s\n" \
|
||||
, code_debug_str(self) \
|
||||
, code_debug_str(other) \
|
||||
, code_debug_str(self->ast) \
|
||||
, code_debug_str(self) \
|
||||
, code_debug_str(other) \
|
||||
, code_debug_str(self->ast) \
|
||||
); \
|
||||
\
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
if ( ! code_is_equal(self->ast, other->ast ) ) \
|
||||
if ( ! code_is_equal(self->ast, other->ast ) ) \
|
||||
{ \
|
||||
log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \
|
||||
"AST : %S\n" \
|
||||
"Other: %S\n" \
|
||||
"For ast member: %S\n" \
|
||||
"other's ast member: %S\n" \
|
||||
, code_debug_str(self) \
|
||||
, code_debug_str(other) \
|
||||
, code_debug_str(self->ast) \
|
||||
, code_debug_str(other->ast) \
|
||||
"AST : %S\n" \
|
||||
"Other: %S\n" \
|
||||
"For ast member: %S\n" \
|
||||
"other's ast member: %S\n" \
|
||||
, code_debug_str(self) \
|
||||
, code_debug_str(other) \
|
||||
, code_debug_str(self->ast) \
|
||||
, code_debug_str(other->ast) \
|
||||
); \
|
||||
\
|
||||
return false; \
|
||||
@ -918,10 +918,10 @@ bool code_is_equal( Code self, Code other )
|
||||
if ( curr_other == nullptr )
|
||||
{
|
||||
log_fmt("\nAST::is_equal: Failed for parameter, other equivalent param is null\n"
|
||||
"AST : %S\n"
|
||||
"Other: %S\n"
|
||||
"For ast member: %S\n"
|
||||
, code_debug_str(curr)
|
||||
"AST : %S\n"
|
||||
"Other: %S\n"
|
||||
"For ast member: %S\n"
|
||||
, code_debug_str(curr)
|
||||
);
|
||||
|
||||
return false;
|
||||
@ -1066,7 +1066,7 @@ bool code_is_equal( Code self, Code other )
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
case CT_Union_Fwd:
|
||||
{
|
||||
check_member_val( ModuleFlags );
|
||||
@ -1117,10 +1117,10 @@ bool code_is_equal( Code self, Code other )
|
||||
if ( curr_other == nullptr )
|
||||
{
|
||||
log_fmt("\nAST::is_equal: Failed for body, other equivalent param is null\n"
|
||||
"AST : %S\n"
|
||||
"Other: %S\n"
|
||||
"For ast member: %S\n"
|
||||
, code_debug_str(curr)
|
||||
"AST : %S\n"
|
||||
"Other: %S\n"
|
||||
"For ast member: %S\n"
|
||||
, code_debug_str(curr)
|
||||
);
|
||||
|
||||
return false;
|
||||
|
@ -153,7 +153,9 @@ Define_Code(Var);
|
||||
#undef Define_Code
|
||||
|
||||
GEN_NS_PARSER_BEGIN
|
||||
|
||||
struct Token;
|
||||
|
||||
GEN_NS_PARSER_END
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
@ -380,12 +382,13 @@ static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST POD is not size of AST_P
|
||||
struct InvalidCode_ImplictCaster;
|
||||
#define InvalidCode (InvalidCode_ImplictCaster{})
|
||||
#else
|
||||
#define InvalidCode { (AST*)Code_Invalid }
|
||||
#define InvalidCode { (void*)Code_Invalid }
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
struct NullCode_ImplicitCaster;
|
||||
// Used when the its desired when omission is allowed in a definition.
|
||||
#define NullCode { nullptr }
|
||||
#define NullCode (NullCode_ImplicitCaster{})
|
||||
#else
|
||||
#define NullCode nullptr
|
||||
#endif
|
||||
|
@ -184,7 +184,7 @@ void class_to_string_def( CodeClass self, String* result )
|
||||
|
||||
if ( self->ParentType )
|
||||
{
|
||||
char const* access_level = to_str( self->ParentAccess );
|
||||
char const* access_level = access_spec_to_str( self->ParentAccess );
|
||||
|
||||
string_append_fmt( result, "%SC : %s %S", self->Name, access_level, typename_to_string(self->ParentType) );
|
||||
|
||||
@ -368,7 +368,10 @@ void enum_to_string_fwd(CodeEnum self, String* result )
|
||||
if ( self->UnderlyingType )
|
||||
string_append_fmt( result, "enum %SC : %S", self->Name, typename_to_string(self->UnderlyingType) );
|
||||
else if (self->UnderlyingTypeMacro)
|
||||
string_append_fmt( result, "enum %SC %S", self->Name, typename_to_string(self->UnderlyingType) );
|
||||
{
|
||||
log_fmt("IDENTIFIED A UNDERLYING ENUM MACRO");
|
||||
string_append_fmt( result, "enum %SC %S", self->Name, code_to_string(self->UnderlyingTypeMacro) );
|
||||
}
|
||||
else
|
||||
string_append_fmt( result, "enum %SC", self->Name );
|
||||
|
||||
@ -1033,7 +1036,7 @@ void struct_to_string_def( CodeStruct self, String* result )
|
||||
|
||||
if ( self->ParentType )
|
||||
{
|
||||
char const* access_level = to_str( self->ParentAccess );
|
||||
char const* access_level = access_spec_to_str( self->ParentAccess );
|
||||
|
||||
string_append_fmt( result, "%SC : %s %S", self->Name, access_level, typename_to_string(self->ParentType) );
|
||||
|
||||
|
@ -911,10 +911,6 @@ struct CodeVar
|
||||
#undef Using_Code
|
||||
#undef Using_CodeOps
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
void to_string_export( CodeBody body, String& result ) { return body_to_string_export(body, & result); };
|
||||
#endif
|
||||
|
||||
#undef Verify_POD
|
||||
|
||||
struct InvalidCode_ImplictCaster
|
||||
@ -951,6 +947,38 @@ struct InvalidCode_ImplictCaster
|
||||
operator CodeVar () const { return cast(CodeVar, Code_Invalid); }
|
||||
};
|
||||
|
||||
struct NullCode_ImplicitCaster
|
||||
{
|
||||
operator Code () const { return {nullptr}; }
|
||||
operator CodeBody () const { return {(AST_Body*) nullptr}; }
|
||||
operator CodeAttributes () const { return {(AST_Attributes*)nullptr}; }
|
||||
operator CodeComment () const { return {nullptr}; }
|
||||
operator CodeClass () const { return {nullptr}; }
|
||||
operator CodeConstructor () const { return {nullptr}; }
|
||||
operator CodeDefine () const { return {nullptr}; }
|
||||
operator CodeDestructor () const { return {nullptr}; }
|
||||
operator CodeExec () const { return {nullptr}; }
|
||||
operator CodeEnum () const { return {nullptr}; }
|
||||
operator CodeExtern () const { return {nullptr}; }
|
||||
operator CodeInclude () const { return {nullptr}; }
|
||||
operator CodeFriend () const { return {nullptr}; }
|
||||
operator CodeFn () const { return {nullptr}; }
|
||||
operator CodeModule () const { return {nullptr}; }
|
||||
operator CodeNS () const { return {nullptr}; }
|
||||
operator CodeOperator () const { return {nullptr}; }
|
||||
operator CodeOpCast () const { return {nullptr}; }
|
||||
operator CodeParam () const { return {nullptr}; }
|
||||
operator CodePragma () const { return {nullptr}; }
|
||||
operator CodePreprocessCond() const { return {nullptr}; }
|
||||
operator CodeSpecifiers () const { return {nullptr}; }
|
||||
operator CodeStruct () const { return {nullptr}; }
|
||||
operator CodeTemplate () const { return {nullptr}; }
|
||||
operator CodeTypename () const { return CodeTypename{(AST_Typename*)nullptr}; }
|
||||
operator CodeTypedef () const { return {nullptr}; }
|
||||
operator CodeUnion () const { return {nullptr}; }
|
||||
operator CodeUsing () const { return {nullptr}; }
|
||||
operator CodeVar () const { return {nullptr}; }
|
||||
};
|
||||
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,73 +7,212 @@
|
||||
|
||||
enum CodeType : u32
|
||||
{
|
||||
CT_Invalid,CT_Untyped,CT_NewLine,CT_Comment,CT_Access_Private,CT_Access_Protected,CT_Access_Public,CT_PlatformAttributes,CT_Class,CT_Class_Fwd,CT_Class_Body,CT_Constructor,CT_Constructor_Fwd,CT_Destructor,CT_Destructor_Fwd,CT_Enum,CT_Enum_Fwd,CT_Enum_Body,CT_Enum_Class,CT_Enum_Class_Fwd,CT_Execution,CT_Export_Body,CT_Extern_Linkage,CT_Extern_Linkage_Body,CT_Friend,CT_Function,CT_Function_Fwd,CT_Function_Body,CT_Global_Body,CT_Module,CT_Namespace,CT_Namespace_Body,CT_Operator,CT_Operator_Fwd,CT_Operator_Member,CT_Operator_Member_Fwd,CT_Operator_Cast,CT_Operator_Cast_Fwd,CT_Parameters,CT_Preprocess_Define,CT_Preprocess_Include,CT_Preprocess_If,CT_Preprocess_IfDef,CT_Preprocess_IfNotDef,CT_Preprocess_ElIf,CT_Preprocess_Else,CT_Preprocess_EndIf,CT_Preprocess_Pragma,CT_Specifiers,CT_Struct,CT_Struct_Fwd,CT_Struct_Body,CT_Template,CT_Typedef,CT_Typename,CT_Union,CT_Union_Fwd,CT_Union_Body,CT_Using,CT_Using_Namespace,CT_Variable,CT_NumTypes
|
||||
CT_Invalid,
|
||||
CT_Untyped,
|
||||
CT_NewLine,
|
||||
CT_Comment,
|
||||
CT_Access_Private,
|
||||
CT_Access_Protected,
|
||||
CT_Access_Public,
|
||||
CT_PlatformAttributes,
|
||||
CT_Class,
|
||||
CT_Class_Fwd,
|
||||
CT_Class_Body,
|
||||
CT_Constructor,
|
||||
CT_Constructor_Fwd,
|
||||
CT_Destructor,
|
||||
CT_Destructor_Fwd,
|
||||
CT_Enum,
|
||||
CT_Enum_Fwd,
|
||||
CT_Enum_Body,
|
||||
CT_Enum_Class,
|
||||
CT_Enum_Class_Fwd,
|
||||
CT_Execution,
|
||||
CT_Export_Body,
|
||||
CT_Extern_Linkage,
|
||||
CT_Extern_Linkage_Body,
|
||||
CT_Friend,
|
||||
CT_Function,
|
||||
CT_Function_Fwd,
|
||||
CT_Function_Body,
|
||||
CT_Global_Body,
|
||||
CT_Module,
|
||||
CT_Namespace,
|
||||
CT_Namespace_Body,
|
||||
CT_Operator,
|
||||
CT_Operator_Fwd,
|
||||
CT_Operator_Member,
|
||||
CT_Operator_Member_Fwd,
|
||||
CT_Operator_Cast,
|
||||
CT_Operator_Cast_Fwd,
|
||||
CT_Parameters,
|
||||
CT_Preprocess_Define,
|
||||
CT_Preprocess_Include,
|
||||
CT_Preprocess_If,
|
||||
CT_Preprocess_IfDef,
|
||||
CT_Preprocess_IfNotDef,
|
||||
CT_Preprocess_ElIf,
|
||||
CT_Preprocess_Else,
|
||||
CT_Preprocess_EndIf,
|
||||
CT_Preprocess_Pragma,
|
||||
CT_Specifiers,
|
||||
CT_Struct,
|
||||
CT_Struct_Fwd,
|
||||
CT_Struct_Body,
|
||||
CT_Template,
|
||||
CT_Typedef,
|
||||
CT_Typename,
|
||||
CT_Union,
|
||||
CT_Union_Fwd,
|
||||
CT_Union_Body,
|
||||
CT_Using,
|
||||
CT_Using_Namespace,
|
||||
CT_Variable,
|
||||
CT_NumTypes
|
||||
};
|
||||
typedef enum CodeType CodeType;
|
||||
inline
|
||||
StrC codetype_to_str( CodeType type)
|
||||
|
||||
inline StrC codetype_to_str( CodeType type )
|
||||
{
|
||||
local_persist StrC lookup[61] = { { sizeof("Invalid"), "Invalid" },
|
||||
{ sizeof("Untyped"), "Untyped" },
|
||||
{ sizeof("NewLine"), "NewLine" },
|
||||
{ sizeof("Comment"), "Comment" },
|
||||
{ sizeof("Access_Private"), "Access_Private" },
|
||||
{ sizeof("Access_Protected"), "Access_Protected" },
|
||||
{ sizeof("Access_Public"), "Access_Public" },
|
||||
{ sizeof("PlatformAttributes"), "PlatformAttributes" },
|
||||
{ sizeof("Class"), "Class" },
|
||||
{ sizeof("Class_Fwd"), "Class_Fwd" },
|
||||
{ sizeof("Class_Body"), "Class_Body" },
|
||||
{ sizeof("Constructor"), "Constructor" },
|
||||
{ sizeof("Constructor_Fwd"), "Constructor_Fwd" },
|
||||
{ sizeof("Destructor"), "Destructor" },
|
||||
{ sizeof("Destructor_Fwd"), "Destructor_Fwd" },
|
||||
{ sizeof("Enum"), "Enum" },
|
||||
{ sizeof("Enum_Fwd"), "Enum_Fwd" },
|
||||
{ sizeof("Enum_Body"), "Enum_Body" },
|
||||
{ sizeof("Enum_Class"), "Enum_Class" },
|
||||
{ sizeof("Enum_Class_Fwd"), "Enum_Class_Fwd" },
|
||||
{ sizeof("Execution"), "Execution" },
|
||||
{ sizeof("Export_Body"), "Export_Body" },
|
||||
{ sizeof("Extern_Linkage"), "Extern_Linkage" },
|
||||
{ sizeof("Extern_Linkage_Body"), "Extern_Linkage_Body" },
|
||||
{ sizeof("Friend"), "Friend" },
|
||||
{ sizeof("Function"), "Function" },
|
||||
{ sizeof("Function_Fwd"), "Function_Fwd" },
|
||||
{ sizeof("Function_Body"), "Function_Body" },
|
||||
{ sizeof("Global_Body"), "Global_Body" },
|
||||
{ sizeof("Module"), "Module" },
|
||||
{ sizeof("Namespace"), "Namespace" },
|
||||
{ sizeof("Namespace_Body"), "Namespace_Body" },
|
||||
{ sizeof("Operator"), "Operator" },
|
||||
{ sizeof("Operator_Fwd"), "Operator_Fwd" },
|
||||
{ sizeof("Operator_Member"), "Operator_Member" },
|
||||
{ sizeof("Operator_Member_Fwd"), "Operator_Member_Fwd" },
|
||||
{ sizeof("Operator_Cast"), "Operator_Cast" },
|
||||
{ sizeof("Operator_Cast_Fwd"), "Operator_Cast_Fwd" },
|
||||
{ sizeof("Parameters"), "Parameters" },
|
||||
{ sizeof("Preprocess_Define"), "Preprocess_Define" },
|
||||
{ sizeof("Preprocess_Include"), "Preprocess_Include" },
|
||||
{ sizeof("Preprocess_If"), "Preprocess_If" },
|
||||
{ sizeof("Preprocess_IfDef"), "Preprocess_IfDef" },
|
||||
{ sizeof("Preprocess_IfNotDef"), "Preprocess_IfNotDef" },
|
||||
{ sizeof("Preprocess_ElIf"), "Preprocess_ElIf" },
|
||||
{ sizeof("Preprocess_Else"), "Preprocess_Else" },
|
||||
{ sizeof("Preprocess_EndIf"), "Preprocess_EndIf" },
|
||||
{ sizeof("Preprocess_Pragma"), "Preprocess_Pragma" },
|
||||
{ sizeof("Specifiers"), "Specifiers" },
|
||||
{ sizeof("Struct"), "Struct" },
|
||||
{ sizeof("Struct_Fwd"), "Struct_Fwd" },
|
||||
{ sizeof("Struct_Body"), "Struct_Body" },
|
||||
{ sizeof("Template"), "Template" },
|
||||
{ sizeof("Typedef"), "Typedef" },
|
||||
{ sizeof("Typename"), "Typename" },
|
||||
{ sizeof("Union"), "Union" },
|
||||
{ sizeof("Union_Fwd"), "Union_Fwd" },
|
||||
{ sizeof("Union_Body"), "Union_Body" },
|
||||
{ sizeof("Using"), "Using" },
|
||||
{ sizeof("Using_Namespace"), "Using_Namespace" },
|
||||
{ sizeof("Variable"), "Variable" },
|
||||
}; return lookup[ type ];
|
||||
local_persist StrC lookup[61] = {
|
||||
{ sizeof( "Invalid" ), "Invalid" },
|
||||
{ sizeof( "Untyped" ), "Untyped" },
|
||||
{ sizeof( "NewLine" ), "NewLine" },
|
||||
{ sizeof( "Comment" ), "Comment" },
|
||||
{ sizeof( "Access_Private" ), "Access_Private" },
|
||||
{ sizeof( "Access_Protected" ), "Access_Protected" },
|
||||
{ sizeof( "Access_Public" ), "Access_Public" },
|
||||
{ sizeof( "PlatformAttributes" ), "PlatformAttributes" },
|
||||
{ sizeof( "Class" ), "Class" },
|
||||
{ sizeof( "Class_Fwd" ), "Class_Fwd" },
|
||||
{ sizeof( "Class_Body" ), "Class_Body" },
|
||||
{ sizeof( "Constructor" ), "Constructor" },
|
||||
{ sizeof( "Constructor_Fwd" ), "Constructor_Fwd" },
|
||||
{ sizeof( "Destructor" ), "Destructor" },
|
||||
{ sizeof( "Destructor_Fwd" ), "Destructor_Fwd" },
|
||||
{ sizeof( "Enum" ), "Enum" },
|
||||
{ sizeof( "Enum_Fwd" ), "Enum_Fwd" },
|
||||
{ sizeof( "Enum_Body" ), "Enum_Body" },
|
||||
{ sizeof( "Enum_Class" ), "Enum_Class" },
|
||||
{ sizeof( "Enum_Class_Fwd" ), "Enum_Class_Fwd" },
|
||||
{ sizeof( "Execution" ), "Execution" },
|
||||
{ sizeof( "Export_Body" ), "Export_Body" },
|
||||
{ sizeof( "Extern_Linkage" ), "Extern_Linkage" },
|
||||
{ sizeof( "Extern_Linkage_Body" ), "Extern_Linkage_Body" },
|
||||
{ sizeof( "Friend" ), "Friend" },
|
||||
{ sizeof( "Function" ), "Function" },
|
||||
{ sizeof( "Function_Fwd" ), "Function_Fwd" },
|
||||
{ sizeof( "Function_Body" ), "Function_Body" },
|
||||
{ sizeof( "Global_Body" ), "Global_Body" },
|
||||
{ sizeof( "Module" ), "Module" },
|
||||
{ sizeof( "Namespace" ), "Namespace" },
|
||||
{ sizeof( "Namespace_Body" ), "Namespace_Body" },
|
||||
{ sizeof( "Operator" ), "Operator" },
|
||||
{ sizeof( "Operator_Fwd" ), "Operator_Fwd" },
|
||||
{ sizeof( "Operator_Member" ), "Operator_Member" },
|
||||
{ sizeof( "Operator_Member_Fwd" ), "Operator_Member_Fwd" },
|
||||
{ sizeof( "Operator_Cast" ), "Operator_Cast" },
|
||||
{ sizeof( "Operator_Cast_Fwd" ), "Operator_Cast_Fwd" },
|
||||
{ sizeof( "Parameters" ), "Parameters" },
|
||||
{ sizeof( "Preprocess_Define" ), "Preprocess_Define" },
|
||||
{ sizeof( "Preprocess_Include" ), "Preprocess_Include" },
|
||||
{ sizeof( "Preprocess_If" ), "Preprocess_If" },
|
||||
{ sizeof( "Preprocess_IfDef" ), "Preprocess_IfDef" },
|
||||
{ sizeof( "Preprocess_IfNotDef" ), "Preprocess_IfNotDef" },
|
||||
{ sizeof( "Preprocess_ElIf" ), "Preprocess_ElIf" },
|
||||
{ sizeof( "Preprocess_Else" ), "Preprocess_Else" },
|
||||
{ sizeof( "Preprocess_EndIf" ), "Preprocess_EndIf" },
|
||||
{ sizeof( "Preprocess_Pragma" ), "Preprocess_Pragma" },
|
||||
{ sizeof( "Specifiers" ), "Specifiers" },
|
||||
{ sizeof( "Struct" ), "Struct" },
|
||||
{ sizeof( "Struct_Fwd" ), "Struct_Fwd" },
|
||||
{ sizeof( "Struct_Body" ), "Struct_Body" },
|
||||
{ sizeof( "Template" ), "Template" },
|
||||
{ sizeof( "Typedef" ), "Typedef" },
|
||||
{ sizeof( "Typename" ), "Typename" },
|
||||
{ sizeof( "Union" ), "Union" },
|
||||
{ sizeof( "Union_Fwd" ), "Union_Fwd" },
|
||||
{ sizeof( "Union_Body" ), "Union_Body" },
|
||||
{ sizeof( "Using" ), "Using" },
|
||||
{ sizeof( "Using_Namespace" ), "Using_Namespace" },
|
||||
{ sizeof( "Variable" ), "Variable" },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline StrC codetype_to_keyword_str( CodeType type )
|
||||
{
|
||||
local_persist StrC lookup[61] = {
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "//" ), "//" },
|
||||
{ sizeof( "private" ), "private" },
|
||||
{ sizeof( "protected" ), "protected" },
|
||||
{ sizeof( "public" ), "public" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "class" ), "class" },
|
||||
{ sizeof( "clsss" ), "clsss" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "enum" ), "enum" },
|
||||
{ sizeof( "enum" ), "enum" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "enum class" ), "enum class" },
|
||||
{ sizeof( "enum class" ), "enum class" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "extern" ), "extern" },
|
||||
{ sizeof( "extern" ), "extern" },
|
||||
{ sizeof( "friend" ), "friend" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "module" ), "module" },
|
||||
{ sizeof( "namespace" ), "namespace" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "operator" ), "operator" },
|
||||
{ sizeof( "operator" ), "operator" },
|
||||
{ sizeof( "operator" ), "operator" },
|
||||
{ sizeof( "operator" ), "operator" },
|
||||
{ sizeof( "operator" ), "operator" },
|
||||
{ sizeof( "operator" ), "operator" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "define" ), "define" },
|
||||
{ sizeof( "include" ), "include" },
|
||||
{ sizeof( "if" ), "if" },
|
||||
{ sizeof( "ifdef" ), "ifdef" },
|
||||
{ sizeof( "ifndef" ), "ifndef" },
|
||||
{ sizeof( "elif" ), "elif" },
|
||||
{ sizeof( "else" ), "else" },
|
||||
{ sizeof( "endif" ), "endif" },
|
||||
{ sizeof( "pragma" ), "pragma" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "struct" ), "struct" },
|
||||
{ sizeof( "struct" ), "struct" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "template" ), "template" },
|
||||
{ sizeof( "typedef" ), "typedef" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "union" ), "union" },
|
||||
{ sizeof( "union" ), "union" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
{ sizeof( "using" ), "using" },
|
||||
{ sizeof( "using namespace" ), "using namespace" },
|
||||
{ sizeof( "__NA__" ), "__NA__" },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
forceinline StrC to_str( CodeType type )
|
||||
{
|
||||
return codetype_to_str( type );
|
||||
}
|
||||
|
||||
forceinline StrC to_keyword_str( CodeType type )
|
||||
{
|
||||
return codetype_to_keyword_str( type );
|
||||
}
|
||||
|
@ -7,59 +7,111 @@
|
||||
|
||||
enum Operator : u32
|
||||
{
|
||||
Op_Invalid,Op_Assign,Op_Assign_Add,Op_Assign_Subtract,Op_Assign_Multiply,Op_Assign_Divide,Op_Assign_Modulo,Op_Assign_BAnd,Op_Assign_BOr,Op_Assign_BXOr,Op_Assign_LShift,Op_Assign_RShift,Op_Increment,Op_Decrement,Op_Unary_Plus,Op_Unary_Minus,Op_UnaryNot,Op_Add,Op_Subtract,Op_Multiply,Op_Divide,Op_Modulo,Op_BNot,Op_BAnd,Op_BOr,Op_BXOr,Op_LShift,Op_RShift,Op_LAnd,Op_LOr,Op_LEqual,Op_LNot,Op_Lesser,Op_Greater,Op_LesserEqual,Op_GreaterEqual,Op_Subscript,Op_Indirection,Op_AddressOf,Op_MemberOfPointer,Op_PtrToMemOfPtr,Op_FunctionCall,Op_Comma,Op_New,Op_NewArray,Op_Delete,Op_DeleteArray,NumOps
|
||||
Op_Invalid,
|
||||
Op_Assign,
|
||||
Op_Assign_Add,
|
||||
Op_Assign_Subtract,
|
||||
Op_Assign_Multiply,
|
||||
Op_Assign_Divide,
|
||||
Op_Assign_Modulo,
|
||||
Op_Assign_BAnd,
|
||||
Op_Assign_BOr,
|
||||
Op_Assign_BXOr,
|
||||
Op_Assign_LShift,
|
||||
Op_Assign_RShift,
|
||||
Op_Increment,
|
||||
Op_Decrement,
|
||||
Op_Unary_Plus,
|
||||
Op_Unary_Minus,
|
||||
Op_UnaryNot,
|
||||
Op_Add,
|
||||
Op_Subtract,
|
||||
Op_Multiply,
|
||||
Op_Divide,
|
||||
Op_Modulo,
|
||||
Op_BNot,
|
||||
Op_BAnd,
|
||||
Op_BOr,
|
||||
Op_BXOr,
|
||||
Op_LShift,
|
||||
Op_RShift,
|
||||
Op_LAnd,
|
||||
Op_LOr,
|
||||
Op_LEqual,
|
||||
Op_LNot,
|
||||
Op_Lesser,
|
||||
Op_Greater,
|
||||
Op_LesserEqual,
|
||||
Op_GreaterEqual,
|
||||
Op_Subscript,
|
||||
Op_Indirection,
|
||||
Op_AddressOf,
|
||||
Op_MemberOfPointer,
|
||||
Op_PtrToMemOfPtr,
|
||||
Op_FunctionCall,
|
||||
Op_Comma,
|
||||
Op_New,
|
||||
Op_NewArray,
|
||||
Op_Delete,
|
||||
Op_DeleteArray,
|
||||
NumOps
|
||||
};
|
||||
typedef enum Operator Operator;
|
||||
inline
|
||||
StrC operator_to_str( Operator op)
|
||||
|
||||
inline StrC operator_to_str( Operator op )
|
||||
{
|
||||
local_persist StrC lookup[47] = { { sizeof("INVALID"), "INVALID" },
|
||||
{ sizeof("="), "=" },
|
||||
{ sizeof("+="), "+=" },
|
||||
{ sizeof("-="), "-=" },
|
||||
{ sizeof("*="), "*=" },
|
||||
{ sizeof("/="), "/=" },
|
||||
{ sizeof("%="), "%=" },
|
||||
{ sizeof("&="), "&=" },
|
||||
{ sizeof("|="), "|=" },
|
||||
{ sizeof("^="), "^=" },
|
||||
{ sizeof("<<="), "<<=" },
|
||||
{ sizeof(">>="), ">>=" },
|
||||
{ sizeof("++"), "++" },
|
||||
{ sizeof("--"), "--" },
|
||||
{ sizeof("+"), "+" },
|
||||
{ sizeof("-"), "-" },
|
||||
{ sizeof("!"), "!" },
|
||||
{ sizeof("+"), "+" },
|
||||
{ sizeof("-"), "-" },
|
||||
{ sizeof("*"), "*" },
|
||||
{ sizeof("/"), "/" },
|
||||
{ sizeof("%"), "%" },
|
||||
{ sizeof("~"), "~" },
|
||||
{ sizeof("&"), "&" },
|
||||
{ sizeof("|"), "|" },
|
||||
{ sizeof("^"), "^" },
|
||||
{ sizeof("<<"), "<<" },
|
||||
{ sizeof(">>"), ">>" },
|
||||
{ sizeof("&&"), "&&" },
|
||||
{ sizeof("||"), "||" },
|
||||
{ sizeof("=="), "==" },
|
||||
{ sizeof("!="), "!=" },
|
||||
{ sizeof("<"), "<" },
|
||||
{ sizeof(">"), ">" },
|
||||
{ sizeof("<="), "<=" },
|
||||
{ sizeof(">="), ">=" },
|
||||
{ sizeof("[]"), "[]" },
|
||||
{ sizeof("*"), "*" },
|
||||
{ sizeof("&"), "&" },
|
||||
{ sizeof("->"), "->" },
|
||||
{ sizeof("->*"), "->*" },
|
||||
{ sizeof("()"), "()" },
|
||||
{ sizeof(","), "," },
|
||||
{ sizeof("new"), "new" },
|
||||
{ sizeof("new[]"), "new[]" },
|
||||
{ sizeof("delete"), "delete" },
|
||||
{ sizeof("delete[]"), "delete[]" },
|
||||
}; return lookup[ op ];
|
||||
local_persist StrC lookup[47] = {
|
||||
{ sizeof( "INVALID" ), "INVALID" },
|
||||
{ sizeof( "=" ), "=" },
|
||||
{ sizeof( "+=" ), "+=" },
|
||||
{ sizeof( "-=" ), "-=" },
|
||||
{ sizeof( "*=" ), "*=" },
|
||||
{ sizeof( "/=" ), "/=" },
|
||||
{ sizeof( "%=" ), "%=" },
|
||||
{ sizeof( "&=" ), "&=" },
|
||||
{ sizeof( "|=" ), "|=" },
|
||||
{ sizeof( "^=" ), "^=" },
|
||||
{ sizeof( "<<=" ), "<<=" },
|
||||
{ sizeof( ">>=" ), ">>=" },
|
||||
{ sizeof( "++" ), "++" },
|
||||
{ sizeof( "--" ), "--" },
|
||||
{ sizeof( "+" ), "+" },
|
||||
{ sizeof( "-" ), "-" },
|
||||
{ sizeof( "!" ), "!" },
|
||||
{ sizeof( "+" ), "+" },
|
||||
{ sizeof( "-" ), "-" },
|
||||
{ sizeof( "*" ), "*" },
|
||||
{ sizeof( "/" ), "/" },
|
||||
{ sizeof( "%" ), "%" },
|
||||
{ sizeof( "~" ), "~" },
|
||||
{ sizeof( "&" ), "&" },
|
||||
{ sizeof( "|" ), "|" },
|
||||
{ sizeof( "^" ), "^" },
|
||||
{ sizeof( "<<" ), "<<" },
|
||||
{ sizeof( ">>" ), ">>" },
|
||||
{ sizeof( "&&" ), "&&" },
|
||||
{ sizeof( "||" ), "||" },
|
||||
{ sizeof( "==" ), "==" },
|
||||
{ sizeof( "!=" ), "!=" },
|
||||
{ sizeof( "<" ), "<" },
|
||||
{ sizeof( ">" ), ">" },
|
||||
{ sizeof( "<=" ), "<=" },
|
||||
{ sizeof( ">=" ), ">=" },
|
||||
{ sizeof( "[]" ), "[]" },
|
||||
{ sizeof( "*" ), "*" },
|
||||
{ sizeof( "&" ), "&" },
|
||||
{ sizeof( "->" ), "->" },
|
||||
{ sizeof( "->*" ), "->*" },
|
||||
{ sizeof( "()" ), "()" },
|
||||
{ sizeof( "," ), "," },
|
||||
{ sizeof( "new" ), "new" },
|
||||
{ sizeof( "new[]" ), "new[]" },
|
||||
{ sizeof( "delete" ), "delete" },
|
||||
{ sizeof( "delete[]" ), "delete[]" },
|
||||
};
|
||||
return lookup[op];
|
||||
}
|
||||
|
||||
forceinline StrC to_str( Operator op )
|
||||
{
|
||||
return operator_to_str( op );
|
||||
}
|
||||
|
@ -7,48 +7,101 @@
|
||||
|
||||
enum Specifier : u32
|
||||
{
|
||||
Spec_Invalid,Spec_Consteval,Spec_Constexpr,Spec_Constinit,Spec_Explicit,Spec_External_Linkage,Spec_ForceInline,Spec_Global,Spec_Inline,Spec_Internal_Linkage,Spec_Local_Persist,Spec_Mutable,Spec_NeverInline,Spec_Ptr,Spec_Ref,Spec_Register,Spec_RValue,Spec_Static,Spec_Thread_Local,Spec_Virtual,Spec_Const,Spec_Final,Spec_NoExceptions,Spec_Override,Spec_Pure,Spec_Volatile,Spec_NumSpecifiers
|
||||
Spec_Invalid,
|
||||
Spec_Consteval,
|
||||
Spec_Constexpr,
|
||||
Spec_Constinit,
|
||||
Spec_Explicit,
|
||||
Spec_External_Linkage,
|
||||
Spec_ForceInline,
|
||||
Spec_Global,
|
||||
Spec_Inline,
|
||||
Spec_Internal_Linkage,
|
||||
Spec_Local_Persist,
|
||||
Spec_Mutable,
|
||||
Spec_NeverInline,
|
||||
Spec_Ptr,
|
||||
Spec_Ref,
|
||||
Spec_Register,
|
||||
Spec_RValue,
|
||||
Spec_Static,
|
||||
Spec_Thread_Local,
|
||||
Spec_Virtual,
|
||||
Spec_Const,
|
||||
Spec_Final,
|
||||
Spec_NoExceptions,
|
||||
Spec_Override,
|
||||
Spec_Pure,
|
||||
Spec_Volatile,
|
||||
Spec_NumSpecifiers
|
||||
};
|
||||
typedef enum Specifier Specifier;
|
||||
inline
|
||||
bool spec_is_trailing( Specifier specifier)
|
||||
|
||||
inline StrC spec_to_str( Specifier type )
|
||||
{
|
||||
return specifier > Spec_Virtual;
|
||||
}
|
||||
inline
|
||||
StrC spec_to_str( Specifier type)
|
||||
{
|
||||
local_persist StrC lookup[26] = { { sizeof("INVALID"), "INVALID" },
|
||||
{ sizeof("consteval"), "consteval" },
|
||||
{ sizeof("constexpr"), "constexpr" },
|
||||
{ sizeof("constinit"), "constinit" },
|
||||
{ sizeof("explicit"), "explicit" },
|
||||
{ sizeof("extern"), "extern" },
|
||||
{ sizeof("forceinline"), "forceinline" },
|
||||
{ sizeof("global"), "global" },
|
||||
{ sizeof("inline"), "inline" },
|
||||
{ sizeof("internal"), "internal" },
|
||||
{ sizeof("local_persist"), "local_persist" },
|
||||
{ sizeof("mutable"), "mutable" },
|
||||
{ sizeof("neverinline"), "neverinline" },
|
||||
{ sizeof("*"), "*" },
|
||||
{ sizeof("&"), "&" },
|
||||
{ sizeof("register"), "register" },
|
||||
{ sizeof("&&"), "&&" },
|
||||
{ sizeof("static"), "static" },
|
||||
{ sizeof("thread_local"), "thread_local" },
|
||||
{ sizeof("virtual"), "virtual" },
|
||||
{ sizeof("const"), "const" },
|
||||
{ sizeof("final"), "final" },
|
||||
{ sizeof("noexcept"), "noexcept" },
|
||||
{ sizeof("override"), "override" },
|
||||
{ sizeof("= 0"), "= 0" },
|
||||
{ sizeof("volatile"), "volatile" },
|
||||
}; return lookup[ type ];
|
||||
}
|
||||
inline
|
||||
Specifier strc_to_specifier( StrC str)
|
||||
{
|
||||
local_persist u32 keymap[ Spec_NumSpecifiers ]; do_once_start for ( u32 index = 0; index < Spec_NumSpecifiers; index++ ) { StrC enum_str = spec_to_str( (Specifier)index ); keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1); } do_once_end u32 hash = crc32( str.Ptr, str.Len ); for ( u32 index = 0; index < Spec_NumSpecifiers; index++ ) { if ( keymap[index] == hash ) return (Specifier)index; } return Spec_Invalid;
|
||||
local_persist StrC lookup[26] = {
|
||||
{ sizeof( "INVALID" ), "INVALID" },
|
||||
{ sizeof( "consteval" ), "consteval" },
|
||||
{ sizeof( "constexpr" ), "constexpr" },
|
||||
{ sizeof( "constinit" ), "constinit" },
|
||||
{ sizeof( "explicit" ), "explicit" },
|
||||
{ sizeof( "extern" ), "extern" },
|
||||
{ sizeof( "forceinline" ), "forceinline" },
|
||||
{ sizeof( "global" ), "global" },
|
||||
{ sizeof( "inline" ), "inline" },
|
||||
{ sizeof( "internal" ), "internal" },
|
||||
{ sizeof( "local_persist" ), "local_persist" },
|
||||
{ sizeof( "mutable" ), "mutable" },
|
||||
{ sizeof( "neverinline" ), "neverinline" },
|
||||
{ sizeof( "*" ), "*" },
|
||||
{ sizeof( "&" ), "&" },
|
||||
{ sizeof( "register" ), "register" },
|
||||
{ sizeof( "&&" ), "&&" },
|
||||
{ sizeof( "static" ), "static" },
|
||||
{ sizeof( "thread_local" ), "thread_local" },
|
||||
{ sizeof( "virtual" ), "virtual" },
|
||||
{ sizeof( "const" ), "const" },
|
||||
{ sizeof( "final" ), "final" },
|
||||
{ sizeof( "noexcept" ), "noexcept" },
|
||||
{ sizeof( "override" ), "override" },
|
||||
{ sizeof( "= 0" ), "= 0" },
|
||||
{ sizeof( "volatile" ), "volatile" },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline bool spec_is_trailing( Specifier specifier )
|
||||
{
|
||||
return specifier > Spec_Virtual;
|
||||
}
|
||||
|
||||
inline Specifier strc_to_specifier( StrC str )
|
||||
{
|
||||
local_persist u32 keymap[Spec_NumSpecifiers];
|
||||
do_once_start for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
|
||||
{
|
||||
StrC enum_str = spec_to_str( (Specifier)index );
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
||||
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
return (Specifier)index;
|
||||
}
|
||||
return Spec_Invalid;
|
||||
}
|
||||
|
||||
forceinline StrC to_str( Specifier spec )
|
||||
{
|
||||
return spec_to_str( spec );
|
||||
}
|
||||
|
||||
forceinline Specifier to_type( StrC str )
|
||||
{
|
||||
return strc_to_specifier( str );
|
||||
}
|
||||
|
||||
forceinline bool is_trailing( Specifier specifier )
|
||||
{
|
||||
return spec_is_trailing( specifier );
|
||||
}
|
||||
|
@ -6,119 +6,230 @@
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
GEN_NS_PARSER_BEGIN
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) \
|
||||
Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" )
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" )
|
||||
|
||||
enum TokType_Def : u32
|
||||
{
|
||||
Tok_Invalid,Tok_Access_Private,Tok_Access_Protected,Tok_Access_Public,Tok_Access_MemberSymbol,Tok_Access_StaticSymbol,Tok_Ampersand,Tok_Ampersand_DBL,Tok_Assign_Classifer,Tok_Attribute_Open,Tok_Attribute_Close,Tok_BraceCurly_Open,Tok_BraceCurly_Close,Tok_BraceSquare_Open,Tok_BraceSquare_Close,Tok_Capture_Start,Tok_Capture_End,Tok_Comment,Tok_Comment_End,Tok_Comment_Start,Tok_Char,Tok_Comma,Tok_Decl_Class,Tok_Decl_GNU_Attribute,Tok_Decl_MSVC_Attribute,Tok_Decl_Enum,Tok_Decl_Extern_Linkage,Tok_Decl_Friend,Tok_Decl_Module,Tok_Decl_Namespace,Tok_Decl_Operator,Tok_Decl_Struct,Tok_Decl_Template,Tok_Decl_Typedef,Tok_Decl_Using,Tok_Decl_Union,Tok_Identifier,Tok_Module_Import,Tok_Module_Export,Tok_NewLine,Tok_Number,Tok_Operator,Tok_Preprocess_Hash,Tok_Preprocess_Define,Tok_Preprocess_If,Tok_Preprocess_IfDef,Tok_Preprocess_IfNotDef,Tok_Preprocess_ElIf,Tok_Preprocess_Else,Tok_Preprocess_EndIf,Tok_Preprocess_Include,Tok_Preprocess_Pragma,Tok_Preprocess_Content,Tok_Preprocess_Macro,Tok_Preprocess_Unsupported,Tok_Spec_Alignas,Tok_Spec_Const,Tok_Spec_Consteval,Tok_Spec_Constexpr,Tok_Spec_Constinit,Tok_Spec_Explicit,Tok_Spec_Extern,Tok_Spec_Final,Tok_Spec_ForceInline,Tok_Spec_Global,Tok_Spec_Inline,Tok_Spec_Internal_Linkage,Tok_Spec_LocalPersist,Tok_Spec_Mutable,Tok_Spec_NeverInline,Tok_Spec_Override,Tok_Spec_Static,Tok_Spec_ThreadLocal,Tok_Spec_Volatile,Tok_Spec_Virtual,Tok_Star,Tok_Statement_End,Tok_StaticAssert,Tok_String,Tok_Type_Typename,Tok_Type_Unsigned,Tok_Type_Signed,Tok_Type_Short,Tok_Type_Long,Tok_Type_bool,Tok_Type_char,Tok_Type_int,Tok_Type_double,Tok_Type_MS_int8,Tok_Type_MS_int16,Tok_Type_MS_int32,Tok_Type_MS_int64,Tok_Type_MS_W64,Tok_Varadic_Argument,Tok___Attributes_Start,Tok_Attribute_API_Export,Tok_Attribute_API_Import,Tok_NumTokens
|
||||
Tok_Invalid,
|
||||
Tok_Access_Private,
|
||||
Tok_Access_Protected,
|
||||
Tok_Access_Public,
|
||||
Tok_Access_MemberSymbol,
|
||||
Tok_Access_StaticSymbol,
|
||||
Tok_Ampersand,
|
||||
Tok_Ampersand_DBL,
|
||||
Tok_Assign_Classifer,
|
||||
Tok_Attribute_Open,
|
||||
Tok_Attribute_Close,
|
||||
Tok_BraceCurly_Open,
|
||||
Tok_BraceCurly_Close,
|
||||
Tok_BraceSquare_Open,
|
||||
Tok_BraceSquare_Close,
|
||||
Tok_Capture_Start,
|
||||
Tok_Capture_End,
|
||||
Tok_Comment,
|
||||
Tok_Comment_End,
|
||||
Tok_Comment_Start,
|
||||
Tok_Char,
|
||||
Tok_Comma,
|
||||
Tok_Decl_Class,
|
||||
Tok_Decl_GNU_Attribute,
|
||||
Tok_Decl_MSVC_Attribute,
|
||||
Tok_Decl_Enum,
|
||||
Tok_Decl_Extern_Linkage,
|
||||
Tok_Decl_Friend,
|
||||
Tok_Decl_Module,
|
||||
Tok_Decl_Namespace,
|
||||
Tok_Decl_Operator,
|
||||
Tok_Decl_Struct,
|
||||
Tok_Decl_Template,
|
||||
Tok_Decl_Typedef,
|
||||
Tok_Decl_Using,
|
||||
Tok_Decl_Union,
|
||||
Tok_Identifier,
|
||||
Tok_Module_Import,
|
||||
Tok_Module_Export,
|
||||
Tok_NewLine,
|
||||
Tok_Number,
|
||||
Tok_Operator,
|
||||
Tok_Preprocess_Hash,
|
||||
Tok_Preprocess_Define,
|
||||
Tok_Preprocess_If,
|
||||
Tok_Preprocess_IfDef,
|
||||
Tok_Preprocess_IfNotDef,
|
||||
Tok_Preprocess_ElIf,
|
||||
Tok_Preprocess_Else,
|
||||
Tok_Preprocess_EndIf,
|
||||
Tok_Preprocess_Include,
|
||||
Tok_Preprocess_Pragma,
|
||||
Tok_Preprocess_Content,
|
||||
Tok_Preprocess_Macro,
|
||||
Tok_Preprocess_Unsupported,
|
||||
Tok_Spec_Alignas,
|
||||
Tok_Spec_Const,
|
||||
Tok_Spec_Consteval,
|
||||
Tok_Spec_Constexpr,
|
||||
Tok_Spec_Constinit,
|
||||
Tok_Spec_Explicit,
|
||||
Tok_Spec_Extern,
|
||||
Tok_Spec_Final,
|
||||
Tok_Spec_ForceInline,
|
||||
Tok_Spec_Global,
|
||||
Tok_Spec_Inline,
|
||||
Tok_Spec_Internal_Linkage,
|
||||
Tok_Spec_LocalPersist,
|
||||
Tok_Spec_Mutable,
|
||||
Tok_Spec_NeverInline,
|
||||
Tok_Spec_Override,
|
||||
Tok_Spec_Static,
|
||||
Tok_Spec_ThreadLocal,
|
||||
Tok_Spec_Volatile,
|
||||
Tok_Spec_Virtual,
|
||||
Tok_Star,
|
||||
Tok_Statement_End,
|
||||
Tok_StaticAssert,
|
||||
Tok_String,
|
||||
Tok_Type_Typename,
|
||||
Tok_Type_Unsigned,
|
||||
Tok_Type_Signed,
|
||||
Tok_Type_Short,
|
||||
Tok_Type_Long,
|
||||
Tok_Type_bool,
|
||||
Tok_Type_char,
|
||||
Tok_Type_int,
|
||||
Tok_Type_double,
|
||||
Tok_Type_MS_int8,
|
||||
Tok_Type_MS_int16,
|
||||
Tok_Type_MS_int32,
|
||||
Tok_Type_MS_int64,
|
||||
Tok_Type_MS_W64,
|
||||
Tok_Varadic_Argument,
|
||||
Tok___Attributes_Start,
|
||||
Tok_Attribute_API_Export,
|
||||
Tok_Attribute_API_Import,
|
||||
Tok_NumTokens
|
||||
};
|
||||
typedef enum TokType_Def TokType;
|
||||
inline
|
||||
StrC to_str( TokType type)
|
||||
|
||||
inline StrC to_str( TokType type )
|
||||
{
|
||||
local_persist StrC lookup[] { { sizeof("__invalid__"), "__invalid__" },
|
||||
{ sizeof("private"), "private" },
|
||||
{ sizeof("protected"), "protected" },
|
||||
{ sizeof("public"), "public" },
|
||||
{ sizeof("."), "." },
|
||||
{ sizeof("::"), "::" },
|
||||
{ sizeof("&"), "&" },
|
||||
{ sizeof("&&"), "&&" },
|
||||
{ sizeof(":"), ":" },
|
||||
{ sizeof("[["), "[[" },
|
||||
{ sizeof("]]"), "]]" },
|
||||
{ sizeof("{"), "{" },
|
||||
{ sizeof("}"), "}" },
|
||||
{ sizeof("["), "[" },
|
||||
{ sizeof("]"), "]" },
|
||||
{ sizeof("("), "(" },
|
||||
{ sizeof(")"), ")" },
|
||||
{ sizeof("__comment__"), "__comment__" },
|
||||
{ sizeof("__comment_end__"), "__comment_end__" },
|
||||
{ sizeof("__comment_start__"), "__comment_start__" },
|
||||
{ sizeof("__character__"), "__character__" },
|
||||
{ sizeof(","), "," },
|
||||
{ sizeof("class"), "class" },
|
||||
{ sizeof("__attribute__"), "__attribute__" },
|
||||
{ sizeof("__declspec"), "__declspec" },
|
||||
{ sizeof("enum"), "enum" },
|
||||
{ sizeof("extern"), "extern" },
|
||||
{ sizeof("friend"), "friend" },
|
||||
{ sizeof("module"), "module" },
|
||||
{ sizeof("namespace"), "namespace" },
|
||||
{ sizeof("operator"), "operator" },
|
||||
{ sizeof("struct"), "struct" },
|
||||
{ sizeof("template"), "template" },
|
||||
{ sizeof("typedef"), "typedef" },
|
||||
{ sizeof("using"), "using" },
|
||||
{ sizeof("union"), "union" },
|
||||
{ sizeof("__identifier__"), "__identifier__" },
|
||||
{ sizeof("import"), "import" },
|
||||
{ sizeof("export"), "export" },
|
||||
{ sizeof("__new_line__"), "__new_line__" },
|
||||
{ sizeof("__number__"), "__number__" },
|
||||
{ sizeof("__operator__"), "__operator__" },
|
||||
{ sizeof("#"), "#" },
|
||||
{ sizeof("define"), "define" },
|
||||
{ sizeof("if"), "if" },
|
||||
{ sizeof("ifdef"), "ifdef" },
|
||||
{ sizeof("ifndef"), "ifndef" },
|
||||
{ sizeof("elif"), "elif" },
|
||||
{ sizeof("else"), "else" },
|
||||
{ sizeof("endif"), "endif" },
|
||||
{ sizeof("include"), "include" },
|
||||
{ sizeof("pragma"), "pragma" },
|
||||
{ sizeof("__macro_content__"), "__macro_content__" },
|
||||
{ sizeof("__macro__"), "__macro__" },
|
||||
{ sizeof("__unsupported__"), "__unsupported__" },
|
||||
{ sizeof("alignas"), "alignas" },
|
||||
{ sizeof("const"), "const" },
|
||||
{ sizeof("consteval"), "consteval" },
|
||||
{ sizeof("constexpr"), "constexpr" },
|
||||
{ sizeof("constinit"), "constinit" },
|
||||
{ sizeof("explicit"), "explicit" },
|
||||
{ sizeof("extern"), "extern" },
|
||||
{ sizeof("final"), "final" },
|
||||
{ sizeof("forceinline"), "forceinline" },
|
||||
{ sizeof("global"), "global" },
|
||||
{ sizeof("inline"), "inline" },
|
||||
{ sizeof("internal"), "internal" },
|
||||
{ sizeof("local_persist"), "local_persist" },
|
||||
{ sizeof("mutable"), "mutable" },
|
||||
{ sizeof("neverinline"), "neverinline" },
|
||||
{ sizeof("override"), "override" },
|
||||
{ sizeof("static"), "static" },
|
||||
{ sizeof("thread_local"), "thread_local" },
|
||||
{ sizeof("volatile"), "volatile" },
|
||||
{ sizeof("virtual"), "virtual" },
|
||||
{ sizeof("*"), "*" },
|
||||
{ sizeof(";"), ";" },
|
||||
{ sizeof("static_assert"), "static_assert" },
|
||||
{ sizeof("__string__"), "__string__" },
|
||||
{ sizeof("typename"), "typename" },
|
||||
{ sizeof("unsigned"), "unsigned" },
|
||||
{ sizeof("signed"), "signed" },
|
||||
{ sizeof("short"), "short" },
|
||||
{ sizeof("long"), "long" },
|
||||
{ sizeof("bool"), "bool" },
|
||||
{ sizeof("char"), "char" },
|
||||
{ sizeof("int"), "int" },
|
||||
{ sizeof("double"), "double" },
|
||||
{ sizeof("__int8"), "__int8" },
|
||||
{ sizeof("__int16"), "__int16" },
|
||||
{ sizeof("__int32"), "__int32" },
|
||||
{ sizeof("__int64"), "__int64" },
|
||||
{ sizeof("_W64"), "_W64" },
|
||||
{ sizeof("..."), "..." },
|
||||
{ sizeof("__attrib_start__"), "__attrib_start__" },
|
||||
{ sizeof("GEN_API_Export_Code"), "GEN_API_Export_Code" },
|
||||
{ sizeof("GEN_API_Import_Code"), "GEN_API_Import_Code" },
|
||||
}; return lookup[ type ];
|
||||
local_persist StrC lookup[] {
|
||||
{ sizeof( "__invalid__" ), "__invalid__" },
|
||||
{ sizeof( "private" ), "private" },
|
||||
{ sizeof( "protected" ), "protected" },
|
||||
{ sizeof( "public" ), "public" },
|
||||
{ sizeof( "." ), "." },
|
||||
{ sizeof( "::" ), "::" },
|
||||
{ sizeof( "&" ), "&" },
|
||||
{ sizeof( "&&" ), "&&" },
|
||||
{ sizeof( ":" ), ":" },
|
||||
{ sizeof( "[[" ), "[[" },
|
||||
{ sizeof( "]]" ), "]]" },
|
||||
{ sizeof( "{" ), "{" },
|
||||
{ sizeof( "}" ), "}" },
|
||||
{ sizeof( "[" ), "[" },
|
||||
{ sizeof( "]" ), "]" },
|
||||
{ sizeof( "(" ), "(" },
|
||||
{ sizeof( ")" ), ")" },
|
||||
{ sizeof( "__comment__" ), "__comment__" },
|
||||
{ sizeof( "__comment_end__" ), "__comment_end__" },
|
||||
{ sizeof( "__comment_start__" ), "__comment_start__" },
|
||||
{ sizeof( "__character__" ), "__character__" },
|
||||
{ sizeof( "," ), "," },
|
||||
{ sizeof( "class" ), "class" },
|
||||
{ sizeof( "__attribute__" ), "__attribute__" },
|
||||
{ sizeof( "__declspec" ), "__declspec" },
|
||||
{ sizeof( "enum" ), "enum" },
|
||||
{ sizeof( "extern" ), "extern" },
|
||||
{ sizeof( "friend" ), "friend" },
|
||||
{ sizeof( "module" ), "module" },
|
||||
{ sizeof( "namespace" ), "namespace" },
|
||||
{ sizeof( "operator" ), "operator" },
|
||||
{ sizeof( "struct" ), "struct" },
|
||||
{ sizeof( "template" ), "template" },
|
||||
{ sizeof( "typedef" ), "typedef" },
|
||||
{ sizeof( "using" ), "using" },
|
||||
{ sizeof( "union" ), "union" },
|
||||
{ sizeof( "__identifier__" ), "__identifier__" },
|
||||
{ sizeof( "import" ), "import" },
|
||||
{ sizeof( "export" ), "export" },
|
||||
{ sizeof( "__new_line__" ), "__new_line__" },
|
||||
{ sizeof( "__number__" ), "__number__" },
|
||||
{ sizeof( "__operator__" ), "__operator__" },
|
||||
{ sizeof( "#" ), "#" },
|
||||
{ sizeof( "define" ), "define" },
|
||||
{ sizeof( "if" ), "if" },
|
||||
{ sizeof( "ifdef" ), "ifdef" },
|
||||
{ sizeof( "ifndef" ), "ifndef" },
|
||||
{ sizeof( "elif" ), "elif" },
|
||||
{ sizeof( "else" ), "else" },
|
||||
{ sizeof( "endif" ), "endif" },
|
||||
{ sizeof( "include" ), "include" },
|
||||
{ sizeof( "pragma" ), "pragma" },
|
||||
{ sizeof( "__macro_content__" ), "__macro_content__" },
|
||||
{ sizeof( "__macro__" ), "__macro__" },
|
||||
{ sizeof( "__unsupported__" ), "__unsupported__" },
|
||||
{ sizeof( "alignas" ), "alignas" },
|
||||
{ sizeof( "const" ), "const" },
|
||||
{ sizeof( "consteval" ), "consteval" },
|
||||
{ sizeof( "constexpr" ), "constexpr" },
|
||||
{ sizeof( "constinit" ), "constinit" },
|
||||
{ sizeof( "explicit" ), "explicit" },
|
||||
{ sizeof( "extern" ), "extern" },
|
||||
{ sizeof( "final" ), "final" },
|
||||
{ sizeof( "forceinline" ), "forceinline" },
|
||||
{ sizeof( "global" ), "global" },
|
||||
{ sizeof( "inline" ), "inline" },
|
||||
{ sizeof( "internal" ), "internal" },
|
||||
{ sizeof( "local_persist" ), "local_persist" },
|
||||
{ sizeof( "mutable" ), "mutable" },
|
||||
{ sizeof( "neverinline" ), "neverinline" },
|
||||
{ sizeof( "override" ), "override" },
|
||||
{ sizeof( "static" ), "static" },
|
||||
{ sizeof( "thread_local" ), "thread_local" },
|
||||
{ sizeof( "volatile" ), "volatile" },
|
||||
{ sizeof( "virtual" ), "virtual" },
|
||||
{ sizeof( "*" ), "*" },
|
||||
{ sizeof( ";" ), ";" },
|
||||
{ sizeof( "static_assert" ), "static_assert" },
|
||||
{ sizeof( "__string__" ), "__string__" },
|
||||
{ sizeof( "typename" ), "typename" },
|
||||
{ sizeof( "unsigned" ), "unsigned" },
|
||||
{ sizeof( "signed" ), "signed" },
|
||||
{ sizeof( "short" ), "short" },
|
||||
{ sizeof( "long" ), "long" },
|
||||
{ sizeof( "bool" ), "bool" },
|
||||
{ sizeof( "char" ), "char" },
|
||||
{ sizeof( "int" ), "int" },
|
||||
{ sizeof( "double" ), "double" },
|
||||
{ sizeof( "__int8" ), "__int8" },
|
||||
{ sizeof( "__int16" ), "__int16" },
|
||||
{ sizeof( "__int32" ), "__int32" },
|
||||
{ sizeof( "__int64" ), "__int64" },
|
||||
{ sizeof( "_W64" ), "_W64" },
|
||||
{ sizeof( "..." ), "..." },
|
||||
{ sizeof( "__attrib_start__" ), "__attrib_start__" },
|
||||
{ sizeof( "GEN_API_Export_Code" ), "GEN_API_Export_Code" },
|
||||
{ sizeof( "GEN_API_Import_Code" ), "GEN_API_Import_Code" },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
inline
|
||||
TokType to_toktype( StrC str)
|
||||
|
||||
inline TokType to_toktype( StrC str )
|
||||
{
|
||||
local_persist u32 keymap[ Tok_NumTokens ]; do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ ) { StrC enum_str = to_str( (TokType)index ); keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1); } do_once_end u32 hash = crc32( str.Ptr, str.Len ); for ( u32 index = 0; index < Tok_NumTokens; index++ ) { if ( keymap[index] == hash ) return (TokType)index; } return Tok_Invalid;
|
||||
local_persist u32 keymap[Tok_NumTokens];
|
||||
do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (TokType)index );
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
||||
for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
return (TokType)index;
|
||||
}
|
||||
return Tok_Invalid;
|
||||
}
|
||||
|
||||
GEN_NS_PARSER_END
|
||||
|
@ -25,7 +25,7 @@
|
||||
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
||||
#endif
|
||||
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4)
|
||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(8)
|
||||
#endif
|
||||
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
||||
@ -42,7 +42,7 @@ constexpr s32 InitSize_DataArrays = 16;
|
||||
|
||||
// NOTE: This limits the maximum size of an allocation
|
||||
// If you are generating a string larger than this, increase the size of the bucket here.
|
||||
constexpr usize Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
|
||||
constexpr usize Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
|
||||
constexpr s32 CodePool_NumBlocks = GEN_CODEPOOL_NUM_BLOCKS;
|
||||
constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
|
||||
|
||||
@ -131,38 +131,12 @@ extern CodeTypename t_typename;
|
||||
|
||||
#pragma endregion Constants
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#ifndef token_fmt
|
||||
# define gen_main main
|
||||
|
||||
# define __ NullCode
|
||||
|
||||
// Convienence for defining any name used with the gen api.
|
||||
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
||||
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
|
||||
|
||||
// Same as name just used to indicate intention of literal for code instead of names.
|
||||
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
|
||||
|
||||
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
||||
|
||||
# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
|
||||
# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
|
||||
|
||||
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros
|
||||
|
||||
// Used by the lexer to persistently treat all these identifiers as preprocessor defines.
|
||||
// Populate with strings via gen::get_cached_string.
|
||||
// Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments.
|
||||
extern Array(StringCached) PreprocessorDefines;
|
||||
|
||||
#ifdef GEN_EXPOSE_BACKEND
|
||||
|
||||
// Global allocator used for data with process lifetime.
|
||||
extern AllocatorInfo GlobalAllocator;
|
||||
extern Array(Arena) Global_AllocatorBuckets;
|
||||
@ -180,5 +154,4 @@ extern Array(StringCached) PreprocessorDefines;
|
||||
extern AllocatorInfo Allocator_StringArena;
|
||||
extern AllocatorInfo Allocator_StringTable;
|
||||
extern AllocatorInfo Allocator_TypeTable;
|
||||
|
||||
#endif
|
||||
|
@ -183,6 +183,7 @@ void params_append( CodeParam appendee, CodeParam other )
|
||||
{
|
||||
GEN_ASSERT(appendee);
|
||||
GEN_ASSERT(other);
|
||||
GEN_ASSERT_MSG(appendee != other, "Attempted to append parameter to itself.");
|
||||
Code self = cast(Code, appendee);
|
||||
Code entry = cast(Code, other);
|
||||
|
||||
@ -250,7 +251,8 @@ CodeParam end_CodeParam(CodeParam params)
|
||||
forceinline
|
||||
CodeParam next_CodeParam(CodeParam params, CodeParam param_iter)
|
||||
{
|
||||
return params->Next;
|
||||
GEN_ASSERT(param_iter);
|
||||
return param_iter->Next;
|
||||
}
|
||||
#pragma endregion CodeParam
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
#include "code_serialization.cpp"
|
||||
#endif
|
||||
|
||||
namespace parser {
|
||||
GEN_NS_PARSER_BEGIN
|
||||
internal void init();
|
||||
internal void deinit();
|
||||
}
|
||||
GEN_NS_PARSER_END
|
||||
|
||||
internal
|
||||
void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
|
||||
|
@ -161,7 +161,7 @@ struct Opts_def_variable
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT );
|
||||
CodeVar def_variable( CodeTypename 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.
|
||||
CodeBody def_body( CodeTypename type );
|
||||
@ -266,4 +266,55 @@ Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
||||
|
||||
#pragma endregion Untyped text
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#ifndef token_fmt
|
||||
# define gen_main main
|
||||
|
||||
# define __ NullCode
|
||||
|
||||
// Convienence for defining any name used with the gen api.
|
||||
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
||||
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
|
||||
|
||||
// Same as name just used to indicate intention of literal for code instead of names.
|
||||
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
|
||||
|
||||
// Provides the number of arguments while passing args inplace.
|
||||
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
||||
|
||||
// Just wrappers over common untyped code definition constructions.
|
||||
# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
|
||||
# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
|
||||
|
||||
# define parse_fmt( type, ... ) GEN_NS parse_##type( token_fmt( __VA_ARGS__ ) )
|
||||
|
||||
/*
|
||||
Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
Tokens are provided in '<'identifier'>' format where '<' '>' are just angle brakcets (you can change it in token_fmt_va)
|
||||
---------------------------------------------------------
|
||||
Example - A string with:
|
||||
typedef <type> <name> <name>;
|
||||
Will have a token_fmt arguments populated with:
|
||||
"type", strc_for_type,
|
||||
"name", strc_for_name,
|
||||
and:
|
||||
stringize( typedef <type> <name> <name>; ) )
|
||||
-----------------------------------------------------------
|
||||
So the full call for this example would be:
|
||||
token_fmt(
|
||||
"type", strc_for_type
|
||||
, "name", strc_for_name
|
||||
, stringize(
|
||||
typedef <type> <name> <name>
|
||||
));
|
||||
!----------------------------------------------------------
|
||||
! Note: token_fmt_va is whitespace sensitive for the tokens.
|
||||
! This can be alleviated by skipping whitespace between brackets but it was choosen to not have that implementation by default.
|
||||
*/
|
||||
# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros
|
||||
|
||||
#pragma endregion Gen Interface
|
||||
|
@ -21,29 +21,29 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
|
||||
}
|
||||
|
||||
#pragma region Helper Macros
|
||||
# define check_params() \
|
||||
if ( ! params_code ) \
|
||||
{ \
|
||||
log_failure("gen::def_operator: params is null and operator%s requires it", operator_to_str(op)); \
|
||||
return OpValResult_Fail; \
|
||||
} \
|
||||
if ( params_code->Type != CT_Parameters ) \
|
||||
{ \
|
||||
# define check_params() \
|
||||
if ( ! params_code ) \
|
||||
{ \
|
||||
log_failure("gen::def_operator: params is null and operator%s requires it", operator_to_str(op)); \
|
||||
return OpValResult_Fail; \
|
||||
} \
|
||||
if ( params_code->Type != CT_Parameters ) \
|
||||
{ \
|
||||
log_failure("gen::def_operator: params is not of Parameters type - %s", code_debug_str( cast(Code, params_code))); \
|
||||
return OpValResult_Fail; \
|
||||
return OpValResult_Fail; \
|
||||
}
|
||||
|
||||
# define check_param_eq_ret() \
|
||||
if ( ! is_member_symbol && ! code_is_equal(cast(Code, params_code->ValueType), cast(Code, ret_type)) ) \
|
||||
{ \
|
||||
log_failure("gen::def_operator: operator%s requires first parameter to equal return type\n" \
|
||||
"param types: %s\n" \
|
||||
"return type: %s", \
|
||||
operator_to_str(op).Ptr, \
|
||||
code_debug_str(cast(Code, params_code)), \
|
||||
code_debug_str(cast(Code, ret_type)) \
|
||||
); \
|
||||
return OpValResult_Fail; \
|
||||
# define check_param_eq_ret() \
|
||||
if ( ! is_member_symbol && ! code_is_equal(cast(Code, params_code->ValueType), cast(Code, ret_type)) ) \
|
||||
{ \
|
||||
log_failure("gen::def_operator: operator%s requires first parameter to equal return type\n" \
|
||||
"param types: %s\n" \
|
||||
"return type: %s", \
|
||||
operator_to_str(op).Ptr, \
|
||||
code_debug_str(cast(Code, params_code)), \
|
||||
code_debug_str(cast(Code, ret_type)) \
|
||||
); \
|
||||
return OpValResult_Fail; \
|
||||
}
|
||||
#pragma endregion Helper Macros
|
||||
|
||||
@ -216,9 +216,9 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
|
||||
if ( params_code->NumEntries > 1 )
|
||||
{
|
||||
log_failure(
|
||||
"gen::def_operator: operator%s may not have more than one parameter - param count: %d",
|
||||
operator_to_str( op ),
|
||||
params_code->NumEntries
|
||||
"gen::def_operator: operator%s may not have more than one parameter - param count: %d",
|
||||
operator_to_str( op ),
|
||||
params_code->NumEntries
|
||||
);
|
||||
return OpValResult_Fail;
|
||||
}
|
||||
|
@ -1614,6 +1614,13 @@ CodeBody parse_global_nspace( CodeType which )
|
||||
|
||||
switch ( currtok_noskip.Type )
|
||||
{
|
||||
case Tok_Comma:
|
||||
{
|
||||
log_failure("Dangling comma found: %S\nContext:\n%S", to_string(currtok), to_string(Context));
|
||||
pop( & Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
break;
|
||||
case Tok_Statement_End:
|
||||
{
|
||||
// TODO(Ed): Convert this to a general warning procedure
|
||||
@ -1885,7 +1892,7 @@ CodeBody parse_global_nspace( CodeType which )
|
||||
|
||||
if ( member == Code_Invalid )
|
||||
{
|
||||
log_failure( "Failed to parse member\n%s", to_string(Context) );
|
||||
log_failure( "Failed to parse member\nToken: %s\nContext:\n%s", to_string(currtok_noskip), to_string(Context) );
|
||||
pop(& Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ using LogFailType = ssize(*)(char const*, ...);
|
||||
#define log_failure GEN_FATAL
|
||||
#endif
|
||||
|
||||
enum AccessSpec enum_underlying(u32)
|
||||
enum AccessSpec : u32
|
||||
{
|
||||
AccessSpec_Default,
|
||||
AccessSpec_Private,
|
||||
@ -28,7 +28,7 @@ enum AccessSpec enum_underlying(u32)
|
||||
static_assert( size_of(AccessSpec) == size_of(u32), "AccessSpec not u32 size" );
|
||||
|
||||
inline
|
||||
char const* to_str( AccessSpec type )
|
||||
char const* access_spec_to_str( AccessSpec type )
|
||||
{
|
||||
local_persist
|
||||
char const* lookup[ (u32)AccessSpec_Num_AccessSpec ] = {
|
||||
@ -44,7 +44,7 @@ char const* to_str( AccessSpec type )
|
||||
return lookup[ (u32)type ];
|
||||
}
|
||||
|
||||
enum CodeFlag enum_underlying(u32)
|
||||
enum CodeFlag : u32
|
||||
{
|
||||
CodeFlag_None = 0,
|
||||
CodeFlag_FunctionType = bit(0),
|
||||
@ -57,7 +57,7 @@ enum CodeFlag enum_underlying(u32)
|
||||
static_assert( size_of(CodeFlag) == size_of(u32), "CodeFlag not u32 size" );
|
||||
|
||||
// Used to indicate if enum definitoin is an enum class or regular enum.
|
||||
enum EnumDecl enum_underlying(u8)
|
||||
enum EnumDecl : u8
|
||||
{
|
||||
EnumDecl_Regular,
|
||||
EnumDecl_Class,
|
||||
@ -66,7 +66,7 @@ enum EnumDecl enum_underlying(u8)
|
||||
};
|
||||
typedef u8 EnumT;
|
||||
|
||||
enum ModuleFlag enum_underlying(u32)
|
||||
enum ModuleFlag : u32
|
||||
{
|
||||
ModuleFlag_None = 0,
|
||||
ModuleFlag_Export = bit(0),
|
||||
@ -80,28 +80,24 @@ enum ModuleFlag enum_underlying(u32)
|
||||
static_assert( size_of(ModuleFlag) == size_of(u32), "ModuleFlag not u32 size" );
|
||||
|
||||
inline
|
||||
StrC to_str( ModuleFlag flag )
|
||||
StrC module_flag_to_str( ModuleFlag flag )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[ (u32)ModuleFlag::Num_ModuleFlags ] = {
|
||||
StrC lookup[ (u32)Num_ModuleFlags ] = {
|
||||
{ sizeof("__none__"), "__none__" },
|
||||
{ sizeof("export"), "export" },
|
||||
{ sizeof("import"), "import" },
|
||||
};
|
||||
|
||||
local_persist
|
||||
StrC invalid_flag = { sizeof("invalid"), "invalid" };
|
||||
if ( flag > ModuleFlag_Import )
|
||||
return { sizeof("invalid"), "invalid" };
|
||||
return invalid_flag;
|
||||
|
||||
return lookup[ (u32)flag ];
|
||||
}
|
||||
|
||||
inline
|
||||
ModuleFlag operator|( ModuleFlag A, ModuleFlag B)
|
||||
{
|
||||
return (ModuleFlag)( (u32)A | (u32)B );
|
||||
}
|
||||
|
||||
enum EPreprocessCond enum_underlying(u32)
|
||||
enum EPreprocessCond : u32
|
||||
{
|
||||
PreprocessCond_If,
|
||||
PreprocessCond_IfDef,
|
||||
|
Reference in New Issue
Block a user