Replace __attribute__ keywords with a macro to improve compiler compatibility.

This commit is contained in:
King_DuckZ 2014-08-14 12:00:04 +02:00
parent dff58a98ef
commit 4e89878eb4
13 changed files with 118 additions and 48 deletions

View file

@ -20,13 +20,14 @@
#ifndef id8714F4436A1F462193A253C8C5AF55CD
#define id8714F4436A1F462193A253C8C5AF55CD
#include "compatibility.h"
#if !defined(NDEBUG)
#include <cassert>
#endif
namespace cloonel {
template <typename To, typename From>
To checked_numcast ( From parFrom ) __attribute__((pure));
To checked_numcast ( From parFrom ) a_pure;
template <typename To, typename From>
inline

58
src/compatibility.h Normal file
View file

@ -0,0 +1,58 @@
/*
Copyright 2014 Michele "King_DuckZ" Santullo
This file is part of CloonelJump.
CloonelJump is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CloonelJump is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CloonelJump. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id45CDD1DAEF4F42968E3C89F68FDDA9BC
#define id45CDD1DAEF4F42968E3C89F68FDDA9BC
#if defined(__GNUC__)
# if defined(__clang__)
# if !defined(__has_attribute)
//Fall back to version number comparing
# else
# if __has_attribute(flatten)
# define a_flatten __attribute__((flatten))
# else
# define a_flatten
# endif
# if __has_attribute(always_inline)
# define a_always_inline __attribute__((always_inline))
# else
# define a_always_inline
# endif
# if __has_attribute(pure)
# define a_pure __attribute__((pure))
# else
# define a_pure
# endif
# endif
# else
//Fix here if you get warnings about unsupported attributes on your compiler
# define a_flatten __attribute__((flatten))
# define a_always_inline __attribute__((always_inline))
# define a_pure __attribute__((pure))
# endif
#else
# warning "Unsupported compiler, please fill this section or file a bug"
# define a_flatten
# define a_always_inline
# define a_pure
#endif
#endif

View file

@ -28,9 +28,9 @@ namespace cloonel {
namespace {
typedef HorzCollisionBar::Line2D Line2D;
float calculateOverlappingTime ( float parDeltaT, float parAY, float parBY, float parDeltaA, float parDeltaB ) __attribute__((pure));
void DoNothing ( const Line2D&, const float2& ) __attribute__((pure));
std::pair<bool, Line2D> getOverlap ( float parDeltaT, const Line2D& parA, const Line2D& parB, const float2& parDeltaA, const float2& parDeltaB ) __attribute__((pure));
float calculateOverlappingTime ( float parDeltaT, float parAY, float parBY, float parDeltaA, float parDeltaB ) a_pure;
void DoNothing ( const Line2D&, const float2& ) a_pure;
std::pair<bool, Line2D> getOverlap ( float parDeltaT, const Line2D& parA, const Line2D& parB, const float2& parDeltaA, const float2& parDeltaB ) a_pure;
///----------------------------------------------------------------------
///Calculate the time t at which the two segments (which are assumed to

View file

@ -23,6 +23,7 @@
#include "vector.hpp"
#include "placeable.hpp"
#include "line.hpp"
#include "compatibility.h"
#include <functional>
namespace cloonel {
@ -56,7 +57,7 @@ namespace cloonel {
CallbackType m_callback;
};
bool Collide ( float parDeltaT, const HorzCollisionBar& parA, const HorzCollisionBar& parB, HorzCollisionBar::Line2D& parOut ) __attribute__((pure));
bool Collide ( float parDeltaT, const HorzCollisionBar& parA, const HorzCollisionBar& parB, HorzCollisionBar::Line2D& parOut ) a_pure;
} //namespace cloonel
#endif

View file

@ -20,6 +20,7 @@
#ifndef id56F112C6551D44039D0C0270F573B35B
#define id56F112C6551D44039D0C0270F573B35B
#include "compatibility.h"
#include "vector.hpp"
#include "vectormath.hpp"
@ -42,30 +43,30 @@ namespace cloonel {
const Point& Start ( void ) const { return m_points.x(); }
const Point& End ( void ) const { return m_points.y(); }
Line& operator+= ( const Point& parRhs ) __attribute__((flatten));
Line& operator-= ( const Point& parRhs ) __attribute__((flatten));
Line& operator+= ( const Point& parRhs ) a_flatten;
Line& operator-= ( const Point& parRhs ) a_flatten;
private:
Vector<Point, 2> m_points;
};
template <typename T, uint32_t S>
Line<T, S> operator+ ( Line<T, S> parLhs, const Vector<T, S>& parRhs ) __attribute__((pure)) __attribute__((flatten));
Line<T, S> operator+ ( Line<T, S> parLhs, const Vector<T, S>& parRhs ) a_pure a_flatten;
template <typename T, uint32_t S>
Line<T, S> operator- ( Line<T, S> parLhs, const Vector<T, S>& parRhs ) __attribute__((pure)) __attribute__((flatten));
Line<T, S> operator- ( Line<T, S> parLhs, const Vector<T, S>& parRhs ) a_pure a_flatten;
template <typename T, uint32_t S>
Line<T, S> operator+ ( const Vector<T, S>& parLhs, Line<T, S> parRhs ) __attribute__((pure)) __attribute__((flatten));
Line<T, S> operator+ ( const Vector<T, S>& parLhs, Line<T, S> parRhs ) a_pure a_flatten;
template <typename T, uint32_t S>
Line<T, S> operator- ( const Vector<T, S>& parLhs, Line<T, S> parRhs ) __attribute__((pure)) __attribute__((flatten));
Line<T, S> operator- ( const Vector<T, S>& parLhs, Line<T, S> parRhs ) a_pure a_flatten;
template <typename T>
bool operator> ( const Vector<T, 2>& parLhs, const Line<T, 2>& parRhs ) __attribute__((pure));
bool operator> ( const Vector<T, 2>& parLhs, const Line<T, 2>& parRhs ) a_pure;
template <typename T>
bool operator< ( const Vector<T, 2>& parLhs, const Line<T, 2>& parRhs ) __attribute__((pure));
bool operator< ( const Vector<T, 2>& parLhs, const Line<T, 2>& parRhs ) a_pure;
template <typename T>
bool operator>= ( const Vector<T, 2>& parLhs, const Line<T, 2>& parRhs ) __attribute__((pure));
bool operator>= ( const Vector<T, 2>& parLhs, const Line<T, 2>& parRhs ) a_pure;
template <typename T>
bool operator<= ( const Vector<T, 2>& parLhs, const Line<T, 2>& parRhs ) __attribute__((pure));
bool operator<= ( const Vector<T, 2>& parLhs, const Line<T, 2>& parRhs ) a_pure;
} //namespace cloonel
#include "line.inl"

View file

@ -22,14 +22,15 @@
#include "vector.hpp"
#include "line.hpp"
#include "compatibility.h"
#include <cmath>
namespace cloonel {
template <typename T, uint32_t S>
T len ( const Line<T, S>& parLine ) __attribute__((pure));
T len ( const Line<T, S>& parLine ) a_pure;
template <typename T, uint32_t S>
T len_sq ( const Line<T, S>& parLine ) __attribute__((pure));
T len_sq ( const Line<T, S>& parLine ) a_pure;
} //namespace cloonel
#include "line_helpers.inl"

View file

@ -21,11 +21,13 @@
#ifndef id44C452F5B87A4993B127EFE654837C7D
#define id44C452F5B87A4993B127EFE654837C7D
#include "compatibility.h"
namespace cloonel {
template <typename T, typename U>
T Lerp ( const T& parStart, const T& parEnd, const U& parPercent ) __attribute__((pure));
T Lerp ( const T& parStart, const T& parEnd, const U& parPercent ) a_pure;
template <typename T, typename R, typename U>
T LerpRange ( const T& parStart, const R& parRange, const U& parPercent ) __attribute__((pure));
T LerpRange ( const T& parStart, const R& parRange, const U& parPercent ) a_pure;
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------

View file

@ -18,12 +18,13 @@
*/
#include "moverleftright.hpp"
#include "compatibility.h"
#include <algorithm>
#include <cmath>
namespace cloonel {
namespace {
float Clamp ( float parValue, float parMin, float parMax ) __attribute__((pure));
float Clamp ( float parValue, float parMin, float parMax ) a_pure;
float Clamp ( float parValue, float parMin, float parMax ) {
assert(parMin <= parMax);
return std::max(parMin, std::min(parMax, parValue));

View file

@ -1,8 +1,9 @@
#include "sizeratio.hpp"
#include "compatibility.h"
namespace cloonel {
namespace {
float2 CalculateRatio ( float2 parOriginal, float2 parResolution ) __attribute__((pure));
float2 CalculateRatio ( float2 parOriginal, float2 parResolution ) a_pure;
///----------------------------------------------------------------------
///----------------------------------------------------------------------

View file

@ -21,6 +21,7 @@
#include "sdlerror.hpp"
#include "sdlmain.hpp"
#include "physicsfswrapper.hpp"
#include "compatibility.h"
#include <SDL2/SDL.h>
#include <stdexcept>
#include <cassert>
@ -105,10 +106,10 @@ namespace cloonel {
{".png", 4, GraphicFormat_Png}
};
GraphicFormat GuessGraphicFormatFromName (const std::string& parPath) __attribute__((pure));
GraphicFormat GuessGraphicFormatFromName (const std::string& parPath) a_pure;
bool ClipRect ( RectFloat& parSrc, RectFloat& parDest, const RectFloat& parClip );
#if !defined(NDEBUG)
bool IsRectCompletelyInsideRect ( const RectFloat& parInner, const RectFloat& parOuter ) __attribute__((pure));
bool IsRectCompletelyInsideRect ( const RectFloat& parInner, const RectFloat& parOuter ) a_pure;
#endif
///----------------------------------------------------------------------

View file

@ -21,11 +21,12 @@
#include "texture.hpp"
#include "sdlmain.hpp"
#include "sizeratio.hpp"
#include "compatibility.h"
#include <cassert>
namespace cloonel {
namespace {
float2 CountTilesInScreen ( const ushort2& parScreenSize, const ushort2& parTileSize ) __attribute__((pure));
float2 CountTilesInScreen ( const ushort2& parScreenSize, const ushort2& parTileSize ) a_pure;
///----------------------------------------------------------------------
///----------------------------------------------------------------------

View file

@ -20,6 +20,7 @@
#ifndef idid0528646832E04CF08E9785B66CFE0BD1
#define idid0528646832E04CF08E9785B66CFE0BD1
#include "compatibility.h"
#include <cstdint>
#include <ciso646>
#include <type_traits>
@ -73,45 +74,45 @@ namespace cloonel {
};
template <typename T, typename U, uint32_t S>
Vector<typename std::common_type<T, U>::type, S> operator+ ( Vector<T, S> parA, const Vector<U, S>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator+ ( Vector<T, S> parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
Vector<typename std::common_type<T, U>::type, S> operator- ( Vector<T, S> parA, const Vector<U, S>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator- ( Vector<T, S> parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
Vector<typename std::common_type<T, U>::type, S> operator* ( Vector<T, S> parA, const Vector<U, S>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator* ( Vector<T, S> parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
Vector<typename std::common_type<T, U>::type, S> operator/ ( Vector<T, S> parA, const Vector<U, S>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator/ ( Vector<T, S> parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator+ ( U parA, const Vector<T, S>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator+ ( U parA, const Vector<T, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator- ( U parA, const Vector<T, S>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator- ( U parA, const Vector<T, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator* ( U parA, const Vector<T, S>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator* ( U parA, const Vector<T, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator/ ( U parA, const Vector<T, S>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator/ ( U parA, const Vector<T, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator+ ( const Vector<T, S>& parA, U parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator+ ( const Vector<T, S>& parA, U parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator- ( const Vector<T, S>& parA, U parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator- ( const Vector<T, S>& parA, U parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator* ( const Vector<T, S>& parA, U parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator* ( const Vector<T, S>& parA, U parB ) a_pure;
template <typename T, typename U, uint32_t S, typename=typename std::enable_if<std::is_fundamental<U>::value>::type>
Vector<typename std::common_type<T, U>::type, S> operator/ ( const Vector<T, S>& parA, U parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, S> operator/ ( const Vector<T, S>& parA, U parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator< ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
bool operator< ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator> ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
bool operator> ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator<= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
bool operator<= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator>= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
bool operator>= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator== ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
bool operator== ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U, uint32_t S>
bool operator!= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
bool operator!= ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, uint32_t S>
Vector<T, S> operator- ( Vector<T, S> parOperand ) __attribute__((pure));
Vector<T, S> operator- ( Vector<T, S> parOperand ) a_pure;
typedef Vector<float, 2> float2;
typedef Vector<uint16_t, 2> ushort2;

View file

@ -21,21 +21,22 @@
#define id5DB098DAA5534A0A869DEF23888F96B0
#include "vector.hpp"
#include "compatibility.h"
#include <type_traits>
#include <cstdint>
#include <cmath>
namespace cloonel {
template <typename T, typename U, uint32_t S>
typename std::common_type<T, U>::type dot ( const Vector<T, S>& parA, const Vector<U, S>& parB ) __attribute__((pure));
typename std::common_type<T, U>::type dot ( const Vector<T, S>& parA, const Vector<U, S>& parB ) a_pure;
template <typename T, typename U>
Vector<typename std::common_type<T, U>::type, 3> cross ( const Vector<T, 3>& parA, const Vector<U, 3>& parB ) __attribute__((pure));
Vector<typename std::common_type<T, U>::type, 3> cross ( const Vector<T, 3>& parA, const Vector<U, 3>& parB ) a_pure;
template <typename T, uint32_t S>
T len ( const Vector<T, S>& parVector ) __attribute__((pure));
T len ( const Vector<T, S>& parVector ) a_pure;
template <typename T, uint32_t S>
T len_sq ( const Vector<T, S>& parVector ) __attribute__((pure));
T len_sq ( const Vector<T, S>& parVector ) a_pure;
template <typename T, uint32_t S>
Vector<T, S> normalized ( const Vector<T, S>& parVector ) __attribute__((pure));
Vector<T, S> normalized ( const Vector<T, S>& parVector ) a_pure;
} //namespace cloonel
#include "vectormath.inl"