mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
Lexer improvement prep, segmentation of lexer and parser.
This commit is contained in:
@ -381,7 +381,7 @@ void AST::to_string( String& result )
|
||||
{
|
||||
local_persist thread_local
|
||||
char SerializationLevel = 0;
|
||||
|
||||
|
||||
switch ( Type )
|
||||
{
|
||||
using namespace ECode;
|
||||
@ -410,7 +410,7 @@ void AST::to_string( String& result )
|
||||
case Access_Public:
|
||||
result.append( Name );
|
||||
break;
|
||||
|
||||
|
||||
case Class:
|
||||
cast<CodeClass>().to_string_def( result );
|
||||
break;
|
||||
@ -500,7 +500,7 @@ void AST::to_string( String& result )
|
||||
case Parameters:
|
||||
cast<CodeParam>().to_string( result );
|
||||
break;
|
||||
|
||||
|
||||
case Preprocess_Define:
|
||||
cast<CodeDefine>().to_string( result );
|
||||
break;
|
||||
|
@ -113,13 +113,19 @@ struct Code
|
||||
return ast;
|
||||
}
|
||||
Code& operator ++();
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO(Ed) : Remove this overload.
|
||||
// auto& operator*()
|
||||
// {
|
||||
// return *this;
|
||||
// }
|
||||
auto& operator*()
|
||||
{
|
||||
local_persist thread_local
|
||||
Code NullRef = { nullptr };
|
||||
|
||||
if ( ast == nullptr )
|
||||
return NullRef;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
AST* ast;
|
||||
|
||||
@ -182,7 +188,10 @@ struct AST
|
||||
char const* type_str();
|
||||
bool validate_body();
|
||||
|
||||
neverinline String to_string();
|
||||
String to_string();
|
||||
|
||||
neverinline
|
||||
void to_string( String& result );
|
||||
|
||||
template< class Type >
|
||||
forceinline Type cast()
|
||||
@ -282,6 +291,7 @@ struct AST
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
// CodeFlag CodeFlags;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
@ -341,6 +351,7 @@ struct AST_POD
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
CodeFlag CodeFlags;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
@ -369,6 +380,14 @@ static_assert( sizeof(AST_POD) == AST_POD_Size, "ERROR: AST POD is not size o
|
||||
|
||||
#pragma region Code Types
|
||||
|
||||
// struct CodeIterator
|
||||
// {
|
||||
// Code begin()
|
||||
// {
|
||||
|
||||
// }
|
||||
// };
|
||||
|
||||
struct CodeBody
|
||||
{
|
||||
Using_Code( CodeBody );
|
||||
@ -424,7 +443,7 @@ struct CodeClass
|
||||
Using_Code( CodeClass );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
@ -569,7 +588,7 @@ struct CodeStruct
|
||||
Using_Code( CodeStruct );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
@ -609,10 +628,10 @@ Define_CodeType( Comment );
|
||||
struct CodeConstructor
|
||||
{
|
||||
Using_Code( CodeConstructor );
|
||||
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Constructor* operator->();
|
||||
@ -622,9 +641,9 @@ struct CodeConstructor
|
||||
struct CodeDefine
|
||||
{
|
||||
Using_Code( CodeDefine );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Define* operator->();
|
||||
@ -634,10 +653,10 @@ struct CodeDefine
|
||||
struct CodeDestructor
|
||||
{
|
||||
Using_Code( CodeDestructor );
|
||||
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Destructor* operator->();
|
||||
@ -647,10 +666,12 @@ struct CodeDestructor
|
||||
struct CodeEnum
|
||||
{
|
||||
Using_Code( CodeEnum );
|
||||
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
void to_string_class_def( String& result );
|
||||
void to_string_class_fwd( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Enum* operator->();
|
||||
@ -662,9 +683,9 @@ Define_CodeType( Exec );
|
||||
struct CodeExtern
|
||||
{
|
||||
Using_Code( CodeExtern );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Extern* operator->();
|
||||
@ -674,9 +695,9 @@ struct CodeExtern
|
||||
struct CodeInclude
|
||||
{
|
||||
Using_Code( CodeInclude );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Include* operator->();
|
||||
@ -686,9 +707,9 @@ struct CodeInclude
|
||||
struct CodeFriend
|
||||
{
|
||||
Using_Code( CodeFriend );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Friend* operator->();
|
||||
@ -697,11 +718,11 @@ struct CodeFriend
|
||||
|
||||
struct CodeFn
|
||||
{
|
||||
Using_Code( CodeFriend );
|
||||
|
||||
Using_Code( CodeFn );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Fn* operator->();
|
||||
@ -711,9 +732,9 @@ struct CodeFn
|
||||
struct CodeModule
|
||||
{
|
||||
Using_Code( CodeModule );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Module* operator->();
|
||||
@ -723,9 +744,9 @@ struct CodeModule
|
||||
struct CodeNS
|
||||
{
|
||||
Using_Code( CodeNS );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_NS* operator->();
|
||||
@ -735,10 +756,10 @@ struct CodeNS
|
||||
struct CodeOperator
|
||||
{
|
||||
Using_Code( CodeOperator );
|
||||
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Operator* operator->();
|
||||
@ -748,10 +769,10 @@ struct CodeOperator
|
||||
struct CodeOpCast
|
||||
{
|
||||
Using_Code( CodeOpCast );
|
||||
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_OpCast* operator->();
|
||||
@ -761,9 +782,9 @@ struct CodeOpCast
|
||||
struct CodePragma
|
||||
{
|
||||
Using_Code( CodePragma );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Pragma* operator->();
|
||||
@ -773,14 +794,14 @@ struct CodePragma
|
||||
struct CodePreprocessCond
|
||||
{
|
||||
Using_Code( CodePreprocessCond );
|
||||
|
||||
|
||||
void to_string_if( String& result );
|
||||
void to_string_ifdef( String& result );
|
||||
void to_string_ifndef( String& result );
|
||||
void to_string_elif( String& result );
|
||||
void to_string_else( String& result );
|
||||
void to_string_endif( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_PreprocessCond* operator->();
|
||||
@ -790,9 +811,9 @@ struct CodePreprocessCond
|
||||
struct CodeTemplate
|
||||
{
|
||||
Using_Code( CodeTemplate );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Template* operator->();
|
||||
@ -802,9 +823,9 @@ struct CodeTemplate
|
||||
struct CodeType
|
||||
{
|
||||
Using_Code( CodeType );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Type* operator->();
|
||||
@ -814,9 +835,9 @@ struct CodeType
|
||||
struct CodeTypedef
|
||||
{
|
||||
Using_Code( CodeTypedef );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Typedef* operator->();
|
||||
@ -826,9 +847,9 @@ struct CodeTypedef
|
||||
struct CodeUnion
|
||||
{
|
||||
Using_Code( CodeUnion );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Union* operator->();
|
||||
@ -838,10 +859,10 @@ struct CodeUnion
|
||||
struct CodeUsing
|
||||
{
|
||||
Using_Code( CodeUsing );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
void to_string_ns( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Using* operator->();
|
||||
@ -851,9 +872,9 @@ struct CodeUsing
|
||||
struct CodeVar
|
||||
{
|
||||
Using_Code( CodeVar );
|
||||
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Var* operator->();
|
||||
|
@ -1,4 +1,4 @@
|
||||
#if GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast.cpp"
|
||||
#endif
|
||||
@ -24,6 +24,11 @@ String CodeBody::to_string()
|
||||
switch ( ast->Type )
|
||||
{
|
||||
using namespace ECode;
|
||||
case Untyped:
|
||||
case Execution:
|
||||
result.append( raw()->Content );
|
||||
break;
|
||||
|
||||
case Enum_Body:
|
||||
case Class_Body:
|
||||
case Extern_Linkage_Body:
|
||||
@ -34,7 +39,7 @@ String CodeBody::to_string()
|
||||
case Union_Body:
|
||||
to_string( result );
|
||||
break;
|
||||
|
||||
|
||||
case Export_Body:
|
||||
to_string_export( result );
|
||||
break;
|
||||
@ -57,7 +62,7 @@ void CodeBody::to_string_export( String& result )
|
||||
{
|
||||
result.append_fmt( "export\n{\n" );
|
||||
|
||||
Code curr = { this };
|
||||
Code curr = *this;
|
||||
s32 left = ast->NumEntries;
|
||||
while ( left-- )
|
||||
{
|
||||
@ -91,26 +96,26 @@ String CodeConstructor::to_string()
|
||||
|
||||
void CodeConstructor::to_string_def( String& result )
|
||||
{
|
||||
result.append( ast->Parent->name );
|
||||
|
||||
result.append( ast->Parent->Name );
|
||||
|
||||
if ( ast->Params )
|
||||
result.append_fmt( "( %S )", ast->Params.to_string() );
|
||||
else
|
||||
result.append( "(void)" );
|
||||
|
||||
|
||||
if ( ast->InitializerList )
|
||||
result.append_fmt( " : %S", ast->InitializerList.to_string() );
|
||||
|
||||
|
||||
if ( ast->InlineCmt )
|
||||
result.append_fmt( " // %S", ast->InlineCmt->Content );
|
||||
|
||||
|
||||
result.append_fmt( "\n{\n%S\n}\n", ast->Body.to_string() );
|
||||
}
|
||||
|
||||
void CodeConstructor::to_string_fwd( String& result )
|
||||
{
|
||||
result.append( ast->Parent->Name );
|
||||
|
||||
|
||||
if ( ast->Params )
|
||||
result.append_fmt( "( %S )", ast->Params.to_string() );
|
||||
else
|
||||
@ -178,7 +183,7 @@ void CodeClass::to_string_def( String& result )
|
||||
|
||||
result.append_fmt( "\n{\n%S\n}", ast->Body.to_string() );
|
||||
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
result.append(";\n");
|
||||
}
|
||||
|
||||
@ -193,7 +198,7 @@ void CodeClass::to_string_fwd( String& result )
|
||||
else result.append_fmt( "class %S", ast->Name );
|
||||
|
||||
// Check if it can have an end-statement
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( ast->InlineCmt )
|
||||
result.append_fmt( "; // %S\n", ast->InlineCmt->Content );
|
||||
@ -209,7 +214,7 @@ String CodeDefine::to_string()
|
||||
|
||||
void CodeDefine::to_string( String& result )
|
||||
{
|
||||
return result.append_fmt( "#define %S %S\n", ast->Name, ast->Content );
|
||||
result.append_fmt( "#define %S %S\n", ast->Name, ast->Content );
|
||||
}
|
||||
|
||||
String CodeDestructor::to_string()
|
||||
@ -239,7 +244,7 @@ void CodeDestructor::to_string_def( String& result )
|
||||
}
|
||||
else
|
||||
result.append_fmt( "~%S()", ast->Parent->Name );
|
||||
|
||||
|
||||
result.append_fmt( "\n{\n%S\n}\n", ast->Body.to_string() );
|
||||
}
|
||||
|
||||
@ -290,26 +295,26 @@ void CodeEnum::to_string_def( String& result )
|
||||
{
|
||||
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag::Export ))
|
||||
result.append( "export " );
|
||||
|
||||
|
||||
if ( ast->Attributes || ast->UnderlyingType )
|
||||
{
|
||||
result.append( "enum " );
|
||||
|
||||
|
||||
if ( ast->Attributes )
|
||||
result.append_fmt( "%S ", ast->Attributes.to_string() );
|
||||
|
||||
if ( UnderlyingType )
|
||||
|
||||
if ( ast->UnderlyingType )
|
||||
result.append_fmt( "%S : %S\n{\n%S\n}"
|
||||
, ast->Name
|
||||
, ast->UnderlyingType.to_string()
|
||||
, ast->Body.to_string()
|
||||
);
|
||||
|
||||
|
||||
else result.append_fmt( "%S\n{\n%S\n}", ast->Name, ast->Body.to_string() );
|
||||
}
|
||||
else result.append_fmt( "enum %S\n{\n%S\n}", ast->Name, ast->Body.to_string() );
|
||||
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
result.append(";\n");
|
||||
}
|
||||
|
||||
@ -323,7 +328,7 @@ void CodeEnum::to_string_fwd( String& result )
|
||||
|
||||
result.append_fmt( "enum %S : %S", ast->Name, ast->UnderlyingType.to_string() );
|
||||
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( ast->InlineCmt )
|
||||
result.append_fmt("; %S", ast->InlineCmt->Content );
|
||||
@ -336,16 +341,16 @@ void CodeEnum::to_string_class_def( String& result )
|
||||
{
|
||||
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag::Export ))
|
||||
result.append( "export " );
|
||||
|
||||
|
||||
if ( ast->Attributes || ast->UnderlyingType )
|
||||
{
|
||||
result.append( "enum class " );
|
||||
|
||||
|
||||
if ( ast->Attributes )
|
||||
{
|
||||
result.append_fmt( "%S ", ast->Attributes.to_string() );
|
||||
}
|
||||
|
||||
|
||||
if ( ast->UnderlyingType )
|
||||
{
|
||||
result.append_fmt( "%S : %S\n{\n%S\n}", ast->Name, ast->UnderlyingType.to_string(), ast->Body.to_string() );
|
||||
@ -359,8 +364,8 @@ void CodeEnum::to_string_class_def( String& result )
|
||||
{
|
||||
result.append_fmt( "enum class %S\n{\n%S\n}", ast->Body.to_string() );
|
||||
}
|
||||
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
result.append(";\n");
|
||||
}
|
||||
|
||||
@ -376,7 +381,7 @@ void CodeEnum::to_string_class_fwd( String& result )
|
||||
|
||||
result.append_fmt( "%S : %S", ast->Name, ast->UnderlyingType.to_string() );
|
||||
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( ast->InlineCmt )
|
||||
result.append_fmt("; %S", ast->InlineCmt->Content );
|
||||
@ -390,13 +395,6 @@ String CodeExec::to_string()
|
||||
return ast->Content.duplicate( GlobalAllocator );
|
||||
}
|
||||
|
||||
String CodeExtern::to_string()
|
||||
{
|
||||
String result = String::make( GlobalAllocator, "" );
|
||||
to_string( result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void CodeExtern::to_string( String& result )
|
||||
{
|
||||
if ( ast->Body )
|
||||
@ -407,7 +405,7 @@ void CodeExtern::to_string( String& result )
|
||||
|
||||
String CodeInclude::to_string()
|
||||
{
|
||||
return String::fmt( GlobalAllocator, "#include %S\n", ast->Content );
|
||||
return String::fmt_buf( GlobalAllocator, "#include %S\n", ast->Content );
|
||||
}
|
||||
|
||||
void CodeInclude::to_string( String& result )
|
||||
@ -415,7 +413,7 @@ void CodeInclude::to_string( String& result )
|
||||
result.append_fmt( "#include %S\n", ast->Content );
|
||||
}
|
||||
|
||||
String CodeFriend::to_string( String& result )
|
||||
String CodeFriend::to_string()
|
||||
{
|
||||
String result = String::make( GlobalAllocator, "" );
|
||||
to_string( result );
|
||||
@ -437,7 +435,7 @@ void CodeFriend::to_string( String& result )
|
||||
result.append("\n");
|
||||
}
|
||||
|
||||
String CodeFn::to_string( String& result )
|
||||
String CodeFn::to_string()
|
||||
{
|
||||
String result = String::make( GlobalAllocator, "" );
|
||||
switch ( ast->Type )
|
||||
@ -482,7 +480,7 @@ void CodeFn::to_string_def( String& result )
|
||||
else
|
||||
result.append_fmt( "%S(", ast->Name );
|
||||
|
||||
if ( Params )
|
||||
if ( ast->Params )
|
||||
result.append_fmt( "%S)", ast->Params.to_string() );
|
||||
|
||||
else
|
||||
@ -511,9 +509,9 @@ void CodeFn::to_string_fwd( String& result )
|
||||
if ( ast->Attributes )
|
||||
result.append_fmt( "%S ", ast->Attributes.to_string() );
|
||||
|
||||
if ( Specs )
|
||||
if ( ast->Specs )
|
||||
{
|
||||
for ( SpecifierT spec : Specs )
|
||||
for ( SpecifierT spec : ast->Specs )
|
||||
{
|
||||
if ( ! ESpecifier::is_trailing( spec ) )
|
||||
{
|
||||
@ -542,7 +540,7 @@ void CodeFn::to_string_fwd( String& result )
|
||||
|
||||
if ( ast->Specs )
|
||||
{
|
||||
for ( SpecifierT spec : Specs )
|
||||
for ( SpecifierT spec : ast->Specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
{
|
||||
@ -673,7 +671,7 @@ void CodeOperator::to_string_fwd( String& result )
|
||||
|
||||
if ( ast->Specs )
|
||||
{
|
||||
for ( SpecifierT spec : Specs )
|
||||
for ( SpecifierT spec : ast->Specs )
|
||||
{
|
||||
if ( ! ESpecifier::is_trailing( spec ) )
|
||||
{
|
||||
@ -698,7 +696,7 @@ void CodeOperator::to_string_fwd( String& result )
|
||||
|
||||
if ( ast->Specs )
|
||||
{
|
||||
for ( SpecifierT spec : Specs )
|
||||
for ( SpecifierT spec : ast->Specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
{
|
||||
@ -741,7 +739,7 @@ void CodeOpCast::to_string_def( String& result )
|
||||
else
|
||||
result.append_fmt( "operator %S()", ast->ValueType.to_string() );
|
||||
|
||||
for ( SpecifierT spec : Specs )
|
||||
for ( SpecifierT spec : ast->Specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
{
|
||||
@ -751,7 +749,7 @@ void CodeOpCast::to_string_def( String& result )
|
||||
}
|
||||
|
||||
result.append_fmt( "\n{\n%S\n}\n", ast->Body.to_string() );
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ast->Name && ast->Name.length() )
|
||||
@ -765,10 +763,10 @@ void CodeOpCast::to_string_fwd( String& result )
|
||||
if ( ast->Specs )
|
||||
{
|
||||
// TODO : Add support for specifies before the operator keyword
|
||||
|
||||
|
||||
result.append_fmt( "operator %S()", ast->ValueType.to_string() );
|
||||
|
||||
for ( SpecifierT spec : Specs )
|
||||
|
||||
for ( SpecifierT spec : ast->Specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
{
|
||||
@ -776,14 +774,14 @@ void CodeOpCast::to_string_fwd( String& result )
|
||||
result.append_fmt( " %*s", spec_str.Len, spec_str.Ptr );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ast->InlineCmt )
|
||||
result.append_fmt( "; %S", ast->InlineCmt->Content );
|
||||
else
|
||||
result.append( ";\n" );
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( ast->InlineCmt )
|
||||
result.append_fmt("operator %S(); %S", ast->ValueType.to_string() );
|
||||
else
|
||||
@ -799,10 +797,10 @@ String CodeParam::to_string()
|
||||
|
||||
void CodeParam::to_string( String& result )
|
||||
{
|
||||
if ( ast->ValueType == nullptr )
|
||||
if ( ast->ValueType.ast == nullptr )
|
||||
{
|
||||
result.append_fmt( "%S", ast->Name );
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ast->Name )
|
||||
@ -835,7 +833,7 @@ String CodePreprocessCond::to_string()
|
||||
case Preprocess_IfDef:
|
||||
to_string_ifdef( result );
|
||||
break;
|
||||
case Preprocess_IfNotDef
|
||||
case Preprocess_IfNotDef:
|
||||
to_string_ifndef( result );
|
||||
break;
|
||||
case Preprocess_ElIf:
|
||||
@ -968,7 +966,7 @@ void CodeStruct::to_string_def( String& result )
|
||||
|
||||
result.append_fmt( "\n{\n%S\n}", ast->Body.to_string() );
|
||||
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
result.append(";\n");
|
||||
}
|
||||
|
||||
@ -982,7 +980,7 @@ void CodeStruct::to_string_fwd( String& result )
|
||||
|
||||
else result.append_fmt( "struct %S", ast->Name );
|
||||
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( ast->InlineCmt )
|
||||
result.append_fmt("; %S", ast->InlineCmt->Content );
|
||||
@ -1029,14 +1027,14 @@ void CodeTypedef::to_string( String& result )
|
||||
else
|
||||
result.append_fmt( "%S %S", ast->UnderlyingType.to_string(), ast->Name );
|
||||
|
||||
if ( ast->UnderlyingType->Type == Typename && ast->UnderlyingType->ArrExpr )
|
||||
if ( ast->UnderlyingType->Type == ECode::Typename && ast->UnderlyingType->ArrExpr )
|
||||
{
|
||||
result.append_fmt( "[ %S ];", ast->UnderlyingType->ArrExpr->to_string() );
|
||||
|
||||
AST* next_arr_expr = ast->UnderlyingType->ArrExpr->Next;
|
||||
while ( next_arr_expr )
|
||||
{
|
||||
result.append_fmt( "[ %S ];", next_arr_expr.to_string() );
|
||||
result.append_fmt( "[ %S ];", next_arr_expr->to_string() );
|
||||
next_arr_expr = next_arr_expr->Next;
|
||||
}
|
||||
}
|
||||
@ -1082,13 +1080,13 @@ void CodeType::to_string( String& result )
|
||||
result.append_fmt( "%S ", ast->Attributes.to_string() );
|
||||
else
|
||||
{
|
||||
if ( Specs )
|
||||
if ( ast->Specs )
|
||||
result.append_fmt( "%S %S ( %S ) %S", ast->ReturnType.to_string(), ast->Name, ast->Params.to_string(), ast->Specs.to_string() );
|
||||
else
|
||||
result.append_fmt( "%S %S ( %S )", ast->ReturnType.to_string(), ast->Name, ast->Params.to_string() );
|
||||
}
|
||||
|
||||
break;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1136,7 +1134,7 @@ void CodeUnion::to_string( String& result )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ast->Parent == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
|
||||
result.append(";\n");
|
||||
}
|
||||
|
||||
@ -1236,7 +1234,7 @@ void CodeVar::to_string( String& result )
|
||||
if ( ast->NextVar )
|
||||
result.append_fmt( ", %S", ast->NextVar.to_string() );
|
||||
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag::Export ))
|
||||
@ -1278,13 +1276,13 @@ void CodeVar::to_string( String& result )
|
||||
else
|
||||
result.append( ";\n" );
|
||||
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ast->BitfieldSize )
|
||||
result.append_fmt( "%S %S : %S", ast->ValueType.to_string(), ast->Name, ast->BitfieldSize.to_string() );
|
||||
|
||||
else if ( ValueType->ArrExpr )
|
||||
else if ( ast->ValueType->ArrExpr )
|
||||
{
|
||||
result.append_fmt( "%S %S[ %S ]", ast->ValueType.to_string(), ast->Name, ast->ValueType->ArrExpr.to_string() );
|
||||
|
||||
@ -1299,15 +1297,15 @@ void CodeVar::to_string( String& result )
|
||||
else
|
||||
result.append_fmt( "%S %S", ast->ValueType.to_string(), ast->Name );
|
||||
|
||||
if ( Value )
|
||||
if ( ast->Value )
|
||||
result.append_fmt( " = %S", ast->Value.to_string() );
|
||||
|
||||
if ( NextVar )
|
||||
if ( ast->NextVar )
|
||||
result.append_fmt( ", %S", ast->NextVar.to_string() );
|
||||
|
||||
result.append( ";" );
|
||||
|
||||
if ( InlineCmt )
|
||||
if ( ast->InlineCmt )
|
||||
result.append_fmt(" %S", ast->InlineCmt->Content);
|
||||
else
|
||||
result.append("\n");
|
||||
|
@ -869,16 +869,6 @@ void CodeExtern::set_global()
|
||||
rcast( AST*, ast )->Parent = Code::Global.ast;
|
||||
}
|
||||
|
||||
String CodeExtern::to_string()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
|
||||
return { nullptr };
|
||||
}
|
||||
return rcast( AST*, ast )->to_string();
|
||||
}
|
||||
|
||||
CodeExtern& CodeExtern::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace Parser
|
||||
namespace parser
|
||||
{
|
||||
namespace ETokType
|
||||
{
|
||||
@ -234,4 +234,4 @@ namespace Parser
|
||||
|
||||
using TokType = ETokType::Type;
|
||||
|
||||
} // namespace Parser
|
||||
} // namespace parser
|
||||
|
@ -3,8 +3,10 @@
|
||||
#include "code_serialization.cpp"
|
||||
#endif
|
||||
|
||||
internal void init_parser();
|
||||
internal void deinit_parser();
|
||||
namespace parser {
|
||||
internal void init();
|
||||
internal void deinit();
|
||||
}
|
||||
|
||||
internal
|
||||
void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
|
||||
@ -288,7 +290,7 @@ void init()
|
||||
}
|
||||
|
||||
define_constants();
|
||||
init_parser();
|
||||
parser::init();
|
||||
}
|
||||
|
||||
void deinit()
|
||||
@ -331,7 +333,7 @@ void deinit()
|
||||
while ( left--, left );
|
||||
|
||||
Global_AllocatorBuckets.free();
|
||||
deinit_parser();
|
||||
parser::deinit();
|
||||
}
|
||||
|
||||
void reset()
|
||||
|
File diff suppressed because it is too large
Load Diff
1207
project/components/lexer.cpp
Normal file
1207
project/components/lexer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
4400
project/components/parser.cpp
Normal file
4400
project/components/parser.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user