refactor(declarations): also generate prototypes for functions in headers

Before this change, "static inline" functions in headers needed to have
their function attributes specified in a completely different way. The
prototype had to be duplicated, and REAL_FATTR_ had to be used instead
of the public FUNC_ATTR_ names.

TODO: need a check that a "header.h.inline.generated.h" file is not
forgotten when the first "static inline" function with attributes
is added to a header (they would just be silently missing).
This commit is contained in:
bfredl
2024-06-13 12:00:58 +02:00
parent b0f39f3ef5
commit 7dffc36e61
20 changed files with 187 additions and 245 deletions

View File

@@ -2,9 +2,12 @@
#include <stdbool.h>
#include "nvim/func_attr.h"
#include "nvim/os/os_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ascii_defs.h.inline.generated.h"
#endif
// Definitions of various common control characters.
#define CHAR_ORD(x) ((uint8_t)(x) < 'a' \
@@ -82,31 +85,24 @@
# define PATHSEPSTR "/"
#endif
static inline bool ascii_iswhite(int c)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Checks if `c` is a space or tab character.
///
/// @see {ascii_isdigit}
static inline bool ascii_iswhite(int c)
FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
{
return c == ' ' || c == '\t';
}
static inline bool ascii_iswhite_or_nul(int c)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Checks if `c` is a space or tab character or NUL.
///
/// @see {ascii_isdigit}
static inline bool ascii_iswhite_or_nul(int c)
FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
{
return ascii_iswhite(c) || c == NUL;
}
static inline bool ascii_isdigit(int c)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Check whether character is a decimal digit.
///
/// Library isdigit() function is officially locale-dependent and, for
@@ -117,64 +113,55 @@ static inline bool ascii_isdigit(int c)
/// what may be used for some optimizations (e.g. simple `return
/// isdigit_table[c];`).
static inline bool ascii_isdigit(int c)
FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
{
return c >= '0' && c <= '9';
}
static inline bool ascii_isxdigit(int c)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Checks if `c` is a hexadecimal digit, that is, one of 0-9, a-f, A-F.
///
/// @see {ascii_isdigit}
static inline bool ascii_isxdigit(int c)
FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
{
return (c >= '0' && c <= '9')
|| (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F');
}
static inline bool ascii_isident(int c)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Checks if `c` is an “identifier” character
///
/// That is, whether it is alphanumeric character or underscore.
static inline bool ascii_isident(int c)
FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
{
return ASCII_ISALNUM(c) || c == '_';
}
static inline bool ascii_isbdigit(int c)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Checks if `c` is a binary digit, that is, 0-1.
///
/// @see {ascii_isdigit}
static inline bool ascii_isbdigit(int c)
FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
{
return (c == '0' || c == '1');
}
static inline bool ascii_isodigit(int c)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Checks if `c` is an octal digit, that is, 0-7.
///
/// @see {ascii_isdigit}
static inline bool ascii_isodigit(int c)
FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
{
return (c >= '0' && c <= '7');
}
static inline bool ascii_isspace(int c)
REAL_FATTR_CONST
REAL_FATTR_ALWAYS_INLINE;
/// Checks if `c` is a white-space character, that is,
/// one of \f, \n, \r, \t, \v.
///
/// @see {ascii_isdigit}
static inline bool ascii_isspace(int c)
FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
{
return (c >= 9 && c <= 13) || c == ' ';
}