1
+ //! Intermediate representation for attributes.
1
2
use std:: str;
2
3
3
4
use clang:: Cursor ;
@@ -6,20 +7,33 @@ use cexpr::token::{Token, Kind};
6
7
7
8
use super :: context:: BindgenContext ;
8
9
10
+ /// The special attribute
9
11
#[ derive( Clone , Debug ) ]
10
12
pub enum Attribute {
13
+ /// This attribute results in a warning if the type is used anywhere in the source file.
11
14
Deprecated ( Option < String > ) ,
15
+ /// This attribute means that variables of that type are meant to appear possibly unused.
12
16
Unused ,
17
+ /// This attribute attached to a function, means that code must be emitted for the function
18
+ /// even if it appears that the function is not referenced.
13
19
Used ,
20
+ /// This attribute on functions is used to inform the compiler that the function is unlikely to be executed.
14
21
Cold ,
22
+ /// Many functions do not examine any values except their arguments,
23
+ /// and have no effects except the return value.
15
24
Const ,
25
+ /// This attribute causes the function to be called automatically before execution enters main ().
16
26
Constructor ( Option < isize > ) ,
27
+ /// This attribute causes the function to be called automatically after main () completes or exit () is called.
17
28
Destructor ( Option < isize > ) ,
29
+ /// This attribute specifies a minimum alignment (in bytes)
18
30
Aligned ( Vec < Token > ) ,
31
+ /// An attribute whose specific kind is not exposed via this interface.
19
32
Unexposed ( String , Vec < Token > )
20
33
}
21
34
22
35
impl Attribute {
36
+ /// Construct a new `Attribute`.
23
37
pub fn new ( tokens : Vec < Token > ) -> Self {
24
38
// https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax
25
39
assert ! ( !tokens. is_empty( ) ) ;
@@ -78,6 +92,7 @@ impl Attribute {
78
92
}
79
93
}
80
94
95
+ /// Parse a `Cursor` for `Vec<Attribute>`.
81
96
pub fn parse ( cur : & Cursor , ctx : & BindgenContext ) -> Vec < Self > {
82
97
let mut attributes = vec ! [ ] ;
83
98
@@ -110,6 +125,7 @@ impl Attribute {
110
125
attributes
111
126
}
112
127
128
+ /// Extract `Vec<Attribute>` from cursor's children.
113
129
pub fn extract ( cur : & Cursor , ctx : & BindgenContext ) -> Vec < Self > {
114
130
let mut attributes = vec ! [ ] ;
115
131
@@ -126,6 +142,7 @@ impl Attribute {
126
142
attributes
127
143
}
128
144
145
+ /// Whether this attribute whose specific kind is not exposed.
129
146
pub fn is_unexposed ( & self ) -> bool {
130
147
match * self {
131
148
Attribute :: Unexposed ( ..) |
0 commit comments