remove annotations header

The annotations were never particularly robust, and weren't used in many
locations (or consistently). And we should be migrating to c++14
annotation syntax anyway. By focusing on writing them all locally we
will be a little more standards compliant, and the attributes should be
more visible.
This commit is contained in:
Danny Robson 2014-10-17 19:24:53 +11:00
parent abfe4daac3
commit 23b0a7b146
8 changed files with 23 additions and 77 deletions

View File

@ -12,7 +12,6 @@ SUBDIRS = test
## Source definitions ## Source definitions
UTIL_FILES = \ UTIL_FILES = \
annotations.hpp \
backtrace.hpp \ backtrace.hpp \
bitwise.cpp \ bitwise.cpp \
bitwise.hpp \ bitwise.hpp \

View File

@ -1,44 +0,0 @@
/*
* This file is part of libgim.
*
* libgim 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.
*
* ligim 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 libgim. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2010-2012 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __ANNOTATIONS_HPP
#define __ANNOTATIONS_HPP
// Don't use the name 'noreturn' as it interferes with other headers which
// may use __attribute__((noreturn)) explicitly.
#define terminal __attribute__ ((noreturn))
#if GCC_VERSION >= 40601
#define nonnull __attribute__ ((nonnull))
#endif
#define mustuse __attribute__ ((warn_unused_result))
#if GCC_VERSION >= 40601
#define unused __attribute__ ((unused))
#endif
#define pure __attribute__ ((pure))
#define likely(X) (__builtin_expect((X), 1))
#define unlikely(X) (__builtin_expect((X), 0))
#endif // __ANNOTATIONS_HPP

View File

@ -20,8 +20,6 @@
#ifndef __DEBUG_HPP #ifndef __DEBUG_HPP
#define __DEBUG_HPP #define __DEBUG_HPP
#include "annotations.hpp"
#include "maths.hpp" #include "maths.hpp"
#include <stdexcept> #include <stdexcept>
@ -79,7 +77,7 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define _CHECK_META(C, SUCCESS, FAILURE) do { \ #define _CHECK_META(C, SUCCESS, FAILURE) do { \
const auto __DEBUG_value = (C); \ const auto __DEBUG_value = (C); \
if (unlikely (!__DEBUG_value)) { \ if (!__DEBUG_value) { \
std::cerr << PACKAGE << ": " \ std::cerr << PACKAGE << ": " \
<< __FILE__ << ":" \ << __FILE__ << ":" \
<< __LINE__ << ": " \ << __LINE__ << ": " \
@ -221,7 +219,7 @@
catch (E) \ catch (E) \
{ caught = true; } \ { caught = true; } \
\ \
if (unlikely (!caught)) \ if (!caught) \
panic ("expected exception: " #E); \ panic ("expected exception: " #E); \
} while (0) } while (0)
@ -248,19 +246,19 @@ class panic_error {
}; };
void panic (const std::string&) terminal; void panic [[noreturn]] (const std::string&);
void panic (void) terminal; void panic [[noreturn]] (void);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void not_implemented (void) terminal; void not_implemented [[noreturn]] (void);
void not_implemented (const char*) terminal; void not_implemented [[noreturn]] (const char*);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void unreachable (void) terminal; void unreachable [[noreturn]] (void);
void unreachable (const std::string&) terminal; void unreachable [[noreturn]] (const std::string&);
void unusual (void); void unusual (void);
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

3
io.hpp
View File

@ -20,7 +20,6 @@
#ifndef __UTIL_IO_HPP #ifndef __UTIL_IO_HPP
#define __UTIL_IO_HPP #define __UTIL_IO_HPP
#include "annotations.hpp"
#include "types.hpp" #include "types.hpp"
#include "memory.hpp" #include "memory.hpp"
@ -41,7 +40,7 @@ namespace util {
/// Reads an entire file into memory. Caller frees the result. Guarantees a /// Reads an entire file into memory. Caller frees the result. Guarantees a
/// null trailing byte. /// null trailing byte.
std::unique_ptr<char []> std::unique_ptr<char []>
slurp (const boost::filesystem::path&) mustuse; slurp [[gnu::warn_unused_result]] (const boost::filesystem::path&);
void void
write (const boost::filesystem::path &, const char *data, size_t len); write (const boost::filesystem::path &, const char *data, size_t len);

View File

@ -20,8 +20,6 @@
#ifndef __MATHS_HPP #ifndef __MATHS_HPP
#define __MATHS_HPP #define __MATHS_HPP
#include "annotations.hpp"
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@ -33,42 +31,42 @@ pow2 (T value)
template <typename T> template <typename T>
bool bool
is_pow2 (T value) pure; is_pow2 [[gnu::pure]] (T value);
template <typename T> template <typename T>
T T
log2 (T val) pure; log2 [[gnu::pure]] (T val);
template <typename T> template <typename T>
T T
log2up (T val) pure; log2up [[gnu::pure]] (T val);
template <typename T> template <typename T>
double double
rootsquare (T a, T b) pure; rootsquare [[gnu::pure]] (T a, T b);
template <typename T, typename U> template <typename T, typename U>
typename std::common_type<T, U>::type typename std::common_type<T, U>::type
align (T value, U size) pure; align [[gnu::pure]] (T value, U size);
template <typename T> template <typename T>
T T
round_pow2 (T value) pure; round_pow2 [[gnu::pure]] (T value);
template <typename T> template <typename T>
bool bool
is_integer (const T& value) pure; is_integer [[gnu::pure]] (const T& value);
template <typename T> template <typename T>
unsigned unsigned
digits (const T& value) pure; digits [[gnu::pure]] (const T& value);
template <typename T, typename U> template <typename T, typename U>

View File

@ -30,8 +30,6 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#include "../annotations.hpp"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
namespace net { namespace net {
@ -47,14 +45,14 @@ namespace net {
/// Throw an error corresponding the a given code. Code must be a valid error code, /// Throw an error corresponding the a given code. Code must be a valid error code,
/// not success otherwise the application will (at best) abort. /// not success otherwise the application will (at best) abort.
static void static void
throw_code (int code) terminal; throw_code [[noreturn]] (int code);
/// Throw an error corresponding to the most recent error condition. This will check /// Throw an error corresponding to the most recent error condition. This will check
/// the current error condition in a platform agnostic manner, and pass on to /// the current error condition in a platform agnostic manner, and pass on to
/// throw_code(int). This should be used whenever an error has been detected, rather /// throw_code(int). This should be used whenever an error has been detected, rather
/// than the more normal try_code(errno) due to Windows error reporting quirks. /// than the more normal try_code(errno) due to Windows error reporting quirks.
static void static void
throw_code (void) terminal; throw_code [[noreturn]] (void);
static void static void
try_code (int code); try_code (int code);

View File

@ -20,7 +20,6 @@
#ifndef __UTIL_QUATERNION_HPP #ifndef __UTIL_QUATERNION_HPP
#define __UTIL_QUATERNION_HPP #define __UTIL_QUATERNION_HPP
#include "annotations.hpp"
#include "vector.hpp" #include "vector.hpp"
namespace util { namespace util {
@ -29,8 +28,8 @@ namespace util {
static const quaternion IDENTITY; static const quaternion IDENTITY;
static quaternion rotation (double radians, vector<3> axis) mustuse; static quaternion rotation (double radians, vector<3> axis);
static quaternion rotation (vector<3> from, vector<3> to) mustuse; static quaternion rotation (vector<3> from, vector<3> to);
quaternion operator* (const quaternion&) const; quaternion operator* (const quaternion&) const;
}; };

View File

@ -22,7 +22,6 @@
#include "json.hpp" #include "json.hpp"
#include "detail/coord.hpp" #include "detail/coord.hpp"
#include "annotations.hpp"
#include <array> #include <array>
#include <iostream> #include <iostream>
@ -71,7 +70,7 @@ namespace util {
double dot (const util::vector<S>&) const; double dot (const util::vector<S>&) const;
util::vector<S>& normalise (void); util::vector<S>& normalise (void);
util::vector<S> normalised (void) const mustuse; util::vector<S> normalised [[gnu::warn_unused_result]] (void) const;
bool is_zero (void) const; bool is_zero (void) const;