diff options
author | ZyX <kp-pav@ya.ru> | 2014-05-10 17:24:13 +0400 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-06-02 11:04:17 -0300 |
commit | 70929f7e1616bab2783cc5735c6061981cda8a0f (patch) | |
tree | 4a947af96fa0bac749f843a41e7b6593dd2659c0 /src/nvim/func_attr.h | |
parent | 880957ad4e3fc0ff681025f5e29c5eccf797c564 (diff) | |
download | rneovim-70929f7e1616bab2783cc5735c6061981cda8a0f.tar.gz rneovim-70929f7e1616bab2783cc5735c6061981cda8a0f.tar.bz2 rneovim-70929f7e1616bab2783cc5735c6061981cda8a0f.zip |
Add automatic generation of headers
- The 'stripdecls.py' script replaces declarations in all headers by includes to
generated headers.
`ag '#\s*if(?!ndef NEOVIM_).*((?!#\s*endif).*\n)*#ifdef INCLUDE_GENERATED'`
was used for this.
- Add and integrate gendeclarations.lua into the build system to generate the
required includes.
- Add -Wno-unused-function
- Made a bunch of old-style definitions ANSI
This adds a requirement: all type and structure definitions must be present
before INCLUDE_GENERATED_DECLARATIONS-protected include.
Warning: mch_expandpath (path.h.generated.h) was moved manually. So far it is
the only exception.
Diffstat (limited to 'src/nvim/func_attr.h')
-rw-r--r-- | src/nvim/func_attr.h | 191 |
1 files changed, 128 insertions, 63 deletions
diff --git a/src/nvim/func_attr.h b/src/nvim/func_attr.h index 6e7149e8fb..68384e1b61 100644 --- a/src/nvim/func_attr.h +++ b/src/nvim/func_attr.h @@ -1,5 +1,20 @@ -#ifndef NVIM_FUNC_ATTR_H -#define NVIM_FUNC_ATTR_H +// If DEFINE_FUNC_ATTRIBUTES macro is not defined then all function attributes +// are defined as empty values. +// +// If DO_NOT_DEFINE_EMPTY_ATTRIBUTES then empty macros are not defined. Thus +// undefined DEFINE_FUNC_ATTRIBUTES and defined DO_NOT_DEFINE_EMPTY_ATTRIBUTES +// leaves file with untouched FUNC_ATTR_* macros. This variant is used for +// scripts/gendeclarations.lua. +// +// Empty macros are used for *.c files. (undefined DEFINE_FUNC_ATTRIBUTES and +// undefined DO_NOT_DEFINE_EMPTY_ATTRIBUTES) +// +// Macros defined as __attribute__((*)) are used by generated header files. +// (defined DEFINE_FUNC_ATTRIBUTES and undefined +// DO_NOT_DEFINE_EMPTY_ATTRIBUTES) +// +// Defined DEFINE_FUNC_ATTRIBUTES and defined DO_NOT_DEFINE_EMPTY_ATTRIBUTES is +// not used by anything. // gcc and clang expose their version as follows: // @@ -21,90 +36,140 @@ // $ gcc -E -dM - </dev/null // $ echo | clang -dM -E - -#ifdef __GNUC__ - // place defines for all gnulikes here, for now that's gcc, clang and - // intel. - - // place these after the argument list of the function declaration - // (not definition), like so: - // void myfunc(void) FUNC_ATTR_ALWAYS_INLINE; - #define FUNC_ATTR_MALLOC __attribute__((malloc)) - #define FUNC_ATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x))) - #define FUNC_ATTR_PURE __attribute__ ((pure)) - #define FUNC_ATTR_CONST __attribute__((const)) - #define FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) - #define FUNC_ATTR_ALWAYS_INLINE __attribute__((always_inline)) - #define FUNC_ATTR_UNUSED __attribute__((unused)) - - #ifdef __clang__ - // clang only - #elif defined(__INTEL_COMPILER) - // intel only - #else - #define GCC_VERSION \ - (__GNUC__ * 10000 + \ - __GNUC_MINOR__ * 100 + \ - __GNUC_PATCHLEVEL__) - // gcc only - #define FUNC_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x))) - #define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) __attribute__((alloc_size(x,y))) - #define FUNC_ATTR_NONNULL_ALL __attribute__((nonnull)) - #define FUNC_ATTR_NONNULL_ARG(...) __attribute__((nonnull(__VA_ARGS__))) - #if GCC_VERSION >= 40900 - #define FUNC_ATTR_NONNULL_RET __attribute__((returns_nonnull)) - #endif - #endif +#ifdef FUNC_ATTR_MALLOC + #undef FUNC_ATTR_MALLOC #endif -// define function attributes that haven't been defined for this specific -// compiler. - -#ifndef FUNC_ATTR_MALLOC - #define FUNC_ATTR_MALLOC +#ifdef FUNC_ATTR_ALLOC_SIZE + #undef FUNC_ATTR_ALLOC_SIZE #endif -#ifndef FUNC_ATTR_ALLOC_SIZE - #define FUNC_ATTR_ALLOC_SIZE(x) +#ifdef FUNC_ATTR_ALLOC_SIZE_PROD + #undef FUNC_ATTR_ALLOC_SIZE_PROD #endif -#ifndef FUNC_ATTR_ALLOC_SIZE_PROD - #define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) +#ifdef FUNC_ATTR_ALLOC_ALIGN + #undef FUNC_ATTR_ALLOC_ALIGN #endif -#ifndef FUNC_ATTR_ALLOC_ALIGN - #define FUNC_ATTR_ALLOC_ALIGN(x) +#ifdef FUNC_ATTR_PURE + #undef FUNC_ATTR_PURE #endif -#ifndef FUNC_ATTR_PURE - #define FUNC_ATTR_PURE +#ifdef FUNC_ATTR_CONST + #undef FUNC_ATTR_CONST #endif -#ifndef FUNC_ATTR_CONST - #define FUNC_ATTR_CONST +#ifdef FUNC_ATTR_WARN_UNUSED_RESULT + #undef FUNC_ATTR_WARN_UNUSED_RESULT #endif -#ifndef FUNC_ATTR_WARN_UNUSED_RESULT - #define FUNC_ATTR_WARN_UNUSED_RESULT +#ifdef FUNC_ATTR_ALWAYS_INLINE + #undef FUNC_ATTR_ALWAYS_INLINE #endif -#ifndef FUNC_ATTR_ALWAYS_INLINE - #define FUNC_ATTR_ALWAYS_INLINE +#ifdef FUNC_ATTR_UNUSED + #undef FUNC_ATTR_UNUSED #endif -#ifndef FUNC_ATTR_UNUSED - #define FUNC_ATTR_UNUSED +#ifdef FUNC_ATTR_NONNULL_ALL + #undef FUNC_ATTR_NONNULL_ALL #endif -#ifndef FUNC_ATTR_NONNULL_ALL - #define FUNC_ATTR_NONNULL_ALL +#ifdef FUNC_ATTR_NONNULL_ARG + #undef FUNC_ATTR_NONNULL_ARG #endif -#ifndef FUNC_ATTR_NONNULL_ARG - #define FUNC_ATTR_NONNULL_ARG(...) +#ifdef FUNC_ATTR_NONNULL_RET + #undef FUNC_ATTR_NONNULL_RET #endif -#ifndef FUNC_ATTR_NONNULL_RET - #define FUNC_ATTR_NONNULL_RET +#ifdef DEFINE_FUNC_ATTRIBUTES + #ifdef __GNUC__ + // place defines for all gnulikes here, for now that's gcc, clang and + // intel. + + // place these after the argument list of the function declaration + // (not definition), like so: + // void myfunc(void) FUNC_ATTR_ALWAYS_INLINE; + #define FUNC_ATTR_MALLOC __attribute__((malloc)) + #define FUNC_ATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x))) + #define FUNC_ATTR_PURE __attribute__ ((pure)) + #define FUNC_ATTR_CONST __attribute__((const)) + #define FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) + #define FUNC_ATTR_ALWAYS_INLINE __attribute__((always_inline)) + #define FUNC_ATTR_UNUSED __attribute__((unused)) + + #ifdef __clang__ + // clang only + #elif defined(__INTEL_COMPILER) + // intel only + #else + #define GCC_VERSION \ + (__GNUC__ * 10000 + \ + __GNUC_MINOR__ * 100 + \ + __GNUC_PATCHLEVEL__) + // gcc only + #define FUNC_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x))) + #define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) __attribute__((alloc_size(x,y))) + #define FUNC_ATTR_NONNULL_ALL __attribute__((nonnull)) + #define FUNC_ATTR_NONNULL_ARG(...) __attribute__((nonnull(__VA_ARGS__))) + #if GCC_VERSION >= 40900 + #define FUNC_ATTR_NONNULL_RET __attribute__((returns_nonnull)) + #endif + #endif + #endif #endif -#endif // NVIM_FUNC_ATTR_H +#ifndef DO_NOT_DEFINE_EMPTY_ATTRIBUTES + // define function attributes that haven't been defined for this specific + // compiler. + + #ifndef FUNC_ATTR_MALLOC + #define FUNC_ATTR_MALLOC + #endif + + #ifndef FUNC_ATTR_ALLOC_SIZE + #define FUNC_ATTR_ALLOC_SIZE(x) + #endif + + #ifndef FUNC_ATTR_ALLOC_SIZE_PROD + #define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) + #endif + + #ifndef FUNC_ATTR_ALLOC_ALIGN + #define FUNC_ATTR_ALLOC_ALIGN(x) + #endif + + #ifndef FUNC_ATTR_PURE + #define FUNC_ATTR_PURE + #endif + + #ifndef FUNC_ATTR_CONST + #define FUNC_ATTR_CONST + #endif + + #ifndef FUNC_ATTR_WARN_UNUSED_RESULT + #define FUNC_ATTR_WARN_UNUSED_RESULT + #endif + + #ifndef FUNC_ATTR_ALWAYS_INLINE + #define FUNC_ATTR_ALWAYS_INLINE + #endif + + #ifndef FUNC_ATTR_UNUSED + #define FUNC_ATTR_UNUSED + #endif + + #ifndef FUNC_ATTR_NONNULL_ALL + #define FUNC_ATTR_NONNULL_ALL + #endif + + #ifndef FUNC_ATTR_NONNULL_ARG + #define FUNC_ATTR_NONNULL_ARG(...) + #endif + + #ifndef FUNC_ATTR_NONNULL_RET + #define FUNC_ATTR_NONNULL_RET + #endif +#endif |