move utility macros to picrin/util.h

This commit is contained in:
Yuichi Nishiwaki 2014-03-19 17:43:53 +09:00
parent ef7d01971b
commit 8625f75470
2 changed files with 41 additions and 24 deletions

View File

@ -39,31 +39,8 @@ extern "C" {
#include "xfile/xfile.h"
#include "xrope/xrope.h"
#if __STDC_VERSION__ >= 201112L
# define noreturn _Noreturn
#elif __GNUC__ || __clang__
# define noreturn __attribute__((noreturn))
#endif
#define FALLTHROUGH ((void)0)
#define UNUSED(v) ((void)(v))
#define GENSYM2__(x,y) x##y
#define GENSYM1__(x,y) GENSYM2__(x,y)
#if defined(__COUNTER__)
# define GENSYM(x) GENSYM1__(x,__COUNTER__)
#else
# define GENSYM(x) GENSYM1__(x,__LINE__)
#endif
#if __GNUC__ || __clang__
# define UNREACHABLE() (__builtin_unreachable())
#else
# include <assert.h>
# define UNREACHABLE() (assert(false))
#endif
#include "config.h"
#include "picrin/util.h"
#include "picrin/value.h"
typedef struct pic_code pic_code;

40
include/picrin/util.h Normal file
View File

@ -0,0 +1,40 @@
/**
* See Copyright Notice in picrin.h
*/
#ifndef PICRIN_UTIL_H__
#define PICRIN_UTIL_H__
#if defined(__cplusplus)
extern "C" {
#endif
#if __STDC_VERSION__ >= 201112L
# define noreturn _Noreturn
#elif __GNUC__ || __clang__
# define noreturn __attribute__((noreturn))
#endif
#define FALLTHROUGH ((void)0)
#define UNUSED(v) ((void)(v))
#define GENSYM2__(x,y) x##y
#define GENSYM1__(x,y) GENSYM2__(x,y)
#if defined(__COUNTER__)
# define GENSYM(x) GENSYM1__(x,__COUNTER__)
#else
# define GENSYM(x) GENSYM1__(x,__LINE__)
#endif
#if __GNUC__ || __clang__
# define UNREACHABLE() (__builtin_unreachable())
#else
# include <assert.h>
# define UNREACHABLE() (assert(false))
#endif
#if defined(__cplusplus)
}
#endif
#endif