Reorganization of files, refactors, doc updates (WIP)

Removing the gen. namespace from the files for components, dependencies, and file_processors.
They are only necessary if the include directory is transparent, and in my case those are not.

Made a docs directory. I'm offloading information from the main readme to there along with additional informationn I end up elaborating on down the line.
Enum tables were moved to their own directory (project/enums).

Library will not compile for now. Major refactor occuring with parsing related components.
This commit is contained in:
2023-07-29 05:52:06 -04:00
parent 31e1c38c18
commit c5afede7b5
68 changed files with 1077 additions and 888 deletions

View File

@ -1,2 +0,0 @@
API_Export, GEN_API_Export_Code
API_Import, GEN_API_Import_Code
1 API_Export GEN_API_Export_Code
2 API_Import GEN_API_Import_Code

View File

@ -1,47 +0,0 @@
Invalid
Untyped
Comment
Access_Private
Access_Protected
Access_Public
PlatformAttributes
Class
Class_Fwd
Class_Body
Enum
Enum_Fwd
Enum_Body
Enum_Class
Enum_Class_Fwd
Execution
Export_Body
Extern_Linkage
Extern_Linkage_Body
Friend
Function
Function_Fwd
Function_Body
Global_Body
Module
Namespace
Namespace_Body
Operator
Operator_Fwd
Operator_Member
Operator_Member_Fwd
Operator_Cast
Operator_Cast_Fwd
Parameters
Preprocessor_Include
Specifiers
Struct
Struct_Fwd
Struct_Body
Template
Typedef
Typename
Union
Union_Body
Using
Using_Namespace
Variable
1 Invalid
2 Untyped
3 Comment
4 Access_Private
5 Access_Protected
6 Access_Public
7 PlatformAttributes
8 Class
9 Class_Fwd
10 Class_Body
11 Enum
12 Enum_Fwd
13 Enum_Body
14 Enum_Class
15 Enum_Class_Fwd
16 Execution
17 Export_Body
18 Extern_Linkage
19 Extern_Linkage_Body
20 Friend
21 Function
22 Function_Fwd
23 Function_Body
24 Global_Body
25 Module
26 Namespace
27 Namespace_Body
28 Operator
29 Operator_Fwd
30 Operator_Member
31 Operator_Member_Fwd
32 Operator_Cast
33 Operator_Cast_Fwd
34 Parameters
35 Preprocessor_Include
36 Specifiers
37 Struct
38 Struct_Fwd
39 Struct_Body
40 Template
41 Typedef
42 Typename
43 Union
44 Union_Body
45 Using
46 Using_Namespace
47 Variable

View File

@ -1,43 +0,0 @@
Invalid, INVALID
Assign, "="
Assign_Add, "+="
Assign_Subtract, "-="
Assign_Multiply, "*="
Assign_Divide, "/="
Assign_Modulo, "%="
Assign_BAnd, "&="
Assign_BOr, "|="
Assign_BXOr, "^="
Assign_LShift, "<<="
Assign_RShift, ">>="
Increment, "++"
Decrement, "--"
Unary_Plus, "+"
Unary_Minus, "-"
UnaryNot, "!"
Add, "+"
Subtract, "-"
Multiply, "*"
Divide, "/"
Modulo, "%"
BNot, "~"
BAnd, "&"
BOr, "|"
BXOr, "^"
LShift, "<<"
RShift, ">>"
LAnd, "&&"
LOr, "||"
LEqual, "=="
LNot, "!="
Lesser, "<"
Greater, ">"
LesserEqual, "<="
GreaterEqual, ">="
Subscript, "[]"
Indirection, "*"
AddressOf, "&"
MemberOfPointer, "->"
PtrToMemOfPtr, "->*"
FunctionCall, "()"
Comma, ","
1 Invalid INVALID
2 Assign =
3 Assign_Add +=
4 Assign_Subtract -=
5 Assign_Multiply *=
6 Assign_Divide /=
7 Assign_Modulo %=
8 Assign_BAnd &=
9 Assign_BOr |=
10 Assign_BXOr ^=
11 Assign_LShift <<=
12 Assign_RShift >>=
13 Increment ++
14 Decrement --
15 Unary_Plus +
16 Unary_Minus -
17 UnaryNot !
18 Add +
19 Subtract -
20 Multiply *
21 Divide /
22 Modulo %
23 BNot ~
24 BAnd &
25 BOr |
26 BXOr ^
27 LShift <<
28 RShift >>
29 LAnd &&
30 LOr ||
31 LEqual ==
32 LNot !=
33 Lesser <
34 Greater >
35 LesserEqual <=
36 GreaterEqual >=
37 Subscript []
38 Indirection *
39 AddressOf &
40 MemberOfPointer ->
41 PtrToMemOfPtr ->*
42 FunctionCall ()
43 Comma ,

View File

@ -1,22 +0,0 @@
Invalid, INVALID
Consteval, consteval
Constexpr, constexpr
Constinit, constinit
Explicit, explicit
External_Linkage, extern
Global, global
Inline, inline
Internal_Linkage, internal
Local_Persist, local_persist
Mutable, mutable
Ptr, *
Ref, &
Register, register
RValue, &&
Static, static
Thread_Local, thread_local
Volatile, volatile
Virtual, virtual
Const, const
Final, final
Override, override
1 Invalid INVALID
2 Consteval consteval
3 Constexpr constexpr
4 Constinit constinit
5 Explicit explicit
6 External_Linkage extern
7 Global global
8 Inline inline
9 Internal_Linkage internal
10 Local_Persist local_persist
11 Mutable mutable
12 Ptr *
13 Ref &
14 Register register
15 RValue &&
16 Static static
17 Thread_Local thread_local
18 Volatile volatile
19 Virtual virtual
20 Const const
21 Final final
22 Override override

View File

@ -1,74 +0,0 @@
Invalid, "__invalid__"
Access_Private, "private"
Access_Protected, "protected"
Access_Public, "public"
Access_MemberSymbol, "."
Access_StaticSymbol, "::"
Ampersand, "&"
Ampersand_DBL, "&&"
Assign_Classifer, ":"
Attribute_Open, "[["
Attribute_Close, "]]"
BraceCurly_Open, "{"
BraceCurly_Close, "}"
BraceSquare_Open, "["
BraceSquare_Close, "]"
Capture_Start, "("
Capture_End, ")"
Comment, "__comment__"
Char, "__char__"
Comma, ","
Decl_Class, "class"
Decl_GNU_Attribute, "__attribute__"
Decl_MSVC_Attribute, "__declspec"
Decl_Enum, "enum"
Decl_Extern_Linkage, "extern"
Decl_Friend, "friend"
Decl_Module, "module"
Decl_Namespace, "namespace"
Decl_Operator, "operator"
Decl_Struct, "struct"
Decl_Template, "template"
Decl_Typedef, "typedef"
Decl_Using, "using"
Decl_Union, "union"
Identifier, "__identifier__"
Module_Import, "import"
Module_Export, "export"
Number, "number"
Operator, "operator"
Preprocess_Define, "#define"
Preprocess_Include, "#include"
Preprocess_If, "#if"
Preprocess_ElIF, "#elif"
Preprocess_Else, "#else"
Preprocess_EndIf, "#endif"
Spec_Alignas, "alignas"
Spec_Const, "const"
Spec_Consteval, "consteval"
Spec_Constexpr, "constexpr"
Spec_Constinit, "constinit"
Spec_Explicit, "explicit"
Spec_Extern, "extern"
Spec_Final, "final"
Spec_Global, "global"
Spec_Inline, "inline"
Spec_Internal_Linkage, "internal"
Spec_LocalPersist, "local_persist"
Spec_Mutable, "mutable"
Spec_Override, "override"
Spec_Static, "static"
Spec_ThreadLocal, "thread_local"
Spec_Volatile, "volatile"
Star, "*"
Statement_End, ";"
String, "__string__"
Type_Unsigned, "unsigned"
Type_Signed, "signed"
Type_Short, "short"
Type_Long, "long"
Type_char, "char"
Type_int, "int"
Type_double, "double"
Varadic_Argument, "..."
Attributes_Start, "__attrib_start__"
1 Invalid __invalid__
2 Access_Private private
3 Access_Protected protected
4 Access_Public public
5 Access_MemberSymbol .
6 Access_StaticSymbol ::
7 Ampersand &
8 Ampersand_DBL &&
9 Assign_Classifer :
10 Attribute_Open [[
11 Attribute_Close ]]
12 BraceCurly_Open {
13 BraceCurly_Close }
14 BraceSquare_Open [
15 BraceSquare_Close ]
16 Capture_Start (
17 Capture_End )
18 Comment __comment__
19 Char __char__
20 Comma ,
21 Decl_Class class
22 Decl_GNU_Attribute __attribute__
23 Decl_MSVC_Attribute __declspec
24 Decl_Enum enum
25 Decl_Extern_Linkage extern
26 Decl_Friend friend
27 Decl_Module module
28 Decl_Namespace namespace
29 Decl_Operator operator
30 Decl_Struct struct
31 Decl_Template template
32 Decl_Typedef typedef
33 Decl_Using using
34 Decl_Union union
35 Identifier __identifier__
36 Module_Import import
37 Module_Export export
38 Number number
39 Operator operator
40 Preprocess_Define #define
41 Preprocess_Include #include
42 Preprocess_If #if
43 Preprocess_ElIF #elif
44 Preprocess_Else #else
45 Preprocess_EndIf #endif
46 Spec_Alignas alignas
47 Spec_Const const
48 Spec_Consteval consteval
49 Spec_Constexpr constexpr
50 Spec_Constinit constinit
51 Spec_Explicit explicit
52 Spec_Extern extern
53 Spec_Final final
54 Spec_Global global
55 Spec_Inline inline
56 Spec_Internal_Linkage internal
57 Spec_LocalPersist local_persist
58 Spec_Mutable mutable
59 Spec_Override override
60 Spec_Static static
61 Spec_ThreadLocal thread_local
62 Spec_Volatile volatile
63 Star *
64 Statement_End ;
65 String __string__
66 Type_Unsigned unsigned
67 Type_Signed signed
68 Type_Short short
69 Type_Long long
70 Type_char char
71 Type_int int
72 Type_double double
73 Varadic_Argument ...
74 Attributes_Start __attrib_start__

View File

@ -17,20 +17,9 @@ AST* AST::duplicate()
String AST::to_string()
{
# define ProcessModuleFlags() \
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export )) \
result.append( "export " ); \
\
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Import )) \
result.append( "import " ); \
local_persist thread_local
char SerializationLevel = 0;
#if defined(GEN_BENCHMARK) && defined(GEN_BENCHMARK_SERIALIZATION)
u64 time_start = time_rel_ms();
#endif
// TODO : Need to refactor so that intermeidate strings are freed conviently.
String result = String::make( GlobalAllocator, "" );
@ -82,7 +71,8 @@ String AST::to_string()
case Class:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes || ParentType )
{
@ -129,7 +119,8 @@ String AST::to_string()
case Class_Fwd:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes )
result.append_fmt( "class %s %s;", Attributes->to_string(), Name );
@ -140,7 +131,8 @@ String AST::to_string()
case Enum:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes || UnderlyingType )
{
@ -170,7 +162,8 @@ String AST::to_string()
case Enum_Fwd:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
@ -181,7 +174,8 @@ String AST::to_string()
case Enum_Class:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes || UnderlyingType )
{
@ -219,7 +213,8 @@ String AST::to_string()
case Enum_Class_Fwd:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
result.append( "enum class " );
@ -262,7 +257,8 @@ String AST::to_string()
case Function:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
@ -301,7 +297,8 @@ String AST::to_string()
case Function_Fwd:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
@ -347,7 +344,8 @@ String AST::to_string()
break;
case Namespace:
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
result.append_fmt( "namespace %s\n{\n%s}"
, Name
@ -358,7 +356,8 @@ String AST::to_string()
case Operator:
case Operator_Member:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
@ -395,7 +394,8 @@ String AST::to_string()
case Operator_Fwd:
case Operator_Member_Fwd:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
@ -513,7 +513,8 @@ String AST::to_string()
case Struct:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Name == nullptr)
{
@ -566,7 +567,8 @@ String AST::to_string()
case Struct_Fwd:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes )
result.append_fmt( "struct %s %s;", Attributes->to_string(), Name );
@ -577,7 +579,8 @@ String AST::to_string()
case Template:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
result.append_fmt( "template< %s >\n%s", Params->to_string(), Declaration->to_string() );
}
@ -585,7 +588,8 @@ String AST::to_string()
case Typedef:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
result.append( "typedef ");
@ -624,7 +628,8 @@ String AST::to_string()
case Union:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
result.append( "union " );
@ -650,7 +655,8 @@ String AST::to_string()
case Using:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes )
result.append_fmt( "%s ", Attributes->to_string() );
@ -675,7 +681,8 @@ String AST::to_string()
case Variable:
{
ProcessModuleFlags();
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
if ( Attributes || Specs )
{
@ -726,11 +733,7 @@ String AST::to_string()
break;
}
#if defined(GEN_BENCHMARK) && defined(GEN_BENCHMARK_SERIALIZATION)
log_fmt("AST::to_string() time taken: %llu for: %s\n", time_rel_ms() - time_start, result );
#endif
return result;
#undef ProcessModuleFlags
}
bool AST::is_equal( AST* other )
@ -760,19 +763,19 @@ bool AST::validate_body()
{
using namespace ECode;
#define CheckEntries( Unallowed_Types ) \
do \
{ \
for ( Code entry : cast<CodeBody>() ) \
{ \
switch ( entry->Type ) \
{ \
Unallowed_Types \
log_failure( "AST::validate_body: Invalid entry in body %s", entry.debug_str() ); \
return false; \
} \
} \
} \
#define CheckEntries( Unallowed_Types ) \
do \
{ \
for ( Code entry : cast<CodeBody>() ) \
{ \
switch ( entry->Type ) \
{ \
Unallowed_Types \
log_failure( "AST::validate_body: Invalid entry in body %s", entry.debug_str() ); \
return false; \
} \
} \
} \
while (0);
switch ( Type )
@ -825,6 +828,8 @@ bool AST::validate_body()
}
return false;
#undef CheckEntries
}
#pragma endregion AST

View File

@ -72,4 +72,4 @@ namespace EOperator
# undef Define_Operators
}
using OperatorT = EOperator::Type;
using OperatorT = EOperator::Type;

View File

@ -101,5 +101,4 @@ namespace ESpecifier
# undef Define_Specifiers
}
using SpecifierT = ESpecifier::Type;

View File

@ -9,8 +9,8 @@ namespace Parser
Attributes_Start is only used to indicate the start of the user_defined attribute list.
*/
#ifndef GEN_Define_Attribute_Tokens
# define GEN_Define_Attribute_Tokens \
#ifndef GEN_DEFINE_ATTRIBUTE_TOKENS
# define GEN_DEFINE_ATTRIBUTE_TOKENS \
Entry( API_Export, "GEN_API_Export_Code" ) \
Entry( API_Import, "GEN_API_Import_Code" )
#endif
@ -97,7 +97,7 @@ namespace Parser
{
# define Entry( Name_, Str_ ) Name_,
Define_TokType
GEN_Define_Attribute_Tokens
GEN_DEFINE_ATTRIBUTE_TOKENS
# undef Entry
NumTokens,
};
@ -110,7 +110,7 @@ namespace Parser
{
# define Entry( Name_, Str_ ) { sizeof(Str_), Str_ },
Define_TokType
GEN_Define_Attribute_Tokens
GEN_DEFINE_ATTRIBUTE_TOKENS
# undef Entry
};
@ -137,7 +137,7 @@ namespace Parser
{
# define Entry( Name_, Str_ ) Str_,
Define_TokType
GEN_Define_Attribute_Tokens
GEN_DEFINE_ATTRIBUTE_TOKENS
# undef Entry
};

View File

@ -105,7 +105,7 @@ void define_constants()
#endif
# undef def_constant_code_type
t_empty = (CodeType) make_code();
t_empty = (CodeType) make_code();
t_empty->Type = ECode::Typename;
t_empty->Name = get_cached_string( txt_StrC("") );
t_empty.set_global();
@ -127,12 +127,12 @@ void define_constants()
access_private->Name = get_cached_string( txt_StrC("private:") );
access_private.set_global();
access_protected = make_code();
access_protected = make_code();
access_protected->Type = ECode::Access_Protected;
access_protected->Name = get_cached_string( txt_StrC("protected:") );
access_protected.set_global();
access_public = make_code();
access_public = make_code();
access_public->Type = ECode::Access_Public;
access_public->Name = get_cached_string( txt_StrC("public:") );
access_public.set_global();

View File

@ -68,7 +68,7 @@ ModuleFlag operator|( ModuleFlag A, ModuleFlag B)
Override these to change the attribute to your own unique identifier convention.
The tokenizer identifies attribute defines with the GEN_Define_Attribute_Tokens macros.
The tokenizer identifies attribute defines with the GEN_DEFINE_ATTRIBUTE_TOKENS macros.
See the example below and the Define_TokType macro used in gen.cpp to know the format.
While the library can parse raw attributes, most projects use defines to wrap them for compiler
platform indendence. The token define allows support for them without having to modify the library.

View File

@ -12,8 +12,7 @@ sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
char tok_map_mem[ TokenFmt_TokenMap_MemSize ];
tok_map_arena = Arena::init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
tok_map = HashTable<StrC>::init( tok_map_arena );
tok_map = HashTable<StrC>::init( tok_map_arena );
s32 left = num_tokens - 1;