Compare commits

...

5 Commits

24 changed files with 2769 additions and 2814 deletions

View File

@ -243,7 +243,12 @@ int gen_main()
Code untyped = scan_file( "components/interface.untyped.cpp" );
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
src = Builder::open( "gen/gen.cpp" );

View File

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

View File

@ -67,7 +67,7 @@ struct AST_Stmt_While;
struct AST_Struct;
struct AST_Template;
struct AST_Type;
struct AST_Typename;
struct AST_Typedef;
struct AST_Union;
struct AST_Using;
@ -145,7 +145,7 @@ Define_Code(Stmt_While);
Define_Code(Struct);
Define_Code(Template);
Define_Code(Type);
Define_Code(Typename);
Define_Code(Typedef);
Define_Code(Union);
Define_Code(Using);
@ -260,7 +260,7 @@ struct Code
operator CodeSpecifiers() const;
operator CodeStruct() const;
operator CodeTemplate() const;
operator CodeType() const;
operator CodeTypename() const;
operator CodeTypedef() const;
operator CodeUnion() const;
operator CodeUsing() const;
@ -294,7 +294,7 @@ int AST_ArrSpecs_Cap =
- sizeof(parser::Token*)
- sizeof(AST*)
- sizeof(StringCached)
- sizeof(CodeT)
- sizeof(CodeType)
- sizeof(ModuleFlag)
- sizeof(int)
)
@ -337,7 +337,7 @@ struct AST
};
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
Specifier ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
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.
Code Parent;
StringCached Name;
CodeT Type;
CodeType Type;
// CodeFlag CodeFlags;
ModuleFlag ModuleFlags;
union {
b32 IsFunction; // Used by typedef to not serialize the name field.
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
OperatorT Op;
Operator Op;
AccessSpec ParentAccess;
s32 NumEntries;
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 \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Extern_Linkage: \
case Function_Body: \
case Function_Fwd: \
case Global_Body: \
case Namespace: \
case Namespace_Body: \
case Operator: \
case Operator_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
case CT_PlatformAttributes: \
case CT_Class_Body: \
case CT_Enum_Body: \
case CT_Extern_Linkage: \
case CT_Function_Body: \
case CT_Function_Fwd: \
case CT_Global_Body: \
case CT_Namespace: \
case CT_Namespace_Body: \
case CT_Operator: \
case CT_Operator_Fwd: \
case CT_Parameters: \
case CT_Specifiers: \
case CT_Struct_Body: \
case CT_Typename:
# define GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES
# define GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Extern_Linkage: \
case Friend: \
case Function_Body: \
case Function_Fwd: \
case Global_Body: \
case Namespace: \
case Namespace_Body: \
case Operator: \
case Operator_Fwd: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
case CT_Access_Public: \
case CT_Access_Protected: \
case CT_Access_Private: \
case CT_PlatformAttributes: \
case CT_Class_Body: \
case CT_Enum_Body: \
case CT_Extern_Linkage: \
case CT_Friend: \
case CT_Function_Body: \
case CT_Function_Fwd: \
case CT_Global_Body: \
case CT_Namespace: \
case CT_Namespace_Body: \
case CT_Operator: \
case CT_Operator_Fwd: \
case CT_Operator_Member: \
case CT_Operator_Member_Fwd: \
case CT_Parameters: \
case CT_Specifiers: \
case CT_Struct_Body: \
case CT_Typename:
# define GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Execution: \
case Friend: \
case Function_Body: \
case Namespace_Body: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
case CT_Access_Public: \
case CT_Access_Protected: \
case CT_Access_Private: \
case CT_PlatformAttributes: \
case CT_Class_Body: \
case CT_Enum_Body: \
case CT_Execution: \
case CT_Friend: \
case CT_Function_Body: \
case CT_Namespace_Body: \
case CT_Operator_Member: \
case CT_Operator_Member_Fwd: \
case CT_Parameters: \
case CT_Specifiers: \
case CT_Struct_Body: \
case CT_Typename:
# 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_NAMESPACE_UNALLOWED_TYPES \
case Access_Public: \
case Access_Protected: \
case Access_Private: \
case PlatformAttributes: \
case Class_Body: \
case Enum_Body: \
case Execution: \
case Friend: \
case Function_Body: \
case Namespace_Body: \
case Operator_Member: \
case Operator_Member_Fwd: \
case Parameters: \
case Specifiers: \
case Struct_Body: \
case Typename:
case CT_Access_Public: \
case CT_Access_Protected: \
case CT_Access_Private: \
case CT_PlatformAttributes: \
case CT_Class_Body: \
case CT_Enum_Body: \
case CT_Execution: \
case CT_Friend: \
case CT_Function_Body: \
case CT_Namespace_Body: \
case CT_Operator_Member: \
case CT_Operator_Member_Fwd: \
case CT_Parameters: \
case CT_Specifiers: \
case CT_Struct_Body: \
case CT_Typename:

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -44,11 +44,11 @@ CodeComment def_comment ( StrC content );
struct Opts_def_struct {
Code body;
CodeType parent;
CodeTypename parent;
AccessSpec parent_access;
CodeAttributes attributes;
ModuleFlag mflags;
CodeType* interfaces;
CodeTypename* interfaces;
s32 num_interfaces;
};
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 {
Code body;
CodeType type;
CodeTypename type;
EnumT specifier;
CodeAttributes attributes;
ModuleFlag mflags;
@ -83,7 +83,7 @@ CodeFriend def_friend ( Code symbol );
struct Opts_def_function {
CodeParam params;
CodeType ret_type;
CodeTypename ret_type;
Code body;
CodeSpecifiers specs;
CodeAttributes attrs;
@ -100,27 +100,27 @@ CodeNS def_namespace( StrC name, Code body, Opts_def_namespace opts GEN_PAR
struct Opts_def_operator {
CodeParam params;
CodeType ret_type;
CodeTypename ret_type;
Code body;
CodeSpecifiers specifiers;
CodeAttributes attributes;
ModuleFlag mflags;
};
CodeOperator def_operator( OperatorT op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
struct Opts_def_operator_cast {
Code body;
CodeSpecifiers specs;
};
CodeOpCast def_operator_cast( CodeType type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
struct Opts_def_param { Code value; };
CodeParam def_param ( CodeType type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT );
CodeParam def_param ( CodeTypename type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT );
CodePragma def_pragma( StrC directive );
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
CodeSpecifiers def_specifier( SpecifierT specifier );
CodeSpecifiers def_specifier( Specifier specifier );
CodeStruct def_struct( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
@ -132,7 +132,7 @@ struct Opts_def_type {
CodeSpecifiers specifiers;
CodeAttributes attributes;
};
CodeType def_type( StrC name, Opts_def_type opts GEN_PARAM_DEFAULT );
CodeTypename def_type( StrC name, Opts_def_type opts GEN_PARAM_DEFAULT );
struct Opts_def_typedef {
CodeAttributes attributes;
@ -161,10 +161,10 @@ struct Opts_def_variable
CodeAttributes attributes;
ModuleFlag mflags;
};
CodeVar def_variable( CodeType type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT );
CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT );
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
CodeBody def_body( CodeT type );
CodeBody def_body( CodeTypename type );
// 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.
@ -186,7 +186,7 @@ CodeBody def_namespace_body ( s32 num, Code* codes );
CodeParam def_params ( s32 num, ... );
CodeParam def_params ( s32 num, CodeParam* params );
CodeSpecifiers def_specifiers ( s32 num, ... );
CodeSpecifiers def_specifiers ( s32 num, SpecifierT* specs );
CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
CodeBody def_struct_body ( s32 num, ... );
CodeBody def_struct_body ( s32 num, Code* codes );
CodeBody def_union_body ( s32 num, ... );
@ -246,7 +246,7 @@ CodeOperator parse_operator ( StrC operator_def );
CodeOpCast parse_operator_cast( StrC operator_def );
CodeStruct parse_struct ( StrC struct_def );
CodeTemplate parse_template ( StrC template_def );
CodeType parse_type ( StrC type_def );
CodeTypename parse_type ( StrC type_def );
CodeTypedef parse_typedef ( StrC typedef_def );
CodeUnion parse_union ( StrC union_def );
CodeUsing parse_using ( StrC using_def );

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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