mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* trigger tidy * copy&move BApplicPtr obj always commit tidy changes * move PolObject * fix house add_component * Automated clang-tidy change: performance-unnecessary-copy-initialization,performance-unnecessary-value-param * Revert "Automated clang-tidy change: performance-unnecessary-copy-initialization,performance-unnecessary-value-param" This reverts commit bb6aab13dbdfa4aaf420cdaafaf22940f241fc5b. * performance-unnecessary-value-param gives some weird suggestions * Automated clang-tidy change: performance-unnecessary-copy-initialization * minor performance improvements * added used tidy check * missing dependency * renamed build so its no longer requires? * better add docs for the sneaky fix * silence pr check, not all headers can be compiled seperatly --------- Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>
86 lines
2.3 KiB
C++
86 lines
2.3 KiB
C++
#include "ScopableName.h"
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include "clib/clib.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
ScopableName::ScopableName( const ScopeName& scope, std::string name )
|
|
: scope( scope ), name( std::move( name ) )
|
|
{
|
|
}
|
|
|
|
ScopableName::ScopableName( std::string scope, std::string name )
|
|
: ScopableName( ScopeName( std::move( scope ) ), std::move( name ) )
|
|
{
|
|
}
|
|
|
|
bool ScopableName::global() const
|
|
{
|
|
return scope.global();
|
|
}
|
|
|
|
std::string ScopableName::string() const
|
|
{
|
|
return fmt::format( "{}{}{}", scope.string(), scope.global() ? "" : "::", name );
|
|
}
|
|
|
|
bool ScopableName::operator<( const ScopableName& other ) const
|
|
{
|
|
// Check for special equality condition: <nullopt>::Foo == Foo::Foo
|
|
if ( scope.empty() && !other.scope.empty() )
|
|
{
|
|
std::string expectedScope = name + "::" + name;
|
|
if ( stricmp( other.string().c_str(), expectedScope.c_str() ) == 0 )
|
|
{
|
|
// 'this' is considered equal to 'other' for this special case
|
|
return false;
|
|
}
|
|
}
|
|
else if ( !scope.empty() && other.scope.empty() )
|
|
{
|
|
std::string expectedScope = other.name + "::" + other.name;
|
|
if ( stricmp( string().c_str(), expectedScope.c_str() ) == 0 )
|
|
{
|
|
// 'other' is considered equal to 'this' for this special case
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Compare scopes first
|
|
if ( !scope.empty() && !other.scope.empty() )
|
|
{
|
|
int scopeComparison = stricmp( scope.string().c_str(), other.scope.string().c_str() );
|
|
if ( scopeComparison < 0 )
|
|
{
|
|
return true;
|
|
}
|
|
if ( scopeComparison > 0 )
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else if ( !scope.empty() && other.scope.empty() )
|
|
{
|
|
return false;
|
|
}
|
|
else if ( scope.empty() && !other.scope.empty() )
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// If scopes are equal (both empty or both equal), compare names
|
|
return stricmp( name.c_str(), other.name.c_str() ) < 0;
|
|
}
|
|
} // namespace Pol::Bscript::Compiler
|
|
|
|
fmt::format_context::iterator fmt::formatter<Pol::Bscript::Compiler::ScopableName>::format(
|
|
const Pol::Bscript::Compiler::ScopableName& scoped_name, fmt::format_context& ctx ) const
|
|
{
|
|
// Uses .empty() vs .global() to distinguish "::foo" vs "foo".
|
|
return fmt::formatter<std::string>::format(
|
|
fmt::format( "{}{}{}", scoped_name.scope.string(),
|
|
scoped_name.scope.empty() ? "" : "::", scoped_name.name ),
|
|
ctx );
|
|
}
|