1
0
Fork 0

Codechange: Use attribute syntax for debug_inline, so clang-format understands it.

pull/14042/head
frosch 2025-04-21 18:58:08 +02:00
parent 28c4f8e05a
commit 928a388a65
10 changed files with 50 additions and 50 deletions

View File

@ -29,7 +29,7 @@
* @return The selected bits, aligned to a LSB.
*/
template <typename T>
debug_inline constexpr static uint GB(const T x, const uint8_t s, const uint8_t n)
[[debug_inline]] inline constexpr static uint GB(const T x, const uint8_t s, const uint8_t n)
{
return (x >> s) & (((T)1U << n) - 1);
}
@ -100,7 +100,7 @@ constexpr T AB(T &x, const uint8_t s, const uint8_t n, const U i)
* @return True if the bit is set, false else.
*/
template <typename T>
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
[[debug_inline]] inline constexpr bool HasBit(const T x, const uint8_t y)
{
return (x & ((T)1U << y)) != 0;
}

View File

@ -90,7 +90,7 @@ inline constexpr enum_type operator --(enum_type &e, int)
* @return True iff the flag is set.
*/
template <typename T, class = typename std::enable_if_t<std::is_enum_v<T>>>
debug_inline constexpr bool HasFlag(const T x, const T y)
[[debug_inline]] inline constexpr bool HasFlag(const T x, const T y)
{
return (x & y) == y;
}
@ -101,7 +101,7 @@ debug_inline constexpr bool HasFlag(const T x, const T y)
* @param y The flag to toggle.
*/
template <typename T, class = typename std::enable_if_t<std::is_enum_v<T>>>
debug_inline constexpr void ToggleFlag(T &x, const T y)
[[debug_inline]] inline constexpr void ToggleFlag(T &x, const T y)
{
if (HasFlag(x, y)) {
x &= ~y;

View File

@ -61,7 +61,7 @@ public:
* Create the tile wrapper for the given tile.
* @param tile The tile to access the map for.
*/
debug_inline Tile(TileIndex tile) : tile(tile) {}
[[debug_inline]] inline Tile(TileIndex tile) : tile(tile) {}
/**
* Create the tile wrapper for the given tile.
@ -72,12 +72,12 @@ public:
/**
* Implicit conversion to the TileIndex.
*/
debug_inline constexpr operator TileIndex() const { return this->tile; }
[[debug_inline]] inline constexpr operator TileIndex() const { return this->tile; }
/**
* Implicit conversion to the uint for bounds checking.
*/
debug_inline constexpr operator uint() const { return this->tile.base(); }
[[debug_inline]] inline constexpr operator uint() const { return this->tile.base(); }
/**
* The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
@ -86,7 +86,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the byte holding the data.
*/
debug_inline uint8_t &type()
[[debug_inline]] inline uint8_t &type()
{
return base_tiles[this->tile.base()].type;
}
@ -98,7 +98,7 @@ public:
* @param tile The tile to get the height for.
* @return reference to the byte holding the height.
*/
debug_inline uint8_t &height()
[[debug_inline]] inline uint8_t &height()
{
return base_tiles[this->tile.base()].height;
}
@ -110,7 +110,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the byte holding the data.
*/
debug_inline uint8_t &m1()
[[debug_inline]] inline uint8_t &m1()
{
return base_tiles[this->tile.base()].m1;
}
@ -122,7 +122,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the uint16_t holding the data.
*/
debug_inline uint16_t &m2()
[[debug_inline]] inline uint16_t &m2()
{
return base_tiles[this->tile.base()].m2;
}
@ -134,7 +134,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the byte holding the data.
*/
debug_inline uint8_t &m3()
[[debug_inline]] inline uint8_t &m3()
{
return base_tiles[this->tile.base()].m3;
}
@ -146,7 +146,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the byte holding the data.
*/
debug_inline uint8_t &m4()
[[debug_inline]] inline uint8_t &m4()
{
return base_tiles[this->tile.base()].m4;
}
@ -158,7 +158,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the byte holding the data.
*/
debug_inline uint8_t &m5()
[[debug_inline]] inline uint8_t &m5()
{
return base_tiles[this->tile.base()].m5;
}
@ -170,7 +170,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the byte holding the data.
*/
debug_inline uint8_t &m6()
[[debug_inline]] inline uint8_t &m6()
{
return extended_tiles[this->tile.base()].m6;
}
@ -182,7 +182,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the byte holding the data.
*/
debug_inline uint8_t &m7()
[[debug_inline]] inline uint8_t &m7()
{
return extended_tiles[this->tile.base()].m7;
}
@ -194,7 +194,7 @@ public:
* @param tile The tile to get the data for.
* @return reference to the uint16_t holding the data.
*/
debug_inline uint16_t &m8()
[[debug_inline]] inline uint16_t &m8()
{
return extended_tiles[this->tile.base()].m8;
}
@ -247,7 +247,7 @@ public:
* @note try to avoid using this one
* @return 2^"return value" == Map::SizeX()
*/
debug_inline static uint LogX()
[[debug_inline]] inline static uint LogX()
{
return Map::log_x;
}
@ -266,7 +266,7 @@ public:
* Get the size of the map along the X
* @return the number of tiles along the X of the map
*/
debug_inline static uint SizeX()
[[debug_inline]] inline static uint SizeX()
{
return Map::size_x;
}
@ -284,7 +284,7 @@ public:
* Get the size of the map
* @return the number of tiles of the map
*/
debug_inline static uint Size()
[[debug_inline]] inline static uint Size()
{
return Map::size;
}
@ -293,7 +293,7 @@ public:
* Gets the maximum X coordinate within the map, including MP_VOID
* @return the maximum X coordinate
*/
debug_inline static uint MaxX()
[[debug_inline]] inline static uint MaxX()
{
return Map::SizeX() - 1;
}
@ -369,7 +369,7 @@ public:
* @param y The y coordinate of the tile
* @return The TileIndex calculated by the coordinate
*/
debug_inline static TileIndex TileXY(uint x, uint y)
[[debug_inline]] inline static TileIndex TileXY(uint x, uint y)
{
return TileIndex{(y << Map::LogX()) + x};
}
@ -400,7 +400,7 @@ inline TileIndexDiff TileDiffXY(int x, int y)
* @param y The virtual y coordinate of the tile.
* @return The TileIndex calculated by the coordinate.
*/
debug_inline static TileIndex TileVirtXY(uint x, uint y)
[[debug_inline]] inline static TileIndex TileVirtXY(uint x, uint y)
{
return TileIndex{(y >> 4 << Map::LogX()) + (x >> 4)};
}
@ -411,7 +411,7 @@ debug_inline static TileIndex TileVirtXY(uint x, uint y)
* @param tile the tile to get the X component of
* @return the X component
*/
debug_inline static uint TileX(TileIndex tile)
[[debug_inline]] inline static uint TileX(TileIndex tile)
{
return tile.base() & Map::MaxX();
}
@ -421,7 +421,7 @@ debug_inline static uint TileX(TileIndex tile)
* @param tile the tile to get the Y component of
* @return the Y component
*/
debug_inline static uint TileY(TileIndex tile)
[[debug_inline]] inline static uint TileY(TileIndex tile)
{
return tile.base() >> Map::LogX();
}

View File

@ -88,11 +88,11 @@ struct CFollowTrackT
this->railtypes = railtype_override;
}
debug_inline static TransportType TT() { return Ttr_type_; }
debug_inline static bool IsWaterTT() { return TT() == TRANSPORT_WATER; }
debug_inline static bool IsRailTT() { return TT() == TRANSPORT_RAIL; }
[[debug_inline]] inline static TransportType TT() { return Ttr_type_; }
[[debug_inline]] inline static bool IsWaterTT() { return TT() == TRANSPORT_WATER; }
[[debug_inline]] inline static bool IsRailTT() { return TT() == TRANSPORT_RAIL; }
inline bool IsTram() { return IsRoadTT() && RoadTypeIsTram(RoadVehicle::From(this->veh)->roadtype); }
debug_inline static bool IsRoadTT() { return TT() == TRANSPORT_ROAD; }
[[debug_inline]] inline static bool IsRoadTT() { return TT() == TRANSPORT_ROAD; }
inline static bool Allow90degTurns() { return T90deg_turns_allowed_; }
inline static bool DoTrackMasking() { return Tmask_reserved_tracks; }

View File

@ -33,7 +33,7 @@ enum RailTileType : uint8_t {
* @pre IsTileType(t, MP_RAILWAY)
* @return the RailTileType
*/
debug_inline static RailTileType GetRailTileType(Tile t)
[[debug_inline]] inline static RailTileType GetRailTileType(Tile t)
{
assert(IsTileType(t, MP_RAILWAY));
return (RailTileType)GB(t.m5(), 6, 2);
@ -46,7 +46,7 @@ debug_inline static RailTileType GetRailTileType(Tile t)
* @pre IsTileType(t, MP_RAILWAY)
* @return true if and only if the tile is normal rail (with or without signals)
*/
debug_inline static bool IsPlainRail(Tile t)
[[debug_inline]] inline static bool IsPlainRail(Tile t)
{
RailTileType rtt = GetRailTileType(t);
return rtt == RAIL_TILE_NORMAL || rtt == RAIL_TILE_SIGNALS;
@ -57,7 +57,7 @@ debug_inline static bool IsPlainRail(Tile t)
* @param t the tile to get the information from
* @return true if and only if the tile is normal rail (with or without signals)
*/
debug_inline static bool IsPlainRailTile(Tile t)
[[debug_inline]] inline static bool IsPlainRailTile(Tile t)
{
return IsTileType(t, MP_RAILWAY) && IsPlainRail(t);
}
@ -92,7 +92,7 @@ inline void SetHasSignals(Tile tile, bool signals)
* @pre IsTileType(t, MP_RAILWAY)
* @return true if and only if the tile is a rail depot
*/
debug_inline static bool IsRailDepot(Tile t)
[[debug_inline]] inline static bool IsRailDepot(Tile t)
{
return GetRailTileType(t) == RAIL_TILE_DEPOT;
}
@ -102,7 +102,7 @@ debug_inline static bool IsRailDepot(Tile t)
* @param t the tile to get the information from
* @return true if and only if the tile is a rail depot
*/
debug_inline static bool IsRailDepotTile(Tile t)
[[debug_inline]] inline static bool IsRailDepotTile(Tile t)
{
return IsTileType(t, MP_RAILWAY) && IsRailDepot(t);
}

View File

@ -33,7 +33,7 @@ bool MayHaveRoad(Tile t);
* @pre IsTileType(t, MP_ROAD)
* @return The road tile type.
*/
debug_inline static RoadTileType GetRoadTileType(Tile t)
[[debug_inline]] inline static RoadTileType GetRoadTileType(Tile t)
{
assert(IsTileType(t, MP_ROAD));
return (RoadTileType)GB(t.m5(), 6, 2);
@ -45,7 +45,7 @@ debug_inline static RoadTileType GetRoadTileType(Tile t)
* @pre IsTileType(t, MP_ROAD)
* @return True if normal road.
*/
debug_inline static bool IsNormalRoad(Tile t)
[[debug_inline]] inline static bool IsNormalRoad(Tile t)
{
return GetRoadTileType(t) == ROAD_TILE_NORMAL;
}
@ -55,7 +55,7 @@ debug_inline static bool IsNormalRoad(Tile t)
* @param t Tile to query.
* @return True if normal road tile.
*/
debug_inline static bool IsNormalRoadTile(Tile t)
[[debug_inline]] inline static bool IsNormalRoadTile(Tile t)
{
return IsTileType(t, MP_ROAD) && IsNormalRoad(t);
}
@ -87,7 +87,7 @@ inline bool IsLevelCrossingTile(Tile t)
* @pre IsTileType(t, MP_ROAD)
* @return True if road depot.
*/
debug_inline static bool IsRoadDepot(Tile t)
[[debug_inline]] inline static bool IsRoadDepot(Tile t)
{
return GetRoadTileType(t) == ROAD_TILE_DEPOT;
}
@ -97,7 +97,7 @@ debug_inline static bool IsRoadDepot(Tile t)
* @param t Tile to query.
* @return True if road depot tile.
*/
debug_inline static bool IsRoadDepotTile(Tile t)
[[debug_inline]] inline static bool IsRoadDepotTile(Tile t)
{
return IsTileType(t, MP_ROAD) && IsRoadDepot(t);
}

View File

@ -301,7 +301,7 @@ struct GoodsEntry {
* Test if this goods entry has optional cargo packet/flow data.
* @returns true iff optional data is present.
*/
debug_inline bool HasData() const { return this->data != nullptr; }
[[debug_inline]] inline bool HasData() const { return this->data != nullptr; }
/**
* Clear optional cargo packet/flow data.
@ -313,7 +313,7 @@ struct GoodsEntry {
* @pre HasData()
* @returns cargo packet/flow data.
*/
debug_inline const GoodsEntryData &GetData() const
[[debug_inline]] inline const GoodsEntryData &GetData() const
{
assert(this->HasData());
return *this->data;
@ -324,7 +324,7 @@ struct GoodsEntry {
* @pre HasData()
* @returns non-const cargo packet/flow data.
*/
debug_inline GoodsEntryData &GetData()
[[debug_inline]] inline GoodsEntryData &GetData()
{
assert(this->HasData());
return *this->data;

View File

@ -219,16 +219,16 @@
* Do not force inlining when not in debug. This way we do not work against
* any carefully designed compiler optimizations.
*/
#define debug_inline inline
#define debug_inline
#elif defined(__clang__) || defined(__GNUC__)
#define debug_inline [[gnu::always_inline]] inline
#define debug_inline gnu::always_inline
#else
/*
* MSVC explicitly disables inlining, even forced inlining, in debug builds
* so __forceinline makes no difference compared to inline. Other unknown
* compilers can also just fallback to a normal inline.
*/
#define debug_inline inline
#define debug_inline
#endif
/* This is already defined in unix, but not in QNX Neutrino (6.x) or Cygwin. */

View File

@ -26,7 +26,7 @@
* @return the height of the tile
* @pre tile < Map::Size()
*/
debug_inline static uint TileHeight(Tile tile)
[[debug_inline]] inline static uint TileHeight(Tile tile)
{
assert(tile < Map::Size());
return tile.height();
@ -93,7 +93,7 @@ inline uint TilePixelHeightOutsideMap(int x, int y)
* @return The tiletype of the tile
* @pre tile < Map::Size()
*/
debug_inline static TileType GetTileType(Tile tile)
[[debug_inline]] inline static TileType GetTileType(Tile tile)
{
assert(tile < Map::Size());
return (TileType)GB(tile.type(), 4, 4);
@ -147,7 +147,7 @@ inline void SetTileType(Tile tile, TileType type)
* @param type The type to check against
* @return true If the type matches against the type of the tile
*/
debug_inline static bool IsTileType(Tile tile, TileType type)
[[debug_inline]] inline static bool IsTileType(Tile tile, TileType type)
{
return GetTileType(tile) == type;
}

View File

@ -492,7 +492,7 @@ public:
* Check if the vehicle is a ground vehicle.
* @return True iff the vehicle is a train or a road vehicle.
*/
debug_inline bool IsGroundVehicle() const
[[debug_inline]] inline bool IsGroundVehicle() const
{
return this->type == VEH_TRAIN || this->type == VEH_ROAD;
}
@ -922,7 +922,7 @@ public:
* Check if the vehicle is a front engine.
* @return Returns true if the vehicle is a front engine.
*/
debug_inline bool IsFrontEngine() const
[[debug_inline]] inline bool IsFrontEngine() const
{
return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT);
}