String::is_equal added (bad last commit)

This commit is contained in:
Edward R. Gonzalez 2024-12-01 13:29:33 -05:00
parent f61c1c560d
commit 9e88cb8724
6 changed files with 302 additions and 7 deletions

View File

@ -165,6 +165,7 @@ struct Code
char const* debug_str(); \ char const* debug_str(); \
Code duplicate(); \ Code duplicate(); \
bool is_equal( Code other ); \ bool is_equal( Code other ); \
bool is_body(); \
bool is_valid(); \ bool is_valid(); \
void set_global(); \ void set_global(); \
String to_string(); \ String to_string(); \
@ -259,6 +260,7 @@ struct AST
Code& entry ( u32 idx ); Code& entry ( u32 idx );
bool has_entries(); bool has_entries();
bool is_equal ( AST* other ); bool is_equal ( AST* other );
bool is_body();
char const* type_str(); char const* type_str();
bool validate_body(); bool validate_body();

View File

@ -11,6 +11,10 @@ struct CodeBody
void append( Code other ) void append( Code other )
{ {
if (other.is_body())
{
append( other.cast<CodeBody>() );
}
raw()->append( other.ast ); raw()->append( other.ast );
} }
void append( CodeBody body ) void append( CodeBody body )

View File

@ -24,6 +24,15 @@ inline Code Code::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool Code::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool Code::is_equal( Code other ) inline bool Code::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -91,6 +100,15 @@ inline Code CodeBody::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeBody::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeBody::is_equal( Code other ) inline bool CodeBody::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -158,6 +176,15 @@ inline Code CodeAttributes::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeAttributes::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeAttributes::is_equal( Code other ) inline bool CodeAttributes::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -245,6 +272,15 @@ inline Code CodeComment::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeComment::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeComment::is_equal( Code other ) inline bool CodeComment::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -332,6 +368,15 @@ inline Code CodeConstructor::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeConstructor::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeConstructor::is_equal( Code other ) inline bool CodeConstructor::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -419,6 +464,15 @@ inline Code CodeClass::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeClass::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeClass::is_equal( Code other ) inline bool CodeClass::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -486,6 +540,15 @@ inline Code CodeDefine::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeDefine::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeDefine::is_equal( Code other ) inline bool CodeDefine::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -573,6 +636,15 @@ inline Code CodeDestructor::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeDestructor::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeDestructor::is_equal( Code other ) inline bool CodeDestructor::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -660,6 +732,15 @@ inline Code CodeEnum::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeEnum::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeEnum::is_equal( Code other ) inline bool CodeEnum::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -747,6 +828,15 @@ inline Code CodeExec::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeExec::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeExec::is_equal( Code other ) inline bool CodeExec::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -834,6 +924,15 @@ inline Code CodeExtern::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeExtern::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeExtern::is_equal( Code other ) inline bool CodeExtern::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -921,6 +1020,15 @@ inline Code CodeFriend::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeFriend::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeFriend::is_equal( Code other ) inline bool CodeFriend::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1008,6 +1116,15 @@ inline Code CodeFn::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeFn::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeFn::is_equal( Code other ) inline bool CodeFn::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1095,6 +1212,15 @@ inline Code CodeInclude::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeInclude::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeInclude::is_equal( Code other ) inline bool CodeInclude::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1182,6 +1308,15 @@ inline Code CodeModule::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeModule::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeModule::is_equal( Code other ) inline bool CodeModule::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1269,6 +1404,15 @@ inline Code CodeNS::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeNS::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeNS::is_equal( Code other ) inline bool CodeNS::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1356,6 +1500,15 @@ inline Code CodeOperator::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeOperator::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeOperator::is_equal( Code other ) inline bool CodeOperator::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1443,6 +1596,15 @@ inline Code CodeOpCast::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeOpCast::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeOpCast::is_equal( Code other ) inline bool CodeOpCast::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1530,6 +1692,15 @@ inline Code CodeParam::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeParam::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeParam::is_equal( Code other ) inline bool CodeParam::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1597,6 +1768,15 @@ inline Code CodePragma::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodePragma::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodePragma::is_equal( Code other ) inline bool CodePragma::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1684,6 +1864,15 @@ inline Code CodePreprocessCond::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodePreprocessCond::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodePreprocessCond::is_equal( Code other ) inline bool CodePreprocessCond::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1771,6 +1960,15 @@ inline Code CodeSpecifiers::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeSpecifiers::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeSpecifiers::is_equal( Code other ) inline bool CodeSpecifiers::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1838,6 +2036,15 @@ inline Code CodeStruct::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeStruct::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeStruct::is_equal( Code other ) inline bool CodeStruct::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1905,6 +2112,15 @@ inline Code CodeTemplate::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeTemplate::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeTemplate::is_equal( Code other ) inline bool CodeTemplate::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -1992,6 +2208,15 @@ inline Code CodeType::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeType::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeType::is_equal( Code other ) inline bool CodeType::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -2079,6 +2304,15 @@ inline Code CodeTypedef::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeTypedef::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeTypedef::is_equal( Code other ) inline bool CodeTypedef::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -2166,6 +2400,15 @@ inline Code CodeUnion::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeUnion::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeUnion::is_equal( Code other ) inline bool CodeUnion::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -2253,6 +2496,15 @@ inline Code CodeUsing::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeUsing::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeUsing::is_equal( Code other ) inline bool CodeUsing::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )
@ -2340,6 +2592,15 @@ inline Code CodeVar::duplicate()
return { rcast( AST*, ast )->duplicate() }; return { rcast( AST*, ast )->duplicate() };
} }
inline bool CodeVar::is_body()
{
if ( ast == nullptr )
{
return rcast( AST*, ast )->is_body();
}
return false;
}
inline bool CodeVar::is_equal( Code other ) inline bool CodeVar::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )

View File

@ -50,6 +50,25 @@ bool AST::has_entries()
return NumEntries > 0; return NumEntries > 0;
} }
inline
bool AST::is_body()
{
switch (Type)
{
case ECode::Enum_Body:
case ECode::Class_Body:
case ECode::Union_Body:
case ECode::Export_Body:
case ECode::Global_Body:
case ECode::Struct_Body:
case ECode::Function_Body:
case ECode::Namespace_Body:
case ECode::Extern_Linkage_Body:
return true;
}
return false;
}
inline inline
char const* AST::type_str() char const* AST::type_str()
{ {

View File

@ -41,8 +41,8 @@ String string_fmt(AllocatorInfo allocator, char* buf, ssize buf_size, cha
String string_fmt_buf(AllocatorInfo allocator, char const* fmt, ...); String string_fmt_buf(AllocatorInfo allocator, char const* fmt, ...);
String string_join(AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue); String string_join(AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue);
usize string_grow_formula(usize value); usize string_grow_formula(usize value);
bool are_equal(String lhs, String rhs); bool are_equal(String const& lhs, String const& rhs);
bool are_equal(String lhs, StrC rhs); bool are_equal(String const& lhs, StrC rhs);
bool make_space_for(String& str, char const* to_append, ssize add_len); bool make_space_for(String& str, char const* to_append, ssize add_len);
bool append(String& str, char c); bool append(String& str, char c);
bool append(String& str, char const* str_to_append); bool append(String& str, char const* str_to_append);
@ -108,8 +108,6 @@ struct String
forceinline static String make_length(AllocatorInfo a, char const* s, ssize l) { return GEN_NS string_make_length(a, s, l); } forceinline static String make_length(AllocatorInfo a, char const* s, ssize l) { return GEN_NS string_make_length(a, s, l); }
forceinline static String join(AllocatorInfo a, char const** p, ssize n, char const* g) { return GEN_NS string_join(a, p, n, g); } forceinline static String join(AllocatorInfo a, char const** p, ssize n, char const* g) { return GEN_NS string_join(a, p, n, g); }
forceinline static usize grow_formula(usize value) { return GEN_NS string_grow_formula(value); } forceinline static usize grow_formula(usize value) { return GEN_NS string_grow_formula(value); }
forceinline static bool are_equal(String lhs, String rhs) { return GEN_NS are_equal(lhs, rhs); }
forceinline static bool are_equal(String lhs, StrC rhs) { return GEN_NS are_equal(lhs, rhs); }
static static
String fmt(AllocatorInfo allocator, char* buf, ssize buf_size, char const* fmt, ...) { String fmt(AllocatorInfo allocator, char* buf, ssize buf_size, char const* fmt, ...) {
@ -145,6 +143,8 @@ struct String
forceinline void clear() { GEN_NS clear(*this); } forceinline void clear() { GEN_NS clear(*this); }
forceinline String duplicate(AllocatorInfo allocator) const { return GEN_NS duplicate(*this, allocator); } forceinline String duplicate(AllocatorInfo allocator) const { return GEN_NS duplicate(*this, allocator); }
forceinline void free() { GEN_NS free(*this); } forceinline void free() { GEN_NS free(*this); }
forceinline bool is_equal(String const& other) const { return GEN_NS are_equal(* this, other); }
forceinline bool is_equal(StrC other) const { return GEN_NS are_equal(* this, other); }
forceinline ssize length() const { return GEN_NS length(*this); } forceinline ssize length() const { return GEN_NS length(*this); }
forceinline b32 starts_with(StrC substring) const { return GEN_NS starts_with(*this, substring); } forceinline b32 starts_with(StrC substring) const { return GEN_NS starts_with(*this, substring); }
forceinline b32 starts_with(String substring) const { return GEN_NS starts_with(*this, substring); } forceinline b32 starts_with(String substring) const { return GEN_NS starts_with(*this, substring); }
@ -286,7 +286,7 @@ bool append_fmt(String& str, char const* fmt, ...) {
} }
inline inline
bool are_equal(String lhs, String rhs) bool are_equal(String const& lhs, String const& rhs)
{ {
if (length(lhs) != length(rhs)) if (length(lhs) != length(rhs))
return false; return false;
@ -299,7 +299,7 @@ bool are_equal(String lhs, String rhs)
} }
inline inline
bool are_equal(String lhs, StrC rhs) bool are_equal(String const& lhs, StrC rhs)
{ {
if (length(lhs) != (rhs.Len)) if (length(lhs) != (rhs.Len))
return false; return false;

View File

@ -368,6 +368,15 @@ CodeBody gen_ast_inlines()
return { rcast(AST*, ast)->duplicate() }; return { rcast(AST*, ast)->duplicate() };
} }
inline inline
bool <typename>::is_body()
{
if ( ast == nullptr )
{
return rcast(AST*, ast)->is_body();
}
return false;
}
inline
bool <typename>::is_equal( Code other ) bool <typename>::is_equal( Code other )
{ {
if ( ast == nullptr || other.ast == nullptr ) if ( ast == nullptr || other.ast == nullptr )