Compare commits

..

No commits in common. "8f47f3b30fdf52ce04edbe9a8b66624b11723f27" and "16b8a3a164c6b6d83a4ec700a8cf2c627b5e69ad" have entirely different histories.

10 changed files with 663 additions and 576 deletions

View File

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

View File

@ -13,8 +13,9 @@ String to_string(Code self)
return to_string( self.ast );
}
String to_string(CodeAttributes attributes) {
return GEN_NS duplicate( attributes->Content, GlobalAllocator );
String CodeAttributes::to_string()
{
return GEN_NS duplicate( ast->Content, GlobalAllocator );
}
String to_string(CodeBody body)
@ -77,73 +78,73 @@ void to_string_export( CodeBody body, String* result )
append_fmt( result, "};\n" );
}
String to_string(CodeComment comment)
String CodeComment::to_string()
{
return GEN_NS duplicate( comment->Content, GlobalAllocator );
return GEN_NS duplicate( ast->Content, GlobalAllocator );
}
String to_string(CodeConstructor self)
String CodeConstructor::to_string()
{
String result = string_make( GlobalAllocator, "" );
switch (self->Type)
switch (ast->Type)
{
using namespace ECode;
case Constructor:
to_string_def( self, & result );
to_string_def( result );
break;
case Constructor_Fwd:
to_string_fwd( self, & result );
to_string_fwd( result );
break;
}
return result;
}
void to_string_def(CodeConstructor self, String* result )
void CodeConstructor::to_string_def( String& result )
{
AST* ClassStructParent = self->Parent->Parent;
AST* ClassStructParent = ast->Parent->Parent;
if (ClassStructParent) {
append( result, ClassStructParent->Name );
append( & result, ClassStructParent->Name );
}
else {
append( result, self->Name );
append( & result, ast->Name );
}
if ( self->Params )
append_fmt( result, "( %S )", GEN_NS to_string(self->Params) );
if ( ast->Params )
append_fmt( & result, "( %S )", ast->Params.to_string() );
else
append( result, "()" );
append( & result, "()" );
if ( self->InitializerList )
append_fmt( result, " : %S", GEN_NS to_string(self->InitializerList) );
if ( ast->InitializerList )
append_fmt( & result, " : %S", GEN_NS to_string(ast->InitializerList) );
if ( self->InlineCmt )
append_fmt( result, " // %S", self->InlineCmt->Content );
if ( ast->InlineCmt )
append_fmt( & result, " // %S", ast->InlineCmt->Content );
append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) );
}
void to_string_fwd(CodeConstructor self, String* result )
void CodeConstructor::to_string_fwd( String& result )
{
AST* ClassStructParent = self->Parent->Parent;
AST* ClassStructParent = ast->Parent->Parent;
if (ClassStructParent) {
append( result, ClassStructParent->Name );
append( & result, ClassStructParent->Name );
}
else {
append( result, self->Name );
append( & result, ast->Name );
}
if ( self->Params )
append_fmt( result, "( %S )", GEN_NS to_string(self->Params) );
if ( ast->Params )
append_fmt( & result, "( %S )", ast->Params.to_string() );
else
append_fmt( result, "()");
append_fmt( & result, "()");
if (self->Body)
append_fmt( result, " = %S", GEN_NS to_string(self->Body) );
if (ast->Body)
append_fmt( & result, " = %S", GEN_NS to_string(ast->Body) );
if ( self->InlineCmt )
append_fmt( result, "; // %S\n", self->InlineCmt->Content );
if ( ast->InlineCmt )
append_fmt( & result, "; // %S\n", ast->InlineCmt->Content );
else
append( result, ";\n" );
append( & result, ";\n" );
}
String to_string( CodeClass self )
@ -174,7 +175,7 @@ void to_string_def( CodeClass self, String* result )
if ( ast->Attributes )
{
append_fmt( result, "%S ", GEN_NS to_string(ast->Attributes) );
append_fmt( result, "%S ", ast->Attributes.to_string() );
}
if ( ast->ParentType )
@ -218,7 +219,7 @@ void to_string_fwd( CodeClass self, String* result )
append( result, "export " );
if ( ast->Attributes )
append_fmt( result, "class %S %S", to_string(ast->Attributes), ast->Name );
append_fmt( result, "class %S %S", ast->Attributes.to_string(), ast->Name );
else append_fmt( result, "class %S", ast->Name );
@ -232,379 +233,379 @@ void to_string_fwd( CodeClass self, String* result )
}
}
String to_string(CodeDefine define)
String CodeDefine::to_string()
{
return string_fmt_buf( GlobalAllocator, "#define %S %S\n", define->Name, define->Content );
return string_fmt_buf( GlobalAllocator, "#define %S %S\n", ast->Name, ast->Content );
}
void to_string(CodeDefine define, String* result )
void CodeDefine::to_string( String& result )
{
append_fmt( result, "#define %S %S\n", define->Name, define->Content );
append_fmt( & result, "#define %S %S\n", ast->Name, ast->Content );
}
String to_string(CodeDestructor self)
String CodeDestructor::to_string()
{
String result = string_make( GlobalAllocator, "" );
switch ( self->Type )
switch ( ast->Type )
{
using namespace ECode;
case Destructor:
to_string_def( self, & result );
to_string_def( result );
break;
case Destructor_Fwd:
to_string_fwd( self, & result );
to_string_fwd( result );
break;
}
return result;
}
void to_string_def(CodeDestructor self, String* result )
void CodeDestructor::to_string_def( String& result )
{
if ( self->Name )
if ( ast->Name )
{
append_fmt( result, "%S()", self->Name );
append_fmt( & result, "%S()", ast->Name );
}
else if ( self->Specs )
else if ( ast->Specs )
{
if ( has(self->Specs, ESpecifier::Virtual ) )
append_fmt( result, "virtual ~%S()", self->Parent->Name );
if ( ast->Specs.has( ESpecifier::Virtual ) )
append_fmt( & result, "virtual ~%S()", ast->Parent->Name );
else
append_fmt( result, "~%S()", self->Parent->Name );
append_fmt( & result, "~%S()", ast->Parent->Name );
}
else
append_fmt( result, "~%S()", self->Parent->Name );
append_fmt( & result, "~%S()", ast->Parent->Name );
append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) );
append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) );
}
void to_string_fwd(CodeDestructor self, String* result )
void CodeDestructor::to_string_fwd( String& result )
{
if ( self->Specs )
if ( ast->Specs )
{
if ( has(self->Specs, ESpecifier::Virtual ) )
append_fmt( result, "virtual ~%S();\n", self->Parent->Name );
if ( ast->Specs.has( ESpecifier::Virtual ) )
append_fmt( & result, "virtual ~%S();\n", ast->Parent->Name );
else
append_fmt( result, "~%S()", self->Parent->Name );
append_fmt( & result, "~%S()", ast->Parent->Name );
if ( has(self->Specs, ESpecifier::Pure ) )
append( result, " = 0;" );
else if (self->Body)
append_fmt( result, " = %S;", GEN_NS to_string(self->Body) );
if ( ast->Specs.has( ESpecifier::Pure ) )
append( & result, " = 0;" );
else if (ast->Body)
append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) );
}
else
append_fmt( result, "~%S();", self->Parent->Name );
append_fmt( & result, "~%S();", ast->Parent->Name );
if ( self->InlineCmt )
append_fmt( result, " %S", self->InlineCmt->Content );
if ( ast->InlineCmt )
append_fmt( & result, " %S", ast->InlineCmt->Content );
else
append( result, "\n");
append( & result, "\n");
}
String to_string(CodeEnum self)
String CodeEnum::to_string()
{
String result = string_make( GlobalAllocator, "" );
switch ( self->Type )
switch ( ast->Type )
{
using namespace ECode;
case Enum:
to_string_def(self, & result );
to_string_def( result );
break;
case Enum_Fwd:
to_string_fwd(self, & result );
to_string_fwd( result );
break;
case Enum_Class:
to_string_class_def(self, & result );
to_string_class_def( result );
break;
case Enum_Class_Fwd:
to_string_class_fwd(self, & result );
to_string_class_fwd( result );
break;
}
return result;
}
void to_string_def(CodeEnum self, String* result )
void CodeEnum::to_string_def( String& result )
{
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( result, "export " );
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " );
if ( self->Attributes || self->UnderlyingType )
if ( ast->Attributes || ast->UnderlyingType )
{
append( result, "enum " );
append( & result, "enum " );
if ( self->Attributes )
append_fmt( result, "%S ", GEN_NS to_string(self->Attributes) );
if ( ast->Attributes )
append_fmt( & result, "%S ", ast->Attributes.to_string() );
if ( self->UnderlyingType )
append_fmt( result, "%S : %S\n{\n%S\n}"
, self->Name
, self->UnderlyingType.to_string()
, GEN_NS to_string(self->Body)
if ( ast->UnderlyingType )
append_fmt( & result, "%S : %S\n{\n%S\n}"
, ast->Name
, ast->UnderlyingType.to_string()
, GEN_NS to_string(ast->Body)
);
else if ( self->UnderlyingTypeMacro )
append_fmt( result, "%S : %S\n{\n%S\n}"
, self->Name
, GEN_NS to_string(self->UnderlyingTypeMacro)
, GEN_NS to_string(self->Body)
else if ( ast->UnderlyingTypeMacro )
append_fmt( & result, "%S : %S\n{\n%S\n}"
, ast->Name
, GEN_NS to_string(ast->UnderlyingTypeMacro)
, 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, "%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) );
else append_fmt( & result, "enum %S\n{\n%S\n}", ast->Name, GEN_NS to_string(ast->Body) );
if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
append( result, ";\n");
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
append( & result, ";\n");
}
void to_string_fwd(CodeEnum self, String* result )
void CodeEnum::to_string_fwd( String& result )
{
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( result, "export " );
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " );
if ( self->Attributes )
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
if ( ast->Attributes )
append_fmt( & result, "%S ", ast->Attributes.to_string() );
if ( self->UnderlyingType )
append_fmt( result, "enum %S : %S", self->Name, self->UnderlyingType.to_string() );
if ( ast->UnderlyingType )
append_fmt( & result, "enum %S : %S", ast->Name, ast->UnderlyingType.to_string() );
else
append_fmt( result, "enum %S", self->Name );
append_fmt( & result, "enum %S", ast->Name );
if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
{
if ( self->InlineCmt )
append_fmt( result, "; %S", self->InlineCmt->Content );
if ( ast->InlineCmt )
append_fmt( & result, "; %S", ast->InlineCmt->Content );
else
append( result, ";\n");
append( & result, ";\n");
}
}
void to_string_class_def(CodeEnum self, String* result )
void CodeEnum::to_string_class_def( String& result )
{
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( result, "export " );
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " );
if ( self->Attributes || self->UnderlyingType )
if ( ast->Attributes || ast->UnderlyingType )
{
append( result, "enum class " );
append( & result, "enum class " );
if ( self->Attributes )
if ( ast->Attributes )
{
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
append_fmt( & result, "%S ", ast->Attributes.to_string() );
}
if ( self->UnderlyingType )
if ( ast->UnderlyingType )
{
append_fmt( result, "%S : %S\n{\n%S\n}", self->Name, self->UnderlyingType.to_string(), GEN_NS to_string(self->Body) );
append_fmt( & result, "%S : %S\n{\n%S\n}", ast->Name, ast->UnderlyingType.to_string(), GEN_NS to_string(ast->Body) );
}
else
{
append_fmt( result, "%S\n{\n%S\n}", self->Name, GEN_NS to_string(self->Body) );
append_fmt( & result, "%S\n{\n%S\n}", ast->Name, GEN_NS to_string(ast->Body) );
}
}
else
{
append_fmt( result, "enum class %S\n{\n%S\n}", GEN_NS to_string(self->Body) );
append_fmt( & result, "enum class %S\n{\n%S\n}", GEN_NS to_string(ast->Body) );
}
if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
append( result, ";\n");
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
append( & result, ";\n");
}
void to_string_class_fwd(CodeEnum self, String* result )
void CodeEnum::to_string_class_fwd( String& result )
{
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( result, "export " );
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " );
append( result, "enum class " );
append( & result, "enum class " );
if ( self->Attributes )
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
if ( ast->Attributes )
append_fmt( & result, "%S ", ast->Attributes.to_string() );
append_fmt( result, "%S : %S", self->Name, self->UnderlyingType.to_string() );
append_fmt( & result, "%S : %S", ast->Name, ast->UnderlyingType.to_string() );
if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) )
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
{
if ( self->InlineCmt )
append_fmt( result, "; %S", self->InlineCmt->Content );
if ( ast->InlineCmt )
append_fmt( & result, "; %S", ast->InlineCmt->Content );
else
append( result, ";\n");
append( & result, ";\n");
}
}
String to_string(CodeExec exec)
String CodeExec::to_string()
{
return GEN_NS duplicate( exec->Content, GlobalAllocator );
return GEN_NS duplicate( ast->Content, GlobalAllocator );
}
void to_string(CodeExtern self, String* result )
void CodeExtern::to_string( String& result )
{
if ( self->Body )
append_fmt( result, "extern \"%S\"\n{\n%S\n}\n", self->Name, GEN_NS to_string(self->Body) );
if ( ast->Body )
append_fmt( & result, "extern \"%S\"\n{\n%S\n}\n", ast->Name, GEN_NS to_string(ast->Body) );
else
append_fmt( result, "extern \"%S\"\n{}\n", self->Name );
append_fmt( & result, "extern \"%S\"\n{}\n", ast->Name );
}
String to_string(CodeInclude include)
String CodeInclude::to_string()
{
return string_fmt_buf( GlobalAllocator, "#include %S\n", include->Content );
return string_fmt_buf( GlobalAllocator, "#include %S\n", ast->Content );
}
void to_string( CodeInclude include, String* result )
void CodeInclude::to_string( String& result )
{
append_fmt( result, "#include %S\n", include->Content );
append_fmt( & result, "#include %S\n", ast->Content );
}
String to_string(CodeFriend self)
String CodeFriend::to_string()
{
String result = string_make( GlobalAllocator, "" );
to_string( self, & result );
to_string( result );
return result;
}
void to_string(CodeFriend self, String* result )
void CodeFriend::to_string( String& result )
{
append_fmt( result, "friend %S", GEN_NS to_string(self->Declaration) );
append_fmt( & result, "friend %S", GEN_NS to_string(ast->Declaration) );
if ( self->Declaration->Type != ECode::Function && (* result)[ length(* result) - 1 ] != ';' )
if ( ast->Declaration->Type != ECode::Function && result[ length(result) - 1 ] != ';' )
{
append( result, ";" );
append( & result, ";" );
}
if ( self->InlineCmt )
append_fmt( result, " %S", self->InlineCmt->Content );
if ( ast->InlineCmt )
append_fmt( & result, " %S", ast->InlineCmt->Content );
else
append( result, "\n");
append( & result, "\n");
}
String to_string(CodeFn self)
String CodeFn::to_string()
{
String result = string_make( GlobalAllocator, "" );
switch ( self->Type )
switch ( ast->Type )
{
using namespace ECode;
case Function:
to_string_def(self, & result );
to_string_def( result );
break;
case Function_Fwd:
to_string_fwd(self, & result );
to_string_fwd( result );
break;
}
return result;
}
void to_string_def(CodeFn self, String* result )
void CodeFn::to_string_def( String& result )
{
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( result, "export" );
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( & result, "export" );
if ( self->Attributes )
append_fmt( result, " %S ",GEN_NS to_string(self->Attributes) );
if ( ast->Attributes )
append_fmt( & result, " %S ", ast->Attributes.to_string() );
bool prefix_specs = false;
if ( self->Specs )
if ( ast->Specs )
{
for ( SpecifierT spec : self->Specs )
for ( SpecifierT spec : ast->Specs )
{
if ( ! ESpecifier::is_trailing( 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;
}
}
}
if ( self->Attributes || prefix_specs )
append( result, "\n" );
if ( ast->Attributes || prefix_specs )
append( & result, "\n" );
if ( self->ReturnType )
append_fmt( result, "%S %S(", self->ReturnType.to_string(), self->Name );
if ( ast->ReturnType )
append_fmt( & result, "%S %S(", ast->ReturnType.to_string(), ast->Name );
else
append_fmt( result, "%S(", self->Name );
append_fmt( & result, "%S(", ast->Name );
if ( self->Params )
append_fmt( result, "%S)", GEN_NS to_string(self->Params) );
if ( ast->Params )
append_fmt( & result, "%S)", ast->Params.to_string() );
else
append( result, ")" );
append( & result, ")" );
if ( self->Specs )
if ( ast->Specs )
{
for ( SpecifierT spec : self->Specs )
for ( SpecifierT spec : ast->Specs )
{
if ( ESpecifier::is_trailing( 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(self->Body) );
append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) );
}
void to_string_fwd(CodeFn self, String* result )
void CodeFn::to_string_fwd( String& result )
{
if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export ))
append( result, "export " );
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( & result, "export " );
if ( self->Attributes )
append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) );
if ( ast->Attributes )
append_fmt( & result, "%S ", ast->Attributes.to_string() );
b32 prefix_specs = false;
if ( self->Specs )
if ( ast->Specs )
{
for ( SpecifierT spec : self->Specs )
for ( SpecifierT spec : ast->Specs )
{
if ( ! ESpecifier::is_trailing( spec ) || ! (spec != ESpecifier::Pure) )
{
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;
}
}
}
if ( self->Attributes || prefix_specs )
if ( ast->Attributes || prefix_specs )
{
append( result, "\n" );
append( & result, "\n" );
}
if ( self->ReturnType )
append_fmt( result, "%S %S(", self->ReturnType.to_string(), self->Name );
if ( ast->ReturnType )
append_fmt( & result, "%S %S(", ast->ReturnType.to_string(), ast->Name );
else
append_fmt( result, "%S(", self->Name );
append_fmt( & result, "%S(", ast->Name );
if ( self->Params )
append_fmt( result, "%S)", GEN_NS to_string(self->Params) );
if ( ast->Params )
append_fmt( & result, "%S)", ast->Params.to_string() );
else
append( result, ")" );
append( & result, ")" );
if ( self->Specs )
if ( ast->Specs )
{
for ( SpecifierT spec : self->Specs )
for ( SpecifierT spec : ast->Specs )
{
if ( ESpecifier::is_trailing( spec ) )
{
StrC spec_str = ESpecifier::to_str( spec );
append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr );
}
}
}
if ( self->Specs && has(self->Specs, ESpecifier::Pure ) >= 0 )
append( result, " = 0;" );
else if (self->Body)
append_fmt( result, " = %S;", GEN_NS to_string(self->Body) );
if ( ast->Specs && ast->Specs.has( ESpecifier::Pure ) >= 0 )
append( & result, " = 0;" );
else if (ast->Body)
append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) );
if ( self->InlineCmt )
append_fmt( result, "; %S", self->InlineCmt->Content );
if ( ast->InlineCmt )
append_fmt( & result, "; %S", ast->InlineCmt->Content );
else
append( result, ";\n" );
append( & result, ";\n" );
}
String CodeModule::to_string()
@ -664,10 +665,10 @@ void CodeOperator::to_string_def( String& result )
append( & result, "export " );
if ( ast->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) );
append_fmt( & result, "%S ", ast->Attributes.to_string() );
if ( ast->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) );
append_fmt( & result, "%S ", ast->Attributes.to_string() );
if ( ast->Specs )
{
@ -690,7 +691,7 @@ void CodeOperator::to_string_def( String& result )
append_fmt( & result, "%S %S (", ast->ReturnType.to_string(), ast->Name );
if ( ast->Params )
append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) );
append_fmt( & result, "%S)", ast->Params.to_string() );
else
append( & result, ")" );
@ -718,7 +719,7 @@ void CodeOperator::to_string_fwd( String& result )
append( & result, "export " );
if ( ast->Attributes )
append_fmt( & result, "%S\n",GEN_NS to_string(ast->Attributes) );
append_fmt( & result, "%S\n", ast->Attributes.to_string() );
if ( ast->Specs )
{
@ -740,7 +741,7 @@ void CodeOperator::to_string_fwd( String& result )
append_fmt( & result, "%S %S (", ast->ReturnType.to_string(), ast->Name );
if ( ast->Params )
append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) );
append_fmt( & result, "%S)", ast->Params.to_string() );
else
append_fmt( & result, ")" );
@ -853,47 +854,46 @@ void CodeOpCast::to_string_fwd( String& result )
append_fmt( & result, "operator %S();\n", ast->ValueType.to_string() );
}
String to_string(CodeParam self)
String CodeParam::to_string()
{
String result = string_make( GlobalAllocator, "" );
to_string( self, & result );
to_string( result );
return result;
}
void to_string( CodeParam self, String* result )
void CodeParam::to_string( String& result )
{
AST_Param* ast = self.ast;
if ( ast->Macro )
{
// Related to parsing: ( <macro>, ... )
GEN_NS append( result, ast->Macro.ast->Content );
GEN_NS append( & result, ast->Macro.ast->Content );
// Could also be: ( <macro> <type <name>, ... )
}
if ( ast->Name )
{
if ( ast->ValueType.ast == nullptr )
append_fmt( result, " %S", ast->Name );
append_fmt( & result, " %S", ast->Name );
else
append_fmt( result, " %S %S", ast->ValueType.to_string(), ast->Name );
append_fmt( & result, " %S %S", ast->ValueType.to_string(), ast->Name );
}
else if ( ast->ValueType )
append_fmt( result, " %S", ast->ValueType.to_string() );
append_fmt( & result, " %S", ast->ValueType.to_string() );
if ( ast->PostNameMacro )
{
append_fmt( result, " %S", GEN_NS to_string(ast->PostNameMacro) );
append_fmt( & result, " %S", GEN_NS to_string(ast->PostNameMacro) );
}
if ( ast->Value )
append_fmt( result, " = %S", GEN_NS to_string(ast->Value) );
append_fmt( & result, " = %S", GEN_NS to_string(ast->Value) );
if ( ast->NumEntries - 1 > 0 )
{
for ( CodeParam param : ast->Next )
{
append_fmt( result, ", %S", to_string(param) );
append_fmt( & result, ", %S", param.to_string() );
}
}
}
@ -968,110 +968,101 @@ void CodePragma::to_string( String& result )
append_fmt( & result, "#pragma %S\n", ast->Content );
}
String to_string(CodeSpecifiers self)
String CodeSpecifiers::to_string()
{
String result = string_make( GlobalAllocator, "" );
to_string( self, & result );
to_string( result );
return result;
}
void to_string( CodeSpecifiers self, String* result )
void CodeSpecifiers::to_string( String& result )
{
GEN_ASSERT(self.ast != nullptr);
GEN_ASSERT(result != nullptr);
s32 idx = 0;
s32 left = self->NumEntries;
s32 left = ast->NumEntries;
while ( left-- )
{
StrC spec = ESpecifier::to_str( self->ArrSpecs[idx] );
append_fmt( result, "%.*s ", spec.Len, spec.Ptr );
StrC spec = ESpecifier::to_str( ast->ArrSpecs[idx] );
append_fmt( & result, "%.*s ", spec.Len, spec.Ptr );
idx++;
}
}
String to_string(CodeStruct self)
String CodeStruct::to_string()
{
GEN_ASSERT(self.ast != nullptr);
String result = string_make( GlobalAllocator, "" );
switch ( self->Type )
switch ( ast->Type )
{
using namespace ECode;
case Struct:
to_string_def( self, & result );
to_string_def( result );
break;
case Struct_Fwd:
to_string_fwd( self, & result );
to_string_fwd( result );
break;
}
return result;
}
void to_string_def( CodeStruct self, String* result )
void CodeStruct::to_string_def( String& result )
{
GEN_ASSERT(self.ast != nullptr);
AST_Struct* ast = self.ast;
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( result, "export " );
append( & result, "export " );
append( result, "struct " );
append( & result, "struct " );
if ( ast->Attributes )
{
append_fmt( result, "%S ",GEN_NS to_string(ast->Attributes) );
append_fmt( & result, "%S ", ast->Attributes.to_string() );
}
if ( ast->ParentType )
{
char const* access_level = to_str( ast->ParentAccess );
append_fmt( result, "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() );
append_fmt( & result, "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() );
CodeType interface = cast(CodeType, ast->ParentType->Next);
if ( interface )
append( result, "\n" );
append( & result, "\n" );
while ( interface )
{
append_fmt( result, ", %S", interface.to_string() );
append_fmt( & result, ", %S", interface.to_string() );
interface = interface->Next ? cast( CodeType, interface->Next) : CodeType { nullptr };
}
}
else if ( ast->Name )
{
append( result, ast->Name );
append( & result, ast->Name );
}
if ( ast->InlineCmt )
{
append_fmt( result, " // %S", ast->InlineCmt->Content );
append_fmt( & result, " // %S", ast->InlineCmt->Content );
}
append_fmt( result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
append_fmt( & result, "\n{\n%S\n}", GEN_NS to_string(ast->Body) );
if ( ast->Parent.ast == nullptr || ( ast->Parent->Type != ECode::Typedef && ast->Parent->Type != ECode::Variable ) )
append( result, ";\n");
append( & result, ";\n");
}
void to_string_fwd( CodeStruct self, String* result )
void CodeStruct::to_string_fwd( String& result )
{
GEN_ASSERT(self.ast != nullptr);
AST_Struct* ast = self.ast;
if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export ))
append( result, "export " );
append( & result, "export " );
if ( ast->Attributes )
append_fmt( result, "struct %S %S",GEN_NS to_string(ast->Attributes), ast->Name );
append_fmt( & result, "struct %S %S", ast->Attributes.to_string(), ast->Name );
else append_fmt( result, "struct %S", ast->Name );
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->InlineCmt )
append_fmt( result, "; %S", ast->InlineCmt->Content );
append_fmt( & result, "; %S", ast->InlineCmt->Content );
else
append( result, ";\n");
append( & result, ";\n");
}
}
@ -1148,7 +1139,7 @@ void CodeType::to_string( String& result )
if ( ast->ReturnType && ast->Params )
{
if ( ast->Attributes )
append_fmt( result, "%S ",GEN_NS to_string(ast->Attributes) );
append_fmt( result, "%S ", ast->Attributes.to_string() );
else
{
if ( ast->Specs )
@ -1163,13 +1154,13 @@ void CodeType::to_string( String& result )
if ( ast->ReturnType && ast->Params )
{
if ( ast->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) );
append_fmt( & result, "%S ", ast->Attributes.to_string() );
else
{
if ( ast->Specs )
append_fmt( & result, "%S %S ( %S ) %S", ast->ReturnType.to_string(), ast->Name, GEN_NS to_string(ast->Params), GEN_NS to_string(ast->Specs) );
append_fmt( & result, "%S %S ( %S ) %S", ast->ReturnType.to_string(), ast->Name, ast->Params.to_string(), ast->Specs.to_string() );
else
append_fmt( & result, "%S %S ( %S )", ast->ReturnType.to_string(), ast->Name, GEN_NS to_string(ast->Params) );
append_fmt( & result, "%S %S ( %S )", ast->ReturnType.to_string(), ast->Name, ast->Params.to_string() );
}
return;
@ -1177,10 +1168,10 @@ void CodeType::to_string( String& result )
#endif
if ( ast->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) );
append_fmt( & result, "%S ", ast->Attributes.to_string() );
if ( ast->Specs )
append_fmt( & result, "%S %S", ast->Name, GEN_NS to_string(ast->Specs) );
append_fmt( & result, "%S %S", ast->Name, ast->Specs.to_string() );
else
append_fmt( & result, "%S", ast->Name );
@ -1203,7 +1194,7 @@ void CodeUnion::to_string( String& result )
append( & result, "union " );
if ( ast->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) );
append_fmt( & result, "%S ", ast->Attributes.to_string() );
if ( ast->Name )
{
@ -1246,7 +1237,7 @@ void CodeUsing::to_string( String& result )
append( & result, "export " );
if ( ast->Attributes )
append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) );
append_fmt( & result, "%S ", ast->Attributes.to_string() );
if ( ast->UnderlyingType )
{
@ -1297,7 +1288,7 @@ void CodeVar::to_string( String& result )
// Its a comma-separated variable ( a NextVar )
if ( ast->Specs )
append_fmt( & result, "%S ", GEN_NS to_string(ast->Specs) );
append_fmt( & result, "%S ", ast->Specs.to_string() );
append( & result, ast->Name );
@ -1337,10 +1328,10 @@ void CodeVar::to_string( String& result )
if ( ast->Attributes || ast->Specs )
{
if ( ast->Attributes )
append_fmt( & result, "%S ", GEN_NS to_string(ast->Specs) );
append_fmt( & result, "%S ", ast->Specs.to_string() );
if ( ast->Specs )
append_fmt( & result, "%S\n", GEN_NS to_string(ast->Specs) );
append_fmt( & result, "%S\n", ast->Specs.to_string() );
append_fmt( & result, "%S %S", ast->ValueType.to_string(), ast->Name );

View File

@ -9,71 +9,11 @@ String to_string ( CodeBody body );
void to_string ( CodeBody body, String* result );
void to_string_export ( CodeBody body, String* result );
Code begin( CodeBody body);
Code end ( CodeBody body );
void add_interface( CodeClass self, CodeType interface );
String to_string ( CodeClass self );
void to_string_def( CodeClass self, String* result );
void to_string_fwd( CodeClass self, String* result );
void append (CodeParam params, CodeParam param );
CodeParam get (CodeParam params, s32 idx);
bool has_entries(CodeParam params );
String to_string (CodeParam params );
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 );
String to_string(CodeSpecifiers specifiers);
void to_string(CodeSpecifiers specifiers, String* result);
SpecifierT* begin(CodeSpecifiers specifiers );
SpecifierT* end (CodeSpecifiers specifiers);
void add_interface(CodeStruct self, CodeType interface);
String to_string (CodeStruct self);
void to_string_fwd(CodeStruct self, String* result);
void to_string_def(CodeStruct self, String* result);
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
// These structs are not used at all by the C vairant.
#if ! GEN_COMPILER_C
@ -91,21 +31,31 @@ struct CodeBody
String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ) { return GEN_NS to_string(* this, & result ); }
void to_string_export( String& result ) { return GEN_NS to_string_export(* this, & result); }
Code begin() { return GEN_NS begin(* this); }
Code end() { return GEN_NS end(* this); }
#endif
Using_CodeOps( CodeBody );
operator Code() { return * rcast( Code*, this ); }
AST_Body* operator->() { return ast; }
#pragma region Iterator
Code begin()
{
if ( ast )
return { rcast( AST*, ast)->Front };
return { nullptr };
}
Code end()
{
return { rcast(AST*, ast)->Back->Next };
}
#pragma endregion Iterator
AST_Body* ast;
};
struct CodeClass
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 0
Using_Code( CodeClass );
void add_interface( CodeType interface );
@ -131,7 +81,7 @@ struct CodeClass
struct CodeParam
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeParam );
void append( CodeParam other );
@ -142,6 +92,10 @@ struct CodeParam
#endif
Using_CodeOps( CodeParam );
AST* raw()
{
return rcast( AST*, ast );
}
AST_Param* operator->()
{
if ( ast == nullptr )
@ -151,27 +105,115 @@ struct CodeParam
}
return ast;
}
operator Code() { return { (AST*)ast }; }
CodeParam operator*() { return * this; }
operator Code()
{
return { (AST*)ast };
}
#pragma region Iterator
CodeParam begin()
{
if ( ast )
return { ast };
return { nullptr };
}
CodeParam end()
{
// return { (AST_Param*) rcast( AST*, ast)->Last };
return { nullptr };
}
CodeParam& operator++();
CodeParam operator*()
{
return * this;
}
#pragma endregion Iterator
AST_Param* ast;
};
struct CodeSpecifiers
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeSpecifiers );
bool append( SpecifierT spec ) { return GEN_NS append(* this, spec); }
s32 has( SpecifierT spec ) { return GEN_NS has(* this, spec); }
s32 remove( SpecifierT to_remove ) { return GEN_NS remove(* this, to_remove); }
String to_string() { return GEN_NS to_string(* this ); }
void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
bool append( SpecifierT spec )
{
if ( ast == nullptr )
{
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
return false;
}
if ( raw()->NumEntries == AST_ArrSpecs_Cap )
{
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST_ArrSpecs_Cap );
return false;
}
raw()->ArrSpecs[ raw()->NumEntries ] = spec;
raw()->NumEntries++;
return true;
}
s32 has( SpecifierT spec )
{
for ( s32 idx = 0; idx < raw()->NumEntries; idx++ )
{
if ( raw()->ArrSpecs[ idx ] == spec )
return idx;
}
return -1;
}
s32 remove( SpecifierT to_remove )
{
if ( ast == nullptr )
{
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
return -1;
}
if ( raw()->NumEntries == AST_ArrSpecs_Cap )
{
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST_ArrSpecs_Cap );
return -1;
}
s32 result = -1;
s32 curr = 0;
s32 next = 0;
for(; next < raw()->NumEntries; ++ curr, ++ next)
{
SpecifierT spec = raw()->ArrSpecs[next];
if (spec == to_remove)
{
result = next;
next ++;
if (next >= raw()->NumEntries)
break;
spec = raw()->ArrSpecs[next];
}
raw()->ArrSpecs[ curr ] = spec;
}
if (result > -1) {
raw()->NumEntries --;
}
return result;
}
String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeSpecifiers);
operator Code() { return { (AST*) ast }; }
AST* raw()
{
return rcast( AST*, ast );
}
AST_Specifiers* operator->()
{
if ( ast == nullptr )
@ -181,13 +223,30 @@ struct CodeSpecifiers
}
return ast;
}
operator Code()
{
return { (AST*) ast };
}
#pragma region Iterator
SpecifierT* begin()
{
if ( ast )
return & raw()->ArrSpecs[0];
return nullptr;
}
SpecifierT* end()
{
return raw()->ArrSpecs + raw()->NumEntries;
}
#pragma endregion Iterator
AST_Specifiers* ast;
};
struct CodeStruct
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeStruct );
void add_interface( CodeType interface );
@ -198,7 +257,14 @@ struct CodeStruct
#endif
Using_CodeOps( CodeStruct );
operator Code() { return * rcast( Code*, this ); }
AST* raw()
{
return rcast( AST*, ast );
}
operator Code()
{
return * rcast( Code*, this );
}
AST_Struct* operator->()
{
if ( ast == nullptr )
@ -213,12 +279,13 @@ struct CodeStruct
struct CodeAttributes
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code(CodeAttributes);
String to_string();
#endif
Using_CodeOps(CodeAttributes);
AST *raw();
operator Code();
AST_Attributes *operator->();
AST_Attributes *ast;
@ -228,12 +295,13 @@ struct CodeAttributes
struct CodeComment
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code(CodeComment);
String to_string() { return GEN_NS to_string(* this); }
String to_string();
#endif
Using_CodeOps(CodeComment);
AST *raw();
operator Code();
AST_Comment *operator->();
AST_Comment *ast;
@ -241,15 +309,16 @@ struct CodeComment
struct CodeConstructor
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeConstructor );
String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); }
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); }
String to_string();
void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
Using_CodeOps(CodeConstructor);
AST* raw();
operator Code();
AST_Constructor* operator->();
AST_Constructor* ast;
@ -257,14 +326,15 @@ struct CodeConstructor
struct CodeDefine
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeDefine );
String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeDefine);
AST* raw();
operator Code();
AST_Define* operator->();
AST_Define* ast;
@ -272,15 +342,16 @@ struct CodeDefine
struct CodeDestructor
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeDestructor );
String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); }
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); }
String to_string();
void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
Using_CodeOps(CodeDestructor);
AST* raw();
operator Code();
AST_Destructor* operator->();
AST_Destructor* ast;
@ -288,17 +359,18 @@ struct CodeDestructor
struct CodeEnum
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeEnum );
String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ) { return GEN_NS to_string_def(* this); }
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); }
void to_string_class_def( String& result ) { return GEN_NS to_string_class_def(* this); }
void to_string_class_fwd( String& result ) { return GEN_NS to_string_class_fwd(* this); }
String to_string();
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 );
#endif
Using_CodeOps(CodeEnum);
AST* raw();
operator Code();
AST_Enum* operator->();
AST_Enum* ast;
@ -306,12 +378,13 @@ struct CodeEnum
struct CodeExec
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code(CodeExec);
String to_string() { return GEN_NS to_string(* this); }
String to_string();
#endif
Using_CodeOps(CodeExec);
AST *raw();
operator Code();
AST_Exec *operator->();
AST_Exec *ast;
@ -525,13 +598,14 @@ struct CodeExpr_UnaryPostfix
struct CodeExtern
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeExtern );
void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
void to_string( String& result );
#endif
Using_CodeOps(CodeExtern);
AST* raw();
operator Code();
AST_Extern* operator->();
AST_Extern* ast;
@ -539,14 +613,15 @@ struct CodeExtern
struct CodeInclude
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeInclude );
String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeInclude);
AST* raw();
operator Code();
AST_Include* operator->();
AST_Include* ast;
@ -554,14 +629,15 @@ struct CodeInclude
struct CodeFriend
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeFriend );
String to_string() { return GEN_NS to_string(* this); }
void to_string( String& result ) { return GEN_NS to_string(* this, & result); }
String to_string();
void to_string( String& result );
#endif
Using_CodeOps(CodeFriend);
AST* raw();
operator Code();
AST_Friend* operator->();
AST_Friend* ast;
@ -569,15 +645,16 @@ struct CodeFriend
struct CodeFn
{
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
Using_Code( CodeFn );
String to_string() { return GEN_NS to_string(* this); }
void to_string_def( String& result ) { return GEN_NS to_string_def(* this); }
void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); }
String to_string();
void to_string_def( String& result );
void to_string_fwd( String& result );
#endif
Using_CodeOps(CodeFn);
AST* raw();
operator Code();
AST_Fn* operator->();
AST_Fn* ast;
@ -593,6 +670,7 @@ struct CodeModule
#endif
Using_CodeOps(CodeModule);
AST* raw();
operator Code();
AST_Module* operator->();
AST_Module* ast;
@ -608,6 +686,7 @@ struct CodeNS
#endif
Using_CodeOps(CodeNS);
AST* raw();
operator Code();
AST_NS* operator->();
AST_NS* ast;
@ -624,6 +703,7 @@ struct CodeOperator
#endif
Using_CodeOps(CodeOperator);
AST* raw();
operator Code();
AST_Operator* operator->();
AST_Operator* ast;
@ -640,6 +720,7 @@ struct CodeOpCast
#endif
Using_CodeOps(CodeOpCast);
AST* raw();
operator Code();
AST_OpCast* operator->();
AST_OpCast* ast;
@ -655,6 +736,7 @@ struct CodePragma
#endif
Using_CodeOps( CodePragma );
AST* raw();
operator Code();
AST_Pragma* operator->();
AST_Pragma* ast;
@ -675,6 +757,7 @@ struct CodePreprocessCond
#endif
Using_CodeOps( CodePreprocessCond );
AST* raw();
operator Code();
AST_PreprocessCond* operator->();
AST_PreprocessCond* ast;
@ -874,6 +957,7 @@ struct CodeTemplate
#endif
Using_CodeOps( CodeTemplate );
AST* raw();
operator Code();
AST_Template* operator->();
AST_Template* ast;
@ -889,6 +973,7 @@ struct CodeType
#endif
Using_CodeOps( CodeType );
AST* raw();
operator Code();
AST_Type* operator->();
AST_Type* ast;
@ -904,6 +989,7 @@ struct CodeTypedef
#endif
Using_CodeOps( CodeTypedef );
AST* raw();
operator Code();
AST_Typedef* operator->();
AST_Typedef* ast;
@ -919,6 +1005,7 @@ struct CodeUnion
#endif
Using_CodeOps(CodeUnion);
AST* raw();
operator Code();
AST_Union* operator->();
AST_Union* ast;
@ -935,6 +1022,7 @@ struct CodeUsing
#endif
Using_CodeOps(CodeUsing);
AST* raw();
operator Code();
AST_Using* operator->();
AST_Using* ast;
@ -950,6 +1038,7 @@ struct CodeVar
#endif
Using_CodeOps(CodeVar);
AST* raw();
operator Code();
AST_Var* operator->();
AST_Var* ast;
@ -964,5 +1053,4 @@ void to_string_export( CodeBody body, String& result ) { return to_string_export
#endif
#endif //if ! GEN_COMPILER_C
#pragma endregion Code Types

View File

@ -55,6 +55,11 @@ inline CodeAttributes::operator bool()
return ast != nullptr;
}
inline AST* CodeAttributes::raw()
{
return rcast( AST*, ast );
}
inline CodeAttributes::operator Code()
{
return *rcast( Code*, this );
@ -86,6 +91,11 @@ inline CodeComment::operator bool()
return ast != nullptr;
}
inline AST* CodeComment::raw()
{
return rcast( AST*, ast );
}
inline CodeComment::operator Code()
{
return *rcast( Code*, this );
@ -117,6 +127,11 @@ inline CodeConstructor::operator bool()
return ast != nullptr;
}
inline AST* CodeConstructor::raw()
{
return rcast( AST*, ast );
}
inline CodeConstructor::operator Code()
{
return *rcast( Code*, this );
@ -164,6 +179,11 @@ inline CodeDefine::operator bool()
return ast != nullptr;
}
inline AST* CodeDefine::raw()
{
return rcast( AST*, ast );
}
inline CodeDefine::operator Code()
{
return *rcast( Code*, this );
@ -195,6 +215,11 @@ inline CodeDestructor::operator bool()
return ast != nullptr;
}
inline AST* CodeDestructor::raw()
{
return rcast( AST*, ast );
}
inline CodeDestructor::operator Code()
{
return *rcast( Code*, this );
@ -226,6 +251,11 @@ inline CodeEnum::operator bool()
return ast != nullptr;
}
inline AST* CodeEnum::raw()
{
return rcast( AST*, ast );
}
inline CodeEnum::operator Code()
{
return *rcast( Code*, this );
@ -257,6 +287,11 @@ inline CodeExec::operator bool()
return ast != nullptr;
}
inline AST* CodeExec::raw()
{
return rcast( AST*, ast );
}
inline CodeExec::operator Code()
{
return *rcast( Code*, this );
@ -288,6 +323,11 @@ inline CodeExtern::operator bool()
return ast != nullptr;
}
inline AST* CodeExtern::raw()
{
return rcast( AST*, ast );
}
inline CodeExtern::operator Code()
{
return *rcast( Code*, this );
@ -319,6 +359,11 @@ inline CodeFriend::operator bool()
return ast != nullptr;
}
inline AST* CodeFriend::raw()
{
return rcast( AST*, ast );
}
inline CodeFriend::operator Code()
{
return *rcast( Code*, this );
@ -350,6 +395,11 @@ inline CodeFn::operator bool()
return ast != nullptr;
}
inline AST* CodeFn::raw()
{
return rcast( AST*, ast );
}
inline CodeFn::operator Code()
{
return *rcast( Code*, this );
@ -381,6 +431,11 @@ inline CodeInclude::operator bool()
return ast != nullptr;
}
inline AST* CodeInclude::raw()
{
return rcast( AST*, ast );
}
inline CodeInclude::operator Code()
{
return *rcast( Code*, this );
@ -412,6 +467,11 @@ inline CodeModule::operator bool()
return ast != nullptr;
}
inline AST* CodeModule::raw()
{
return rcast( AST*, ast );
}
inline CodeModule::operator Code()
{
return *rcast( Code*, this );
@ -443,6 +503,11 @@ inline CodeNS::operator bool()
return ast != nullptr;
}
inline AST* CodeNS::raw()
{
return rcast( AST*, ast );
}
inline CodeNS::operator Code()
{
return *rcast( Code*, this );
@ -474,6 +539,11 @@ inline CodeOperator::operator bool()
return ast != nullptr;
}
inline AST* CodeOperator::raw()
{
return rcast( AST*, ast );
}
inline CodeOperator::operator Code()
{
return *rcast( Code*, this );
@ -505,6 +575,11 @@ inline CodeOpCast::operator bool()
return ast != nullptr;
}
inline AST* CodeOpCast::raw()
{
return rcast( AST*, ast );
}
inline CodeOpCast::operator Code()
{
return *rcast( Code*, this );
@ -552,6 +627,11 @@ inline CodePragma::operator bool()
return ast != nullptr;
}
inline AST* CodePragma::raw()
{
return rcast( AST*, ast );
}
inline CodePragma::operator Code()
{
return *rcast( Code*, this );
@ -583,6 +663,11 @@ inline CodePreprocessCond::operator bool()
return ast != nullptr;
}
inline AST* CodePreprocessCond::raw()
{
return rcast( AST*, ast );
}
inline CodePreprocessCond::operator Code()
{
return *rcast( Code*, this );
@ -646,6 +731,11 @@ inline CodeTemplate::operator bool()
return ast != nullptr;
}
inline AST* CodeTemplate::raw()
{
return rcast( AST*, ast );
}
inline CodeTemplate::operator Code()
{
return *rcast( Code*, this );
@ -677,6 +767,11 @@ inline CodeType::operator bool()
return ast != nullptr;
}
inline AST* CodeType::raw()
{
return rcast( AST*, ast );
}
inline CodeType::operator Code()
{
return *rcast( Code*, this );
@ -708,6 +803,11 @@ inline CodeTypedef::operator bool()
return ast != nullptr;
}
inline AST* CodeTypedef::raw()
{
return rcast( AST*, ast );
}
inline CodeTypedef::operator Code()
{
return *rcast( Code*, this );
@ -739,6 +839,11 @@ inline CodeUnion::operator bool()
return ast != nullptr;
}
inline AST* CodeUnion::raw()
{
return rcast( AST*, ast );
}
inline CodeUnion::operator Code()
{
return *rcast( Code*, this );
@ -770,6 +875,11 @@ inline CodeUsing::operator bool()
return ast != nullptr;
}
inline AST* CodeUsing::raw()
{
return rcast( AST*, ast );
}
inline CodeUsing::operator Code()
{
return *rcast( Code*, this );
@ -801,6 +911,11 @@ inline CodeVar::operator bool()
return ast != nullptr;
}
inline AST* CodeVar::raw()
{
return rcast( AST*, ast );
}
inline CodeVar::operator Code()
{
return *rcast( Code*, this );

View File

@ -89,6 +89,7 @@ AST::operator Code()
}
#pragma region Code
inline
char const* debug_str( Code code )
{
@ -97,6 +98,7 @@ char const* debug_str( Code code )
return debug_str( code.ast );
}
inline
Code duplicate( Code code )
{
@ -108,6 +110,7 @@ Code duplicate( Code code )
return { duplicate(code.ast) };
}
inline
bool is_body(Code code)
{
@ -117,6 +120,7 @@ bool is_body(Code code)
}
return false;
}
inline
bool is_equal( Code self, Code other )
{
@ -128,11 +132,13 @@ bool is_equal( Code self, Code other )
}
return is_equal( self.ast, other.ast );
}
inline
bool is_valid(Code self)
{
return self.ast != nullptr && self.ast->Type != CodeT::Invalid;
}
inline
void set_global(Code self)
{
@ -144,6 +150,7 @@ void set_global(Code self)
self->Parent = Code_Global.ast;
}
inline
Code& Code::operator ++()
{
@ -152,9 +159,9 @@ Code& Code::operator ++()
return *this;
}
#pragma endregion Code
#pragma region CodeBody
inline
void append( CodeBody self, Code other )
{
@ -167,28 +174,15 @@ void append( CodeBody self, Code other )
append( rcast(AST*, self.ast), other.ast );
}
inline
void append( CodeBody self, CodeBody body )
{
GEN_ASSERT(self.ast != nullptr);
for ( Code entry : body ) {
append( self, entry );
}
}
inline
Code begin( CodeBody body) {
if ( body.ast )
return { rcast( AST*, body.ast)->Front };
return { nullptr };
}
inline
Code end(CodeBody body ){
return { rcast(AST*, body.ast)->Back->Next };
}
#pragma endregion CodeBody
#pragma region CodeClass
inline
void add_interface( CodeClass self, CodeType type )
{
@ -209,14 +203,11 @@ void add_interface( CodeClass self, CodeType type )
possible_slot.ast = type.ast;
}
#pragma endregion CodeClass
#pragma region CodeParam
inline
void append( CodeParam appendee, CodeParam other )
void CodeParam::append( CodeParam other )
{
GEN_ASSERT(appendee.ast != nullptr);
AST* self = cast(Code, appendee).ast;
AST* self = (AST*) ast;
AST* entry = (AST*) other.ast;
if ( entry->Parent )
@ -236,144 +227,44 @@ void append( CodeParam appendee, CodeParam other )
self->Last = entry;
self->NumEntries++;
}
inline
CodeParam get(CodeParam self, s32 idx )
CodeParam CodeParam::get( s32 idx )
{
GEN_ASSERT(self.ast != nullptr);
CodeParam param = * self;
CodeParam param = *this;
do
{
if ( ! ++ param )
return { nullptr };
param = { (AST_Param*) cast(Code, param)->Next };
param = { (AST_Param*) param.raw()->Next };
}
while ( --idx );
return param;
}
inline
bool has_entries(CodeParam self)
bool CodeParam::has_entries()
{
GEN_ASSERT(self.ast != nullptr);
return self->NumEntries > 0;
return ast->NumEntries > 0;
}
inline
CodeParam& CodeParam::operator ++()
{
ast = ast->Next.ast;
return * this;
}
inline
CodeParam begin(CodeParam params)
void CodeStruct::add_interface( CodeType type )
{
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 region CodeSpecifiers
inline
bool append(CodeSpecifiers self, SpecifierT spec )
{
if ( self.ast == nullptr )
{
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
return false;
}
if ( self->NumEntries == AST_ArrSpecs_Cap )
{
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST_ArrSpecs_Cap );
return false;
}
self->ArrSpecs[ self->NumEntries ] = spec;
self->NumEntries++;
return true;
}
inline
s32 has(CodeSpecifiers self, SpecifierT spec)
{
GEN_ASSERT(self.ast != nullptr);
for ( s32 idx = 0; idx < self->NumEntries; idx++ ) {
if ( self->ArrSpecs[ idx ] == spec )
return idx;
}
return -1;
}
inline
s32 remove( CodeSpecifiers self, SpecifierT to_remove )
{
AST_Specifiers* ast = self.ast;
if ( ast == nullptr )
{
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
return -1;
}
if ( self->NumEntries == AST_ArrSpecs_Cap )
{
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST_ArrSpecs_Cap );
return -1;
}
s32 result = -1;
s32 curr = 0;
s32 next = 0;
for(; next < self->NumEntries; ++ curr, ++ next)
{
SpecifierT spec = self->ArrSpecs[next];
if (spec == to_remove)
{
result = next;
next ++;
if (next >= self->NumEntries)
break;
spec = self->ArrSpecs[next];
}
self->ArrSpecs[ curr ] = spec;
}
if (result > -1) {
self->NumEntries --;
}
return result;
}
inline
SpecifierT* begin(CodeSpecifiers self)
{
if ( self.ast )
return & self->ArrSpecs[0];
return nullptr;
}
inline
SpecifierT* end(CodeSpecifiers self)
{
return self->ArrSpecs + self->NumEntries;
}
#pragma endregion CodeSpecifiers
#pragma region CodeStruct
inline
void add_interface(CodeStruct self, CodeType type )
{
CodeType possible_slot = self->ParentType;
CodeType possible_slot = ast->ParentType;
if ( possible_slot.ast )
{
// Were adding an interface to parent type, so we need to make sure the parent type is public.
self->ParentAccess = AccessSpec_Public;
ast->ParentAccess = AccessSpec_Public;
// If your planning on adding a proper parent,
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
}
@ -385,9 +276,7 @@ void add_interface(CodeStruct self, CodeType type )
possible_slot.ast = type.ast;
}
#pragma endregion Code
#pragma region Interface
inline
CodeBody def_body( CodeT type )
{
@ -430,4 +319,3 @@ StrC token_fmt_impl( ssize num, ... )
return { result, buf };
}
#pragma endregion Interface

View File

@ -180,7 +180,7 @@ void define_constants()
# define def_constant_spec( Type_, ... ) \
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
set_global(spec_##Type_);
spec_##Type_.set_global();
# pragma push_macro("forceinline")
# pragma push_macro("global")
@ -218,7 +218,7 @@ void define_constants()
def_constant_spec( volatile, ESpecifier::Volatile)
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
set_global(spec_local_persist);
spec_local_persist.set_global();
# pragma pop_macro("forceinline")
# pragma pop_macro("global")

View File

@ -31,7 +31,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
} \
if ( params_code->Type != ECode::Parameters ) \
{ \
log_failure("gen::def_operator: params is not of Parameters type - %s", debug_str(params_code)); \
log_failure("gen::def_operator: params is not of Parameters type - %s", params_code.debug_str()); \
return OpValidateResult::Fail; \
}
@ -42,7 +42,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
"param types: %s\n" \
"return type: %s", \
to_str(op).Ptr, \
debug_str(params_code), \
params_code.debug_str(), \
ret_type.debug_str() \
); \
return OpValidateResult::Fail; \
@ -73,7 +73,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
log_failure("gen::def_operator: "
"operator%s does not support non-member definition (more than one parameter provided) - %s",
to_str(op),
debug_str(params_code)
params_code.debug_str()
);
return OpValidateResult::Fail;
}
@ -104,7 +104,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
log_failure("gen::def_operator: operator%s may not be defined with more than two parametes - param count; %d\n%s"
, to_str(op)
, params_code->NumEntries
, debug_str(params_code)
, params_code.debug_str()
);
return OpValidateResult::Fail;
}
@ -119,7 +119,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
{
log_failure("gen::def_operator: operator%s params code provided is not of Parameters type - %s"
, to_str(op)
, debug_str(params_code)
, params_code.debug_str()
);
return OpValidateResult::Fail;
}
@ -137,7 +137,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
case 2:
check_param_eq_ret();
if ( ! is_equal(get(params_code, 1), t_int ) )
if ( ! params_code.get(1).is_equal( t_int ) )
{
log_failure("gen::def_operator: "
"operator%s requires second parameter of non-member definition to be int for post-decrement",
@ -166,7 +166,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
{
if ( params_code->Type != ECode::Parameters )
{
log_failure("gen::def_operator: params is not of Parameters type - %s", debug_str(params_code));
log_failure("gen::def_operator: params is not of Parameters type - %s", params_code.debug_str());
return OpValidateResult::Fail;
}
@ -176,7 +176,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
"operator%s is non-member symbol yet first paramter does not equal return type\n"
"param type: %s\n"
"return type: %s\n"
, debug_str(params_code)
, params_code.debug_str()
, ret_type.debug_str()
);
return OpValidateResult::Fail;
@ -199,7 +199,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
#if 0
if ( ! ret_type.is_equal( t_bool) )
{
log_failure( "gen::def_operator: return type is not a boolean - %s", debug_str(params_code) );
log_failure( "gen::def_operator: return type is not a boolean - %s", params_code.debug_str() );
return OpValidateResult::Fail;
}
#endif
@ -211,7 +211,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
{
if ( params_code->Type != ECode::Parameters )
{
log_failure( "gen::def_operator: params is not of Parameters type - %s", debug_str(params_code) );
log_failure( "gen::def_operator: params is not of Parameters type - %s", params_code.debug_str() );
return OpValidateResult::Fail;
}
@ -253,7 +253,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
"operator%s is non-member symbol yet first paramter does not equal return type\n"
"param type: %s\n"
"return type: %s\n"
, debug_str(params_code)
, params_code.debug_str()
, ret_type.debug_str()
);
return OpValidateResult::Fail;
@ -277,7 +277,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
{
if ( params_code->Type != ECode::Parameters )
{
log_failure("gen::def_operator: params is not of Parameters type - %s", debug_str(params_code));
log_failure("gen::def_operator: params is not of Parameters type - %s", params_code.debug_str());
return OpValidateResult::Fail;
}
@ -349,7 +349,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
case PtrToMemOfPtr:
if ( params_code )
{
log_failure("gen::def_operator: operator%s expects no paramters - %s", to_str(op), debug_str(params_code));
log_failure("gen::def_operator: operator%s expects no paramters - %s", to_str(op), params_code.debug_str());
return OpValidateResult::Fail;
}
break;
@ -501,7 +501,7 @@ CodeConstructor def_constructor( CodeParam params, Code initializer_list, Code b
if ( params && params->Type != Parameters )
{
log_failure("gen::def_constructor: params must be of Parameters type - %s", debug_str(params));
log_failure("gen::def_constructor: params must be of Parameters type - %s", params.debug_str());
return InvalidCode;
}
@ -555,7 +555,7 @@ CodeClass def_class( StrC name
if ( attributes && attributes->Type != PlatformAttributes )
{
log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", debug_str(attributes) );
log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", attributes.debug_str() );
return InvalidCode;
}
@ -647,7 +647,7 @@ CodeDestructor def_destructor( Code body, CodeSpecifiers specifiers )
if ( specifiers && specifiers->Type != Specifiers )
{
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", debug_str(specifiers) );
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", specifiers.debug_str() );
return InvalidCode;
}
@ -697,7 +697,7 @@ CodeEnum def_enum( StrC name
if ( attributes && attributes->Type != PlatformAttributes )
{
log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", debug_str(attributes) );
log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", attributes.debug_str() );
return InvalidCode;
}
@ -828,25 +828,25 @@ CodeFn def_function( StrC name
if ( params && params->Type != Parameters )
{
log_failure( "gen::def_function: params was not a `Parameters` type: %s", debug_str(params) );
log_failure( "gen::def_function: params was not a `Parameters` type: %s", params.debug_str() );
return InvalidCode;
}
if ( ret_type && ret_type->Type != Typename )
{
log_failure( "gen::def_function: ret_type was not a Typename: %s", debug_str(ret_type) );
log_failure( "gen::def_function: ret_type was not a Typename: %s", ret_type.debug_str() );
return InvalidCode;
}
if ( specifiers && specifiers->Type != Specifiers )
{
log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", debug_str(specifiers) );
log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", specifiers.debug_str() );
return InvalidCode;
}
if ( attributes && attributes->Type != PlatformAttributes )
{
log_failure( "gen::def_function: attributes was not a `PlatformAttributes` type: %s", debug_str(attributes) );
log_failure( "gen::def_function: attributes was not a `PlatformAttributes` type: %s", attributes.debug_str() );
return InvalidCode;
}
@ -967,13 +967,13 @@ CodeOperator def_operator( OperatorT op, StrC nspace
if ( attributes && attributes->Type != PlatformAttributes )
{
log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", debug_str(attributes) );
log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", attributes.debug_str() );
return InvalidCode;
}
if ( specifiers && specifiers->Type != Specifiers )
{
log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", debug_str(specifiers) );
log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", specifiers.debug_str() );
return InvalidCode;
}
@ -1167,7 +1167,7 @@ CodeSpecifiers def_specifier( SpecifierT spec )
CodeSpecifiers
result = (CodeSpecifiers) make_code();
result->Type = ECode::Specifiers;
append(result, spec );
result.append( spec );
return result;
}
@ -1183,7 +1183,7 @@ CodeStruct def_struct( StrC name
if ( attributes && attributes->Type != PlatformAttributes )
{
log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", debug_str(attributes) );
log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", attributes.debug_str() );
return InvalidCode;
}
@ -1229,7 +1229,7 @@ CodeStruct def_struct( StrC name
{
for (s32 idx = 0; idx < num_interfaces; idx++ )
{
add_interface(result, interfaces[idx] );
result.add_interface( interfaces[idx] );
}
}
@ -1242,7 +1242,7 @@ CodeTemplate def_template( CodeParam params, Code declaration, ModuleFlag mflags
if ( params && params->Type != ECode::Parameters )
{
log_failure( "gen::def_template: params is not of parameters type - %s", debug_str(params) );
log_failure( "gen::def_template: params is not of parameters type - %s", params.debug_str() );
return InvalidCode;
}
@ -1387,7 +1387,7 @@ CodeUnion def_union( StrC name, Code body, CodeAttributes attributes, ModuleFlag
if ( attributes && attributes->Type != ECode::PlatformAttributes )
{
log_failure( "gen::def_union: attributes was not a PlatformAttributes type - %s", debug_str(attributes) );
log_failure( "gen::def_union: attributes was not a PlatformAttributes type - %s", attributes.debug_str() );
return InvalidCode;
}
@ -1424,7 +1424,7 @@ CodeUsing def_using( StrC name, CodeType type
if ( attributes && attributes->Type != ECode::PlatformAttributes )
{
log_failure( "gen::def_using: attributes was not a PlatformAttributes type - %s", debug_str(attributes) );
log_failure( "gen::def_using: attributes was not a PlatformAttributes type - %s", attributes.debug_str() );
return InvalidCode;
}
@ -1464,13 +1464,13 @@ CodeVar def_variable( CodeType type, StrC name, Code value
if ( attributes && attributes->Type != ECode::PlatformAttributes )
{
log_failure( "gen::def_variable: attributes was not a `PlatformAttributes` type - %s", debug_str(attributes) );
log_failure( "gen::def_variable: attributes was not a `PlatformAttributes` type - %s", attributes.debug_str() );
return InvalidCode;
}
if ( specifiers && specifiers->Type != ECode::Specifiers )
{
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type - %s", debug_str(specifiers) );
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type - %s", specifiers.debug_str() );
return InvalidCode;
}
@ -2077,7 +2077,7 @@ CodeParam def_params( s32 num, ... )
return InvalidCode;
}
CodeParam result = (CodeParam) duplicate(param);
CodeParam result = (CodeParam) param.duplicate();
while ( -- num )
{
@ -2090,7 +2090,7 @@ CodeParam def_params( s32 num, ... )
return InvalidCode;
}
append(result, param );
result.append( param );
}
va_end(va);
@ -2110,11 +2110,11 @@ CodeParam def_params( s32 num, CodeParam* codes )
\
if (current->Type != Parameters ) \
{ \
log_failure("gen::def_params: Code in coes array is not of paramter type - %s", debug_str(current) ); \
log_failure("gen::def_params: Code in coes array is not of paramter type - %s", current.debug_str() ); \
return InvalidCode; \
}
CodeParam current = (CodeParam)duplicate(* codes);
CodeParam current = (CodeParam) codes->duplicate();
check_current();
CodeParam
@ -2126,7 +2126,7 @@ CodeParam def_params( s32 num, CodeParam* codes )
while( codes++, current = * codes, num--, num > 0 )
{
check_current();
append(result, current );
result.append( current );
}
# undef check_current
@ -2157,7 +2157,7 @@ CodeSpecifiers def_specifiers( s32 num, ... )
{
SpecifierT type = (SpecifierT)va_arg(va, int);
append(result, type );
result.append( type );
}
while ( --num, num );
va_end(va);
@ -2186,7 +2186,7 @@ CodeSpecifiers def_specifiers( s32 num, SpecifierT* specs )
s32 idx = 0;
do
{
append(result, specs[idx] );
result.append( specs[idx] );
idx++;
}
while ( --num, num );

View File

@ -1440,7 +1440,7 @@ CodeFn parse_function_after_name(
continue;
}
append(specifiers, ESpecifier::to_type(currtok) );
specifiers.append( ESpecifier::to_type(currtok) );
eat( currtok.Type );
}
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers>
@ -1460,7 +1460,7 @@ CodeFn parse_function_after_name(
else if ( check(TokType::Operator) && currtok.Text[0] == '=' )
{
eat(TokType::Operator);
append(specifiers, ESpecifier::Pure );
specifiers.append( ESpecifier::Pure );
eat( TokType::Number);
Token stmt_end = currtok;
@ -2443,7 +2443,7 @@ CodeOperator parse_operator_after_ret_type(
continue;
}
append(specifiers, ESpecifier::to_type(currtok) );
specifiers.append( ESpecifier::to_type(currtok) );
eat( currtok.Type );
}
// <ExportFlag> <Attributes> <Specifiers> <ReturnType> <Qualifier::...> operator <Op> ( <Parameters> ) <Specifiers>
@ -2760,7 +2760,7 @@ CodeParam parse_params( bool use_template_capture )
if ( check( TokType::Varadic_Argument ) )
{
eat( TokType::Varadic_Argument );
append(result, param_varadic );
result.append( param_varadic );
continue;
// ( <Macro> <ValueType> <Name> = <Expression>, ...
}
@ -2864,7 +2864,7 @@ CodeParam parse_params( bool use_template_capture )
if ( value )
param->Value = value;
append(result, param );
result.append( param );
}
if ( ! use_template_capture )
@ -3288,7 +3288,7 @@ CodeVar parse_variable_declaration_list()
"(Parser will add and continue to specifiers, but will most likely fail to compile)\n%s"
, Context.to_string() );
append(specifiers, spec );
specifiers.append( spec );
}
break;
@ -3310,7 +3310,7 @@ CodeVar parse_variable_declaration_list()
// eat(currtok.Type);
if ( specifiers )
append(specifiers, spec );
specifiers.append( spec );
else
specifiers = def_specifier( spec );
}
@ -3450,7 +3450,7 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
if ( check( TokType::Spec_Virtual ) )
{
if ( specifiers )
append(specifiers, ESpecifier::Virtual );
specifiers.append( ESpecifier::Virtual );
else
specifiers = def_specifier( ESpecifier::Virtual );
eat( TokType::Spec_Virtual );
@ -3493,7 +3493,7 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
eat( TokType::Number );
// <Virtual Specifier> ~<Name>() = 0
append(specifiers, ESpecifier::Pure );
specifiers.append( ESpecifier::Pure );
}
else if ( left && str_compare( next.Text, "default", sizeof("default") - 1 ) == 0)
{
@ -4148,7 +4148,7 @@ CodeOpCast parse_operator_cast( CodeSpecifiers specifiers )
specifiers = def_specifier( ESpecifier::Const );
else
append(specifiers, ESpecifier::Const );
specifiers.append( ESpecifier::Const );
eat( TokType::Spec_Const );
}

View File

@ -185,9 +185,9 @@ void clear(String& str);
void free(String& str);
#endif
inline char* begin(String str) { return str; }
inline char* end(String str) { return scast(char*, str) + length(str); }
inline char* next(String str) { return scast(char*, str) + 1; }
inline char* begin(String& str) { return str; }
inline char* end(String& str) { return scast(char*, str) + length(str); }
inline char* next(String& str) { return scast(char*, str) + 1; }
inline
usize string_grow_formula(usize value) {

View File

@ -373,6 +373,11 @@ CodeBody gen_ast_inlines()
);
char const* codetype_impl_tmpl = stringize(
inline
AST* Code<typename>::raw()
{
return rcast( AST*, ast );
}
inline
Code<typename>::operator Code()
{