Add support for #[deprecated].

Closes #875.
Closes #860.
Closes #408.
This commit is contained in:
sevenc-nanashi
2023-07-23 07:31:55 +09:00
committed by Emilio Cobos Álvarez
parent d8355da466
commit 0fb5d07ae4
21 changed files with 769 additions and 2 deletions
+46
View File
@@ -0,0 +1,46 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum DEPRECATED_ENUM DeprecatedEnum {
A = 0,
};
typedef int32_t DeprecatedEnum;
enum DEPRECATED_ENUM_WITH_NOTE("This is a note") DeprecatedEnumWithNote {
B = 0,
};
typedef int32_t DeprecatedEnumWithNote;
typedef struct DEPRECATED_STRUCT {
int32_t a;
} DeprecatedStruct;
typedef struct DEPRECATED_STRUCT_WITH_NOTE("This is a note") {
int32_t a;
} DeprecatedStructWithNote;
DEPRECATED_FUNC void deprecated_without_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_without_bracket(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note_and_since(void);
DEPRECATED_FUNC_WITH_NOTE("This quote \" requires to be quoted, and this [\n] requires to be escaped")
void deprecated_with_note_which_requires_to_be_escaped(void);
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
DeprecatedStruct c,
DeprecatedStructWithNote d);
+66
View File
@@ -0,0 +1,66 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum DEPRECATED_ENUM DeprecatedEnum
#ifdef __cplusplus
: int32_t
#endif // __cplusplus
{
A = 0,
};
#ifndef __cplusplus
typedef int32_t DeprecatedEnum;
#endif // __cplusplus
enum DEPRECATED_ENUM_WITH_NOTE("This is a note") DeprecatedEnumWithNote
#ifdef __cplusplus
: int32_t
#endif // __cplusplus
{
B = 0,
};
#ifndef __cplusplus
typedef int32_t DeprecatedEnumWithNote;
#endif // __cplusplus
typedef struct DEPRECATED_STRUCT {
int32_t a;
} DeprecatedStruct;
typedef struct DEPRECATED_STRUCT_WITH_NOTE("This is a note") {
int32_t a;
} DeprecatedStructWithNote;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
DEPRECATED_FUNC void deprecated_without_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_without_bracket(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note_and_since(void);
DEPRECATED_FUNC_WITH_NOTE("This quote \" requires to be quoted, and this [\n] requires to be escaped")
void deprecated_with_note_which_requires_to_be_escaped(void);
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
DeprecatedStruct c,
DeprecatedStructWithNote d);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+49
View File
@@ -0,0 +1,49 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>
enum class DEPRECATED_ENUM DeprecatedEnum : int32_t {
A = 0,
};
enum class DEPRECATED_ENUM_WITH_NOTE("This is a note") DeprecatedEnumWithNote : int32_t {
B = 0,
};
struct DEPRECATED_STRUCT DeprecatedStruct {
int32_t a;
};
struct DEPRECATED_STRUCT_WITH_NOTE("This is a note") DeprecatedStructWithNote {
int32_t a;
};
extern "C" {
DEPRECATED_FUNC void deprecated_without_note();
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_without_bracket();
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note();
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note_and_since();
DEPRECATED_FUNC_WITH_NOTE("This quote \" requires to be quoted, and this [\n] requires to be escaped")
void deprecated_with_note_which_requires_to_be_escaped();
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
DeprecatedStruct c,
DeprecatedStructWithNote d);
} // extern "C"
+44
View File
@@ -0,0 +1,44 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
cdef extern from *:
cdef enum:
A # = 0,
ctypedef int32_t DeprecatedEnum;
cdef enum:
B # = 0,
ctypedef int32_t DeprecatedEnumWithNote;
ctypedef struct DeprecatedStruct:
int32_t a;
ctypedef struct DeprecatedStructWithNote:
int32_t a;
void deprecated_without_note();
void deprecated_without_bracket();
void deprecated_with_note();
void deprecated_with_note_and_since();
void deprecated_with_note_which_requires_to_be_escaped();
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
DeprecatedStruct c,
DeprecatedStructWithNote d);
+46
View File
@@ -0,0 +1,46 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum DEPRECATED_ENUM DeprecatedEnum {
A = 0,
};
typedef int32_t DeprecatedEnum;
enum DEPRECATED_ENUM_WITH_NOTE("This is a note") DeprecatedEnumWithNote {
B = 0,
};
typedef int32_t DeprecatedEnumWithNote;
typedef struct DEPRECATED_STRUCT DeprecatedStruct {
int32_t a;
} DeprecatedStruct;
typedef struct DEPRECATED_STRUCT_WITH_NOTE("This is a note") DeprecatedStructWithNote {
int32_t a;
} DeprecatedStructWithNote;
DEPRECATED_FUNC void deprecated_without_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_without_bracket(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note_and_since(void);
DEPRECATED_FUNC_WITH_NOTE("This quote \" requires to be quoted, and this [\n] requires to be escaped")
void deprecated_with_note_which_requires_to_be_escaped(void);
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
struct DeprecatedStruct c,
struct DeprecatedStructWithNote d);
@@ -0,0 +1,66 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum DEPRECATED_ENUM DeprecatedEnum
#ifdef __cplusplus
: int32_t
#endif // __cplusplus
{
A = 0,
};
#ifndef __cplusplus
typedef int32_t DeprecatedEnum;
#endif // __cplusplus
enum DEPRECATED_ENUM_WITH_NOTE("This is a note") DeprecatedEnumWithNote
#ifdef __cplusplus
: int32_t
#endif // __cplusplus
{
B = 0,
};
#ifndef __cplusplus
typedef int32_t DeprecatedEnumWithNote;
#endif // __cplusplus
typedef struct DEPRECATED_STRUCT DeprecatedStruct {
int32_t a;
} DeprecatedStruct;
typedef struct DEPRECATED_STRUCT_WITH_NOTE("This is a note") DeprecatedStructWithNote {
int32_t a;
} DeprecatedStructWithNote;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
DEPRECATED_FUNC void deprecated_without_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_without_bracket(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note_and_since(void);
DEPRECATED_FUNC_WITH_NOTE("This quote \" requires to be quoted, and this [\n] requires to be escaped")
void deprecated_with_note_which_requires_to_be_escaped(void);
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
struct DeprecatedStruct c,
struct DeprecatedStructWithNote d);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+46
View File
@@ -0,0 +1,46 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum DEPRECATED_ENUM DeprecatedEnum {
A = 0,
};
typedef int32_t DeprecatedEnum;
enum DEPRECATED_ENUM_WITH_NOTE("This is a note") DeprecatedEnumWithNote {
B = 0,
};
typedef int32_t DeprecatedEnumWithNote;
struct DEPRECATED_STRUCT DeprecatedStruct {
int32_t a;
};
struct DEPRECATED_STRUCT_WITH_NOTE("This is a note") DeprecatedStructWithNote {
int32_t a;
};
DEPRECATED_FUNC void deprecated_without_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_without_bracket(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note_and_since(void);
DEPRECATED_FUNC_WITH_NOTE("This quote \" requires to be quoted, and this [\n] requires to be escaped")
void deprecated_with_note_which_requires_to_be_escaped(void);
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
struct DeprecatedStruct c,
struct DeprecatedStructWithNote d);
@@ -0,0 +1,66 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
enum DEPRECATED_ENUM DeprecatedEnum
#ifdef __cplusplus
: int32_t
#endif // __cplusplus
{
A = 0,
};
#ifndef __cplusplus
typedef int32_t DeprecatedEnum;
#endif // __cplusplus
enum DEPRECATED_ENUM_WITH_NOTE("This is a note") DeprecatedEnumWithNote
#ifdef __cplusplus
: int32_t
#endif // __cplusplus
{
B = 0,
};
#ifndef __cplusplus
typedef int32_t DeprecatedEnumWithNote;
#endif // __cplusplus
struct DEPRECATED_STRUCT DeprecatedStruct {
int32_t a;
};
struct DEPRECATED_STRUCT_WITH_NOTE("This is a note") DeprecatedStructWithNote {
int32_t a;
};
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
DEPRECATED_FUNC void deprecated_without_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_without_bracket(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note(void);
DEPRECATED_FUNC_WITH_NOTE("This is a note") void deprecated_with_note_and_since(void);
DEPRECATED_FUNC_WITH_NOTE("This quote \" requires to be quoted, and this [\n] requires to be escaped")
void deprecated_with_note_which_requires_to_be_escaped(void);
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
struct DeprecatedStruct c,
struct DeprecatedStructWithNote d);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+44
View File
@@ -0,0 +1,44 @@
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
cdef extern from *:
ctypedef bint bool
ctypedef struct va_list
cdef extern from *:
cdef enum:
A # = 0,
ctypedef int32_t DeprecatedEnum;
cdef enum:
B # = 0,
ctypedef int32_t DeprecatedEnumWithNote;
cdef struct DeprecatedStruct:
int32_t a;
cdef struct DeprecatedStructWithNote:
int32_t a;
void deprecated_without_note();
void deprecated_without_bracket();
void deprecated_with_note();
void deprecated_with_note_and_since();
void deprecated_with_note_which_requires_to_be_escaped();
void dummy(DeprecatedEnum a,
DeprecatedEnumWithNote b,
DeprecatedStruct c,
DeprecatedStructWithNote d);
+52
View File
@@ -0,0 +1,52 @@
#[no_mangle]
#[deprecated]
pub extern "C" fn deprecated_without_note() {}
#[no_mangle]
#[deprecated = "This is a note"]
pub extern "C" fn deprecated_without_bracket() {}
#[no_mangle]
#[deprecated(note = "This is a note")]
pub extern "C" fn deprecated_with_note() {}
#[no_mangle]
#[deprecated(note = "This is a note", since = "1.0.0")]
pub extern "C" fn deprecated_with_note_and_since() {}
#[no_mangle]
#[deprecated(note = "This quote \" requires to be quoted, and this [\n] requires to be escaped")]
pub extern "C" fn deprecated_with_note_which_requires_to_be_escaped() {}
#[repr(i32)]
#[deprecated]
pub enum DeprecatedEnum {
A = 0,
}
#[repr(i32)]
#[deprecated(note = "This is a note")]
pub enum DeprecatedEnumWithNote {
B = 0,
}
#[repr(C)]
#[deprecated]
pub struct DeprecatedStruct {
pub a: i32,
}
#[repr(C)]
#[deprecated(note = "This is a note")]
pub struct DeprecatedStructWithNote {
pub a: i32,
}
#[no_mangle]
pub extern "C" fn dummy(
a: DeprecatedEnum,
b: DeprecatedEnumWithNote,
c: DeprecatedStruct,
d: DeprecatedStructWithNote,
) -> void {
}
+20
View File
@@ -0,0 +1,20 @@
header = """
#define DEPRECATED_FUNC __attribute__((deprecated))
#define DEPRECATED_STRUCT __attribute__((deprecated))
#define DEPRECATED_ENUM __attribute__((deprecated))
#define DEPRECATED_FUNC_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_STRUCT_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
#define DEPRECATED_ENUM_WITH_NOTE(...) __attribute__((deprecated(__VA_ARGS__)))
"""
[fn]
deprecated = "DEPRECATED_FUNC"
deprecated_with_note = "DEPRECATED_FUNC_WITH_NOTE({})"
[struct]
deprecated = "DEPRECATED_STRUCT"
deprecated_with_note = "DEPRECATED_STRUCT_WITH_NOTE({})"
[enum]
deprecated = "DEPRECATED_ENUM"
deprecated_with_note = "DEPRECATED_ENUM_WITH_NOTE({})"
+3
View File
@@ -140,6 +140,9 @@ fn compile(
// clang also warns about returning non-instantiated templates (they could
// be specialized, but they're not so it's fine).
command.arg("-Wno-return-type-c-linkage");
// deprecated warnings should not be errors as it's intended
command.arg("-Wno-deprecated-declarations");
if let Language::Cxx = language {
// enum class is a c++11 extension which makes g++ on macos 10.14 error out
// inline variables are are a c++17 extension