Compare commits

..

No commits in common. "e00b2f8afbde47a4e08fff762c4da2b3eed28f7a" and "63ebd0d0946a777f5450242e0cde72d18e62a3fd" have entirely different histories.

24 changed files with 2805 additions and 2760 deletions

View File

@ -243,12 +243,7 @@ int gen_main()
Code untyped = scan_file( "components/interface.untyped.cpp" ); Code untyped = scan_file( "components/interface.untyped.cpp" );
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" ); CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
//CodeNS nspaced_etoktype = def_namespace( name(parser), def_namespace_body( args(etoktype)) ); CodeNS nspaced_etoktype = def_namespace( name(parser), def_namespace_body( args(etoktype)) );
CodeBody nspaced_etoktype = def_global_body( args(
untyped_str(txt("GEN_NS_PARSER_BEGIN\n")),
etoktype,
untyped_str(txt("GEN_NS_PARSER_END\n"))
));
Builder Builder
src = Builder::open( "gen/gen.cpp" ); src = Builder::open( "gen/gen.cpp" );

View File

@ -24,29 +24,31 @@ char const* debug_str(Code self)
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Invalid: using namespace ECode;
case CT_NewLine:
case CT_Access_Private: case Invalid:
case CT_Access_Protected: case NewLine:
case CT_Access_Public: case Access_Private:
case Access_Protected:
case Access_Public:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
break; break;
case CT_Untyped: case Untyped:
case CT_Execution: case Execution:
case CT_Comment: case Comment:
case CT_PlatformAttributes: case PlatformAttributes:
case CT_Preprocess_Define: case Preprocess_Define:
case CT_Preprocess_Include: case Preprocess_Include:
case CT_Preprocess_Pragma: case Preprocess_Pragma:
case CT_Preprocess_If: case Preprocess_If:
case CT_Preprocess_ElIf: case Preprocess_ElIf:
case CT_Preprocess_Else: case Preprocess_Else:
case CT_Preprocess_IfDef: case Preprocess_IfDef:
case CT_Preprocess_IfNotDef: case Preprocess_IfNotDef:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -55,8 +57,8 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tContent: %S", self->Content ); append_fmt( result, "\n\tContent: %S", self->Content );
break; break;
case CT_Class: case Class:
case CT_Struct: case Struct:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -69,8 +71,8 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" ); append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break; break;
case CT_Class_Fwd: case Class_Fwd:
case CT_Struct_Fwd: case Struct_Fwd:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -82,7 +84,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tParentType : %s", self->ParentType ? type_str(self->ParentType) : "Null" ); append_fmt( result, "\n\tParentType : %s", self->ParentType ? type_str(self->ParentType) : "Null" );
break; break;
case CT_Constructor: case Constructor:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -95,7 +97,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" ); append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break; break;
case CT_Constructor_Fwd: case Constructor_Fwd:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -107,7 +109,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" ); append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
break; break;
case CT_Destructor: case Destructor:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -118,11 +120,11 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" ); append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break; break;
case CT_Destructor_Fwd: case Destructor_Fwd:
break; break;
case CT_Enum: case Enum:
case CT_Enum_Class: case Enum_Class:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -134,8 +136,8 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" ); append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break; break;
case CT_Enum_Fwd: case Enum_Fwd:
case CT_Enum_Class_Fwd: case Enum_Class_Fwd:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -146,8 +148,8 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" ); append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
break; break;
case CT_Extern_Linkage: case Extern_Linkage:
case CT_Namespace: case Namespace:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -156,7 +158,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tBody: %S", self->Body ? debug_str(self->Body) : "Null" ); append_fmt( result, "\n\tBody: %S", self->Body ? debug_str(self->Body) : "Null" );
break; break;
case CT_Friend: case Friend:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -166,7 +168,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" ); append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" );
break; break;
case CT_Function: case Function:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -180,7 +182,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" ); append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break; break;
case CT_Function_Fwd: case Function_Fwd:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -193,15 +195,15 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" ); append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
break; break;
case CT_Module: case Module:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
break; break;
case CT_Operator: case Operator:
case CT_Operator_Member: case Operator_Member:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -216,8 +218,8 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tOp : %S", to_str( self->Op ) ); append_fmt( result, "\n\tOp : %S", to_str( self->Op ) );
break; break;
case CT_Operator_Fwd: case Operator_Fwd:
case CT_Operator_Member_Fwd: case Operator_Member_Fwd:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -231,7 +233,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tOp : %S", to_str( self->Op ) ); append_fmt( result, "\n\tOp : %S", to_str( self->Op ) );
break; break;
case CT_Operator_Cast: case Operator_Cast:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -243,7 +245,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" ); append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break; break;
case CT_Operator_Cast_Fwd: case Operator_Cast_Fwd:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -254,7 +256,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" ); append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
break; break;
case CT_Parameters: case Parameters:
append_fmt( result, "\n\tNumEntries: %d", self->NumEntries ); append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
append_fmt( result, "\n\tLast : %S", self->Last->Name ); append_fmt( result, "\n\tLast : %S", self->Last->Name );
append_fmt( result, "\n\tNext : %S", self->Next->Name ); append_fmt( result, "\n\tNext : %S", self->Next->Name );
@ -262,7 +264,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" ); append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
break; break;
case CT_Specifiers: case Specifiers:
{ {
append_fmt( result, "\n\tNumEntries: %d", self->NumEntries ); append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
GEN_NS append( result, "\n\tArrSpecs: " ); GEN_NS append( result, "\n\tArrSpecs: " );
@ -271,7 +273,7 @@ char const* debug_str(Code self)
s32 left = self->NumEntries; s32 left = self->NumEntries;
while ( left-- ) while ( left-- )
{ {
StrC spec = to_str( self->ArrSpecs[idx] ); StrC spec = ESpecifier::to_str( self->ArrSpecs[idx] );
append_fmt( result, "%.*s, ", spec.Len, spec.Ptr ); append_fmt( result, "%.*s, ", spec.Len, spec.Ptr );
idx++; idx++;
} }
@ -279,7 +281,7 @@ char const* debug_str(Code self)
} }
break; break;
case CT_Template: case Template:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -289,7 +291,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" ); append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" );
break; break;
case CT_Typedef: case Typedef:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -299,7 +301,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" ); append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
break; break;
case CT_Typename: case Typename:
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" ); append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" ); append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tReturnType : %S", self->ReturnType ? to_string(self->ReturnType) : "Null" ); append_fmt( result, "\n\tReturnType : %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
@ -307,7 +309,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tArrExpr : %S", self->ArrExpr ? to_string(self->ArrExpr) : "Null" ); append_fmt( result, "\n\tArrExpr : %S", self->ArrExpr ? to_string(self->ArrExpr) : "Null" );
break; break;
case CT_Union: case Union:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -317,7 +319,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" ); append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break; break;
case CT_Using: case Using:
if ( self->Prev ) if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" ); append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next ) if ( self->Next )
@ -328,9 +330,9 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" ); append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
break; break;
case CT_Variable: case Variable:
if ( self->Parent && self->Parent->Type == CT_Variable ) if ( self->Parent && self->Parent->Type == Variable )
{ {
// Its a NextVar // Its a NextVar
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" ); append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
@ -360,6 +362,8 @@ char const* debug_str(Code self)
Code duplicate(Code self) Code duplicate(Code self)
{ {
using namespace ECode;
Code result = make_code(); Code result = make_code();
mem_copy( result.ast, self.ast, sizeof( AST ) ); mem_copy( result.ast, self.ast, sizeof( AST ) );
@ -383,7 +387,9 @@ void to_string( Code self, String* result )
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Invalid: using namespace ECode;
case Invalid:
#ifdef GEN_DONT_ALLOW_INVALID_CODE #ifdef GEN_DONT_ALLOW_INVALID_CODE
log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->debug_str() : Name ); log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->debug_str() : Name );
#else #else
@ -391,197 +397,197 @@ void to_string( Code self, String* result )
#endif #endif
break; break;
case CT_NewLine: case NewLine:
append( result,"\n"); append( result,"\n");
break; break;
case CT_Untyped: case Untyped:
case CT_Execution: case Execution:
case CT_Comment: case Comment:
case CT_PlatformAttributes: case PlatformAttributes:
append( result, self->Content ); append( result, self->Content );
break; break;
case CT_Access_Private: case Access_Private:
case CT_Access_Protected: case Access_Protected:
case CT_Access_Public: case Access_Public:
append( result, self->Name ); append( result, self->Name );
break; break;
case CT_Class: case Class:
to_string_def(cast(CodeClass, self), result ); to_string_def(cast(CodeClass, self), result );
break; break;
case CT_Class_Fwd: case Class_Fwd:
to_string_fwd(cast(CodeClass, self), result ); to_string_fwd(cast(CodeClass, self), result );
break; break;
case CT_Constructor: case Constructor:
to_string_def(cast(CodeConstructor, self), result ); to_string_def(cast(CodeConstructor, self), result );
break; break;
case CT_Constructor_Fwd: case Constructor_Fwd:
to_string_fwd(cast(CodeConstructor, self), result ); to_string_fwd(cast(CodeConstructor, self), result );
break; break;
case CT_Destructor: case Destructor:
to_string_def(cast(CodeDestructor, self), result ); to_string_def(cast(CodeDestructor, self), result );
break; break;
case CT_Destructor_Fwd: case Destructor_Fwd:
to_string_fwd(cast(CodeDestructor, self), result ); to_string_fwd(cast(CodeDestructor, self), result );
break; break;
case CT_Enum: case Enum:
to_string_def(cast(CodeEnum, self), result ); to_string_def(cast(CodeEnum, self), result );
break; break;
case CT_Enum_Fwd: case Enum_Fwd:
to_string_fwd(cast(CodeEnum, self), result ); to_string_fwd(cast(CodeEnum, self), result );
break; break;
case CT_Enum_Class: case Enum_Class:
to_string_class_def(cast(CodeEnum, self), result ); to_string_class_def(cast(CodeEnum, self), result );
break; break;
case CT_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 CT_Export_Body: case Export_Body:
to_string_export(cast(CodeBody, self), result ); to_string_export(cast(CodeBody, self), result );
break; break;
case CT_Extern_Linkage: case Extern_Linkage:
to_string(cast(CodeExtern, self), result ); to_string(cast(CodeExtern, self), result );
break; break;
case CT_Friend: case Friend:
to_string(cast(CodeFriend, self), result ); to_string(cast(CodeFriend, self), result );
break; break;
case CT_Function: case Function:
to_string_def(cast(CodeFn, self), result ); to_string_def(cast(CodeFn, self), result );
break; break;
case CT_Function_Fwd: case Function_Fwd:
to_string_fwd(cast(CodeFn, self), result ); to_string_fwd(cast(CodeFn, self), result );
break; break;
case CT_Module: case Module:
to_string(cast(CodeModule, self), result ); to_string(cast(CodeModule, self), result );
break; break;
case CT_Namespace: case Namespace:
to_string(cast(CodeNS, self), result ); to_string(cast(CodeNS, self), result );
break; break;
case CT_Operator: case Operator:
case CT_Operator_Member: case Operator_Member:
to_string_def(cast(CodeOperator, self), result ); to_string_def(cast(CodeOperator, self), result );
break; break;
case CT_Operator_Fwd: case Operator_Fwd:
case CT_Operator_Member_Fwd: case Operator_Member_Fwd:
to_string_fwd(cast(CodeOperator, self), result ); to_string_fwd(cast(CodeOperator, self), result );
break; break;
case CT_Operator_Cast: case Operator_Cast:
to_string_def(cast(CodeOpCast, self), result ); to_string_def(cast(CodeOpCast, self), result );
break; break;
case CT_Operator_Cast_Fwd: case Operator_Cast_Fwd:
to_string_fwd(cast(CodeOpCast, self), result ); to_string_fwd(cast(CodeOpCast, self), result );
break; break;
case CT_Parameters: case Parameters:
to_string(cast(CodeParam, self), result ); to_string(cast(CodeParam, self), result );
break; break;
case CT_Preprocess_Define: case Preprocess_Define:
to_string(cast(CodeDefine, self), result ); to_string(cast(CodeDefine, self), result );
break; break;
case CT_Preprocess_If: case Preprocess_If:
to_string_if(cast(CodePreprocessCond, self), result ); to_string_if(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_IfDef: case Preprocess_IfDef:
to_string_ifdef(cast(CodePreprocessCond, self), result ); to_string_ifdef(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_IfNotDef: case Preprocess_IfNotDef:
to_string_ifndef(cast(CodePreprocessCond, self), result ); to_string_ifndef(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_Include: case Preprocess_Include:
to_string(cast(CodeInclude, self), result ); to_string(cast(CodeInclude, self), result );
break; break;
case CT_Preprocess_ElIf: case Preprocess_ElIf:
to_string_elif(cast(CodePreprocessCond, self), result ); to_string_elif(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_Else: case Preprocess_Else:
to_string_else(cast(CodePreprocessCond, self), result ); to_string_else(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_EndIf: case Preprocess_EndIf:
to_string_endif(cast(CodePreprocessCond, self), result ); to_string_endif(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_Pragma: case Preprocess_Pragma:
to_string(cast(CodePragma, self), result ); to_string(cast(CodePragma, self), result );
break; break;
case CT_Specifiers: case Specifiers:
to_string(cast(CodeSpecifiers, self), result ); to_string(cast(CodeSpecifiers, self), result );
break; break;
case CT_Struct: case Struct:
to_string_def(cast(CodeStruct, self), result ); to_string_def(cast(CodeStruct, self), result );
break; break;
case CT_Struct_Fwd: case Struct_Fwd:
to_string_fwd(cast(CodeStruct, self), result ); to_string_fwd(cast(CodeStruct, self), result );
break; break;
case CT_Template: case Template:
to_string(cast(CodeTemplate, self), result ); to_string(cast(CodeTemplate, self), result );
break; break;
case CT_Typedef: case Typedef:
to_string(cast(CodeTypedef, self), result ); to_string(cast(CodeTypedef, self), result );
break; break;
case CT_Typename: case Typename:
to_string(cast(CodeTypename, self), result ); to_string(cast(CodeType, self), result );
break; break;
case CT_Union: case Union:
to_string( cast(CodeUnion, self), result ); to_string( cast(CodeUnion, self), result );
break; break;
case CT_Using: case Using:
to_string(cast(CodeUsing, self), result ); to_string(cast(CodeUsing, self), result );
break; break;
case CT_Using_Namespace: case Using_Namespace:
to_string_ns(cast(CodeUsing, self), result ); to_string_ns(cast(CodeUsing, self), result );
break; break;
case CT_Variable: case Variable:
to_string(cast(CodeVar, self), result ); to_string(cast(CodeVar, self), result );
break; break;
case CT_Enum_Body: case Enum_Body:
case CT_Class_Body: case Class_Body:
case CT_Extern_Linkage_Body: case Extern_Linkage_Body:
case CT_Function_Body: case Function_Body:
case CT_Global_Body: case Global_Body:
case CT_Namespace_Body: case Namespace_Body:
case CT_Struct_Body: case Struct_Body:
case CT_Union_Body: case Union_Body:
to_string( cast(CodeBody, self), result ); to_string( cast(CodeBody, self), result );
break; break;
} }
@ -614,6 +620,8 @@ bool is_equal( Code self, Code other )
switch ( self->Type ) switch ( self->Type )
{ {
using namespace ECode;
#define check_member_val( val ) \ #define check_member_val( val ) \
if ( self->val != other->val ) \ if ( self->val != other->val ) \
{ \ { \
@ -693,30 +701,30 @@ bool is_equal( Code self, Code other )
} \ } \
} }
case CT_NewLine: case NewLine:
case CT_Access_Public: case Access_Public:
case CT_Access_Protected: case Access_Protected:
case CT_Access_Private: case Access_Private:
case CT_Preprocess_Else: case Preprocess_Else:
case CT_Preprocess_EndIf: case Preprocess_EndIf:
return true; return true;
// Comments are not validated. // Comments are not validated.
case CT_Comment: case Comment:
return true; return true;
case CT_Execution: case Execution:
case CT_PlatformAttributes: case PlatformAttributes:
case CT_Untyped: case Untyped:
{ {
check_member_content( Content ); check_member_content( Content );
return true; return true;
} }
case CT_Class_Fwd: case Class_Fwd:
case CT_Struct_Fwd: case Struct_Fwd:
{ {
check_member_str( Name ); check_member_str( Name );
check_member_ast( ParentType ); check_member_ast( ParentType );
@ -726,8 +734,8 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Class: case Class:
case CT_Struct: case Struct:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -739,7 +747,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Constructor: case Constructor:
{ {
check_member_ast( InitializerList ); check_member_ast( InitializerList );
check_member_ast( Params ); check_member_ast( Params );
@ -748,7 +756,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Constructor_Fwd: case Constructor_Fwd:
{ {
check_member_ast( InitializerList ); check_member_ast( InitializerList );
check_member_ast( Params ); check_member_ast( Params );
@ -756,7 +764,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Destructor: case Destructor:
{ {
check_member_ast( Specs ); check_member_ast( Specs );
check_member_ast( Body ); check_member_ast( Body );
@ -764,15 +772,15 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Destructor_Fwd: case Destructor_Fwd:
{ {
check_member_ast( Specs ); check_member_ast( Specs );
return true; return true;
} }
case CT_Enum: case Enum:
case CT_Enum_Class: case Enum_Class:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -783,8 +791,8 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Enum_Fwd: case Enum_Fwd:
case CT_Enum_Class_Fwd: case Enum_Class_Fwd:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -794,7 +802,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Extern_Linkage: case Extern_Linkage:
{ {
check_member_str( Name ); check_member_str( Name );
check_member_ast( Body ); check_member_ast( Body );
@ -802,7 +810,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Friend: case Friend:
{ {
check_member_str( Name ); check_member_str( Name );
check_member_ast( Declaration ); check_member_ast( Declaration );
@ -810,7 +818,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Function: case Function:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -823,7 +831,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Function_Fwd: case Function_Fwd:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -835,7 +843,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Module: case Module:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -843,7 +851,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Namespace: case Namespace:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -852,8 +860,8 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Operator: case Operator:
case CT_Operator_Member: case Operator_Member:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -866,8 +874,8 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Operator_Fwd: case Operator_Fwd:
case CT_Operator_Member_Fwd: case Operator_Member_Fwd:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -879,7 +887,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Operator_Cast: case Operator_Cast:
{ {
check_member_str( Name ); check_member_str( Name );
check_member_ast( Specs ); check_member_ast( Specs );
@ -889,7 +897,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Operator_Cast_Fwd: case Operator_Cast_Fwd:
{ {
check_member_str( Name ); check_member_str( Name );
check_member_ast( Specs ); check_member_ast( Specs );
@ -898,7 +906,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Parameters: case Parameters:
{ {
if ( self->NumEntries > 1 ) if ( self->NumEntries > 1 )
{ {
@ -983,7 +991,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Preprocess_Define: case Preprocess_Define:
{ {
check_member_str( Name ); check_member_str( Name );
check_member_content( Content ); check_member_content( Content );
@ -991,25 +999,25 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Preprocess_If: case Preprocess_If:
case CT_Preprocess_IfDef: case Preprocess_IfDef:
case CT_Preprocess_IfNotDef: case Preprocess_IfNotDef:
case CT_Preprocess_ElIf: case Preprocess_ElIf:
{ {
check_member_content( Content ); check_member_content( Content );
return true; return true;
} }
case CT_Preprocess_Include: case Preprocess_Include:
case CT_Preprocess_Pragma: case Preprocess_Pragma:
{ {
check_member_content( Content ); check_member_content( Content );
return true; return true;
} }
case CT_Specifiers: case Specifiers:
{ {
check_member_val( NumEntries ); check_member_val( NumEntries );
check_member_str( Name ); check_member_str( Name );
@ -1020,7 +1028,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Template: case Template:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -1030,7 +1038,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Typedef: case Typedef:
{ {
check_member_val( IsFunction ); check_member_val( IsFunction );
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
@ -1040,7 +1048,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Typename: case Typename:
{ {
check_member_val( IsParamPack ); check_member_val( IsParamPack );
check_member_str( Name ); check_member_str( Name );
@ -1050,7 +1058,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Union: case Union:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -1060,8 +1068,8 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Using: case Using:
case CT_Using_Namespace: case Using_Namespace:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -1071,7 +1079,7 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Variable: case Variable:
{ {
check_member_val( ModuleFlags ); check_member_val( ModuleFlags );
check_member_str( Name ); check_member_str( Name );
@ -1085,13 +1093,13 @@ bool is_equal( Code self, Code other )
return true; return true;
} }
case CT_Class_Body: case Class_Body:
case CT_Enum_Body: case Enum_Body:
case CT_Export_Body: case Export_Body:
case CT_Global_Body: case Global_Body:
case CT_Namespace_Body: case Namespace_Body:
case CT_Struct_Body: case Struct_Body:
case CT_Union_Body: case Union_Body:
{ {
check_member_ast( Front ); check_member_ast( Front );
check_member_ast( Back ); check_member_ast( Back );
@ -1147,6 +1155,8 @@ bool is_equal( Code self, Code other )
bool validate_body(Code self) bool validate_body(Code self)
{ {
using namespace ECode;
#define CheckEntries( Unallowed_Types ) \ #define CheckEntries( Unallowed_Types ) \
do \ do \
{ \ { \
@ -1164,65 +1174,65 @@ bool validate_body(Code self)
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Class_Body: case Class_Body:
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
break; break;
case CT_Enum_Body: case Enum_Body:
for ( Code entry : cast(CodeBody, self) ) for ( Code entry : cast(CodeBody, self) )
{ {
if ( entry->Type != CT_Untyped ) if ( entry->Type != Untyped )
{ {
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", GEN_NS debug_str(entry) ); log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", GEN_NS debug_str(entry) );
return false; return false;
} }
} }
break; break;
case CT_Export_Body: case Export_Body:
CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES );
break; break;
case CT_Extern_Linkage: case Extern_Linkage:
CheckEntries( GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES );
break; break;
case CT_Function_Body: case Function_Body:
CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES );
break; break;
case CT_Global_Body: case Global_Body:
for (Code entry : cast(CodeBody, self)) for (Code entry : cast(CodeBody, self))
{ {
switch (entry->Type) switch (entry->Type)
{ {
case CT_Access_Public: case Access_Public:
case CT_Access_Protected: case Access_Protected:
case CT_Access_Private: case Access_Private:
case CT_PlatformAttributes: case PlatformAttributes:
case CT_Class_Body: case Class_Body:
case CT_Enum_Body: case Enum_Body:
case CT_Execution: case Execution:
case CT_Friend: case Friend:
case CT_Function_Body: case Function_Body:
case CT_Global_Body: case Global_Body:
case CT_Namespace_Body: case Namespace_Body:
case CT_Operator_Member: case Operator_Member:
case CT_Operator_Member_Fwd: case Operator_Member_Fwd:
case CT_Parameters: case Parameters:
case CT_Specifiers: case Specifiers:
case CT_Struct_Body: case Struct_Body:
case CT_Typename: case Typename:
log_failure("AST::validate_body: Invalid entry in body %s", GEN_NS debug_str(entry)); log_failure("AST::validate_body: Invalid entry in body %s", GEN_NS debug_str(entry));
return false; return false;
} }
} }
break; break;
case CT_Namespace_Body: case Namespace_Body:
CheckEntries( GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES );
break; break;
case CT_Struct_Body: case Struct_Body:
CheckEntries( GEN_AST_BODY_STRUCT_UNALLOWED_TYPES ); CheckEntries( GEN_AST_BODY_STRUCT_UNALLOWED_TYPES );
break; break;
case CT_Union_Body: case Union_Body:
for ( Code entry : cast(CodeBody, {self->Body}) ) for ( Code entry : cast(CodeBody, {self->Body}) )
{ {
if ( entry->Type != CT_Untyped ) if ( entry->Type != Untyped )
{ {
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", GEN_NS debug_str(entry) ); log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", GEN_NS debug_str(entry) );
return false; return false;

View File

@ -67,7 +67,7 @@ struct AST_Stmt_While;
struct AST_Struct; struct AST_Struct;
struct AST_Template; struct AST_Template;
struct AST_Typename; struct AST_Type;
struct AST_Typedef; struct AST_Typedef;
struct AST_Union; struct AST_Union;
struct AST_Using; struct AST_Using;
@ -145,7 +145,7 @@ Define_Code(Stmt_While);
Define_Code(Struct); Define_Code(Struct);
Define_Code(Template); Define_Code(Template);
Define_Code(Typename); Define_Code(Type);
Define_Code(Typedef); Define_Code(Typedef);
Define_Code(Union); Define_Code(Union);
Define_Code(Using); Define_Code(Using);
@ -260,7 +260,7 @@ struct Code
operator CodeSpecifiers() const; operator CodeSpecifiers() const;
operator CodeStruct() const; operator CodeStruct() const;
operator CodeTemplate() const; operator CodeTemplate() const;
operator CodeTypename() const; operator CodeType() const;
operator CodeTypedef() const; operator CodeTypedef() const;
operator CodeUnion() const; operator CodeUnion() const;
operator CodeUsing() const; operator CodeUsing() const;
@ -294,7 +294,7 @@ int AST_ArrSpecs_Cap =
- sizeof(parser::Token*) - sizeof(parser::Token*)
- sizeof(AST*) - sizeof(AST*)
- sizeof(StringCached) - sizeof(StringCached)
- sizeof(CodeType) - sizeof(CodeT)
- sizeof(ModuleFlag) - sizeof(ModuleFlag)
- sizeof(int) - sizeof(int)
) )
@ -337,7 +337,7 @@ struct AST
}; };
StringCached Content; // Attributes, Comment, Execution, Include StringCached Content; // Attributes, Comment, Execution, Include
struct { struct {
Specifier ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used. Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
}; };
}; };
@ -353,13 +353,13 @@ struct AST
parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing. parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
Code Parent; Code Parent;
StringCached Name; StringCached Name;
CodeType Type; CodeT Type;
// CodeFlag CodeFlags; // CodeFlag CodeFlags;
ModuleFlag ModuleFlags; ModuleFlag ModuleFlags;
union { union {
b32 IsFunction; // Used by typedef to not serialize the name field. 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. b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
Operator Op; OperatorT Op;
AccessSpec ParentAccess; AccessSpec ParentAccess;
s32 NumEntries; s32 NumEntries;
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression. s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.

View File

@ -1,78 +1,78 @@
# define GEN_AST_BODY_CLASS_UNALLOWED_TYPES \ # define GEN_AST_BODY_CLASS_UNALLOWED_TYPES \
case CT_PlatformAttributes: \ case PlatformAttributes: \
case CT_Class_Body: \ case Class_Body: \
case CT_Enum_Body: \ case Enum_Body: \
case CT_Extern_Linkage: \ case Extern_Linkage: \
case CT_Function_Body: \ case Function_Body: \
case CT_Function_Fwd: \ case Function_Fwd: \
case CT_Global_Body: \ case Global_Body: \
case CT_Namespace: \ case Namespace: \
case CT_Namespace_Body: \ case Namespace_Body: \
case CT_Operator: \ case Operator: \
case CT_Operator_Fwd: \ case Operator_Fwd: \
case CT_Parameters: \ case Parameters: \
case CT_Specifiers: \ case Specifiers: \
case CT_Struct_Body: \ case Struct_Body: \
case CT_Typename: case Typename:
# define GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES # define GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES
# define GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES \ # define GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES \
case CT_Access_Public: \ case Access_Public: \
case CT_Access_Protected: \ case Access_Protected: \
case CT_Access_Private: \ case Access_Private: \
case CT_PlatformAttributes: \ case PlatformAttributes: \
case CT_Class_Body: \ case Class_Body: \
case CT_Enum_Body: \ case Enum_Body: \
case CT_Extern_Linkage: \ case Extern_Linkage: \
case CT_Friend: \ case Friend: \
case CT_Function_Body: \ case Function_Body: \
case CT_Function_Fwd: \ case Function_Fwd: \
case CT_Global_Body: \ case Global_Body: \
case CT_Namespace: \ case Namespace: \
case CT_Namespace_Body: \ case Namespace_Body: \
case CT_Operator: \ case Operator: \
case CT_Operator_Fwd: \ case Operator_Fwd: \
case CT_Operator_Member: \ case Operator_Member: \
case CT_Operator_Member_Fwd: \ case Operator_Member_Fwd: \
case CT_Parameters: \ case Parameters: \
case CT_Specifiers: \ case Specifiers: \
case CT_Struct_Body: \ case Struct_Body: \
case CT_Typename: case Typename:
# define GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES \ # define GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES \
case CT_Access_Public: \ case Access_Public: \
case CT_Access_Protected: \ case Access_Protected: \
case CT_Access_Private: \ case Access_Private: \
case CT_PlatformAttributes: \ case PlatformAttributes: \
case CT_Class_Body: \ case Class_Body: \
case CT_Enum_Body: \ case Enum_Body: \
case CT_Execution: \ case Execution: \
case CT_Friend: \ case Friend: \
case CT_Function_Body: \ case Function_Body: \
case CT_Namespace_Body: \ case Namespace_Body: \
case CT_Operator_Member: \ case Operator_Member: \
case CT_Operator_Member_Fwd: \ case Operator_Member_Fwd: \
case CT_Parameters: \ case Parameters: \
case CT_Specifiers: \ case Specifiers: \
case CT_Struct_Body: \ case Struct_Body: \
case CT_Typename: case Typename:
# define GEN_AST_BODY_EXPORT_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES # define GEN_AST_BODY_EXPORT_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
# define GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES # define GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
# define GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES \ # define GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES \
case CT_Access_Public: \ case Access_Public: \
case CT_Access_Protected: \ case Access_Protected: \
case CT_Access_Private: \ case Access_Private: \
case CT_PlatformAttributes: \ case PlatformAttributes: \
case CT_Class_Body: \ case Class_Body: \
case CT_Enum_Body: \ case Enum_Body: \
case CT_Execution: \ case Execution: \
case CT_Friend: \ case Friend: \
case CT_Function_Body: \ case Function_Body: \
case CT_Namespace_Body: \ case Namespace_Body: \
case CT_Operator_Member: \ case Operator_Member: \
case CT_Operator_Member_Fwd: \ case Operator_Member_Fwd: \
case CT_Parameters: \ case Parameters: \
case CT_Specifiers: \ case Specifiers: \
case CT_Struct_Body: \ case Struct_Body: \
case CT_Typename: case Typename:

File diff suppressed because it is too large Load Diff

View File

@ -13,23 +13,24 @@ String to_string(CodeBody body)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( body.ast->Type ) switch ( body.ast->Type )
{ {
case CT_Untyped: using namespace ECode;
case CT_Execution: case Untyped:
case Execution:
append( & result, rcast(AST*, body.ast)->Content ); append( & result, rcast(AST*, body.ast)->Content );
break; break;
case CT_Enum_Body: case Enum_Body:
case CT_Class_Body: case Class_Body:
case CT_Extern_Linkage_Body: case Extern_Linkage_Body:
case CT_Function_Body: case Function_Body:
case CT_Global_Body: case Global_Body:
case CT_Namespace_Body: case Namespace_Body:
case CT_Struct_Body: case Struct_Body:
case CT_Union_Body: case Union_Body:
to_string( body, & result ); to_string( body, & result );
break; break;
case CT_Export_Body: case Export_Body:
to_string_export( body, & result ); to_string_export( body, & result );
break; break;
} }
@ -76,10 +77,11 @@ String to_string(CodeConstructor self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch (self->Type) switch (self->Type)
{ {
case CT_Constructor: using namespace ECode;
case Constructor:
to_string_def( self, & result ); to_string_def( self, & result );
break; break;
case CT_Constructor_Fwd: case Constructor_Fwd:
to_string_fwd( self, & result ); to_string_fwd( self, & result );
break; break;
} }
@ -139,10 +141,11 @@ String to_string( CodeClass self )
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Class: using namespace ECode;
case Class:
to_string_def(self, & result ); to_string_def(self, & result );
break; break;
case CT_Class_Fwd: case Class_Fwd:
to_string_fwd(self, & result ); to_string_fwd(self, & result );
break; break;
} }
@ -170,14 +173,14 @@ void to_string_def( CodeClass self, String* result )
append_fmt( result, "%S : %s %S", ast->Name, access_level, to_string(ast->ParentType) ); append_fmt( result, "%S : %s %S", ast->Name, access_level, to_string(ast->ParentType) );
CodeTypename interface = cast(CodeTypename, ast->ParentType->Next); CodeType interface = cast(CodeType, ast->ParentType->Next);
if ( interface ) if ( interface )
append( result, "\n" ); append( result, "\n" );
while ( interface ) while ( interface )
{ {
append_fmt( result, ", %S", to_string(interface) ); append_fmt( result, ", %S", to_string(interface) );
interface = interface->Next ? cast(CodeTypename, interface->Next) : CodeTypename { nullptr }; interface = interface->Next ? cast(CodeType, interface->Next) : CodeType { nullptr };
} }
} }
else if ( ast->Name ) else if ( ast->Name )
@ -192,7 +195,7 @@ void to_string_def( CodeClass self, String* result )
append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) ); append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != CT_Typedef && ast->Parent->Type != CT_Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
append( result, ";\n"); append( result, ";\n");
} }
@ -210,7 +213,7 @@ void to_string_fwd( CodeClass self, String* result )
else append_fmt( result, "class %S", ast->Name ); else append_fmt( result, "class %S", ast->Name );
// Check if it can have an end-statement // Check if it can have an end-statement
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != CT_Typedef && ast->Parent->Type != CT_Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
{ {
if ( ast->InlineCmt ) if ( ast->InlineCmt )
append_fmt( result, "; // %S\n", ast->InlineCmt->Content ); append_fmt( result, "; // %S\n", ast->InlineCmt->Content );
@ -234,10 +237,11 @@ String to_string(CodeDestructor self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Destructor: using namespace ECode;
case Destructor:
to_string_def( self, & result ); to_string_def( self, & result );
break; break;
case CT_Destructor_Fwd: case Destructor_Fwd:
to_string_fwd( self, & result ); to_string_fwd( self, & result );
break; break;
} }
@ -252,7 +256,7 @@ void to_string_def(CodeDestructor self, String* result )
} }
else if ( self->Specs ) else if ( self->Specs )
{ {
if ( has(self->Specs, Spec_Virtual ) ) if ( has(self->Specs, ESpecifier::Virtual ) )
append_fmt( result, "virtual ~%S()", self->Parent->Name ); append_fmt( result, "virtual ~%S()", self->Parent->Name );
else else
append_fmt( result, "~%S()", self->Parent->Name ); append_fmt( result, "~%S()", self->Parent->Name );
@ -267,12 +271,12 @@ void to_string_fwd(CodeDestructor self, String* result )
{ {
if ( self->Specs ) if ( self->Specs )
{ {
if ( has(self->Specs, Spec_Virtual ) ) if ( has(self->Specs, ESpecifier::Virtual ) )
append_fmt( result, "virtual ~%S();\n", self->Parent->Name ); append_fmt( result, "virtual ~%S();\n", self->Parent->Name );
else else
append_fmt( result, "~%S()", self->Parent->Name ); append_fmt( result, "~%S()", self->Parent->Name );
if ( has(self->Specs, Spec_Pure ) ) if ( has(self->Specs, ESpecifier::Pure ) )
append( result, " = 0;" ); append( result, " = 0;" );
else if (self->Body) else if (self->Body)
append_fmt( result, " = %S;", GEN_NS to_string(self->Body) ); append_fmt( result, " = %S;", GEN_NS to_string(self->Body) );
@ -291,16 +295,17 @@ String to_string(CodeEnum self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Enum: using namespace ECode;
case Enum:
to_string_def(self, & result ); to_string_def(self, & result );
break; break;
case CT_Enum_Fwd: case Enum_Fwd:
to_string_fwd(self, & result ); to_string_fwd(self, & result );
break; break;
case CT_Enum_Class: case Enum_Class:
to_string_class_def(self, & result ); to_string_class_def(self, & result );
break; break;
case CT_Enum_Class_Fwd: case Enum_Class_Fwd:
to_string_class_fwd(self, & result ); to_string_class_fwd(self, & result );
break; break;
} }
@ -336,7 +341,7 @@ void to_string_def(CodeEnum self, String* result )
} }
else append_fmt( result, "enum %S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) ); else append_fmt( result, "enum %S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) );
if ( self->Parent.ast == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
append( result, ";\n"); append( result, ";\n");
} }
@ -353,7 +358,7 @@ void to_string_fwd(CodeEnum self, String* result )
else else
append_fmt( result, "enum %S", self->Name ); append_fmt( result, "enum %S", self->Name );
if ( self->Parent.ast == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
{ {
if ( self->InlineCmt ) if ( self->InlineCmt )
append_fmt( result, "; %S", self->InlineCmt->Content ); append_fmt( result, "; %S", self->InlineCmt->Content );
@ -390,7 +395,7 @@ void to_string_class_def(CodeEnum self, String* result )
append_fmt( result, "enum class %S\n{\n%S\n}", GEN_NS to_string(self->Body) ); append_fmt( result, "enum class %S\n{\n%S\n}", GEN_NS to_string(self->Body) );
} }
if ( self->Parent.ast == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
append( result, ";\n"); append( result, ";\n");
} }
@ -406,7 +411,7 @@ void to_string_class_fwd(CodeEnum self, String* result )
append_fmt( result, "%S : %S", self->Name, to_string(self->UnderlyingType) ); append_fmt( result, "%S : %S", self->Name, to_string(self->UnderlyingType) );
if ( self->Parent.ast == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
{ {
if ( self->InlineCmt ) if ( self->InlineCmt )
append_fmt( result, "; %S", self->InlineCmt->Content ); append_fmt( result, "; %S", self->InlineCmt->Content );
@ -449,7 +454,7 @@ void to_string(CodeFriend self, String* result )
{ {
append_fmt( result, "friend %S", GEN_NS to_string(self->Declaration) ); append_fmt( result, "friend %S", GEN_NS to_string(self->Declaration) );
if ( self->Declaration->Type != CT_Function && (* result)[ length(* result) - 1 ] != ';' ) if ( self->Declaration->Type != ECode::Function && (* result)[ length(* result) - 1 ] != ';' )
{ {
append( result, ";" ); append( result, ";" );
} }
@ -465,10 +470,11 @@ String to_string(CodeFn self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Function: using namespace ECode;
case Function:
to_string_def(self, & result ); to_string_def(self, & result );
break; break;
case CT_Function_Fwd: case Function_Fwd:
to_string_fwd(self, & result ); to_string_fwd(self, & result );
break; break;
} }
@ -486,11 +492,11 @@ void to_string_def(CodeFn self, String* result )
bool prefix_specs = false; bool prefix_specs = false;
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ! is_trailing( spec ) ) if ( ! ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
prefix_specs = true; prefix_specs = true;
@ -515,11 +521,11 @@ void to_string_def(CodeFn self, String* result )
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
@ -539,11 +545,11 @@ void to_string_fwd(CodeFn self, String* result )
b32 prefix_specs = false; b32 prefix_specs = false;
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ! is_trailing( spec ) || ! (spec != Spec_Pure) ) if ( ! ESpecifier::is_trailing( spec ) || ! (spec != ESpecifier::Pure) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
prefix_specs = true; prefix_specs = true;
@ -570,17 +576,17 @@ void to_string_fwd(CodeFn self, String* result )
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
} }
if ( self->Specs && has(self->Specs, Spec_Pure ) >= 0 ) if ( self->Specs && has(self->Specs, ESpecifier::Pure ) >= 0 )
append( result, " = 0;" ); append( result, " = 0;" );
else if (self->Body) else if (self->Body)
append_fmt( result, " = %S;", GEN_NS to_string(self->Body) ); append_fmt( result, " = %S;", GEN_NS to_string(self->Body) );
@ -629,12 +635,13 @@ String to_string(CodeOperator self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Operator: using namespace ECode;
case CT_Operator_Member: case Operator:
case Operator_Member:
to_string_def( self, & result ); to_string_def( self, & result );
break; break;
case CT_Operator_Fwd: case Operator_Fwd:
case CT_Operator_Member_Fwd: case Operator_Member_Fwd:
to_string_fwd( self, & result ); to_string_fwd( self, & result );
break; break;
} }
@ -654,11 +661,11 @@ void to_string_def(CodeOperator self, String* result )
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ! is_trailing( spec ) ) if ( ! ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
@ -680,11 +687,11 @@ void to_string_def(CodeOperator self, String* result )
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
@ -705,11 +712,11 @@ void to_string_fwd(CodeOperator self, String* result )
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ! is_trailing( spec ) ) if ( ! ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
@ -730,11 +737,11 @@ void to_string_fwd(CodeOperator self, String* result )
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
@ -751,10 +758,11 @@ String to_string(CodeOpCast self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Operator_Cast: using namespace ECode;
case Operator_Cast:
to_string_def(self, & result ); to_string_def(self, & result );
break; break;
case CT_Operator_Cast_Fwd: case Operator_Cast_Fwd:
to_string_fwd(self, & result ); to_string_fwd(self, & result );
break; break;
} }
@ -765,11 +773,11 @@ void to_string_def(CodeOpCast self, String* result )
{ {
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ! is_trailing( spec ) ) if ( ! ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, "%*s ", spec_str.Len, spec_str.Ptr ); append_fmt( result, "%*s ", spec_str.Len, spec_str.Ptr );
} }
} }
@ -779,11 +787,11 @@ void to_string_def(CodeOpCast self, String* result )
else else
append_fmt( result, "operator %S()", to_string(self->ValueType) ); append_fmt( result, "operator %S()", to_string(self->ValueType) );
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
@ -802,22 +810,22 @@ void to_string_fwd(CodeOpCast self, String* result )
{ {
if ( self->Specs ) if ( self->Specs )
{ {
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ! is_trailing( spec ) ) if ( ! ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, "%*s ", spec_str.Len, spec_str.Ptr ); append_fmt( result, "%*s ", spec_str.Len, spec_str.Ptr );
} }
} }
append_fmt( result, "operator %S()", to_string(self->ValueType) ); append_fmt( result, "operator %S()", to_string(self->ValueType) );
for ( Specifier spec : self->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %*s", spec_str.Len, spec_str.Ptr );
} }
} }
@ -885,22 +893,23 @@ String to_string(CodePreprocessCond self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Preprocess_If: using namespace ECode;
case Preprocess_If:
to_string_if( self, & result ); to_string_if( self, & result );
break; break;
case CT_Preprocess_IfDef: case Preprocess_IfDef:
to_string_ifdef( self, & result ); to_string_ifdef( self, & result );
break; break;
case CT_Preprocess_IfNotDef: case Preprocess_IfNotDef:
to_string_ifndef( self, & result ); to_string_ifndef( self, & result );
break; break;
case CT_Preprocess_ElIf: case Preprocess_ElIf:
to_string_elif( self, & result ); to_string_elif( self, & result );
break; break;
case CT_Preprocess_Else: case Preprocess_Else:
to_string_else( self, & result ); to_string_else( self, & result );
break; break;
case CT_Preprocess_EndIf: case Preprocess_EndIf:
to_string_endif( self, & result ); to_string_endif( self, & result );
break; break;
} }
@ -964,7 +973,7 @@ void to_string( CodeSpecifiers self, String* result )
s32 left = self->NumEntries; s32 left = self->NumEntries;
while ( left-- ) while ( left-- )
{ {
StrC spec = to_str( self->ArrSpecs[idx] ); StrC spec = ESpecifier::to_str( self->ArrSpecs[idx] );
append_fmt( result, "%.*s ", spec.Len, spec.Ptr ); append_fmt( result, "%.*s ", spec.Len, spec.Ptr );
idx++; idx++;
} }
@ -976,10 +985,11 @@ String to_string(CodeStruct self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Struct: using namespace ECode;
case Struct:
to_string_def( self, & result ); to_string_def( self, & result );
break; break;
case CT_Struct_Fwd: case Struct_Fwd:
to_string_fwd( self, & result ); to_string_fwd( self, & result );
break; break;
} }
@ -1007,14 +1017,14 @@ void to_string_def( CodeStruct self, String* result )
append_fmt( result, "%S : %s %S", ast->Name, access_level, GEN_NS to_string(ast->ParentType) ); append_fmt( result, "%S : %s %S", ast->Name, access_level, GEN_NS to_string(ast->ParentType) );
CodeTypename interface = cast(CodeTypename, ast->ParentType->Next); CodeType interface = cast(CodeType, ast->ParentType->Next);
if ( interface ) if ( interface )
append( result, "\n" ); append( result, "\n" );
while ( interface ) while ( interface )
{ {
append_fmt( result, ", %S", GEN_NS to_string(interface) ); append_fmt( result, ", %S", GEN_NS to_string(interface) );
interface = interface->Next ? cast( CodeTypename, interface->Next) : CodeTypename { nullptr }; interface = interface->Next ? cast( CodeType, interface->Next) : CodeType { nullptr };
} }
} }
else if ( ast->Name ) else if ( ast->Name )
@ -1029,7 +1039,7 @@ void to_string_def( CodeStruct self, String* result )
append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) ); append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != CT_Typedef && ast->Parent->Type != CT_Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
append( result, ";\n"); append( result, ";\n");
} }
@ -1046,7 +1056,7 @@ void to_string_fwd( CodeStruct self, String* result )
else append_fmt( result, "struct %S", ast->Name ); else append_fmt( result, "struct %S", ast->Name );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != CT_Typedef && ast->Parent->Type != CT_Variable ) ) if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
{ {
if ( ast->InlineCmt ) if ( ast->InlineCmt )
append_fmt( result, "; %S", ast->InlineCmt->Content ); append_fmt( result, "; %S", ast->InlineCmt->Content );
@ -1093,7 +1103,7 @@ void to_string(CodeTypedef self, String* result )
else else
append_fmt( result, "%S %S", GEN_NS to_string(self->UnderlyingType), self->Name ); append_fmt( result, "%S %S", GEN_NS to_string(self->UnderlyingType), self->Name );
if ( self->UnderlyingType->Type == CT_Typename && self->UnderlyingType->ArrExpr ) if ( self->UnderlyingType->Type == ECode::Typename && self->UnderlyingType->ArrExpr )
{ {
append_fmt( result, "[ %S ];", GEN_NS to_string(self->UnderlyingType->ArrExpr) ); append_fmt( result, "[ %S ];", GEN_NS to_string(self->UnderlyingType->ArrExpr) );
@ -1115,14 +1125,14 @@ void to_string(CodeTypedef self, String* result )
append( result, "\n"); append( result, "\n");
} }
String to_string(CodeTypename self) String to_string(CodeType self)
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
to_string( self, & result ); to_string( self, & result );
return result; return result;
} }
void to_string(CodeTypename self, String* result ) void to_string(CodeType self, String* result )
{ {
#if defined(GEN_USE_NEW_TYPENAME_PARSING) #if defined(GEN_USE_NEW_TYPENAME_PARSING)
if ( self->ReturnType && self->Params ) if ( self->ReturnType && self->Params )
@ -1200,7 +1210,7 @@ void to_string(CodeUnion self, String* result )
); );
} }
if ( self->Parent.ast == nullptr || ( self->Parent->Type != CT_Typedef && self->Parent->Type != CT_Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
append( result, ";\n"); append( result, ";\n");
} }
@ -1209,10 +1219,11 @@ String to_string(CodeUsing self)
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( self->Type ) switch ( self->Type )
{ {
case CT_Using: using namespace ECode;
case Using:
to_string( self, & result ); to_string( self, & result );
break; break;
case CT_Using_Namespace: case Using_Namespace:
to_string_ns( self, & result ); to_string_ns( self, & result );
break; break;
} }
@ -1271,7 +1282,7 @@ String to_string(CodeVar self)
void to_string(CodeVar self, String* result ) void to_string(CodeVar self, String* result )
{ {
if ( self->Parent && self->Parent->Type == CT_Variable ) if ( self->Parent && self->Parent->Type == ECode::Variable )
{ {
// Its a comma-separated variable ( a NextVar ) // Its a comma-separated variable ( a NextVar )

View File

@ -27,14 +27,14 @@ void to_string (CodeParam params, String* result );
CodeParam begin(CodeParam params); CodeParam begin(CodeParam params);
CodeParam end (CodeParam params); CodeParam end (CodeParam params);
bool append (CodeSpecifiers specifiers, Specifier spec); bool append (CodeSpecifiers specifiers, SpecifierT spec);
s32 has (CodeSpecifiers specifiers, Specifier spec); s32 has (CodeSpecifiers specifiers, SpecifierT spec);
s32 remove (CodeSpecifiers specifiers, Specifier to_remove ); s32 remove (CodeSpecifiers specifiers, SpecifierT to_remove );
String to_string(CodeSpecifiers specifiers); String to_string(CodeSpecifiers specifiers);
void to_string(CodeSpecifiers specifiers, String* result); void to_string(CodeSpecifiers specifiers, String* result);
Specifier* begin(CodeSpecifiers specifiers ); SpecifierT* begin(CodeSpecifiers specifiers );
Specifier* end (CodeSpecifiers specifiers); SpecifierT* end (CodeSpecifiers specifiers);
void add_interface(CodeStruct self, CodeType interface); void add_interface(CodeStruct self, CodeType interface);
String to_string (CodeStruct self); String to_string (CodeStruct self);
@ -103,8 +103,8 @@ void to_string_endif (CodePreprocessCond cond, String* result );
String to_string(CodeTemplate self); String to_string(CodeTemplate self);
void to_string(CodeTemplate self, String* result); void to_string(CodeTemplate self, String* result);
String to_string(CodeTypename self); String to_string(CodeType self);
void to_string(CodeTypename self, String* result); void to_string(CodeType self, String* result);
String to_string(CodeTypedef self); String to_string(CodeTypedef self);
void to_string(CodeTypedef self, String* result); void to_string(CodeTypedef self, String* result);
@ -927,19 +927,19 @@ struct CodeTemplate
AST_Template* ast; AST_Template* ast;
}; };
struct CodeTypename struct CodeType
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeTypename ); Using_Code( CodeType );
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); }
#endif #endif
Using_CodeOps( CodeTypename ); Using_CodeOps( CodeType );
operator Code(); operator Code();
AST_Typename* operator->(); AST_Type* operator->();
AST_Typename* ast; AST_Type* ast;
}; };
struct CodeTypedef struct CodeTypedef
@ -1040,7 +1040,7 @@ struct InvalidCode_ImplictCaster
operator CodeSpecifiers () const { return cast(CodeSpecifiers, Code_Invalid); } operator CodeSpecifiers () const { return cast(CodeSpecifiers, Code_Invalid); }
operator CodeStruct () const { return cast(CodeStruct, Code_Invalid); } operator CodeStruct () const { return cast(CodeStruct, Code_Invalid); }
operator CodeTemplate () const { return cast(CodeTemplate, Code_Invalid); } operator CodeTemplate () const { return cast(CodeTemplate, Code_Invalid); }
operator CodeTypename () const { return cast(CodeTypename, Code_Invalid); } operator CodeType () const { return cast(CodeType, Code_Invalid); }
operator CodeTypedef () const { return cast(CodeTypedef, Code_Invalid); } operator CodeTypedef () const { return cast(CodeTypedef, Code_Invalid); }
operator CodeUnion () const { return cast(CodeUnion, Code_Invalid); } operator CodeUnion () const { return cast(CodeUnion, Code_Invalid); }
operator CodeUsing () const { return cast(CodeUsing, Code_Invalid); } operator CodeUsing () const { return cast(CodeUsing, Code_Invalid); }

View File

@ -661,7 +661,7 @@ inline AST_Template* CodeTemplate::operator->()
return ast; return ast;
} }
inline CodeTypename& CodeTypename::operator=( Code other ) inline CodeType& CodeType::operator=( Code other )
{ {
if ( other.ast && other->Parent ) if ( other.ast && other->Parent )
{ {
@ -672,17 +672,17 @@ inline CodeTypename& CodeTypename::operator=( Code other )
return *this; return *this;
} }
inline CodeTypename::operator bool() inline CodeType::operator bool()
{ {
return ast != nullptr; return ast != nullptr;
} }
inline CodeTypename::operator Code() inline CodeType::operator Code()
{ {
return *rcast( Code*, this ); return *rcast( Code*, this );
} }
inline AST_Typename* CodeTypename::operator->() inline AST_Type* CodeType::operator->()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
{ {
@ -935,9 +935,9 @@ inline Code::operator CodeTemplate() const
return { (AST_Template*)ast }; return { (AST_Template*)ast };
} }
inline Code::operator CodeTypename() const inline Code::operator CodeType() const
{ {
return { (AST_Typename*)ast }; return { (AST_Type*)ast };
} }
inline Code::operator CodeTypedef() const inline Code::operator CodeTypedef() const

View File

@ -5,74 +5,74 @@
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
typedef enum CodeType_Def CodeType; namespace ECode
enum CodeType_Def : u32
{ {
CT_Invalid, enum Type : u32
CT_Untyped, {
CT_NewLine, Invalid,
CT_Comment, Untyped,
CT_Access_Private, NewLine,
CT_Access_Protected, Comment,
CT_Access_Public, Access_Private,
CT_PlatformAttributes, Access_Protected,
CT_Class, Access_Public,
CT_Class_Fwd, PlatformAttributes,
CT_Class_Body, Class,
CT_Constructor, Class_Fwd,
CT_Constructor_Fwd, Class_Body,
CT_Destructor, Constructor,
CT_Destructor_Fwd, Constructor_Fwd,
CT_Enum, Destructor,
CT_Enum_Fwd, Destructor_Fwd,
CT_Enum_Body, Enum,
CT_Enum_Class, Enum_Fwd,
CT_Enum_Class_Fwd, Enum_Body,
CT_Execution, Enum_Class,
CT_Export_Body, Enum_Class_Fwd,
CT_Extern_Linkage, Execution,
CT_Extern_Linkage_Body, Export_Body,
CT_Friend, Extern_Linkage,
CT_Function, Extern_Linkage_Body,
CT_Function_Fwd, Friend,
CT_Function_Body, Function,
CT_Global_Body, Function_Fwd,
CT_Module, Function_Body,
CT_Namespace, Global_Body,
CT_Namespace_Body, Module,
CT_Operator, Namespace,
CT_Operator_Fwd, Namespace_Body,
CT_Operator_Member, Operator,
CT_Operator_Member_Fwd, Operator_Fwd,
CT_Operator_Cast, Operator_Member,
CT_Operator_Cast_Fwd, Operator_Member_Fwd,
CT_Parameters, Operator_Cast,
CT_Preprocess_Define, Operator_Cast_Fwd,
CT_Preprocess_Include, Parameters,
CT_Preprocess_If, Preprocess_Define,
CT_Preprocess_IfDef, Preprocess_Include,
CT_Preprocess_IfNotDef, Preprocess_If,
CT_Preprocess_ElIf, Preprocess_IfDef,
CT_Preprocess_Else, Preprocess_IfNotDef,
CT_Preprocess_EndIf, Preprocess_ElIf,
CT_Preprocess_Pragma, Preprocess_Else,
CT_Specifiers, Preprocess_EndIf,
CT_Struct, Preprocess_Pragma,
CT_Struct_Fwd, Specifiers,
CT_Struct_Body, Struct,
CT_Template, Struct_Fwd,
CT_Typedef, Struct_Body,
CT_Typename, Template,
CT_Union, Typedef,
CT_Union_Body, Typename,
CT_Using, Union,
CT_Using_Namespace, Union_Body,
CT_Variable, Using,
CT_NumTypes Using_Namespace,
Variable,
NumTypes
}; };
inline StrC to_str( CodeType type ) inline StrC to_str( Type type )
{ {
local_persist StrC lookup[] { local_persist StrC lookup[] {
{ sizeof( "Invalid" ), "Invalid" }, { sizeof( "Invalid" ), "Invalid" },
@ -138,3 +138,7 @@ inline StrC to_str( CodeType type )
}; };
return lookup[type]; return lookup[type];
} }
} // namespace ECode
using CodeT = ECode::Type;

View File

@ -5,61 +5,61 @@
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
typedef enum Operator_Def Operator; namespace EOperator
enum Operator_Def : u32
{ {
Op_Invalid, enum Type : u32
Op_Assign, {
Op_Assign_Add, Invalid,
Op_Assign_Subtract, Assign,
Op_Assign_Multiply, Assign_Add,
Op_Assign_Divide, Assign_Subtract,
Op_Assign_Modulo, Assign_Multiply,
Op_Assign_BAnd, Assign_Divide,
Op_Assign_BOr, Assign_Modulo,
Op_Assign_BXOr, Assign_BAnd,
Op_Assign_LShift, Assign_BOr,
Op_Assign_RShift, Assign_BXOr,
Op_Increment, Assign_LShift,
Op_Decrement, Assign_RShift,
Op_Unary_Plus, Increment,
Op_Unary_Minus, Decrement,
Op_UnaryNot, Unary_Plus,
Op_Add, Unary_Minus,
Op_Subtract, UnaryNot,
Op_Multiply, Add,
Op_Divide, Subtract,
Op_Modulo, Multiply,
Op_BNot, Divide,
Op_BAnd, Modulo,
Op_BOr, BNot,
Op_BXOr, BAnd,
Op_LShift, BOr,
Op_RShift, BXOr,
Op_LAnd, LShift,
Op_LOr, RShift,
Op_LEqual, LAnd,
Op_LNot, LOr,
Op_Lesser, LEqual,
Op_Greater, LNot,
Op_LesserEqual, Lesser,
Op_GreaterEqual, Greater,
Op_Subscript, LesserEqual,
Op_Indirection, GreaterEqual,
Op_AddressOf, Subscript,
Op_MemberOfPointer, Indirection,
Op_PtrToMemOfPtr, AddressOf,
Op_FunctionCall, MemberOfPointer,
Op_Comma, PtrToMemOfPtr,
Op_New, FunctionCall,
Op_NewArray, Comma,
Op_Delete, New,
Op_DeleteArray, NewArray,
Delete,
DeleteArray,
NumOps NumOps
}; };
inline StrC to_str( Operator op ) inline StrC to_str( Type op )
{ {
local_persist StrC lookup[] { local_persist StrC lookup[] {
{ sizeof( "INVALID" ), "INVALID" }, { sizeof( "INVALID" ), "INVALID" },
@ -112,3 +112,7 @@ inline StrC to_str( Operator op )
}; };
return lookup[op]; return lookup[op];
} }
} // namespace EOperator
using OperatorT = EOperator::Type;

View File

@ -5,45 +5,45 @@
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
typedef enum Specifier_Def Specifier; namespace ESpecifier
enum Specifier_Def : u32
{ {
Spec_Invalid, enum Type : u32
Spec_Consteval, {
Spec_Constexpr, Invalid,
Spec_Constinit, Consteval,
Spec_Explicit, Constexpr,
Spec_External_Linkage, Constinit,
Spec_ForceInline, Explicit,
Spec_Global, External_Linkage,
Spec_Inline, ForceInline,
Spec_Internal_Linkage, Global,
Spec_Local_Persist, Inline,
Spec_Mutable, Internal_Linkage,
Spec_NeverInline, Local_Persist,
Spec_Ptr, Mutable,
Spec_Ref, NeverInline,
Spec_Register, Ptr,
Spec_RValue, Ref,
Spec_Static, Register,
Spec_Thread_Local, RValue,
Spec_Virtual, Static,
Spec_Const, Thread_Local,
Spec_Final, Virtual,
Spec_NoExceptions, Const,
Spec_Override, Final,
Spec_Pure, NoExceptions,
Spec_Volatile, Override,
Spec_NumSpecifiers Pure,
Volatile,
NumSpecifiers
}; };
inline bool is_trailing( Specifier specifier ) inline bool is_trailing( Type specifier )
{ {
return specifier > Spec_Virtual; return specifier > Virtual;
} }
inline StrC to_str( Specifier type ) inline StrC to_str( Type type )
{ {
local_persist StrC lookup[] { local_persist StrC lookup[] {
{ sizeof( "INVALID" ), "INVALID" }, { sizeof( "INVALID" ), "INVALID" },
@ -76,19 +76,23 @@ inline StrC to_str( Specifier type )
return lookup[type]; return lookup[type];
} }
inline Specifier to_specifier( StrC str ) inline Type to_type( StrC str )
{ {
local_persist u32 keymap[Spec_NumSpecifiers]; local_persist u32 keymap[NumSpecifiers];
do_once_start for ( u32 index = 0; index < Spec_NumSpecifiers; index++ ) do_once_start for ( u32 index = 0; index < NumSpecifiers; index++ )
{ {
StrC enum_str = to_str( (Specifier)index ); StrC enum_str = to_str( (Type)index );
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 ); keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
} }
do_once_end u32 hash = crc32( str.Ptr, str.Len ); do_once_end u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ ) for ( u32 index = 0; index < NumSpecifiers; index++ )
{ {
if ( keymap[index] == hash ) if ( keymap[index] == hash )
return (Specifier)index; return (Type)index;
} }
return Spec_Invalid; return Invalid;
} }
} // namespace ESpecifier
using SpecifierT = ESpecifier::Type;

View File

@ -5,114 +5,115 @@
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
GEN_NS_PARSER_BEGIN namespace parser
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" )
typedef enum TokType_Def TokType;
enum TokType_Def : u32
{ {
Tok_Invalid, namespace ETokType
Tok_Access_Private, {
Tok_Access_Protected, #define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Attribute_API_Import, "GEN_API_Import_Code" )
Tok_Access_Public,
Tok_Access_MemberSymbol, enum Type : u32
Tok_Access_StaticSymbol, {
Tok_Ampersand, Invalid,
Tok_Ampersand_DBL, Access_Private,
Tok_Assign_Classifer, Access_Protected,
Tok_Attribute_Open, Access_Public,
Tok_Attribute_Close, Access_MemberSymbol,
Tok_BraceCurly_Open, Access_StaticSymbol,
Tok_BraceCurly_Close, Ampersand,
Tok_BraceSquare_Open, Ampersand_DBL,
Tok_BraceSquare_Close, Assign_Classifer,
Tok_Capture_Start, Attribute_Open,
Tok_Capture_End, Attribute_Close,
Tok_Comment, BraceCurly_Open,
Tok_Comment_End, BraceCurly_Close,
Tok_Comment_Start, BraceSquare_Open,
Tok_Char, BraceSquare_Close,
Tok_Comma, Capture_Start,
Tok_Decl_Class, Capture_End,
Tok_Decl_GNU_Attribute, Comment,
Tok_Decl_MSVC_Attribute, Comment_End,
Tok_Decl_Enum, Comment_Start,
Tok_Decl_Extern_Linkage, Char,
Tok_Decl_Friend, Comma,
Tok_Decl_Module, Decl_Class,
Tok_Decl_Namespace, Decl_GNU_Attribute,
Tok_Decl_Operator, Decl_MSVC_Attribute,
Tok_Decl_Struct, Decl_Enum,
Tok_Decl_Template, Decl_Extern_Linkage,
Tok_Decl_Typedef, Decl_Friend,
Tok_Decl_Using, Decl_Module,
Tok_Decl_Union, Decl_Namespace,
Tok_Identifier, Decl_Operator,
Tok_Module_Import, Decl_Struct,
Tok_Module_Export, Decl_Template,
Tok_NewLine, Decl_Typedef,
Tok_Number, Decl_Using,
Tok_Operator, Decl_Union,
Tok_Preprocess_Hash, Identifier,
Tok_Preprocess_Define, Module_Import,
Tok_Preprocess_If, Module_Export,
Tok_Preprocess_IfDef, NewLine,
Tok_Preprocess_IfNotDef, Number,
Tok_Preprocess_ElIf, Operator,
Tok_Preprocess_Else, Preprocess_Hash,
Tok_Preprocess_EndIf, Preprocess_Define,
Tok_Preprocess_Include, Preprocess_If,
Tok_Preprocess_Pragma, Preprocess_IfDef,
Tok_Preprocess_Content, Preprocess_IfNotDef,
Tok_Preprocess_Macro, Preprocess_ElIf,
Tok_Preprocess_Unsupported, Preprocess_Else,
Tok_Spec_Alignas, Preprocess_EndIf,
Tok_Spec_Const, Preprocess_Include,
Tok_Spec_Consteval, Preprocess_Pragma,
Tok_Spec_Constexpr, Preprocess_Content,
Tok_Spec_Constinit, Preprocess_Macro,
Tok_Spec_Explicit, Preprocess_Unsupported,
Tok_Spec_Extern, Spec_Alignas,
Tok_Spec_Final, Spec_Const,
Tok_Spec_ForceInline, Spec_Consteval,
Tok_Spec_Global, Spec_Constexpr,
Tok_Spec_Inline, Spec_Constinit,
Tok_Spec_Internal_Linkage, Spec_Explicit,
Tok_Spec_LocalPersist, Spec_Extern,
Tok_Spec_Mutable, Spec_Final,
Tok_Spec_NeverInline, Spec_ForceInline,
Tok_Spec_Override, Spec_Global,
Tok_Spec_Static, Spec_Inline,
Tok_Spec_ThreadLocal, Spec_Internal_Linkage,
Tok_Spec_Volatile, Spec_LocalPersist,
Tok_Spec_Virtual, Spec_Mutable,
Tok_Star, Spec_NeverInline,
Tok_Statement_End, Spec_Override,
Tok_StaticAssert, Spec_Static,
Tok_String, Spec_ThreadLocal,
Tok_Type_Typename, Spec_Volatile,
Tok_Type_Unsigned, Spec_Virtual,
Tok_Type_Signed, Star,
Tok_Type_Short, Statement_End,
Tok_Type_Long, StaticAssert,
Tok_Type_bool, String,
Tok_Type_char, Type_Typename,
Tok_Type_int, Type_Unsigned,
Tok_Type_double, Type_Signed,
Tok_Type_MS_int8, Type_Short,
Tok_Type_MS_int16, Type_Long,
Tok_Type_MS_int32, Type_bool,
Tok_Type_MS_int64, Type_char,
Tok_Type_MS_W64, Type_int,
Tok_Varadic_Argument, Type_double,
Tok___Attributes_Start, Type_MS_int8,
Tok_Attribute_API_Export, Type_MS_int16,
Tok_Attribute_API_Import, Type_MS_int32,
Tok_NumTokens Type_MS_int64,
Type_MS_W64,
Varadic_Argument,
__Attributes_Start,
Attribute_API_Export,
Attribute_API_Import,
NumTokens
}; };
inline StrC to_str( TokType type ) inline StrC to_str( Type type )
{ {
local_persist StrC lookup[] { local_persist StrC lookup[] {
{ sizeof( "__invalid__" ), "__invalid__" }, { sizeof( "__invalid__" ), "__invalid__" },
@ -216,21 +217,25 @@ inline StrC to_str( TokType type )
return lookup[type]; return lookup[type];
} }
inline TokType to_toktype( StrC str ) inline Type to_type( StrC str )
{ {
local_persist u32 keymap[Tok_NumTokens]; local_persist u32 keymap[NumTokens];
do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ ) do_once_start for ( u32 index = 0; index < NumTokens; index++ )
{ {
StrC enum_str = to_str( (TokType)index ); StrC enum_str = to_str( (Type)index );
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 ); keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
} }
do_once_end u32 hash = crc32( str.Ptr, str.Len ); do_once_end u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < Tok_NumTokens; index++ ) for ( u32 index = 0; index < NumTokens; index++ )
{ {
if ( keymap[index] == hash ) if ( keymap[index] == hash )
return (TokType)index; return (Type)index;
} }
return Tok_Invalid; return Invalid;
} }
GEN_NS_PARSER_END } // namespace ETokType
using TokType = ETokType::Type;
} // namespace parser

View File

@ -97,36 +97,36 @@ extern CodeSpecifiers spec_thread_local;
extern CodeSpecifiers spec_virtual; extern CodeSpecifiers spec_virtual;
extern CodeSpecifiers spec_volatile; extern CodeSpecifiers spec_volatile;
extern CodeTypename t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance) extern CodeType t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
extern CodeTypename t_auto; extern CodeType t_auto;
extern CodeTypename t_void; extern CodeType t_void;
extern CodeTypename t_int; extern CodeType t_int;
extern CodeTypename t_bool; extern CodeType t_bool;
extern CodeTypename t_char; extern CodeType t_char;
extern CodeTypename t_wchar_t; extern CodeType t_wchar_t;
extern CodeTypename t_class; extern CodeType t_class;
extern CodeTypename t_typename; extern CodeType t_typename;
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS #ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
// Predefined typename codes. Are set to readonly and are setup during gen::init() // Predefined typename codes. Are set to readonly and are setup during gen::init()
extern CodeTypename t_b32; extern CodeType t_b32;
extern CodeTypename t_s8; extern CodeType t_s8;
extern CodeTypename t_s16; extern CodeType t_s16;
extern CodeTypename t_s32; extern CodeType t_s32;
extern CodeTypename t_s64; extern CodeType t_s64;
extern CodeTypename t_u8; extern CodeType t_u8;
extern CodeTypename t_u16; extern CodeType t_u16;
extern CodeTypename t_u32; extern CodeType t_u32;
extern CodeTypename t_u64; extern CodeType t_u64;
extern CodeTypename t_ssize; extern CodeType t_ssize;
extern CodeTypename t_usize; extern CodeType t_usize;
extern CodeTypename t_f32; extern CodeType t_f32;
extern CodeTypename t_f64; extern CodeType t_f64;
#endif #endif
#pragma endregion Constants #pragma endregion Constants

View File

@ -37,15 +37,15 @@ bool is_body(Code self)
GEN_ASSERT(self != nullptr); GEN_ASSERT(self != nullptr);
switch (self->Type) switch (self->Type)
{ {
case CT_Enum_Body: case ECode::Enum_Body:
case CT_Class_Body: case ECode::Class_Body:
case CT_Union_Body: case ECode::Union_Body:
case CT_Export_Body: case ECode::Export_Body:
case CT_Global_Body: case ECode::Global_Body:
case CT_Struct_Body: case ECode::Struct_Body:
case CT_Function_Body: case ECode::Function_Body:
case CT_Namespace_Body: case ECode::Namespace_Body:
case CT_Extern_Linkage_Body: case ECode::Extern_Linkage_Body:
return true; return true;
} }
return false; return false;
@ -69,7 +69,7 @@ Code* entry( Code self, u32 idx )
inline inline
bool is_valid(Code self) bool is_valid(Code self)
{ {
return self.ast != nullptr && self.ast->Type != CT_Invalid; return self.ast != nullptr && self.ast->Type != CodeT::Invalid;
} }
inline inline
bool has_entries(AST* self) bool has_entries(AST* self)
@ -100,7 +100,7 @@ inline
char const* type_str(Code self) char const* type_str(Code self)
{ {
GEN_ASSERT(self != nullptr); GEN_ASSERT(self != nullptr);
return to_str( self->Type ); return ECode::to_str( self->Type );
} }
#pragma endregion Code #pragma endregion Code
@ -140,10 +140,10 @@ Code end(CodeBody body ){
#pragma region CodeClass #pragma region CodeClass
inline inline
void add_interface( CodeClass self, CodeTypename type ) void add_interface( CodeClass self, CodeType type )
{ {
GEN_ASSERT(self.ast !=nullptr); GEN_ASSERT(self.ast !=nullptr);
CodeTypename possible_slot = self->ParentType; CodeType possible_slot = self->ParentType;
if ( possible_slot.ast ) if ( possible_slot.ast )
{ {
// Were adding an interface to parent type, so we need to make sure the parent type is public. // Were adding an interface to parent type, so we need to make sure the parent type is public.
@ -154,7 +154,7 @@ void add_interface( CodeClass self, CodeTypename type )
while ( possible_slot.ast != nullptr ) while ( possible_slot.ast != nullptr )
{ {
possible_slot.ast = (AST_Typename*) possible_slot->Next.ast; possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
} }
possible_slot.ast = type.ast; possible_slot.ast = type.ast;
@ -232,7 +232,7 @@ CodeParam end(CodeParam params)
#pragma region CodeSpecifiers #pragma region CodeSpecifiers
inline inline
bool append(CodeSpecifiers self, Specifier spec ) bool append(CodeSpecifiers self, SpecifierT spec )
{ {
if ( self.ast == nullptr ) if ( self.ast == nullptr )
{ {
@ -250,7 +250,7 @@ bool append(CodeSpecifiers self, Specifier spec )
return true; return true;
} }
inline inline
s32 has(CodeSpecifiers self, Specifier spec) s32 has(CodeSpecifiers self, SpecifierT spec)
{ {
GEN_ASSERT(self.ast != nullptr); GEN_ASSERT(self.ast != nullptr);
for ( s32 idx = 0; idx < self->NumEntries; idx++ ) { for ( s32 idx = 0; idx < self->NumEntries; idx++ ) {
@ -260,7 +260,7 @@ s32 has(CodeSpecifiers self, Specifier spec)
return -1; return -1;
} }
inline inline
s32 remove( CodeSpecifiers self, Specifier to_remove ) s32 remove( CodeSpecifiers self, SpecifierT to_remove )
{ {
AST_Specifiers* ast = self.ast; AST_Specifiers* ast = self.ast;
if ( ast == nullptr ) if ( ast == nullptr )
@ -280,7 +280,7 @@ s32 remove( CodeSpecifiers self, Specifier to_remove )
s32 next = 0; s32 next = 0;
for(; next < self->NumEntries; ++ curr, ++ next) for(; next < self->NumEntries; ++ curr, ++ next)
{ {
Specifier spec = self->ArrSpecs[next]; SpecifierT spec = self->ArrSpecs[next];
if (spec == to_remove) if (spec == to_remove)
{ {
result = next; result = next;
@ -301,7 +301,7 @@ s32 remove( CodeSpecifiers self, Specifier to_remove )
return result; return result;
} }
inline inline
Specifier* begin(CodeSpecifiers self) SpecifierT* begin(CodeSpecifiers self)
{ {
if ( self.ast ) if ( self.ast )
return & self->ArrSpecs[0]; return & self->ArrSpecs[0];
@ -309,7 +309,7 @@ Specifier* begin(CodeSpecifiers self)
return nullptr; return nullptr;
} }
inline inline
Specifier* end(CodeSpecifiers self) SpecifierT* end(CodeSpecifiers self)
{ {
return self->ArrSpecs + self->NumEntries; return self->ArrSpecs + self->NumEntries;
} }
@ -317,9 +317,9 @@ Specifier* end(CodeSpecifiers self)
#pragma region CodeStruct #pragma region CodeStruct
inline inline
void add_interface(CodeStruct self, CodeTypename type ) void add_interface(CodeStruct self, CodeType type )
{ {
CodeTypename possible_slot = self->ParentType; CodeType possible_slot = self->ParentType;
if ( possible_slot.ast ) if ( possible_slot.ast )
{ {
// Were adding an interface to parent type, so we need to make sure the parent type is public. // Were adding an interface to parent type, so we need to make sure the parent type is public.
@ -330,7 +330,7 @@ void add_interface(CodeStruct self, CodeTypename type )
while ( possible_slot.ast != nullptr ) while ( possible_slot.ast != nullptr )
{ {
possible_slot.ast = (AST_Typename*) possible_slot->Next.ast; possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
} }
possible_slot.ast = type.ast; possible_slot.ast = type.ast;
@ -339,23 +339,24 @@ void add_interface(CodeStruct self, CodeTypename type )
#pragma region Interface #pragma region Interface
inline inline
CodeBody def_body( CodeType type ) CodeBody def_body( CodeT type )
{ {
switch ( type ) switch ( type )
{ {
case CT_Class_Body: using namespace ECode;
case CT_Enum_Body: case Class_Body:
case CT_Export_Body: case Enum_Body:
case CT_Extern_Linkage: case Export_Body:
case CT_Function_Body: case Extern_Linkage:
case CT_Global_Body: case Function_Body:
case CT_Namespace_Body: case Global_Body:
case CT_Struct_Body: case Namespace_Body:
case CT_Union_Body: case Struct_Body:
case Union_Body:
break; break;
default: default:
log_failure( "def_body: Invalid type %s", (char const*)to_str(type) ); log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
return (CodeBody)Code_Invalid; return (CodeBody)Code_Invalid;
} }

View File

@ -81,23 +81,23 @@ void define_constants()
Code_Invalid = make_code(); Code_Invalid = make_code();
set_global(Code_Invalid); set_global(Code_Invalid);
t_empty = (CodeTypename) make_code(); t_empty = (CodeType) make_code();
t_empty->Type = CT_Typename; t_empty->Type = ECode::Typename;
t_empty->Name = get_cached_string( txt("") ); t_empty->Name = get_cached_string( txt("") );
set_global(t_empty); set_global(t_empty);
access_private = make_code(); access_private = make_code();
access_private->Type = CT_Access_Private; access_private->Type = ECode::Access_Private;
access_private->Name = get_cached_string( txt("private:\n") ); access_private->Name = get_cached_string( txt("private:\n") );
set_global(access_private); set_global(access_private);
access_protected = make_code(); access_protected = make_code();
access_protected->Type = CT_Access_Protected; access_protected->Type = ECode::Access_Protected;
access_protected->Name = get_cached_string( txt("protected:\n") ); access_protected->Name = get_cached_string( txt("protected:\n") );
set_global(access_protected); set_global(access_protected);
access_public = make_code(); access_public = make_code();
access_public->Type = CT_Access_Public; access_public->Type = ECode::Access_Public;
access_public->Name = get_cached_string( txt("public:\n") ); access_public->Name = get_cached_string( txt("public:\n") );
set_global(access_public); set_global(access_public);
@ -108,39 +108,39 @@ void define_constants()
set_global(attrib_api_import); set_global(attrib_api_import);
module_global_fragment = make_code(); module_global_fragment = make_code();
module_global_fragment->Type = CT_Untyped; module_global_fragment->Type = ECode::Untyped;
module_global_fragment->Name = get_cached_string( txt("module;") ); module_global_fragment->Name = get_cached_string( txt("module;") );
module_global_fragment->Content = module_global_fragment->Name; module_global_fragment->Content = module_global_fragment->Name;
set_global(module_global_fragment); set_global(module_global_fragment);
module_private_fragment = make_code(); module_private_fragment = make_code();
module_private_fragment->Type = CT_Untyped; module_private_fragment->Type = ECode::Untyped;
module_private_fragment->Name = get_cached_string( txt("module : private;") ); module_private_fragment->Name = get_cached_string( txt("module : private;") );
module_private_fragment->Content = module_private_fragment->Name; module_private_fragment->Content = module_private_fragment->Name;
set_global(module_private_fragment); set_global(module_private_fragment);
fmt_newline = make_code(); fmt_newline = make_code();
fmt_newline->Type = CT_NewLine; fmt_newline->Type = ECode::NewLine;
set_global(fmt_newline); set_global(fmt_newline);
pragma_once = (CodePragma) make_code(); pragma_once = (CodePragma) make_code();
pragma_once->Type = CT_Preprocess_Pragma; pragma_once->Type = ECode::Preprocess_Pragma;
pragma_once->Name = get_cached_string( txt("once") ); pragma_once->Name = get_cached_string( txt("once") );
pragma_once->Content = pragma_once->Name; pragma_once->Content = pragma_once->Name;
set_global(pragma_once); set_global(pragma_once);
param_varadic = (CodeTypename) make_code(); param_varadic = (CodeType) make_code();
param_varadic->Type = CT_Parameters; param_varadic->Type = ECode::Parameters;
param_varadic->Name = get_cached_string( txt("...") ); param_varadic->Name = get_cached_string( txt("...") );
param_varadic->ValueType = t_empty; param_varadic->ValueType = t_empty;
set_global(param_varadic); set_global(param_varadic);
preprocess_else = (CodePreprocessCond) make_code(); preprocess_else = (CodePreprocessCond) make_code();
preprocess_else->Type = CT_Preprocess_Else; preprocess_else->Type = ECode::Preprocess_Else;
set_global(preprocess_else); set_global(preprocess_else);
preprocess_endif = (CodePreprocessCond) make_code(); preprocess_endif = (CodePreprocessCond) make_code();
preprocess_endif->Type = CT_Preprocess_EndIf; preprocess_endif->Type = ECode::Preprocess_EndIf;
set_global(preprocess_endif); set_global(preprocess_endif);
# define def_constant_code_type( Type_ ) \ # define def_constant_code_type( Type_ ) \
@ -192,32 +192,32 @@ void define_constants()
# undef internal # undef internal
# undef local_persist # undef local_persist
# undef neverinline # undef neverinline
def_constant_spec( const, Spec_Const ); def_constant_spec( const, ESpecifier::Const );
def_constant_spec( consteval, Spec_Consteval ); def_constant_spec( consteval, ESpecifier::Consteval );
def_constant_spec( constexpr, Spec_Constexpr ); def_constant_spec( constexpr, ESpecifier::Constexpr );
def_constant_spec( constinit, Spec_Constinit ); def_constant_spec( constinit, ESpecifier::Constinit );
def_constant_spec( extern_linkage, Spec_External_Linkage ); def_constant_spec( extern_linkage, ESpecifier::External_Linkage );
def_constant_spec( final, Spec_Final ); def_constant_spec( final, ESpecifier::Final );
def_constant_spec( forceinline, Spec_ForceInline ); def_constant_spec( forceinline, ESpecifier::ForceInline );
def_constant_spec( global, Spec_Global ); def_constant_spec( global, ESpecifier::Global );
def_constant_spec( inline, Spec_Inline ); def_constant_spec( inline, ESpecifier::Inline );
def_constant_spec( internal_linkage, Spec_Internal_Linkage ); def_constant_spec( internal_linkage, ESpecifier::Internal_Linkage );
def_constant_spec( local_persist, Spec_Local_Persist ); def_constant_spec( local_persist, ESpecifier::Local_Persist );
def_constant_spec( mutable, Spec_Mutable ); def_constant_spec( mutable, ESpecifier::Mutable );
def_constant_spec( neverinline, Spec_NeverInline ); def_constant_spec( neverinline, ESpecifier::NeverInline );
def_constant_spec( noexcept, Spec_NoExceptions ); def_constant_spec( noexcept, ESpecifier::NoExceptions );
def_constant_spec( override, Spec_Override ); def_constant_spec( override, ESpecifier::Override );
def_constant_spec( ptr, Spec_Ptr ); def_constant_spec( ptr, ESpecifier::Ptr );
def_constant_spec( pure, Spec_Pure ) def_constant_spec( pure, ESpecifier::Pure )
def_constant_spec( ref, Spec_Ref ); def_constant_spec( ref, ESpecifier::Ref );
def_constant_spec( register, Spec_Register ); def_constant_spec( register, ESpecifier::Register );
def_constant_spec( rvalue, Spec_RValue ); def_constant_spec( rvalue, ESpecifier::RValue );
def_constant_spec( static_member, Spec_Static ); def_constant_spec( static_member, ESpecifier::Static );
def_constant_spec( thread_local, Spec_Thread_Local ); def_constant_spec( thread_local, ESpecifier::Thread_Local );
def_constant_spec( virtual, Spec_Virtual ); def_constant_spec( virtual, ESpecifier::Virtual );
def_constant_spec( volatile, Spec_Volatile) def_constant_spec( volatile, ESpecifier::Volatile)
spec_local_persist = def_specifiers( 1, Spec_Local_Persist ); spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
set_global(spec_local_persist); set_global(spec_local_persist);
# pragma pop_macro("forceinline") # pragma pop_macro("forceinline")

View File

@ -44,11 +44,11 @@ CodeComment def_comment ( StrC content );
struct Opts_def_struct { struct Opts_def_struct {
Code body; Code body;
CodeTypename parent; CodeType parent;
AccessSpec parent_access; AccessSpec parent_access;
CodeAttributes attributes; CodeAttributes attributes;
ModuleFlag mflags; ModuleFlag mflags;
CodeTypename* interfaces; CodeType* interfaces;
s32 num_interfaces; s32 num_interfaces;
}; };
CodeClass def_class( StrC name, Opts_def_struct otps GEN_PARAM_DEFAULT ); CodeClass def_class( StrC name, Opts_def_struct otps GEN_PARAM_DEFAULT );
@ -70,7 +70,7 @@ CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
struct Opts_def_enum { struct Opts_def_enum {
Code body; Code body;
CodeTypename type; CodeType type;
EnumT specifier; EnumT specifier;
CodeAttributes attributes; CodeAttributes attributes;
ModuleFlag mflags; ModuleFlag mflags;
@ -83,7 +83,7 @@ CodeFriend def_friend ( Code symbol );
struct Opts_def_function { struct Opts_def_function {
CodeParam params; CodeParam params;
CodeTypename ret_type; CodeType ret_type;
Code body; Code body;
CodeSpecifiers specs; CodeSpecifiers specs;
CodeAttributes attrs; CodeAttributes attrs;
@ -100,27 +100,27 @@ CodeNS def_namespace( StrC name, Code body, Opts_def_namespace opts GEN_PAR
struct Opts_def_operator { struct Opts_def_operator {
CodeParam params; CodeParam params;
CodeTypename ret_type; CodeType ret_type;
Code body; Code body;
CodeSpecifiers specifiers; CodeSpecifiers specifiers;
CodeAttributes attributes; CodeAttributes attributes;
ModuleFlag mflags; ModuleFlag mflags;
}; };
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT ); CodeOperator def_operator( OperatorT op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
struct Opts_def_operator_cast { struct Opts_def_operator_cast {
Code body; Code body;
CodeSpecifiers specs; CodeSpecifiers specs;
}; };
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT ); CodeOpCast def_operator_cast( CodeType type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
struct Opts_def_param { Code value; }; struct Opts_def_param { Code value; };
CodeParam def_param ( CodeTypename type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT ); 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( Specifier specifier ); CodeSpecifiers def_specifier( SpecifierT specifier );
CodeStruct def_struct( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT ); CodeStruct def_struct( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
@ -132,7 +132,7 @@ struct Opts_def_type {
CodeSpecifiers specifiers; CodeSpecifiers specifiers;
CodeAttributes attributes; CodeAttributes attributes;
}; };
CodeTypename def_type( StrC name, Opts_def_type opts GEN_PARAM_DEFAULT ); CodeType def_type( StrC name, Opts_def_type opts GEN_PARAM_DEFAULT );
struct Opts_def_typedef { struct Opts_def_typedef {
CodeAttributes attributes; CodeAttributes attributes;
@ -161,10 +161,10 @@ struct Opts_def_variable
CodeAttributes attributes; CodeAttributes attributes;
ModuleFlag mflags; ModuleFlag mflags;
}; };
CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT ); 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( CodeTypename type ); CodeBody def_body( CodeT type );
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num, // There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
/// or provide as an array of Code objects. /// or provide as an array of Code objects.
@ -186,7 +186,7 @@ CodeBody def_namespace_body ( s32 num, Code* codes );
CodeParam def_params ( s32 num, ... ); CodeParam def_params ( s32 num, ... );
CodeParam def_params ( s32 num, CodeParam* params ); CodeParam def_params ( s32 num, CodeParam* params );
CodeSpecifiers def_specifiers ( s32 num, ... ); CodeSpecifiers def_specifiers ( s32 num, ... );
CodeSpecifiers def_specifiers ( s32 num, Specifier* specs ); CodeSpecifiers def_specifiers ( s32 num, SpecifierT* specs );
CodeBody def_struct_body ( s32 num, ... ); CodeBody def_struct_body ( s32 num, ... );
CodeBody def_struct_body ( s32 num, Code* codes ); CodeBody def_struct_body ( s32 num, Code* codes );
CodeBody def_union_body ( s32 num, ... ); CodeBody def_union_body ( s32 num, ... );
@ -246,7 +246,7 @@ CodeOperator parse_operator ( StrC operator_def );
CodeOpCast parse_operator_cast( StrC operator_def ); CodeOpCast parse_operator_cast( StrC operator_def );
CodeStruct parse_struct ( StrC struct_def ); CodeStruct parse_struct ( StrC struct_def );
CodeTemplate parse_template ( StrC template_def ); CodeTemplate parse_template ( StrC template_def );
CodeTypename parse_type ( StrC type_def ); CodeType parse_type ( StrC type_def );
CodeTypedef parse_typedef ( StrC typedef_def ); CodeTypedef parse_typedef ( StrC typedef_def );
CodeUnion parse_union ( StrC union_def ); CodeUnion parse_union ( StrC union_def );
CodeUsing parse_using ( StrC using_def ); CodeUsing parse_using ( StrC using_def );

View File

@ -10,24 +10,23 @@
CodeClass parse_class( StrC def ) CodeClass parse_class( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
TokArray toks = lex( def ); parser::TokArray toks = parser::lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
return InvalidCode; return InvalidCode;
Context.Tokens = toks; parser::Context.Tokens = toks;
push_scope(); push_scope();
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class ); CodeClass result = (CodeClass) parser::parse_class_struct( parser::TokType::Decl_Class );
pop(& Context); parser::Context.pop();
return result; return result;
} }
CodeConstructor parse_constructor( StrC def ) CodeConstructor parse_constructor( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -36,31 +35,31 @@ CodeConstructor parse_constructor( StrC def )
// TODO(Ed): Constructors can have prefix attributes // TODO(Ed): Constructors can have prefix attributes
CodeSpecifiers specifiers; CodeSpecifiers specifiers;
Specifier specs_found[ 16 ] { Spec_NumSpecifiers }; SpecifierT specs_found[ 16 ] { ESpecifier::NumSpecifiers };
s32 NumSpecifiers = 0; s32 NumSpecifiers = 0;
while ( left && is_specifier(currtok) ) while ( left && is_specifier(currtok) )
{ {
Specifier spec = to_specifier( to_str(currtok) ); SpecifierT spec = ESpecifier::to_type( to_str(currtok) );
b32 ignore_spec = false; b32 ignore_spec = false;
switch ( spec ) switch ( spec )
{ {
case Spec_Constexpr : case ESpecifier::Constexpr :
case Spec_Explicit: case ESpecifier::Explicit:
case Spec_Inline : case ESpecifier::Inline :
case Spec_ForceInline : case ESpecifier::ForceInline :
case Spec_NeverInline : case ESpecifier::NeverInline :
break; break;
case Spec_Const : case ESpecifier::Const :
ignore_spec = true; ignore_spec = true;
break; break;
default : default :
log_failure( "Invalid specifier %s for variable\n%s", to_str( spec ), to_string(Context) ); log_failure( "Invalid specifier %s for variable\n%s", ESpecifier::to_str( spec ), Context.to_string() );
pop(& Context); Context.pop();
return InvalidCode; return InvalidCode;
} }
@ -86,8 +85,8 @@ CodeConstructor parse_constructor( StrC def )
CodeDestructor parse_destructor( StrC def ) CodeDestructor parse_destructor( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -103,13 +102,13 @@ CodeDestructor parse_destructor( StrC def )
CodeEnum parse_enum( StrC def ) CodeEnum parse_enum( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
{ {
pop(& Context); Context.pop();
return InvalidCode; return InvalidCode;
} }
@ -119,8 +118,8 @@ CodeEnum parse_enum( StrC def )
CodeBody parse_export_body( StrC def ) CodeBody parse_export_body( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -132,8 +131,8 @@ CodeBody parse_export_body( StrC def )
CodeExtern parse_extern_link( StrC def ) CodeExtern parse_extern_link( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -145,8 +144,8 @@ CodeExtern parse_extern_link( StrC def )
CodeFriend parse_friend( StrC def ) CodeFriend parse_friend( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -158,8 +157,8 @@ CodeFriend parse_friend( StrC def )
CodeFn parse_function( StrC def ) CodeFn parse_function( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -171,8 +170,8 @@ CodeFn parse_function( StrC def )
CodeBody parse_global_body( StrC def ) CodeBody parse_global_body( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -180,15 +179,15 @@ CodeBody parse_global_body( StrC def )
Context.Tokens = toks; Context.Tokens = toks;
push_scope(); push_scope();
CodeBody result = parse_global_nspace( CT_Global_Body ); CodeBody result = parse_global_nspace( ECode::Global_Body );
pop(& Context); Context.pop();
return result; return result;
} }
CodeNS parse_namespace( StrC def ) CodeNS parse_namespace( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -200,8 +199,8 @@ CodeNS parse_namespace( StrC def )
CodeOperator parse_operator( StrC def ) CodeOperator parse_operator( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -213,8 +212,8 @@ CodeOperator parse_operator( StrC def )
CodeOpCast parse_operator_cast( StrC def ) CodeOpCast parse_operator_cast( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -226,8 +225,8 @@ CodeOpCast parse_operator_cast( StrC def )
CodeStruct parse_struct( StrC def ) CodeStruct parse_struct( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -235,15 +234,15 @@ CodeStruct parse_struct( StrC def )
Context.Tokens = toks; Context.Tokens = toks;
push_scope(); push_scope();
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct ); CodeStruct result = (CodeStruct) parse_class_struct( TokType::Decl_Struct );
pop(& Context); Context.pop();
return result; return result;
} }
CodeTemplate parse_template( StrC def ) CodeTemplate parse_template( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -253,10 +252,10 @@ CodeTemplate parse_template( StrC def )
return parse_template(); return parse_template();
} }
CodeTypename parse_type( StrC def ) CodeType parse_type( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -268,8 +267,8 @@ CodeTypename parse_type( StrC def )
CodeTypedef parse_typedef( StrC def ) CodeTypedef parse_typedef( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -281,8 +280,8 @@ CodeTypedef parse_typedef( StrC def )
CodeUnion parse_union( StrC def ) CodeUnion parse_union( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -294,8 +293,8 @@ CodeUnion parse_union( StrC def )
CodeUsing parse_using( StrC def ) CodeUsing parse_using( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )
@ -307,8 +306,8 @@ CodeUsing parse_using( StrC def )
CodeVar parse_variable( StrC def ) CodeVar parse_variable( StrC def )
{ {
GEN_USING_NS_PARSER;
check_parse_args( def ); check_parse_args( def );
using namespace parser;
TokArray toks = lex( def ); TokArray toks = lex( def );
if ( toks.Arr == nullptr ) if ( toks.Arr == nullptr )

View File

@ -112,7 +112,7 @@ Code untyped_str( StrC content )
Code Code
result = make_code(); result = make_code();
result->Name = get_cached_string( content ); result->Name = get_cached_string( content );
result->Type = CT_Untyped; result->Type = ECode::Untyped;
result->Content = result->Name; result->Content = result->Name;
if ( result->Name == nullptr ) if ( result->Name == nullptr )
@ -143,7 +143,7 @@ Code untyped_fmt( char const* fmt, ...)
Code Code
result = make_code(); result = make_code();
result->Name = get_cached_string( { str_len(fmt, MaxNameLength), fmt } ); result->Name = get_cached_string( { str_len(fmt, MaxNameLength), fmt } );
result->Type = CT_Untyped; result->Type = ECode::Untyped;
result->Content = get_cached_string( { length, buf } ); result->Content = get_cached_string( { length, buf } );
if ( result->Name == nullptr ) if ( result->Name == nullptr )
@ -174,7 +174,7 @@ Code untyped_token_fmt( s32 num_tokens, ... )
Code Code
result = make_code(); result = make_code();
result->Name = get_cached_string( { length, buf } ); result->Name = get_cached_string( { length, buf } );
result->Type = CT_Untyped; result->Type = ECode::Untyped;
result->Content = result->Name; result->Content = result->Name;
if ( result->Name == nullptr ) if ( result->Name == nullptr )

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@ struct Token
u32 Flags; u32 Flags;
}; };
constexpr Token NullToken { nullptr, 0, Tok_Invalid, false, 0, TF_Null }; constexpr Token NullToken { nullptr, 0, TokType::Invalid, false, 0, TF_Null };
AccessSpec to_access_specifier(Token tok) AccessSpec to_access_specifier(Token tok)
{ {
@ -47,7 +47,7 @@ StrC to_str(Token tok)
bool is_valid( Token tok ) bool is_valid( Token tok )
{ {
return tok.Text && tok.Length && tok.Type != Tok_Invalid; return tok.Text && tok.Length && tok.Type != TokType::Invalid;
} }
bool is_access_operator(Token tok) bool is_access_operator(Token tok)
@ -94,7 +94,7 @@ String to_string(Token tok)
{ {
String result = string_make_reserve( GlobalAllocator, kilobytes(4) ); String result = string_make_reserve( GlobalAllocator, kilobytes(4) );
StrC type_str = to_str( tok.Type ); StrC type_str = ETokType::to_str( tok.Type );
append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s" append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s"
, tok.Line, tok.Column , tok.Line, tok.Column
@ -117,7 +117,7 @@ Token* current(TokArray* self, bool skip_formatting )
{ {
if ( skip_formatting ) if ( skip_formatting )
{ {
while ( self->Arr[self->Idx].Type == Tok_NewLine || self->Arr[self->Idx].Type == Tok_Comment ) while ( self->Arr[self->Idx].Type == TokType::NewLine || self->Arr[self->Idx].Type == TokType::Comment )
self->Idx++; self->Idx++;
} }
@ -130,7 +130,7 @@ Token* previous(TokArray self, bool skip_formatting)
if ( skip_formatting ) if ( skip_formatting )
{ {
while ( self.Arr[idx].Type == Tok_NewLine ) while ( self.Arr[idx].Type == TokType::NewLine )
idx --; idx --;
return & self.Arr[idx]; return & self.Arr[idx];
@ -145,7 +145,7 @@ Token* next(TokArray self, bool skip_formatting)
if ( skip_formatting ) if ( skip_formatting )
{ {
while ( self.Arr[idx].Type == Tok_NewLine ) while ( self.Arr[idx].Type == TokType::NewLine )
idx++; idx++;
return & self.Arr[idx + 1]; return & self.Arr[idx + 1];
@ -221,7 +221,7 @@ forceinline
s32 lex_preprocessor_directive( LexContext* ctx ) s32 lex_preprocessor_directive( LexContext* ctx )
{ {
char const* hash = ctx->scanner; char const* hash = ctx->scanner;
append( & Tokens, { hash, 1, Tok_Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess } ); append( & Tokens, { hash, 1, TokType::Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess } );
move_forward(); move_forward();
SkipWhitespace(); SkipWhitespace();
@ -233,12 +233,12 @@ s32 lex_preprocessor_directive( LexContext* ctx )
ctx->token.Length++; ctx->token.Length++;
} }
ctx->token.Type = to_toktype( to_str(ctx->token) ); ctx->token.Type = ETokType::to_type( to_str(ctx->token) );
bool is_preprocessor = ctx->token.Type >= Tok_Preprocess_Define && ctx->token.Type <= Tok_Preprocess_Pragma; bool is_preprocessor = ctx->token.Type >= TokType::Preprocess_Define && ctx->token.Type <= TokType::Preprocess_Pragma;
if ( ! is_preprocessor ) if ( ! is_preprocessor )
{ {
ctx->token.Type = Tok_Preprocess_Unsupported; ctx->token.Type = TokType::Preprocess_Unsupported;
// Its an unsupported directive, skip it // Its an unsupported directive, skip it
s32 within_string = false; s32 within_string = false;
@ -301,14 +301,14 @@ s32 lex_preprocessor_directive( LexContext* ctx )
return Lex_Continue; // Skip found token, its all handled here. return Lex_Continue; // Skip found token, its all handled here.
} }
if ( ctx->token.Type == Tok_Preprocess_Else || ctx->token.Type == Tok_Preprocess_EndIf ) if ( ctx->token.Type == TokType::Preprocess_Else || ctx->token.Type == TokType::Preprocess_EndIf )
{ {
ctx->token.Flags |= TF_Preprocess_Cond; ctx->token.Flags |= TF_Preprocess_Cond;
append( & Tokens, ctx->token ); append( & Tokens, ctx->token );
end_line(); end_line();
return Lex_Continue; return Lex_Continue;
} }
else if ( ctx->token.Type >= Tok_Preprocess_If && ctx->token.Type <= Tok_Preprocess_ElIf ) else if ( ctx->token.Type >= TokType::Preprocess_If && ctx->token.Type <= TokType::Preprocess_ElIf )
{ {
ctx->token.Flags |= TF_Preprocess_Cond; ctx->token.Flags |= TF_Preprocess_Cond;
} }
@ -317,9 +317,9 @@ s32 lex_preprocessor_directive( LexContext* ctx )
SkipWhitespace(); SkipWhitespace();
if ( ctx->token.Type == Tok_Preprocess_Define ) if ( ctx->token.Type == TokType::Preprocess_Define )
{ {
Token name = { ctx->scanner, 0, Tok_Identifier, ctx->line, ctx->column, TF_Preprocess }; Token name = { ctx->scanner, 0, TokType::Identifier, ctx->line, ctx->column, TF_Preprocess };
name.Text = ctx->scanner; name.Text = ctx->scanner;
name.Length = 1; name.Length = 1;
@ -343,11 +343,11 @@ s32 lex_preprocessor_directive( LexContext* ctx )
set(& ctx->defines, key, to_str(name) ); set(& ctx->defines, key, to_str(name) );
} }
Token preprocess_content = { ctx->scanner, 0, Tok_Preprocess_Content, ctx->line, ctx->column, TF_Preprocess }; Token preprocess_content = { ctx->scanner, 0, TokType::Preprocess_Content, ctx->line, ctx->column, TF_Preprocess };
if ( ctx->token.Type == Tok_Preprocess_Include ) if ( ctx->token.Type == TokType::Preprocess_Include )
{ {
preprocess_content.Type = Tok_String; preprocess_content.Type = TokType::String;
if ( current != '"' && current != '<' ) if ( current != '"' && current != '<' )
{ {
@ -452,31 +452,31 @@ s32 lex_preprocessor_directive( LexContext* ctx )
forceinline forceinline
void lex_found_token( LexContext* ctx ) void lex_found_token( LexContext* ctx )
{ {
if ( ctx->token.Type != Tok_Invalid ) if ( ctx->token.Type != TokType::Invalid )
{ {
append( & Tokens, ctx->token ); append( & Tokens, ctx->token );
return; return;
} }
TokType type = to_toktype( to_str(ctx->token) ); TokType type = ETokType::to_type( to_str(ctx->token) );
if (type <= Tok_Access_Public && type >= Tok_Access_Private ) if (type <= TokType::Access_Public && type >= TokType::Access_Private )
{ {
ctx->token.Flags |= TF_AccessSpecifier; ctx->token.Flags |= TF_AccessSpecifier;
} }
if ( type > Tok___Attributes_Start ) if ( type > TokType::__Attributes_Start )
{ {
ctx->token.Flags |= TF_Attribute; ctx->token.Flags |= TF_Attribute;
} }
if ( type == Tok_Decl_Extern_Linkage ) if ( type == ETokType::Decl_Extern_Linkage )
{ {
SkipWhitespace(); SkipWhitespace();
if ( current != '"' ) if ( current != '"' )
{ {
type = Tok_Spec_Extern; type = ETokType::Spec_Extern;
ctx->token.Flags |= TF_Specifier; ctx->token.Flags |= TF_Specifier;
} }
@ -485,9 +485,9 @@ void lex_found_token( LexContext* ctx )
return; return;
} }
if ( ( type <= Tok_Star && type >= Tok_Spec_Alignas) if ( ( type <= TokType::Star && type >= TokType::Spec_Alignas)
|| type == Tok_Ampersand || type == TokType::Ampersand
|| type == Tok_Ampersand_DBL ) || type == TokType::Ampersand_DBL )
{ {
ctx->token.Type = type; ctx->token.Type = type;
ctx->token.Flags |= TF_Specifier; ctx->token.Flags |= TF_Specifier;
@ -496,7 +496,7 @@ void lex_found_token( LexContext* ctx )
} }
if ( type != Tok_Invalid ) if ( type != TokType::Invalid )
{ {
ctx->token.Type = type; ctx->token.Type = type;
append( & Tokens, ctx->token ); append( & Tokens, ctx->token );
@ -512,7 +512,7 @@ void lex_found_token( LexContext* ctx )
StrC* define = get(ctx->defines, key ); StrC* define = get(ctx->defines, key );
if ( define ) if ( define )
{ {
ctx->token.Type = Tok_Preprocess_Macro; ctx->token.Type = TokType::Preprocess_Macro;
// Want to ignore any arguments the define may have as they can be execution expressions. // Want to ignore any arguments the define may have as they can be execution expressions.
if ( ctx->left && current == '(' ) if ( ctx->left && current == '(' )
@ -548,7 +548,7 @@ void lex_found_token( LexContext* ctx )
} }
else else
{ {
ctx->token.Type = Tok_Identifier; ctx->token.Type = TokType::Identifier;
} }
append( & Tokens, ctx->token ); append( & Tokens, ctx->token );
@ -607,7 +607,7 @@ TokArray lex( StrC content )
} }
#endif #endif
c.token = { c.scanner, 0, Tok_Invalid, c.line, c.column, TF_Null }; c.token = { c.scanner, 0, TokType::Invalid, c.line, c.column, TF_Null };
bool is_define = false; bool is_define = false;
@ -623,7 +623,7 @@ TokArray lex( StrC content )
{ {
move_forward(); move_forward();
c.token.Type = Tok_NewLine; c.token.Type = TokType::NewLine;
c.token.Length++; c.token.Length++;
append( & Tokens, c.token ); append( & Tokens, c.token );
@ -655,7 +655,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Access_MemberSymbol; c.token.Type = TokType::Access_MemberSymbol;
c.token.Flags = TF_AccessOperator; c.token.Flags = TF_AccessOperator;
if (c.left) { if (c.left) {
@ -668,7 +668,7 @@ TokArray lex( StrC content )
if( current == '.' ) if( current == '.' )
{ {
c.token.Length = 3; c.token.Length = 3;
c.token.Type = Tok_Varadic_Argument; c.token.Type = TokType::Varadic_Argument;
c.token.Flags = TF_Null; c.token.Flags = TF_Null;
move_forward(); move_forward();
} }
@ -686,7 +686,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Ampersand; c.token.Type = TokType::Ampersand;
c.token.Flags |= TF_Operator; c.token.Flags |= TF_Operator;
c.token.Flags |= TF_Specifier; c.token.Flags |= TF_Specifier;
@ -696,7 +696,7 @@ TokArray lex( StrC content )
if ( current == '&' ) // && if ( current == '&' ) // &&
{ {
c.token.Length = 2; c.token.Length = 2;
c.token.Type = Tok_Ampersand_DBL; c.token.Type = TokType::Ampersand_DBL;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -708,9 +708,9 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Assign_Classifer; c.token.Type = TokType::Assign_Classifer;
// Can be either a classifier (ParentType, Bitfield width), or ternary else // Can be either a classifier (ParentType, Bitfield width), or ternary else
// token.Type = Tok_Colon; // token.Type = TokType::Colon;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -718,7 +718,7 @@ TokArray lex( StrC content )
if ( current == ':' ) if ( current == ':' )
{ {
move_forward(); move_forward();
c.token.Type = Tok_Access_StaticSymbol; c.token.Type = TokType::Access_StaticSymbol;
c.token.Length++; c.token.Length++;
} }
goto FoundToken; goto FoundToken;
@ -727,7 +727,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_BraceCurly_Open; c.token.Type = TokType::BraceCurly_Open;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -737,7 +737,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_BraceCurly_Close; c.token.Type = TokType::BraceCurly_Close;
c.token.Flags = TF_EndDefinition; c.token.Flags = TF_EndDefinition;
if (c.left) if (c.left)
@ -750,7 +750,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_BraceSquare_Open; c.token.Type = TokType::BraceSquare_Open;
if ( c.left ) if ( c.left )
{ {
move_forward(); move_forward();
@ -758,7 +758,7 @@ TokArray lex( StrC content )
if ( current == ']' ) if ( current == ']' )
{ {
c.token.Length = 2; c.token.Length = 2;
c.token.Type = Tok_Operator; c.token.Type = TokType::Operator;
move_forward(); move_forward();
} }
} }
@ -768,7 +768,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_BraceSquare_Close; c.token.Type = TokType::BraceSquare_Close;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -778,7 +778,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Capture_Start; c.token.Type = TokType::Capture_Start;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -788,7 +788,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Capture_End; c.token.Type = TokType::Capture_End;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -798,7 +798,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Char; c.token.Type = TokType::Char;
c.token.Flags = TF_Literal; c.token.Flags = TF_Literal;
move_forward(); move_forward();
@ -832,7 +832,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Comma; c.token.Type = TokType::Comma;
c.token.Flags = TF_Operator; c.token.Flags = TF_Operator;
if (c.left) if (c.left)
@ -843,7 +843,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Star; c.token.Type = TokType::Star;
c.token.Flags |= TF_Specifier; c.token.Flags |= TF_Specifier;
c.token.Flags |= TF_Operator; c.token.Flags |= TF_Operator;
@ -854,7 +854,7 @@ TokArray lex( StrC content )
{ {
c.token.Length++; c.token.Length++;
c.token.Flags |= TF_Assign; c.token.Flags |= TF_Assign;
// c.token.Type = Tok_Assign_Multiply; // c.token.Type = TokType::Assign_Multiply;
if ( c.left ) if ( c.left )
move_forward(); move_forward();
@ -866,7 +866,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Statement_End; c.token.Type = TokType::Statement_End;
c.token.Flags = TF_EndDefinition; c.token.Flags = TF_EndDefinition;
if (c.left) if (c.left)
@ -879,7 +879,7 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_String; c.token.Type = TokType::String;
c.token.Flags |= TF_Literal; c.token.Flags |= TF_Literal;
move_forward(); move_forward();
@ -913,8 +913,8 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Operator; c.token.Type = TokType::Operator;
// c.token.Type = Tok_Ternary; // c.token.Type = TokType::Ternary;
c.token.Flags = TF_Operator; c.token.Flags = TF_Operator;
if (c.left) if (c.left)
@ -926,8 +926,8 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Operator; c.token.Type = TokType::Operator;
// c.token.Type = Tok_Assign; // c.token.Type = TokType::Assign;
c.token.Flags = TF_Operator; c.token.Flags = TF_Operator;
c.token.Flags |= TF_Assign; c.token.Flags |= TF_Assign;
@ -947,44 +947,44 @@ TokArray lex( StrC content )
} }
case '+': case '+':
{ {
// c.token.Type = Tok_Add // c.token.Type = TokType::Add
} }
case '%': case '%':
{ {
// c.token.Type = Tok_Modulo; // c.token.Type = TokType::Modulo;
} }
case '^': case '^':
{ {
// c.token.Type = Tok_B_XOr; // c.token.Type = TokType::B_XOr;
} }
case '~': case '~':
{ {
// c.token.Type = Tok_Unary_Not; // c.token.Type = TokType::Unary_Not;
} }
case '!': case '!':
{ {
// c.token.Type = Tok_L_Not; // c.token.Type = TokType::L_Not;
} }
case '<': case '<':
{ {
// c.token.Type = Tok_Lesser; // c.token.Type = TokType::Lesser;
} }
case '>': case '>':
{ {
// c.token.Type = Tok_Greater; // c.token.Type = TokType::Greater;
} }
case '|': case '|':
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Operator; c.token.Type = TokType::Operator;
c.token.Flags = TF_Operator; c.token.Flags = TF_Operator;
// token.Type = Tok_L_Or; // token.Type = TokType::L_Or;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -994,7 +994,7 @@ TokArray lex( StrC content )
c.token.Length++; c.token.Length++;
c.token.Flags |= TF_Assign; c.token.Flags |= TF_Assign;
// token.Flags |= TokFlags::Assignment; // token.Flags |= TokFlags::Assignment;
// token.Type = Tok_Assign_L_Or; // token.Type = TokType::Assign_L_Or;
if (c.left) if (c.left)
move_forward(); move_forward();
@ -1014,8 +1014,8 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Operator; c.token.Type = TokType::Operator;
// token.Type = Tok_Subtract; // token.Type = TokType::Subtract;
c.token.Flags = TF_Operator; c.token.Flags = TF_Operator;
if ( c.left ) if ( c.left )
{ {
@ -1024,13 +1024,13 @@ TokArray lex( StrC content )
if ( current == '>' ) if ( current == '>' )
{ {
c.token.Length++; c.token.Length++;
// token.Type = Tok_Access_PointerToMemberSymbol; // token.Type = TokType::Access_PointerToMemberSymbol;
c.token.Flags |= TF_AccessOperator; c.token.Flags |= TF_AccessOperator;
move_forward(); move_forward();
if ( current == '*' ) if ( current == '*' )
{ {
// token.Type = Tok_Access_PointerToMemberOfPointerSymbol; // token.Type = TokType::Access_PointerToMemberOfPointerSymbol;
c.token.Length++; c.token.Length++;
move_forward(); move_forward();
} }
@ -1038,7 +1038,7 @@ TokArray lex( StrC content )
else if ( current == '=' ) else if ( current == '=' )
{ {
c.token.Length++; c.token.Length++;
// token.Type = Tok_Assign_Subtract; // token.Type = TokType::Assign_Subtract;
c.token.Flags |= TF_Assign; c.token.Flags |= TF_Assign;
if (c.left) if (c.left)
@ -1058,8 +1058,8 @@ TokArray lex( StrC content )
{ {
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Operator; c.token.Type = TokType::Operator;
// token.Type = Tok_Divide; // token.Type = TokType::Divide;
c.token.Flags = TF_Operator; c.token.Flags = TF_Operator;
move_forward(); move_forward();
@ -1074,7 +1074,7 @@ TokArray lex( StrC content )
} }
else if ( current == '/' ) else if ( current == '/' )
{ {
c.token.Type = Tok_Comment; c.token.Type = TokType::Comment;
c.token.Length = 2; c.token.Length = 2;
c.token.Flags = TF_Null; c.token.Flags = TF_Null;
move_forward(); move_forward();
@ -1100,7 +1100,7 @@ TokArray lex( StrC content )
} }
else if ( current == '*' ) else if ( current == '*' )
{ {
c.token.Type = Tok_Comment; c.token.Type = TokType::Comment;
c.token.Length = 2; c.token.Length = 2;
c.token.Flags = TF_Null; c.token.Flags = TF_Null;
move_forward(); move_forward();
@ -1160,7 +1160,7 @@ TokArray lex( StrC content )
c.token.Text = c.scanner; c.token.Text = c.scanner;
c.token.Length = 1; c.token.Length = 1;
c.token.Type = Tok_Number; c.token.Type = TokType::Number;
c.token.Flags = TF_Literal; c.token.Flags = TF_Literal;
move_forward(); move_forward();
@ -1230,7 +1230,7 @@ TokArray lex( StrC content )
{ {
log_fmt( "Token %d Type: %s : %.*s\n" log_fmt( "Token %d Type: %s : %.*s\n"
, idx , idx
, to_str( Tokens[ idx ].Type ).Ptr , ETokType::to_str( Tokens[ idx ].Type ).Ptr
, Tokens[ idx ].Length, Tokens[ idx ].Text , Tokens[ idx ].Length, Tokens[ idx ].Text
); );
} }

File diff suppressed because it is too large Load Diff

View File

@ -72,36 +72,36 @@ global CodeSpecifiers spec_thread_local;
global CodeSpecifiers spec_virtual; global CodeSpecifiers spec_virtual;
global CodeSpecifiers spec_volatile; global CodeSpecifiers spec_volatile;
global CodeTypename t_empty; global CodeType t_empty;
global CodeTypename t_auto; global CodeType t_auto;
global CodeTypename t_void; global CodeType t_void;
global CodeTypename t_int; global CodeType t_int;
global CodeTypename t_bool; global CodeType t_bool;
global CodeTypename t_char; global CodeType t_char;
global CodeTypename t_wchar_t; global CodeType t_wchar_t;
global CodeTypename t_class; global CodeType t_class;
global CodeTypename t_typename; global CodeType t_typename;
global Array< StringCached > PreprocessorDefines; global Array< StringCached > PreprocessorDefines;
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS #ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
global CodeTypename t_b32; global CodeType t_b32;
global CodeTypename t_s8; global CodeType t_s8;
global CodeTypename t_s16; global CodeType t_s16;
global CodeTypename t_s32; global CodeType t_s32;
global CodeTypename t_s64; global CodeType t_s64;
global CodeTypename t_u8; global CodeType t_u8;
global CodeTypename t_u16; global CodeType t_u16;
global CodeTypename t_u32; global CodeType t_u32;
global CodeTypename t_u64; global CodeType t_u64;
global CodeTypename t_ssize; global CodeType t_ssize;
global CodeTypename t_usize; global CodeType t_usize;
global CodeTypename t_f32; global CodeType t_f32;
global CodeTypename t_f64; global CodeType t_f64;
#endif #endif
#pragma endregion Constants #pragma endregion Constants

View File

@ -135,7 +135,6 @@
# if GEN_COMPILER_C # if GEN_COMPILER_C
# define GEN_NS_PARSER_BEGIN # define GEN_NS_PARSER_BEGIN
# define GEN_NS_PARSER_END # define GEN_NS_PARSER_END
# define GEN_USING_NS_PARSER
# 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
@ -144,7 +143,6 @@
# else # else
# define GEN_NS_PARSER_BEGIN namespace parser { # define GEN_NS_PARSER_BEGIN namespace parser {
# define GEN_NS_PARSER_END } # define GEN_NS_PARSER_END }
# define GEN_USING_NS_PARSER using namespace parser
# 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 ::
@ -154,7 +152,6 @@
#else #else
# define GEN_NS_PARSER_BEGIN namespace parser { # define GEN_NS_PARSER_BEGIN namespace parser {
# define GEN_NS_PARSER_END } # define GEN_NS_PARSER_END }
# define GEN_USING_NS_PARSER using namespace parser
# 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

@ -27,17 +27,17 @@ CodeBody gen_ecode( char const* path )
{ {
char const* code = node.string; char const* code = node.string;
append_fmt( & enum_entries, "CT_%s,\n", code ); append_fmt( & enum_entries, "%s,\n", code );
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code ); append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code );
} }
CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", (StrC)enum_entries, "enum CodeType_Def : u32 { <entries> CT_NumTypes };")); CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", (StrC)enum_entries, "enum Type : u32 { <entries> NumTypes };"));
#pragma push_macro("local_persist") #pragma push_macro("local_persist")
#undef local_persist #undef local_persist
CodeFn to_str = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize( CodeFn to_str = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
inline inline
StrC to_str( CodeType type ) StrC to_str( Type type )
{ {
local_persist local_persist
StrC lookup[] { StrC lookup[] {
@ -49,11 +49,10 @@ CodeBody gen_ecode( char const* path )
))); )));
#pragma pop_macro("local_persist") #pragma pop_macro("local_persist")
//CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) ); CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) );
//CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) ); CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) );
CodeTypedef code_t = parse_typedef(code(typedef enum CodeType_Def CodeType; ));
return def_global_body( args( code_t, enum_code, to_str, fmt_newline ) ); return def_global_body( args( nspace, code_t, fmt_newline ) );
} }
CodeBody gen_eoperator( char const* path ) CodeBody gen_eoperator( char const* path )
@ -77,12 +76,12 @@ CodeBody gen_eoperator( char const* path )
char const* enum_str = enum_strs[idx].string; char const* enum_str = enum_strs[idx].string;
char const* entry_to_str = str_strs [idx].string; char const* entry_to_str = str_strs [idx].string;
append_fmt( & enum_entries, "Op_%s,\n", enum_str ); append_fmt( & enum_entries, "%s,\n", enum_str );
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str); append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
} }
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize( CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize(
enum Operator_Def : u32 enum Type : u32
{ {
<entries> <entries>
NumOps NumOps
@ -93,7 +92,7 @@ CodeBody gen_eoperator( char const* path )
#undef local_persist #undef local_persist
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize( CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
inline inline
StrC to_str( Operator op ) StrC to_str( Type op )
{ {
local_persist local_persist
StrC lookup[] { StrC lookup[] {
@ -105,11 +104,11 @@ CodeBody gen_eoperator( char const* path )
))); )));
#pragma pop_macro("local_persist") #pragma pop_macro("local_persist")
//CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) ); CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
//CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
CodeTypedef operator_t = parse_typedef(code( typedef enum Operator_Def Operator; ));
return def_global_body( args( operator_t, enum_code, to_str, fmt_newline ) ); CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
return def_global_body( args( nspace, operator_t, fmt_newline ) );
} }
CodeBody gen_especifier( char const* path ) CodeBody gen_especifier( char const* path )
@ -133,23 +132,23 @@ CodeBody gen_especifier( char const* path )
char const* enum_str = enum_strs[idx].string; char const* enum_str = enum_strs[idx].string;
char const* entry_to_str = str_strs [idx].string; char const* entry_to_str = str_strs [idx].string;
append_fmt( & enum_entries, "Spec_%s,\n", enum_str ); append_fmt( & enum_entries, "%s,\n", enum_str );
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str); append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
} }
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize( CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize(
enum Specifier_Def : u32 enum Type : u32
{ {
<entries> <entries>
Spec_NumSpecifiers NumSpecifiers
}; };
))); )));
CodeFn is_trailing = parse_function(token_fmt("specifier", (StrC)to_str_entries, stringize( CodeFn is_trailing = parse_function(token_fmt("specifier", (StrC)to_str_entries, stringize(
inline inline
bool is_trailing( Specifier specifier ) bool is_trailing( Type specifier )
{ {
return specifier > Spec_Virtual; return specifier > Virtual;
} }
))); )));
@ -165,7 +164,7 @@ CodeBody gen_especifier( char const* path )
#undef neverinline #undef neverinline
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize( CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
inline inline
StrC to_str( Specifier type ) StrC to_str( Type type )
{ {
local_persist local_persist
StrC lookup[] { StrC lookup[] {
@ -178,14 +177,14 @@ CodeBody gen_especifier( char const* path )
CodeFn to_type = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize( CodeFn to_type = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
inline inline
Specifier to_specifier( StrC str ) Type to_type( StrC str )
{ {
local_persist local_persist
u32 keymap[ Spec_NumSpecifiers ]; u32 keymap[ NumSpecifiers ];
do_once_start do_once_start
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ ) for ( u32 index = 0; index < NumSpecifiers; index++ )
{ {
StrC enum_str = to_str( (Specifier)index ); StrC enum_str = to_str( (Type)index );
// We subtract 1 to remove the null terminator // We subtract 1 to remove the null terminator
// This is because the tokens lexed are not null terminated. // This is because the tokens lexed are not null terminated.
@ -195,13 +194,13 @@ CodeBody gen_especifier( char const* path )
u32 hash = crc32( str.Ptr, str.Len ); u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ ) for ( u32 index = 0; index < NumSpecifiers; index++ )
{ {
if ( keymap[index] == hash ) if ( keymap[index] == hash )
return (Specifier)index; return (Type)index;
} }
return Spec_Invalid; return Invalid;
} }
))); )));
#pragma pop_macro("local_persist") #pragma pop_macro("local_persist")
@ -210,11 +209,11 @@ CodeBody gen_especifier( char const* path )
#pragma pop_macro("forceinline") #pragma pop_macro("forceinline")
#pragma pop_macro("neverinline") #pragma pop_macro("neverinline")
//CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) ); CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) );
//CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) );
CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier_Def Specifier; ));
return def_global_body( args( specifier_t, enum_code, is_trailing, to_str, to_type, fmt_newline ) ); CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) );
return def_global_body( args( nspace, specifier_t, fmt_newline ) );
} }
CodeBody gen_etoktype( char const* etok_path, char const* attr_path ) CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
@ -250,7 +249,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
char const* enum_str = enum_strs[idx].string; char const* enum_str = enum_strs[idx].string;
char const* entry_to_str = enum_str_strs [idx].string; char const* entry_to_str = enum_str_strs [idx].string;
append_fmt( & enum_entries, "Tok_%s,\n", enum_str ); append_fmt( & enum_entries, "%s,\n", enum_str );
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str); append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
} }
@ -259,9 +258,9 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
char const* attribute_str = attribute_strs[idx].string; char const* attribute_str = attribute_strs[idx].string;
char const* entry_to_str = attribute_str_strs [idx].string; char const* entry_to_str = attribute_str_strs [idx].string;
append_fmt( & attribute_entries, "Tok_Attribute_%s,\n", attribute_str ); append_fmt( & attribute_entries, "Attribute_%s,\n", attribute_str );
append_fmt( & to_str_attributes, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str); append_fmt( & to_str_attributes, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
append_fmt( & attribute_define_entries, "Entry( Tok_Attribute_%s, \"%s\" )", attribute_str, entry_to_str ); append_fmt( & attribute_define_entries, "Entry( Attribute_%s, \"%s\" )", attribute_str, entry_to_str );
if ( idx < num(attribute_strs) - 1 ) if ( idx < num(attribute_strs) - 1 )
append( & attribute_define_entries, " \\\n"); append( & attribute_define_entries, " \\\n");
@ -276,11 +275,11 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
// We cannot parse this enum, it has Attribute names as enums // We cannot parse this enum, it has Attribute names as enums
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize( CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize(
enum TokType_Def : u32 enum Type : u32
{ {
<entries> <entries>
<attribute_toks> <attribute_toks>
Tok_NumTokens NumTokens
}; };
))); )));
@ -292,7 +291,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
#undef do_once_end #undef do_once_end
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, "attribute_toks", (StrC)to_str_attributes, stringize( CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, "attribute_toks", (StrC)to_str_attributes, stringize(
inline inline
StrC to_str( TokType type ) StrC to_str( Type type )
{ {
local_persist local_persist
StrC lookup[] { StrC lookup[] {
@ -306,14 +305,14 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
CodeFn to_type = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize( CodeFn to_type = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
inline inline
TokType to_toktype( StrC str ) Type to_type( StrC str )
{ {
local_persist local_persist
u32 keymap[ Tok_NumTokens ]; u32 keymap[ NumTokens ];
do_once_start do_once_start
for ( u32 index = 0; index < Tok_NumTokens; index++ ) for ( u32 index = 0; index < NumTokens; index++ )
{ {
StrC enum_str = to_str( (TokType)index ); StrC enum_str = to_str( (Type)index );
// We subtract 1 to remove the null terminator // We subtract 1 to remove the null terminator
// This is because the tokens lexed are not null terminated. // This is because the tokens lexed are not null terminated.
@ -323,29 +322,23 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
u32 hash = crc32( str.Ptr, str.Len ); u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < Tok_NumTokens; index++ ) for ( u32 index = 0; index < NumTokens; index++ )
{ {
if ( keymap[index] == hash ) if ( keymap[index] == hash )
return (TokType)index; return (Type)index;
} }
return Tok_Invalid; return Invalid;
} }
))); )));
#pragma pop_macro("local_persist") #pragma pop_macro("local_persist")
#pragma pop_macro("do_once_start") #pragma pop_macro("do_once_start")
#pragma pop_macro("do_once_end") #pragma pop_macro("do_once_end")
//CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) ); CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) );
CodeTypedef td_toktype = parse_typedef( code( typedef enum TokType_Def TokType; )); CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) );
return def_global_body( args( return def_global_body( args( nspace, td_toktype ) );
attribute_entires_def,
td_toktype,
enum_code,
to_str,
to_type
));
} }
CodeBody gen_ast_inlines() CodeBody gen_ast_inlines()
@ -424,7 +417,7 @@ CodeBody gen_ast_inlines()
CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", StrC name(CodeSpecifiers), code_impl_tmpl )); CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", StrC name(CodeSpecifiers), code_impl_tmpl ));
CodeBody impl_code_struct = parse_global_body( token_fmt( "typename", StrC name(CodeStruct), code_impl_tmpl )); CodeBody impl_code_struct = parse_global_body( token_fmt( "typename", StrC name(CodeStruct), code_impl_tmpl ));
CodeBody impl_code_tmpl = parse_global_body( token_fmt( "typename", StrC name(CodeTemplate), code_impl_tmpl )); CodeBody impl_code_tmpl = parse_global_body( token_fmt( "typename", StrC name(CodeTemplate), code_impl_tmpl ));
CodeBody impl_code_type = parse_global_body( token_fmt( "typename", StrC name(CodeTypename), code_impl_tmpl )); CodeBody impl_code_type = parse_global_body( token_fmt( "typename", StrC name(CodeType), code_impl_tmpl ));
CodeBody impl_code_typedef = parse_global_body( token_fmt( "typename", StrC name(CodeTypedef), code_impl_tmpl )); CodeBody impl_code_typedef = parse_global_body( token_fmt( "typename", StrC name(CodeTypedef), code_impl_tmpl ));
CodeBody impl_code_union = parse_global_body( token_fmt( "typename", StrC name(CodeUnion), code_impl_tmpl )); CodeBody impl_code_union = parse_global_body( token_fmt( "typename", StrC name(CodeUnion), code_impl_tmpl ));
CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl )); CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl ));
@ -448,7 +441,7 @@ CodeBody gen_ast_inlines()
append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl ))); append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl )));
append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl ))); append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl )));
append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl ))); append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl )));
append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Typename), codetype_impl_tmpl ))); append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Type), codetype_impl_tmpl )));
append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl ))); append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl )));
append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl ))); append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl )));
append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl ))); append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl )));
@ -484,7 +477,7 @@ CodeBody gen_ast_inlines()
CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", StrC name(Specifiers), cast_tmpl )); CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", StrC name(Specifiers), cast_tmpl ));
CodeBody impl_cast_struct = parse_global_body( token_fmt( "typename", StrC name(Struct), cast_tmpl )); CodeBody impl_cast_struct = parse_global_body( token_fmt( "typename", StrC name(Struct), cast_tmpl ));
CodeBody impl_cast_tmpl = parse_global_body( token_fmt( "typename", StrC name(Template), cast_tmpl )); CodeBody impl_cast_tmpl = parse_global_body( token_fmt( "typename", StrC name(Template), cast_tmpl ));
CodeBody impl_cast_type = parse_global_body( token_fmt( "typename", StrC name(Typename), cast_tmpl )); CodeBody impl_cast_type = parse_global_body( token_fmt( "typename", StrC name(Type), cast_tmpl ));
CodeBody impl_cast_typedef = parse_global_body( token_fmt( "typename", StrC name(Typedef), cast_tmpl )); CodeBody impl_cast_typedef = parse_global_body( token_fmt( "typename", StrC name(Typedef), cast_tmpl ));
CodeBody impl_cast_union = parse_global_body( token_fmt( "typename", StrC name(Union), cast_tmpl )); CodeBody impl_cast_union = parse_global_body( token_fmt( "typename", StrC name(Union), cast_tmpl ));
CodeBody impl_cast_using = parse_global_body( token_fmt( "typename", StrC name(Using), cast_tmpl )); CodeBody impl_cast_using = parse_global_body( token_fmt( "typename", StrC name(Using), cast_tmpl ));