mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08:00
Progress on member proc usage reduction (CodeParam, CodeSpecifiers)
This commit is contained in:
parent
16b8a3a164
commit
ea18792373
@ -501,7 +501,7 @@ void to_string( AST* self, String* result )
|
||||
break;
|
||||
|
||||
case Parameters:
|
||||
cast(CodeParam, {self}).to_string( * result );
|
||||
to_string(cast(CodeParam, {self}), result );
|
||||
break;
|
||||
|
||||
case Preprocess_Define:
|
||||
@ -541,7 +541,7 @@ void to_string( AST* self, String* result )
|
||||
break;
|
||||
|
||||
case Specifiers:
|
||||
cast(CodeSpecifiers, {self}).to_string( * result );
|
||||
to_string(cast(CodeSpecifiers, {self}), result );
|
||||
break;
|
||||
|
||||
case Struct:
|
||||
|
@ -110,7 +110,7 @@ void CodeConstructor::to_string_def( String& result )
|
||||
}
|
||||
|
||||
if ( ast->Params )
|
||||
append_fmt( & result, "( %S )", ast->Params.to_string() );
|
||||
append_fmt( & result, "( %S )", GEN_NS to_string(ast->Params) );
|
||||
else
|
||||
append( & result, "()" );
|
||||
|
||||
@ -134,7 +134,7 @@ void CodeConstructor::to_string_fwd( String& result )
|
||||
}
|
||||
|
||||
if ( ast->Params )
|
||||
append_fmt( & result, "( %S )", ast->Params.to_string() );
|
||||
append_fmt( & result, "( %S )", GEN_NS to_string(ast->Params) );
|
||||
else
|
||||
append_fmt( & result, "()");
|
||||
|
||||
@ -267,7 +267,7 @@ void CodeDestructor::to_string_def( String& result )
|
||||
}
|
||||
else if ( ast->Specs )
|
||||
{
|
||||
if ( ast->Specs.has( ESpecifier::Virtual ) )
|
||||
if ( has(ast->Specs, ESpecifier::Virtual ) )
|
||||
append_fmt( & result, "virtual ~%S()", ast->Parent->Name );
|
||||
else
|
||||
append_fmt( & result, "~%S()", ast->Parent->Name );
|
||||
@ -282,12 +282,12 @@ void CodeDestructor::to_string_fwd( String& result )
|
||||
{
|
||||
if ( ast->Specs )
|
||||
{
|
||||
if ( ast->Specs.has( ESpecifier::Virtual ) )
|
||||
if ( has(ast->Specs, ESpecifier::Virtual ) )
|
||||
append_fmt( & result, "virtual ~%S();\n", ast->Parent->Name );
|
||||
else
|
||||
append_fmt( & result, "~%S()", ast->Parent->Name );
|
||||
|
||||
if ( ast->Specs.has( ESpecifier::Pure ) )
|
||||
if ( has(ast->Specs, ESpecifier::Pure ) )
|
||||
append( & result, " = 0;" );
|
||||
else if (ast->Body)
|
||||
append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) );
|
||||
@ -525,7 +525,7 @@ void CodeFn::to_string_def( String& result )
|
||||
append_fmt( & result, "%S(", ast->Name );
|
||||
|
||||
if ( ast->Params )
|
||||
append_fmt( & result, "%S)", ast->Params.to_string() );
|
||||
append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) );
|
||||
|
||||
else
|
||||
append( & result, ")" );
|
||||
@ -580,7 +580,7 @@ void CodeFn::to_string_fwd( String& result )
|
||||
append_fmt( & result, "%S(", ast->Name );
|
||||
|
||||
if ( ast->Params )
|
||||
append_fmt( & result, "%S)", ast->Params.to_string() );
|
||||
append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) );
|
||||
|
||||
else
|
||||
append( & result, ")" );
|
||||
@ -597,7 +597,7 @@ void CodeFn::to_string_fwd( String& result )
|
||||
}
|
||||
}
|
||||
|
||||
if ( ast->Specs && ast->Specs.has( ESpecifier::Pure ) >= 0 )
|
||||
if ( ast->Specs && has(ast->Specs, ESpecifier::Pure ) >= 0 )
|
||||
append( & result, " = 0;" );
|
||||
else if (ast->Body)
|
||||
append_fmt( & result, " = %S;", GEN_NS to_string(ast->Body) );
|
||||
@ -691,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)", ast->Params.to_string() );
|
||||
append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) );
|
||||
|
||||
else
|
||||
append( & result, ")" );
|
||||
@ -741,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)", ast->Params.to_string() );
|
||||
append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) );
|
||||
|
||||
else
|
||||
append_fmt( & result, ")" );
|
||||
@ -854,46 +854,47 @@ void CodeOpCast::to_string_fwd( String& result )
|
||||
append_fmt( & result, "operator %S();\n", ast->ValueType.to_string() );
|
||||
}
|
||||
|
||||
String CodeParam::to_string()
|
||||
String to_string(CodeParam self)
|
||||
{
|
||||
String result = string_make( GlobalAllocator, "" );
|
||||
to_string( result );
|
||||
to_string( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void CodeParam::to_string( String& result )
|
||||
void to_string( CodeParam self, 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", param.to_string() );
|
||||
append_fmt( result, ", %S", to_string(param) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -968,21 +969,23 @@ void CodePragma::to_string( String& result )
|
||||
append_fmt( & result, "#pragma %S\n", ast->Content );
|
||||
}
|
||||
|
||||
String CodeSpecifiers::to_string()
|
||||
String to_string(CodeSpecifiers self)
|
||||
{
|
||||
String result = string_make( GlobalAllocator, "" );
|
||||
to_string( result );
|
||||
to_string( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void CodeSpecifiers::to_string( String& result )
|
||||
void to_string( CodeSpecifiers self, String* result )
|
||||
{
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
GEN_ASSERT(result != nullptr);
|
||||
s32 idx = 0;
|
||||
s32 left = ast->NumEntries;
|
||||
s32 left = self->NumEntries;
|
||||
while ( left-- )
|
||||
{
|
||||
StrC spec = ESpecifier::to_str( ast->ArrSpecs[idx] );
|
||||
append_fmt( & result, "%.*s ", spec.Len, spec.Ptr );
|
||||
StrC spec = ESpecifier::to_str( self->ArrSpecs[idx] );
|
||||
append_fmt( result, "%.*s ", spec.Len, spec.Ptr );
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
@ -1158,9 +1161,9 @@ void CodeType::to_string( String& result )
|
||||
else
|
||||
{
|
||||
if ( ast->Specs )
|
||||
append_fmt( & result, "%S %S ( %S ) %S", ast->ReturnType.to_string(), ast->Name, ast->Params.to_string(), ast->Specs.to_string() );
|
||||
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) );
|
||||
else
|
||||
append_fmt( & result, "%S %S ( %S )", ast->ReturnType.to_string(), ast->Name, ast->Params.to_string() );
|
||||
append_fmt( & result, "%S %S ( %S )", ast->ReturnType.to_string(), ast->Name, GEN_NS to_string(ast->Params) );
|
||||
}
|
||||
|
||||
return;
|
||||
@ -1171,7 +1174,7 @@ void CodeType::to_string( String& result )
|
||||
append_fmt( & result, "%S ", ast->Attributes.to_string() );
|
||||
|
||||
if ( ast->Specs )
|
||||
append_fmt( & result, "%S %S", ast->Name, ast->Specs.to_string() );
|
||||
append_fmt( & result, "%S %S", ast->Name, GEN_NS to_string(ast->Specs) );
|
||||
else
|
||||
append_fmt( & result, "%S", ast->Name );
|
||||
|
||||
@ -1288,7 +1291,7 @@ void CodeVar::to_string( String& result )
|
||||
// Its a comma-separated variable ( a NextVar )
|
||||
|
||||
if ( ast->Specs )
|
||||
append_fmt( & result, "%S ", ast->Specs.to_string() );
|
||||
append_fmt( & result, "%S ", GEN_NS to_string(ast->Specs) );
|
||||
|
||||
append( & result, ast->Name );
|
||||
|
||||
@ -1328,10 +1331,10 @@ void CodeVar::to_string( String& result )
|
||||
if ( ast->Attributes || ast->Specs )
|
||||
{
|
||||
if ( ast->Attributes )
|
||||
append_fmt( & result, "%S ", ast->Specs.to_string() );
|
||||
append_fmt( & result, "%S ", GEN_NS to_string(ast->Specs) );
|
||||
|
||||
if ( ast->Specs )
|
||||
append_fmt( & result, "%S\n", ast->Specs.to_string() );
|
||||
append_fmt( & result, "%S\n", GEN_NS to_string(ast->Specs) );
|
||||
|
||||
append_fmt( & result, "%S %S", ast->ValueType.to_string(), ast->Name );
|
||||
|
||||
|
@ -9,11 +9,32 @@ 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);
|
||||
|
||||
#pragma region Code Types
|
||||
// These structs are not used at all by the C vairant.
|
||||
#if ! GEN_COMPILER_C
|
||||
@ -31,31 +52,21 @@ 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 || 0
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
Using_Code( CodeClass );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
@ -81,7 +92,7 @@ struct CodeClass
|
||||
|
||||
struct CodeParam
|
||||
{
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
Using_Code( CodeParam );
|
||||
|
||||
void append( CodeParam other );
|
||||
@ -92,10 +103,6 @@ struct CodeParam
|
||||
#endif
|
||||
|
||||
Using_CodeOps( CodeParam );
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Param* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
@ -105,115 +112,27 @@ struct CodeParam
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
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 };
|
||||
}
|
||||
operator Code() { return { (AST*)ast }; }
|
||||
CodeParam operator*() { return * this; }
|
||||
CodeParam& operator++();
|
||||
CodeParam operator*()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Param* ast;
|
||||
};
|
||||
|
||||
struct CodeSpecifiers
|
||||
{
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
Using_Code( CodeSpecifiers );
|
||||
|
||||
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 );
|
||||
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); }
|
||||
#endif
|
||||
|
||||
Using_CodeOps(CodeSpecifiers);
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code() { return { (AST*) ast }; }
|
||||
AST_Specifiers* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
@ -223,23 +142,6 @@ 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;
|
||||
};
|
||||
@ -1053,4 +955,20 @@ void to_string_export( CodeBody body, String& result ) { return to_string_export
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
@ -89,7 +89,6 @@ AST::operator Code()
|
||||
}
|
||||
|
||||
#pragma region Code
|
||||
|
||||
inline
|
||||
char const* debug_str( Code code )
|
||||
{
|
||||
@ -98,7 +97,6 @@ char const* debug_str( Code code )
|
||||
|
||||
return debug_str( code.ast );
|
||||
}
|
||||
|
||||
inline
|
||||
Code duplicate( Code code )
|
||||
{
|
||||
@ -110,7 +108,6 @@ Code duplicate( Code code )
|
||||
|
||||
return { duplicate(code.ast) };
|
||||
}
|
||||
|
||||
inline
|
||||
bool is_body(Code code)
|
||||
{
|
||||
@ -120,7 +117,6 @@ bool is_body(Code code)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
bool is_equal( Code self, Code other )
|
||||
{
|
||||
@ -132,13 +128,11 @@ 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)
|
||||
{
|
||||
@ -150,7 +144,6 @@ void set_global(Code self)
|
||||
|
||||
self->Parent = Code_Global.ast;
|
||||
}
|
||||
|
||||
inline
|
||||
Code& Code::operator ++()
|
||||
{
|
||||
@ -159,9 +152,9 @@ Code& Code::operator ++()
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#pragma endregion Code
|
||||
|
||||
#pragma region CodeBody
|
||||
inline
|
||||
void append( CodeBody self, Code other )
|
||||
{
|
||||
@ -174,15 +167,28 @@ 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 )
|
||||
{
|
||||
@ -203,11 +209,14 @@ void add_interface( CodeClass self, CodeType type )
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
#pragma endregion CodeClass
|
||||
|
||||
#pragma region CodeParam
|
||||
inline
|
||||
void CodeParam::append( CodeParam other )
|
||||
void append( CodeParam appendee, CodeParam other )
|
||||
{
|
||||
AST* self = (AST*) ast;
|
||||
GEN_ASSERT(appendee.ast != nullptr);
|
||||
AST* self = cast(Code, appendee).ast;
|
||||
AST* entry = (AST*) other.ast;
|
||||
|
||||
if ( entry->Parent )
|
||||
@ -227,36 +236,122 @@ void CodeParam::append( CodeParam other )
|
||||
self->Last = entry;
|
||||
self->NumEntries++;
|
||||
}
|
||||
|
||||
inline
|
||||
CodeParam CodeParam::get( s32 idx )
|
||||
CodeParam get(CodeParam self, s32 idx )
|
||||
{
|
||||
CodeParam param = *this;
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
CodeParam param = * self;
|
||||
do
|
||||
{
|
||||
if ( ! ++ param )
|
||||
return { nullptr };
|
||||
|
||||
param = { (AST_Param*) param.raw()->Next };
|
||||
param = { (AST_Param*) cast(Code, param)->Next };
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
inline
|
||||
bool CodeParam::has_entries()
|
||||
bool has_entries(CodeParam self)
|
||||
{
|
||||
return ast->NumEntries > 0;
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
return self->NumEntries > 0;
|
||||
}
|
||||
|
||||
inline
|
||||
CodeParam& CodeParam::operator ++()
|
||||
{
|
||||
ast = ast->Next.ast;
|
||||
return * this;
|
||||
}
|
||||
#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 CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
@ -276,7 +371,9 @@ void CodeStruct::add_interface( CodeType type )
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
#pragma endregion Code
|
||||
|
||||
#pragma region Interface
|
||||
inline
|
||||
CodeBody def_body( CodeT type )
|
||||
{
|
||||
@ -319,3 +416,4 @@ StrC token_fmt_impl( ssize num, ... )
|
||||
|
||||
return { result, buf };
|
||||
}
|
||||
#pragma endregion Interface
|
||||
|
@ -180,7 +180,7 @@ void define_constants()
|
||||
|
||||
# define def_constant_spec( Type_, ... ) \
|
||||
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
|
||||
spec_##Type_.set_global();
|
||||
set_global(spec_##Type_);
|
||||
|
||||
# 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 );
|
||||
spec_local_persist.set_global();
|
||||
set_global(spec_local_persist);
|
||||
|
||||
# pragma pop_macro("forceinline")
|
||||
# pragma pop_macro("global")
|
||||
|
@ -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", params_code.debug_str()); \
|
||||
log_failure("gen::def_operator: params is not of Parameters type - %s", debug_str(params_code)); \
|
||||
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, \
|
||||
params_code.debug_str(), \
|
||||
debug_str(params_code), \
|
||||
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),
|
||||
params_code.debug_str()
|
||||
debug_str(params_code)
|
||||
);
|
||||
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
|
||||
, params_code.debug_str()
|
||||
, debug_str(params_code)
|
||||
);
|
||||
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)
|
||||
, params_code.debug_str()
|
||||
, debug_str(params_code)
|
||||
);
|
||||
return OpValidateResult::Fail;
|
||||
}
|
||||
@ -137,7 +137,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
||||
case 2:
|
||||
check_param_eq_ret();
|
||||
|
||||
if ( ! params_code.get(1).is_equal( t_int ) )
|
||||
if ( ! is_equal(get(params_code, 1), 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", params_code.debug_str());
|
||||
log_failure("gen::def_operator: params is not of Parameters type - %s", debug_str(params_code));
|
||||
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"
|
||||
, params_code.debug_str()
|
||||
, debug_str(params_code)
|
||||
, 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", params_code.debug_str() );
|
||||
log_failure( "gen::def_operator: return type is not a boolean - %s", debug_str(params_code) );
|
||||
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", params_code.debug_str() );
|
||||
log_failure( "gen::def_operator: params is not of Parameters type - %s", debug_str(params_code) );
|
||||
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"
|
||||
, params_code.debug_str()
|
||||
, debug_str(params_code)
|
||||
, 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", params_code.debug_str());
|
||||
log_failure("gen::def_operator: params is not of Parameters type - %s", debug_str(params_code));
|
||||
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), params_code.debug_str());
|
||||
log_failure("gen::def_operator: operator%s expects no paramters - %s", to_str(op), debug_str(params_code));
|
||||
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", params.debug_str());
|
||||
log_failure("gen::def_constructor: params must be of Parameters type - %s", debug_str(params));
|
||||
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", specifiers.debug_str() );
|
||||
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", debug_str(specifiers) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
@ -828,19 +828,19 @@ CodeFn def_function( StrC name
|
||||
|
||||
if ( params && params->Type != Parameters )
|
||||
{
|
||||
log_failure( "gen::def_function: params was not a `Parameters` type: %s", params.debug_str() );
|
||||
log_failure( "gen::def_function: params was not a `Parameters` type: %s", debug_str(params) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
if ( ret_type && ret_type->Type != Typename )
|
||||
{
|
||||
log_failure( "gen::def_function: ret_type was not a Typename: %s", ret_type.debug_str() );
|
||||
log_failure( "gen::def_function: ret_type was not a Typename: %s", debug_str(ret_type) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
if ( specifiers && specifiers->Type != Specifiers )
|
||||
{
|
||||
log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", specifiers.debug_str() );
|
||||
log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", debug_str(specifiers) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
@ -973,7 +973,7 @@ CodeOperator def_operator( OperatorT op, StrC nspace
|
||||
|
||||
if ( specifiers && specifiers->Type != Specifiers )
|
||||
{
|
||||
log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", specifiers.debug_str() );
|
||||
log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", debug_str(specifiers) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
@ -1167,7 +1167,7 @@ CodeSpecifiers def_specifier( SpecifierT spec )
|
||||
CodeSpecifiers
|
||||
result = (CodeSpecifiers) make_code();
|
||||
result->Type = ECode::Specifiers;
|
||||
result.append( spec );
|
||||
append(result, spec );
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -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", params.debug_str() );
|
||||
log_failure( "gen::def_template: params is not of parameters type - %s", debug_str(params) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
@ -1470,7 +1470,7 @@ CodeVar def_variable( CodeType type, StrC name, Code value
|
||||
|
||||
if ( specifiers && specifiers->Type != ECode::Specifiers )
|
||||
{
|
||||
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type - %s", specifiers.debug_str() );
|
||||
log_failure( "gen::def_variable: specifiers was not a `Specifiers` type - %s", debug_str(specifiers) );
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
@ -2077,7 +2077,7 @@ CodeParam def_params( s32 num, ... )
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
CodeParam result = (CodeParam) param.duplicate();
|
||||
CodeParam result = (CodeParam) duplicate(param);
|
||||
|
||||
while ( -- num )
|
||||
{
|
||||
@ -2090,7 +2090,7 @@ CodeParam def_params( s32 num, ... )
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
result.append( param );
|
||||
append(result, 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", current.debug_str() ); \
|
||||
log_failure("gen::def_params: Code in coes array is not of paramter type - %s", debug_str(current) ); \
|
||||
return InvalidCode; \
|
||||
}
|
||||
|
||||
CodeParam current = (CodeParam) codes->duplicate();
|
||||
CodeParam current = (CodeParam)duplicate(* codes);
|
||||
check_current();
|
||||
|
||||
CodeParam
|
||||
@ -2126,7 +2126,7 @@ CodeParam def_params( s32 num, CodeParam* codes )
|
||||
while( codes++, current = * codes, num--, num > 0 )
|
||||
{
|
||||
check_current();
|
||||
result.append( current );
|
||||
append(result, current );
|
||||
}
|
||||
# undef check_current
|
||||
|
||||
@ -2157,7 +2157,7 @@ CodeSpecifiers def_specifiers( s32 num, ... )
|
||||
{
|
||||
SpecifierT type = (SpecifierT)va_arg(va, int);
|
||||
|
||||
result.append( type );
|
||||
append(result, type );
|
||||
}
|
||||
while ( --num, num );
|
||||
va_end(va);
|
||||
@ -2186,7 +2186,7 @@ CodeSpecifiers def_specifiers( s32 num, SpecifierT* specs )
|
||||
s32 idx = 0;
|
||||
do
|
||||
{
|
||||
result.append( specs[idx] );
|
||||
append(result, specs[idx] );
|
||||
idx++;
|
||||
}
|
||||
while ( --num, num );
|
||||
|
@ -1440,7 +1440,7 @@ CodeFn parse_function_after_name(
|
||||
continue;
|
||||
}
|
||||
|
||||
specifiers.append( ESpecifier::to_type(currtok) );
|
||||
append(specifiers, 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);
|
||||
specifiers.append( ESpecifier::Pure );
|
||||
append(specifiers, ESpecifier::Pure );
|
||||
|
||||
eat( TokType::Number);
|
||||
Token stmt_end = currtok;
|
||||
@ -2443,7 +2443,7 @@ CodeOperator parse_operator_after_ret_type(
|
||||
continue;
|
||||
}
|
||||
|
||||
specifiers.append( ESpecifier::to_type(currtok) );
|
||||
append(specifiers, 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 );
|
||||
result.append( param_varadic );
|
||||
append(result, param_varadic );
|
||||
continue;
|
||||
// ( <Macro> <ValueType> <Name> = <Expression>, ...
|
||||
}
|
||||
@ -2864,7 +2864,7 @@ CodeParam parse_params( bool use_template_capture )
|
||||
if ( value )
|
||||
param->Value = value;
|
||||
|
||||
result.append( param );
|
||||
append(result, 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() );
|
||||
|
||||
specifiers.append( spec );
|
||||
append(specifiers, spec );
|
||||
}
|
||||
break;
|
||||
|
||||
@ -3310,7 +3310,7 @@ CodeVar parse_variable_declaration_list()
|
||||
// eat(currtok.Type);
|
||||
|
||||
if ( specifiers )
|
||||
specifiers.append( spec );
|
||||
append(specifiers, spec );
|
||||
else
|
||||
specifiers = def_specifier( spec );
|
||||
}
|
||||
@ -3450,7 +3450,7 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
|
||||
if ( check( TokType::Spec_Virtual ) )
|
||||
{
|
||||
if ( specifiers )
|
||||
specifiers.append( ESpecifier::Virtual );
|
||||
append(specifiers, 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
|
||||
|
||||
specifiers.append( ESpecifier::Pure );
|
||||
append(specifiers, 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
|
||||
specifiers.append( ESpecifier::Const );
|
||||
append(specifiers, ESpecifier::Const );
|
||||
|
||||
eat( TokType::Spec_Const );
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user