Skip to content

Commit

Permalink
Emit different pragmas for matches & matches99
Browse files Browse the repository at this point in the history
  • Loading branch information
hirrolot committed Aug 13, 2021
1 parent 0b761ee commit 8e5e21f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
52 changes: 29 additions & 23 deletions datatype99.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ SOFTWARE.
#define match match99
#define MATCHES MATCHES99
/// @deprecated Use `MATCHES` instead.
#define matches matches99
#define matches(val, tag_) \
DATATYPE99_PRIV_PRAGMA_WARN("GCC warning \"`matches` is deprecated, use `MATCHES` instead\"") \
MATCHES(val, tag_)
#define ifLet ifLet99
#define of of99
#define otherwise otherwise99
Expand Down Expand Up @@ -271,22 +273,10 @@ static const UnitT99 unit_v99 = '\0';
#define MATCHES99(val, tag_) ((val).tag == tag_##Tag)

/// @deprecated Use `MATCHES99` instead.
#define matches99(val, tag_) DATATYPE99_PRIV_DEPRECATE_MATCHES MATCHES99(val, tag_)

// Deprecate `matches99` {

#define DATATYPE99_PRIV_IS_GCC_4_8_1_OR_HIGHER \
((__GNUC__ == 4 && \
(__GNUC_MINOR__ >= 8 && __GNUC_PATCHLEVEL__ >= 1 || __GNUC_MINOR__ >= 9)) || \
__GNUC__ >= 5)

#if defined(__clang__) || DATATYPE99_PRIV_IS_GCC_4_8_1_OR_HIGHER
#define DATATYPE99_PRIV_DEPRECATE_MATCHES \
_Pragma("GCC warning \"`matches`/`matches99` are deprecated, use `MATCHES`/`MATCHES99`\"")
#else
#define DATATYPE99_PRIV_DEPRECATE_MATCHES
#endif
// } (Deprecate `matches99`)
#define matches99(val, tag_) \
DATATYPE99_PRIV_PRAGMA_WARN( \
"GCC warning \"`matches99` is deprecated, use `MATCHES99` instead\"") \
MATCHES99(val, tag_)

// } (Pattern matching)

Expand Down Expand Up @@ -399,23 +389,39 @@ static const UnitT99 unit_v99 = '\0';
#define DATATYPE99_PRIV_genRecordField_IMPL(ty, ident) v(ty ident;)

// Compiler-specific stuff {

#define DATATYPE99_PRIV_CTOR_ATTRS DATATYPE99_PRIV_WARN_UNUSED_RESULT DATATYPE99_PRIV_CONST

// DATATYPE99_PRIV_WARN_UNUSED_RESULT {
#if defined(__GNUC__)
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT
#endif
// }

// DATATYPE99_PRIV_CONST {
#if defined(__GNUC__) && !defined(__clang__)
#define DATATYPE99_PRIV_CONST __attribute__((const))
#else
#define DATATYPE99_PRIV_CONST
#endif
// }

#define DATATYPE99_PRIV_CTOR_ATTRS DATATYPE99_PRIV_WARN_UNUSED_RESULT DATATYPE99_PRIV_CONST
// DATATYPE99_PRIV_PRAGMA_WARN {

#ifndef DATATYPE99_PRIV_WARN_UNUSED_RESULT
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT
#endif
#define DATATYPE99_PRIV_IS_GCC_4_8_1_OR_HIGHER \
((__GNUC__ == 4 && \
(__GNUC_MINOR__ >= 8 && __GNUC_PATCHLEVEL__ >= 1 || __GNUC_MINOR__ >= 9)) || \
__GNUC__ >= 5)

#ifndef DATATYPE99_PRIV_CONST
#define DATATYPE99_PRIV_CONST
#if defined(__clang__) || DATATYPE99_PRIV_IS_GCC_4_8_1_OR_HIGHER
#define DATATYPE99_PRIV_PRAGMA_WARN _Pragma
#else
#define DATATYPE99_PRIV_PRAGMA_WARN ML99_EMPTY
#endif
// }

// } (Compiler-specific stuff)

// Arity specifiers {
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,8 @@ int main(void) {

UnitT dummy = unit_v;
(void)dummy;

// Probe.
(void)matches(a, A);
(void)matches99(a, A);
}

0 comments on commit 8e5e21f

Please sign in to comment.