Skip to content

Commit ed855e6

Browse files
committed
Merge pull request #467 from PeterMitsis/toolchain
Abstract toolchain capabilities
2 parents 02fc2b2 + 9bbebfc commit ed855e6

File tree

16 files changed

+377
-160
lines changed

16 files changed

+377
-160
lines changed

code/ai/aiturret.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ void turret_ai_update_aim(ai_info *aip, object *En_Objp, ship_subsys *ss)
13771377
*/
13781378
int aifft_rotate_turret(ship *shipp, int parent_objnum, ship_subsys *ss, object *objp, object *lep, vec3d *predicted_enemy_pos, vec3d *gvec)
13791379
{
1380-
int ret_val __attribute__((__unused__)) = 0; // to be used in future, see comment @ end of function
1380+
int ret_val __UNUSED = 0; // to be used in future, see comment @ end of function
13811381

13821382
if (ss->turret_enemy_objnum != -1) {
13831383
model_subsystem *tp = ss->system_info;

code/freespace2/freespace.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ void game_loading_callback_close()
12651265
// Make sure bar shows all the way over.
12661266
game_loading_callback(COUNT_ESTIMATE);
12671267

1268-
int real_count __attribute__((__unused__)) = game_busy_callback( NULL );
1268+
int real_count __UNUSED = game_busy_callback( NULL );
12691269
Mouse_hidden = 0;
12701270

12711271
Game_loading_callback_inited = 0;
@@ -1429,7 +1429,7 @@ int game_start_mission()
14291429
{
14301430
mprintf(( "=================== STARTING LEVEL LOAD ==================\n" ));
14311431

1432-
int s1 __attribute__((__unused__)) = timer_get_milliseconds();
1432+
int s1 __UNUSED = timer_get_milliseconds();
14331433

14341434
// clear post processing settings
14351435
gr_post_process_set_defaults();
@@ -1486,7 +1486,7 @@ int game_start_mission()
14861486

14871487
bm_print_bitmaps();
14881488

1489-
int e1 __attribute__((__unused__)) = timer_get_milliseconds();
1489+
int e1 __UNUSED = timer_get_milliseconds();
14901490

14911491
mprintf(("Level load took %f seconds.\n", (e1 - s1) / 1000.0f ));
14921492

@@ -1745,7 +1745,7 @@ char full_path[1024];
17451745
*/
17461746
void game_init()
17471747
{
1748-
int s1 __attribute__((__unused__)), e1 __attribute__((__unused__));
1748+
int s1 __UNUSED, e1 __UNUSED;
17491749
const char *ptr;
17501750
char whee[MAX_PATH_LEN];
17511751

code/fs2netd/fs2netd_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static void fs2netd_handle_messages()
737737

738738
case PCKT_SLIST_REPLY: {
739739
int numServers = 0;
740-
int svr_flags __attribute__((__unused__)); // gcc [-Wunused-but-set-variable] doesn't like MACROs
740+
int svr_flags __UNUSED; // gcc [-Wunused-but-set-variable] doesn't like MACROs
741741
ushort svr_port;
742742
char svr_ip[16];
743743
active_game ag;

code/fs2netd/tcp_client.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ int FS2NetD_GetPlayerData(const char *player_name, player *pl, bool can_create,
218218
uint rc_total = 0;
219219
ubyte reply_type = 0;
220220
int si_index = 0;
221-
ushort bogus __attribute__((unused));
221+
ushort bogus __UNUSED;
222222
ushort num_type_kills = 0, num_medals = 0;
223223
char ship_name[NAME_LENGTH];
224224
int idx;
@@ -489,8 +489,8 @@ int FS2NetD_Login(const char *username, const char *password, bool do_send)
489489
int rc;
490490
uint rc_total = 0;
491491
ubyte login_status = 0;
492-
int sid __attribute__((unused));
493-
short pilots __attribute__((unused));
492+
int sid __UNUSED;
493+
short pilots __UNUSED;
494494

495495
do {
496496
rc = FS2NetD_GetData(buffer+rc_total, sizeof(buffer)-rc_total);

code/globalincs/pstypes.h

Lines changed: 1 addition & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <stdlib.h>
1818
#include <memory.h>
1919
#include <string.h>
20+
#include "globalincs/toolchain.h"
2021

2122
#if defined( __x86_64__ ) || defined( _WIN64 )
2223
#define IAM_64BIT 1
@@ -63,39 +64,6 @@ typedef unsigned short ushort;
6364
typedef unsigned int uint;
6465
typedef unsigned long ulong;
6566

66-
// Format specifier macros
67-
#ifdef DOXYGEN
68-
// Documentation macros, only used by DOXYGEN
69-
/**
70-
* @brief Identifies a printf-style format string
71-
*/
72-
#define SCP_FORMAT_STRING
73-
74-
/**
75-
* @brief Specifies which arguments are involved in printf-style string formatting
76-
*
77-
* @details Expands to a compiler specific attribute which specify where the
78-
* format arguments are located. Parameters are 1-based which also includes
79-
* the 'this' parameter at position 1 for class methods.
80-
*
81-
* @param formatArg The location of the format string argument in the argument list
82-
* @param varArgs The location where the variable arguments begin
83-
*/
84-
#define SCP_FORMAT_STRING_ARGS(formatArg, varArgs)
85-
#elif defined(_MSC_VER)
86-
#include <sal.h>
87-
88-
#define SCP_FORMAT_STRING _Printf_format_string_
89-
#define SCP_FORMAT_STRING_ARGS(x, y)
90-
#elif defined(__GNUC__) || defined(__clang__)
91-
// GCC and clang use function attributes
92-
#define SCP_FORMAT_STRING
93-
#define SCP_FORMAT_STRING_ARGS(x, y) __attribute__ ((format (printf, x, y)))
94-
#else
95-
#define SCP_FORMAT_STRING
96-
#define SCP_FORMAT_STRING_ARGS(x, y)
97-
#endif
98-
9967
#define HARDWARE_ONLY
10068

10169
//Stucture to store clipping codes in a word
@@ -264,11 +232,6 @@ extern int Global_error_count;
264232

265233
#include "osapi/outwnd.h"
266234

267-
// remove __attribute__ on non-GCC compilers
268-
#ifndef __GNUC__
269-
# define __attribute__(x) /*NOTHING*/
270-
#endif
271-
272235
// To debug printf do this:
273236
// mprintf(( "Error opening %s\n", filename ));
274237
#ifndef NDEBUG
@@ -290,22 +253,10 @@ extern int Global_error_count;
290253
// Please never uncomment the functionality of Assert in debug
291254
// The code, as with all development like this is littered with Asserts which are designed to throw
292255
// up an error message if variables are out of range.
293-
294-
#define ASSUME(x)
295-
296256
// Disabling this functionality is dangerous, crazy values can run rampent unchecked and the longer its disabled
297257
// the more likely you are to have problems getting it working again.
298258
#if defined(NDEBUG)
299259
# define Assert(expr) do { ASSUME(expr); } while (0)
300-
# ifndef _MSC_VER // non MS compilers
301-
# define Assertion(expr, msg, ...) do {} while (0)
302-
# else
303-
# if _MSC_VER >= 1400 // VC 2005 or greater
304-
# define Assertion(expr, msg, ...) do { ASSUME(expr); } while (0)
305-
# else
306-
# define Assertion(expr, msg) do {} while (0)
307-
# endif
308-
# endif
309260
#else
310261
void gr_activate(int);
311262
# define Assert(expr) do {\
@@ -314,30 +265,6 @@ extern int Global_error_count;
314265
}\
315266
ASSUME( expr );\
316267
} while (0)
317-
318-
// Assertion can only use its proper fuctionality in compilers that support variadic macro
319-
# ifndef _MSC_VER // non MS compilers
320-
# define Assertion(expr, msg, ...) do {\
321-
if (!(expr)) {\
322-
WinAssert(#expr,__FILE__,__LINE__, msg , ##__VA_ARGS__ );\
323-
}\
324-
} while (0)
325-
# else
326-
# if _MSC_VER >= 1400 // VC 2005 or greater
327-
# define Assertion(expr, msg, ...) do {\
328-
if (!(expr)) {\
329-
WinAssert(#expr,__FILE__,__LINE__, msg, __VA_ARGS__ );\
330-
}\
331-
ASSUME(expr);\
332-
} while (0)
333-
# else // older MSVC compilers
334-
# define Assertion(expr, msg) do {\
335-
if (!(expr)) {\
336-
WinAssert(#expr,__FILE__,__LINE__);\
337-
}\
338-
} while (0)
339-
# endif
340-
# endif
341268
#endif
342269
/*******************NEVER COMMENT Assert ************************************************/
343270

@@ -693,79 +620,9 @@ class camid
693620
bool isValid();
694621
};
695622

696-
/* Restrict keyword semantics are different under VC and GCC */
697-
698-
#ifndef NO_RESTRICT_USE
699-
# ifdef _MSC_VER
700-
# if _MSC_VER >= 1400
701-
# define RESTRICT __restrict
702-
# else
703-
# define RESTRICT
704-
# endif
705-
# else
706-
# define RESTRICT restrict
707-
# endif
708-
#else
709-
# define RESTRICT
710-
#endif
711-
712623
#include "globalincs/vmallocator.h"
713624
#include "globalincs/safe_strings.h"
714625

715-
// Macros for portable printf argument specification
716-
#ifdef DOXYGEN
717-
// Special section for doxygen
718-
/**
719-
* @brief Format specifier for a @c size_t argument
720-
* Due to different runtimes using different format specifier for these types
721-
* it's necessary to hide these changes behind a macro. Use this in place of %zu
722-
*/
723-
#define SIZE_T_ARG
724-
/**
725-
* @brief Format specifier for a @c ptrdiff_t argument
726-
* Due to different runtimes using different format specifier for these types
727-
* it's necessary to hide these changes behind a macro. Use this in place of %zd
728-
*/
729-
#define PTRDIFF_T_ARG
730-
#elif defined(_MSC_VER)
731-
#define SIZE_T_ARG "%Iu"
732-
#define PTRDIFF_T_ARG "%Id"
733-
#else
734-
// Asume C99 compatibility for everyone else
735-
#define SIZE_T_ARG "%zu"
736-
#define PTRDIFF_T_ARG "%zd"
737-
#endif
738-
739-
// c++11 standard detection
740-
// for GCC with autotools, see AX_CXX_COMPILE_STDCXX_11 macro in configure.ac
741-
// this sets HAVE_CXX11 & -std=c++0x or -std=c++11 appropriately
742-
743-
#ifndef HAVE_CXX11
744-
// Use the visual studio version to detect C++11 support
745-
#if _MSC_VER >= 1600
746-
# define HAVE_CXX11
747-
#endif
748-
// clang doesn't seem to have a feature check for is_trivial
749-
// oh well, assume it'll be covered by one of the other two checks...
750-
// http://clang.llvm.org/docs/LanguageExtensions.html#feature_check
751-
#if defined(__clang__)
752-
#if __has_feature(cxx_static_assert)
753-
#if __has_feature(cxx_auto_type)
754-
#define HAVE_CXX11
755-
#endif // __has_feature(cxx_auto_type)
756-
#endif // __has_feature(cxx_static_assert)
757-
#endif // defined(__clang__)
758-
// TODO: sort out cmake/gcc
759-
#endif // HAVE_CXX11
760-
761-
// In compilers before VS 2015, the noexcept keyword isn't defined. Nonetheless, we need to define it in VS 2015 and non-MS compilers.
762-
#if defined(_MSC_VER) && _MSC_VER < 1900
763-
# define NOEXCEPT
764-
#else
765-
# define NOEXCEPT noexcept
766-
#endif
767-
768-
769626
// DEBUG compile time catch for dangerous uses of memset/memcpy/memmove
770627
// would prefer std::is_trivially_copyable but it's not supported by gcc yet
771628
// ref: http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html

code/globalincs/toolchain.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) Volition, Inc. 1999. All rights reserved.
3+
*
4+
* All source code herein is the property of Volition, Inc. You may not sell
5+
* or otherwise commercially exploit the source or things you created based on
6+
* the source.
7+
*/
8+
9+
/**
10+
* @file
11+
*
12+
* @brief Macros to abstract compiler capabilities for various toolchains
13+
*/
14+
15+
#ifndef _TOOLCHAIN_H
16+
#define _TOOLCHAIN_H
17+
18+
#if defined(DOXYGEN)
19+
# include "globalincs/toolchain/doxygen.h"
20+
#elif defined(__MINGW32__)
21+
# include "globalincs/toolchain/mingw.h"
22+
#elif defined(__clang__)
23+
# include "globalincs/toolchain/clang.h"
24+
#elif defined(__GNUC__)
25+
# include "globalincs/toolchain/gcc.h"
26+
#elif defined(_MSC_VER)
27+
# include "globalincs/toolchain/msvc.h"
28+
#else
29+
# error "Unknown toolchain detected!\n" \
30+
"Currently supported toolchains include:\n" \
31+
"\tMingW, Clang, GCC, MSVC\n" \
32+
"Update toolchain.h to add support for additional toolchains.\n"
33+
#endif
34+
35+
#endif /* _TOOLCHAIN_H */

code/globalincs/toolchain/clang.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (C) Volition, Inc. 1999. All rights reserved.
3+
*
4+
* All source code herein is the property of Volition, Inc. You may not sell
5+
* or otherwise commercially exploit the source or things you created based on
6+
* the source.
7+
*/
8+
9+
/**
10+
* @file
11+
*
12+
* @brief Macros to abstract compiler capabilities for the Clang toolchain
13+
*
14+
* @internal
15+
* This file should never be included directly; instead, one should
16+
* include toolchain.h which will pull in the file appropriate to
17+
* the detected toolchain.
18+
*/
19+
20+
#define SCP_FORMAT_STRING
21+
#define SCP_FORMAT_STRING_ARGS(x,y) __attribute__((format(printf, x, y)))
22+
23+
#define __UNUSED __attribute__((__unused__))
24+
#define __ALIGNED(x) __attribute__((__aligned__(x)))
25+
26+
#ifdef NO_RESTRICT_USE
27+
# define RESTRICT
28+
#else
29+
# define RESTRICT restrict
30+
#endif
31+
32+
#define ASSUME(x)
33+
34+
#if defined(NDEBUG)
35+
# define Assertion(expr, msg, ...) do { } while (0)
36+
#else
37+
/*
38+
* NOTE: Assertion() can only use its proper functionality in compilers
39+
* that support variadic macros.
40+
*/
41+
# define Assertion(expr, msg, ...) \
42+
do { \
43+
if (!(expr)) { \
44+
WinAssert(#expr, __FILE__, __LINE__, msg, ##__VA_ARGS__); \
45+
} \
46+
} while (0)
47+
#endif
48+
49+
/* C++11 Standard Detection */
50+
#if !defined(HAVE_CXX11)
51+
/*
52+
* Clang does not seem to have a feature check for 'is_trivial'.
53+
* Assume it will be covered by one of the following checks ...
54+
* http://clang.llvm.org/docs/LanguageExtensions.html#feature_check
55+
*/
56+
# if __has_feature(cxx_static_assert) && __has_feature(cxx_auto_type)
57+
# define HAVE_CXX11
58+
# endif
59+
#endif
60+
61+
#define SIZE_T_ARG "%zu"
62+
#define PTRDIFF_T_ARG "%zd"
63+
64+
#define NOEXCEPT noexcept
65+
66+
#define likely(x) __builtin_expect((long) !!(x), 1L)
67+
#define unlikely(x) __builtin_expect((long) !!(x), 0L)

0 commit comments

Comments
 (0)