Comment, Constructor, Destructor, Define, Enum, Exec, Extern, Include, Friend, Fn codes member proc usage reductions

This commit is contained in:
Edward R. Gonzalez 2024-12-02 16:59:13 -05:00
parent 0bad61fda6
commit 8f47f3b30f
4 changed files with 285 additions and 254 deletions

View File

@ -423,35 +423,35 @@ void to_string( AST* self, String* result )
break; break;
case Constructor: case Constructor:
cast(CodeConstructor, {self}).to_string_def( * result ); to_string_def(cast(CodeConstructor, {self}), result );
break; break;
case Constructor_Fwd: case Constructor_Fwd:
cast(CodeConstructor, {self}).to_string_fwd( * result ); to_string_fwd(cast(CodeConstructor, {self}), result );
break; break;
case Destructor: case Destructor:
cast(CodeDestructor, {self}).to_string_def( * result ); to_string_def(cast(CodeDestructor, {self}), result );
break; break;
case Destructor_Fwd: case Destructor_Fwd:
cast(CodeDestructor, {self}).to_string_fwd( * result ); to_string_fwd(cast(CodeDestructor, {self}), result );
break; break;
case Enum: case Enum:
cast(CodeEnum, {self}).to_string_def( * result ); to_string_def(cast(CodeEnum, {self}), result );
break; break;
case Enum_Fwd: case Enum_Fwd:
cast(CodeEnum, {self}).to_string_fwd( * result ); to_string_fwd(cast(CodeEnum, {self}), result );
break; break;
case Enum_Class: case Enum_Class:
cast(CodeEnum, {self}).to_string_class_def( * result ); to_string_class_def(cast(CodeEnum, {self}), result );
break; break;
case Enum_Class_Fwd: case Enum_Class_Fwd:
cast(CodeEnum, {self}).to_string_class_fwd( * result ); to_string_class_fwd(cast(CodeEnum, {self}), result );
break; break;
case Export_Body: case Export_Body:
@ -459,19 +459,19 @@ void to_string( AST* self, String* result )
break; break;
case Extern_Linkage: case Extern_Linkage:
cast(CodeExtern, {self}).to_string( * result ); to_string(cast(CodeExtern, {self}), result );
break; break;
case Friend: case Friend:
cast(CodeFriend, {self}).to_string( * result ); to_string(cast(CodeFriend, {self}), result );
break; break;
case Function: case Function:
cast(CodeFn, {self}).to_string_def( * result ); to_string_def(cast(CodeFn, {self}), result );
break; break;
case Function_Fwd: case Function_Fwd:
cast(CodeFn, {self}).to_string_fwd( * result ); to_string_fwd(cast(CodeFn, {self}), result );
break; break;
case Module: case Module:
@ -505,7 +505,7 @@ void to_string( AST* self, String* result )
break; break;
case Preprocess_Define: case Preprocess_Define:
cast(CodeDefine, {self}).to_string( * result ); to_string(cast(CodeDefine, {self}), result );
break; break;
case Preprocess_If: case Preprocess_If:
@ -521,7 +521,7 @@ void to_string( AST* self, String* result )
break; break;
case Preprocess_Include: case Preprocess_Include:
cast(CodeInclude, {self}).to_string( * result ); to_string(cast(CodeInclude, {self}), result );
break; break;
case Preprocess_ElIf: case Preprocess_ElIf:

View File

@ -77,73 +77,73 @@ void to_string_export( CodeBody body, String* result )
append_fmt( result, "};\n" ); append_fmt( result, "};\n" );
} }
String CodeComment::to_string() String to_string(CodeComment comment)
{ {
return GEN_NS duplicate( ast->Content, GlobalAllocator ); return GEN_NS duplicate( comment->Content, GlobalAllocator );
} }
String CodeConstructor::to_string() String to_string(CodeConstructor self)
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch (ast->Type) switch (self->Type)
{ {
using namespace ECode; using namespace ECode;
case Constructor: case Constructor:
to_string_def( result ); to_string_def( self, & result );
break; break;
case Constructor_Fwd: case Constructor_Fwd:
to_string_fwd( result ); to_string_fwd( self, & result );
break; break;
} }
return result; return result;
} }
void CodeConstructor::to_string_def( String& result ) void to_string_def(CodeConstructor self, String* result )
{ {
AST* ClassStructParent = ast->Parent->Parent; AST* ClassStructParent = self->Parent->Parent;
if (ClassStructParent) { if (ClassStructParent) {
append( & result, ClassStructParent->Name ); append( result, ClassStructParent->Name );
} }
else { else {
append( & result, ast->Name ); append( result, self->Name );
} }
if ( ast->Params ) if ( self->Params )
append_fmt( & result, "( %S )", GEN_NS to_string(ast->Params) ); append_fmt( result, "( %S )", GEN_NS to_string(self->Params) );
else else
append( & result, "()" ); append( result, "()" );
if ( ast->InitializerList ) if ( self->InitializerList )
append_fmt( & result, " : %S", GEN_NS to_string(ast->InitializerList) ); append_fmt( result, " : %S", GEN_NS to_string(self->InitializerList) );
if ( ast->InlineCmt ) if ( self->InlineCmt )
append_fmt( & result, " // %S", ast->InlineCmt->Content ); append_fmt( result, " // %S", self->InlineCmt->Content );
append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) ); append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
} }
void CodeConstructor::to_string_fwd( String& result ) void to_string_fwd(CodeConstructor self, String* result )
{ {
AST* ClassStructParent = ast->Parent->Parent; AST* ClassStructParent = self->Parent->Parent;
if (ClassStructParent) { if (ClassStructParent) {
append( & result, ClassStructParent->Name ); append( result, ClassStructParent->Name );
} }
else { else {
append( & result, ast->Name ); append( result, self->Name );
} }
if ( ast->Params ) if ( self->Params )
append_fmt( & result, "( %S )", GEN_NS to_string(ast->Params) ); append_fmt( result, "( %S )", GEN_NS to_string(self->Params) );
else else
append_fmt( & result, "()"); append_fmt( result, "()");
if (ast->Body) if (self->Body)
append_fmt( & result, " = %S", GEN_NS to_string(ast->Body) ); append_fmt( result, " = %S", GEN_NS to_string(self->Body) );
if ( ast->InlineCmt ) if ( self->InlineCmt )
append_fmt( & result, "; // %S\n", ast->InlineCmt->Content ); append_fmt( result, "; // %S\n", self->InlineCmt->Content );
else else
append( & result, ";\n" ); append( result, ";\n" );
} }
String to_string( CodeClass self ) String to_string( CodeClass self )
@ -232,379 +232,379 @@ void to_string_fwd( CodeClass self, String* result )
} }
} }
String CodeDefine::to_string() String to_string(CodeDefine define)
{ {
return string_fmt_buf( GlobalAllocator, "#define %S %S\n", ast->Name, ast->Content ); return string_fmt_buf( GlobalAllocator, "#define %S %S\n", define->Name, define->Content );
} }
void CodeDefine::to_string( String& result ) void to_string(CodeDefine define, String* result )
{ {
append_fmt( & result, "#define %S %S\n", ast->Name, ast->Content ); append_fmt( result, "#define %S %S\n", define->Name, define->Content );
} }
String CodeDestructor::to_string() String to_string(CodeDestructor self)
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( ast->Type ) switch ( self->Type )
{ {
using namespace ECode; using namespace ECode;
case Destructor: case Destructor:
to_string_def( result ); to_string_def( self, & result );
break; break;
case Destructor_Fwd: case Destructor_Fwd:
to_string_fwd( result ); to_string_fwd( self, & result );
break; break;
} }
return result; return result;
} }
void CodeDestructor::to_string_def( String& result ) void to_string_def(CodeDestructor self, String* result )
{ {
if ( ast->Name ) if ( self->Name )
{ {
append_fmt( & result, "%S()", ast->Name ); append_fmt( result, "%S()", self->Name );
} }
else if ( ast->Specs ) else if ( self->Specs )
{ {
if ( has(ast->Specs, ESpecifier::Virtual ) ) if ( has(self->Specs, ESpecifier::Virtual ) )
append_fmt( & result, "virtual ~%S()", ast->Parent->Name ); append_fmt( result, "virtual ~%S()", self->Parent->Name );
else else
append_fmt( & result, "~%S()", ast->Parent->Name ); append_fmt( result, "~%S()", self->Parent->Name );
} }
else else
append_fmt( & result, "~%S()", ast->Parent->Name ); append_fmt( result, "~%S()", self->Parent->Name );
append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) ); append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
} }
void CodeDestructor::to_string_fwd( String& result ) void to_string_fwd(CodeDestructor self, String* result )
{ {
if ( ast->Specs ) if ( self->Specs )
{ {
if ( has(ast->Specs, ESpecifier::Virtual ) ) if ( has(self->Specs, ESpecifier::Virtual ) )
append_fmt( & result, "virtual ~%S();\n", ast->Parent->Name ); append_fmt( result, "virtual ~%S();\n", self->Parent->Name );
else else
append_fmt( & result, "~%S()", ast->Parent->Name ); append_fmt( result, "~%S()", self->Parent->Name );
if ( has(ast->Specs, ESpecifier::Pure ) ) if ( has(self->Specs, ESpecifier::Pure ) )
append( & result, " = 0;" ); append( result, " = 0;" );
else if (ast->Body) else if (self->Body)
append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) ); append_fmt( result, " = %S;", GEN_NS to_string(self->Body) );
} }
else else
append_fmt( & result, "~%S();", ast->Parent->Name ); append_fmt( result, "~%S();", self->Parent->Name );
if ( ast->InlineCmt ) if ( self->InlineCmt )
append_fmt( & result, " %S", ast->InlineCmt->Content ); append_fmt( result, " %S", self->InlineCmt->Content );
else else
append( & result, "\n"); append( result, "\n");
} }
String CodeEnum::to_string() String to_string(CodeEnum self)
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( ast->Type ) switch ( self->Type )
{ {
using namespace ECode; using namespace ECode;
case Enum: case Enum:
to_string_def( result ); to_string_def(self, & result );
break; break;
case Enum_Fwd: case Enum_Fwd:
to_string_fwd( result ); to_string_fwd(self, & result );
break; break;
case Enum_Class: case Enum_Class:
to_string_class_def( result ); to_string_class_def(self, & result );
break; break;
case Enum_Class_Fwd: case Enum_Class_Fwd:
to_string_class_fwd( result ); to_string_class_fwd(self, & result );
break; break;
} }
return result; return result;
} }
void CodeEnum::to_string_def( String& result ) void to_string_def(CodeEnum self, String* result )
{ {
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " ); append( result, "export " );
if ( ast->Attributes || ast->UnderlyingType ) if ( self->Attributes || self->UnderlyingType )
{ {
append( & result, "enum " ); append( result, "enum " );
if ( ast->Attributes ) if ( self->Attributes )
append_fmt( & result, "%S ", GEN_NS to_string(ast->Attributes) ); append_fmt( result, "%S ", GEN_NS to_string(self->Attributes) );
if ( ast->UnderlyingType ) if ( self->UnderlyingType )
append_fmt( & result, "%S : %S\n{\n%S\n}" append_fmt( result, "%S : %S\n{\n%S\n}"
, ast->Name , self->Name
, ast->UnderlyingType.to_string() , self->UnderlyingType.to_string()
, GEN_NS to_string(ast->Body) , GEN_NS to_string(self->Body)
); );
else if ( ast->UnderlyingTypeMacro ) else if ( self->UnderlyingTypeMacro )
append_fmt( & result, "%S : %S\n{\n%S\n}" append_fmt( result, "%S : %S\n{\n%S\n}"
, ast->Name , self->Name
, GEN_NS to_string(ast->UnderlyingTypeMacro) , GEN_NS to_string(self->UnderlyingTypeMacro)
, GEN_NS to_string(ast->Body) , GEN_NS to_string(self->Body)
); );
else append_fmt( & result, "%S\n{\n%S\n}", ast->Name, GEN_NS to_string(ast->Body) ); else append_fmt( result, "%S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) );
} }
else append_fmt( & result, "enum %S\n{\n%S\n}", ast->Name, GEN_NS to_string(ast->Body) ); else append_fmt( result, "enum %S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
append( & result, ";\n"); append( result, ";\n");
} }
void CodeEnum::to_string_fwd( String& result ) void to_string_fwd(CodeEnum self, String* result )
{ {
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " ); append( result, "export " );
if ( ast->Attributes ) if ( self->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) ); append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
if ( ast->UnderlyingType ) if ( self->UnderlyingType )
append_fmt( & result, "enum %S : %S", ast->Name, ast->UnderlyingType.to_string() ); append_fmt( result, "enum %S : %S", self->Name, self->UnderlyingType.to_string() );
else else
append_fmt( & result, "enum %S", ast->Name ); append_fmt( result, "enum %S", self->Name );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
{ {
if ( ast->InlineCmt ) if ( self->InlineCmt )
append_fmt( & result, "; %S", ast->InlineCmt->Content ); append_fmt( result, "; %S", self->InlineCmt->Content );
else else
append( & result, ";\n"); append( result, ";\n");
} }
} }
void CodeEnum::to_string_class_def( String& result ) void to_string_class_def(CodeEnum self, String* result )
{ {
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " ); append( result, "export " );
if ( ast->Attributes || ast->UnderlyingType ) if ( self->Attributes || self->UnderlyingType )
{ {
append( & result, "enum class " ); append( result, "enum class " );
if ( ast->Attributes ) if ( self->Attributes )
{ {
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) ); append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
} }
if ( ast->UnderlyingType ) if ( self->UnderlyingType )
{ {
append_fmt( & result, "%S : %S\n{\n%S\n}", ast->Name, ast->UnderlyingType.to_string(), GEN_NS to_string(ast->Body) ); append_fmt( result, "%S : %S\n{\n%S\n}", self->Name, self->UnderlyingType.to_string(), GEN_NS to_string(self->Body) );
} }
else else
{ {
append_fmt( & result, "%S\n{\n%S\n}", ast->Name, GEN_NS to_string(ast->Body) ); append_fmt( result, "%S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) );
} }
} }
else else
{ {
append_fmt( & result, "enum class %S\n{\n%S\n}", GEN_NS to_string(ast->Body) ); append_fmt( result, "enum class %S\n{\n%S\n}", GEN_NS to_string(self->Body) );
} }
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
append( & result, ";\n"); append( result, ";\n");
} }
void CodeEnum::to_string_class_fwd( String& result ) void to_string_class_fwd(CodeEnum self, String* result )
{ {
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " ); append( result, "export " );
append( & result, "enum class " ); append( result, "enum class " );
if ( ast->Attributes ) if ( self->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) ); append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
append_fmt( & result, "%S : %S", ast->Name, ast->UnderlyingType.to_string() ); append_fmt( result, "%S : %S", self->Name, self->UnderlyingType.to_string() );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) ) if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
{ {
if ( ast->InlineCmt ) if ( self->InlineCmt )
append_fmt( & result, "; %S", ast->InlineCmt->Content ); append_fmt( result, "; %S", self->InlineCmt->Content );
else else
append( & result, ";\n"); append( result, ";\n");
} }
} }
String CodeExec::to_string() String to_string(CodeExec exec)
{ {
return GEN_NS duplicate( ast->Content, GlobalAllocator ); return GEN_NS duplicate( exec->Content, GlobalAllocator );
} }
void CodeExtern::to_string( String& result ) void to_string(CodeExtern self, String* result )
{ {
if ( ast->Body ) if ( self->Body )
append_fmt( & result, "extern \"%S\"\n{\n%S\n}\n", ast->Name, GEN_NS to_string(ast->Body) ); append_fmt( result, "extern \"%S\"\n{\n%S\n}\n", self->Name, GEN_NS to_string(self->Body) );
else else
append_fmt( & result, "extern \"%S\"\n{}\n", ast->Name ); append_fmt( result, "extern \"%S\"\n{}\n", self->Name );
} }
String CodeInclude::to_string() String to_string(CodeInclude include)
{ {
return string_fmt_buf( GlobalAllocator, "#include %S\n", ast->Content ); return string_fmt_buf( GlobalAllocator, "#include %S\n", include->Content );
} }
void CodeInclude::to_string( String& result ) void to_string( CodeInclude include, String* result )
{ {
append_fmt( & result, "#include %S\n", ast->Content ); append_fmt( result, "#include %S\n", include->Content );
} }
String CodeFriend::to_string() String to_string(CodeFriend self)
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
to_string( result ); to_string( self, & result );
return result; return result;
} }
void CodeFriend::to_string( String& result ) void to_string(CodeFriend self, String* result )
{ {
append_fmt( & result, "friend %S", GEN_NS to_string(ast->Declaration) ); append_fmt( result, "friend %S", GEN_NS to_string(self->Declaration) );
if ( ast->Declaration->Type != ECode::Function && result[ length(result) - 1 ] != ';' ) if ( self->Declaration->Type != ECode::Function && (* result)[ length(* result) - 1 ] != ';' )
{ {
append( & result, ";" ); append( result, ";" );
} }
if ( ast->InlineCmt ) if ( self->InlineCmt )
append_fmt( & result, " %S", ast->InlineCmt->Content ); append_fmt( result, " %S", self->InlineCmt->Content );
else else
append( & result, "\n"); append( result, "\n");
} }
String CodeFn::to_string() String to_string(CodeFn self)
{ {
String result = string_make( GlobalAllocator, "" ); String result = string_make( GlobalAllocator, "" );
switch ( ast->Type ) switch ( self->Type )
{ {
using namespace ECode; using namespace ECode;
case Function: case Function:
to_string_def( result ); to_string_def(self, & result );
break; break;
case Function_Fwd: case Function_Fwd:
to_string_fwd( result ); to_string_fwd(self, & result );
break; break;
} }
return result; return result;
} }
void CodeFn::to_string_def( String& result ) void to_string_def(CodeFn self, String* result )
{ {
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( & result, "export" ); append( result, "export" );
if ( ast->Attributes ) if ( self->Attributes )
append_fmt( & result, " %S ",GEN_NS to_string(ast->Attributes) ); append_fmt( result, " %S ",GEN_NS to_string(self->Attributes) );
bool prefix_specs = false; bool prefix_specs = false;
if ( ast->Specs ) if ( self->Specs )
{ {
for ( SpecifierT spec : ast->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ! ESpecifier::is_trailing( spec ) ) if ( ! ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = ESpecifier::to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
prefix_specs = true; prefix_specs = true;
} }
} }
} }
if ( ast->Attributes || prefix_specs ) if ( self->Attributes || prefix_specs )
append( & result, "\n" ); append( result, "\n" );
if ( ast->ReturnType ) if ( self->ReturnType )
append_fmt( & result, "%S %S(", ast->ReturnType.to_string(), ast->Name ); append_fmt( result, "%S %S(", self->ReturnType.to_string(), self->Name );
else else
append_fmt( & result, "%S(", ast->Name ); append_fmt( result, "%S(", self->Name );
if ( ast->Params ) if ( self->Params )
append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) ); append_fmt( result, "%S)", GEN_NS to_string(self->Params) );
else else
append( & result, ")" ); append( result, ")" );
if ( ast->Specs ) if ( self->Specs )
{ {
for ( SpecifierT spec : ast->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ESpecifier::is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = ESpecifier::to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
} }
append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) ); append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
} }
void CodeFn::to_string_fwd( String& result ) void to_string_fwd(CodeFn self, String* result )
{ {
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " ); append( result, "export " );
if ( ast->Attributes ) if ( self->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) ); append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
b32 prefix_specs = false; b32 prefix_specs = false;
if ( ast->Specs ) if ( self->Specs )
{ {
for ( SpecifierT spec : ast->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ! ESpecifier::is_trailing( spec ) || ! (spec != ESpecifier::Pure) ) if ( ! ESpecifier::is_trailing( spec ) || ! (spec != ESpecifier::Pure) )
{ {
StrC spec_str = ESpecifier::to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
prefix_specs = true; prefix_specs = true;
} }
} }
} }
if ( ast->Attributes || prefix_specs ) if ( self->Attributes || prefix_specs )
{ {
append( & result, "\n" ); append( result, "\n" );
} }
if ( ast->ReturnType ) if ( self->ReturnType )
append_fmt( & result, "%S %S(", ast->ReturnType.to_string(), ast->Name ); append_fmt( result, "%S %S(", self->ReturnType.to_string(), self->Name );
else else
append_fmt( & result, "%S(", ast->Name ); append_fmt( result, "%S(", self->Name );
if ( ast->Params ) if ( self->Params )
append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) ); append_fmt( result, "%S)", GEN_NS to_string(self->Params) );
else else
append( & result, ")" ); append( result, ")" );
if ( ast->Specs ) if ( self->Specs )
{ {
for ( SpecifierT spec : ast->Specs ) for ( SpecifierT spec : self->Specs )
{ {
if ( ESpecifier::is_trailing( spec ) ) if ( ESpecifier::is_trailing( spec ) )
{ {
StrC spec_str = ESpecifier::to_str( spec ); StrC spec_str = ESpecifier::to_str( spec );
append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
} }
} }
} }
if ( ast->Specs && has(ast->Specs, ESpecifier::Pure ) >= 0 ) if ( self->Specs && has(self->Specs, ESpecifier::Pure ) >= 0 )
append( & result, " = 0;" ); append( result, " = 0;" );
else if (ast->Body) else if (self->Body)
append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) ); append_fmt( result, " = %S;", GEN_NS to_string(self->Body) );
if ( ast->InlineCmt ) if ( self->InlineCmt )
append_fmt( & result, "; %S", ast->InlineCmt->Content ); append_fmt( result, "; %S", self->InlineCmt->Content );
else else
append( & result, ";\n" ); append( result, ";\n" );
} }
String CodeModule::to_string() String CodeModule::to_string()

View File

@ -41,6 +41,38 @@ void to_string_fwd(CodeStruct self, String* result);
void to_string_def(CodeStruct self, String* result); void to_string_def(CodeStruct self, String* result);
String to_string(CodeAttributes attributes); String to_string(CodeAttributes attributes);
String to_string(CodeComment comment );
String to_string (CodeConstructor constructor);
void to_string_def(CodeConstructor constructor, String* result );
void to_string_fwd(CodeConstructor constructor, String* result );
String to_string(CodeDefine define);
void to_string(CodeDefine define, String* result);
String to_string (CodeDestructor destructor);
void to_string_def(CodeDestructor destructor, String* result );
void to_string_fwd(CodeDestructor destructor, String* result );
String to_string (CodeEnum self);
void to_string_def (CodeEnum self, String* result );
void to_string_fwd (CodeEnum self, String* result );
void to_string_class_def(CodeEnum self, String* result );
void to_string_class_fwd(CodeEnum self, String* result );
String to_string(CodeExec exec);
void to_string(CodeExtern self, String* result);
String to_string(CodeInclude include);
void to_string(CodeInclude include, String* result);
String to_string(CodeFriend self);
void to_string(CodeFriend self, String* result);
String to_string (CodeFn self);
void to_string_def(CodeFn self, String* result);
void to_string_fwd(CodeFn self, String* result);
#pragma region Code Types #pragma region Code Types
// These structs are not used at all by the C vairant. // These structs are not used at all by the C vairant.
@ -196,9 +228,9 @@ struct CodeAttributes
struct CodeComment struct CodeComment
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code(CodeComment); Using_Code(CodeComment);
String to_string(); String to_string() { return GEN_NS to_string(* this); }
#endif #endif
Using_CodeOps(CodeComment); Using_CodeOps(CodeComment);
@ -209,12 +241,12 @@ struct CodeComment
struct CodeConstructor struct CodeConstructor
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeConstructor ); Using_Code( CodeConstructor );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ); void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); }
void to_string_fwd( String& result ); void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); }
#endif #endif
Using_CodeOps(CodeConstructor); Using_CodeOps(CodeConstructor);
@ -225,11 +257,11 @@ struct CodeConstructor
struct CodeDefine struct CodeDefine
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeDefine ); Using_Code( CodeDefine );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps(CodeDefine); Using_CodeOps(CodeDefine);
@ -240,12 +272,12 @@ struct CodeDefine
struct CodeDestructor struct CodeDestructor
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeDestructor ); Using_Code( CodeDestructor );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ); void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); }
void to_string_fwd( String& result ); void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); }
#endif #endif
Using_CodeOps(CodeDestructor); Using_CodeOps(CodeDestructor);
@ -256,14 +288,14 @@ struct CodeDestructor
struct CodeEnum struct CodeEnum
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeEnum ); Using_Code( CodeEnum );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ); void to_string_def( String& result ) { return GEN_NS to_string_def(* this); }
void to_string_fwd( String& result ); void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); }
void to_string_class_def( String& result ); void to_string_class_def( String& result ) { return GEN_NS to_string_class_def(* this); }
void to_string_class_fwd( String& result ); void to_string_class_fwd( String& result ) { return GEN_NS to_string_class_fwd(* this); }
#endif #endif
Using_CodeOps(CodeEnum); Using_CodeOps(CodeEnum);
@ -274,9 +306,9 @@ struct CodeEnum
struct CodeExec struct CodeExec
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code(CodeExec); Using_Code(CodeExec);
String to_string(); String to_string() { return GEN_NS to_string(* this); }
#endif #endif
Using_CodeOps(CodeExec); Using_CodeOps(CodeExec);
@ -493,10 +525,10 @@ struct CodeExpr_UnaryPostfix
struct CodeExtern struct CodeExtern
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeExtern ); Using_Code( CodeExtern );
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps(CodeExtern); Using_CodeOps(CodeExtern);
@ -507,11 +539,11 @@ struct CodeExtern
struct CodeInclude struct CodeInclude
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeInclude ); Using_Code( CodeInclude );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps(CodeInclude); Using_CodeOps(CodeInclude);
@ -522,11 +554,11 @@ struct CodeInclude
struct CodeFriend struct CodeFriend
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeFriend ); Using_Code( CodeFriend );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ); void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
#endif #endif
Using_CodeOps(CodeFriend); Using_CodeOps(CodeFriend);
@ -537,12 +569,12 @@ struct CodeFriend
struct CodeFn struct CodeFn
{ {
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 #if GEN_SUPPORT_CPP_MEMBER_FEATURES
Using_Code( CodeFn ); Using_Code( CodeFn );
String to_string(); String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ); void to_string_def( String& result ) { return GEN_NS to_string_def(* this); }
void to_string_fwd( String& result ); void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); }
#endif #endif
Using_CodeOps(CodeFn); Using_CodeOps(CodeFn);
@ -933,19 +965,4 @@ void to_string_export( CodeBody body, String& result ) { return to_string_export
#endif //if ! GEN_COMPILER_C #endif //if ! GEN_COMPILER_C
inline
CodeParam begin(CodeParam params)
{
if ( params.ast )
return { params.ast };
return { nullptr };
}
inline
CodeParam end(CodeParam params)
{
// return { (AST_Param*) rcast( AST*, ast)->Last };
return { nullptr };
}
#pragma endregion Code Types #pragma endregion Code Types

View File

@ -264,6 +264,20 @@ CodeParam& CodeParam::operator ++()
ast = ast->Next.ast; ast = ast->Next.ast;
return * this; return * this;
} }
inline
CodeParam begin(CodeParam params)
{
if ( params.ast )
return { params.ast };
return { nullptr };
}
inline
CodeParam end(CodeParam params)
{
// return { (AST_Param*) rcast( AST*, ast)->Last };
return { nullptr };
}
#pragma endregion CodeParam #pragma endregion CodeParam
#pragma region CodeSpecifiers #pragma region CodeSpecifiers